MLIR 22.0.0git
mlir::spirv::Deserializer Class Reference

A SPIR-V module serializer. More...

#include "Target/SPIRV/Deserialization/Deserializer.h"

Public Types

using BlockPhiInfo
 For OpPhi instructions, we use block arguments to represent them.

Public Member Functions

LogicalResult processFunction (ArrayRef< uint32_t > operands)
 Creates a deserializer for the given SPIR-V binary module.
LogicalResult processFunctionEnd (ArrayRef< uint32_t > operands)
 Processes OpFunctionEnd and finalizes function.
std::optional< std::pair< Attribute, Type > > getConstant (uint32_t id)
 Gets the constant's attribute and type associated with the given <id>.
std::optional< std::pair< Attribute, Type > > getConstantCompositeReplicate (uint32_t id)
 Gets the replicated composite constant's attribute and type associated with the given <id>.
std::optional< SpecConstOperationMaterializationInfogetSpecConstantOperation (uint32_t id)
 Gets the info needed to materialize the spec constant operation op associated with the given <id>.
IntegerAttr getConstantInt (uint32_t id)
 Gets the constant's integer attribute with the given <id>.
std::string getFunctionSymbol (uint32_t id)
 Returns a symbol to be used for the function name with the given result <id>.
std::string getGraphSymbol (uint32_t id)
 Returns a symbol to be used for the graph name with the given result <id>.
std::string getSpecConstantSymbol (uint32_t id)
 Returns a symbol to be used for the specialization constant with the given result <id>.
spirv::SpecConstantOp getSpecConstant (uint32_t id)
 Gets the specialization constant with the given result <id>.
spirv::SpecConstantCompositeOp getSpecConstantComposite (uint32_t id)
 Gets the composite specialization constant with the given result <id>.
spirv::EXTSpecConstantCompositeReplicateOp getSpecConstantCompositeReplicate (uint32_t id)
 Gets the replicated composite specialization constant with the given result <id>.
spirv::SpecConstantOp createSpecConstant (Location loc, uint32_t resultID, TypedAttr defaultValue)
 Creates a spirv::SpecConstantOp.
std::optional< spirv::GraphConstantARMOpMaterializationInfogetGraphConstantARM (uint32_t id)
 Gets the GraphConstantARM ID attribute and result type with the given result <id>.
LogicalResult processGlobalVariable (ArrayRef< uint32_t > operands)
 Processes the OpVariable instructions at current offset into binary.
spirv::GlobalVariableOp getGlobalVariable (uint32_t id)
 Gets the global variable associated with a result <id> of OpVariable.
LogicalResult setFunctionArgAttrs (uint32_t argID, SmallVectorImpl< Attribute > &argAttrs, size_t argIndex)
 Sets the function argument's attributes.
StringAttr getSymbolDecoration (StringRef decorationName)
 Gets the symbol name from the name of decoration.
LogicalResult splitConditionalBlocks ()
 Move a conditional branch into a separate basic block to avoid unnecessary sinking of defs that may be required outside a selection region.
Type getType (uint32_t id)
 Gets type for a given result <id>.
Type getUndefType (uint32_t id)
 Get the type associated with the result <id> of an OpUndef.
bool isVoidType (Type type) const
 Returns true if the given type is for SPIR-V void type.
LogicalResult processType (spirv::Opcode opcode, ArrayRef< uint32_t > operands)
 Processes a SPIR-V type instruction with given opcode and operands and registers the type into module.
LogicalResult processOpTypePointer (ArrayRef< uint32_t > operands)
LogicalResult processArrayType (ArrayRef< uint32_t > operands)
LogicalResult processCooperativeMatrixTypeKHR (ArrayRef< uint32_t > operands)
LogicalResult processCooperativeMatrixTypeNV (ArrayRef< uint32_t > operands)
LogicalResult processFunctionType (ArrayRef< uint32_t > operands)
LogicalResult processImageType (ArrayRef< uint32_t > operands)
LogicalResult processSampledImageType (ArrayRef< uint32_t > operands)
LogicalResult processRuntimeArrayType (ArrayRef< uint32_t > operands)
LogicalResult processStructType (ArrayRef< uint32_t > operands)
LogicalResult processMatrixType (ArrayRef< uint32_t > operands)
LogicalResult processTensorARMType (ArrayRef< uint32_t > operands)
LogicalResult processGraphTypeARM (ArrayRef< uint32_t > operands)
LogicalResult processGraphEntryPointARM (ArrayRef< uint32_t > operands)
LogicalResult processGraphARM (ArrayRef< uint32_t > operands)
LogicalResult processOpGraphSetOutputARM (ArrayRef< uint32_t > operands)
LogicalResult processGraphEndARM (ArrayRef< uint32_t > operands)
LogicalResult processTypeForwardPointer (ArrayRef< uint32_t > operands)
LogicalResult processConstant (ArrayRef< uint32_t > operands, bool isSpec)
 Processes a SPIR-V Op{|Spec}Constant instruction with the given operands.
LogicalResult processConstantBool (bool isTrue, ArrayRef< uint32_t > operands, bool isSpec)
 Processes a SPIR-V Op{|Spec}Constant{True|False} instruction with the given operands.
