LLVM 24.0.0git
AMDGPUAsmPrinter.cpp
Go to the documentation of this file.
1//===-- AMDGPUAsmPrinter.cpp - AMDGPU assembly printer --------------------===//
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/// \file
10///
11/// The AMDGPUAsmPrinter is used to print both assembly string and also binary
12/// code. When passed an MCAsmStreamer it prints assembly and when passed
13/// an MCObjectStreamer it outputs binary code.
14//
15//===----------------------------------------------------------------------===//
16//
17
18#include "AMDGPUAsmPrinter.h"
19#include "AMDGPU.h"
23#include "AMDGPUTargetMachine.h"
24#include "GCNSubtarget.h"
29#include "R600AsmPrinter.h"
43#include "llvm/MC/MCAssembler.h"
44#include "llvm/MC/MCContext.h"
46#include "llvm/MC/MCStreamer.h"
47#include "llvm/MC/MCValue.h"
54
55using namespace llvm;
56using namespace llvm::AMDGPU;
57
58// This should get the default rounding mode from the kernel. We just set the
59// default here, but this could change if the OpenCL rounding mode pragmas are
60// used.
61//
62// The denormal mode here should match what is reported by the OpenCL runtime
63// for the CL_FP_DENORM bit from CL_DEVICE_{HALF|SINGLE|DOUBLE}_FP_CONFIG, but
64// can also be override to flush with the -cl-denorms-are-zero compiler flag.
65//
66// AMD OpenCL only sets flush none and reports CL_FP_DENORM for double
67// precision, and leaves single precision to flush all and does not report
68// CL_FP_DENORM for CL_DEVICE_SINGLE_FP_CONFIG. Mesa's OpenCL currently reports
69// CL_FP_DENORM for both.
70//
71// FIXME: It seems some instructions do not support single precision denormals
72// regardless of the mode (exp_*_f32, rcp_*_f32, rsq_*_f32, rsq_*f32, sqrt_f32,
73// and sin_f32, cos_f32 on most parts).
74
75// We want to use these instructions, and using fp32 denormals also causes
76// instructions to run at the double precision rate for the device so it's
77// probably best to just report no single precision denormals.
84
85static AsmPrinter *
87 std::unique_ptr<MCStreamer> &&Streamer) {
88 return new AMDGPUAsmPrinter(tm, std::move(Streamer));
89}
90
100
101namespace {
102class AMDGPUAsmPrinterHandler : public AsmPrinterHandler {
103protected:
104 AMDGPUAsmPrinter *Asm;
105
106public:
107 AMDGPUAsmPrinterHandler(AMDGPUAsmPrinter *A) : Asm(A) {}
108
109 void beginFunction(const MachineFunction *MF) override {}
110
111 void endFunction(const MachineFunction *MF) override { Asm->endFunction(MF); }
112
113 void endModule() override {}
114};
115} // End anonymous namespace
116
118 std::unique_ptr<MCStreamer> Streamer)
120 assert(OutStreamer && "AsmPrinter constructed without streamer");
121 // AMDGPU describes a pointer's address space with its own attribute rather
122 // than DW_AT_address_class.
123 TypeAddressSpaceAttribute = dwarf::DW_AT_LLVM_address_space;
126 if (auto *ResourceUsageW =
128 return &ResourceUsageW->getResourceInfo();
129 return nullptr;
130 };
131}
132
134 return "AMDGPU Assembly Printer";
135}
136
138 return &TM.getMCSubtargetInfo();
139}
140
142 if (!OutStreamer)
143 return nullptr;
144 return static_cast<AMDGPUTargetStreamer *>(OutStreamer->getTargetStreamer());
145}
146
150
151void AMDGPUAsmPrinter::initTargetStreamer(Module &M) {
153
154 // TODO: Which one is called first, emitStartOfAsmFile or
155 // emitFunctionBodyStart?
156 if (getTargetStreamer() && !getTargetStreamer()->getTargetID())
157 initializeTargetID(M);
158
159 const Triple &TT = M.getTargetTriple();
160 if (TT.getOS() != Triple::AMDHSA && TT.getOS() != Triple::AMDPAL)
161 return;
162
164
165 if (TT.getOS() == Triple::AMDHSA) {
167 CodeObjectVersion);
168 HSAMetadataStream->begin(M, *getTargetStreamer()->getTargetID());
169 }
170
171 if (TT.getOS() == Triple::AMDPAL)
173}
174
176 // Init target streamer if it has not yet happened
178 initTargetStreamer(M);
179
180 const Triple &TT = M.getTargetTriple();
181 if (TT.getOS() != Triple::AMDHSA)
183
184 // Emit HSA Metadata (NT_AMD_AMDGPU_HSA_METADATA).
185 // Emit HSA Metadata (NT_AMD_HSA_METADATA).
186 if (TT.getOS() == Triple::AMDHSA) {
187 HSAMetadataStream->end();
188 bool Success = HSAMetadataStream->emitTo(*getTargetStreamer());
189 (void)Success;
190 assert(Success && "Malformed HSA Metadata");
191 }
192}
193
195 const SIMachineFunctionInfo &MFI = *MF->getInfo<SIMachineFunctionInfo>();
196 const GCNSubtarget &STM = MF->getSubtarget<GCNSubtarget>();
197 const Function &F = MF->getFunction();
198
199 // TODO: We're checking this late, would be nice to check it earlier.
200 if (STM.requiresCodeObjectV6() && CodeObjectVersion < AMDGPU::AMDHSA_COV6) {
202 STM.getCPU() + " is only available on code object version 6 or better");
203 }
204
205 // TODO: Which one is called first, emitStartOfAsmFile or
206 // emitFunctionBodyStart?
207 if (!getTargetStreamer()->getTargetID())
208 initializeTargetID(*F.getParent());
209
210 if (!MFI.isEntryFunction())
211 return;
212
213 if (STM.isMesaKernel(F) &&
214 (F.getCallingConv() == CallingConv::AMDGPU_KERNEL ||
215 F.getCallingConv() == CallingConv::SPIR_KERNEL)) {
216 AMDGPUMCKernelCodeT KernelCode;
217 getAmdKernelCode(KernelCode, CurrentProgramInfo, *MF);
218 KernelCode.validate(&STM, MF->getContext());
220 }
221
222 if (STM.isAmdHsaOS())
223 HSAMetadataStream->emitKernel(*MF, CurrentProgramInfo);
224}
225
226/// Set bits in a kernel descriptor MCExpr field:
227/// return ((Dst & ~Mask) | (Value << Shift))
228static const MCExpr *setBits(const MCExpr *Dst, const MCExpr *Value,
229 uint32_t Mask, uint32_t Shift, MCContext &Ctx) {
230 const auto *Shft = MCConstantExpr::create(Shift, Ctx);
231 const auto *Msk = MCConstantExpr::create(Mask, Ctx);
232 Dst = MCBinaryExpr::createAnd(Dst, MCUnaryExpr::createNot(Msk, Ctx), Ctx);
234 Ctx);
235 return Dst;
236}
237
239 const SIMachineFunctionInfo &MFI = *MF->getInfo<SIMachineFunctionInfo>();
240 if (!MFI.isEntryFunction())
241 return;
242
243 assert(TM.getTargetTriple().getOS() == Triple::AMDHSA);
244
245 const GCNSubtarget &STM = MF->getSubtarget<GCNSubtarget>();
246 MCContext &Ctx = MF->getContext();
247
249 getAmdhsaKernelDescriptor(*MF, CurrentProgramInfo);
250
251 // Compute inst_pref_size using MCExpr label subtraction for exact code
252 // size. At this point .Lfunc_end has been emitted (by the base AsmPrinter)
253 // right after the function code, so (Lfunc_end - func_sym) gives the
254 // exact function code size in bytes.
255 if (STM.hasInstPrefSize()) {
256 const MCExpr *CodeSizeExpr = MCBinaryExpr::createSub(
259
260 uint32_t Mask, Shift, Width, CacheLineSize;
261 STM.getInstPrefSizeArgs(Mask, Shift, Width, CacheLineSize);
262 const MCExpr *InstPrefSize =
263 AMDGPUMCExpr::createInstPrefSize(CodeSizeExpr, Ctx);
265 setBits(KD.compute_pgm_rsrc3, InstPrefSize, Mask, Shift, Ctx);
266 }
267
269 auto &Context = Streamer.getContext();
270 auto &ObjectFileInfo = *Context.getObjectFileInfo();
271 auto &ReadOnlySection = *ObjectFileInfo.getReadOnlySection();
272
273 Streamer.pushSection();
274 Streamer.switchSection(&ReadOnlySection);
275
276 // CP microcode requires the kernel descriptor to be allocated on 64 byte
277 // alignment.
278 Streamer.emitValueToAlignment(Align(64), 0, 1, 0);
279 ReadOnlySection.ensureMinAlignment(Align(64));
280
281 SmallString<128> KernelName;
282 getNameWithPrefix(KernelName, &MF->getFunction());
284 STM, KernelName, KD, CurrentProgramInfo.NumVGPRsForWavesPerEU,
286 CurrentProgramInfo.NumSGPRsForWavesPerEU,
288 CurrentProgramInfo.VCCUsed, CurrentProgramInfo.FlatUsed,
289 getTargetStreamer()->getTargetID()->isXnackOnOrAny(), Context),
290 Context),
291 CurrentProgramInfo.VCCUsed, CurrentProgramInfo.FlatUsed);
292
293 Streamer.popSection();
294}
295
297 Register RegNo = MI->getOperand(0).getReg();
298
300 raw_svector_ostream OS(Str);
301 OS << "implicit-def: "
302 << printReg(RegNo, MF->getSubtarget().getRegisterInfo());
303
304 if (MI->getAsmPrinterFlags() & AMDGPU::SGPR_SPILL)
305 OS << " : SGPR spill to VGPR lane";
306
307 OutStreamer->AddComment(OS.str());
308 OutStreamer->addBlankLine();
309}
310
312 if (TM.getTargetTriple().getOS() == Triple::AMDHSA) {
314 return;
315 }
316
317 const SIMachineFunctionInfo *MFI = MF->getInfo<SIMachineFunctionInfo>();
318 const GCNSubtarget &STM = MF->getSubtarget<GCNSubtarget>();
319 if (MFI->isEntryFunction() && STM.isAmdHsaOrMesa(MF->getFunction())) {
320 SmallString<128> SymbolName;
321 getNameWithPrefix(SymbolName, &MF->getFunction()),
324 }
325 if (DumpCodeInstEmitter) {
326 // Disassemble function name label to text.
327 DisasmLines.push_back(MF->getName().str() + ":");
328 DisasmLineMaxLen = std::max(DisasmLineMaxLen, DisasmLines.back().size());
329 HexLines.emplace_back("");
330 }
331
333}
334
336 if (DumpCodeInstEmitter && !isBlockOnlyReachableByFallthrough(&MBB)) {
337 // Write a line for the basic block label if it is not only fallthrough.
338 DisasmLines.push_back((Twine("BB") + Twine(getFunctionNumber()) + "_" +
339 Twine(MBB.getNumber()) + ":")
340 .str());
341 DisasmLineMaxLen = std::max(DisasmLineMaxLen, DisasmLines.back().size());
342 HexLines.emplace_back("");
343 }
345}
346
349 if (GV->hasInitializer() && !isa<UndefValue>(GV->getInitializer())) {
350 OutContext.reportError({},
351 Twine(GV->getName()) +
352 ": unsupported initializer for address space");
353 return;
354 }
355
356 const Triple::OSType OS = TM.getTargetTriple().getOS();
357 if (OS == Triple::AMDHSA || OS == Triple::AMDPAL) {
359 return;
360 // With object linking, LDS definitions should have been externalized
361 // by earlier passes (e.g. LDS lowering, named barrier lowering).
362 // Only declarations reach here, emitted as SHN_AMDGPU_LDS symbols
363 // so the linker can assign their offsets.
364 assert(GV->isDeclaration() &&
365 "LDS definitions should have been externalized when object "
366 "linking is enabled");
367 }
368
369 MCSymbol *GVSym = getSymbol(GV);
370
371 GVSym->redefineIfPossible();
372 if (GVSym->isDefined() || GVSym->isVariable())
373 report_fatal_error("symbol '" + Twine(GVSym->getName()) +
374 "' is already defined");
375
376 const DataLayout &DL = GV->getDataLayout();
377 uint64_t Size = GV->getGlobalSize(DL);
378 Align Alignment = GV->getAlign().value_or(Align(4));
379
380 emitVisibility(GVSym, GV->getVisibility(), !GV->isDeclaration());
381 emitLinkage(GV, GVSym);
382 auto *TS = getTargetStreamer();
383 TS->emitAMDGPULDS(GVSym, Size, Alignment);
384 return;
385 }
386
388}
389
391 const Triple &TT = M.getTargetTriple();
392 if (TT.getSubArch() == Triple::NoSubArch) {
393 Triple::SubArchType SubArch =
395 if (SubArch != Triple::NoSubArch) {
396 Triple Fixed(TT);
397 Fixed.setArch(Triple::amdgpu, SubArch);
398 M.getContext().diagnose(DiagnosticInfoGeneric(
399 "codegen with no subarch in the target triple is deprecated and will "
400 "become an error; use the target triple '" +
401 Fixed.str() + "' instead",
402 DS_Warning));
403 } else {
404 M.getContext().diagnose(DiagnosticInfoGeneric(
405 "codegen with no subarch in the target triple is deprecated and will "
406 "become an error",
407 DS_Warning));
408 }
409 }
410
411 CodeObjectVersion = AMDGPU::getAMDHSACodeObjectVersion(M);
412
413 if (TT.getOS() == Triple::AMDHSA) {
414 const AMDGPUOptions &CLOpts =
415 static_cast<const AMDGPUTargetMachine &>(TM).getCLOpts();
416 switch (CodeObjectVersion) {
418 HSAMetadataStream =
419 std::make_unique<HSAMD::MetadataStreamerMsgPackV4>(CLOpts);
420 break;
422 HSAMetadataStream =
423 std::make_unique<HSAMD::MetadataStreamerMsgPackV5>(CLOpts);
424 break;
426 HSAMetadataStream =
427 std::make_unique<HSAMD::MetadataStreamerMsgPackV6>(CLOpts);
428 break;
429 default:
430 reportFatalUsageError("unsupported code object version");
431 }
432
433 addAsmPrinterHandler(std::make_unique<AMDGPUAsmPrinterHandler>(this));
434 }
435
437}
438
439/// Mimics GCNSubtarget::computeOccupancy for MCExpr.
440///
441/// Remove dependency on GCNSubtarget and depend only only the necessary values
442/// for said occupancy computation. Should match computeOccupancy implementation
443/// without passing \p STM on.
444const AMDGPUMCExpr *createOccupancy(unsigned InitOcc, const MCExpr *NumSGPRs,
445 const MCExpr *NumVGPRs,
446 unsigned DynamicVGPRBlockSize,
447 const GCNSubtarget &STM, MCContext &Ctx) {
448 unsigned MaxWaves = STM.getMaxWavesPerEU();
449 unsigned Granule = IsaInfo::getVGPRAllocGranule(STM, DynamicVGPRBlockSize);
450 unsigned TargetTotalNumVGPRs = STM.getTotalNumVGPRs();
451
452 // Bake the per-function SGPR budget into the operands so the late-evaluated
453 // MCExpr stays arithmetic. The trap reservation in particular is implicit on
454 // amdhsa and lives on STM, not on the assembler's MCSubtargetInfo.
456 unsigned SGPRTotal = AMDGPU::getTotalNumSGPRs(Kind);
457 unsigned SGPRGranule = AMDGPU::getSGPRAllocGranule(Kind);
458 unsigned SGPRTrapReserve = STM.hasTrapHandler() ? IsaInfo::TRAP_NUM_SGPRS : 0;
459
460 auto CreateExpr = [&Ctx](unsigned Value) {
461 return MCConstantExpr::create(Value, Ctx);
462 };
463
464 // Zero SGPR count when SGPRs don't limit occupancy, so the MCExpr skips the
465 // SGPR term without having to test the generation itself.
466 const MCExpr *SGPRArg =
467 IsaInfo::isSGPROccupancyLimited(STM) ? NumSGPRs : CreateExpr(0);
468
470 {CreateExpr(MaxWaves), CreateExpr(Granule),
471 CreateExpr(TargetTotalNumVGPRs),
472 CreateExpr(InitOcc), CreateExpr(SGPRTotal),
473 CreateExpr(SGPRGranule),
474 CreateExpr(SGPRTrapReserve), SGPRArg, NumVGPRs},
475 Ctx);
476}
477
478void AMDGPUAsmPrinter::validateMCResourceInfo(Function &F) {
479 if (F.isDeclaration() || !AMDGPU::isModuleEntryFunctionCC(F.getCallingConv()))
480 return;
481
483 const GCNSubtarget &STM = TM.getSubtarget<GCNSubtarget>(F);
484 MCSymbol *FnSym = TM.getSymbol(&F);
485
486 auto TryGetMCExprValue = [](const MCExpr *Value, uint64_t &Res) -> bool {
487 int64_t Val;
488 if (Value->evaluateAsAbsolute(Val)) {
489 Res = Val;
490 return true;
491 }
492 return false;
493 };
494
495 const uint64_t MaxScratchPerWorkitem =
497 MCSymbol *ScratchSizeSymbol =
498 RI.getSymbol(FnSym->getName(), RIK::RIK_PrivateSegSize, OutContext);
499 uint64_t ScratchSize;
500 if (ScratchSizeSymbol->isVariable() &&
501 TryGetMCExprValue(ScratchSizeSymbol->getVariableValue(), ScratchSize) &&
502 ScratchSize > MaxScratchPerWorkitem) {
503 DiagnosticInfoStackSize DiagStackSize(F, ScratchSize, MaxScratchPerWorkitem,
504 DS_Error);
505 F.getContext().diagnose(DiagStackSize);
506 }
507
508 // Validate addressable scalar registers (i.e., prior to added implicit
509 // SGPRs).
510 MCSymbol *NumSGPRSymbol =
511 RI.getSymbol(FnSym->getName(), RIK::RIK_NumSGPR, OutContext);
513 !STM.hasSGPRInitBug()) {
514 unsigned MaxAddressableNumSGPRs = STM.getAddressableNumSGPRs();
515 uint64_t NumSgpr;
516 if (NumSGPRSymbol->isVariable() &&
517 TryGetMCExprValue(NumSGPRSymbol->getVariableValue(), NumSgpr) &&
518 NumSgpr > MaxAddressableNumSGPRs) {
519 F.getContext().diagnose(DiagnosticInfoResourceLimit(
520 F, "addressable scalar registers", NumSgpr, MaxAddressableNumSGPRs,
522 return;
523 }
524 }
525
526 MCSymbol *VCCUsedSymbol =
527 RI.getSymbol(FnSym->getName(), RIK::RIK_UsesVCC, OutContext);
528 MCSymbol *FlatUsedSymbol =
529 RI.getSymbol(FnSym->getName(), RIK::RIK_UsesFlatScratch, OutContext);
530 uint64_t VCCUsed, FlatUsed, NumSgpr;
531
532 if (NumSGPRSymbol->isVariable() && VCCUsedSymbol->isVariable() &&
533 FlatUsedSymbol->isVariable() &&
534 TryGetMCExprValue(NumSGPRSymbol->getVariableValue(), NumSgpr) &&
535 TryGetMCExprValue(VCCUsedSymbol->getVariableValue(), VCCUsed) &&
536 TryGetMCExprValue(FlatUsedSymbol->getVariableValue(), FlatUsed)) {
537
538 // Recomputes NumSgprs + implicit SGPRs but all symbols should now be
539 // resolvable.
540 NumSgpr += IsaInfo::getNumExtraSGPRs(
541 STM, VCCUsed, FlatUsed,
542 getTargetStreamer()->getTargetID()->isXnackOnOrAny());
544 STM.hasSGPRInitBug()) {
545 unsigned MaxAddressableNumSGPRs = STM.getAddressableNumSGPRs();
546 if (NumSgpr > MaxAddressableNumSGPRs) {
547 F.getContext().diagnose(DiagnosticInfoResourceLimit(
548 F, "scalar registers", NumSgpr, MaxAddressableNumSGPRs, DS_Error,
550 return;
551 }
552 }
553
554 MCSymbol *NumVgprSymbol =
555 RI.getSymbol(FnSym->getName(), RIK::RIK_NumVGPR, OutContext);
556 MCSymbol *NumAgprSymbol =
557 RI.getSymbol(FnSym->getName(), RIK::RIK_NumAGPR, OutContext);
558 uint64_t NumVgpr, NumAgpr;
559
560 MachineModuleInfo &MMI = *GetMMI();
561 MachineFunction *MF = MMI.getMachineFunction(F);
562 if (MF && NumVgprSymbol->isVariable() && NumAgprSymbol->isVariable() &&
563 TryGetMCExprValue(NumVgprSymbol->getVariableValue(), NumVgpr) &&
564 TryGetMCExprValue(NumAgprSymbol->getVariableValue(), NumAgpr)) {
565 const SIMachineFunctionInfo &MFI = *MF->getInfo<SIMachineFunctionInfo>();
566 unsigned MaxWaves = MFI.getMaxWavesPerEU();
567 uint64_t TotalNumVgpr =
568 getTotalNumVGPRs(STM.hasGFX90AInsts(), static_cast<uint32_t>(NumAgpr),
569 static_cast<uint32_t>(NumVgpr));
570 uint64_t NumVGPRsForWavesPerEU =
571 std::max({TotalNumVgpr, (uint64_t)1,
573 MaxWaves, MFI.getDynamicVGPRBlockSize())});
574 uint64_t NumSGPRsForWavesPerEU = std::max(
575 {NumSgpr, (uint64_t)1, (uint64_t)STM.getMinNumSGPRs(MaxWaves)});
576 const MCExpr *OccupancyExpr = createOccupancy(
577 STM.getOccupancyWithWorkGroupSizes(*MF).second,
578 MCConstantExpr::create(NumSGPRsForWavesPerEU, OutContext),
579 MCConstantExpr::create(NumVGPRsForWavesPerEU, OutContext),
581 uint64_t Occupancy;
582
583 const auto [MinWEU, MaxWEU] = AMDGPU::getIntegerPairAttribute(
584 F, "amdgpu-waves-per-eu", {0, 0}, true);
585
586 if (TryGetMCExprValue(OccupancyExpr, Occupancy) && Occupancy < MinWEU) {
587 DiagnosticInfoOptimizationFailure Diag(
588 F, F.getSubprogram(),
589 "failed to meet occupancy target given by 'amdgpu-waves-per-eu' in "
590 "'" +
591 F.getName() + "': desired occupancy was " + Twine(MinWEU) +
592 ", final occupancy is " + Twine(Occupancy));
593 F.getContext().diagnose(Diag);
594 return;
595 }
596 }
597 }
598}
599
600static void appendTypeEncoding(std::string &Enc, Type *Ty, const DataLayout &DL,
601 bool IsReturnType) {
602 if (Ty->isVoidTy()) {
603 Enc += 'v';
604 return;
605 }
606 uint64_t Bits = DL.getTypeSizeInBits(Ty);
607 // Zero-sized non-void types (e.g. `{}` or `[0 x i8]`) consume no ABI
608 // registers. For returns, emit the same no-result marker as void so the
609 // parameter encoding still has an explicit return-type prefix.
610 if (Bits == 0) {
611 if (IsReturnType)
612 Enc += 'v';
613 return;
614 }
615 if (Bits <= 32)
616 Enc += 'i';
617 else if (Bits <= 64)
618 Enc += 'l';
619 else
620 Enc.append(divideCeil(Bits, 32), 'i');
621}
622
623static std::string computeTypeId(const FunctionType *FTy,
624 const DataLayout &DL) {
625 std::string Enc;
626 appendTypeEncoding(Enc, FTy->getReturnType(), DL, /*IsReturnType=*/true);
627 for (Type *ParamTy : FTy->params())
628 appendTypeEncoding(Enc, ParamTy, DL, /*IsReturnType=*/false);
629 return Enc;
630}
631
632void AMDGPUAsmPrinter::collectCallEdge(const MachineInstr &MI) {
634 return;
635 const SIInstrInfo *TII = MF->getSubtarget<GCNSubtarget>().getInstrInfo();
636 const MachineOperand *Callee =
637 TII->getNamedOperand(MI, AMDGPU::OpName::callee);
638 if (!Callee || !Callee->isGlobal())
639 return;
640 DirectCallEdges.insert(
641 {getSymbol(&MF->getFunction()), getSymbol(Callee->getGlobal())});
642}
643
644void AMDGPUAsmPrinter::emitAMDGPUInfo(Module &M) {
646 return;
647
648 const NamedMDNode *LDSMD = M.getNamedMetadata("amdgpu.lds.uses");
649 bool HasLDSUses = LDSMD && LDSMD->getNumOperands() > 0;
650
651 const NamedMDNode *BarMD = M.getNamedMetadata("amdgpu.named_barrier.uses");
652 bool HasNamedBarriers = BarMD && BarMD->getNumOperands() > 0;
653
654 // Collect address-taken functions (with type IDs) and indirect call sites.
655 DenseMap<const Function *, std::string> AddrTakenTypeIds;
656 using IndirectCallInfo = std::pair<const Function *, std::string>;
658
659 for (const Function &F : M) {
660 bool IsKernel = AMDGPU::isKernel(F.getCallingConv());
661
662 if (!IsKernel && F.hasAddressTaken(/*PutOffender=*/nullptr,
663 /*IgnoreCallbackUses=*/false,
664 /*IgnoreAssumeLikeCalls=*/true,
665 /*IgnoreLLVMUsed=*/true)) {
666 AddrTakenTypeIds[&F] =
667 computeTypeId(F.getFunctionType(), M.getDataLayout());
668 }
669
670 if (F.isDeclaration())
671 continue;
672
673 StringSet<> SeenTypeIds;
674 for (const BasicBlock &BB : F) {
675 for (const Instruction &I : BB) {
676 const auto *CB = dyn_cast<CallBase>(&I);
677 if (!CB || !CB->isIndirectCall())
678 continue;
679 std::string TId =
680 computeTypeId(CB->getFunctionType(), M.getDataLayout());
681 if (SeenTypeIds.insert(TId).second)
682 IndirectCalls.push_back({&F, std::move(TId)});
683 }
684 }
685 }
686
687 if (FunctionInfos.empty() && DirectCallEdges.empty() && !HasLDSUses &&
688 !HasNamedBarriers && AddrTakenTypeIds.empty() && IndirectCalls.empty())
689 return;
690
691 AMDGPU::InfoSectionData Data;
692 Data.Funcs = std::move(FunctionInfos);
693
694 for (auto &[F, TypeId] : AddrTakenTypeIds) {
695 MCSymbol *Sym = getSymbol(F);
696 Data.TypeIds.push_back({Sym, TypeId});
697 }
698
699 for (auto &[CallerSym, CalleeSym] : DirectCallEdges)
700 Data.Calls.push_back({CallerSym, CalleeSym});
701 DirectCallEdges.clear();
702
703 if (HasLDSUses) {
704 for (const MDNode *N : LDSMD->operands()) {
705 auto *Func = mdconst::extract<Function>(N->getOperand(0));
706 auto *LdsVar = mdconst::extract<GlobalVariable>(N->getOperand(1));
707 Data.Uses.push_back({getSymbol(Func), getSymbol(LdsVar)});
708 }
709 }
710
711 if (HasNamedBarriers) {
712 for (const MDNode *N : BarMD->operands()) {
713 auto *BarVar = mdconst::extract<GlobalVariable>(N->getOperand(0));
714 MCSymbol *BarSym = getSymbol(BarVar);
715 for (unsigned I = 1, E = N->getNumOperands(); I < E; ++I) {
716 auto *Func = mdconst::extract<Function>(N->getOperand(I));
717 Data.Uses.push_back({getSymbol(Func), BarSym});
718 }
719 }
720 }
721
722 for (auto &[Caller, Enc] : IndirectCalls) {
723 MCSymbol *CallerSym = getSymbol(Caller);
724 Data.IndirectCalls.push_back({CallerSym, Enc});
725 }
726
728}
729
731 const Triple &TT = M.getTargetTriple();
732
733 // Pad with s_code_end to help tools and guard against instruction prefetch
734 // causing stale data in caches. Arguably this should be done by the linker,
735 // which is why this isn't done for Mesa.
736 // Don't do it if there is no code.
737 const MCSubtargetInfo &STI = *getGlobalSTI();
738 if ((AMDGPU::isGFX10Plus(STI) || AMDGPU::isGFX90A(STI)) &&
739 (TT.getOS() == Triple::AMDHSA || TT.getOS() == Triple::AMDPAL)) {
741 if (TextSect->hasInstructions()) {
742 OutStreamer->switchSection(TextSect);
744 }
745 }
746
747 // Emit the unified .amdgpu.info section (per-function resources, call graph,
748 // LDS/named-barrier use edges, indirect calls, and address-taken type IDs).
749 emitAMDGPUInfo(M);
750
751 // Assign expressions which can only be resolved when all other functions are
752 // known.
753 RI.finalize(OutContext);
754
755 // Switch section and emit all GPR maximums within the processed module.
756 OutStreamer->pushSection();
757 MCSectionELF *MaxGPRSection =
758 OutContext.getELFSection(".AMDGPU.gpr_maximums", ELF::SHT_PROGBITS, 0);
759 OutStreamer->switchSection(MaxGPRSection);
761 RI.getMaxVGPRSymbol(OutContext), RI.getMaxAGPRSymbol(OutContext),
762 RI.getMaxSGPRSymbol(OutContext), RI.getMaxNamedBarrierSymbol(OutContext));
763 OutStreamer->popSection();
764
765 // In the object-linking pipeline per-function resource MCExprs reference
766 // external callee symbols that cannot be evaluated here, so cross-TU limit
767 // checks would silently no-op for every non-leaf function. Defer resource
768 // sanity checking to the linker, which re-validates against the aggregated
769 // call graph in the combined .amdgpu.info metadata.
771 for (Function &F : M.functions())
772 validateMCResourceInfo(F);
773 }
774
775 RI.reset();
776
778}
779
780SmallString<128> AMDGPUAsmPrinter::getMCExprStr(const MCExpr *Value) {
782 raw_svector_ostream OSS(Str);
784 auto &Context = Streamer.getContext();
785 const MCExpr *New = foldAMDGPUMCExpr(Value, Context);
786 printAMDGPUMCExpr(New, OSS, &MAI);
787 return Str;
788}
789
790// Print comments that apply to both callable functions and entry points.
791void AMDGPUAsmPrinter::emitCommonFunctionComments(
792 const MCExpr *NumVGPR, const MCExpr *NumAGPR, const MCExpr *TotalNumVGPR,
793 const MCExpr *NumSGPR, const MCExpr *ScratchSize, uint64_t CodeSize,
794 const AMDGPUMachineFunctionInfo *MFI) {
795 OutStreamer->emitRawComment(" codeLenInByte = " + Twine(CodeSize), false);
796 OutStreamer->emitRawComment(" TotalNumSgprs: " + getMCExprStr(NumSGPR),
797 false);
798 OutStreamer->emitRawComment(" NumVgprs: " + getMCExprStr(NumVGPR), false);
799 if (NumAGPR && TotalNumVGPR) {
800 OutStreamer->emitRawComment(" NumAgprs: " + getMCExprStr(NumAGPR), false);
801 OutStreamer->emitRawComment(" TotalNumVgprs: " + getMCExprStr(TotalNumVGPR),
802 false);
803 }
804 OutStreamer->emitRawComment(" ScratchSize: " + getMCExprStr(ScratchSize),
805 false);
806 OutStreamer->emitRawComment(" MemoryBound: " + Twine(MFI->isMemoryBound()),
807 false);
808}
809
810const MCExpr *AMDGPUAsmPrinter::getAmdhsaKernelCodeProperties(
811 const MachineFunction &MF) const {
812 const SIMachineFunctionInfo &MFI = *MF.getInfo<SIMachineFunctionInfo>();
813 MCContext &Ctx = MF.getContext();
814 uint16_t KernelCodeProperties = 0;
815 const GCNUserSGPRUsageInfo &UserSGPRInfo = MFI.getUserSGPRInfo();
816
817 if (UserSGPRInfo.hasPrivateSegmentBuffer()) {
818 KernelCodeProperties |=
819 amdhsa::KERNEL_CODE_PROPERTY_ENABLE_SGPR_PRIVATE_SEGMENT_BUFFER;
820 }
821 if (UserSGPRInfo.hasDispatchPtr()) {
822 KernelCodeProperties |=
823 amdhsa::KERNEL_CODE_PROPERTY_ENABLE_SGPR_DISPATCH_PTR;
824 }
825 if (UserSGPRInfo.hasQueuePtr()) {
826 KernelCodeProperties |= amdhsa::KERNEL_CODE_PROPERTY_ENABLE_SGPR_QUEUE_PTR;
827 }
828 if (UserSGPRInfo.hasKernargSegmentPtr()) {
829 KernelCodeProperties |=
830 amdhsa::KERNEL_CODE_PROPERTY_ENABLE_SGPR_KERNARG_SEGMENT_PTR;
831 }
832 if (UserSGPRInfo.hasDispatchID()) {
833 KernelCodeProperties |=
834 amdhsa::KERNEL_CODE_PROPERTY_ENABLE_SGPR_DISPATCH_ID;
835 }
836 if (UserSGPRInfo.hasFlatScratchInit()) {
837 KernelCodeProperties |=
838 amdhsa::KERNEL_CODE_PROPERTY_ENABLE_SGPR_FLAT_SCRATCH_INIT;
839 }
840 if (UserSGPRInfo.hasPrivateSegmentSize()) {
841 KernelCodeProperties |=
842 amdhsa::KERNEL_CODE_PROPERTY_ENABLE_SGPR_PRIVATE_SEGMENT_SIZE;
843 }
844 if (MF.getSubtarget<GCNSubtarget>().isWave32()) {
845 KernelCodeProperties |=
846 amdhsa::KERNEL_CODE_PROPERTY_ENABLE_WAVEFRONT_SIZE32;
847 }
848
849 // CurrentProgramInfo.DynamicCallStack is a MCExpr and could be
850 // un-evaluatable at this point so it cannot be conditionally checked here.
851 // Instead, we'll directly shift the possibly unknown MCExpr into its place
852 // and bitwise-or it into KernelCodeProperties.
853 const MCExpr *KernelCodePropExpr =
854 MCConstantExpr::create(KernelCodeProperties, Ctx);
855 const MCExpr *OrValue = MCConstantExpr::create(
856 amdhsa::KERNEL_CODE_PROPERTY_USES_DYNAMIC_STACK_SHIFT, Ctx);
857 OrValue = MCBinaryExpr::createShl(CurrentProgramInfo.DynamicCallStack,
858 OrValue, Ctx);
859 KernelCodePropExpr = MCBinaryExpr::createOr(KernelCodePropExpr, OrValue, Ctx);
860
861 return KernelCodePropExpr;
862}
863
864MCKernelDescriptor
865AMDGPUAsmPrinter::getAmdhsaKernelDescriptor(const MachineFunction &MF,
866 const SIProgramInfo &PI) const {
867 const GCNSubtarget &STM = MF.getSubtarget<GCNSubtarget>();
868 const Function &F = MF.getFunction();
869 const SIMachineFunctionInfo *Info = MF.getInfo<SIMachineFunctionInfo>();
870 MCContext &Ctx = MF.getContext();
871
872 MCKernelDescriptor KernelDescriptor;
873
874 KernelDescriptor.group_segment_fixed_size =
876 KernelDescriptor.private_segment_fixed_size = PI.ScratchSize;
877
878 Align MaxKernArgAlign;
879 KernelDescriptor.kernarg_size = MCConstantExpr::create(
880 STM.getKernArgSegmentSize(F, MaxKernArgAlign), Ctx);
881
882 KernelDescriptor.compute_pgm_rsrc1 = PI.getComputePGMRSrc1(STM, Ctx);
883 KernelDescriptor.compute_pgm_rsrc2 = PI.getComputePGMRSrc2(STM, Ctx);
884 KernelDescriptor.kernel_code_properties = getAmdhsaKernelCodeProperties(MF);
885
886 int64_t PGM_Rsrc3 = 1;
887 bool EvaluatableRsrc3 =
888 CurrentProgramInfo.ComputePGMRSrc3->evaluateAsAbsolute(PGM_Rsrc3);
889 (void)PGM_Rsrc3;
890 (void)EvaluatableRsrc3;
892 STM.hasGFX90AInsts() || STM.hasGFX1250Insts() || !EvaluatableRsrc3 ||
893 static_cast<uint64_t>(PGM_Rsrc3) == 0);
894 KernelDescriptor.compute_pgm_rsrc3 = CurrentProgramInfo.ComputePGMRSrc3;
895
896 KernelDescriptor.kernarg_preload = MCConstantExpr::create(
897 AMDGPU::hasKernargPreload(STM) ? Info->getNumKernargPreloadedSGPRs() : 0,
898 Ctx);
899
900 return KernelDescriptor;
901}
902
904 // Init target streamer lazily on the first function so that previous passes
905 // can set metadata.
907 initTargetStreamer(*MF.getFunction().getParent());
908
909 ResourceUsage = GetResourceUsage(MF);
910 CurrentProgramInfo.reset(MF);
911
912 const AMDGPUMachineFunctionInfo *MFI =
913 MF.getInfo<AMDGPUMachineFunctionInfo>();
914 MCContext &Ctx = MF.getContext();
915
916 // The starting address of all shader programs must be 256 bytes aligned.
917 // Regular functions just need the basic required instruction alignment.
918 MF.ensureAlignment(MFI->isEntryFunction() ? Align(256) : Align(4));
919
921
922 const GCNSubtarget &STM = MF.getSubtarget<GCNSubtarget>();
924 // FIXME: This should be an explicit check for Mesa.
925 if (!STM.isAmdHsaOS() && !STM.isAmdPalOS()) {
926 MCSectionELF *ConfigSection =
927 Context.getELFSection(".AMDGPU.config", ELF::SHT_PROGBITS, 0);
928 OutStreamer->switchSection(ConfigSection);
929 }
930
931 RI.gatherResourceInfo(MF, *ResourceUsage, OutContext);
932
935 *ResourceUsage;
936 FunctionInfos.push_back(
937 {/*NumSGPR=*/static_cast<uint32_t>(RU.NumExplicitSGPR),
938 /*NumArchVGPR=*/static_cast<uint32_t>(RU.NumVGPR),
939 /*NumAccVGPR=*/static_cast<uint32_t>(RU.NumAGPR),
940 /*PrivateSegmentSize=*/static_cast<uint32_t>(RU.PrivateSegmentSize),
941 /*UsesVCC=*/RU.UsesVCC,
942 /*UsesFlatScratch=*/RU.UsesFlatScratch,
943 /*HasDynStack=*/RU.HasDynamicallySizedStack,
944 /*Sym=*/getSymbol(&MF.getFunction())});
945 }
946
947 if (MFI->isModuleEntryFunction()) {
948 getSIProgramInfo(CurrentProgramInfo, MF);
949 }
950
951 if (STM.isAmdPalOS()) {
952 if (MFI->isEntryFunction())
953 EmitPALMetadata(MF, CurrentProgramInfo);
954 else if (MFI->isModuleEntryFunction())
955 emitPALFunctionMetadata(MF);
956 } else if (!STM.isAmdHsaOS()) {
957 EmitProgramInfoSI(MF, CurrentProgramInfo);
958 }
959
960 DumpCodeInstEmitter = nullptr;
961 if (STM.dumpCode()) {
962 // For -dumpcode, get the assembler out of the streamer. This only works
963 // with -filetype=obj.
964 MCAssembler *Assembler = OutStreamer->getAssemblerPtr();
965 if (Assembler)
966 DumpCodeInstEmitter = Assembler->getEmitterPtr();
967 }
968
969 DisasmLines.clear();
970 HexLines.clear();
972
974
975 emitResourceUsageRemarks(MF, CurrentProgramInfo, MFI->isModuleEntryFunction(),
976 STM.hasMAIInsts());
977
978 {
981 RI.getSymbol(CurrentFnSym->getName(), RIK::RIK_NumVGPR, OutContext),
982 RI.getSymbol(CurrentFnSym->getName(), RIK::RIK_NumAGPR, OutContext),
983 RI.getSymbol(CurrentFnSym->getName(), RIK::RIK_NumSGPR, OutContext),
984 RI.getSymbol(CurrentFnSym->getName(), RIK::RIK_NumNamedBarrier,
985 OutContext),
986 RI.getSymbol(CurrentFnSym->getName(), RIK::RIK_PrivateSegSize,
987 OutContext),
988 RI.getSymbol(CurrentFnSym->getName(), RIK::RIK_UsesVCC, OutContext),
989 RI.getSymbol(CurrentFnSym->getName(), RIK::RIK_UsesFlatScratch,
990 OutContext),
991 RI.getSymbol(CurrentFnSym->getName(), RIK::RIK_HasDynSizedStack,
992 OutContext),
993 RI.getSymbol(CurrentFnSym->getName(), RIK::RIK_HasRecursion,
994 OutContext),
995 RI.getSymbol(CurrentFnSym->getName(), RIK::RIK_HasIndirectCall,
996 OutContext));
997 }
998
999 // Emit _dvgpr$ symbol when appropriate.
1000 emitDVgprSymbol(MF);
1001
1002 if (isVerbose()) {
1003 MCSectionELF *CommentSection =
1004 Context.getELFSection(".AMDGPU.csdata", ELF::SHT_PROGBITS, 0);
1005 OutStreamer->switchSection(CommentSection);
1006
1007 if (!MFI->isEntryFunction()) {
1009 OutStreamer->emitRawComment(" Function info:", false);
1010
1011 emitCommonFunctionComments(
1012 RI.getSymbol(CurrentFnSym->getName(), RIK::RIK_NumVGPR, OutContext)
1013 ->getVariableValue(),
1014 STM.hasMAIInsts() ? RI.getSymbol(CurrentFnSym->getName(),
1015 RIK::RIK_NumAGPR, OutContext)
1016 ->getVariableValue()
1017 : nullptr,
1018 RI.createTotalNumVGPRs(MF, Ctx),
1019 RI.createTotalNumSGPRs(
1020 MF,
1021 MF.getSubtarget<GCNSubtarget>().getTargetID().isXnackOnOrAny(),
1022 Ctx),
1023 RI.getSymbol(CurrentFnSym->getName(), RIK::RIK_PrivateSegSize,
1024 OutContext)
1025 ->getVariableValue(),
1026 CurrentProgramInfo.getFunctionCodeSize(MF), MFI);
1027 return false;
1028 }
1029
1030 OutStreamer->emitRawComment(" Kernel info:", false);
1031 emitCommonFunctionComments(
1032 CurrentProgramInfo.NumArchVGPR,
1033 STM.hasMAIInsts() ? CurrentProgramInfo.NumAccVGPR : nullptr,
1034 CurrentProgramInfo.NumVGPR, CurrentProgramInfo.NumSGPR,
1035 CurrentProgramInfo.ScratchSize,
1036 CurrentProgramInfo.getFunctionCodeSize(MF), MFI);
1037
1038 OutStreamer->emitRawComment(
1039 " FloatMode: " + Twine(CurrentProgramInfo.FloatMode), false);
1040 OutStreamer->emitRawComment(
1041 " IeeeMode: " + Twine(CurrentProgramInfo.IEEEMode), false);
1042 OutStreamer->emitRawComment(
1043 " LDSByteSize: " + Twine(CurrentProgramInfo.LDSSize) +
1044 " bytes/workgroup (compile time only)",
1045 false);
1046
1047 OutStreamer->emitRawComment(
1048 " SGPRBlocks: " + getMCExprStr(CurrentProgramInfo.SGPRBlocks), false);
1049
1050 OutStreamer->emitRawComment(
1051 " VGPRBlocks: " + getMCExprStr(CurrentProgramInfo.VGPRBlocks), false);
1052
1053 OutStreamer->emitRawComment(
1054 " NumSGPRsForWavesPerEU: " +
1055 getMCExprStr(CurrentProgramInfo.NumSGPRsForWavesPerEU),
1056 false);
1057 OutStreamer->emitRawComment(
1058 " NumVGPRsForWavesPerEU: " +
1059 getMCExprStr(CurrentProgramInfo.NumVGPRsForWavesPerEU),
1060 false);
1061
1062 if (STM.hasGFX90AInsts()) {
1063 const MCExpr *AdjustedAccum = MCBinaryExpr::createAdd(
1064 CurrentProgramInfo.AccumOffset, MCConstantExpr::create(1, Ctx), Ctx);
1065 AdjustedAccum = MCBinaryExpr::createMul(
1066 AdjustedAccum, MCConstantExpr::create(4, Ctx), Ctx);
1067 OutStreamer->emitRawComment(
1068 " AccumOffset: " + getMCExprStr(AdjustedAccum), false);
1069 }
1070
1071 if (STM.hasGFX1250Insts())
1072 OutStreamer->emitRawComment(
1073 " NamedBarCnt: " + getMCExprStr(CurrentProgramInfo.NamedBarCnt),
1074 false);
1075
1076 OutStreamer->emitRawComment(
1077 " Occupancy: " + getMCExprStr(CurrentProgramInfo.Occupancy), false);
1078
1079 OutStreamer->emitRawComment(
1080 " WaveLimiterHint : " + Twine(MFI->needsWaveLimiter()), false);
1081
1082 OutStreamer->emitRawComment(
1083 " COMPUTE_PGM_RSRC2:SCRATCH_EN: " +
1084 getMCExprStr(CurrentProgramInfo.ScratchEnable),
1085 false);
1086 OutStreamer->emitRawComment(" COMPUTE_PGM_RSRC2:USER_SGPR: " +
1087 Twine(CurrentProgramInfo.UserSGPR),
1088 false);
1089 OutStreamer->emitRawComment(" COMPUTE_PGM_RSRC2:TRAP_HANDLER: " +
1090 Twine(CurrentProgramInfo.TrapHandlerEnable),
1091 false);
1092 OutStreamer->emitRawComment(" COMPUTE_PGM_RSRC2:TGID_X_EN: " +
1093 Twine(CurrentProgramInfo.TGIdXEnable),
1094 false);
1095 OutStreamer->emitRawComment(" COMPUTE_PGM_RSRC2:TGID_Y_EN: " +
1096 Twine(CurrentProgramInfo.TGIdYEnable),
1097 false);
1098 OutStreamer->emitRawComment(" COMPUTE_PGM_RSRC2:TGID_Z_EN: " +
1099 Twine(CurrentProgramInfo.TGIdZEnable),
1100 false);
1101 OutStreamer->emitRawComment(" COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: " +
1102 Twine(CurrentProgramInfo.TIdIGCompCount),
1103 false);
1104
1105 [[maybe_unused]] int64_t PGMRSrc3;
1107 STM.hasGFX90AInsts() || STM.hasGFX1250Insts() ||
1108 (CurrentProgramInfo.ComputePGMRSrc3->evaluateAsAbsolute(PGMRSrc3) &&
1109 static_cast<uint64_t>(PGMRSrc3) == 0));
1110 if (STM.hasGFX90AInsts()) {
1111 OutStreamer->emitRawComment(
1112 " COMPUTE_PGM_RSRC3_GFX90A:ACCUM_OFFSET: " +
1113 getMCExprStr(MCKernelDescriptor::bits_get(
1114 CurrentProgramInfo.ComputePGMRSrc3,
1115 amdhsa::COMPUTE_PGM_RSRC3_GFX90A_ACCUM_OFFSET_SHIFT,
1116 amdhsa::COMPUTE_PGM_RSRC3_GFX90A_ACCUM_OFFSET, Ctx)),
1117 false);
1118 OutStreamer->emitRawComment(
1119 " COMPUTE_PGM_RSRC3_GFX90A:TG_SPLIT: " +
1120 getMCExprStr(MCKernelDescriptor::bits_get(
1121 CurrentProgramInfo.ComputePGMRSrc3,
1122 amdhsa::COMPUTE_PGM_RSRC3_GFX90A_TG_SPLIT_SHIFT,
1123 amdhsa::COMPUTE_PGM_RSRC3_GFX90A_TG_SPLIT, Ctx)),
1124 false);
1125 }
1126 }
1127
1128 if (DumpCodeInstEmitter) {
1129
1130 OutStreamer->switchSection(
1131 Context.getELFSection(".AMDGPU.disasm", ELF::SHT_PROGBITS, 0));
1132
1133 for (size_t i = 0; i < DisasmLines.size(); ++i) {
1134 std::string Comment = "\n";
1135 if (!HexLines[i].empty()) {
1136 Comment = std::string(DisasmLineMaxLen - DisasmLines[i].size(), ' ');
1137 Comment += " ; " + HexLines[i] + "\n";
1138 }
1139
1140 OutStreamer->emitBytes(StringRef(DisasmLines[i]));
1141 OutStreamer->emitBytes(StringRef(Comment));
1142 }
1143 }
1144
1145 return false;
1146}
1147
1148// When appropriate, add a _dvgpr$ symbol, with the value of the function
1149// symbol, plus an offset encoding one less than the number of VGPR blocks used
1150// by the function in bits 5..3 of the symbol value. A "VGPR block" can be
1151// either 16 VGPRs (for a max of 128), or 32 VGPRs (for a max of 256). This is
1152// used by a front-end to have functions that are chained rather than called,
1153// and a dispatcher that dynamically resizes the VGPR count before dispatching
1154// to a function.
1155void AMDGPUAsmPrinter::emitDVgprSymbol(MachineFunction &MF) {
1157 if (MFI.isDynamicVGPREnabled() &&
1159 MCContext &Ctx = MF.getContext();
1160 unsigned BlockSize = MFI.getDynamicVGPRBlockSize();
1161
1162 const MCExpr *EncodedBlocks;
1163 MCValue NumVGPRs;
1164 if (CurrentProgramInfo.NumVGPRsForWavesPerEU->evaluateAsRelocatable(
1165 NumVGPRs, nullptr) &&
1166 NumVGPRs.isAbsolute()) {
1167
1168 // Calculate number of VGPR blocks.
1169 // Treat 0 VGPRs as 1 VGPR to avoid underflowing.
1170 unsigned NumBlocks =
1171 divideCeil(std::max(unsigned(NumVGPRs.getConstant()), 1U), BlockSize);
1172
1173 if (NumBlocks > AMDGPU::IsaInfo::MaxDynamicVGPRBlocks) {
1175 {}, "DVGPR block count " + Twine(NumBlocks) +
1176 " exceeds maximum of " +
1178 " for __dvgpr$ symbol for '" +
1179 Twine(CurrentFnSym->getName()) + "'");
1180 return;
1181 }
1182 unsigned EncodedNumBlocks = (NumBlocks - 1) << 3;
1183 EncodedBlocks = MCConstantExpr::create(EncodedNumBlocks, Ctx);
1184 } else {
1185 // Value not yet available so build a symbolic MCExpr:
1186 // ((alignTo(max(NumVGPRs, 1), BlockSize) / BlockSize - 1) << 3
1187 const MCExpr *One = MCConstantExpr::create(1, Ctx);
1188 const MCExpr *BlockSizeConst = MCConstantExpr::create(BlockSize, Ctx);
1189 const MCExpr *MaxVGPRs = AMDGPUMCExpr::createMax(
1190 {CurrentProgramInfo.NumVGPRsForWavesPerEU, One}, Ctx);
1191 const MCExpr *NumBlocks = MCBinaryExpr::createDiv(
1192 AMDGPUMCExpr::createAlignTo(MaxVGPRs, BlockSizeConst, Ctx),
1193 BlockSizeConst, Ctx);
1194 EncodedBlocks =
1196 MCConstantExpr::create(3, Ctx), Ctx);
1197 }
1198
1199 // Add to function symbol to create _dvgpr$ symbol.
1200 const MCExpr *DVgprFuncVal = MCBinaryExpr::createAdd(
1201 MCSymbolRefExpr::create(CurrentFnSym, Ctx), EncodedBlocks, Ctx);
1202 MCSymbol *DVgprFuncSym =
1203 Ctx.getOrCreateSymbol(Twine("_dvgpr$") + CurrentFnSym->getName());
1204 OutStreamer->emitAssignment(DVgprFuncSym, DVgprFuncVal);
1205 emitVisibility(DVgprFuncSym, MF.getFunction().getVisibility());
1206 emitLinkage(&MF.getFunction(), DVgprFuncSym);
1207 }
1208}
1209
1210// TODO: Fold this into emitFunctionBodyStart.
1211void AMDGPUAsmPrinter::initializeTargetID(const Module &M) {
1213
1214 auto &TSTargetID = getTargetStreamer()->getTargetID();
1215
1216 // Error if -mattr specified xnack or sramecc.
1217 // TODO: Remove this when subtarget features removed.
1218 StringRef FeatureString = getGlobalSTI()->getFeatureString();
1219 if (FeatureString.contains("xnack")) {
1220 M.getContext().diagnose(DiagnosticInfoGeneric(
1221 "xnack/sramecc should be specified via module flags. "
1222 "Use module flag 'amdgpu.xnack' instead of subtarget feature",
1223 DS_Error));
1224 }
1225 if (FeatureString.contains("sramecc")) {
1226 M.getContext().diagnose(DiagnosticInfoGeneric(
1227 "xnack/sramecc should be specified via module flags. "
1228 "Use module flag 'amdgpu.sramecc' instead of subtarget feature",
1229 DS_Error));
1230 }
1231
1232 // Apply xnack/sramecc settings from module flags.
1233 const auto &GCNTM = static_cast<const GCNTargetMachine &>(TM);
1234 if (getGlobalSTI()->getFeatureBits().test(AMDGPU::FeatureXNACKOnOffModes)) {
1235 AMDGPU::TargetIDSetting Setting =
1236 GCNTM.getTargetIDSettingFromModuleFlag(M, "amdgpu.xnack");
1237 if (Setting != AMDGPU::TargetIDSetting::Any)
1238 TSTargetID->setXnackSetting(Setting);
1239 }
1240
1241 if (getGlobalSTI()->getFeatureBits().test(AMDGPU::FeatureSRAMECCOnOffModes)) {
1242 AMDGPU::TargetIDSetting Setting =
1243 GCNTM.getTargetIDSettingFromModuleFlag(M, "amdgpu.sramecc");
1244 if (Setting != AMDGPU::TargetIDSetting::Any)
1245 TSTargetID->setSramEccSetting(Setting);
1246 }
1247}
1248
1249// AccumOffset computed for the MCExpr equivalent of:
1250// alignTo(std::max(1, NumVGPR), 4) / 4 - 1;
1251static const MCExpr *computeAccumOffset(const MCExpr *NumVGPR, MCContext &Ctx) {
1252 const MCExpr *ConstFour = MCConstantExpr::create(4, Ctx);
1253 const MCExpr *ConstOne = MCConstantExpr::create(1, Ctx);
1254
1255 // Can't be lower than 1 for subsequent alignTo.
1256 const MCExpr *MaximumTaken =
1257 AMDGPUMCExpr::createMax({ConstOne, NumVGPR}, Ctx);
1258
1259 // Practically, it's computing divideCeil(MaximumTaken, 4).
1260 const MCExpr *DivCeil = MCBinaryExpr::createDiv(
1261 AMDGPUMCExpr::createAlignTo(MaximumTaken, ConstFour, Ctx), ConstFour,
1262 Ctx);
1263
1264 return MCBinaryExpr::createSub(DivCeil, ConstOne, Ctx);
1265}
1266
1267static unsigned getLDSEncodingGranule(const GCNSubtarget &ST) {
1268 unsigned Granule =
1269 AMDGPU::getLDSEncodingGranule(ST.getTargetID().getGPUKind());
1270 // The legacy generic targets have no encoding granularity feature. Preserve
1271 // the default used for code generation when no GPU is specified.
1272 return Granule ? Granule : 256;
1273}
1274
1275void AMDGPUAsmPrinter::getSIProgramInfo(SIProgramInfo &ProgInfo,
1276 const MachineFunction &MF) {
1277 const GCNSubtarget &STM = MF.getSubtarget<GCNSubtarget>();
1278 MCContext &Ctx = MF.getContext();
1279
1280 auto CreateExpr = [&Ctx](int64_t Value) {
1281 return MCConstantExpr::create(Value, Ctx);
1282 };
1283
1284 auto TryGetMCExprValue = [](const MCExpr *Value, uint64_t &Res) -> bool {
1285 int64_t Val;
1286 if (Value->evaluateAsAbsolute(Val)) {
1287 Res = Val;
1288 return true;
1289 }
1290 return false;
1291 };
1292
1293 auto GetSymRefExpr =
1294 [&](MCResourceInfo::ResourceInfoKind RIK) -> const MCExpr * {
1295 MCSymbol *Sym = RI.getSymbol(CurrentFnSym->getName(), RIK, OutContext);
1296 return MCSymbolRefExpr::create(Sym, Ctx);
1297 };
1298
1300 ProgInfo.NumArchVGPR = GetSymRefExpr(RIK::RIK_NumVGPR);
1301 ProgInfo.NumAccVGPR = GetSymRefExpr(RIK::RIK_NumAGPR);
1303 ProgInfo.NumAccVGPR, ProgInfo.NumArchVGPR, Ctx);
1304
1305 ProgInfo.AccumOffset = computeAccumOffset(ProgInfo.NumArchVGPR, Ctx);
1306 ProgInfo.TgSplit =
1307 STM.hasTgSplitSupport() && AMDGPU::isTgSplitEnabled(MF.getFunction());
1308 ProgInfo.NumSGPR = GetSymRefExpr(RIK::RIK_NumSGPR);
1309 ProgInfo.ScratchSize = GetSymRefExpr(RIK::RIK_PrivateSegSize);
1310 ProgInfo.VCCUsed = GetSymRefExpr(RIK::RIK_UsesVCC);
1311 ProgInfo.FlatUsed = GetSymRefExpr(RIK::RIK_UsesFlatScratch);
1312 ProgInfo.DynamicCallStack =
1313 MCBinaryExpr::createOr(GetSymRefExpr(RIK::RIK_HasDynSizedStack),
1314 GetSymRefExpr(RIK::RIK_HasRecursion), Ctx);
1315
1316 const MCExpr *BarBlkConst = MCConstantExpr::create(4, Ctx);
1317 const MCExpr *AlignToBlk = AMDGPUMCExpr::createAlignTo(
1318 GetSymRefExpr(RIK::RIK_NumNamedBarrier), BarBlkConst, Ctx);
1319 ProgInfo.NamedBarCnt = MCBinaryExpr::createDiv(AlignToBlk, BarBlkConst, Ctx);
1320
1321 const SIMachineFunctionInfo *MFI = MF.getInfo<SIMachineFunctionInfo>();
1322
1323 // The calculations related to SGPR/VGPR blocks are
1324 // duplicated in part in AMDGPUAsmParser::calculateGPRBlocks, and could be
1325 // unified.
1326 const MCExpr *ExtraSGPRs = AMDGPUMCExpr::createExtraSGPRs(
1327 ProgInfo.VCCUsed, ProgInfo.FlatUsed,
1328 getTargetStreamer()->getTargetID()->isXnackOnOrAny(), Ctx);
1329
1330 // Check the addressable register limit before we add ExtraSGPRs.
1332 !STM.hasSGPRInitBug()) {
1333 unsigned MaxAddressableNumSGPRs = STM.getAddressableNumSGPRs();
1334 uint64_t NumSgpr;
1335 if (TryGetMCExprValue(ProgInfo.NumSGPR, NumSgpr) &&
1336 NumSgpr > MaxAddressableNumSGPRs) {
1337 // This can happen due to a compiler bug or when using inline asm.
1338 LLVMContext &Ctx = MF.getFunction().getContext();
1339 Ctx.diagnose(DiagnosticInfoResourceLimit(
1340 MF.getFunction(), "addressable scalar registers", NumSgpr,
1341 MaxAddressableNumSGPRs, DS_Error, DK_ResourceLimit));
1342 ProgInfo.NumSGPR = CreateExpr(MaxAddressableNumSGPRs - 1);
1343 }
1344 }
1345
1346 // Account for extra SGPRs and VGPRs reserved for debugger use.
1347 ProgInfo.NumSGPR = MCBinaryExpr::createAdd(ProgInfo.NumSGPR, ExtraSGPRs, Ctx);
1348
1349 const Function &F = MF.getFunction();
1350
1351 // Ensure there are enough SGPRs and VGPRs for wave dispatch, where wave
1352 // dispatch registers as function args.
1353 unsigned WaveDispatchNumSGPR = MFI->getNumWaveDispatchSGPRs(),
1354 WaveDispatchNumVGPR = MFI->getNumWaveDispatchVGPRs();
1355
1356 if (WaveDispatchNumSGPR) {
1358 {ProgInfo.NumSGPR,
1359 MCBinaryExpr::createAdd(CreateExpr(WaveDispatchNumSGPR), ExtraSGPRs,
1360 Ctx)},
1361 Ctx);
1362 }
1363
1364 if (WaveDispatchNumVGPR) {
1366 {ProgInfo.NumArchVGPR, CreateExpr(WaveDispatchNumVGPR)}, Ctx);
1367
1369 ProgInfo.NumAccVGPR, ProgInfo.NumArchVGPR, Ctx);
1370 }
1371
1372 // Adjust number of registers used to meet default/requested minimum/maximum
1373 // number of waves per execution unit request.
1374 unsigned MaxWaves = MFI->getMaxWavesPerEU();
1375 ProgInfo.NumSGPRsForWavesPerEU =
1376 AMDGPUMCExpr::createMax({ProgInfo.NumSGPR, CreateExpr(1ul),
1377 CreateExpr(STM.getMinNumSGPRs(MaxWaves))},
1378 Ctx);
1379 ProgInfo.NumVGPRsForWavesPerEU =
1380 AMDGPUMCExpr::createMax({ProgInfo.NumVGPR, CreateExpr(1ul),
1381 CreateExpr(STM.getMinNumVGPRs(
1382 MaxWaves, MFI->getDynamicVGPRBlockSize()))},
1383 Ctx);
1384
1386 STM.hasSGPRInitBug()) {
1387 unsigned MaxAddressableNumSGPRs = STM.getAddressableNumSGPRs();
1388 uint64_t NumSgpr;
1389 if (TryGetMCExprValue(ProgInfo.NumSGPR, NumSgpr) &&
1390 NumSgpr > MaxAddressableNumSGPRs) {
1391 // This can happen due to a compiler bug or when using inline asm to use
1392 // the registers which are usually reserved for vcc etc.
1393 LLVMContext &Ctx = MF.getFunction().getContext();
1394 Ctx.diagnose(DiagnosticInfoResourceLimit(
1395 MF.getFunction(), "scalar registers", NumSgpr, MaxAddressableNumSGPRs,
1397 ProgInfo.NumSGPR = CreateExpr(MaxAddressableNumSGPRs);
1398 ProgInfo.NumSGPRsForWavesPerEU = CreateExpr(MaxAddressableNumSGPRs);
1399 }
1400 }
1401
1402 if (STM.hasSGPRInitBug()) {
1403 ProgInfo.NumSGPR =
1405 ProgInfo.NumSGPRsForWavesPerEU =
1407 }
1408
1409 if (MFI->getNumUserSGPRs() > STM.getMaxNumUserSGPRs()) {
1410 LLVMContext &Ctx = MF.getFunction().getContext();
1411 Ctx.diagnose(DiagnosticInfoResourceLimit(
1412 MF.getFunction(), "user SGPRs", MFI->getNumUserSGPRs(),
1414 }
1415
1416 if (MFI->getLDSSize() > STM.getAddressableLocalMemorySize()) {
1417 LLVMContext &Ctx = MF.getFunction().getContext();
1418 Ctx.diagnose(DiagnosticInfoResourceLimit(
1419 MF.getFunction(), "local memory", MFI->getLDSSize(),
1421 }
1422
1423 // When dynamic VGPRs are enabled, entry functions are launched with a single
1424 // VGPR block. The register allocator enforces this constraint, but we also
1425 // need to catch explicit physical registers in inline asm and wave dispatch
1426 // VGPR arguments.
1427 if (MFI->isDynamicVGPREnabled() &&
1428 AMDGPU::isEntryFunctionCC(F.getCallingConv())) {
1429 unsigned BlockSize = MFI->getDynamicVGPRBlockSize();
1430 uint64_t NumVgpr;
1431 if (TryGetMCExprValue(ProgInfo.NumVGPRsForWavesPerEU, NumVgpr) &&
1432 NumVgpr > BlockSize) {
1433 LLVMContext &Ctx = F.getContext();
1434 Ctx.diagnose(DiagnosticInfoResourceLimit(
1435 F, "dynamic VGPR entry point vector registers", NumVgpr, BlockSize,
1437 }
1438 }
1439
1440 // The MCExpr equivalent of getNumSGPRBlocks/getNumVGPRBlocks:
1441 // (alignTo(max(1u, NumGPR), GPREncodingGranule) / GPREncodingGranule) - 1
1442 auto GetNumGPRBlocks = [&CreateExpr, &Ctx](const MCExpr *NumGPR,
1443 unsigned Granule) {
1444 const MCExpr *OneConst = CreateExpr(1ul);
1445 const MCExpr *GranuleConst = CreateExpr(Granule);
1446 const MCExpr *MaxNumGPR = AMDGPUMCExpr::createMax({NumGPR, OneConst}, Ctx);
1447 const MCExpr *AlignToGPR =
1448 AMDGPUMCExpr::createAlignTo(MaxNumGPR, GranuleConst, Ctx);
1449 const MCExpr *DivGPR =
1450 MCBinaryExpr::createDiv(AlignToGPR, GranuleConst, Ctx);
1451 const MCExpr *SubGPR = MCBinaryExpr::createSub(DivGPR, OneConst, Ctx);
1452 return SubGPR;
1453 };
1454 // GFX10+ will always allocate 128 SGPRs and this field must be 0
1456 ProgInfo.SGPRBlocks = CreateExpr(0ul);
1457 } else {
1458 ProgInfo.SGPRBlocks = GetNumGPRBlocks(ProgInfo.NumSGPRsForWavesPerEU,
1460 }
1461 ProgInfo.VGPRBlocks = GetNumGPRBlocks(ProgInfo.NumVGPRsForWavesPerEU,
1463
1464 const SIModeRegisterDefaults Mode = MFI->getMode();
1465
1466 // Set the value to initialize FP_ROUND and FP_DENORM parts of the mode
1467 // register.
1468 ProgInfo.FloatMode = getFPMode(Mode);
1469
1470 ProgInfo.IEEEMode = Mode.IEEE;
1471
1472 // Make clamp modifier on NaN input returns 0.
1473 ProgInfo.DX10Clamp = Mode.DX10Clamp;
1474 ProgInfo.SGPRSpill = MFI->getNumSpilledSGPRs();
1475 ProgInfo.VGPRSpill = MFI->getNumSpilledVGPRs();
1476
1477 ProgInfo.LDSSize = MFI->getLDSSize();
1478
1479 unsigned LDSGranularityBytes = getLDSEncodingGranule(STM);
1480 ProgInfo.LDSBlocks =
1481 alignTo(ProgInfo.LDSSize, LDSGranularityBytes) / LDSGranularityBytes;
1482
1483 // The MCExpr equivalent of divideCeil.
1484 auto DivideCeil = [&Ctx](const MCExpr *Numerator, const MCExpr *Denominator) {
1485 const MCExpr *Ceil =
1486 AMDGPUMCExpr::createAlignTo(Numerator, Denominator, Ctx);
1487 return MCBinaryExpr::createDiv(Ceil, Denominator, Ctx);
1488 };
1489
1490 // Scratch is allocated in 64-dword or 256-dword blocks.
1491 unsigned ScratchAlignShift =
1492 STM.getGeneration() >= AMDGPUSubtarget::GFX11 ? 8 : 10;
1493 // We need to program the hardware with the amount of scratch memory that
1494 // is used by the entire wave. ProgInfo.ScratchSize is the amount of
1495 // scratch memory used per thread.
1496 ProgInfo.ScratchBlocks = DivideCeil(
1498 CreateExpr(STM.getWavefrontSize()), Ctx),
1499 CreateExpr(1ULL << ScratchAlignShift));
1500
1501 if (STM.hasSupportsWGP()) {
1502 ProgInfo.WgpMode = STM.isCuModeEnabled() ? 0 : 1;
1503 }
1504
1505 if (getIsaVersion(getGlobalSTI()->getCPU()).Major >= 10) {
1506 ProgInfo.MemOrdered = 1;
1507 ProgInfo.FwdProgress = !F.hasFnAttribute("amdgpu-no-fwd-progress");
1508 }
1509
1510 // 0 = X, 1 = XY, 2 = XYZ
1511 unsigned TIDIGCompCnt = 0;
1512 if (MFI->hasWorkItemIDZ())
1513 TIDIGCompCnt = 2;
1514 else if (MFI->hasWorkItemIDY())
1515 TIDIGCompCnt = 1;
1516
1517 // The private segment wave byte offset is the last of the system SGPRs. We
1518 // initially assumed it was allocated, and may have used it. It shouldn't harm
1519 // anything to disable it if we know the stack isn't used here. We may still
1520 // have emitted code reading it to initialize scratch, but if that's unused
1521 // reading garbage should be OK.
1524 MCConstantExpr::create(0, Ctx), Ctx),
1525 ProgInfo.DynamicCallStack, Ctx);
1526
1527 ProgInfo.UserSGPR = MFI->getNumUserSGPRs();
1528 // For AMDHSA, TRAP_HANDLER must be zero, as it is populated by the CP.
1529 ProgInfo.TrapHandlerEnable = STM.isAmdHsaOS() ? 0 : STM.hasTrapHandler();
1530 ProgInfo.TGIdXEnable = MFI->hasWorkGroupIDX();
1531 ProgInfo.TGIdYEnable = MFI->hasWorkGroupIDY();
1532 ProgInfo.TGIdZEnable = MFI->hasWorkGroupIDZ();
1533 ProgInfo.TGSizeEnable = MFI->hasWorkGroupInfo();
1534 ProgInfo.TIdIGCompCount = TIDIGCompCnt;
1535 ProgInfo.EXCPEnMSB = 0;
1536 // For AMDHSA, LDS_SIZE must be zero, as it is populated by the CP.
1537 ProgInfo.LdsSize = STM.isAmdHsaOS() ? 0 : ProgInfo.LDSBlocks;
1538 ProgInfo.EXCPEnable = 0;
1539
1540 if (STM.hasGFX90AInsts()) {
1541 ProgInfo.ComputePGMRSrc3 =
1542 setBits(ProgInfo.ComputePGMRSrc3, ProgInfo.AccumOffset,
1543 amdhsa::COMPUTE_PGM_RSRC3_GFX90A_ACCUM_OFFSET,
1544 amdhsa::COMPUTE_PGM_RSRC3_GFX90A_ACCUM_OFFSET_SHIFT, Ctx);
1545 ProgInfo.ComputePGMRSrc3 =
1546 setBits(ProgInfo.ComputePGMRSrc3, CreateExpr(ProgInfo.TgSplit),
1547 amdhsa::COMPUTE_PGM_RSRC3_GFX90A_TG_SPLIT,
1548 amdhsa::COMPUTE_PGM_RSRC3_GFX90A_TG_SPLIT_SHIFT, Ctx);
1549 }
1550
1551 if (STM.hasGFX1250Insts())
1552 ProgInfo.ComputePGMRSrc3 =
1553 setBits(ProgInfo.ComputePGMRSrc3, ProgInfo.NamedBarCnt,
1554 amdhsa::COMPUTE_PGM_RSRC3_GFX125_NAMED_BAR_CNT,
1555 amdhsa::COMPUTE_PGM_RSRC3_GFX125_NAMED_BAR_CNT_SHIFT, Ctx);
1556
1557 ProgInfo.Occupancy = createOccupancy(
1560 MFI->getDynamicVGPRBlockSize(), STM, Ctx);
1561
1562 const auto [MinWEU, MaxWEU] =
1563 AMDGPU::getIntegerPairAttribute(F, "amdgpu-waves-per-eu", {0, 0}, true);
1564 uint64_t Occupancy;
1565 if (TryGetMCExprValue(ProgInfo.Occupancy, Occupancy) && Occupancy < MinWEU) {
1566 DiagnosticInfoOptimizationFailure Diag(
1567 F, F.getSubprogram(),
1568 "failed to meet occupancy target given by 'amdgpu-waves-per-eu' in "
1569 "'" +
1570 F.getName() + "': desired occupancy was " + Twine(MinWEU) +
1571 ", final occupancy is " + Twine(Occupancy));
1572 F.getContext().diagnose(Diag);
1573 }
1574}
1575
1576static unsigned getRsrcReg(CallingConv::ID CallConv) {
1577 switch (CallConv) {
1578 default:
1579 [[fallthrough]];
1594 }
1595}
1596
1597void AMDGPUAsmPrinter::EmitProgramInfoSI(
1598 const MachineFunction &MF, const SIProgramInfo &CurrentProgramInfo) {
1599 const SIMachineFunctionInfo *MFI = MF.getInfo<SIMachineFunctionInfo>();
1600 const GCNSubtarget &STM = MF.getSubtarget<GCNSubtarget>();
1601 unsigned RsrcReg = getRsrcReg(MF.getFunction().getCallingConv());
1602 MCContext &Ctx = MF.getContext();
1603
1604 // (((Value) & Mask) << Shift)
1605 auto SetBits = [&Ctx](const MCExpr *Value, uint32_t Mask, uint32_t Shift) {
1606 const MCExpr *msk = MCConstantExpr::create(Mask, Ctx);
1607 const MCExpr *shft = MCConstantExpr::create(Shift, Ctx);
1609 shft, Ctx);
1610 };
1611
1612 auto EmitResolvedOrExpr = [this](const MCExpr *Value, unsigned Size) {
1613 int64_t Val;
1614 if (Value->evaluateAsAbsolute(Val))
1615 OutStreamer->emitIntValue(static_cast<uint64_t>(Val), Size);
1616 else
1617 OutStreamer->emitValue(Value, Size);
1618 };
1619
1620 if (AMDGPU::isCompute(MF.getFunction().getCallingConv())) {
1622
1623 EmitResolvedOrExpr(CurrentProgramInfo.getComputePGMRSrc1(STM, Ctx),
1624 /*Size=*/4);
1625
1627 EmitResolvedOrExpr(CurrentProgramInfo.getComputePGMRSrc2(STM, Ctx),
1628 /*Size=*/4);
1629
1631
1632 // Sets bits according to S_0286E8_WAVESIZE_* mask and shift values for the
1633 // appropriate generation.
1634 if (STM.getGeneration() >= AMDGPUSubtarget::GFX12) {
1635 EmitResolvedOrExpr(SetBits(CurrentProgramInfo.ScratchBlocks,
1636 /*Mask=*/0x3FFFF, /*Shift=*/12),
1637 /*Size=*/4);
1638 } else if (STM.getGeneration() == AMDGPUSubtarget::GFX11) {
1639 EmitResolvedOrExpr(SetBits(CurrentProgramInfo.ScratchBlocks,
1640 /*Mask=*/0x7FFF, /*Shift=*/12),
1641 /*Size=*/4);
1642 } else {
1643 EmitResolvedOrExpr(SetBits(CurrentProgramInfo.ScratchBlocks,
1644 /*Mask=*/0x1FFF, /*Shift=*/12),
1645 /*Size=*/4);
1646 }
1647
1648 // TODO: Should probably note flat usage somewhere. SC emits a "FlatPtr32 =
1649 // 0" comment but I don't see a corresponding field in the register spec.
1650 } else {
1651 OutStreamer->emitInt32(RsrcReg);
1652
1653 const MCExpr *GPRBlocks = MCBinaryExpr::createOr(
1654 SetBits(CurrentProgramInfo.VGPRBlocks, /*Mask=*/0x3F, /*Shift=*/0),
1655 SetBits(CurrentProgramInfo.SGPRBlocks, /*Mask=*/0x0F, /*Shift=*/6),
1656 MF.getContext());
1657 EmitResolvedOrExpr(GPRBlocks, /*Size=*/4);
1659
1660 // Sets bits according to S_0286E8_WAVESIZE_* mask and shift values for the
1661 // appropriate generation.
1662 if (STM.getGeneration() >= AMDGPUSubtarget::GFX12) {
1663 EmitResolvedOrExpr(SetBits(CurrentProgramInfo.ScratchBlocks,
1664 /*Mask=*/0x3FFFF, /*Shift=*/12),
1665 /*Size=*/4);
1666 } else if (STM.getGeneration() == AMDGPUSubtarget::GFX11) {
1667 EmitResolvedOrExpr(SetBits(CurrentProgramInfo.ScratchBlocks,
1668 /*Mask=*/0x7FFF, /*Shift=*/12),
1669 /*Size=*/4);
1670 } else {
1671 EmitResolvedOrExpr(SetBits(CurrentProgramInfo.ScratchBlocks,
1672 /*Mask=*/0x1FFF, /*Shift=*/12),
1673 /*Size=*/4);
1674 }
1675 }
1676
1677 if (MF.getFunction().getCallingConv() == CallingConv::AMDGPU_PS) {
1679 unsigned ExtraLDSSize = STM.getGeneration() >= AMDGPUSubtarget::GFX11
1680 ? divideCeil(CurrentProgramInfo.LDSBlocks, 2)
1681 : CurrentProgramInfo.LDSBlocks;
1682 OutStreamer->emitInt32(S_00B02C_EXTRA_LDS_SIZE(ExtraLDSSize));
1684 OutStreamer->emitInt32(MFI->getPSInputEnable());
1686 OutStreamer->emitInt32(MFI->getPSInputAddr());
1687 }
1688
1689 OutStreamer->emitInt32(R_SPILLED_SGPRS);
1690 OutStreamer->emitInt32(MFI->getNumSpilledSGPRs());
1691 OutStreamer->emitInt32(R_SPILLED_VGPRS);
1692 OutStreamer->emitInt32(MFI->getNumSpilledVGPRs());
1693}
1694
1695// Helper function to add common PAL Metadata 3.0+
1697 const SIProgramInfo &CurrentProgramInfo,
1698 CallingConv::ID CC, const GCNSubtarget &ST,
1699 unsigned DynamicVGPRBlockSize) {
1700 if (ST.hasFeature(AMDGPU::FeatureDX10ClampAndIEEEMode))
1701 MD->setHwStage(CC, ".ieee_mode", (bool)CurrentProgramInfo.IEEEMode);
1702
1703 MD->setHwStage(CC, ".wgp_mode", (bool)CurrentProgramInfo.WgpMode);
1704 MD->setHwStage(CC, ".mem_ordered", (bool)CurrentProgramInfo.MemOrdered);
1705 MD->setHwStage(CC, ".forward_progress", (bool)CurrentProgramInfo.FwdProgress);
1706
1707 if (AMDGPU::isCompute(CC)) {
1708 MD->setHwStage(CC, ".trap_present",
1709 (bool)CurrentProgramInfo.TrapHandlerEnable);
1710 MD->setHwStage(CC, ".excp_en", CurrentProgramInfo.EXCPEnable);
1711
1712 if (DynamicVGPRBlockSize != 0)
1713 MD->setComputeRegisters(".dynamic_vgpr_en", true);
1714 }
1715
1717 CC, ".lds_size",
1718 (unsigned)(CurrentProgramInfo.LdsSize * getLDSEncodingGranule(ST)));
1719}
1720
1721// This is the equivalent of EmitProgramInfoSI above, but for when the OS type
1722// is AMDPAL. It stores each compute/SPI register setting and other PAL
1723// metadata items into the PALMD::Metadata, combining with any provided by the
1724// frontend as LLVM metadata. Once all functions are written, the PAL metadata
1725// is then written as a single block in the .note section.
1726void AMDGPUAsmPrinter::EmitPALMetadata(
1727 const MachineFunction &MF, const SIProgramInfo &CurrentProgramInfo) {
1728 const SIMachineFunctionInfo *MFI = MF.getInfo<SIMachineFunctionInfo>();
1729 auto CC = MF.getFunction().getCallingConv();
1730 auto *MD = getTargetStreamer()->getPALMetadata();
1731 auto &Ctx = MF.getContext();
1732
1733 MD->setEntryPoint(CC, MF.getFunction().getName());
1734 MD->setNumUsedVgprs(CC, CurrentProgramInfo.NumVGPRsForWavesPerEU, Ctx);
1735
1736 // For targets that support dynamic VGPRs, set the number of saved dynamic
1737 // VGPRs (if any) in the PAL metadata.
1738 const GCNSubtarget &STM = MF.getSubtarget<GCNSubtarget>();
1739 if (MFI->isDynamicVGPREnabled() &&
1741 MD->setHwStage(CC, ".dynamic_vgpr_saved_count",
1743
1744 // Only set AGPRs for supported devices
1745 if (STM.hasMAIInsts()) {
1746 MD->setNumUsedAgprs(CC, CurrentProgramInfo.NumAccVGPR);
1747 }
1748
1749 MD->setNumUsedSgprs(CC, CurrentProgramInfo.NumSGPRsForWavesPerEU, Ctx);
1750 if (MD->getPALMajorVersion() < 3) {
1751 MD->setRsrc1(CC, CurrentProgramInfo.getPGMRSrc1(CC, STM, Ctx), Ctx);
1752 if (AMDGPU::isCompute(CC)) {
1753 MD->setRsrc2(CC, CurrentProgramInfo.getComputePGMRSrc2(STM, Ctx), Ctx);
1754 } else {
1755 const MCExpr *HasScratchBlocks =
1756 MCBinaryExpr::createGT(CurrentProgramInfo.ScratchBlocks,
1757 MCConstantExpr::create(0, Ctx), Ctx);
1758 auto [Shift, Mask] = getShiftMask(C_00B84C_SCRATCH_EN);
1759 MD->setRsrc2(CC, maskShiftSet(HasScratchBlocks, Mask, Shift, Ctx), Ctx);
1760 }
1761 } else {
1762 MD->setHwStage(CC, ".debug_mode", (bool)CurrentProgramInfo.DebugMode);
1763 MD->setHwStage(CC, ".scratch_en", msgpack::Type::Boolean,
1764 CurrentProgramInfo.ScratchEnable);
1765 EmitPALMetadataCommon(MD, CurrentProgramInfo, CC, STM,
1767 }
1768
1769 // ScratchSize is in bytes, 16 aligned.
1770 MD->setScratchSize(
1771 CC,
1772 AMDGPUMCExpr::createAlignTo(CurrentProgramInfo.ScratchSize,
1773 MCConstantExpr::create(16, Ctx), Ctx),
1774 Ctx);
1775
1776 if (MF.getFunction().getCallingConv() == CallingConv::AMDGPU_PS) {
1777 unsigned ExtraLDSSize = STM.getGeneration() >= AMDGPUSubtarget::GFX11
1778 ? divideCeil(CurrentProgramInfo.LDSBlocks, 2)
1779 : CurrentProgramInfo.LDSBlocks;
1780 if (MD->getPALMajorVersion() < 3) {
1781 MD->setRsrc2(
1782 CC,
1784 Ctx);
1785 MD->setSpiPsInputEna(MFI->getPSInputEnable());
1786 MD->setSpiPsInputAddr(MFI->getPSInputAddr());
1787 } else {
1788 // Graphics registers
1789 const unsigned ExtraLdsDwGranularity =
1790 STM.getGeneration() >= AMDGPUSubtarget::GFX11 ? 256 : 128;
1791 MD->setGraphicsRegisters(
1792 ".ps_extra_lds_size",
1793 (unsigned)(ExtraLDSSize * ExtraLdsDwGranularity * sizeof(uint32_t)));
1794
1795 // Set PsInputEna and PsInputAddr .spi_ps_input_ena and .spi_ps_input_addr
1796 static StringLiteral const PsInputFields[] = {
1797 ".persp_sample_ena", ".persp_center_ena",
1798 ".persp_centroid_ena", ".persp_pull_model_ena",
1799 ".linear_sample_ena", ".linear_center_ena",
1800 ".linear_centroid_ena", ".line_stipple_tex_ena",
1801 ".pos_x_float_ena", ".pos_y_float_ena",
1802 ".pos_z_float_ena", ".pos_w_float_ena",
1803 ".front_face_ena", ".ancillary_ena",
1804 ".sample_coverage_ena", ".pos_fixed_pt_ena"};
1805 unsigned PSInputEna = MFI->getPSInputEnable();
1806 unsigned PSInputAddr = MFI->getPSInputAddr();
1807 for (auto [Idx, Field] : enumerate(PsInputFields)) {
1808 MD->setGraphicsRegisters(".spi_ps_input_ena", Field,
1809 (bool)((PSInputEna >> Idx) & 1));
1810 MD->setGraphicsRegisters(".spi_ps_input_addr", Field,
1811 (bool)((PSInputAddr >> Idx) & 1));
1812 }
1813 }
1814 }
1815
1816 // For version 3 and above the wave front size is already set in the metadata
1817 if (MD->getPALMajorVersion() < 3 && STM.isWave32())
1818 MD->setWave32(MF.getFunction().getCallingConv());
1819}
1820
1821void AMDGPUAsmPrinter::emitPALFunctionMetadata(const MachineFunction &MF) {
1822 auto *MD = getTargetStreamer()->getPALMetadata();
1823 const MachineFrameInfo &MFI = MF.getFrameInfo();
1824 StringRef FnName = MF.getFunction().getName();
1825 MD->setFunctionScratchSize(FnName, MFI.getStackSize());
1826 const GCNSubtarget &ST = MF.getSubtarget<GCNSubtarget>();
1827 MCContext &Ctx = MF.getContext();
1828
1829 if (MD->getPALMajorVersion() < 3) {
1830 // Set compute registers
1831 MD->setRsrc1(
1833 CurrentProgramInfo.getPGMRSrc1(CallingConv::AMDGPU_CS, ST, Ctx), Ctx);
1834 MD->setRsrc2(CallingConv::AMDGPU_CS,
1835 CurrentProgramInfo.getComputePGMRSrc2(ST, Ctx), Ctx);
1836 } else {
1838 MD, CurrentProgramInfo, CallingConv::AMDGPU_CS, ST,
1839 MF.getInfo<SIMachineFunctionInfo>()->getDynamicVGPRBlockSize());
1840 }
1841
1842 // Set optional info
1843 MD->setFunctionLdsSize(FnName, CurrentProgramInfo.LDSSize);
1844 MD->setFunctionNumUsedVgprs(FnName, CurrentProgramInfo.NumVGPRsForWavesPerEU);
1845 MD->setFunctionNumUsedSgprs(FnName, CurrentProgramInfo.NumSGPRsForWavesPerEU);
1846}
1847
1848// This is supposed to be log2(Size)
1850 switch (Size) {
1851 case 4:
1852 return AMD_ELEMENT_4_BYTES;
1853 case 8:
1854 return AMD_ELEMENT_8_BYTES;
1855 case 16:
1856 return AMD_ELEMENT_16_BYTES;
1857 default:
1858 llvm_unreachable("invalid private_element_size");
1859 }
1860}
1861
1862void AMDGPUAsmPrinter::getAmdKernelCode(AMDGPUMCKernelCodeT &Out,
1863 const SIProgramInfo &CurrentProgramInfo,
1864 const MachineFunction &MF) const {
1865 const Function &F = MF.getFunction();
1866 assert(F.getCallingConv() == CallingConv::AMDGPU_KERNEL ||
1867 F.getCallingConv() == CallingConv::SPIR_KERNEL);
1868
1869 const SIMachineFunctionInfo *MFI = MF.getInfo<SIMachineFunctionInfo>();
1870 const GCNSubtarget &STM = MF.getSubtarget<GCNSubtarget>();
1871 MCContext &Ctx = MF.getContext();
1872
1873 Out.initDefault(STM, Ctx, /*InitMCExpr=*/false);
1874
1875 Out.compute_pgm_resource1_registers =
1876 CurrentProgramInfo.getComputePGMRSrc1(STM, Ctx);
1877 Out.compute_pgm_resource2_registers =
1878 CurrentProgramInfo.getComputePGMRSrc2(STM, Ctx);
1879 Out.code_properties |= AMD_CODE_PROPERTY_IS_PTR64;
1880
1881 Out.is_dynamic_callstack = CurrentProgramInfo.DynamicCallStack;
1882
1884 getElementByteSizeValue(STM.getMaxPrivateElementSize(true)));
1885
1886 const GCNUserSGPRUsageInfo &UserSGPRInfo = MFI->getUserSGPRInfo();
1887 if (UserSGPRInfo.hasPrivateSegmentBuffer()) {
1889 }
1890
1891 if (UserSGPRInfo.hasDispatchPtr())
1893
1894 if (UserSGPRInfo.hasQueuePtr())
1896
1897 if (UserSGPRInfo.hasKernargSegmentPtr())
1899
1900 if (UserSGPRInfo.hasDispatchID())
1902
1903 if (UserSGPRInfo.hasFlatScratchInit())
1905
1906 if (UserSGPRInfo.hasPrivateSegmentSize())
1908
1909 if (STM.isXNACKEnabled())
1910 Out.code_properties |= AMD_CODE_PROPERTY_IS_XNACK_SUPPORTED;
1911
1912 Align MaxKernArgAlign;
1913 Out.kernarg_segment_byte_size = STM.getKernArgSegmentSize(F, MaxKernArgAlign);
1914 Out.wavefront_sgpr_count = CurrentProgramInfo.NumSGPR;
1915 Out.workitem_vgpr_count = CurrentProgramInfo.NumVGPR;
1916 Out.workitem_private_segment_byte_size = CurrentProgramInfo.ScratchSize;
1917 Out.workgroup_group_segment_byte_size = CurrentProgramInfo.LDSSize;
1918
1919 // kernarg_segment_alignment is specified as log of the alignment.
1920 // The minimum alignment is 16.
1921 // FIXME: The metadata treats the minimum as 4?
1922 Out.kernarg_segment_alignment =
1923 static_cast<uint8_t>(Log2(std::max(Align(16), MaxKernArgAlign)));
1924}
1925
1927 const char *ExtraCode, raw_ostream &O) {
1928 // First try the generic code, which knows about modifiers like 'c' and 'n'.
1929 if (!AsmPrinter::PrintAsmOperand(MI, OpNo, ExtraCode, O))
1930 return false;
1931
1932 if (ExtraCode && ExtraCode[0]) {
1933 if (ExtraCode[1] != 0)
1934 return true; // Unknown modifier.
1935
1936 switch (ExtraCode[0]) {
1937 case 'r':
1938 break;
1939 default:
1940 return true;
1941 }
1942 }
1943
1944 // TODO: Should be able to support other operand types like globals.
1945 const MachineOperand &MO = MI->getOperand(OpNo);
1946 if (MO.isReg()) {
1948 *MF->getSubtarget().getRegisterInfo());
1949 return false;
1950 }
1951 if (MO.isImm()) {
1952 int64_t Val = MO.getImm();
1954 O << Val;
1955 } else if (isUInt<16>(Val)) {
1956 O << format("0x%" PRIx16, static_cast<uint16_t>(Val));
1957 } else if (isUInt<32>(Val)) {
1958 O << format("0x%" PRIx32, static_cast<uint32_t>(Val));
1959 } else {
1960 O << format("0x%" PRIx64, static_cast<uint64_t>(Val));
1961 }
1962 return false;
1963 }
1964 return true;
1965}
1966
1968 unsigned OpNo,
1969 const char *ExtraCode,
1970 raw_ostream &OS) {
1971 const MachineOperand &MO = MI->getOperand(OpNo);
1973 *MF->getSubtarget().getRegisterInfo());
1974 return false;
1975}
1976
1984
1985void AMDGPUAsmPrinter::emitResourceUsageRemarks(
1986 const MachineFunction &MF, const SIProgramInfo &CurrentProgramInfo,
1987 bool isModuleEntryFunction, bool hasMAIInsts) {
1988 if (!ORE)
1989 return;
1990
1991 const char *Name = "kernel-resource-usage";
1992 const char *Indent = " ";
1993
1994 // If the remark is not specifically enabled, do not output to yaml
1996 if (!Ctx.getDiagHandlerPtr()->isAnalysisRemarkEnabled(Name))
1997 return;
1998
1999 // Currently non-kernel functions have no resources to emit.
2001 return;
2002
2003 auto EmitResourceUsageRemark = [&](StringRef RemarkName,
2004 StringRef RemarkLabel, auto Argument) {
2005 // Add an indent for every line besides the line with the kernel name. This
2006 // makes it easier to tell which resource usage go with which kernel since
2007 // the kernel name will always be displayed first.
2008 std::string LabelStr = RemarkLabel.str() + ": ";
2009 if (RemarkName != "FunctionName")
2010 LabelStr = Indent + LabelStr;
2011
2012 ORE->emit([&]() {
2013 return MachineOptimizationRemarkAnalysis(Name, RemarkName,
2015 &MF.front())
2016 << LabelStr << ore::NV(RemarkName, Argument);
2017 });
2018 };
2019
2020 // FIXME: Formatting here is pretty nasty because clang does not accept
2021 // newlines from diagnostics. This forces us to emit multiple diagnostic
2022 // remarks to simulate newlines. If and when clang does accept newlines, this
2023 // formatting should be aggregated into one remark with newlines to avoid
2024 // printing multiple diagnostic location and diag opts.
2025 EmitResourceUsageRemark("FunctionName", "Function Name",
2026 MF.getFunction().getName());
2027 EmitResourceUsageRemark("NumSGPR", "TotalSGPRs",
2028 getMCExprStr(CurrentProgramInfo.NumSGPR));
2029 EmitResourceUsageRemark("NumVGPR", "VGPRs",
2030 getMCExprStr(CurrentProgramInfo.NumArchVGPR));
2031 if (hasMAIInsts) {
2032 EmitResourceUsageRemark("NumAGPR", "AGPRs",
2033 getMCExprStr(CurrentProgramInfo.NumAccVGPR));
2034 }
2035 EmitResourceUsageRemark("ScratchSize", "ScratchSize [bytes/lane]",
2036 getMCExprStr(CurrentProgramInfo.ScratchSize));
2037 int64_t DynStack;
2038 bool DynStackEvaluatable =
2039 CurrentProgramInfo.DynamicCallStack->evaluateAsAbsolute(DynStack);
2040 StringRef DynamicStackStr =
2041 DynStackEvaluatable && DynStack ? "True" : "False";
2042 EmitResourceUsageRemark("DynamicStack", "Dynamic Stack", DynamicStackStr);
2043 EmitResourceUsageRemark("Occupancy", "Occupancy [waves/SIMD]",
2044 getMCExprStr(CurrentProgramInfo.Occupancy));
2045 EmitResourceUsageRemark("SGPRSpill", "SGPRs Spill",
2046 CurrentProgramInfo.SGPRSpill);
2047 EmitResourceUsageRemark("VGPRSpill", "VGPRs Spill",
2048 CurrentProgramInfo.VGPRSpill);
2049 if (isModuleEntryFunction)
2050 EmitResourceUsageRemark("BytesLDS", "LDS Size [bytes/block]",
2051 CurrentProgramInfo.LDSSize);
2052}
2053
2063
2079
2088
2089char AMDGPUAsmPrinter::ID = 0;
2090
2091INITIALIZE_PASS(AMDGPUAsmPrinter, "amdgpu-asm-printer",
2092 "AMDGPU Assembly Printer", false, false)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static void EmitPALMetadataCommon(AMDGPUPALMetadata *MD, const SIProgramInfo &CurrentProgramInfo, CallingConv::ID CC, const GCNSubtarget &ST, unsigned DynamicVGPRBlockSize)
const AMDGPUMCExpr * createOccupancy(unsigned InitOcc, const MCExpr *NumSGPRs, const MCExpr *NumVGPRs, unsigned DynamicVGPRBlockSize, const GCNSubtarget &STM, MCContext &Ctx)
Mimics GCNSubtarget::computeOccupancy for MCExpr.
static unsigned getRsrcReg(CallingConv::ID CallConv)
LLVM_ABI LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAMDGPUAsmPrinter()
static amd_element_byte_size_t getElementByteSizeValue(unsigned Size)
static const MCExpr * setBits(const MCExpr *Dst, const MCExpr *Value, uint32_t Mask, uint32_t Shift, MCContext &Ctx)
Set bits in a kernel descriptor MCExpr field: return ((Dst & ~Mask) | (Value << Shift))
static uint32_t getFPMode(SIModeRegisterDefaults Mode)
static std::string computeTypeId(const FunctionType *FTy, const DataLayout &DL)
static const MCExpr * computeAccumOffset(const MCExpr *NumVGPR, MCContext &Ctx)
static void appendTypeEncoding(std::string &Enc, Type *Ty, const DataLayout &DL, bool IsReturnType)
static AsmPrinter * createAMDGPUAsmPrinterPass(TargetMachine &tm, std::unique_ptr< MCStreamer > &&Streamer)
AMDGPU Assembly printer class.
uint64_t uint64_t
AMDGPU HSA Metadata Streamer.
AMDHSA kernel descriptor MCExpr struct for use in MC layer.
MC infrastructure to propagate the function level resource usage info.
Analyzes how many registers and other resources are used by functions.
The AMDGPU TargetMachine interface definition for hw codegen targets.
AMDHSA kernel descriptor definitions.
MC layer struct for AMDGPUMCKernelCodeT, provides MCExpr functionality where required.
amd_element_byte_size_t
The values used to define the number of bytes to use for the swizzle element size.
@ AMD_ELEMENT_8_BYTES
@ AMD_ELEMENT_16_BYTES
@ AMD_ELEMENT_4_BYTES
#define AMD_HSA_BITS_SET(dst, mask, val)
@ AMD_CODE_PROPERTY_ENABLE_SGPR_DISPATCH_ID
@ AMD_CODE_PROPERTY_PRIVATE_ELEMENT_SIZE
@ AMD_CODE_PROPERTY_ENABLE_SGPR_KERNARG_SEGMENT_PTR
@ AMD_CODE_PROPERTY_ENABLE_SGPR_QUEUE_PTR
@ AMD_CODE_PROPERTY_ENABLE_SGPR_PRIVATE_SEGMENT_SIZE
@ AMD_CODE_PROPERTY_ENABLE_SGPR_PRIVATE_SEGMENT_BUFFER
@ AMD_CODE_PROPERTY_ENABLE_SGPR_DISPATCH_PTR
@ AMD_CODE_PROPERTY_IS_XNACK_SUPPORTED
@ AMD_CODE_PROPERTY_ENABLE_SGPR_FLAT_SCRATCH_INIT
@ AMD_CODE_PROPERTY_IS_PTR64
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static const Function * getParent(const Value *V)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define LLVM_ABI
Definition Compiler.h:211
#define LLVM_EXTERNAL_VISIBILITY
Definition Compiler.h:132
AMD GCN specific subclass of TargetSubtarget.
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
===- MachineOptimizationRemarkEmitter.h - Opt Diagnostics -*- C++ -*-—===//
modulo schedule test
OptimizedStructLayoutField Field
ModuleAnalysisManager MAM
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition PassSupport.h:56
R600 Assembly printer class.
RISCVCC::CondCode CC
static cl::opt< RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development, "development", "for training")))
#define R_00B028_SPI_SHADER_PGM_RSRC1_PS
Definition SIDefines.h:1387
#define R_0286E8_SPI_TMPRING_SIZE
Definition SIDefines.h:1529
#define FP_ROUND_MODE_DP(x)
Definition SIDefines.h:1511
#define C_00B84C_SCRATCH_EN
Definition SIDefines.h:1423
#define FP_ROUND_ROUND_TO_NEAREST
Definition SIDefines.h:1503
#define R_0286D0_SPI_PS_INPUT_ADDR
Definition SIDefines.h:1462
#define R_00B860_COMPUTE_TMPRING_SIZE
Definition SIDefines.h:1524
#define R_00B428_SPI_SHADER_PGM_RSRC1_HS
Definition SIDefines.h:1410
#define R_00B328_SPI_SHADER_PGM_RSRC1_ES
Definition SIDefines.h:1409
#define R_00B528_SPI_SHADER_PGM_RSRC1_LS
Definition SIDefines.h:1418
#define R_0286CC_SPI_PS_INPUT_ENA
Definition SIDefines.h:1461
#define R_00B128_SPI_SHADER_PGM_RSRC1_VS
Definition SIDefines.h:1396
#define FP_DENORM_MODE_DP(x)
Definition SIDefines.h:1522
#define R_00B848_COMPUTE_PGM_RSRC1
Definition SIDefines.h:1464
#define R_SPILLED_SGPRS
Definition SIDefines.h:1543
#define FP_ROUND_MODE_SP(x)
Definition SIDefines.h:1510
#define FP_DENORM_MODE_SP(x)
Definition SIDefines.h:1521
#define R_00B228_SPI_SHADER_PGM_RSRC1_GS
Definition SIDefines.h:1401
#define R_SPILLED_VGPRS
Definition SIDefines.h:1544
#define S_00B02C_EXTRA_LDS_SIZE(x)
Definition SIDefines.h:1395
#define R_00B84C_COMPUTE_PGM_RSRC2
Definition SIDefines.h:1420
#define R_00B02C_SPI_SHADER_PGM_RSRC2_PS
Definition SIDefines.h:1394
std::unique_ptr< MCStreamer > && Streamer
static const int BlockSize
Definition TarWriter.cpp:33
static cl::opt< unsigned > CacheLineSize("cache-line-size", cl::init(0), cl::Hidden, cl::desc("Use this to override the target cache line size when " "specified by the user."))
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM)
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM)
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
void emitFunctionEntryLabel() override
EmitFunctionEntryLabel - Emit the label that is the entrypoint for the function.
const MCSubtargetInfo * getGlobalSTI() const
void emitImplicitDef(const MachineInstr *MI) const override
Targets can override this to customize the output of IMPLICIT_DEF instructions in verbose mode.
std::vector< std::string > DisasmLines
std::function< const AMDGPUResourceUsageAnalysisImpl::SIFunctionResourceInfo *(MachineFunction &)> GetResourceUsage
void emitStartOfAsmFile(Module &M) override
This virtual method can be overridden by targets that want to emit something at the start of their fi...
void endFunction(const MachineFunction *MF)
bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum, const char *ExtraCode, raw_ostream &O) override
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant as...
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
std::vector< std::string > HexLines
void emitGlobalVariable(const GlobalVariable *GV) override
Emit the specified global variable to the .s file.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, const char *ExtraCode, raw_ostream &O) override
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant.
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
bool doFinalization(Module &M) override
doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes...
void emitEndOfAsmFile(Module &M) override
This virtual method can be overridden by targets that want to emit something at the end of their file...
AMDGPUAsmPrinter(TargetMachine &TM, std::unique_ptr< MCStreamer > Streamer)
bool doInitialization(Module &M) override
doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...
void emitFunctionBodyStart() override
Targets can override this to emit stuff before the first basic block in the function.
void emitBasicBlockStart(const MachineBasicBlock &MBB) override
Targets can override this to emit stuff at the start of a basic block.
AMDGPUTargetStreamer * getTargetStreamer() const
static void printRegOperand(MCRegister Reg, raw_ostream &O, const MCRegisterInfo &MRI)
AMDGPU target specific MCExpr operations.
static const AMDGPUMCExpr * createInstPrefSize(const MCExpr *CodeSizeBytes, MCContext &Ctx)
Create an expression for instruction prefetch size computation: min(divideCeil(CodeSizeBytes,...
static const AMDGPUMCExpr * createMax(ArrayRef< const MCExpr * > Args, MCContext &Ctx)
static const AMDGPUMCExpr * createTotalNumVGPR(const MCExpr *NumAGPR, const MCExpr *NumVGPR, MCContext &Ctx)
static const AMDGPUMCExpr * create(VariantKind Kind, ArrayRef< const MCExpr * > Args, MCContext &Ctx)
static const AMDGPUMCExpr * createExtraSGPRs(const MCExpr *VCCUsed, const MCExpr *FlatScrUsed, bool XNACKUsed, MCContext &Ctx)
Allow delayed MCExpr resolve of ExtraSGPRs (in case VCCUsed or FlatScrUsed are unresolvable but neede...
static const AMDGPUMCExpr * createAlignTo(const MCExpr *Value, const MCExpr *Align, MCContext &Ctx)
void setHwStage(unsigned CC, StringRef field, unsigned Val)
void updateHwStageMaximum(unsigned CC, StringRef field, unsigned Val)
void setComputeRegisters(StringRef field, unsigned Val)
std::pair< unsigned, unsigned > getOccupancyWithWorkGroupSizes(uint32_t LDSBytes, const Function &F) const
Subtarget's minimum/maximum occupancy, in number of waves per EU, that can be achieved when the only ...
unsigned getAddressableLocalMemorySize() const
Return the maximum number of bytes of LDS that can be allocated to a single workgroup.
unsigned getKernArgSegmentSize(const Function &F, Align &MaxAlign) const
unsigned getWavefrontSize() const
virtual void EmitAmdhsaKernelDescriptor(const MCSubtargetInfo &STI, StringRef KernelName, const AMDGPU::MCKernelDescriptor &KernelDescriptor, const MCExpr *NextVGPR, const MCExpr *NextSGPR, const MCExpr *ReserveVCC, const MCExpr *ReserveFlatScr)
virtual void emitAMDGPUInfo(const AMDGPU::InfoSectionData &Data)
AMDGPUPALMetadata * getPALMetadata()
void initializeTargetID(const MCSubtargetInfo &STI, bool ApplyFeatureString=false)
virtual void EmitDirectiveAMDHSACodeObjectVersion(unsigned COV)
virtual void EmitMCResourceInfo(const MCSymbol *NumVGPR, const MCSymbol *NumAGPR, const MCSymbol *NumExplicitSGPR, const MCSymbol *NumNamedBarrier, const MCSymbol *PrivateSegmentSize, const MCSymbol *UsesVCC, const MCSymbol *UsesFlatScratch, const MCSymbol *HasDynamicallySizedStack, const MCSymbol *HasRecursion, const MCSymbol *HasIndirectCall)
virtual bool EmitCodeEnd(const MCSubtargetInfo &STI)
virtual void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type)
const std::optional< AMDGPU::TargetID > & getTargetID() const
void emitDirectiveAMDGCNTargetOnce()
Emit the .amdgcn_target directive unless it has already been emitted to this streamer.
virtual void EmitAMDKernelCodeT(AMDGPU::AMDGPUMCKernelCodeT &Header)
virtual void EmitMCResourceMaximums(const MCSymbol *MaxVGPR, const MCSymbol *MaxAGPR, const MCSymbol *MaxSGPR, const MCSymbol *MaxNamedBarrier)
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
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 represents an incoming formal argument to a Function.
Definition Argument.h:32
Collects and handles AsmPrinter objects required to build debug or EH information.
This class is intended to be used as a driving class for all asm writers.
Definition AsmPrinter.h:95
const TargetLoweringObjectFile & getObjFileLowering() const
Return information about object file lowering.
MCSymbol * getSymbol(const GlobalValue *GV) const
virtual void emitGlobalVariable(const GlobalVariable *GV)
Emit the specified global variable to the .s file.
dwarf::Attribute TypeAddressSpaceAttribute
The attribute used for a pointer type's DWARF address space.
Definition AsmPrinter.h:299
TargetMachine & TM
Target machine description.
Definition AsmPrinter.h:98
MachineFunction * MF
The current machine function.
Definition AsmPrinter.h:113
virtual void SetupMachineFunction(MachineFunction &MF)
This should be called when a new MachineFunction is being processed from runOnMachineFunction.
void emitFunctionBody()
This method emits the body and trailer for a function.
virtual bool isBlockOnlyReachableByFallthrough(const MachineBasicBlock *MBB) const
Return true if the basic block has exactly one predecessor and the control transfer mechanism between...
bool doInitialization(Module &M) override
Set up the AsmPrinter when we are working on a new module.
virtual void emitLinkage(const GlobalValue *GV, MCSymbol *GVSym) const
This emits linkage information about GVSym based on GV, if this is supported by the target.
void getAnalysisUsage(AnalysisUsage &AU) const override
Record analysis usage.
unsigned getFunctionNumber() const
Return a unique ID for the current function.
MachineOptimizationRemarkEmitter * ORE
Optimization remark emitter.
Definition AsmPrinter.h:128
AsmPrinter(TargetMachine &TM, std::unique_ptr< MCStreamer > Streamer, char &ID=AsmPrinter::ID)
MCSymbol * CurrentFnSym
The symbol for the current function.
Definition AsmPrinter.h:135
MachineModuleInfo * MMI
This is a pointer to the current MachineModuleInfo.
Definition AsmPrinter.h:116
MCContext & OutContext
This is the context for the output file that we are streaming.
Definition AsmPrinter.h:105
bool doFinalization(Module &M) override
Shut down the asmprinter.
virtual void emitBasicBlockStart(const MachineBasicBlock &MBB)
Targets can override this to emit stuff at the start of a basic block.
void emitVisibility(MCSymbol *Sym, unsigned Visibility, bool IsDefinition=true) const
This emits visibility information about symbol, if this is supported by the target.
bool runOnMachineFunction(MachineFunction &MF) override
Emit the specified function out to the OutStreamer.
Definition AsmPrinter.h:478
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition AsmPrinter.h:110
const MCAsmInfo & MAI
Target Asm Printer information.
Definition AsmPrinter.h:101
std::function< MachineModuleInfo *()> GetMMI
Definition AsmPrinter.h:183
bool isVerbose() const
Return true if assembly output should contain comments.
Definition AsmPrinter.h:335
MCSymbol * getFunctionEnd() const
Definition AsmPrinter.h:345
void getNameWithPrefix(SmallVectorImpl< char > &Name, const GlobalValue *GV) const
virtual void emitFunctionEntryLabel()
EmitFunctionEntryLabel - Emit the label that is the entrypoint for the function.
void addAsmPrinterHandler(std::unique_ptr< AsmPrinterHandler > Handler)
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.
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
bool empty() const
Definition DenseMap.h:716
DISubprogram * getSubprogram() const
Get the attached subprogram.
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Definition Function.h:273
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
Definition Function.cpp:352
unsigned getMinNumSGPRs(unsigned WavesPerEU) const
unsigned getTotalNumVGPRs() const
unsigned getMinNumVGPRs(unsigned WavesPerEU, unsigned DynamicVGPRBlockSize) const
bool hasInstPrefSize() const
bool isCuModeEnabled() const
const AMDGPU::TargetID & getTargetID() const
bool isWave32() const
void getInstPrefSizeArgs(uint32_t &Mask, uint32_t &Shift, uint32_t &Width, uint32_t &CacheLineSize) const
unsigned getMaxNumUserSGPRs() const
unsigned getMaxWavesPerEU() const
Generation getGeneration() const
unsigned getAddressableNumSGPRs() const
unsigned getMaxWaveScratchSize() const
bool hasPrivateSegmentBuffer() const
VisibilityTypes getVisibility() const
LLVM_ABI bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Definition Globals.cpp:408
unsigned getAddressSpace() const
LLVM_ABI const DataLayout & getDataLayout() const
Get the data layout of the module this global belongs to.
Definition Globals.cpp:205
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
bool hasInitializer() const
Definitions have initializers, declarations don't.
MaybeAlign getAlign() const
Returns the alignment of the given variable.
LLVM_ABI uint64_t getGlobalSize(const DataLayout &DL) const
Get the size of this global variable in bytes.
Definition Globals.cpp:640
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:76
LLVM_ABI void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
MCCodeEmitter * getEmitterPtr() const
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.h:342
static const MCBinaryExpr * createAnd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:347
static const MCBinaryExpr * createOr(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:407
static const MCBinaryExpr * createLOr(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:377
static const MCBinaryExpr * createMul(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:397
static const MCBinaryExpr * createGT(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:362
static const MCBinaryExpr * createDiv(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:352
static const MCBinaryExpr * createShl(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:412
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:427
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Definition MCExpr.cpp:212
Context object for machine code objects.
Definition MCContext.h:83
LLVM_ABI void reportError(SMLoc L, const Twine &Msg)
LLVM_ABI MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
Base class for the full range of assembler expressions which are needed for parsing.
Definition MCExpr.h:34
LLVM_ABI bool evaluateAsRelocatable(MCValue &Res, const MCAssembler *Asm) const
Try to evaluate the expression to a relocatable value, i.e.
Definition MCExpr.cpp:450
MCSection * getTextSection() const
MCContext & getContext() const
This represents a section on linux, lots of unix variants and some bare metal systems.
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition MCSection.h:580
bool hasInstructions() const
Definition MCSection.h:676
Generic base class for all target subtargets.
StringRef getFeatureString() const
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.h:213
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
bool isDefined() const
isDefined - Check if this symbol is defined (i.e., it has an address).
Definition MCSymbol.h:233
StringRef getName() const
getName - Get the symbol name.
Definition MCSymbol.h:188
bool isVariable() const
isVariable - Check if this is a variable symbol.
Definition MCSymbol.h:267
void redefineIfPossible()
Prepare this symbol to be redefined.
Definition MCSymbol.h:212
const MCExpr * getVariableValue() const
Get the expression of the variable symbol.
Definition MCSymbol.h:270
MCStreamer & getStreamer()
Definition MCStreamer.h:103
static const MCUnaryExpr * createNot(const MCExpr *Expr, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.h:272
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects.
MCContext & getContext() const
Function & getFunction()
Return the LLVM function that this machine code represents.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
const MachineBasicBlock & front() const
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
int64_t getImm() const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
Register getReg() const
getReg - Returns the register number.
Diagnostic information for optimization analysis remarks.
LLVM_ABI void emit(DiagnosticInfoOptimizationBase &OptDiag)
Emit an optimization remark.
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
LLVM_ABI unsigned getNumOperands() const
iterator_range< op_iterator > operands()
Definition Metadata.h:1893
AnalysisType * getAnalysisIfAvailable() const
getAnalysisIfAvailable<AnalysisType>() - Subclasses use this function to get analysis information tha...
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
Wrapper class representing virtual and physical registers.
Definition Register.h:20
This class keeps track of the SPI_SP_INPUT_ADDR config register, which tells the hardware which inter...
GCNUserSGPRUsageInfo & getUserSGPRInfo()
SIModeRegisterDefaults getMode() const
unsigned getScratchReservedForDynamicVGPRs() const
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:28
void push_back(const T &Elt)
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
bool contains(StringRef Other) const
Return true if the given string is a substring of *this, and false otherwise.
Definition StringRef.h:446
std::pair< typename Base::iterator, bool > insert(StringRef key)
Definition StringSet.h:41
Primary interface to the complete machine description for the target machine.
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
LLVM Value Representation.
Definition Value.h:75
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
Definition Value.cpp:314
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
A raw_ostream that writes to an SmallVector or SmallString.
StringRef str() const
Return a StringRef for the vector contents.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ LOCAL_ADDRESS
Address space for local memory.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
bool isSGPROccupancyLimited(const MCSubtargetInfo &STI)
unsigned getVGPREncodingGranule(const MCSubtargetInfo &STI, std::optional< bool > EnableWavefrontSize32)
static constexpr unsigned MaxDynamicVGPRBlocks
Maximum number of VGPR blocks that can be allocated in dynamic VGPR mode.
unsigned getSGPREncodingGranule(const MCSubtargetInfo &STI)
unsigned getNumExtraSGPRs(const MCSubtargetInfo &STI, bool VCCUsed, bool FlatScrUsed, bool XNACKUsed)
unsigned getVGPRAllocGranule(const MCSubtargetInfo &STI, unsigned DynamicVGPRBlockSize, std::optional< bool > EnableWavefrontSize32)
LLVM_ABI unsigned getLDSEncodingGranule(GPUKind AK)
void printAMDGPUMCExpr(const MCExpr *Expr, raw_ostream &OS, const MCAsmInfo *MAI)
LLVM_READNONE constexpr bool isModuleEntryFunctionCC(CallingConv::ID CC)
LLVM_ABI IsaVersion getIsaVersion(StringRef GPU)
LLVM_ABI unsigned getTotalNumVGPRs(GPUKind AK, bool IsWave32)
LLVM_ABI unsigned getTotalNumSGPRs(GPUKind AK)
const MCExpr * maskShiftSet(const MCExpr *Val, uint32_t Mask, uint32_t Shift, MCContext &Ctx)
Provided with the MCExpr * Val, uint32 Mask and Shift, will return the masked and left shifted,...
unsigned getAMDHSACodeObjectVersion(const Module &M)
bool isTgSplitEnabled(const Function &F)
GPUKind
GPU kinds supported by the AMDGPU target.
bool isGFX90A(const MCSubtargetInfo &STI)
LLVM_READNONE constexpr bool isKernel(CallingConv::ID CC)
LLVM_ABI unsigned getSGPRAllocGranule(GPUKind AK)
LLVM_READNONE constexpr bool isEntryFunctionCC(CallingConv::ID CC)
LLVM_READNONE constexpr bool isCompute(CallingConv::ID CC)
bool hasMAIInsts(const MCSubtargetInfo &STI)
LLVM_ABI Triple::SubArchType getSubArch(GPUKind AK)
LLVM_READNONE bool isInlinableIntLiteral(int64_t Literal)
Is this literal inlinable, and not one of the values intended for floating point values.
LLVM_ABI GPUKind parseArchAMDGCN(StringRef CPU)
const MCExpr * foldAMDGPUMCExpr(const MCExpr *Expr, MCContext &Ctx)
bool isGFX10Plus(const MCSubtargetInfo &STI)
constexpr std::pair< unsigned, unsigned > getShiftMask(unsigned Value)
Deduce the least significant bit aligned shift and mask values for a binary Complement Value (as they...
unsigned hasKernargPreload(const MCSubtargetInfo &STI)
std::pair< unsigned, unsigned > getIntegerPairAttribute(const Function &F, StringRef Name, std::pair< unsigned, unsigned > Default, bool OnlyFirstRequired)
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
@ AMDGPU_CS
Used for Mesa/AMDPAL compute shaders.
@ AMDGPU_VS
Used for Mesa vertex shaders, or AMDPAL last shader stage before rasterization (vertex shader if tess...
@ AMDGPU_KERNEL
Used for AMDGPU code object kernels.
@ AMDGPU_HS
Used for Mesa/AMDPAL hull shaders (= tessellation control shaders).
@ AMDGPU_GS
Used for Mesa/AMDPAL geometry shaders.
@ AMDGPU_CS_Chain
Used on AMDGPUs to give the middle-end more control over argument placement.
@ AMDGPU_PS
Used for Mesa/AMDPAL pixel shaders.
@ SPIR_KERNEL
Used for SPIR kernel functions.
@ AMDGPU_ES
Used for AMDPAL shader stage before geometry shader if geometry is in use.
@ AMDGPU_LS
Used for AMDPAL vertex shader if tessellation is in use.
@ SHT_PROGBITS
Definition ELF.h:965
@ STT_AMDGPU_HSA_KERNEL
Definition ELF.h:1255
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > extract(Y &&MD)
Extract a Value from Metadata.
Definition Metadata.h:679
DiagnosticInfoOptimizationBase::Argument NV
NodeAddr< FuncNode * > Func
Definition RDFGraph.h:393
This is an optimization pass for GlobalISel generic memory operations.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition STLExtras.h:1685
OuterAnalysisManagerProxy< ModuleAnalysisManager, MachineFunction > ModuleAnalysisManagerMachineFunctionProxy
Provide the ModuleAnalysisManager to Function proxy.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
Definition STLExtras.h:2570
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
static StringRef getCPU(StringRef CPU)
Processes a CPU name.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
Target & getTheR600Target()
The target for R600 GPUs.
@ DK_ResourceLimit
AsmPrinter * createR600AsmPrinterPass(TargetMachine &TM, std::unique_ptr< MCStreamer > &&Streamer)
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
Definition InstrProf.h:143
LLVM_ABI void setupModuleAsmPrinter(Module &M, ModuleAnalysisManager &MAM, AsmPrinter &AsmPrinter)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:163
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition Alignment.h:149
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
Definition MathExtras.h:190
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition Format.h:102
@ Success
The lock was released successfully.
constexpr T divideCeil(U Numerator, V Denominator)
Returns the integer ceil(Numerator / Denominator).
Definition MathExtras.h:389
Target & getTheGCNTarget()
The target for GCN GPUs.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1933
LLVM_ABI void setupMachineFunctionAsmPrinter(MachineFunctionAnalysisManager &MFAM, MachineFunction &MF, AsmPrinter &AsmPrinter)
Target & getTheGCNLegacyTarget()
The target for GCN GPUs, registered under the legacy "amdgcn" architecture name for use with -march.
unsigned Log2(Align A)
Returns the log2 of the alignment.
Definition Alignment.h:202
LLVM_ABI Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition MIRParser.h:39
LLVM_ABI void reportFatalUsageError(Error Err)
Report a fatal error that does not indicate a bug in LLVM.
Definition Error.cpp:177
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:879
#define N
AMDGPUResourceUsageAnalysisImpl::SIFunctionResourceInfo FunctionResourceInfo
void validate(const MCSubtargetInfo *STI, MCContext &Ctx)
static const MCExpr * bits_get(const MCExpr *Src, uint32_t Shift, uint32_t Mask, MCContext &Ctx)
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
Track resource usage for kernels / entry functions.
const MCExpr * NumSGPR
const MCExpr * NumArchVGPR
const MCExpr * VGPRBlocks
const MCExpr * ScratchBlocks
const MCExpr * ComputePGMRSrc3
const MCExpr * getComputePGMRSrc1(const GCNSubtarget &ST, MCContext &Ctx) const
Compute the value of the ComputePGMRsrc1 register.
const MCExpr * VCCUsed
const MCExpr * FlatUsed
const MCExpr * NamedBarCnt
const MCExpr * ScratchEnable
const MCExpr * AccumOffset
const MCExpr * NumAccVGPR
const MCExpr * DynamicCallStack
const MCExpr * SGPRBlocks
const MCExpr * NumVGPRsForWavesPerEU
const MCExpr * NumVGPR
const MCExpr * Occupancy
const MCExpr * ScratchSize
const MCExpr * NumSGPRsForWavesPerEU
const MCExpr * getComputePGMRSrc2(const GCNSubtarget &ST, MCContext &Ctx) const
Compute the value of the ComputePGMRsrc2 register.
static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn)
RegisterAsmPrinter - Register an AsmPrinter implementation for the given target.