Skip to content

Commit

Permalink
Emit companion Assumes for UNR Only SVAs as Immediate (instead of con…
Browse files Browse the repository at this point in the history
…current) (llvm#5561)
  • Loading branch information
girishpai authored and uenoku committed Aug 2, 2023
1 parent cc61339 commit b48ffd1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
38 changes: 30 additions & 8 deletions lib/Conversion/FIRRTLToHW/LowerToHW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3977,9 +3977,24 @@ LogicalResult FIRRTLLowering::lowerVerificationStatement(
Value opEnable, StringAttr opMessageAttr, ValueRange opOperands,
StringAttr opNameAttr, bool isConcurrent, EventControl opEventControl) {
StringRef opName = op->getName().stripDialect();

// The attribute holding the compile guards
ArrayRef<Attribute> guards{};
if (auto guardsAttr = op->template getAttrOfType<ArrayAttr>("guards"))
guards = guardsAttr.getValue();

auto isAssert = opName == "assert";
auto isCover = opName == "cover";

// TODO : Need to figure out if there is a cleaner way to get the string which
// indicates the assert is UNR only. Or better - not rely on this at all -
// ideally there should have been some other attribute which indicated that
// this assert for UNR only.
auto isUnrOnlyAssert = llvm::any_of(guards, [](Attribute attr) {
StringAttr strAttr = dyn_cast<StringAttr>(attr);
return strAttr && strAttr.getValue() == "USE_UNR_ONLY_CONSTRAINTS";
});

auto clock = getLoweredValue(opClock);
auto enable = getLoweredValue(opEnable);
auto predicate = getLoweredValue(opPredicate);
Expand Down Expand Up @@ -4098,19 +4113,27 @@ LogicalResult FIRRTLLowering::lowerVerificationStatement(
assumeLabel = StringAttr::get(builder.getContext(),
"assume__" + label.getValue());
addToIfDefBlock("USE_PROPERTY_AS_CONSTRAINT", [&]() {
builder.create<sv::AssumeConcurrentOp>(
circt::sv::EventControlAttr::get(builder.getContext(), event),
clock, predicate, assumeLabel);
if (!isUnrOnlyAssert) {
builder.create<sv::AssumeConcurrentOp>(
circt::sv::EventControlAttr::get(builder.getContext(), event),
clock, predicate, assumeLabel);
} else {
builder.create<sv::AlwaysOp>(
ArrayRef(sv::EventControl::AtEdge), ArrayRef(predicate), [&]() {
buildImmediateVerifOp(builder, "assume", predicate,
circt::sv::DeferAssertAttr::get(
builder.getContext(),
circt::sv::DeferAssert::Immediate),
assumeLabel);
});
}
});
}
};

// Wrap the verification statement up in the optional preprocessor
// guards. This is a bit awkward since we want to translate an array of
// guards into a recursive call to `addToIfDefBlock`.
ArrayRef<Attribute> guards{};
if (auto guardsAttr = op->template getAttrOfType<ArrayAttr>("guards"))
guards = guardsAttr.getValue();
// guards into a recursive call to `addToIfDefBlock`.
bool anyFailed = false;
std::function<void()> emitWrapped = [&]() {
if (guards.empty()) {
Expand All @@ -4129,7 +4152,6 @@ LogicalResult FIRRTLLowering::lowerVerificationStatement(
emitWrapped();
if (anyFailed)
return failure();

return success();
}

Expand Down
6 changes: 4 additions & 2 deletions test/Dialect/FIRRTL/SFCTests/complex-asserts.fir
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ circuit Foo:
; CHECK-NEXT: assert__verif_library_1: assert property (@(posedge clock) [[TMP4]])
; CHECK-SAME: else $error("Assertion failed (verification library): Conditional compilation example for UNR-only assert");
; CHECK-NEXT: `ifdef USE_PROPERTY_AS_CONSTRAINT
; CHECK-NEXT: assume__verif_library_1: assume property (@(posedge clock) [[TMP4]]);
; CHECK-NEXT: always @(edge [[TMP4]])
; CHECK-NEXT: assume__verif_library_1: assume([[TMP4]]);
; CHECK-NEXT: `endif
when not(or(predicate8, asUInt(reset))) :
printf(clock, enable, "foo [verif-library-assert]<extraction-summary>{\"predicateModifier\":{\"type\":\"noMod\"},\"conditionalCompileToggles\":[{\"type\":\"unrOnly\"}],\"format\":{\"type\":\"sva\"},\"baseMsg\":\"Assertion failed (verification library): Conditional compilation example for UNR-only assert\"}</extraction-summary> bar")
Expand Down Expand Up @@ -144,7 +145,8 @@ circuit Foo:
; CHECK-NEXT: assert__verif_library_2: assert property (@(posedge clock) [[TMP5]])
; CHECK-SAME: else $error("Assertion failed (verification library): Conditional compilation example for UNR-only and formal-only assert");
; CHECK-NEXT: `ifdef USE_PROPERTY_AS_CONSTRAINT
; CHECK-NEXT: assume__verif_library_2: assume property (@(posedge clock) [[TMP5]]);
; CHECK-NEXT: always @(edge [[TMP5]])
; CHECK-NEXT: assume__verif_library_2: assume([[TMP5]]);
; CHECK-NEXT: `endif
; CHECK-NEXT: `endif
; CHECK-NEXT: `endif
Expand Down

0 comments on commit b48ffd1

Please sign in to comment.