LogicalResult processConstantComposite (ArrayRef< uint32_t > operands)
 Processes a SPIR-V OpConstantComposite instruction with the given operands.
LogicalResult processConstantCompositeReplicateEXT (ArrayRef< uint32_t > operands)
 Processes a SPIR-V OpConstantCompositeReplicateEXT instruction with the given operands.
LogicalResult processSpecConstantComposite (ArrayRef< uint32_t > operands)
 Processes a SPIR-V OpSpecConstantComposite instruction with the given operands.
LogicalResult processSpecConstantCompositeReplicateEXT (ArrayRef< uint32_t > operands)
 Processes a SPIR-V OpSpecConstantCompositeReplicateEXT instruction with the given operands.
LogicalResult processSpecConstantOperation (ArrayRef< uint32_t > operands)
 Processes a SPIR-V OpSpecConstantOp instruction with the given operands.
Value materializeSpecConstantOperation (uint32_t resultID, spirv::Opcode enclosedOpcode, uint32_t resultTypeID, ArrayRef< uint32_t > enclosedOpOperands)
 Materializes/emits an OpSpecConstantOp instruction.
LogicalResult processConstantNull (ArrayRef< uint32_t > operands)
 Processes a SPIR-V OpConstantNull instruction with the given operands.
LogicalResult processGraphConstantARM (ArrayRef< uint32_t > operands)
 Processes a SPIR-V OpGraphConstantARM instruction with the given operands.
void clearDebugLine ()
 Discontinues any source-level location information that might be active from a previous OpLine instruction.
Location createFileLineColLoc (OpBuilder opBuilder)
 Creates a FileLineColLoc with the OpLine location information.
LogicalResult processDebugLine (ArrayRef< uint32_t > operands)
 Processes a SPIR-V OpLine instruction with the given operands.
LogicalResult processDebugString (ArrayRef< uint32_t > operands)
 Processes a SPIR-V OpString instruction with the given operands.
BlockgetBlock (uint32_t id) const
 Returns the block for the given label <id>.
BlockgetOrCreateBlock (uint32_t id)
 Gets or creates the block corresponding to the given label <id>.
LogicalResult processBranch (ArrayRef< uint32_t > operands)
LogicalResult processBranchConditional (ArrayRef< uint32_t > operands)
LogicalResult processLabel (ArrayRef< uint32_t > operands)
 Processes a SPIR-V OpLabel instruction with the given operands.
LogicalResult processSelectionMerge (ArrayRef< uint32_t > operands)
 Processes a SPIR-V OpSelectionMerge instruction with the given operands.
LogicalResult processLoopMerge (ArrayRef< uint32_t > operands)
 Processes a SPIR-V OpLoopMerge instruction with the given operands.
LogicalResult processPhi (ArrayRef< uint32_t > operands)
 Processes a SPIR-V OpPhi instruction with the given operands.
LogicalResult wireUpBlockArgument ()
 Creates block arguments on predecessors previously recorded when handling OpPhi instructions.
LogicalResult structurizeControlFlow ()
 Extracts blocks belonging to a structured selection/loop into a spirv.mlir.selection/spirv.mlir.loop op.
LogicalResult createGraphBlock (uint32_t graphID)
 Creates a block for graph with the given graphID.
Value getValue (uint32_t id)
 Get the Value associated with a result <id>.
LogicalResult sliceInstruction (spirv::Opcode &opcode, ArrayRef< uint32_t > &operands, std::optional< spirv::Opcode > expectedOpcode=std::nullopt)
 Slices the first instruction out of binary and returns its opcode and operands via opcode and operands respectively.
LogicalResult processInstruction (spirv::Opcode opcode, ArrayRef< uint32_t > operands, bool deferInstructions=true)
 Processes a SPIR-V instruction with the given opcode and operands.
LogicalResult processOpWithoutGrammarAttr (ArrayRef< uint32_t > words, StringRef opName, bool hasResult, unsigned numOperands)
 Processes a SPIR-V instruction from the given operands.
LogicalResult processUndef (ArrayRef< uint32_t > operands)
 Processes a OpUndef instruction.
LogicalResult dispatchToAutogenDeserialization (spirv::Opcode opcode, ArrayRef< uint32_t > words)
 Method to dispatch to the specialized deserialization function for an operation in SPIR-V dialect that is a mirror of an instruction in the SPIR-V spec.
LogicalResult processExtInst (ArrayRef< uint32_t > operands)
 Processes a SPIR-V OpExtInst with given operands.
LogicalResult dispatchToExtensionSetAutogenDeserialization (StringRef extensionSetName, uint32_t instructionID, ArrayRef< uint32_t > words)
 Dispatches the deserialization of extended instruction set operation based on the extended instruction set name, and instruction opcode.
template<typename OpTy>
LogicalResult processOp (ArrayRef< uint32_t > words)
 Method to deserialize an operation in the SPIR-V dialect that is a mirror of an instruction in the SPIR-V spec.

Detailed Description

A SPIR-V module serializer.

A SPIR-V binary module is a single linear stream of instructions; each instruction is composed of 32-bit words. The first word of an instruction records the total number of words of that instruction using the 16 higher-order bits. So this deserializer uses that to get instruction boundary and parse instructions and build a SPIR-V ModuleOp gradually.

