Skip to content

Commit

Permalink
[MooreToCore] Support assert, assume, cover ops (#7681)
Browse files Browse the repository at this point in the history
* [MooreToCore] Support assert, assume, cover ops

Add conversion patterns from moore.{assert,assume,cover} to the corresponding verif.* op in MooreToConv. Consider rejecting deferred assertions for now. https://chipsalliance.github.io/sv-tests-results/?v=circt_verilog+16.2+assert_test
Fix issue #7630


* Do not differentiate between the different scheduling regions in SV
  • Loading branch information
mingzheTerapines authored Oct 11, 2024
1 parent 71b8665 commit acd335d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
2 changes: 1 addition & 1 deletion include/circt/Conversion/Passes.td
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ def ConvertMooreToCore : Pass<"convert-moore-to-core", "mlir::ModuleOp"> {
let constructor = "circt::createConvertMooreToCorePass()";
let dependentDialects = ["comb::CombDialect", "hw::HWDialect",
"llhd::LLHDDialect", "mlir::cf::ControlFlowDialect",
"mlir::scf::SCFDialect"];
"mlir::scf::SCFDialect", "verif::VerifDialect"];
}

//===----------------------------------------------------------------------===//
Expand Down
1 change: 1 addition & 0 deletions lib/Conversion/MooreToCore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ add_circt_conversion_library(CIRCTMooreToCore
CIRCTHW
CIRCTLLHD
CIRCTMoore
CIRCTVerif
MLIRControlFlowDialect
MLIRFuncDialect
MLIRSCFDialect
Expand Down
29 changes: 27 additions & 2 deletions lib/Conversion/MooreToCore/MooreToCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "circt/Dialect/HW/HWOps.h"
#include "circt/Dialect/LLHD/IR/LLHDOps.h"
#include "circt/Dialect/Moore/MooreOps.h"
#include "circt/Dialect/Verif/VerifOps.h"
#include "mlir/Dialect/ControlFlow/IR/ControlFlowOps.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/SCF/IR/SCF.h"
Expand Down Expand Up @@ -1237,6 +1238,24 @@ struct InPlaceOpConversion : public OpConversionPattern<SourceOp> {
}
};

template <typename MooreOpTy, typename VerifOpTy>
struct AssertLikeOpConversion : public OpConversionPattern<MooreOpTy> {
using OpConversionPattern<MooreOpTy>::OpConversionPattern;
using OpAdaptor = typename MooreOpTy::Adaptor;

LogicalResult
matchAndRewrite(MooreOpTy op, OpAdaptor adaptor,
ConversionPatternRewriter &rewriter) const override {
StringAttr label =
op.getLabel().has_value()
? StringAttr::get(op->getContext(), op.getLabel().value())
: StringAttr::get(op->getContext());
rewriter.replaceOpWithNewOp<VerifOpTy>(op, adaptor.getCond(), mlir::Value(),
label);
return success();
}
};

} // namespace

//===----------------------------------------------------------------------===//
Expand All @@ -1250,6 +1269,7 @@ static void populateLegality(ConversionTarget &target,
target.addLegalDialect<hw::HWDialect>();
target.addLegalDialect<llhd::LLHDDialect>();
target.addLegalDialect<comb::CombDialect>();
target.addLegalDialect<verif::VerifDialect>();

target.addLegalOp<debug::ScopeOp>();

Expand Down Expand Up @@ -1423,7 +1443,7 @@ static void populateOpConversion(RewritePatternSet &patterns,
ICmpOpConversion<WildcardNeOp, ICmpPredicate::wne>,
CaseXZEqOpConversion<CaseZEqOp, true>,
CaseXZEqOpConversion<CaseXZEqOp, false>,

// Patterns of structural operations.
SVModuleOpConversion, InstanceOpConversion, ProcedureOpConversion, WaitEventOpConversion,

Expand All @@ -1444,7 +1464,12 @@ static void populateOpConversion(RewritePatternSet &patterns,
CallOpConversion, UnrealizedConversionCastConversion,
InPlaceOpConversion<debug::ArrayOp>,
InPlaceOpConversion<debug::StructOp>,
InPlaceOpConversion<debug::VariableOp>
InPlaceOpConversion<debug::VariableOp>,

// Patterns of assert-like operations
AssertLikeOpConversion<AssertOp, verif::AssertOp>,
AssertLikeOpConversion<AssumeOp, verif::AssumeOp>,
AssertLikeOpConversion<CoverOp, verif::CoverOp>
>(typeConverter, context);
// clang-format on
mlir::populateAnyFunctionOpInterfaceTypeConversionPattern(patterns,
Expand Down
13 changes: 13 additions & 0 deletions test/Conversion/MooreToCore/basic.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -836,3 +836,16 @@ dbg.variable "b", %dbg0 scope %dbg1 : !moore.l32
dbg.array [%dbg0] : !moore.l32
// CHECK: dbg.struct {"q": [[TMP]]} : i32
dbg.struct {"q": %dbg0} : !moore.l32

// CHECK-LABEL: hw.module @Assert
moore.module @Assert(in %cond : !moore.l1) {
moore.procedure always {
// CHECK: verif.assert %cond label "cond" : i1
moore.assert immediate %cond label "cond" : l1
// CHECK: verif.assume %cond label "" : i1
moore.assume observed %cond : l1
// CHECK: verif.cover %cond label "" : i1
moore.cover final %cond : l1
moore.return
}
}

0 comments on commit acd335d

Please sign in to comment.