Skip to content

Commit 8af679c

Browse files
committed
[FIRRTL] Move LowerLayers (and pals) after IMDCE
Move `LowerLayers` after IMDCE. Due to one small class of missed optimizations, add a canonicalizer after `LowerLayers` to prevent Verilog quality regressions (which were caught by an integration test). This is working towards moving `LowerLayers` to the end of the FIRRTL pipelinen so that inline layers can be used to crate `sv.ifdef` safely and a feature can be added to force out of a layer block. Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
1 parent 2d1b963 commit 8af679c

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

lib/Firtool/Firtool.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,6 @@ LogicalResult firtool::populateCHIRRTLToLowFIRRTL(mlir::PassManager &pm,
139139
pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
140140
firrtl::createLayerMergePass());
141141

142-
if (opt.shouldAdvancedLayerSink())
143-
pm.nest<firrtl::CircuitOp>().addPass(firrtl::createAdvancedLayerSinkPass());
144-
else
145-
pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
146-
firrtl::createLayerSinkPass());
147-
148142
// Preset the random initialization parameters for each module. The current
149143
// implementation assumes it can run at a time where every register is
150144
// currently in the final module it will be emitted in, all registers have
@@ -184,8 +178,6 @@ LogicalResult firtool::populateCHIRRTLToLowFIRRTL(mlir::PassManager &pm,
184178

185179
pm.addNestedPass<firrtl::CircuitOp>(firrtl::createExtractInstancesPass());
186180

187-
pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerLayersPass());
188-
189181
// Run passes to resolve Grand Central features. This should run before
190182
// BlackBoxReader because Grand Central needs to inform BlackBoxReader where
191183
// certain black boxes should be placed. Note: all Grand Central Taps related
@@ -216,6 +208,22 @@ LogicalResult firtool::populateCHIRRTLToLowFIRRTL(mlir::PassManager &pm,
216208
pm.addPass(firrtl::createIMDeadCodeElimPass());
217209
}
218210

211+
// Layer lowering passes. Move operations into layers when possible and
212+
// remove layers by converting them to other constructs. This lowering
213+
// process can create a few optimization opportunities.
214+
//
215+
// TODO: Improve LowerLayers to avoid the need for canonicalization. See:
216+
// https://github.com/llvm/circt/issues/7896
217+
if (opt.shouldAdvancedLayerSink())
218+
pm.nest<firrtl::CircuitOp>().addPass(firrtl::createAdvancedLayerSinkPass());
219+
else
220+
pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
221+
firrtl::createLayerSinkPass());
222+
pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerLayersPass());
223+
if (!opt.shouldDisableOptimization())
224+
pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
225+
createSimpleCanonicalizerPass());
226+
219227
if (opt.shouldEmitOMIR())
220228
pm.nest<firrtl::CircuitOp>().addPass(
221229
firrtl::createEmitOMIRPass(opt.getOmirOutputFile()));

0 commit comments

Comments
 (0)