27#define DEBUG_TYPE "asm-printer"
30#include "SPIRVGenAsmWriter.inc"
36 bool SkipImmediates) {
37 const unsigned NumOps =
MI->getNumOperands();
38 for (
unsigned i = StartIndex; i <
NumOps; ++i) {
39 if (!SkipImmediates || !
MI->getOperand(i).isImm()) {
40 if (!SkipFirstSpace || i != StartIndex)
51 const unsigned NumVarOps =
MI->getNumOperands() - StartIndex;
53 assert((NumVarOps == 1 || NumVarOps == 2) &&
54 "Unsupported number of bits for literal variable");
58 uint64_t Imm =
MI->getOperand(StartIndex).getImm();
62 Imm |= (
MI->getOperand(StartIndex + 1).
getImm() << 32);
66 if (
MI->getOpcode() == SPIRV::OpConstantF && IsBitwidth16 == 0) {
73 if (
FP.isInfinity()) {
86 O <<
format(
"%.*g", std::numeric_limits<double>::max_digits10,
87 FP.convertToDouble());
96void SPIRVInstPrinter::recordOpExtInstImport(
const MCInst *
MI) {
100 ExtInstSetIDs.
insert({Reg, Set});
106 const unsigned OpCode =
MI->getOpcode();
109 if (OpCode == SPIRV::OpDecorate) {
111 }
else if (OpCode == SPIRV::OpExtInstImport) {
112 recordOpExtInstImport(
MI);
113 }
else if (OpCode == SPIRV::OpExtInst) {
115 }
else if (OpCode == SPIRV::UNKNOWN_type) {
122 const unsigned LastFixedIndex = NumFixedOps - 1;
123 const int FirstVariableIndex = NumFixedOps;
124 if (NumFixedOps > 0 && MCDesc.
operands()[LastFixedIndex].OperandType ==
130 case SPIRV::OpTypeImage:
133 MI, FirstVariableIndex, OS);
135 case SPIRV::OpVariable:
139 case SPIRV::OpEntryPoint: {
145 case SPIRV::OpMemberDecorate:
148 case SPIRV::OpExecutionMode:
149 case SPIRV::OpExecutionModeId:
150 case SPIRV::OpLoopMerge: {
167 MI, FirstVariableIndex, OS);
170 case SPIRV::OpImageSampleImplicitLod:
171 case SPIRV::OpImageSampleDrefImplicitLod:
172 case SPIRV::OpImageSampleProjImplicitLod:
173 case SPIRV::OpImageSampleProjDrefImplicitLod:
174 case SPIRV::OpImageFetch:
175 case SPIRV::OpImageGather:
176 case SPIRV::OpImageDrefGather:
177 case SPIRV::OpImageRead:
178 case SPIRV::OpImageWrite:
179 case SPIRV::OpImageSparseSampleImplicitLod:
180 case SPIRV::OpImageSparseSampleDrefImplicitLod:
181 case SPIRV::OpImageSparseSampleProjImplicitLod:
182 case SPIRV::OpImageSparseSampleProjDrefImplicitLod:
183 case SPIRV::OpImageSparseFetch:
184 case SPIRV::OpImageSparseGather:
185 case SPIRV::OpImageSparseDrefGather:
186 case SPIRV::OpImageSparseRead:
187 case SPIRV::OpImageSampleFootprintNV:
190 MI, FirstVariableIndex, OS);
193 case SPIRV::OpCopyMemory:
194 case SPIRV::OpCopyMemorySized: {
195 const unsigned NumOps =
MI->getNumOperands();
196 for (
unsigned i = NumFixedOps; i <
NumOps; ++i) {
200 if (
MI->getOperand(i).getImm() & MemoryOperand::Aligned) {
209 case SPIRV::OpConstantI:
210 case SPIRV::OpConstantF:
213 assert(NumFixedOps > 0 &&
"Expected at least one fixed operand");
216 case SPIRV::OpCooperativeMatrixMulAddKHR: {
217 const unsigned NumOps =
MI->getNumOperands();
218 if (NumFixedOps ==
NumOps)
222 const unsigned MulAddOp =
MI->getOperand(FirstVariableIndex).getImm();
225 OperandCategory::CooperativeMatrixOperandsOperand>(
226 MI, FirstVariableIndex, OS);
229 for (
unsigned Mask = 0x1;
230 Mask != SPIRV::CooperativeMatrixOperands::
231 MatrixResultBFloat16ComponentsINTEL;
233 if (MulAddOp & Mask) {
237 OperandCategory::CooperativeMatrixOperandsOperand, Mask);
244 case SPIRV::OpSubgroupMatrixMultiplyAccumulateINTEL: {
245 const unsigned NumOps =
MI->getNumOperands();
246 if (NumFixedOps >=
NumOps)
249 const unsigned Flags =
MI->getOperand(
NumOps - 1).getImm();
252 OperandCategory::MatrixMultiplyAccumulateOperandsOperand>(
256 for (
unsigned Mask = 0x1;
257 Mask <= SPIRV::MatrixMultiplyAccumulateOperands::
258 MatrixBPackedBFloat16INTEL;
264 OperandCategory::MatrixMultiplyAccumulateOperandsOperand,
275 case SPIRV::OpSDotAccSat:
276 case SPIRV::OpUDotAccSat:
277 case SPIRV::OpSUDotAccSat: {
278 const unsigned NumOps =
MI->getNumOperands();
279 if (
NumOps > NumFixedOps) {
287 case SPIRV::OpPredicatedLoadINTEL:
288 case SPIRV::OpPredicatedStoreINTEL: {
289 const unsigned NumOps =
MI->getNumOperands();
290 if (
NumOps > NumFixedOps) {
314 const auto NumOps =
MI->getNumOperands();
315 if (
NumOps == NumFixedOps)
330 if (NumFixedOps !=
MI->getNumOperands()) {
331 auto DecOp =
MI->getOperand(NumFixedOps - 1);
332 auto Dec =
static_cast<Decoration::Decoration
>(DecOp.getImm());
337 case Decoration::BuiltIn:
340 case Decoration::UniformId:
343 case Decoration::FuncParamAttr:
347 case Decoration::FPRoundingMode:
351 case Decoration::FPFastMathMode:
355 case Decoration::LinkageAttributes:
356 case Decoration::UserSemantic:
359 case Decoration::HostAccessINTEL:
361 if (NumFixedOps + 1 <
MI->getNumOperands()) {
374 const auto EnumOperand =
MI->getOperand(1);
375 assert(EnumOperand.isImm() &&
376 "second operand of UNKNOWN_type must be opcode!");
378 const auto Enumerant = EnumOperand.getImm();
379 const auto NumOps =
MI->getNumOperands();
382 O <<
"OpUnknown(" << Enumerant <<
", " <<
NumOps <<
") ";
391 if (
NumOps == NumFixedOps)
400 if (OpNo < MI->getNumOperands()) {
404 else if (
Op.isImm()) {
405 int64_t Imm =
Op.getImm();
410 if (
MI->getOpcode() == SPIRV::OpVectorShuffle && Imm == -1)
414 }
else if (
Op.isDFPImm())
416 else if (
Op.isExpr())
417 MAI.printExpr(O, *
Op.getExpr());
425 const unsigned NumOps =
MI->getNumOperands();
426 unsigned StrStartIndex = OpNo;
427 while (StrStartIndex <
NumOps) {
428 if (
MI->getOperand(StrStartIndex).isReg())
432 if (StrStartIndex != OpNo)
447 unsigned numOpsInString = (Str.size() / 4) + 1;
448 StrStartIndex += numOpsInString;
451 if (
MI->getOpcode() == SPIRV::OpDecorate &&
452 MI->getOperand(1).getImm() ==
453 static_cast<unsigned>(Decoration::LinkageAttributes)) {
456 MI, StrStartIndex, O);
464 auto SetReg =
MI->getOperand(2).getReg();
465 auto Set = ExtInstSetIDs[SetReg];
466 auto Op =
MI->getOperand(OpNo).getImm();
470template <OperandCategory::OperandCategory category>
473 if (OpNo < MI->getNumOperands()) {
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file declares a class to represent arbitrary precision floating point values and provide a varie...
const size_t AbstractManglingParser< Derived, Alloc >::NumOps
Class for arbitrary precision integers.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
void printAnnotation(raw_ostream &OS, StringRef Annot)
Utility function for printing annotations.
format_object< int64_t > formatImm(int64_t Value) const
Utility function to print immediates in decimal or hex.
Instances of this class represent a single low-level machine instruction.
Describe properties that are true of each instruction in the target description file.
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
ArrayRef< MCOperandInfo > operands() const
bool isVariadic() const
Return true if this instruction can have a variable number of operands.
Instances of this class represent operands of the MCInst class.
Wrapper class representing physical registers. Should be passed by value.
Generic base class for all target subtargets.
void printExtension(const MCInst *MI, unsigned OpNo, raw_ostream &O)
void printStringImm(const MCInst *MI, unsigned OpNo, raw_ostream &O)
void printInstruction(const MCInst *MI, uint64_t Address, raw_ostream &O)
void printInst(const MCInst *MI, uint64_t Address, StringRef Annot, const MCSubtargetInfo &STI, raw_ostream &OS) override
Print the specified MCInst to the specified raw_ostream.
void printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O)
void printOpExtInst(const MCInst *MI, raw_ostream &O)
void printOpConstantVarOps(const MCInst *MI, unsigned StartIndex, raw_ostream &O)
void printSymbolicOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O)
void printRemainingVariableOps(const MCInst *MI, unsigned StartIndex, raw_ostream &O, bool SkipFirstSpace=false, bool SkipImmediates=false)
void printOpDecorate(const MCInst *MI, raw_ostream &O)
void printUnknownType(const MCInst *MI, raw_ostream &O)
StringRef - Represent a constant reference to a string, i.e.
This class implements an extremely fast bulk output stream that can only output to a stream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned getIDFromRegister(unsigned Reg)
This is an optimization pass for GlobalISel generic memory operations.
std::string getExtInstName(SPIRV::InstructionSet::InstructionSet Set, uint32_t InstructionNumber)
MachineInstr * getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
std::string getSPIRVStringOperand(const InstType &MI, unsigned StartIndex)
SPIRV::InstructionSet::InstructionSet getExtInstSetFromString(std::string SetName)
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
std::string getSymbolicOperandMnemonic(SPIRV::OperandCategory::OperandCategory Category, int32_t Value)
DWARFExpression::Operation Op