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"
144 LogicalResult processHeader();
160 void attachVCETriple();
178 spirv::FuncOp getFunction(uint32_t
id) {
return funcMap.lookup(
id); }
192 std::optional<std::pair<Attribute, Type>> getConstant(uint32_t
id);
196 std::optional<std::pair<Attribute, Type>>
197 getConstantCompositeReplicate(uint32_t
id);
201 std::optional<SpecConstOperationMaterializationInfo>
202 getSpecConstantOperation(uint32_t
id);
207 IntegerAttr getConstantInt(uint32_t
id);
212 std::string getFunctionSymbol(uint32_t
id);
217 std::string getSpecConstantSymbol(uint32_t
id);
220 spirv::SpecConstantOp getSpecConstant(uint32_t
id) {
221 return specConstMap.lookup(
id);
225 spirv::SpecConstantCompositeOp getSpecConstantComposite(uint32_t
id) {
226 return specConstCompositeMap.lookup(
id);
231 spirv::EXTSpecConstantCompositeReplicateOp
232 getSpecConstantCompositeReplicate(uint32_t
id) {
233 return specConstCompositeReplicateMap.lookup(
id);
237 spirv::SpecConstantOp createSpecConstant(
Location loc, uint32_t resultID,
238 TypedAttr defaultValue);
247 spirv::GlobalVariableOp getGlobalVariable(uint32_t
id) {
248 return globalVariableMap.lookup(
id);
254 LogicalResult setFunctionArgAttrs(uint32_t argID,
259 StringAttr getSymbolDecoration(StringRef decorationName) {
260 auto attrName = llvm::convertToSnakeFromCamelCase(decorationName);
268 LogicalResult splitConditionalBlocks();
275 Type getType(uint32_t
id) {
return typeMap.lookup(
id); }
278 Type getUndefType(uint32_t
id) {
return undefMap.lookup(
id); }
281 bool isVoidType(
Type type)
const {
return isa<NoneType>(type); }
348 Value materializeSpecConstantOperation(uint32_t resultID,
349 spirv::Opcode enclosedOpcode,
350 uint32_t resultTypeID,
362 void clearDebugLine();
378 Block *getBlock(uint32_t
id)
const {
return blockMap.lookup(
id); }
426 Block *getOrCreateBlock(uint32_t
id);
446 LogicalResult wireUpBlockArgument();
451 LogicalResult structurizeControlFlow();
463 Value getValue(uint32_t
id);
471 std::optional<spirv::Opcode> expectedOpcode = std::nullopt);
480 LogicalResult processInstruction(spirv::Opcode opcode,
482 bool deferInstructions =
true);
489 StringRef opName,
bool hasResult,
490 unsigned numOperands);
500 LogicalResult dispatchToAutogenDeserialization(spirv::Opcode opcode,
513 dispatchToExtensionSetAutogenDeserialization(StringRef extensionSetName,
514 uint32_t instructionID,
520 template <
typename OpTy>
522 return emitError(unknownLoc,
"unsupported deserialization for ")
523 << OpTy::getOperationName() <<
" op";
532 std::optional<DebugLine> debugLine;
535 unsigned curOffset = 0;
547 std::optional<spirv::FuncOp> curFunction;
550 Block *curBlock =
nullptr;
554 spirv::Version version = spirv::Version::V_1_0;
557 llvm::SmallSetVector<spirv::Capability, 4> capabilities;
560 llvm::SmallSetVector<spirv::Extension, 2> extensions;
595 specConstCompositeReplicateMap;
600 specConstOperationMap;
659 deferredInstructions;
673 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 SpecConstantOperation op.
SmallVector< uint32_t > enclosedOpOperands
spirv::Opcode enclodesOpcode