LLVM  10.0.0
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"
20 #include "AMDGPUSubtarget.h"
21 #include "AMDGPUTargetMachine.h"
25 #include "R600AsmPrinter.h"
26 #include "R600Defines.h"
28 #include "R600RegisterInfo.h"
29 #include "SIDefines.h"
30 #include "SIInstrInfo.h"
31 #include "SIMachineFunctionInfo.h"
32 #include "SIRegisterInfo.h"
34 #include "Utils/AMDGPUBaseInfo.h"
35 #include "llvm/BinaryFormat/ELF.h"
37 #include "llvm/IR/DiagnosticInfo.h"
38 #include "llvm/MC/MCAssembler.h"
39 #include "llvm/MC/MCContext.h"
40 #include "llvm/MC/MCSectionELF.h"
41 #include "llvm/MC/MCStreamer.h"
47 
48 using namespace llvm;
49 using namespace llvm::AMDGPU;
50 using namespace llvm::AMDGPU::HSAMD;
51 
52 // TODO: This should get the default rounding mode from the kernel. We just set
53 // the default here, but this could change if the OpenCL rounding mode pragmas
54 // are used.
55 //
56 // The denormal mode here should match what is reported by the OpenCL runtime
57 // for the CL_FP_DENORM bit from CL_DEVICE_{HALF|SINGLE|DOUBLE}_FP_CONFIG, but
58 // can also be override to flush with the -cl-denorms-are-zero compiler flag.
59 //
60 // AMD OpenCL only sets flush none and reports CL_FP_DENORM for double
61 // precision, and leaves single precision to flush all and does not report
62 // CL_FP_DENORM for CL_DEVICE_SINGLE_FP_CONFIG. Mesa's OpenCL currently reports
63 // CL_FP_DENORM for both.
64 //
65 // FIXME: It seems some instructions do not support single precision denormals
66 // regardless of the mode (exp_*_f32, rcp_*_f32, rsq_*_f32, rsq_*f32, sqrt_f32,
67 // and sin_f32, cos_f32 on most parts).
68 
69 // We want to use these instructions, and using fp32 denormals also causes
70 // instructions to run at the double precision rate for the device so it's
71 // probably best to just report no single precision denormals.
72 static uint32_t getFPMode(AMDGPU::SIModeRegisterDefaults Mode) {
73 
74  // TODO: Is there any real use for the flush in only / flush out only modes?
75  uint32_t FP32Denormals =
77 
78  uint32_t FP64Denormals =
79  Mode.FP64FP16Denormals ? FP_DENORM_FLUSH_NONE : FP_DENORM_FLUSH_IN_FLUSH_OUT;
80 
83  FP_DENORM_MODE_SP(FP32Denormals) |
84  FP_DENORM_MODE_DP(FP64Denormals);
85 }
86 
87 static AsmPrinter *
89  std::unique_ptr<MCStreamer> &&Streamer) {
90  return new AMDGPUAsmPrinter(tm, std::move(Streamer));
91 }
92 
98 }
99 
101  std::unique_ptr<MCStreamer> Streamer)
102  : AsmPrinter(TM, std::move(Streamer)) {
104  HSAMetadataStream.reset(new MetadataStreamerV3());
105  else
106  HSAMetadataStream.reset(new MetadataStreamerV2());
107 }
108 
110  return "AMDGPU Assembly Printer";
111 }
112 
114  return TM.getMCSubtargetInfo();
115 }
116 
118  if (!OutStreamer)
119  return nullptr;
120  return static_cast<AMDGPUTargetStreamer*>(OutStreamer->getTargetStreamer());
121 }
122 
125  std::string ExpectedTarget;
126  raw_string_ostream ExpectedTargetOS(ExpectedTarget);
127  IsaInfo::streamIsaVersion(getGlobalSTI(), ExpectedTargetOS);
128 
129  getTargetStreamer()->EmitDirectiveAMDGCNTarget(ExpectedTarget);
130  }
131 
132  if (TM.getTargetTriple().getOS() != Triple::AMDHSA &&
134  return;
135 
137  HSAMetadataStream->begin(M);
138 
141 
143  return;
144 
145  // HSA emits NT_AMDGPU_HSA_CODE_OBJECT_VERSION for code objects v2.
148 
149  // HSA and PAL emit NT_AMDGPU_HSA_ISA for code objects v2.
152  Version.Major, Version.Minor, Version.Stepping, "AMD", "AMDGPU");
153 }
154 
156  // Following code requires TargetStreamer to be present.
157  if (!getTargetStreamer())
158  return;
159 
161  // Emit ISA Version (NT_AMD_AMDGPU_ISA).
162  std::string ISAVersionString;
163  raw_string_ostream ISAVersionStream(ISAVersionString);
164  IsaInfo::streamIsaVersion(getGlobalSTI(), ISAVersionStream);
165  getTargetStreamer()->EmitISAVersion(ISAVersionStream.str());
166  }
167 
168  // Emit HSA Metadata (NT_AMD_AMDGPU_HSA_METADATA).
169  if (TM.getTargetTriple().getOS() == Triple::AMDHSA) {
170  HSAMetadataStream->end();
171  bool Success = HSAMetadataStream->emitTo(*getTargetStreamer());
172  (void)Success;
173  assert(Success && "Malformed HSA Metadata");
174  }
175 }
176 
178  const MachineBasicBlock *MBB) const {
180  return false;
181 
182  if (MBB->empty())
183  return true;
184 
185  // If this is a block implementing a long branch, an expression relative to
186  // the start of the block is needed. to the start of the block.
187  // XXX - Is there a smarter way to check this?
188  return (MBB->back().getOpcode() != AMDGPU::S_SETPC_B64);
189 }
190 
193  if (!MFI.isEntryFunction())
194  return;
195 
196  const GCNSubtarget &STM = MF->getSubtarget<GCNSubtarget>();
197  const Function &F = MF->getFunction();
198  if (!STM.hasCodeObjectV3() && STM.isAmdHsaOrMesa(F) &&
199  (F.getCallingConv() == CallingConv::AMDGPU_KERNEL ||
200  F.getCallingConv() == CallingConv::SPIR_KERNEL)) {
201  amd_kernel_code_t KernelCode;
202  getAmdKernelCode(KernelCode, CurrentProgramInfo, *MF);
203  getTargetStreamer()->EmitAMDKernelCodeT(KernelCode);
204  }
205 
206  if (STM.isAmdHsaOS())
207  HSAMetadataStream->emitKernel(*MF, CurrentProgramInfo);
208 }
209 
212  if (!MFI.isEntryFunction())
213  return;
214 
217  return;
218 
219  auto &Streamer = getTargetStreamer()->getStreamer();
220  auto &Context = Streamer.getContext();
221  auto &ObjectFileInfo = *Context.getObjectFileInfo();
222  auto &ReadOnlySection = *ObjectFileInfo.getReadOnlySection();
223 
224  Streamer.PushSection();
225  Streamer.SwitchSection(&ReadOnlySection);
226 
227  // CP microcode requires the kernel descriptor to be allocated on 64 byte
228  // alignment.
229  Streamer.EmitValueToAlignment(64, 0, 1, 0);
230  if (ReadOnlySection.getAlignment() < 64)
231  ReadOnlySection.setAlignment(Align(64));
232 
233  const MCSubtargetInfo &STI = MF->getSubtarget();
234 
235  SmallString<128> KernelName;
236  getNameWithPrefix(KernelName, &MF->getFunction());
238  STI, KernelName, getAmdhsaKernelDescriptor(*MF, CurrentProgramInfo),
239  CurrentProgramInfo.NumVGPRsForWavesPerEU,
240  CurrentProgramInfo.NumSGPRsForWavesPerEU -
242  CurrentProgramInfo.VCCUsed,
243  CurrentProgramInfo.FlatUsed),
244  CurrentProgramInfo.VCCUsed, CurrentProgramInfo.FlatUsed,
245  hasXNACK(STI));
246 
247  Streamer.PopSection();
248 }
249 
254  return;
255  }
256 
258  const GCNSubtarget &STM = MF->getSubtarget<GCNSubtarget>();
259  if (MFI->isEntryFunction() && STM.isAmdHsaOrMesa(MF->getFunction())) {
261  getNameWithPrefix(SymbolName, &MF->getFunction()),
263  SymbolName, ELF::STT_AMDGPU_HSA_KERNEL);
264  }
265  if (DumpCodeInstEmitter) {
266  // Disassemble function name label to text.
267  DisasmLines.push_back(MF->getName().str() + ":");
269  HexLines.push_back("");
270  }
271 
273 }
274 
276  if (DumpCodeInstEmitter && !isBlockOnlyReachableByFallthrough(&MBB)) {
277  // Write a line for the basic block label if it is not only fallthrough.
278  DisasmLines.push_back(
279  (Twine("BB") + Twine(getFunctionNumber())
280  + "_" + Twine(MBB.getNumber()) + ":").str());
282  HexLines.push_back("");
283  }
285 }
286 
289  if (GV->hasInitializer() && !isa<UndefValue>(GV->getInitializer())) {
291  Twine(GV->getName()) +
292  ": unsupported initializer for address space");
293  return;
294  }
295 
296  // LDS variables aren't emitted in HSA or PAL yet.
297  const Triple::OSType OS = TM.getTargetTriple().getOS();
298  if (OS == Triple::AMDHSA || OS == Triple::AMDPAL)
299  return;
300 
301  MCSymbol *GVSym = getSymbol(GV);
302 
303  GVSym->redefineIfPossible();
304  if (GVSym->isDefined() || GVSym->isVariable())
305  report_fatal_error("symbol '" + Twine(GVSym->getName()) +
306  "' is already defined");
307 
308  const DataLayout &DL = GV->getParent()->getDataLayout();
309  uint64_t Size = DL.getTypeAllocSize(GV->getValueType());
310  unsigned Align = GV->getAlignment();
311  if (!Align)
312  Align = 4;
313 
314  EmitVisibility(GVSym, GV->getVisibility(), !GV->isDeclaration());
315  EmitLinkage(GV, GVSym);
316  if (auto TS = getTargetStreamer())
317  TS->emitAMDGPULDS(GVSym, Size, Align);
318  return;
319  }
320 
322 }
323 
325  CallGraphResourceInfo.clear();
326 
327  // Pad with s_code_end to help tools and guard against instruction prefetch
328  // causing stale data in caches. Arguably this should be done by the linker,
329  // which is why this isn't done for Mesa.
330  const MCSubtargetInfo &STI = *getGlobalSTI();
331  if (AMDGPU::isGFX10(STI) &&
332  (STI.getTargetTriple().getOS() == Triple::AMDHSA ||
333  STI.getTargetTriple().getOS() == Triple::AMDPAL)) {
334  OutStreamer->SwitchSection(getObjFileLowering().getTextSection());
336  }
337 
338  return AsmPrinter::doFinalization(M);
339 }
340 
341 // Print comments that apply to both callable functions and entry points.
342 void AMDGPUAsmPrinter::emitCommonFunctionComments(
343  uint32_t NumVGPR,
344  Optional<uint32_t> NumAGPR,
345  uint32_t TotalNumVGPR,
346  uint32_t NumSGPR,
347  uint64_t ScratchSize,
348  uint64_t CodeSize,
349  const AMDGPUMachineFunction *MFI) {
350  OutStreamer->emitRawComment(" codeLenInByte = " + Twine(CodeSize), false);
351  OutStreamer->emitRawComment(" NumSgprs: " + Twine(NumSGPR), false);
352  OutStreamer->emitRawComment(" NumVgprs: " + Twine(NumVGPR), false);
353  if (NumAGPR) {
354  OutStreamer->emitRawComment(" NumAgprs: " + Twine(*NumAGPR), false);
355  OutStreamer->emitRawComment(" TotalNumVgprs: " + Twine(TotalNumVGPR),
356  false);
357  }
358  OutStreamer->emitRawComment(" ScratchSize: " + Twine(ScratchSize), false);
359  OutStreamer->emitRawComment(" MemoryBound: " + Twine(MFI->isMemoryBound()),
360  false);
361 }
362 
363 uint16_t AMDGPUAsmPrinter::getAmdhsaKernelCodeProperties(
364  const MachineFunction &MF) const {
366  uint16_t KernelCodeProperties = 0;
367 
368  if (MFI.hasPrivateSegmentBuffer()) {
369  KernelCodeProperties |=
370  amdhsa::KERNEL_CODE_PROPERTY_ENABLE_SGPR_PRIVATE_SEGMENT_BUFFER;
371  }
372  if (MFI.hasDispatchPtr()) {
373  KernelCodeProperties |=
374  amdhsa::KERNEL_CODE_PROPERTY_ENABLE_SGPR_DISPATCH_PTR;
375  }
376  if (MFI.hasQueuePtr()) {
377  KernelCodeProperties |=
378  amdhsa::KERNEL_CODE_PROPERTY_ENABLE_SGPR_QUEUE_PTR;
379  }
380  if (MFI.hasKernargSegmentPtr()) {
381  KernelCodeProperties |=
382  amdhsa::KERNEL_CODE_PROPERTY_ENABLE_SGPR_KERNARG_SEGMENT_PTR;
383  }
384  if (MFI.hasDispatchID()) {
385  KernelCodeProperties |=
386  amdhsa::KERNEL_CODE_PROPERTY_ENABLE_SGPR_DISPATCH_ID;
387  }
388  if (MFI.hasFlatScratchInit()) {
389  KernelCodeProperties |=
390  amdhsa::KERNEL_CODE_PROPERTY_ENABLE_SGPR_FLAT_SCRATCH_INIT;
391  }
392  if (MF.getSubtarget<GCNSubtarget>().isWave32()) {
393  KernelCodeProperties |=
394  amdhsa::KERNEL_CODE_PROPERTY_ENABLE_WAVEFRONT_SIZE32;
395  }
396 
397  return KernelCodeProperties;
398 }
399 
400 amdhsa::kernel_descriptor_t AMDGPUAsmPrinter::getAmdhsaKernelDescriptor(
401  const MachineFunction &MF,
402  const SIProgramInfo &PI) const {
403  amdhsa::kernel_descriptor_t KernelDescriptor;
404  memset(&KernelDescriptor, 0x0, sizeof(KernelDescriptor));
405 
409 
410  KernelDescriptor.group_segment_fixed_size = PI.LDSSize;
411  KernelDescriptor.private_segment_fixed_size = PI.ScratchSize;
412  KernelDescriptor.compute_pgm_rsrc1 = PI.ComputePGMRSrc1;
413  KernelDescriptor.compute_pgm_rsrc2 = PI.ComputePGMRSrc2;
414  KernelDescriptor.kernel_code_properties = getAmdhsaKernelCodeProperties(MF);
415 
416  return KernelDescriptor;
417 }
418 
420  CurrentProgramInfo = SIProgramInfo();
421 
423 
424  // The starting address of all shader programs must be 256 bytes aligned.
425  // Regular functions just need the basic required instruction alignment.
426  MF.setAlignment(MFI->isEntryFunction() ? Align(256) : Align(4));
427 
429 
430  const GCNSubtarget &STM = MF.getSubtarget<GCNSubtarget>();
432  // FIXME: This should be an explicit check for Mesa.
433  if (!STM.isAmdHsaOS() && !STM.isAmdPalOS()) {
434  MCSectionELF *ConfigSection =
435  Context.getELFSection(".AMDGPU.config", ELF::SHT_PROGBITS, 0);
436  OutStreamer->SwitchSection(ConfigSection);
437  }
438 
439  if (MFI->isEntryFunction()) {
440  getSIProgramInfo(CurrentProgramInfo, MF);
441  } else {
442  auto I = CallGraphResourceInfo.insert(
443  std::make_pair(&MF.getFunction(), SIFunctionResourceInfo()));
444  SIFunctionResourceInfo &Info = I.first->second;
445  assert(I.second && "should only be called once per function");
446  Info = analyzeResourceUsage(MF);
447  }
448 
449  if (STM.isAmdPalOS())
450  EmitPALMetadata(MF, CurrentProgramInfo);
451  else if (!STM.isAmdHsaOS()) {
452  EmitProgramInfoSI(MF, CurrentProgramInfo);
453  }
454 
455  DumpCodeInstEmitter = nullptr;
456  if (STM.dumpCode()) {
457  // For -dumpcode, get the assembler out of the streamer, even if it does
458  // not really want to let us have it. This only works with -filetype=obj.
459  bool SaveFlag = OutStreamer->getUseAssemblerInfoForParsing();
460  OutStreamer->setUseAssemblerInfoForParsing(true);
461  MCAssembler *Assembler = OutStreamer->getAssemblerPtr();
462  OutStreamer->setUseAssemblerInfoForParsing(SaveFlag);
463  if (Assembler)
464  DumpCodeInstEmitter = Assembler->getEmitterPtr();
465  }
466 
467  DisasmLines.clear();
468  HexLines.clear();
469  DisasmLineMaxLen = 0;
470 
472 
473  if (isVerbose()) {
474  MCSectionELF *CommentSection =
475  Context.getELFSection(".AMDGPU.csdata", ELF::SHT_PROGBITS, 0);
476  OutStreamer->SwitchSection(CommentSection);
477 
478  if (!MFI->isEntryFunction()) {
479  OutStreamer->emitRawComment(" Function info:", false);
480  SIFunctionResourceInfo &Info = CallGraphResourceInfo[&MF.getFunction()];
481  emitCommonFunctionComments(
482  Info.NumVGPR,
483  STM.hasMAIInsts() ? Info.NumAGPR : Optional<uint32_t>(),
484  Info.getTotalNumVGPRs(STM),
485  Info.getTotalNumSGPRs(MF.getSubtarget<GCNSubtarget>()),
486  Info.PrivateSegmentSize,
487  getFunctionCodeSize(MF), MFI);
488  return false;
489  }
490 
491  OutStreamer->emitRawComment(" Kernel info:", false);
492  emitCommonFunctionComments(CurrentProgramInfo.NumArchVGPR,
493  STM.hasMAIInsts()
494  ? CurrentProgramInfo.NumAccVGPR
495  : Optional<uint32_t>(),
496  CurrentProgramInfo.NumVGPR,
497  CurrentProgramInfo.NumSGPR,
498  CurrentProgramInfo.ScratchSize,
499  getFunctionCodeSize(MF), MFI);
500 
501  OutStreamer->emitRawComment(
502  " FloatMode: " + Twine(CurrentProgramInfo.FloatMode), false);
503  OutStreamer->emitRawComment(
504  " IeeeMode: " + Twine(CurrentProgramInfo.IEEEMode), false);
505  OutStreamer->emitRawComment(
506  " LDSByteSize: " + Twine(CurrentProgramInfo.LDSSize) +
507  " bytes/workgroup (compile time only)", false);
508 
509  OutStreamer->emitRawComment(
510  " SGPRBlocks: " + Twine(CurrentProgramInfo.SGPRBlocks), false);
511  OutStreamer->emitRawComment(
512  " VGPRBlocks: " + Twine(CurrentProgramInfo.VGPRBlocks), false);
513 
514  OutStreamer->emitRawComment(
515  " NumSGPRsForWavesPerEU: " +
516  Twine(CurrentProgramInfo.NumSGPRsForWavesPerEU), false);
517  OutStreamer->emitRawComment(
518  " NumVGPRsForWavesPerEU: " +
519  Twine(CurrentProgramInfo.NumVGPRsForWavesPerEU), false);
520 
521  OutStreamer->emitRawComment(
522  " Occupancy: " +
523  Twine(CurrentProgramInfo.Occupancy), false);
524 
525  OutStreamer->emitRawComment(
526  " WaveLimiterHint : " + Twine(MFI->needsWaveLimiter()), false);
527 
528  OutStreamer->emitRawComment(
529  " COMPUTE_PGM_RSRC2:USER_SGPR: " +
530  Twine(G_00B84C_USER_SGPR(CurrentProgramInfo.ComputePGMRSrc2)), false);
531  OutStreamer->emitRawComment(
532  " COMPUTE_PGM_RSRC2:TRAP_HANDLER: " +
533  Twine(G_00B84C_TRAP_HANDLER(CurrentProgramInfo.ComputePGMRSrc2)), false);
534  OutStreamer->emitRawComment(
535  " COMPUTE_PGM_RSRC2:TGID_X_EN: " +
536  Twine(G_00B84C_TGID_X_EN(CurrentProgramInfo.ComputePGMRSrc2)), false);
537  OutStreamer->emitRawComment(
538  " COMPUTE_PGM_RSRC2:TGID_Y_EN: " +
539  Twine(G_00B84C_TGID_Y_EN(CurrentProgramInfo.ComputePGMRSrc2)), false);
540  OutStreamer->emitRawComment(
541  " COMPUTE_PGM_RSRC2:TGID_Z_EN: " +
542  Twine(G_00B84C_TGID_Z_EN(CurrentProgramInfo.ComputePGMRSrc2)), false);
543  OutStreamer->emitRawComment(
544  " COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: " +
545  Twine(G_00B84C_TIDIG_COMP_CNT(CurrentProgramInfo.ComputePGMRSrc2)),
546  false);
547  }
548 
549  if (DumpCodeInstEmitter) {
550 
551  OutStreamer->SwitchSection(
552  Context.getELFSection(".AMDGPU.disasm", ELF::SHT_NOTE, 0));
553 
554  for (size_t i = 0; i < DisasmLines.size(); ++i) {
555  std::string Comment = "\n";
556  if (!HexLines[i].empty()) {
557  Comment = std::string(DisasmLineMaxLen - DisasmLines[i].size(), ' ');
558  Comment += " ; " + HexLines[i] + "\n";
559  }
560 
561  OutStreamer->EmitBytes(StringRef(DisasmLines[i]));
562  OutStreamer->EmitBytes(StringRef(Comment));
563  }
564  }
565 
566  return false;
567 }
568 
569 uint64_t AMDGPUAsmPrinter::getFunctionCodeSize(const MachineFunction &MF) const {
570  const GCNSubtarget &STM = MF.getSubtarget<GCNSubtarget>();
571  const SIInstrInfo *TII = STM.getInstrInfo();
572 
573  uint64_t CodeSize = 0;
574 
575  for (const MachineBasicBlock &MBB : MF) {
576  for (const MachineInstr &MI : MBB) {
577  // TODO: CodeSize should account for multiple functions.
578 
579  // TODO: Should we count size of debug info?
580  if (MI.isDebugInstr())
581  continue;
582 
583  CodeSize += TII->getInstSizeInBytes(MI);
584  }
585  }
586 
587  return CodeSize;
588 }
589 
591  const SIInstrInfo &TII,
592  unsigned Reg) {
593  for (const MachineOperand &UseOp : MRI.reg_operands(Reg)) {
594  if (!UseOp.isImplicit() || !TII.isFLAT(*UseOp.getParent()))
595  return true;
596  }
597 
598  return false;
599 }
600 
602  const GCNSubtarget &ST) const {
603  return NumExplicitSGPR + IsaInfo::getNumExtraSGPRs(&ST,
604  UsesVCC, UsesFlatScratch);
605 }
606 
608  const GCNSubtarget &ST) const {
609  return std::max(NumVGPR, NumAGPR);
610 }
611 
612 AMDGPUAsmPrinter::SIFunctionResourceInfo AMDGPUAsmPrinter::analyzeResourceUsage(
613  const MachineFunction &MF) const {
614  SIFunctionResourceInfo Info;
615 
617  const GCNSubtarget &ST = MF.getSubtarget<GCNSubtarget>();
618  const MachineFrameInfo &FrameInfo = MF.getFrameInfo();
619  const MachineRegisterInfo &MRI = MF.getRegInfo();
620  const SIInstrInfo *TII = ST.getInstrInfo();
621  const SIRegisterInfo &TRI = TII->getRegisterInfo();
622 
623  Info.UsesFlatScratch = MRI.isPhysRegUsed(AMDGPU::FLAT_SCR_LO) ||
624  MRI.isPhysRegUsed(AMDGPU::FLAT_SCR_HI);
625 
626  // Even if FLAT_SCRATCH is implicitly used, it has no effect if flat
627  // instructions aren't used to access the scratch buffer. Inline assembly may
628  // need it though.
629  //
630  // If we only have implicit uses of flat_scr on flat instructions, it is not
631  // really needed.
632  if (Info.UsesFlatScratch && !MFI->hasFlatScratchInit() &&
633  (!hasAnyNonFlatUseOfReg(MRI, *TII, AMDGPU::FLAT_SCR) &&
634  !hasAnyNonFlatUseOfReg(MRI, *TII, AMDGPU::FLAT_SCR_LO) &&
635  !hasAnyNonFlatUseOfReg(MRI, *TII, AMDGPU::FLAT_SCR_HI))) {
636  Info.UsesFlatScratch = false;
637  }
638 
639  Info.HasDynamicallySizedStack = FrameInfo.hasVarSizedObjects();
640  Info.PrivateSegmentSize = FrameInfo.getStackSize();
641  if (MFI->isStackRealigned())
642  Info.PrivateSegmentSize += FrameInfo.getMaxAlignment();
643 
644 
645  Info.UsesVCC = MRI.isPhysRegUsed(AMDGPU::VCC_LO) ||
646  MRI.isPhysRegUsed(AMDGPU::VCC_HI);
647 
648  // If there are no calls, MachineRegisterInfo can tell us the used register
649  // count easily.
650  // A tail call isn't considered a call for MachineFrameInfo's purposes.
651  if (!FrameInfo.hasCalls() && !FrameInfo.hasTailCall()) {
652  MCPhysReg HighestVGPRReg = AMDGPU::NoRegister;
653  for (MCPhysReg Reg : reverse(AMDGPU::VGPR_32RegClass.getRegisters())) {
654  if (MRI.isPhysRegUsed(Reg)) {
655  HighestVGPRReg = Reg;
656  break;
657  }
658  }
659 
660  if (ST.hasMAIInsts()) {
661  MCPhysReg HighestAGPRReg = AMDGPU::NoRegister;
662  for (MCPhysReg Reg : reverse(AMDGPU::AGPR_32RegClass.getRegisters())) {
663  if (MRI.isPhysRegUsed(Reg)) {
664  HighestAGPRReg = Reg;
665  break;
666  }
667  }
668  Info.NumAGPR = HighestAGPRReg == AMDGPU::NoRegister ? 0 :
669  TRI.getHWRegIndex(HighestAGPRReg) + 1;
670  }
671 
672  MCPhysReg HighestSGPRReg = AMDGPU::NoRegister;
673  for (MCPhysReg Reg : reverse(AMDGPU::SGPR_32RegClass.getRegisters())) {
674  if (MRI.isPhysRegUsed(Reg)) {
675  HighestSGPRReg = Reg;
676  break;
677  }
678  }
679 
680  // We found the maximum register index. They start at 0, so add one to get the
681  // number of registers.
682  Info.NumVGPR = HighestVGPRReg == AMDGPU::NoRegister ? 0 :
683  TRI.getHWRegIndex(HighestVGPRReg) + 1;
684  Info.NumExplicitSGPR = HighestSGPRReg == AMDGPU::NoRegister ? 0 :
685  TRI.getHWRegIndex(HighestSGPRReg) + 1;
686 
687  return Info;
688  }
689 
690  int32_t MaxVGPR = -1;
691  int32_t MaxAGPR = -1;
692  int32_t MaxSGPR = -1;
693  uint64_t CalleeFrameSize = 0;
694 
695  for (const MachineBasicBlock &MBB : MF) {
696  for (const MachineInstr &MI : MBB) {
697  // TODO: Check regmasks? Do they occur anywhere except calls?
698  for (const MachineOperand &MO : MI.operands()) {
699  unsigned Width = 0;
700  bool IsSGPR = false;
701  bool IsAGPR = false;
702 
703  if (!MO.isReg())
704  continue;
705 
706  Register Reg = MO.getReg();
707  switch (Reg) {
708  case AMDGPU::EXEC:
709  case AMDGPU::EXEC_LO:
710  case AMDGPU::EXEC_HI:
711  case AMDGPU::SCC:
712  case AMDGPU::M0:
713  case AMDGPU::SRC_SHARED_BASE:
714  case AMDGPU::SRC_SHARED_LIMIT:
715  case AMDGPU::SRC_PRIVATE_BASE:
716  case AMDGPU::SRC_PRIVATE_LIMIT:
717  case AMDGPU::SGPR_NULL:
718  continue;
719 
720  case AMDGPU::SRC_POPS_EXITING_WAVE_ID:
721  llvm_unreachable("src_pops_exiting_wave_id should not be used");
722 
723  case AMDGPU::NoRegister:
724  assert(MI.isDebugInstr());
725  continue;
726 
727  case AMDGPU::VCC:
728  case AMDGPU::VCC_LO:
729  case AMDGPU::VCC_HI:
730  Info.UsesVCC = true;
731  continue;
732 
733  case AMDGPU::FLAT_SCR:
734  case AMDGPU::FLAT_SCR_LO:
735  case AMDGPU::FLAT_SCR_HI:
736  continue;
737 
738  case AMDGPU::XNACK_MASK:
739  case AMDGPU::XNACK_MASK_LO:
740  case AMDGPU::XNACK_MASK_HI:
741  llvm_unreachable("xnack_mask registers should not be used");
742 
743  case AMDGPU::LDS_DIRECT:
744  llvm_unreachable("lds_direct register should not be used");
745 
746  case AMDGPU::TBA:
747  case AMDGPU::TBA_LO:
748  case AMDGPU::TBA_HI:
749  case AMDGPU::TMA:
750  case AMDGPU::TMA_LO:
751  case AMDGPU::TMA_HI:
752  llvm_unreachable("trap handler registers should not be used");
753 
754  case AMDGPU::SRC_VCCZ:
755  llvm_unreachable("src_vccz register should not be used");
756 
757  case AMDGPU::SRC_EXECZ:
758  llvm_unreachable("src_execz register should not be used");
759 
760  case AMDGPU::SRC_SCC:
761  llvm_unreachable("src_scc register should not be used");
762 
763  default:
764  break;
765  }
766 
767  if (AMDGPU::SReg_32RegClass.contains(Reg)) {
768  assert(!AMDGPU::TTMP_32RegClass.contains(Reg) &&
769  "trap handler registers should not be used");
770  IsSGPR = true;
771  Width = 1;
772  } else if (AMDGPU::VGPR_32RegClass.contains(Reg)) {
773  IsSGPR = false;
774  Width = 1;
775  } else if (AMDGPU::AGPR_32RegClass.contains(Reg)) {
776  IsSGPR = false;
777  IsAGPR = true;
778  Width = 1;
779  } else if (AMDGPU::SReg_64RegClass.contains(Reg)) {
780  assert(!AMDGPU::TTMP_64RegClass.contains(Reg) &&
781  "trap handler registers should not be used");
782  IsSGPR = true;
783  Width = 2;
784  } else if (AMDGPU::VReg_64RegClass.contains(Reg)) {
785  IsSGPR = false;
786  Width = 2;
787  } else if (AMDGPU::AReg_64RegClass.contains(Reg)) {
788  IsSGPR = false;
789  IsAGPR = true;
790  Width = 2;
791  } else if (AMDGPU::VReg_96RegClass.contains(Reg)) {
792  IsSGPR = false;
793  Width = 3;
794  } else if (AMDGPU::SReg_96RegClass.contains(Reg)) {
795  IsSGPR = true;
796  Width = 3;
797  } else if (AMDGPU::SReg_128RegClass.contains(Reg)) {
798  assert(!AMDGPU::TTMP_128RegClass.contains(Reg) &&
799  "trap handler registers should not be used");
800  IsSGPR = true;
801  Width = 4;
802  } else if (AMDGPU::VReg_128RegClass.contains(Reg)) {
803  IsSGPR = false;
804  Width = 4;
805  } else if (AMDGPU::AReg_128RegClass.contains(Reg)) {
806  IsSGPR = false;
807  IsAGPR = true;
808  Width = 4;
809  } else if (AMDGPU::VReg_160RegClass.contains(Reg)) {
810  IsSGPR = false;
811  Width = 5;
812  } else if (AMDGPU::SReg_160RegClass.contains(Reg)) {
813  IsSGPR = true;
814  Width = 5;
815  } else if (AMDGPU::SReg_256RegClass.contains(Reg)) {
816  assert(!AMDGPU::TTMP_256RegClass.contains(Reg) &&
817  "trap handler registers should not be used");
818  IsSGPR = true;
819  Width = 8;
820  } else if (AMDGPU::VReg_256RegClass.contains(Reg)) {
821  IsSGPR = false;
822  Width = 8;
823  } else if (AMDGPU::SReg_512RegClass.contains(Reg)) {
824  assert(!AMDGPU::TTMP_512RegClass.contains(Reg) &&
825  "trap handler registers should not be used");
826  IsSGPR = true;
827  Width = 16;
828  } else if (AMDGPU::VReg_512RegClass.contains(Reg)) {
829  IsSGPR = false;
830  Width = 16;
831  } else if (AMDGPU::AReg_512RegClass.contains(Reg)) {
832  IsSGPR = false;
833  IsAGPR = true;
834  Width = 16;
835  } else if (AMDGPU::SReg_1024RegClass.contains(Reg)) {
836  IsSGPR = true;
837  Width = 32;
838  } else if (AMDGPU::VReg_1024RegClass.contains(Reg)) {
839  IsSGPR = false;
840  Width = 32;
841  } else if (AMDGPU::AReg_1024RegClass.contains(Reg)) {
842  IsSGPR = false;
843  IsAGPR = true;
844  Width = 32;
845  } else {
846  llvm_unreachable("Unknown register class");
847  }
848  unsigned HWReg = TRI.getHWRegIndex(Reg);
849  int MaxUsed = HWReg + Width - 1;
850  if (IsSGPR) {
851  MaxSGPR = MaxUsed > MaxSGPR ? MaxUsed : MaxSGPR;
852  } else if (IsAGPR) {
853  MaxAGPR = MaxUsed > MaxAGPR ? MaxUsed : MaxAGPR;
854  } else {
855  MaxVGPR = MaxUsed > MaxVGPR ? MaxUsed : MaxVGPR;
856  }
857  }
858 
859  if (MI.isCall()) {
860  // Pseudo used just to encode the underlying global. Is there a better
861  // way to track this?
862 
863  const MachineOperand *CalleeOp
864  = TII->getNamedOperand(MI, AMDGPU::OpName::callee);
865  const Function *Callee = cast<Function>(CalleeOp->getGlobal());
866  if (Callee->isDeclaration()) {
867  // If this is a call to an external function, we can't do much. Make
868  // conservative guesses.
869 
870  // 48 SGPRs - vcc, - flat_scr, -xnack
871  int MaxSGPRGuess =
872  47 - IsaInfo::getNumExtraSGPRs(&ST, true, ST.hasFlatAddressSpace());
873  MaxSGPR = std::max(MaxSGPR, MaxSGPRGuess);
874  MaxVGPR = std::max(MaxVGPR, 23);
875  MaxAGPR = std::max(MaxAGPR, 23);
876 
877  CalleeFrameSize = std::max(CalleeFrameSize, UINT64_C(16384));
878  Info.UsesVCC = true;
879  Info.UsesFlatScratch = ST.hasFlatAddressSpace();
880  Info.HasDynamicallySizedStack = true;
881  } else {
882  // We force CodeGen to run in SCC order, so the callee's register
883  // usage etc. should be the cumulative usage of all callees.
884 
885  auto I = CallGraphResourceInfo.find(Callee);
886  if (I == CallGraphResourceInfo.end()) {
887  // Avoid crashing on undefined behavior with an illegal call to a
888  // kernel. If a callsite's calling convention doesn't match the
889  // function's, it's undefined behavior. If the callsite calling
890  // convention does match, that would have errored earlier.
891  // FIXME: The verifier shouldn't allow this.
893  report_fatal_error("invalid call to entry function");
894 
895  llvm_unreachable("callee should have been handled before caller");
896  }
897 
898  MaxSGPR = std::max(I->second.NumExplicitSGPR - 1, MaxSGPR);
899  MaxVGPR = std::max(I->second.NumVGPR - 1, MaxVGPR);
900  MaxAGPR = std::max(I->second.NumAGPR - 1, MaxAGPR);
901  CalleeFrameSize
902  = std::max(I->second.PrivateSegmentSize, CalleeFrameSize);
903  Info.UsesVCC |= I->second.UsesVCC;
904  Info.UsesFlatScratch |= I->second.UsesFlatScratch;
905  Info.HasDynamicallySizedStack |= I->second.HasDynamicallySizedStack;
906  Info.HasRecursion |= I->second.HasRecursion;
907  }
908 
909  if (!Callee->doesNotRecurse())
910  Info.HasRecursion = true;
911  }
912  }
913  }
914 
915  Info.NumExplicitSGPR = MaxSGPR + 1;
916  Info.NumVGPR = MaxVGPR + 1;
917  Info.NumAGPR = MaxAGPR + 1;
918  Info.PrivateSegmentSize += CalleeFrameSize;
919 
920  return Info;
921 }
922 
923 void AMDGPUAsmPrinter::getSIProgramInfo(SIProgramInfo &ProgInfo,
924  const MachineFunction &MF) {
925  SIFunctionResourceInfo Info = analyzeResourceUsage(MF);
926  const GCNSubtarget &STM = MF.getSubtarget<GCNSubtarget>();
927 
928  ProgInfo.NumArchVGPR = Info.NumVGPR;
929  ProgInfo.NumAccVGPR = Info.NumAGPR;
930  ProgInfo.NumVGPR = Info.getTotalNumVGPRs(STM);
931  ProgInfo.NumSGPR = Info.NumExplicitSGPR;
932  ProgInfo.ScratchSize = Info.PrivateSegmentSize;
933  ProgInfo.VCCUsed = Info.UsesVCC;
934  ProgInfo.FlatUsed = Info.UsesFlatScratch;
935  ProgInfo.DynamicCallStack = Info.HasDynamicallySizedStack || Info.HasRecursion;
936 
937  if (!isUInt<32>(ProgInfo.ScratchSize)) {
938  DiagnosticInfoStackSize DiagStackSize(MF.getFunction(),
939  ProgInfo.ScratchSize, DS_Error);
940  MF.getFunction().getContext().diagnose(DiagStackSize);
941  }
942 
944 
945  // TODO(scott.linder): The calculations related to SGPR/VGPR blocks are
946  // duplicated in part in AMDGPUAsmParser::calculateGPRBlocks, and could be
947  // unified.
948  unsigned ExtraSGPRs = IsaInfo::getNumExtraSGPRs(
949  &STM, ProgInfo.VCCUsed, ProgInfo.FlatUsed);
950 
951  // Check the addressable register limit before we add ExtraSGPRs.
953  !STM.hasSGPRInitBug()) {
954  unsigned MaxAddressableNumSGPRs = STM.getAddressableNumSGPRs();
955  if (ProgInfo.NumSGPR > MaxAddressableNumSGPRs) {
956  // This can happen due to a compiler bug or when using inline asm.
957  LLVMContext &Ctx = MF.getFunction().getContext();
959  "addressable scalar registers",
960  ProgInfo.NumSGPR, DS_Error,
962  MaxAddressableNumSGPRs);
963  Ctx.diagnose(Diag);
964  ProgInfo.NumSGPR = MaxAddressableNumSGPRs - 1;
965  }
966  }
967 
968  // Account for extra SGPRs and VGPRs reserved for debugger use.
969  ProgInfo.NumSGPR += ExtraSGPRs;
970 
971  // Ensure there are enough SGPRs and VGPRs for wave dispatch, where wave
972  // dispatch registers are function args.
973  unsigned WaveDispatchNumSGPR = 0, WaveDispatchNumVGPR = 0;
974  for (auto &Arg : MF.getFunction().args()) {
975  unsigned NumRegs = (Arg.getType()->getPrimitiveSizeInBits() + 31) / 32;
976  if (Arg.hasAttribute(Attribute::InReg))
977  WaveDispatchNumSGPR += NumRegs;
978  else
979  WaveDispatchNumVGPR += NumRegs;
980  }
981  ProgInfo.NumSGPR = std::max(ProgInfo.NumSGPR, WaveDispatchNumSGPR);
982  ProgInfo.NumVGPR = std::max(ProgInfo.NumVGPR, WaveDispatchNumVGPR);
983 
984  // Adjust number of registers used to meet default/requested minimum/maximum
985  // number of waves per execution unit request.
986  ProgInfo.NumSGPRsForWavesPerEU = std::max(
987  std::max(ProgInfo.NumSGPR, 1u), STM.getMinNumSGPRs(MFI->getMaxWavesPerEU()));
988  ProgInfo.NumVGPRsForWavesPerEU = std::max(
989  std::max(ProgInfo.NumVGPR, 1u), STM.getMinNumVGPRs(MFI->getMaxWavesPerEU()));
990 
992  STM.hasSGPRInitBug()) {
993  unsigned MaxAddressableNumSGPRs = STM.getAddressableNumSGPRs();
994  if (ProgInfo.NumSGPR > MaxAddressableNumSGPRs) {
995  // This can happen due to a compiler bug or when using inline asm to use
996  // the registers which are usually reserved for vcc etc.
997  LLVMContext &Ctx = MF.getFunction().getContext();
999  "scalar registers",
1000  ProgInfo.NumSGPR, DS_Error,
1002  MaxAddressableNumSGPRs);
1003  Ctx.diagnose(Diag);
1004  ProgInfo.NumSGPR = MaxAddressableNumSGPRs;
1005  ProgInfo.NumSGPRsForWavesPerEU = MaxAddressableNumSGPRs;
1006  }
1007  }
1008 
1009  if (STM.hasSGPRInitBug()) {
1010  ProgInfo.NumSGPR =
1012  ProgInfo.NumSGPRsForWavesPerEU =
1014  }
1015 
1016  if (MFI->getNumUserSGPRs() > STM.getMaxNumUserSGPRs()) {
1017  LLVMContext &Ctx = MF.getFunction().getContext();
1018  DiagnosticInfoResourceLimit Diag(MF.getFunction(), "user SGPRs",
1019  MFI->getNumUserSGPRs(), DS_Error);
1020  Ctx.diagnose(Diag);
1021  }
1022 
1023  if (MFI->getLDSSize() > static_cast<unsigned>(STM.getLocalMemorySize())) {
1024  LLVMContext &Ctx = MF.getFunction().getContext();
1025  DiagnosticInfoResourceLimit Diag(MF.getFunction(), "local memory",
1026  MFI->getLDSSize(), DS_Error);
1027  Ctx.diagnose(Diag);
1028  }
1029 
1031  &STM, ProgInfo.NumSGPRsForWavesPerEU);
1033  &STM, ProgInfo.NumVGPRsForWavesPerEU);
1034 
1035  const SIModeRegisterDefaults Mode = MFI->getMode();
1036 
1037  // Set the value to initialize FP_ROUND and FP_DENORM parts of the mode
1038  // register.
1039  ProgInfo.FloatMode = getFPMode(Mode);
1040 
1041  ProgInfo.IEEEMode = Mode.IEEE;
1042 
1043  // Make clamp modifier on NaN input returns 0.
1044  ProgInfo.DX10Clamp = Mode.DX10Clamp;
1045 
1046  unsigned LDSAlignShift;
1048  // LDS is allocated in 64 dword blocks.
1049  LDSAlignShift = 8;
1050  } else {
1051  // LDS is allocated in 128 dword blocks.
1052  LDSAlignShift = 9;
1053  }
1054 
1055  unsigned LDSSpillSize =
1057 
1058  ProgInfo.LDSSize = MFI->getLDSSize() + LDSSpillSize;
1059  ProgInfo.LDSBlocks =
1060  alignTo(ProgInfo.LDSSize, 1ULL << LDSAlignShift) >> LDSAlignShift;
1061 
1062  // Scratch is allocated in 256 dword blocks.
1063  unsigned ScratchAlignShift = 10;
1064  // We need to program the hardware with the amount of scratch memory that
1065  // is used by the entire wave. ProgInfo.ScratchSize is the amount of
1066  // scratch memory used per thread.
1067  ProgInfo.ScratchBlocks =
1068  alignTo(ProgInfo.ScratchSize * STM.getWavefrontSize(),
1069  1ULL << ScratchAlignShift) >>
1070  ScratchAlignShift;
1071 
1072  if (getIsaVersion(getGlobalSTI()->getCPU()).Major >= 10) {
1073  ProgInfo.WgpMode = STM.isCuModeEnabled() ? 0 : 1;
1074  ProgInfo.MemOrdered = 1;
1075  }
1076 
1077  ProgInfo.ComputePGMRSrc1 =
1078  S_00B848_VGPRS(ProgInfo.VGPRBlocks) |
1079  S_00B848_SGPRS(ProgInfo.SGPRBlocks) |
1080  S_00B848_PRIORITY(ProgInfo.Priority) |
1081  S_00B848_FLOAT_MODE(ProgInfo.FloatMode) |
1082  S_00B848_PRIV(ProgInfo.Priv) |
1083  S_00B848_DX10_CLAMP(ProgInfo.DX10Clamp) |
1084  S_00B848_DEBUG_MODE(ProgInfo.DebugMode) |
1085  S_00B848_IEEE_MODE(ProgInfo.IEEEMode) |
1086  S_00B848_WGP_MODE(ProgInfo.WgpMode) |
1087  S_00B848_MEM_ORDERED(ProgInfo.MemOrdered);
1088 
1089  // 0 = X, 1 = XY, 2 = XYZ
1090  unsigned TIDIGCompCnt = 0;
1091  if (MFI->hasWorkItemIDZ())
1092  TIDIGCompCnt = 2;
1093  else if (MFI->hasWorkItemIDY())
1094  TIDIGCompCnt = 1;
1095 
1096  ProgInfo.ComputePGMRSrc2 =
1097  S_00B84C_SCRATCH_EN(ProgInfo.ScratchBlocks > 0) |
1099  // For AMDHSA, TRAP_HANDLER must be zero, as it is populated by the CP.
1105  S_00B84C_TIDIG_COMP_CNT(TIDIGCompCnt) |
1107  // For AMDHSA, LDS_SIZE must be zero, as it is populated by the CP.
1108  S_00B84C_LDS_SIZE(STM.isAmdHsaOS() ? 0 : ProgInfo.LDSBlocks) |
1109  S_00B84C_EXCP_EN(0);
1110 
1111  ProgInfo.Occupancy = STM.computeOccupancy(MF, ProgInfo.LDSSize,
1112  ProgInfo.NumSGPRsForWavesPerEU,
1113  ProgInfo.NumVGPRsForWavesPerEU);
1114 }
1115 
1116 static unsigned getRsrcReg(CallingConv::ID CallConv) {
1117  switch (CallConv) {
1118  default: LLVM_FALLTHROUGH;
1126  }
1127 }
1128 
1129 void AMDGPUAsmPrinter::EmitProgramInfoSI(const MachineFunction &MF,
1130  const SIProgramInfo &CurrentProgramInfo) {
1132  unsigned RsrcReg = getRsrcReg(MF.getFunction().getCallingConv());
1133 
1135  OutStreamer->EmitIntValue(R_00B848_COMPUTE_PGM_RSRC1, 4);
1136 
1137  OutStreamer->EmitIntValue(CurrentProgramInfo.ComputePGMRSrc1, 4);
1138 
1139  OutStreamer->EmitIntValue(R_00B84C_COMPUTE_PGM_RSRC2, 4);
1140  OutStreamer->EmitIntValue(CurrentProgramInfo.ComputePGMRSrc2, 4);
1141 
1142  OutStreamer->EmitIntValue(R_00B860_COMPUTE_TMPRING_SIZE, 4);
1143  OutStreamer->EmitIntValue(S_00B860_WAVESIZE(CurrentProgramInfo.ScratchBlocks), 4);
1144 
1145  // TODO: Should probably note flat usage somewhere. SC emits a "FlatPtr32 =
1146  // 0" comment but I don't see a corresponding field in the register spec.
1147  } else {
1148  OutStreamer->EmitIntValue(RsrcReg, 4);
1149  OutStreamer->EmitIntValue(S_00B028_VGPRS(CurrentProgramInfo.VGPRBlocks) |
1150  S_00B028_SGPRS(CurrentProgramInfo.SGPRBlocks), 4);
1151  OutStreamer->EmitIntValue(R_0286E8_SPI_TMPRING_SIZE, 4);
1152  OutStreamer->EmitIntValue(
1153  S_0286E8_WAVESIZE(CurrentProgramInfo.ScratchBlocks), 4);
1154  }
1155 
1158  OutStreamer->EmitIntValue(S_00B02C_EXTRA_LDS_SIZE(CurrentProgramInfo.LDSBlocks), 4);
1159  OutStreamer->EmitIntValue(R_0286CC_SPI_PS_INPUT_ENA, 4);
1160  OutStreamer->EmitIntValue(MFI->getPSInputEnable(), 4);
1161  OutStreamer->EmitIntValue(R_0286D0_SPI_PS_INPUT_ADDR, 4);
1162  OutStreamer->EmitIntValue(MFI->getPSInputAddr(), 4);
1163  }
1164 
1165  OutStreamer->EmitIntValue(R_SPILLED_SGPRS, 4);
1166  OutStreamer->EmitIntValue(MFI->getNumSpilledSGPRs(), 4);
1167  OutStreamer->EmitIntValue(R_SPILLED_VGPRS, 4);
1168  OutStreamer->EmitIntValue(MFI->getNumSpilledVGPRs(), 4);
1169 }
1170 
1171 // This is the equivalent of EmitProgramInfoSI above, but for when the OS type
1172 // is AMDPAL. It stores each compute/SPI register setting and other PAL
1173 // metadata items into the PALMD::Metadata, combining with any provided by the
1174 // frontend as LLVM metadata. Once all functions are written, the PAL metadata
1175 // is then written as a single block in the .note section.
1176 void AMDGPUAsmPrinter::EmitPALMetadata(const MachineFunction &MF,
1177  const SIProgramInfo &CurrentProgramInfo) {
1179  auto CC = MF.getFunction().getCallingConv();
1180  auto MD = getTargetStreamer()->getPALMetadata();
1181 
1182  MD->setEntryPoint(CC, MF.getFunction().getName());
1183  MD->setNumUsedVgprs(CC, CurrentProgramInfo.NumVGPRsForWavesPerEU);
1184  MD->setNumUsedSgprs(CC, CurrentProgramInfo.NumSGPRsForWavesPerEU);
1186  MD->setRsrc1(CC, CurrentProgramInfo.ComputePGMRSrc1);
1187  MD->setRsrc2(CC, CurrentProgramInfo.ComputePGMRSrc2);
1188  } else {
1189  MD->setRsrc1(CC, S_00B028_VGPRS(CurrentProgramInfo.VGPRBlocks) |
1190  S_00B028_SGPRS(CurrentProgramInfo.SGPRBlocks));
1191  if (CurrentProgramInfo.ScratchBlocks > 0)
1192  MD->setRsrc2(CC, S_00B84C_SCRATCH_EN(1));
1193  }
1194  // ScratchSize is in bytes, 16 aligned.
1195  MD->setScratchSize(CC, alignTo(CurrentProgramInfo.ScratchSize, 16));
1197  MD->setRsrc2(CC, S_00B02C_EXTRA_LDS_SIZE(CurrentProgramInfo.LDSBlocks));
1198  MD->setSpiPsInputEna(MFI->getPSInputEnable());
1199  MD->setSpiPsInputAddr(MFI->getPSInputAddr());
1200  }
1201 
1202  const GCNSubtarget &STM = MF.getSubtarget<GCNSubtarget>();
1203  if (STM.isWave32())
1204  MD->setWave32(MF.getFunction().getCallingConv());
1205 }
1206 
1207 // This is supposed to be log2(Size)
1209  switch (Size) {
1210  case 4:
1211  return AMD_ELEMENT_4_BYTES;
1212  case 8:
1213  return AMD_ELEMENT_8_BYTES;
1214  case 16:
1215  return AMD_ELEMENT_16_BYTES;
1216  default:
1217  llvm_unreachable("invalid private_element_size");
1218  }
1219 }
1220 
1221 void AMDGPUAsmPrinter::getAmdKernelCode(amd_kernel_code_t &Out,
1222  const SIProgramInfo &CurrentProgramInfo,
1223  const MachineFunction &MF) const {
1224  const Function &F = MF.getFunction();
1227 
1229  const GCNSubtarget &STM = MF.getSubtarget<GCNSubtarget>();
1230 
1232 
1234  CurrentProgramInfo.ComputePGMRSrc1 |
1235  (CurrentProgramInfo.ComputePGMRSrc2 << 32);
1237 
1238  if (CurrentProgramInfo.DynamicCallStack)
1240 
1243  getElementByteSizeValue(STM.getMaxPrivateElementSize()));
1244 
1245  if (MFI->hasPrivateSegmentBuffer()) {
1246  Out.code_properties |=
1248  }
1249 
1250  if (MFI->hasDispatchPtr())
1252 
1253  if (MFI->hasQueuePtr())
1255 
1256  if (MFI->hasKernargSegmentPtr())
1258 
1259  if (MFI->hasDispatchID())
1261 
1262  if (MFI->hasFlatScratchInit())
1264 
1265  if (MFI->hasDispatchPtr())
1267 
1268  if (STM.isXNACKEnabled())
1270 
1271  Align MaxKernArgAlign;
1272  Out.kernarg_segment_byte_size = STM.getKernArgSegmentSize(F, MaxKernArgAlign);
1273  Out.wavefront_sgpr_count = CurrentProgramInfo.NumSGPR;
1274  Out.workitem_vgpr_count = CurrentProgramInfo.NumVGPR;
1275  Out.workitem_private_segment_byte_size = CurrentProgramInfo.ScratchSize;
1276  Out.workgroup_group_segment_byte_size = CurrentProgramInfo.LDSSize;
1277 
1278  // kernarg_segment_alignment is specified as log of the alignment.
1279  // The minimum alignment is 16.
1280  Out.kernarg_segment_alignment = Log2(std::max(Align(16), MaxKernArgAlign));
1281 }
1282 
1284  const char *ExtraCode, raw_ostream &O) {
1285  // First try the generic code, which knows about modifiers like 'c' and 'n'.
1286  if (!AsmPrinter::PrintAsmOperand(MI, OpNo, ExtraCode, O))
1287  return false;
1288 
1289  if (ExtraCode && ExtraCode[0]) {
1290  if (ExtraCode[1] != 0)
1291  return true; // Unknown modifier.
1292 
1293  switch (ExtraCode[0]) {
1294  case 'r':
1295  break;
1296  default:
1297  return true;
1298  }
1299  }
1300 
1301  // TODO: Should be able to support other operand types like globals.
1302  const MachineOperand &MO = MI->getOperand(OpNo);
1303  if (MO.isReg()) {
1305  *MF->getSubtarget().getRegisterInfo());
1306  return false;
1307  }
1308 
1309  return true;
1310 }
virtual void EmitGlobalVariable(const GlobalVariable *GV)
Emit the specified global variable to the .s file.
Definition: AsmPrinter.cpp:454
unsigned Log2(Align A)
Returns the log2 of the alignment.
Definition: Alignment.h:204
constexpr bool isUInt< 32 >(uint64_t x)
Definition: MathExtras.h:385
const TargetLoweringObjectFile & getObjFileLowering() const
Return information about object file lowering.
Definition: AsmPrinter.cpp:214
unsigned getAlignment() const
Definition: GlobalObject.h:73
void EmitGlobalVariable(const GlobalVariable *GV) override
Emit the specified global variable to the .s file.
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:111
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
Interface definition for SIRegisterInfo.
Calling convention used for Mesa/AMDPAL hull shaders (= tessellation control shaders).
Definition: CallingConv.h:218
Target & getTheGCNTarget()
The target for GCN GPUs.
#define S_00B848_VGPRS(x)
Definition: SIDefines.h:552
#define S_00B848_PRIV(x)
Definition: SIDefines.h:564
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:239
LLVMContext & Context
AMDGPU specific subclass of TargetSubtarget.
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:95
SI Whole Quad Mode
#define FP_DENORM_MODE_SP(x)
Definition: SIDefines.h:606
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:140
This class represents lattice values for constants.
Definition: AllocatorList.h:23
bool isVariable() const
isVariable - Check if this is a variable symbol.
Definition: MCSymbol.h:289
#define R_00B228_SPI_SHADER_PGM_RSRC1_GS
Definition: SIDefines.h:503
#define G_00B84C_USER_SGPR(x)
Definition: SIDefines.h:516
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
const MCSubtargetInfo * getGlobalSTI() const
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:66
void redefineIfPossible()
Prepare this symbol to be redefined.
Definition: MCSymbol.h:223
bool doFinalization(Module &M) override
Shut down the asmprinter.
MCContext & OutContext
This is the context for the output file that we are streaming.
Definition: AsmPrinter.h:90
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
OSType getOS() const
getOS - Get the parsed operating system type of this triple.
Definition: Triple.h:306
void EmitFunctionBodyEnd() override
Targets can override this to emit stuff after the last basic block in the function.
Target & getTheAMDGPUTarget()
The target which supports all AMD GPUs.
#define G_00B84C_TGID_Z_EN(x)
Definition: SIDefines.h:528
unsigned Reg
#define R_00B028_SPI_SHADER_PGM_RSRC1_PS
Definition: SIDefines.h:499
iterator_range< reg_iterator > reg_operands(unsigned Reg) const
virtual void EmitAmdhsaKernelDescriptor(const MCSubtargetInfo &STI, StringRef KernelName, const amdhsa::kernel_descriptor_t &KernelDescriptor, uint64_t NextVGPR, uint64_t NextSGPR, bool ReserveVCC, bool ReserveFlatScr, bool ReserveXNACK)=0
Instruction set architecture version.
Definition: TargetParser.h:136
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...
#define S_00B84C_SCRATCH_EN(x)
Definition: SIDefines.h:512
const SIInstrInfo * getInstrInfo() const override
#define S_00B84C_TG_SIZE_EN(x)
Definition: SIDefines.h:530
#define S_00B848_DX10_CLAMP(x)
Definition: SIDefines.h:567
#define S_00B848_WGP_MODE(x)
Definition: SIDefines.h:576
uint32_t NumSGPRsForWavesPerEU
Definition: SIProgramInfo.h:51
unsigned const TargetRegisterInfo * TRI
F(f)
MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:98
#define G_00B84C_TGID_Y_EN(x)
Definition: SIDefines.h:525
Calling convention used for AMDPAL vertex shader if tessellation is in use.
Definition: CallingConv.h:226
Interface definition for R600RegisterInfo.
unsigned getMinNumSGPRs(unsigned WavesPerEU) const
#define R_0286CC_SPI_PS_INPUT_ENA
Definition: SIDefines.h:548
#define S_00B028_SGPRS(x)
Definition: SIDefines.h:509
AsmPrinter * createR600AsmPrinterPass(TargetMachine &TM, std::unique_ptr< MCStreamer > &&Streamer)
Track resource usage for kernels / entry functions.
Definition: SIProgramInfo.h:21
void setEntryPoint(unsigned CC, StringRef Name)
Calling convention used for Mesa/AMDPAL geometry shaders.
Definition: CallingConv.h:202
virtual void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type)=0
const SIRegisterInfo & getRegisterInfo() const
Definition: SIInstrInfo.h:173
return AArch64::GPR64RegClass contains(Reg)
const Triple & getTargetTriple() const
static amd_element_byte_size_t getElementByteSizeValue(unsigned Size)
#define S_00B848_MEM_ORDERED(x)
Definition: SIDefines.h:579
#define FP_DENORM_FLUSH_NONE
Definition: SIDefines.h:601
uint32_t code_properties
Code properties.
void setAlignment(Align A)
setAlignment - Set the alignment of the function.
Definition: BitVector.h:937
SPIR_KERNEL - Calling convention for SPIR kernel functions.
Definition: CallingConv.h:147
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
static bool isFLAT(const MachineInstr &MI)
Definition: SIInstrInfo.h:497
const DataLayout & getDataLayout() const
Get the data layout for the module&#39;s target platform.
Definition: Module.cpp:369
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:80
unsigned getInstSizeInBytes(const MachineInstr &MI) const override
const HexagonInstrInfo * TII
int getLocalMemorySize() const
AMD Kernel Code Object (amd_kernel_code_t).
static void printRegOperand(unsigned RegNo, raw_ostream &O, const MCRegisterInfo &MRI)
bool IEEE
Floating point opcodes that support exception flag gathering quiet and propagate signaling NaN inputs...
#define G_00B84C_TRAP_HANDLER(x)
Definition: SIDefines.h:519
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
AMDGPUAsmPrinter(TargetMachine &TM, std::unique_ptr< MCStreamer > Streamer)
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:426
bool isTrapHandlerEnabled() const
#define FP_ROUND_MODE_SP(x)
Definition: SIDefines.h:595
Diagnostic information for stack size etc.
#define S_00B84C_TGID_Y_EN(x)
Definition: SIDefines.h:524
bool hasCodeObjectV3(const MCSubtargetInfo *STI)
unsigned getTotalNumVGPRs(const MCSubtargetInfo *STI)
Context object for machine code objects.
Definition: MCContext.h:65
auto reverse(ContainerTy &&C, typename std::enable_if< has_rbegin< ContainerTy >::value >::type *=nullptr) -> decltype(make_range(C.rbegin(), C.rend()))
Definition: STLExtras.h:265
#define S_00B848_FLOAT_MODE(x)
Definition: SIDefines.h:561
#define R_00B848_COMPUTE_PGM_RSRC1
Definition: SIDefines.h:551
uint8_t kernarg_segment_alignment
The maximum byte alignment of variables used by the kernel in the specified memory segment...
void EmitFunctionBody()
This method emits the body and trailer for a function.
virtual bool EmitCodeEnd()=0
unsigned getNumExtraSGPRs(const MCSubtargetInfo *STI, bool VCCUsed, bool FlatScrUsed, bool XNACKUsed)
unsigned getAddressableNumSGPRs() const
LLVM_READONLY MachineOperand * getNamedOperand(MachineInstr &MI, unsigned OperandName) const
Returns the operand named Op.
#define S_00B84C_TRAP_HANDLER(x)
Definition: SIDefines.h:518
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they&#39;re not in a MachineFuncti...
uint64_t ComputePGMRSrc2
Definition: SIProgramInfo.h:41
bool isVerbose() const
Return true if assembly output should contain comments.
Definition: AsmPrinter.h:213
uint64_t compute_pgm_resource_registers
Shader program settings for CS.
Analysis containing CSE Info
Definition: CSEInfo.cpp:25
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
bool dumpCode() const
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
Definition: MCRegister.h:19
Calling convention used for Mesa/AMDPAL compute shaders.
Definition: CallingConv.h:208
uint32_t NumVGPRsForWavesPerEU
Definition: SIProgramInfo.h:54
bool isBlockOnlyReachableByFallthrough(const MachineBasicBlock *MBB) const override
Return true if the basic block has exactly one predecessor and the control transfer mechanism between...
#define S_00B848_IEEE_MODE(x)
Definition: SIDefines.h:573
bool isCompute(CallingConv::ID cc)
#define S_00B028_VGPRS(x)
Definition: SIDefines.h:508
uint16_t wavefront_sgpr_count
Number of scalar registers used by a wavefront.
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
unsigned const MachineRegisterInfo * MRI
VisibilityTypes getVisibility() const
Definition: GlobalValue.h:236
bool isGFX10(const MCSubtargetInfo &STI)
AMDGPUPALMetadata * getPALMetadata()
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:63
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
#define G_00B84C_TGID_X_EN(x)
Definition: SIDefines.h:522
#define S_00B84C_TIDIG_COMP_CNT(x)
Definition: SIDefines.h:533
#define FP_ROUND_MODE_DP(x)
Definition: SIDefines.h:596
const GlobalValue * getGlobal() const
TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
Definition: DataLayout.h:486
virtual bool isBlockOnlyReachableByFallthrough(const MachineBasicBlock *MBB) const
Return true if the basic block has exactly one predecessor and the control transfer mechanism between...
bool isEntryFunctionCC(CallingConv::ID CC)
TargetMachine & TM
Target machine description.
Definition: AsmPrinter.h:83
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:80
void getNameWithPrefix(SmallVectorImpl< char > &Name, const GlobalValue *GV) const
Definition: AsmPrinter.cpp:444
void EmitEndOfAsmFile(Module &M) override
This virtual method can be overridden by targets that want to emit something at the end of their file...
AMDGPU::SIModeRegisterDefaults getMode() const
bool isCuModeEnabled() const
unsigned getAddressSpace() const
Definition: Globals.cpp:111
#define S_00B84C_EXCP_EN_MSB(x)
Definition: SIDefines.h:537
bool DX10Clamp
Used by the vector ALU to force DX10-style treatment of NaNs: when set, clamp NaN to zero; otherwise...
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
void reportError(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:690
Generation getGeneration() const
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
const Triple & getTargetTriple() const
#define R_00B02C_SPI_SHADER_PGM_RSRC2_PS
Definition: SIDefines.h:500
#define FP_DENORM_FLUSH_IN_FLUSH_OUT
Definition: SIDefines.h:598
#define S_00B84C_TGID_Z_EN(x)
Definition: SIDefines.h:527
The AMDGPU TargetMachine interface definition for hw codgen targets.
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
Definition: Function.cpp:223
#define R_00B328_SPI_SHADER_PGM_RSRC1_ES
Definition: SIDefines.h:504
#define S_00B84C_LDS_SIZE(x)
Definition: SIDefines.h:541
#define R_SPILLED_SGPRS
Definition: SIDefines.h:624
virtual void EmitDirectiveHSACodeObjectISA(uint32_t Major, uint32_t Minor, uint32_t Stepping, StringRef VendorName, StringRef ArchName)=0
std::string & str()
Flushes the stream contents to the target string and returns the string&#39;s reference.
Definition: raw_ostream.h:532
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:40
amd_element_byte_size_t
The values used to define the number of bytes to use for the swizzle element size.
constexpr bool empty(const T &RangeOrContainer)
Test whether RangeOrContainer is empty. Similar to C++17 std::empty.
Definition: STLExtras.h:192
#define FP_ROUND_ROUND_TO_NEAREST
Definition: SIDefines.h:588
bool doesNotRecurse() const
Determine if the function is known not to recurse, directly or indirectly.
Definition: Function.h:588
#define S_00B84C_EXCP_EN(x)
Definition: SIDefines.h:544
IsaVersion getIsaVersion(StringRef GPU)
unsigned getWavefrontSize() const
#define R_00B428_SPI_SHADER_PGM_RSRC1_HS
Definition: SIDefines.h:505
AMDGPUTargetStreamer * getTargetStreamer() const
unsigned getFunctionNumber() const
Return a unique ID for the current function.
Definition: AsmPrinter.cpp:210
#define G_00B84C_TIDIG_COMP_CNT(x)
Definition: SIDefines.h:534
MCStreamer & getStreamer()
Definition: MCStreamer.h:99
void EmitBasicBlockStart(const MachineBasicBlock &MBB) override
Targets can override this to emit stuff at the start of a basic block.
std::vector< std::string > HexLines
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
Definition: STLExtras.h:1163
Align max(MaybeAlign Lhs, Align Rhs)
Definition: Alignment.h:390
#define R_00B128_SPI_SHADER_PGM_RSRC1_VS
Definition: SIDefines.h:502
uint64_t kernarg_segment_byte_size
The size in bytes of the kernarg segment that holds the values of the arguments to the kernel...
unsigned getTotalNumSGPRs(const MCSubtargetInfo *STI)
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: AsmPrinter.cpp:449
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Definition: Function.h:212
Address space for local memory.
Definition: AMDGPU.h:276
R600 Assembly printer class.
MachineOperand class - Representation of each machine instruction operand.
Calling convention used for Mesa/AMDPAL pixel shaders.
Definition: CallingConv.h:205
const MCSubtargetInfo * getMCSubtargetInfo() const
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...
virtual void EmitAMDKernelCodeT(const amd_kernel_code_t &Header)=0
uint16_t workitem_vgpr_count
Number of vector registers used by each work-item.
bool hasSGPRInitBug() const
#define LLVM_EXTERNAL_VISIBILITY
Definition: Compiler.h:130
#define S_00B848_DEBUG_MODE(x)
Definition: SIDefines.h:570
#define FP_DENORM_MODE_DP(x)
Definition: SIDefines.h:607
#define S_0286E8_WAVESIZE(x)
Definition: SIDefines.h:613
const Function & getFunction() const
Return the LLVM function that this machine code represents.
#define S_00B84C_TGID_X_EN(x)
Definition: SIDefines.h:521
bool runOnMachineFunction(MachineFunction &MF) override
Emit the specified function out to the OutStreamer.
bool isPhysRegUsed(unsigned PhysReg) const
Return true if the specified register is modified or read in this function.
uint32_t workgroup_group_segment_byte_size
The amount of group segment memory required by a work-group in bytes.
bool isDefined() const
isDefined - Check if this symbol is defined (i.e., it has an address).
Definition: MCSymbol.h:241
#define AMD_HSA_BITS_SET(dst, mask, val)
amdgpu Simplify well known AMD library false FunctionCallee Callee
std::vector< std::string > DisasmLines
virtual void EmitDirectiveHSACodeObjectVersion(uint32_t Major, uint32_t Minor)=0
unsigned computeOccupancy(const MachineFunction &MF, unsigned LDSSize=0, unsigned NumSGPRs=0, unsigned NumVGPRs=0) const
Return occupancy for the given function.
unsigned getNumVGPRBlocks(const MCSubtargetInfo *STI, unsigned NumVGPRs, Optional< bool > EnableWavefrontSize32)
void EmitFunctionEntryLabel() override
EmitFunctionEntryLabel - Emit the label that is the entrypoint for the function.
static AsmPrinter * createAMDGPUAsmPrinterPass(TargetMachine &tm, std::unique_ptr< MCStreamer > &&Streamer)
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
#define Success
virtual bool EmitISAVersion(StringRef IsaVersionString)=0
Provides AMDGPU specific target descriptions.
Representation of each machine instruction.
Definition: MachineInstr.h:63
void EmitFunctionBodyStart() override
Targets can override this to emit stuff before the first basic block in the function.
virtual void EmitDirectiveAMDGCNTarget(StringRef Target)=0
bool doFinalization(Module &M) override
Shut down the asmprinter.
void EmitLinkage(const GlobalValue *GV, MCSymbol *GVSym) const
This emits linkage information about GVSym based on GV, if this is supported by the target...
Definition: AsmPrinter.cpp:400
This class keeps track of the SPI_SP_INPUT_ADDR config register, which tells the hardware which inter...
Interface definition for SIInstrInfo.
virtual void SetupMachineFunction(MachineFunction &MF)
This should be called when a new MachineFunction is being processed from runOnMachineFunction.
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition: Alignment.h:163
void LLVM_EXTERNAL_VISIBILITY LLVMInitializeAMDGPUAsmPrinter()
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
unsigned getNumSGPRBlocks(const MCSubtargetInfo *STI, unsigned NumSGPRs)
#define S_00B848_SGPRS(x)
Definition: SIDefines.h:555
bool hasXNACK(const MCSubtargetInfo &STI)
StringRef getName() const
Return a constant reference to the value&#39;s name.
Definition: Value.cpp:215
uint32_t workitem_private_segment_byte_size
The amount of memory required for the combined private, spill and arg segments for a work-item in byt...
Calling convention used for Mesa vertex shaders, or AMDPAL last shader stage before rasterization (ve...
Definition: CallingConv.h:199
#define S_00B84C_USER_SGPR(x)
Definition: SIDefines.h:515
#define I(x, y, z)
Definition: MD5.cpp:58
AMDGPU Assembly printer class.
#define R_00B860_COMPUTE_TMPRING_SIZE
Definition: SIDefines.h:609
Generic base class for all target subtargets.
bool isAmdHsaOrMesa(const Function &F) const
This represents a section on linux, lots of unix variants and some bare metal systems.
Definition: MCSectionELF.h:27
Type * getValueType() const
Definition: GlobalValue.h:279
uint32_t Size
Definition: Profile.cpp:46
#define R_SPILLED_VGPRS
Definition: SIDefines.h:625
void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
static bool hasAnyNonFlatUseOfReg(const MachineRegisterInfo &MRI, const SIInstrInfo &TII, unsigned Reg)
virtual void EmitFunctionEntryLabel()
EmitFunctionEntryLabel - Emit the label that is the entrypoint for the function.
Definition: AsmPrinter.cpp:774
bool isReg() const
isReg - Tests if this is a MO_Register operand.
unsigned getMinNumVGPRs(unsigned WavesPerEU) const
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Definition: Globals.cpp:231
StringRef getName() const
getName - Get the symbol name.
Definition: MCSymbol.h:196
static unsigned getRsrcReg(CallingConv::ID CallConv)
static StringRef getCPU(StringRef CPU)
Processes a CPU name.
unsigned getMaxNumUserSGPRs() const
#define S_00B860_WAVESIZE(x)
Definition: SIDefines.h:610
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
#define R_00B84C_COMPUTE_PGM_RSRC2
Definition: SIDefines.h:511
#define S_00B848_PRIORITY(x)
Definition: SIDefines.h:558
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:516
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
void EmitStartOfAsmFile(Module &M) override
This virtual method can be overridden by targets that want to emit something at the start of their fi...
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:575
uint64_t ComputePGMRSrc1
Definition: SIProgramInfo.h:35
bool hasInitializer() const
Definitions have initializers, declarations don&#39;t.
#define R_0286E8_SPI_TMPRING_SIZE
Definition: SIDefines.h:612
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Definition: Compiler.h:279
unsigned getHWRegIndex(unsigned Reg) const
#define S_00B02C_EXTRA_LDS_SIZE(x)
Definition: SIDefines.h:501
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
bool hasMAIInsts() const
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:65
static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn)
RegisterAsmPrinter - Register an AsmPrinter implementation for the given target.
IRTranslator LLVM IR MI
#define R_00B528_SPI_SHADER_PGM_RSRC1_LS
Definition: SIDefines.h:506
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:54
AMDGPU metadata definitions and in-memory representations.
virtual void EmitBasicBlockStart(const MachineBasicBlock &MBB)
Targets can override this to emit stuff at the start of a basic block.
#define R_0286D0_SPI_PS_INPUT_ADDR
Definition: SIDefines.h:549
Register getReg() const
getReg - Returns the register number.
void EmitVisibility(MCSymbol *Sym, unsigned Visibility, bool IsDefinition=true) const
This emits visibility information about symbol, if this is supported by the target.
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:431
void initDefaultAMDKernelCodeT(amd_kernel_code_t &Header, const MCSubtargetInfo *STI)
static uint32_t getFPMode(AMDGPU::SIModeRegisterDefaults Mode)
Calling convention for AMDGPU code object kernels.
Definition: CallingConv.h:211
const uint64_t Version
Definition: InstrProf.h:980
MCCodeEmitter * getEmitterPtr() const
Definition: MCAssembler.h:285
void streamIsaVersion(const MCSubtargetInfo *STI, raw_ostream &Stream)
Streams isa version string for given subtarget STI into Stream.
iterator_range< arg_iterator > args()
Definition: Function.h:730
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
Calling convention used for AMDPAL shader stage before geometry shader if geometry is in use...
Definition: CallingConv.h:231
bool hasCodeObjectV3() const