MLIR
20.0.0git
|
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "mlir/Dialect/LLVMIR/LLVMTypes.h"
#include "mlir/IR/Matchers.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/Interfaces/DataLayoutInterfaces.h"
#include "mlir/Interfaces/MemorySlotInterfaces.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/TypeSwitch.h"
Go to the source code of this file.
Macros | |
#define | DEBUG_TYPE "sroa" |
Functions | |
static bool | isSupportedTypeForConversion (Type type) |
Checks if type can be used in any kind of conversion sequences. More... | |
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. More... | |
static bool | isBigEndian (const DataLayout &dataLayout) |
Checks if dataLayout describes a little endian layout. More... | |
static Value | castToSameSizedInt (OpBuilder &builder, Location loc, Value val, const DataLayout &dataLayout) |
Converts a value to an integer type of the same size. More... | |
static Value | castIntValueToSameSizedType (OpBuilder &builder, Location loc, Value val, Type targetType) |
Converts a value with an integer type to targetType . More... | |
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 . More... | |
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 . More... | |
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 is endianness dependent). More... | |
static bool | isValidAccessType (const MemorySlot &slot, Type accessType, const DataLayout &dataLayout) |
Checks if slot can be accessed through the provided access type. More... | |
static Type | getTypeAtIndex (const DestructurableMemorySlot &slot, Attribute index) |
Returns the subslot's type at the requested index. More... | |
static bool | forwardToUsers (Operation *op, SmallVectorImpl< OpOperand * > &newBlockingUses) |
Conditions the deletion of the operation to the removal of all its uses. More... | |
static bool | hasAllZeroIndices (LLVM::GEPOp gepOp) |
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. More... | |
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. More... | |
static LLVM::LLVMArrayType | getByteArrayType (MLIRContext *context, unsigned size) |
Constructs a byte array type of the given size. More... | |
template<class MemIntr > | |
static bool | definitelyWritesOnlyWithinSlot (MemIntr op, const MemorySlot &slot, const DataLayout &dataLayout) |
Returns whether one can be sure the memory intrinsic does not write outside of the bounds of the given slot, on a best-effort basis. More... | |
static bool | areAllIndicesI32 (const DestructurableMemorySlot &slot) |
Checks whether all indices are i32. More... | |
template<class MemsetIntr > | |
static bool | memsetCanRewire (MemsetIntr op, const DestructurableMemorySlot &slot, SmallPtrSetImpl< Attribute > &usedIndices, SmallVectorImpl< MemorySlot > &mustBeSafelyUsed, const DataLayout &dataLayout) |
template<class MemsetIntr > | |
static Value | memsetGetStored (MemsetIntr op, const MemorySlot &slot, OpBuilder &builder) |
template<class MemsetIntr > | |
static bool | memsetCanUsesBeRemoved (MemsetIntr op, const MemorySlot &slot, const SmallPtrSetImpl< OpOperand * > &blockingUses, SmallVectorImpl< OpOperand * > &newBlockingUses, const DataLayout &dataLayout) |
template<class MemsetIntr > | |
static DeletionKind | memsetRewire (MemsetIntr op, const DestructurableMemorySlot &slot, DenseMap< Attribute, MemorySlot > &subslots, OpBuilder &builder, const DataLayout &dataLayout) |
template<class MemcpyLike > | |
static bool | memcpyLoadsFrom (MemcpyLike op, const MemorySlot &slot) |
template<class MemcpyLike > | |
static bool | memcpyStoresTo (MemcpyLike op, const MemorySlot &slot) |
template<class MemcpyLike > | |
static Value | memcpyGetStored (MemcpyLike op, const MemorySlot &slot, OpBuilder &builder) |
template<class MemcpyLike > | |
static bool | memcpyCanUsesBeRemoved (MemcpyLike op, const MemorySlot &slot, const SmallPtrSetImpl< OpOperand * > &blockingUses, SmallVectorImpl< OpOperand * > &newBlockingUses, const DataLayout &dataLayout) |
template<class MemcpyLike > | |
static DeletionKind | memcpyRemoveBlockingUses (MemcpyLike op, const MemorySlot &slot, const SmallPtrSetImpl< OpOperand * > &blockingUses, OpBuilder &builder, Value reachingDefinition) |
template<class MemcpyLike > | |
static LogicalResult | memcpyEnsureOnlySafeAccesses (MemcpyLike op, const MemorySlot &slot, SmallVectorImpl< MemorySlot > &mustBeSafelyUsed) |
template<class MemcpyLike > | |
static bool | memcpyCanRewire (MemcpyLike op, const DestructurableMemorySlot &slot, SmallPtrSetImpl< Attribute > &usedIndices, SmallVectorImpl< MemorySlot > &mustBeSafelyUsed, const DataLayout &dataLayout) |
template<class MemcpyLike > | |
static DeletionKind | memcpyRewire (MemcpyLike op, const DestructurableMemorySlot &slot, DenseMap< Attribute, MemorySlot > &subslots, OpBuilder &builder, const DataLayout &dataLayout) |
Rewires a memcpy-like operation. More... | |
#define DEBUG_TYPE "sroa" |
Definition at line 23 of file LLVMMemorySlot.cpp.
|
static |
Checks whether all indices are i32.
This is used to check GEPs can index into them.
Definition at line 1018 of file LLVMMemorySlot.cpp.
References mlir::get(), mlir::Value::getContext(), mlir::MemorySlot::ptr, and mlir::DestructurableMemorySlot::subelementTypes.
Referenced by memcpyCanRewire(), and memsetCanRewire().
|
static |
Checks that rhs
can be converted to lhs
by a sequence of casts and truncations.
Checks for narrowing or widening conversion compatibility depending on narrowingConversion
.
Definition at line 152 of file LLVMMemorySlot.cpp.
References mlir::DataLayout::getTypeSize(), and isSupportedTypeForConversion().
Referenced by castSameSizedTypes(), createExtractAndCast(), and createInsertAndCast().
|
static |
Converts a value with an integer type to targetType
.
Definition at line 201 of file LLVMMemorySlot.cpp.
References mlir::OpBuilder::createOrFold(), mlir::Value::getType(), and isSupportedTypeForConversion().
Referenced by castSameSizedTypes(), createExtractAndCast(), and createInsertAndCast().
|
static |
Constructs operations that convert srcValue
into a new value of type targetType
.
Assumes the types have the same bitsize.
Definition at line 216 of file LLVMMemorySlot.cpp.
References areConversionCompatible(), castIntValueToSameSizedType(), castToSameSizedInt(), mlir::OpBuilder::createOrFold(), and mlir::Value::getType().
Referenced by createExtractAndCast(), and createInsertAndCast().
|
static |
Converts a value to an integer type of the same size.
Assumes that the type can be converted.
Definition at line 183 of file LLVMMemorySlot.cpp.
References mlir::OpBuilder::createOrFold(), mlir::Builder::getIntegerType(), mlir::Value::getType(), mlir::DataLayout::getTypeSizeInBits(), and isSupportedTypeForConversion().
Referenced by castSameSizedTypes(), createExtractAndCast(), and createInsertAndCast().
|
static |
Constructs operations that convert srcValue
into a new value of type targetType
.
Performs bit-level extraction if the source type is larger than the target type. Assumes that this conversion is possible.
Definition at line 245 of file LLVMMemorySlot.cpp.
References areConversionCompatible(), castIntValueToSameSizedType(), castSameSizedTypes(), castToSameSizedInt(), mlir::OpBuilder::create(), mlir::OpBuilder::createOrFold(), mlir::Builder::getIntegerAttr(), mlir::Builder::getIntegerType(), mlir::Value::getType(), mlir::DataLayout::getTypeSizeInBits(), and isBigEndian().
|
static |
Constructs operations that insert the bits of srcValue
into the "beginning" of reachingDef
(beginning is endianness dependent).
Assumes that this conversion is possible.
Definition at line 281 of file LLVMMemorySlot.cpp.
References areConversionCompatible(), castIntValueToSameSizedType(), castSameSizedTypes(), castToSameSizedInt(), mlir::OpBuilder::create(), mlir::OpBuilder::createOrFold(), mlir::Builder::getIntegerAttr(), mlir::Value::getType(), mlir::DataLayout::getTypeSizeInBits(), and isBigEndian().
|
static |
Returns whether one can be sure the memory intrinsic does not write outside of the bounds of the given slot, on a best-effort basis.
Definition at line 1006 of file LLVMMemorySlot.cpp.
References mlir::MemorySlot::elemType, mlir::Value::getType(), mlir::DataLayout::getTypeSize(), and mlir::MemorySlot::ptr.
Referenced by memcpyEnsureOnlySafeAccesses(), and memsetCanRewire().
|
static |
Conditions the deletion of the operation to the removal of all its uses.
Definition at line 513 of file LLVMMemorySlot.cpp.
References mlir::Operation::getResults().
|
static |
Returns the amount of bytes the provided GEP elements will offset the pointer by.
Returns nullopt if no constant offset could be computed.
Definition at line 693 of file LLVMMemorySlot.cpp.
References mlir::DataLayout::getTypeABIAlignment(), and mlir::DataLayout::getTypeSize().
Referenced by getSubslotAccessInfo().
|
static |
Constructs a byte array type of the given size.
Definition at line 828 of file LLVMMemorySlot.cpp.
References mlir::get().
|
static |
Computes subslot access information for an access into slot
with the given offset.
Returns nullopt when the offset is out-of-bounds or when the access is into the padding of slot
.
Definition at line 767 of file LLVMMemorySlot.cpp.
References mlir::MemorySlot::elemType, mlir::detail::enumerate(), gepToByteOffset(), mlir::DataLayout::getTypeABIAlignment(), mlir::DataLayout::getTypeSize(), and mlir::LLVM::kGEPConstantBitWidth.
|
static |
Returns the subslot's type at the requested index.
Definition at line 425 of file LLVMMemorySlot.cpp.
References mlir::MemorySlot::elemType.
|
static |
Definition at line 669 of file LLVMMemorySlot.cpp.
|
static |
Checks if dataLayout
describes a little endian layout.
Definition at line 176 of file LLVMMemorySlot.cpp.
References mlir::DataLayout::getEndianness().
Referenced by createExtractAndCast(), and createInsertAndCast().
|
static |
Checks if type
can be used in any kind of conversion sequences.
Definition at line 132 of file LLVMMemorySlot.cpp.
Referenced by areConversionCompatible(), castIntValueToSameSizedType(), and castToSameSizedInt().
|
static |
Checks if slot
can be accessed through the provided access type.
Definition at line 404 of file LLVMMemorySlot.cpp.
References mlir::MemorySlot::elemType, and mlir::DataLayout::getTypeSize().
|
static |
Definition at line 1309 of file LLVMMemorySlot.cpp.
References areAllIndicesI32(), mlir::MemorySlot::elemType, mlir::DataLayout::getTypeSize(), mlir::MemorySlot::ptr, and mlir::DestructurableMemorySlot::subelementTypes.
|
static |
Definition at line 1271 of file LLVMMemorySlot.cpp.
References mlir::MemorySlot::elemType, and mlir::DataLayout::getTypeSize().
|
static |
Definition at line 1299 of file LLVMMemorySlot.cpp.
References mlir::DataLayout::closest(), and definitelyWritesOnlyWithinSlot().
|
static |
Definition at line 1264 of file LLVMMemorySlot.cpp.
References mlir::OpBuilder::create(), and mlir::MemorySlot::elemType.
|
static |
Definition at line 1254 of file LLVMMemorySlot.cpp.
References mlir::MemorySlot::ptr.
|
static |
Definition at line 1289 of file LLVMMemorySlot.cpp.
References mlir::OpBuilder::create(), and mlir::Delete.
|
static |
Rewires a memcpy-like operation.
Only copies to or from the full slot are supported.
Definition at line 1363 of file LLVMMemorySlot.cpp.
References mlir::OpBuilder::create(), mlir::Delete, mlir::MemorySlot::elemType, mlir::get(), mlir::MemorySlot::ptr, and mlir::DestructurableMemorySlot::subelementTypes.
|
static |
Definition at line 1259 of file LLVMMemorySlot.cpp.
References mlir::MemorySlot::ptr.
|
static |
Definition at line 1032 of file LLVMMemorySlot.cpp.
References areAllIndicesI32(), definitelyWritesOnlyWithinSlot(), mlir::MemorySlot::elemType, and mlir::Type::getDialect().
|
static |
Definition at line 1087 of file LLVMMemorySlot.cpp.
References mlir::MemorySlot::elemType, and mlir::DataLayout::getTypeSize().
|
static |
Definition at line 1052 of file LLVMMemorySlot.cpp.
References mlir::OpBuilder::create(), and mlir::MemorySlot::elemType.
|
static |
Definition at line 1109 of file LLVMMemorySlot.cpp.
References mlir::Delete, mlir::MemorySlot::elemType, mlir::get(), mlir::DataLayout::getTypeABIAlignment(), mlir::DataLayout::getTypeSize(), and min().