MLIR 24.0.0git
SPIRVToLLVM.cpp File Reference

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "spirv-to-llvm-pattern"
#define DISPATCH(functionControl, llvmAttr)

Functions

static bool isSignedIntegerOrVector (Type type)
 Returns true if the given type is a signed integer or vector type.
static bool isUnsignedIntegerOrVector (Type type)
 Returns true if the given type is an unsigned integer or vector type.
static std::optional< uint64_t > getIntegerOrVectorElementWidth (Type type)
 Returns the width of an integer or of the element type of an integer vector, if applicable.
static unsigned getBitWidth (Type type)
 Returns the bit width of integer, float or vector of float or integer values.
static unsigned getLLVMTypeBitWidth (Type type)
 Returns the bit width of LLVMType integer or vector.
static Value createIntegerConstant (Location loc, Type srcType, Type dstType, PatternRewriter &rewriter, IntegerAttr scalarAttr)
 Creates llvm.mlir.constant with a scalar or vector integer value, broadcasting scalarAttr across the vector if srcType is a vector.
static Value createConstantAllBitsSet (Location loc, Type srcType, Type dstType, PatternRewriter &rewriter)
 Creates llvm.mlir.constant with all bits set for the given type.
static Value createFPConstant (Location loc, Type srcType, Type dstType, PatternRewriter &rewriter, double value)
 Creates llvm.mlir.constant with a floating-point scalar or vector value.
static Value optionallyTruncateOrExtend (Location loc, Value value, Type llvmType, PatternRewriter &rewriter)
 Utility function for bitfield ops:
static Value broadcast (Location loc, Value toBroadcast, unsigned numElements, const TypeConverter &typeConverter, ConversionPatternRewriter &rewriter)
 Broadcasts the value to vector with numElements number of elements.
static Value optionallyBroadcast (Location loc, Value value, Type srcType, const TypeConverter &typeConverter, ConversionPatternRewriter &rewriter)
 Broadcasts the value. If srcType is a scalar, the value remains unchanged.
static Value processCountOrOffset (Location loc, Value value, Type srcType, Type dstType, const TypeConverter &converter, ConversionPatternRewriter &rewriter)
 Utility function for bitfield ops: BitFieldInsert, BitFieldSExtract and BitFieldUExtract.
static Type convertStructTypeWithOffset (spirv::StructType type, const TypeConverter &converter)
 Converts SPIR-V struct with a regular (according to VulkanLayoutUtils) offset to LLVM struct.
static Type convertStructTypePacked (spirv::StructType type, const TypeConverter &converter)
 Converts SPIR-V struct with no offset to packed LLVM struct.
static Value createI32ConstantOf (Location loc, PatternRewriter &rewriter, unsigned value)
 Creates LLVM dialect constant with the given value.
static LogicalResult replaceWithLoadOrStore (Operation *op, ValueRange operands, ConversionPatternRewriter &rewriter, const TypeConverter &typeConverter, unsigned alignment, bool isVolatile, bool isNonTemporal)
 Utility for spirv.Load and spirv.Store conversion.
static std::optional< TypeconvertArrayType (spirv::ArrayType type, TypeConverter &converter)
 Converts SPIR-V array type to LLVM array.
static Type convertPointerType (spirv::PointerType type, const TypeConverter &converter, spirv::ClientAPI clientAPI)
 Converts SPIR-V pointer type to LLVM pointer.
static std::optional< TypeconvertRuntimeArrayType (spirv::RuntimeArrayType type, TypeConverter &converter)
 Converts SPIR-V runtime array to LLVM array.
static Type convertStructType (spirv::StructType type, const TypeConverter &converter)
 Converts SPIR-V struct to LLVM struct.

Variables

static constexpr StringRef kBinding = "binding"
 Hook for descriptor set and binding number encoding.
static constexpr StringRef kDescriptorSet = "descriptor_set"

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "spirv-to-llvm-pattern"

Definition at line 26 of file SPIRVToLLVM.cpp.

◆ DISPATCH

#define DISPATCH ( functionControl,
llvmAttr )
Value:
case functionControl: \
newFuncOp->setAttr("passthrough", ArrayAttr::get(context, {llvmAttr})); \
break;

Function Documentation

◆ broadcast()

Value broadcast ( Location loc,
Value toBroadcast,
unsigned numElements,
const TypeConverter & typeConverter,
ConversionPatternRewriter & rewriter )
static

