19 #include "llvm/ADT/SmallString.h"
20 #include "llvm/ADT/TypeSwitch.h"
29 void PtrDialect::initialize() {
32 #include "mlir/Dialect/Ptr/IR/PtrOps.cpp.inc"
35 #define GET_ATTRDEF_LIST
36 #include "mlir/Dialect/Ptr/IR/PtrOpsAttrs.cpp.inc"
39 #define GET_TYPEDEF_LIST
40 #include "mlir/Dialect/Ptr/IR/PtrOpsTypes.cpp.inc"
56 FromPtrOp fromPtr = *
this;
57 while (fromPtr !=
nullptr) {
58 auto toPtr = dyn_cast_or_null<ToPtrOp>(fromPtr.getPtr().getDefiningOp());
61 if (!toPtr || toPtr.getPtr().getType() != fromPtr.getType())
63 Value md = fromPtr.getMetadata();
65 if (!fromPtr.getType().hasPtrMetadata()) {
66 ptrLike = toPtr.getPtr();
69 if (
auto mdOp = dyn_cast_or_null<GetMetadataOp>(md.
getDefiningOp());
70 mdOp && mdOp.getPtr() == toPtr.getPtr())
71 ptrLike = toPtr.getPtr();
74 fromPtr = dyn_cast_or_null<FromPtrOp>(ptrLike ? ptrLike.
getDefiningOp()
82 return emitError() <<
"the result type cannot be `!ptr.ptr`";
83 if (
getType().getMemorySpace() != getPtr().
getType().getMemorySpace()) {
85 <<
"expected the input and output to have the same memory space";
115 ToPtrOp toPtr = *
this;
116 while (toPtr !=
nullptr) {
117 auto fromPtr = dyn_cast_or_null<FromPtrOp>(toPtr.getPtr().getDefiningOp());
121 ptr = fromPtr.getPtr();
129 if (isa<PtrType>(getPtr().
getType()))
130 return emitError() <<
"the input value cannot be of type `!ptr.ptr`";
131 if (
getType().getMemorySpace() != getPtr().
getType().getMemorySpace()) {
133 <<
"expected the input and output to have the same memory space";
142 llvm::TypeSize TypeOffsetOp::getTypeSize(std::optional<DataLayout> layout) {
153 #include "mlir/Dialect/Ptr/IR/PtrOpsDialect.cpp.inc"
155 #define GET_ATTRDEF_CLASSES
156 #include "mlir/Dialect/Ptr/IR/PtrOpsAttrs.cpp.inc"
158 #include "mlir/Dialect/Ptr/IR/MemorySpaceInterfaces.cpp.inc"
160 #include "mlir/Dialect/Ptr/IR/MemorySpaceAttrInterfaces.cpp.inc"
162 #include "mlir/Dialect/Ptr/IR/PtrOpsEnums.cpp.inc"
164 #define GET_TYPEDEF_CLASSES
165 #include "mlir/Dialect/Ptr/IR/PtrOpsTypes.cpp.inc"
167 #define GET_OP_CLASSES
168 #include "mlir/Dialect/Ptr/IR/PtrOps.cpp.inc"
static Value getBase(Value v)
Looks through known "view-like" ops to find the base memref.
static Type getElementType(Type type, ArrayRef< int32_t > indices, function_ref< InFlightDiagnostic(StringRef)> emitErrorFn)
Walks the given type hierarchy with the given indices, potentially down to component granularity,...
Attributes are known-constant values of operations.
The main mechanism for performing data layout queries.
static DataLayout closest(Operation *op)
Returns the layout of the closest parent operation carrying layout info.
llvm::TypeSize getTypeSize(Type t) const
Returns the size of the given type in the current scope.
This class represents a single result from folding an operation.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Operation * getDefiningOp() const
If this value is the result of an operation, return the operation that defines it.
Include the generated interface declarations.
detail::constant_int_value_binder m_ConstantInt(IntegerAttr::ValueType *bind_value)
Matches a constant holding a scalar/vector/tensor integer (splat) and writes the integer value to bin...
Type getType(OpFoldResult ofr)
Returns the int type of the integer in ofr.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
LogicalResult verify(Operation *op, bool verifyRecursively=true)
Perform (potentially expensive) checks of invariants, used to detect compiler bugs,...
bool match(Attribute attr)