|
11 | 11 |
|
12 | 12 | include "mlir/Dialect/Ptr/IR/PtrDialect.td" |
13 | 13 | include "mlir/Dialect/Ptr/IR/PtrAttrDefs.td" |
| 14 | +include "mlir/Dialect/Ptr/IR/PtrEnums.td" |
14 | 15 | include "mlir/Dialect/Ptr/IR/MemorySpaceInterfaces.td" |
| 16 | +include "mlir/Interfaces/SideEffectInterfaces.td" |
| 17 | +include "mlir/Interfaces/ViewLikeInterface.td" |
15 | 18 | include "mlir/IR/OpAsmInterface.td" |
16 | 19 |
|
| 20 | +//===----------------------------------------------------------------------===// |
| 21 | +// PtrAddOp |
| 22 | +//===----------------------------------------------------------------------===// |
| 23 | + |
| 24 | +def Ptr_PtrAddOp : Pointer_Op<"ptr_add", [ |
| 25 | + Pure, AllTypesMatch<["base", "result"]>, ViewLikeOpInterface |
| 26 | + ]> { |
| 27 | + let summary = "Pointer add operation"; |
| 28 | + let description = [{ |
| 29 | + The `ptr_add` operation adds an integer offset to a pointer to produce a new |
| 30 | + pointer. The input and output pointer types are always the same. |
| 31 | + |
| 32 | + Example: |
| 33 | + |
| 34 | + ```mlir |
| 35 | + %x_off = ptr.ptr_add %x, %off : !ptr.ptr<0>, i32 |
| 36 | + %x_off0 = ptr.ptr_add nusw %x, %off : !ptr.ptr<0>, i32 |
| 37 | + ``` |
| 38 | + }]; |
| 39 | + |
| 40 | + let arguments = (ins |
| 41 | + Ptr_PtrType:$base, |
| 42 | + AnySignlessIntegerOrIndex:$offset, |
| 43 | + DefaultValuedProp<EnumProp<Ptr_PtrAddFlags>, "PtrAddFlags::none">:$flags); |
| 44 | + let results = (outs Ptr_PtrType:$result); |
| 45 | + let assemblyFormat = [{ |
| 46 | + ($flags^)? $base `,` $offset attr-dict `:` type($base) `,` type($offset) |
| 47 | + }]; |
| 48 | + let hasFolder = 1; |
| 49 | + let extraClassDeclaration = [{ |
| 50 | + /// `ViewLikeOp::getViewSource` method. |
| 51 | + Value getViewSource() { return getBase(); } |
| 52 | + }]; |
| 53 | +} |
| 54 | + |
| 55 | +//===----------------------------------------------------------------------===// |
| 56 | +// TypeOffsetOp |
| 57 | +//===----------------------------------------------------------------------===// |
| 58 | + |
| 59 | +def Ptr_TypeOffsetOp : Pointer_Op<"type_offset", [Pure]> { |
| 60 | + let summary = "Type offset operation"; |
| 61 | + let description = [{ |
| 62 | + The `type_offset` operation produces an int or index-typed SSA value |
| 63 | + equal to a target-specific constant representing the offset of a single |
| 64 | + element of the given type. |
| 65 | + |
| 66 | + Example: |
| 67 | + |
| 68 | + ```mlir |
| 69 | + // Return the offset between two f32 stored in memory |
| 70 | + %0 = ptr.type_offset f32 : index |
| 71 | + // Return the offset between two memref descriptors stored in memory |
| 72 | + %1 = ptr.type_offset memref<12 x f64> : i32 |
| 73 | + ``` |
| 74 | + }]; |
| 75 | + |
| 76 | + let arguments = (ins TypeAttr:$elementType); |
| 77 | + let results = (outs AnySignlessIntegerOrIndex:$result); |
| 78 | + let builders = [ |
| 79 | + OpBuilder<(ins "Type":$elementType)> |
| 80 | + ]; |
| 81 | + let assemblyFormat = [{ |
| 82 | + $elementType attr-dict `:` type($result) |
| 83 | + }]; |
| 84 | + let extraClassDeclaration = [{ |
| 85 | + /// Returns the type offset according to `layout`. If `layout` is `nullopt` |
| 86 | + /// the nearest layout the op will be used for the computation. |
| 87 | + llvm::TypeSize getTypeSize(std::optional<DataLayout> layout = std::nullopt); |
| 88 | + }]; |
| 89 | +} |
| 90 | + |
17 | 91 | #endif // PTR_OPS |
0 commit comments