MLIR 24.0.0git
LLVMMemoryOps.cpp File Reference
#include "mlir/Dialect/LLVMIR/LLVMMemoryOps.h"
#include "IR/LLVMOps.h"
#include "mlir/Dialect/LLVMIR/LLVMArithOps.h"
#include "mlir/Dialect/LLVMIR/LLVMConstantOps.h"
#include "mlir/Dialect/LLVMIR/LLVMConversionOps.h"
#include "mlir/Dialect/LLVMIR/LLVMDebugIntrinsicOps.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/DialectImplementation.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"
#include "llvm/Support/DebugLog.h"
#include <optional>
#include "mlir/Dialect/LLVMIR/LLVMMemoryOps.cpp.inc"

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "sroa"
#define GET_OP_CLASSES

Functions

static void destructureIndices (Type currType, ArrayRef< GEPArg > indices, SmallVectorImpl< int32_t > &rawConstantIndices, SmallVectorImpl< Value > &dynamicIndices)
 Destructures the 'indices' parameter into 'rawConstantIndices' and 'dynamicIndices', encoding the former in the process.
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 LLVMStructTypes nested within.
static LogicalResult verifyStructIndices (Type baseGEPType, GEPIndicesAdaptor< ValueRange > indices, function_ref< InFlightDiagnostic()> emitOpError)
 Driver function around verifyStructIndices.
template<typename OpTy>
static LogicalResult verifyAtomicMemOp (OpTy memOp, Type valueType, ArrayRef< AtomicOrdering > unsupportedOrderings)
 Verifies the attributes and the type of atomic memory access operations.
static bool isSupportedTypeForConversion (Type type)
 Checks if type can be used in any kind of conversion sequences.
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 isBigEndian (const DataLayout &dataLayout)
 Checks if dataLayout describes a little endian layout.
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 castIntValueToSameSizedType (OpBuilder &builder, Location loc, Value val, Type targetType)
 Converts a value with an integer type to targetType.
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 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 is endianness dependent).
static bool isValidAccessType (const MemorySlot &slot, Type accessType, const DataLayout &dataLayout)
 Checks if slot can be accessed through the provided access type.
static Type getTypeAtIndex (const DestructurableMemorySlot &slot, Attribute index)
 Returns the subslot's type at the requested index.
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.
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 LLVM::LLVMArrayType getByteArrayType (MLIRContext *context, unsigned size)
 Constructs a byte array type of the given size.

Variables

static constexpr const char kElemTypeAttrName [] = "elem_type"

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "sroa"

Definition at line 32 of file LLVMMemoryOps.cpp.

◆ GET_OP_CLASSES

#define GET_OP_CLASSES

Definition at line 1389 of file LLVMMemoryOps.cpp.

Function Documentation

◆ areConversionCompatible()

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 771 of file LLVMMemoryOps.cpp.

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

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

◆ castIntValueToSameSizedType()

Value castIntValueToSameSizedType ( OpBuilder & builder,
Location loc,
Value val,
Type targetType )
static

Converts a value with an integer type to targetType.

Definition at line 820 of file LLVMMemoryOps.cpp.

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

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

◆ castSameSizedTypes()

