Skip to content

Commit

Permalink
[firtool] fix: remove unused modules before infering resets
Browse files Browse the repository at this point in the history
The Chisel's Definition API generates modules that are not instantiated,
whose reset cannot be inferred properly. Remove them before InferResets
pass to resolve it.

Signed-off-by: unlsycn <[email protected]>
  • Loading branch information
unlsycn committed Jul 23, 2024
1 parent bb80521 commit 583e6ce
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/Firtool/Firtool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ LogicalResult firtool::populateCHIRRTLToLowFIRRTL(mlir::PassManager &pm,
firrtl::createMemToRegOfVecPass(opt.shouldReplicateSequentialMemories(),
opt.shouldIgnoreReadEnableMemories()));

pm.nest<firrtl::CircuitOp>().addPass(firrtl::createInferResetsPass());

if (opt.shouldExportChiselInterface()) {
StringRef outdir = opt.getChiselInterfaceOutputDirectory();
if (opt.isDefaultOutputFilename() && outdir.empty()) {
Expand Down Expand Up @@ -138,6 +136,8 @@ LogicalResult firtool::populateCHIRRTLToLowFIRRTL(mlir::PassManager &pm,

pm.nest<firrtl::CircuitOp>().addPass(firrtl::createInlinerPass());

pm.nest<firrtl::CircuitOp>().addPass(firrtl::createInferResetsPass());

// Preset the random initialization parameters for each module. The current
// implementation assumes it can run at a time where every register is
// currently in the final module it will be emitted in, all registers have
Expand Down
28 changes: 28 additions & 0 deletions test/firtool/definition-infer-resets-error.fir
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
; RUN: firtool %s --verify-diagnostics --split-input-file

FIRRTL version 3.3.0
circuit Foo:
module Adder :
input clock : Clock
input reset : Reset
input in : UInt<10>
output out : UInt<10>

node _out_T = add(in, UInt<1>(0h1))
node _out_T_1 = tail(_out_T, 1)
connect out, _out_T_1

; expected-warning @below {{module `Foo` is empty}}
module Foo :
input clock : Clock
input reset : UInt<1>

;// -----

FIRRTL version 3.3.0
circuit Bar:
; expected-note @below {{the module with this uninferred reset port was defined here}}
module Bar :
input clock : Clock
; expected-error @below {{a port "reset" with abstract reset type was unable to be inferred by InferResets}}
input reset : Reset

0 comments on commit 583e6ce

Please sign in to comment.