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