Skip to content

Commit dde772c

Browse files
authored
[circt-bmc] add verif.formal support (#9145)
1 parent 9dfde5e commit dde772c

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

integration_test/circt-bmc/seq.mlir

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,28 @@ hw.module @Counter_with_firreg_sync_reset(in %clk: !seq.clock, in %rst: i1, out
8585
hw.output %reg : i3
8686
}
8787

88+
// Check that verif.formal ops are ingested correctly
89+
// RUN: circt-bmc %s -b 2 --module FormalOp --shared-libs=%libz3 | FileCheck %s --check-prefix=FORMAL2
90+
// FORMAL2: Bound reached with no violations!
91+
// RUN: circt-bmc %s -b 10 --module FormalOp --shared-libs=%libz3 | FileCheck %s --check-prefix=FORMAL10
92+
// FORMAL10: Assertion can be violated!
93+
94+
hw.module @CounterWithoutAssert(in %clk: !seq.clock, out count: i2) {
95+
%init = seq.initial () {
96+
%c0_i2 = hw.constant 0 : i2
97+
seq.yield %c0_i2 : i2
98+
} : () -> !seq.immutable<i2>
99+
%c1_i2 = hw.constant 1 : i2
100+
%regPlusOne = comb.add %reg, %c1_i2 : i2
101+
%reg = seq.compreg %regPlusOne, %clk initial %init : i2
102+
hw.output %reg : i2
103+
}
104+
105+
verif.formal @FormalOp {} {
106+
%symClk = verif.symbolic_value : !seq.clock
107+
%count = hw.instance "counter" @CounterWithoutAssert(clk: %symClk: !seq.clock) -> (count: i2)
108+
// Condition - count should never reach 3
109+
%c3_i2 = hw.constant 3 : i2
110+
%lt = comb.icmp ult %count, %c3_i2 : i2
111+
verif.assert %lt : i1
112+
}

tools/circt-bmc/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ target_link_libraries(circt-bmc
2424
CIRCTSupport
2525
CIRCTVerif
2626
CIRCTVerifToSMT
27+
CIRCTVerifTransforms
2728
LLVMSupport
2829
MLIRArithDialect
2930
MLIRBuiltinToLLVMIRTranslation

tools/circt-bmc/circt-bmc.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "circt/Dialect/OM/OMPasses.h"
2323
#include "circt/Dialect/Seq/SeqDialect.h"
2424
#include "circt/Dialect/Verif/VerifDialect.h"
25+
#include "circt/Dialect/Verif/VerifPasses.h"
2526
#include "circt/Support/Passes.h"
2627
#include "circt/Support/Version.h"
2728
#include "circt/Tools/circt-bmc/Passes.h"
@@ -68,7 +69,8 @@ static cl::OptionCategory mainCategory("circt-bmc Options");
6869

6970
static cl::opt<std::string>
7071
moduleName("module",
71-
cl::desc("Specify a named module to verify properties over."),
72+
cl::desc("Specify a named module (or verif.formal op) to verify "
73+
"properties over."),
7274
cl::value_desc("module name"), cl::cat(mainCategory));
7375

7476
static cl::opt<int> clockBound(
@@ -186,6 +188,7 @@ static LogicalResult executeBMC(MLIRContext &context) {
186188

187189
pm.addPass(om::createStripOMPass());
188190
pm.addPass(emit::createStripEmitPass());
191+
pm.addPass(verif::createLowerFormalToHWPass());
189192
pm.addPass(createExternalizeRegisters());
190193
LowerToBMCOptions lowerToBMCOptions;
191194
lowerToBMCOptions.bound = clockBound;

0 commit comments

Comments
 (0)