Skip to content

Commit

Permalink
[FIRRTL] AdvancedLayerSink: don't sink instances of modules with port…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
rwy7 authored Dec 13, 2024
1 parent 54d3dd0 commit 6b4bea0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
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
%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 6b4bea0

Please sign in to comment.