26#include "llvm/ADT/STLExtras.h"
27#include "llvm/ADT/TypeSwitch.h"
28#include "llvm/Support/DebugLog.h"
32#define DEBUG_TYPE "sroa"
54 p <<
' ' << getArraySize() <<
" x " << getElemType();
55 NamedAttrList attrs((*this)->getDiscardableAttrDictionary().getValue());
56 if (getAlignment() && *getAlignment() != 0)
57 attrs.
append(getAlignmentAttrName(), getAlignmentAttr());
67 SMLoc trailingTypeLoc;
79 std::optional<NamedAttribute> alignmentAttr =
80 result.attributes.getNamed(
"alignment");
81 if (alignmentAttr.has_value()) {
82 auto alignmentInt = llvm::dyn_cast<IntegerAttr>(alignmentAttr->getValue());
85 "expected integer alignment");
86 if (alignmentInt.getValue().isZero())
87 result.attributes.erase(
"alignment");
91 auto funcType = llvm::dyn_cast<FunctionType>(type);
92 if (!funcType || funcType.getNumInputs() != 1 ||
93 funcType.getNumResults() != 1)
96 "expected trailing function type with one argument and one result");
101 Type resultType = funcType.getResult(0);
102 if (
auto ptrResultType = llvm::dyn_cast<LLVMPointerType>(resultType))
105 result.addTypes({funcType.getResult(0)});
109LogicalResult AllocaOp::verify() {
111 if (
auto targetExtType = dyn_cast<LLVMTargetExtType>(getElemType());
112 targetExtType && !targetExtType.supportsMemOps())
114 <<
"this target extension type cannot be used in alloca";
119LogicalResult AllocaOp::canonicalize(AllocaOp op,
PatternRewriter &rewriter) {
123 numElements.isOne() || numElements.getActiveBits() > 64)
127 LLVMArrayType::get(op.getElemType(), numElements.getZExtValue());
128 Value one = ConstantOp::create(rewriter, op.getLoc(), rewriter.
getI32Type(),
131 AllocaOp::create(rewriter, op.getLoc(), op.getType(), one,
132 op.getAlignmentAttr(), arrayType, op.getInalloca());
133 newAlloca->setDiscardableAttrs(op->getDiscardableAttrDictionary());
144 getDynamicIndices());
149 if (
auto vectorType = llvm::dyn_cast<VectorType>(type))
150 return vectorType.getElementType();
167 bool requiresConst = !rawConstantIndices.empty() &&
168 isa_and_nonnull<LLVMStructType>(currType);
169 if (
Value val = llvm::dyn_cast_if_present<Value>(iter)) {
173 rawConstantIndices.push_back(intC.getSExtValue());
175 rawConstantIndices.push_back(GEPOp::kDynamicIndex);
176 dynamicIndices.push_back(val);
179 rawConstantIndices.push_back(cast<GEPConstantIndex>(iter));
184 if (rawConstantIndices.size() == 1 || !currType)
188 .Case<VectorType, LLVMArrayType>([](
auto containerType) {
189 return containerType.getElementType();
191 .Case([&](LLVMStructType structType) ->
Type {
192 int64_t memberIndex = rawConstantIndices.back();
193 if (memberIndex >= 0 &&
static_cast<size_t>(memberIndex) <
194 structType.getBody().size())
195 return structType.getBody()[memberIndex];
204 GEPNoWrapFlags noWrapFlags, ConstantRangeAttr inrange,
210 result.addTypes(resultType);
211 result.addAttributes(attributes);
212 result.getOrAddProperties<Properties>().rawConstantIndices =
214 result.getOrAddProperties<Properties>().noWrapFlags = noWrapFlags;
215 result.getOrAddProperties<Properties>().elem_type =
216 TypeAttr::get(elementType);
217 result.getOrAddProperties<Properties>().inrange = inrange;
218 result.addOperands(basePtr);
219 result.addOperands(dynamicIndices);
224 GEPNoWrapFlags noWrapFlags, ConstantRangeAttr inrange,
226 build(builder,
result, resultType, elementType, basePtr,
236 auto idxParser = [&]() -> ParseResult {
237 int32_t constantIndex;
241 if (failed(parsedInteger.
value()))
243 constantIndices.push_back(constantIndex);
247 constantIndices.push_back(LLVM::GEPOp::kDynamicIndex);
261 llvm::interleaveComma(
264 if (
Value val = llvm::dyn_cast_if_present<Value>(cst))
267 printer << cast<IntegerAttr>(cst).getInt();
277 if (indexPos >=
indices.size())
282 .Case([&](LLVMStructType structType) -> LogicalResult {
283 auto attr = dyn_cast<IntegerAttr>(
indices[indexPos]);
285 return emitOpError() <<
"expected index " << indexPos
286 <<
" indexing a struct to be constant";
288 int32_t gepIndex = attr.getInt();
291 static_cast<size_t>(gepIndex) >= elementTypes.size())
292 return emitOpError() <<
"index " << indexPos
293 <<
" indexing a struct is out of bounds";
300 .Case<VectorType, LLVMArrayType>(
301 [&](
auto containerType) -> LogicalResult {
303 indexPos + 1,
indices, emitOpError);
305 .Default([&](
auto otherType) -> LogicalResult {
307 <<
"type " << otherType <<
" cannot be indexed (index #"
319LogicalResult LLVM::GEPOp::verify() {
320 if (
static_cast<size_t>(
321 llvm::count(getRawConstantIndices(), kDynamicIndex)) !=
322 getDynamicIndices().size())
323 return emitOpError(
"expected as many dynamic indices as specified in '")
324 << getRawConstantIndicesAttrName().getValue() <<
"'";
326 if (getNoWrapFlags() == GEPNoWrapFlags::inboundsFlag)
327 return emitOpError(
"'inbounds_flag' cannot be used directly.");
334 if (
auto inrange = getInrangeAttr()) {
338 std::optional<uint64_t> indexWidth =
340 assert(indexWidth &&
"pointers always return an index bitwidth");
341 if (inrange.getLower().getBitWidth() != *indexWidth)
342 return emitOpError(
"'inrange' bitwidth ")
343 << inrange.getLower().getBitWidth()
344 <<
" must match the pointer index bitwidth (" << *indexWidth
345 <<
") specified in the datalayout";
346 if (inrange.getLower().sge(inrange.getUpper()))
347 return emitOpError(
"expected 'inrange' end to be larger than start");
351 [&] {
return emitOpError(); });
358void LoadOp::getEffects(
367 if (getVolatile_() || (getOrdering() != AtomicOrdering::not_atomic &&
368 getOrdering() != AtomicOrdering::unordered)) {
379 if (!isa<IntegerType, LLVMPointerType>(type))
384 if (bitWidth.isScalable())
387 return bitWidth >= 8 && (bitWidth & (bitWidth - 1)) == 0;
391template <
typename OpTy>
395 if (memOp.getOrdering() != AtomicOrdering::not_atomic) {
398 return memOp.emitOpError(
"unsupported type ")
399 << valueType <<
" for atomic access";
400 if (llvm::is_contained(unsupportedOrderings, memOp.getOrdering()))
401 return memOp.emitOpError(
"unsupported ordering '")
402 << stringifyAtomicOrdering(memOp.getOrdering()) <<
"'";
403 if (!memOp.getAlignment())
404 return memOp.emitOpError(
"expected alignment for atomic access");
407 if (memOp.getSyncscope())
408 return memOp.emitOpError(
409 "expected syncscope to be null for non-atomic access");
413LogicalResult LoadOp::verify() {
414 Type valueType = getResult().getType();
416 {AtomicOrdering::release, AtomicOrdering::acq_rel});
420 Value addr,
unsigned alignment,
bool isVolatile,
421 bool isNonTemporal,
bool isInvariant,
bool isInvariantGroup,
422 bool isNoundef, AtomicOrdering ordering,
423 StringRef syncscope) {
424 build(builder, state, type, addr,
426 isNonTemporal, isInvariant, isInvariantGroup, ordering,
427 syncscope.empty() ?
nullptr : builder.
getStringAttr(syncscope),
428 nullptr, isNoundef,
nullptr,
438void StoreOp::getEffects(
447 if (getVolatile_() || (getOrdering() != AtomicOrdering::not_atomic &&
448 getOrdering() != AtomicOrdering::unordered)) {
454LogicalResult StoreOp::verify() {
455 Type valueType = getValue().getType();
457 {AtomicOrdering::acquire, AtomicOrdering::acq_rel});
461 Value addr,
unsigned alignment,
bool isVolatile,
462 bool isNonTemporal,
bool isInvariantGroup,
463 AtomicOrdering ordering, StringRef syncscope) {
464 build(builder, state, value, addr,
466 isNonTemporal, isInvariantGroup, ordering,
467 syncscope.empty() ?
nullptr : builder.
getStringAttr(syncscope),
469 nullptr,
nullptr,
nullptr);
478 AtomicOrdering ordering, StringRef syncscope,
479 unsigned alignment,
bool isVolatile,
480 bool ignoreDenormalMode) {
481 build(builder, state, val.
getType(), binOp,
ptr, val, ordering,
482 !syncscope.empty() ? builder.
getStringAttr(syncscope) :
nullptr,
486 nullptr,
nullptr,
nullptr);
489LogicalResult AtomicRMWOp::verify() {
490 auto valType = getVal().getType();
491 if (isFloatingPointOperation()) {
494 return emitOpError(
"expected LLVM IR fixed vector type");
495 Type elemType = llvm::cast<VectorType>(valType).getElementType();
498 "expected LLVM IR floating point type for vector element");
500 return emitOpError(
"expected LLVM IR floating point type");
502 }
else if (getBinOp() == AtomicBinOp::xchg) {
505 return emitOpError(
"unexpected LLVM IR type for 'xchg' bin_op");
507 auto intType = llvm::dyn_cast<IntegerType>(valType);
508 unsigned intBitWidth = intType ? intType.getWidth() : 0;
509 if (intBitWidth != 8 && intBitWidth != 16 && intBitWidth != 32 &&
511 return emitOpError(
"expected LLVM IR integer type");
514 if (getIgnoreDenormalMode() && !isFloatingPointOperation())
516 "expected floating-point operation with 'ignore_denormal_mode'");
518 if (
static_cast<unsigned>(getOrdering()) <
519 static_cast<unsigned>(AtomicOrdering::monotonic))
520 return emitOpError() <<
"expected at least '"
521 << stringifyAtomicOrdering(AtomicOrdering::monotonic)
533 auto boolType = IntegerType::get(valType.
getContext(), 1);
534 return LLVMStructType::getLiteral(valType.
getContext(), {valType, boolType});
539 AtomicOrdering successOrdering,
540 AtomicOrdering failureOrdering, StringRef syncscope,
541 unsigned alignment,
bool isWeak,
bool isVolatile) {
543 successOrdering, failureOrdering,
544 !syncscope.empty() ? builder.
getStringAttr(syncscope) :
nullptr,
547 nullptr,
nullptr,
nullptr);
550LogicalResult AtomicCmpXchgOp::verify() {
551 auto ptrType = llvm::cast<LLVM::LLVMPointerType>(getPtr().
getType());
553 return emitOpError(
"expected LLVM IR pointer type for operand #0");
554 auto valType = getVal().getType();
557 return emitOpError(
"unexpected LLVM IR type");
558 if (getSuccessOrdering() < AtomicOrdering::monotonic ||
559 getFailureOrdering() < AtomicOrdering::monotonic)
560 return emitOpError(
"ordering must be at least 'monotonic'");
561 if (getFailureOrdering() == AtomicOrdering::release ||
562 getFailureOrdering() == AtomicOrdering::acq_rel)
563 return emitOpError(
"failure ordering cannot be 'release' or 'acq_rel'");
572 AtomicOrdering ordering, StringRef syncscope) {
573 build(builder, state, ordering,
574 syncscope.empty() ?
nullptr : builder.
getStringAttr(syncscope));
577LogicalResult FenceOp::verify() {
578 if (getOrdering() == AtomicOrdering::not_atomic ||
579 getOrdering() == AtomicOrdering::unordered ||
580 getOrdering() == AtomicOrdering::monotonic)
581 return emitOpError(
"can be given only acquire, release, acq_rel, "
582 "and seq_cst orderings");
592 adaptor.getDynamicIndices());
595 if (getInrangeAttr())
600 if (
auto integer = llvm::dyn_cast_or_null<IntegerAttr>(
indices[0]))
601 if (integer.getValue().isZero())
605 bool changed =
false;
607 for (
auto iter : llvm::enumerate(
indices)) {
608 auto integer = llvm::dyn_cast_or_null<IntegerAttr>(iter.value());
611 if (!
indices.isDynamicIndex(iter.index()) || !integer ||
615 if (
Value val = llvm::dyn_cast_if_present<Value>(existing))
616 gepArgs.emplace_back(val);
618 gepArgs.emplace_back(cast<IntegerAttr>(existing).getInt());
624 gepArgs.emplace_back(integer.getInt());
632 getDynamicIndicesMutable().assign(dynamicIndices);
633 setRawConstantIndices(rawConstantIndices);
647 if (!getOperation()->getBlock()->isEntryBlock())
650 return {
MemorySlot{getResult(), getElemType()}};
655 return LLVM::UndefOp::create(builder, getLoc(), slot.
valueType);
658void LLVM::AllocaOp::handleBlockArgument(
const MemorySlot &slot,
661 for (
Operation *user : getOperation()->getUsers())
662 if (
auto declareOp = llvm::dyn_cast<LLVM::DbgDeclareOp>(user))
663 LLVM::DbgValueOp::create(builder, declareOp.getLoc(), argument,
664 declareOp.getVarInfo(),
665 declareOp.getLocationExpr());
668std::optional<PromotableAllocationOpInterface>
669LLVM::AllocaOp::handlePromotionComplete(
const MemorySlot &slot,
672 if (defaultValue && defaultValue.
use_empty())
682 auto destructurable = dyn_cast<DestructurableTypeInterface>(getElemType());
686 std::optional<DenseMap<Attribute, Type>> destructuredType =
687 destructurable.getSubelementIndexMap();
688 if (!destructuredType)
699 assert(slot.
ptr == getResult());
702 auto destructurableType = cast<DestructurableTypeInterface>(getElemType());
709 if (!usedIndices.contains(
index))
711 Type elemType = destructurableType.getTypeAtIndex(
index);
712 assert(elemType &&
"used index must exist");
713 auto subAlloca = LLVM::AllocaOp::create(
714 builder, getLoc(), LLVM::LLVMPointerType::get(
getContext()), elemType,
716 newAllocators.push_back(subAlloca);
717 slotMap.try_emplace<
MemorySlot>(
index, {subAlloca.getResult(), elemType});
723std::optional<DestructurableAllocationOpInterface>
724LLVM::AllocaOp::handleDestructuringComplete(
726 assert(slot.
ptr == getResult());
735bool LLVM::LoadOp::loadsFrom(
const MemorySlot &slot) {
736 return getAddr() == slot.
ptr;
739bool LLVM::LoadOp::storesTo(
const MemorySlot &slot) {
return false; }
743 llvm_unreachable(
"getStored should not be called on LoadOp");
746bool LLVM::StoreOp::loadsFrom(
const MemorySlot &slot) {
return false; }
748bool LLVM::StoreOp::storesTo(
const MemorySlot &slot) {
749 return getAddr() == slot.
ptr;
755 if (isa<LLVM::LLVMStructType, LLVM::LLVMArrayType>(type))
758 if (
auto vectorType = dyn_cast<VectorType>(type)) {
760 if (isa<LLVM::LLVMPointerType>(vectorType.getElementType()))
763 return !vectorType.isScalable();
772 Type srcType,
bool narrowingConversion) {
773 if (targetType == srcType)
780 uint64_t targetSize = layout.
getTypeSize(targetType);
785 if (isa<LLVM::LLVMPointerType>(targetType) &&
786 isa<LLVM::LLVMPointerType>(srcType))
787 return targetSize == srcSize;
789 if (narrowingConversion)
790 return targetSize <= srcSize;
791 return targetSize >= srcSize;
796 auto endiannessStr = dyn_cast_or_null<StringAttr>(dataLayout.
getEndianness());
797 return endiannessStr && endiannessStr ==
"big";
806 "expected value to have a convertible type");
808 if (isa<IntegerType>(type))
812 IntegerType valueSizeInteger = builder.
getIntegerType(typeBitSize);
814 if (isa<LLVM::LLVMPointerType>(type))
815 return builder.
createOrFold<LLVM::PtrToIntOp>(loc, valueSizeInteger, val);
816 return builder.
createOrFold<LLVM::BitcastOp>(loc, valueSizeInteger, val);
822 assert(isa<IntegerType>(val.
getType()) &&
823 "expected value to have an integer type");
825 "expected the target type to be supported for conversions");
826 if (val.
getType() == targetType)
828 if (isa<LLVM::LLVMPointerType>(targetType))
829 return builder.
createOrFold<LLVM::IntToPtrOp>(loc, targetType, val);
830 return builder.
createOrFold<LLVM::BitcastOp>(loc, targetType, val);
841 "expected that the compatibility was checked before");
844 if (srcType == targetType)
851 if (isa<LLVM::LLVMPointerType>(targetType) &&
852 isa<LLVM::LLVMPointerType>(srcType))
853 return builder.
createOrFold<LLVM::AddrSpaceCastOp>(loc, targetType,
871 "expected that the compatibility was checked before");
875 if (srcType == targetType)
880 if (srcTypeSize == targetTypeSize)
888 uint64_t shiftAmount = srcTypeSize - targetTypeSize;
889 auto shiftConstant = LLVM::ConstantOp::create(
892 builder.
createOrFold<LLVM::LShrOp>(loc, srcValue, shiftConstant);
912 "expected that the compatibility was checked before");
921 if (slotTypeSize == valueTypeSize)
934 uint64_t sizeDifference = slotTypeSize - valueTypeSize;
939 Value bigEndianShift = LLVM::ConstantOp::create(
943 builder.
createOrFold<LLVM::ShlOp>(loc, valueAsInt, bigEndianShift);
952 maskValue = APInt::getAllOnes(sizeDifference).zext(slotTypeSize);
956 maskValue = APInt::getAllOnes(valueTypeSize).zext(slotTypeSize);
957 maskValue.flipAllBits();
961 Value mask = LLVM::ConstantOp::create(
976 "expected the reaching definition's type to match the slot's type");
981bool LLVM::LoadOp::canUsesBeRemoved(
985 if (blockingUses.size() != 1)
987 Value blockingUse = (*blockingUses.begin())->get();
991 return blockingUse == slot.
ptr && getAddr() == slot.
ptr &&
1005 getResult().
getType(), dataLayout);
1006 getResult().replaceAllUsesWith(newResult);
1010bool LLVM::StoreOp::canUsesBeRemoved(
1014 if (blockingUses.size() != 1)
1016 Value blockingUse = (*blockingUses.begin())->get();
1020 return blockingUse == slot.
ptr && getAddr() == slot.
ptr &&
1021 getValue() != slot.
ptr &&
1042LogicalResult LLVM::LoadOp::ensureOnlySafeAccesses(
1049LogicalResult LLVM::StoreOp::ensureOnlySafeAccesses(
1059 auto subelementIndexMap =
1060 cast<DestructurableTypeInterface>(slot.
valueType).getSubelementIndexMap();
1061 if (!subelementIndexMap)
1063 assert(!subelementIndexMap->empty());
1066 return subelementIndexMap->lookup(
index);
1086 usedIndices.insert(
index);
1095 auto it = subslots.find(
index);
1096 assert(it != subslots.end());
1098 getAddrMutable().set(it->getSecond().ptr);
1110 if (getValue() == slot.
ptr)
1124 usedIndices.insert(
index);
1133 auto it = subslots.find(
index);
1134 assert(it != subslots.end());
1136 getAddrMutable().set(it->getSecond().ptr);
1149 newBlockingUses.push_back(&use);
1158 return llvm::all_of(gepOp.getIndices(), [](
auto index) {
1159 auto indexAttr = llvm::dyn_cast_if_present<IntegerAttr>(index);
1160 return indexAttr && indexAttr.getValue() == 0;
1164bool LLVM::GEPOp::canUsesBeRemoved(
1187 for (
auto index : gep.getIndices()) {
1188 auto constIndex = dyn_cast<IntegerAttr>(
index);
1191 int64_t gepIndex = constIndex.getInt();
1198 Type currentType = gep.getElemType();
1204 .Case([&](LLVM::LLVMArrayType arrayType) {
1207 currentType = arrayType.getElementType();
1210 .Case([&](LLVM::LLVMStructType structType) {
1211 offset += structType.getElementOffset(dataLayout,
index);
1212 currentType = structType.getBody()[
index];
1215 .Default([&](
Type type) {
1216 LDBG() <<
"[sroa] Unsupported type for offset computations"
1222 return std::nullopt;
1231struct SubslotAccessInfo {
1235 uint64_t subslotOffset;
1243static std::optional<SubslotAccessInfo>
1245 const DataLayout &dataLayout, LLVM::GEPOp gep) {
1253 auto isOutOfBoundsGEPIndex = [](uint64_t
index) {
1261 .Case([&](LLVM::LLVMArrayType arrayType)
1262 -> std::optional<SubslotAccessInfo> {
1264 uint64_t elemSize = dataLayout.
getTypeSize(arrayType.getElementType());
1265 uint64_t
index = *offset / elemSize;
1266 if (isOutOfBoundsGEPIndex(
index))
1268 return SubslotAccessInfo{
static_cast<uint32_t
>(
index),
1269 *offset - (
index * elemSize)};
1271 .Case([&](LLVM::LLVMStructType structType)
1272 -> std::optional<SubslotAccessInfo> {
1275 for (
auto [
index, elem] : llvm::enumerate(structType.getBody())) {
1276 uint64_t elemOffset = structType.getElementOffset(dataLayout,
index);
1278 if (*offset < elemOffset)
1281 if (*offset < elemOffset + dataLayout.
getTypeSize(elem)) {
1282 if (isOutOfBoundsGEPIndex(
index))
1286 return SubslotAccessInfo{
static_cast<uint32_t
>(
index),
1287 *offset - elemOffset};
1298 auto byteType = IntegerType::get(context, 8);
1299 return LLVM::LLVMArrayType::get(context, byteType, size);
1302LogicalResult LLVM::GEPOp::ensureOnlySafeAccesses(
1307 std::optional<uint64_t> gepOffset =
gepToByteOffset(dataLayout, *
this);
1312 if (*gepOffset >= slotSize)
1332 if (getInrangeAttr())
1334 std::optional<SubslotAccessInfo> accessInfo =
1339 IntegerAttr::get(IntegerType::get(
getContext(), 32), accessInfo->index);
1341 usedIndices.insert(indexAttr);
1346 uint64_t slotSize = dataLayout.
getTypeSize(subslotType);
1347 LLVM::LLVMArrayType remainingSlotType =
1349 mustBeSafelyUsed.emplace_back<
MemorySlot>({getRes(), remainingSlotType});
1358 std::optional<SubslotAccessInfo> accessInfo =
1360 assert(accessInfo &&
"expected access info to be checked before");
1362 IntegerAttr::get(IntegerType::get(
getContext(), 32), accessInfo->index);
1363 const MemorySlot &newSlot = subslots.at(indexAttr);
1365 auto byteType = IntegerType::get(builder.
getContext(), 8);
1367 getLoc(), getResult().getType(), byteType, newSlot.
ptr,
1369 getResult().replaceAllUsesWith(newPtr);
1389#define GET_OP_CLASSES
1390#include "mlir/Dialect/LLVMIR/LLVMMemoryOps.cpp.inc"
static Value getBase(Value v)
Looks through known "view-like" ops to find the base memref.
static LLVM::LLVMArrayType getByteArrayType(MLIRContext *context, unsigned size)
Constructs a byte array type of the given size.
static LogicalResult verifyAtomicMemOp(OpTy memOp, Type valueType, ArrayRef< AtomicOrdering > unsupportedOrderings)
Verifies the attributes and the type of atomic memory access operations.
static std::optional< SubslotAccessInfo > getSubslotAccessInfo(const DestructurableMemorySlot &slot, const DataLayout &dataLayout, LLVM::GEPOp gep)
Computes subslot access information for an access into slot with the given offset.
static Value castToSameSizedInt(OpBuilder &builder, Location loc, Value val, const DataLayout &dataLayout)
Converts a value to an integer type of the same size.
static Value castSameSizedTypes(OpBuilder &builder, Location loc, Value srcValue, Type targetType, const DataLayout &dataLayout)
Constructs operations that convert srcValue into a new value of type targetType.
static Type getTypeAtIndex(const DestructurableMemorySlot &slot, Attribute index)
Returns the subslot's type at the requested index.
static bool areConversionCompatible(const DataLayout &layout, Type targetType, Type srcType, bool narrowingConversion)
Checks that rhs can be converted to lhs by a sequence of casts and truncations.
static bool isSupportedTypeForConversion(Type type)
Checks if type can be used in any kind of conversion sequences.
static Value createExtractAndCast(OpBuilder &builder, Location loc, Value srcValue, Type targetType, const DataLayout &dataLayout)
Constructs operations that convert srcValue into a new value of type targetType.
static Value createInsertAndCast(OpBuilder &builder, Location loc, Value srcValue, Value reachingDef, const DataLayout &dataLayout)
Constructs operations that insert the bits of srcValue into the "beginning" of reachingDef (beginning...
static bool isBigEndian(const DataLayout &dataLayout)
Checks if dataLayout describes a little endian layout.
static std::optional< uint64_t > gepToByteOffset(const DataLayout &dataLayout, LLVM::GEPOp gep)
Returns the amount of bytes the provided GEP elements will offset the pointer by.
static void destructureIndices(Type currType, ArrayRef< GEPArg > indices, SmallVectorImpl< int32_t > &rawConstantIndices, SmallVectorImpl< Value > &dynamicIndices)
Destructures the 'indices' parameter into 'rawConstantIndices' and 'dynamicIndices',...
static bool hasAllZeroIndices(LLVM::GEPOp gepOp)
static bool isValidAccessType(const MemorySlot &slot, Type accessType, const DataLayout &dataLayout)
Checks if slot can be accessed through the provided access type.
static constexpr const char kElemTypeAttrName[]
static LogicalResult verifyStructIndices(Type baseGEPType, unsigned indexPos, GEPIndicesAdaptor< ValueRange > indices, function_ref< InFlightDiagnostic()> emitOpError)
For the given indices, check if they comply with baseGEPType, especially check against LLVMStructType...
static Value castIntValueToSameSizedType(OpBuilder &builder, Location loc, Value val, Type targetType)
Converts a value with an integer type to targetType.
*if copies could not be generated due to yet unimplemented cases *copyInPlacementStart and copyOutPlacementStart in copyPlacementBlock *specify the insertion points where the incoming copies and outgoing should be the output argument nBegin is set to its * replacement(set to `begin` if no invalidation happens). Since outgoing *copies could have been inserted at `end`
virtual OptionalParseResult parseOptionalInteger(APInt &result)=0
Parse an optional integer value from the stream.
virtual ParseResult parseCommaSeparatedList(Delimiter delimiter, function_ref< ParseResult()> parseElementFn, StringRef contextMessage=StringRef())=0
Parse a list of comma-separated items with an optional delimiter.
virtual ParseResult parseOptionalAttrDict(NamedAttrList &result)=0
Parse a named dictionary into 'result' if it is present.
virtual ParseResult parseOptionalKeyword(StringRef keyword)=0
Parse the given keyword if present.
MLIRContext * getContext() const
virtual InFlightDiagnostic emitError(SMLoc loc, const Twine &message={})=0
Emit a diagnostic at the specified location and return failure.
virtual SMLoc getCurrentLocation()=0
Get the location of the next token and store it into the argument.
virtual ParseResult parseColon()=0
Parse a : token.
virtual SMLoc getNameLoc() const =0
Return the location of the original name token.
virtual ParseResult parseType(Type &result)=0
Parse a type.
ParseResult parseKeyword(StringRef keyword)
Parse a given keyword.
Attributes are known-constant values of operations.
This class represents an argument of a Block.
DenseI32ArrayAttr getDenseI32ArrayAttr(ArrayRef< int32_t > values)
IntegerAttr getIntegerAttr(Type type, int64_t value)
IntegerAttr getI64IntegerAttr(int64_t value)
IntegerType getIntegerType(unsigned width)
StringAttr getStringAttr(const Twine &bytes)
MLIRContext * getContext() const
The main mechanism for performing data layout queries.
static DataLayout closest(Operation *op)
Returns the layout of the closest parent operation carrying layout info.
std::optional< uint64_t > getTypeIndexBitwidth(Type t) const
Returns the bitwidth that should be used when performing index computations for the given pointer-lik...
llvm::TypeSize getTypeSize(Type t) const
Returns the size of the given type in the current scope.
llvm::TypeSize getTypeSizeInBits(Type t) const
Returns the size in bits of the given type in the current scope.
Attribute getEndianness() const
Returns the specified endianness.
This class represents a diagnostic that is inflight and set to be reported.
Class used for building a 'llvm.getelementptr'.
Class used for convenient access and iteration over GEP indices.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
MLIRContext is the top-level object for a collection of MLIR operations.
NamedAttrList is array of NamedAttributes that tracks whether it is sorted and does some basic work t...
void append(StringRef name, Attribute attr)
Add an attribute with the specified name.
The OpAsmParser has methods for interacting with the asm parser: parsing things from it,...
virtual ParseResult resolveOperand(const UnresolvedOperand &operand, Type type, SmallVectorImpl< Value > &result)=0
Resolve an operand to an SSA value, emitting an error on failure.
virtual ParseResult parseOperand(UnresolvedOperand &result, bool allowResultNumber=true)=0
Parse a single SSA value operand name along with a result number if allowResultNumber is true.
This is a pure-virtual base class that exposes the asmprinter hooks necessary to implement a custom p...
virtual void printOptionalAttrDict(ArrayRef< NamedAttribute > attrs, ArrayRef< StringRef > elidedAttrs={})=0
If the specified operation has attributes, print out an attribute dictionary with their values.
virtual void printOperand(Value value)=0
Print implementations for various things an operation contains.
This class helps build Operations.
void createOrFold(SmallVectorImpl< Value > &results, Location location, Args &&...args)
Create an operation of specific op type at the current insertion point, and immediately try to fold i...
void setInsertionPointAfter(Operation *op)
Sets the insertion point to the node after the specified operation, which will cause subsequent inser...
This class represents a single result from folding an operation.
This class represents an operand of an operation.
This class implements the operand iterators for the Operation class.
Operation is the basic unit of execution within MLIR.
result_range getResults()
void erase()
Remove this operation from its parent block and delete it.
This class implements Optional functionality for ParseResult.
ParseResult value() const
Access the internal ParseResult value.
bool has_value() const
Returns true if we contain a valid ParseResult value.
A special type of RewriterBase that coordinates the application of a rewrite pattern on the current I...
virtual void replaceOp(Operation *op, ValueRange newValues)
Replace the results of the given (original) operation with the specified list of values (replacements...
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...
MLIRContext * getContext() const
Return the MLIRContext in which this type was uniqued.
This class provides an abstraction over the different types of ranges over Values.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
bool use_empty() const
Returns true if this value has no uses.
Type getType() const
Return the type of this value.
Operation * getDefiningOp() const
If this value is the result of an operation, return the operation that defines it.
static DenseArrayAttrImpl get(MLIRContext *context, ArrayRef< int32_t > content)
bool isScalableVectorType(Type vectorType)
Returns whether a vector type is scalable or not.
Type extractVectorElementType(Type type)
Returns the elemental type of any LLVM-compatible vector type or self.
bool isCompatibleVectorType(Type type)
Returns true if the given type is a vector type compatible with the LLVM dialect.
bool forwardToUsers(Operation *op, SmallVectorImpl< OpOperand * > &newBlockingUses)
Conditions the deletion of the operation to the removal of all its uses.
constexpr int kGEPConstantBitWidth
Bit-width of a 'GEPConstantIndex' within GEPArg.
bool isTypeCompatibleWithAtomicOp(Type type, const DataLayout &dataLayout)
Returns true if the given type is supported by atomic operations.
mlir::LLVM::LLVMStructType getValAndBoolStructType(mlir::Type valType)
Returns an LLVM struct type that contains a value type and a boolean type.
bool isCompatibleFloatingPointType(Type type)
Returns true if the given type is a floating-point type compatible with the LLVM dialect.
mlir::ParseResult parseGEPIndices(mlir::OpAsmParser &parser, mlir::SmallVectorImpl< mlir::OpAsmParser::UnresolvedOperand > &indices, mlir::DenseI32ArrayAttr &rawConstantIndices)
void printGEPIndices(mlir::OpAsmPrinter &printer, mlir::LLVM::GEPOp gepOp, mlir::OperandRange indices, mlir::DenseI32ArrayAttr rawConstantIndices)
Operation::operand_range getIndices(Operation *op)
Get the indices that the given load/store operation is operating on.
Include the generated interface declarations.
bool matchPattern(Value value, const Pattern &pattern)
Entry point for matching a pattern over a Value.
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.
detail::DenseArrayAttrImpl< int32_t > DenseI32ArrayAttr
detail::constant_int_predicate_matcher m_One()
Matches a constant scalar / vector splat / tensor splat integer one.
DeletionKind
Returned by operation promotion logic requesting the deletion of an operation.
@ Keep
Keep the operation after promotion.
@ Delete
Delete the operation after promotion.
llvm::TypeSwitch< T, ResultT > TypeSwitch
llvm::DenseMap< KeyT, ValueT, KeyInfoT, BucketT > DenseMap
llvm::function_ref< Fn > function_ref
Memory slot attached with information about its destructuring procedure.
DenseMap< Attribute, Type > subelementTypes
Maps an index within the memory slot to the corresponding subelement type.
Represents a slot in memory.
Type valueType
Type of the value contained in the slot.
Value ptr
Pointer to the memory slot, used by operations to refer to it.
This is the representation of an operand reference.
This represents an operation in an abstracted form, suitable for use with the builder APIs.