From 0938ce4508f82cb4361ee085d4f3e7fdd8071721 Mon Sep 17 00:00:00 2001 From: Schuyler Eldridge Date: Wed, 4 Aug 2021 23:51:44 -0400 Subject: [PATCH] [FIRRTLToHW] Copy "output_file" attr on FModuleOp Copy an "output_file" attribute from a FIRRTL module to a HW module if such an attribute exists. This enables FIRRTL transforms to set output file information in a FIRRTL pass, which may be necessary if such information is available in an annotation that that pass consumes. Signed-off-by: Schuyler Eldridge --- lib/Conversion/FIRRTLToHW/LowerToHW.cpp | 6 +++++- test/Conversion/FIRRTLToHW/lower-to-hw.mlir | 12 ++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/Conversion/FIRRTLToHW/LowerToHW.cpp b/lib/Conversion/FIRRTLToHW/LowerToHW.cpp index 808a5af870..27d707699a 100644 --- a/lib/Conversion/FIRRTLToHW/LowerToHW.cpp +++ b/lib/Conversion/FIRRTLToHW/LowerToHW.cpp @@ -726,7 +726,11 @@ FIRRTLModuleLowering::lowerModule(FModuleOp oldModule, Block *topLevelModule, OpBuilder builder(topLevelModule->getParent()->getContext()); builder.setInsertionPointToEnd(topLevelModule); auto nameAttr = builder.getStringAttr(oldModule.getName()); - return builder.create(oldModule.getLoc(), nameAttr, ports); + auto newModule = + builder.create(oldModule.getLoc(), nameAttr, ports); + if (auto outputFile = oldModule->getAttr("output_file")) + newModule->setAttr("output_file", outputFile); + return newModule; } /// Given a value of analog type, check to see the only use of it is an attach. diff --git a/test/Conversion/FIRRTLToHW/lower-to-hw.mlir b/test/Conversion/FIRRTLToHW/lower-to-hw.mlir index 469ad13cb5..5d02d7991f 100644 --- a/test/Conversion/FIRRTLToHW/lower-to-hw.mlir +++ b/test/Conversion/FIRRTLToHW/lower-to-hw.mlir @@ -406,6 +406,18 @@ firrtl.circuit "Simple" attributes {annotations = [{class = %baz = firrtl.instance @bar {lowerToBind = true, name = "baz"} : !firrtl.uint<1> } + + // CHECK-LABEL: hw.module @output_fileTest + // CHECK-SAME: directory = "output_fileTest/dir", exclude_from_filelist = true + // CHECK-SAME: exclude_replicated_ops = true, name = "output_fileTest.sv" + firrtl.module @output_fileTest() attributes {output_file = { + directory = "output_fileTest/dir", + exclude_from_filelist = true, + exclude_replicated_ops = true, + name = "output_fileTest.sv" + }} { + } + // https://github.com/llvm/circt/issues/314 // CHECK-LABEL: hw.module @issue314 firrtl.module @issue314(in %inp_2: !firrtl.uint<27>, in %inpi: !firrtl.uint<65>) {