Value castSameSizedTypes ( OpBuilder & builder,
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 835 of file LLVMMemoryOps.cpp.

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

Referenced by createExtractAndCast(), and createInsertAndCast().

◆ castToSameSizedInt()

Value castToSameSizedInt ( OpBuilder & builder,
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 802 of file LLVMMemoryOps.cpp.

References mlir::OpBuilder::createOrFold(), mlir::Builder::getIntegerType(), mlir::Value::getType(), mlir::DataLayout::getTypeSizeInBits(), and isSupportedTypeForConversion().

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

◆ createExtractAndCast()

Value createExtractAndCast ( OpBuilder & builder,
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 864 of file LLVMMemoryOps.cpp.

References areConversionCompatible(), castIntValueToSameSizedType(), castSameSizedTypes(), castToSameSizedInt(), mlir::OpBuilder::createOrFold(), mlir::Builder::getIntegerAttr(), mlir::Builder::getIntegerType(), mlir::Value::getType(), mlir::DataLayout::getTypeSizeInBits(), isBigEndian(), and replacement().

◆ createInsertAndCast()

Value createInsertAndCast ( OpBuilder & builder,
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 905 of file LLVMMemoryOps.cpp.

References areConversionCompatible(), castIntValueToSameSizedType(), castSameSizedTypes(), castToSameSizedInt(), mlir::OpBuilder::createOrFold(), mlir::Builder::getIntegerAttr(), mlir::Value::getType(), mlir::DataLayout::getTypeSizeInBits(), and isBigEndian().

◆ destructureIndices()

void destructureIndices ( Type currType,
ArrayRef< GEPArg > indices,
SmallVectorImpl< int32_t > & rawConstantIndices,
SmallVectorImpl< Value > & dynamicIndices )
static

Destructures the 'indices' parameter into 'rawConstantIndices' and 'dynamicIndices', encoding the former in the process.

In the process, dynamic indices which are used to index into a structure type are converted to constant indices when possible. To do this, the GEPs element type should be passed as first parameter.

Definition at line 159 of file LLVMMemoryOps.cpp.

References indices, mlir::LLVM::kGEPConstantBitWidth, mlir::m_ConstantInt(), and mlir::matchPattern().

◆ gepToByteOffset()

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 1183 of file LLVMMemoryOps.cpp.

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

Referenced by getSubslotAccessInfo().

◆ getByteArrayType()

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

Constructs a byte array type of the given size.

Definition at line 1296 of file LLVMMemoryOps.cpp.

◆ getSubslotAccessInfo()

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 1244 of file LLVMMemoryOps.cpp.

References gepToByteOffset(), mlir::DataLayout::getTypeSize(), mlir::LLVM::kGEPConstantBitWidth, and mlir::MemorySlot::valueType.

◆ getTypeAtIndex()

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

Returns the subslot's type at the requested index.

Definition at line 1057 of file LLVMMemoryOps.cpp.

References mlir::MemorySlot::valueType.

◆ hasAllZeroIndices()

bool hasAllZeroIndices ( LLVM::GEPOp gepOp)
static

Definition at line 1157 of file LLVMMemoryOps.cpp.

◆ isBigEndian()

bool isBigEndian ( const DataLayout & dataLayout)
static

Checks if dataLayout describes a little endian layout.

Definition at line 795 of file LLVMMemoryOps.cpp.

References mlir::DataLayout::getEndianness().

Referenced by createExtractAndCast(), and createInsertAndCast().

◆ isSupportedTypeForConversion()

bool isSupportedTypeForConversion ( Type type)
static

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

Definition at line 753 of file LLVMMemoryOps.cpp.

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

◆ isValidAccessType()

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 1036 of file LLVMMemoryOps.cpp.

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

◆ verifyAtomicMemOp()

template<typename OpTy>
LogicalResult verifyAtomicMemOp ( OpTy memOp,
Type valueType,
ArrayRef< AtomicOrdering > unsupportedOrderings )
static

Verifies the attributes and the type of atomic memory access operations.

Definition at line 393 of file LLVMMemoryOps.cpp.

References mlir::DataLayout::closest(), mlir::LLVM::isTypeCompatibleWithAtomicOp(), and success().

◆ verifyStructIndices() [1/2]

LogicalResult verifyStructIndices ( Type baseGEPType,
GEPIndicesAdaptor< ValueRange > indices,
function_ref< InFlightDiagnostic()> emitOpError )
static

Driver function around verifyStructIndices.

Definition at line 314 of file LLVMMemoryOps.cpp.

References indices, and verifyStructIndices().

◆ verifyStructIndices() [2/2]

LogicalResult verifyStructIndices ( Type baseGEPType,
unsigned indexPos,
GEPIndicesAdaptor< ValueRange > indices,
function_ref< InFlightDiagnostic()> emitOpError )
static

For the given indices, check if they comply with baseGEPType, especially check against LLVMStructTypes nested within.

Definition at line 274 of file LLVMMemoryOps.cpp.

References indices, success(), and verifyStructIndices().

Referenced by verifyStructIndices(), and verifyStructIndices().

Variable Documentation

◆ kElemTypeAttrName

const char kElemTypeAttrName[] = "elem_type"
staticconstexpr

Definition at line 41 of file LLVMMemoryOps.cpp.