MLIR  16.0.0git
Namespaces | Macros | Functions
MemRefToSPIRV.cpp File Reference
#include "mlir/Dialect/MemRef/IR/MemRef.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/Transforms/SPIRVConversion.h"
#include "llvm/Support/Debug.h"
+ Include dependency graph for MemRefToSPIRV.cpp:

Go to the source code of this file.

Namespaces

 mlir
 Include the generated interface declarations.
 

Macros

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

Functions

static Value getOffsetForBitwidth (Location loc, Value srcIdx, int sourceBits, int targetBits, OpBuilder &builder)
 Returns the offset of the value in targetBits representation. More...
 
static Value adjustAccessChainForBitwidth (SPIRVTypeConverter &typeConverter, spirv::AccessChainOp op, int sourceBits, int targetBits, OpBuilder &builder)
 Returns an adjusted spirv::AccessChainOp. More...
 
static Value shiftValue (Location loc, Value value, Value offset, Value mask, int targetBits, OpBuilder &builder)
 Returns the shifted targetBits-bit value with the given offset. More...
 
static bool isAllocationSupported (Operation *allocOp, MemRefType type)
 Returns true if the allocations of memref type generated from allocOp can be lowered to SPIR-V. More...
 
static Optional< spirv::Scope > getAtomicOpScope (MemRefType type)
 Returns the scope to use for atomic operations use for emulating store operations of unsupported integer bitwidths, based on the memref type. More...
 
static Value castIntNToBool (Location loc, Value srcInt, OpBuilder &builder)
 Casts the given srcInt into a boolean value. More...
 
static Value castBoolToIntN (Location loc, Value srcBool, Type dstType, OpBuilder &builder)
 Casts the given srcBool into an integer of dstType. More...
 
void mlir::populateMemRefToSPIRVPatterns (SPIRVTypeConverter &typeConverter, RewritePatternSet &patterns)
 Appends to a pattern list additional patterns for translating MemRef ops to SPIR-V ops. More...
 

Macro Definition Documentation

◆ DEBUG_TYPE

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

Definition at line 20 of file MemRefToSPIRV.cpp.

Function Documentation

◆ adjustAccessChainForBitwidth()

static Value adjustAccessChainForBitwidth ( SPIRVTypeConverter typeConverter,
spirv::AccessChainOp  op,
int  sourceBits,
int  targetBits,
OpBuilder builder 
)
static

Returns an adjusted spirv::AccessChainOp.

Based on the extension/capabilities, certain integer bitwidths sourceBits might not be supported. During conversion if a memref of an unsupported type is used, load/stores to this memref need to be modified to use a supported higher bitwidth targetBits and extracting the required bits. For an accessing a 1D array (spv.array or spv.rt_array), the last index is modified to load the bits needed. The extraction of the actual bits needed are handled separately. Note that this only works for a 1-D tensor.

Definition at line 61 of file MemRefToSPIRV.cpp.

References mlir::TypeConverter::convertType(), mlir::OpBuilder::create(), mlir::Builder::getIntegerAttr(), mlir::Builder::getIntegerType(), and mlir::Operation::getOperand().

Referenced by castBoolToIntN().

◆ castBoolToIntN()

static Value castBoolToIntN ( Location  loc,
Value  srcBool,
Type  dstType,
OpBuilder builder 
)
static

◆ castIntNToBool()

static Value castIntNToBool ( Location  loc,
Value  srcInt,
OpBuilder builder 
)
static

Casts the given srcInt into a boolean value.

Definition at line 132 of file MemRefToSPIRV.cpp.

References mlir::OpBuilder::create(), mlir::Value::getType(), and mlir::Type::isInteger().

Referenced by castBoolToIntN().

◆ getAtomicOpScope()

static Optional<spirv::Scope> getAtomicOpScope ( MemRefType  type)
static

Returns the scope to use for atomic operations use for emulating store operations of unsupported integer bitwidths, based on the memref type.

Returns None on failure.

Definition at line 118 of file MemRefToSPIRV.cpp.

Referenced by castBoolToIntN().

◆ getOffsetForBitwidth()

static Value getOffsetForBitwidth ( Location  loc,
Value  srcIdx,
int  sourceBits,
int  targetBits,
OpBuilder builder 
)
static

Returns the offset of the value in targetBits representation.

srcIdx is an index into a 1-D array with each element having sourceBits. It's assumed to be non-negative.

When accessing an element in the array treating as having elements of targetBits, multiple values are loaded in the same time. The method returns the offset where the srcIdx locates in the value. For example, if sourceBits equals to 8 and targetBits equals to 32, the x-th element is located at (x % 4) * 8. Because there are four elements in one i32, and one element has 8 bits.

Definition at line 39 of file MemRefToSPIRV.cpp.

References mlir::OpBuilder::create(), mlir::Builder::getIntegerAttr(), and mlir::Builder::getIntegerType().

Referenced by castBoolToIntN().

◆ isAllocationSupported()

static bool isAllocationSupported ( Operation allocOp,
MemRefType  type 
)
static

Returns true if the allocations of memref type generated from allocOp can be lowered to SPIR-V.

Definition at line 91 of file MemRefToSPIRV.cpp.

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

Referenced by castBoolToIntN().

◆ shiftValue()

static Value shiftValue ( Location  loc,
Value  value,
Value  offset,
Value  mask,
int  targetBits,
OpBuilder builder 
)
static

Returns the shifted targetBits-bit value with the given offset.

Definition at line 81 of file MemRefToSPIRV.cpp.

References mlir::OpBuilder::create(), mlir::Builder::getIntegerType(), and value.

Referenced by castBoolToIntN().