Skip to content

Commit

Permalink
Add verif.bmc VerifToSMT lowering (#7603)
Browse files Browse the repository at this point in the history
Co-authored-by: Martin Erhart <[email protected]>
  • Loading branch information
TaoBi22 and maerhart authored Sep 24, 2024
1 parent 685cc3b commit c601695
Show file tree
Hide file tree
Showing 8 changed files with 509 additions and 13 deletions.
7 changes: 6 additions & 1 deletion include/circt/Conversion/Passes.td
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,12 @@ def ConvertHWToSMT : Pass<"convert-hw-to-smt", "mlir::ModuleOp"> {

def ConvertVerifToSMT : Pass<"convert-verif-to-smt", "mlir::ModuleOp"> {
let summary = "Convert Verif ops to SMT ops";
let dependentDialects = ["smt::SMTDialect", "mlir::arith::ArithDialect"];
let dependentDialects = [
"smt::SMTDialect",
"mlir::arith::ArithDialect",
"mlir::scf::SCFDialect",
"mlir::func::FuncDialect"
];
}

//===----------------------------------------------------------------------===//
Expand Down
4 changes: 3 additions & 1 deletion include/circt/Conversion/VerifToSMT.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
#include <memory>

namespace circt {
class Namespace;

#define GEN_PASS_DECL_CONVERTVERIFTOSMT
#include "circt/Conversion/Passes.h.inc"

/// Get the Verif to SMT conversion patterns.
void populateVerifToSMTConversionPatterns(TypeConverter &converter,
RewritePatternSet &patterns);
RewritePatternSet &patterns,
Namespace &names);

} // namespace circt

Expand Down
1 change: 1 addition & 0 deletions lib/Conversion/HWToSMT/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ add_circt_conversion_library(CIRCTHWToSMT
LINK_LIBS PUBLIC
CIRCTHW
CIRCTSMT
CIRCTSeq
MLIRFuncDialect
MLIRTransforms
MLIRTransformUtils
Expand Down
24 changes: 23 additions & 1 deletion lib/Conversion/HWToSMT/HWToSMT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "circt/Conversion/HWToSMT.h"
#include "circt/Dialect/HW/HWOps.h"
#include "circt/Dialect/SMT/SMTOps.h"
#include "circt/Dialect/Seq/SeqOps.h"
#include "mlir/Analysis/TopologicalSortUtils.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Pass/Pass.h"
Expand Down Expand Up @@ -92,6 +93,20 @@ struct InstanceOpConversion : OpConversionPattern<InstanceOp> {
}
};

/// Remove redundant (seq::FromClock and seq::ToClock) ops.
template <typename OpTy>
struct ReplaceWithInput : OpConversionPattern<OpTy> {
using OpConversionPattern<OpTy>::OpConversionPattern;
using OpAdaptor = typename OpTy::Adaptor;

LogicalResult
matchAndRewrite(OpTy op, OpAdaptor adaptor,
ConversionPatternRewriter &rewriter) const override {
rewriter.replaceOp(op, adaptor.getOperands());
return success();
}
};

} // namespace

//===----------------------------------------------------------------------===//
Expand All @@ -118,6 +133,9 @@ void circt::populateHWToSMTTypeConverter(TypeConverter &converter) {
return std::nullopt;
return smt::BitVectorType::get(type.getContext(), type.getWidth());
});
converter.addConversion([](seq::ClockType type) -> std::optional<Type> {
return smt::BitVectorType::get(type.getContext(), 1);
});

// Default target materialization to convert from illegal types to legal
// types, e.g., at the boundary of an inlined child block.
Expand Down Expand Up @@ -200,12 +218,16 @@ void circt::populateHWToSMTTypeConverter(TypeConverter &converter) {
void circt::populateHWToSMTConversionPatterns(TypeConverter &converter,
RewritePatternSet &patterns) {
patterns.add<HWConstantOpConversion, HWModuleOpConversion, OutputOpConversion,
InstanceOpConversion>(converter, patterns.getContext());
InstanceOpConversion, ReplaceWithInput<seq::ToClockOp>,
ReplaceWithInput<seq::FromClockOp>>(converter,
patterns.getContext());
}

void ConvertHWToSMTPass::runOnOperation() {
ConversionTarget target(getContext());
target.addIllegalDialect<hw::HWDialect>();
target.addIllegalOp<seq::FromClockOp>();
target.addIllegalOp<seq::ToClockOp>();
target.addLegalDialect<smt::SMTDialect>();
target.addLegalDialect<mlir::func::FuncDialect>();

Expand Down
2 changes: 2 additions & 0 deletions lib/Conversion/VerifToSMT/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ add_circt_conversion_library(CIRCTVerifToSMT
CIRCTSMT
CIRCTVerif
MLIRArithDialect
MLIRFuncDialect
MLIRSCFDialect
MLIRTransforms
MLIRTransformUtils
MLIRReconcileUnrealizedCasts
Expand Down
Loading

0 comments on commit c601695

Please sign in to comment.