Definition at line 129 of file Deserializer.h.

Member Typedef Documentation

◆ BlockPhiInfo

Initial value:

For OpPhi instructions, we use block arguments to represent them.

OpPhi encodes a list of (value, predecessor) pairs. At the time of handling the block containing an OpPhi instruction, the predecessor block might not be processed yet, also the value sent by it. So we need to defer handling the block argument from the predecessors. We use the following approach:

  1. For each OpPhi instruction, add a block argument to the current block in construction. Record the block argument in valueMap so its uses can be resolved. For the list of (value, predecessor) pairs, update blockPhiInfo for bookkeeping.
  2. After processing all blocks, loop over blockPhiInfo to fix up each block recorded there to create the proper block arguments on their terminators. A data structure for containing a SPIR-V block's phi info. It will be represented as block argument in SPIR-V dialect.

Definition at line 452 of file Deserializer.h.

Member Function Documentation

◆ clearDebugLine()

void spirv::Deserializer::clearDebugLine ( )

Discontinues any source-level location information that might be active from a previous OpLine instruction.

Definition at line 2974 of file Deserializer.cpp.

Referenced by processBranch(), processBranchConditional(), processInstruction(), and processOpWithoutGrammarAttr().

◆ createFileLineColLoc()

Location spirv::Deserializer::createFileLineColLoc ( OpBuilder opBuilder)

◆ createGraphBlock()

LogicalResult spirv::Deserializer::createGraphBlock ( uint32_t graphID)

Creates a block for graph with the given graphID.

Definition at line 2192 of file Deserializer.cpp.

References mlir::emitError(), mlir::Block::empty(), getOrCreateBlock(), and success().

Referenced by processGraphARM().

◆ createSpecConstant()

spirv::SpecConstantOp spirv::Deserializer::createSpecConstant ( Location loc,
uint32_t resultID,
TypedAttr defaultValue )

Creates a spirv::SpecConstantOp.

Definition at line 915 of file Deserializer.cpp.

References getSpecConstantSymbol().

Referenced by processConstant(), and processConstantBool().

◆ dispatchToAutogenDeserialization()

LogicalResult mlir::spirv::spirv::Deserializer::dispatchToAutogenDeserialization ( spirv::Opcode opcode,
ArrayRef< uint32_t > words )

Method to dispatch to the specialized deserialization function for an operation in SPIR-V dialect that is a mirror of an instruction in the SPIR-V spec.

This is auto-generated from ODS. Dispatch is handled for all operations in SPIR-V dialect that have hasOpcode == 1.

Definition at line 11845 of file DeserializeOps.cpp.

Referenced by processInstruction().

◆ dispatchToExtensionSetAutogenDeserialization()

LogicalResult mlir::spirv::spirv::Deserializer::dispatchToExtensionSetAutogenDeserialization ( StringRef extensionSetName,
uint32_t instructionID,
ArrayRef< uint32_t > words )

Dispatches the deserialization of extended instruction set operation based on the extended instruction set name, and instruction opcode.

This is autogenerated from ODS.

Definition at line 12259 of file DeserializeOps.cpp.

Referenced by processExtInst().

◆ getBlock()

Block * mlir::spirv::Deserializer::getBlock ( uint32_t id) const
inline

Returns the block for the given label <id>.

Definition at line 409 of file Deserializer.h.

Referenced by getOrCreateBlock().

◆ getConstant()

std::optional< std::pair< Attribute, Type > > spirv::Deserializer::getConstant ( uint32_t id)

Gets the constant's attribute and type associated with the given <id>.

Definition at line 867 of file Deserializer.cpp.

Referenced by getConstantInt(), getValue(), processArrayType(), processConstantComposite(), processConstantCompositeReplicateEXT(), and processTensorARMType().

◆ getConstantCompositeReplicate()

std::optional< std::pair< Attribute, Type > > spirv::Deserializer::getConstantCompositeReplicate ( uint32_t id)

Gets the replicated composite constant's attribute and type associated with the given <id>.

Definition at line 875 of file Deserializer.cpp.

Referenced by getValue(), and processConstantCompositeReplicateEXT().

◆ getConstantInt()

IntegerAttr spirv::Deserializer::getConstantInt ( uint32_t id)

Gets the constant's integer attribute with the given <id>.

Returns a null IntegerAttr if the given is not registered or does not correspond to an integer constant.

Definition at line 1015 of file Deserializer.cpp.

References getConstant().

Referenced by processCooperativeMatrixTypeKHR(), processGraphARM(), processOpGraphSetOutputARM(), and processTensorARMType().

◆ getFunctionSymbol()

std::string spirv::Deserializer::getFunctionSymbol ( uint32_t id)

Returns a symbol to be used for the function name with the given result <id>.

This tries to use the function's OpName if exists; otherwise creates one based on the <id>.

Definition at line 890 of file Deserializer.cpp.

Referenced by processFunction().

◆ getGlobalVariable()

spirv::GlobalVariableOp mlir::spirv::Deserializer::getGlobalVariable ( uint32_t id)
inline

Gets the global variable associated with a result <id> of OpVariable.

Definition at line 264 of file Deserializer.h.

