21#include "llvm/ADT/STLExtras.h"
22#include "llvm/ADT/SmallVector.h"
23#include "llvm/Support/Debug.h"
28#define DEBUG_TYPE "spirv-deserialization"
36 return static_cast<spirv::Opcode
>(word & 0xffff);
49 if (std::optional<std::pair<Attribute, Type>> constCompositeReplicateInfo =
51 Value &value = blockConstantMap[{opBuilder.getInsertionBlock(),
id}];
53 value = spirv::EXTConstantCompositeReplicateOp::create(
54 opBuilder, unknownLoc, constCompositeReplicateInfo->second,
55 constCompositeReplicateInfo->first);
60 Value &value = blockConstantMap[{opBuilder.getInsertionBlock(),
id}];
65 value = spirv::ConstantOp::create(opBuilder, loc, constInfo->second,
72 spirv::AddressOfOp::create(opBuilder, unknownLoc, varOp.getType(),
73 SymbolRefAttr::get(varOp.getOperation()));
74 return addressOfOp.getPointer();
77 auto referenceOfOp = spirv::ReferenceOfOp::create(
78 opBuilder, unknownLoc, constOp.getDefaultValue().getType(),
79 SymbolRefAttr::get(constOp.getOperation()));
80 return referenceOfOp.getReference();
82 if (SpecConstantCompositeOp specConstCompositeOp =
84 auto referenceOfOp = spirv::ReferenceOfOp::create(
85 opBuilder, unknownLoc, specConstCompositeOp.getType(),
86 SymbolRefAttr::get(specConstCompositeOp.getOperation()));
87 return referenceOfOp.getReference();
89 if (
auto specConstCompositeReplicateOp =
91 auto referenceOfOp = spirv::ReferenceOfOp::create(
92 opBuilder, unknownLoc, specConstCompositeReplicateOp.getType(),
93 SymbolRefAttr::get(specConstCompositeReplicateOp.getOperation()));
94 return referenceOfOp.getReference();
98 id, specConstOperationInfo->enclodesOpcode,
99 specConstOperationInfo->resultTypeID,
100 specConstOperationInfo->enclosedOpOperands);
103 Value &value = blockConstantMap[{opBuilder.getInsertionBlock(),
id}];
105 value = spirv::UndefOp::create(opBuilder, unknownLoc, undef);
109 Value &value = blockConstantMap[{opBuilder.getInsertionBlock(),
id}];
111 value = spirv::INTELConstantFunctionPointerOp::create(
116 std::pair<Block *, uint32_t> key = {opBuilder.getInsertionBlock(),
id};
117 if (
Value value = blockConstantMap.lookup(key))
121 for (uint32_t constituentID : undefComposite->second)
122 constituents.push_back(
getValue(constituentID));
123 Value value = spirv::CompositeConstructOp::create(
124 opBuilder, unknownLoc, undefComposite->first, constituents);
125 blockConstantMap[key] = value;
128 if (std::optional<spirv::GraphConstantARMOpMaterializationInfo>
130 IntegerAttr graphConstantID = graphConstantARMInfo->graphConstantID;
131 Type resultType = graphConstantARMInfo->resultType;
132 return spirv::GraphConstantARMOp::create(opBuilder, unknownLoc, resultType,
135 return valueMap.lookup(
id);
140 std::optional<spirv::Opcode> expectedOpcode) {
141 auto binarySize = binary.size();
142 if (curOffset >= binarySize) {
143 return emitError(unknownLoc,
"expected ")
144 << (expectedOpcode ? spirv::stringifyOpcode(*expectedOpcode)
152 uint32_t wordCount = binary[curOffset] >> 16;
155 return emitError(unknownLoc,
"word count cannot be zero");
157 uint32_t nextOffset = curOffset + wordCount;
158 if (nextOffset > binarySize)
159 return emitError(unknownLoc,
"insufficient words for the last instruction");
162 operands = binary.slice(curOffset + 1, wordCount - 1);
163 curOffset = nextOffset;
174 size_t binarySize = binary.size();
175 auto isNextContinuation = [&]() {
176 if (curOffset >= binarySize)
178 uint32_t wordCount = binary[curOffset] >> 16;
179 if (wordCount == 0 || curOffset + wordCount > binarySize)
184 if (!isNextContinuation())
187 mergedStorage.assign(operands);
189 spirv::Opcode contOpcode;
193 llvm::append_range(mergedStorage, contOperands);
194 }
while (isNextContinuation());
195 operands = mergedStorage;
200 LLVM_DEBUG(logger.startLine() <<
"[inst] processing instruction "
201 << spirv::stringifyOpcode(opcode) <<
"\n");
209 case spirv::Opcode::OpCapability:
210 return processCapability(operands);
211 case spirv::Opcode::OpExtension:
212 return processExtension(operands);
213 case spirv::Opcode::OpExtInst: {
215 operands.size() >= 4 ? extendedInstSets.find(operands[2])
216 : extendedInstSets.end();
221 case spirv::Opcode::OpExtInstImport:
222 return processExtInstImport(operands);
223 case spirv::Opcode::OpMemberName:
224 return processMemberName(operands);
225 case spirv::Opcode::OpMemoryModel:
226 return processMemoryModel(operands);
227 case spirv::Opcode::OpEntryPoint:
228 case spirv::Opcode::OpExecutionMode:
229 case spirv::Opcode::OpExecutionModeId:
230 if (deferInstructions) {
231 deferredInstructions.emplace_back(opcode, operands);
235 case spirv::Opcode::OpVariable:
236 if (isa<spirv::ModuleOp>(opBuilder.getBlock()->getParentOp())) {
239 if (operands.size() > 3 && undefCompositeMap.contains(operands[3])) {
240 return emitError(unknownLoc,
"OpVariable initializer <id> ")
242 <<
" has OpUndef constituents, which cannot be represented in "
246 case spirv::Opcode::OpUntypedVariableKHR:
247 if (isa<spirv::ModuleOp>(opBuilder.getBlock()->getParentOp()))
250 case spirv::Opcode::OpLine:
252 case spirv::Opcode::OpNoLine:
255 case spirv::Opcode::OpName:
256 return processName(operands);
257 case spirv::Opcode::OpString:
259 case spirv::Opcode::OpModuleProcessed:
260 case spirv::Opcode::OpSource:
261 case spirv::Opcode::OpSourceContinued:
262 case spirv::Opcode::OpSourceExtension:
266 case spirv::Opcode::OpTypeVoid:
267 case spirv::Opcode::OpTypeBool:
268 case spirv::Opcode::OpTypeInt:
269 case spirv::Opcode::OpTypeFloat:
270 case spirv::Opcode::OpTypeVector:
271 case spirv::Opcode::OpTypeMatrix:
272 case spirv::Opcode::OpTypeArray:
273 case spirv::Opcode::OpTypeFunction:
274 case spirv::Opcode::OpTypeImage:
275 case spirv::Opcode::OpTypeSampler:
276 case spirv::Opcode::OpTypeNamedBarrier:
277 case spirv::Opcode::OpTypeSampledImage:
278 case spirv::Opcode::OpTypeRuntimeArray:
279 case spirv::Opcode::OpTypeStruct:
280 case spirv::Opcode::OpTypePointer:
281 case spirv::Opcode::OpTypeUntypedPointerKHR:
282 case spirv::Opcode::OpTypeTensorARM:
283 case spirv::Opcode::OpTypeGraphARM:
284 case spirv::Opcode::OpTypeCooperativeMatrixKHR:
286 case spirv::Opcode::OpTypeForwardPointer:
288 case spirv::Opcode::OpConstant:
290 case spirv::Opcode::OpSpecConstant:
292 case spirv::Opcode::OpConstantComposite:
294 case spirv::Opcode::OpConstantCompositeReplicateEXT:
296 case spirv::Opcode::OpSpecConstantComposite:
298 case spirv::Opcode::OpSpecConstantCompositeReplicateEXT:
300 case spirv::Opcode::OpSpecConstantOp:
302 case spirv::Opcode::OpConstantTrue:
304 case spirv::Opcode::OpSpecConstantTrue:
306 case spirv::Opcode::OpConstantFalse:
308 case spirv::Opcode::OpSpecConstantFalse:
310 case spirv::Opcode::OpConstantNull:
312 case spirv::Opcode::OpGraphConstantARM:
314 case spirv::Opcode::OpDecorate:
315 case spirv::Opcode::OpDecorateId:
316 return processDecoration(operands);
317 case spirv::Opcode::OpMemberDecorate:
318 return processMemberDecoration(operands);
319 case spirv::Opcode::OpFunction:
321 case spirv::Opcode::OpGraphEntryPointARM:
322 if (deferInstructions) {
323 deferredInstructions.emplace_back(opcode, operands);
327 case spirv::Opcode::OpGraphARM:
329 case spirv::Opcode::OpGraphSetOutputARM:
331 case spirv::Opcode::OpGraphEndARM:
333 case spirv::Opcode::OpLabel:
335 case spirv::Opcode::OpBranch:
337 case spirv::Opcode::OpBranchConditional:
339 case spirv::Opcode::OpSelectionMerge:
341 case spirv::Opcode::OpLoopMerge:
343 case spirv::Opcode::OpPhi:
345 case spirv::Opcode::OpSwitch:
347 case spirv::Opcode::OpUndef:
349 case spirv::Opcode::OpConstantFunctionPointerINTEL:
359 unsigned numOperands) {
361 uint32_t valueID = 0;
363 size_t wordIndex = 0;
365 if (wordIndex >= words.size())
367 "expected result type <id> while deserializing for ")
371 auto type =
getType(words[wordIndex]);
373 return emitError(unknownLoc,
"unknown type result <id>: ")
375 resultTypes.push_back(type);
379 if (wordIndex >= words.size())
381 "expected result <id> while deserializing for ")
383 valueID = words[wordIndex];
391 size_t operandIndex = 0;
392 for (; operandIndex < numOperands && wordIndex < words.size();
393 ++operandIndex, ++wordIndex) {
394 auto arg =
getValue(words[wordIndex]);
396 return emitError(unknownLoc,
"unknown result <id>: ") << words[wordIndex];
397 operands.push_back(arg);
399 if (operandIndex != numOperands) {
402 "found less operands than expected when deserializing for ")
403 << opName <<
"; only " << operandIndex <<
" of " << numOperands
406 if (wordIndex != words.size()) {
409 "found more operands than expected when deserializing for ")
410 << opName <<
"; only " << wordIndex <<
" of " << words.size()
415 if (decorations.count(valueID)) {
416 auto attrs = decorations[valueID].getAttrs();
417 attributes.append(attrs.begin(), attrs.end());
438 if (operands.size() != 2) {
439 return emitError(unknownLoc,
"OpUndef instruction must have two operands");
441 auto type =
getType(operands[0]);
443 return emitError(unknownLoc,
"unknown type <id> with OpUndef instruction");
445 undefMap[operands[1]] = type;
451 if (operands.size() != 3) {
453 "OpConstantFunctionPointerINTEL must have 3 operands");
457 return emitError(unknownLoc,
"unknown type <id> with "
458 "OpConstantFunctionPointerINTEL instruction");
460 constantFunctionPointerMap[operands[1]] = {type, operands[2]};
466 bool deferInstructions) {
467 if (deferInstructions) {
468 deferredInstructions.emplace_back(spirv::Opcode::OpExtInst, operands);
472 if (operands.size() < 4) {
474 "OpExtInst must have at least 4 operands, result type "
475 "<id>, result <id>, set <id> and instruction opcode");
481 "DebugInfo instructions must have OpTypeVoid result type");
483 auto getDebugLoc = [&](uint32_t stringID) -> FailureOr<Location> {
485 debugInfoMap.find(stringID);
486 if (stringIt == debugInfoMap.end()) {
487 return emitError(unknownLoc,
"undefined string <id> ")
488 << stringID <<
" in DebugInfo";
494 return emitError(unknownLoc,
"unknown DebugInfo instruction opcode: ")
498 switch (instructionID) {
500 if (operands.size() < 6)
501 return emitError(unknownLoc,
"DebugGraph must have graph and string IDs");
502 uint32_t graphID = operands[4];
503 uint32_t stringID = operands[5];
505 graphMap.find(graphID);
506 if (graphIt == graphMap.end())
507 return emitError(unknownLoc,
"undefined graph <id> ")
508 << graphID <<
" in DebugGraph";
509 FailureOr<Location> loc = getDebugLoc(stringID);
512 graphIt->second->setLoc(*loc);
516 if (operands.size() < 7)
517 return emitError(unknownLoc,
"DebugOperation must have graph, string and "
519 uint32_t stringID = operands[5];
520 FailureOr<Location> loc = getDebugLoc(stringID);
524 operationIDs.append(std::next(operands.begin(), 6), operands.end());
525 for (uint32_t operationID : operationIDs) {
527 if (valueIt == valueMap.end())
528 return emitError(unknownLoc,
"undefined operation <id> ")
529 << operationID <<
" in DebugOperation";
530 valueIt->second.setLoc(*loc);
535 if (operands.size() < 6)
537 "DebugTensor must have tensor and string IDs");
538 uint32_t stringID = operands[5];
539 uint32_t tensorID = operands[4];
540 FailureOr<Location> loc = getDebugLoc(stringID);
543 if (constantMap.contains(tensorID)) {
544 constantLocMap[tensorID] = *loc;
548 if (valueIt == valueMap.end())
549 return emitError(unknownLoc,
"undefined tensor <id> ")
550 << tensorID <<
" in DebugTensor";
551 valueIt->second.setLoc(*loc);
560 if (operands.size() < 4) {
562 "OpExtInst must have at least 4 operands, result type "
563 "<id>, result <id>, set <id> and instruction opcode");
565 if (!extendedInstSets.count(operands[2])) {
566 return emitError(unknownLoc,
"undefined set <id> in OpExtInst");
569 slicedOperands.append(operands.begin(), std::next(operands.begin(), 2));
570 slicedOperands.append(std::next(operands.begin(), 4), operands.end());
572 extendedInstSets[operands[2]], operands[3], slicedOperands);
581 unsigned wordIndex = 0;
582 if (wordIndex >= words.size()) {
584 "missing Execution Model specification in OpEntryPoint");
586 auto execModel = spirv::ExecutionModelAttr::get(
587 context,
static_cast<spirv::ExecutionModel
>(words[wordIndex++]));
588 if (wordIndex >= words.size()) {
589 return emitError(unknownLoc,
"missing <id> in OpEntryPoint");
592 auto fnID = words[wordIndex++];
596 auto parsedFunc = getFunction(fnID);
598 return emitError(unknownLoc,
"no function matching <id> ") << fnID;
600 if (parsedFunc.getName() != fnName) {
604 if (!parsedFunc.getName().starts_with(
"spirv_fn_"))
606 "function name mismatch between OpEntryPoint "
607 "and OpFunction with <id> ")
608 << fnID <<
": " << fnName <<
" vs. " << parsedFunc.getName();
609 parsedFunc.setName(fnName);
612 while (wordIndex < words.size()) {
613 auto arg = getGlobalVariable(words[wordIndex]);
615 return emitError(unknownLoc,
"undefined result <id> ")
616 << words[wordIndex] <<
" while decoding OpEntryPoint";
618 interface.push_back(SymbolRefAttr::get(arg.getOperation()));
621 spirv::EntryPointOp::create(
622 opBuilder, unknownLoc, execModel,
623 SymbolRefAttr::get(opBuilder.getContext(), fnName),
624 opBuilder.getArrayAttr(interface));
631 unsigned wordIndex = 0;
632 if (wordIndex >= words.size()) {
634 "missing function result <id> in OpExecutionMode");
637 auto fnID = words[wordIndex++];
638 auto fn = getFunction(fnID);
640 return emitError(unknownLoc,
"no function matching <id> ") << fnID;
643 if (wordIndex >= words.size()) {
644 return emitError(unknownLoc,
"missing Execution Mode in OpExecutionMode");
646 auto execMode = spirv::ExecutionModeAttr::get(
647 context,
static_cast<spirv::ExecutionMode
>(words[wordIndex++]));
651 while (wordIndex < words.size()) {
652 attrListElems.push_back(opBuilder.getI32IntegerAttr(words[wordIndex++]));
654 auto values = opBuilder.getArrayAttr(attrListElems);
655 spirv::ExecutionModeOp::create(
656 opBuilder, unknownLoc,
657 SymbolRefAttr::get(opBuilder.getContext(), fn.getName()), execMode,
665 unsigned wordIndex = 0;
666 unsigned const wordsSize = words.size();
667 if (wordIndex >= wordsSize)
669 "missing function result <id> in OpExecutionModeId");
672 uint32_t fnID = words[wordIndex++];
673 FuncOp fn = getFunction(fnID);
675 return emitError(unknownLoc,
"no function matching <id> ") << fnID;
678 if (wordIndex >= wordsSize)
679 return emitError(unknownLoc,
"missing Execution Mode in OpExecutionModeId");
681 ExecutionModeAttr execMode = spirv::ExecutionModeAttr::get(
682 context,
static_cast<spirv::ExecutionMode
>(words[wordIndex++]));
686 while (wordIndex < words.size()) {
687 uint32_t
id = words[wordIndex++];
689 attrListElems.push_back(TypeAttr::get(type));
690 }
else if (std::optional<std::pair<Attribute, Type>> constInfo =
692 attrListElems.push_back(constInfo->first);
693 }
else if (spirv::SpecConstantOp specConst = getSpecConstant(
id)) {
694 attrListElems.push_back(SymbolRefAttr::get(specConst));
696 return emitError(unknownLoc,
"unknown <id> ")
697 <<
id <<
" in OpExecutionModeId";
700 ArrayAttr values = opBuilder.getArrayAttr(attrListElems);
701 spirv::ExecutionModeIdOp::create(
702 opBuilder, unknownLoc,
703 SymbolRefAttr::get(opBuilder.getContext(), fn.getName()), execMode,
711 if (operands.size() < 3) {
713 "OpFunctionCall must have at least 3 operands");
718 return emitError(unknownLoc,
"undefined result type from <id> ")
723 if (isVoidType(resultType))
724 resultType =
nullptr;
726 auto resultID = operands[1];
727 auto functionID = operands[2];
729 auto functionName = getFunctionSymbol(functionID);
732 for (
auto operand : llvm::drop_begin(operands, 3)) {
733 auto value = getValue(operand);
735 return emitError(unknownLoc,
"unknown <id> ")
736 << operand <<
" used by OpFunctionCall";
738 arguments.push_back(value);
741 auto opFunctionCall = spirv::FunctionCallOp::create(
742 opBuilder, unknownLoc, resultType,
743 SymbolRefAttr::get(opBuilder.getContext(), functionName), arguments);
745 if (
auto it = decorations.find(resultID); it != decorations.end())
750 valueMap[resultID] = opFunctionCall.getResult(0);
757 if (operands.size() < 3) {
759 unknownLoc,
"OpFunctionPointerCallINTEL must have at least 3 operands");
764 return emitError(unknownLoc,
"undefined result type from <id> ")
768 if (isVoidType(resultType))
769 resultType =
nullptr;
771 uint32_t resultID = operands[1];
773 for (uint32_t operand : llvm::drop_begin(operands, 2)) {
774 Value value = getValue(operand);
776 return emitError(unknownLoc,
"unknown <id> ")
777 << operand <<
" used by OpFunctionPointerCallINTEL";
779 values.push_back(value);
782 auto callOp = spirv::INTELFunctionPointerCallOp::create(
783 opBuilder, unknownLoc, resultType, values.front(),
786 if (
auto it = decorations.find(resultID); it != decorations.end())
791 valueMap[resultID] = callOp.getReturnValue();
799 size_t wordIndex = 0;
803 if (wordIndex < words.size()) {
804 auto arg = getValue(words[wordIndex]);
807 return emitError(unknownLoc,
"unknown result <id> : ")
811 operands.push_back(arg);
815 if (wordIndex < words.size()) {
816 auto arg = getValue(words[wordIndex]);
819 return emitError(unknownLoc,
"unknown result <id> : ")
823 operands.push_back(arg);
827 bool isAlignedAttr =
false;
829 if (wordIndex < words.size()) {
830 auto attrValue = words[wordIndex++];
831 auto attr = opBuilder.getAttr<spirv::MemoryAccessAttr>(
832 static_cast<spirv::MemoryAccess
>(attrValue));
833 attributes.push_back(
834 opBuilder.getNamedAttr(attributeName<MemoryAccess>(), attr));
835 isAlignedAttr = (attrValue == 2);
838 if (isAlignedAttr && wordIndex < words.size()) {
839 attributes.push_back(opBuilder.getNamedAttr(
840 "alignment", opBuilder.getI32IntegerAttr(words[wordIndex++])));
843 if (wordIndex < words.size()) {
844 auto attrValue = words[wordIndex++];
845 auto attr = opBuilder.getAttr<spirv::MemoryAccessAttr>(
846 static_cast<spirv::MemoryAccess
>(attrValue));
847 attributes.push_back(opBuilder.getNamedAttr(
"source_memory_access", attr));
850 if (wordIndex < words.size()) {
851 attributes.push_back(opBuilder.getNamedAttr(
852 "source_alignment", opBuilder.getI32IntegerAttr(words[wordIndex++])));
855 if (wordIndex != words.size()) {
857 "found more operands than expected when deserializing "
858 "spirv::CopyMemoryOp, only ")
859 << wordIndex <<
" of " << words.size() <<
" processed";
862 Location loc = createFileLineColLoc(opBuilder);
863 spirv::CopyMemoryOp::Properties properties{};
864 spirv::CopyMemoryOp::populateDefaultProperties(
866 opBuilder.getContext()),
868 if (failed(spirv::CopyMemoryOp::setPropertiesFromAttr(
869 properties, opBuilder.getDictionaryAttr(attributes),
870 [&]() { return emitError(loc); })))
872 spirv::CopyMemoryOp::create(opBuilder, loc, resultTypes, operands, properties,
881 if (words.size() != 4) {
883 "expected 4 words in GenericCastToPtrExplicitOp"
889 uint32_t valueID = 0;
893 return emitError(unknownLoc,
"unknown type result <id> : ") << words[0];
894 resultTypes.push_back(type);
898 auto arg = getValue(words[2]);
900 return emitError(unknownLoc,
"unknown result <id> : ") << words[2];
901 operands.push_back(arg);
903 Location loc = createFileLineColLoc(opBuilder);
904 Operation *op = spirv::GenericCastToPtrExplicitOp::create(
905 opBuilder, loc, resultTypes, operands);
913 if (words.size() != 2)
914 return emitError(unknownLoc,
"OpAbortKHR must have two operands");
918 return emitError(unknownLoc,
"unknown type <id> : ") << words[0];
920 Value message = getValue(words[1]);
922 return emitError(unknownLoc,
"unknown <id> : ") << words[1];
925 if (message.
getType() != messageType)
926 return emitError(unknownLoc,
"OpAbortKHR Message Type ")
927 << messageType <<
" differs from the type of Message "
930 spirv::KHRAbortOp::create(opBuilder, createFileLineColLoc(opBuilder),
938#define GET_DESERIALIZATION_FNS
939#include "mlir/Dialect/SPIRV/IR/SPIRVSerialization.inc"
static spirv::Opcode extractOpcode(uint32_t word)
Extracts the opcode from the given first word of a SPIR-V instruction.
static NameLoc getLocFromDebugInfoString(OpBuilder &builder, StringRef source)
Returns a NameLoc location from the given debug info string.
StringAttr getStringAttr(const Twine &bytes)
Location objects represent source locations information in MLIR.
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.
StringAttr getName() const
Return the name of the attribute.
Attribute getValue() const
Return the value of the attribute.
This class helps build Operations.
This class provides the API for ops that are known to be terminators.
Operation is the basic unit of execution within MLIR.
bool hasTrait()
Returns true if the operation was registered with a particular trait, e.g.
OpResult getResult(unsigned idx)
Get the 'idx'th result of this operation.
static Operation * create(Location location, OperationName name, TypeRange resultTypes, ValueRange operands, NamedAttrList &&attributes, PropertyRef properties, BlockRange successors, unsigned numRegions)
Create a new Operation with the specific fields.
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...
Type getType() const
Return the type of this value.
Value materializeSpecConstantOperation(uint32_t resultID, spirv::Opcode enclosedOpcode, uint32_t resultTypeID, ArrayRef< uint32_t > enclosedOpOperands)
Materializes/emits an OpSpecConstantOp instruction.
Value getValue(uint32_t id)
Get the Value associated with a result <id>.
std::optional< SpecConstOperationMaterializationInfo > getSpecConstantOperation(uint32_t id)
Gets the info needed to materialize the spec constant operation op associated with the given <id>.
LogicalResult dispatchToAutogenDeserialization(spirv::Opcode opcode, ArrayRef< uint32_t > words)
Method to dispatch to the specialized deserialization function for an operation in SPIR-V dialect tha...
LogicalResult processGraphDebugInfoExtInst(ArrayRef< uint32_t > operands, bool deferInstructions)
Processes a SPIR-V OpExtInst with given operands for a NonSemantic.Graph.DebugInfo instruction.
LogicalResult processConstantNull(ArrayRef< uint32_t > operands)
Processes a SPIR-V OpConstantNull instruction with the given operands.
LogicalResult processSpecConstantComposite(ArrayRef< uint32_t > operands)
Processes a SPIR-V OpSpecConstantComposite instruction with the given operands.
LogicalResult processInstruction(spirv::Opcode opcode, ArrayRef< uint32_t > operands, bool deferInstructions=true)
Processes a SPIR-V instruction with the given opcode and operands.
LogicalResult processBranchConditional(ArrayRef< uint32_t > operands)
LogicalResult processGlobalVariable(spirv::Opcode opcode, ArrayRef< uint32_t > operands)
Processes the OpVariable or OpUntypedVariableKHR instructions at current offset into binary.
spirv::GlobalVariableOp getGlobalVariable(uint32_t id)
Gets the global variable associated with a result <id> of OpVariable.
LogicalResult processGraphARM(ArrayRef< uint32_t > operands)
LogicalResult processConstantFunctionPointer(ArrayRef< uint32_t > operands)
Processes an OpConstantFunctionPointerINTEL instruction.
LogicalResult processLabel(ArrayRef< uint32_t > operands)
Processes a SPIR-V OpLabel instruction with the given operands.
LogicalResult processExtInst(ArrayRef< uint32_t > operands)
Processes a SPIR-V OpExtInst with given operands.
std::optional< spirv::GraphConstantARMOpMaterializationInfo > getGraphConstantARM(uint32_t id)
Gets the GraphConstantARM ID attribute and result type with the given result <id>.
std::optional< std::pair< Attribute, Type > > getConstant(uint32_t id)
Gets the constant's attribute and type associated with the given <id>.
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 processLoopMerge(ArrayRef< uint32_t > operands)
Processes a SPIR-V OpLoopMerge instruction with the given operands.
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 operand...
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>.
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 SP...
Type getUndefType(uint32_t id)
Get the type associated with the result <id> of an OpUndef.
LogicalResult processSpecConstantCompositeReplicateEXT(ArrayRef< uint32_t > operands)
Processes a SPIR-V OpSpecConstantCompositeReplicateEXT instruction with the given operands.
std::pair< Type, uint32_t > getConstantFunctionPointer(uint32_t id)
Gets the type and function <id> of an OpConstantFunctionPointerINTEL.
LogicalResult processGraphEntryPointARM(ArrayRef< uint32_t > operands)
LogicalResult processFunction(ArrayRef< uint32_t > operands)
Creates a deserializer for the given SPIR-V binary module.
bool isVoidType(Type type) const
Returns true if the given type is for SPIR-V void type.
LogicalResult processDebugString(ArrayRef< uint32_t > operands)
Processes a SPIR-V OpString instruction with the 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 instructio...
LogicalResult processPhi(ArrayRef< uint32_t > operands)
Processes a SPIR-V OpPhi instruction with the given operands.
std::string getFunctionSymbol(uint32_t id)
Returns a symbol to be used for the function name with the given result <id>.
void clearDebugLine()
Discontinues any source-level location information that might be active from a previous OpLine instru...
void mergeLongCompositeContinuations(spirv::Opcode opcode, ArrayRef< uint32_t > &operands, SmallVectorImpl< uint32_t > &mergedStorage)
If opcode is a SPV_INTEL_long_composites splittable opcode and the next binary instruction(s) are mat...
LogicalResult processTypeForwardPointer(ArrayRef< uint32_t > operands)
LogicalResult processSwitch(ArrayRef< uint32_t > operands)
Processes a SPIR-V OpSwitch instruction with the given operands.
LogicalResult processOpWithoutGrammarAttr(ArrayRef< uint32_t > words, StringRef opName, bool hasResult, unsigned numOperands)
Processes a SPIR-V instruction from the given operands.
LogicalResult processGraphEndARM(ArrayRef< uint32_t > operands)
LogicalResult processConstantComposite(ArrayRef< uint32_t > operands)
Processes a SPIR-V OpConstantComposite instruction with the given operands.
LogicalResult processBranch(ArrayRef< uint32_t > operands)
std::optional< std::pair< Attribute, Type > > getConstantCompositeReplicate(uint32_t id)
Gets the replicated composite constant's attribute and type associated with the given <id>.
LogicalResult processUndef(ArrayRef< uint32_t > operands)
Processes a OpUndef instruction.
LogicalResult processSpecConstantOperation(ArrayRef< uint32_t > operands)
Processes a SPIR-V OpSpecConstantOp instruction with the given operands.
LogicalResult processConstant(ArrayRef< uint32_t > operands, bool isSpec)
Processes a SPIR-V Op{|Spec}Constant instruction with the given operands.
Location createFileLineColLoc(OpBuilder opBuilder)
Creates a FileLineColLoc with the OpLine location information.
LogicalResult processGraphConstantARM(ArrayRef< uint32_t > operands)
Processes a SPIR-V OpGraphConstantARM 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.
spirv::SpecConstantOp getSpecConstant(uint32_t id)
Gets the specialization constant with the given result <id>.
LogicalResult processConstantCompositeReplicateEXT(ArrayRef< uint32_t > operands)
Processes a SPIR-V OpConstantCompositeReplicateEXT instruction with the given operands.
LogicalResult processSelectionMerge(ArrayRef< uint32_t > operands)
Processes a SPIR-V OpSelectionMerge instruction with the given operands.
LogicalResult processOpGraphSetOutputARM(ArrayRef< uint32_t > operands)
LogicalResult processDebugLine(ArrayRef< uint32_t > operands)
Processes a SPIR-V OpLine instruction with the given operands.
std::optional< std::pair< Type, SmallVector< uint32_t > > > getUndefComposite(uint32_t id)
Gets the type and constituent <id>s of the undef composite with the given <id>.
std::optional< spirv::Opcode > getContinuationOpcode(spirv::Opcode parent)
Returns the SPV_INTEL_long_composites continuation opcode that may follow parent, or std::nullopt if ...
constexpr bool isValidGraphDebugInfoExtInst(uint32_t opcode)
constexpr llvm::StringLiteral extGraphDebugInfo
Extension set name for non-semantic graph debug info.
StringRef decodeStringLiteral(ArrayRef< uint32_t > words, unsigned &wordIndex)
Decodes a string literal in words starting at wordIndex.
GraphDebugInfoExtInst
Instruction opcodes in the NonSemantic.Graph.DebugInfo.1 extended instruction set.
Include the generated interface declarations.
Type getType(OpFoldResult ofr)
Returns the int type of the integer in ofr.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
llvm::DenseMap< KeyT, ValueT, KeyInfoT, BucketT > DenseMap
This represents an operation in an abstracted form, suitable for use with the builder APIs.
void addOperands(ValueRange newOperands)
void addAttributes(ArrayRef< NamedAttribute > newAttributes)
Add an array of named attributes.
void addTypes(ArrayRef< Type > newTypes)