Skip to content

Commit

Permalink
Support seq.clock
Browse files Browse the repository at this point in the history
  • Loading branch information
TaoBi22 committed Sep 19, 2023
1 parent 1c18325 commit ecfc453
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
1 change: 1 addition & 0 deletions include/circt/LogicalEquivalence/Circuit.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class Solver::Circuit {
mlir::Value reset, mlir::Value resetValue);
void performFirReg(mlir::Value next, mlir::Value clk, mlir::Value data,
mlir::Value reset, mlir::Value resetValue);
void performFromClock(mlir::Value result, mlir::Value input);

// `verif` dialect operations.
void performAssert(mlir::Value property);
Expand Down
7 changes: 4 additions & 3 deletions integration_test/circt-mc/seq.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
// RUN: circt-mc %s -b 10 --module ClkProp | FileCheck %s --check-prefix=CLKPROP
// CLKPROP: Success!

hw.module @ClkProp(%i0: i1, %clk: i1) {
hw.module @ClkProp(%clk: !seq.clock, %i0: i1) {
%reg = seq.compreg %i0, %clk : i1
// Condition (equivalent to %clk -> %reg == %i0)
%c-1_i1 = hw.constant -1 : i1
%nclk = comb.xor bin %clk, %c-1_i1 : i1
%c-1_i1 = hw.constant -1 : i1
%clk_i1 = seq.from_clock %clk
%nclk = comb.xor bin %clk_i1, %c-1_i1 : i1
%eq = comb.icmp bin eq %i0, %reg : i1
%imp = comb.or bin %nclk, %eq : i1
verif.assert %imp : i1
Expand Down
14 changes: 12 additions & 2 deletions lib/LogicalEquivalence/Circuit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,9 @@ z3::expr Solver::Circuit::fetchOrAllocateExpr(Value value) {
auto nameInsertion = nameTable.insert(std::pair(value, valueName));
assert(nameInsertion.second && "Name not inserted in state table");
Type type = value.getType();
assert(type.isSignlessInteger() && "Unsupported type");
unsigned int width = type.getIntOrFloatBitWidth();
auto isClockType = hw::type_isa<seq::ClockType>(type);
assert((type.isSignlessInteger() || isClockType) && "Unsupported type");
unsigned int width = isClockType ? 1 : type.getIntOrFloatBitWidth();
// Technically allowed for the `hw` dialect but
// disallowed for `comb` operations; should check separately.
assert(width > 0 && "0-width integers are not supported"); // NOLINT
Expand Down Expand Up @@ -845,6 +846,15 @@ void Solver::Circuit::performFirReg(mlir::Value next, mlir::Value clk,
addClk(clk);
}

void Solver::Circuit::performFromClock(mlir::Value result, mlir::Value input) {
z3::expr resultState = fetchOrAllocateExpr(result);
z3::expr inputState = fetchOrAllocateExpr(input);
// Constrain the result directly to the input's value
constrainResult(result, inputState);
combTransformTable.insert(std::pair(
result, std::pair(std::make_tuple(input), [](auto op1) { return op1; })));
}

//===----------------------------------------------------------------------===//
// `seq` dialect operations
//===----------------------------------------------------------------------===//
Expand Down
12 changes: 12 additions & 0 deletions lib/LogicalEquivalence/LogicExporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ struct Visitor : public hw::StmtVisitor<Visitor, LogicalResult>,
.Case<circt::seq::FirRegOp>([&](circt::seq::FirRegOp &op) {
return visitSeqOp(op, circuit);
})
.Case<circt::seq::FromClockOp>([&](circt::seq::FromClockOp &op) {
return visitSeqOp(op, circuit);
})
.Default([&](mlir::Operation *op) { return visitUnhandledOp(op); });
return outcome;
}
Expand All @@ -296,6 +299,15 @@ struct Visitor : public hw::StmtVisitor<Visitor, LogicalResult>,
circuit->performCompReg(next, clk, data, reset, resetValue);
return mlir::success();
}

mlir::LogicalResult visitSeqOp(circt::seq::FromClockOp &op,
Solver::Circuit *circuit) {
mlir::Value result = op.getResult();
mlir::Value input = op.getInput();
// circuit->performCompReg(next, clk, data, reset, resetValue);
circuit->performFromClock(result, input);
return mlir::success();
}
};
} // namespace

Expand Down

0 comments on commit ecfc453

Please sign in to comment.