Referenced by getValue(), processGlobalVariable(), and processGraphEntryPointARM().

◆ getGraphConstantARM()

std::optional< spirv::GraphConstantARMOpMaterializationInfo > spirv::Deserializer::getGraphConstantARM ( uint32_t id)

Gets the GraphConstantARM ID attribute and result type with the given result <id>.

Definition at line 929 of file Deserializer.cpp.

Referenced by getValue().

◆ getGraphSymbol()

std::string spirv::Deserializer::getGraphSymbol ( uint32_t id)

Returns a symbol to be used for the graph name with the given result <id>.

This tries to use the graph's OpName if exists; otherwise creates one based on the <id>.

Definition at line 898 of file Deserializer.cpp.

Referenced by processGraphARM().

◆ getOrCreateBlock()

Block * spirv::Deserializer::getOrCreateBlock ( uint32_t id)

Gets or creates the block corresponding to the given label <id>.

The newly created block will always be placed at the end of the current function.

Definition at line 2099 of file Deserializer.cpp.

References getBlock().

Referenced by createGraphBlock(), processBranch(), processBranchConditional(), processLabel(), processLoopMerge(), processPhi(), and processSelectionMerge().

◆ getSpecConstant()

spirv::SpecConstantOp mlir::spirv::Deserializer::getSpecConstant ( uint32_t id)
inline

Gets the specialization constant with the given result <id>.

Definition at line 232 of file Deserializer.h.

Referenced by getValue(), processGlobalVariable(), processSpecConstantComposite(), and processSpecConstantCompositeReplicateEXT().

◆ getSpecConstantComposite()

spirv::SpecConstantCompositeOp mlir::spirv::Deserializer::getSpecConstantComposite ( uint32_t id)
inline

Gets the composite specialization constant with the given result <id>.

Definition at line 237 of file Deserializer.h.

Referenced by getValue(), and processGlobalVariable().

◆ getSpecConstantCompositeReplicate()

spirv::EXTSpecConstantCompositeReplicateOp mlir::spirv::Deserializer::getSpecConstantCompositeReplicate ( uint32_t id)
inline

Gets the replicated composite specialization constant with the given result <id>.

Definition at line 244 of file Deserializer.h.

Referenced by getValue().

◆ getSpecConstantOperation()

std::optional< spirv::SpecConstOperationMaterializationInfo > spirv::Deserializer::getSpecConstantOperation ( uint32_t id)

Gets the info needed to materialize the spec constant operation op associated with the given <id>.

Definition at line 883 of file Deserializer.cpp.

Referenced by getValue().

◆ getSpecConstantSymbol()

std::string spirv::Deserializer::getSpecConstantSymbol ( uint32_t id)

Returns a symbol to be used for the specialization constant with the given result <id>.

This tries to use the specialization constant's OpName if exists; otherwise creates one based on the <id>.

Definition at line 906 of file Deserializer.cpp.

Referenced by createSpecConstant(), processSpecConstantComposite(), and processSpecConstantCompositeReplicateEXT().

◆ getSymbolDecoration()

StringAttr mlir::spirv::Deserializer::getSymbolDecoration ( StringRef decorationName)
inline

Gets the symbol name from the name of decoration.

Definition at line 276 of file Deserializer.h.

Referenced by setFunctionArgAttrs().

◆ getType()

Type mlir::spirv::Deserializer::getType ( uint32_t id)
inline

Gets type for a given result <id>.

Definition at line 292 of file Deserializer.h.

◆ getUndefType()

Type mlir::spirv::Deserializer::getUndefType ( uint32_t id)
inline

Get the type associated with the result <id> of an OpUndef.

Definition at line 295 of file Deserializer.h.

Referenced by getValue().

◆ getValue()

Value spirv::Deserializer::getValue ( uint32_t id)

Get the Value associated with a result <id>.

This method materializes normal constants and inserts "casting" ops (spirv.mlir.addressof and spirv.mlir.referenceof) to turn an symbol into a SSA value for handling uses of module scope constants/variables in functions.

Definition at line 42 of file DeserializeOps.cpp.

References getConstant(), getConstantCompositeReplicate(), getGlobalVariable(), getGraphConstantARM(), getSpecConstant(), getSpecConstantComposite(), getSpecConstantCompositeReplicate(), getSpecConstantOperation(), getUndefType(), and materializeSpecConstantOperation().

Referenced by processBranchConditional(), processFunction(), processGraphARM(), processOpGraphSetOutputARM(), processOpWithoutGrammarAttr(), and wireUpBlockArgument().

◆ isVoidType()

bool mlir::spirv::Deserializer::isVoidType ( Type type) const
inline

Returns true if the given type is for SPIR-V void type.

Definition at line 298 of file Deserializer.h.

Referenced by processFunction(), and processFunctionType().

◆ materializeSpecConstantOperation()

Value spirv::Deserializer::materializeSpecConstantOperation ( uint32_t resultID,
spirv::Opcode enclosedOpcode,
uint32_t resultTypeID,
ArrayRef< uint32_t > enclosedOpOperands )

◆ processArrayType()

LogicalResult spirv::Deserializer::processArrayType ( ArrayRef< uint32_t > operands)

◆ processBranch()

