LLVM 19.0.0git
SPIRVAsmPrinter.cpp
Go to the documentation of this file.
1//===-- SPIRVAsmPrinter.cpp - SPIR-V LLVM assembly writer ------*- C++ -*--===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains a printer that converts from our internal representation
10// of machine-dependent LLVM code to the SPIR-V assembly language.
11//
12//===----------------------------------------------------------------------===//
13
15#include "SPIRV.h"
16#include "SPIRVInstrInfo.h"
17#include "SPIRVMCInstLower.h"
18#include "SPIRVModuleAnalysis.h"
19#include "SPIRVSubtarget.h"
20#include "SPIRVTargetMachine.h"
21#include "SPIRVUtils.h"
23#include "llvm/ADT/DenseMap.h"
31#include "llvm/MC/MCAsmInfo.h"
32#include "llvm/MC/MCAssembler.h"
33#include "llvm/MC/MCInst.h"
35#include "llvm/MC/MCStreamer.h"
36#include "llvm/MC/MCSymbol.h"
39
40using namespace llvm;
41
42#define DEBUG_TYPE "asm-printer"
43
44namespace {
45class SPIRVAsmPrinter : public AsmPrinter {
46 unsigned NLabels = 0;
47
48public:
49 explicit SPIRVAsmPrinter(TargetMachine &TM,
50 std::unique_ptr<MCStreamer> Streamer)
51 : AsmPrinter(TM, std::move(Streamer)), ST(nullptr), TII(nullptr) {}
52 bool ModuleSectionsEmitted;
53 const SPIRVSubtarget *ST;
54 const SPIRVInstrInfo *TII;
55
56 StringRef getPassName() const override { return "SPIRV Assembly Printer"; }
57 void printOperand(const MachineInstr *MI, int OpNum, raw_ostream &O);
58 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
59 const char *ExtraCode, raw_ostream &O) override;
60
61 void outputMCInst(MCInst &Inst);
62 void outputInstruction(const MachineInstr *MI);
63 void outputModuleSection(SPIRV::ModuleSectionType MSType);
64 void outputGlobalRequirements();
65 void outputEntryPoints();
66 void outputDebugSourceAndStrings(const Module &M);
67 void outputOpExtInstImports(const Module &M);
68 void outputOpMemoryModel();
69 void outputOpFunctionEnd();
70 void outputExtFuncDecls();
71 void outputExecutionModeFromMDNode(Register Reg, MDNode *Node,
72 SPIRV::ExecutionMode::ExecutionMode EM);
73 void outputExecutionModeFromNumthreadsAttribute(
74 const Register &Reg, const Attribute &Attr,
75 SPIRV::ExecutionMode::ExecutionMode EM);
76 void outputExecutionMode(const Module &M);
77 void outputAnnotations(const Module &M);
78 void outputModuleSections();
79
80 void emitInstruction(const MachineInstr *MI) override;
81 void emitFunctionEntryLabel() override {}
82 void emitFunctionHeader() override;
83 void emitFunctionBodyStart() override {}
84 void emitFunctionBodyEnd() override;
85 void emitBasicBlockStart(const MachineBasicBlock &MBB) override;
86 void emitBasicBlockEnd(const MachineBasicBlock &MBB) override {}
87 void emitGlobalVariable(const GlobalVariable *GV) override {}
88 void emitOpLabel(const MachineBasicBlock &MBB);
89 void emitEndOfAsmFile(Module &M) override;
90 bool doInitialization(Module &M) override;
91
92 void getAnalysisUsage(AnalysisUsage &AU) const override;
94};
95} // namespace
96
97void SPIRVAsmPrinter::getAnalysisUsage(AnalysisUsage &AU) const {
101}
102
103// If the module has no functions, we need output global info anyway.
104void SPIRVAsmPrinter::emitEndOfAsmFile(Module &M) {
105 if (ModuleSectionsEmitted == false) {
106 outputModuleSections();
107 ModuleSectionsEmitted = true;
108 }
109
110 ST = static_cast<const SPIRVTargetMachine &>(TM).getSubtargetImpl();
111 uint32_t DecSPIRVVersion = ST->getSPIRVVersion();
112 uint32_t Major = DecSPIRVVersion / 10;
113 uint32_t Minor = DecSPIRVVersion - Major * 10;
114 // Bound is an approximation that accounts for the maximum used register
115 // number and number of generated OpLabels
116 unsigned Bound = 2 * (ST->getBound() + 1) + NLabels;
117 bool FlagToRestore = OutStreamer->getUseAssemblerInfoForParsing();
118 OutStreamer->setUseAssemblerInfoForParsing(true);
119 if (MCAssembler *Asm = OutStreamer->getAssemblerPtr())
120 Asm->setBuildVersion(static_cast<MachO::PlatformType>(0), Major, Minor,
121 Bound, VersionTuple(Major, Minor, 0, Bound));
122 OutStreamer->setUseAssemblerInfoForParsing(FlagToRestore);
123}
124
125void SPIRVAsmPrinter::emitFunctionHeader() {
126 if (ModuleSectionsEmitted == false) {
127 outputModuleSections();
128 ModuleSectionsEmitted = true;
129 }
130 // Get the subtarget from the current MachineFunction.
131 ST = &MF->getSubtarget<SPIRVSubtarget>();
132 TII = ST->getInstrInfo();
133 const Function &F = MF->getFunction();
134
135 if (isVerbose()) {
136 OutStreamer->getCommentOS()
137 << "-- Begin function "
138 << GlobalValue::dropLLVMManglingEscape(F.getName()) << '\n';
139 }
140
141 auto Section = getObjFileLowering().SectionForGlobal(&F, TM);
142 MF->setSection(Section);
143}
144
145void SPIRVAsmPrinter::outputOpFunctionEnd() {
146 MCInst FunctionEndInst;
147 FunctionEndInst.setOpcode(SPIRV::OpFunctionEnd);
148 outputMCInst(FunctionEndInst);
149}
150
151// Emit OpFunctionEnd at the end of MF and clear BBNumToRegMap.
152void SPIRVAsmPrinter::emitFunctionBodyEnd() {
153 outputOpFunctionEnd();
154 MAI->BBNumToRegMap.clear();
155}
156
157void SPIRVAsmPrinter::emitOpLabel(const MachineBasicBlock &MBB) {
158 MCInst LabelInst;
159 LabelInst.setOpcode(SPIRV::OpLabel);
160 LabelInst.addOperand(MCOperand::createReg(MAI->getOrCreateMBBRegister(MBB)));
161 outputMCInst(LabelInst);
162 ++NLabels;
163}
164
165void SPIRVAsmPrinter::emitBasicBlockStart(const MachineBasicBlock &MBB) {
166 assert(!MBB.empty() && "MBB is empty!");
167
168 // If it's the first MBB in MF, it has OpFunction and OpFunctionParameter, so
169 // OpLabel should be output after them.
170 if (MBB.getNumber() == MF->front().getNumber()) {
171 for (const MachineInstr &MI : MBB)
172 if (MI.getOpcode() == SPIRV::OpFunction)
173 return;
174 // TODO: this case should be checked by the verifier.
175 report_fatal_error("OpFunction is expected in the front MBB of MF");
176 }
177 emitOpLabel(MBB);
178}
179
180void SPIRVAsmPrinter::printOperand(const MachineInstr *MI, int OpNum,
181 raw_ostream &O) {
182 const MachineOperand &MO = MI->getOperand(OpNum);
183
184 switch (MO.getType()) {
187 break;
188
190 O << MO.getImm();
191 break;
192
194 O << MO.getFPImm();
195 break;
196
198 O << *MO.getMBB()->getSymbol();
199 break;
200
202 O << *getSymbol(MO.getGlobal());
203 break;
204
206 MCSymbol *BA = GetBlockAddressSymbol(MO.getBlockAddress());
207 O << BA->getName();
208 break;
209 }
210
212 O << *GetExternalSymbolSymbol(MO.getSymbolName());
213 break;
214
217 default:
218 llvm_unreachable("<unknown operand type>");
219 }
220}
221
222bool SPIRVAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
223 const char *ExtraCode, raw_ostream &O) {
224 if (ExtraCode && ExtraCode[0])
225 return true; // Invalid instruction - SPIR-V does not have special modifiers
226
227 printOperand(MI, OpNo, O);
228 return false;
229}
230
232 const SPIRVInstrInfo *TII) {
233 return TII->isHeaderInstr(*MI) || MI->getOpcode() == SPIRV::OpFunction ||
234 MI->getOpcode() == SPIRV::OpFunctionParameter;
235}
236
237void SPIRVAsmPrinter::outputMCInst(MCInst &Inst) {
238 OutStreamer->emitInstruction(Inst, *OutContext.getSubtargetInfo());
239}
240
241void SPIRVAsmPrinter::outputInstruction(const MachineInstr *MI) {
242 SPIRVMCInstLower MCInstLowering;
243 MCInst TmpInst;
244 MCInstLowering.lower(MI, TmpInst, MAI);
245 outputMCInst(TmpInst);
246}
247
248void SPIRVAsmPrinter::emitInstruction(const MachineInstr *MI) {
249 SPIRV_MC::verifyInstructionPredicates(MI->getOpcode(),
250 getSubtargetInfo().getFeatureBits());
251
252 if (!MAI->getSkipEmission(MI))
253 outputInstruction(MI);
254
255 // Output OpLabel after OpFunction and OpFunctionParameter in the first MBB.
256 const MachineInstr *NextMI = MI->getNextNode();
257 if (!MAI->hasMBBRegister(*MI->getParent()) && isFuncOrHeaderInstr(MI, TII) &&
258 (!NextMI || !isFuncOrHeaderInstr(NextMI, TII))) {
259 assert(MI->getParent()->getNumber() == MF->front().getNumber() &&
260 "OpFunction is not in the front MBB of MF");
261 emitOpLabel(*MI->getParent());
262 }
263}
264
265void SPIRVAsmPrinter::outputModuleSection(SPIRV::ModuleSectionType MSType) {
266 for (MachineInstr *MI : MAI->getMSInstrs(MSType))
267 outputInstruction(MI);
268}
269
270void SPIRVAsmPrinter::outputDebugSourceAndStrings(const Module &M) {
271 // Output OpSourceExtensions.
272 for (auto &Str : MAI->SrcExt) {
273 MCInst Inst;
274 Inst.setOpcode(SPIRV::OpSourceExtension);
275 addStringImm(Str.first(), Inst);
276 outputMCInst(Inst);
277 }
278 // Output OpSource.
279 MCInst Inst;
280 Inst.setOpcode(SPIRV::OpSource);
281 Inst.addOperand(MCOperand::createImm(static_cast<unsigned>(MAI->SrcLang)));
282 Inst.addOperand(
283 MCOperand::createImm(static_cast<unsigned>(MAI->SrcLangVersion)));
284 outputMCInst(Inst);
285}
286
287void SPIRVAsmPrinter::outputOpExtInstImports(const Module &M) {
288 for (auto &CU : MAI->ExtInstSetMap) {
289 unsigned Set = CU.first;
290 Register Reg = CU.second;
291 MCInst Inst;
292 Inst.setOpcode(SPIRV::OpExtInstImport);
295 static_cast<SPIRV::InstructionSet::InstructionSet>(Set)),
296 Inst);
297 outputMCInst(Inst);
298 }
299}
300
301void SPIRVAsmPrinter::outputOpMemoryModel() {
302 MCInst Inst;
303 Inst.setOpcode(SPIRV::OpMemoryModel);
304 Inst.addOperand(MCOperand::createImm(static_cast<unsigned>(MAI->Addr)));
305 Inst.addOperand(MCOperand::createImm(static_cast<unsigned>(MAI->Mem)));
306 outputMCInst(Inst);
307}
308
309// Before the OpEntryPoints' output, we need to add the entry point's
310// interfaces. The interface is a list of IDs of global OpVariable instructions.
311// These declare the set of global variables from a module that form
312// the interface of this entry point.
313void SPIRVAsmPrinter::outputEntryPoints() {
314 // Find all OpVariable IDs with required StorageClass.
315 DenseSet<Register> InterfaceIDs;
316 for (MachineInstr *MI : MAI->GlobalVarList) {
317 assert(MI->getOpcode() == SPIRV::OpVariable);
318 auto SC = static_cast<SPIRV::StorageClass::StorageClass>(
319 MI->getOperand(2).getImm());
320 // Before version 1.4, the interface's storage classes are limited to
321 // the Input and Output storage classes. Starting with version 1.4,
322 // the interface's storage classes are all storage classes used in
323 // declaring all global variables referenced by the entry point call tree.
324 if (ST->getSPIRVVersion() >= 14 || SC == SPIRV::StorageClass::Input ||
325 SC == SPIRV::StorageClass::Output) {
326 MachineFunction *MF = MI->getMF();
327 Register Reg = MAI->getRegisterAlias(MF, MI->getOperand(0).getReg());
328 InterfaceIDs.insert(Reg);
329 }
330 }
331
332 // Output OpEntryPoints adding interface args to all of them.
333 for (MachineInstr *MI : MAI->getMSInstrs(SPIRV::MB_EntryPoints)) {
334 SPIRVMCInstLower MCInstLowering;
335 MCInst TmpInst;
336 MCInstLowering.lower(MI, TmpInst, MAI);
337 for (Register Reg : InterfaceIDs) {
338 assert(Reg.isValid());
339 TmpInst.addOperand(MCOperand::createReg(Reg));
340 }
341 outputMCInst(TmpInst);
342 }
343}
344
345// Create global OpCapability instructions for the required capabilities.
346void SPIRVAsmPrinter::outputGlobalRequirements() {
347 // Abort here if not all requirements can be satisfied.
348 MAI->Reqs.checkSatisfiable(*ST);
349
350 for (const auto &Cap : MAI->Reqs.getMinimalCapabilities()) {
351 MCInst Inst;
352 Inst.setOpcode(SPIRV::OpCapability);
354 outputMCInst(Inst);
355 }
356
357 // Generate the final OpExtensions with strings instead of enums.
358 for (const auto &Ext : MAI->Reqs.getExtensions()) {
359 MCInst Inst;
360 Inst.setOpcode(SPIRV::OpExtension);
362 SPIRV::OperandCategory::ExtensionOperand, Ext),
363 Inst);
364 outputMCInst(Inst);
365 }
366 // TODO add a pseudo instr for version number.
367}
368
369void SPIRVAsmPrinter::outputExtFuncDecls() {
370 // Insert OpFunctionEnd after each declaration.
372 I = MAI->getMSInstrs(SPIRV::MB_ExtFuncDecls).begin(),
373 E = MAI->getMSInstrs(SPIRV::MB_ExtFuncDecls).end();
374 for (; I != E; ++I) {
375 outputInstruction(*I);
376 if ((I + 1) == E || (*(I + 1))->getOpcode() == SPIRV::OpFunction)
377 outputOpFunctionEnd();
378 }
379}
380
381// Encode LLVM type by SPIR-V execution mode VecTypeHint.
382static unsigned encodeVecTypeHint(Type *Ty) {
383 if (Ty->isHalfTy())
384 return 4;
385 if (Ty->isFloatTy())
386 return 5;
387 if (Ty->isDoubleTy())
388 return 6;
389 if (IntegerType *IntTy = dyn_cast<IntegerType>(Ty)) {
390 switch (IntTy->getIntegerBitWidth()) {
391 case 8:
392 return 0;
393 case 16:
394 return 1;
395 case 32:
396 return 2;
397 case 64:
398 return 3;
399 default:
400 llvm_unreachable("invalid integer type");
401 }
402 }
403 if (FixedVectorType *VecTy = dyn_cast<FixedVectorType>(Ty)) {
404 Type *EleTy = VecTy->getElementType();
405 unsigned Size = VecTy->getNumElements();
406 return Size << 16 | encodeVecTypeHint(EleTy);
407 }
408 llvm_unreachable("invalid type");
409}
410
411static void addOpsFromMDNode(MDNode *MDN, MCInst &Inst,
413 for (const MDOperand &MDOp : MDN->operands()) {
414 if (auto *CMeta = dyn_cast<ConstantAsMetadata>(MDOp)) {
415 Constant *C = CMeta->getValue();
416 if (ConstantInt *Const = dyn_cast<ConstantInt>(C)) {
417 Inst.addOperand(MCOperand::createImm(Const->getZExtValue()));
418 } else if (auto *CE = dyn_cast<Function>(C)) {
419 Register FuncReg = MAI->getFuncReg(CE);
420 assert(FuncReg.isValid());
421 Inst.addOperand(MCOperand::createReg(FuncReg));
422 }
423 }
424 }
425}
426
427void SPIRVAsmPrinter::outputExecutionModeFromMDNode(
428 Register Reg, MDNode *Node, SPIRV::ExecutionMode::ExecutionMode EM) {
429 MCInst Inst;
430 Inst.setOpcode(SPIRV::OpExecutionMode);
432 Inst.addOperand(MCOperand::createImm(static_cast<unsigned>(EM)));
433 addOpsFromMDNode(Node, Inst, MAI);
434 outputMCInst(Inst);
435}
436
437void SPIRVAsmPrinter::outputExecutionModeFromNumthreadsAttribute(
438 const Register &Reg, const Attribute &Attr,
439 SPIRV::ExecutionMode::ExecutionMode EM) {
440 assert(Attr.isValid() && "Function called with an invalid attribute.");
441
442 MCInst Inst;
443 Inst.setOpcode(SPIRV::OpExecutionMode);
445 Inst.addOperand(MCOperand::createImm(static_cast<unsigned>(EM)));
446
447 SmallVector<StringRef> NumThreads;
448 Attr.getValueAsString().split(NumThreads, ',');
449 assert(NumThreads.size() == 3 && "invalid numthreads");
450 for (uint32_t i = 0; i < 3; ++i) {
451 uint32_t V;
452 [[maybe_unused]] bool Result = NumThreads[i].getAsInteger(10, V);
453 assert(!Result && "Failed to parse numthreads");
455 }
456
457 outputMCInst(Inst);
458}
459
460void SPIRVAsmPrinter::outputExecutionMode(const Module &M) {
461 NamedMDNode *Node = M.getNamedMetadata("spirv.ExecutionMode");
462 if (Node) {
463 for (unsigned i = 0; i < Node->getNumOperands(); i++) {
464 MCInst Inst;
465 Inst.setOpcode(SPIRV::OpExecutionMode);
466 addOpsFromMDNode(cast<MDNode>(Node->getOperand(i)), Inst, MAI);
467 outputMCInst(Inst);
468 }
469 }
470 for (auto FI = M.begin(), E = M.end(); FI != E; ++FI) {
471 const Function &F = *FI;
472 // Only operands of OpEntryPoint instructions are allowed to be
473 // <Entry Point> operands of OpExecutionMode
474 if (F.isDeclaration() || !isEntryPoint(F))
475 continue;
476 Register FReg = MAI->getFuncReg(&F);
477 assert(FReg.isValid());
478 if (MDNode *Node = F.getMetadata("reqd_work_group_size"))
479 outputExecutionModeFromMDNode(FReg, Node,
480 SPIRV::ExecutionMode::LocalSize);
481 if (Attribute Attr = F.getFnAttribute("hlsl.numthreads"); Attr.isValid())
482 outputExecutionModeFromNumthreadsAttribute(
483 FReg, Attr, SPIRV::ExecutionMode::LocalSize);
484 if (MDNode *Node = F.getMetadata("work_group_size_hint"))
485 outputExecutionModeFromMDNode(FReg, Node,
486 SPIRV::ExecutionMode::LocalSizeHint);
487 if (MDNode *Node = F.getMetadata("intel_reqd_sub_group_size"))
488 outputExecutionModeFromMDNode(FReg, Node,
489 SPIRV::ExecutionMode::SubgroupSize);
490 if (MDNode *Node = F.getMetadata("vec_type_hint")) {
491 MCInst Inst;
492 Inst.setOpcode(SPIRV::OpExecutionMode);
494 unsigned EM = static_cast<unsigned>(SPIRV::ExecutionMode::VecTypeHint);
496 unsigned TypeCode = encodeVecTypeHint(getMDOperandAsType(Node, 0));
497 Inst.addOperand(MCOperand::createImm(TypeCode));
498 outputMCInst(Inst);
499 }
500 if (ST->isOpenCLEnv() && !M.getNamedMetadata("spirv.ExecutionMode") &&
501 !M.getNamedMetadata("opencl.enable.FP_CONTRACT")) {
502 MCInst Inst;
503 Inst.setOpcode(SPIRV::OpExecutionMode);
505 unsigned EM = static_cast<unsigned>(SPIRV::ExecutionMode::ContractionOff);
507 outputMCInst(Inst);
508 }
509 }
510}
511
512void SPIRVAsmPrinter::outputAnnotations(const Module &M) {
513 outputModuleSection(SPIRV::MB_Annotations);
514 // Process llvm.global.annotations special global variable.
515 for (auto F = M.global_begin(), E = M.global_end(); F != E; ++F) {
516 if ((*F).getName() != "llvm.global.annotations")
517 continue;
518 const GlobalVariable *V = &(*F);
519 const ConstantArray *CA = cast<ConstantArray>(V->getOperand(0));
520 for (Value *Op : CA->operands()) {
521 ConstantStruct *CS = cast<ConstantStruct>(Op);
522 // The first field of the struct contains a pointer to
523 // the annotated variable.
524 Value *AnnotatedVar = CS->getOperand(0)->stripPointerCasts();
525 if (!isa<Function>(AnnotatedVar))
526 report_fatal_error("Unsupported value in llvm.global.annotations");
527 Function *Func = cast<Function>(AnnotatedVar);
528 Register Reg = MAI->getFuncReg(Func);
529 if (!Reg.isValid()) {
530 std::string DiagMsg;
531 raw_string_ostream OS(DiagMsg);
532 AnnotatedVar->print(OS);
533 DiagMsg = "Unknown function in llvm.global.annotations: " + DiagMsg;
534 report_fatal_error(DiagMsg.c_str());
535 }
536
537 // The second field contains a pointer to a global annotation string.
538 GlobalVariable *GV =
539 cast<GlobalVariable>(CS->getOperand(1)->stripPointerCasts());
540
541 StringRef AnnotationString;
542 getConstantStringInfo(GV, AnnotationString);
543 MCInst Inst;
544 Inst.setOpcode(SPIRV::OpDecorate);
546 unsigned Dec = static_cast<unsigned>(SPIRV::Decoration::UserSemantic);
548 addStringImm(AnnotationString, Inst);
549 outputMCInst(Inst);
550 }
551 }
552}
553
554void SPIRVAsmPrinter::outputModuleSections() {
555 const Module *M = MMI->getModule();
556 // Get the global subtarget to output module-level info.
557 ST = static_cast<const SPIRVTargetMachine &>(TM).getSubtargetImpl();
558 TII = ST->getInstrInfo();
560 assert(ST && TII && MAI && M && "Module analysis is required");
561 // Output instructions according to the Logical Layout of a Module:
562 // 1,2. All OpCapability instructions, then optional OpExtension instructions.
563 outputGlobalRequirements();
564 // 3. Optional OpExtInstImport instructions.
565 outputOpExtInstImports(*M);
566 // 4. The single required OpMemoryModel instruction.
567 outputOpMemoryModel();
568 // 5. All entry point declarations, using OpEntryPoint.
569 outputEntryPoints();
570 // 6. Execution-mode declarations, using OpExecutionMode or OpExecutionModeId.
571 outputExecutionMode(*M);
572 // 7a. Debug: all OpString, OpSourceExtension, OpSource, and
573 // OpSourceContinued, without forward references.
574 outputDebugSourceAndStrings(*M);
575 // 7b. Debug: all OpName and all OpMemberName.
576 outputModuleSection(SPIRV::MB_DebugNames);
577 // 7c. Debug: all OpModuleProcessed instructions.
578 outputModuleSection(SPIRV::MB_DebugModuleProcessed);
579 // 8. All annotation instructions (all decorations).
580 outputAnnotations(*M);
581 // 9. All type declarations (OpTypeXXX instructions), all constant
582 // instructions, and all global variable declarations. This section is
583 // the first section to allow use of: OpLine and OpNoLine debug information;
584 // non-semantic instructions with OpExtInst.
585 outputModuleSection(SPIRV::MB_TypeConstVars);
586 // 10. All function declarations (functions without a body).
587 outputExtFuncDecls();
588 // 11. All function definitions (functions with a body).
589 // This is done in regular function output.
590}
591
592bool SPIRVAsmPrinter::doInitialization(Module &M) {
593 ModuleSectionsEmitted = false;
594 // We need to call the parent's one explicitly.
596}
597
598// Force static initialization.
603}
MachineBasicBlock & MBB
#define LLVM_EXTERNAL_VISIBILITY
Definition: Compiler.h:135
This file defines the DenseMap class.
uint64_t Size
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
const char LLVMTargetMachineRef TM
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static void addOpsFromMDNode(MDNode *MDN, MCInst &Inst, SPIRV::ModuleAnalysisInfo *MAI)
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeSPIRVAsmPrinter()
static bool isFuncOrHeaderInstr(const MachineInstr *MI, const SPIRVInstrInfo *TII)
static unsigned encodeVecTypeHint(Type *Ty)
raw_pwrite_stream & OS
static bool printOperand(raw_ostream &OS, const SelectionDAG *G, const SDValue Value)
static std::optional< unsigned > getOpcode(ArrayRef< VPValue * > Values)
Returns the opcode of Values or ~0 if they do not all agree.
Definition: VPlanSLP.cpp:191
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:84
virtual void emitInstruction(const MachineInstr *)
Targets should implement this to emit instructions.
Definition: AsmPrinter.h:567
virtual void emitGlobalVariable(const GlobalVariable *GV)
Emit the specified global variable to the .s file.
Definition: AsmPrinter.cpp:722
virtual void emitBasicBlockEnd(const MachineBasicBlock &MBB)
Targets can override this to emit stuff at the end of a basic block.
const MCAsmInfo * MAI
Target Asm Printer information.
Definition: AsmPrinter.h:90
virtual void emitFunctionBodyStart()
Targets can override this to emit stuff before the first basic block in the function.
Definition: AsmPrinter.h:551
virtual void emitEndOfAsmFile(Module &)
This virtual method can be overridden by targets that want to emit something at the end of their file...
Definition: AsmPrinter.h:547
bool doInitialization(Module &M) override
Set up the AsmPrinter when we are working on a new module.
Definition: AsmPrinter.cpp:449
void getAnalysisUsage(AnalysisUsage &AU) const override
Record analysis usage.
Definition: AsmPrinter.cpp:440
virtual void emitBasicBlockStart(const MachineBasicBlock &MBB)
Targets can override this to emit stuff at the start of a basic block.
virtual void emitFunctionBodyEnd()
Targets can override this to emit stuff after the last basic block in the function.
Definition: AsmPrinter.h:555
virtual void emitFunctionEntryLabel()
EmitFunctionEntryLabel - Emit the label that is the entrypoint for the function.
virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, const char *ExtraCode, raw_ostream &OS)
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant.
StringRef getValueAsString() const
Return the attribute's value as a string.
Definition: Attributes.cpp:349
bool isValid() const
Return true if the attribute is any kind of attribute.
Definition: Attributes.h:193
ConstantArray - Constant Array Declarations.
Definition: Constants.h:423
This is the shared class of boolean and integer constants.
Definition: Constants.h:80
This is an important base class in LLVM.
Definition: Constant.h:41
This class represents an Operation in the Expression.
Implements a dense probed hash-table based set.
Definition: DenseSet.h:271
Class to represent fixed width SIMD vectors.
Definition: DerivedTypes.h:539
static StringRef dropLLVMManglingEscape(StringRef Name)
If the given string begins with the GlobalValue name mangling escape character '\1',...
Definition: GlobalValue.h:567
Class to represent integer types.
Definition: DerivedTypes.h:40
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
void addOperand(const MCOperand Op)
Definition: MCInst.h:210
void setOpcode(unsigned Op)
Definition: MCInst.h:197
static MCOperand createReg(unsigned Reg)
Definition: MCInst.h:134
static MCOperand createImm(int64_t Val)
Definition: MCInst.h:141
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:40
StringRef getName() const
getName - Get the symbol name.
Definition: MCSymbol.h:205
Metadata node.
Definition: Metadata.h:1067
ArrayRef< MDOperand > operands() const
Definition: Metadata.h:1426
Tracking metadata reference owned by Metadata.
Definition: Metadata.h:889
MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
Representation of each machine instruction.
Definition: MachineInstr.h:69
MachineOperand class - Representation of each machine instruction operand.
const GlobalValue * getGlobal() const
int64_t getImm() const
MachineBasicBlock * getMBB() const
const BlockAddress * getBlockAddress() const
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
const char * getSymbolName() const
Register getReg() const
getReg - Returns the register number.
const ConstantFP * getFPImm() const
@ MO_Immediate
Immediate operand.
@ MO_ConstantPoolIndex
Address of indexed Constant in Constant Pool.
@ MO_GlobalAddress
Address of a global value.
@ MO_BlockAddress
Address of a basic block.
@ MO_MachineBasicBlock
MachineBasicBlock reference.
@ MO_Register
Register operand.
@ MO_ExternalSymbol
Name of external global symbol.
@ MO_JumpTableIndex
Address of indexed Jump Table for switch.
@ MO_FPImmediate
Floating-point immediate operand.
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
A tuple of MDNodes.
Definition: Metadata.h:1729
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
Definition: Pass.cpp:81
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
constexpr bool isValid() const
Definition: Register.h:116
static const char * getRegisterName(MCRegister Reg)
void lower(const MachineInstr *MI, MCInst &OutMI, SPIRV::ModuleAnalysisInfo *MAI) const
size_t size() const
Definition: SmallVector.h:91
typename SuperClass::iterator iterator
Definition: SmallVector.h:590
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition: StringRef.h:696
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:76
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
Definition: Type.h:154
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
Definition: Type.h:143
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
Definition: Type.h:157
op_range operands()
Definition: User.h:242
Value * getOperand(unsigned i) const
Definition: User.h:169
LLVM Value Representation.
Definition: Value.h:74
void print(raw_ostream &O, bool IsForDebug=false) const
Implement operator<< on Value.
Definition: AsmWriter.cpp:4996
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
Definition: Value.cpp:693
Represents a version number in the form major[.minor[.subminor[.build]]].
Definition: VersionTuple.h:29
std::pair< iterator, bool > insert(const ValueT &V)
Definition: DenseSet.h:206
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:660
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
PlatformType
Definition: MachO.h:500
@ SC
CHAIN = SC CHAIN, Imm128 - System call.
Reg
All possible values of the reg field in the ModR/M byte.
NodeAddr< FuncNode * > Func
Definition: RDFGraph.h:393
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Target & getTheSPIRV32Target()
bool getConstantStringInfo(const Value *V, StringRef &Str, bool TrimAtNul=true)
This function computes the length of a null-terminated C string pointed to by V.
std::string getExtInstSetName(SPIRV::InstructionSet::InstructionSet Set)
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:156
std::string getSymbolicOperandMnemonic(SPIRV::OperandCategory::OperandCategory Category, int32_t Value)
bool isEntryPoint(const Function &F)
Definition: SPIRVUtils.cpp:358
Target & getTheSPIRV64Target()
Target & getTheSPIRVLogicalTarget()
Type * getMDOperandAsType(const MDNode *N, unsigned I)
Definition: SPIRVUtils.cpp:253
void addStringImm(const StringRef &Str, MCInst &Inst)
Definition: SPIRVUtils.cpp:51
RegisterAsmPrinter - Helper template for registering a target specific assembly printer,...
static struct SPIRV::ModuleAnalysisInfo MAI
Register getFuncReg(const Function *F)