Skip to content

Commit 024a0e8

Browse files
authored
[FIRRTL] Remove nonlocal field from annotations when NLA becomes local (#9329)
This patch adds logic to the module inliner to detect when a NLA becomes local after inlining mutations. When this occurs, the `circt.nonlocal` field is removed from the annotation since it is no longer needed.
1 parent 4b8be16 commit 024a0e8

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

lib/Dialect/FIRRTL/Transforms/ModuleInliner.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,6 +1560,15 @@ LogicalResult Inliner::run() {
15601560
if (mnla.isDead())
15611561
return true;
15621562

1563+
// If the NLA becomes local after mutation (or sometimes an NLA is
1564+
// annotated even when the annotation is local in the first place),
1565+
// remove the nonlocal field.
1566+
if (mnla.isLocal()) {
1567+
anno.removeMember("circt.nonlocal");
1568+
newAnnotations.push_back(anno.getAttr());
1569+
return true;
1570+
}
1571+
15631572
// Do nothing if there are no additional NLAs to add or if we're
15641573
// dealing with a root module. Root modules have already been updated
15651574
// earlier in the pass. We only need to update NLA paths which are

test/Dialect/FIRRTL/inliner.mlir

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,3 +1426,17 @@ firrtl.circuit "FormalMarkerIsUse" {
14261426
// CHECK: firrtl.module private @Foo
14271427
// CHECK: firrtl.module private @Bar
14281428
}
1429+
1430+
1431+
// -----
1432+
1433+
firrtl.circuit "RemoveNonLocalFromLocal" {
1434+
// CHECK-NOT: @dutNLA
1435+
hw.hierpath private @dutNLA [@RemoveNonLocalFromLocal::@sym]
1436+
firrtl.module @Bar() {}
1437+
// CHECK-LABEL: firrtl.module @RemoveNonLocalFromLocal
1438+
firrtl.module @RemoveNonLocalFromLocal() {
1439+
// CHECK: firrtl.instance bar sym @sym {annotations = [{class = "circt.tracker", id = distinct[0]<>}]} @Bar()
1440+
firrtl.instance bar sym @sym {annotations = [{circt.nonlocal = @dutNLA, class = "circt.tracker", id = distinct[0]<>}]} @Bar()
1441+
}
1442+
}

0 commit comments

Comments
 (0)