LogicalResult spirv::Deserializer::processBranch ( ArrayRef< uint32_t > operands)

◆ processBranchConditional()

LogicalResult spirv::Deserializer::processBranchConditional ( ArrayRef< uint32_t > operands)

◆ processConstant()

LogicalResult spirv::Deserializer::processConstant ( ArrayRef< uint32_t > operands,
bool isSpec )

Processes a SPIR-V Op{|Spec}Constant instruction with the given operands.

isSpec indicates whether this is a specialization constant.

Definition at line 1635 of file Deserializer.cpp.

References createSpecConstant(), mlir::emitError(), mlir::getType(), and success().

Referenced by processInstruction().

◆ processConstantBool()

LogicalResult spirv::Deserializer::processConstantBool ( bool isTrue,
ArrayRef< uint32_t > operands,
bool isSpec )

Processes a SPIR-V Op{|Spec}Constant{True|False} instruction with the given operands.

isSpec indicates whether this is a specialization constant.

Definition at line 1753 of file Deserializer.cpp.

References createSpecConstant(), mlir::emitError(), and success().

Referenced by processInstruction().

◆ processConstantComposite()

LogicalResult spirv::Deserializer::processConstantComposite ( ArrayRef< uint32_t > operands)

Processes a SPIR-V OpConstantComposite instruction with the given operands.

Definition at line 1776 of file Deserializer.cpp.

References mlir::emitError(), mlir::DenseElementsAttr::get(), getConstant(), mlir::getType(), and success().

Referenced by processInstruction().

◆ processConstantCompositeReplicateEXT()

LogicalResult spirv::Deserializer::processConstantCompositeReplicateEXT ( ArrayRef< uint32_t > operands)

Processes a SPIR-V OpConstantCompositeReplicateEXT instruction with the given operands.

Definition at line 1832 of file Deserializer.cpp.

References mlir::emitError(), getConstant(), getConstantCompositeReplicate(), mlir::getType(), and success().

Referenced by processInstruction().

◆ processConstantNull()

LogicalResult spirv::Deserializer::processConstantNull ( ArrayRef< uint32_t > operands)

Processes a SPIR-V OpConstantNull instruction with the given operands.

Definition at line 2035 of file Deserializer.cpp.

References mlir::emitError(), mlir::DenseElementsAttr::get(), mlir::getType(), mlir::Type::isIntOrFloat(), and success().

Referenced by processInstruction().

◆ processCooperativeMatrixTypeKHR()

LogicalResult spirv::Deserializer::processCooperativeMatrixTypeKHR ( ArrayRef< uint32_t > operands)

◆ processCooperativeMatrixTypeNV()

LogicalResult mlir::spirv::Deserializer::processCooperativeMatrixTypeNV ( ArrayRef< uint32_t > operands)

◆ processDebugLine()

LogicalResult spirv::Deserializer::processDebugLine ( ArrayRef< uint32_t > operands)

Processes a SPIR-V OpLine instruction with the given operands.

Definition at line 2962 of file Deserializer.cpp.

References mlir::emitError(), and success().

Referenced by processInstruction().

◆ processDebugString()

LogicalResult spirv::Deserializer::processDebugString ( ArrayRef< uint32_t > operands)

Processes a SPIR-V OpString instruction with the given operands.

Definition at line 2977 of file Deserializer.cpp.

References mlir::debugString(), mlir::spirv::decodeStringLiteral(), mlir::emitError(), and success().

Referenced by processInstruction().

◆ processExtInst()

LogicalResult spirv::Deserializer::processExtInst ( ArrayRef< uint32_t > operands)

Processes a SPIR-V OpExtInst with given operands.

This slices the entries of operands that specify the extended instruction set <id> and the instruction opcode. The op deserializer is then invoked using the other entries.

Definition at line 351 of file DeserializeOps.cpp.

References dispatchToExtensionSetAutogenDeserialization(), and mlir::emitError().

Referenced by processInstruction().

◆ processFunction()

LogicalResult spirv::Deserializer::processFunction ( ArrayRef< uint32_t > operands)

Creates a deserializer for the given SPIR-V binary module.

