Skip to content

Commit 2c8cfd9

Browse files
committed
[FIRRTL] Check that instance domains match modules
1 parent 1b7bb54 commit 2c8cfd9

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

lib/Dialect/FIRRTL/FIRRTLInstanceImplementation.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ instance_like_impl::verifyReferencedModule(Operation *instanceOp,
6464
instanceOp->emitOpError("the number of result annotations should be "
6565
"equal to the number of results"));
6666

67+
auto domainInfo = instanceOp->getAttrOfType<ArrayAttr>("domainInfo");
68+
if (domainInfo.size() != numExpected)
69+
return emitNote(
70+
instanceOp->emitOpError()
71+
<< "has a wrong number of port domain info attributes; expected "
72+
<< numExpected << ", got " << domainInfo.size());
73+
6774
// Check that the port names match the referenced module.
6875
if (portNames != referencedModule.getPortNamesAttr()) {
6976
// We know there is an error, try to figure out whats wrong.
@@ -122,6 +129,17 @@ instance_like_impl::verifyReferencedModule(Operation *instanceOp,
122129
llvm_unreachable("should have found something wrong");
123130
}
124131

132+
// Check the domain info matches.
133+
for (size_t i = 0; i < numResults; ++i) {
134+
auto portDomainInfo = domainInfo[i];
135+
auto modulePortDomainInfo = referencedModule.getDomainInfoAttrForPort(i);
136+
if (portDomainInfo != modulePortDomainInfo)
137+
return emitNote(instanceOp->emitOpError()
138+
<< "domain info for " << portNames[i] << " must be "
139+
<< modulePortDomainInfo << ", but got "
140+
<< portDomainInfo);
141+
}
142+
125143
// Check that the instance op lists the correct layer requirements.
126144
auto instanceLayers = instanceOp->getAttrOfType<ArrayAttr>("layers");
127145
auto moduleLayers = referencedModule.getLayersAttr();

test/Dialect/FIRRTL/errors.mlir

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3143,3 +3143,58 @@ firrtl.circuit "NonPropertyTypeInDomainField" {
31433143
firrtl.domain @Foo ["bar", !firrtl.uint<1>]
31443144
firrtl.module @NonPropertyTypeInDomainField() {}
31453145
}
3146+
3147+
// -----
3148+
3149+
firrtl.circuit "WrongInstanceDomainInfo" {
3150+
firrtl.domain @ClockDomain
3151+
// expected-note @below {{original module declared here}}
3152+
firrtl.module @Foo(in %a: !firrtl.uint<1>) {}
3153+
firrtl.module @WrongInstanceDomainInfo() {
3154+
// expected-error @below {{'firrtl.instance' op has a wrong number of port domain info attributes; expected 1, got 0}}
3155+
%a = firrtl.instance foo {domainInfo = []} @Foo(in a: !firrtl.uint<1>)
3156+
}
3157+
}
3158+
3159+
// -----
3160+
3161+
firrtl.circuit "WrongInstanceDomainInfo" {
3162+
firrtl.domain @ClockDomain
3163+
// expected-note @below {{original module declared here}}
3164+
firrtl.module @Foo(
3165+
in %A : !firrtl.domain of @ClockDomain,
3166+
in %B : !firrtl.domain of @ClockDomain,
3167+
in %a : !firrtl.uint<1> domains [%A]
3168+
) {}
3169+
firrtl.module @WrongInstanceDomainInfo() {
3170+
// expected-error @below {{op domain info for "a" must be [0 : ui32], but got [1 : ui32]}}
3171+
%foo_A, %foo_B, %foo_a = firrtl.instance foo @Foo(
3172+
in A : !firrtl.domain of @ClockDomain,
3173+
in B : !firrtl.domain of @ClockDomain,
3174+
in a : !firrtl.uint<1> domains [B]
3175+
)
3176+
}
3177+
}
3178+
3179+
// -----
3180+
3181+
firrtl.circuit "WrongInstanceChoiceDomainInfo" {
3182+
firrtl.option @Platform {
3183+
firrtl.option_case @FPGA
3184+
}
3185+
firrtl.domain @ClockDomain
3186+
// expected-note @below {{original module declared here}}
3187+
firrtl.module @Foo(
3188+
in %A : !firrtl.domain of @ClockDomain,
3189+
in %B : !firrtl.domain of @ClockDomain,
3190+
in %a : !firrtl.uint<1> domains [%A]
3191+
) {}
3192+
firrtl.module @WrongInstanceChoiceDomainInfo() {
3193+
// expected-error @below {{op domain info for "a" must be [0 : ui32], but got [1 : ui32]}}
3194+
%foo_A, %foo_B, %foo_a = firrtl.instance_choice foo @Foo alternatives @Platform { @FPGA -> @Foo } (
3195+
in A : !firrtl.domain of @ClockDomain,
3196+
in B : !firrtl.domain of @ClockDomain,
3197+
in a : !firrtl.uint<1> domains [B]
3198+
)
3199+
}
3200+
}

0 commit comments

Comments
 (0)