MLIR
17.0.0git
|
#include "mlir/Dialect/SPIRV/Transforms/SPIRVConversion.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h"
#include "mlir/Dialect/SPIRV/IR/SPIRVEnums.h"
#include "mlir/Dialect/SPIRV/IR/SPIRVOps.h"
#include "mlir/Dialect/SPIRV/IR/SPIRVTypes.h"
#include "mlir/Dialect/SPIRV/IR/TargetAndABI.h"
#include "mlir/Transforms/DialectConversion.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/MathExtras.h"
#include <functional>
#include <optional>
Go to the source code of this file.
Macros | |
#define | DEBUG_TYPE "mlir-spirv-conversion" |
Functions | |
template<typename LabelT > | |
static LogicalResult | checkExtensionRequirements (LabelT label, const spirv::TargetEnv &targetEnv, const spirv::SPIRVType::ExtensionArrayRefVector &candidates) |
Checks that candidates extension requirements are possible to be satisfied with the given targetEnv . More... | |
template<typename LabelT > | |
static LogicalResult | checkCapabilityRequirements (LabelT label, const spirv::TargetEnv &targetEnv, const spirv::SPIRVType::CapabilityArrayRefVector &candidates) |
Checks that candidates capability requirements are possible to be satisfied with the given isAllowedFn . More... | |
static bool | needsExplicitLayout (spirv::StorageClass storageClass) |
Returns true if the given storageClass needs explicit layout when used in Shader environments. More... | |
static spirv::PointerType | wrapInStructAndGetPointer (Type elementType, spirv::StorageClass storageClass) |
Wraps the given elementType in a struct and gets the pointer to the struct. More... | |
static spirv::ScalarType | getIndexType (MLIRContext *ctx, const SPIRVConversionOptions &options) |
static std::optional< int64_t > | getTypeNumBytes (const SPIRVConversionOptions &options, Type type) |
static Type | convertScalarType (const spirv::TargetEnv &targetEnv, const SPIRVConversionOptions &options, spirv::ScalarType type, std::optional< spirv::StorageClass > storageClass={}) |
Converts a scalar type to a suitable type under the given targetEnv . More... | |
static Type | convertSubByteIntegerType (const SPIRVConversionOptions &options, IntegerType type) |
Converts a sub-byte integer type to i32 regardless of target environment. More... | |
static ShapedType | convertIndexElementType (ShapedType type, const SPIRVConversionOptions &options) |
Returns a type with the same shape but with any index element type converted to the matching integer type. More... | |
static Type | convertVectorType (const spirv::TargetEnv &targetEnv, const SPIRVConversionOptions &options, VectorType type, std::optional< spirv::StorageClass > storageClass={}) |
Converts a vector type to a suitable type under the given targetEnv . More... | |
static Type | convertComplexType (const spirv::TargetEnv &targetEnv, const SPIRVConversionOptions &options, ComplexType type, std::optional< spirv::StorageClass > storageClass={}) |
static Type | convertTensorType (const spirv::TargetEnv &targetEnv, const SPIRVConversionOptions &options, TensorType type) |
Converts a tensor type to a suitable type under the given targetEnv . More... | |
static Type | convertBoolMemrefType (const spirv::TargetEnv &targetEnv, const SPIRVConversionOptions &options, MemRefType type, spirv::StorageClass storageClass) |
static Type | convertSubByteMemrefType (const spirv::TargetEnv &targetEnv, const SPIRVConversionOptions &options, MemRefType type, spirv::StorageClass storageClass) |
static Type | convertMemrefType (const spirv::TargetEnv &targetEnv, const SPIRVConversionOptions &options, MemRefType type) |
static spirv::GlobalVariableOp | getBuiltinVariable (Block &body, spirv::BuiltIn builtin) |
static std::string | getBuiltinVarName (spirv::BuiltIn builtin) |
Gets name of global variable for a builtin. More... | |
static spirv::GlobalVariableOp | getOrInsertBuiltinVariable (Block &body, Location loc, spirv::BuiltIn builtin, Type integerType, OpBuilder &builder) |
Gets or inserts a global variable for a builtin within body block. More... | |
static spirv::PointerType | getPushConstantStorageType (unsigned elementCount, Builder &builder, Type indexType) |
Returns the pointer type for the push constant storage containing elementCount 32-bit integer values. More... | |
static spirv::GlobalVariableOp | getPushConstantVariable (Block &body, unsigned elementCount) |
Returns the push constant varible containing elementCount 32-bit integer values in body . More... | |
static spirv::GlobalVariableOp | getOrInsertPushConstantVariable (Location loc, Block &block, unsigned elementCount, OpBuilder &b, Type indexType) |
Gets or inserts a global variable for push constant storage containing elementCount 32-bit integer values in block . More... | |
#define DEBUG_TYPE "mlir-spirv-conversion" |
Definition at line 28 of file SPIRVConversion.cpp.
|
static |
Checks that candidates
capability requirements are possible to be satisfied with the given isAllowedFn
.
candidates
is a vector of vector for capability requirements following ((Capability::A OR Capability::B) AND (Capability::C OR Capability::D)) convention.
Definition at line 71 of file SPIRVConversion.cpp.
References mlir::spirv::TargetEnv::allows(), mlir::failure(), and mlir::success().
|
static |
Checks that candidates
extension requirements are possible to be satisfied with the given targetEnv
.
candidates
is a vector of vector for extension requirements following ((Extension::A OR Extension::B) AND (Extension::C OR Extension::D)) convention.
Definition at line 43 of file SPIRVConversion.cpp.
References mlir::spirv::TargetEnv::allows(), mlir::failure(), and mlir::success().
|
static |
Definition at line 408 of file SPIRVConversion.cpp.
References mlir::spirv::TargetEnv::allows(), convertScalarType(), mlir::get(), mlir::spirv::RuntimeArrayType::get(), mlir::spirv::ArrayType::get(), mlir::spirv::PointerType::get(), getTypeNumBytes(), needsExplicitLayout(), options, and wrapInStructAndGetPointer().
Referenced by convertMemrefType().
|
static |
Definition at line 338 of file SPIRVConversion.cpp.
Referenced by convertMemrefType(), and mlir::SPIRVTypeConverter::SPIRVTypeConverter().
|
static |
Returns a type with the same shape but with any index element type converted to the matching integer type.
This is a noop when the element type is not the index type.
Definition at line 289 of file SPIRVConversion.cpp.
References getIndexType(), and options.
Referenced by convertMemrefType(), and convertTensorType().
|
static |
Definition at line 487 of file SPIRVConversion.cpp.
References mlir::spirv::TargetEnv::allows(), convertBoolMemrefType(), convertComplexType(), convertIndexElementType(), convertScalarType(), convertSubByteMemrefType(), convertVectorType(), mlir::spirv::RuntimeArrayType::get(), mlir::spirv::ArrayType::get(), mlir::spirv::PointerType::get(), getTypeNumBytes(), needsExplicitLayout(), options, and wrapInStructAndGetPointer().
Referenced by mlir::SPIRVTypeConverter::SPIRVTypeConverter().
|
static |
Converts a scalar type
to a suitable type under the given targetEnv
.
Definition at line 222 of file SPIRVConversion.cpp.
Referenced by convertBoolMemrefType(), convertMemrefType(), convertTensorType(), and mlir::SPIRVTypeConverter::SPIRVTypeConverter().
|
static |
Converts a sub-byte integer type
to i32 regardless of target environment.
Note that we don't recognize sub-byte types in spirv::ScalarType
and use the above given that these sub-byte types are not supported at all in SPIR-V; there are no compute/storage capability for them like other supported integer types.
Definition at line 266 of file SPIRVConversion.cpp.
References mlir::get(), options, and mlir::Packed.
Referenced by convertSubByteMemrefType(), and mlir::SPIRVTypeConverter::SPIRVTypeConverter().
|
static |
Definition at line 455 of file SPIRVConversion.cpp.
References mlir::spirv::TargetEnv::allows(), convertSubByteIntegerType(), mlir::spirv::RuntimeArrayType::get(), mlir::spirv::ArrayType::get(), mlir::spirv::PointerType::get(), getTypeNumBytes(), needsExplicitLayout(), options, and wrapInStructAndGetPointer().
Referenced by convertMemrefType().
|
static |
Converts a tensor type
to a suitable type under the given targetEnv
.
Note that this is mainly for lowering constant tensors. In SPIR-V one can create composite constants with OpConstantComposite to embed relative large constant values and use OpCompositeExtract and OpCompositeInsert to manipulate, like what we do for vectors.
Definition at line 367 of file SPIRVConversion.cpp.
References convertIndexElementType(), convertScalarType(), mlir::spirv::ArrayType::get(), mlir::TensorType::getElementType(), getTypeNumBytes(), and options.
Referenced by mlir::SPIRVTypeConverter::SPIRVTypeConverter().
|
static |
Converts a vector type
to a suitable type under the given targetEnv
.
Definition at line 300 of file SPIRVConversion.cpp.
Referenced by convertMemrefType(), and mlir::SPIRVTypeConverter::SPIRVTypeConverter().
|
static |
Definition at line 687 of file SPIRVConversion.cpp.
References mlir::Block::getOps().
Referenced by getOrInsertBuiltinVariable().
|
static |
Gets name of global variable for a builtin.
Definition at line 705 of file SPIRVConversion.cpp.
Referenced by getOrInsertBuiltinVariable().
|
static |
Definition at line 120 of file SPIRVConversion.cpp.
References mlir::get(), and options.
Referenced by convertIndexElementType(), and mlir::SPIRVTypeConverter::getIndexType().
|
static |
Gets or inserts a global variable for a builtin within body
block.
Definition at line 711 of file SPIRVConversion.cpp.
References mlir::OpBuilder::create(), mlir::emitError(), mlir::get(), mlir::spirv::PointerType::get(), getBuiltinVariable(), getBuiltinVarName(), and mlir::OpBuilder::setInsertionPointToStart().
|
static |
Gets or inserts a global variable for push constant storage containing elementCount
32-bit integer values in block
.
Definition at line 809 of file SPIRVConversion.cpp.
References mlir::OpBuilder::atBlockBegin(), mlir::OpBuilder::create(), mlir::OpBuilder::getListener(), getPushConstantStorageType(), and getPushConstantVariable().
|
static |
Returns the pointer type for the push constant storage containing elementCount
32-bit integer values.
Definition at line 773 of file SPIRVConversion.cpp.
References mlir::spirv::StructType::get(), mlir::spirv::ArrayType::get(), and mlir::spirv::PointerType::get().
Referenced by getOrInsertPushConstantVariable().
|
static |
Returns the push constant varible containing elementCount
32-bit integer values in body
.
Returns null op if such an op does not exit.
Definition at line 784 of file SPIRVConversion.cpp.
References mlir::Block::getOps().
Referenced by getOrInsertPushConstantVariable().
|
static |
Definition at line 141 of file SPIRVConversion.cpp.
References mlir::detail::enumerate(), mlir::failed(), mlir::Type::getIntOrFloatBitWidth(), mlir::getStridesAndOffset(), max(), and options.
Referenced by convertBoolMemrefType(), convertMemrefType(), convertSubByteMemrefType(), and convertTensorType().
|
static |
Returns true if the given storageClass
needs explicit layout when used in Shader environments.
Definition at line 94 of file SPIRVConversion.cpp.
Referenced by convertBoolMemrefType(), convertMemrefType(), convertSubByteMemrefType(), and wrapInStructAndGetPointer().
|
static |
Wraps the given elementType
in a struct and gets the pointer to the struct.
This is used to satisfy Vulkan interface requirements.
Definition at line 109 of file SPIRVConversion.cpp.
References mlir::spirv::StructType::get(), mlir::spirv::PointerType::get(), and needsExplicitLayout().
Referenced by convertBoolMemrefType(), convertMemrefType(), and convertSubByteMemrefType().