The SPIR-V ModuleOp will be created into `context. explicit Deserializer(ArrayRef<uint32_t> binary, MLIRContext *context, const DeserializationOptions &options);

/ Deserializes the remembered SPIR-V binary module. LogicalResult deserialize();

/ Collects the final SPIR-V ModuleOp. OwningOpRef<spirv::ModuleOp> collect();

private: ===-----------------------------------------------------------------—===// Module structure ===-----------------------------------------------------------------—===//

/ Initializes the module ModuleOp in this deserializer instance. OwningOpRef<spirv::ModuleOp> createModuleOp();

/ Processes SPIR-V module header in binary. LogicalResult processHeader();

/ Processes the SPIR-V OpCapability with operands and updates bookkeeping / in the deserializer. LogicalResult processCapability(ArrayRef<uint32_t> operands);

/ Processes the SPIR-V OpExtension with operands and updates bookkeeping / in the deserializer. LogicalResult processExtension(ArrayRef<uint32_t> words);

/ Processes the SPIR-V OpExtInstImport with operands and updates / bookkeeping in the deserializer. LogicalResult processExtInstImport(ArrayRef<uint32_t> words);

/ Attaches (version, capabilities, extensions) triple to module as an / attribute. void attachVCETriple();

/ Processes the SPIR-V OpMemoryModel with operands and updates module. LogicalResult processMemoryModel(ArrayRef<uint32_t> operands);

/ Process SPIR-V OpName with operands. LogicalResult processName(ArrayRef<uint32_t> operands);

/ Processes an OpDecorate instruction. LogicalResult processDecoration(ArrayRef<uint32_t> words);

Processes an OpMemberDecorate instruction. LogicalResult processMemberDecoration(ArrayRef<uint32_t> words);

/ Processes an OpMemberName instruction. LogicalResult processMemberName(ArrayRef<uint32_t> words);

/ Gets the function op associated with a result <id> of OpFunction. spirv::FuncOp getFunction(uint32_t id) { return funcMap.lookup(id); }

/ Processes the SPIR-V function at the current offset into binary. / The operands to the OpFunction instruction is passed in as `operands. This method processes each instruction inside the function and dispatches them to their handler method accordingly.

Definition at line 480 of file Deserializer.cpp.

References mlir::emitError(), getFunctionSymbol(), mlir::getType(), getValue(), isVoidType(), processFunctionEnd(), processInstruction(), processLabel(), setFunctionArgAttrs(), and sliceInstruction().

Referenced by processInstruction().

◆ processFunctionEnd()

LogicalResult spirv::Deserializer::processFunctionEnd ( ArrayRef< uint32_t > operands)

Processes OpFunctionEnd and finalizes function.

This wires up block argument created from OpPhi instructions and also structurizes control flow.

Definition at line 648 of file Deserializer.cpp.

References mlir::emitError(), structurizeControlFlow(), success(), and wireUpBlockArgument().

Referenced by processFunction().

◆ processFunctionType()

LogicalResult spirv::Deserializer::processFunctionType ( ArrayRef< uint32_t > operands)

Definition at line 1254 of file Deserializer.cpp.

References mlir::emitError(), mlir::getType(), isVoidType(), and success().

Referenced by processType().

◆ processGlobalVariable()

LogicalResult spirv::Deserializer::processGlobalVariable ( ArrayRef< uint32_t > operands)

Processes the OpVariable instructions at current offset into binary.

It is expected that this method is used for variables that are to be defined at module scope and will be deserialized into a spirv.GlobalVariable instruction.

Definition at line 937 of file Deserializer.cpp.

References createFileLineColLoc(), mlir::emitError(), getGlobalVariable(), getSpecConstant(), getSpecConstantComposite(), mlir::getType(), and success().

Referenced by processInstruction().

◆ processGraphARM()

LogicalResult spirv::Deserializer::processGraphARM ( ArrayRef< uint32_t > operands)

◆ processGraphConstantARM()

LogicalResult spirv::Deserializer::processGraphConstantARM ( ArrayRef< uint32_t > operands)

Processes a SPIR-V OpGraphConstantARM instruction with the given operands.

Definition at line 2068 of file Deserializer.cpp.

References mlir::emitError(), mlir::getType(), and success().

Referenced by processInstruction().

◆ processGraphEndARM()

LogicalResult spirv::Deserializer::processGraphEndARM ( ArrayRef< uint32_t > operands)

Definition at line 845 of file Deserializer.cpp.

References mlir::emitError(), and success().

Referenced by processInstruction().

◆ processGraphEntryPointARM()

LogicalResult spirv::Deserializer::processGraphEntryPointARM ( ArrayRef< uint32_t > operands)

◆ processGraphTypeARM()

LogicalResult spirv::Deserializer::processGraphTypeARM ( ArrayRef< uint32_t > operands)

Definition at line 1527 of file Deserializer.cpp.

References mlir::emitError(), mlir::getType(), and success().

Referenced by processType().

◆ processImageType()

LogicalResult spirv::Deserializer::processImageType ( ArrayRef< uint32_t > operands)

Definition at line 1569 of file Deserializer.cpp.

References mlir::emitError(), mlir::spirv::ImageType::get(), mlir::getType(), and success().

Referenced by processType().

◆ processInstruction()

LogicalResult spirv::Deserializer::processInstruction ( spirv::Opcode opcode,
ArrayRef< uint32_t > operands,
bool deferInstructions = true )

Processes a SPIR-V instruction with the given opcode and operands.

This method is the main entrance for handling SPIR-V instruction; it checks the instruction opcode and dispatches to the corresponding handler. Processing of Some instructions (like OpEntryPoint and OpExecutionMode) might need to be deferred, since they contain forward references to <id>s in the deserialized binary, but module in SPIR-V dialect expects these to be ssa-uses.

Definition at line 128 of file DeserializeOps.cpp.

References clearDebugLine(), dispatchToAutogenDeserialization(), processBranch(), processBranchConditional(), processConstant(), processConstantBool(), processConstantComposite(), processConstantCompositeReplicateEXT(), processConstantNull(), processDebugLine(), processDebugString(), processExtInst(), processFunction(), processGlobalVariable(), processGraphARM(), processGraphConstantARM(), processGraphEndARM(), processGraphEntryPointARM(), processLabel(), processLoopMerge(), processOpGraphSetOutputARM(), processPhi(), processSelectionMerge(), processSpecConstantComposite(), processSpecConstantCompositeReplicateEXT(), processSpecConstantOperation(), processType(), processTypeForwardPointer(), processUndef(), and success().

