Skip to content

Commit 6902cc3

Browse files
committed
[FIRRTL] Add domain support to instance choice
1 parent 78721e6 commit 6902cc3

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

lib/Dialect/FIRRTL/FIRRTLOps.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2924,6 +2924,13 @@ void InstanceChoiceOp::build(
29242924
portAnnotationsAttr = builder.getArrayAttr(portAnnotations);
29252925
}
29262926

2927+
// Create the domain info attribute.
2928+
ArrayAttr domainInfoAttr = defaultModule.getDomainInfoAttr();
2929+
if (domainInfoAttr.empty()) {
2930+
domainInfoAttr = builder.getArrayAttr(SmallVector<Attribute, 16>(
2931+
resultTypes.size(), builder.getArrayAttr({})));
2932+
}
2933+
29272934
// Gather the module & case names.
29282935
SmallVector<Attribute> moduleNames, caseNames;
29292936
moduleNames.push_back(SymbolRefAttr::get(defaultModule.getModuleNameAttr()));
@@ -2934,14 +2941,14 @@ void InstanceChoiceOp::build(
29342941
moduleNames.push_back(SymbolRefAttr::get(caseModule.getModuleNameAttr()));
29352942
}
29362943

2937-
return build(
2938-
builder, result, resultTypes, builder.getArrayAttr(moduleNames),
2939-
builder.getArrayAttr(caseNames), builder.getStringAttr(name),
2940-
NameKindEnumAttr::get(builder.getContext(), nameKind),
2941-
defaultModule.getPortDirectionsAttr(), defaultModule.getPortNamesAttr(),
2942-
defaultModule.getDomainInfoAttr(), builder.getArrayAttr(annotations),
2943-
portAnnotationsAttr, defaultModule.getLayersAttr(),
2944-
innerSym ? hw::InnerSymAttr::get(innerSym) : hw::InnerSymAttr());
2944+
return build(builder, result, resultTypes, builder.getArrayAttr(moduleNames),
2945+
builder.getArrayAttr(caseNames), builder.getStringAttr(name),
2946+
NameKindEnumAttr::get(builder.getContext(), nameKind),
2947+
defaultModule.getPortDirectionsAttr(),
2948+
defaultModule.getPortNamesAttr(), domainInfoAttr,
2949+
builder.getArrayAttr(annotations), portAnnotationsAttr,
2950+
defaultModule.getLayersAttr(),
2951+
innerSym ? hw::InnerSymAttr::get(innerSym) : hw::InnerSymAttr());
29452952
}
29462953

29472954
std::optional<size_t> InstanceChoiceOp::getTargetResultIndex() {
@@ -3067,7 +3074,7 @@ ParseResult InstanceChoiceOp::parse(OpAsmParser &parser,
30673074
}
30683075

30693076
if (parseModulePorts(parser, /*hasSSAIdentifiers=*/false,
3070-
/*supportsSymbols=*/false, /*supportsDomains=*/false,
3077+
/*supportsSymbols=*/false, /*supportsDomains=*/true,
30713078
entryArgs, portDirections, portNames, portTypes,
30723079
portAnnotations, portSyms, portLocs, domains))
30733080
return failure();

test/Dialect/FIRRTL/round-trip.mlir

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,4 +262,18 @@ firrtl.module @DomainDefine(
262262
firrtl.domain.define %y, %x
263263
}
264264

265+
firrtl.module private @DefaultTargetWithDomain(in %A: !firrtl.domain of @ClockDomain, in %clock: !firrtl.clock domains [%A]) {}
266+
firrtl.module private @FPGATargetWithDomain(in %A: !firrtl.domain of @ClockDomain, in %clock: !firrtl.clock domains [%A]) {}
267+
firrtl.module private @ASICTargetWithDomain(in %A: !firrtl.domain of @ClockDomain, in %clock: !firrtl.clock domains [%A]) {}
268+
269+
// CHECK-LABEL: firrtl.module @InstanceChoiceWithDomain
270+
firrtl.module @InstanceChoiceWithDomain(in %A: !firrtl.domain of @ClockDomain, in %clock: !firrtl.clock domains [%A]) {
271+
// CHECK: %inst_A, %inst_clock = firrtl.instance_choice inst interesting_name @DefaultTargetWithDomain alternatives @Platform
272+
// CHECK-SAME: { @FPGA -> @FPGATargetWithDomain, @ASIC -> @ASICTargetWithDomain } (in A: !firrtl.domain of @ClockDomain, in clock: !firrtl.clock domains [A])
273+
%inst_A, %inst_clock = firrtl.instance_choice inst interesting_name @DefaultTargetWithDomain alternatives @Platform
274+
{ @FPGA -> @FPGATargetWithDomain, @ASIC -> @ASICTargetWithDomain } (in A: !firrtl.domain of @ClockDomain, in clock: !firrtl.clock domains [A])
275+
firrtl.matchingconnect %inst_clock, %clock : !firrtl.clock
276+
firrtl.domain.define %inst_A, %A
277+
}
278+
265279
}

0 commit comments

Comments
 (0)