31 if (alignment.value() <= 0)
32 return emitError() <<
"alignment must be positive";
33 if (!llvm::isPowerOf2_64(alignment.value()))
34 return emitError() <<
"alignment must be a power of 2";
42OpFoldResult ConstantOp::fold(FoldAdaptor adaptor) {
return getValue(); }
56 FromPtrOp fromPtr = *
this;
57 while (fromPtr !=
nullptr) {
58 auto toPtr = fromPtr.getPtr().getDefiningOp<ToPtrOp>();
61 if (!toPtr || toPtr.getPtr().getType() != fromPtr.getType())
63 Value md = fromPtr.getMetadata();
65 if (!fromPtr.getType().hasPtrMetadata()) {
66 ptrLike = toPtr.getPtr();
70 mdOp && mdOp.getPtr() == toPtr.getPtr())
71 ptrLike = toPtr.getPtr();
79LogicalResult FromPtrOp::verify() {
81 return emitError() <<
"the result type cannot be `!ptr.ptr`";
82 if (
getType().getMemorySpace() != getPtr().
getType().getMemorySpace()) {
84 <<
"expected the input and output to have the same memory space";
93void GatherOp::getEffects(
100LogicalResult GatherOp::verify() {
104 MemorySpaceAttrInterface ms =
107 if (!ms.isValidLoad(getResult().
getType(), AtomicOrdering::not_atomic,
108 getAlignment(), &dataLayout,
emitDiag))
117 unsigned alignment) {
118 build(builder, state, resultType, ptrs, mask, passthrough,
119 alignment ? std::optional<int64_t>(alignment) : std::nullopt);
127template <
typename OpTy>
130 if (memOp.getOrdering() != AtomicOrdering::not_atomic) {
131 if (llvm::is_contained(unsupportedOrderings, memOp.getOrdering()))
132 return memOp.emitOpError(
"unsupported ordering '")
133 << stringifyAtomicOrdering(memOp.getOrdering()) <<
"'";
134 if (!memOp.getAlignment())
135 return memOp.emitOpError(
"expected alignment for atomic access");
138 if (memOp.getSyncscope()) {
139 return memOp.emitOpError(
140 "expected syncscope to be null for non-atomic access");
145void LoadOp::getEffects(
154 if (getVolatile_() || (getOrdering() != AtomicOrdering::not_atomic &&
155 getOrdering() != AtomicOrdering::unordered)) {
161LogicalResult LoadOp::verify() {
163 MemorySpaceAttrInterface ms = getPtr().getType().getMemorySpace();
165 if (!ms.isValidLoad(getResult().
getType(), getOrdering(), getAlignment(),
171 {AtomicOrdering::release, AtomicOrdering::acq_rel});
175 Value addr,
unsigned alignment,
bool isVolatile,
176 bool isNonTemporal,
bool isInvariant,
bool isInvariantGroup,
177 AtomicOrdering ordering, StringRef syncscope) {
178 build(builder, state, type, addr,
179 alignment ? std::optional<int64_t>(alignment) : std::nullopt,
180 isVolatile, isNonTemporal, isInvariant, isInvariantGroup, ordering,
181 syncscope.empty() ?
nullptr : builder.
getStringAttr(syncscope));
187void MaskedLoadOp::getEffects(
194LogicalResult MaskedLoadOp::verify() {
197 MemorySpaceAttrInterface ms = getPtr().getType().getMemorySpace();
199 if (!ms.isValidLoad(getResult().
getType(), AtomicOrdering::not_atomic,
200 getAlignment(), &dataLayout,
emitDiag))
209 Value passthrough,
unsigned alignment) {
210 build(builder, state, resultType,
ptr, mask, passthrough,
211 alignment ? std::optional<int64_t>(alignment) : std::nullopt);
218void MaskedStoreOp::getEffects(
225LogicalResult MaskedStoreOp::verify() {
228 MemorySpaceAttrInterface ms = getPtr().getType().getMemorySpace();
230 if (!ms.isValidStore(getValue().
getType(), AtomicOrdering::not_atomic,
231 getAlignment(), &dataLayout,
emitDiag))
240 unsigned alignment) {
241 build(builder, state, value,
ptr, mask,
242 alignment ? std::optional<int64_t>(alignment) : std::nullopt);
249void ScatterOp::getEffects(
256LogicalResult ScatterOp::verify() {
260 MemorySpaceAttrInterface ms =
263 if (!ms.isValidStore(getValue().
getType(), AtomicOrdering::not_atomic,
264 getAlignment(), &dataLayout,
emitDiag))
273 build(builder, state, value, ptrs, mask,
274 alignment ? std::optional<int64_t>(alignment) : std::nullopt);
281void StoreOp::getEffects(
290 if (getVolatile_() || (getOrdering() != AtomicOrdering::not_atomic &&
291 getOrdering() != AtomicOrdering::unordered)) {
297LogicalResult StoreOp::verify() {
299 MemorySpaceAttrInterface ms = getPtr().getType().getMemorySpace();
301 if (!ms.isValidStore(getValue().
getType(), getOrdering(), getAlignment(),
307 {AtomicOrdering::acquire, AtomicOrdering::acq_rel});
311 Value addr,
unsigned alignment,
bool isVolatile,
312 bool isNonTemporal,
bool isInvariantGroup,
313 AtomicOrdering ordering, StringRef syncscope) {
314 build(builder, state, value, addr,
315 alignment ? std::optional<int64_t>(alignment) : std::nullopt,
316 isVolatile, isNonTemporal, isInvariantGroup, ordering,
317 syncscope.empty() ?
nullptr : builder.
getStringAttr(syncscope));
335LogicalResult PtrAddOp::inferReturnTypes(
343 auto offTy = dyn_cast<ShapedType>(offsetType);
346 inferredReturnTypes.push_back(baseType);
349 auto baseTy = dyn_cast<ShapedType>(baseType);
353 inferredReturnTypes.push_back(offTy.clone(baseType));
358 if (offTy.getShape() != baseTy.getShape()) {
370 inferredReturnTypes.push_back(baseType);
378LogicalResult PtrDiffOp::verify() {
380 if (!isa<ShapedType>(getLhs().
getType()))
385 if (getResult().
getType().getTypeID() != getLhs().
getType().getTypeID()) {
386 return emitError() <<
"expected the result to have the same container "
387 "type as the operands when operands are shaped";
393ptr::PtrType PtrDiffOp::getPtrType() {
394 Type lhsType = getLhs().getType();
395 if (
auto shapedType = dyn_cast<ShapedType>(lhsType))
396 return cast<ptr::PtrType>(shapedType.getElementType());
397 return cast<ptr::PtrType>(lhsType);
400Type PtrDiffOp::getIntType() {
401 Type resultType = getResult().getType();
402 if (
auto shapedType = dyn_cast<ShapedType>(resultType))
403 return shapedType.getElementType();
418 ToPtrOp toPtr = *
this;
419 while (toPtr !=
nullptr) {
420 auto fromPtr = toPtr.getPtr().getDefiningOp<FromPtrOp>();
424 ptr = fromPtr.getPtr();
426 toPtr =
ptr.getDefiningOp<ToPtrOp>();
431LogicalResult ToPtrOp::verify() {
432 if (isa<PtrType>(getPtr().
getType()))
433 return emitError() <<
"the input value cannot be of type `!ptr.ptr`";
434 if (
getType().getMemorySpace() != getPtr().
getType().getMemorySpace()) {
436 <<
"expected the input and output to have the same memory space";
445llvm::TypeSize TypeOffsetOp::getTypeSize(std::optional<DataLayout> layout) {
455#include "mlir/Dialect/Ptr/IR/PtrOpsDialect.cpp.inc"
457#define GET_ATTRDEF_CLASSES
458#include "mlir/Dialect/Ptr/IR/PtrOpsAttrs.cpp.inc"
460#include "mlir/Dialect/Ptr/IR/PtrOpsEnums.cpp.inc"
462#define GET_TYPEDEF_CLASSES
463#include "mlir/Dialect/Ptr/IR/PtrOpsTypes.cpp.inc"
465#define GET_OP_CLASSES
466#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 InFlightDiagnostic emitDiag(Location location, DiagnosticSeverity severity, const Twine &message)
Helper function used to emit a diagnostic with an optionally empty twine message.
static LogicalResult verifyAtomicMemOp(OpTy memOp, ArrayRef< AtomicOrdering > unsupportedOrderings)
Verifies the attributes and the type of atomic memory access operations.
static LogicalResult verifyAlignment(std::optional< int64_t > alignment, function_ref< InFlightDiagnostic()> emitError)
Verifies that the alignment attribute is a power of 2 if present.
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.
StringAttr getStringAttr(const Twine &bytes)
The main mechanism for performing data layout queries.
static DataLayout closest(Operation *op)
Returns the layout of the closest parent operation carrying layout info.
This class represents a diagnostic that is inflight and set to be reported.
MLIRContext is the top-level object for a collection of MLIR operations.
This class helps build Operations.
This class represents a single result from folding an operation.
Type-safe wrapper around a void* for passing properties, including the properties structs of operatio...
This class provides an abstraction over the different types of ranges over Regions.
This class represents a specific instance of an effect.
static DerivedEffect * get()
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
TypeID getTypeID()
Return a unique identifier for the concrete type.
This class provides an abstraction over the different types of ranges over Values.
type_range getType() const
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.
llvm::function_ref< Fn > function_ref
This represents an operation in an abstracted form, suitable for use with the builder APIs.
bool match(Attribute attr)