◆ convertArrayType()

std::optional< Type > convertArrayType ( spirv::ArrayType type,
TypeConverter & converter )
static

Converts SPIR-V array type to LLVM array.

Natural stride (according to VulkanLayoutUtils) is also mapped to LLVM array. This has to be respected when converting ops that manipulate array types.

Definition at line 253 of file SPIRVToLLVM.cpp.

References mlir::spirv::ArrayType::getArrayStride(), mlir::spirv::ArrayType::getElementType(), and mlir::spirv::ArrayType::getNumElements().

Referenced by mlir::populateSPIRVToLLVMTypeConversion().

◆ convertPointerType()

Type convertPointerType ( spirv::PointerType type,
const TypeConverter & converter,
spirv::ClientAPI clientAPI )
static

Converts SPIR-V pointer type to LLVM pointer.

Pointer's storage class is not modelled at the moment.

Definition at line 268 of file SPIRVToLLVM.cpp.

References mlir::spirv::PointerType::getStorageClass(), and mlir::storageClassToAddressSpace().

Referenced by mlir::populateSPIRVToLLVMTypeConversion().

◆ convertRuntimeArrayType()

std::optional< Type > convertRuntimeArrayType ( spirv::RuntimeArrayType type,
TypeConverter & converter )
static

Converts SPIR-V runtime array to LLVM array.

Since LLVM allows indexing over the bounds, the runtime array is converted to a 0-sized LLVM array. There is no modelling of array stride at the moment.

Definition at line 279 of file SPIRVToLLVM.cpp.

References mlir::spirv::RuntimeArrayType::getArrayStride(), and mlir::spirv::RuntimeArrayType::getElementType().

Referenced by mlir::populateSPIRVToLLVMTypeConversion().

◆ convertStructType()

Type convertStructType ( spirv::StructType type,
const TypeConverter & converter )
static

Converts SPIR-V struct to LLVM struct.

There is no support of structs with member decorations. Also, only natural offset is supported.

Definition at line 289 of file SPIRVToLLVM.cpp.

References convertStructTypePacked(), convertStructTypeWithOffset(), mlir::spirv::StructType::getMemberDecorations(), and mlir::spirv::StructType::hasOffset().

Referenced by mlir::populateSPIRVToLLVMTypeConversion().

◆ convertStructTypePacked()

Type convertStructTypePacked ( spirv::StructType type,
const TypeConverter & converter )
static

Converts SPIR-V struct with no offset to packed LLVM struct.

Definition at line 206 of file SPIRVToLLVM.cpp.

References mlir::spirv::StructType::getElementTypes().

Referenced by convertStructType().

◆ convertStructTypeWithOffset()

Type convertStructTypeWithOffset ( spirv::StructType type,
const TypeConverter & converter )
static

Converts SPIR-V struct with a regular (according to VulkanLayoutUtils) offset to LLVM struct.

Otherwise, the conversion is not supported.

Definition at line 193 of file SPIRVToLLVM.cpp.

References mlir::VulkanLayoutUtils::decorateType(), and mlir::spirv::StructType::getElementTypes().

Referenced by convertStructType().

◆ createConstantAllBitsSet()

Value createConstantAllBitsSet ( Location loc,
Type srcType,
Type dstType,
PatternRewriter & rewriter )
static

Creates llvm.mlir.constant with all bits set for the given type.

Definition at line 95 of file SPIRVToLLVM.cpp.

References createIntegerConstant(), getElementType(), and mlir::Builder::getIntegerAttr().

◆ createFPConstant()

Value createFPConstant ( Location loc,
Type srcType,
Type dstType,
PatternRewriter & rewriter,
double value )
static

Creates llvm.mlir.constant with a floating-point scalar or vector value.

Definition at line 105 of file SPIRVToLLVM.cpp.

References mlir::DenseElementsAttr::get(), and mlir::Builder::getFloatAttr().

◆ createI32ConstantOf()

Value createI32ConstantOf ( Location loc,
PatternRewriter & rewriter,
unsigned value )
static

Creates LLVM dialect constant with the given value.

Definition at line 216 of file SPIRVToLLVM.cpp.

References mlir::Builder::getContext(), mlir::Builder::getI32Type(), and mlir::Builder::getIntegerAttr().

◆ createIntegerConstant()

Value createIntegerConstant ( Location loc,
Type srcType,
Type dstType,
PatternRewriter & rewriter,
IntegerAttr scalarAttr )
static

