Skip to content

Commit

Permalink
[SMT] Add set_logic operation (#7927)
Browse files Browse the repository at this point in the history
  • Loading branch information
TaoBi22 authored Nov 30, 2024
1 parent 44a38c4 commit c9b5ba9
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 1 deletion.
6 changes: 6 additions & 0 deletions include/circt/Dialect/SMT/SMTOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ def SolverOp : SMTOp<"solver", [
let hasRegionVerifier = true;
}

def SetLogicOp : SMTOp<"set_logic", []> {
let summary = "set the logic for the SMT solver";
let arguments = (ins StrAttr:$logic);
let assemblyFormat = "$logic attr-dict";
}

def AssertOp : SMTOp<"assert", []> {
let summary = "assert that a boolean expression holds";
let arguments = (ins BoolType:$input);
Expand Down
3 changes: 2 additions & 1 deletion include/circt/Dialect/SMT/SMTVisitors.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class SMTOpVisitor {
// Variable/symbol declaration
DeclareFunOp, ApplyFuncOp,
// solver interaction
SolverOp, AssertOp, ResetOp, PushOp, PopOp, CheckOp,
SolverOp, AssertOp, ResetOp, PushOp, PopOp, CheckOp, SetLogicOp,
// Boolean logic
NotOp, AndOp, OrOp, XOrOp, ImpliesOp,
// Arrays
Expand Down Expand Up @@ -128,6 +128,7 @@ class SMTOpVisitor {
HANDLE(PushOp, Unhandled);
HANDLE(PopOp, Unhandled);
HANDLE(CheckOp, Unhandled);
HANDLE(SetLogicOp, Unhandled);

// Boolean logic operations
HANDLE(NotOp, Unhandled);
Expand Down
17 changes: 17 additions & 0 deletions integration_test/Target/ExportSMTLIB/basic.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,20 @@ smt.solver () : () -> () {
// CHECK-NOT: error
// CHECK-NOT: unsat
// CHECK: sat

smt.solver () : () -> () {
smt.set_logic "HORN"
%c = smt.declare_fun : !smt.int
%c4 = smt.int.constant 4
%eq = smt.eq %c, %c4 : !smt.int
smt.assert %eq
smt.check sat {} unknown {} unsat {}
}

// CHECK-NOT: WARNING
// CHECK-NOT: warning
// CHECK-NOT: ERROR
// CHECK-NOT: error
// CHECK-NOT: unsat
// CHECK-NOT: sat
// CHECK: unknown
6 changes: 6 additions & 0 deletions lib/Target/ExportSMTLIB/ExportSMTLIB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,12 @@ struct StatementVisitor
return success();
}

LogicalResult visitSMTOp(SetLogicOp op, mlir::raw_indented_ostream &stream,
ValueMap &valueMap) {
stream << "(set-logic " << op.getLogic() << ")\n";
return success();
}

LogicalResult visitUnhandledSMTOp(Operation *op,
mlir::raw_indented_ostream &stream,
ValueMap &valueMap) {
Expand Down
7 changes: 7 additions & 0 deletions test/Dialect/SMT/basic.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ func.func @core(%in: i8) {
// CHECK-NEXT: }
smt.solver() : () -> () { }

// CHECK: smt.solver() : () -> () {
// CHECK-NEXT: smt.set_logic "AUFLIA"
// CHECK-NEXT: }
smt.solver() : () -> () {
smt.set_logic "AUFLIA"
}

// CHECK: smt.check sat {
// CHECK-NEXT: } unknown {
// CHECK-NEXT: } unsat {
Expand Down
4 changes: 4 additions & 0 deletions test/Target/ExportSMTLIB/core.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ smt.solver () : () -> () {
// CHECK-INLINED: (pop 1)
smt.pop 1

// CHECK: (set-logic AUFLIA)
// CHECK-INLINED: (set-logic AUFLIA)
smt.set_logic "AUFLIA"

// CHECK: (reset)
// CHECK-INLINED: (reset)
}

0 comments on commit c9b5ba9

Please sign in to comment.