MLIR  19.0.0git
Macros | Functions
LLVMMemorySlot.cpp File Reference
#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 (RewriterBase &rewriter, Location loc, Value val, const DataLayout &dataLayout)
 Converts a value to an integer type of the same size. More...
 
static Value castIntValueToSameSizedType (RewriterBase &rewriter, Location loc, Value val, Type targetType)
 Converts a value with an integer type to targetType. More...
 
static Value castSameSizedTypes (RewriterBase &rewriter, 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 (RewriterBase &rewriter, 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 (RewriterBase &rewriter, 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 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, RewriterBase &rewriter)
 
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, RewriterBase &rewriter, 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, RewriterBase &rewriter, const DataLayout &dataLayout)
 Rewires a memcpy-like operation. More...
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "sroa"

Definition at line 23 of file LLVMMemorySlot.cpp.

Function Documentation

◆ areAllIndicesI32()

static bool areAllIndicesI32 ( const DestructurableMemorySlot slot)
static

Checks whether all indices are i32.

This is used to check GEPs can index into them.

Definition at line 922 of file LLVMMemorySlot.cpp.

References mlir::DestructurableMemorySlot::elementPtrs, mlir::get(), mlir::Value::getContext(), and mlir::MemorySlot::ptr.

◆ areConversionCompatible()

static bool areConversionCompatible ( const DataLayout layout,
Type  targetType,
Type  srcType,
bool  narrowingConversion 
)
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 147 of file LLVMMemorySlot.cpp.

References mlir::DataLayout::getTypeSize(), and isSupportedTypeForConversion().

Referenced by castSameSizedTypes(), createExtractAndCast(), and createInsertAndCast().

◆ castIntValueToSameSizedType()

static Value castIntValueToSameSizedType ( RewriterBase rewriter,
Location  loc,
Value  val,
Type  targetType 
)
static

Converts a value with an integer type to targetType.

Definition at line 196 of file LLVMMemorySlot.cpp.

References mlir::OpBuilder::createOrFold(), mlir::Value::getType(), and isSupportedTypeForConversion().

Referenced by castSameSizedTypes(), createExtractAndCast(), and createInsertAndCast().

◆ castSameSizedTypes()

static Value castSameSizedTypes ( RewriterBase rewriter,
Location  loc,
Value  srcValue,
Type  targetType,
const DataLayout dataLayout 
)
static

Constructs operations that convert srcValue into a new value of type targetType.

Assumes the types have the same bitsize.

Definition at line 211 of file LLVMMemorySlot.cpp.

References areConversionCompatible(), castIntValueToSameSizedType(), castToSameSizedInt(), mlir::OpBuilder::createOrFold(), and mlir::Value::getType().

Referenced by createExtractAndCast(), and createInsertAndCast().

◆ castToSameSizedInt()

static Value castToSameSizedInt ( RewriterBase rewriter,
Location  loc,
Value  val,
const DataLayout dataLayout 
)
static

Converts a value to an integer type of the same size.

Assumes that the type can be converted.

Definition at line 178 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().

◆ createExtractAndCast()

static Value createExtractAndCast ( RewriterBase rewriter,
Location  loc,
Value  srcValue,
Type  targetType,
const DataLayout dataLayout 
)
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 240 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().

◆ createInsertAndCast()

static Value createInsertAndCast ( RewriterBase rewriter,
Location  loc,
Value  srcValue,
Value  reachingDef,
const DataLayout dataLayout 
)
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 276 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().

◆ definitelyWritesOnlyWithinSlot()

template<class MemIntr >
static bool definitelyWritesOnlyWithinSlot ( MemIntr  op,
const MemorySlot slot,
const DataLayout dataLayout 
)
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 910 of file LLVMMemorySlot.cpp.

◆ forwardToUsers()

static bool forwardToUsers ( Operation op,
SmallVectorImpl< OpOperand * > &  newBlockingUses 
)
static

Conditions the deletion of the operation to the removal of all its uses.

Definition at line 510 of file LLVMMemorySlot.cpp.

◆ gepToByteOffset()

static std::optional<uint64_t> gepToByteOffset ( const DataLayout dataLayout,
LLVM::GEPOp  gep 
)
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 667 of file LLVMMemorySlot.cpp.

References mlir::LLVM::LLVMStructType::getBody(), mlir::DataLayout::getTypeABIAlignment(), mlir::DataLayout::getTypeSize(), and mlir::LLVM::LLVMStructType::isPacked().

Referenced by getSubslotAccessInfo().

◆ getByteArrayType()

static LLVM::LLVMArrayType getByteArrayType ( MLIRContext context,
unsigned  size 
)
static

Constructs a byte array type of the given size.

Definition at line 802 of file LLVMMemorySlot.cpp.

References mlir::get().

◆ getSubslotAccessInfo()

static std::optional<SubslotAccessInfo> getSubslotAccessInfo ( const DestructurableMemorySlot slot,
const DataLayout dataLayout,
LLVM::GEPOp  gep 
)
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 741 of file LLVMMemorySlot.cpp.

References mlir::MemorySlot::elemType, mlir::detail::enumerate(), gepToByteOffset(), mlir::LLVM::LLVMStructType::getBody(), mlir::DataLayout::getTypeABIAlignment(), mlir::DataLayout::getTypeSize(), mlir::LLVM::LLVMStructType::isPacked(), and mlir::LLVM::kGEPConstantBitWidth.

◆ getTypeAtIndex()

static Type getTypeAtIndex ( const DestructurableMemorySlot slot,
Attribute  index 
)
static

Returns the subslot's type at the requested index.

Definition at line 420 of file LLVMMemorySlot.cpp.

References mlir::MemorySlot::elemType.

◆ hasAllZeroIndices()

static bool hasAllZeroIndices ( LLVM::GEPOp  gepOp)
static

Definition at line 643 of file LLVMMemorySlot.cpp.

◆ isBigEndian()

static bool isBigEndian ( const DataLayout dataLayout)
static

Checks if dataLayout describes a little endian layout.

Definition at line 171 of file LLVMMemorySlot.cpp.

References mlir::DataLayout::getEndianness().

Referenced by createExtractAndCast(), and createInsertAndCast().

◆ isSupportedTypeForConversion()

static bool isSupportedTypeForConversion ( Type  type)
static

Checks if type can be used in any kind of conversion sequences.

Definition at line 127 of file LLVMMemorySlot.cpp.

Referenced by areConversionCompatible(), castIntValueToSameSizedType(), and castToSameSizedInt().

◆ isValidAccessType()

static bool isValidAccessType ( const MemorySlot slot,
Type  accessType,
const DataLayout dataLayout 
)
static

Checks if slot can be accessed through the provided access type.

Definition at line 399 of file LLVMMemorySlot.cpp.

References mlir::MemorySlot::elemType, and mlir::DataLayout::getTypeSize().

◆ memcpyCanRewire()

template<class MemcpyLike >
static bool memcpyCanRewire ( MemcpyLike  op,
const DestructurableMemorySlot slot,
SmallPtrSetImpl< Attribute > &  usedIndices,
SmallVectorImpl< MemorySlot > &  mustBeSafelyUsed,
const DataLayout dataLayout 
)
static

Definition at line 1144 of file LLVMMemorySlot.cpp.

◆ memcpyCanUsesBeRemoved()

template<class MemcpyLike >
static bool memcpyCanUsesBeRemoved ( MemcpyLike  op,
const MemorySlot slot,
const SmallPtrSetImpl< OpOperand * > &  blockingUses,
SmallVectorImpl< OpOperand * > &  newBlockingUses,
const DataLayout dataLayout 
)
static

Definition at line 1105 of file LLVMMemorySlot.cpp.

◆ memcpyEnsureOnlySafeAccesses()

template<class MemcpyLike >
static LogicalResult memcpyEnsureOnlySafeAccesses ( MemcpyLike  op,
const MemorySlot slot,
SmallVectorImpl< MemorySlot > &  mustBeSafelyUsed 
)
static

Definition at line 1134 of file LLVMMemorySlot.cpp.

◆ memcpyGetStored()

template<class MemcpyLike >
static Value memcpyGetStored ( MemcpyLike  op,
const MemorySlot slot,
RewriterBase rewriter 
)
static

Definition at line 1098 of file LLVMMemorySlot.cpp.

◆ memcpyLoadsFrom()

template<class MemcpyLike >
static bool memcpyLoadsFrom ( MemcpyLike  op,
const MemorySlot slot 
)
static

Definition at line 1088 of file LLVMMemorySlot.cpp.

◆ memcpyRemoveBlockingUses()

template<class MemcpyLike >
static DeletionKind memcpyRemoveBlockingUses ( MemcpyLike  op,
const MemorySlot slot,
const SmallPtrSetImpl< OpOperand * > &  blockingUses,
RewriterBase rewriter,
Value  reachingDefinition 
)
static

Definition at line 1123 of file LLVMMemorySlot.cpp.

◆ memcpyRewire()

template<class MemcpyLike >
static DeletionKind memcpyRewire ( MemcpyLike  op,
const DestructurableMemorySlot slot,
DenseMap< Attribute, MemorySlot > &  subslots,
RewriterBase rewriter,
const DataLayout dataLayout 
)
static

Rewires a memcpy-like operation.

Only copies to or from the full slot are supported.

Definition at line 1198 of file LLVMMemorySlot.cpp.

◆ memcpyStoresTo()

template<class MemcpyLike >
static bool memcpyStoresTo ( MemcpyLike  op,
const MemorySlot slot 
)
static

Definition at line 1093 of file LLVMMemorySlot.cpp.