29#define DEBUG_TYPE "asm-printer"
32#include "SPIRVGenAsmWriter.inc"
38 bool SkipImmediates) {
39 const unsigned NumOps =
MI->getNumOperands();
40 for (
unsigned i = StartIndex; i < NumOps; ++i) {
41 if (!SkipImmediates || !
MI->getOperand(i).isImm()) {
42 if (!SkipFirstSpace || i != StartIndex)
53 if (
MI->getNumOperands() - StartIndex == 2) {
54 uint64_t Imm =
MI->getOperand(StartIndex).getImm();
55 Imm |= (
MI->getOperand(StartIndex + 1).getImm() << 32);
62void SPIRVInstPrinter::recordOpExtInstImport(
const MCInst *
MI) {
66 ExtInstSetIDs.
insert({Reg, Set});
72 const unsigned OpCode =
MI->getOpcode();
75 if (OpCode == SPIRV::OpDecorate) {
77 }
else if (OpCode == SPIRV::OpExtInstImport) {
78 recordOpExtInstImport(
MI);
79 }
else if (OpCode == SPIRV::OpExtInst) {
86 const unsigned LastFixedIndex = NumFixedOps - 1;
87 const int FirstVariableIndex = NumFixedOps;
88 if (NumFixedOps > 0 && MCDesc.
operands()[LastFixedIndex].OperandType ==
94 case SPIRV::OpTypeImage:
96 printSymbolicOperand<OperandCategory::AccessQualifierOperand>(
97 MI, FirstVariableIndex,
OS);
99 case SPIRV::OpVariable:
103 case SPIRV::OpEntryPoint: {
109 case SPIRV::OpExecutionMode:
110 case SPIRV::OpExecutionModeId:
111 case SPIRV::OpLoopMerge: {
127 printSymbolicOperand<OperandCategory::MemoryOperandOperand>(
128 MI, FirstVariableIndex,
OS);
131 case SPIRV::OpImageSampleImplicitLod:
132 case SPIRV::OpImageSampleDrefImplicitLod:
133 case SPIRV::OpImageSampleProjImplicitLod:
134 case SPIRV::OpImageSampleProjDrefImplicitLod:
135 case SPIRV::OpImageFetch:
136 case SPIRV::OpImageGather:
137 case SPIRV::OpImageDrefGather:
138 case SPIRV::OpImageRead:
139 case SPIRV::OpImageWrite:
140 case SPIRV::OpImageSparseSampleImplicitLod:
141 case SPIRV::OpImageSparseSampleDrefImplicitLod:
142 case SPIRV::OpImageSparseSampleProjImplicitLod:
143 case SPIRV::OpImageSparseSampleProjDrefImplicitLod:
144 case SPIRV::OpImageSparseFetch:
145 case SPIRV::OpImageSparseGather:
146 case SPIRV::OpImageSparseDrefGather:
147 case SPIRV::OpImageSparseRead:
148 case SPIRV::OpImageSampleFootprintNV:
150 printSymbolicOperand<OperandCategory::ImageOperandOperand>(
151 MI, FirstVariableIndex,
OS);
154 case SPIRV::OpCopyMemory:
155 case SPIRV::OpCopyMemorySized: {
156 const unsigned NumOps =
MI->getNumOperands();
157 for (
unsigned i = NumFixedOps; i < NumOps; ++i) {
159 printSymbolicOperand<OperandCategory::MemoryOperandOperand>(
MI, i,
161 if (
MI->getOperand(i).getImm() & MemoryOperand::Aligned) {
162 assert(i + 1 < NumOps &&
"Missing alignment operand");
170 case SPIRV::OpConstantI:
171 case SPIRV::OpConstantF:
190 const auto NumOps =
MI->getNumOperands();
191 if (NumOps == NumFixedOps)
206 if (NumFixedOps !=
MI->getNumOperands()) {
207 auto DecOp =
MI->getOperand(NumFixedOps - 1);
208 auto Dec =
static_cast<Decoration::Decoration
>(DecOp.getImm());
213 case Decoration::BuiltIn:
214 printSymbolicOperand<OperandCategory::BuiltInOperand>(
MI, NumFixedOps, O);
216 case Decoration::UniformId:
217 printSymbolicOperand<OperandCategory::ScopeOperand>(
MI, NumFixedOps, O);
219 case Decoration::FuncParamAttr:
220 printSymbolicOperand<OperandCategory::FunctionParameterAttributeOperand>(
223 case Decoration::FPRoundingMode:
224 printSymbolicOperand<OperandCategory::FPRoundingModeOperand>(
227 case Decoration::FPFastMathMode:
228 printSymbolicOperand<OperandCategory::FPFastMathModeOperand>(
231 case Decoration::LinkageAttributes:
232 case Decoration::UserSemantic:
246 if (
const MCBinaryExpr *BE = dyn_cast<MCBinaryExpr>(Expr))
247 SRE = cast<MCSymbolRefExpr>(BE->getLHS());
249 SRE = cast<MCSymbolRefExpr>(Expr);
260 assert((Modifier == 0 || Modifier[0] == 0) &&
"No modifiers supported");
261 if (OpNo < MI->getNumOperands()) {
267 else if (Op.isDFPImm())
269 else if (Op.isExpr())
278 const unsigned NumOps =
MI->getNumOperands();
279 unsigned StrStartIndex = OpNo;
280 while (StrStartIndex < NumOps) {
281 if (
MI->getOperand(StrStartIndex).isReg())
285 if (StrStartIndex != OpNo)
295 unsigned numOpsInString = (Str.size() / 4) + 1;
296 StrStartIndex += numOpsInString;
299 if (
MI->getOpcode() == SPIRV::OpDecorate &&
300 MI->getOperand(1).getImm() ==
301 static_cast<unsigned>(Decoration::LinkageAttributes)) {
303 printSymbolicOperand<OperandCategory::LinkageTypeOperand>(
304 MI, StrStartIndex, O);
312 auto SetReg =
MI->getOperand(2).getReg();
313 auto Set = ExtInstSetIDs[SetReg];
314 auto Op =
MI->getOperand(OpNo).getImm();
318template <OperandCategory::OperandCategory category>
321 if (OpNo < MI->getNumOperands()) {
static void printExpr(const MCExpr *Expr, const MCAsmInfo *MAI, raw_ostream &OS)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Binary assembler expressions.
Base class for the full range of assembler expressions which are needed for parsing.
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.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode.
Instances of this class represent operands of the MCInst class.
Generic base class for all target subtargets.
Represent a reference to a symbol from inside an expression.
VariantKind getKind() const
Wrapper class representing virtual and physical registers.
static unsigned virtReg2Index(Register Reg)
Convert a virtual register number to a 0-based index.
void printExtension(const MCInst *MI, unsigned OpNo, raw_ostream &O)
void printStringImm(const MCInst *MI, unsigned OpNo, raw_ostream &O)
void printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O, const char *Modifier=nullptr)
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 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)
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.
Lowers a builtin funtion call using the provided DemangledCall skeleton and external instruction Set.
This is an optimization pass for GlobalISel generic memory operations.
std::string getExtInstName(SPIRV::InstructionSet::InstructionSet Set, uint32_t InstructionNumber)
std::string getSPIRVStringOperand(const InstType &MI, unsigned StartIndex)
SPIRV::InstructionSet::InstructionSet getExtInstSetFromString(std::string SetName)
std::string getSymbolicOperandMnemonic(SPIRV::OperandCategory::OperandCategory Category, int32_t Value)