Skip to content

Conversation

@luisacicolini
Copy link
Contributor

@luisacicolini luisacicolini commented Dec 22, 2025

This PR lowers the FSM dialect into SMT-LIB assertions.
We represent a transition s0 -> s1 as a Constrained Horn Clause (CHC), i.e., as an implication.

fsm.transition @S0
}
}
} No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: missing EOF newline

// CHECK-NEXT: }


module @fsm_with_time {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this FSM have specific characteristics to make it suitable for the timed test? If not then you could do this in basic.mlir with a --check-prefix (like in

hw.module @Top(in %clock : !seq.clock, in %i0 : i4, in %i1 : i4, out out : i4) {
)

Comment on lines +5 to +11
// CHECK-NEXT: %c0_i8 = hw.constant 0 : i8
// CHECK-NEXT: %c50_i8 = hw.constant 50 : i8
// CHECK-NEXT: %c50_i32 = hw.constant 50 : i32
// CHECK-NEXT: %c1_i32 = hw.constant 1 : i32
// CHECK-NEXT: %true = hw.constant true
// CHECK-NEXT: %F_S0 = smt.declare_fun "F_S0" : !smt.func<(!smt.bv<8>, !smt.bv<32>) !smt.bool>
// CHECK-NEXT: %F_S1 = smt.declare_fun "F_S1" : !smt.func<(!smt.bv<8>, !smt.bv<32>) !smt.bool>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could these SSA values be matched as FileCheck variables instead of using raw names? (It's a bit more stable if the naming changes for some reason)

// Read options from the generated base
LoweringConfig cfg;
cfg.withTime = withTime; // default false
cfg.timeWidth = 5;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth making this a pass option?

SmallVector<std::string> &states, Location &loc) {
std::string nextState = t.getNextState().str();
Transition tr = {from, insertStates(states, nextState)};
if (!t.getGuard().empty()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!t.getGuard().empty()) {
if (t.hasGuard()) {

}
} else {
// Ignore assertions in action regions
mlir::emitWarning(loc, "Assertions in action regions are ignored.");
Copy link
Contributor

@TaoBi22 TaoBi22 Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
mlir::emitWarning(loc, "Assertions in action regions are ignored.");
newOp->emitWarning("Assertions in action regions are ignored.");

Comment on lines +492 to +494
if (!isa<verif::AssertOp>(newOp)) {
// Retrieve the guard value
if (isa<fsm::ReturnOp>(newOp)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above

} else {
// Ignore assertions in guard regions

mlir::emitWarning(loc, "Assertions in guard regions are ignored.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as above

Comment on lines +528 to +531
if (!isa<verif::AssertOp>(newOp)) {

// Retrieve all the operands of the output operation
if (isa<fsm::OutputOp>(newOp)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above

Comment on lines +647 to +648
if (!isa<fsm::OutputOp>(op) && !isa<fsm::UpdateOp>(op) &&
!isa<fsm::ReturnOp>(op)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can just do

Suggested change
if (!isa<fsm::OutputOp>(op) && !isa<fsm::UpdateOp>(op) &&
!isa<fsm::ReturnOp>(op)) {
if (!isa<fsm::OutputOp, fsm::UpdateOp, fsm::ReturnOp>(op)) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

FSM the FSM dialect SMT

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants