Skip to content

Commit 81140f6

Browse files
authored
[FIRRTL] Fix Grand Central companion not-in-design (#8625)
Fix a regression introduced in 88f5d5a where a Grand Central companion instantiated only under the test harness would cause the companion to be instantiated in the Grand Central directory and not under the test harness directory. An early exit if no instances are in the design was incorrectly dropped. Signed-off-by: Schuyler Eldridge <[email protected]>
1 parent 23d2665 commit 81140f6

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

lib/Dialect/FIRRTL/Transforms/GrandCentral.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2131,6 +2131,13 @@ void GrandCentralPass::runOnOperation() {
21312131
}
21322132
}
21332133

2134+
// If the companion is instantiated above the DUT, then don't
2135+
// extract it.
2136+
if (!instanceInfo->allInstancesUnderEffectiveDut(op)) {
2137+
++numAnnosRemoved;
2138+
return true;
2139+
}
2140+
21342141
// Look for any modules/extmodules _only_ instantiated by the
21352142
// companion. If these have no output file attribute, then mark
21362143
// them as being extracted into the Grand Central directory.

test/Dialect/FIRRTL/grand-central.mlir

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,3 +1146,56 @@ firrtl.circuit "MultiplyInstantiated" attributes {
11461146
// CHECK-NOT: output_file
11471147
//
11481148
// CHECK: sv.interface
1149+
1150+
// -----
1151+
1152+
firrtl.circuit "CompanionInTestharness" attributes {
1153+
annotations = [
1154+
{class = "sifive.enterprise.grandcentral.AugmentedBundleType",
1155+
defName = "View",
1156+
elements = [
1157+
{class = "sifive.enterprise.grandcentral.AugmentedGroundType",
1158+
id = 42 : i64,
1159+
name = "field"}],
1160+
id = 0 : i64},
1161+
{class = "sifive.enterprise.grandcentral.ExtractGrandCentralAnnotation",
1162+
directory = "gct-dir",
1163+
filename = "gct-dir/bindings.sv"},
1164+
{class = "sifive.enterprise.grandcentral.GrandCentralHierarchyFileAnnotation",
1165+
filename = "gct.yaml"},
1166+
{class = "sifive.enterprise.firrtl.TestBenchDirAnnotation", dirname = "testbench"}]} {
1167+
firrtl.layer @A bind {}
1168+
firrtl.module private @View_companion() attributes {
1169+
annotations = [
1170+
{class = "sifive.enterprise.grandcentral.ViewAnnotation.companion",
1171+
defName = "Companion",
1172+
id = 0 : i64,
1173+
name = "View"}]} {
1174+
%0 = firrtl.constant 0 :!firrtl.uint<1>
1175+
%zero = firrtl.node %0 {
1176+
annotations = [
1177+
{
1178+
class = "sifive.enterprise.grandcentral.AugmentedGroundType",
1179+
id = 42 : i64
1180+
}
1181+
]
1182+
} : !firrtl.uint<1>
1183+
}
1184+
firrtl.module public @DUT() attributes {
1185+
annotations = [
1186+
{
1187+
class = "sifive.enterprise.firrtl.MarkDUTAnnotation"
1188+
}
1189+
]
1190+
} {
1191+
}
1192+
firrtl.module @CompanionInTestharness() {
1193+
firrtl.instance dut @DUT()
1194+
firrtl.instance foo @View_companion()
1195+
}
1196+
}
1197+
1198+
// CHECK: firrtl.module private @View_companion()
1199+
// CHECK-NOT: output_file
1200+
//
1201+
// CHECK: firrtl.module public @DUT()

0 commit comments

Comments
 (0)