1//===- SMTTypes.td - SMT dialect types ---------------------*- tablegen -*-===//
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
7//===----------------------------------------------------------------------===//
9#ifndef MLIR_DIALECT_SMT_IR_SMTTYPES_TD
10#define MLIR_DIALECT_SMT_IR_SMTTYPES_TD
12include "llzk/Dialect/SMT/IR/SMTDialect.td"
13include "mlir/IR/AttrTypeBase.td"
15class SMTTypeDef<string name> : TypeDef<SMTDialect, name> {}
17def BoolType : SMTTypeDef<"Bool"> {
18 let mnemonic = "bool";
19 let assemblyFormat = "";
22def IntType : SMTTypeDef<"Int"> {
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
29 let assemblyFormat = "";
32def BitVectorType : SMTTypeDef<"BitVector"> {
35 This type represents the `(_ BitVec width)` sort as described in the
37 theory](https://smtlib.cs.uiowa.edu/theories-FixedSizeBitVectors.shtml).
39 The bit-width must be strictly greater than zero.
42 let parameters = (ins "int64_t":$width);
43 let assemblyFormat = "`<` $width `>`";
45 let genVerifyDecl = true;
48def ArrayType : SMTTypeDef<"Array"> {
49 let mnemonic = "array";
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.
57 let parameters = (ins "mlir::Type":$domainType, "mlir::Type":$rangeType);
58 let assemblyFormat = "`<` `[` $domainType `->` $rangeType `]` `>`";
60 let genVerifyDecl = true;
63def SMTFuncType : SMTTypeDef<"SMTFunc"> {
64 let mnemonic = "func";
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.
70 A function in SMT can have an arbitrary domain size, but always has exactly
73 Since SMT only supports first-order logic, it is not possible to nest
76 Example: `!smt.func<(!smt.bool, !smt.int) !smt.bool>` is equivalent to
77 `((Bool Int) Bool)` in SMT-LIB.
81 (ins ArrayRefParameter<"mlir::Type", "domain types">:$domainTypes,
82 "mlir::Type":$rangeType);
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
87 let assemblyFormat = "`<` `(` $domainTypes `)` ` ` $rangeType `>`";
89 let builders = [TypeBuilderWithInferredContext<
90 (ins "llvm::ArrayRef<mlir::Type>":$domainTypes,
91 "mlir::Type":$rangeType),
93 return $_get(rangeType.getContext(), domainTypes, rangeType);
95 TypeBuilderWithInferredContext<(ins "mlir::Type":$rangeType),
97 return $_get(rangeType.getContext(),
98 llvm::ArrayRef<mlir::Type>{}, rangeType);
101 let genVerifyDecl = true;
104def SortType : SMTTypeDef<"Sort"> {
105 let mnemonic = "sort";
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).
116 let parameters = (ins "mlir::StringAttr":$identifier,
117 OptionalArrayRefParameter<"mlir::Type", "sort parameters">:$sortParams);
119 let assemblyFormat = "`<` $identifier (`[` $sortParams^ `]`)? `>`";
121 let builders = [TypeBuilder<(ins "llvm::StringRef":$identifier,
122 "llvm::ArrayRef<mlir::Type>":$sortParams),
124 return $_get($_ctxt, mlir::StringAttr::get($_ctxt, identifier),
127 TypeBuilder<(ins "llvm::StringRef":$identifier), [{
128 return $_get($_ctxt, mlir::StringAttr::get($_ctxt, identifier),
129 llvm::ArrayRef<mlir::Type>{});
133 let genVerifyDecl = true;
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">;
142#endif // MLIR_DIALECT_SMT_IR_SMTTYPES_TD