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 VersionTuple SPIRVVersion = ST->getSPIRVVersion();
112 uint32_t Major = SPIRVVersion.getMajor();
113 uint32_t Minor = SPIRVVersion.getMinor().value_or(0);
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 if (MCAssembler *Asm = OutStreamer->getAssemblerPtr())
118 Asm->setBuildVersion(static_cast<MachO::PlatformType>(0), Major, Minor,
119 Bound, VersionTuple(Major, Minor, 0, Bound));
120}
121
122void SPIRVAsmPrinter::emitFunctionHeader() {
123 if (ModuleSectionsEmitted == false) {
124 outputModuleSections();
125 ModuleSectionsEmitted = true;
126 }
127 // Get the subtarget from the current MachineFunction.
128 ST = &MF->getSubtarget<SPIRVSubtarget>();
129 TII = ST->getInstrInfo();
130 const Function &F = MF->getFunction();
131
132 if (isVerbose()) {
133 OutStreamer->getCommentOS()
134 << "-- Begin function "
135 << GlobalValue::dropLLVMManglingEscape(F.getName()) << '\n';
136 }
137
138 auto Section = getObjFileLowering().SectionForGlobal(&F, TM);
139 MF->setSection(Section);
140}
141
142void SPIRVAsmPrinter::outputOpFunctionEnd() {
143 MCInst FunctionEndInst;
144 FunctionEndInst.setOpcode(SPIRV::OpFunctionEnd);
145 outputMCInst(FunctionEndInst);
146}
147
148// Emit OpFunctionEnd at the end of MF and clear BBNumToRegMap.
149void SPIRVAsmPrinter::emitFunctionBodyEnd() {
150 outputOpFunctionEnd();
151 MAI->BBNumToRegMap.clear();
152}
153
154void SPIRVAsmPrinter::emitOpLabel(const MachineBasicBlock &MBB) {
155 MCInst LabelInst;
156 LabelInst.setOpcode(SPIRV::OpLabel);
157 LabelInst.addOperand(MCOperand::createReg(MAI->getOrCreateMBBRegister(MBB)));
158 outputMCInst(LabelInst);
159 ++NLabels;
160}
161
162void SPIRVAsmPrinter::emitBasicBlockStart(const MachineBasicBlock &MBB) {
163 assert(!MBB.empty() && "MBB is empty!");
164
165 // If it's the first MBB in MF, it has OpFunction and OpFunctionParameter, so
166 // OpLabel should be output after them.
167 if (MBB.getNumber() == MF->front().getNumber()) {
168 for (const MachineInstr &MI : MBB)
169 if (MI.getOpcode() == SPIRV::OpFunction)
170 return;
171 // TODO: this case should be checked by the verifier.
172 report_fatal_error("OpFunction is expected in the front MBB of MF");
173 }
174 emitOpLabel(MBB);
175}
176
177void SPIRVAsmPrinter::printOperand(const MachineInstr *MI, int OpNum,
178 raw_ostream &O) {
179 const MachineOperand &MO = MI->getOperand(OpNum);
180
181 switch (MO.getType()) {
184 break;
185
187 O << MO.getImm();
188 break;
189
191 O << MO.getFPImm();
192 break;
193
195 O << *MO.getMBB()->getSymbol();
196 break;
197
199 O << *getSymbol(MO.getGlobal());
200 break;
201
203 MCSymbol *BA = GetBlockAddressSymbol(MO.getBlockAddress());
204 O << BA->getName();
205 break;
206 }
207
209 O << *GetExternalSymbolSymbol(MO.getSymbolName());
210 break;
211
214 default:
215 llvm_unreachable("<unknown operand type>");
216 }
217}
218
219bool SPIRVAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
220 const char *ExtraCode, raw_ostream &O) {
221 if (ExtraCode && ExtraCode[0])
222 return true; // Invalid instruction - SPIR-V does not have special modifiers
223
224 printOperand(MI, OpNo, O);
225 return false;
226}
227
229 const SPIRVInstrInfo *TII) {
230 return TII->isHeaderInstr(*MI) || MI->getOpcode() == SPIRV::OpFunction ||
231 MI->getOpcode() == SPIRV::OpFunctionParameter;
232}
233
234void SPIRVAsmPrinter::outputMCInst(MCInst &Inst) {
235 OutStreamer->emitInstruction(Inst, *OutContext.getSubtargetInfo());
236}
237
238void SPIRVAsmPrinter::outputInstruction(const MachineInstr *MI) {
239 SPIRVMCInstLower MCInstLowering;
240 MCInst TmpInst;
241 MCInstLowering.lower(MI, TmpInst, MAI);
242 outputMCInst(TmpInst);
243}
244
245void SPIRVAsmPrinter::emitInstruction(const MachineInstr *MI) {
246 SPIRV_MC::verifyInstructionPredicates(MI->getOpcode(),
247 getSubtargetInfo().getFeatureBits());
248
249 if (!MAI->getSkipEmission(MI))
250 outputInstruction(MI);
251
252 // Output OpLabel after OpFunction and OpFunctionParameter in the first MBB.
253 const MachineInstr *NextMI = MI->getNextNode();
254 if (!MAI->hasMBBRegister(*MI->getParent()) && isFuncOrHeaderInstr(MI, TII) &&
255 (!NextMI || !isFuncOrHeaderInstr(NextMI, TII))) {
256 assert(MI->getParent()->getNumber() == MF->front().getNumber() &&
257 "OpFunction is not in the front MBB of MF");
258 emitOpLabel(*MI->getParent());
259 }
260}
261
262void SPIRVAsmPrinter::outputModuleSection(SPIRV::ModuleSectionType MSType) {
263 for (MachineInstr *MI : MAI->getMSInstrs(MSType))
264 outputInstruction(MI);
265}
266
267void SPIRVAsmPrinter::outputDebugSourceAndStrings(const Module &M) {
268 // Output OpSourceExtensions.
269 for (auto &Str : MAI->SrcExt) {
270 MCInst Inst;
271 Inst.setOpcode(SPIRV::OpSourceExtension);
272 addStringImm(Str.first(), Inst);
273 outputMCInst(Inst);
274 }
275 // Output OpSource.
276 MCInst Inst;
277 Inst.setOpcode(SPIRV::OpSource);
278 Inst.addOperand(MCOperand::createImm(static_cast<unsigned>(MAI->SrcLang)));
279 Inst.addOperand(
280 MCOperand::createImm(static_cast<unsigned>(MAI->SrcLangVersion)));
281 outputMCInst(Inst);
282}
283
284void SPIRVAsmPrinter::outputOpExtInstImports(const Module &M) {
285 for (auto &CU : MAI->ExtInstSetMap) {
286 unsigned Set = CU.first;
287 Register Reg = CU.second;
288 MCInst Inst;
289 Inst.setOpcode(SPIRV::OpExtInstImport);
292 static_cast<SPIRV::InstructionSet::InstructionSet>(Set)),
293 Inst);
294 outputMCInst(Inst);
295 }
296}
297
298void SPIRVAsmPrinter::outputOpMemoryModel() {
299 MCInst Inst;
300 Inst.setOpcode(SPIRV::OpMemoryModel);
301 Inst.addOperand(MCOperand::createImm(static_cast<unsigned>(MAI->Addr)));
302 Inst.addOperand(MCOperand::createImm(static_cast<unsigned>(MAI->Mem)));
303 outputMCInst(Inst);
304}
305
306// Before the OpEntryPoints' output, we need to add the entry point's
307// interfaces. The interface is a list of IDs of global OpVariable instructions.
308// These declare the set of global variables from a module that form
309// the interface of this entry point.
310void SPIRVAsmPrinter::outputEntryPoints() {
311 // Find all OpVariable IDs with required StorageClass.
312 DenseSet<Register> InterfaceIDs;
313 for (MachineInstr *MI : MAI->GlobalVarList) {
314 assert(MI->getOpcode() == SPIRV::OpVariable);
315 auto SC = static_cast<SPIRV::StorageClass::StorageClass>(
316 MI->getOperand(2).getImm());
317 // Before version 1.4, the interface's storage classes are limited to
318 // the Input and Output storage classes. Starting with version 1.4,
319 // the interface's storage classes are all storage classes used in
320 // declaring all global variables referenced by the entry point call tree.
321 if (ST->isAtLeastSPIRVVer(VersionTuple(1, 4)) ||
322 SC == SPIRV::StorageClass::Input || SC == SPIRV::StorageClass::Output) {
323 MachineFunction *MF = MI->getMF();
324 Register Reg = MAI->getRegisterAlias(MF, MI->getOperand(0).getReg());
325 InterfaceIDs.insert(Reg);
326 }
327 }
328
329 // Output OpEntryPoints adding interface args to all of them.
330 for (MachineInstr *MI : MAI->getMSInstrs(SPIRV::MB_EntryPoints)) {
331 SPIRVMCInstLower MCInstLowering;
332 MCInst TmpInst;
333 MCInstLowering.lower(MI, TmpInst, MAI);
334 for (Register Reg : InterfaceIDs) {
335 assert(Reg.isValid());
336 TmpInst.addOperand(MCOperand::createReg(Reg));
337 }
338 outputMCInst(TmpInst);
339 }
340}
341
342// Create global OpCapability instructions for the required capabilities.
343void SPIRVAsmPrinter::outputGlobalRequirements() {
344 // Abort here if not all requirements can be satisfied.
345 MAI->Reqs.checkSatisfiable(*ST);
346
347 for (const auto &Cap : MAI->Reqs.getMinimalCapabilities()) {
348 MCInst Inst;
349 Inst.setOpcode(SPIRV::OpCapability);
351 outputMCInst(Inst);
352 }
353
354 // Generate the final OpExtensions with strings instead of enums.
355 for (const auto &Ext : MAI->Reqs.getExtensions()) {
356 MCInst Inst;
357 Inst.setOpcode(SPIRV::OpExtension);
359 SPIRV::OperandCategory::ExtensionOperand, Ext),
360 Inst);
361 outputMCInst(Inst);
362 }
363 // TODO add a pseudo instr for version number.
364}
365
366void SPIRVAsmPrinter::outputExtFuncDecls() {
367 // Insert OpFunctionEnd after each declaration.
369 I = MAI->getMSInstrs(SPIRV::MB_ExtFuncDecls).begin(),
370 E = MAI->getMSInstrs(SPIRV::MB_ExtFuncDecls).end();
371 for (; I != E; ++I) {
372 outputInstruction(*I);
373 if ((I + 1) == E || (*(I + 1))->getOpcode() == SPIRV::OpFunction)
374 outputOpFunctionEnd();
375 }
376}
377
378// Encode LLVM type by SPIR-V execution mode VecTypeHint.
379static unsigned encodeVecTypeHint(Type *Ty) {
380 if (Ty->isHalfTy())
381 return 4;
382 if (Ty->isFloatTy())
383 return 5;
384 if (Ty->isDoubleTy())
385 return 6;
386 if (IntegerType *IntTy = dyn_cast<IntegerType>(Ty)) {
387 switch (IntTy->getIntegerBitWidth()) {
388 case 8:
389 return 0;
390 case 16:
391 return 1;
392 case 32:
393 return 2;
394 case 64:
395 return 3;
396 default:
397 llvm_unreachable("invalid integer type");
398 }
399 }
400 if (FixedVectorType *VecTy = dyn_cast<FixedVectorType>(Ty)) {
401 Type *EleTy = VecTy->getElementType();
402 unsigned Size = VecTy->getNumElements();
403 return Size << 16 | encodeVecTypeHint(EleTy);
404 }
405 llvm_unreachable("invalid type");
406}
407
408static void addOpsFromMDNode(MDNode *MDN, MCInst &Inst,
410 for (const MDOperand &MDOp : MDN->operands()) {
411 if (auto *CMeta = dyn_cast<ConstantAsMetadata>(MDOp)) {
412 Constant *C = CMeta->getValue();
413 if (ConstantInt *Const = dyn_cast<ConstantInt>(C)) {
414 Inst.addOperand(MCOperand::createImm(Const->getZExtValue()));
415 } else if (auto *CE = dyn_cast<Function>(C)) {
416 Register FuncReg = MAI->getFuncReg(CE);
417 assert(FuncReg.isValid());
418 Inst.addOperand(MCOperand::createReg(FuncReg));
419 }
420 }
421 }
422}
423
424void SPIRVAsmPrinter::outputExecutionModeFromMDNode(
425 Register Reg, MDNode *Node, SPIRV::ExecutionMode::ExecutionMode EM) {
426 MCInst Inst;
427 Inst.setOpcode(SPIRV::OpExecutionMode);
429 Inst.addOperand(MCOperand::createImm(static_cast<unsigned>(EM)));
430 addOpsFromMDNode(Node, Inst, MAI);
431 outputMCInst(Inst);
432}
433
434void SPIRVAsmPrinter::outputExecutionModeFromNumthreadsAttribute(
435 const Register &Reg, const Attribute &Attr,
436 SPIRV::ExecutionMode::ExecutionMode EM) {
437 assert(Attr.isValid() && "Function called with an invalid attribute.");
438
439 MCInst Inst;
440 Inst.setOpcode(SPIRV::OpExecutionMode);
442 Inst.addOperand(MCOperand::createImm(static_cast<unsigned>(EM)));
443
444 SmallVector<StringRef> NumThreads;
445 Attr.getValueAsString().split(NumThreads, ',');
446 assert(NumThreads.size() == 3 && "invalid numthreads");
447 for (uint32_t i = 0; i < 3; ++i) {
448 uint32_t V;
449 [[maybe_unused]] bool Result = NumThreads[i].getAsInteger(10, V);
450 assert(!Result && "Failed to parse numthreads");
452 }
453
454 outputMCInst(Inst);
455}
456
457void SPIRVAsmPrinter::outputExecutionMode(const Module &M) {
458 NamedMDNode *Node = M.getNamedMetadata("spirv.ExecutionMode");
459 if (Node) {
460 for (unsigned i = 0; i < Node->getNumOperands(); i++) {
461 MCInst Inst;
462 Inst.setOpcode(SPIRV::OpExecutionMode);
463 addOpsFromMDNode(cast<MDNode>(Node->getOperand(i)), Inst, MAI);
464 outputMCInst(Inst);
465 }
466 }
467 for (auto FI = M.begin(), E = M.end(); FI != E; ++FI) {
468 const Function &F = *FI;
469 // Only operands of OpEntryPoint instructions are allowed to be
470 // <Entry Point> operands of OpExecutionMode
471 if (F.isDeclaration() || !isEntryPoint(F))
472 continue;
473 Register FReg = MAI->getFuncReg(&F);
474 assert(FReg.isValid());
475 if (MDNode *Node = F.getMetadata("reqd_work_group_size"))
476 outputExecutionModeFromMDNode(FReg, Node,
477 SPIRV::ExecutionMode::LocalSize);
478 if (Attribute Attr = F.getFnAttribute("hlsl.numthreads"); Attr.isValid())
479 outputExecutionModeFromNumthreadsAttribute(
480 FReg, Attr, SPIRV::ExecutionMode::LocalSize);
481 if (MDNode *Node = F.getMetadata("work_group_size_hint"))
482 outputExecutionModeFromMDNode(FReg, Node,
483 SPIRV::ExecutionMode::LocalSizeHint);
484 if (MDNode *Node = F.getMetadata("intel_reqd_sub_group_size"))
485 outputExecutionModeFromMDNode(FReg, Node,
486 SPIRV::ExecutionMode::SubgroupSize);
487 if (MDNode *Node = F.getMetadata("vec_type_hint")) {
488 MCInst Inst;
489 Inst.setOpcode(SPIRV::OpExecutionMode);
491 unsigned EM = static_cast<unsigned>(SPIRV::ExecutionMode::VecTypeHint);
493 unsigned TypeCode = encodeVecTypeHint(getMDOperandAsType(Node, 0));
494 Inst.addOperand(MCOperand::createImm(TypeCode));
495 outputMCInst(Inst);
496 }
497 if (ST->isOpenCLEnv() && !M.getNamedMetadata("spirv.ExecutionMode") &&
498 !M.getNamedMetadata("opencl.enable.FP_CONTRACT")) {
499 MCInst Inst;
500 Inst.setOpcode(SPIRV::OpExecutionMode);
502 unsigned EM = static_cast<unsigned>(SPIRV::ExecutionMode::ContractionOff);
504 outputMCInst(Inst);
505 }
506 }
507}
508
509void SPIRVAsmPrinter::outputAnnotations(const Module &M) {
510 outputModuleSection(SPIRV::MB_Annotations);
511 // Process llvm.global.annotations special global variable.
512 for (auto F = M.global_begin(), E = M.global_end(); F != E; ++F) {
513 if ((*F).getName() != "llvm.global.annotations")
514 continue;
515 const GlobalVariable *V = &(*F);
516 const ConstantArray *CA = cast<ConstantArray>(V->getOperand(0));
517 for (Value *Op : CA->operands()) {
518 ConstantStruct *CS = cast<ConstantStruct>(Op);
519 // The first field of the struct contains a pointer to
520 // the annotated variable.
521 Value *AnnotatedVar = CS->getOperand(0)->stripPointerCasts();
522 if (!isa<Function>(AnnotatedVar))
523 report_fatal_error("Unsupported value in llvm.global.annotations");
524 Function *Func = cast<Function>(AnnotatedVar);
525 Register Reg = MAI->getFuncReg(Func);
526 if (!Reg.isValid()) {
527 std::string DiagMsg;
528 raw_string_ostream OS(DiagMsg);
529 AnnotatedVar->print(OS);
530 DiagMsg = "Unknown function in llvm.global.annotations: " + DiagMsg;
531 report_fatal_error(DiagMsg.c_str());
532 }
533
534 // The second field contains a pointer to a global annotation string.
535 GlobalVariable *GV =
536 cast<GlobalVariable>(CS->getOperand(1)->stripPointerCasts());
537
538 StringRef AnnotationString;
539 getConstantStringInfo(GV, AnnotationString);
540 MCInst Inst;
541 Inst.setOpcode(SPIRV::OpDecorate);
543 unsigned Dec = static_cast<unsigned>(SPIRV::Decoration::UserSemantic);
545 addStringImm(AnnotationString, Inst);
546 outputMCInst(Inst);
547 }
548 }
549}
550
551void SPIRVAsmPrinter::outputModuleSections() {
552 const Module *M = MMI->getModule();
553 // Get the global subtarget to output module-level info.
554 ST = static_cast<const SPIRVTargetMachine &>(TM).getSubtargetImpl();
555 TII = ST->getInstrInfo();
557 assert(ST && TII && MAI && M && "Module analysis is required");
558 // Output instructions according to the Logical Layout of a Module:
559 // 1,2. All OpCapability instructions, then optional OpExtension instructions.
560 outputGlobalRequirements();
561 // 3. Optional OpExtInstImport instructions.
562 outputOpExtInstImports(*M);
563 // 4. The single required OpMemoryModel instruction.
564 outputOpMemoryModel();
565 // 5. All entry point declarations, using OpEntryPoint.
566 outputEntryPoints();
567 // 6. Execution-mode declarations, using OpExecutionMode or OpExecutionModeId.
568 outputExecutionMode(*M);
569 // 7a. Debug: all OpString, OpSourceExtension, OpSource, and
570 // OpSourceContinued, without forward references.
571 outputDebugSourceAndStrings(*M);
572 // 7b. Debug: all OpName and all OpMemberName.
573 outputModuleSection(SPIRV::MB_DebugNames);
574 // 7c. Debug: all OpModuleProcessed instructions.
575 outputModuleSection(SPIRV::MB_DebugModuleProcessed);
576 // 8. All annotation instructions (all decorations).
577 outputAnnotations(*M);
578 // 9. All type declarations (OpTypeXXX instructions), all constant
579 // instructions, and all global variable declarations. This section is
580 // the first section to allow use of: OpLine and OpNoLine debug information;
581 // non-semantic instructions with OpExtInst.
582 outputModuleSection(SPIRV::MB_TypeConstVars);
583 // 10. All function declarations (functions without a body).
584 outputExtFuncDecls();
585 // 11. All function definitions (functions with a body).
586 // This is done in regular function output.
587}
588
589bool SPIRVAsmPrinter::doInitialization(Module &M) {
590 ModuleSectionsEmitted = false;
591 // We need to call the parent's one explicitly.
593}
594
595// Force static initialization.
600}
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:726
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:450
void getAnalysisUsage(AnalysisUsage &AU) const override
Record analysis usage.
Definition: AsmPrinter.cpp:441
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:566
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:692
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
unsigned getMajor() const
Retrieve the major version number.
Definition: VersionTuple.h:71
std::optional< unsigned > getMinor() const
Retrieve the minor version number, if provided.
Definition: VersionTuple.h:74
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:386
Target & getTheSPIRV64Target()
Target & getTheSPIRVLogicalTarget()
Type * getMDOperandAsType(const MDNode *N, unsigned I)
Definition: SPIRVUtils.cpp:281
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)