|
| 1 | +//===-- MemorySpaceInterfaces.td - Memory space interfaces ----------------===// |
| 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 | +// This file defines memory space attribute interfaces. |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +#ifndef PTR_MEMORYSPACEINTERFACES |
| 14 | +#define PTR_MEMORYSPACEINTERFACES |
| 15 | + |
| 16 | +include "mlir/IR/AttrTypeBase.td" |
| 17 | +include "mlir/IR/OpBase.td" |
| 18 | + |
| 19 | +//===----------------------------------------------------------------------===// |
| 20 | +// Memory space attribute interface. |
| 21 | +//===----------------------------------------------------------------------===// |
| 22 | + |
| 23 | +def MemorySpaceAttrInterface : AttrInterface<"MemorySpaceAttrInterface"> { |
| 24 | + let description = [{ |
| 25 | + This interface defines a common API for interacting with the memory model of |
| 26 | + a memory space and the operations in the pointer dialect, giving proper |
| 27 | + semantical meaning to the ops. |
| 28 | + |
| 29 | + Furthermore, this interface allows concepts such as read-only memory to be |
| 30 | + adequately modeled and enforced. |
| 31 | + }]; |
| 32 | + let cppNamespace = "::mlir::ptr"; |
| 33 | + let methods = [ |
| 34 | + InterfaceMethod< |
| 35 | + /*desc=*/ [{ |
| 36 | + Returns the default memory space as an attribute. |
| 37 | + }], |
| 38 | + /*returnType=*/ "::mlir::ptr::MemorySpaceAttrInterface", |
| 39 | + /*methodName=*/ "getDefaultMemorySpace", |
| 40 | + /*args=*/ (ins), |
| 41 | + /*methodBody=*/ [{}], |
| 42 | + /*defaultImpl=*/ [{}] |
| 43 | + >, |
| 44 | + InterfaceMethod< |
| 45 | + /*desc=*/ [{ |
| 46 | + This method checks if it's valid to load a value from the memory space |
| 47 | + with a specific type, alignment, and atomic ordering. |
| 48 | + If `emitError` is non-null then the method is allowed to emit errors. |
| 49 | + }], |
| 50 | + /*returnType=*/ "::mlir::LogicalResult", |
| 51 | + /*methodName=*/ "isValidLoad", |
| 52 | + /*args=*/ (ins "::mlir::Type":$type, |
| 53 | + "::mlir::ptr::AtomicOrdering":$ordering, |
| 54 | + "::mlir::IntegerAttr":$alignment, |
| 55 | + "::llvm::function_ref<::mlir::InFlightDiagnostic()>":$emitError), |
| 56 | + /*methodBody=*/ [{}], |
| 57 | + /*defaultImpl=*/ [{}] |
| 58 | + >, |
| 59 | + InterfaceMethod< |
| 60 | + /*desc=*/ [{ |
| 61 | + This method checks if it's valid to store a value in the memory space |
| 62 | + with a specific type, alignment, and atomic ordering. |
| 63 | + If `emitError` is non-null then the method is allowed to emit errors. |
| 64 | + }], |
| 65 | + /*returnType=*/ "::mlir::LogicalResult", |
| 66 | + /*methodName=*/ "isValidStore", |
| 67 | + /*args=*/ (ins "::mlir::Type":$type, |
| 68 | + "::mlir::ptr::AtomicOrdering":$ordering, |
| 69 | + "::mlir::IntegerAttr":$alignment, |
| 70 | + "::llvm::function_ref<::mlir::InFlightDiagnostic()>":$emitError), |
| 71 | + /*methodBody=*/ [{}], |
| 72 | + /*defaultImpl=*/ [{}] |
| 73 | + >, |
| 74 | + InterfaceMethod< |
| 75 | + /*desc=*/ [{ |
| 76 | + This method checks if it's valid to perform an atomic operation in the |
| 77 | + memory space with a specific type, alignment, and atomic ordering. |
| 78 | + If `emitError` is non-null then the method is allowed to emit errors. |
| 79 | + }], |
| 80 | + /*returnType=*/ "::mlir::LogicalResult", |
| 81 | + /*methodName=*/ "isValidAtomicOp", |
| 82 | + /*args=*/ (ins "::mlir::ptr::AtomicBinOp":$op, |
| 83 | + "::mlir::Type":$type, |
| 84 | + "::mlir::ptr::AtomicOrdering":$ordering, |
| 85 | + "::mlir::IntegerAttr":$alignment, |
| 86 | + "::llvm::function_ref<::mlir::InFlightDiagnostic()>":$emitError), |
| 87 | + /*methodBody=*/ [{}], |
| 88 | + /*defaultImpl=*/ [{}] |
| 89 | + >, |
| 90 | + InterfaceMethod< |
| 91 | + /*desc=*/ [{ |
| 92 | + This method checks if it's valid to perform an atomic exchange operation |
| 93 | + in the memory space with a specific type, alignment, and atomic |
| 94 | + orderings. |
| 95 | + If `emitError` is non-null then the method is allowed to emit errors. |
| 96 | + }], |
| 97 | + /*returnType=*/ "::mlir::LogicalResult", |
| 98 | + /*methodName=*/ "isValidAtomicXchg", |
| 99 | + /*args=*/ (ins "::mlir::Type":$type, |
| 100 | + "::mlir::ptr::AtomicOrdering":$successOrdering, |
| 101 | + "::mlir::ptr::AtomicOrdering":$failureOrdering, |
| 102 | + "::mlir::IntegerAttr":$alignment, |
| 103 | + "::llvm::function_ref<::mlir::InFlightDiagnostic()>":$emitError), |
| 104 | + /*methodBody=*/ [{}], |
| 105 | + /*defaultImpl=*/ [{}] |
| 106 | + >, |
| 107 | + InterfaceMethod< |
| 108 | + /*desc=*/ [{ |
| 109 | + This method checks if it's valid to perform an `addrspacecast` op |
| 110 | + in the memory space. |
| 111 | + Both types are expected to be vectors of rank 1, or scalars of `ptr` |
| 112 | + type. |
| 113 | + If `emitError` is non-null then the method is allowed to emit errors. |
| 114 | + }], |
| 115 | + /*returnType=*/ "::mlir::LogicalResult", |
| 116 | + /*methodName=*/ "isValidAddrSpaceCast", |
| 117 | + /*args=*/ (ins "::mlir::Type":$tgt, |
| 118 | + "::mlir::Type":$src, |
| 119 | + "::llvm::function_ref<::mlir::InFlightDiagnostic()>":$emitError), |
| 120 | + /*methodBody=*/ [{}], |
| 121 | + /*defaultImpl=*/ [{}] |
| 122 | + >, |
| 123 | + InterfaceMethod< |
| 124 | + /*desc=*/ [{ |
| 125 | + This method checks if it's valid to perform a `ptrtoint` or `inttoptr` |
| 126 | + op in the memory space. `CastValidity::InvalidSourceType` always refers |
| 127 | + to the 'ptr-like' type and `CastValidity::InvalidTargetType` always |
| 128 | + refers to the `int-like` type. |
| 129 | + The first type is expected to be integer-like, while the second must be a |
| 130 | + ptr-like type. |
| 131 | + If `emitError` is non-null then the method is allowed to emit errors. |
| 132 | + }], |
| 133 | + /*returnType=*/ "::mlir::LogicalResult", |
| 134 | + /*methodName=*/ "isValidPtrIntCast", |
| 135 | + /*args=*/ (ins "::mlir::Type":$intLikeTy, |
| 136 | + "::mlir::Type":$ptrLikeTy, |
| 137 | + "::llvm::function_ref<::mlir::InFlightDiagnostic()>":$emitError), |
| 138 | + /*methodBody=*/ [{}], |
| 139 | + /*defaultImpl=*/ [{}] |
| 140 | + >, |
| 141 | + ]; |
| 142 | +} |
| 143 | + |
| 144 | +def MemorySpaceOpInterface : OpInterface<"MemorySpaceOpInterface"> { |
| 145 | + let description = [{ |
| 146 | + An interface for operations with a memory space. |
| 147 | + }]; |
| 148 | + |
| 149 | + let cppNamespace = "::mlir::ptr"; |
| 150 | + |
| 151 | + let methods = [ |
| 152 | + InterfaceMethod< |
| 153 | + /*desc=*/ "Returns the memory space of the op.", |
| 154 | + /*returnType=*/ "::mlir::ptr::MemorySpaceAttrInterface", |
| 155 | + /*methodName=*/ "getMemorySpace", |
| 156 | + /*args=*/ (ins), |
| 157 | + /*methodBody=*/ [{}], |
| 158 | + /*defaultImpl=*/ [{}] |
| 159 | + >, |
| 160 | + ]; |
| 161 | +} |
| 162 | +#endif // PTR_MEMORYSPACEINTERFACES |
0 commit comments