Skip to content

Commit 6b4bea0

Browse files
authored
[FIRRTL] AdvancedLayerSink: don't sink instances of modules with port annos (#7982)
If a module-like has port annotations, mark it as containing an effect, which will prevent the pass from moving or deleting its instances later on.
1 parent 54d3dd0 commit 6b4bea0

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

lib/Dialect/FIRRTL/Transforms/AdvancedLayerSink.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,18 @@ class EffectInfo {
111111
});
112112
}
113113

114+
/// Record whether the module-like op contains any effectful op.
114115
void update(FModuleLike moduleOp) {
115-
if (!AnnotationSet(moduleOp).empty())
116-
return markEffectful(moduleOp);
116+
// If the module op has any annotations, then we pretend the module contains
117+
// some kind of important effect, so that we cannot sink its instances.
118+
if (auto annos = getAnnotationsIfPresent(moduleOp))
119+
if (!annos.empty())
120+
return markEffectful(moduleOp);
121+
122+
for (auto annos : moduleOp.getPortAnnotations())
123+
if (!cast<ArrayAttr>(annos).empty())
124+
return markEffectful(moduleOp);
125+
117126
auto *op = moduleOp.getOperation();
118127
// Regular modules may be pure.
119128
if (auto m = dyn_cast<FModuleOp>(op))

test/Dialect/FIRRTL/advanced-layer-sink.mlir

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,3 +715,26 @@ firrtl.circuit "Sub" {
715715
}
716716
}
717717
}
718+
719+
// Test that a port annotation on a module prevents us from sinking instances of
720+
// that module into layerblocks.
721+
firrtl.circuit "DoNotSinkInstanceOfModuleWithPortAnno" {
722+
firrtl.layer @A bind {}
723+
firrtl.module @ModuleWithPortAnno(out %out : !firrtl.uint<1>)
724+
attributes {
725+
portAnnotations = [
726+
[{class = "circt.FullResetAnnotation", resetType = "async"}]
727+
]
728+
}
729+
{}
730+
731+
// CHECK: firrtl.module @DoNotSinkInstanceOfModuleWithPortAnno
732+
firrtl.module @DoNotSinkInstanceOfModuleWithPortAnno() {
733+
// CHECK-NEXT: firrtl.instance foo @ModuleWithPortAnn
734+
%foo_out = firrtl.instance foo @ModuleWithPortAnno(out out : !firrtl.uint<1>)
735+
// CHECK-NEXT: firrtl.layerblock
736+
firrtl.layerblock @A {
737+
"unknown"(%foo_out) : (!firrtl.uint<1>) -> ()
738+
}
739+
}
740+
}

0 commit comments

Comments
 (0)