13 #ifndef MLIR_TARGET_SPIRV_DESERIALIZER_H
14 #define MLIR_TARGET_SPIRV_DESERIALIZER_H
20 #include "llvm/ADT/ArrayRef.h"
21 #include "llvm/ADT/SetVector.h"
22 #include "llvm/ADT/StringRef.h"
23 #include "llvm/Support/ScopedPrinter.h"
151 LogicalResult processHeader();
167 void attachVCETriple();
185 spirv::FuncOp getFunction(uint32_t
id) {
return funcMap.lookup(
id); }
199 std::optional<std::pair<Attribute, Type>> getConstant(uint32_t
id);
203 std::optional<std::pair<Attribute, Type>>
204 getConstantCompositeReplicate(uint32_t
id);
208 std::optional<SpecConstOperationMaterializationInfo>
209 getSpecConstantOperation(uint32_t
id);
214 IntegerAttr getConstantInt(uint32_t
id);
219 std::string getFunctionSymbol(uint32_t
id);
224 std::string getGraphSymbol(uint32_t
id);
229 std::string getSpecConstantSymbol(uint32_t
id);
232 spirv::SpecConstantOp getSpecConstant(uint32_t
id) {
233 return specConstMap.lookup(
id);
237 spirv::SpecConstantCompositeOp getSpecConstantComposite(uint32_t
id) {
238 return specConstCompositeMap.lookup(
id);
243 spirv::EXTSpecConstantCompositeReplicateOp
244 getSpecConstantCompositeReplicate(uint32_t
id) {
245 return specConstCompositeReplicateMap.lookup(
id);
249 spirv::SpecConstantOp createSpecConstant(
Location loc, uint32_t resultID,
250 TypedAttr defaultValue);
254 std::optional<spirv::GraphConstantARMOpMaterializationInfo>
255 getGraphConstantARM(uint32_t
id);
264 spirv::GlobalVariableOp getGlobalVariable(uint32_t
id) {
265 return globalVariableMap.lookup(
id);
271 LogicalResult setFunctionArgAttrs(uint32_t argID,
276 StringAttr getSymbolDecoration(StringRef decorationName) {
277 auto attrName = llvm::convertToSnakeFromCamelCase(decorationName);
285 LogicalResult splitConditionalBlocks();
292 Type getType(uint32_t
id) {
return typeMap.lookup(
id); }
295 Type getUndefType(uint32_t
id) {
return undefMap.lookup(
id); }
298 bool isVoidType(
Type type)
const {
return isa<NoneType>(type); }
375 Value materializeSpecConstantOperation(uint32_t resultID,
376 spirv::Opcode enclosedOpcode,
377 uint32_t resultTypeID,
393 void clearDebugLine();
409 Block *getBlock(uint32_t
id)
const {
return blockMap.lookup(
id); }
457 Block *getOrCreateBlock(uint32_t
id);
477 LogicalResult wireUpBlockArgument();
482 LogicalResult structurizeControlFlow();
485 LogicalResult createGraphBlock(uint32_t graphID);
497 Value getValue(uint32_t
id);
505 std::optional<spirv::Opcode> expectedOpcode = std::nullopt);
514 LogicalResult processInstruction(spirv::Opcode opcode,
516 bool deferInstructions =
true);
523 StringRef opName,
bool hasResult,
524 unsigned numOperands);
534 LogicalResult dispatchToAutogenDeserialization(spirv::Opcode opcode,
547 dispatchToExtensionSetAutogenDeserialization(StringRef extensionSetName,
548 uint32_t instructionID,
554 template <
typename OpTy>
556 return emitError(unknownLoc,
"unsupported deserialization for ")
557 << OpTy::getOperationName() <<
" op";
566 std::optional<DebugLine> debugLine;
569 unsigned curOffset = 0;
581 std::optional<spirv::FuncOp> curFunction;
584 std::optional<spirv::GraphARMOp> curGraph;
587 Block *curBlock =
nullptr;
591 spirv::Version version = spirv::Version::V_1_0;
594 llvm::SmallSetVector<spirv::Capability, 4> capabilities;
597 llvm::SmallSetVector<spirv::Extension, 2> extensions;
632 specConstCompositeReplicateMap;
637 specConstOperationMap;
703 deferredInstructions;
720 llvm::ScopedPrinter logger;
Block represents an ordered list of Operations.
StringAttr getStringAttr(const Twine &bytes)
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
MLIRContext is the top-level object for a collection of MLIR operations.
This class helps build Operations.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
A SPIR-V module serializer.
LogicalResult deserialize()
Deserializes the remembered SPIR-V binary module.
Deserializer(ArrayRef< uint32_t > binary, MLIRContext *context, const DeserializationOptions &options)
Creates a deserializer for the given SPIR-V binary module.
OwningOpRef< spirv::ModuleOp > collect()
Collects the final SPIR-V ModuleOp.
Include the generated interface declarations.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
A struct for containing a header block's merge and continue targets.
BlockMergeInfo(Location location, uint32_t control, Block *m, Block *c=nullptr)
BlockMergeInfo(Location location, uint32_t control)
A struct for containing OpLine instruction information.
A "deferred struct type" is a struct type with one or more member types not known when the Deserializ...
spirv::StructType deferredStructType
SmallVector< spirv::StructType::StructDecorationInfo, 0 > structDecorationsInfo
SmallVector< spirv::StructType::MemberDecorationInfo, 0 > memberDecorationsInfo
SmallVector< spirv::StructType::OffsetInfo, 0 > offsetInfo
SmallVector< Type, 4 > memberTypes
SmallVector< std::pair< uint32_t, unsigned >, 0 > unresolvedMemberTypes
A struct that collects the info needed to materialize/emit a GraphConstantARMOp.
IntegerAttr graphConstantID
A struct that collects the info needed to materialize/emit a SpecConstantOperation op.
SmallVector< uint32_t > enclosedOpOperands
spirv::Opcode enclodesOpcode