|
MLIR 24.0.0git
|
#include "mlir/Conversion/SPIRVToLLVM/SPIRVToLLVM.h"#include "mlir/Conversion/LLVMCommon/TypeConverter.h"#include "mlir/Conversion/SPIRVCommon/AttrToLLVMConverter.h"#include "mlir/Dialect/LLVMIR/LLVMDialect.h"#include "mlir/Dialect/SPIRV/IR/SPIRVEnums.h"#include "mlir/Dialect/SPIRV/IR/SPIRVOps.h"#include "mlir/Dialect/SPIRV/Utils/LayoutUtils.h"#include "mlir/IR/BuiltinOps.h"#include "mlir/IR/PatternMatch.h"#include "mlir/Transforms/DialectConversion.h"#include "llvm/ADT/TypeSwitch.h"#include "llvm/Support/FormatVariadic.h"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< Type > | convertArrayType (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< Type > | convertRuntimeArrayType (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" |
| #define DEBUG_TYPE "spirv-to-llvm-pattern" |
Definition at line 26 of file SPIRVToLLVM.cpp.
| #define DISPATCH | ( | functionControl, | |
| llvmAttr ) |
|
static |
Broadcasts the value to vector with numElements number of elements.
Definition at line 146 of file SPIRVToLLVM.cpp.
References mlir::Value::getType().
Referenced by mlir::xegpu::createXeGPUPropagateLayout(), mlir::linalg::hoistRedundantVectorBroadcasts(), mlir::math::ErfcPolynomialApproximation::matchAndRewrite(), mlir::math::ErfPolynomialApproximation::matchAndRewrite(), optionallyBroadcast(), and supportsMMaMatrixType().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
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().
|
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.
Returns the bit width of LLVMType integer or vector.
Definition at line 77 of file SPIRVToLLVM.cpp.
Referenced by optionallyTruncateOrExtend().
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().
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().
|
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().
|
static |
Utility function for bitfield ops:
Definition at line 125 of file SPIRVToLLVM.cpp.
References getBitWidth(), getLLVMTypeBitWidth(), mlir::Value::getType(), and mlir::LLVM::isCompatibleType().
Referenced by processCountOrOffset().
|
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:
Definition at line 183 of file SPIRVToLLVM.cpp.
References optionallyBroadcast(), and optionallyTruncateOrExtend().
|
static |
Utility for spirv.Load and spirv.Store conversion.
Definition at line 224 of file SPIRVToLLVM.cpp.
References success().
|
staticconstexpr |
Hook for descriptor set and binding number encoding.
Definition at line 2186 of file SPIRVToLLVM.cpp.
Referenced by mlir::encodeBindAttribute().
|
staticconstexpr |
Definition at line 2187 of file SPIRVToLLVM.cpp.
Referenced by mlir::encodeBindAttribute().