Skip to content

Commit

Permalink
[FIRRTL][IMDCE] Don't try to remove main module, don't warn if empty. (
Browse files Browse the repository at this point in the history
  • Loading branch information
dtzSiFive authored Sep 8, 2023
1 parent e0d1804 commit 3a241f7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/Dialect/FIRRTL/Transforms/IMDeadCodeElim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,8 @@ void IMDeadCodeElimPass::runOnOperation() {
op.erase();

for (auto module : modules)
eraseEmptyModule(module);
if (module != circuit.getMainModule())
eraseEmptyModule(module);

// Clean up data structures.
executableBlocks.clear();
Expand Down
16 changes: 14 additions & 2 deletions test/Dialect/FIRRTL/imdce.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ firrtl.circuit "top" {

// CHECK-LABEL: firrtl.module @top(in %clock: !firrtl.clock, in %input: !firrtl.uint<1>) {
// CHECK-NEXT: }
// expected-warning @+1 {{module `top` is empty but cannot be removed because the module is public}}
firrtl.module @top(in %clock: !firrtl.clock, in %input: !firrtl.uint<1>) {
%tile_input, %tile_output = firrtl.instance tile @Child1(in input: !firrtl.uint<1>, out output: !firrtl.uint<1>)
firrtl.strictconnect %tile_input, %input : !firrtl.uint<1>
Expand Down Expand Up @@ -251,7 +250,6 @@ firrtl.circuit "RefPorts" {

firrtl.circuit "MemoryInDeadCycle" {
// CHECK-LABEL: firrtl.module public @MemoryInDeadCycle
// expected-warning @+1{{module `MemoryInDeadCycle` is empty but cannot be removed because the module is public}}
firrtl.module public @MemoryInDeadCycle(in %clock: !firrtl.clock, in %addr: !firrtl.uint<4>) {

// CHECK-NOT: firrtl.mem
Expand Down Expand Up @@ -477,3 +475,17 @@ firrtl.circuit "AnnoAlive" {
firrtl.wire {annotations = [{class = "circt.test"}]} : !firrtl.uint
}
}

// -----
// Test warning about not being able to remove dead public modules.

// CHECK-LABEL: "DeadPublic"
firrtl.circuit "DeadPublic" {
// CHECK: module @PublicDeadChild
// expected-warning @below {{module `PublicDeadChild` is empty but cannot be removed because the module is public}}
firrtl.module @PublicDeadChild() {}
// CHECK: module @DeadPublic
firrtl.module @DeadPublic() {
firrtl.instance pdc @PublicDeadChild()
}
}
1 change: 0 additions & 1 deletion test/firtool/firtool-errors.mlir
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// RUN: firtool %s -format=mlir -verilog -verify-diagnostics | FileCheck --allow-empty %s

firrtl.circuit "top" {
// expected-warning @+3 {{module `top` is empty but cannot be removed because the module is public}}
// expected-error @+2 {{'firrtl.module' op contains a 'chisel3.util.experimental.ForceNameAnnotation' that is not a non-local annotation}}
// expected-note @+1 {{the erroneous annotation is '{class = "chisel3.util.experimental.ForceNameAnnotation"}'}}
firrtl.module @top() attributes {annotations = [{class = "chisel3.util.experimental.ForceNameAnnotation"}]} {
Expand Down

0 comments on commit 3a241f7

Please sign in to comment.