MLIR  16.0.0git
Macros | Functions
SPIRVConversion.cpp File Reference
#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/Transforms/DialectConversion.h"
#include "llvm/ADT/Sequence.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/Debug.h"
#include <functional>
+ Include dependency graph for SPIRVConversion.cpp:

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 candidatescapability 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 Optional< int64_t > getTypeNumBytes (const SPIRVConversionOptions &options, Type type)
 
static Type convertScalarType (const spirv::TargetEnv &targetEnv, const SPIRVConversionOptions &options, spirv::ScalarType type, Optional< spirv::StorageClass > storageClass={})
 Converts a scalar type to a suitable type under the given targetEnv. More...
 
static Type convertVectorType (const spirv::TargetEnv &targetEnv, const SPIRVConversionOptions &options, VectorType type, Optional< spirv::StorageClass > storageClass={})
 Converts a vector type to a suitable type under the given targetEnv. More...
 
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 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...
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "mlir-spirv-conversion"

Definition at line 25 of file SPIRVConversion.cpp.

Function Documentation

◆ checkCapabilityRequirements()

template<typename LabelT >
static LogicalResult checkCapabilityRequirements ( LabelT  label,
const spirv::TargetEnv targetEnv,
const spirv::SPIRVType::CapabilityArrayRefVector candidates 
)
static

Checks that candidatescapability 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 68 of file SPIRVConversion.cpp.

References mlir::spirv::TargetEnv::allows(), mlir::failure(), and mlir::success().

Referenced by convertScalarType(), convertVectorType(), and mlir::SPIRVConversionTarget::get().

◆ checkExtensionRequirements()

template<typename LabelT >
static LogicalResult checkExtensionRequirements ( LabelT  label,
const spirv::TargetEnv targetEnv,
const spirv::SPIRVType::ExtensionArrayRefVector candidates 
)
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 40 of file SPIRVConversion.cpp.

References mlir::spirv::TargetEnv::allows(), mlir::failure(), and mlir::success().

Referenced by convertScalarType(), convertVectorType(), and mlir::SPIRVConversionTarget::get().

◆ convertBoolMemrefType()

static Type convertBoolMemrefType ( const spirv::TargetEnv targetEnv,
const SPIRVConversionOptions options,
MemRefType  type,
spirv::StorageClass  storageClass 
)
static

◆ convertMemrefType()

static Type convertMemrefType ( const spirv::TargetEnv targetEnv,
const SPIRVConversionOptions options,
MemRefType  type 
)
static

◆ convertScalarType()

static Type convertScalarType ( const spirv::TargetEnv targetEnv,
const SPIRVConversionOptions options,
spirv::ScalarType  type,
Optional< spirv::StorageClass >  storageClass = {} 
)
static

◆ convertTensorType()

static Type convertTensorType ( const spirv::TargetEnv targetEnv,
const SPIRVConversionOptions options,
TensorType  type 
)
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 277 of file SPIRVConversion.cpp.

References convertScalarType(), mlir::Type::dyn_cast(), mlir::spirv::ArrayType::get(), mlir::TensorType::getElementType(), and getTypeNumBytes().

Referenced by mlir::SPIRVTypeConverter::SPIRVTypeConverter().

◆ convertVectorType()

static Type convertVectorType ( const spirv::TargetEnv targetEnv,
const SPIRVConversionOptions options,
VectorType  type,
Optional< spirv::StorageClass >  storageClass = {} 
)
static

Converts a vector type to a suitable type under the given targetEnv.

Definition at line 238 of file SPIRVConversion.cpp.

References checkCapabilityRequirements(), checkExtensionRequirements(), convertScalarType(), mlir::spirv::CompositeType::isValid(), and mlir::succeeded().

Referenced by convertMemrefType(), and mlir::SPIRVTypeConverter::SPIRVTypeConverter().

◆ getBuiltinVariable()

static spirv::GlobalVariableOp getBuiltinVariable ( Block body,
spirv::BuiltIn  builtin 
)
static

Definition at line 549 of file SPIRVConversion.cpp.

References mlir::Block::getOps().

Referenced by getOrInsertBuiltinVariable().

◆ getBuiltinVarName()

static std::string getBuiltinVarName ( spirv::BuiltIn  builtin)
static

Gets name of global variable for a builtin.

Definition at line 567 of file SPIRVConversion.cpp.

Referenced by getOrInsertBuiltinVariable().

◆ getOrInsertBuiltinVariable()

static spirv::GlobalVariableOp getOrInsertBuiltinVariable ( Block body,
Location  loc,
spirv::BuiltIn  builtin,
Type  integerType,
OpBuilder builder 
)
static

◆ getOrInsertPushConstantVariable()

static spirv::GlobalVariableOp getOrInsertPushConstantVariable ( Location  loc,
Block block,
unsigned  elementCount,
OpBuilder b,
Type  indexType 
)
static

Gets or inserts a global variable for push constant storage containing elementCount 32-bit integer values in block.

Definition at line 672 of file SPIRVConversion.cpp.

References mlir::OpBuilder::atBlockBegin(), mlir::OpBuilder::create(), mlir::OpBuilder::getListener(), getPushConstantStorageType(), and getPushConstantVariable().

Referenced by mlir::spirv::getPushConstantValue().

◆ getPushConstantStorageType()

static spirv::PointerType getPushConstantStorageType ( unsigned  elementCount,
Builder builder,
Type  indexType 
)
static

Returns the pointer type for the push constant storage containing elementCount 32-bit integer values.

Definition at line 635 of file SPIRVConversion.cpp.

References mlir::spirv::ArrayType::get(), mlir::spirv::PointerType::get(), and mlir::spirv::StructType::get().

Referenced by getOrInsertPushConstantVariable().

◆ getPushConstantVariable()

static spirv::GlobalVariableOp getPushConstantVariable ( Block body,
unsigned  elementCount 
)
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 646 of file SPIRVConversion.cpp.

References mlir::Type::cast(), getElementType(), getNumElements(), mlir::Block::getOps(), and mlir::spirv::PointerType::getPointeeType().

Referenced by getOrInsertPushConstantVariable().

◆ getTypeNumBytes()

static Optional<int64_t> getTypeNumBytes ( const SPIRVConversionOptions options,
Type  type 
)
static

◆ needsExplicitLayout()

static bool needsExplicitLayout ( spirv::StorageClass  storageClass)
static

Returns true if the given storageClass needs explicit layout when used in Shader environments.

Definition at line 91 of file SPIRVConversion.cpp.

Referenced by convertBoolMemrefType(), convertMemrefType(), and wrapInStructAndGetPointer().

◆ wrapInStructAndGetPointer()

static spirv::PointerType wrapInStructAndGetPointer ( Type  elementType,
spirv::StorageClass  storageClass 
)
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 106 of file SPIRVConversion.cpp.

References mlir::spirv::PointerType::get(), mlir::spirv::StructType::get(), and needsExplicitLayout().

Referenced by convertBoolMemrefType(), and convertMemrefType().