LLZK 2.0.0
An open-source IR for Zero Knowledge (ZK) circuits
Loading...
Searching...
No Matches
SMTVisitors.h
Go to the documentation of this file.
1//===- SMTVisitors.h - SMT Dialect Visitors ---------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines visitors that make it easier to work with the SMT IR.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef MLIR_DIALECT_SMT_IR_SMTVISITORS_H
14#define MLIR_DIALECT_SMT_IR_SMTVISITORS_H
15
16#include "llvm/ADT/TypeSwitch.h"
17
19
20namespace llzk {
21namespace smt {
22
24template <typename ConcreteType, typename ResultType = void, typename... ExtraArgs>
26public:
27 ResultType dispatchSMTOpVisitor(Operation *op, ExtraArgs... args) {
28 auto *thisCast = static_cast<ConcreteType *>(this);
29 return TypeSwitch<Operation *, ResultType>(op)
30 .template Case<
31 // Constants
33 // Bit-vector arithmetic
36 // Bit-vector bitwise
38 // Other bit-vector ops
40 // Int arithmetic
42 // Core Ops
44 // Variable/symbol declaration
46 // solver interaction
48 // Boolean logic
50 // Arrays
52 // Quantifiers
53 ForallOp, ExistsOp, YieldOp>([&](auto expr) -> ResultType {
54 return thisCast->visitSMTOp(expr, args...);
55 }).Default([&](auto expr) -> ResultType { return thisCast->visitInvalidSMTOp(op, args...); });
56 }
57
59 ResultType visitInvalidSMTOp(Operation *op, ExtraArgs... args) {
60 op->emitOpError("unknown SMT node");
61 abort();
62 }
63
66 ResultType visitUnhandledSMTOp(Operation *op, ExtraArgs... args) { return ResultType(); }
67
68#define HANDLE(OPTYPE, OPKIND) \
69 ResultType visitSMTOp(OPTYPE op, ExtraArgs... args) { \
70 return static_cast<ConcreteType *>(this)->visit##OPKIND##SMTOp(op, args...); \
71 }
72
73 // Constants
75 HANDLE(IntConstantOp, Unhandled);
76 HANDLE(BVConstantOp, Unhandled);
77
78 // Bit-vector arithmetic
79 HANDLE(BVNegOp, Unhandled);
80 HANDLE(BVAddOp, Unhandled);
81 HANDLE(BVMulOp, Unhandled);
82 HANDLE(BVURemOp, Unhandled);
83 HANDLE(BVSRemOp, Unhandled);
84 HANDLE(BVSModOp, Unhandled);
85 HANDLE(BVShlOp, Unhandled);
86 HANDLE(BVLShrOp, Unhandled);
87 HANDLE(BVAShrOp, Unhandled);
88 HANDLE(BVUDivOp, Unhandled);
89 HANDLE(BVSDivOp, Unhandled);
90
91 // Bit-vector bitwise operations
92 HANDLE(BVNotOp, Unhandled);
93 HANDLE(BVAndOp, Unhandled);
94 HANDLE(BVOrOp, Unhandled);
95 HANDLE(BVXOrOp, Unhandled);
96
97 // Other bit-vector operations
98 HANDLE(ConcatOp, Unhandled);
99 HANDLE(ExtractOp, Unhandled);
100 HANDLE(RepeatOp, Unhandled);
101 HANDLE(BVCmpOp, Unhandled);
102 HANDLE(BV2IntOp, Unhandled);
103
104 // Int arithmetic
105 HANDLE(IntAddOp, Unhandled);
106 HANDLE(IntMulOp, Unhandled);
107 HANDLE(IntSubOp, Unhandled);
108 HANDLE(IntDivOp, Unhandled);
109 HANDLE(IntModOp, Unhandled);
110
111 HANDLE(IntCmpOp, Unhandled);
112 HANDLE(Int2BVOp, Unhandled);
113
114 HANDLE(EqOp, Unhandled);
115 HANDLE(DistinctOp, Unhandled);
116 HANDLE(IteOp, Unhandled);
117
118 HANDLE(DeclareFunOp, Unhandled);
119 HANDLE(ApplyFuncOp, Unhandled);
120
121 HANDLE(SolverOp, Unhandled);
122 HANDLE(AssertOp, Unhandled);
123 HANDLE(ResetOp, Unhandled);
124 HANDLE(PushOp, Unhandled);
125 HANDLE(PopOp, Unhandled);
126 HANDLE(CheckOp, Unhandled);
127 HANDLE(SetLogicOp, Unhandled);
128
129 // Boolean logic operations
130 HANDLE(NotOp, Unhandled);
131 HANDLE(AndOp, Unhandled);
132 HANDLE(OrOp, Unhandled);
133 HANDLE(XOrOp, Unhandled);
134 HANDLE(ImpliesOp, Unhandled);
135
136 // Array operations
137 HANDLE(ArrayStoreOp, Unhandled);
140
141 // Quantifier operations
142 HANDLE(ForallOp, Unhandled);
143 HANDLE(ExistsOp, Unhandled);
144 HANDLE(YieldOp, Unhandled);
145
146#undef HANDLE
147};
148
150template <typename ConcreteType, typename ResultType = void, typename... ExtraArgs>
152public:
153 ResultType dispatchSMTTypeVisitor(Type type, ExtraArgs... args) {
154 auto *thisCast = static_cast<ConcreteType *>(this);
155 return TypeSwitch<Type, ResultType>(type)
156 .template Case<BoolType, IntType, BitVectorType, ArrayType, SMTFuncType, SortType>(
157 [&](auto expr) -> ResultType { return thisCast->visitSMTType(expr, args...); }
158 )
159 .Default([&](auto expr) -> ResultType {
160 return thisCast->visitInvalidSMTType(type, args...);
161 });
162 }
163
165 ResultType visitInvalidSMTType(Type type, ExtraArgs... args) { abort(); }
166
169 ResultType visitUnhandledSMTType(Type type, ExtraArgs... args) { return ResultType(); }
170
171#define HANDLE(TYPE, KIND) \
172 ResultType visitSMTType(TYPE op, ExtraArgs... args) { \
173 return static_cast<ConcreteType *>(this)->visit##KIND##SMTType(op, args...); \
174 }
175
176 HANDLE(BoolType, Unhandled);
177 HANDLE(IntegerType, Unhandled);
179 HANDLE(ArrayType, Unhandled);
180 HANDLE(SMTFuncType, Unhandled);
181 HANDLE(SortType, Unhandled);
182
183#undef HANDLE
184};
185
186} // namespace smt
187} // namespace llzk
188
189#endif // MLIR_DIALECT_SMT_IR_SMTVISITORS_H
This helps visit SMT nodes.
Definition SMTVisitors.h:25
HANDLE(IntMulOp, Unhandled)
HANDLE(BVURemOp, Unhandled)
HANDLE(ResetOp, Unhandled)
HANDLE(ForallOp, Unhandled)
ResultType visitInvalidSMTOp(Operation *op, ExtraArgs... args)
This callback is invoked on any non-expression operations.
Definition SMTVisitors.h:59
HANDLE(ArrayStoreOp, Unhandled)
HANDLE(BVLShrOp, Unhandled)
HANDLE(BVUDivOp, Unhandled)
HANDLE(BoolConstantOp, Unhandled)
HANDLE(BVShlOp, Unhandled)
HANDLE(BVAShrOp, Unhandled)
HANDLE(PushOp, Unhandled)
HANDLE(ImpliesOp, Unhandled)
HANDLE(OrOp, Unhandled)
HANDLE(ExistsOp, Unhandled)
HANDLE(IntAddOp, Unhandled)
HANDLE(IntSubOp, Unhandled)
HANDLE(BVConstantOp, Unhandled)
HANDLE(RepeatOp, Unhandled)
ResultType visitUnhandledSMTOp(Operation *op, ExtraArgs... args)
This callback is invoked on any SMT operations that are not handled by the concrete visitor.
Definition SMTVisitors.h:66
HANDLE(Int2BVOp, Unhandled)
HANDLE(ConcatOp, Unhandled)
HANDLE(SetLogicOp, Unhandled)
HANDLE(AssertOp, Unhandled)
HANDLE(BVMulOp, Unhandled)
HANDLE(BV2IntOp, Unhandled)
HANDLE(SolverOp, Unhandled)
HANDLE(IntModOp, Unhandled)
HANDLE(BVSRemOp, Unhandled)
HANDLE(BVAddOp, Unhandled)
HANDLE(IntConstantOp, Unhandled)
HANDLE(BVAndOp, Unhandled)
HANDLE(BVXOrOp, Unhandled)
HANDLE(NotOp, Unhandled)
HANDLE(BVNotOp, Unhandled)
HANDLE(IteOp, Unhandled)
HANDLE(EqOp, Unhandled)
HANDLE(CheckOp, Unhandled)
HANDLE(AndOp, Unhandled)
HANDLE(BVSDivOp, Unhandled)
HANDLE(BVNegOp, Unhandled)
HANDLE(ArraySelectOp, Unhandled)
HANDLE(YieldOp, Unhandled)
HANDLE(ExtractOp, Unhandled)
HANDLE(ApplyFuncOp, Unhandled)
HANDLE(DistinctOp, Unhandled)
HANDLE(IntDivOp, Unhandled)
HANDLE(BVCmpOp, Unhandled)
HANDLE(IntCmpOp, Unhandled)
HANDLE(PopOp, Unhandled)
HANDLE(XOrOp, Unhandled)
HANDLE(BVOrOp, Unhandled)
HANDLE(BVSModOp, Unhandled)
ResultType dispatchSMTOpVisitor(Operation *op, ExtraArgs... args)
Definition SMTVisitors.h:27
HANDLE(DeclareFunOp, Unhandled)
HANDLE(ArrayBroadcastOp, Unhandled)
This helps visit SMT types.
HANDLE(BoolType, Unhandled)
HANDLE(SortType, Unhandled)
HANDLE(BitVectorType, Unhandled)
ResultType visitUnhandledSMTType(Type type, ExtraArgs... args)
This callback is invoked on any SMT type that are not handled by the concrete visitor.
HANDLE(IntegerType, Unhandled)
ResultType dispatchSMTTypeVisitor(Type type, ExtraArgs... args)
HANDLE(SMTFuncType, Unhandled)
ResultType visitInvalidSMTType(Type type, ExtraArgs... args)
This callback is invoked on any non-expression types.
HANDLE(ArrayType, Unhandled)