LLZK 2.0.0
An open-source IR for Zero Knowledge (ZK) circuits
Loading...
Searching...
No Matches
SMTArrayOps.td
Go to the documentation of this file.
1//===- SMTArrayOps.td - SMT array 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_SMTARRAYOPS_TD
10#define MLIR_DIALECT_SMT_IR_SMTARRAYOPS_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/Interfaces/SideEffectInterfaces.td"
16
17class SMTArrayOp<string mnemonic, list<Trait> traits = []>
18 : SMTOp<"array."#mnemonic, traits>;
19
20def ArrayStoreOp
21 : SMTArrayOp<
22 "store", [Pure,
23 TypesMatchWith<"summary", "array", "index",
24 "cast<ArrayType>($_self).getDomainType()">,
25 TypesMatchWith<"summary", "array", "value",
26 "cast<ArrayType>($_self).getRangeType()">,
27 AllTypesMatch<["array", "result"]>,
28]> {
29 let summary = "stores a value at a given index and returns the new array";
30 let description = [{
31 This operation returns a new array which is the same as the 'array' operand
32 except that the value at the given 'index' is changed to the given 'value'.
33 The semantics are equivalent to the 'store' operator described in the
34 [SMT ArrayEx theory](https://smtlib.cs.uiowa.edu/Theories/ArraysEx.smt2) of
35 the SMT-LIB standard 2.7.
36 }];
37
38 let arguments = (ins ArrayType:$array, AnySMTType:$index, AnySMTType:$value);
39 let results = (outs ArrayType:$result);
40
41 let assemblyFormat = [{
42 $array `[` $index `]` `,` $value attr-dict `:` qualified(type($array))
43 }];
44}
45
46def ArraySelectOp
47 : SMTArrayOp<
48 "select", [Pure,
49 TypesMatchWith<"summary", "array", "index",
50 "cast<ArrayType>($_self).getDomainType()">,
51 TypesMatchWith<"summary", "array", "result",
52 "cast<ArrayType>($_self).getRangeType()">,
53]> {
54 let summary = "get the value stored in the array at the given index";
55 let description = [{
56 This operation is retuns the value stored in the given array at the given
57 index. The semantics are equivalent to the `select` operator defined in the
58 [SMT ArrayEx theory](https://smtlib.cs.uiowa.edu/Theories/ArraysEx.smt2) of
59 the SMT-LIB standard 2.7.
60 }];
61
62 let arguments = (ins ArrayType:$array, AnySMTType:$index);
63 let results = (outs AnySMTType:$result);
64
65 let assemblyFormat = [{
66 $array `[` $index `]` attr-dict `:` qualified(type($array))
67 }];
68}
69
70def ArrayBroadcastOp
71 : SMTArrayOp<"broadcast", [Pure,
72 TypesMatchWith<
73 "summary", "result", "value",
74 "cast<ArrayType>($_self).getRangeType()">,
75]> {
76 let summary = "construct an array with the given value stored at every index";
77 let description = [{
78 This operation represents a broadcast of the 'value' operand to all indices
79 of the array. It is equivalent to
80 ```
81 %0 = smt.declare_fun "array" : !smt.array<[!smt.int -> !smt.bool]>
82 %1 = smt.forall ["idx"] {
83 ^bb0(%idx: !smt.int):
84 %2 = smt.array.select %0[%idx] : !smt.array<[!smt.int -> !smt.bool]>
85 %3 = smt.eq %value, %2 : !smt.bool
86 smt.yield %3 : !smt.bool
87 }
88 smt.assert %1
89 // return %0
90 ```
91
92 In SMT-LIB, this is frequently written as
93 `((as const (Array Int Bool)) value)`.
94 }];
95
96 let arguments = (ins AnySMTType:$value);
97 let results = (outs ArrayType:$result);
98
99 let assemblyFormat = "$value attr-dict `:` qualified(type($result))";
100}
101
102#endif // MLIR_DIALECT_SMT_IR_SMTARRAYOPS_TD