Referenced by materializeSpecConstantOperation(), processFunction(), and processGraphARM().

◆ processLabel()

LogicalResult spirv::Deserializer::processLabel ( ArrayRef< uint32_t > operands)

Processes a SPIR-V OpLabel instruction with the given operands.

Definition at line 2169 of file Deserializer.cpp.

References mlir::emitError(), getOrCreateBlock(), and success().

Referenced by processFunction(), and processInstruction().

◆ processLoopMerge()

LogicalResult spirv::Deserializer::processLoopMerge ( ArrayRef< uint32_t > operands)

Processes a SPIR-V OpLoopMerge instruction with the given operands.

Definition at line 2237 of file Deserializer.cpp.

References createFileLineColLoc(), mlir::emitError(), getOrCreateBlock(), and success().

Referenced by processInstruction().

◆ processMatrixType()

LogicalResult spirv::Deserializer::processMatrixType ( ArrayRef< uint32_t > operands)

Definition at line 1458 of file Deserializer.cpp.

References mlir::emitError(), mlir::spirv::MatrixType::get(), mlir::getType(), and success().

Referenced by processType().

◆ processOp()

template<typename OpTy>
LogicalResult mlir::spirv::Deserializer::processOp ( ArrayRef< uint32_t > words)
inline

Method to deserialize an operation in the SPIR-V dialect that is a mirror of an instruction in the SPIR-V spec.

This is auto generated if hasOpcode == 1 and autogenSerialization == 1 in ODS.

Definition at line 555 of file Deserializer.h.

References mlir::emitError().

Referenced by mlir::spirv::Deserializer::processOp< spirv::CopyMemoryOp >(), mlir::spirv::Deserializer::processOp< spirv::EntryPointOp >(), mlir::spirv::Deserializer::processOp< spirv::ExecutionModeOp >(), mlir::spirv::Deserializer::processOp< spirv::FunctionCallOp >(), and mlir::spirv::Deserializer::processOp< spirv::GenericCastToPtrExplicitOp >().

◆ processOpGraphSetOutputARM()

LogicalResult spirv::Deserializer::processOpGraphSetOutputARM ( ArrayRef< uint32_t > operands)

Definition at line 821 of file Deserializer.cpp.

References mlir::emitError(), getConstantInt(), getValue(), and success().

Referenced by processInstruction().

◆ processOpTypePointer()

LogicalResult spirv::Deserializer::processOpTypePointer ( ArrayRef< uint32_t > operands)

Definition at line 1166 of file Deserializer.cpp.

References mlir::emitError(), mlir::spirv::PointerType::get(), mlir::getType(), and success().

Referenced by processType().

◆ processOpWithoutGrammarAttr()

LogicalResult spirv::Deserializer::processOpWithoutGrammarAttr ( ArrayRef< uint32_t > words,
StringRef opName,
bool hasResult,
unsigned numOperands )

Processes a SPIR-V instruction from the given operands.

It should deserialize into an op with the given opName and numOperands. This method is a generic one for dispatching any SPIR-V ops without variadic operands and attributes in TableGen definitions.

Definition at line 259 of file DeserializeOps.cpp.

References mlir::OperationState::addAttributes(), mlir::OperationState::addOperands(), mlir::OperationState::addTypes(), clearDebugLine(), mlir::Operation::create(), createFileLineColLoc(), mlir::emitError(), mlir::Operation::getResult(), mlir::getType(), getValue(), mlir::Operation::hasTrait(), and success().

◆ processPhi()

LogicalResult spirv::Deserializer::processPhi ( ArrayRef< uint32_t > operands)

Processes a SPIR-V OpPhi instruction with the given operands.

Definition at line 2263 of file Deserializer.cpp.

References mlir::emitError(), getOrCreateBlock(), mlir::getType(), and success().

Referenced by processInstruction().

◆ processRuntimeArrayType()

LogicalResult spirv::Deserializer::processRuntimeArrayType ( ArrayRef< uint32_t > operands)

◆ processSampledImageType()

LogicalResult spirv::Deserializer::processSampledImageType ( ArrayRef< uint32_t > operands)

◆ processSelectionMerge()

LogicalResult spirv::Deserializer::processSelectionMerge ( ArrayRef< uint32_t > operands)

Processes a SPIR-V OpSelectionMerge instruction with the given operands.

Definition at line 2211 of file Deserializer.cpp.

References createFileLineColLoc(), mlir::emitError(), getOrCreateBlock(), and success().

Referenced by processInstruction().

◆ processSpecConstantComposite()

LogicalResult spirv::Deserializer::processSpecConstantComposite ( ArrayRef< uint32_t > operands)

Processes a SPIR-V OpSpecConstantComposite instruction with the given operands.

Definition at line 1880 of file Deserializer.cpp.

References mlir::emitError(), getSpecConstant(), getSpecConstantSymbol(), mlir::getType(), and success().

Referenced by processInstruction().

