Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIRRTL] AdvancedLayerSink: don't sink instances of mods with port annos #7982

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 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 (!AnnotationSet(moduleOp).empty())
return markEffectful(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 (auto annos = getAnnotationsIfPresent(moduleOp))
if (!annos.empty())
return markEffectful(moduleOp);

for (auto annos : moduleOp.getPortAnnotations())
if (!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
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
rwy7 marked this conversation as resolved.
Show resolved Hide resolved
%foo_out = firrtl.instance foo @ModuleWithPortAnno(out out : !firrtl.uint<1>)
// CHECK-NEXT: firrtl.layerblock
firrtl.layerblock @A {
"unknown"(%foo_out) : (!firrtl.uint<1>) -> ()
}
}
}
Loading