LLZK 2.0.0
An open-source IR for Zero Knowledge (ZK) circuits
Loading...
Searching...
No Matches
SMTTypes.td
Go to the documentation of this file.
1//===- SMTTypes.td - SMT dialect types ---------------------*- tablegen -*-===//
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#ifndef MLIR_DIALECT_SMT_IR_SMTTYPES_TD
10#define MLIR_DIALECT_SMT_IR_SMTTYPES_TD
11
12include "llzk/Dialect/SMT/IR/SMTDialect.td"
13include "mlir/IR/AttrTypeBase.td"
14
15class SMTTypeDef<string name> : TypeDef<SMTDialect, name> {}
16
17def BoolType : SMTTypeDef<"Bool"> {
18 let mnemonic = "bool";
19 let assemblyFormat = "";
20}
21
22def IntType : SMTTypeDef<"Int"> {
23 let mnemonic = "int";
24 let description = [{
25 This type represents the `Int` sort as described in the
26 [SMT Ints theory](https://smtlib.cs.uiowa.edu/Theories/Ints.smt2) of the
27 SMT-LIB 2.7 standard.
28 }];
29 let assemblyFormat = "";
30}
31
32def BitVectorType : SMTTypeDef<"BitVector"> {
33 let mnemonic = "bv";
34 let description = [{
35 This type represents the `(_ BitVec width)` sort as described in the
36 [SMT bit-vector
37 theory](https://smtlib.cs.uiowa.edu/theories-FixedSizeBitVectors.shtml).
38
39 The bit-width must be strictly greater than zero.
40 }];
41
42 let parameters = (ins "int64_t":$width);
43 let assemblyFormat = "`<` $width `>`";
44
45 let genVerifyDecl = true;
46}
47
48def ArrayType : SMTTypeDef<"Array"> {
49 let mnemonic = "array";
50 let description = [{
51 This type represents the `(Array X Y)` sort, where X and Y are any
52 sort/type, as described in the
53 [SMT ArrayEx theory](https://smtlib.cs.uiowa.edu/Theories/ArraysEx.smt2) of
54 the SMT-LIB standard 2.7.
55 }];
56
57 let parameters = (ins "mlir::Type":$domainType, "mlir::Type":$rangeType);
58 let assemblyFormat = "`<` `[` $domainType `->` $rangeType `]` `>`";
59
60 let genVerifyDecl = true;
61}
62
63def SMTFuncType : SMTTypeDef<"SMTFunc"> {
64 let mnemonic = "func";
65 let description = [{
66 This type represents the SMT function sort as described in the
67 [SMT-LIB 2.7 standard](https://smt-lib.org/papers/smt-lib-reference-v2.7-r2025-02-05.pdf).
68 It is part of the language itself rather than a theory or logic.
69
70 A function in SMT can have an arbitrary domain size, but always has exactly
71 one range sort.
72
73 Since SMT only supports first-order logic, it is not possible to nest
74 function types.
75
76 Example: `!smt.func<(!smt.bool, !smt.int) !smt.bool>` is equivalent to
77 `((Bool Int) Bool)` in SMT-LIB.
78 }];
79
80 let parameters =
81 (ins ArrayRefParameter<"mlir::Type", "domain types">:$domainTypes,
82 "mlir::Type":$rangeType);
83
84 // Note: We are not printing the parentheses when no domain type is present
85 // because the default MLIR parser thinks it is a builtin function type
86 // otherwise.
87 let assemblyFormat = "`<` `(` $domainTypes `)` ` ` $rangeType `>`";
88
89 let builders = [TypeBuilderWithInferredContext<
90 (ins "llvm::ArrayRef<mlir::Type>":$domainTypes,
91 "mlir::Type":$rangeType),
92 [{
93 return $_get(rangeType.getContext(), domainTypes, rangeType);
94 }]>,
95 TypeBuilderWithInferredContext<(ins "mlir::Type":$rangeType),
96 [{
97 return $_get(rangeType.getContext(),
98 llvm::ArrayRef<mlir::Type>{}, rangeType);
99 }]>];
100
101 let genVerifyDecl = true;
102}
103
104def SortType : SMTTypeDef<"Sort"> {
105 let mnemonic = "sort";
106 let description = [{
107 This type represents uninterpreted sorts. The usage of a type like
108 `!smt.sort<"sort_name"[!smt.bool, !smt.sort<"other_sort">]>` implies a
109 `declare-sort sort_name 2` and a `declare-sort other_sort 0` in SMT-LIB.
110 This type represents concrete use-sites of such declared sorts, in this
111 particular case it would be equivalent to `(sort_name Bool other_sort)` in
112 SMT-LIB. More details about the semantics can be found in the
113 [SMT-LIB 2.7 standard](https://smt-lib.org/papers/smt-lib-reference-v2.7-r2025-02-05.pdf).
114 }];
115
116 let parameters = (ins "mlir::StringAttr":$identifier,
117 OptionalArrayRefParameter<"mlir::Type", "sort parameters">:$sortParams);
118
119 let assemblyFormat = "`<` $identifier (`[` $sortParams^ `]`)? `>`";
120
121 let builders = [TypeBuilder<(ins "llvm::StringRef":$identifier,
122 "llvm::ArrayRef<mlir::Type>":$sortParams),
123 [{
124 return $_get($_ctxt, mlir::StringAttr::get($_ctxt, identifier),
125 sortParams);
126 }]>,
127 TypeBuilder<(ins "llvm::StringRef":$identifier), [{
128 return $_get($_ctxt, mlir::StringAttr::get($_ctxt, identifier),
129 llvm::ArrayRef<mlir::Type>{});
130 }]>,
131 ];
132
133 let genVerifyDecl = true;
134}
135
136def AnySMTType
137 : Type<CPred<"smt::isAnySMTValueType($_self)">, "any SMT value type">;
138def AnyNonFuncSMTType : Type<CPred<"smt::isAnyNonFuncSMTValueType($_self)">,
139 "any non-function SMT value type">;
140def AnyNonSMTType : Type<Neg<AnySMTType.predicate>, "any non-smt type">;
141
142#endif // MLIR_DIALECT_SMT_IR_SMTTYPES_TD