LLVM 23.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 "SPIRVAuxDataHandler.h"
17#include "SPIRVInstrInfo.h"
18#include "SPIRVMCInstLower.h"
19#include "SPIRVModuleAnalysis.h"
21#include "SPIRVSubtarget.h"
22#include "SPIRVTargetMachine.h"
23#include "SPIRVUtils.h"
25#include "llvm/ADT/DenseMap.h"
32#include "llvm/MC/MCAsmInfo.h"
33#include "llvm/MC/MCAssembler.h"
34#include "llvm/MC/MCInst.h"
37#include "llvm/MC/MCStreamer.h"
38#include "llvm/MC/MCSymbol.h"
43
44using namespace llvm;
45
46#define DEBUG_TYPE "asm-printer"
47
48namespace {
49enum class SPIRVFPContractMode { On, Off, Fast };
50
51static cl::opt<SPIRVFPContractMode> SPIRVFPContract(
52 "spirv-fp-contract",
53 cl::desc("Override FP contraction policy for SPIR-V kernel entry points"),
55 clEnumValN(SPIRVFPContractMode::On, "on",
56 "Follow IR metadata (default)"),
57 clEnumValN(SPIRVFPContractMode::Off, "off",
58 "Force ContractionOff on all kernel entry points"),
59 clEnumValN(SPIRVFPContractMode::Fast, "fast",
60 "Suppress ContractionOff on all kernel entry points")),
61 cl::init(SPIRVFPContractMode::On));
62
63class SPIRVAsmPrinter : public AsmPrinter {
64 unsigned NLabels = 0;
66
67public:
68 explicit SPIRVAsmPrinter(TargetMachine &TM,
69 std::unique_ptr<MCStreamer> Streamer)
70 : AsmPrinter(TM, std::move(Streamer), ID), ModuleSectionsEmitted(false),
71 ST(nullptr), TII(nullptr), MAI(nullptr) {}
72 static char ID;
73 bool ModuleSectionsEmitted;
74 const SPIRVSubtarget *ST;
75 const SPIRVInstrInfo *TII;
76
77 StringRef getPassName() const override { return "SPIRV Assembly Printer"; }
78 void printOperand(const MachineInstr *MI, int OpNum, raw_ostream &O);
79 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
80 const char *ExtraCode, raw_ostream &O) override;
81
82 void outputMCInst(MCInst &Inst);
83 void outputInstruction(const MachineInstr *MI);
84 void outputModuleSection(SPIRV::ModuleSectionType MSType);
85 void outputGlobalRequirements();
86 void outputEntryPoints();
87 void outputDebugSourceAndStrings(const Module &M);
88 void outputOpExtInstImports(const Module &M);
89 void outputOpMemoryModel();
90 void outputOpFunctionEnd();
91 void outputExtFuncDecls();
92 void outputExecutionModeFromMDNode(MCRegister Reg, MDNode *Node,
93 SPIRV::ExecutionMode::ExecutionMode EM,
94 unsigned ExpectMDOps, int64_t DefVal);
95 void outputExecutionModeFromNumthreadsAttribute(
96 const MCRegister &Reg, const Attribute &Attr,
97 SPIRV::ExecutionMode::ExecutionMode EM);
98 void outputExecutionModeFromEnableMaximalReconvergenceAttr(
99 const MCRegister &Reg, const SPIRVSubtarget &ST);
100 void emitSimpleExecutionMode(MCRegister Reg,
101 SPIRV::ExecutionMode::ExecutionMode EM);
102 void outputExecutionMode(const Module &M);
103 void outputAnnotations(const Module &M);
104 void outputModuleSections();
105 void outputFPFastMathDefaultInfo();
106 bool isHidden() {
107 return MF->getFunction()
108 .getFnAttribute(SPIRV_BACKEND_SERVICE_FUN_NAME)
109 .isValid();
110 }
111
112 void emitInstruction(const MachineInstr *MI) override;
113 void emitFunctionEntryLabel() override {}
114 void emitFunctionHeader() override;
115 void emitFunctionBodyStart() override {}
116 void emitFunctionBodyEnd() override;
117 void emitBasicBlockStart(const MachineBasicBlock &MBB) override;
118 void emitBasicBlockEnd(const MachineBasicBlock &MBB) override {}
119 void emitGlobalVariable(const GlobalVariable *GV) override {}
120 void emitOpLabel(const MachineBasicBlock &MBB);
121 void emitEndOfAsmFile(Module &M) override;
122 bool doInitialization(Module &M) override;
123
124 void getAnalysisUsage(AnalysisUsage &AU) const override;
126
127 // Non-owning pointer to the NSDI handler registered via addAsmPrinterHandler.
128 // The handler's lifetime is managed by AsmPrinter (the base class of this
129 // object), so this pointer cannot dangle.
130 SPIRVNonSemanticDebugHandler *NSDebugHandler = nullptr;
131
132 std::unique_ptr<SPIRVAuxDataHandler> AuxDataHandler;
133
134protected:
135 void cleanUp(Module &M);
136};
137} // namespace
138
139void SPIRVAsmPrinter::getAnalysisUsage(AnalysisUsage &AU) const {
140 AU.addRequired<SPIRVModuleAnalysis>();
141 AU.addPreserved<SPIRVModuleAnalysis>();
143}
144
145// If the module has no functions, we need output global info anyway.
146void SPIRVAsmPrinter::emitEndOfAsmFile(Module &M) {
147 if (!ModuleSectionsEmitted) {
148 outputModuleSections();
149 ModuleSectionsEmitted = true;
150 }
151
152 ST = static_cast<const SPIRVTargetMachine &>(TM).getSubtargetImpl();
153 // SPIRVModuleAnalysis sets GR->Bound = MAI->MaxID before printing. Any IDs
154 // allocated by AsmPrinter handlers (e.g. SPIRVNonSemanticDebugHandler) during
155 // outputModuleSections() are not counted. Refresh the bound here so the
156 // formula below sees the final allocation count.
157 if (MAI)
158 ST->getSPIRVGlobalRegistry()->setBound(MAI->MaxID);
159 VersionTuple SPIRVVersion = ST->getSPIRVVersion();
160 uint32_t Major = SPIRVVersion.getMajor();
161 uint32_t Minor = SPIRVVersion.getMinor().value_or(0);
162 // Bound is an approximation that accounts for the maximum used register
163 // number and number of generated OpLabels
164 unsigned Bound = 2 * (ST->getBound() + 1) + NLabels;
165 if (MCAssembler *Asm = OutStreamer->getAssemblerPtr())
166 static_cast<SPIRVObjectWriter &>(Asm->getWriter())
167 .setBuildVersion(Major, Minor, Bound);
168
169 cleanUp(M);
170}
171
172// Any cleanup actions with the Module after we don't care about its content
173// anymore.
174void SPIRVAsmPrinter::cleanUp(Module &M) {
175 // Verifier disallows uses of intrinsic global variables.
176 for (StringRef GVName :
177 {"llvm.global_ctors", "llvm.global_dtors", "llvm.used"}) {
178 if (GlobalVariable *GV = M.getNamedGlobal(GVName))
179 GV->setName("");
180 }
181}
182
183void SPIRVAsmPrinter::emitFunctionHeader() {
184 if (!ModuleSectionsEmitted) {
185 outputModuleSections();
186 ModuleSectionsEmitted = true;
187 }
188 // Get the subtarget from the current MachineFunction.
189 ST = &MF->getSubtarget<SPIRVSubtarget>();
190 TII = ST->getInstrInfo();
191 const Function &F = MF->getFunction();
192
193 if (isVerbose() && !isHidden()) {
194 OutStreamer->getCommentOS()
195 << "-- Begin function "
196 << GlobalValue::dropLLVMManglingEscape(F.getName()) << '\n';
197 }
198
199 auto Section = getObjFileLowering().SectionForGlobal(&F, TM);
200 MF->setSection(Section);
201
202 // SPIRVAsmPrinter::emitFunctionHeader() does not call the base class,
203 // so handlers never receive beginFunction() from the normal path. Drive the
204 // per-function lifecycle here, matching what AsmPrinter::emitFunctionHeader()
205 // does for other targets.
206 for (auto &Handler : Handlers) {
207 Handler->beginFunction(MF);
208 Handler->beginBasicBlockSection(MF->front());
209 }
210}
211
212void SPIRVAsmPrinter::outputOpFunctionEnd() {
213 MCInst FunctionEndInst;
214 FunctionEndInst.setOpcode(SPIRV::OpFunctionEnd);
215 outputMCInst(FunctionEndInst);
216}
217
218void SPIRVAsmPrinter::emitFunctionBodyEnd() {
219 if (!isHidden())
220 outputOpFunctionEnd();
221}
222
223void SPIRVAsmPrinter::emitOpLabel(const MachineBasicBlock &MBB) {
224 // Do not emit anything if it's an internal service function.
225 if (isHidden())
226 return;
227
228 MCInst LabelInst;
229 LabelInst.setOpcode(SPIRV::OpLabel);
230 LabelInst.addOperand(MCOperand::createReg(MAI->getOrCreateMBBRegister(MBB)));
231 outputMCInst(LabelInst);
232 ++NLabels;
233 LabeledMBB.insert(&MBB);
234}
235
236void SPIRVAsmPrinter::emitBasicBlockStart(const MachineBasicBlock &MBB) {
237 // Do not emit anything if it's an internal service function.
238 if (MBB.empty() || isHidden())
239 return;
240
241 // If it's the first MBB in MF, it has OpFunction and OpFunctionParameter, so
242 // OpLabel should be output after them.
243 if (MBB.getNumber() == MF->front().getNumber()) {
244 for (const MachineInstr &MI : MBB)
245 if (MI.getOpcode() == SPIRV::OpFunction)
246 return;
247 // TODO: this case should be checked by the verifier.
248 report_fatal_error("OpFunction is expected in the front MBB of MF");
249 }
250 emitOpLabel(MBB);
251}
252
253void SPIRVAsmPrinter::printOperand(const MachineInstr *MI, int OpNum,
254 raw_ostream &O) {
255 const MachineOperand &MO = MI->getOperand(OpNum);
256
257 switch (MO.getType()) {
260 break;
261
263 O << MO.getImm();
264 break;
265
267 O << MO.getFPImm();
268 break;
269
271 O << *MO.getMBB()->getSymbol();
272 break;
273
275 O << *getSymbol(MO.getGlobal());
276 break;
277
279 MCSymbol *BA = GetBlockAddressSymbol(MO.getBlockAddress());
280 O << BA->getName();
281 break;
282 }
283
285 O << *GetExternalSymbolSymbol(MO.getSymbolName());
286 break;
287
290 default:
291 llvm_unreachable("<unknown operand type>");
292 }
293}
294
295bool SPIRVAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
296 const char *ExtraCode, raw_ostream &O) {
297 if (ExtraCode && ExtraCode[0])
298 return true; // Invalid instruction - SPIR-V does not have special modifiers
299
300 printOperand(MI, OpNo, O);
301 return false;
302}
303
305 const SPIRVInstrInfo *TII) {
306 return TII->isHeaderInstr(*MI) || MI->getOpcode() == SPIRV::OpFunction ||
307 MI->getOpcode() == SPIRV::OpFunctionParameter;
308}
309
310void SPIRVAsmPrinter::outputMCInst(MCInst &Inst) {
311 OutStreamer->emitInstruction(Inst, *OutContext.getSubtargetInfo());
312}
313
314void SPIRVAsmPrinter::outputInstruction(const MachineInstr *MI) {
315 SPIRVMCInstLower MCInstLowering;
316 MCInst TmpInst;
317 MCInstLowering.lower(MI, TmpInst, MAI);
318 outputMCInst(TmpInst);
319}
320
321void SPIRVAsmPrinter::emitInstruction(const MachineInstr *MI) {
322 SPIRV_MC::verifyInstructionPredicates(MI->getOpcode(),
323 getSubtargetInfo().getFeatureBits());
324
325 if (!MAI->getSkipEmission(MI))
326 outputInstruction(MI);
327
328 // Output OpLabel after OpFunction and OpFunctionParameter in the first MBB.
329 const MachineInstr *NextMI = MI->getNextNode();
330 if (!LabeledMBB.contains(MI->getParent()) && isFuncOrHeaderInstr(MI, TII) &&
331 (!NextMI || !isFuncOrHeaderInstr(NextMI, TII))) {
332 assert(MI->getParent()->getNumber() == MF->front().getNumber() &&
333 "OpFunction is not in the front MBB of MF");
334 emitOpLabel(*MI->getParent());
335 }
336}
337
338void SPIRVAsmPrinter::outputModuleSection(SPIRV::ModuleSectionType MSType) {
339 for (const MachineInstr *MI : MAI->getMSInstrs(MSType))
340 outputInstruction(MI);
341}
342
343void SPIRVAsmPrinter::outputDebugSourceAndStrings(const Module &M) {
344 // Output OpSourceExtensions.
345 for (auto &Str : MAI->SrcExt) {
346 MCInst Inst;
347 Inst.setOpcode(SPIRV::OpSourceExtension);
348 addStringImm(Str.first(), Inst);
349 outputMCInst(Inst);
350 }
351 // Output OpString.
352 outputModuleSection(SPIRV::MB_DebugStrings);
353 // Output OpSource.
354 MCInst Inst;
355 Inst.setOpcode(SPIRV::OpSource);
356 Inst.addOperand(MCOperand::createImm(static_cast<unsigned>(MAI->SrcLang)));
357 Inst.addOperand(
358 MCOperand::createImm(static_cast<unsigned>(MAI->SrcLangVersion)));
359 outputMCInst(Inst);
360 // Emit OpString instructions for NSDI file paths and type names here, in
361 // section 7. OpString must precede type/constant declarations per the SPIR-V
362 // module layout (section 2.4). The OpExtInst instructions that reference
363 // these strings are emitted later at section 10 by
364 // emitNonSemanticGlobalDebugInfo().
365 if (NSDebugHandler)
366 NSDebugHandler->emitNonSemanticDebugStrings(*MAI);
367 if (AuxDataHandler)
368 AuxDataHandler->emitAuxDataStrings(*MAI);
369}
370
371void SPIRVAsmPrinter::outputOpExtInstImports(const Module &M) {
372 for (auto &CU : MAI->ExtInstSetMap) {
373 unsigned Set = CU.first;
374 MCRegister Reg = CU.second;
375 MCInst Inst;
376 Inst.setOpcode(SPIRV::OpExtInstImport);
379 static_cast<SPIRV::InstructionSet::InstructionSet>(Set)),
380 Inst);
381 outputMCInst(Inst);
382 }
383}
384
385void SPIRVAsmPrinter::outputOpMemoryModel() {
386 MCInst Inst;
387 Inst.setOpcode(SPIRV::OpMemoryModel);
388 Inst.addOperand(MCOperand::createImm(static_cast<unsigned>(MAI->Addr)));
389 Inst.addOperand(MCOperand::createImm(static_cast<unsigned>(MAI->Mem)));
390 outputMCInst(Inst);
391}
392
393// Before the OpEntryPoints' output, we need to add the entry point's
394// interfaces. The interface is a list of IDs of global OpVariable instructions.
395// These declare the set of global variables from a module that form
396// the interface of this entry point.
397void SPIRVAsmPrinter::outputEntryPoints() {
398 // Find all OpVariable IDs with required StorageClass.
399 DenseSet<MCRegister> InterfaceIDs;
400 for (const MachineInstr *MI : MAI->GlobalVarList) {
401 assert(MI->getOpcode() == SPIRV::OpVariable);
402 auto SC = static_cast<SPIRV::StorageClass::StorageClass>(
403 MI->getOperand(2).getImm());
404 // Before version 1.4, the interface's storage classes are limited to
405 // the Input and Output storage classes. Starting with version 1.4,
406 // the interface's storage classes are all storage classes used in
407 // declaring all global variables referenced by the entry point call tree.
408 if (ST->isAtLeastSPIRVVer(VersionTuple(1, 4)) ||
409 SC == SPIRV::StorageClass::Input || SC == SPIRV::StorageClass::Output) {
410 const MachineFunction *MF = MI->getMF();
411 MCRegister Reg = MAI->getRegisterAlias(MF, MI->getOperand(0).getReg());
412 InterfaceIDs.insert(Reg);
413 }
414 }
415
416 // Output OpEntryPoints adding interface args to all of them.
417 for (const MachineInstr *MI : MAI->getMSInstrs(SPIRV::MB_EntryPoints)) {
418 SPIRVMCInstLower MCInstLowering;
419 MCInst TmpInst;
420 MCInstLowering.lower(MI, TmpInst, MAI);
421 for (MCRegister Reg : InterfaceIDs) {
422 assert(Reg.isValid());
424 }
425 outputMCInst(TmpInst);
426 }
427}
428
429// Create global OpCapability instructions for the required capabilities.
430void SPIRVAsmPrinter::outputGlobalRequirements() {
431 // Abort here if not all requirements can be satisfied.
432 MAI->Reqs.checkSatisfiable(*ST);
433
434 for (const auto &Cap : MAI->Reqs.getMinimalCapabilities()) {
435 MCInst Inst;
436 Inst.setOpcode(SPIRV::OpCapability);
438 outputMCInst(Inst);
439 }
440
441 // Generate the final OpExtensions with strings instead of enums.
442 for (const auto &Ext : MAI->Reqs.getExtensions()) {
443 MCInst Inst;
444 Inst.setOpcode(SPIRV::OpExtension);
446 SPIRV::OperandCategory::ExtensionOperand, Ext),
447 Inst);
448 outputMCInst(Inst);
449 }
450 // TODO add a pseudo instr for version number.
451}
452
453void SPIRVAsmPrinter::outputExtFuncDecls() {
454 // Insert OpFunctionEnd after each declaration.
455 auto I = MAI->getMSInstrs(SPIRV::MB_ExtFuncDecls).begin(),
456 E = MAI->getMSInstrs(SPIRV::MB_ExtFuncDecls).end();
457 for (; I != E; ++I) {
458 outputInstruction(*I);
459 if ((I + 1) == E || (*(I + 1))->getOpcode() == SPIRV::OpFunction)
460 outputOpFunctionEnd();
461 }
462}
463
464// Encode LLVM type by SPIR-V execution mode VecTypeHint.
465static unsigned encodeVecTypeHint(Type *Ty) {
466 if (Ty->isHalfTy())
467 return 4;
468 if (Ty->isFloatTy())
469 return 5;
470 if (Ty->isDoubleTy())
471 return 6;
472 if (IntegerType *IntTy = dyn_cast<IntegerType>(Ty)) {
473 switch (IntTy->getIntegerBitWidth()) {
474 case 8:
475 return 0;
476 case 16:
477 return 1;
478 case 32:
479 return 2;
480 case 64:
481 return 3;
482 default:
483 llvm_unreachable("invalid integer type");
484 }
485 }
487 Type *EleTy = VecTy->getElementType();
488 unsigned Size = VecTy->getNumElements();
489 return Size << 16 | encodeVecTypeHint(EleTy);
490 }
491 llvm_unreachable("invalid type");
492}
493
494static void addOpsFromMDNode(MDNode *MDN, MCInst &Inst,
496 for (const MDOperand &MDOp : MDN->operands()) {
497 if (auto *CMeta = dyn_cast<ConstantAsMetadata>(MDOp)) {
498 Constant *C = CMeta->getValue();
499 if (ConstantInt *Const = dyn_cast<ConstantInt>(C)) {
500 Inst.addOperand(MCOperand::createImm(Const->getZExtValue()));
501 } else if (auto *CE = dyn_cast<Function>(C)) {
502 MCRegister FuncReg = MAI->getGlobalObjReg(CE);
503 assert(FuncReg.isValid());
504 Inst.addOperand(MCOperand::createReg(FuncReg));
505 }
506 }
507 }
508}
509
510void SPIRVAsmPrinter::outputExecutionModeFromMDNode(
511 MCRegister Reg, MDNode *Node, SPIRV::ExecutionMode::ExecutionMode EM,
512 unsigned ExpectMDOps, int64_t DefVal) {
513 MCInst Inst;
514 Inst.setOpcode(SPIRV::OpExecutionMode);
516 Inst.addOperand(MCOperand::createImm(static_cast<unsigned>(EM)));
517 addOpsFromMDNode(Node, Inst, MAI);
518 // reqd_work_group_size and work_group_size_hint require 3 operands,
519 // if metadata contains less operands, just add a default value
520 unsigned NodeSz = Node->getNumOperands();
521 if (ExpectMDOps > 0 && NodeSz < ExpectMDOps)
522 for (unsigned i = NodeSz; i < ExpectMDOps; ++i)
523 Inst.addOperand(MCOperand::createImm(DefVal));
524 outputMCInst(Inst);
525}
526
527void SPIRVAsmPrinter::outputExecutionModeFromNumthreadsAttribute(
528 const MCRegister &Reg, const Attribute &Attr,
529 SPIRV::ExecutionMode::ExecutionMode EM) {
530 assert(Attr.isValid() && "Function called with an invalid attribute.");
531
532 MCInst Inst;
533 Inst.setOpcode(SPIRV::OpExecutionMode);
535 Inst.addOperand(MCOperand::createImm(static_cast<unsigned>(EM)));
536
537 SmallVector<StringRef> NumThreads;
538 Attr.getValueAsString().split(NumThreads, ',');
539 assert(NumThreads.size() == 3 && "invalid numthreads");
540 for (uint32_t i = 0; i < 3; ++i) {
541 uint32_t V;
542 [[maybe_unused]] bool Result = NumThreads[i].getAsInteger(10, V);
543 assert(!Result && "Failed to parse numthreads");
545 }
546
547 outputMCInst(Inst);
548}
549
550void SPIRVAsmPrinter::emitSimpleExecutionMode(
551 MCRegister Reg, SPIRV::ExecutionMode::ExecutionMode EM) {
552 MCInst Inst;
553 Inst.setOpcode(SPIRV::OpExecutionMode);
555 Inst.addOperand(MCOperand::createImm(static_cast<unsigned>(EM)));
556 outputMCInst(Inst);
557}
558
559void SPIRVAsmPrinter::outputExecutionModeFromEnableMaximalReconvergenceAttr(
560 const MCRegister &Reg, const SPIRVSubtarget &ST) {
561 assert(ST.canUseExtension(SPIRV::Extension::SPV_KHR_maximal_reconvergence) &&
562 "Function called when SPV_KHR_maximal_reconvergence is not enabled.");
563
564 emitSimpleExecutionMode(Reg, SPIRV::ExecutionMode::MaximallyReconvergesKHR);
565}
566
567void SPIRVAsmPrinter::outputExecutionMode(const Module &M) {
568 NamedMDNode *Node = M.getNamedMetadata("spirv.ExecutionMode");
569 if (Node) {
570 for (unsigned i = 0; i < Node->getNumOperands(); i++) {
571 const auto EM =
573 cast<ConstantAsMetadata>((Node->getOperand(i))->getOperand(1))
574 ->getValue())
575 ->getZExtValue();
576 // Skip ArithmeticPoisonKHR to avoid a duplicate.
577 if (EM == SPIRV::ExecutionMode::ArithmeticPoisonKHR)
578 continue;
579 // If SPV_KHR_float_controls2 is enabled and we find any of
580 // FPFastMathDefault, ContractionOff or SignedZeroInfNanPreserve execution
581 // modes, skip it, it'll be done somewhere else.
582 if (ST->canUseExtension(SPIRV::Extension::SPV_KHR_float_controls2)) {
583 if (EM == SPIRV::ExecutionMode::FPFastMathDefault ||
584 EM == SPIRV::ExecutionMode::ContractionOff ||
585 EM == SPIRV::ExecutionMode::SignedZeroInfNanPreserve)
586 continue;
587 }
588
589 MCInst Inst;
590 Inst.setOpcode(SPIRV::OpExecutionMode);
591 addOpsFromMDNode(cast<MDNode>(Node->getOperand(i)), Inst, MAI);
592 outputMCInst(Inst);
593 }
594 outputFPFastMathDefaultInfo();
595 }
596 for (auto FI = M.begin(), E = M.end(); FI != E; ++FI) {
597 const Function &F = *FI;
598 // Only operands of OpEntryPoint instructions are allowed to be
599 // <Entry Point> operands of OpExecutionMode
600 if (F.isDeclaration() || !isEntryPoint(F))
601 continue;
602 MCRegister FReg = MAI->getGlobalObjReg(&F);
603 assert(FReg.isValid());
604
605 if (Attribute Attr = F.getFnAttribute("hlsl.shader"); Attr.isValid()) {
606 // SPIR-V common validation: Fragment requires OriginUpperLeft or
607 // OriginLowerLeft.
608 // VUID-StandaloneSpirv-OriginLowerLeft-04653: Fragment must declare
609 // OriginUpperLeft.
610 if (Attr.getValueAsString() == "pixel") {
611 emitSimpleExecutionMode(FReg, SPIRV::ExecutionMode::OriginUpperLeft);
612 }
613 }
614 if (MDNode *Node = F.getMetadata("reqd_work_group_size"))
615 outputExecutionModeFromMDNode(FReg, Node, SPIRV::ExecutionMode::LocalSize,
616 3, 1);
617 if (Attribute Attr = F.getFnAttribute("hlsl.numthreads"); Attr.isValid())
618 outputExecutionModeFromNumthreadsAttribute(
619 FReg, Attr, SPIRV::ExecutionMode::LocalSize);
620 if (Attribute Attr = F.getFnAttribute("enable-maximal-reconvergence");
621 Attr.getValueAsBool()) {
622 outputExecutionModeFromEnableMaximalReconvergenceAttr(FReg, *ST);
623 }
624 if (MDNode *Node = F.getMetadata("work_group_size_hint"))
625 outputExecutionModeFromMDNode(FReg, Node,
626 SPIRV::ExecutionMode::LocalSizeHint, 3, 1);
627 if (MDNode *Node = F.getMetadata("reqd_sub_group_size"))
628 outputExecutionModeFromMDNode(FReg, Node,
629 SPIRV::ExecutionMode::SubgroupSize, 0, 0);
630 if (MDNode *Node = F.getMetadata("intel_reqd_sub_group_size"))
631 outputExecutionModeFromMDNode(FReg, Node,
632 SPIRV::ExecutionMode::SubgroupSize, 0, 0);
633 if (MDNode *Node = F.getMetadata("max_work_group_size")) {
634 if (ST->canUseExtension(SPIRV::Extension::SPV_INTEL_kernel_attributes))
635 outputExecutionModeFromMDNode(
636 FReg, Node, SPIRV::ExecutionMode::MaxWorkgroupSizeINTEL, 3, 1);
637 }
638 if (MDNode *Node = F.getMetadata("vec_type_hint")) {
639 MCInst Inst;
640 Inst.setOpcode(SPIRV::OpExecutionMode);
642 unsigned EM = static_cast<unsigned>(SPIRV::ExecutionMode::VecTypeHint);
644 unsigned TypeCode = encodeVecTypeHint(getMDOperandAsType(Node, 0));
645 Inst.addOperand(MCOperand::createImm(TypeCode));
646 outputMCInst(Inst);
647 }
648 // Per SPV_KHR_poison_freeze description of PoisonFreezeKHR "If declared,
649 // all entry points must use the ArithmeticPoisonKHR execution mode".
650 if (llvm::is_contained(MAI->Reqs.getMinimalCapabilities(),
651 SPIRV::Capability::PoisonFreezeKHR)) {
652 emitSimpleExecutionMode(FReg, SPIRV::ExecutionMode::ArithmeticPoisonKHR);
653 }
654 // --spirv-fp-contract=off forces to emit ContractionOff for this kernel
655 // entry point, --spirv-fp-contract=fast suppresses it.
656 bool EmitContractionOff =
657 ST->isKernel() && !M.getNamedMetadata("spirv.ExecutionMode") &&
658 SPIRVFPContract != SPIRVFPContractMode::Fast &&
659 (SPIRVFPContract == SPIRVFPContractMode::Off ||
660 !M.getNamedMetadata("opencl.enable.FP_CONTRACT"));
661 if (EmitContractionOff) {
662 if (ST->canUseExtension(SPIRV::Extension::SPV_KHR_float_controls2)) {
663 // When SPV_KHR_float_controls2 is enabled, ContractionOff is
664 // deprecated. We need to use FPFastMathDefault with the appropriate
665 // flags instead. Since FPFastMathDefault takes a target type, we need
666 // to emit it for each floating-point type that exists in the module
667 // to match the effect of ContractionOff. As of now, there are 3 FP
668 // types: fp16, fp32 and fp64.
669
670 // We only end up here because there is no "spirv.ExecutionMode"
671 // metadata, so that means no FPFastMathDefault. Therefore, we only
672 // need to make sure AllowContract is set to 0, as the rest of flags.
673 // We still need to emit the OpExecutionMode instruction, otherwise
674 // it's up to the client API to define the flags. Therefore, we need
675 // to find the constant with 0 value.
676
677 // Collect the SPIRVTypes for fp16, fp32, and fp64 and the constant of
678 // type int32 with 0 value to represent the FP Fast Math Mode.
679 std::vector<const MachineInstr *> SPIRVFloatTypes;
680 const MachineInstr *ConstZeroInt32 = nullptr;
681 for (const MachineInstr *MI :
682 MAI->getMSInstrs(SPIRV::MB_TypeConstVars)) {
683 unsigned OpCode = MI->getOpcode();
684
685 // Collect the SPIRV type if it's a float.
686 if (OpCode == SPIRV::OpTypeFloat) {
687 // Skip if the target type is not fp16, fp32, fp64.
688 const unsigned OpTypeFloatSize = MI->getOperand(1).getImm();
689 if (OpTypeFloatSize != 16 && OpTypeFloatSize != 32 &&
690 OpTypeFloatSize != 64) {
691 continue;
692 }
693 SPIRVFloatTypes.push_back(MI);
694 continue;
695 }
696
697 if (OpCode == SPIRV::OpConstantNull) {
698 // Check if the constant is int32, if not skip it.
699 const MachineRegisterInfo &MRI = MI->getMF()->getRegInfo();
700 MachineInstr *TypeMI = MRI.getVRegDef(MI->getOperand(1).getReg());
701 bool IsInt32Ty = TypeMI &&
702 TypeMI->getOpcode() == SPIRV::OpTypeInt &&
703 TypeMI->getOperand(1).getImm() == 32;
704 if (IsInt32Ty)
705 ConstZeroInt32 = MI;
706 }
707 }
708
709 // When SPV_KHR_float_controls2 is enabled, ContractionOff is
710 // deprecated. We need to use FPFastMathDefault with the appropriate
711 // flags instead. Since FPFastMathDefault takes a target type, we need
712 // to emit it for each floating-point type that exists in the module
713 // to match the effect of ContractionOff. As of now, there are 3 FP
714 // types: fp16, fp32 and fp64.
715 for (const MachineInstr *MI : SPIRVFloatTypes) {
716 MCInst Inst;
717 Inst.setOpcode(SPIRV::OpExecutionModeId);
719 unsigned EM =
720 static_cast<unsigned>(SPIRV::ExecutionMode::FPFastMathDefault);
722 const MachineFunction *MF = MI->getMF();
723 MCRegister TypeReg =
724 MAI->getRegisterAlias(MF, MI->getOperand(0).getReg());
725 Inst.addOperand(MCOperand::createReg(TypeReg));
726 assert(ConstZeroInt32 && "There should be a constant zero.");
727 MCRegister ConstReg = MAI->getRegisterAlias(
728 ConstZeroInt32->getMF(), ConstZeroInt32->getOperand(0).getReg());
729 Inst.addOperand(MCOperand::createReg(ConstReg));
730 outputMCInst(Inst);
731 }
732 } else {
733 emitSimpleExecutionMode(FReg, SPIRV::ExecutionMode::ContractionOff);
734 }
735 }
736 }
737}
738
739void SPIRVAsmPrinter::outputAnnotations(const Module &M) {
740 outputModuleSection(SPIRV::MB_Annotations);
741 // Process llvm.global.annotations special global variable.
742 for (auto F = M.global_begin(), E = M.global_end(); F != E; ++F) {
743 if ((*F).getName() != "llvm.global.annotations")
744 continue;
745 const GlobalVariable *V = &(*F);
746 const ConstantArray *CA = cast<ConstantArray>(V->getOperand(0));
747 for (Value *Op : CA->operands()) {
748 ConstantStruct *CS = cast<ConstantStruct>(Op);
749 // The first field of the struct contains a pointer to
750 // the annotated variable.
751 Value *AnnotatedVar = CS->getOperand(0)->stripPointerCasts();
752 auto *GO = dyn_cast<GlobalObject>(AnnotatedVar);
753 MCRegister Reg = GO ? MAI->getGlobalObjReg(GO) : MCRegister();
754 if (!Reg.isValid()) {
755 std::string DiagMsg;
756 raw_string_ostream OS(DiagMsg);
757 AnnotatedVar->print(OS);
758 DiagMsg = "Unsupported value in llvm.global.annotations: " + DiagMsg;
759 report_fatal_error(DiagMsg.c_str());
760 }
761
762 // The second field contains a pointer to a global annotation string.
763 GlobalVariable *GV =
765
766 StringRef AnnotationString;
767 [[maybe_unused]] bool Success =
768 getConstantStringInfo(GV, AnnotationString);
769 assert(Success && "Failed to get annotation string");
770 MCInst Inst;
771 Inst.setOpcode(SPIRV::OpDecorate);
773 unsigned Dec = static_cast<unsigned>(SPIRV::Decoration::UserSemantic);
775 addStringImm(AnnotationString, Inst);
776 outputMCInst(Inst);
777 }
778 }
779}
780
781void SPIRVAsmPrinter::outputFPFastMathDefaultInfo() {
782 // Collect the SPIRVTypes that are OpTypeFloat and the constants of type
783 // int32, that might be used as FP Fast Math Mode.
784 std::vector<const MachineInstr *> SPIRVFloatTypes;
785 // Hashtable to associate immediate values with the constant holding them.
786 DenseMap<int, const MachineInstr *> ConstMap;
787 for (const MachineInstr *MI : MAI->getMSInstrs(SPIRV::MB_TypeConstVars)) {
788 // Skip if the instruction is not OpTypeFloat or OpConstant.
789 unsigned OpCode = MI->getOpcode();
790 if (OpCode != SPIRV::OpTypeFloat && OpCode != SPIRV::OpConstantI &&
791 OpCode != SPIRV::OpConstantNull)
792 continue;
793
794 // Collect the SPIRV type if it's a float.
795 if (OpCode == SPIRV::OpTypeFloat) {
796 SPIRVFloatTypes.push_back(MI);
797 } else {
798 // Check if the constant is int32, if not skip it.
799 const MachineRegisterInfo &MRI = MI->getMF()->getRegInfo();
800 MachineInstr *TypeMI = MRI.getVRegDef(MI->getOperand(1).getReg());
801 if (!TypeMI || TypeMI->getOpcode() != SPIRV::OpTypeInt ||
802 TypeMI->getOperand(1).getImm() != 32)
803 continue;
804
805 if (OpCode == SPIRV::OpConstantI)
806 ConstMap[MI->getOperand(2).getImm()] = MI;
807 else
808 ConstMap[0] = MI;
809 }
810 }
811
812 for (const auto &[Func, FPFastMathDefaultInfoVec] :
813 MAI->FPFastMathDefaultInfoMap) {
814 if (FPFastMathDefaultInfoVec.empty())
815 continue;
816
817 for (const MachineInstr *MI : SPIRVFloatTypes) {
818 unsigned OpTypeFloatSize = MI->getOperand(1).getImm();
821 assert(Index < FPFastMathDefaultInfoVec.size() &&
822 "Index out of bounds for FPFastMathDefaultInfoVec");
823 const auto &FPFastMathDefaultInfo = FPFastMathDefaultInfoVec[Index];
824 assert(FPFastMathDefaultInfo.Ty &&
825 "Expected target type for FPFastMathDefaultInfo");
826 assert(FPFastMathDefaultInfo.Ty->getScalarSizeInBits() ==
827 OpTypeFloatSize &&
828 "Mismatched float type size");
829 MCInst Inst;
830 Inst.setOpcode(SPIRV::OpExecutionModeId);
831 MCRegister FuncReg = MAI->getGlobalObjReg(Func);
832 assert(FuncReg.isValid());
833 Inst.addOperand(MCOperand::createReg(FuncReg));
834 Inst.addOperand(
835 MCOperand::createImm(SPIRV::ExecutionMode::FPFastMathDefault));
836 MCRegister TypeReg =
837 MAI->getRegisterAlias(MI->getMF(), MI->getOperand(0).getReg());
838 Inst.addOperand(MCOperand::createReg(TypeReg));
839 unsigned Flags = FPFastMathDefaultInfo.FastMathFlags;
840 if (FPFastMathDefaultInfo.ContractionOff &&
841 (Flags & SPIRV::FPFastMathMode::AllowContract))
843 "Conflicting FPFastMathFlags: ContractionOff and AllowContract");
844
845 if (FPFastMathDefaultInfo.SignedZeroInfNanPreserve &&
846 !(Flags &
847 (SPIRV::FPFastMathMode::NotNaN | SPIRV::FPFastMathMode::NotInf |
848 SPIRV::FPFastMathMode::NSZ))) {
849 if (FPFastMathDefaultInfo.FPFastMathDefault)
850 report_fatal_error("Conflicting FPFastMathFlags: "
851 "SignedZeroInfNanPreserve but at least one of "
852 "NotNaN/NotInf/NSZ is enabled.");
853 }
854
855 // Don't emit if none of the execution modes was used.
856 if (Flags == SPIRV::FPFastMathMode::None &&
857 !FPFastMathDefaultInfo.ContractionOff &&
858 !FPFastMathDefaultInfo.SignedZeroInfNanPreserve &&
859 !FPFastMathDefaultInfo.FPFastMathDefault)
860 continue;
861
862 // Retrieve the constant instruction for the immediate value.
863 auto It = ConstMap.find(Flags);
864 if (It == ConstMap.end())
865 report_fatal_error("Expected constant instruction for FP Fast Math "
866 "Mode operand of FPFastMathDefault execution mode.");
867 const MachineInstr *ConstMI = It->second;
868 MCRegister ConstReg = MAI->getRegisterAlias(
869 ConstMI->getMF(), ConstMI->getOperand(0).getReg());
870 Inst.addOperand(MCOperand::createReg(ConstReg));
871 outputMCInst(Inst);
872 }
873 }
874}
875
876void SPIRVAsmPrinter::outputModuleSections() {
877 const Module *M = MMI->getModule();
878 // Get the global subtarget to output module-level info.
879 ST = static_cast<const SPIRVTargetMachine &>(TM).getSubtargetImpl();
880 TII = ST->getInstrInfo();
881 MAI = &getAnalysis<SPIRVModuleAnalysis>().MAI;
882 assert(ST && TII && MAI && M && "Module analysis is required");
883
884 if (!AuxDataHandler) {
885 auto Handler = std::make_unique<SPIRVAuxDataHandler>(*this, *M);
886 if (Handler->hasWork())
887 AuxDataHandler = std::move(Handler);
888 }
889
890 // Let the NSDI handler add its extension and ext inst import entry to MAI
891 // before the module header sections are emitted.
892 if (NSDebugHandler)
893 NSDebugHandler->prepareModuleOutput(*ST, *MAI);
894 if (AuxDataHandler)
895 AuxDataHandler->prepareModuleOutput(*ST, *MAI);
896
897 // Output instructions according to the Logical Layout of a Module:
898 // 1,2. All OpCapability instructions, then optional OpExtension
899 // instructions.
900 outputGlobalRequirements();
901 // 3. Optional OpExtInstImport instructions.
902 outputOpExtInstImports(*M);
903 // 4. The single required OpMemoryModel instruction.
904 outputOpMemoryModel();
905 // 5. All entry point declarations, using OpEntryPoint.
906 outputEntryPoints();
907 // 6. Execution-mode declarations, using OpExecutionMode or
908 // OpExecutionModeId.
909 outputExecutionMode(*M);
910 // 7a. Debug: all OpString, OpSourceExtension, OpSource, and
911 // OpSourceContinued, without forward references.
912 outputDebugSourceAndStrings(*M);
913 // 7b. Debug: all OpName and all OpMemberName.
914 outputModuleSection(SPIRV::MB_DebugNames);
915 // 7c. Debug: all OpModuleProcessed instructions.
916 outputModuleSection(SPIRV::MB_DebugModuleProcessed);
917 // xxx. SPV_INTEL_memory_access_aliasing instructions go before 8.
918 // "All annotation instructions"
919 outputModuleSection(SPIRV::MB_AliasingInsts);
920 // 8. All annotation instructions (all decorations).
921 outputAnnotations(*M);
922 // 9. All type declarations (OpTypeXXX instructions), all constant
923 // instructions, and all global variable declarations. This section is
924 // the first section to allow use of: OpLine and OpNoLine debug information;
925 // non-semantic instructions with OpExtInst.
926 outputModuleSection(SPIRV::MB_TypeConstVars);
927 // 10. All global NonSemantic.Shader.DebugInfo.100 instructions. The
928 // SPIRVNonSemanticDebugHandler emits these directly as MCInsts; the
929 // MB_NonSemanticGlobalDI section in MAI is intentionally left empty.
930 if (NSDebugHandler)
931 NSDebugHandler->emitNonSemanticGlobalDebugInfo(*MAI);
932 if (AuxDataHandler)
933 AuxDataHandler->emitAuxData(*MAI);
934 // 11. All function declarations (functions without a body).
935 outputExtFuncDecls();
936 // 12. All function definitions (functions with a body).
937 // This is done in regular function output.
938}
939
940bool SPIRVAsmPrinter::doInitialization(Module &M) {
941 ModuleSectionsEmitted = false;
942 if (!M.getModuleInlineAsm().empty()) {
943 M.getContext().emitError(
944 "SPIR-V does not support module-level inline assembly");
945 M.removeModuleInlineAsm();
946 }
947
948 // Register the NSDI handler before calling the base class so that
949 // AsmPrinter::doInitialization() calls Handler->beginModule(M) for it.
950 if (M.getNamedMetadata("llvm.dbg.cu")) {
951 auto Handler = std::make_unique<SPIRVNonSemanticDebugHandler>(*this);
952 NSDebugHandler = Handler.get();
953 addAsmPrinterHandler(std::move(Handler));
954 }
955 // We need to call the parent's one explicitly.
957}
958
959char SPIRVAsmPrinter::ID = 0;
960
961INITIALIZE_PASS(SPIRVAsmPrinter, "spirv-asm-printer", "SPIRV Assembly Printer",
962 false, false)
963
964// Force static initialization.
966LLVMInitializeSPIRVAsmPrinter() {
970}
#define Success
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock & MBB
#define X(NUM, ENUM, NAME)
Definition ELF.h:856
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
#define LLVM_ABI
Definition Compiler.h:215
#define LLVM_EXTERNAL_VISIBILITY
Definition Compiler.h:132
This file defines the DenseMap class.
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
Machine Check Debug Module
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
Register Reg
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition PassSupport.h:56
static void addOpsFromMDNode(MDNode *MDN, MCInst &Inst, SPIRV::ModuleAnalysisInfo *MAI)
static bool isFuncOrHeaderInstr(const MachineInstr *MI, const SPIRVInstrInfo *TII)
static unsigned encodeVecTypeHint(Type *Ty)
#define SPIRV_BACKEND_SERVICE_FUN_NAME
Definition SPIRVUtils.h:537
static bool printOperand(raw_ostream &OS, const SelectionDAG *G, const SDValue Value)
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
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:91
bool doInitialization(Module &M) override
Set up the AsmPrinter when we are working on a new module.
void getAnalysisUsage(AnalysisUsage &AU) const override
Record analysis usage.
Functions, function parameters, and return types can have attributes to indicate how they should be t...
Definition Attributes.h:105
LLVM_ABI bool getValueAsBool() const
Return the attribute's value as a boolean.
LLVM_ABI StringRef getValueAsString() const
Return the attribute's value as a string.
bool isValid() const
Return true if the attribute is any kind of attribute.
Definition Attributes.h:261
This is the shared class of boolean and integer constants.
Definition Constants.h:87
This is an important base class in LLVM.
Definition Constant.h:43
iterator find(const_arg_type_t< KeyT > Val)
Definition DenseMap.h:223
iterator end()
Definition DenseMap.h:141
Class to represent fixed width SIMD vectors.
static StringRef dropLLVMManglingEscape(StringRef Name)
If the given string begins with the GlobalValue name mangling escape character '\1',...
Class to represent integer types.
Instances of this class represent a single low-level machine instruction.
Definition MCInst.h:188
void addOperand(const MCOperand Op)
Definition MCInst.h:215
void setOpcode(unsigned Op)
Definition MCInst.h:201
static MCOperand createReg(MCRegister Reg)
Definition MCInst.h:138
static MCOperand createImm(int64_t Val)
Definition MCInst.h:145
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:41
constexpr bool isValid() const
Definition MCRegister.h:84
StringRef getName() const
getName - Get the symbol name.
Definition MCSymbol.h:188
Metadata node.
Definition Metadata.h:1069
ArrayRef< MDOperand > operands() const
Definition Metadata.h:1424
Tracking metadata reference owned by Metadata.
Definition Metadata.h:891
LLVM_ABI 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.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
LLVM_ABI const MachineFunction * getMF() const
Return the function that contains the basic block that this instruction belongs to.
const MachineOperand & getOperand(unsigned i) const
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.
LLVM_ABI MachineInstr * getVRegDef(Register Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
constexpr bool isValid() const
Definition Register.h:112
static const char * getRegisterName(MCRegister Reg)
void lower(const MachineInstr *MI, MCInst &OutMI, SPIRV::ModuleAnalysisInfo *MAI) const
AsmPrinter handler that emits NonSemantic.Shader.DebugInfo.100 (NSDI) instructions for the SPIR-V bac...
void emitNonSemanticDebugStrings(SPIRV::ModuleAnalysisInfo &MAI)
Emit OpString instructions for all NSDI file paths and basic type names into the debug section (secti...
void emitNonSemanticGlobalDebugInfo(SPIRV::ModuleAnalysisInfo &MAI)
Emit module-scope NSDI instructions (DebugSource, DebugCompilationUnit, DebugTypeBasic,...
void prepareModuleOutput(const SPIRVSubtarget &ST, SPIRV::ModuleAnalysisInfo &MAI)
Add SPV_KHR_non_semantic_info extension and NonSemantic.Shader.DebugInfo.100 ext inst set entry to MA...
const SPIRVInstrInfo * getInstrInfo() const override
bool isAtLeastSPIRVVer(VersionTuple VerToCompareTo) const
SPIRVGlobalRegistry * getSPIRVGlobalRegistry() const
VersionTuple getSPIRVVersion() const
unsigned getBound() const
bool canUseExtension(SPIRV::Extension::Extension E) const
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
bool contains(ConstPtrType Ptr) const
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition StringRef.h:736
Primary interface to the complete machine description for the target machine.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
op_range operands()
Definition User.h:267
Value * getOperand(unsigned i) const
Definition User.h:207
LLVM_ABI void print(raw_ostream &O, bool IsForDebug=false) const
Implement operator<< on Value.
LLVM_ABI const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
Definition Value.cpp:713
unsigned getMajor() const
Retrieve the major version number.
std::optional< unsigned > getMinor() const
Retrieve the minor version number, if provided.
std::pair< iterator, bool > insert(const ValueT &V)
Definition DenseSet.h:209
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
@ Fast
Attempts to make calls as fast as possible (e.g.
Definition CallingConv.h:41
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
initializer< Ty > init(const Ty &Val)
NodeAddr< NodeBase * > Node
Definition RDFGraph.h:383
This is an optimization pass for GlobalISel generic memory operations.
void addStringImm(StringRef Str, MCInst &Inst)
Target & getTheSPIRV32Target()
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
DenseMap< Value *, Constant * > ConstMap
LLVM_ABI 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)
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
Definition InstrProf.h:143
MachineInstr * getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:163
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
std::string getSymbolicOperandMnemonic(SPIRV::OperandCategory::OperandCategory Category, int32_t Value)
bool isEntryPoint(const Function &F)
Target & getTheSPIRV64Target()
Target & getTheSPIRVLogicalTarget()
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
Type * getMDOperandAsType(const MDNode *N, unsigned I)
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1947
RegisterAsmPrinter - Helper template for registering a target specific assembly printer,...
static size_t computeFPFastMathDefaultInfoVecIndex(size_t BitWidth)
Definition SPIRVUtils.h:149
MCRegister getGlobalObjReg(const GlobalObject *GO)