Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add verif.bmc VerifToSMT lowering #7603

Merged
merged 11 commits into from
Sep 24, 2024
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
TaoBi22 marked this conversation as resolved.
Show resolved Hide resolved
MLIRTransforms
MLIRTransformUtils
MLIRReconcileUnrealizedCasts
Expand Down
Loading
Loading