Skip to content

Commit

Permalink
[FIRRTL] AdvancedLayerSink: don't sink instances of mods with port annos
Browse files Browse the repository at this point in the history
If a module-like has port annotations, mark it as an effectful module, which
will prevent the pass from moving or deleting its instances later on.
  • Loading branch information
rwy7 committed Dec 13, 2024
1 parent 2aaf978 commit cbfb5a2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
9 changes: 9 additions & 0 deletions lib/Dialect/FIRRTL/Transforms/AdvancedLayerSink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,18 @@ class EffectInfo {
});
}

/// Record whether the module-like op contains any effectful op.
void update(FModuleLike moduleOp) {
// If the module op has any annotations, then we pretend the module contains
// some kind of important effect, so that we cannot sink its instances.
if (!AnnotationSet(moduleOp).empty())
return markEffectful(moduleOp);

for (auto annos : moduleOp.getPortAnnotations()) {
if (!AnnotationSet(cast<ArrayAttr>(annos)).empty())
return markEffectful(moduleOp);
}

auto *op = moduleOp.getOperation();
// Regular modules may be pure.
if (auto m = dyn_cast<FModuleOp>(op))
Expand Down
2 changes: 1 addition & 1 deletion llvm
Submodule llvm updated 8433 files
23 changes: 23 additions & 0 deletions test/Dialect/FIRRTL/advanced-layer-sink.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -715,3 +715,26 @@ firrtl.circuit "Sub" {
}
}
}

// Test that a port annotation on a module prevents us from sinking instances of
// that module into layerblocks.
firrtl.circuit "DoNotSinkInstanceOfModuleWithPortAnno" {
firrtl.layer @A bind {}
firrtl.module @ModuleWithPortAnno(out %out : !firrtl.uint<1>)
attributes {
portAnnotations = [
[{class = "circt.FullResetAnnotation", resetType = "async"}]
]
}
{}

// CHECK: firrtl.module @DoNotSinkInstanceOfModuleWithPortAnno
firrtl.module @DoNotSinkInstanceOfModuleWithPortAnno() {
// CHECK-NEXT: firrtl.instance foo @ModuleWithPortAnn
%foo_out = firrtl.instance foo @ModuleWithPortAnno(out out : !firrtl.uint<1>)
// CHECK-NEXT: firrtl.layerblock
firrtl.layerblock @A {
"unknown"(%foo_out) : (!firrtl.uint<1>) -> ()
}
}
}

0 comments on commit cbfb5a2

Please sign in to comment.