LLVM 21.0.0git
AMDGPUBaseInfo.cpp
Go to the documentation of this file.
1//===- AMDGPUBaseInfo.cpp - AMDGPU Base encoding information --------------===//
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#include "AMDGPUBaseInfo.h"
10#include "AMDGPU.h"
11#include "AMDGPUAsmUtils.h"
12#include "AMDKernelCodeT.h"
17#include "llvm/IR/Attributes.h"
18#include "llvm/IR/Constants.h"
19#include "llvm/IR/Function.h"
20#include "llvm/IR/GlobalValue.h"
21#include "llvm/IR/IntrinsicsAMDGPU.h"
22#include "llvm/IR/IntrinsicsR600.h"
23#include "llvm/IR/LLVMContext.h"
24#include "llvm/MC/MCInstrInfo.h"
29#include <optional>
30
31#define GET_INSTRINFO_NAMED_OPS
32#define GET_INSTRMAP_INFO
33#include "AMDGPUGenInstrInfo.inc"
34
36 "amdhsa-code-object-version", llvm::cl::Hidden,
38 llvm::cl::desc("Set default AMDHSA Code Object Version (module flag "
39 "or asm directive still take priority if present)"));
40
41namespace {
42
43/// \returns Bit mask for given bit \p Shift and bit \p Width.
44unsigned getBitMask(unsigned Shift, unsigned Width) {
45 return ((1 << Width) - 1) << Shift;
46}
47
48/// Packs \p Src into \p Dst for given bit \p Shift and bit \p Width.
49///
50/// \returns Packed \p Dst.
51unsigned packBits(unsigned Src, unsigned Dst, unsigned Shift, unsigned Width) {
52 unsigned Mask = getBitMask(Shift, Width);
53 return ((Src << Shift) & Mask) | (Dst & ~Mask);
54}
55
56/// Unpacks bits from \p Src for given bit \p Shift and bit \p Width.
57///
58/// \returns Unpacked bits.
59unsigned unpackBits(unsigned Src, unsigned Shift, unsigned Width) {
60 return (Src & getBitMask(Shift, Width)) >> Shift;
61}
62
63/// \returns Vmcnt bit shift (lower bits).
64unsigned getVmcntBitShiftLo(unsigned VersionMajor) {
65 return VersionMajor >= 11 ? 10 : 0;
66}
67
68/// \returns Vmcnt bit width (lower bits).
69unsigned getVmcntBitWidthLo(unsigned VersionMajor) {
70 return VersionMajor >= 11 ? 6 : 4;
71}
72
73/// \returns Expcnt bit shift.
74unsigned getExpcntBitShift(unsigned VersionMajor) {
75 return VersionMajor >= 11 ? 0 : 4;
76}
77
78/// \returns Expcnt bit width.
79unsigned getExpcntBitWidth(unsigned VersionMajor) { return 3; }
80
81/// \returns Lgkmcnt bit shift.
82unsigned getLgkmcntBitShift(unsigned VersionMajor) {
83 return VersionMajor >= 11 ? 4 : 8;
84}
85
86/// \returns Lgkmcnt bit width.
87unsigned getLgkmcntBitWidth(unsigned VersionMajor) {
88 return VersionMajor >= 10 ? 6 : 4;
89}
90
91/// \returns Vmcnt bit shift (higher bits).
92unsigned getVmcntBitShiftHi(unsigned VersionMajor) { return 14; }
93
94/// \returns Vmcnt bit width (higher bits).
95unsigned getVmcntBitWidthHi(unsigned VersionMajor) {
96 return (VersionMajor == 9 || VersionMajor == 10) ? 2 : 0;
97}
98
99/// \returns Loadcnt bit width
100unsigned getLoadcntBitWidth(unsigned VersionMajor) {
101 return VersionMajor >= 12 ? 6 : 0;
102}
103
104/// \returns Samplecnt bit width.
105unsigned getSamplecntBitWidth(unsigned VersionMajor) {
106 return VersionMajor >= 12 ? 6 : 0;
107}
108
109/// \returns Bvhcnt bit width.
110unsigned getBvhcntBitWidth(unsigned VersionMajor) {
111 return VersionMajor >= 12 ? 3 : 0;
112}
113
114/// \returns Dscnt bit width.
115unsigned getDscntBitWidth(unsigned VersionMajor) {
116 return VersionMajor >= 12 ? 6 : 0;
117}
118
119/// \returns Dscnt bit shift in combined S_WAIT instructions.
120unsigned getDscntBitShift(unsigned VersionMajor) { return 0; }
121
122/// \returns Storecnt or Vscnt bit width, depending on VersionMajor.
123unsigned getStorecntBitWidth(unsigned VersionMajor) {
124 return VersionMajor >= 10 ? 6 : 0;
125}
126
127/// \returns Kmcnt bit width.
128unsigned getKmcntBitWidth(unsigned VersionMajor) {
129 return VersionMajor >= 12 ? 5 : 0;
130}
131
132/// \returns shift for Loadcnt/Storecnt in combined S_WAIT instructions.
133unsigned getLoadcntStorecntBitShift(unsigned VersionMajor) {
134 return VersionMajor >= 12 ? 8 : 0;
135}
136
137/// \returns VaSdst bit width
138inline unsigned getVaSdstBitWidth() { return 3; }
139
140/// \returns VaSdst bit shift
141inline unsigned getVaSdstBitShift() { return 9; }
142
143/// \returns VmVsrc bit width
144inline unsigned getVmVsrcBitWidth() { return 3; }
145
146/// \returns VmVsrc bit shift
147inline unsigned getVmVsrcBitShift() { return 2; }
148
149/// \returns VaVdst bit width
150inline unsigned getVaVdstBitWidth() { return 4; }
151
152/// \returns VaVdst bit shift
153inline unsigned getVaVdstBitShift() { return 12; }
154
155/// \returns VaVcc bit width
156inline unsigned getVaVccBitWidth() { return 1; }
157
158/// \returns VaVcc bit shift
159inline unsigned getVaVccBitShift() { return 1; }
160
161/// \returns SaSdst bit width
162inline unsigned getSaSdstBitWidth() { return 1; }
163
164/// \returns SaSdst bit shift
165inline unsigned getSaSdstBitShift() { return 0; }
166
167} // end anonymous namespace
168
169namespace llvm {
170
171namespace AMDGPU {
172
173/// \returns true if the target supports signed immediate offset for SMRD
174/// instructions.
176 return isGFX9Plus(ST);
177}
178
179/// \returns True if \p STI is AMDHSA.
180bool isHsaAbi(const MCSubtargetInfo &STI) {
181 return STI.getTargetTriple().getOS() == Triple::AMDHSA;
182}
183
185 if (auto *Ver = mdconst::extract_or_null<ConstantInt>(
186 M.getModuleFlag("amdhsa_code_object_version"))) {
187 return (unsigned)Ver->getZExtValue() / 100;
188 }
189
191}
192
195}
196
197unsigned getAMDHSACodeObjectVersion(unsigned ABIVersion) {
198 switch (ABIVersion) {
200 return 4;
202 return 5;
204 return 6;
205 default:
207 }
208}
209
210uint8_t getELFABIVersion(const Triple &T, unsigned CodeObjectVersion) {
211 if (T.getOS() != Triple::AMDHSA)
212 return 0;
213
214 switch (CodeObjectVersion) {
215 case 4:
217 case 5:
219 case 6:
221 default:
222 report_fatal_error("Unsupported AMDHSA Code Object Version " +
223 Twine(CodeObjectVersion));
224 }
225}
226
227unsigned getMultigridSyncArgImplicitArgPosition(unsigned CodeObjectVersion) {
228 switch (CodeObjectVersion) {
229 case AMDHSA_COV4:
230 return 48;
231 case AMDHSA_COV5:
232 case AMDHSA_COV6:
233 default:
235 }
236}
237
238
239// FIXME: All such magic numbers about the ABI should be in a
240// central TD file.
241unsigned getHostcallImplicitArgPosition(unsigned CodeObjectVersion) {
242 switch (CodeObjectVersion) {
243 case AMDHSA_COV4:
244 return 24;
245 case AMDHSA_COV5:
246 case AMDHSA_COV6:
247 default:
249 }
250}
251
252unsigned getDefaultQueueImplicitArgPosition(unsigned CodeObjectVersion) {
253 switch (CodeObjectVersion) {
254 case AMDHSA_COV4:
255 return 32;
256 case AMDHSA_COV5:
257 case AMDHSA_COV6:
258 default:
260 }
261}
262
263unsigned getCompletionActionImplicitArgPosition(unsigned CodeObjectVersion) {
264 switch (CodeObjectVersion) {
265 case AMDHSA_COV4:
266 return 40;
267 case AMDHSA_COV5:
268 case AMDHSA_COV6:
269 default:
271 }
272}
273
274#define GET_MIMGBaseOpcodesTable_IMPL
275#define GET_MIMGDimInfoTable_IMPL
276#define GET_MIMGInfoTable_IMPL
277#define GET_MIMGLZMappingTable_IMPL
278#define GET_MIMGMIPMappingTable_IMPL
279#define GET_MIMGBiasMappingTable_IMPL
280#define GET_MIMGOffsetMappingTable_IMPL
281#define GET_MIMGG16MappingTable_IMPL
282#define GET_MAIInstInfoTable_IMPL
283#include "AMDGPUGenSearchableTables.inc"
284
285int getMIMGOpcode(unsigned BaseOpcode, unsigned MIMGEncoding,
286 unsigned VDataDwords, unsigned VAddrDwords) {
287 const MIMGInfo *Info = getMIMGOpcodeHelper(BaseOpcode, MIMGEncoding,
288 VDataDwords, VAddrDwords);
289 return Info ? Info->Opcode : -1;
290}
291
293 const MIMGInfo *Info = getMIMGInfo(Opc);
294 return Info ? getMIMGBaseOpcodeInfo(Info->BaseOpcode) : nullptr;
295}
296
297int getMaskedMIMGOp(unsigned Opc, unsigned NewChannels) {
298 const MIMGInfo *OrigInfo = getMIMGInfo(Opc);
299 const MIMGInfo *NewInfo =
300 getMIMGOpcodeHelper(OrigInfo->BaseOpcode, OrigInfo->MIMGEncoding,
301 NewChannels, OrigInfo->VAddrDwords);
302 return NewInfo ? NewInfo->Opcode : -1;
303}
304
305unsigned getAddrSizeMIMGOp(const MIMGBaseOpcodeInfo *BaseOpcode,
306 const MIMGDimInfo *Dim, bool IsA16,
307 bool IsG16Supported) {
308 unsigned AddrWords = BaseOpcode->NumExtraArgs;
309 unsigned AddrComponents = (BaseOpcode->Coordinates ? Dim->NumCoords : 0) +
310 (BaseOpcode->LodOrClampOrMip ? 1 : 0);
311 if (IsA16)
312 AddrWords += divideCeil(AddrComponents, 2);
313 else
314 AddrWords += AddrComponents;
315
316 // Note: For subtargets that support A16 but not G16, enabling A16 also
317 // enables 16 bit gradients.
318 // For subtargets that support A16 (operand) and G16 (done with a different
319 // instruction encoding), they are independent.
320
321 if (BaseOpcode->Gradients) {
322 if ((IsA16 && !IsG16Supported) || BaseOpcode->G16)
323 // There are two gradients per coordinate, we pack them separately.
324 // For the 3d case,
325 // we get (dy/du, dx/du) (-, dz/du) (dy/dv, dx/dv) (-, dz/dv)
326 AddrWords += alignTo<2>(Dim->NumGradients / 2);
327 else
328 AddrWords += Dim->NumGradients;
329 }
330 return AddrWords;
331}
332
333struct MUBUFInfo {
341 bool tfe;
342};
343
344struct MTBUFInfo {
351};
352
353struct SMInfo {
356};
357
358struct VOPInfo {
361};
362
365};
366
369};
370
373};
374
379};
380
381struct VOPDInfo {
386};
387
391};
392
393#define GET_FP4FP8DstByteSelTable_DECL
394#define GET_FP4FP8DstByteSelTable_IMPL
395
399};
400
405};
406
407#define GET_MTBUFInfoTable_DECL
408#define GET_MTBUFInfoTable_IMPL
409#define GET_MUBUFInfoTable_DECL
410#define GET_MUBUFInfoTable_IMPL
411#define GET_SMInfoTable_DECL
412#define GET_SMInfoTable_IMPL
413#define GET_VOP1InfoTable_DECL
414#define GET_VOP1InfoTable_IMPL
415#define GET_VOP2InfoTable_DECL
416#define GET_VOP2InfoTable_IMPL
417#define GET_VOP3InfoTable_DECL
418#define GET_VOP3InfoTable_IMPL
419#define GET_VOPC64DPPTable_DECL
420#define GET_VOPC64DPPTable_IMPL
421#define GET_VOPC64DPP8Table_DECL
422#define GET_VOPC64DPP8Table_IMPL
423#define GET_VOPCAsmOnlyInfoTable_DECL
424#define GET_VOPCAsmOnlyInfoTable_IMPL
425#define GET_VOP3CAsmOnlyInfoTable_DECL
426#define GET_VOP3CAsmOnlyInfoTable_IMPL
427#define GET_VOPDComponentTable_DECL
428#define GET_VOPDComponentTable_IMPL
429#define GET_VOPDPairs_DECL
430#define GET_VOPDPairs_IMPL
431#define GET_VOPTrue16Table_DECL
432#define GET_VOPTrue16Table_IMPL
433#define GET_WMMAOpcode2AddrMappingTable_DECL
434#define GET_WMMAOpcode2AddrMappingTable_IMPL
435#define GET_WMMAOpcode3AddrMappingTable_DECL
436#define GET_WMMAOpcode3AddrMappingTable_IMPL
437#define GET_getMFMA_F8F6F4_WithSize_DECL
438#define GET_getMFMA_F8F6F4_WithSize_IMPL
439#define GET_isMFMA_F8F6F4Table_IMPL
440#define GET_isCvtScaleF32_F32F16ToF8F4Table_IMPL
441
442#include "AMDGPUGenSearchableTables.inc"
443
444int getMTBUFBaseOpcode(unsigned Opc) {
445 const MTBUFInfo *Info = getMTBUFInfoFromOpcode(Opc);
446 return Info ? Info->BaseOpcode : -1;
447}
448
449int getMTBUFOpcode(unsigned BaseOpc, unsigned Elements) {
450 const MTBUFInfo *Info = getMTBUFInfoFromBaseOpcodeAndElements(BaseOpc, Elements);
451 return Info ? Info->Opcode : -1;
452}
453
454int getMTBUFElements(unsigned Opc) {
455 const MTBUFInfo *Info = getMTBUFOpcodeHelper(Opc);
456 return Info ? Info->elements : 0;
457}
458
459bool getMTBUFHasVAddr(unsigned Opc) {
460 const MTBUFInfo *Info = getMTBUFOpcodeHelper(Opc);
461 return Info ? Info->has_vaddr : false;
462}
463
464bool getMTBUFHasSrsrc(unsigned Opc) {
465 const MTBUFInfo *Info = getMTBUFOpcodeHelper(Opc);
466 return Info ? Info->has_srsrc : false;
467}
468
469bool getMTBUFHasSoffset(unsigned Opc) {
470 const MTBUFInfo *Info = getMTBUFOpcodeHelper(Opc);
471 return Info ? Info->has_soffset : false;
472}
473
474int getMUBUFBaseOpcode(unsigned Opc) {
475 const MUBUFInfo *Info = getMUBUFInfoFromOpcode(Opc);
476 return Info ? Info->BaseOpcode : -1;
477}
478
479int getMUBUFOpcode(unsigned BaseOpc, unsigned Elements) {
480 const MUBUFInfo *Info = getMUBUFInfoFromBaseOpcodeAndElements(BaseOpc, Elements);
481 return Info ? Info->Opcode : -1;
482}
483
484int getMUBUFElements(unsigned Opc) {
485 const MUBUFInfo *Info = getMUBUFOpcodeHelper(Opc);
486 return Info ? Info->elements : 0;
487}
488
489bool getMUBUFHasVAddr(unsigned Opc) {
490 const MUBUFInfo *Info = getMUBUFOpcodeHelper(Opc);
491 return Info ? Info->has_vaddr : false;
492}
493
494bool getMUBUFHasSrsrc(unsigned Opc) {
495 const MUBUFInfo *Info = getMUBUFOpcodeHelper(Opc);
496 return Info ? Info->has_srsrc : false;
497}
498
499bool getMUBUFHasSoffset(unsigned Opc) {
500 const MUBUFInfo *Info = getMUBUFOpcodeHelper(Opc);
501 return Info ? Info->has_soffset : false;
502}
503
504bool getMUBUFIsBufferInv(unsigned Opc) {
505 const MUBUFInfo *Info = getMUBUFOpcodeHelper(Opc);
506 return Info ? Info->IsBufferInv : false;
507}
508
509bool getMUBUFTfe(unsigned Opc) {
510 const MUBUFInfo *Info = getMUBUFOpcodeHelper(Opc);
511 return Info ? Info->tfe : false;
512}
513
514bool getSMEMIsBuffer(unsigned Opc) {
515 const SMInfo *Info = getSMEMOpcodeHelper(Opc);
516 return Info ? Info->IsBuffer : false;
517}
518
519bool getVOP1IsSingle(unsigned Opc) {
520 const VOPInfo *Info = getVOP1OpcodeHelper(Opc);
521 return Info ? Info->IsSingle : true;
522}
523
524bool getVOP2IsSingle(unsigned Opc) {
525 const VOPInfo *Info = getVOP2OpcodeHelper(Opc);
526 return Info ? Info->IsSingle : true;
527}
528
529bool getVOP3IsSingle(unsigned Opc) {
530 const VOPInfo *Info = getVOP3OpcodeHelper(Opc);
531 return Info ? Info->IsSingle : true;
532}
533
534bool isVOPC64DPP(unsigned Opc) {
535 return isVOPC64DPPOpcodeHelper(Opc) || isVOPC64DPP8OpcodeHelper(Opc);
536}
537
538bool isVOPCAsmOnly(unsigned Opc) { return isVOPCAsmOnlyOpcodeHelper(Opc); }
539
540bool getMAIIsDGEMM(unsigned Opc) {
541 const MAIInstInfo *Info = getMAIInstInfoHelper(Opc);
542 return Info ? Info->is_dgemm : false;
543}
544
545bool getMAIIsGFX940XDL(unsigned Opc) {
546 const MAIInstInfo *Info = getMAIInstInfoHelper(Opc);
547 return Info ? Info->is_gfx940_xdl : false;
548}
549
551 switch (EncodingVal) {
554 return 6;
556 return 4;
559 default:
560 return 8;
561 }
562
563 llvm_unreachable("covered switch over mfma scale formats");
564}
565
567 unsigned BLGP,
568 unsigned F8F8Opcode) {
569 uint8_t SrcANumRegs = mfmaScaleF8F6F4FormatToNumRegs(CBSZ);
570 uint8_t SrcBNumRegs = mfmaScaleF8F6F4FormatToNumRegs(BLGP);
571 return getMFMA_F8F6F4_InstWithNumRegs(SrcANumRegs, SrcBNumRegs, F8F8Opcode);
572}
573
575 if (ST.hasFeature(AMDGPU::FeatureGFX12Insts))
577 if (ST.hasFeature(AMDGPU::FeatureGFX11Insts))
579 llvm_unreachable("Subtarget generation does not support VOPD!");
580}
581
582CanBeVOPD getCanBeVOPD(unsigned Opc) {
583 const VOPDComponentInfo *Info = getVOPDComponentHelper(Opc);
584 if (Info)
585 return {Info->CanBeVOPDX, true};
586 return {false, false};
587}
588
589unsigned getVOPDOpcode(unsigned Opc) {
590 const VOPDComponentInfo *Info = getVOPDComponentHelper(Opc);
591 return Info ? Info->VOPDOp : ~0u;
592}
593
594bool isVOPD(unsigned Opc) {
595 return AMDGPU::hasNamedOperand(Opc, AMDGPU::OpName::src0X);
596}
597
598bool isMAC(unsigned Opc) {
599 return Opc == AMDGPU::V_MAC_F32_e64_gfx6_gfx7 ||
600 Opc == AMDGPU::V_MAC_F32_e64_gfx10 ||
601 Opc == AMDGPU::V_MAC_F32_e64_vi ||
602 Opc == AMDGPU::V_MAC_LEGACY_F32_e64_gfx6_gfx7 ||
603 Opc == AMDGPU::V_MAC_LEGACY_F32_e64_gfx10 ||
604 Opc == AMDGPU::V_MAC_F16_e64_vi ||
605 Opc == AMDGPU::V_FMAC_F64_e64_gfx90a ||
606 Opc == AMDGPU::V_FMAC_F32_e64_gfx10 ||
607 Opc == AMDGPU::V_FMAC_F32_e64_gfx11 ||
608 Opc == AMDGPU::V_FMAC_F32_e64_gfx12 ||
609 Opc == AMDGPU::V_FMAC_F32_e64_vi ||
610 Opc == AMDGPU::V_FMAC_LEGACY_F32_e64_gfx10 ||
611 Opc == AMDGPU::V_FMAC_DX9_ZERO_F32_e64_gfx11 ||
612 Opc == AMDGPU::V_FMAC_F16_e64_gfx10 ||
613 Opc == AMDGPU::V_FMAC_F16_fake16_e64_gfx11 ||
614 Opc == AMDGPU::V_FMAC_F16_fake16_e64_gfx12 ||
615 Opc == AMDGPU::V_DOT2C_F32_F16_e64_vi ||
616 Opc == AMDGPU::V_DOT2C_F32_BF16_e64_vi ||
617 Opc == AMDGPU::V_DOT2C_I32_I16_e64_vi ||
618 Opc == AMDGPU::V_DOT4C_I32_I8_e64_vi ||
619 Opc == AMDGPU::V_DOT8C_I32_I4_e64_vi;
620}
621
622bool isPermlane16(unsigned Opc) {
623 return Opc == AMDGPU::V_PERMLANE16_B32_gfx10 ||
624 Opc == AMDGPU::V_PERMLANEX16_B32_gfx10 ||
625 Opc == AMDGPU::V_PERMLANE16_B32_e64_gfx11 ||
626 Opc == AMDGPU::V_PERMLANEX16_B32_e64_gfx11 ||
627 Opc == AMDGPU::V_PERMLANE16_B32_e64_gfx12 ||
628 Opc == AMDGPU::V_PERMLANEX16_B32_e64_gfx12 ||
629 Opc == AMDGPU::V_PERMLANE16_VAR_B32_e64_gfx12 ||
630 Opc == AMDGPU::V_PERMLANEX16_VAR_B32_e64_gfx12;
631}
632
633bool isCvt_F32_Fp8_Bf8_e64(unsigned Opc) {
634 return Opc == AMDGPU::V_CVT_F32_BF8_e64_gfx12 ||
635 Opc == AMDGPU::V_CVT_F32_FP8_e64_gfx12 ||
636 Opc == AMDGPU::V_CVT_F32_BF8_e64_dpp_gfx12 ||
637 Opc == AMDGPU::V_CVT_F32_FP8_e64_dpp_gfx12 ||
638 Opc == AMDGPU::V_CVT_F32_BF8_e64_dpp8_gfx12 ||
639 Opc == AMDGPU::V_CVT_F32_FP8_e64_dpp8_gfx12 ||
640 Opc == AMDGPU::V_CVT_PK_F32_BF8_fake16_e64_gfx12 ||
641 Opc == AMDGPU::V_CVT_PK_F32_FP8_fake16_e64_gfx12 ||
642 Opc == AMDGPU::V_CVT_PK_F32_BF8_t16_e64_gfx12 ||
643 Opc == AMDGPU::V_CVT_PK_F32_FP8_t16_e64_gfx12;
644}
645
646bool isGenericAtomic(unsigned Opc) {
647 return Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_SWAP ||
648 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_ADD ||
649 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_SUB ||
650 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_SMIN ||
651 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_UMIN ||
652 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_SMAX ||
653 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_UMAX ||
654 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_AND ||
655 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_OR ||
656 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_XOR ||
657 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_INC ||
658 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_DEC ||
659 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_FADD ||
660 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_FMIN ||
661 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_FMAX ||
662 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_CMPSWAP ||
663 Opc == AMDGPU::G_AMDGPU_ATOMIC_CMPXCHG;
664}
665
666bool isTrue16Inst(unsigned Opc) {
667 const VOPTrue16Info *Info = getTrue16OpcodeHelper(Opc);
668 return Info ? Info->IsTrue16 : false;
669}
670
671FPType getFPDstSelType(unsigned Opc) {
672 const FP4FP8DstByteSelInfo *Info = getFP4FP8DstByteSelHelper(Opc);
673 if (!Info)
674 return FPType::None;
675 if (Info->HasFP8DstByteSel)
676 return FPType::FP8;
677 if (Info->HasFP4DstByteSel)
678 return FPType::FP4;
679
680 return FPType::None;
681}
682
683unsigned mapWMMA2AddrTo3AddrOpcode(unsigned Opc) {
684 const WMMAOpcodeMappingInfo *Info = getWMMAMappingInfoFrom2AddrOpcode(Opc);
685 return Info ? Info->Opcode3Addr : ~0u;
686}
687
688unsigned mapWMMA3AddrTo2AddrOpcode(unsigned Opc) {
689 const WMMAOpcodeMappingInfo *Info = getWMMAMappingInfoFrom3AddrOpcode(Opc);
690 return Info ? Info->Opcode2Addr : ~0u;
691}
692
693// Wrapper for Tablegen'd function. enum Subtarget is not defined in any
694// header files, so we need to wrap it in a function that takes unsigned
695// instead.
696int getMCOpcode(uint16_t Opcode, unsigned Gen) {
697 return getMCOpcodeGen(Opcode, static_cast<Subtarget>(Gen));
698}
699
700int getVOPDFull(unsigned OpX, unsigned OpY, unsigned EncodingFamily) {
701 const VOPDInfo *Info =
702 getVOPDInfoFromComponentOpcodes(OpX, OpY, EncodingFamily);
703 return Info ? Info->Opcode : -1;
704}
705
706std::pair<unsigned, unsigned> getVOPDComponents(unsigned VOPDOpcode) {
707 const VOPDInfo *Info = getVOPDOpcodeHelper(VOPDOpcode);
708 assert(Info);
709 const auto *OpX = getVOPDBaseFromComponent(Info->OpX);
710 const auto *OpY = getVOPDBaseFromComponent(Info->OpY);
711 assert(OpX && OpY);
712 return {OpX->BaseVOP, OpY->BaseVOP};
713}
714
715namespace VOPD {
716
719
722 auto TiedIdx = OpDesc.getOperandConstraint(Component::SRC2, MCOI::TIED_TO);
723 assert(TiedIdx == -1 || TiedIdx == Component::DST);
724 HasSrc2Acc = TiedIdx != -1;
725
726 SrcOperandsNum = OpDesc.getNumOperands() - OpDesc.getNumDefs();
727 assert(SrcOperandsNum <= Component::MAX_SRC_NUM);
728
729 auto OperandsNum = OpDesc.getNumOperands();
730 unsigned CompOprIdx;
731 for (CompOprIdx = Component::SRC1; CompOprIdx < OperandsNum; ++CompOprIdx) {
732 if (OpDesc.operands()[CompOprIdx].OperandType == AMDGPU::OPERAND_KIMM32) {
733 MandatoryLiteralIdx = CompOprIdx;
734 break;
735 }
736 }
737}
738
739unsigned ComponentInfo::getIndexInParsedOperands(unsigned CompOprIdx) const {
740 assert(CompOprIdx < Component::MAX_OPR_NUM);
741
742 if (CompOprIdx == Component::DST)
744
745 auto CompSrcIdx = CompOprIdx - Component::DST_NUM;
746 if (CompSrcIdx < getCompParsedSrcOperandsNum())
747 return getIndexOfSrcInParsedOperands(CompSrcIdx);
748
749 // The specified operand does not exist.
750 return 0;
751}
752
754 std::function<unsigned(unsigned, unsigned)> GetRegIdx, bool SkipSrc) const {
755
756 auto OpXRegs = getRegIndices(ComponentIndex::X, GetRegIdx);
757 auto OpYRegs = getRegIndices(ComponentIndex::Y, GetRegIdx);
758
759 const unsigned CompOprNum =
761 unsigned CompOprIdx;
762 for (CompOprIdx = 0; CompOprIdx < CompOprNum; ++CompOprIdx) {
763 unsigned BanksMasks = VOPD_VGPR_BANK_MASKS[CompOprIdx];
764 if (OpXRegs[CompOprIdx] && OpYRegs[CompOprIdx] &&
765 ((OpXRegs[CompOprIdx] & BanksMasks) ==
766 (OpYRegs[CompOprIdx] & BanksMasks)))
767 return CompOprIdx;
768 }
769
770 return {};
771}
772
773// Return an array of VGPR registers [DST,SRC0,SRC1,SRC2] used
774// by the specified component. If an operand is unused
775// or is not a VGPR, the corresponding value is 0.
776//
777// GetRegIdx(Component, MCOperandIdx) must return a VGPR register index
778// for the specified component and MC operand. The callback must return 0
779// if the operand is not a register or not a VGPR.
780InstInfo::RegIndices InstInfo::getRegIndices(
781 unsigned CompIdx,
782 std::function<unsigned(unsigned, unsigned)> GetRegIdx) const {
783 assert(CompIdx < COMPONENTS_NUM);
784
785 const auto &Comp = CompInfo[CompIdx];
787
788 RegIndices[DST] = GetRegIdx(CompIdx, Comp.getIndexOfDstInMCOperands());
789
790 for (unsigned CompOprIdx : {SRC0, SRC1, SRC2}) {
791 unsigned CompSrcIdx = CompOprIdx - DST_NUM;
792 RegIndices[CompOprIdx] =
793 Comp.hasRegSrcOperand(CompSrcIdx)
794 ? GetRegIdx(CompIdx, Comp.getIndexOfSrcInMCOperands(CompSrcIdx))
795 : 0;
796 }
797 return RegIndices;
798}
799
800} // namespace VOPD
801
803 return VOPD::InstInfo(OpX, OpY);
804}
805
806VOPD::InstInfo getVOPDInstInfo(unsigned VOPDOpcode,
807 const MCInstrInfo *InstrInfo) {
808 auto [OpX, OpY] = getVOPDComponents(VOPDOpcode);
809 const auto &OpXDesc = InstrInfo->get(OpX);
810 const auto &OpYDesc = InstrInfo->get(OpY);
812 VOPD::ComponentInfo OpYInfo(OpYDesc, OpXInfo);
813 return VOPD::InstInfo(OpXInfo, OpYInfo);
814}
815
816namespace IsaInfo {
817
819 : STI(STI), XnackSetting(TargetIDSetting::Any),
820 SramEccSetting(TargetIDSetting::Any) {
821 if (!STI.getFeatureBits().test(FeatureSupportsXNACK))
822 XnackSetting = TargetIDSetting::Unsupported;
823 if (!STI.getFeatureBits().test(FeatureSupportsSRAMECC))
824 SramEccSetting = TargetIDSetting::Unsupported;
825}
826
828 // Check if xnack or sramecc is explicitly enabled or disabled. In the
829 // absence of the target features we assume we must generate code that can run
830 // in any environment.
831 SubtargetFeatures Features(FS);
832 std::optional<bool> XnackRequested;
833 std::optional<bool> SramEccRequested;
834
835 for (const std::string &Feature : Features.getFeatures()) {
836 if (Feature == "+xnack")
837 XnackRequested = true;
838 else if (Feature == "-xnack")
839 XnackRequested = false;
840 else if (Feature == "+sramecc")
841 SramEccRequested = true;
842 else if (Feature == "-sramecc")
843 SramEccRequested = false;
844 }
845
846 bool XnackSupported = isXnackSupported();
847 bool SramEccSupported = isSramEccSupported();
848
849 if (XnackRequested) {
850 if (XnackSupported) {
851 XnackSetting =
852 *XnackRequested ? TargetIDSetting::On : TargetIDSetting::Off;
853 } else {
854 // If a specific xnack setting was requested and this GPU does not support
855 // xnack emit a warning. Setting will remain set to "Unsupported".
856 if (*XnackRequested) {
857 errs() << "warning: xnack 'On' was requested for a processor that does "
858 "not support it!\n";
859 } else {
860 errs() << "warning: xnack 'Off' was requested for a processor that "
861 "does not support it!\n";
862 }
863 }
864 }
865
866 if (SramEccRequested) {
867 if (SramEccSupported) {
868 SramEccSetting =
869 *SramEccRequested ? TargetIDSetting::On : TargetIDSetting::Off;
870 } else {
871 // If a specific sramecc setting was requested and this GPU does not
872 // support sramecc emit a warning. Setting will remain set to
873 // "Unsupported".
874 if (*SramEccRequested) {
875 errs() << "warning: sramecc 'On' was requested for a processor that "
876 "does not support it!\n";
877 } else {
878 errs() << "warning: sramecc 'Off' was requested for a processor that "
879 "does not support it!\n";
880 }
881 }
882 }
883}
884
885static TargetIDSetting
887 if (FeatureString.ends_with("-"))
889 if (FeatureString.ends_with("+"))
890 return TargetIDSetting::On;
891
892 llvm_unreachable("Malformed feature string");
893}
894
896 SmallVector<StringRef, 3> TargetIDSplit;
897 TargetID.split(TargetIDSplit, ':');
898
899 for (const auto &FeatureString : TargetIDSplit) {
900 if (FeatureString.starts_with("xnack"))
901 XnackSetting = getTargetIDSettingFromFeatureString(FeatureString);
902 if (FeatureString.starts_with("sramecc"))
903 SramEccSetting = getTargetIDSettingFromFeatureString(FeatureString);
904 }
905}
906
907std::string AMDGPUTargetID::toString() const {
908 std::string StringRep;
909 raw_string_ostream StreamRep(StringRep);
910
911 auto TargetTriple = STI.getTargetTriple();
912 auto Version = getIsaVersion(STI.getCPU());
913
914 StreamRep << TargetTriple.getArchName() << '-'
915 << TargetTriple.getVendorName() << '-'
916 << TargetTriple.getOSName() << '-'
917 << TargetTriple.getEnvironmentName() << '-';
918
919 std::string Processor;
920 // TODO: Following else statement is present here because we used various
921 // alias names for GPUs up until GFX9 (e.g. 'fiji' is same as 'gfx803').
922 // Remove once all aliases are removed from GCNProcessors.td.
923 if (Version.Major >= 9)
924 Processor = STI.getCPU().str();
925 else
926 Processor = (Twine("gfx") + Twine(Version.Major) + Twine(Version.Minor) +
927 Twine(Version.Stepping))
928 .str();
929
930 std::string Features;
931 if (STI.getTargetTriple().getOS() == Triple::AMDHSA) {
932 // sramecc.
934 Features += ":sramecc-";
936 Features += ":sramecc+";
937 // xnack.
939 Features += ":xnack-";
941 Features += ":xnack+";
942 }
943
944 StreamRep << Processor << Features;
945
946 return StringRep;
947}
948
949unsigned getWavefrontSize(const MCSubtargetInfo *STI) {
950 if (STI->getFeatureBits().test(FeatureWavefrontSize16))
951 return 16;
952 if (STI->getFeatureBits().test(FeatureWavefrontSize32))
953 return 32;
954
955 return 64;
956}
957
959 unsigned BytesPerCU = getAddressableLocalMemorySize(STI);
960
961 // "Per CU" really means "per whatever functional block the waves of a
962 // workgroup must share". So the effective local memory size is doubled in
963 // WGP mode on gfx10.
964 if (isGFX10Plus(*STI) && !STI->getFeatureBits().test(FeatureCuMode))
965 BytesPerCU *= 2;
966
967 return BytesPerCU;
968}
969
971 if (STI->getFeatureBits().test(FeatureAddressableLocalMemorySize32768))
972 return 32768;
973 if (STI->getFeatureBits().test(FeatureAddressableLocalMemorySize65536))
974 return 65536;
975 if (STI->getFeatureBits().test(FeatureAddressableLocalMemorySize163840))
976 return 163840;
977 return 0;
978}
979
980unsigned getEUsPerCU(const MCSubtargetInfo *STI) {
981 // "Per CU" really means "per whatever functional block the waves of a
982 // workgroup must share". For gfx10 in CU mode this is the CU, which contains
983 // two SIMDs.
984 if (isGFX10Plus(*STI) && STI->getFeatureBits().test(FeatureCuMode))
985 return 2;
986 // Pre-gfx10 a CU contains four SIMDs. For gfx10 in WGP mode the WGP contains
987 // two CUs, so a total of four SIMDs.
988 return 4;
989}
990
992 unsigned FlatWorkGroupSize) {
993 assert(FlatWorkGroupSize != 0);
994 if (STI->getTargetTriple().getArch() != Triple::amdgcn)
995 return 8;
996 unsigned MaxWaves = getMaxWavesPerEU(STI) * getEUsPerCU(STI);
997 unsigned N = getWavesPerWorkGroup(STI, FlatWorkGroupSize);
998 if (N == 1) {
999 // Single-wave workgroups don't consume barrier resources.
1000 return MaxWaves;
1001 }
1002
1003 unsigned MaxBarriers = 16;
1004 if (isGFX10Plus(*STI) && !STI->getFeatureBits().test(FeatureCuMode))
1005 MaxBarriers = 32;
1006
1007 return std::min(MaxWaves / N, MaxBarriers);
1008}
1009
1010unsigned getMinWavesPerEU(const MCSubtargetInfo *STI) {
1011 return 1;
1012}
1013
1014unsigned getMaxWavesPerEU(const MCSubtargetInfo *STI) {
1015 // FIXME: Need to take scratch memory into account.
1016 if (isGFX90A(*STI))
1017 return 8;
1018 if (!isGFX10Plus(*STI))
1019 return 10;
1020 return hasGFX10_3Insts(*STI) ? 16 : 20;
1021}
1022
1024 unsigned FlatWorkGroupSize) {
1025 return divideCeil(getWavesPerWorkGroup(STI, FlatWorkGroupSize),
1026 getEUsPerCU(STI));
1027}
1028
1030 return 1;
1031}
1032
1034 // Some subtargets allow encoding 2048, but this isn't tested or supported.
1035 return 1024;
1036}
1037
1039 unsigned FlatWorkGroupSize) {
1040 return divideCeil(FlatWorkGroupSize, getWavefrontSize(STI));
1041}
1042
1045 if (Version.Major >= 10)
1046 return getAddressableNumSGPRs(STI);
1047 if (Version.Major >= 8)
1048 return 16;
1049 return 8;
1050}
1051
1053 return 8;
1054}
1055
1056unsigned getTotalNumSGPRs(const MCSubtargetInfo *STI) {
1058 if (Version.Major >= 8)
1059 return 800;
1060 return 512;
1061}
1062
1064 if (STI->getFeatureBits().test(FeatureSGPRInitBug))
1066
1068 if (Version.Major >= 10)
1069 return 106;
1070 if (Version.Major >= 8)
1071 return 102;
1072 return 104;
1073}
1074
1075unsigned getMinNumSGPRs(const MCSubtargetInfo *STI, unsigned WavesPerEU) {
1076 assert(WavesPerEU != 0);
1077
1079 if (Version.Major >= 10)
1080 return 0;
1081
1082 if (WavesPerEU >= getMaxWavesPerEU(STI))
1083 return 0;
1084
1085 unsigned MinNumSGPRs = getTotalNumSGPRs(STI) / (WavesPerEU + 1);
1086 if (STI->getFeatureBits().test(FeatureTrapHandler))
1087 MinNumSGPRs -= std::min(MinNumSGPRs, (unsigned)TRAP_NUM_SGPRS);
1088 MinNumSGPRs = alignDown(MinNumSGPRs, getSGPRAllocGranule(STI)) + 1;
1089 return std::min(MinNumSGPRs, getAddressableNumSGPRs(STI));
1090}
1091
1092unsigned getMaxNumSGPRs(const MCSubtargetInfo *STI, unsigned WavesPerEU,
1093 bool Addressable) {
1094 assert(WavesPerEU != 0);
1095
1096 unsigned AddressableNumSGPRs = getAddressableNumSGPRs(STI);
1098 if (Version.Major >= 10)
1099 return Addressable ? AddressableNumSGPRs : 108;
1100 if (Version.Major >= 8 && !Addressable)
1101 AddressableNumSGPRs = 112;
1102 unsigned MaxNumSGPRs = getTotalNumSGPRs(STI) / WavesPerEU;
1103 if (STI->getFeatureBits().test(FeatureTrapHandler))
1104 MaxNumSGPRs -= std::min(MaxNumSGPRs, (unsigned)TRAP_NUM_SGPRS);
1105 MaxNumSGPRs = alignDown(MaxNumSGPRs, getSGPRAllocGranule(STI));
1106 return std::min(MaxNumSGPRs, AddressableNumSGPRs);
1107}
1108
1109unsigned getNumExtraSGPRs(const MCSubtargetInfo *STI, bool VCCUsed,
1110 bool FlatScrUsed, bool XNACKUsed) {
1111 unsigned ExtraSGPRs = 0;
1112 if (VCCUsed)
1113 ExtraSGPRs = 2;
1114
1116 if (Version.Major >= 10)
1117 return ExtraSGPRs;
1118
1119 if (Version.Major < 8) {
1120 if (FlatScrUsed)
1121 ExtraSGPRs = 4;
1122 } else {
1123 if (XNACKUsed)
1124 ExtraSGPRs = 4;
1125
1126 if (FlatScrUsed ||
1127 STI->getFeatureBits().test(AMDGPU::FeatureArchitectedFlatScratch))
1128 ExtraSGPRs = 6;
1129 }
1130
1131 return ExtraSGPRs;
1132}
1133
1134unsigned getNumExtraSGPRs(const MCSubtargetInfo *STI, bool VCCUsed,
1135 bool FlatScrUsed) {
1136 return getNumExtraSGPRs(STI, VCCUsed, FlatScrUsed,
1137 STI->getFeatureBits().test(AMDGPU::FeatureXNACK));
1138}
1139
1140static unsigned getGranulatedNumRegisterBlocks(unsigned NumRegs,
1141 unsigned Granule) {
1142 return divideCeil(std::max(1u, NumRegs), Granule);
1143}
1144
1145unsigned getNumSGPRBlocks(const MCSubtargetInfo *STI, unsigned NumSGPRs) {
1146 // SGPRBlocks is actual number of SGPR blocks minus 1.
1148 1;
1149}
1150
1152 std::optional<bool> EnableWavefrontSize32) {
1153 if (STI->getFeatureBits().test(FeatureGFX90AInsts))
1154 return 8;
1155
1156 bool IsWave32 = EnableWavefrontSize32 ?
1157 *EnableWavefrontSize32 :
1158 STI->getFeatureBits().test(FeatureWavefrontSize32);
1159
1160 if (STI->getFeatureBits().test(Feature1_5xVGPRs))
1161 return IsWave32 ? 24 : 12;
1162
1163 if (hasGFX10_3Insts(*STI))
1164 return IsWave32 ? 16 : 8;
1165
1166 return IsWave32 ? 8 : 4;
1167}
1168
1170 std::optional<bool> EnableWavefrontSize32) {
1171 if (STI->getFeatureBits().test(FeatureGFX90AInsts))
1172 return 8;
1173
1174 bool IsWave32 = EnableWavefrontSize32 ?
1175 *EnableWavefrontSize32 :
1176 STI->getFeatureBits().test(FeatureWavefrontSize32);
1177
1178 return IsWave32 ? 8 : 4;
1179}
1180
1181unsigned getTotalNumVGPRs(const MCSubtargetInfo *STI) {
1182 if (STI->getFeatureBits().test(FeatureGFX90AInsts))
1183 return 512;
1184 if (!isGFX10Plus(*STI))
1185 return 256;
1186 bool IsWave32 = STI->getFeatureBits().test(FeatureWavefrontSize32);
1187 if (STI->getFeatureBits().test(Feature1_5xVGPRs))
1188 return IsWave32 ? 1536 : 768;
1189 return IsWave32 ? 1024 : 512;
1190}
1191
1192unsigned getAddressableNumArchVGPRs(const MCSubtargetInfo *STI) { return 256; }
1193
1195 if (STI->getFeatureBits().test(FeatureGFX90AInsts))
1196 return 512;
1197 return getAddressableNumArchVGPRs(STI);
1198}
1199
1201 unsigned NumVGPRs) {
1203 getMaxWavesPerEU(STI),
1204 getTotalNumVGPRs(STI));
1205}
1206
1207unsigned getNumWavesPerEUWithNumVGPRs(unsigned NumVGPRs, unsigned Granule,
1208 unsigned MaxWaves,
1209 unsigned TotalNumVGPRs) {
1210 if (NumVGPRs < Granule)
1211 return MaxWaves;
1212 unsigned RoundedRegs = alignTo(NumVGPRs, Granule);
1213 return std::min(std::max(TotalNumVGPRs / RoundedRegs, 1u), MaxWaves);
1214}
1215
1216unsigned getOccupancyWithNumSGPRs(unsigned SGPRs, unsigned MaxWaves,
1218 if (Gen >= AMDGPUSubtarget::GFX10)
1219 return MaxWaves;
1220
1222 if (SGPRs <= 80)
1223 return 10;
1224 if (SGPRs <= 88)
1225 return 9;
1226 if (SGPRs <= 100)
1227 return 8;
1228 return 7;
1229 }
1230 if (SGPRs <= 48)
1231 return 10;
1232 if (SGPRs <= 56)
1233 return 9;
1234 if (SGPRs <= 64)
1235 return 8;
1236 if (SGPRs <= 72)
1237 return 7;
1238 if (SGPRs <= 80)
1239 return 6;
1240 return 5;
1241}
1242
1243unsigned getMinNumVGPRs(const MCSubtargetInfo *STI, unsigned WavesPerEU) {
1244 assert(WavesPerEU != 0);
1245
1246 unsigned MaxWavesPerEU = getMaxWavesPerEU(STI);
1247 if (WavesPerEU >= MaxWavesPerEU)
1248 return 0;
1249
1250 unsigned TotNumVGPRs = getTotalNumVGPRs(STI);
1251 unsigned AddrsableNumVGPRs = getAddressableNumVGPRs(STI);
1252 unsigned Granule = getVGPRAllocGranule(STI);
1253 unsigned MaxNumVGPRs = alignDown(TotNumVGPRs / WavesPerEU, Granule);
1254
1255 if (MaxNumVGPRs == alignDown(TotNumVGPRs / MaxWavesPerEU, Granule))
1256 return 0;
1257
1258 unsigned MinWavesPerEU = getNumWavesPerEUWithNumVGPRs(STI, AddrsableNumVGPRs);
1259 if (WavesPerEU < MinWavesPerEU)
1260 return getMinNumVGPRs(STI, MinWavesPerEU);
1261
1262 unsigned MaxNumVGPRsNext = alignDown(TotNumVGPRs / (WavesPerEU + 1), Granule);
1263 unsigned MinNumVGPRs = 1 + std::min(MaxNumVGPRs - Granule, MaxNumVGPRsNext);
1264 return std::min(MinNumVGPRs, AddrsableNumVGPRs);
1265}
1266
1267unsigned getMaxNumVGPRs(const MCSubtargetInfo *STI, unsigned WavesPerEU) {
1268 assert(WavesPerEU != 0);
1269
1270 unsigned MaxNumVGPRs = alignDown(getTotalNumVGPRs(STI) / WavesPerEU,
1271 getVGPRAllocGranule(STI));
1272 unsigned AddressableNumVGPRs = getAddressableNumVGPRs(STI);
1273 return std::min(MaxNumVGPRs, AddressableNumVGPRs);
1274}
1275
1276unsigned getEncodedNumVGPRBlocks(const MCSubtargetInfo *STI, unsigned NumVGPRs,
1277 std::optional<bool> EnableWavefrontSize32) {
1279 NumVGPRs, getVGPREncodingGranule(STI, EnableWavefrontSize32)) -
1280 1;
1281}
1282
1284 unsigned NumVGPRs,
1285 std::optional<bool> EnableWavefrontSize32) {
1287 NumVGPRs, getVGPRAllocGranule(STI, EnableWavefrontSize32));
1288}
1289} // end namespace IsaInfo
1290
1292 const MCSubtargetInfo *STI) {
1294 KernelCode.amd_kernel_code_version_major = 1;
1295 KernelCode.amd_kernel_code_version_minor = 2;
1296 KernelCode.amd_machine_kind = 1; // AMD_MACHINE_KIND_AMDGPU
1297 KernelCode.amd_machine_version_major = Version.Major;
1298 KernelCode.amd_machine_version_minor = Version.Minor;
1299 KernelCode.amd_machine_version_stepping = Version.Stepping;
1301 if (STI->getFeatureBits().test(FeatureWavefrontSize32)) {
1302 KernelCode.wavefront_size = 5;
1304 } else {
1305 KernelCode.wavefront_size = 6;
1306 }
1307
1308 // If the code object does not support indirect functions, then the value must
1309 // be 0xffffffff.
1310 KernelCode.call_convention = -1;
1311
1312 // These alignment values are specified in powers of two, so alignment =
1313 // 2^n. The minimum alignment is 2^4 = 16.
1314 KernelCode.kernarg_segment_alignment = 4;
1315 KernelCode.group_segment_alignment = 4;
1316 KernelCode.private_segment_alignment = 4;
1317
1318 if (Version.Major >= 10) {
1319 KernelCode.compute_pgm_resource_registers |=
1320 S_00B848_WGP_MODE(STI->getFeatureBits().test(FeatureCuMode) ? 0 : 1) |
1322 }
1323}
1324
1327}
1328
1331}
1332
1334 unsigned AS = GV->getAddressSpace();
1335 return AS == AMDGPUAS::CONSTANT_ADDRESS ||
1337}
1338
1340 return TT.getArch() == Triple::r600;
1341}
1342
1343std::pair<unsigned, unsigned>
1345 std::pair<unsigned, unsigned> Default,
1346 bool OnlyFirstRequired) {
1347 if (auto Attr = getIntegerPairAttribute(F, Name, OnlyFirstRequired))
1348 return {Attr->first, Attr->second ? *(Attr->second) : Default.second};
1349 return Default;
1350}
1351
1352std::optional<std::pair<unsigned, std::optional<unsigned>>>
1354 bool OnlyFirstRequired) {
1355 Attribute A = F.getFnAttribute(Name);
1356 if (!A.isStringAttribute())
1357 return std::nullopt;
1358
1359 LLVMContext &Ctx = F.getContext();
1360 std::pair<unsigned, std::optional<unsigned>> Ints;
1361 std::pair<StringRef, StringRef> Strs = A.getValueAsString().split(',');
1362 if (Strs.first.trim().getAsInteger(0, Ints.first)) {
1363 Ctx.emitError("can't parse first integer attribute " + Name);
1364 return std::nullopt;
1365 }
1366 unsigned Second = 0;
1367 if (Strs.second.trim().getAsInteger(0, Second)) {
1368 if (!OnlyFirstRequired || !Strs.second.trim().empty()) {
1369 Ctx.emitError("can't parse second integer attribute " + Name);
1370 return std::nullopt;
1371 }
1372 } else {
1373 Ints.second = Second;
1374 }
1375
1376 return Ints;
1377}
1378
1380 unsigned Size,
1381 unsigned DefaultVal) {
1382 assert(Size > 2);
1384
1385 Attribute A = F.getFnAttribute(Name);
1386 if (!A.isStringAttribute())
1387 return Default;
1388
1390
1391 LLVMContext &Ctx = F.getContext();
1392
1393 StringRef S = A.getValueAsString();
1394 unsigned i = 0;
1395 for (; !S.empty() && i < Size; i++) {
1396 std::pair<StringRef, StringRef> Strs = S.split(',');
1397 unsigned IntVal;
1398 if (Strs.first.trim().getAsInteger(0, IntVal)) {
1399 Ctx.emitError("can't parse integer attribute " + Strs.first + " in " +
1400 Name);
1401 return Default;
1402 }
1403 Vals[i] = IntVal;
1404 S = Strs.second;
1405 }
1406
1407 if (!S.empty() || i < Size) {
1408 Ctx.emitError("attribute " + Name +
1409 " has incorrect number of integers; expected " +
1410 llvm::utostr(Size));
1411 return Default;
1412 }
1413 return Vals;
1414}
1415
1417 return (1 << (getVmcntBitWidthLo(Version.Major) +
1418 getVmcntBitWidthHi(Version.Major))) -
1419 1;
1420}
1421
1423 return (1 << getLoadcntBitWidth(Version.Major)) - 1;
1424}
1425
1427 return (1 << getSamplecntBitWidth(Version.Major)) - 1;
1428}
1429
1431 return (1 << getBvhcntBitWidth(Version.Major)) - 1;
1432}
1433
1435 return (1 << getExpcntBitWidth(Version.Major)) - 1;
1436}
1437
1439 return (1 << getLgkmcntBitWidth(Version.Major)) - 1;
1440}
1441
1443 return (1 << getDscntBitWidth(Version.Major)) - 1;
1444}
1445
1447 return (1 << getKmcntBitWidth(Version.Major)) - 1;
1448}
1449
1451 return (1 << getStorecntBitWidth(Version.Major)) - 1;
1452}
1453
1455 unsigned VmcntLo = getBitMask(getVmcntBitShiftLo(Version.Major),
1456 getVmcntBitWidthLo(Version.Major));
1457 unsigned Expcnt = getBitMask(getExpcntBitShift(Version.Major),
1458 getExpcntBitWidth(Version.Major));
1459 unsigned Lgkmcnt = getBitMask(getLgkmcntBitShift(Version.Major),
1460 getLgkmcntBitWidth(Version.Major));
1461 unsigned VmcntHi = getBitMask(getVmcntBitShiftHi(Version.Major),
1462 getVmcntBitWidthHi(Version.Major));
1463 return VmcntLo | Expcnt | Lgkmcnt | VmcntHi;
1464}
1465
1466unsigned decodeVmcnt(const IsaVersion &Version, unsigned Waitcnt) {
1467 unsigned VmcntLo = unpackBits(Waitcnt, getVmcntBitShiftLo(Version.Major),
1468 getVmcntBitWidthLo(Version.Major));
1469 unsigned VmcntHi = unpackBits(Waitcnt, getVmcntBitShiftHi(Version.Major),
1470 getVmcntBitWidthHi(Version.Major));
1471 return VmcntLo | VmcntHi << getVmcntBitWidthLo(Version.Major);
1472}
1473
1474unsigned decodeExpcnt(const IsaVersion &Version, unsigned Waitcnt) {
1475 return unpackBits(Waitcnt, getExpcntBitShift(Version.Major),
1476 getExpcntBitWidth(Version.Major));
1477}
1478
1479unsigned decodeLgkmcnt(const IsaVersion &Version, unsigned Waitcnt) {
1480 return unpackBits(Waitcnt, getLgkmcntBitShift(Version.Major),
1481 getLgkmcntBitWidth(Version.Major));
1482}
1483
1485 unsigned &Vmcnt, unsigned &Expcnt, unsigned &Lgkmcnt) {
1486 Vmcnt = decodeVmcnt(Version, Waitcnt);
1487 Expcnt = decodeExpcnt(Version, Waitcnt);
1488 Lgkmcnt = decodeLgkmcnt(Version, Waitcnt);
1489}
1490
1491Waitcnt decodeWaitcnt(const IsaVersion &Version, unsigned Encoded) {
1492 Waitcnt Decoded;
1493 Decoded.LoadCnt = decodeVmcnt(Version, Encoded);
1494 Decoded.ExpCnt = decodeExpcnt(Version, Encoded);
1495 Decoded.DsCnt = decodeLgkmcnt(Version, Encoded);
1496 return Decoded;
1497}
1498
1499unsigned encodeVmcnt(const IsaVersion &Version, unsigned Waitcnt,
1500 unsigned Vmcnt) {
1501 Waitcnt = packBits(Vmcnt, Waitcnt, getVmcntBitShiftLo(Version.Major),
1502 getVmcntBitWidthLo(Version.Major));
1503 return packBits(Vmcnt >> getVmcntBitWidthLo(Version.Major), Waitcnt,
1504 getVmcntBitShiftHi(Version.Major),
1505 getVmcntBitWidthHi(Version.Major));
1506}
1507
1508unsigned encodeExpcnt(const IsaVersion &Version, unsigned Waitcnt,
1509 unsigned Expcnt) {
1510 return packBits(Expcnt, Waitcnt, getExpcntBitShift(Version.Major),
1511 getExpcntBitWidth(Version.Major));
1512}
1513
1514unsigned encodeLgkmcnt(const IsaVersion &Version, unsigned Waitcnt,
1515 unsigned Lgkmcnt) {
1516 return packBits(Lgkmcnt, Waitcnt, getLgkmcntBitShift(Version.Major),
1517 getLgkmcntBitWidth(Version.Major));
1518}
1519
1521 unsigned Vmcnt, unsigned Expcnt, unsigned Lgkmcnt) {
1522 unsigned Waitcnt = getWaitcntBitMask(Version);
1524 Waitcnt = encodeExpcnt(Version, Waitcnt, Expcnt);
1525 Waitcnt = encodeLgkmcnt(Version, Waitcnt, Lgkmcnt);
1526 return Waitcnt;
1527}
1528
1529unsigned encodeWaitcnt(const IsaVersion &Version, const Waitcnt &Decoded) {
1530 return encodeWaitcnt(Version, Decoded.LoadCnt, Decoded.ExpCnt, Decoded.DsCnt);
1531}
1532
1534 bool IsStore) {
1535 unsigned Dscnt = getBitMask(getDscntBitShift(Version.Major),
1536 getDscntBitWidth(Version.Major));
1537 if (IsStore) {
1538 unsigned Storecnt = getBitMask(getLoadcntStorecntBitShift(Version.Major),
1539 getStorecntBitWidth(Version.Major));
1540 return Dscnt | Storecnt;
1541 }
1542 unsigned Loadcnt = getBitMask(getLoadcntStorecntBitShift(Version.Major),
1543 getLoadcntBitWidth(Version.Major));
1544 return Dscnt | Loadcnt;
1545}
1546
1547Waitcnt decodeLoadcntDscnt(const IsaVersion &Version, unsigned LoadcntDscnt) {
1548 Waitcnt Decoded;
1549 Decoded.LoadCnt =
1550 unpackBits(LoadcntDscnt, getLoadcntStorecntBitShift(Version.Major),
1551 getLoadcntBitWidth(Version.Major));
1552 Decoded.DsCnt = unpackBits(LoadcntDscnt, getDscntBitShift(Version.Major),
1553 getDscntBitWidth(Version.Major));
1554 return Decoded;
1555}
1556
1557Waitcnt decodeStorecntDscnt(const IsaVersion &Version, unsigned StorecntDscnt) {
1558 Waitcnt Decoded;
1559 Decoded.StoreCnt =
1560 unpackBits(StorecntDscnt, getLoadcntStorecntBitShift(Version.Major),
1561 getStorecntBitWidth(Version.Major));
1562 Decoded.DsCnt = unpackBits(StorecntDscnt, getDscntBitShift(Version.Major),
1563 getDscntBitWidth(Version.Major));
1564 return Decoded;
1565}
1566
1567static unsigned encodeLoadcnt(const IsaVersion &Version, unsigned Waitcnt,
1568 unsigned Loadcnt) {
1569 return packBits(Loadcnt, Waitcnt, getLoadcntStorecntBitShift(Version.Major),
1570 getLoadcntBitWidth(Version.Major));
1571}
1572
1573static unsigned encodeStorecnt(const IsaVersion &Version, unsigned Waitcnt,
1574 unsigned Storecnt) {
1575 return packBits(Storecnt, Waitcnt, getLoadcntStorecntBitShift(Version.Major),
1576 getStorecntBitWidth(Version.Major));
1577}
1578
1579static unsigned encodeDscnt(const IsaVersion &Version, unsigned Waitcnt,
1580 unsigned Dscnt) {
1581 return packBits(Dscnt, Waitcnt, getDscntBitShift(Version.Major),
1582 getDscntBitWidth(Version.Major));
1583}
1584
1585static unsigned encodeLoadcntDscnt(const IsaVersion &Version, unsigned Loadcnt,
1586 unsigned Dscnt) {
1587 unsigned Waitcnt = getCombinedCountBitMask(Version, false);
1588 Waitcnt = encodeLoadcnt(Version, Waitcnt, Loadcnt);
1590 return Waitcnt;
1591}
1592
1593unsigned encodeLoadcntDscnt(const IsaVersion &Version, const Waitcnt &Decoded) {
1594 return encodeLoadcntDscnt(Version, Decoded.LoadCnt, Decoded.DsCnt);
1595}
1596
1598 unsigned Storecnt, unsigned Dscnt) {
1599 unsigned Waitcnt = getCombinedCountBitMask(Version, true);
1600 Waitcnt = encodeStorecnt(Version, Waitcnt, Storecnt);
1602 return Waitcnt;
1603}
1604
1606 const Waitcnt &Decoded) {
1607 return encodeStorecntDscnt(Version, Decoded.StoreCnt, Decoded.DsCnt);
1608}
1609
1610//===----------------------------------------------------------------------===//
1611// Custom Operand Values
1612//===----------------------------------------------------------------------===//
1613
1615 int Size,
1616 const MCSubtargetInfo &STI) {
1617 unsigned Enc = 0;
1618 for (int Idx = 0; Idx < Size; ++Idx) {
1619 const auto &Op = Opr[Idx];
1620 if (Op.isSupported(STI))
1621 Enc |= Op.encode(Op.Default);
1622 }
1623 return Enc;
1624}
1625
1627 int Size, unsigned Code,
1628 bool &HasNonDefaultVal,
1629 const MCSubtargetInfo &STI) {
1630 unsigned UsedOprMask = 0;
1631 HasNonDefaultVal = false;
1632 for (int Idx = 0; Idx < Size; ++Idx) {
1633 const auto &Op = Opr[Idx];
1634 if (!Op.isSupported(STI))
1635 continue;
1636 UsedOprMask |= Op.getMask();
1637 unsigned Val = Op.decode(Code);
1638 if (!Op.isValid(Val))
1639 return false;
1640 HasNonDefaultVal |= (Val != Op.Default);
1641 }
1642 return (Code & ~UsedOprMask) == 0;
1643}
1644
1645static bool decodeCustomOperand(const CustomOperandVal *Opr, int Size,
1646 unsigned Code, int &Idx, StringRef &Name,
1647 unsigned &Val, bool &IsDefault,
1648 const MCSubtargetInfo &STI) {
1649 while (Idx < Size) {
1650 const auto &Op = Opr[Idx++];
1651 if (Op.isSupported(STI)) {
1652 Name = Op.Name;
1653 Val = Op.decode(Code);
1654 IsDefault = (Val == Op.Default);
1655 return true;
1656 }
1657 }
1658
1659 return false;
1660}
1661
1663 int64_t InputVal) {
1664 if (InputVal < 0 || InputVal > Op.Max)
1665 return OPR_VAL_INVALID;
1666 return Op.encode(InputVal);
1667}
1668
1669static int encodeCustomOperand(const CustomOperandVal *Opr, int Size,
1670 const StringRef Name, int64_t InputVal,
1671 unsigned &UsedOprMask,
1672 const MCSubtargetInfo &STI) {
1673 int InvalidId = OPR_ID_UNKNOWN;
1674 for (int Idx = 0; Idx < Size; ++Idx) {
1675 const auto &Op = Opr[Idx];
1676 if (Op.Name == Name) {
1677 if (!Op.isSupported(STI)) {
1678 InvalidId = OPR_ID_UNSUPPORTED;
1679 continue;
1680 }
1681 auto OprMask = Op.getMask();
1682 if (OprMask & UsedOprMask)
1683 return OPR_ID_DUPLICATE;
1684 UsedOprMask |= OprMask;
1685 return encodeCustomOperandVal(Op, InputVal);
1686 }
1687 }
1688 return InvalidId;
1689}
1690
1691//===----------------------------------------------------------------------===//
1692// DepCtr
1693//===----------------------------------------------------------------------===//
1694
1695namespace DepCtr {
1696
1698 static int Default = -1;
1699 if (Default == -1)
1701 return Default;
1702}
1703
1704bool isSymbolicDepCtrEncoding(unsigned Code, bool &HasNonDefaultVal,
1705 const MCSubtargetInfo &STI) {
1707 HasNonDefaultVal, STI);
1708}
1709
1710bool decodeDepCtr(unsigned Code, int &Id, StringRef &Name, unsigned &Val,
1711 bool &IsDefault, const MCSubtargetInfo &STI) {
1712 return decodeCustomOperand(DepCtrInfo, DEP_CTR_SIZE, Code, Id, Name, Val,
1713 IsDefault, STI);
1714}
1715
1716int encodeDepCtr(const StringRef Name, int64_t Val, unsigned &UsedOprMask,
1717 const MCSubtargetInfo &STI) {
1718 return encodeCustomOperand(DepCtrInfo, DEP_CTR_SIZE, Name, Val, UsedOprMask,
1719 STI);
1720}
1721
1722unsigned decodeFieldVmVsrc(unsigned Encoded) {
1723 return unpackBits(Encoded, getVmVsrcBitShift(), getVmVsrcBitWidth());
1724}
1725
1726unsigned decodeFieldVaVdst(unsigned Encoded) {
1727 return unpackBits(Encoded, getVaVdstBitShift(), getVaVdstBitWidth());
1728}
1729
1730unsigned decodeFieldSaSdst(unsigned Encoded) {
1731 return unpackBits(Encoded, getSaSdstBitShift(), getSaSdstBitWidth());
1732}
1733
1734unsigned decodeFieldVaSdst(unsigned Encoded) {
1735 return unpackBits(Encoded, getVaSdstBitShift(), getVaSdstBitWidth());
1736}
1737
1738unsigned decodeFieldVaVcc(unsigned Encoded) {
1739 return unpackBits(Encoded, getVaVccBitShift(), getVaVccBitWidth());
1740}
1741
1742unsigned encodeFieldVmVsrc(unsigned Encoded, unsigned VmVsrc) {
1743 return packBits(VmVsrc, Encoded, getVmVsrcBitShift(), getVmVsrcBitWidth());
1744}
1745
1746unsigned encodeFieldVmVsrc(unsigned VmVsrc) {
1747 return encodeFieldVmVsrc(0xffff, VmVsrc);
1748}
1749
1750unsigned encodeFieldVaVdst(unsigned Encoded, unsigned VaVdst) {
1751 return packBits(VaVdst, Encoded, getVaVdstBitShift(), getVaVdstBitWidth());
1752}
1753
1754unsigned encodeFieldVaVdst(unsigned VaVdst) {
1755 return encodeFieldVaVdst(0xffff, VaVdst);
1756}
1757
1758unsigned encodeFieldSaSdst(unsigned Encoded, unsigned SaSdst) {
1759 return packBits(SaSdst, Encoded, getSaSdstBitShift(), getSaSdstBitWidth());
1760}
1761
1762unsigned encodeFieldSaSdst(unsigned SaSdst) {
1763 return encodeFieldSaSdst(0xffff, SaSdst);
1764}
1765
1766unsigned encodeFieldVaSdst(unsigned Encoded, unsigned VaSdst) {
1767 return packBits(VaSdst, Encoded, getVaSdstBitShift(), getVaSdstBitWidth());
1768}
1769
1770unsigned encodeFieldVaSdst(unsigned VaSdst) {
1771 return encodeFieldVaSdst(0xffff, VaSdst);
1772}
1773
1774unsigned encodeFieldVaVcc(unsigned Encoded, unsigned VaVcc) {
1775 return packBits(VaVcc, Encoded, getVaVccBitShift(), getVaVccBitWidth());
1776}
1777
1778unsigned encodeFieldVaVcc(unsigned VaVcc) {
1779 return encodeFieldVaVcc(0xffff, VaVcc);
1780}
1781
1782} // namespace DepCtr
1783
1784//===----------------------------------------------------------------------===//
1785// exp tgt
1786//===----------------------------------------------------------------------===//
1787
1788namespace Exp {
1789
1790struct ExpTgt {
1792 unsigned Tgt;
1793 unsigned MaxIndex;
1794};
1795
1796static constexpr ExpTgt ExpTgtInfo[] = {
1797 {{"null"}, ET_NULL, ET_NULL_MAX_IDX},
1798 {{"mrtz"}, ET_MRTZ, ET_MRTZ_MAX_IDX},
1799 {{"prim"}, ET_PRIM, ET_PRIM_MAX_IDX},
1800 {{"mrt"}, ET_MRT0, ET_MRT_MAX_IDX},
1801 {{"pos"}, ET_POS0, ET_POS_MAX_IDX},
1802 {{"dual_src_blend"}, ET_DUAL_SRC_BLEND0, ET_DUAL_SRC_BLEND_MAX_IDX},
1803 {{"param"}, ET_PARAM0, ET_PARAM_MAX_IDX},
1804};
1805
1806bool getTgtName(unsigned Id, StringRef &Name, int &Index) {
1807 for (const ExpTgt &Val : ExpTgtInfo) {
1808 if (Val.Tgt <= Id && Id <= Val.Tgt + Val.MaxIndex) {
1809 Index = (Val.MaxIndex == 0) ? -1 : (Id - Val.Tgt);
1810 Name = Val.Name;
1811 return true;
1812 }
1813 }
1814 return false;
1815}
1816
1817unsigned getTgtId(const StringRef Name) {
1818
1819 for (const ExpTgt &Val : ExpTgtInfo) {
1820 if (Val.MaxIndex == 0 && Name == Val.Name)
1821 return Val.Tgt;
1822
1823 if (Val.MaxIndex > 0 && Name.starts_with(Val.Name)) {
1824 StringRef Suffix = Name.drop_front(Val.Name.size());
1825
1826 unsigned Id;
1827 if (Suffix.getAsInteger(10, Id) || Id > Val.MaxIndex)
1828 return ET_INVALID;
1829
1830 // Disable leading zeroes
1831 if (Suffix.size() > 1 && Suffix[0] == '0')
1832 return ET_INVALID;
1833
1834 return Val.Tgt + Id;
1835 }
1836 }
1837 return ET_INVALID;
1838}
1839
1840bool isSupportedTgtId(unsigned Id, const MCSubtargetInfo &STI) {
1841 switch (Id) {
1842 case ET_NULL:
1843 return !isGFX11Plus(STI);
1844 case ET_POS4:
1845 case ET_PRIM:
1846 return isGFX10Plus(STI);
1847 case ET_DUAL_SRC_BLEND0:
1848 case ET_DUAL_SRC_BLEND1:
1849 return isGFX11Plus(STI);
1850 default:
1851 if (Id >= ET_PARAM0 && Id <= ET_PARAM31)
1852 return !isGFX11Plus(STI);
1853 return true;
1854 }
1855}
1856
1857} // namespace Exp
1858
1859//===----------------------------------------------------------------------===//
1860// MTBUF Format
1861//===----------------------------------------------------------------------===//
1862
1863namespace MTBUFFormat {
1864
1865int64_t getDfmt(const StringRef Name) {
1866 for (int Id = DFMT_MIN; Id <= DFMT_MAX; ++Id) {
1867 if (Name == DfmtSymbolic[Id])
1868 return Id;
1869 }
1870 return DFMT_UNDEF;
1871}
1872
1874 assert(Id <= DFMT_MAX);
1875 return DfmtSymbolic[Id];
1876}
1877
1879 if (isSI(STI) || isCI(STI))
1880 return NfmtSymbolicSICI;
1881 if (isVI(STI) || isGFX9(STI))
1882 return NfmtSymbolicVI;
1883 return NfmtSymbolicGFX10;
1884}
1885
1886int64_t getNfmt(const StringRef Name, const MCSubtargetInfo &STI) {
1887 const auto *lookupTable = getNfmtLookupTable(STI);
1888 for (int Id = NFMT_MIN; Id <= NFMT_MAX; ++Id) {
1889 if (Name == lookupTable[Id])
1890 return Id;
1891 }
1892 return NFMT_UNDEF;
1893}
1894
1895StringRef getNfmtName(unsigned Id, const MCSubtargetInfo &STI) {
1896 assert(Id <= NFMT_MAX);
1897 return getNfmtLookupTable(STI)[Id];
1898}
1899
1900bool isValidDfmtNfmt(unsigned Id, const MCSubtargetInfo &STI) {
1901 unsigned Dfmt;
1902 unsigned Nfmt;
1903 decodeDfmtNfmt(Id, Dfmt, Nfmt);
1904 return isValidNfmt(Nfmt, STI);
1905}
1906
1907bool isValidNfmt(unsigned Id, const MCSubtargetInfo &STI) {
1908 return !getNfmtName(Id, STI).empty();
1909}
1910
1911int64_t encodeDfmtNfmt(unsigned Dfmt, unsigned Nfmt) {
1912 return (Dfmt << DFMT_SHIFT) | (Nfmt << NFMT_SHIFT);
1913}
1914
1915void decodeDfmtNfmt(unsigned Format, unsigned &Dfmt, unsigned &Nfmt) {
1916 Dfmt = (Format >> DFMT_SHIFT) & DFMT_MASK;
1917 Nfmt = (Format >> NFMT_SHIFT) & NFMT_MASK;
1918}
1919
1921 if (isGFX11Plus(STI)) {
1922 for (int Id = UfmtGFX11::UFMT_FIRST; Id <= UfmtGFX11::UFMT_LAST; ++Id) {
1923 if (Name == UfmtSymbolicGFX11[Id])
1924 return Id;
1925 }
1926 } else {
1927 for (int Id = UfmtGFX10::UFMT_FIRST; Id <= UfmtGFX10::UFMT_LAST; ++Id) {
1928 if (Name == UfmtSymbolicGFX10[Id])
1929 return Id;
1930 }
1931 }
1932 return UFMT_UNDEF;
1933}
1934
1936 if(isValidUnifiedFormat(Id, STI))
1937 return isGFX10(STI) ? UfmtSymbolicGFX10[Id] : UfmtSymbolicGFX11[Id];
1938 return "";
1939}
1940
1941bool isValidUnifiedFormat(unsigned Id, const MCSubtargetInfo &STI) {
1942 return isGFX10(STI) ? Id <= UfmtGFX10::UFMT_LAST : Id <= UfmtGFX11::UFMT_LAST;
1943}
1944
1945int64_t convertDfmtNfmt2Ufmt(unsigned Dfmt, unsigned Nfmt,
1946 const MCSubtargetInfo &STI) {
1947 int64_t Fmt = encodeDfmtNfmt(Dfmt, Nfmt);
1948 if (isGFX11Plus(STI)) {
1949 for (int Id = UfmtGFX11::UFMT_FIRST; Id <= UfmtGFX11::UFMT_LAST; ++Id) {
1950 if (Fmt == DfmtNfmt2UFmtGFX11[Id])
1951 return Id;
1952 }
1953 } else {
1954 for (int Id = UfmtGFX10::UFMT_FIRST; Id <= UfmtGFX10::UFMT_LAST; ++Id) {
1955 if (Fmt == DfmtNfmt2UFmtGFX10[Id])
1956 return Id;
1957 }
1958 }
1959 return UFMT_UNDEF;
1960}
1961
1962bool isValidFormatEncoding(unsigned Val, const MCSubtargetInfo &STI) {
1963 return isGFX10Plus(STI) ? (Val <= UFMT_MAX) : (Val <= DFMT_NFMT_MAX);
1964}
1965
1967 if (isGFX10Plus(STI))
1968 return UFMT_DEFAULT;
1969 return DFMT_NFMT_DEFAULT;
1970}
1971
1972} // namespace MTBUFFormat
1973
1974//===----------------------------------------------------------------------===//
1975// SendMsg
1976//===----------------------------------------------------------------------===//
1977
1978namespace SendMsg {
1979
1982}
1983
1984bool isValidMsgId(int64_t MsgId, const MCSubtargetInfo &STI) {
1985 return (MsgId & ~(getMsgIdMask(STI))) == 0;
1986}
1987
1988bool isValidMsgOp(int64_t MsgId, int64_t OpId, const MCSubtargetInfo &STI,
1989 bool Strict) {
1990 assert(isValidMsgId(MsgId, STI));
1991
1992 if (!Strict)
1993 return 0 <= OpId && isUInt<OP_WIDTH_>(OpId);
1994
1995 if (msgRequiresOp(MsgId, STI)) {
1996 if (MsgId == ID_GS_PreGFX11 && OpId == OP_GS_NOP)
1997 return false;
1998
1999 return !getMsgOpName(MsgId, OpId, STI).empty();
2000 }
2001
2002 return OpId == OP_NONE_;
2003}
2004
2005bool isValidMsgStream(int64_t MsgId, int64_t OpId, int64_t StreamId,
2006 const MCSubtargetInfo &STI, bool Strict) {
2007 assert(isValidMsgOp(MsgId, OpId, STI, Strict));
2008
2009 if (!Strict)
2010 return 0 <= StreamId && isUInt<STREAM_ID_WIDTH_>(StreamId);
2011
2012 if (!isGFX11Plus(STI)) {
2013 switch (MsgId) {
2014 case ID_GS_PreGFX11:
2017 return (OpId == OP_GS_NOP) ?
2020 }
2021 }
2022 return StreamId == STREAM_ID_NONE_;
2023}
2024
2025bool msgRequiresOp(int64_t MsgId, const MCSubtargetInfo &STI) {
2026 return MsgId == ID_SYSMSG ||
2027 (!isGFX11Plus(STI) &&
2028 (MsgId == ID_GS_PreGFX11 || MsgId == ID_GS_DONE_PreGFX11));
2029}
2030
2031bool msgSupportsStream(int64_t MsgId, int64_t OpId,
2032 const MCSubtargetInfo &STI) {
2033 return !isGFX11Plus(STI) &&
2034 (MsgId == ID_GS_PreGFX11 || MsgId == ID_GS_DONE_PreGFX11) &&
2035 OpId != OP_GS_NOP;
2036}
2037
2038void decodeMsg(unsigned Val, uint16_t &MsgId, uint16_t &OpId,
2039 uint16_t &StreamId, const MCSubtargetInfo &STI) {
2040 MsgId = Val & getMsgIdMask(STI);
2041 if (isGFX11Plus(STI)) {
2042 OpId = 0;
2043 StreamId = 0;
2044 } else {
2045 OpId = (Val & OP_MASK_) >> OP_SHIFT_;
2047 }
2048}
2049
2051 uint64_t OpId,
2053 return MsgId | (OpId << OP_SHIFT_) | (StreamId << STREAM_ID_SHIFT_);
2054}
2055
2056} // namespace SendMsg
2057
2058//===----------------------------------------------------------------------===//
2059//
2060//===----------------------------------------------------------------------===//
2061
2063 return F.getFnAttributeAsParsedInteger("InitialPSInputAddr", 0);
2064}
2065
2067 // As a safe default always respond as if PS has color exports.
2068 return F.getFnAttributeAsParsedInteger(
2069 "amdgpu-color-export",
2070 F.getCallingConv() == CallingConv::AMDGPU_PS ? 1 : 0) != 0;
2071}
2072
2074 return F.getFnAttributeAsParsedInteger("amdgpu-depth-export", 0) != 0;
2075}
2076
2078 switch(cc) {
2088 return true;
2089 default:
2090 return false;
2091 }
2092}
2093
2095 return isShader(cc) || cc == CallingConv::AMDGPU_Gfx;
2096}
2097
2099 return !isGraphics(cc) || cc == CallingConv::AMDGPU_CS;
2100}
2101
2103 switch (CC) {
2113 return true;
2114 default:
2115 return false;
2116 }
2117}
2118
2120 switch (CC) {
2122 return true;
2123 default:
2124 return isEntryFunctionCC(CC) || isChainCC(CC);
2125 }
2126}
2127
2129 switch (CC) {
2132 return true;
2133 default:
2134 return false;
2135 }
2136}
2137
2138bool isKernelCC(const Function *Func) {
2139 return AMDGPU::isModuleEntryFunctionCC(Func->getCallingConv());
2140}
2141
2142bool hasXNACK(const MCSubtargetInfo &STI) {
2143 return STI.hasFeature(AMDGPU::FeatureXNACK);
2144}
2145
2146bool hasSRAMECC(const MCSubtargetInfo &STI) {
2147 return STI.hasFeature(AMDGPU::FeatureSRAMECC);
2148}
2149
2151 return STI.hasFeature(AMDGPU::FeatureMIMG_R128) && !STI.hasFeature(AMDGPU::FeatureR128A16);
2152}
2153
2154bool hasA16(const MCSubtargetInfo &STI) {
2155 return STI.hasFeature(AMDGPU::FeatureA16);
2156}
2157
2158bool hasG16(const MCSubtargetInfo &STI) {
2159 return STI.hasFeature(AMDGPU::FeatureG16);
2160}
2161
2163 return !STI.hasFeature(AMDGPU::FeatureUnpackedD16VMem) && !isCI(STI) &&
2164 !isSI(STI);
2165}
2166
2167bool hasGDS(const MCSubtargetInfo &STI) {
2168 return STI.hasFeature(AMDGPU::FeatureGDS);
2169}
2170
2171unsigned getNSAMaxSize(const MCSubtargetInfo &STI, bool HasSampler) {
2172 auto Version = getIsaVersion(STI.getCPU());
2173 if (Version.Major == 10)
2174 return Version.Minor >= 3 ? 13 : 5;
2175 if (Version.Major == 11)
2176 return 5;
2177 if (Version.Major >= 12)
2178 return HasSampler ? 4 : 5;
2179 return 0;
2180}
2181
2182unsigned getMaxNumUserSGPRs(const MCSubtargetInfo &STI) { return 16; }
2183
2184bool isSI(const MCSubtargetInfo &STI) {
2185 return STI.hasFeature(AMDGPU::FeatureSouthernIslands);
2186}
2187
2188bool isCI(const MCSubtargetInfo &STI) {
2189 return STI.hasFeature(AMDGPU::FeatureSeaIslands);
2190}
2191
2192bool isVI(const MCSubtargetInfo &STI) {
2193 return STI.hasFeature(AMDGPU::FeatureVolcanicIslands);
2194}
2195
2196bool isGFX9(const MCSubtargetInfo &STI) {
2197 return STI.hasFeature(AMDGPU::FeatureGFX9);
2198}
2199
2201 return isGFX9(STI) || isGFX10(STI);
2202}
2203
2205 return isGFX9(STI) || isGFX10(STI) || isGFX11(STI);
2206}
2207
2209 return isVI(STI) || isGFX9(STI) || isGFX10(STI);
2210}
2211
2212bool isGFX8Plus(const MCSubtargetInfo &STI) {
2213 return isVI(STI) || isGFX9Plus(STI);
2214}
2215
2216bool isGFX9Plus(const MCSubtargetInfo &STI) {
2217 return isGFX9(STI) || isGFX10Plus(STI);
2218}
2219
2220bool isNotGFX9Plus(const MCSubtargetInfo &STI) { return !isGFX9Plus(STI); }
2221
2222bool isGFX10(const MCSubtargetInfo &STI) {
2223 return STI.hasFeature(AMDGPU::FeatureGFX10);
2224}
2225
2227 return isGFX10(STI) || isGFX11(STI);
2228}
2229
2231 return isGFX10(STI) || isGFX11Plus(STI);
2232}
2233
2234bool isGFX11(const MCSubtargetInfo &STI) {
2235 return STI.hasFeature(AMDGPU::FeatureGFX11);
2236}
2237
2239 return isGFX11(STI) || isGFX12Plus(STI);
2240}
2241
2242bool isGFX12(const MCSubtargetInfo &STI) {
2243 return STI.getFeatureBits()[AMDGPU::FeatureGFX12];
2244}
2245
2246bool isGFX12Plus(const MCSubtargetInfo &STI) { return isGFX12(STI); }
2247
2248bool isNotGFX12Plus(const MCSubtargetInfo &STI) { return !isGFX12Plus(STI); }
2249
2251 return !isGFX11Plus(STI);
2252}
2253
2255 return isSI(STI) || isCI(STI) || isVI(STI) || isGFX9(STI);
2256}
2257
2259 return isGFX10(STI) && !AMDGPU::isGFX10_BEncoding(STI);
2260}
2261
2263 return STI.hasFeature(AMDGPU::FeatureGCN3Encoding);
2264}
2265
2267 return STI.hasFeature(AMDGPU::FeatureGFX10_AEncoding);
2268}
2269
2271 return STI.hasFeature(AMDGPU::FeatureGFX10_BEncoding);
2272}
2273
2275 return STI.hasFeature(AMDGPU::FeatureGFX10_3Insts);
2276}
2277
2279 return isGFX10_BEncoding(STI) && !isGFX12Plus(STI);
2280}
2281
2282bool isGFX90A(const MCSubtargetInfo &STI) {
2283 return STI.hasFeature(AMDGPU::FeatureGFX90AInsts);
2284}
2285
2286bool isGFX940(const MCSubtargetInfo &STI) {
2287 return STI.hasFeature(AMDGPU::FeatureGFX940Insts);
2288}
2289
2291 return STI.hasFeature(AMDGPU::FeatureArchitectedFlatScratch);
2292}
2293
2295 return STI.hasFeature(AMDGPU::FeatureMAIInsts);
2296}
2297
2298bool hasVOPD(const MCSubtargetInfo &STI) {
2299 return STI.hasFeature(AMDGPU::FeatureVOPD);
2300}
2301
2303 return STI.hasFeature(AMDGPU::FeatureDPPSrc1SGPR);
2304}
2305
2307 return STI.hasFeature(AMDGPU::FeatureKernargPreload);
2308}
2309
2310int32_t getTotalNumVGPRs(bool has90AInsts, int32_t ArgNumAGPR,
2311 int32_t ArgNumVGPR) {
2312 if (has90AInsts && ArgNumAGPR)
2313 return alignTo(ArgNumVGPR, 4) + ArgNumAGPR;
2314 return std::max(ArgNumVGPR, ArgNumAGPR);
2315}
2316
2318 const MCRegisterClass SGPRClass = TRI->getRegClass(AMDGPU::SReg_32RegClassID);
2319 const MCRegister FirstSubReg = TRI->getSubReg(Reg, AMDGPU::sub0);
2320 return SGPRClass.contains(FirstSubReg != 0 ? FirstSubReg : Reg) ||
2321 Reg == AMDGPU::SCC;
2322}
2323
2325 return MRI.getEncodingValue(Reg) & AMDGPU::HWEncoding::IS_HI16;
2326}
2327
2328#define MAP_REG2REG \
2329 using namespace AMDGPU; \
2330 switch(Reg.id()) { \
2331 default: return Reg; \
2332 CASE_CI_VI(FLAT_SCR) \
2333 CASE_CI_VI(FLAT_SCR_LO) \
2334 CASE_CI_VI(FLAT_SCR_HI) \
2335 CASE_VI_GFX9PLUS(TTMP0) \
2336 CASE_VI_GFX9PLUS(TTMP1) \
2337 CASE_VI_GFX9PLUS(TTMP2) \
2338 CASE_VI_GFX9PLUS(TTMP3) \
2339 CASE_VI_GFX9PLUS(TTMP4) \
2340 CASE_VI_GFX9PLUS(TTMP5) \
2341 CASE_VI_GFX9PLUS(TTMP6) \
2342 CASE_VI_GFX9PLUS(TTMP7) \
2343 CASE_VI_GFX9PLUS(TTMP8) \
2344 CASE_VI_GFX9PLUS(TTMP9) \
2345 CASE_VI_GFX9PLUS(TTMP10) \
2346 CASE_VI_GFX9PLUS(TTMP11) \
2347 CASE_VI_GFX9PLUS(TTMP12) \
2348 CASE_VI_GFX9PLUS(TTMP13) \
2349 CASE_VI_GFX9PLUS(TTMP14) \
2350 CASE_VI_GFX9PLUS(TTMP15) \
2351 CASE_VI_GFX9PLUS(TTMP0_TTMP1) \
2352 CASE_VI_GFX9PLUS(TTMP2_TTMP3) \
2353 CASE_VI_GFX9PLUS(TTMP4_TTMP5) \
2354 CASE_VI_GFX9PLUS(TTMP6_TTMP7) \
2355 CASE_VI_GFX9PLUS(TTMP8_TTMP9) \
2356 CASE_VI_GFX9PLUS(TTMP10_TTMP11) \
2357 CASE_VI_GFX9PLUS(TTMP12_TTMP13) \
2358 CASE_VI_GFX9PLUS(TTMP14_TTMP15) \
2359 CASE_VI_GFX9PLUS(TTMP0_TTMP1_TTMP2_TTMP3) \
2360 CASE_VI_GFX9PLUS(TTMP4_TTMP5_TTMP6_TTMP7) \
2361 CASE_VI_GFX9PLUS(TTMP8_TTMP9_TTMP10_TTMP11) \
2362 CASE_VI_GFX9PLUS(TTMP12_TTMP13_TTMP14_TTMP15) \
2363 CASE_VI_GFX9PLUS(TTMP0_TTMP1_TTMP2_TTMP3_TTMP4_TTMP5_TTMP6_TTMP7) \
2364 CASE_VI_GFX9PLUS(TTMP4_TTMP5_TTMP6_TTMP7_TTMP8_TTMP9_TTMP10_TTMP11) \
2365 CASE_VI_GFX9PLUS(TTMP8_TTMP9_TTMP10_TTMP11_TTMP12_TTMP13_TTMP14_TTMP15) \
2366 CASE_VI_GFX9PLUS(TTMP0_TTMP1_TTMP2_TTMP3_TTMP4_TTMP5_TTMP6_TTMP7_TTMP8_TTMP9_TTMP10_TTMP11_TTMP12_TTMP13_TTMP14_TTMP15) \
2367 CASE_GFXPRE11_GFX11PLUS(M0) \
2368 CASE_GFXPRE11_GFX11PLUS(SGPR_NULL) \
2369 CASE_GFXPRE11_GFX11PLUS_TO(SGPR_NULL64, SGPR_NULL) \
2370 }
2371
2372#define CASE_CI_VI(node) \
2373 assert(!isSI(STI)); \
2374 case node: return isCI(STI) ? node##_ci : node##_vi;
2375
2376#define CASE_VI_GFX9PLUS(node) \
2377 case node: return isGFX9Plus(STI) ? node##_gfx9plus : node##_vi;
2378
2379#define CASE_GFXPRE11_GFX11PLUS(node) \
2380 case node: return isGFX11Plus(STI) ? node##_gfx11plus : node##_gfxpre11;
2381
2382#define CASE_GFXPRE11_GFX11PLUS_TO(node, result) \
2383 case node: return isGFX11Plus(STI) ? result##_gfx11plus : result##_gfxpre11;
2384
2386 if (STI.getTargetTriple().getArch() == Triple::r600)
2387 return Reg;
2389}
2390
2391#undef CASE_CI_VI
2392#undef CASE_VI_GFX9PLUS
2393#undef CASE_GFXPRE11_GFX11PLUS
2394#undef CASE_GFXPRE11_GFX11PLUS_TO
2395
2396#define CASE_CI_VI(node) case node##_ci: case node##_vi: return node;
2397#define CASE_VI_GFX9PLUS(node) case node##_vi: case node##_gfx9plus: return node;
2398#define CASE_GFXPRE11_GFX11PLUS(node) case node##_gfx11plus: case node##_gfxpre11: return node;
2399#define CASE_GFXPRE11_GFX11PLUS_TO(node, result)
2400
2402
2403bool isInlineValue(unsigned Reg) {
2404 switch (Reg) {
2405 case AMDGPU::SRC_SHARED_BASE_LO:
2406 case AMDGPU::SRC_SHARED_BASE:
2407 case AMDGPU::SRC_SHARED_LIMIT_LO:
2408 case AMDGPU::SRC_SHARED_LIMIT:
2409 case AMDGPU::SRC_PRIVATE_BASE_LO:
2410 case AMDGPU::SRC_PRIVATE_BASE:
2411 case AMDGPU::SRC_PRIVATE_LIMIT_LO:
2412 case AMDGPU::SRC_PRIVATE_LIMIT:
2413 case AMDGPU::SRC_POPS_EXITING_WAVE_ID:
2414 return true;
2415 case AMDGPU::SRC_VCCZ:
2416 case AMDGPU::SRC_EXECZ:
2417 case AMDGPU::SRC_SCC:
2418 return true;
2419 case AMDGPU::SGPR_NULL:
2420 return true;
2421 default:
2422 return false;
2423 }
2424}
2425
2426#undef CASE_CI_VI
2427#undef CASE_VI_GFX9PLUS
2428#undef CASE_GFXPRE11_GFX11PLUS
2429#undef CASE_GFXPRE11_GFX11PLUS_TO
2430#undef MAP_REG2REG
2431
2432bool isSISrcOperand(const MCInstrDesc &Desc, unsigned OpNo) {
2433 assert(OpNo < Desc.NumOperands);
2434 unsigned OpType = Desc.operands()[OpNo].OperandType;
2435 return OpType >= AMDGPU::OPERAND_SRC_FIRST &&
2436 OpType <= AMDGPU::OPERAND_SRC_LAST;
2437}
2438
2439bool isKImmOperand(const MCInstrDesc &Desc, unsigned OpNo) {
2440 assert(OpNo < Desc.NumOperands);
2441 unsigned OpType = Desc.operands()[OpNo].OperandType;
2442 return OpType >= AMDGPU::OPERAND_KIMM_FIRST &&
2443 OpType <= AMDGPU::OPERAND_KIMM_LAST;
2444}
2445
2446bool isSISrcFPOperand(const MCInstrDesc &Desc, unsigned OpNo) {
2447 assert(OpNo < Desc.NumOperands);
2448 unsigned OpType = Desc.operands()[OpNo].OperandType;
2449 switch (OpType) {
2466 return true;
2467 default:
2468 return false;
2469 }
2470}
2471
2472bool isSISrcInlinableOperand(const MCInstrDesc &Desc, unsigned OpNo) {
2473 assert(OpNo < Desc.NumOperands);
2474 unsigned OpType = Desc.operands()[OpNo].OperandType;
2475 return (OpType >= AMDGPU::OPERAND_REG_INLINE_C_FIRST &&
2479}
2480
2481// Avoid using MCRegisterClass::getSize, since that function will go away
2482// (move from MC* level to Target* level). Return size in bits.
2483unsigned getRegBitWidth(unsigned RCID) {
2484 switch (RCID) {
2485 case AMDGPU::SGPR_LO16RegClassID:
2486 case AMDGPU::AGPR_LO16RegClassID:
2487 return 16;
2488 case AMDGPU::SGPR_32RegClassID:
2489 case AMDGPU::VGPR_32RegClassID:
2490 case AMDGPU::VRegOrLds_32RegClassID:
2491 case AMDGPU::AGPR_32RegClassID:
2492 case AMDGPU::VS_32RegClassID:
2493 case AMDGPU::AV_32RegClassID:
2494 case AMDGPU::SReg_32RegClassID:
2495 case AMDGPU::SReg_32_XM0RegClassID:
2496 case AMDGPU::SRegOrLds_32RegClassID:
2497 return 32;
2498 case AMDGPU::SGPR_64RegClassID:
2499 case AMDGPU::VS_64RegClassID:
2500 case AMDGPU::SReg_64RegClassID:
2501 case AMDGPU::VReg_64RegClassID:
2502 case AMDGPU::AReg_64RegClassID:
2503 case AMDGPU::SReg_64_XEXECRegClassID:
2504 case AMDGPU::VReg_64_Align2RegClassID:
2505 case AMDGPU::AReg_64_Align2RegClassID:
2506 case AMDGPU::AV_64RegClassID:
2507 case AMDGPU::AV_64_Align2RegClassID:
2508 return 64;
2509 case AMDGPU::SGPR_96RegClassID:
2510 case AMDGPU::SReg_96RegClassID:
2511 case AMDGPU::VReg_96RegClassID:
2512 case AMDGPU::AReg_96RegClassID:
2513 case AMDGPU::VReg_96_Align2RegClassID:
2514 case AMDGPU::AReg_96_Align2RegClassID:
2515 case AMDGPU::AV_96RegClassID:
2516 case AMDGPU::AV_96_Align2RegClassID:
2517 return 96;
2518 case AMDGPU::SGPR_128RegClassID:
2519 case AMDGPU::SReg_128RegClassID:
2520 case AMDGPU::VReg_128RegClassID:
2521 case AMDGPU::AReg_128RegClassID:
2522 case AMDGPU::VReg_128_Align2RegClassID:
2523 case AMDGPU::AReg_128_Align2RegClassID:
2524 case AMDGPU::AV_128RegClassID:
2525 case AMDGPU::AV_128_Align2RegClassID:
2526 case AMDGPU::SReg_128_XNULLRegClassID:
2527 return 128;
2528 case AMDGPU::SGPR_160RegClassID:
2529 case AMDGPU::SReg_160RegClassID:
2530 case AMDGPU::VReg_160RegClassID:
2531 case AMDGPU::AReg_160RegClassID:
2532 case AMDGPU::VReg_160_Align2RegClassID:
2533 case AMDGPU::AReg_160_Align2RegClassID:
2534 case AMDGPU::AV_160RegClassID:
2535 case AMDGPU::AV_160_Align2RegClassID:
2536 return 160;
2537 case AMDGPU::SGPR_192RegClassID:
2538 case AMDGPU::SReg_192RegClassID:
2539 case AMDGPU::VReg_192RegClassID:
2540 case AMDGPU::AReg_192RegClassID:
2541 case AMDGPU::VReg_192_Align2RegClassID:
2542 case AMDGPU::AReg_192_Align2RegClassID:
2543 case AMDGPU::AV_192RegClassID:
2544 case AMDGPU::AV_192_Align2RegClassID:
2545 return 192;
2546 case AMDGPU::SGPR_224RegClassID:
2547 case AMDGPU::SReg_224RegClassID:
2548 case AMDGPU::VReg_224RegClassID:
2549 case AMDGPU::AReg_224RegClassID:
2550 case AMDGPU::VReg_224_Align2RegClassID:
2551 case AMDGPU::AReg_224_Align2RegClassID:
2552 case AMDGPU::AV_224RegClassID:
2553 case AMDGPU::AV_224_Align2RegClassID:
2554 return 224;
2555 case AMDGPU::SGPR_256RegClassID:
2556 case AMDGPU::SReg_256RegClassID:
2557 case AMDGPU::VReg_256RegClassID:
2558 case AMDGPU::AReg_256RegClassID:
2559 case AMDGPU::VReg_256_Align2RegClassID:
2560 case AMDGPU::AReg_256_Align2RegClassID:
2561 case AMDGPU::AV_256RegClassID:
2562 case AMDGPU::AV_256_Align2RegClassID:
2563 case AMDGPU::SReg_256_XNULLRegClassID:
2564 return 256;
2565 case AMDGPU::SGPR_288RegClassID:
2566 case AMDGPU::SReg_288RegClassID:
2567 case AMDGPU::VReg_288RegClassID:
2568 case AMDGPU::AReg_288RegClassID:
2569 case AMDGPU::VReg_288_Align2RegClassID:
2570 case AMDGPU::AReg_288_Align2RegClassID:
2571 case AMDGPU::AV_288RegClassID:
2572 case AMDGPU::AV_288_Align2RegClassID:
2573 return 288;
2574 case AMDGPU::SGPR_320RegClassID:
2575 case AMDGPU::SReg_320RegClassID:
2576 case AMDGPU::VReg_320RegClassID:
2577 case AMDGPU::AReg_320RegClassID:
2578 case AMDGPU::VReg_320_Align2RegClassID:
2579 case AMDGPU::AReg_320_Align2RegClassID:
2580 case AMDGPU::AV_320RegClassID:
2581 case AMDGPU::AV_320_Align2RegClassID:
2582 return 320;
2583 case AMDGPU::SGPR_352RegClassID:
2584 case AMDGPU::SReg_352RegClassID:
2585 case AMDGPU::VReg_352RegClassID:
2586 case AMDGPU::AReg_352RegClassID:
2587 case AMDGPU::VReg_352_Align2RegClassID:
2588 case AMDGPU::AReg_352_Align2RegClassID:
2589 case AMDGPU::AV_352RegClassID:
2590 case AMDGPU::AV_352_Align2RegClassID:
2591 return 352;
2592 case AMDGPU::SGPR_384RegClassID:
2593 case AMDGPU::SReg_384RegClassID:
2594 case AMDGPU::VReg_384RegClassID:
2595 case AMDGPU::AReg_384RegClassID:
2596 case AMDGPU::VReg_384_Align2RegClassID:
2597 case AMDGPU::AReg_384_Align2RegClassID:
2598 case AMDGPU::AV_384RegClassID:
2599 case AMDGPU::AV_384_Align2RegClassID:
2600 return 384;
2601 case AMDGPU::SGPR_512RegClassID:
2602 case AMDGPU::SReg_512RegClassID:
2603 case AMDGPU::VReg_512RegClassID:
2604 case AMDGPU::AReg_512RegClassID:
2605 case AMDGPU::VReg_512_Align2RegClassID:
2606 case AMDGPU::AReg_512_Align2RegClassID:
2607 case AMDGPU::AV_512RegClassID:
2608 case AMDGPU::AV_512_Align2RegClassID:
2609 return 512;
2610 case AMDGPU::SGPR_1024RegClassID:
2611 case AMDGPU::SReg_1024RegClassID:
2612 case AMDGPU::VReg_1024RegClassID:
2613 case AMDGPU::AReg_1024RegClassID:
2614 case AMDGPU::VReg_1024_Align2RegClassID:
2615 case AMDGPU::AReg_1024_Align2RegClassID:
2616 case AMDGPU::AV_1024RegClassID:
2617 case AMDGPU::AV_1024_Align2RegClassID:
2618 return 1024;
2619 default:
2620 llvm_unreachable("Unexpected register class");
2621 }
2622}
2623
2624unsigned getRegBitWidth(const MCRegisterClass &RC) {
2625 return getRegBitWidth(RC.getID());
2626}
2627
2629 unsigned OpNo) {
2630 assert(OpNo < Desc.NumOperands);
2631 unsigned RCID = Desc.operands()[OpNo].RegClass;
2632 return getRegBitWidth(RCID) / 8;
2633}
2634
2635bool isInlinableLiteral64(int64_t Literal, bool HasInv2Pi) {
2637 return true;
2638
2639 uint64_t Val = static_cast<uint64_t>(Literal);
2640 return (Val == llvm::bit_cast<uint64_t>(0.0)) ||
2641 (Val == llvm::bit_cast<uint64_t>(1.0)) ||
2642 (Val == llvm::bit_cast<uint64_t>(-1.0)) ||
2643 (Val == llvm::bit_cast<uint64_t>(0.5)) ||
2644 (Val == llvm::bit_cast<uint64_t>(-0.5)) ||
2645 (Val == llvm::bit_cast<uint64_t>(2.0)) ||
2646 (Val == llvm::bit_cast<uint64_t>(-2.0)) ||
2647 (Val == llvm::bit_cast<uint64_t>(4.0)) ||
2648 (Val == llvm::bit_cast<uint64_t>(-4.0)) ||
2649 (Val == 0x3fc45f306dc9c882 && HasInv2Pi);
2650}
2651
2652bool isInlinableLiteral32(int32_t Literal, bool HasInv2Pi) {
2654 return true;
2655
2656 // The actual type of the operand does not seem to matter as long
2657 // as the bits match one of the inline immediate values. For example:
2658 //
2659 // -nan has the hexadecimal encoding of 0xfffffffe which is -2 in decimal,
2660 // so it is a legal inline immediate.
2661 //
2662 // 1065353216 has the hexadecimal encoding 0x3f800000 which is 1.0f in
2663 // floating-point, so it is a legal inline immediate.
2664
2665 uint32_t Val = static_cast<uint32_t>(Literal);
2666 return (Val == llvm::bit_cast<uint32_t>(0.0f)) ||
2667 (Val == llvm::bit_cast<uint32_t>(1.0f)) ||
2668 (Val == llvm::bit_cast<uint32_t>(-1.0f)) ||
2669 (Val == llvm::bit_cast<uint32_t>(0.5f)) ||
2670 (Val == llvm::bit_cast<uint32_t>(-0.5f)) ||
2671 (Val == llvm::bit_cast<uint32_t>(2.0f)) ||
2672 (Val == llvm::bit_cast<uint32_t>(-2.0f)) ||
2673 (Val == llvm::bit_cast<uint32_t>(4.0f)) ||
2674 (Val == llvm::bit_cast<uint32_t>(-4.0f)) ||
2675 (Val == 0x3e22f983 && HasInv2Pi);
2676}
2677
2678bool isInlinableLiteralBF16(int16_t Literal, bool HasInv2Pi) {
2679 if (!HasInv2Pi)
2680 return false;
2682 return true;
2683 uint16_t Val = static_cast<uint16_t>(Literal);
2684 return Val == 0x3F00 || // 0.5
2685 Val == 0xBF00 || // -0.5
2686 Val == 0x3F80 || // 1.0
2687 Val == 0xBF80 || // -1.0
2688 Val == 0x4000 || // 2.0
2689 Val == 0xC000 || // -2.0
2690 Val == 0x4080 || // 4.0
2691 Val == 0xC080 || // -4.0
2692 Val == 0x3E22; // 1.0 / (2.0 * pi)
2693}
2694
2695bool isInlinableLiteralI16(int32_t Literal, bool HasInv2Pi) {
2696 return isInlinableLiteral32(Literal, HasInv2Pi);
2697}
2698
2699bool isInlinableLiteralFP16(int16_t Literal, bool HasInv2Pi) {
2700 if (!HasInv2Pi)
2701 return false;
2703 return true;
2704 uint16_t Val = static_cast<uint16_t>(Literal);
2705 return Val == 0x3C00 || // 1.0
2706 Val == 0xBC00 || // -1.0
2707 Val == 0x3800 || // 0.5
2708 Val == 0xB800 || // -0.5
2709 Val == 0x4000 || // 2.0
2710 Val == 0xC000 || // -2.0
2711 Val == 0x4400 || // 4.0
2712 Val == 0xC400 || // -4.0
2713 Val == 0x3118; // 1/2pi
2714}
2715
2716std::optional<unsigned> getInlineEncodingV216(bool IsFloat, uint32_t Literal) {
2717 // Unfortunately, the Instruction Set Architecture Reference Guide is
2718 // misleading about how the inline operands work for (packed) 16-bit
2719 // instructions. In a nutshell, the actual HW behavior is:
2720 //
2721 // - integer encodings (-16 .. 64) are always produced as sign-extended
2722 // 32-bit values
2723 // - float encodings are produced as:
2724 // - for F16 instructions: corresponding half-precision float values in
2725 // the LSBs, 0 in the MSBs
2726 // - for UI16 instructions: corresponding single-precision float value
2727 int32_t Signed = static_cast<int32_t>(Literal);
2728 if (Signed >= 0 && Signed <= 64)
2729 return 128 + Signed;
2730
2731 if (Signed >= -16 && Signed <= -1)
2732 return 192 + std::abs(Signed);
2733
2734 if (IsFloat) {
2735 // clang-format off
2736 switch (Literal) {
2737 case 0x3800: return 240; // 0.5
2738 case 0xB800: return 241; // -0.5
2739 case 0x3C00: return 242; // 1.0
2740 case 0xBC00: return 243; // -1.0
2741 case 0x4000: return 244; // 2.0
2742 case 0xC000: return 245; // -2.0
2743 case 0x4400: return 246; // 4.0
2744 case 0xC400: return 247; // -4.0
2745 case 0x3118: return 248; // 1.0 / (2.0 * pi)
2746 default: break;
2747 }
2748 // clang-format on
2749 } else {
2750 // clang-format off
2751 switch (Literal) {
2752 case 0x3F000000: return 240; // 0.5
2753 case 0xBF000000: return 241; // -0.5
2754 case 0x3F800000: return 242; // 1.0
2755 case 0xBF800000: return 243; // -1.0
2756 case 0x40000000: return 244; // 2.0
2757 case 0xC0000000: return 245; // -2.0
2758 case 0x40800000: return 246; // 4.0
2759 case 0xC0800000: return 247; // -4.0
2760 case 0x3E22F983: return 248; // 1.0 / (2.0 * pi)
2761 default: break;
2762 }
2763 // clang-format on
2764 }
2765
2766 return {};
2767}
2768
2769// Encoding of the literal as an inline constant for a V_PK_*_IU16 instruction
2770// or nullopt.
2771std::optional<unsigned> getInlineEncodingV2I16(uint32_t Literal) {
2772 return getInlineEncodingV216(false, Literal);
2773}
2774
2775// Encoding of the literal as an inline constant for a V_PK_*_BF16 instruction
2776// or nullopt.
2777std::optional<unsigned> getInlineEncodingV2BF16(uint32_t Literal) {
2778 int32_t Signed = static_cast<int32_t>(Literal);
2779 if (Signed >= 0 && Signed <= 64)
2780 return 128 + Signed;
2781
2782 if (Signed >= -16 && Signed <= -1)
2783 return 192 + std::abs(Signed);
2784
2785 // clang-format off
2786 switch (Literal) {
2787 case 0x3F00: return 240; // 0.5
2788 case 0xBF00: return 241; // -0.5
2789 case 0x3F80: return 242; // 1.0
2790 case 0xBF80: return 243; // -1.0
2791 case 0x4000: return 244; // 2.0
2792 case 0xC000: return 245; // -2.0
2793 case 0x4080: return 246; // 4.0
2794 case 0xC080: return 247; // -4.0
2795 case 0x3E22: return 248; // 1.0 / (2.0 * pi)
2796 default: break;
2797 }
2798 // clang-format on
2799
2800 return std::nullopt;
2801}
2802
2803// Encoding of the literal as an inline constant for a V_PK_*_F16 instruction
2804// or nullopt.
2805std::optional<unsigned> getInlineEncodingV2F16(uint32_t Literal) {
2806 return getInlineEncodingV216(true, Literal);
2807}
2808
2809// Whether the given literal can be inlined for a V_PK_* instruction.
2811 switch (OpType) {
2815 return getInlineEncodingV216(false, Literal).has_value();
2819 return getInlineEncodingV216(true, Literal).has_value();
2824 default:
2825 llvm_unreachable("bad packed operand type");
2826 }
2827}
2828
2829// Whether the given literal can be inlined for a V_PK_*_IU16 instruction.
2831 return getInlineEncodingV2I16(Literal).has_value();
2832}
2833
2834// Whether the given literal can be inlined for a V_PK_*_BF16 instruction.
2836 return getInlineEncodingV2BF16(Literal).has_value();
2837}
2838
2839// Whether the given literal can be inlined for a V_PK_*_F16 instruction.
2841 return getInlineEncodingV2F16(Literal).has_value();
2842}
2843
2844bool isValid32BitLiteral(uint64_t Val, bool IsFP64) {
2845 if (IsFP64)
2846 return !(Val & 0xffffffffu);
2847
2848 return isUInt<32>(Val) || isInt<32>(Val);
2849}
2850
2852 const Function *F = A->getParent();
2853
2854 // Arguments to compute shaders are never a source of divergence.
2855 CallingConv::ID CC = F->getCallingConv();
2856 switch (CC) {
2859 return true;
2870 // For non-compute shaders, SGPR inputs are marked with either inreg or
2871 // byval. Everything else is in VGPRs.
2872 return A->hasAttribute(Attribute::InReg) ||
2873 A->hasAttribute(Attribute::ByVal);
2874 default:
2875 // TODO: treat i1 as divergent?
2876 return A->hasAttribute(Attribute::InReg);
2877 }
2878}
2879
2880bool isArgPassedInSGPR(const CallBase *CB, unsigned ArgNo) {
2881 // Arguments to compute shaders are never a source of divergence.
2883 switch (CC) {
2886 return true;
2897 // For non-compute shaders, SGPR inputs are marked with either inreg or
2898 // byval. Everything else is in VGPRs.
2899 return CB->paramHasAttr(ArgNo, Attribute::InReg) ||
2900 CB->paramHasAttr(ArgNo, Attribute::ByVal);
2901 default:
2902 return CB->paramHasAttr(ArgNo, Attribute::InReg);
2903 }
2904}
2905
2906static bool hasSMEMByteOffset(const MCSubtargetInfo &ST) {
2907 return isGCN3Encoding(ST) || isGFX10Plus(ST);
2908}
2909
2911 int64_t EncodedOffset) {
2912 if (isGFX12Plus(ST))
2913 return isUInt<23>(EncodedOffset);
2914
2915 return hasSMEMByteOffset(ST) ? isUInt<20>(EncodedOffset)
2916 : isUInt<8>(EncodedOffset);
2917}
2918
2920 int64_t EncodedOffset,
2921 bool IsBuffer) {
2922 if (isGFX12Plus(ST))
2923 return isInt<24>(EncodedOffset);
2924
2925 return !IsBuffer &&
2927 isInt<21>(EncodedOffset);
2928}
2929
2930static bool isDwordAligned(uint64_t ByteOffset) {
2931 return (ByteOffset & 3) == 0;
2932}
2933
2935 uint64_t ByteOffset) {
2936 if (hasSMEMByteOffset(ST))
2937 return ByteOffset;
2938
2939 assert(isDwordAligned(ByteOffset));
2940 return ByteOffset >> 2;
2941}
2942
2943std::optional<int64_t> getSMRDEncodedOffset(const MCSubtargetInfo &ST,
2944 int64_t ByteOffset, bool IsBuffer,
2945 bool HasSOffset) {
2946 // For unbuffered smem loads, it is illegal for the Immediate Offset to be
2947 // negative if the resulting (Offset + (M0 or SOffset or zero) is negative.
2948 // Handle case where SOffset is not present.
2949 if (!IsBuffer && !HasSOffset && ByteOffset < 0 && hasSMRDSignedImmOffset(ST))
2950 return std::nullopt;
2951
2952 if (isGFX12Plus(ST)) // 24 bit signed offsets
2953 return isInt<24>(ByteOffset) ? std::optional<int64_t>(ByteOffset)
2954 : std::nullopt;
2955
2956 // The signed version is always a byte offset.
2957 if (!IsBuffer && hasSMRDSignedImmOffset(ST)) {
2959 return isInt<20>(ByteOffset) ? std::optional<int64_t>(ByteOffset)
2960 : std::nullopt;
2961 }
2962
2963 if (!isDwordAligned(ByteOffset) && !hasSMEMByteOffset(ST))
2964 return std::nullopt;
2965
2966 int64_t EncodedOffset = convertSMRDOffsetUnits(ST, ByteOffset);
2967 return isLegalSMRDEncodedUnsignedOffset(ST, EncodedOffset)
2968 ? std::optional<int64_t>(EncodedOffset)
2969 : std::nullopt;
2970}
2971
2972std::optional<int64_t> getSMRDEncodedLiteralOffset32(const MCSubtargetInfo &ST,
2973 int64_t ByteOffset) {
2974 if (!isCI(ST) || !isDwordAligned(ByteOffset))
2975 return std::nullopt;
2976
2977 int64_t EncodedOffset = convertSMRDOffsetUnits(ST, ByteOffset);
2978 return isUInt<32>(EncodedOffset) ? std::optional<int64_t>(EncodedOffset)
2979 : std::nullopt;
2980}
2981
2983 if (AMDGPU::isGFX10(ST))
2984 return 12;
2985
2986 if (AMDGPU::isGFX12(ST))
2987 return 24;
2988 return 13;
2989}
2990
2991namespace {
2992
2993struct SourceOfDivergence {
2994 unsigned Intr;
2995};
2996const SourceOfDivergence *lookupSourceOfDivergence(unsigned Intr);
2997
2998struct AlwaysUniform {
2999 unsigned Intr;
3000};
3001const AlwaysUniform *lookupAlwaysUniform(unsigned Intr);
3002
3003#define GET_SourcesOfDivergence_IMPL
3004#define GET_UniformIntrinsics_IMPL
3005#define GET_Gfx9BufferFormat_IMPL
3006#define GET_Gfx10BufferFormat_IMPL
3007#define GET_Gfx11PlusBufferFormat_IMPL
3008
3009#include "AMDGPUGenSearchableTables.inc"
3010
3011} // end anonymous namespace
3012
3013bool isIntrinsicSourceOfDivergence(unsigned IntrID) {
3014 return lookupSourceOfDivergence(IntrID);
3015}
3016
3017bool isIntrinsicAlwaysUniform(unsigned IntrID) {
3018 return lookupAlwaysUniform(IntrID);
3019}
3020
3022 uint8_t NumComponents,
3023 uint8_t NumFormat,
3024 const MCSubtargetInfo &STI) {
3025 return isGFX11Plus(STI)
3026 ? getGfx11PlusBufferFormatInfo(BitsPerComp, NumComponents,
3027 NumFormat)
3028 : isGFX10(STI) ? getGfx10BufferFormatInfo(BitsPerComp,
3029 NumComponents, NumFormat)
3030 : getGfx9BufferFormatInfo(BitsPerComp,
3031 NumComponents, NumFormat);
3032}
3033
3035 const MCSubtargetInfo &STI) {
3036 return isGFX11Plus(STI) ? getGfx11PlusBufferFormatInfo(Format)
3037 : isGFX10(STI) ? getGfx10BufferFormatInfo(Format)
3038 : getGfx9BufferFormatInfo(Format);
3039}
3040
3042 for (auto OpName : { OpName::vdst, OpName::src0, OpName::src1,
3043 OpName::src2 }) {
3044 int Idx = getNamedOperandIdx(OpDesc.getOpcode(), OpName);
3045 if (Idx == -1)
3046 continue;
3047
3048 if (OpDesc.operands()[Idx].RegClass == AMDGPU::VReg_64RegClassID ||
3049 OpDesc.operands()[Idx].RegClass == AMDGPU::VReg_64_Align2RegClassID)
3050 return true;
3051 }
3052
3053 return false;
3054}
3055
3056bool isDPALU_DPP(const MCInstrDesc &OpDesc) {
3057 return hasAny64BitVGPROperands(OpDesc);
3058}
3059
3061 // Currently this is 128 for all subtargets
3062 return 128;
3063}
3064
3065} // namespace AMDGPU
3066
3069 switch (S) {
3071 OS << "Unsupported";
3072 break;
3074 OS << "Any";
3075 break;
3077 OS << "Off";
3078 break;
3080 OS << "On";
3081 break;
3082 }
3083 return OS;
3084}
3085
3086} // namespace llvm
unsigned const MachineRegisterInfo * MRI
#define MAP_REG2REG
unsigned Intr
static llvm::cl::opt< unsigned > DefaultAMDHSACodeObjectVersion("amdhsa-code-object-version", llvm::cl::Hidden, llvm::cl::init(llvm::AMDGPU::AMDHSA_COV5), llvm::cl::desc("Set default AMDHSA Code Object Version (module flag " "or asm directive still take priority if present)"))
Provides AMDGPU specific target descriptions.
MC layer struct for AMDGPUMCKernelCodeT, provides MCExpr functionality where required.
@ AMD_CODE_PROPERTY_ENABLE_WAVEFRONT_SIZE32
This file contains the simple types necessary to represent the attributes associated with functions a...
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
std::string Name
uint32_t Index
uint64_t Size
#define F(x, y, z)
Definition: MD5.cpp:55
unsigned const TargetRegisterInfo * TRI
unsigned Reg
#define S_00B848_MEM_ORDERED(x)
Definition: SIDefines.h:1193
#define S_00B848_WGP_MODE(x)
Definition: SIDefines.h:1190
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
unsigned unsigned DefaultVal
raw_pwrite_stream & OS
This file contains some functions that are useful when dealing with strings.
void setTargetIDFromFeaturesString(StringRef FS)
TargetIDSetting getXnackSetting() const
AMDGPUTargetID(const MCSubtargetInfo &STI)
void setTargetIDFromTargetIDStream(StringRef TargetID)
TargetIDSetting getSramEccSetting() const
unsigned getIndexInParsedOperands(unsigned CompOprIdx) const
unsigned getIndexOfDstInParsedOperands() const
unsigned getIndexOfSrcInParsedOperands(unsigned CompSrcIdx) const
unsigned getCompParsedSrcOperandsNum() const
std::optional< unsigned > getInvalidCompOperandIndex(std::function< unsigned(unsigned, unsigned)> GetRegIdx, bool SkipSrc=false) const
std::array< unsigned, Component::MAX_OPR_NUM > RegIndices
Definition: Any.h:28
This class represents an incoming formal argument to a Function.
Definition: Argument.h:31
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1112
CallingConv::ID getCallingConv() const
Definition: InstrTypes.h:1399
bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Determine whether the argument or parameter has the given attribute.
This class represents an Operation in the Expression.
constexpr bool test(unsigned I) const
unsigned getAddressSpace() const
Definition: GlobalValue.h:206
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
void emitError(const Instruction *I, const Twine &ErrorStr)
emitError - Emit an error message to the currently installed error handler with optional location inf...
Describe properties that are true of each instruction in the target description file.
Definition: MCInstrDesc.h:198
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
Definition: MCInstrDesc.h:237
ArrayRef< MCOperandInfo > operands() const
Definition: MCInstrDesc.h:239
unsigned getNumDefs() const
Return the number of MachineOperands that are register definitions.
Definition: MCInstrDesc.h:248
int getOperandConstraint(unsigned OpNum, MCOI::OperandConstraint Constraint) const
Returns the value of the specified operand constraint if it is present.
Definition: MCInstrDesc.h:219
unsigned getOpcode() const
Return the opcode number for this descriptor.
Definition: MCInstrDesc.h:230
Interface to description of machine instruction set.
Definition: MCInstrInfo.h:26
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode.
Definition: MCInstrInfo.h:63
MCRegisterClass - Base class of TargetRegisterClass.
unsigned getID() const
getID() - Return the register class ID number.
bool contains(MCRegister Reg) const
contains - Return true if the specified register is included in this register class.
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Wrapper class representing physical registers. Should be passed by value.
Definition: MCRegister.h:33
Generic base class for all target subtargets.
bool hasFeature(unsigned Feature) const
const Triple & getTargetTriple() const
const FeatureBitset & getFeatureBits() const
StringRef getCPU() const
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1196
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
Definition: StringRef.h:853
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition: StringRef.h:700
bool getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
Definition: StringRef.h:470
std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:229
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:147
constexpr size_t size() const
size - Get the string size.
Definition: StringRef.h:150
bool ends_with(StringRef Suffix) const
Check if this string ends with the given Suffix.
Definition: StringRef.h:277
Manages the enabling and disabling of subtarget specific features.
const std::vector< std::string > & getFeatures() const
Returns the vector of individual subtarget features.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
OSType getOS() const
Get the parsed operating system type of this triple.
Definition: Triple.h:404
ArchType getArch() const
Get the parsed architecture type of this triple.
Definition: Triple.h:395
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:661
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ CONSTANT_ADDRESS_32BIT
Address space for 32-bit constant memory.
@ LOCAL_ADDRESS
Address space for local memory.
@ CONSTANT_ADDRESS
Address space for constant memory (VTX2).
@ GLOBAL_ADDRESS
Address space for global memory (RAT0, VTX0).
unsigned decodeFieldVaVcc(unsigned Encoded)
unsigned encodeFieldVaVcc(unsigned Encoded, unsigned VaVcc)
bool decodeDepCtr(unsigned Code, int &Id, StringRef &Name, unsigned &Val, bool &IsDefault, const MCSubtargetInfo &STI)
unsigned encodeFieldVaVdst(unsigned Encoded, unsigned VaVdst)
unsigned decodeFieldSaSdst(unsigned Encoded)
unsigned decodeFieldVaSdst(unsigned Encoded)
unsigned encodeFieldVmVsrc(unsigned Encoded, unsigned VmVsrc)
int encodeDepCtr(const StringRef Name, int64_t Val, unsigned &UsedOprMask, const MCSubtargetInfo &STI)
unsigned encodeFieldSaSdst(unsigned Encoded, unsigned SaSdst)
const CustomOperandVal DepCtrInfo[]
bool isSymbolicDepCtrEncoding(unsigned Code, bool &HasNonDefaultVal, const MCSubtargetInfo &STI)
unsigned decodeFieldVaVdst(unsigned Encoded)
int getDefaultDepCtrEncoding(const MCSubtargetInfo &STI)
unsigned decodeFieldVmVsrc(unsigned Encoded)
unsigned encodeFieldVaSdst(unsigned Encoded, unsigned VaSdst)
bool isSupportedTgtId(unsigned Id, const MCSubtargetInfo &STI)
static constexpr ExpTgt ExpTgtInfo[]
bool getTgtName(unsigned Id, StringRef &Name, int &Index)
unsigned getTgtId(const StringRef Name)
constexpr uint32_t VersionMajor
HSA metadata major version.
unsigned getVGPREncodingGranule(const MCSubtargetInfo *STI, std::optional< bool > EnableWavefrontSize32)
unsigned getTotalNumVGPRs(const MCSubtargetInfo *STI)
unsigned getWavesPerEUForWorkGroup(const MCSubtargetInfo *STI, unsigned FlatWorkGroupSize)
unsigned getWavefrontSize(const MCSubtargetInfo *STI)
unsigned getMaxWorkGroupsPerCU(const MCSubtargetInfo *STI, unsigned FlatWorkGroupSize)
unsigned getMaxFlatWorkGroupSize(const MCSubtargetInfo *STI)
unsigned getMaxWavesPerEU(const MCSubtargetInfo *STI)
unsigned getWavesPerWorkGroup(const MCSubtargetInfo *STI, unsigned FlatWorkGroupSize)
unsigned getNumExtraSGPRs(const MCSubtargetInfo *STI, bool VCCUsed, bool FlatScrUsed, bool XNACKUsed)
unsigned getSGPREncodingGranule(const MCSubtargetInfo *STI)
unsigned getLocalMemorySize(const MCSubtargetInfo *STI)
unsigned getAddressableLocalMemorySize(const MCSubtargetInfo *STI)
unsigned getMinNumVGPRs(const MCSubtargetInfo *STI, unsigned WavesPerEU)
unsigned getEUsPerCU(const MCSubtargetInfo *STI)
unsigned getAddressableNumSGPRs(const MCSubtargetInfo *STI)
unsigned getAddressableNumVGPRs(const MCSubtargetInfo *STI)
unsigned getMinNumSGPRs(const MCSubtargetInfo *STI, unsigned WavesPerEU)
static TargetIDSetting getTargetIDSettingFromFeatureString(StringRef FeatureString)
unsigned getMinFlatWorkGroupSize(const MCSubtargetInfo *STI)
unsigned getMaxNumSGPRs(const MCSubtargetInfo *STI, unsigned WavesPerEU, bool Addressable)
unsigned getNumSGPRBlocks(const MCSubtargetInfo *STI, unsigned NumSGPRs)
unsigned getMinWavesPerEU(const MCSubtargetInfo *STI)
unsigned getSGPRAllocGranule(const MCSubtargetInfo *STI)
unsigned getNumWavesPerEUWithNumVGPRs(const MCSubtargetInfo *STI, unsigned NumVGPRs)
unsigned getMaxNumVGPRs(const MCSubtargetInfo *STI, unsigned WavesPerEU)
unsigned getEncodedNumVGPRBlocks(const MCSubtargetInfo *STI, unsigned NumVGPRs, std::optional< bool > EnableWavefrontSize32)
unsigned getOccupancyWithNumSGPRs(unsigned SGPRs, unsigned MaxWaves, AMDGPUSubtarget::Generation Gen)
static unsigned getGranulatedNumRegisterBlocks(unsigned NumRegs, unsigned Granule)
unsigned getVGPRAllocGranule(const MCSubtargetInfo *STI, std::optional< bool > EnableWavefrontSize32)
unsigned getAddressableNumArchVGPRs(const MCSubtargetInfo *STI)
unsigned getAllocatedNumVGPRBlocks(const MCSubtargetInfo *STI, unsigned NumVGPRs, std::optional< bool > EnableWavefrontSize32)
unsigned getTotalNumSGPRs(const MCSubtargetInfo *STI)
StringLiteral const UfmtSymbolicGFX11[]
bool isValidUnifiedFormat(unsigned Id, const MCSubtargetInfo &STI)
unsigned getDefaultFormatEncoding(const MCSubtargetInfo &STI)
StringRef getUnifiedFormatName(unsigned Id, const MCSubtargetInfo &STI)
unsigned const DfmtNfmt2UFmtGFX10[]
StringLiteral const DfmtSymbolic[]
static StringLiteral const * getNfmtLookupTable(const MCSubtargetInfo &STI)
bool isValidNfmt(unsigned Id, const MCSubtargetInfo &STI)
StringLiteral const NfmtSymbolicGFX10[]
bool isValidDfmtNfmt(unsigned Id, const MCSubtargetInfo &STI)
int64_t convertDfmtNfmt2Ufmt(unsigned Dfmt, unsigned Nfmt, const MCSubtargetInfo &STI)
StringRef getDfmtName(unsigned Id)
int64_t encodeDfmtNfmt(unsigned Dfmt, unsigned Nfmt)
int64_t getUnifiedFormat(const StringRef Name, const MCSubtargetInfo &STI)
bool isValidFormatEncoding(unsigned Val, const MCSubtargetInfo &STI)
StringRef getNfmtName(unsigned Id, const MCSubtargetInfo &STI)
unsigned const DfmtNfmt2UFmtGFX11[]
StringLiteral const NfmtSymbolicVI[]
StringLiteral const NfmtSymbolicSICI[]
int64_t getNfmt(const StringRef Name, const MCSubtargetInfo &STI)
int64_t getDfmt(const StringRef Name)
StringLiteral const UfmtSymbolicGFX10[]
void decodeDfmtNfmt(unsigned Format, unsigned &Dfmt, unsigned &Nfmt)
uint64_t encodeMsg(uint64_t MsgId, uint64_t OpId, uint64_t StreamId)
bool msgSupportsStream(int64_t MsgId, int64_t OpId, const MCSubtargetInfo &STI)
void decodeMsg(unsigned Val, uint16_t &MsgId, uint16_t &OpId, uint16_t &StreamId, const MCSubtargetInfo &STI)
bool isValidMsgId(int64_t MsgId, const MCSubtargetInfo &STI)
bool isValidMsgStream(int64_t MsgId, int64_t OpId, int64_t StreamId, const MCSubtargetInfo &STI, bool Strict)
StringRef getMsgOpName(int64_t MsgId, uint64_t Encoding, const MCSubtargetInfo &STI)
Map from an encoding to the symbolic name for a sendmsg operation.
static uint64_t getMsgIdMask(const MCSubtargetInfo &STI)
bool msgRequiresOp(int64_t MsgId, const MCSubtargetInfo &STI)
bool isValidMsgOp(int64_t MsgId, int64_t OpId, const MCSubtargetInfo &STI, bool Strict)
constexpr unsigned VOPD_VGPR_BANK_MASKS[]
constexpr unsigned COMPONENTS_NUM
bool isGCN3Encoding(const MCSubtargetInfo &STI)
bool isInlinableLiteralBF16(int16_t Literal, bool HasInv2Pi)
bool isGFX10_BEncoding(const MCSubtargetInfo &STI)
bool isGFX10_GFX11(const MCSubtargetInfo &STI)
bool isInlinableLiteralV216(uint32_t Literal, uint8_t OpType)
LLVM_READONLY const MIMGInfo * getMIMGInfo(unsigned Opc)
unsigned getRegOperandSize(const MCRegisterInfo *MRI, const MCInstrDesc &Desc, unsigned OpNo)
Get size of register operand.
void decodeWaitcnt(const IsaVersion &Version, unsigned Waitcnt, unsigned &Vmcnt, unsigned &Expcnt, unsigned &Lgkmcnt)
Decodes Vmcnt, Expcnt and Lgkmcnt from given Waitcnt for given isa Version, and writes decoded values...
bool isInlinableLiteralFP16(int16_t Literal, bool HasInv2Pi)
bool isSGPR(MCRegister Reg, const MCRegisterInfo *TRI)
Is Reg - scalar register.
uint64_t convertSMRDOffsetUnits(const MCSubtargetInfo &ST, uint64_t ByteOffset)
Convert ByteOffset to dwords if the subtarget uses dword SMRD immediate offsets.
static unsigned encodeStorecnt(const IsaVersion &Version, unsigned Waitcnt, unsigned Storecnt)
MCRegister getMCReg(MCRegister Reg, const MCSubtargetInfo &STI)
If Reg is a pseudo reg, return the correct hardware register given STI otherwise return Reg.
static bool hasSMEMByteOffset(const MCSubtargetInfo &ST)
bool isVOPCAsmOnly(unsigned Opc)
int getMIMGOpcode(unsigned BaseOpcode, unsigned MIMGEncoding, unsigned VDataDwords, unsigned VAddrDwords)
bool getMTBUFHasSrsrc(unsigned Opc)
std::optional< int64_t > getSMRDEncodedLiteralOffset32(const MCSubtargetInfo &ST, int64_t ByteOffset)
static bool isSymbolicCustomOperandEncoding(const CustomOperandVal *Opr, int Size, unsigned Code, bool &HasNonDefaultVal, const MCSubtargetInfo &STI)
bool isGFX10Before1030(const MCSubtargetInfo &STI)
bool isSISrcInlinableOperand(const MCInstrDesc &Desc, unsigned OpNo)
Does this operand support only inlinable literals?
unsigned mapWMMA2AddrTo3AddrOpcode(unsigned Opc)
const int OPR_ID_UNSUPPORTED
bool shouldEmitConstantsToTextSection(const Triple &TT)
bool isInlinableLiteralV2I16(uint32_t Literal)
int getMTBUFElements(unsigned Opc)
bool isHi16Reg(MCRegister Reg, const MCRegisterInfo &MRI)
static int encodeCustomOperandVal(const CustomOperandVal &Op, int64_t InputVal)
int32_t getTotalNumVGPRs(bool has90AInsts, int32_t ArgNumAGPR, int32_t ArgNumVGPR)
bool isGFX10(const MCSubtargetInfo &STI)
LLVM_READONLY int16_t getNamedOperandIdx(uint16_t Opcode, uint16_t NamedIdx)
bool isInlinableLiteralV2BF16(uint32_t Literal)
unsigned getMaxNumUserSGPRs(const MCSubtargetInfo &STI)
std::optional< unsigned > getInlineEncodingV216(bool IsFloat, uint32_t Literal)
FPType getFPDstSelType(unsigned Opc)
unsigned getNumFlatOffsetBits(const MCSubtargetInfo &ST)
For pre-GFX12 FLAT instructions the offset must be positive; MSB is ignored and forced to zero.
bool hasA16(const MCSubtargetInfo &STI)
bool isLegalSMRDEncodedSignedOffset(const MCSubtargetInfo &ST, int64_t EncodedOffset, bool IsBuffer)
bool isGFX12Plus(const MCSubtargetInfo &STI)
unsigned getNSAMaxSize(const MCSubtargetInfo &STI, bool HasSampler)
CanBeVOPD getCanBeVOPD(unsigned Opc)
bool hasPackedD16(const MCSubtargetInfo &STI)
unsigned getStorecntBitMask(const IsaVersion &Version)
unsigned getLdsDwGranularity(const MCSubtargetInfo &ST)
bool isGFX940(const MCSubtargetInfo &STI)
bool isEntryFunctionCC(CallingConv::ID CC)
bool isInlinableLiteralV2F16(uint32_t Literal)
bool isHsaAbi(const MCSubtargetInfo &STI)
bool isGFX11(const MCSubtargetInfo &STI)
const int OPR_VAL_INVALID
bool getSMEMIsBuffer(unsigned Opc)
bool isGFX10_3_GFX11(const MCSubtargetInfo &STI)
uint8_t mfmaScaleF8F6F4FormatToNumRegs(unsigned EncodingVal)
bool isGroupSegment(const GlobalValue *GV)
IsaVersion getIsaVersion(StringRef GPU)
bool getMTBUFHasSoffset(unsigned Opc)
bool hasXNACK(const MCSubtargetInfo &STI)
bool isValid32BitLiteral(uint64_t Val, bool IsFP64)
static unsigned getCombinedCountBitMask(const IsaVersion &Version, bool IsStore)
unsigned getVOPDOpcode(unsigned Opc)
bool isDPALU_DPP(const MCInstrDesc &OpDesc)
unsigned encodeWaitcnt(const IsaVersion &Version, unsigned Vmcnt, unsigned Expcnt, unsigned Lgkmcnt)
Encodes Vmcnt, Expcnt and Lgkmcnt into Waitcnt for given isa Version.
bool isVOPC64DPP(unsigned Opc)
int getMUBUFOpcode(unsigned BaseOpc, unsigned Elements)
bool isCompute(CallingConv::ID cc)
bool getMAIIsGFX940XDL(unsigned Opc)
bool isSI(const MCSubtargetInfo &STI)
unsigned getDefaultAMDHSACodeObjectVersion()
bool isReadOnlySegment(const GlobalValue *GV)
bool isArgPassedInSGPR(const Argument *A)
bool isIntrinsicAlwaysUniform(unsigned IntrID)
int getMUBUFBaseOpcode(unsigned Opc)
unsigned getAMDHSACodeObjectVersion(const Module &M)
unsigned decodeLgkmcnt(const IsaVersion &Version, unsigned Waitcnt)
unsigned getWaitcntBitMask(const IsaVersion &Version)
bool getVOP3IsSingle(unsigned Opc)
bool isGFX9(const MCSubtargetInfo &STI)
bool getVOP1IsSingle(unsigned Opc)
static bool isDwordAligned(uint64_t ByteOffset)
unsigned getVOPDEncodingFamily(const MCSubtargetInfo &ST)
bool isGFX10_AEncoding(const MCSubtargetInfo &STI)
bool isKImmOperand(const MCInstrDesc &Desc, unsigned OpNo)
Is this a KImm operand?
bool getHasColorExport(const Function &F)
int getMTBUFBaseOpcode(unsigned Opc)
bool isChainCC(CallingConv::ID CC)
bool isGFX90A(const MCSubtargetInfo &STI)
unsigned getSamplecntBitMask(const IsaVersion &Version)
unsigned getDefaultQueueImplicitArgPosition(unsigned CodeObjectVersion)
bool hasSRAMECC(const MCSubtargetInfo &STI)
bool getHasDepthExport(const Function &F)
bool isGFX8_GFX9_GFX10(const MCSubtargetInfo &STI)
bool getMUBUFHasVAddr(unsigned Opc)
int getVOPDFull(unsigned OpX, unsigned OpY, unsigned EncodingFamily)
bool isTrue16Inst(unsigned Opc)
bool hasAny64BitVGPROperands(const MCInstrDesc &OpDesc)
std::pair< unsigned, unsigned > getVOPDComponents(unsigned VOPDOpcode)
bool isInlinableLiteral32(int32_t Literal, bool HasInv2Pi)
bool isGFX12(const MCSubtargetInfo &STI)
unsigned getInitialPSInputAddr(const Function &F)
unsigned encodeExpcnt(const IsaVersion &Version, unsigned Waitcnt, unsigned Expcnt)
bool isSISrcOperand(const MCInstrDesc &Desc, unsigned OpNo)
Is this an AMDGPU specific source operand? These include registers, inline constants,...
unsigned getKmcntBitMask(const IsaVersion &Version)
unsigned getVmcntBitMask(const IsaVersion &Version)
bool isNotGFX10Plus(const MCSubtargetInfo &STI)
bool hasMAIInsts(const MCSubtargetInfo &STI)
bool isIntrinsicSourceOfDivergence(unsigned IntrID)
bool isKernelCC(const Function *Func)
bool isGenericAtomic(unsigned Opc)
Waitcnt decodeStorecntDscnt(const IsaVersion &Version, unsigned StorecntDscnt)
bool isGFX8Plus(const MCSubtargetInfo &STI)
LLVM_READONLY bool hasNamedOperand(uint64_t Opcode, uint64_t NamedIdx)
LLVM_READNONE bool isInlinableIntLiteral(int64_t Literal)
Is this literal inlinable, and not one of the values intended for floating point values.
unsigned getLgkmcntBitMask(const IsaVersion &Version)
bool getMUBUFTfe(unsigned Opc)
unsigned getBvhcntBitMask(const IsaVersion &Version)
bool hasSMRDSignedImmOffset(const MCSubtargetInfo &ST)
bool hasMIMG_R128(const MCSubtargetInfo &STI)
bool hasGFX10_3Insts(const MCSubtargetInfo &STI)
bool hasG16(const MCSubtargetInfo &STI)
unsigned getAddrSizeMIMGOp(const MIMGBaseOpcodeInfo *BaseOpcode, const MIMGDimInfo *Dim, bool IsA16, bool IsG16Supported)
int getMTBUFOpcode(unsigned BaseOpc, unsigned Elements)
unsigned getExpcntBitMask(const IsaVersion &Version)
bool hasArchitectedFlatScratch(const MCSubtargetInfo &STI)
bool getMUBUFHasSoffset(unsigned Opc)
bool isNotGFX11Plus(const MCSubtargetInfo &STI)
bool isGFX11Plus(const MCSubtargetInfo &STI)
std::optional< unsigned > getInlineEncodingV2F16(uint32_t Literal)
bool isInlineValue(unsigned Reg)
bool isSISrcFPOperand(const MCInstrDesc &Desc, unsigned OpNo)
Is this floating-point operand?
bool isShader(CallingConv::ID cc)
unsigned getHostcallImplicitArgPosition(unsigned CodeObjectVersion)
static unsigned getDefaultCustomOperandEncoding(const CustomOperandVal *Opr, int Size, const MCSubtargetInfo &STI)
static unsigned encodeLoadcnt(const IsaVersion &Version, unsigned Waitcnt, unsigned Loadcnt)
bool isGFX10Plus(const MCSubtargetInfo &STI)
static bool decodeCustomOperand(const CustomOperandVal *Opr, int Size, unsigned Code, int &Idx, StringRef &Name, unsigned &Val, bool &IsDefault, const MCSubtargetInfo &STI)
std::optional< int64_t > getSMRDEncodedOffset(const MCSubtargetInfo &ST, int64_t ByteOffset, bool IsBuffer, bool HasSOffset)
bool isGlobalSegment(const GlobalValue *GV)
@ OPERAND_KIMM_LAST
Definition: SIDefines.h:269
@ OPERAND_KIMM32
Operand with 32-bit immediate that uses the constant bus.
Definition: SIDefines.h:234
@ OPERAND_REG_INLINE_C_LAST
Definition: SIDefines.h:260
@ OPERAND_REG_IMM_V2FP16
Definition: SIDefines.h:211
@ OPERAND_REG_INLINE_C_FP64
Definition: SIDefines.h:223
@ OPERAND_REG_INLINE_C_V2BF16
Definition: SIDefines.h:225
@ OPERAND_REG_IMM_V2INT16
Definition: SIDefines.h:212
@ OPERAND_REG_INLINE_AC_V2FP16
Definition: SIDefines.h:246
@ OPERAND_SRC_FIRST
Definition: SIDefines.h:265
@ OPERAND_REG_IMM_V2BF16
Definition: SIDefines.h:210
@ OPERAND_REG_INLINE_AC_FIRST
Definition: SIDefines.h:262
@ OPERAND_KIMM_FIRST
Definition: SIDefines.h:268
@ OPERAND_REG_IMM_FP16
Definition: SIDefines.h:206
@ OPERAND_REG_IMM_FP64
Definition: SIDefines.h:204
@ OPERAND_REG_INLINE_C_V2FP16
Definition: SIDefines.h:226
@ OPERAND_REG_INLINE_AC_V2INT16
Definition: SIDefines.h:244
@ OPERAND_REG_INLINE_AC_FP16
Definition: SIDefines.h:241
@ OPERAND_REG_INLINE_AC_FP32
Definition: SIDefines.h:242
@ OPERAND_REG_INLINE_AC_V2BF16
Definition: SIDefines.h:245
@ OPERAND_REG_IMM_FP32
Definition: SIDefines.h:203
@ OPERAND_REG_INLINE_C_FIRST
Definition: SIDefines.h:259
@ OPERAND_REG_INLINE_C_FP32
Definition: SIDefines.h:222
@ OPERAND_REG_INLINE_AC_LAST
Definition: SIDefines.h:263
@ OPERAND_REG_INLINE_C_V2INT16
Definition: SIDefines.h:224
@ OPERAND_REG_IMM_V2FP32
Definition: SIDefines.h:214
@ OPERAND_REG_INLINE_AC_FP64
Definition: SIDefines.h:243
@ OPERAND_REG_INLINE_C_FP16
Definition: SIDefines.h:221
@ OPERAND_REG_INLINE_C_V2FP32
Definition: SIDefines.h:228
@ OPERAND_REG_IMM_FP32_DEFERRED
Definition: SIDefines.h:209
@ OPERAND_SRC_LAST
Definition: SIDefines.h:266
@ OPERAND_REG_IMM_FP16_DEFERRED
Definition: SIDefines.h:208
void initDefaultAMDKernelCodeT(AMDGPUMCKernelCodeT &KernelCode, const MCSubtargetInfo *STI)
bool isNotGFX9Plus(const MCSubtargetInfo &STI)
bool hasGDS(const MCSubtargetInfo &STI)
bool isLegalSMRDEncodedUnsignedOffset(const MCSubtargetInfo &ST, int64_t EncodedOffset)
bool isGFX9Plus(const MCSubtargetInfo &STI)
bool hasDPPSrc1SGPR(const MCSubtargetInfo &STI)
const int OPR_ID_DUPLICATE
bool isVOPD(unsigned Opc)
VOPD::InstInfo getVOPDInstInfo(const MCInstrDesc &OpX, const MCInstrDesc &OpY)
unsigned encodeVmcnt(const IsaVersion &Version, unsigned Waitcnt, unsigned Vmcnt)
unsigned decodeExpcnt(const IsaVersion &Version, unsigned Waitcnt)
bool isCvt_F32_Fp8_Bf8_e64(unsigned Opc)
Waitcnt decodeLoadcntDscnt(const IsaVersion &Version, unsigned LoadcntDscnt)
std::optional< unsigned > getInlineEncodingV2I16(uint32_t Literal)
unsigned getRegBitWidth(const TargetRegisterClass &RC)
Get the size in bits of a register from the register class RC.
static unsigned encodeStorecntDscnt(const IsaVersion &Version, unsigned Storecnt, unsigned Dscnt)
int getMCOpcode(uint16_t Opcode, unsigned Gen)
const MIMGBaseOpcodeInfo * getMIMGBaseOpcode(unsigned Opc)
bool isVI(const MCSubtargetInfo &STI)
bool getMUBUFIsBufferInv(unsigned Opc)
MCRegister mc2PseudoReg(MCRegister Reg)
Convert hardware register Reg to a pseudo register.
std::optional< unsigned > getInlineEncodingV2BF16(uint32_t Literal)
static int encodeCustomOperand(const CustomOperandVal *Opr, int Size, const StringRef Name, int64_t InputVal, unsigned &UsedOprMask, const MCSubtargetInfo &STI)
unsigned hasKernargPreload(const MCSubtargetInfo &STI)
bool isMAC(unsigned Opc)
bool isCI(const MCSubtargetInfo &STI)
unsigned encodeLgkmcnt(const IsaVersion &Version, unsigned Waitcnt, unsigned Lgkmcnt)
bool getVOP2IsSingle(unsigned Opc)
bool getMAIIsDGEMM(unsigned Opc)
Returns true if MAI operation is a double precision GEMM.
LLVM_READONLY const MIMGBaseOpcodeInfo * getMIMGBaseOpcodeInfo(unsigned BaseOpcode)
const int OPR_ID_UNKNOWN
unsigned getCompletionActionImplicitArgPosition(unsigned CodeObjectVersion)
SmallVector< unsigned > getIntegerVecAttribute(const Function &F, StringRef Name, unsigned Size, unsigned DefaultVal)
int getMaskedMIMGOp(unsigned Opc, unsigned NewChannels)
bool isModuleEntryFunctionCC(CallingConv::ID CC)
bool isNotGFX12Plus(const MCSubtargetInfo &STI)
bool getMTBUFHasVAddr(unsigned Opc)
unsigned decodeVmcnt(const IsaVersion &Version, unsigned Waitcnt)
uint8_t getELFABIVersion(const Triple &T, unsigned CodeObjectVersion)
std::pair< unsigned, unsigned > getIntegerPairAttribute(const Function &F, StringRef Name, std::pair< unsigned, unsigned > Default, bool OnlyFirstRequired)
unsigned getLoadcntBitMask(const IsaVersion &Version)
bool isInlinableLiteralI16(int32_t Literal, bool HasInv2Pi)
bool hasVOPD(const MCSubtargetInfo &STI)
static unsigned encodeDscnt(const IsaVersion &Version, unsigned Waitcnt, unsigned Dscnt)
bool isInlinableLiteral64(int64_t Literal, bool HasInv2Pi)
Is this literal inlinable.
const MFMA_F8F6F4_Info * getMFMA_F8F6F4_WithFormatArgs(unsigned CBSZ, unsigned BLGP, unsigned F8F8Opcode)
unsigned getMultigridSyncArgImplicitArgPosition(unsigned CodeObjectVersion)
bool isGFX9_GFX10_GFX11(const MCSubtargetInfo &STI)
bool isGFX9_GFX10(const MCSubtargetInfo &STI)
int getMUBUFElements(unsigned Opc)
static unsigned encodeLoadcntDscnt(const IsaVersion &Version, unsigned Loadcnt, unsigned Dscnt)
const GcnBufferFormatInfo * getGcnBufferFormatInfo(uint8_t BitsPerComp, uint8_t NumComponents, uint8_t NumFormat, const MCSubtargetInfo &STI)
bool isGraphics(CallingConv::ID cc)
unsigned mapWMMA3AddrTo2AddrOpcode(unsigned Opc)
bool isPermlane16(unsigned Opc)
bool getMUBUFHasSrsrc(unsigned Opc)
unsigned getDscntBitMask(const IsaVersion &Version)
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.
Definition: BitmaskEnum.h:125
@ AMDGPU_CS
Used for Mesa/AMDPAL compute shaders.
Definition: CallingConv.h:197
@ AMDGPU_VS
Used for Mesa vertex shaders, or AMDPAL last shader stage before rasterization (vertex shader if tess...
Definition: CallingConv.h:188
@ AMDGPU_KERNEL
Used for AMDGPU code object kernels.
Definition: CallingConv.h:200
@ AMDGPU_Gfx
Used for AMD graphics targets.
Definition: CallingConv.h:232
@ AMDGPU_CS_ChainPreserve
Used on AMDGPUs to give the middle-end more control over argument placement.
Definition: CallingConv.h:249
@ AMDGPU_HS
Used for Mesa/AMDPAL hull shaders (= tessellation control shaders).
Definition: CallingConv.h:206
@ AMDGPU_GS
Used for Mesa/AMDPAL geometry shaders.
Definition: CallingConv.h:191
@ AMDGPU_CS_Chain
Used on AMDGPUs to give the middle-end more control over argument placement.
Definition: CallingConv.h:245
@ AMDGPU_PS
Used for Mesa/AMDPAL pixel shaders.
Definition: CallingConv.h:194
@ SPIR_KERNEL
Used for SPIR kernel functions.
Definition: CallingConv.h:144
@ AMDGPU_ES
Used for AMDPAL shader stage before geometry shader if geometry is in use.
Definition: CallingConv.h:218
@ AMDGPU_LS
Used for AMDPAL vertex shader if tessellation is in use.
Definition: CallingConv.h:213
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
@ ELFABIVERSION_AMDGPU_HSA_V4
Definition: ELF.h:381
@ ELFABIVERSION_AMDGPU_HSA_V5
Definition: ELF.h:382
@ ELFABIVERSION_AMDGPU_HSA_V6
Definition: ELF.h:383
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
constexpr T alignDown(U Value, V Align, W Skew=0)
Returns the largest unsigned integer less than or equal to Value and is Skew mod Align.
Definition: MathExtras.h:556
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:167
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
constexpr T divideCeil(U Numerator, V Denominator)
Returns the integer ceil(Numerator / Denominator).
Definition: MathExtras.h:404
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition: Alignment.h:155
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
Definition: APFixedPoint.h:303
@ AlwaysUniform
The result values are always uniform.
@ Default
The result values are uniform if and only if all operands are uniform.
#define N
AMD Kernel Code Object (amd_kernel_code_t).
Instruction set architecture version.
Definition: TargetParser.h:130
Represents the counter values to wait for in an s_waitcnt instruction.
Description of the encoding of one expression Op.