Creates llvm.mlir.constant with a scalar or vector integer value, broadcasting scalarAttr across the vector if srcType is a vector.

Definition at line 85 of file SPIRVToLLVM.cpp.

References mlir::DenseElementsAttr::get().

Referenced by createConstantAllBitsSet().

◆ getBitWidth()

unsigned getBitWidth ( Type type)
static

Returns the bit width of integer, float or vector of float or integer values.

Definition at line 64 of file SPIRVToLLVM.cpp.

References mlir::Type::getIntOrFloatBitWidth(), and mlir::Type::isIntOrFloat().

Referenced by optionallyTruncateOrExtend().

◆ getIntegerOrVectorElementWidth()

std::optional< uint64_t > getIntegerOrVectorElementWidth ( Type type)
static

Returns the width of an integer or of the element type of an integer vector, if applicable.

Definition at line 54 of file SPIRVToLLVM.cpp.

◆ getLLVMTypeBitWidth()

unsigned getLLVMTypeBitWidth ( Type type)
static

Returns the bit width of LLVMType integer or vector.

Definition at line 77 of file SPIRVToLLVM.cpp.

Referenced by optionallyTruncateOrExtend().

◆ isSignedIntegerOrVector()

bool isSignedIntegerOrVector ( Type type)
static

Returns true if the given type is a signed integer or vector type.

Definition at line 35 of file SPIRVToLLVM.cpp.

References mlir::Type::isSignedInteger().

◆ isUnsignedIntegerOrVector()

bool isUnsignedIntegerOrVector ( Type type)
static

Returns true if the given type is an unsigned integer or vector type.

Definition at line 44 of file SPIRVToLLVM.cpp.

References mlir::Type::isUnsignedInteger().

◆ optionallyBroadcast()

Value optionallyBroadcast ( Location loc,
Value value,
Type srcType,
const TypeConverter & typeConverter,
ConversionPatternRewriter & rewriter )
static

Broadcasts the value. If srcType is a scalar, the value remains unchanged.

Definition at line 163 of file SPIRVToLLVM.cpp.

References broadcast().

Referenced by processCountOrOffset().

◆ optionallyTruncateOrExtend()

Value optionallyTruncateOrExtend ( Location loc,
Value value,
Type llvmType,
PatternRewriter & rewriter )
static

Utility function for bitfield ops:

  • BitFieldInsert
  • BitFieldSExtract
  • BitFieldUExtract Truncates or extends the value. If the bitwidth of the value is the same as llvmType bitwidth, the value remains unchanged.

Definition at line 125 of file SPIRVToLLVM.cpp.

References getBitWidth(), getLLVMTypeBitWidth(), mlir::Value::getType(), and mlir::LLVM::isCompatibleType().

Referenced by processCountOrOffset().

◆ processCountOrOffset()

Value processCountOrOffset ( Location loc,
Value value,
Type srcType,
Type dstType,
const TypeConverter & converter,
ConversionPatternRewriter & rewriter )
static

Utility function for bitfield ops: BitFieldInsert, BitFieldSExtract and BitFieldUExtract.

Broadcast Offset and Count to match the type of Base. If Base is of a vector type, construct a vector that has:

  • same number of elements as Base
  • each element has the type that is the same as the type of Offset or Count
  • each element has the same value as Offset or Count Then cast Offset and Count if their bit width is different from Base bit width.

Definition at line 183 of file SPIRVToLLVM.cpp.

References optionallyBroadcast(), and optionallyTruncateOrExtend().

◆ replaceWithLoadOrStore()

LogicalResult replaceWithLoadOrStore ( Operation * op,
ValueRange operands,
ConversionPatternRewriter & rewriter,
const TypeConverter & typeConverter,
unsigned alignment,
bool isVolatile,
bool isNonTemporal )
static

Utility for spirv.Load and spirv.Store conversion.

Definition at line 224 of file SPIRVToLLVM.cpp.

References success().

Variable Documentation

◆ kBinding

StringRef kBinding = "binding"
staticconstexpr

Hook for descriptor set and binding number encoding.

Definition at line 2186 of file SPIRVToLLVM.cpp.

Referenced by mlir::encodeBindAttribute().

◆ kDescriptorSet

StringRef kDescriptorSet = "descriptor_set"
staticconstexpr

Definition at line 2187 of file SPIRVToLLVM.cpp.

Referenced by mlir::encodeBindAttribute().