◆ processSpecConstantCompositeReplicateEXT()

LogicalResult spirv::Deserializer::processSpecConstantCompositeReplicateEXT ( ArrayRef< uint32_t > operands)

Processes a SPIR-V OpSpecConstantCompositeReplicateEXT instruction with the given operands.

Definition at line 1915 of file Deserializer.cpp.

References mlir::emitError(), getSpecConstant(), getSpecConstantSymbol(), mlir::getType(), and success().

Referenced by processInstruction().

◆ processSpecConstantOperation()

LogicalResult spirv::Deserializer::processSpecConstantOperation ( ArrayRef< uint32_t > operands)

Processes a SPIR-V OpSpecConstantOp instruction with the given operands.

Definition at line 1951 of file Deserializer.cpp.

References mlir::emitError(), mlir::getType(), and success().

Referenced by processInstruction().

◆ processStructType()

LogicalResult spirv::Deserializer::processStructType ( ArrayRef< uint32_t > operands)

◆ processTensorARMType()

LogicalResult spirv::Deserializer::processTensorARMType ( ArrayRef< uint32_t > operands)

◆ processType()

LogicalResult spirv::Deserializer::processType ( spirv::Opcode opcode,
ArrayRef< uint32_t > operands )

Processes a SPIR-V type instruction with given opcode and operands and registers the type into module.

TODO: Types might be forward declared in some instructions and need to be handled appropriately.

Definition at line 1045 of file Deserializer.cpp.

References mlir::emitError(), mlir::getType(), processArrayType(), processCooperativeMatrixTypeKHR(), processFunctionType(), processGraphTypeARM(), processImageType(), processMatrixType(), processOpTypePointer(), processRuntimeArrayType(), processSampledImageType(), processStructType(), processTensorARMType(), and success().

Referenced by processInstruction().

◆ processTypeForwardPointer()

LogicalResult spirv::Deserializer::processTypeForwardPointer ( ArrayRef< uint32_t > operands)

Definition at line 1556 of file Deserializer.cpp.

References mlir::emitError(), and success().

Referenced by processInstruction().

◆ processUndef()

LogicalResult spirv::Deserializer::processUndef ( ArrayRef< uint32_t > operands)

Processes a OpUndef instruction.

Adds a spirv.Undef operation at the current insertion point.

Definition at line 339 of file DeserializeOps.cpp.

References mlir::emitError(), mlir::getType(), and success().

Referenced by processInstruction().

◆ setFunctionArgAttrs()

LogicalResult spirv::Deserializer::setFunctionArgAttrs ( uint32_t argID,
SmallVectorImpl< Attribute > & argAttrs,
size_t argIndex )

Sets the function argument's attributes.

|argID| is the function argument's result <id>, and |argIndex| is its index in the function's argument list.

Definition at line 424 of file Deserializer.cpp.

References mlir::emitError(), getSymbolDecoration(), and success().

Referenced by processFunction().

◆ sliceInstruction()

LogicalResult spirv::Deserializer::sliceInstruction ( spirv::Opcode & opcode,
ArrayRef< uint32_t > & operands,
std::optional< spirv::Opcode > expectedOpcode = std::nullopt )

Slices the first instruction out of binary and returns its opcode and operands via opcode and operands respectively.

Returns failure if there is no more remaining instructions (expectedOpcode will be used to compose the error message) or the next instruction is malformed.

Definition at line 99 of file DeserializeOps.cpp.

References mlir::emitError(), extractOpcode(), and success().

Referenced by processFunction(), and processGraphARM().

◆ splitConditionalBlocks()

LogicalResult spirv::Deserializer::splitConditionalBlocks ( )

Move a conditional branch into a separate basic block to avoid unnecessary sinking of defs that may be required outside a selection region.

This function also ensures that a single block cannot be a header block of one selection construct and the merge block of another.

Definition at line 2822 of file Deserializer.cpp.

References mlir::Block::splitBlock(), and success().

Referenced by structurizeControlFlow().

◆ structurizeControlFlow()

LogicalResult spirv::Deserializer::structurizeControlFlow ( )

Extracts blocks belonging to a structured selection/loop into a spirv.mlir.selection/spirv.mlir.loop op.

This method iterates until all blocks declared as selection/loop headers are handled.

Definition at line 2868 of file Deserializer.cpp.

References mlir::Block::args_empty(), mlir::Block::begin(), mlir::spirv::BlockMergeInfo::continueBlock, mlir::spirv::BlockMergeInfo::control, mlir::emitError(), mlir::Block::erase(), mlir::spirv::BlockMergeInfo::loc, mlir::spirv::BlockMergeInfo::mergeBlock, mlir::Block::print(), splitConditionalBlocks(), and success().

Referenced by processFunctionEnd().

◆ wireUpBlockArgument()

LogicalResult spirv::Deserializer::wireUpBlockArgument ( )

Creates block arguments on predecessors previously recorded when handling OpPhi instructions.

Definition at line 2742 of file Deserializer.cpp.

References mlir::emitError(), mlir::Block::getParentOp(), mlir::Block::getTerminator(), getValue(), mlir::Operation::print(), success(), and target.

Referenced by processFunctionEnd().


The documentation for this class was generated from the following files: