13 #ifndef MLIR_LIB_TARGET_SPIRV_SERIALIZATION_SERIALIZER_H
14 #define MLIR_LIB_TARGET_SPIRV_SERIALIZATION_SERIALIZER_H
19 #include "llvm/ADT/SetVector.h"
20 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/Support/raw_ostream.h"
27 ArrayRef<uint32_t> operands);
79 uint32_t getNextID() {
return nextID++; }
85 uint32_t getSpecConstID(StringRef constName)
const {
86 return specConstIDMap.lookup(constName);
89 uint32_t getVariableID(StringRef varName)
const {
90 return globalVarIDMap.lookup(varName);
93 uint32_t getFunctionID(StringRef fnName)
const {
94 return funcIDMap.lookup(fnName);
99 uint32_t getOrCreateFunctionID(StringRef fnName);
101 void processCapability();
103 void processDebugInfo();
105 void processExtension();
107 void processMemoryModel();
111 LogicalResult processSpecConstantOp(spirv::SpecConstantOp op);
114 processSpecConstantCompositeOp(spirv::SpecConstantCompositeOp op);
117 processSpecConstantOperationOp(spirv::SpecConstantOperationOp op);
126 LogicalResult processName(uint32_t resultID, StringRef name);
134 LogicalResult processGlobalVariableOp(spirv::GlobalVariableOp varOp);
140 template <
typename DType>
143 return emitError(loc,
"unhandled decoration for type:") << type;
155 uint32_t getTypeID(
Type type)
const {
return typeIDMap.lookup(type); }
159 bool isVoidType(
Type type)
const {
return isa<NoneType>(type); }
163 bool isInterfaceStructPtrType(
Type type)
const;
174 spirv::Opcode &typeEnum,
176 bool &deferSerialization,
180 spirv::Opcode &typeEnum,
187 uint32_t getConstantID(
Attribute value)
const {
188 return constIDMap.lookup(value);
201 uint32_t prepareArrayConstant(
Location loc,
Type constType, ArrayAttr attr);
210 uint32_t prepareDenseElementsConstant(
Location loc,
Type constType,
219 bool isSpec =
false);
222 bool isSpec =
false);
224 uint32_t prepareConstantInt(
Location loc, IntegerAttr intAttr,
225 bool isSpec =
false);
227 uint32_t prepareConstantFp(
Location loc, FloatAttr floatAttr,
228 bool isSpec =
false);
235 uint32_t getBlockID(
Block *block)
const {
return blockIDMap.lookup(block); }
239 uint32_t getOrCreateBlockID(
Block *block);
243 void printBlock(
Block *block, raw_ostream &os);
257 LogicalResult processSelectionOp(spirv::SelectionOp selectionOp);
261 LogicalResult processBranchConditionalOp(spirv::BranchConditionalOp);
270 StringRef extensionSetName,
274 uint32_t getValueID(
Value val)
const {
return valueIDMap.lookup(val); }
276 LogicalResult processAddressOfOp(spirv::AddressOfOp addressOfOp);
278 LogicalResult processReferenceOfOp(spirv::ReferenceOfOp referenceOfOp);
300 template <
typename OpTy>
302 return op.emitError(
"unsupported op serialization");
311 LogicalResult emitDecoration(uint32_t target, spirv::Decoration decoration,
320 spirv::ModuleOp module;
332 bool lastProcessedWasMergeInst =
false;
361 struct RecursiveStructPointerInfo {
362 uint32_t pointerTypeID;
363 spirv::StorageClass storageClass;
368 recursiveStructInfos;
390 llvm::StringMap<uint32_t> specConstIDMap;
393 llvm::StringMap<uint32_t> globalVarIDMap;
396 llvm::StringMap<uint32_t> funcIDMap;
408 llvm::StringMap<uint32_t> extendedInstSetIDMap;
Attributes are known-constant values of operations.
Block represents an ordered list of Operations.
Special case of IntegerAttr to represent boolean integers, i.e., signless i1 integers.
This class is a general helper class for creating context-global objects like types,...
An attribute that represents a reference to a dense vector or tensor object.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
NamedAttribute represents a combination of a name and an Attribute value.
Operation is the basic unit of execution within MLIR.
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.
void printValueIDMap(raw_ostream &os)
(For debugging) prints each value and its corresponding result <id>.
Serializer(spirv::ModuleOp module, const SerializationOptions &options)
Creates a serializer for the given SPIR-V module.
LogicalResult serialize()
Serializes the remembered SPIR-V module.
void collect(SmallVectorImpl< uint32_t > &binary)
Collects the final SPIR-V binary.
void encodeInstructionInto(SmallVectorImpl< uint32_t > &binary, spirv::Opcode op, ArrayRef< uint32_t > operands)
Encodes an SPIR-V instruction with the given opcode and operands into the given binary vector.
This header declares functions that assist transformations in the MemRef dialect.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
This class represents an efficient way to signal success or failure.