LLZK 2.0.0
An open-source IR for Zero Knowledge (ZK) circuits
Loading...
Searching...
No Matches
SMTIntOps.td
Go to the documentation of this file.
1//===- SMTIntOps.td - SMT dialect int theory operations ----*- 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_SMTINTOPS_TD
10#define MLIR_DIALECT_SMT_IR_SMTINTOPS_TD
11
12include "llzk/Dialect/SMT/IR/SMTDialect.td"
13include "llzk/Dialect/SMT/IR/SMTAttributes.td"
14include "llzk/Dialect/SMT/IR/SMTTypes.td"
15include "mlir/IR/EnumAttr.td"
16include "mlir/IR/OpAsmInterface.td"
17include "mlir/Interfaces/SideEffectInterfaces.td"
18
19class SMTIntOp<string mnemonic, list<Trait> traits = []>
20 : SMTOp<"int."#mnemonic, traits>;
21
22def IntConstantOp
23 : SMTIntOp<"constant", [Pure, ConstantLike,
24 DeclareOpInterfaceMethods<
25 OpAsmOpInterface, ["getAsmResultNames"]>,
26]> {
27 let summary = "produce a constant (infinite-precision) integer";
28 let description = [{
29 This operation represents (infinite-precision) integer literals of the `Int`
30 sort. The set of values for the sort `Int` consists of all numerals and
31 all terms of the form `-n`where n is a numeral other than 0. For more
32 information refer to the
33 [SMT Ints theory](https://smtlib.cs.uiowa.edu/Theories/Ints.smt2) of the
34 SMT-LIB 2.7 standard.
35 }];
36
37 let arguments = (ins APIntAttr:$value);
38 let results = (outs IntType:$result);
39
40 let hasCustomAssemblyFormat = true;
41 let hasFolder = true;
42}
43
44class VariadicIntOp<string mnemonic> : SMTIntOp<mnemonic, [Pure, Commutative]> {
45 let description = [{
46 This operation represents (infinite-precision) }]#summary#[{.
47 The semantics are equivalent to the corresponding operator described in
48 the [SMT Ints theory](https://smtlib.cs.uiowa.edu/Theories/Ints.smt2) of the
49 SMT-LIB 2.7 standard.
50 }];
51
52 let arguments = (ins Variadic<IntType>:$inputs);
53 let results = (outs IntType:$result);
54 let assemblyFormat = "$inputs attr-dict";
55}
56
57class BinaryIntOp<string mnemonic> : SMTIntOp<mnemonic, [Pure]> {
58 let description = [{
59 This operation represents (infinite-precision) }]#summary#[{.
60 The semantics are equivalent to the corresponding operator described in
61 the [SMT Ints theory](https://smtlib.cs.uiowa.edu/Theories/Ints.smt2) of the
62 SMT-LIB 2.7 standard.
63 }];
64
65 let arguments = (ins IntType:$lhs, IntType:$rhs);
66 let results = (outs IntType:$result);
67 let assemblyFormat = "$lhs `,` $rhs attr-dict";
68}
69
70def IntAbsOp : SMTIntOp<"abs", [Pure]> {
71 let summary = "the absolute value of an Int";
72 let description = [{
73 This operation represents the absolute value function for the `Int` sort.
74 The semantics are equivalent to the `abs` operator as described in the
75 [SMT Ints theory](https://smtlib.cs.uiowa.edu/Theories/Ints.smt2) of the
76 SMT-LIB 2.7 standard.
77 }];
78
79 let arguments = (ins IntType:$input);
80 let results = (outs IntType:$result);
81 let assemblyFormat = "$input attr-dict";
82}
83
84def IntNegOp : SMTIntOp<"neg", [Pure]> {
85 let summary = "the negation of an Int";
86 let description =
87 "This operation represents unary negation for the `Int` sort.";
88 let arguments = (ins IntType:$input);
89 let results = (outs IntType:$result);
90 let assemblyFormat = "$input attr-dict";
91}
92
93def IntAddOp : VariadicIntOp<"add"> { let summary = "integer addition"; }
94def IntMulOp : VariadicIntOp<"mul"> { let summary = "integer multiplication"; }
95def IntSubOp : BinaryIntOp<"sub"> { let summary = "integer subtraction"; }
96def IntDivOp : BinaryIntOp<"div"> { let summary = "integer division"; }
97def IntModOp : BinaryIntOp<"mod"> { let summary = "integer remainder"; }
98
99def IntPredicateLT : I64EnumAttrCase<"lt", 0>;
100def IntPredicateLE : I64EnumAttrCase<"le", 1>;
101def IntPredicateGT : I64EnumAttrCase<"gt", 2>;
102def IntPredicateGE : I64EnumAttrCase<"ge", 3>;
103let cppNamespace = "::llzk::smt" in def IntPredicate
104 : I64EnumAttr<"IntPredicate", "smt comparison predicate for integers",
105 [IntPredicateLT, IntPredicateLE, IntPredicateGT,
106 IntPredicateGE]>;
107
108def IntCmpOp : SMTIntOp<"cmp", [Pure]> {
109 let summary = "integer comparison";
110 let description = [{
111 This operation represents the comparison of (infinite-precision) integers.
112 The semantics are equivalent to the `<= (le)`, `< (lt)`, `>= (ge)`, or
113 `> (gt)` operator depending on the predicate (indicated in parentheses) as
114 described in the
115 [SMT Ints theory](https://smtlib.cs.uiowa.edu/Theories/Ints.smt2) of the
116 SMT-LIB 2.7 standard.
117 }];
118
119 let arguments = (ins IntPredicate:$pred, IntType:$lhs, IntType:$rhs);
120 let results = (outs BoolType:$result);
121 let assemblyFormat = "$pred $lhs `,` $rhs attr-dict";
122}
123
124def Int2BVOp : SMTOp<"int2bv", [Pure]> {
125 let summary = "Convert an integer to an inferred-width bitvector.";
126 let description = [{
127 Designed to lower directly to an operation of the same name in Z3. The Z3
128 C API describes the semantics as follows:
129 Create an n bit bit-vector from the integer argument t1.
130 The resulting bit-vector has n bits, where the i'th bit (counting from 0
131 to n-1) is 1 if (t1 div 2^i) mod 2 is 1.
132 The node t1 must have integer sort.
133 }];
134 let arguments = (ins IntType:$input);
135 let results = (outs BitVectorType:$result);
136 let assemblyFormat = "$input attr-dict `:` qualified(type($result))";
137}
138
139#endif // MLIR_DIALECT_SMT_IR_SMTINTOPS_TD