LLVM 23.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/IR/Metadata.h"
25#include "llvm/MC/MCInstrInfo.h"
30#include <optional>
31
32#define GET_INSTRINFO_NAMED_OPS
33#define GET_INSTRMAP_INFO
34#include "AMDGPUGenInstrInfo.inc"
35
37 "amdhsa-code-object-version", llvm::cl::Hidden,
39 llvm::cl::desc("Set default AMDHSA Code Object Version (module flag "
40 "or asm directive still take priority if present)"));
41
42namespace {
43
44/// \returns Bit mask for given bit \p Shift and bit \p Width.
45unsigned getBitMask(unsigned Shift, unsigned Width) {
46 return ((1 << Width) - 1) << Shift;
47}
48
49/// Packs \p Src into \p Dst for given bit \p Shift and bit \p Width.
50///
51/// \returns Packed \p Dst.
52unsigned packBits(unsigned Src, unsigned Dst, unsigned Shift, unsigned Width) {
53 unsigned Mask = getBitMask(Shift, Width);
54 return ((Src << Shift) & Mask) | (Dst & ~Mask);
55}
56
57/// Unpacks bits from \p Src for given bit \p Shift and bit \p Width.
58///
59/// \returns Unpacked bits.
60unsigned unpackBits(unsigned Src, unsigned Shift, unsigned Width) {
61 return (Src & getBitMask(Shift, Width)) >> Shift;
62}
63
64/// \returns Vmcnt bit shift (lower bits).
65unsigned getVmcntBitShiftLo(unsigned VersionMajor) {
66 return VersionMajor >= 11 ? 10 : 0;
67}
68
69/// \returns Vmcnt bit width (lower bits).
70unsigned getVmcntBitWidthLo(unsigned VersionMajor) {
71 return VersionMajor >= 11 ? 6 : 4;
72}
73
74/// \returns Expcnt bit shift.
75unsigned getExpcntBitShift(unsigned VersionMajor) {
76 return VersionMajor >= 11 ? 0 : 4;
77}
78
79/// \returns Expcnt bit width.
80unsigned getExpcntBitWidth(unsigned VersionMajor) { return 3; }
81
82/// \returns Lgkmcnt bit shift.
83unsigned getLgkmcntBitShift(unsigned VersionMajor) {
84 return VersionMajor >= 11 ? 4 : 8;
85}
86
87/// \returns Lgkmcnt bit width.
88unsigned getLgkmcntBitWidth(unsigned VersionMajor) {
89 return VersionMajor >= 10 ? 6 : 4;
90}
91
92/// \returns Vmcnt bit shift (higher bits).
93unsigned getVmcntBitShiftHi(unsigned VersionMajor) { return 14; }
94
95/// \returns Vmcnt bit width (higher bits).
96unsigned getVmcntBitWidthHi(unsigned VersionMajor) {
97 return (VersionMajor == 9 || VersionMajor == 10) ? 2 : 0;
98}
99
100/// \returns Loadcnt bit width
101unsigned getLoadcntBitWidth(unsigned VersionMajor) {
102 return VersionMajor >= 12 ? 6 : 0;
103}
104
105/// \returns Samplecnt bit width.
106unsigned getSamplecntBitWidth(unsigned VersionMajor) {
107 return VersionMajor >= 12 ? 6 : 0;
108}
109
110/// \returns Bvhcnt bit width.
111unsigned getBvhcntBitWidth(unsigned VersionMajor) {
112 return VersionMajor >= 12 ? 3 : 0;
113}
114
115/// \returns Dscnt bit width.
116unsigned getDscntBitWidth(unsigned VersionMajor) {
117 return VersionMajor >= 12 ? 6 : 0;
118}
119
120/// \returns Dscnt bit shift in combined S_WAIT instructions.
121unsigned getDscntBitShift(unsigned VersionMajor) { return 0; }
122
123/// \returns Storecnt or Vscnt bit width, depending on VersionMajor.
124unsigned getStorecntBitWidth(unsigned VersionMajor) {
125 return VersionMajor >= 10 ? 6 : 0;
126}
127
128/// \returns Kmcnt bit width.
129unsigned getKmcntBitWidth(unsigned VersionMajor) {
130 return VersionMajor >= 12 ? 5 : 0;
131}
132
133/// \returns Xcnt bit width.
134unsigned getXcntBitWidth(unsigned VersionMajor, unsigned VersionMinor) {
135 return VersionMajor == 12 && VersionMinor == 5 ? 6 : 0;
136}
137
138/// \returns Asynccnt bit width.
139unsigned getAsynccntBitWidth(unsigned VersionMajor, unsigned VersionMinor) {
140 return VersionMajor == 12 && VersionMinor == 5 ? 6 : 0;
141}
142
143/// \returns shift for Loadcnt/Storecnt in combined S_WAIT instructions.
144unsigned getLoadcntStorecntBitShift(unsigned VersionMajor) {
145 return VersionMajor >= 12 ? 8 : 0;
146}
147
148/// \returns VaSdst bit width
149inline unsigned getVaSdstBitWidth() { return 3; }
150
151/// \returns VaSdst bit shift
152inline unsigned getVaSdstBitShift() { return 9; }
153
154/// \returns VmVsrc bit width
155inline unsigned getVmVsrcBitWidth() { return 3; }
156
157/// \returns VmVsrc bit shift
158inline unsigned getVmVsrcBitShift() { return 2; }
159
160/// \returns VaVdst bit width
161inline unsigned getVaVdstBitWidth() { return 4; }
162
163/// \returns VaVdst bit shift
164inline unsigned getVaVdstBitShift() { return 12; }
165
166/// \returns VaVcc bit width
167inline unsigned getVaVccBitWidth() { return 1; }
168
169/// \returns VaVcc bit shift
170inline unsigned getVaVccBitShift() { return 1; }
171
172/// \returns SaSdst bit width
173inline unsigned getSaSdstBitWidth() { return 1; }
174
175/// \returns SaSdst bit shift
176inline unsigned getSaSdstBitShift() { return 0; }
177
178/// \returns VaSsrc width
179inline unsigned getVaSsrcBitWidth() { return 1; }
180
181/// \returns VaSsrc bit shift
182inline unsigned getVaSsrcBitShift() { return 8; }
183
184/// \returns HoldCnt bit shift
185inline unsigned getHoldCntWidth(unsigned VersionMajor, unsigned VersionMinor) {
186 static constexpr const unsigned MinMajor = 10;
187 static constexpr const unsigned MinMinor = 3;
188 return std::tie(VersionMajor, VersionMinor) >= std::tie(MinMajor, MinMinor)
189 ? 1
190 : 0;
191}
192
193/// \returns HoldCnt bit shift
194inline unsigned getHoldCntBitShift() { return 7; }
195
196} // end anonymous namespace
197
198namespace llvm {
199
200namespace AMDGPU {
201
202/// \returns true if the target supports signed immediate offset for SMRD
203/// instructions.
205 return isGFX9Plus(ST);
206}
207
208/// \returns True if \p STI is AMDHSA.
209bool isHsaAbi(const MCSubtargetInfo &STI) {
210 return STI.getTargetTriple().getOS() == Triple::AMDHSA;
211}
212
215 M.getModuleFlag("amdhsa_code_object_version"))) {
216 return (unsigned)Ver->getZExtValue() / 100;
217 }
218
220}
221
225
226unsigned getAMDHSACodeObjectVersion(unsigned ABIVersion) {
227 switch (ABIVersion) {
229 return 4;
231 return 5;
233 return 6;
234 default:
236 }
237}
238
239uint8_t getELFABIVersion(const Triple &T, unsigned CodeObjectVersion) {
240 if (T.getOS() != Triple::AMDHSA)
241 return 0;
242
243 switch (CodeObjectVersion) {
244 case 4:
246 case 5:
248 case 6:
250 default:
251 report_fatal_error("Unsupported AMDHSA Code Object Version " +
252 Twine(CodeObjectVersion));
253 }
254}
255
256unsigned getMultigridSyncArgImplicitArgPosition(unsigned CodeObjectVersion) {
257 switch (CodeObjectVersion) {
258 case AMDHSA_COV4:
259 return 48;
260 case AMDHSA_COV5:
261 case AMDHSA_COV6:
262 default:
264 }
265}
266
267// FIXME: All such magic numbers about the ABI should be in a
268// central TD file.
269unsigned getHostcallImplicitArgPosition(unsigned CodeObjectVersion) {
270 switch (CodeObjectVersion) {
271 case AMDHSA_COV4:
272 return 24;
273 case AMDHSA_COV5:
274 case AMDHSA_COV6:
275 default:
277 }
278}
279
280unsigned getDefaultQueueImplicitArgPosition(unsigned CodeObjectVersion) {
281 switch (CodeObjectVersion) {
282 case AMDHSA_COV4:
283 return 32;
284 case AMDHSA_COV5:
285 case AMDHSA_COV6:
286 default:
288 }
289}
290
291unsigned getCompletionActionImplicitArgPosition(unsigned CodeObjectVersion) {
292 switch (CodeObjectVersion) {
293 case AMDHSA_COV4:
294 return 40;
295 case AMDHSA_COV5:
296 case AMDHSA_COV6:
297 default:
299 }
300}
301
302#define GET_MIMGBaseOpcodesTable_IMPL
303#define GET_MIMGDimInfoTable_IMPL
304#define GET_MIMGInfoTable_IMPL
305#define GET_MIMGLZMappingTable_IMPL
306#define GET_MIMGMIPMappingTable_IMPL
307#define GET_MIMGBiasMappingTable_IMPL
308#define GET_MIMGOffsetMappingTable_IMPL
309#define GET_MIMGG16MappingTable_IMPL
310#define GET_MAIInstInfoTable_IMPL
311#define GET_WMMAInstInfoTable_IMPL
312#include "AMDGPUGenSearchableTables.inc"
313
314int getMIMGOpcode(unsigned BaseOpcode, unsigned MIMGEncoding,
315 unsigned VDataDwords, unsigned VAddrDwords) {
316 const MIMGInfo *Info =
317 getMIMGOpcodeHelper(BaseOpcode, MIMGEncoding, VDataDwords, VAddrDwords);
318 return Info ? Info->Opcode : -1;
319}
320
322 const MIMGInfo *Info = getMIMGInfo(Opc);
323 return Info ? getMIMGBaseOpcodeInfo(Info->BaseOpcode) : nullptr;
324}
325
326int getMaskedMIMGOp(unsigned Opc, unsigned NewChannels) {
327 const MIMGInfo *OrigInfo = getMIMGInfo(Opc);
328 const MIMGInfo *NewInfo =
329 getMIMGOpcodeHelper(OrigInfo->BaseOpcode, OrigInfo->MIMGEncoding,
330 NewChannels, OrigInfo->VAddrDwords);
331 return NewInfo ? NewInfo->Opcode : -1;
332}
333
334unsigned getAddrSizeMIMGOp(const MIMGBaseOpcodeInfo *BaseOpcode,
335 const MIMGDimInfo *Dim, bool IsA16,
336 bool IsG16Supported) {
337 unsigned AddrWords = BaseOpcode->NumExtraArgs;
338 unsigned AddrComponents = (BaseOpcode->Coordinates ? Dim->NumCoords : 0) +
339 (BaseOpcode->LodOrClampOrMip ? 1 : 0);
340 if (IsA16)
341 AddrWords += divideCeil(AddrComponents, 2);
342 else
343 AddrWords += AddrComponents;
344
345 // Note: For subtargets that support A16 but not G16, enabling A16 also
346 // enables 16 bit gradients.
347 // For subtargets that support A16 (operand) and G16 (done with a different
348 // instruction encoding), they are independent.
349
350 if (BaseOpcode->Gradients) {
351 if ((IsA16 && !IsG16Supported) || BaseOpcode->G16)
352 // There are two gradients per coordinate, we pack them separately.
353 // For the 3d case,
354 // we get (dy/du, dx/du) (-, dz/du) (dy/dv, dx/dv) (-, dz/dv)
355 AddrWords += alignTo<2>(Dim->NumGradients / 2);
356 else
357 AddrWords += Dim->NumGradients;
358 }
359 return AddrWords;
360}
361
372
381
386
391
395
399
403
408
416
421
427
428#define GET_FP4FP8DstByteSelTable_DECL
429#define GET_FP4FP8DstByteSelTable_IMPL
430
435
441
442#define GET_DPMACCInstructionTable_DECL
443#define GET_DPMACCInstructionTable_IMPL
444#define GET_MTBUFInfoTable_DECL
445#define GET_MTBUFInfoTable_IMPL
446#define GET_MUBUFInfoTable_DECL
447#define GET_MUBUFInfoTable_IMPL
448#define GET_SMInfoTable_DECL
449#define GET_SMInfoTable_IMPL
450#define GET_VOP1InfoTable_DECL
451#define GET_VOP1InfoTable_IMPL
452#define GET_VOP2InfoTable_DECL
453#define GET_VOP2InfoTable_IMPL
454#define GET_VOP3InfoTable_DECL
455#define GET_VOP3InfoTable_IMPL
456#define GET_VOPC64DPPTable_DECL
457#define GET_VOPC64DPPTable_IMPL
458#define GET_VOPC64DPP8Table_DECL
459#define GET_VOPC64DPP8Table_IMPL
460#define GET_VOPCAsmOnlyInfoTable_DECL
461#define GET_VOPCAsmOnlyInfoTable_IMPL
462#define GET_VOP3CAsmOnlyInfoTable_DECL
463#define GET_VOP3CAsmOnlyInfoTable_IMPL
464#define GET_VOPDComponentTable_DECL
465#define GET_VOPDComponentTable_IMPL
466#define GET_VOPDPairs_DECL
467#define GET_VOPDPairs_IMPL
468#define GET_VOPDXTable_DECL
469#define GET_VOPDXTable_IMPL
470#define GET_VOPDYTable_DECL
471#define GET_VOPDYTable_IMPL
472#define GET_VOPTrue16Table_DECL
473#define GET_VOPTrue16Table_IMPL
474#define GET_True16D16Table_IMPL
475#define GET_WMMAOpcode2AddrMappingTable_DECL
476#define GET_WMMAOpcode2AddrMappingTable_IMPL
477#define GET_WMMAOpcode3AddrMappingTable_DECL
478#define GET_WMMAOpcode3AddrMappingTable_IMPL
479#define GET_getMFMA_F8F6F4_WithSize_DECL
480#define GET_getMFMA_F8F6F4_WithSize_IMPL
481#define GET_isMFMA_F8F6F4Table_IMPL
482#define GET_isCvtScaleF32_F32F16ToF8F4Table_IMPL
483
484#include "AMDGPUGenSearchableTables.inc"
485
486int getMTBUFBaseOpcode(unsigned Opc) {
487 const MTBUFInfo *Info = getMTBUFInfoFromOpcode(Opc);
488 return Info ? Info->BaseOpcode : -1;
489}
490
491int getMTBUFOpcode(unsigned BaseOpc, unsigned Elements) {
492 const MTBUFInfo *Info =
493 getMTBUFInfoFromBaseOpcodeAndElements(BaseOpc, Elements);
494 return Info ? Info->Opcode : -1;
495}
496
497int getMTBUFElements(unsigned Opc) {
498 const MTBUFInfo *Info = getMTBUFOpcodeHelper(Opc);
499 return Info ? Info->elements : 0;
500}
501
502bool getMTBUFHasVAddr(unsigned Opc) {
503 const MTBUFInfo *Info = getMTBUFOpcodeHelper(Opc);
504 return Info && Info->has_vaddr;
505}
506
507bool getMTBUFHasSrsrc(unsigned Opc) {
508 const MTBUFInfo *Info = getMTBUFOpcodeHelper(Opc);
509 return Info && Info->has_srsrc;
510}
511
512bool getMTBUFHasSoffset(unsigned Opc) {
513 const MTBUFInfo *Info = getMTBUFOpcodeHelper(Opc);
514 return Info && Info->has_soffset;
515}
516
517int getMUBUFBaseOpcode(unsigned Opc) {
518 const MUBUFInfo *Info = getMUBUFInfoFromOpcode(Opc);
519 return Info ? Info->BaseOpcode : -1;
520}
521
522int getMUBUFOpcode(unsigned BaseOpc, unsigned Elements) {
523 const MUBUFInfo *Info =
524 getMUBUFInfoFromBaseOpcodeAndElements(BaseOpc, Elements);
525 return Info ? Info->Opcode : -1;
526}
527
528int getMUBUFElements(unsigned Opc) {
529 const MUBUFInfo *Info = getMUBUFOpcodeHelper(Opc);
530 return Info ? Info->elements : 0;
531}
532
533bool getMUBUFHasVAddr(unsigned Opc) {
534 const MUBUFInfo *Info = getMUBUFOpcodeHelper(Opc);
535 return Info && Info->has_vaddr;
536}
537
538bool getMUBUFHasSrsrc(unsigned Opc) {
539 const MUBUFInfo *Info = getMUBUFOpcodeHelper(Opc);
540 return Info && Info->has_srsrc;
541}
542
543bool getMUBUFHasSoffset(unsigned Opc) {
544 const MUBUFInfo *Info = getMUBUFOpcodeHelper(Opc);
545 return Info && Info->has_soffset;
546}
547
548bool getMUBUFIsBufferInv(unsigned Opc) {
549 const MUBUFInfo *Info = getMUBUFOpcodeHelper(Opc);
550 return Info && Info->IsBufferInv;
551}
552
553bool getMUBUFTfe(unsigned Opc) {
554 const MUBUFInfo *Info = getMUBUFOpcodeHelper(Opc);
555 return Info && Info->tfe;
556}
557
558bool getSMEMIsBuffer(unsigned Opc) {
559 const SMInfo *Info = getSMEMOpcodeHelper(Opc);
560 return Info && Info->IsBuffer;
561}
562
563bool getVOP1IsSingle(unsigned Opc) {
564 const VOPInfo *Info = getVOP1OpcodeHelper(Opc);
565 return !Info || Info->IsSingle;
566}
567
568bool getVOP2IsSingle(unsigned Opc) {
569 const VOPInfo *Info = getVOP2OpcodeHelper(Opc);
570 return !Info || Info->IsSingle;
571}
572
573bool getVOP3IsSingle(unsigned Opc) {
574 const VOPInfo *Info = getVOP3OpcodeHelper(Opc);
575 return !Info || Info->IsSingle;
576}
577
578bool isVOPC64DPP(unsigned Opc) {
579 return isVOPC64DPPOpcodeHelper(Opc) || isVOPC64DPP8OpcodeHelper(Opc);
580}
581
582bool isVOPCAsmOnly(unsigned Opc) { return isVOPCAsmOnlyOpcodeHelper(Opc); }
583
584bool getMAIIsDGEMM(unsigned Opc) {
585 const MAIInstInfo *Info = getMAIInstInfoHelper(Opc);
586 return Info && Info->is_dgemm;
587}
588
589bool getMAIIsGFX940XDL(unsigned Opc) {
590 const MAIInstInfo *Info = getMAIInstInfoHelper(Opc);
591 return Info && Info->is_gfx940_xdl;
592}
593
594bool getWMMAIsXDL(unsigned Opc) {
595 const WMMAInstInfo *Info = getWMMAInstInfoHelper(Opc);
596 return Info ? Info->is_wmma_xdl : false;
597}
598
599bool getHasMatrixScale(unsigned Opc) {
600 const WMMAInstInfo *Info = getWMMAInstInfoHelper(Opc);
601 return Info && Info->HasMatrixScale;
602}
603
605 switch (EncodingVal) {
608 return 6;
610 return 4;
613 default:
614 return 8;
615 }
616
617 llvm_unreachable("covered switch over mfma scale formats");
618}
619
621 unsigned BLGP,
622 unsigned F8F8Opcode) {
623 uint8_t SrcANumRegs = mfmaScaleF8F6F4FormatToNumRegs(CBSZ);
624 uint8_t SrcBNumRegs = mfmaScaleF8F6F4FormatToNumRegs(BLGP);
625 return getMFMA_F8F6F4_InstWithNumRegs(SrcANumRegs, SrcBNumRegs, F8F8Opcode);
626}
627
629 switch (Fmt) {
632 return 16;
635 return 12;
637 return 8;
638 }
639
640 llvm_unreachable("covered switch over wmma scale formats");
641}
642
644 unsigned FmtB,
645 unsigned F8F8Opcode) {
646 uint8_t SrcANumRegs = wmmaScaleF8F6F4FormatToNumRegs(FmtA);
647 uint8_t SrcBNumRegs = wmmaScaleF8F6F4FormatToNumRegs(FmtB);
648 return getMFMA_F8F6F4_InstWithNumRegs(SrcANumRegs, SrcBNumRegs, F8F8Opcode);
649}
650
652 if (ST.hasFeature(AMDGPU::FeatureGFX13Insts))
654 if (ST.hasFeature(AMDGPU::FeatureGFX1250Insts))
656 if (ST.hasFeature(AMDGPU::FeatureGFX12Insts))
658 if (ST.hasFeature(AMDGPU::FeatureGFX11_7Insts))
660 if (ST.hasFeature(AMDGPU::FeatureGFX11Insts))
662 llvm_unreachable("Subtarget generation does not support VOPD!");
663}
664
665static constexpr unsigned getVOPDXYKey(unsigned VOPDOp, unsigned Subtarget,
666 bool VOPD3) {
667 return (VOPDOp << 5) | (Subtarget << 1) | (VOPD3 ? 1u : 0u);
668}
669
670// TODO: Ideally, the table should be emitted by the TableGen backend, however
671// this is currently not supported, so the direct lookup table is generated
672// manually here.
673constexpr unsigned VOPDXYKeyBits = 11;
674static constexpr std::array<CanBeVOPD, 1 << VOPDXYKeyBits> buildVOPDXYLookup() {
675 std::array<CanBeVOPD, 1 << VOPDXYKeyBits> Table{};
676 for (auto &E : Table)
677 E = {false, false};
678 for (const auto &E : VOPDXTable)
679 Table[getVOPDXYKey(E.VOPDOp, E.Subtarget, E.VOPD3)].X = true;
680 for (const auto &E : VOPDYTable)
681 Table[getVOPDXYKey(E.VOPDOp, E.Subtarget, E.VOPD3)].Y = true;
682 return Table;
683}
684
686
687CanBeVOPD getCanBeVOPD(unsigned Opc, unsigned EncodingFamily, bool VOPD3) {
688 bool IsConvertibleToBitOp = VOPD3 ? getBitOp2(Opc) : 0;
689 Opc = IsConvertibleToBitOp ? (unsigned)AMDGPU::V_BITOP3_B32_e64 : Opc;
690 // Normalize through VOPDComponentTable so that e32 and e64 variants
691 // of the same logical opcode all share a single entry.
692 const VOPDComponentInfo *Info = getVOPDComponentHelper(Opc);
693 if (!Info)
694 return {false, false};
695 return VOPDXYLookup[getVOPDXYKey(Info->VOPDOp, EncodingFamily, VOPD3)];
696}
697
698unsigned getVOPDOpcode(unsigned Opc, bool VOPD3) {
699 bool IsConvertibleToBitOp = VOPD3 ? getBitOp2(Opc) : 0;
700 Opc = IsConvertibleToBitOp ? (unsigned)AMDGPU::V_BITOP3_B32_e64 : Opc;
701 const VOPDComponentInfo *Info = getVOPDComponentHelper(Opc);
702 return Info ? Info->VOPDOp : ~0u;
703}
704
705bool isVOPD(unsigned Opc) {
706 return AMDGPU::hasNamedOperand(Opc, AMDGPU::OpName::src0X);
707}
708
709bool isMAC(unsigned Opc) {
710 return Opc == AMDGPU::V_MAC_F32_e64_gfx6_gfx7 ||
711 Opc == AMDGPU::V_MAC_F32_e64_gfx10 ||
712 Opc == AMDGPU::V_MAC_F32_e64_vi ||
713 Opc == AMDGPU::V_MAC_LEGACY_F32_e64_gfx6_gfx7 ||
714 Opc == AMDGPU::V_MAC_LEGACY_F32_e64_gfx10 ||
715 Opc == AMDGPU::V_MAC_F16_e64_vi ||
716 Opc == AMDGPU::V_FMAC_F64_e64_gfx90a ||
717 Opc == AMDGPU::V_FMAC_F64_e64_gfx12 ||
718 Opc == AMDGPU::V_FMAC_F64_e64_gfx13 ||
719 Opc == AMDGPU::V_FMAC_F32_e64_gfx10 ||
720 Opc == AMDGPU::V_FMAC_F32_e64_gfx11 ||
721 Opc == AMDGPU::V_FMAC_F32_e64_gfx12 ||
722 Opc == AMDGPU::V_FMAC_F32_e64_gfx13 ||
723 Opc == AMDGPU::V_FMAC_F32_e64_vi ||
724 Opc == AMDGPU::V_FMAC_LEGACY_F32_e64_gfx10 ||
725 Opc == AMDGPU::V_FMAC_DX9_ZERO_F32_e64_gfx11 ||
726 Opc == AMDGPU::V_FMAC_F16_e64_gfx10 ||
727 Opc == AMDGPU::V_FMAC_F16_t16_e64_gfx11 ||
728 Opc == AMDGPU::V_FMAC_F16_fake16_e64_gfx11 ||
729 Opc == AMDGPU::V_FMAC_F16_t16_e64_gfx12 ||
730 Opc == AMDGPU::V_FMAC_F16_fake16_e64_gfx12 ||
731 Opc == AMDGPU::V_FMAC_F16_t16_e64_gfx13 ||
732 Opc == AMDGPU::V_FMAC_F16_fake16_e64_gfx13 ||
733 Opc == AMDGPU::V_DOT2C_F32_F16_e64_vi ||
734 Opc == AMDGPU::V_DOT2C_F32_BF16_e64_vi ||
735 Opc == AMDGPU::V_DOT2C_I32_I16_e64_vi ||
736 Opc == AMDGPU::V_DOT4C_I32_I8_e64_vi ||
737 Opc == AMDGPU::V_DOT8C_I32_I4_e64_vi;
738}
739
740bool isPermlane16(unsigned Opc) {
741 return Opc == AMDGPU::V_PERMLANE16_B32_gfx10 ||
742 Opc == AMDGPU::V_PERMLANEX16_B32_gfx10 ||
743 Opc == AMDGPU::V_PERMLANE16_B32_e64_gfx11 ||
744 Opc == AMDGPU::V_PERMLANEX16_B32_e64_gfx11 ||
745 Opc == AMDGPU::V_PERMLANE16_B32_e64_gfx12 ||
746 Opc == AMDGPU::V_PERMLANE16_B32_e64_gfx13 ||
747 Opc == AMDGPU::V_PERMLANEX16_B32_e64_gfx12 ||
748 Opc == AMDGPU::V_PERMLANEX16_B32_e64_gfx13 ||
749 Opc == AMDGPU::V_PERMLANE16_VAR_B32_e64_gfx12 ||
750 Opc == AMDGPU::V_PERMLANE16_VAR_B32_e64_gfx13 ||
751 Opc == AMDGPU::V_PERMLANEX16_VAR_B32_e64_gfx12 ||
752 Opc == AMDGPU::V_PERMLANEX16_VAR_B32_e64_gfx13;
753}
754
756 return Opc == AMDGPU::V_CVT_F32_BF8_e64_gfx12 ||
757 Opc == AMDGPU::V_CVT_F32_FP8_e64_gfx12 ||
758 Opc == AMDGPU::V_CVT_F32_BF8_e64_dpp_gfx12 ||
759 Opc == AMDGPU::V_CVT_F32_FP8_e64_dpp_gfx12 ||
760 Opc == AMDGPU::V_CVT_F32_BF8_e64_dpp8_gfx12 ||
761 Opc == AMDGPU::V_CVT_F32_FP8_e64_dpp8_gfx12 ||
762 Opc == AMDGPU::V_CVT_PK_F32_BF8_fake16_e64_gfx12 ||
763 Opc == AMDGPU::V_CVT_PK_F32_FP8_fake16_e64_gfx12 ||
764 Opc == AMDGPU::V_CVT_PK_F32_BF8_t16_e64_gfx12 ||
765 Opc == AMDGPU::V_CVT_PK_F32_FP8_t16_e64_gfx12;
766}
767
768bool isGenericAtomic(unsigned Opc) {
769 return Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_SWAP ||
770 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_ADD ||
771 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_SUB ||
772 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_SMIN ||
773 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_UMIN ||
774 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_SMAX ||
775 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_UMAX ||
776 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_AND ||
777 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_OR ||
778 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_XOR ||
779 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_INC ||
780 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_DEC ||
781 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_FADD ||
782 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_FMIN ||
783 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_FMAX ||
784 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_CMPSWAP ||
785 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_SUB_CLAMP_U32 ||
786 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_COND_SUB_U32 ||
787 Opc == AMDGPU::G_AMDGPU_ATOMIC_CMPXCHG;
788}
789
790bool isAsyncStore(unsigned Opc) {
791 return Opc == GLOBAL_STORE_ASYNC_FROM_LDS_B8_gfx1250 ||
792 Opc == GLOBAL_STORE_ASYNC_FROM_LDS_B32_gfx1250 ||
793 Opc == GLOBAL_STORE_ASYNC_FROM_LDS_B64_gfx1250 ||
794 Opc == GLOBAL_STORE_ASYNC_FROM_LDS_B128_gfx1250 ||
795 Opc == GLOBAL_STORE_ASYNC_FROM_LDS_B8_SADDR_gfx1250 ||
796 Opc == GLOBAL_STORE_ASYNC_FROM_LDS_B32_SADDR_gfx1250 ||
797 Opc == GLOBAL_STORE_ASYNC_FROM_LDS_B64_SADDR_gfx1250 ||
798 Opc == GLOBAL_STORE_ASYNC_FROM_LDS_B128_SADDR_gfx1250;
799}
800
801bool isTensorStore(unsigned Opc) {
802 return Opc == TENSOR_STORE_FROM_LDS_d2_gfx1250 ||
803 Opc == TENSOR_STORE_FROM_LDS_d4_gfx1250;
804}
805
806unsigned getTemporalHintType(const MCInstrDesc TID) {
809 unsigned Opc = TID.getOpcode();
810 // Async and Tensor store should have the temporal hint type of TH_TYPE_STORE
811 if (TID.mayStore() &&
812 (isAsyncStore(Opc) || isTensorStore(Opc) || !TID.mayLoad()))
813 return CPol::TH_TYPE_STORE;
814
815 // This will default to returning TH_TYPE_LOAD when neither MayStore nor
816 // MayLoad flag is present which is the case with instructions like
817 // image_get_resinfo.
818 return CPol::TH_TYPE_LOAD;
819}
820
821bool isTrue16Inst(unsigned Opc) {
822 const VOPTrue16Info *Info = getTrue16OpcodeHelper(Opc);
823 return Info && Info->IsTrue16;
824}
825
827 const FP4FP8DstByteSelInfo *Info = getFP4FP8DstByteSelHelper(Opc);
828 if (!Info)
829 return FPType::None;
830 if (Info->HasFP8DstByteSel)
831 return FPType::FP8;
832 if (Info->HasFP4DstByteSel)
833 return FPType::FP4;
834
835 return FPType::None;
836}
837
838bool isDPMACCInstruction(unsigned Opc) {
839 const DPMACCInstructionInfo *Info = getDPMACCInstructionHelper(Opc);
840 return Info && Info->IsDPMACCInstruction;
841}
842
843unsigned mapWMMA2AddrTo3AddrOpcode(unsigned Opc) {
844 const WMMAOpcodeMappingInfo *Info = getWMMAMappingInfoFrom2AddrOpcode(Opc);
845 return Info ? Info->Opcode3Addr : ~0u;
846}
847
848unsigned mapWMMA3AddrTo2AddrOpcode(unsigned Opc) {
849 const WMMAOpcodeMappingInfo *Info = getWMMAMappingInfoFrom3AddrOpcode(Opc);
850 return Info ? Info->Opcode2Addr : ~0u;
851}
852
853// Wrapper for Tablegen'd function. enum Subtarget is not defined in any
854// header files, so we need to wrap it in a function that takes unsigned
855// instead.
856int32_t getMCOpcode(uint32_t Opcode, unsigned Gen) {
857 return getMCOpcodeGen(Opcode, static_cast<Subtarget>(Gen));
858}
859
860unsigned getBitOp2(unsigned Opc) {
861 switch (Opc) {
862 default:
863 return 0;
864 case AMDGPU::V_AND_B32_e32:
865 return 0x40;
866 case AMDGPU::V_OR_B32_e32:
867 return 0x54;
868 case AMDGPU::V_XOR_B32_e32:
869 return 0x14;
870 case AMDGPU::V_XNOR_B32_e32:
871 return 0x41;
872 }
873}
874
875int getVOPDFull(unsigned OpX, unsigned OpY, unsigned EncodingFamily,
876 bool VOPD3) {
877 bool IsConvertibleToBitOp = VOPD3 ? getBitOp2(OpY) : 0;
878 OpY = IsConvertibleToBitOp ? (unsigned)AMDGPU::V_BITOP3_B32_e64 : OpY;
879 const VOPDInfo *Info =
880 getVOPDInfoFromComponentOpcodes(OpX, OpY, EncodingFamily, VOPD3);
881 return Info ? Info->Opcode : -1;
882}
883
884std::pair<unsigned, unsigned> getVOPDComponents(unsigned VOPDOpcode) {
885 const VOPDInfo *Info = getVOPDOpcodeHelper(VOPDOpcode);
886 assert(Info);
887 const auto *OpX = getVOPDBaseFromComponent(Info->OpX);
888 const auto *OpY = getVOPDBaseFromComponent(Info->OpY);
889 assert(OpX && OpY);
890 return {OpX->BaseVOP, OpY->BaseVOP};
891}
892
893namespace VOPD {
894
895ComponentProps::ComponentProps(const MCInstrDesc &OpDesc, bool VOP3Layout) {
897
900 auto TiedIdx = OpDesc.getOperandConstraint(Component::SRC2, MCOI::TIED_TO);
901 assert(TiedIdx == -1 || TiedIdx == Component::DST);
902 HasSrc2Acc = TiedIdx != -1;
903 Opcode = OpDesc.getOpcode();
904
905 IsVOP3 = VOP3Layout || (OpDesc.TSFlags & SIInstrFlags::VOP3);
906 SrcOperandsNum = AMDGPU::hasNamedOperand(Opcode, AMDGPU::OpName::src2) ? 3
907 : AMDGPU::hasNamedOperand(Opcode, AMDGPU::OpName::imm) ? 3
908 : AMDGPU::hasNamedOperand(Opcode, AMDGPU::OpName::src1) ? 2
909 : 1;
910 assert(SrcOperandsNum <= Component::MAX_SRC_NUM);
911
912 if (Opcode == AMDGPU::V_CNDMASK_B32_e32 ||
913 Opcode == AMDGPU::V_CNDMASK_B32_e64) {
914 // CNDMASK is an awkward exception, it has FP modifiers, but not FP
915 // operands.
916 NumVOPD3Mods = 2;
917 if (IsVOP3)
918 SrcOperandsNum = 3;
919 } else if (isSISrcFPOperand(OpDesc,
920 getNamedOperandIdx(Opcode, OpName::src0))) {
921 // All FP VOPD instructions have Neg modifiers for all operands except
922 // for tied src2.
923 NumVOPD3Mods = SrcOperandsNum;
924 if (HasSrc2Acc)
925 --NumVOPD3Mods;
926 }
927
928 if (OpDesc.TSFlags & SIInstrFlags::VOP3)
929 return;
930
931 auto OperandsNum = OpDesc.getNumOperands();
932 unsigned CompOprIdx;
933 for (CompOprIdx = Component::SRC1; CompOprIdx < OperandsNum; ++CompOprIdx) {
934 if (OpDesc.operands()[CompOprIdx].OperandType == AMDGPU::OPERAND_KIMM32) {
935 MandatoryLiteralIdx = CompOprIdx;
936 break;
937 }
938 }
939}
940
942 return getNamedOperandIdx(Opcode, OpName::bitop3);
943}
944
945unsigned ComponentInfo::getIndexInParsedOperands(unsigned CompOprIdx) const {
946 assert(CompOprIdx < Component::MAX_OPR_NUM);
947
948 if (CompOprIdx == Component::DST)
950
951 auto CompSrcIdx = CompOprIdx - Component::DST_NUM;
952 if (CompSrcIdx < getCompParsedSrcOperandsNum())
953 return getIndexOfSrcInParsedOperands(CompSrcIdx);
954
955 // The specified operand does not exist.
956 return 0;
957}
958
960 std::function<MCRegister(unsigned, unsigned)> GetRegIdx,
961 const MCRegisterInfo &MRI, bool SkipSrc, bool AllowSameVGPR,
962 bool VOPD3) const {
963
964 auto OpXRegs = getRegIndices(ComponentIndex::X, GetRegIdx,
965 CompInfo[ComponentIndex::X].isVOP3());
966 auto OpYRegs = getRegIndices(ComponentIndex::Y, GetRegIdx,
967 CompInfo[ComponentIndex::Y].isVOP3());
968
969 const auto banksOverlap = [&MRI](MCRegister X, MCRegister Y,
970 unsigned BanksMask) -> bool {
971 MCRegister BaseX = MRI.getSubReg(X, AMDGPU::sub0);
972 MCRegister BaseY = MRI.getSubReg(Y, AMDGPU::sub0);
973 if (!BaseX)
974 BaseX = X;
975 if (!BaseY)
976 BaseY = Y;
977 if ((BaseX.id() & BanksMask) == (BaseY.id() & BanksMask))
978 return true;
979 if (BaseX != X /* This is 64-bit register */ &&
980 ((BaseX.id() + 1) & BanksMask) == (BaseY.id() & BanksMask))
981 return true;
982 if (BaseY != Y &&
983 (BaseX.id() & BanksMask) == ((BaseY.id() + 1) & BanksMask))
984 return true;
985
986 // If both are 64-bit bank conflict will be detected yet while checking
987 // the first subreg.
988 return false;
989 };
990
991 unsigned CompOprIdx;
992 for (CompOprIdx = 0; CompOprIdx < Component::MAX_OPR_NUM; ++CompOprIdx) {
993 unsigned BanksMasks = VOPD3 ? VOPD3_VGPR_BANK_MASKS[CompOprIdx]
994 : VOPD_VGPR_BANK_MASKS[CompOprIdx];
995 if (!OpXRegs[CompOprIdx] || !OpYRegs[CompOprIdx])
996 continue;
997
998 if (getVGPREncodingMSBs(OpXRegs[CompOprIdx], MRI) !=
999 getVGPREncodingMSBs(OpYRegs[CompOprIdx], MRI))
1000 return CompOprIdx;
1001
1002 if (SkipSrc && CompOprIdx >= Component::DST_NUM)
1003 continue;
1004
1005 if (CompOprIdx < Component::DST_NUM) {
1006 // Even if we do not check vdst parity, vdst operands still shall not
1007 // overlap.
1008 if (MRI.regsOverlap(OpXRegs[CompOprIdx], OpYRegs[CompOprIdx]))
1009 return CompOprIdx;
1010 if (VOPD3) // No need to check dst parity.
1011 continue;
1012 }
1013
1014 if (banksOverlap(OpXRegs[CompOprIdx], OpYRegs[CompOprIdx], BanksMasks) &&
1015 (!AllowSameVGPR || CompOprIdx < Component::DST_NUM ||
1016 OpXRegs[CompOprIdx] != OpYRegs[CompOprIdx]))
1017 return CompOprIdx;
1018 }
1019
1020 return {};
1021}
1022
1023// Return an array of VGPR registers [DST,SRC0,SRC1,SRC2] used
1024// by the specified component. If an operand is unused
1025// or is not a VGPR, the corresponding value is 0.
1026//
1027// GetRegIdx(Component, MCOperandIdx) must return a VGPR register index
1028// for the specified component and MC operand. The callback must return 0
1029// if the operand is not a register or not a VGPR.
1031InstInfo::getRegIndices(unsigned CompIdx,
1032 std::function<MCRegister(unsigned, unsigned)> GetRegIdx,
1033 bool VOPD3) const {
1034 assert(CompIdx < COMPONENTS_NUM);
1035
1036 const auto &Comp = CompInfo[CompIdx];
1038
1039 RegIndices[DST] = GetRegIdx(CompIdx, Comp.getIndexOfDstInMCOperands());
1040
1041 for (unsigned CompOprIdx : {SRC0, SRC1, SRC2}) {
1042 unsigned CompSrcIdx = CompOprIdx - DST_NUM;
1043 RegIndices[CompOprIdx] =
1044 Comp.hasRegSrcOperand(CompSrcIdx)
1045 ? GetRegIdx(CompIdx,
1046 Comp.getIndexOfSrcInMCOperands(CompSrcIdx, VOPD3))
1047 : MCRegister();
1048 }
1049 return RegIndices;
1050}
1051
1052} // namespace VOPD
1053
1055 return VOPD::InstInfo(OpX, OpY);
1056}
1057
1059 const MCInstrInfo *InstrInfo) {
1060 auto [OpX, OpY] = getVOPDComponents(VOPDOpcode);
1061 const auto &OpXDesc = InstrInfo->get(OpX);
1062 const auto &OpYDesc = InstrInfo->get(OpY);
1063 bool VOPD3 = InstrInfo->get(VOPDOpcode).TSFlags & SIInstrFlags::VOPD3;
1065 VOPD::ComponentInfo OpYInfo(OpYDesc, OpXInfo, VOPD3);
1066 return VOPD::InstInfo(OpXInfo, OpYInfo);
1067}
1068
1069namespace IsaInfo {
1070
1072 : STI(STI), XnackSetting(TargetIDSetting::Any),
1073 SramEccSetting(TargetIDSetting::Any) {
1074 if (!STI.getFeatureBits().test(FeatureSupportsXNACK))
1075 XnackSetting = TargetIDSetting::Unsupported;
1076 if (!STI.getFeatureBits().test(FeatureSupportsSRAMECC))
1077 SramEccSetting = TargetIDSetting::Unsupported;
1078}
1079
1081 // Check if xnack or sramecc is explicitly enabled or disabled. In the
1082 // absence of the target features we assume we must generate code that can run
1083 // in any environment.
1084 SubtargetFeatures Features(FS);
1085 std::optional<bool> XnackRequested;
1086 std::optional<bool> SramEccRequested;
1087
1088 for (const std::string &Feature : Features.getFeatures()) {
1089 if (Feature == "+xnack")
1090 XnackRequested = true;
1091 else if (Feature == "-xnack")
1092 XnackRequested = false;
1093 else if (Feature == "+sramecc")
1094 SramEccRequested = true;
1095 else if (Feature == "-sramecc")
1096 SramEccRequested = false;
1097 }
1098
1099 bool XnackSupported = isXnackSupported();
1100 bool SramEccSupported = isSramEccSupported();
1101
1102 if (XnackRequested) {
1103 if (XnackSupported) {
1104 XnackSetting =
1105 *XnackRequested ? TargetIDSetting::On : TargetIDSetting::Off;
1106 } else {
1107 // If a specific xnack setting was requested and this GPU does not support
1108 // xnack emit a warning. Setting will remain set to "Unsupported".
1109 if (*XnackRequested) {
1110 errs() << "warning: xnack 'On' was requested for a processor that does "
1111 "not support it!\n";
1112 } else {
1113 errs() << "warning: xnack 'Off' was requested for a processor that "
1114 "does not support it!\n";
1115 }
1116 }
1117 }
1118
1119 if (SramEccRequested) {
1120 if (SramEccSupported) {
1121 SramEccSetting =
1122 *SramEccRequested ? TargetIDSetting::On : TargetIDSetting::Off;
1123 } else {
1124 // If a specific sramecc setting was requested and this GPU does not
1125 // support sramecc emit a warning. Setting will remain set to
1126 // "Unsupported".
1127 if (*SramEccRequested) {
1128 errs() << "warning: sramecc 'On' was requested for a processor that "
1129 "does not support it!\n";
1130 } else {
1131 errs() << "warning: sramecc 'Off' was requested for a processor that "
1132 "does not support it!\n";
1133 }
1134 }
1135 }
1136}
1137
1138static TargetIDSetting
1140 if (FeatureString.ends_with("-"))
1141 return TargetIDSetting::Off;
1142 if (FeatureString.ends_with("+"))
1143 return TargetIDSetting::On;
1144
1145 llvm_unreachable("Malformed feature string");
1146}
1147
1149 SmallVector<StringRef, 3> TargetIDSplit;
1150 TargetID.split(TargetIDSplit, ':');
1151
1152 for (const auto &FeatureString : TargetIDSplit) {
1153 if (FeatureString.starts_with("xnack"))
1154 XnackSetting = getTargetIDSettingFromFeatureString(FeatureString);
1155 if (FeatureString.starts_with("sramecc"))
1156 SramEccSetting = getTargetIDSettingFromFeatureString(FeatureString);
1157 }
1158}
1159
1160void AMDGPUTargetID::print(raw_ostream &StreamRep) const {
1161 const Triple &TargetTriple = STI.getTargetTriple();
1162 auto Version = getIsaVersion(STI.getCPU());
1163
1164 StreamRep << TargetTriple.getArchName() << '-' << TargetTriple.getVendorName()
1165 << '-' << TargetTriple.getOSName() << '-'
1166 << TargetTriple.getEnvironmentName() << '-';
1167
1168 std::string Processor;
1169 // TODO: Following else statement is present here because we used various
1170 // alias names for GPUs up until GFX9 (e.g. 'fiji' is same as 'gfx803').
1171 // Remove once all aliases are removed from GCNProcessors.td.
1172 if (Version.Major >= 9)
1173 Processor = STI.getCPU().str();
1174 else
1175 Processor = (Twine("gfx") + Twine(Version.Major) + Twine(Version.Minor) +
1176 Twine(Version.Stepping))
1177 .str();
1178
1179 std::string Features;
1180 if (TargetTriple.getOS() == Triple::AMDHSA) {
1181 // sramecc.
1183 Features += ":sramecc-";
1185 Features += ":sramecc+";
1186 // xnack.
1188 Features += ":xnack-";
1190 Features += ":xnack+";
1191 }
1192
1193 StreamRep << Processor << Features;
1194}
1195
1196std::string AMDGPUTargetID::toString() const {
1197 std::string Str;
1198 raw_string_ostream OS(Str);
1199 OS << *this;
1200 return Str;
1201}
1202
1204 if (STI.getFeatureBits().test(FeatureInstCacheLineSize128))
1205 return 128;
1206 if (STI.getFeatureBits().test(FeatureInstCacheLineSize64))
1207 return 64;
1208 return 64;
1209}
1210
1211unsigned getWavefrontSize(const MCSubtargetInfo &STI) {
1212 if (STI.getFeatureBits().test(FeatureWavefrontSize16))
1213 return 16;
1214 if (STI.getFeatureBits().test(FeatureWavefrontSize32))
1215 return 32;
1216
1217 return 64;
1218}
1219
1221 unsigned BytesPerCU = getAddressableLocalMemorySize(STI);
1222
1223 // "Per CU" really means "per whatever functional block the waves of a
1224 // workgroup must share". So the effective local memory size is doubled in
1225 // WGP mode on gfx10.
1226 if (isGFX10Plus(STI) && !STI.getFeatureBits().test(FeatureCuMode))
1227 BytesPerCU *= 2;
1228
1229 return BytesPerCU;
1230}
1231
1233 if (STI.getFeatureBits().test(FeatureAddressableLocalMemorySize32768))
1234 return 32768;
1235 if (STI.getFeatureBits().test(FeatureAddressableLocalMemorySize65536))
1236 return 65536;
1237 if (STI.getFeatureBits().test(FeatureAddressableLocalMemorySize163840))
1238 return 163840;
1239 if (STI.getFeatureBits().test(FeatureAddressableLocalMemorySize327680))
1240 return 327680;
1241 return 32768;
1242}
1243
1244unsigned getEUsPerCU(const MCSubtargetInfo &STI) {
1245 // "Per CU" really means "per whatever functional block the waves of a
1246 // workgroup must share".
1247
1248 // GFX12.5 only supports CU mode, which contains four SIMDs.
1249 if (isGFX1250(STI)) {
1250 assert(STI.getFeatureBits().test(FeatureCuMode));
1251 return 4;
1252 }
1253
1254 // For gfx10 in CU mode the functional block is the CU, which contains
1255 // two SIMDs.
1256 if (isGFX10Plus(STI) && STI.getFeatureBits().test(FeatureCuMode))
1257 return 2;
1258
1259 // Pre-gfx10 a CU contains four SIMDs. For gfx10 in WGP mode the WGP
1260 // contains two CUs, so a total of four SIMDs.
1261 return 4;
1262}
1263
1265 unsigned FlatWorkGroupSize) {
1266 assert(FlatWorkGroupSize != 0);
1267 if (!STI.getTargetTriple().isAMDGCN())
1268 return 8;
1269 unsigned MaxWaves = getMaxWavesPerEU(STI) * getEUsPerCU(STI);
1270 unsigned N = getWavesPerWorkGroup(STI, FlatWorkGroupSize);
1271 if (N == 1) {
1272 // Single-wave workgroups don't consume barrier resources.
1273 return MaxWaves;
1274 }
1275
1276 unsigned MaxBarriers = 16;
1277 if (isGFX10Plus(STI) && !STI.getFeatureBits().test(FeatureCuMode))
1278 MaxBarriers = 32;
1279
1280 return std::min(MaxWaves / N, MaxBarriers);
1281}
1282
1283unsigned getMinWavesPerEU(const MCSubtargetInfo &STI) { return 1; }
1284
1285unsigned getMaxWavesPerEU(const MCSubtargetInfo &STI) {
1286 // FIXME: Need to take scratch memory into account.
1287 if (isGFX90A(STI))
1288 return 8;
1289 if (!isGFX10Plus(STI))
1290 return 10;
1291 return hasGFX10_3Insts(STI) ? 16 : 20;
1292}
1293
1295 unsigned FlatWorkGroupSize) {
1296 return divideCeil(getWavesPerWorkGroup(STI, FlatWorkGroupSize),
1297 getEUsPerCU(STI));
1298}
1299
1300unsigned getMinFlatWorkGroupSize(const MCSubtargetInfo &STI) { return 1; }
1301
1303 unsigned FlatWorkGroupSize) {
1304 return divideCeil(FlatWorkGroupSize, getWavefrontSize(STI));
1305}
1306
1309 if (Version.Major >= 10)
1310 return getAddressableNumSGPRs(STI);
1311 if (Version.Major >= 8)
1312 return 16;
1313 return 8;
1314}
1315
1316unsigned getSGPREncodingGranule(const MCSubtargetInfo &STI) { return 8; }
1317
1318unsigned getTotalNumSGPRs(const MCSubtargetInfo &STI) {
1320 if (Version.Major >= 8)
1321 return 800;
1322 return 512;
1323}
1324
1326 if (STI.getFeatureBits().test(FeatureSGPRInitBug))
1328
1330 if (Version.Major >= 10)
1331 return 106;
1332 if (Version.Major >= 8)
1333 return 102;
1334 return 104;
1335}
1336
1337unsigned getMinNumSGPRs(const MCSubtargetInfo &STI, unsigned WavesPerEU) {
1338 assert(WavesPerEU != 0);
1339
1341 if (Version.Major >= 10)
1342 return 0;
1343
1344 if (WavesPerEU >= getMaxWavesPerEU(STI))
1345 return 0;
1346
1347 unsigned MinNumSGPRs = getTotalNumSGPRs(STI) / (WavesPerEU + 1);
1348 if (STI.getFeatureBits().test(FeatureTrapHandler))
1349 MinNumSGPRs -= std::min(MinNumSGPRs, (unsigned)TRAP_NUM_SGPRS);
1350 MinNumSGPRs = alignDown(MinNumSGPRs, getSGPRAllocGranule(STI)) + 1;
1351 return std::min(MinNumSGPRs, getAddressableNumSGPRs(STI));
1352}
1353
1354unsigned getMaxNumSGPRs(const MCSubtargetInfo &STI, unsigned WavesPerEU,
1355 bool Addressable) {
1356 assert(WavesPerEU != 0);
1357
1358 unsigned AddressableNumSGPRs = getAddressableNumSGPRs(STI);
1360 if (Version.Major >= 10)
1361 return Addressable ? AddressableNumSGPRs : 108;
1362 if (Version.Major >= 8 && !Addressable)
1363 AddressableNumSGPRs = 112;
1364 unsigned MaxNumSGPRs = getTotalNumSGPRs(STI) / WavesPerEU;
1365 if (STI.getFeatureBits().test(FeatureTrapHandler))
1366 MaxNumSGPRs -= std::min(MaxNumSGPRs, (unsigned)TRAP_NUM_SGPRS);
1367 MaxNumSGPRs = alignDown(MaxNumSGPRs, getSGPRAllocGranule(STI));
1368 return std::min(MaxNumSGPRs, AddressableNumSGPRs);
1369}
1370
1371unsigned getNumExtraSGPRs(const MCSubtargetInfo &STI, bool VCCUsed,
1372 bool FlatScrUsed, bool XNACKUsed) {
1373 unsigned ExtraSGPRs = 0;
1374 if (VCCUsed)
1375 ExtraSGPRs = 2;
1376
1378 if (Version.Major >= 10)
1379 return ExtraSGPRs;
1380
1381 if (Version.Major < 8) {
1382 if (FlatScrUsed)
1383 ExtraSGPRs = 4;
1384 } else {
1385 if (XNACKUsed)
1386 ExtraSGPRs = 4;
1387
1388 if (FlatScrUsed ||
1389 STI.getFeatureBits().test(AMDGPU::FeatureArchitectedFlatScratch))
1390 ExtraSGPRs = 6;
1391 }
1392
1393 return ExtraSGPRs;
1394}
1395
1396unsigned getNumExtraSGPRs(const MCSubtargetInfo &STI, bool VCCUsed,
1397 bool FlatScrUsed) {
1398 return getNumExtraSGPRs(STI, VCCUsed, FlatScrUsed,
1399 STI.getFeatureBits().test(AMDGPU::FeatureXNACK));
1400}
1401
1402static unsigned getGranulatedNumRegisterBlocks(unsigned NumRegs,
1403 unsigned Granule) {
1404 return divideCeil(std::max(1u, NumRegs), Granule);
1405}
1406
1407unsigned getNumSGPRBlocks(const MCSubtargetInfo &STI, unsigned NumSGPRs) {
1408 // SGPRBlocks is actual number of SGPR blocks minus 1.
1410 1;
1411}
1412
1414 unsigned DynamicVGPRBlockSize,
1415 std::optional<bool> EnableWavefrontSize32) {
1416 if (STI.getFeatureBits().test(FeatureGFX90AInsts))
1417 return 8;
1418
1419 if (DynamicVGPRBlockSize != 0)
1420 return DynamicVGPRBlockSize;
1421
1422 bool IsWave32 = EnableWavefrontSize32
1423 ? *EnableWavefrontSize32
1424 : STI.getFeatureBits().test(FeatureWavefrontSize32);
1425
1426 if (STI.getFeatureBits().test(Feature1536VGPRs))
1427 return IsWave32 ? 24 : 12;
1428
1429 if (hasGFX10_3Insts(STI))
1430 return IsWave32 ? 16 : 8;
1431
1432 return IsWave32 ? 8 : 4;
1433}
1434
1436 std::optional<bool> EnableWavefrontSize32) {
1437 if (STI.getFeatureBits().test(FeatureGFX90AInsts))
1438 return 8;
1439
1440 bool IsWave32 = EnableWavefrontSize32
1441 ? *EnableWavefrontSize32
1442 : STI.getFeatureBits().test(FeatureWavefrontSize32);
1443
1444 if (STI.getFeatureBits().test(Feature1024AddressableVGPRs))
1445 return IsWave32 ? 16 : 8;
1446
1447 return IsWave32 ? 8 : 4;
1448}
1449
1450unsigned getArchVGPRAllocGranule() { return 4; }
1451
1452unsigned getTotalNumVGPRs(const MCSubtargetInfo &STI) {
1453 if (STI.getFeatureBits().test(FeatureGFX90AInsts))
1454 return 512;
1455 if (!isGFX10Plus(STI))
1456 return 256;
1457 bool IsWave32 = STI.getFeatureBits().test(FeatureWavefrontSize32);
1458 if (STI.getFeatureBits().test(Feature1536VGPRs))
1459 return IsWave32 ? 1536 : 768;
1460 return IsWave32 ? 1024 : 512;
1461}
1462
1464 const auto &Features = STI.getFeatureBits();
1465 if (Features.test(Feature1024AddressableVGPRs))
1466 return Features.test(FeatureWavefrontSize32) ? 1024 : 512;
1467 return 256;
1468}
1469
1471 unsigned DynamicVGPRBlockSize) {
1472 const auto &Features = STI.getFeatureBits();
1473 if (Features.test(FeatureGFX90AInsts))
1474 return 512;
1475
1476 if (DynamicVGPRBlockSize != 0) {
1477 // On GFX12 we can allocate at most MaxDynamicVGPRBlocks blocks of VGPRs.
1478 return MaxDynamicVGPRBlocks *
1479 getVGPRAllocGranule(STI, DynamicVGPRBlockSize);
1480 }
1481 return getAddressableNumArchVGPRs(STI);
1482}
1483
1485 unsigned NumVGPRs,
1486 unsigned DynamicVGPRBlockSize) {
1488 NumVGPRs, getVGPRAllocGranule(STI, DynamicVGPRBlockSize),
1490}
1491
1492unsigned getNumWavesPerEUWithNumVGPRs(unsigned NumVGPRs, unsigned Granule,
1493 unsigned MaxWaves,
1494 unsigned TotalNumVGPRs) {
1495 if (NumVGPRs < Granule)
1496 return MaxWaves;
1497 unsigned RoundedRegs = alignTo(NumVGPRs, Granule);
1498 return std::min(std::max(TotalNumVGPRs / RoundedRegs, 1u), MaxWaves);
1499}
1500
1501unsigned getOccupancyWithNumSGPRs(unsigned SGPRs, unsigned MaxWaves,
1503 if (Gen >= AMDGPUSubtarget::GFX10)
1504 return MaxWaves;
1505
1507 if (SGPRs <= 80)
1508 return 10;
1509 if (SGPRs <= 88)
1510 return 9;
1511 if (SGPRs <= 100)
1512 return 8;
1513 return 7;
1514 }
1515 if (SGPRs <= 48)
1516 return 10;
1517 if (SGPRs <= 56)
1518 return 9;
1519 if (SGPRs <= 64)
1520 return 8;
1521 if (SGPRs <= 72)
1522 return 7;
1523 if (SGPRs <= 80)
1524 return 6;
1525 return 5;
1526}
1527
1528unsigned getMinNumVGPRs(const MCSubtargetInfo &STI, unsigned WavesPerEU,
1529 unsigned DynamicVGPRBlockSize) {
1530 assert(WavesPerEU != 0);
1531
1532 // In dynamic VGPR mode, (static) occupancy does not depend on VGPR usage,
1533 // so getMaxNumVGPRs does not depend on WavesPerEU, and thus we need to return
1534 // zero because there is no nonzero VGPR usage N where going below N
1535 // achieves higher (static) occupancy.
1536 bool DynamicVGPREnabled = (DynamicVGPRBlockSize != 0);
1537 if (DynamicVGPREnabled)
1538 return 0;
1539
1540 unsigned MaxWavesPerEU = getMaxWavesPerEU(STI);
1541 if (WavesPerEU >= MaxWavesPerEU)
1542 return 0;
1543
1544 unsigned TotNumVGPRs = getTotalNumVGPRs(STI);
1545 unsigned AddrsableNumVGPRs =
1546 getAddressableNumVGPRs(STI, DynamicVGPRBlockSize);
1547 unsigned Granule = getVGPRAllocGranule(STI, DynamicVGPRBlockSize);
1548 unsigned MaxNumVGPRs = alignDown(TotNumVGPRs / WavesPerEU, Granule);
1549
1550 if (MaxNumVGPRs == alignDown(TotNumVGPRs / MaxWavesPerEU, Granule))
1551 return 0;
1552
1553 unsigned MinWavesPerEU = getNumWavesPerEUWithNumVGPRs(STI, AddrsableNumVGPRs,
1554 DynamicVGPRBlockSize);
1555 if (WavesPerEU < MinWavesPerEU)
1556 return getMinNumVGPRs(STI, MinWavesPerEU, DynamicVGPRBlockSize);
1557
1558 unsigned MaxNumVGPRsNext = alignDown(TotNumVGPRs / (WavesPerEU + 1), Granule);
1559 unsigned MinNumVGPRs = 1 + std::min(MaxNumVGPRs - Granule, MaxNumVGPRsNext);
1560 return std::min(MinNumVGPRs, AddrsableNumVGPRs);
1561}
1562
1563unsigned getMaxNumVGPRs(const MCSubtargetInfo &STI, unsigned WavesPerEU,
1564 unsigned DynamicVGPRBlockSize) {
1565 assert(WavesPerEU != 0);
1566
1567 // In dynamic VGPR mode, WavesPerEU does not imply a VGPR limit.
1568 bool DynamicVGPREnabled = (DynamicVGPRBlockSize != 0);
1569 unsigned MaxNumVGPRs =
1570 DynamicVGPREnabled
1571 ? getTotalNumVGPRs(STI)
1572 : alignDown(getTotalNumVGPRs(STI) / WavesPerEU,
1573 getVGPRAllocGranule(STI, DynamicVGPRBlockSize));
1574 unsigned AddressableNumVGPRs =
1575 getAddressableNumVGPRs(STI, DynamicVGPRBlockSize);
1576 return std::min(MaxNumVGPRs, AddressableNumVGPRs);
1577}
1578
1579unsigned getEncodedNumVGPRBlocks(const MCSubtargetInfo &STI, unsigned NumVGPRs,
1580 std::optional<bool> EnableWavefrontSize32) {
1582 NumVGPRs, getVGPREncodingGranule(STI, EnableWavefrontSize32)) -
1583 1;
1584}
1585
1587 unsigned NumVGPRs,
1588 unsigned DynamicVGPRBlockSize,
1589 std::optional<bool> EnableWavefrontSize32) {
1591 NumVGPRs,
1592 getVGPRAllocGranule(STI, DynamicVGPRBlockSize, EnableWavefrontSize32));
1593}
1594} // end namespace IsaInfo
1595
1597 const MCSubtargetInfo &STI) {
1599 KernelCode.amd_kernel_code_version_major = 1;
1600 KernelCode.amd_kernel_code_version_minor = 2;
1601 KernelCode.amd_machine_kind = 1; // AMD_MACHINE_KIND_AMDGPU
1602 KernelCode.amd_machine_version_major = Version.Major;
1603 KernelCode.amd_machine_version_minor = Version.Minor;
1604 KernelCode.amd_machine_version_stepping = Version.Stepping;
1606 if (STI.getFeatureBits().test(FeatureWavefrontSize32)) {
1607 KernelCode.wavefront_size = 5;
1609 } else {
1610 KernelCode.wavefront_size = 6;
1611 }
1612
1613 // If the code object does not support indirect functions, then the value must
1614 // be 0xffffffff.
1615 KernelCode.call_convention = -1;
1616
1617 // These alignment values are specified in powers of two, so alignment =
1618 // 2^n. The minimum alignment is 2^4 = 16.
1619 KernelCode.kernarg_segment_alignment = 4;
1620 KernelCode.group_segment_alignment = 4;
1621 KernelCode.private_segment_alignment = 4;
1622
1623 if (Version.Major >= 10) {
1624 KernelCode.compute_pgm_resource_registers |=
1625 S_00B848_WGP_MODE(STI.getFeatureBits().test(FeatureCuMode) ? 0 : 1) |
1627 }
1628}
1629
1632}
1633
1636}
1637
1639 unsigned AS = GV->getAddressSpace();
1640 return AS == AMDGPUAS::CONSTANT_ADDRESS ||
1642}
1643
1645 return TT.getArch() == Triple::r600;
1646}
1647
1648static bool isValidRegPrefix(char C) {
1649 return C == 'v' || C == 's' || C == 'a';
1650}
1651
1652std::tuple<char, unsigned, unsigned> parseAsmPhysRegName(StringRef RegName) {
1653 char Kind = RegName.front();
1654 if (!isValidRegPrefix(Kind))
1655 return {};
1656
1657 RegName = RegName.drop_front();
1658 if (RegName.consume_front("[")) {
1659 unsigned Idx, End;
1660 bool Failed = RegName.consumeInteger(10, Idx);
1661 Failed |= !RegName.consume_front(":");
1662 Failed |= RegName.consumeInteger(10, End);
1663 Failed |= !RegName.consume_back("]");
1664 if (!Failed) {
1665 unsigned NumRegs = End - Idx + 1;
1666 if (NumRegs > 1)
1667 return {Kind, Idx, NumRegs};
1668 }
1669 } else {
1670 unsigned Idx;
1671 bool Failed = RegName.getAsInteger(10, Idx);
1672 if (!Failed)
1673 return {Kind, Idx, 1};
1674 }
1675
1676 return {};
1677}
1678
1679std::tuple<char, unsigned, unsigned>
1681 StringRef RegName = Constraint;
1682 if (!RegName.consume_front("{") || !RegName.consume_back("}"))
1683 return {};
1685}
1686
1687std::pair<unsigned, unsigned>
1689 std::pair<unsigned, unsigned> Default,
1690 bool OnlyFirstRequired) {
1691 if (auto Attr = getIntegerPairAttribute(F, Name, OnlyFirstRequired))
1692 return {Attr->first, Attr->second.value_or(Default.second)};
1693 return Default;
1694}
1695
1696std::optional<std::pair<unsigned, std::optional<unsigned>>>
1698 bool OnlyFirstRequired) {
1699 Attribute A = F.getFnAttribute(Name);
1700 if (!A.isStringAttribute())
1701 return std::nullopt;
1702
1703 LLVMContext &Ctx = F.getContext();
1704 std::pair<unsigned, std::optional<unsigned>> Ints;
1705 std::pair<StringRef, StringRef> Strs = A.getValueAsString().split(',');
1706 if (Strs.first.trim().getAsInteger(0, Ints.first)) {
1707 Ctx.emitError("can't parse first integer attribute " + Name);
1708 return std::nullopt;
1709 }
1710 unsigned Second = 0;
1711 if (Strs.second.trim().getAsInteger(0, Second)) {
1712 if (!OnlyFirstRequired || !Strs.second.trim().empty()) {
1713 Ctx.emitError("can't parse second integer attribute " + Name);
1714 return std::nullopt;
1715 }
1716 } else {
1717 Ints.second = Second;
1718 }
1719
1720 return Ints;
1721}
1722
1724 unsigned Size,
1725 unsigned DefaultVal) {
1726 std::optional<SmallVector<unsigned>> R =
1728 return R.has_value() ? *R : SmallVector<unsigned>(Size, DefaultVal);
1729}
1730
1731std::optional<SmallVector<unsigned>>
1733 assert(Size > 2);
1734 LLVMContext &Ctx = F.getContext();
1735
1736 Attribute A = F.getFnAttribute(Name);
1737 if (!A.isValid())
1738 return std::nullopt;
1739 if (!A.isStringAttribute()) {
1740 Ctx.emitError(Name + " is not a string attribute");
1741 return std::nullopt;
1742 }
1743
1745
1746 StringRef S = A.getValueAsString();
1747 unsigned i = 0;
1748 for (; !S.empty() && i < Size; i++) {
1749 std::pair<StringRef, StringRef> Strs = S.split(',');
1750 unsigned IntVal;
1751 if (Strs.first.trim().getAsInteger(0, IntVal)) {
1752 Ctx.emitError("can't parse integer attribute " + Strs.first + " in " +
1753 Name);
1754 return std::nullopt;
1755 }
1756 Vals[i] = IntVal;
1757 S = Strs.second;
1758 }
1759
1760 if (!S.empty() || i < Size) {
1761 Ctx.emitError("attribute " + Name +
1762 " has incorrect number of integers; expected " +
1764 return std::nullopt;
1765 }
1766 return Vals;
1767}
1768
1769bool hasValueInRangeLikeMetadata(const MDNode &MD, int64_t Val) {
1770 assert((MD.getNumOperands() % 2 == 0) && "invalid number of operands!");
1771 for (unsigned I = 0, E = MD.getNumOperands() / 2; I != E; ++I) {
1772 auto Low =
1773 mdconst::extract<ConstantInt>(MD.getOperand(2 * I + 0))->getValue();
1774 auto High =
1775 mdconst::extract<ConstantInt>(MD.getOperand(2 * I + 1))->getValue();
1776 // There are two types of [A; B) ranges:
1777 // A < B, e.g. [4; 5) which is a range that only includes 4.
1778 // A > B, e.g. [5; 4) which is a range that wraps around and includes
1779 // everything except 4.
1780 if (Low.ult(High)) {
1781 if (Low.ule(Val) && High.ugt(Val))
1782 return true;
1783 } else {
1784 if (Low.uge(Val) && High.ult(Val))
1785 return true;
1786 }
1787 }
1788
1789 return false;
1790}
1791
1793 return (1 << (getVmcntBitWidthLo(Version.Major) +
1794 getVmcntBitWidthHi(Version.Major))) -
1795 1;
1796}
1797
1799 return (1 << getLoadcntBitWidth(Version.Major)) - 1;
1800}
1801
1803 return (1 << getSamplecntBitWidth(Version.Major)) - 1;
1804}
1805
1807 return (1 << getBvhcntBitWidth(Version.Major)) - 1;
1808}
1809
1811 return (1 << getExpcntBitWidth(Version.Major)) - 1;
1812}
1813
1815 return (1 << getLgkmcntBitWidth(Version.Major)) - 1;
1816}
1817
1819 return (1 << getDscntBitWidth(Version.Major)) - 1;
1820}
1821
1823 return (1 << getKmcntBitWidth(Version.Major)) - 1;
1824}
1825
1827 return (1 << getXcntBitWidth(Version.Major, Version.Minor)) - 1;
1828}
1829
1831 return (1 << getAsynccntBitWidth(Version.Major, Version.Minor)) - 1;
1832}
1833
1835 return (1 << getStorecntBitWidth(Version.Major)) - 1;
1836}
1837
1839 bool HasExtendedWaitCounts = IV.Major >= 12;
1840 if (HasExtendedWaitCounts) {
1843 } else {
1846 }
1856}
1857
1859 unsigned VmcntLo = getBitMask(getVmcntBitShiftLo(Version.Major),
1860 getVmcntBitWidthLo(Version.Major));
1861 unsigned Expcnt = getBitMask(getExpcntBitShift(Version.Major),
1862 getExpcntBitWidth(Version.Major));
1863 unsigned Lgkmcnt = getBitMask(getLgkmcntBitShift(Version.Major),
1864 getLgkmcntBitWidth(Version.Major));
1865 unsigned VmcntHi = getBitMask(getVmcntBitShiftHi(Version.Major),
1866 getVmcntBitWidthHi(Version.Major));
1867 return VmcntLo | Expcnt | Lgkmcnt | VmcntHi;
1868}
1869
1870unsigned decodeVmcnt(const IsaVersion &Version, unsigned Waitcnt) {
1871 unsigned VmcntLo = unpackBits(Waitcnt, getVmcntBitShiftLo(Version.Major),
1872 getVmcntBitWidthLo(Version.Major));
1873 unsigned VmcntHi = unpackBits(Waitcnt, getVmcntBitShiftHi(Version.Major),
1874 getVmcntBitWidthHi(Version.Major));
1875 return VmcntLo | VmcntHi << getVmcntBitWidthLo(Version.Major);
1876}
1877
1878unsigned decodeExpcnt(const IsaVersion &Version, unsigned Waitcnt) {
1879 return unpackBits(Waitcnt, getExpcntBitShift(Version.Major),
1880 getExpcntBitWidth(Version.Major));
1881}
1882
1883unsigned decodeLgkmcnt(const IsaVersion &Version, unsigned Waitcnt) {
1884 return unpackBits(Waitcnt, getLgkmcntBitShift(Version.Major),
1885 getLgkmcntBitWidth(Version.Major));
1886}
1887
1888unsigned decodeLoadcnt(const IsaVersion &Version, unsigned Waitcnt) {
1889 return unpackBits(Waitcnt, getLoadcntStorecntBitShift(Version.Major),
1890 getLoadcntBitWidth(Version.Major));
1891}
1892
1893unsigned decodeStorecnt(const IsaVersion &Version, unsigned Waitcnt) {
1894 return unpackBits(Waitcnt, getLoadcntStorecntBitShift(Version.Major),
1895 getStorecntBitWidth(Version.Major));
1896}
1897
1898unsigned decodeDscnt(const IsaVersion &Version, unsigned Waitcnt) {
1899 return unpackBits(Waitcnt, getDscntBitShift(Version.Major),
1900 getDscntBitWidth(Version.Major));
1901}
1902
1903void decodeWaitcnt(const IsaVersion &Version, unsigned Waitcnt, unsigned &Vmcnt,
1904 unsigned &Expcnt, unsigned &Lgkmcnt) {
1905 Vmcnt = decodeVmcnt(Version, Waitcnt);
1906 Expcnt = decodeExpcnt(Version, Waitcnt);
1907 Lgkmcnt = decodeLgkmcnt(Version, Waitcnt);
1908}
1909
1910unsigned encodeVmcnt(const IsaVersion &Version, unsigned Waitcnt,
1911 unsigned Vmcnt) {
1912 Waitcnt = packBits(Vmcnt, Waitcnt, getVmcntBitShiftLo(Version.Major),
1913 getVmcntBitWidthLo(Version.Major));
1914 return packBits(Vmcnt >> getVmcntBitWidthLo(Version.Major), Waitcnt,
1915 getVmcntBitShiftHi(Version.Major),
1916 getVmcntBitWidthHi(Version.Major));
1917}
1918
1919unsigned encodeExpcnt(const IsaVersion &Version, unsigned Waitcnt,
1920 unsigned Expcnt) {
1921 return packBits(Expcnt, Waitcnt, getExpcntBitShift(Version.Major),
1922 getExpcntBitWidth(Version.Major));
1923}
1924
1925unsigned encodeLgkmcnt(const IsaVersion &Version, unsigned Waitcnt,
1926 unsigned Lgkmcnt) {
1927 return packBits(Lgkmcnt, Waitcnt, getLgkmcntBitShift(Version.Major),
1928 getLgkmcntBitWidth(Version.Major));
1929}
1930
1931unsigned encodeWaitcnt(const IsaVersion &Version, unsigned Vmcnt,
1932 unsigned Expcnt, unsigned Lgkmcnt) {
1933 unsigned Waitcnt = getWaitcntBitMask(Version);
1935 Waitcnt = encodeExpcnt(Version, Waitcnt, Expcnt);
1936 Waitcnt = encodeLgkmcnt(Version, Waitcnt, Lgkmcnt);
1937 return Waitcnt;
1938}
1939
1941 bool IsStore) {
1942 unsigned Dscnt = getBitMask(getDscntBitShift(Version.Major),
1943 getDscntBitWidth(Version.Major));
1944 if (IsStore) {
1945 unsigned Storecnt = getBitMask(getLoadcntStorecntBitShift(Version.Major),
1946 getStorecntBitWidth(Version.Major));
1947 return Dscnt | Storecnt;
1948 }
1949 unsigned Loadcnt = getBitMask(getLoadcntStorecntBitShift(Version.Major),
1950 getLoadcntBitWidth(Version.Major));
1951 return Dscnt | Loadcnt;
1952}
1953
1954static unsigned encodeLoadcnt(const IsaVersion &Version, unsigned Waitcnt,
1955 unsigned Loadcnt) {
1956 return packBits(Loadcnt, Waitcnt, getLoadcntStorecntBitShift(Version.Major),
1957 getLoadcntBitWidth(Version.Major));
1958}
1959
1960static unsigned encodeStorecnt(const IsaVersion &Version, unsigned Waitcnt,
1961 unsigned Storecnt) {
1962 return packBits(Storecnt, Waitcnt, getLoadcntStorecntBitShift(Version.Major),
1963 getStorecntBitWidth(Version.Major));
1964}
1965
1966static unsigned encodeDscnt(const IsaVersion &Version, unsigned Waitcnt,
1967 unsigned Dscnt) {
1968 return packBits(Dscnt, Waitcnt, getDscntBitShift(Version.Major),
1969 getDscntBitWidth(Version.Major));
1970}
1971
1972unsigned encodeLoadcntDscnt(const IsaVersion &Version, unsigned Loadcnt,
1973 unsigned Dscnt) {
1974 unsigned Waitcnt = getCombinedCountBitMask(Version, false);
1975 Waitcnt = encodeLoadcnt(Version, Waitcnt, Loadcnt);
1977 return Waitcnt;
1978}
1979
1980unsigned encodeStorecntDscnt(const IsaVersion &Version, unsigned Storecnt,
1981 unsigned Dscnt) {
1982 unsigned Waitcnt = getCombinedCountBitMask(Version, true);
1983 Waitcnt = encodeStorecnt(Version, Waitcnt, Storecnt);
1985 return Waitcnt;
1986}
1987
1988//===----------------------------------------------------------------------===//
1989// Custom Operand Values
1990//===----------------------------------------------------------------------===//
1991
1993 int Size,
1994 const MCSubtargetInfo &STI) {
1995 unsigned Enc = 0;
1996 for (int Idx = 0; Idx < Size; ++Idx) {
1997 const auto &Op = Opr[Idx];
1998 if (Op.isSupported(STI))
1999 Enc |= Op.encode(Op.Default);
2000 }
2001 return Enc;
2002}
2003
2005 int Size, unsigned Code,
2006 bool &HasNonDefaultVal,
2007 const MCSubtargetInfo &STI) {
2008 unsigned UsedOprMask = 0;
2009 HasNonDefaultVal = false;
2010 for (int Idx = 0; Idx < Size; ++Idx) {
2011 const auto &Op = Opr[Idx];
2012 if (!Op.isSupported(STI))
2013 continue;
2014 UsedOprMask |= Op.getMask();
2015 unsigned Val = Op.decode(Code);
2016 if (!Op.isValid(Val))
2017 return false;
2018 HasNonDefaultVal |= (Val != Op.Default);
2019 }
2020 return (Code & ~UsedOprMask) == 0;
2021}
2022
2023static bool decodeCustomOperand(const CustomOperandVal *Opr, int Size,
2024 unsigned Code, int &Idx, StringRef &Name,
2025 unsigned &Val, bool &IsDefault,
2026 const MCSubtargetInfo &STI) {
2027 while (Idx < Size) {
2028 const auto &Op = Opr[Idx++];
2029 if (Op.isSupported(STI)) {
2030 Name = Op.Name;
2031 Val = Op.decode(Code);
2032 IsDefault = (Val == Op.Default);
2033 return true;
2034 }
2035 }
2036
2037 return false;
2038}
2039
2041 int64_t InputVal) {
2042 if (InputVal < 0 || InputVal > Op.Max)
2043 return OPR_VAL_INVALID;
2044 return Op.encode(InputVal);
2045}
2046
2047static int encodeCustomOperand(const CustomOperandVal *Opr, int Size,
2048 const StringRef Name, int64_t InputVal,
2049 unsigned &UsedOprMask,
2050 const MCSubtargetInfo &STI) {
2051 int InvalidId = OPR_ID_UNKNOWN;
2052 for (int Idx = 0; Idx < Size; ++Idx) {
2053 const auto &Op = Opr[Idx];
2054 if (Op.Name == Name) {
2055 if (!Op.isSupported(STI)) {
2056 InvalidId = OPR_ID_UNSUPPORTED;
2057 continue;
2058 }
2059 auto OprMask = Op.getMask();
2060 if (OprMask & UsedOprMask)
2061 return OPR_ID_DUPLICATE;
2062 UsedOprMask |= OprMask;
2063 return encodeCustomOperandVal(Op, InputVal);
2064 }
2065 }
2066 return InvalidId;
2067}
2068
2069//===----------------------------------------------------------------------===//
2070// DepCtr
2071//===----------------------------------------------------------------------===//
2072
2073namespace DepCtr {
2074
2076 static int Default = -1;
2077 if (Default == -1)
2079 return Default;
2080}
2081
2082bool isSymbolicDepCtrEncoding(unsigned Code, bool &HasNonDefaultVal,
2083 const MCSubtargetInfo &STI) {
2085 HasNonDefaultVal, STI);
2086}
2087
2088bool decodeDepCtr(unsigned Code, int &Id, StringRef &Name, unsigned &Val,
2089 bool &IsDefault, const MCSubtargetInfo &STI) {
2090 return decodeCustomOperand(DepCtrInfo, DEP_CTR_SIZE, Code, Id, Name, Val,
2091 IsDefault, STI);
2092}
2093
2094int encodeDepCtr(const StringRef Name, int64_t Val, unsigned &UsedOprMask,
2095 const MCSubtargetInfo &STI) {
2096 return encodeCustomOperand(DepCtrInfo, DEP_CTR_SIZE, Name, Val, UsedOprMask,
2097 STI);
2098}
2099
2100unsigned getVaVdstBitMask() { return (1 << getVaVdstBitWidth()) - 1; }
2101
2102unsigned getVaSdstBitMask() { return (1 << getVaSdstBitWidth()) - 1; }
2103
2104unsigned getVaSsrcBitMask() { return (1 << getVaSsrcBitWidth()) - 1; }
2105
2107 return (1 << getHoldCntWidth(Version.Major, Version.Minor)) - 1;
2108}
2109
2110unsigned getVmVsrcBitMask() { return (1 << getVmVsrcBitWidth()) - 1; }
2111
2112unsigned getVaVccBitMask() { return (1 << getVaVccBitWidth()) - 1; }
2113
2114unsigned getSaSdstBitMask() { return (1 << getSaSdstBitWidth()) - 1; }
2115
2116unsigned decodeFieldVmVsrc(unsigned Encoded) {
2117 return unpackBits(Encoded, getVmVsrcBitShift(), getVmVsrcBitWidth());
2118}
2119
2120unsigned decodeFieldVaVdst(unsigned Encoded) {
2121 return unpackBits(Encoded, getVaVdstBitShift(), getVaVdstBitWidth());
2122}
2123
2124unsigned decodeFieldSaSdst(unsigned Encoded) {
2125 return unpackBits(Encoded, getSaSdstBitShift(), getSaSdstBitWidth());
2126}
2127
2128unsigned decodeFieldVaSdst(unsigned Encoded) {
2129 return unpackBits(Encoded, getVaSdstBitShift(), getVaSdstBitWidth());
2130}
2131
2132unsigned decodeFieldVaVcc(unsigned Encoded) {
2133 return unpackBits(Encoded, getVaVccBitShift(), getVaVccBitWidth());
2134}
2135
2136unsigned decodeFieldVaSsrc(unsigned Encoded) {
2137 return unpackBits(Encoded, getVaSsrcBitShift(), getVaSsrcBitWidth());
2138}
2139
2140unsigned decodeFieldHoldCnt(unsigned Encoded, const IsaVersion &Version) {
2141 return unpackBits(Encoded, getHoldCntBitShift(),
2142 getHoldCntWidth(Version.Major, Version.Minor));
2143}
2144
2145unsigned encodeFieldVmVsrc(unsigned Encoded, unsigned VmVsrc) {
2146 return packBits(VmVsrc, Encoded, getVmVsrcBitShift(), getVmVsrcBitWidth());
2147}
2148
2149unsigned encodeFieldVmVsrc(unsigned VmVsrc, const MCSubtargetInfo &STI) {
2150 unsigned Encoded = getDefaultDepCtrEncoding(STI);
2151 return encodeFieldVmVsrc(Encoded, VmVsrc);
2152}
2153
2154unsigned encodeFieldVaVdst(unsigned Encoded, unsigned VaVdst) {
2155 return packBits(VaVdst, Encoded, getVaVdstBitShift(), getVaVdstBitWidth());
2156}
2157
2158unsigned encodeFieldVaVdst(unsigned VaVdst, const MCSubtargetInfo &STI) {
2159 unsigned Encoded = getDefaultDepCtrEncoding(STI);
2160 return encodeFieldVaVdst(Encoded, VaVdst);
2161}
2162
2163unsigned encodeFieldSaSdst(unsigned Encoded, unsigned SaSdst) {
2164 return packBits(SaSdst, Encoded, getSaSdstBitShift(), getSaSdstBitWidth());
2165}
2166
2167unsigned encodeFieldSaSdst(unsigned SaSdst, const MCSubtargetInfo &STI) {
2168 unsigned Encoded = getDefaultDepCtrEncoding(STI);
2169 return encodeFieldSaSdst(Encoded, SaSdst);
2170}
2171
2172unsigned encodeFieldVaSdst(unsigned Encoded, unsigned VaSdst) {
2173 return packBits(VaSdst, Encoded, getVaSdstBitShift(), getVaSdstBitWidth());
2174}
2175
2176unsigned encodeFieldVaSdst(unsigned VaSdst, const MCSubtargetInfo &STI) {
2177 unsigned Encoded = getDefaultDepCtrEncoding(STI);
2178 return encodeFieldVaSdst(Encoded, VaSdst);
2179}
2180
2181unsigned encodeFieldVaVcc(unsigned Encoded, unsigned VaVcc) {
2182 return packBits(VaVcc, Encoded, getVaVccBitShift(), getVaVccBitWidth());
2183}
2184
2185unsigned encodeFieldVaVcc(unsigned VaVcc, const MCSubtargetInfo &STI) {
2186 unsigned Encoded = getDefaultDepCtrEncoding(STI);
2187 return encodeFieldVaVcc(Encoded, VaVcc);
2188}
2189
2190unsigned encodeFieldVaSsrc(unsigned Encoded, unsigned VaSsrc) {
2191 return packBits(VaSsrc, Encoded, getVaSsrcBitShift(), getVaSsrcBitWidth());
2192}
2193
2194unsigned encodeFieldVaSsrc(unsigned VaSsrc, const MCSubtargetInfo &STI) {
2195 unsigned Encoded = getDefaultDepCtrEncoding(STI);
2196 return encodeFieldVaSsrc(Encoded, VaSsrc);
2197}
2198
2199unsigned encodeFieldHoldCnt(unsigned Encoded, unsigned HoldCnt,
2200 const IsaVersion &Version) {
2201 return packBits(HoldCnt, Encoded, getHoldCntBitShift(),
2202 getHoldCntWidth(Version.Major, Version.Minor));
2203}
2204
2205unsigned encodeFieldHoldCnt(unsigned HoldCnt, const MCSubtargetInfo &STI) {
2206 unsigned Encoded = getDefaultDepCtrEncoding(STI);
2207 return encodeFieldHoldCnt(Encoded, HoldCnt, getIsaVersion(STI.getCPU()));
2208}
2209
2210} // namespace DepCtr
2211
2212//===----------------------------------------------------------------------===//
2213// exp tgt
2214//===----------------------------------------------------------------------===//
2215
2216namespace Exp {
2217
2218struct ExpTgt {
2220 unsigned Tgt;
2221 unsigned MaxIndex;
2222};
2223
2224// clang-format off
2225static constexpr ExpTgt ExpTgtInfo[] = {
2226 {{"null"}, ET_NULL, ET_NULL_MAX_IDX},
2227 {{"mrtz"}, ET_MRTZ, ET_MRTZ_MAX_IDX},
2228 {{"prim"}, ET_PRIM, ET_PRIM_MAX_IDX},
2229 {{"mrt"}, ET_MRT0, ET_MRT_MAX_IDX},
2230 {{"pos"}, ET_POS0, ET_POS_MAX_IDX},
2231 {{"dual_src_blend"},ET_DUAL_SRC_BLEND0, ET_DUAL_SRC_BLEND_MAX_IDX},
2232 {{"param"}, ET_PARAM0, ET_PARAM_MAX_IDX},
2233};
2234// clang-format on
2235
2236bool getTgtName(unsigned Id, StringRef &Name, int &Index) {
2237 for (const ExpTgt &Val : ExpTgtInfo) {
2238 if (Val.Tgt <= Id && Id <= Val.Tgt + Val.MaxIndex) {
2239 Index = (Val.MaxIndex == 0) ? -1 : (Id - Val.Tgt);
2240 Name = Val.Name;
2241 return true;
2242 }
2243 }
2244 return false;
2245}
2246
2247unsigned getTgtId(const StringRef Name) {
2248
2249 for (const ExpTgt &Val : ExpTgtInfo) {
2250 if (Val.MaxIndex == 0 && Name == Val.Name)
2251 return Val.Tgt;
2252
2253 if (Val.MaxIndex > 0 && Name.starts_with(Val.Name)) {
2254 StringRef Suffix = Name.drop_front(Val.Name.size());
2255
2256 unsigned Id;
2257 if (Suffix.getAsInteger(10, Id) || Id > Val.MaxIndex)
2258 return ET_INVALID;
2259
2260 // Disable leading zeroes
2261 if (Suffix.size() > 1 && Suffix[0] == '0')
2262 return ET_INVALID;
2263
2264 return Val.Tgt + Id;
2265 }
2266 }
2267 return ET_INVALID;
2268}
2269
2270bool isSupportedTgtId(unsigned Id, const MCSubtargetInfo &STI) {
2271 switch (Id) {
2272 case ET_NULL:
2273 return !isGFX11Plus(STI);
2274 case ET_POS4:
2275 case ET_PRIM:
2276 return isGFX10Plus(STI);
2277 case ET_DUAL_SRC_BLEND0:
2278 case ET_DUAL_SRC_BLEND1:
2279 return isGFX11Plus(STI);
2280 default:
2281 if (Id >= ET_PARAM0 && Id <= ET_PARAM31)
2282 return !isGFX11Plus(STI) || isGFX13Plus(STI);
2283 return true;
2284 }
2285}
2286
2287} // namespace Exp
2288
2289//===----------------------------------------------------------------------===//
2290// MTBUF Format
2291//===----------------------------------------------------------------------===//
2292
2293namespace MTBUFFormat {
2294
2295int64_t getDfmt(const StringRef Name) {
2296 for (int Id = DFMT_MIN; Id <= DFMT_MAX; ++Id) {
2297 if (Name == DfmtSymbolic[Id])
2298 return Id;
2299 }
2300 return DFMT_UNDEF;
2301}
2302
2304 assert(Id <= DFMT_MAX);
2305 return DfmtSymbolic[Id];
2306}
2307
2309 if (isSI(STI) || isCI(STI))
2310 return NfmtSymbolicSICI;
2311 if (isVI(STI) || isGFX9(STI))
2312 return NfmtSymbolicVI;
2313 return NfmtSymbolicGFX10;
2314}
2315
2316int64_t getNfmt(const StringRef Name, const MCSubtargetInfo &STI) {
2317 const auto *lookupTable = getNfmtLookupTable(STI);
2318 for (int Id = NFMT_MIN; Id <= NFMT_MAX; ++Id) {
2319 if (Name == lookupTable[Id])
2320 return Id;
2321 }
2322 return NFMT_UNDEF;
2323}
2324
2325StringRef getNfmtName(unsigned Id, const MCSubtargetInfo &STI) {
2326 assert(Id <= NFMT_MAX);
2327 return getNfmtLookupTable(STI)[Id];
2328}
2329
2330bool isValidDfmtNfmt(unsigned Id, const MCSubtargetInfo &STI) {
2331 unsigned Dfmt;
2332 unsigned Nfmt;
2333 decodeDfmtNfmt(Id, Dfmt, Nfmt);
2334 return isValidNfmt(Nfmt, STI);
2335}
2336
2337bool isValidNfmt(unsigned Id, const MCSubtargetInfo &STI) {
2338 return !getNfmtName(Id, STI).empty();
2339}
2340
2341int64_t encodeDfmtNfmt(unsigned Dfmt, unsigned Nfmt) {
2342 return (Dfmt << DFMT_SHIFT) | (Nfmt << NFMT_SHIFT);
2343}
2344
2345void decodeDfmtNfmt(unsigned Format, unsigned &Dfmt, unsigned &Nfmt) {
2346 Dfmt = (Format >> DFMT_SHIFT) & DFMT_MASK;
2347 Nfmt = (Format >> NFMT_SHIFT) & NFMT_MASK;
2348}
2349
2350int64_t getUnifiedFormat(const StringRef Name, const MCSubtargetInfo &STI) {
2351 if (isGFX11Plus(STI)) {
2352 for (int Id = UfmtGFX11::UFMT_FIRST; Id <= UfmtGFX11::UFMT_LAST; ++Id) {
2353 if (Name == UfmtSymbolicGFX11[Id])
2354 return Id;
2355 }
2356 } else {
2357 for (int Id = UfmtGFX10::UFMT_FIRST; Id <= UfmtGFX10::UFMT_LAST; ++Id) {
2358 if (Name == UfmtSymbolicGFX10[Id])
2359 return Id;
2360 }
2361 }
2362 return UFMT_UNDEF;
2363}
2364
2366 if (isValidUnifiedFormat(Id, STI))
2367 return isGFX10(STI) ? UfmtSymbolicGFX10[Id] : UfmtSymbolicGFX11[Id];
2368 return "";
2369}
2370
2371bool isValidUnifiedFormat(unsigned Id, const MCSubtargetInfo &STI) {
2372 return isGFX10(STI) ? Id <= UfmtGFX10::UFMT_LAST : Id <= UfmtGFX11::UFMT_LAST;
2373}
2374
2375int64_t convertDfmtNfmt2Ufmt(unsigned Dfmt, unsigned Nfmt,
2376 const MCSubtargetInfo &STI) {
2377 int64_t Fmt = encodeDfmtNfmt(Dfmt, Nfmt);
2378 if (isGFX11Plus(STI)) {
2379 for (int Id = UfmtGFX11::UFMT_FIRST; Id <= UfmtGFX11::UFMT_LAST; ++Id) {
2380 if (Fmt == DfmtNfmt2UFmtGFX11[Id])
2381 return Id;
2382 }
2383 } else {
2384 for (int Id = UfmtGFX10::UFMT_FIRST; Id <= UfmtGFX10::UFMT_LAST; ++Id) {
2385 if (Fmt == DfmtNfmt2UFmtGFX10[Id])
2386 return Id;
2387 }
2388 }
2389 return UFMT_UNDEF;
2390}
2391
2392bool isValidFormatEncoding(unsigned Val, const MCSubtargetInfo &STI) {
2393 return isGFX10Plus(STI) ? (Val <= UFMT_MAX) : (Val <= DFMT_NFMT_MAX);
2394}
2395
2397 if (isGFX10Plus(STI))
2398 return UFMT_DEFAULT;
2399 return DFMT_NFMT_DEFAULT;
2400}
2401
2402} // namespace MTBUFFormat
2403
2404//===----------------------------------------------------------------------===//
2405// SendMsg
2406//===----------------------------------------------------------------------===//
2407
2408namespace SendMsg {
2409
2413
2414bool isValidMsgId(int64_t MsgId, const MCSubtargetInfo &STI) {
2415 return (MsgId & ~(getMsgIdMask(STI))) == 0;
2416}
2417
2418bool isValidMsgOp(int64_t MsgId, int64_t OpId, const MCSubtargetInfo &STI,
2419 bool Strict) {
2420 assert(isValidMsgId(MsgId, STI));
2421
2422 if (!Strict)
2423 return 0 <= OpId && isUInt<OP_WIDTH_>(OpId);
2424
2425 if (msgRequiresOp(MsgId, STI)) {
2426 if (MsgId == ID_GS_PreGFX11 && OpId == OP_GS_NOP)
2427 return false;
2428
2429 return !getMsgOpName(MsgId, OpId, STI).empty();
2430 }
2431
2432 return OpId == OP_NONE_;
2433}
2434
2435bool isValidMsgStream(int64_t MsgId, int64_t OpId, int64_t StreamId,
2436 const MCSubtargetInfo &STI, bool Strict) {
2437 assert(isValidMsgOp(MsgId, OpId, STI, Strict));
2438
2439 if (!Strict)
2441
2442 if (!isGFX11Plus(STI)) {
2443 switch (MsgId) {
2444 case ID_GS_PreGFX11:
2447 return (OpId == OP_GS_NOP)
2450 }
2451 }
2452 return StreamId == STREAM_ID_NONE_;
2453}
2454
2455bool msgRequiresOp(int64_t MsgId, const MCSubtargetInfo &STI) {
2456 return MsgId == ID_SYSMSG ||
2457 (!isGFX11Plus(STI) &&
2458 (MsgId == ID_GS_PreGFX11 || MsgId == ID_GS_DONE_PreGFX11));
2459}
2460
2461bool msgSupportsStream(int64_t MsgId, int64_t OpId,
2462 const MCSubtargetInfo &STI) {
2463 return !isGFX11Plus(STI) &&
2464 (MsgId == ID_GS_PreGFX11 || MsgId == ID_GS_DONE_PreGFX11) &&
2465 OpId != OP_GS_NOP;
2466}
2467
2468void decodeMsg(unsigned Val, uint16_t &MsgId, uint16_t &OpId,
2469 uint16_t &StreamId, const MCSubtargetInfo &STI) {
2470 MsgId = Val & getMsgIdMask(STI);
2471 if (isGFX11Plus(STI)) {
2472 OpId = 0;
2473 StreamId = 0;
2474 } else {
2475 OpId = (Val & OP_MASK_) >> OP_SHIFT_;
2477 }
2478}
2479
2481 return MsgId | (OpId << OP_SHIFT_) | (StreamId << STREAM_ID_SHIFT_);
2482}
2483
2484bool msgDoesNotUseM0(int64_t MsgId, const MCSubtargetInfo &STI) {
2485 // Explicitly list message types that are known to not use m0.
2486 // This is safer than excluding only GS_ALLOC_REQ, in case new message
2487 // types are added in the future that do use m0.
2488 if (isGFX11Plus(STI)) {
2489 switch (MsgId) {
2491 return true;
2492 default:
2493 break;
2494 }
2495 }
2496 switch (MsgId) {
2497 case ID_SAVEWAVE:
2498 case ID_STALL_WAVE_GEN:
2499 case ID_HALT_WAVES:
2500 case ID_ORDERED_PS_DONE:
2502 case ID_GET_DOORBELL:
2503 case ID_GET_DDID:
2504 case ID_SYSMSG:
2505 return true;
2506 default:
2507 return false;
2508 }
2509}
2510
2511} // namespace SendMsg
2512
2513//===----------------------------------------------------------------------===//
2514//
2515//===----------------------------------------------------------------------===//
2516
2518 return F.getFnAttributeAsParsedInteger("InitialPSInputAddr", 0);
2519}
2520
2522 // As a safe default always respond as if PS has color exports.
2523 return F.getFnAttributeAsParsedInteger(
2524 "amdgpu-color-export",
2525 F.getCallingConv() == CallingConv::AMDGPU_PS ? 1 : 0) != 0;
2526}
2527
2529 return F.getFnAttributeAsParsedInteger("amdgpu-depth-export", 0) != 0;
2530}
2531
2533 unsigned BlockSize =
2534 F.getFnAttributeAsParsedInteger("amdgpu-dynamic-vgpr-block-size", 0);
2535
2536 if (BlockSize == 16 || BlockSize == 32)
2537 return BlockSize;
2538
2539 return 0;
2540}
2541
2542bool hasXNACK(const MCSubtargetInfo &STI) {
2543 return STI.hasFeature(AMDGPU::FeatureXNACK);
2544}
2545
2547 return STI.hasFeature(AMDGPU::FeatureMIMG_R128) &&
2548 !STI.hasFeature(AMDGPU::FeatureR128A16);
2549}
2550
2551bool hasA16(const MCSubtargetInfo &STI) {
2552 return STI.hasFeature(AMDGPU::FeatureA16);
2553}
2554
2555bool hasG16(const MCSubtargetInfo &STI) {
2556 return STI.hasFeature(AMDGPU::FeatureG16);
2557}
2558
2560 return !STI.hasFeature(AMDGPU::FeatureUnpackedD16VMem) && !isCI(STI) &&
2561 !isSI(STI);
2562}
2563
2564bool hasGDS(const MCSubtargetInfo &STI) {
2565 return STI.hasFeature(AMDGPU::FeatureGDS);
2566}
2567
2568unsigned getNSAMaxSize(const MCSubtargetInfo &STI, bool HasSampler) {
2569 auto Version = getIsaVersion(STI.getCPU());
2570 if (Version.Major == 10)
2571 return Version.Minor >= 3 ? 13 : 5;
2572 if (Version.Major == 11)
2573 return 5;
2574 if (Version.Major >= 12)
2575 return HasSampler ? 4 : 5;
2576 return 0;
2577}
2578
2580 if (isGFX1250Plus(STI))
2581 return 32;
2582 return 16;
2583}
2584
2585bool isSI(const MCSubtargetInfo &STI) {
2586 return STI.hasFeature(AMDGPU::FeatureSouthernIslands);
2587}
2588
2589bool isCI(const MCSubtargetInfo &STI) {
2590 return STI.hasFeature(AMDGPU::FeatureSeaIslands);
2591}
2592
2593bool isVI(const MCSubtargetInfo &STI) {
2594 return STI.hasFeature(AMDGPU::FeatureVolcanicIslands);
2595}
2596
2597bool isGFX9(const MCSubtargetInfo &STI) {
2598 return STI.hasFeature(AMDGPU::FeatureGFX9);
2599}
2600
2602 return isGFX9(STI) || isGFX10(STI);
2603}
2604
2606 return isGFX9(STI) || isGFX10(STI) || isGFX11(STI);
2607}
2608
2610 return isVI(STI) || isGFX9(STI) || isGFX10(STI);
2611}
2612
2613bool isGFX8Plus(const MCSubtargetInfo &STI) {
2614 return isVI(STI) || isGFX9Plus(STI);
2615}
2616
2617bool isGFX9Plus(const MCSubtargetInfo &STI) {
2618 return isGFX9(STI) || isGFX10Plus(STI);
2619}
2620
2621bool isNotGFX9Plus(const MCSubtargetInfo &STI) { return !isGFX9Plus(STI); }
2622
2623bool isGFX10(const MCSubtargetInfo &STI) {
2624 return STI.hasFeature(AMDGPU::FeatureGFX10);
2625}
2626
2628 return isGFX10(STI) || isGFX11(STI);
2629}
2630
2632 return isGFX10(STI) || isGFX11Plus(STI);
2633}
2634
2635bool isGFX11(const MCSubtargetInfo &STI) {
2636 return STI.hasFeature(AMDGPU::FeatureGFX11);
2637}
2638
2640 return isGFX11(STI) || isGFX12Plus(STI);
2641}
2642
2643bool isGFX12(const MCSubtargetInfo &STI) {
2644 return STI.getFeatureBits()[AMDGPU::FeatureGFX12];
2645}
2646
2648 return isGFX12(STI) || isGFX13Plus(STI);
2649}
2650
2651bool isNotGFX12Plus(const MCSubtargetInfo &STI) { return !isGFX12Plus(STI); }
2652
2653bool isGFX1250(const MCSubtargetInfo &STI) {
2654 return STI.getFeatureBits()[AMDGPU::FeatureGFX1250Insts] && !isGFX13(STI);
2655}
2656
2658 return STI.getFeatureBits()[AMDGPU::FeatureGFX1250Insts];
2659}
2660
2661bool isGFX13(const MCSubtargetInfo &STI) {
2662 return STI.getFeatureBits()[AMDGPU::FeatureGFX13];
2663}
2664
2665bool isGFX13Plus(const MCSubtargetInfo &STI) { return isGFX13(STI); }
2666
2668 if (isGFX1250(STI))
2669 return false;
2670 return isGFX10Plus(STI);
2671}
2672
2673bool isNotGFX11Plus(const MCSubtargetInfo &STI) { return !isGFX11Plus(STI); }
2674
2676 return isSI(STI) || isCI(STI) || isVI(STI) || isGFX9(STI);
2677}
2678
2680 return isGFX10(STI) && !AMDGPU::isGFX10_BEncoding(STI);
2681}
2682
2684 return STI.hasFeature(AMDGPU::FeatureGCN3Encoding);
2685}
2686
2688 return STI.hasFeature(AMDGPU::FeatureGFX10_AEncoding);
2689}
2690
2692 return STI.hasFeature(AMDGPU::FeatureGFX10_BEncoding);
2693}
2694
2696 return STI.hasFeature(AMDGPU::FeatureGFX10_3Insts);
2697}
2698
2700 return isGFX10_BEncoding(STI) && !isGFX12Plus(STI);
2701}
2702
2703bool isGFX90A(const MCSubtargetInfo &STI) {
2704 return STI.hasFeature(AMDGPU::FeatureGFX90AInsts);
2705}
2706
2707bool isGFX940(const MCSubtargetInfo &STI) {
2708 return STI.hasFeature(AMDGPU::FeatureGFX940Insts);
2709}
2710
2712 return STI.hasFeature(AMDGPU::FeatureArchitectedFlatScratch);
2713}
2714
2716 return STI.hasFeature(AMDGPU::FeatureMAIInsts);
2717}
2718
2719bool hasVOPD(const MCSubtargetInfo &STI) {
2720 return STI.hasFeature(AMDGPU::FeatureVOPDInsts);
2721}
2722
2724 return STI.hasFeature(AMDGPU::FeatureDPPSrc1SGPR);
2725}
2726
2728 return STI.hasFeature(AMDGPU::FeatureKernargPreload);
2729}
2730
2731int32_t getTotalNumVGPRs(bool has90AInsts, int32_t ArgNumAGPR,
2732 int32_t ArgNumVGPR) {
2733 if (has90AInsts && ArgNumAGPR)
2734 return alignTo(ArgNumVGPR, 4) + ArgNumAGPR;
2735 return std::max(ArgNumVGPR, ArgNumAGPR);
2736}
2737
2739 const MCRegisterClass SGPRClass = TRI->getRegClass(AMDGPU::SReg_32RegClassID);
2740 const MCRegister FirstSubReg = TRI->getSubReg(Reg, AMDGPU::sub0);
2741 return SGPRClass.contains(FirstSubReg != 0 ? FirstSubReg : Reg) ||
2742 Reg == AMDGPU::SCC;
2743}
2744
2748
2749#define MAP_REG2REG \
2750 using namespace AMDGPU; \
2751 switch (Reg.id()) { \
2752 default: \
2753 return Reg; \
2754 CASE_CI_VI(FLAT_SCR) \
2755 CASE_CI_VI(FLAT_SCR_LO) \
2756 CASE_CI_VI(FLAT_SCR_HI) \
2757 CASE_VI_GFX9PLUS(TTMP0) \
2758 CASE_VI_GFX9PLUS(TTMP1) \
2759 CASE_VI_GFX9PLUS(TTMP2) \
2760 CASE_VI_GFX9PLUS(TTMP3) \
2761 CASE_VI_GFX9PLUS(TTMP4) \
2762 CASE_VI_GFX9PLUS(TTMP5) \
2763 CASE_VI_GFX9PLUS(TTMP6) \
2764 CASE_VI_GFX9PLUS(TTMP7) \
2765 CASE_VI_GFX9PLUS(TTMP8) \
2766 CASE_VI_GFX9PLUS(TTMP9) \
2767 CASE_VI_GFX9PLUS(TTMP10) \
2768 CASE_VI_GFX9PLUS(TTMP11) \
2769 CASE_VI_GFX9PLUS(TTMP12) \
2770 CASE_VI_GFX9PLUS(TTMP13) \
2771 CASE_VI_GFX9PLUS(TTMP14) \
2772 CASE_VI_GFX9PLUS(TTMP15) \
2773 CASE_VI_GFX9PLUS(TTMP0_TTMP1) \
2774 CASE_VI_GFX9PLUS(TTMP2_TTMP3) \
2775 CASE_VI_GFX9PLUS(TTMP4_TTMP5) \
2776 CASE_VI_GFX9PLUS(TTMP6_TTMP7) \
2777 CASE_VI_GFX9PLUS(TTMP8_TTMP9) \
2778 CASE_VI_GFX9PLUS(TTMP10_TTMP11) \
2779 CASE_VI_GFX9PLUS(TTMP12_TTMP13) \
2780 CASE_VI_GFX9PLUS(TTMP14_TTMP15) \
2781 CASE_VI_GFX9PLUS(TTMP0_TTMP1_TTMP2_TTMP3) \
2782 CASE_VI_GFX9PLUS(TTMP4_TTMP5_TTMP6_TTMP7) \
2783 CASE_VI_GFX9PLUS(TTMP8_TTMP9_TTMP10_TTMP11) \
2784 CASE_VI_GFX9PLUS(TTMP12_TTMP13_TTMP14_TTMP15) \
2785 CASE_VI_GFX9PLUS(TTMP0_TTMP1_TTMP2_TTMP3_TTMP4_TTMP5_TTMP6_TTMP7) \
2786 CASE_VI_GFX9PLUS(TTMP4_TTMP5_TTMP6_TTMP7_TTMP8_TTMP9_TTMP10_TTMP11) \
2787 CASE_VI_GFX9PLUS(TTMP8_TTMP9_TTMP10_TTMP11_TTMP12_TTMP13_TTMP14_TTMP15) \
2788 CASE_VI_GFX9PLUS( \
2789 TTMP0_TTMP1_TTMP2_TTMP3_TTMP4_TTMP5_TTMP6_TTMP7_TTMP8_TTMP9_TTMP10_TTMP11_TTMP12_TTMP13_TTMP14_TTMP15) \
2790 CASE_GFXPRE11_GFX11PLUS(M0) \
2791 CASE_GFXPRE11_GFX11PLUS(SGPR_NULL) \
2792 CASE_GFXPRE11_GFX11PLUS_TO(SGPR_NULL64, SGPR_NULL) \
2793 }
2794
2795#define CASE_CI_VI(node) \
2796 assert(!isSI(STI)); \
2797 case node: \
2798 return isCI(STI) ? node##_ci : node##_vi;
2799
2800#define CASE_VI_GFX9PLUS(node) \
2801 case node: \
2802 return isGFX9Plus(STI) ? node##_gfx9plus : node##_vi;
2803
2804#define CASE_GFXPRE11_GFX11PLUS(node) \
2805 case node: \
2806 return isGFX11Plus(STI) ? node##_gfx11plus : node##_gfxpre11;
2807
2808#define CASE_GFXPRE11_GFX11PLUS_TO(node, result) \
2809 case node: \
2810 return isGFX11Plus(STI) ? result##_gfx11plus : result##_gfxpre11;
2811
2813 if (STI.getTargetTriple().getArch() == Triple::r600)
2814 return Reg;
2816}
2817
2818#undef CASE_CI_VI
2819#undef CASE_VI_GFX9PLUS
2820#undef CASE_GFXPRE11_GFX11PLUS
2821#undef CASE_GFXPRE11_GFX11PLUS_TO
2822
2823#define CASE_CI_VI(node) \
2824 case node##_ci: \
2825 case node##_vi: \
2826 return node;
2827#define CASE_VI_GFX9PLUS(node) \
2828 case node##_vi: \
2829 case node##_gfx9plus: \
2830 return node;
2831#define CASE_GFXPRE11_GFX11PLUS(node) \
2832 case node##_gfx11plus: \
2833 case node##_gfxpre11: \
2834 return node;
2835#define CASE_GFXPRE11_GFX11PLUS_TO(node, result)
2836
2838
2840 switch (Reg.id()) {
2841 case AMDGPU::SRC_SHARED_BASE_LO:
2842 case AMDGPU::SRC_SHARED_BASE:
2843 case AMDGPU::SRC_SHARED_LIMIT_LO:
2844 case AMDGPU::SRC_SHARED_LIMIT:
2845 case AMDGPU::SRC_PRIVATE_BASE_LO:
2846 case AMDGPU::SRC_PRIVATE_BASE:
2847 case AMDGPU::SRC_PRIVATE_LIMIT_LO:
2848 case AMDGPU::SRC_PRIVATE_LIMIT:
2849 case AMDGPU::SRC_FLAT_SCRATCH_BASE_LO:
2850 case AMDGPU::SRC_FLAT_SCRATCH_BASE_HI:
2851 case AMDGPU::SRC_POPS_EXITING_WAVE_ID:
2852 return true;
2853 case AMDGPU::SRC_VCCZ:
2854 case AMDGPU::SRC_EXECZ:
2855 case AMDGPU::SRC_SCC:
2856 return true;
2857 case AMDGPU::SGPR_NULL:
2858 return true;
2859 default:
2860 return false;
2861 }
2862}
2863
2864#undef CASE_CI_VI
2865#undef CASE_VI_GFX9PLUS
2866#undef CASE_GFXPRE11_GFX11PLUS
2867#undef CASE_GFXPRE11_GFX11PLUS_TO
2868#undef MAP_REG2REG
2869
2870bool isKImmOperand(const MCInstrDesc &Desc, unsigned OpNo) {
2871 assert(OpNo < Desc.NumOperands);
2872 unsigned OpType = Desc.operands()[OpNo].OperandType;
2873 return OpType >= AMDGPU::OPERAND_KIMM_FIRST &&
2874 OpType <= AMDGPU::OPERAND_KIMM_LAST;
2875}
2876
2877bool isSISrcFPOperand(const MCInstrDesc &Desc, unsigned OpNo) {
2878 assert(OpNo < Desc.NumOperands);
2879 unsigned OpType = Desc.operands()[OpNo].OperandType;
2880 switch (OpType) {
2894 return true;
2895 default:
2896 return false;
2897 }
2898}
2899
2900bool isSISrcInlinableOperand(const MCInstrDesc &Desc, unsigned OpNo) {
2901 assert(OpNo < Desc.NumOperands);
2902 unsigned OpType = Desc.operands()[OpNo].OperandType;
2903 return (OpType >= AMDGPU::OPERAND_REG_INLINE_C_FIRST &&
2907}
2908
2909// Avoid using MCRegisterClass::getSize, since that function will go away
2910// (move from MC* level to Target* level). Return size in bits.
2911unsigned getRegBitWidth(unsigned RCID) {
2912 switch (RCID) {
2913 case AMDGPU::VGPR_16RegClassID:
2914 case AMDGPU::VGPR_16_Lo128RegClassID:
2915 case AMDGPU::SGPR_LO16RegClassID:
2916 case AMDGPU::AGPR_LO16RegClassID:
2917 return 16;
2918 case AMDGPU::SGPR_32RegClassID:
2919 case AMDGPU::VGPR_32RegClassID:
2920 case AMDGPU::VGPR_32_Lo256RegClassID:
2921 case AMDGPU::VRegOrLds_32RegClassID:
2922 case AMDGPU::AGPR_32RegClassID:
2923 case AMDGPU::VS_32RegClassID:
2924 case AMDGPU::AV_32RegClassID:
2925 case AMDGPU::SReg_32RegClassID:
2926 case AMDGPU::SReg_32_XM0RegClassID:
2927 case AMDGPU::SRegOrLds_32RegClassID:
2928 return 32;
2929 case AMDGPU::SGPR_64RegClassID:
2930 case AMDGPU::VS_64RegClassID:
2931 case AMDGPU::SReg_64RegClassID:
2932 case AMDGPU::VReg_64RegClassID:
2933 case AMDGPU::AReg_64RegClassID:
2934 case AMDGPU::SReg_64_XEXECRegClassID:
2935 case AMDGPU::VReg_64_Align2RegClassID:
2936 case AMDGPU::AReg_64_Align2RegClassID:
2937 case AMDGPU::AV_64RegClassID:
2938 case AMDGPU::AV_64_Align2RegClassID:
2939 case AMDGPU::VReg_64_Lo256_Align2RegClassID:
2940 case AMDGPU::VS_64_Lo256RegClassID:
2941 return 64;
2942 case AMDGPU::SGPR_96RegClassID:
2943 case AMDGPU::SReg_96RegClassID:
2944 case AMDGPU::VReg_96RegClassID:
2945 case AMDGPU::AReg_96RegClassID:
2946 case AMDGPU::VReg_96_Align2RegClassID:
2947 case AMDGPU::AReg_96_Align2RegClassID:
2948 case AMDGPU::AV_96RegClassID:
2949 case AMDGPU::AV_96_Align2RegClassID:
2950 case AMDGPU::VReg_96_Lo256_Align2RegClassID:
2951 return 96;
2952 case AMDGPU::SGPR_128RegClassID:
2953 case AMDGPU::SReg_128RegClassID:
2954 case AMDGPU::VReg_128RegClassID:
2955 case AMDGPU::AReg_128RegClassID:
2956 case AMDGPU::VReg_128_Align2RegClassID:
2957 case AMDGPU::AReg_128_Align2RegClassID:
2958 case AMDGPU::AV_128RegClassID:
2959 case AMDGPU::AV_128_Align2RegClassID:
2960 case AMDGPU::SReg_128_XNULLRegClassID:
2961 case AMDGPU::VReg_128_Lo256_Align2RegClassID:
2962 return 128;
2963 case AMDGPU::SGPR_160RegClassID:
2964 case AMDGPU::SReg_160RegClassID:
2965 case AMDGPU::VReg_160RegClassID:
2966 case AMDGPU::AReg_160RegClassID:
2967 case AMDGPU::VReg_160_Align2RegClassID:
2968 case AMDGPU::AReg_160_Align2RegClassID:
2969 case AMDGPU::AV_160RegClassID:
2970 case AMDGPU::AV_160_Align2RegClassID:
2971 case AMDGPU::VReg_160_Lo256_Align2RegClassID:
2972 return 160;
2973 case AMDGPU::SGPR_192RegClassID:
2974 case AMDGPU::SReg_192RegClassID:
2975 case AMDGPU::VReg_192RegClassID:
2976 case AMDGPU::AReg_192RegClassID:
2977 case AMDGPU::VReg_192_Align2RegClassID:
2978 case AMDGPU::AReg_192_Align2RegClassID:
2979 case AMDGPU::AV_192RegClassID:
2980 case AMDGPU::AV_192_Align2RegClassID:
2981 case AMDGPU::VReg_192_Lo256_Align2RegClassID:
2982 return 192;
2983 case AMDGPU::SGPR_224RegClassID:
2984 case AMDGPU::SReg_224RegClassID:
2985 case AMDGPU::VReg_224RegClassID:
2986 case AMDGPU::AReg_224RegClassID:
2987 case AMDGPU::VReg_224_Align2RegClassID:
2988 case AMDGPU::AReg_224_Align2RegClassID:
2989 case AMDGPU::AV_224RegClassID:
2990 case AMDGPU::AV_224_Align2RegClassID:
2991 case AMDGPU::VReg_224_Lo256_Align2RegClassID:
2992 return 224;
2993 case AMDGPU::SGPR_256RegClassID:
2994 case AMDGPU::SReg_256RegClassID:
2995 case AMDGPU::VReg_256RegClassID:
2996 case AMDGPU::AReg_256RegClassID:
2997 case AMDGPU::VReg_256_Align2RegClassID:
2998 case AMDGPU::AReg_256_Align2RegClassID:
2999 case AMDGPU::AV_256RegClassID:
3000 case AMDGPU::AV_256_Align2RegClassID:
3001 case AMDGPU::SReg_256_XNULLRegClassID:
3002 case AMDGPU::VReg_256_Lo256_Align2RegClassID:
3003 return 256;
3004 case AMDGPU::SGPR_288RegClassID:
3005 case AMDGPU::SReg_288RegClassID:
3006 case AMDGPU::VReg_288RegClassID:
3007 case AMDGPU::AReg_288RegClassID:
3008 case AMDGPU::VReg_288_Align2RegClassID:
3009 case AMDGPU::AReg_288_Align2RegClassID:
3010 case AMDGPU::AV_288RegClassID:
3011 case AMDGPU::AV_288_Align2RegClassID:
3012 case AMDGPU::VReg_288_Lo256_Align2RegClassID:
3013 return 288;
3014 case AMDGPU::SGPR_320RegClassID:
3015 case AMDGPU::SReg_320RegClassID:
3016 case AMDGPU::VReg_320RegClassID:
3017 case AMDGPU::AReg_320RegClassID:
3018 case AMDGPU::VReg_320_Align2RegClassID:
3019 case AMDGPU::AReg_320_Align2RegClassID:
3020 case AMDGPU::AV_320RegClassID:
3021 case AMDGPU::AV_320_Align2RegClassID:
3022 case AMDGPU::VReg_320_Lo256_Align2RegClassID:
3023 return 320;
3024 case AMDGPU::SGPR_352RegClassID:
3025 case AMDGPU::SReg_352RegClassID:
3026 case AMDGPU::VReg_352RegClassID:
3027 case AMDGPU::AReg_352RegClassID:
3028 case AMDGPU::VReg_352_Align2RegClassID:
3029 case AMDGPU::AReg_352_Align2RegClassID:
3030 case AMDGPU::AV_352RegClassID:
3031 case AMDGPU::AV_352_Align2RegClassID:
3032 case AMDGPU::VReg_352_Lo256_Align2RegClassID:
3033 return 352;
3034 case AMDGPU::SGPR_384RegClassID:
3035 case AMDGPU::SReg_384RegClassID:
3036 case AMDGPU::VReg_384RegClassID:
3037 case AMDGPU::AReg_384RegClassID:
3038 case AMDGPU::VReg_384_Align2RegClassID:
3039 case AMDGPU::AReg_384_Align2RegClassID:
3040 case AMDGPU::AV_384RegClassID:
3041 case AMDGPU::AV_384_Align2RegClassID:
3042 case AMDGPU::VReg_384_Lo256_Align2RegClassID:
3043 return 384;
3044 case AMDGPU::SGPR_512RegClassID:
3045 case AMDGPU::SReg_512RegClassID:
3046 case AMDGPU::VReg_512RegClassID:
3047 case AMDGPU::AReg_512RegClassID:
3048 case AMDGPU::VReg_512_Align2RegClassID:
3049 case AMDGPU::AReg_512_Align2RegClassID:
3050 case AMDGPU::AV_512RegClassID:
3051 case AMDGPU::AV_512_Align2RegClassID:
3052 case AMDGPU::VReg_512_Lo256_Align2RegClassID:
3053 return 512;
3054 case AMDGPU::SGPR_1024RegClassID:
3055 case AMDGPU::SReg_1024RegClassID:
3056 case AMDGPU::VReg_1024RegClassID:
3057 case AMDGPU::AReg_1024RegClassID:
3058 case AMDGPU::VReg_1024_Align2RegClassID:
3059 case AMDGPU::AReg_1024_Align2RegClassID:
3060 case AMDGPU::AV_1024RegClassID:
3061 case AMDGPU::AV_1024_Align2RegClassID:
3062 case AMDGPU::VReg_1024_Lo256_Align2RegClassID:
3063 return 1024;
3064 default:
3065 llvm_unreachable("Unexpected register class");
3066 }
3067}
3068
3069unsigned getRegBitWidth(const MCRegisterClass &RC) {
3070 return getRegBitWidth(RC.getID());
3071}
3072
3073bool isInlinableLiteral64(int64_t Literal, bool HasInv2Pi) {
3075 return true;
3076
3077 uint64_t Val = static_cast<uint64_t>(Literal);
3078 return (Val == llvm::bit_cast<uint64_t>(0.0)) ||
3079 (Val == llvm::bit_cast<uint64_t>(1.0)) ||
3080 (Val == llvm::bit_cast<uint64_t>(-1.0)) ||
3081 (Val == llvm::bit_cast<uint64_t>(0.5)) ||
3082 (Val == llvm::bit_cast<uint64_t>(-0.5)) ||
3083 (Val == llvm::bit_cast<uint64_t>(2.0)) ||
3084 (Val == llvm::bit_cast<uint64_t>(-2.0)) ||
3085 (Val == llvm::bit_cast<uint64_t>(4.0)) ||
3086 (Val == llvm::bit_cast<uint64_t>(-4.0)) ||
3087 (Val == 0x3fc45f306dc9c882 && HasInv2Pi);
3088}
3089
3090bool isInlinableLiteral32(int32_t Literal, bool HasInv2Pi) {
3092 return true;
3093
3094 // The actual type of the operand does not seem to matter as long
3095 // as the bits match one of the inline immediate values. For example:
3096 //
3097 // -nan has the hexadecimal encoding of 0xfffffffe which is -2 in decimal,
3098 // so it is a legal inline immediate.
3099 //
3100 // 1065353216 has the hexadecimal encoding 0x3f800000 which is 1.0f in
3101 // floating-point, so it is a legal inline immediate.
3102
3103 uint32_t Val = static_cast<uint32_t>(Literal);
3104 return (Val == llvm::bit_cast<uint32_t>(0.0f)) ||
3105 (Val == llvm::bit_cast<uint32_t>(1.0f)) ||
3106 (Val == llvm::bit_cast<uint32_t>(-1.0f)) ||
3107 (Val == llvm::bit_cast<uint32_t>(0.5f)) ||
3108 (Val == llvm::bit_cast<uint32_t>(-0.5f)) ||
3109 (Val == llvm::bit_cast<uint32_t>(2.0f)) ||
3110 (Val == llvm::bit_cast<uint32_t>(-2.0f)) ||
3111 (Val == llvm::bit_cast<uint32_t>(4.0f)) ||
3112 (Val == llvm::bit_cast<uint32_t>(-4.0f)) ||
3113 (Val == 0x3e22f983 && HasInv2Pi);
3114}
3115
3116bool isInlinableLiteralBF16(int16_t Literal, bool HasInv2Pi) {
3117 if (!HasInv2Pi)
3118 return false;
3120 return true;
3121 uint16_t Val = static_cast<uint16_t>(Literal);
3122 return Val == 0x3F00 || // 0.5
3123 Val == 0xBF00 || // -0.5
3124 Val == 0x3F80 || // 1.0
3125 Val == 0xBF80 || // -1.0
3126 Val == 0x4000 || // 2.0
3127 Val == 0xC000 || // -2.0
3128 Val == 0x4080 || // 4.0
3129 Val == 0xC080 || // -4.0
3130 Val == 0x3E22; // 1.0 / (2.0 * pi)
3131}
3132
3133bool isInlinableLiteralI16(int32_t Literal, bool HasInv2Pi) {
3134 return isInlinableLiteral32(Literal, HasInv2Pi);
3135}
3136
3137bool isInlinableLiteralFP16(int16_t Literal, bool HasInv2Pi) {
3138 if (!HasInv2Pi)
3139 return false;
3141 return true;
3142 uint16_t Val = static_cast<uint16_t>(Literal);
3143 return Val == 0x3C00 || // 1.0
3144 Val == 0xBC00 || // -1.0
3145 Val == 0x3800 || // 0.5
3146 Val == 0xB800 || // -0.5
3147 Val == 0x4000 || // 2.0
3148 Val == 0xC000 || // -2.0
3149 Val == 0x4400 || // 4.0
3150 Val == 0xC400 || // -4.0
3151 Val == 0x3118; // 1/2pi
3152}
3153
3154std::optional<unsigned> getInlineEncodingV216(bool IsFloat, uint32_t Literal) {
3155 // Unfortunately, the Instruction Set Architecture Reference Guide is
3156 // misleading about how the inline operands work for (packed) 16-bit
3157 // instructions. In a nutshell, the actual HW behavior is:
3158 //
3159 // - integer encodings (-16 .. 64) are always produced as sign-extended
3160 // 32-bit values
3161 // - float encodings are produced as:
3162 // - for F16 instructions: corresponding half-precision float values in
3163 // the LSBs, 0 in the MSBs
3164 // - for UI16 instructions: corresponding single-precision float value
3165 int32_t Signed = static_cast<int32_t>(Literal);
3166 if (Signed >= 0 && Signed <= 64)
3167 return 128 + Signed;
3168
3169 if (Signed >= -16 && Signed <= -1)
3170 return 192 + std::abs(Signed);
3171
3172 if (IsFloat) {
3173 // clang-format off
3174 switch (Literal) {
3175 case 0x3800: return 240; // 0.5
3176 case 0xB800: return 241; // -0.5
3177 case 0x3C00: return 242; // 1.0
3178 case 0xBC00: return 243; // -1.0
3179 case 0x4000: return 244; // 2.0
3180 case 0xC000: return 245; // -2.0
3181 case 0x4400: return 246; // 4.0
3182 case 0xC400: return 247; // -4.0
3183 case 0x3118: return 248; // 1.0 / (2.0 * pi)
3184 default: break;
3185 }
3186 // clang-format on
3187 } else {
3188 // clang-format off
3189 switch (Literal) {
3190 case 0x3F000000: return 240; // 0.5
3191 case 0xBF000000: return 241; // -0.5
3192 case 0x3F800000: return 242; // 1.0
3193 case 0xBF800000: return 243; // -1.0
3194 case 0x40000000: return 244; // 2.0
3195 case 0xC0000000: return 245; // -2.0
3196 case 0x40800000: return 246; // 4.0
3197 case 0xC0800000: return 247; // -4.0
3198 case 0x3E22F983: return 248; // 1.0 / (2.0 * pi)
3199 default: break;
3200 }
3201 // clang-format on
3202 }
3203
3204 return {};
3205}
3206
3207// Encoding of the literal as an inline constant for a V_PK_*_IU16 instruction
3208// or nullopt.
3209std::optional<unsigned> getInlineEncodingV2I16(uint32_t Literal) {
3210 return getInlineEncodingV216(false, Literal);
3211}
3212
3213// Encoding of the literal as an inline constant for a V_PK_*_BF16 instruction
3214// or nullopt.
3215std::optional<unsigned> getInlineEncodingV2BF16(uint32_t Literal) {
3216 int32_t Signed = static_cast<int32_t>(Literal);
3217 if (Signed >= 0 && Signed <= 64)
3218 return 128 + Signed;
3219
3220 if (Signed >= -16 && Signed <= -1)
3221 return 192 + std::abs(Signed);
3222
3223 // clang-format off
3224 switch (Literal) {
3225 case 0x3F00: return 240; // 0.5
3226 case 0xBF00: return 241; // -0.5
3227 case 0x3F80: return 242; // 1.0
3228 case 0xBF80: return 243; // -1.0
3229 case 0x4000: return 244; // 2.0
3230 case 0xC000: return 245; // -2.0
3231 case 0x4080: return 246; // 4.0
3232 case 0xC080: return 247; // -4.0
3233 case 0x3E22: return 248; // 1.0 / (2.0 * pi)
3234 default: break;
3235 }
3236 // clang-format on
3237
3238 return std::nullopt;
3239}
3240
3241// Encoding of the literal as an inline constant for a V_PK_*_F16 instruction
3242// or nullopt.
3243std::optional<unsigned> getInlineEncodingV2F16(uint32_t Literal) {
3244 return getInlineEncodingV216(true, Literal);
3245}
3246
3247// Encoding of the literal as an inline constant for V_PK_FMAC_F16 instruction
3248// or nullopt. This accounts for different inline constant behavior:
3249// - Pre-GFX11: fp16 inline constants have the value in low 16 bits, 0 in high
3250// - GFX11+: fp16 inline constants are duplicated into both halves
3252 bool IsGFX11Plus) {
3253 // Pre-GFX11 behavior: f16 in low bits, 0 in high bits
3254 if (!IsGFX11Plus)
3255 return getInlineEncodingV216(/*IsFloat=*/true, Literal);
3256
3257 // GFX11+ behavior: f16 duplicated in both halves
3258 // First, check for sign-extended integer inline constants (-16 to 64)
3259 // These work the same across all generations
3260 int32_t Signed = static_cast<int32_t>(Literal);
3261 if (Signed >= 0 && Signed <= 64)
3262 return 128 + Signed;
3263
3264 if (Signed >= -16 && Signed <= -1)
3265 return 192 + std::abs(Signed);
3266
3267 // For float inline constants on GFX11+, both halves must be equal
3268 uint16_t Lo = static_cast<uint16_t>(Literal);
3269 uint16_t Hi = static_cast<uint16_t>(Literal >> 16);
3270 if (Lo != Hi)
3271 return std::nullopt;
3272 return getInlineEncodingV216(/*IsFloat=*/true, Lo);
3273}
3274
3275// Whether the given literal can be inlined for a V_PK_* instruction.
3277 switch (OpType) {
3280 return getInlineEncodingV216(false, Literal).has_value();
3283 return getInlineEncodingV216(true, Literal).has_value();
3285 llvm_unreachable("OPERAND_REG_IMM_V2FP16_SPLAT is not supported");
3290 return false;
3291 default:
3292 llvm_unreachable("bad packed operand type");
3293 }
3294}
3295
3296// Whether the given literal can be inlined for a V_PK_*_IU16 instruction.
3300
3301// Whether the given literal can be inlined for a V_PK_*_BF16 instruction.
3305
3306// Whether the given literal can be inlined for a V_PK_*_F16 instruction.
3310
3311// Whether the given literal can be inlined for V_PK_FMAC_F16 instruction.
3313 return getPKFMACF16InlineEncoding(Literal, IsGFX11Plus).has_value();
3314}
3315
3316bool isValid32BitLiteral(uint64_t Val, bool IsFP64) {
3317 if (IsFP64)
3318 return !Lo_32(Val);
3319
3320 return isUInt<32>(Val) || isInt<32>(Val);
3321}
3322
3323int64_t encode32BitLiteral(int64_t Imm, OperandType Type, bool IsLit) {
3324 switch (Type) {
3325 default:
3326 break;
3331 return Imm & 0xffff;
3345 return Lo_32(Imm);
3347 return IsLit ? Imm : Hi_32(Imm);
3348 }
3349 return Imm;
3350}
3351
3353 const Function *F = A->getParent();
3354
3355 // Arguments to compute shaders are never a source of divergence.
3356 CallingConv::ID CC = F->getCallingConv();
3357 switch (CC) {
3360 return true;
3371 // For non-compute shaders, SGPR inputs are marked with either inreg or
3372 // byval. Everything else is in VGPRs.
3373 return A->hasAttribute(Attribute::InReg) ||
3374 A->hasAttribute(Attribute::ByVal);
3375 default:
3376 // TODO: treat i1 as divergent?
3377 return A->hasAttribute(Attribute::InReg);
3378 }
3379}
3380
3381bool isArgPassedInSGPR(const CallBase *CB, unsigned ArgNo) {
3382 // Arguments to compute shaders are never a source of divergence.
3384 switch (CC) {
3387 return true;
3398 // For non-compute shaders, SGPR inputs are marked with either inreg or
3399 // byval. Everything else is in VGPRs.
3400 return CB->paramHasAttr(ArgNo, Attribute::InReg) ||
3401 CB->paramHasAttr(ArgNo, Attribute::ByVal);
3402 default:
3403 return CB->paramHasAttr(ArgNo, Attribute::InReg);
3404 }
3405}
3406
3407static bool hasSMEMByteOffset(const MCSubtargetInfo &ST) {
3408 return isGCN3Encoding(ST) || isGFX10Plus(ST);
3409}
3410
3412 int64_t EncodedOffset) {
3413 if (isGFX12Plus(ST))
3414 return isUInt<23>(EncodedOffset);
3415
3416 return hasSMEMByteOffset(ST) ? isUInt<20>(EncodedOffset)
3417 : isUInt<8>(EncodedOffset);
3418}
3419
3421 int64_t EncodedOffset, bool IsBuffer) {
3422 if (isGFX12Plus(ST)) {
3423 if (IsBuffer && EncodedOffset < 0)
3424 return false;
3425 return isInt<24>(EncodedOffset);
3426 }
3427
3428 return !IsBuffer && hasSMRDSignedImmOffset(ST) && isInt<21>(EncodedOffset);
3429}
3430
3431static bool isDwordAligned(uint64_t ByteOffset) {
3432 return (ByteOffset & 3) == 0;
3433}
3434
3436 uint64_t ByteOffset) {
3437 if (hasSMEMByteOffset(ST))
3438 return ByteOffset;
3439
3440 assert(isDwordAligned(ByteOffset));
3441 return ByteOffset >> 2;
3442}
3443
3444std::optional<int64_t> getSMRDEncodedOffset(const MCSubtargetInfo &ST,
3445 int64_t ByteOffset, bool IsBuffer,
3446 bool HasSOffset) {
3447 // For unbuffered smem loads, it is illegal for the Immediate Offset to be
3448 // negative if the resulting (Offset + (M0 or SOffset or zero) is negative.
3449 // Handle case where SOffset is not present.
3450 if (!IsBuffer && !HasSOffset && ByteOffset < 0 && hasSMRDSignedImmOffset(ST))
3451 return std::nullopt;
3452
3453 if (isGFX12Plus(ST)) // 24 bit signed offsets
3454 return isInt<24>(ByteOffset) ? std::optional<int64_t>(ByteOffset)
3455 : std::nullopt;
3456
3457 // The signed version is always a byte offset.
3458 if (!IsBuffer && hasSMRDSignedImmOffset(ST)) {
3460 return isInt<20>(ByteOffset) ? std::optional<int64_t>(ByteOffset)
3461 : std::nullopt;
3462 }
3463
3464 if (!isDwordAligned(ByteOffset) && !hasSMEMByteOffset(ST))
3465 return std::nullopt;
3466
3467 int64_t EncodedOffset = convertSMRDOffsetUnits(ST, ByteOffset);
3468 return isLegalSMRDEncodedUnsignedOffset(ST, EncodedOffset)
3469 ? std::optional<int64_t>(EncodedOffset)
3470 : std::nullopt;
3471}
3472
3473std::optional<int64_t> getSMRDEncodedLiteralOffset32(const MCSubtargetInfo &ST,
3474 int64_t ByteOffset) {
3475 if (!isCI(ST) || !isDwordAligned(ByteOffset))
3476 return std::nullopt;
3477
3478 int64_t EncodedOffset = convertSMRDOffsetUnits(ST, ByteOffset);
3479 return isUInt<32>(EncodedOffset) ? std::optional<int64_t>(EncodedOffset)
3480 : std::nullopt;
3481}
3482
3484 if (ST.getFeatureBits().test(FeatureFlatOffsetBits12))
3485 return 12;
3486 if (ST.getFeatureBits().test(FeatureFlatOffsetBits24))
3487 return 24;
3488 return 13;
3489}
3490
3491namespace {
3492
3493struct SourceOfDivergence {
3494 unsigned Intr;
3495};
3496const SourceOfDivergence *lookupSourceOfDivergence(unsigned Intr);
3497
3498struct AlwaysUniform {
3499 unsigned Intr;
3500};
3501const AlwaysUniform *lookupAlwaysUniform(unsigned Intr);
3502
3503#define GET_SourcesOfDivergence_IMPL
3504#define GET_UniformIntrinsics_IMPL
3505#define GET_Gfx9BufferFormat_IMPL
3506#define GET_Gfx10BufferFormat_IMPL
3507#define GET_Gfx11PlusBufferFormat_IMPL
3508
3509#include "AMDGPUGenSearchableTables.inc"
3510
3511} // end anonymous namespace
3512
3513bool isIntrinsicSourceOfDivergence(unsigned IntrID) {
3514 return lookupSourceOfDivergence(IntrID);
3515}
3516
3517bool isIntrinsicAlwaysUniform(unsigned IntrID) {
3518 return lookupAlwaysUniform(IntrID);
3519}
3520
3522 uint8_t NumComponents,
3523 uint8_t NumFormat,
3524 const MCSubtargetInfo &STI) {
3525 return isGFX11Plus(STI) ? getGfx11PlusBufferFormatInfo(
3526 BitsPerComp, NumComponents, NumFormat)
3527 : isGFX10(STI)
3528 ? getGfx10BufferFormatInfo(BitsPerComp, NumComponents, NumFormat)
3529 : getGfx9BufferFormatInfo(BitsPerComp, NumComponents, NumFormat);
3530}
3531
3533 const MCSubtargetInfo &STI) {
3534 return isGFX11Plus(STI) ? getGfx11PlusBufferFormatInfo(Format)
3535 : isGFX10(STI) ? getGfx10BufferFormatInfo(Format)
3536 : getGfx9BufferFormatInfo(Format);
3537}
3538
3540 const MCRegisterInfo &MRI) {
3541 const unsigned VGPRClasses[] = {
3542 AMDGPU::VGPR_16RegClassID, AMDGPU::VGPR_32RegClassID,
3543 AMDGPU::VReg_64RegClassID, AMDGPU::VReg_96RegClassID,
3544 AMDGPU::VReg_128RegClassID, AMDGPU::VReg_160RegClassID,
3545 AMDGPU::VReg_192RegClassID, AMDGPU::VReg_224RegClassID,
3546 AMDGPU::VReg_256RegClassID, AMDGPU::VReg_288RegClassID,
3547 AMDGPU::VReg_320RegClassID, AMDGPU::VReg_352RegClassID,
3548 AMDGPU::VReg_384RegClassID, AMDGPU::VReg_512RegClassID,
3549 AMDGPU::VReg_1024RegClassID};
3550
3551 for (unsigned RCID : VGPRClasses) {
3552 const MCRegisterClass &RC = MRI.getRegClass(RCID);
3553 if (RC.contains(Reg))
3554 return &RC;
3555 }
3556
3557 return nullptr;
3558}
3559
3561 unsigned Enc = MRI.getEncodingValue(Reg);
3562 unsigned Idx = Enc & AMDGPU::HWEncoding::REG_IDX_MASK;
3563 return Idx >> 8;
3564}
3565
3567 const MCRegisterInfo &MRI) {
3568 unsigned Enc = MRI.getEncodingValue(Reg);
3569 unsigned Idx = Enc & AMDGPU::HWEncoding::REG_IDX_MASK;
3570 if (Idx >= 0x100)
3571 return MCRegister();
3572
3573 const MCRegisterClass *RC = getVGPRPhysRegClass(Reg, MRI);
3574 if (!RC)
3575 return MCRegister();
3576
3577 Idx |= MSBs << 8;
3578 if (RC->getID() == AMDGPU::VGPR_16RegClassID) {
3579 // This class has 2048 registers with interleaved lo16 and hi16.
3580 Idx *= 2;
3582 ++Idx;
3583 }
3584
3585 return RC->getRegister(Idx);
3586}
3587
3588static std::optional<unsigned>
3589convertSetRegImmToVgprMSBs(unsigned Imm, unsigned Simm16,
3590 bool HasSetregVGPRMSBFixup) {
3591 constexpr unsigned VGPRMSBShift =
3593
3594 auto [HwRegId, Offset, Size] = Hwreg::HwregEncoding::decode(Simm16);
3595 if (HwRegId != Hwreg::ID_MODE ||
3596 (!HasSetregVGPRMSBFixup && (Offset + Size) < VGPRMSBShift))
3597 return {};
3598 // If there is SetregVGPRMSBFixup then Offset is ignored.
3599 if (!HasSetregVGPRMSBFixup)
3600 Imm <<= Offset;
3601 Imm = (Imm & Hwreg::VGPR_MSB_MASK) >> VGPRMSBShift;
3602 if (!HasSetregVGPRMSBFixup)
3604 return llvm::rotr<uint8_t>(static_cast<uint8_t>(Imm), /*R=*/2);
3605}
3606
3607std::optional<unsigned> convertSetRegImmToVgprMSBs(const MachineInstr &MI,
3608 bool HasSetregVGPRMSBFixup) {
3609 assert(MI.getOpcode() == AMDGPU::S_SETREG_IMM32_B32);
3610 return convertSetRegImmToVgprMSBs(MI.getOperand(0).getImm(),
3611 MI.getOperand(1).getImm(),
3612 HasSetregVGPRMSBFixup);
3613}
3614
3615std::optional<unsigned> convertSetRegImmToVgprMSBs(const MCInst &MI,
3616 bool HasSetregVGPRMSBFixup) {
3617 assert(MI.getOpcode() == AMDGPU::S_SETREG_IMM32_B32_gfx12);
3618 return convertSetRegImmToVgprMSBs(MI.getOperand(0).getImm(),
3619 MI.getOperand(1).getImm(),
3620 HasSetregVGPRMSBFixup);
3621}
3622
3623std::pair<const AMDGPU::OpName *, const AMDGPU::OpName *>
3625 static const AMDGPU::OpName VOPOps[4] = {
3626 AMDGPU::OpName::src0, AMDGPU::OpName::src1, AMDGPU::OpName::src2,
3627 AMDGPU::OpName::vdst};
3628 static const AMDGPU::OpName VDSOps[4] = {
3629 AMDGPU::OpName::addr, AMDGPU::OpName::data0, AMDGPU::OpName::data1,
3630 AMDGPU::OpName::vdst};
3631 static const AMDGPU::OpName FLATOps[4] = {
3632 AMDGPU::OpName::vaddr, AMDGPU::OpName::vdata,
3633 AMDGPU::OpName::NUM_OPERAND_NAMES, AMDGPU::OpName::vdst};
3634 static const AMDGPU::OpName BUFOps[4] = {
3635 AMDGPU::OpName::vaddr, AMDGPU::OpName::NUM_OPERAND_NAMES,
3636 AMDGPU::OpName::NUM_OPERAND_NAMES, AMDGPU::OpName::vdata};
3637 static const AMDGPU::OpName VIMGOps[4] = {
3638 AMDGPU::OpName::vaddr0, AMDGPU::OpName::vaddr1, AMDGPU::OpName::vaddr2,
3639 AMDGPU::OpName::vdata};
3640
3641 // For VOPD instructions MSB of a corresponding Y component operand VGPR
3642 // address is supposed to match X operand, otherwise VOPD shall not be
3643 // combined.
3644 static const AMDGPU::OpName VOPDOpsX[4] = {
3645 AMDGPU::OpName::src0X, AMDGPU::OpName::vsrc1X, AMDGPU::OpName::vsrc2X,
3646 AMDGPU::OpName::vdstX};
3647 static const AMDGPU::OpName VOPDOpsY[4] = {
3648 AMDGPU::OpName::src0Y, AMDGPU::OpName::vsrc1Y, AMDGPU::OpName::vsrc2Y,
3649 AMDGPU::OpName::vdstY};
3650
3651 // VOP2 MADMK instructions use src0, imm, src1 scheme.
3652 static const AMDGPU::OpName VOP2MADMKOps[4] = {
3653 AMDGPU::OpName::src0, AMDGPU::OpName::NUM_OPERAND_NAMES,
3654 AMDGPU::OpName::src1, AMDGPU::OpName::vdst};
3655 static const AMDGPU::OpName VOPDFMAMKOpsX[4] = {
3656 AMDGPU::OpName::src0X, AMDGPU::OpName::NUM_OPERAND_NAMES,
3657 AMDGPU::OpName::vsrc1X, AMDGPU::OpName::vdstX};
3658 static const AMDGPU::OpName VOPDFMAMKOpsY[4] = {
3659 AMDGPU::OpName::src0Y, AMDGPU::OpName::NUM_OPERAND_NAMES,
3660 AMDGPU::OpName::vsrc1Y, AMDGPU::OpName::vdstY};
3661
3662 unsigned TSFlags = Desc.TSFlags;
3663
3664 if (TSFlags &
3667 switch (Desc.getOpcode()) {
3668 // LD_SCALE operands ignore MSB.
3669 case AMDGPU::V_WMMA_LD_SCALE_PAIRED_B32:
3670 case AMDGPU::V_WMMA_LD_SCALE_PAIRED_B32_gfx1250:
3671 case AMDGPU::V_WMMA_LD_SCALE16_PAIRED_B64:
3672 case AMDGPU::V_WMMA_LD_SCALE16_PAIRED_B64_gfx1250:
3673 return {};
3674 case AMDGPU::V_FMAMK_F16:
3675 case AMDGPU::V_FMAMK_F16_t16:
3676 case AMDGPU::V_FMAMK_F16_t16_gfx12:
3677 case AMDGPU::V_FMAMK_F16_fake16:
3678 case AMDGPU::V_FMAMK_F16_fake16_gfx12:
3679 case AMDGPU::V_FMAMK_F32:
3680 case AMDGPU::V_FMAMK_F32_gfx12:
3681 case AMDGPU::V_FMAMK_F64:
3682 case AMDGPU::V_FMAMK_F64_gfx1250:
3683 return {VOP2MADMKOps, nullptr};
3684 default:
3685 break;
3686 }
3687 return {VOPOps, nullptr};
3688 }
3689
3690 if (TSFlags & SIInstrFlags::DS)
3691 return {VDSOps, nullptr};
3692
3693 if (TSFlags & SIInstrFlags::FLAT)
3694 return {FLATOps, nullptr};
3695
3696 if (TSFlags & (SIInstrFlags::MUBUF | SIInstrFlags::MTBUF))
3697 return {BUFOps, nullptr};
3698
3699 if (TSFlags & SIInstrFlags::VIMAGE)
3700 return {VIMGOps, nullptr};
3701
3702 if (AMDGPU::isVOPD(Desc.getOpcode())) {
3703 auto [OpX, OpY] = getVOPDComponents(Desc.getOpcode());
3704 return {(OpX == AMDGPU::V_FMAMK_F32) ? VOPDFMAMKOpsX : VOPDOpsX,
3705 (OpY == AMDGPU::V_FMAMK_F32) ? VOPDFMAMKOpsY : VOPDOpsY};
3706 }
3707
3708 assert(!(TSFlags & SIInstrFlags::MIMG));
3709
3710 if (TSFlags & (SIInstrFlags::VSAMPLE | SIInstrFlags::EXP))
3711 llvm_unreachable("Sample and export VGPR lowering is not implemented and"
3712 " these instructions are not expected on gfx1250");
3713
3714 return {};
3715}
3716
3717bool supportsScaleOffset(const MCInstrInfo &MII, unsigned Opcode) {
3718 uint64_t TSFlags = MII.get(Opcode).TSFlags;
3719
3720 if (TSFlags & SIInstrFlags::SMRD)
3721 return !getSMEMIsBuffer(Opcode);
3722 if (!(TSFlags & SIInstrFlags::FLAT))
3723 return false;
3724
3725 // Only SV and SVS modes are supported.
3726 if (TSFlags & SIInstrFlags::FlatScratch)
3727 return hasNamedOperand(Opcode, OpName::vaddr);
3728
3729 // Only GVS mode is supported.
3730 return hasNamedOperand(Opcode, OpName::vaddr) &&
3731 hasNamedOperand(Opcode, OpName::saddr);
3732
3733 return false;
3734}
3735
3736bool hasAny64BitVGPROperands(const MCInstrDesc &OpDesc, const MCInstrInfo &MII,
3737 const MCSubtargetInfo &ST) {
3738 for (auto OpName : {OpName::vdst, OpName::src0, OpName::src1, OpName::src2}) {
3739 int Idx = getNamedOperandIdx(OpDesc.getOpcode(), OpName);
3740 if (Idx == -1)
3741 continue;
3742
3743 const MCOperandInfo &OpInfo = OpDesc.operands()[Idx];
3744 int16_t RegClass = MII.getOpRegClassID(
3745 OpInfo, ST.getHwMode(MCSubtargetInfo::HwMode_RegInfo));
3746 if (RegClass == AMDGPU::VReg_64RegClassID ||
3747 RegClass == AMDGPU::VReg_64_Align2RegClassID)
3748 return true;
3749 }
3750
3751 return false;
3752}
3753
3754bool isDPALU_DPP32BitOpc(unsigned Opc) {
3755 switch (Opc) {
3756 case AMDGPU::V_MUL_LO_U32_e64:
3757 case AMDGPU::V_MUL_LO_U32_e64_dpp:
3758 case AMDGPU::V_MUL_LO_U32_e64_dpp_gfx1250:
3759 case AMDGPU::V_MUL_HI_U32_e64:
3760 case AMDGPU::V_MUL_HI_U32_e64_dpp:
3761 case AMDGPU::V_MUL_HI_U32_e64_dpp_gfx1250:
3762 case AMDGPU::V_MUL_HI_I32_e64:
3763 case AMDGPU::V_MUL_HI_I32_e64_dpp:
3764 case AMDGPU::V_MUL_HI_I32_e64_dpp_gfx1250:
3765 case AMDGPU::V_MAD_U32_e64:
3766 case AMDGPU::V_MAD_U32_e64_dpp:
3767 case AMDGPU::V_MAD_U32_e64_dpp_gfx1250:
3768 return true;
3769 default:
3770 return false;
3771 }
3772}
3773
3774bool isDPALU_DPP(const MCInstrDesc &OpDesc, const MCInstrInfo &MII,
3775 const MCSubtargetInfo &ST) {
3776 if (!ST.hasFeature(AMDGPU::FeatureDPALU_DPP))
3777 return false;
3778
3779 if (isDPALU_DPP32BitOpc(OpDesc.getOpcode()))
3780 return ST.hasFeature(AMDGPU::FeatureGFX1250Insts);
3781
3782 return hasAny64BitVGPROperands(OpDesc, MII, ST);
3783}
3784
3786 if (ST.getFeatureBits().test(FeatureAddressableLocalMemorySize32768))
3787 return 64;
3788 if (ST.getFeatureBits().test(FeatureAddressableLocalMemorySize65536))
3789 return 128;
3790 if (ST.getFeatureBits().test(FeatureAddressableLocalMemorySize163840))
3791 return 320;
3792 if (ST.getFeatureBits().test(FeatureAddressableLocalMemorySize327680))
3793 return 512;
3794 return 64; // In sync with getAddressableLocalMemorySize
3795}
3796
3797bool isPackedFP32Inst(unsigned Opc) {
3798 switch (Opc) {
3799 case AMDGPU::V_PK_ADD_F32:
3800 case AMDGPU::V_PK_ADD_F32_gfx12:
3801 case AMDGPU::V_PK_MUL_F32:
3802 case AMDGPU::V_PK_MUL_F32_gfx12:
3803 case AMDGPU::V_PK_FMA_F32:
3804 case AMDGPU::V_PK_FMA_F32_gfx12:
3805 return true;
3806 default:
3807 return false;
3808 }
3809}
3810
3811const std::array<unsigned, 3> &ClusterDimsAttr::getDims() const {
3812 assert(isFixedDims() && "expect kind to be FixedDims");
3813 return Dims;
3814}
3815
3816std::string ClusterDimsAttr::to_string() const {
3817 SmallString<10> Buffer;
3818 raw_svector_ostream OS(Buffer);
3819
3820 switch (getKind()) {
3821 case Kind::Unknown:
3822 return "";
3823 case Kind::NoCluster: {
3824 OS << EncoNoCluster << ',' << EncoNoCluster << ',' << EncoNoCluster;
3825 return Buffer.c_str();
3826 }
3827 case Kind::VariableDims: {
3828 OS << EncoVariableDims << ',' << EncoVariableDims << ','
3829 << EncoVariableDims;
3830 return Buffer.c_str();
3831 }
3832 case Kind::FixedDims: {
3833 OS << Dims[0] << ',' << Dims[1] << ',' << Dims[2];
3834 return Buffer.c_str();
3835 }
3836 }
3837 llvm_unreachable("Unknown ClusterDimsAttr kind");
3838}
3839
3841 std::optional<SmallVector<unsigned>> Attr =
3842 getIntegerVecAttribute(F, "amdgpu-cluster-dims", /*Size=*/3);
3844
3845 if (!Attr.has_value())
3846 AttrKind = Kind::Unknown;
3847 else if (all_of(*Attr, equal_to(EncoNoCluster)))
3848 AttrKind = Kind::NoCluster;
3849 else if (all_of(*Attr, equal_to(EncoVariableDims)))
3850 AttrKind = Kind::VariableDims;
3851
3852 ClusterDimsAttr A(AttrKind);
3853 if (AttrKind == Kind::FixedDims)
3854 A.Dims = {(*Attr)[0], (*Attr)[1], (*Attr)[2]};
3855
3856 return A;
3857}
3858
3859} // namespace AMDGPU
3860
3863 switch (S) {
3865 OS << "Unsupported";
3866 break;
3868 OS << "Any";
3869 break;
3871 OS << "Off";
3872 break;
3874 OS << "On";
3875 break;
3876 }
3877 return OS;
3878}
3879
3880} // namespace llvm
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static llvm::cl::opt< unsigned > DefaultAMDHSACodeObjectVersion("amdhsa-code-object-version", llvm::cl::Hidden, llvm::cl::init(llvm::AMDGPU::AMDHSA_COV6), llvm::cl::desc("Set default AMDHSA Code Object Version (module flag " "or asm directive still take priority if present)"))
#define MAP_REG2REG
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")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
IRTranslator LLVM IR MI
#define RegName(no)
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
Register Reg
Register const TargetRegisterInfo * TRI
This file contains the declarations for metadata subclasses.
#define T
uint64_t High
if(PassOpts->AAPipeline)
#define S_00B848_MEM_ORDERED(x)
Definition SIDefines.h:1254
#define S_00B848_WGP_MODE(x)
Definition SIDefines.h:1251
#define S_00B848_FWD_PROGRESS(x)
Definition SIDefines.h:1257
This file contains some functions that are useful when dealing with strings.
static const int BlockSize
Definition TarWriter.cpp:33
static const uint32_t IV[8]
Definition blake3_impl.h:83
static ClusterDimsAttr get(const Function &F)
const std::array< unsigned, 3 > & getDims() const
TargetIDSetting getXnackSetting() const
void print(raw_ostream &OS) const
Write string representation to OS.
AMDGPUTargetID(const MCSubtargetInfo &STI)
void setTargetIDFromTargetIDStream(StringRef TargetID)
TargetIDSetting getSramEccSetting() const
unsigned getIndexInParsedOperands(unsigned CompOprIdx) const
unsigned getIndexOfSrcInParsedOperands(unsigned CompSrcIdx) const
std::optional< unsigned > getInvalidCompOperandIndex(std::function< MCRegister(unsigned, unsigned)> GetRegIdx, const MCRegisterInfo &MRI, bool SkipSrc=false, bool AllowSameVGPR=false, bool VOPD3=false) const
std::array< MCRegister, Component::MAX_OPR_NUM > RegIndices
Represents the counter values to wait for in an s_waitcnt instruction.
This class represents an incoming formal argument to a Function.
Definition Argument.h:32
Functions, function parameters, and return types can have attributes to indicate how they should be t...
Definition Attributes.h:105
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
CallingConv::ID getCallingConv() const
LLVM_ABI bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Determine whether the argument or parameter has the given attribute.
constexpr bool test(unsigned I) const
unsigned getAddressSpace() const
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
Instances of this class represent a single low-level machine instruction.
Definition MCInst.h:188
Describe properties that are true of each instruction in the target description file.
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
ArrayRef< MCOperandInfo > operands() const
bool mayStore() const
Return true if this instruction could possibly modify memory.
bool mayLoad() const
Return true if this instruction could possibly read memory.
unsigned getNumDefs() const
Return the number of MachineOperands that are register definitions.
int getOperandConstraint(unsigned OpNum, MCOI::OperandConstraint Constraint) const
Returns the value of the specified operand constraint if it is present.
unsigned getOpcode() const
Return the opcode number for this descriptor.
Interface to description of machine instruction set.
Definition MCInstrInfo.h:27
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode.
Definition MCInstrInfo.h:90
int16_t getOpRegClassID(const MCOperandInfo &OpInfo, unsigned HwModeId) const
Return the ID of the register class to use for OpInfo, for the active HwMode HwModeId.
Definition MCInstrInfo.h:80
This holds information about one operand of a machine instruction, indicating the register class for ...
Definition MCInstrDesc.h:86
MCRegisterClass - Base class of TargetRegisterClass.
unsigned getID() const
getID() - Return the register class ID number.
MCRegister getRegister(unsigned i) const
getRegister - Return the specified register in the class.
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...
bool regsOverlap(MCRegister RegA, MCRegister RegB) const
Returns true if the two registers are equal or alias each other.
uint16_t getEncodingValue(MCRegister Reg) const
Returns the encoding for Reg.
const MCRegisterClass & getRegClass(unsigned i) const
Returns the register class associated with the enumeration value.
MCRegister getSubReg(MCRegister Reg, unsigned Idx) const
Returns the physical register number of sub-register "Index" for physical register RegNo.
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:41
constexpr unsigned id() const
Definition MCRegister.h:82
Generic base class for all target subtargets.
bool hasFeature(unsigned Feature) const
const Triple & getTargetTriple() const
const FeatureBitset & getFeatureBits() const
StringRef getCPU() const
Metadata node.
Definition Metadata.h:1075
const MDOperand & getOperand(unsigned I) const
Definition Metadata.h:1439
unsigned getNumOperands() const
Return number of MDNode operands.
Definition Metadata.h:1445
Representation of each machine instruction.
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:26
const char * c_str()
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
Definition StringRef.h:882
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition StringRef.h:730
bool getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
Definition StringRef.h:490
std::string str() const
Get the contents as an std::string.
Definition StringRef.h:222
constexpr bool empty() const
Check if the string is empty.
Definition StringRef.h:141
constexpr size_t size() const
Get the string size.
Definition StringRef.h:144
bool ends_with(StringRef Suffix) const
Check if this string ends with the given Suffix.
Definition StringRef.h:270
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:47
LLVM_ABI StringRef getVendorName() const
Get the vendor (second) component of the triple.
Definition Triple.cpp:1659
LLVM_ABI StringRef getOSName() const
Get the operating system (third) component of the triple.
Definition Triple.cpp:1664
OSType getOS() const
Get the parsed operating system type of this triple.
Definition Triple.h:445
ArchType getArch() const
Get the parsed architecture type of this triple.
Definition Triple.h:436
LLVM_ABI StringRef getEnvironmentName() const
Get the optional environment (fourth) component of the triple, or "" if empty.
Definition Triple.cpp:1670
bool isAMDGCN() const
Tests whether the target is AMDGCN.
Definition Triple.h:908
LLVM_ABI StringRef getArchName() const
Get the architecture (first) component of the triple.
Definition Triple.cpp:1655
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
A raw_ostream that writes to an std::string.
A raw_ostream that writes to an SmallVector or SmallString.
#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)
unsigned decodeFieldHoldCnt(unsigned Encoded, const IsaVersion &Version)
bool decodeDepCtr(unsigned Code, int &Id, StringRef &Name, unsigned &Val, bool &IsDefault, const MCSubtargetInfo &STI)
unsigned encodeFieldHoldCnt(unsigned Encoded, unsigned HoldCnt, const IsaVersion &Version)
unsigned encodeFieldVaSsrc(unsigned Encoded, unsigned VaSsrc)
unsigned encodeFieldVaVdst(unsigned Encoded, unsigned VaVdst)
unsigned decodeFieldSaSdst(unsigned Encoded)
unsigned getHoldCntBitMask(const IsaVersion &Version)
unsigned decodeFieldVaSdst(unsigned Encoded)
unsigned encodeFieldVmVsrc(unsigned Encoded, unsigned VmVsrc)
unsigned decodeFieldVaSsrc(unsigned Encoded)
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 VersionMinor
HSA metadata minor version.
constexpr uint32_t VersionMajor
HSA metadata major version.
unsigned getNumWavesPerEUWithNumVGPRs(const MCSubtargetInfo &STI, unsigned NumVGPRs, unsigned DynamicVGPRBlockSize)
unsigned getSGPRAllocGranule(const MCSubtargetInfo &STI)
unsigned getAddressableNumArchVGPRs(const MCSubtargetInfo &STI)
unsigned getArchVGPRAllocGranule()
For subtargets with a unified VGPR file and mixed ArchVGPR/AGPR usage, returns the allocation granule...
unsigned getEUsPerCU(const MCSubtargetInfo &STI)
unsigned getTotalNumSGPRs(const MCSubtargetInfo &STI)
unsigned getAddressableNumSGPRs(const MCSubtargetInfo &STI)
unsigned getMinFlatWorkGroupSize(const MCSubtargetInfo &STI)
unsigned getAddressableLocalMemorySize(const MCSubtargetInfo &STI)
unsigned getVGPREncodingGranule(const MCSubtargetInfo &STI, std::optional< bool > EnableWavefrontSize32)
unsigned getEncodedNumVGPRBlocks(const MCSubtargetInfo &STI, unsigned NumVGPRs, std::optional< bool > EnableWavefrontSize32)
unsigned getMaxWorkGroupsPerCU(const MCSubtargetInfo &STI, unsigned FlatWorkGroupSize)
unsigned getMinNumSGPRs(const MCSubtargetInfo &STI, unsigned WavesPerEU)
unsigned getMaxNumSGPRs(const MCSubtargetInfo &STI, unsigned WavesPerEU, bool Addressable)
unsigned getWavefrontSize(const MCSubtargetInfo &STI)
unsigned getWavesPerEUForWorkGroup(const MCSubtargetInfo &STI, unsigned FlatWorkGroupSize)
unsigned getInstCacheLineSize(const MCSubtargetInfo &STI)
static constexpr unsigned MaxDynamicVGPRBlocks
Maximum number of VGPR blocks that can be allocated in dynamic VGPR mode.
unsigned getSGPREncodingGranule(const MCSubtargetInfo &STI)
unsigned getTotalNumVGPRs(const MCSubtargetInfo &STI)
unsigned getMinNumVGPRs(const MCSubtargetInfo &STI, unsigned WavesPerEU, unsigned DynamicVGPRBlockSize)
unsigned getAddressableNumVGPRs(const MCSubtargetInfo &STI, unsigned DynamicVGPRBlockSize)
unsigned getWavesPerWorkGroup(const MCSubtargetInfo &STI, unsigned FlatWorkGroupSize)
unsigned getAllocatedNumVGPRBlocks(const MCSubtargetInfo &STI, unsigned NumVGPRs, unsigned DynamicVGPRBlockSize, std::optional< bool > EnableWavefrontSize32)
static TargetIDSetting getTargetIDSettingFromFeatureString(StringRef FeatureString)
unsigned getNumSGPRBlocks(const MCSubtargetInfo &STI, unsigned NumSGPRs)
unsigned getMaxWavesPerEU(const MCSubtargetInfo &STI)
unsigned getNumExtraSGPRs(const MCSubtargetInfo &STI, bool VCCUsed, bool FlatScrUsed, bool XNACKUsed)
unsigned getLocalMemorySize(const MCSubtargetInfo &STI)
unsigned getOccupancyWithNumSGPRs(unsigned SGPRs, unsigned MaxWaves, AMDGPUSubtarget::Generation Gen)
unsigned getMaxNumVGPRs(const MCSubtargetInfo &STI, unsigned WavesPerEU, unsigned DynamicVGPRBlockSize)
static unsigned getGranulatedNumRegisterBlocks(unsigned NumRegs, unsigned Granule)
unsigned getVGPRAllocGranule(const MCSubtargetInfo &STI, unsigned DynamicVGPRBlockSize, std::optional< bool > EnableWavefrontSize32)
unsigned getMinWavesPerEU(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)
bool msgDoesNotUseM0(int64_t MsgId, const MCSubtargetInfo &STI)
Returns true if the message does not use the m0 operand.
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
constexpr unsigned VOPD3_VGPR_BANK_MASKS[]
bool isPackedFP32Inst(unsigned Opc)
bool isGCN3Encoding(const MCSubtargetInfo &STI)
bool isInlinableLiteralBF16(int16_t Literal, bool HasInv2Pi)
bool isGFX10_BEncoding(const MCSubtargetInfo &STI)
bool isInlineValue(MCRegister Reg)
bool isGFX10_GFX11(const MCSubtargetInfo &STI)
bool isInlinableLiteralV216(uint32_t Literal, uint8_t OpType)
bool isPKFMACF16InlineConstant(uint32_t Literal, bool IsGFX11Plus)
LLVM_READONLY const MIMGInfo * getMIMGInfo(unsigned Opc)
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)
bool getWMMAIsXDL(unsigned Opc)
static std::optional< unsigned > convertSetRegImmToVgprMSBs(unsigned Imm, unsigned Simm16, bool HasSetregVGPRMSBFixup)
uint8_t wmmaScaleF8F6F4FormatToNumRegs(unsigned Fmt)
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
void initDefaultAMDKernelCodeT(AMDGPUMCKernelCodeT &KernelCode, const MCSubtargetInfo &STI)
bool shouldEmitConstantsToTextSection(const Triple &TT)
bool isInlinableLiteralV2I16(uint32_t Literal)
bool isDPMACCInstruction(unsigned Opc)
int getMTBUFElements(unsigned Opc)
bool isHi16Reg(MCRegister Reg, const MCRegisterInfo &MRI)
static int encodeCustomOperandVal(const CustomOperandVal &Op, int64_t InputVal)
unsigned getTemporalHintType(const MCInstrDesc TID)
int32_t getTotalNumVGPRs(bool has90AInsts, int32_t ArgNumAGPR, int32_t ArgNumVGPR)
bool isGFX10(const MCSubtargetInfo &STI)
static constexpr std::array< CanBeVOPD, 1<< VOPDXYKeyBits > buildVOPDXYLookup()
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)
const MCRegisterClass * getVGPRPhysRegClass(MCRegister Reg, const MCRegisterInfo &MRI)
unsigned encodeLoadcntDscnt(const IsaVersion &Version, const Waitcnt &Decoded)
bool getHasMatrixScale(unsigned Opc)
bool hasPackedD16(const MCSubtargetInfo &STI)
unsigned getStorecntBitMask(const IsaVersion &Version)
unsigned getLdsDwGranularity(const MCSubtargetInfo &ST)
bool isGFX940(const MCSubtargetInfo &STI)
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)
bool isGFX13(const MCSubtargetInfo &STI)
unsigned getAsynccntBitMask(const IsaVersion &Version)
bool hasValueInRangeLikeMetadata(const MDNode &MD, int64_t Val)
Checks if Val is inside MD, a !range-like metadata.
uint8_t mfmaScaleF8F6F4FormatToNumRegs(unsigned EncodingVal)
constexpr unsigned VOPDXYKeyBits
unsigned getVOPDOpcode(unsigned Opc, bool VOPD3)
bool isGroupSegment(const GlobalValue *GV)
LLVM_ABI 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)
CanBeVOPD getCanBeVOPD(unsigned Opc, unsigned EncodingFamily, bool VOPD3)
bool isVOPC64DPP(unsigned Opc)
int getMUBUFOpcode(unsigned BaseOpc, unsigned Elements)
bool getMAIIsGFX940XDL(unsigned Opc)
bool isSI(const MCSubtargetInfo &STI)
unsigned getDefaultAMDHSACodeObjectVersion()
bool isReadOnlySegment(const GlobalValue *GV)
Waitcnt decodeWaitcnt(const IsaVersion &Version, unsigned Encoded)
bool isArgPassedInSGPR(const Argument *A)
bool isIntrinsicAlwaysUniform(unsigned IntrID)
int getMUBUFBaseOpcode(unsigned Opc)
unsigned encodeWaitcnt(const IsaVersion &Version, const Waitcnt &Decoded)
unsigned getAMDHSACodeObjectVersion(const Module &M)
unsigned decodeLgkmcnt(const IsaVersion &Version, unsigned Waitcnt)
unsigned getWaitcntBitMask(const IsaVersion &Version)
LLVM_READONLY bool hasNamedOperand(uint64_t Opcode, OpName NamedIdx)
bool getVOP3IsSingle(unsigned Opc)
bool isGFX9(const MCSubtargetInfo &STI)
bool isDPALU_DPP32BitOpc(unsigned Opc)
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 isGFX90A(const MCSubtargetInfo &STI)
unsigned getSamplecntBitMask(const IsaVersion &Version)
unsigned getDefaultQueueImplicitArgPosition(unsigned CodeObjectVersion)
std::tuple< char, unsigned, unsigned > parseAsmPhysRegName(StringRef RegName)
Returns a valid charcode or 0 in the first entry if this is a valid physical register name.
bool getHasDepthExport(const Function &F)
bool isGFX8_GFX9_GFX10(const MCSubtargetInfo &STI)
bool getMUBUFHasVAddr(unsigned Opc)
bool isTrue16Inst(unsigned Opc)
unsigned getVGPREncodingMSBs(MCRegister Reg, const MCRegisterInfo &MRI)
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 isAsyncStore(unsigned Opc)
unsigned getDynamicVGPRBlockSize(const Function &F)
unsigned getKmcntBitMask(const IsaVersion &Version)
MCRegister getVGPRWithMSBs(MCRegister Reg, unsigned MSBs, const MCRegisterInfo &MRI)
If Reg is a low VGPR return a corresponding high VGPR with MSBs set.
unsigned getVmcntBitMask(const IsaVersion &Version)
bool isNotGFX10Plus(const MCSubtargetInfo &STI)
bool hasMAIInsts(const MCSubtargetInfo &STI)
unsigned getBitOp2(unsigned Opc)
bool isIntrinsicSourceOfDivergence(unsigned IntrID)
unsigned getXcntBitMask(const IsaVersion &Version)
bool isGenericAtomic(unsigned Opc)
const MFMA_F8F6F4_Info * getWMMA_F8F6F4_WithFormatArgs(unsigned FmtA, unsigned FmtB, unsigned F8F8Opcode)
bool isGFX8Plus(const MCSubtargetInfo &STI)
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)
unsigned decodeDscnt(const IsaVersion &Version, unsigned Waitcnt)
std::pair< const AMDGPU::OpName *, const AMDGPU::OpName * > getVGPRLoweringOperandTables(const MCInstrDesc &Desc)
bool hasG16(const MCSubtargetInfo &STI)
unsigned getAddrSizeMIMGOp(const MIMGBaseOpcodeInfo *BaseOpcode, const MIMGDimInfo *Dim, bool IsA16, bool IsG16Supported)
int getMTBUFOpcode(unsigned BaseOpc, unsigned Elements)
bool isGFX13Plus(const MCSubtargetInfo &STI)
unsigned getExpcntBitMask(const IsaVersion &Version)
bool hasArchitectedFlatScratch(const MCSubtargetInfo &STI)
int32_t getMCOpcode(uint32_t Opcode, unsigned Gen)
bool getMUBUFHasSoffset(unsigned Opc)
bool isNotGFX11Plus(const MCSubtargetInfo &STI)
bool isGFX11Plus(const MCSubtargetInfo &STI)
std::optional< unsigned > getInlineEncodingV2F16(uint32_t Literal)
bool isSISrcFPOperand(const MCInstrDesc &Desc, unsigned OpNo)
Is this floating-point operand?
std::tuple< char, unsigned, unsigned > parseAsmConstraintPhysReg(StringRef Constraint)
Returns a valid charcode or 0 in the first entry if this is a valid physical register constraint.
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)
static bool isValidRegPrefix(char C)
std::optional< int64_t > getSMRDEncodedOffset(const MCSubtargetInfo &ST, int64_t ByteOffset, bool IsBuffer, bool HasSOffset)
bool isGlobalSegment(const GlobalValue *GV)
int64_t encode32BitLiteral(int64_t Imm, OperandType Type, bool IsLit)
@ OPERAND_KIMM32
Operand with 32-bit immediate that uses the constant bus.
Definition SIDefines.h:236
@ OPERAND_REG_INLINE_C_LAST
Definition SIDefines.h:259
@ OPERAND_REG_IMM_V2FP16
Definition SIDefines.h:213
@ OPERAND_REG_INLINE_C_FP64
Definition SIDefines.h:227
@ OPERAND_REG_INLINE_C_BF16
Definition SIDefines.h:224
@ OPERAND_REG_INLINE_C_V2BF16
Definition SIDefines.h:229
@ OPERAND_REG_IMM_V2INT16
Definition SIDefines.h:215
@ OPERAND_REG_IMM_BF16
Definition SIDefines.h:210
@ OPERAND_REG_IMM_INT32
Operands with register, 32-bit, or 64-bit immediate.
Definition SIDefines.h:205
@ OPERAND_REG_IMM_V2BF16
Definition SIDefines.h:212
@ OPERAND_REG_INLINE_AC_FIRST
Definition SIDefines.h:261
@ OPERAND_REG_IMM_FP16
Definition SIDefines.h:211
@ OPERAND_REG_IMM_V2FP16_SPLAT
Definition SIDefines.h:214
@ OPERAND_REG_IMM_NOINLINE_V2FP16
Definition SIDefines.h:216
@ OPERAND_REG_IMM_FP64
Definition SIDefines.h:209
@ OPERAND_REG_INLINE_C_V2FP16
Definition SIDefines.h:230
@ OPERAND_REG_INLINE_AC_INT32
Operands with an AccVGPR register or inline constant.
Definition SIDefines.h:241
@ OPERAND_REG_INLINE_AC_FP32
Definition SIDefines.h:242
@ OPERAND_REG_IMM_V2INT32
Definition SIDefines.h:217
@ OPERAND_REG_IMM_FP32
Definition SIDefines.h:208
@ OPERAND_REG_INLINE_C_FIRST
Definition SIDefines.h:258
@ OPERAND_REG_INLINE_C_FP32
Definition SIDefines.h:226
@ OPERAND_REG_INLINE_AC_LAST
Definition SIDefines.h:262
@ OPERAND_REG_INLINE_C_INT32
Definition SIDefines.h:222
@ OPERAND_REG_INLINE_C_V2INT16
Definition SIDefines.h:228
@ OPERAND_REG_IMM_V2FP32
Definition SIDefines.h:218
@ OPERAND_REG_INLINE_AC_FP64
Definition SIDefines.h:243
@ OPERAND_REG_INLINE_C_FP16
Definition SIDefines.h:225
@ OPERAND_INLINE_SPLIT_BARRIER_INT32
Definition SIDefines.h:233
std::optional< unsigned > getPKFMACF16InlineEncoding(uint32_t Literal, bool IsGFX11Plus)
bool isNotGFX9Plus(const MCSubtargetInfo &STI)
bool isDPALU_DPP(const MCInstrDesc &OpDesc, const MCInstrInfo &MII, const MCSubtargetInfo &ST)
static constexpr unsigned getVOPDXYKey(unsigned VOPDOp, unsigned Subtarget, bool VOPD3)
constexpr auto VOPDXYLookup
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)
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.
unsigned encodeStorecntDscnt(const IsaVersion &Version, const Waitcnt &Decoded)
bool isGFX1250(const MCSubtargetInfo &STI)
const MIMGBaseOpcodeInfo * getMIMGBaseOpcode(unsigned Opc)
bool isVI(const MCSubtargetInfo &STI)
bool isTensorStore(unsigned Opc)
bool getMUBUFIsBufferInv(unsigned Opc)
bool supportsScaleOffset(const MCInstrInfo &MII, unsigned Opcode)
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 supportsWGP(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)
unsigned decodeStorecnt(const IsaVersion &Version, unsigned Waitcnt)
bool isGFX1250Plus(const MCSubtargetInfo &STI)
int getMaskedMIMGOp(unsigned Opc, unsigned NewChannels)
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)
int getVOPDFull(unsigned OpX, unsigned OpY, unsigned EncodingFamily, bool VOPD3)
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 decodeLoadcnt(const IsaVersion &Version, unsigned Waitcnt)
unsigned getMultigridSyncArgImplicitArgPosition(unsigned CodeObjectVersion)
bool isGFX9_GFX10_GFX11(const MCSubtargetInfo &STI)
bool isGFX9_GFX10(const MCSubtargetInfo &STI)
int getMUBUFElements(unsigned Opc)
const GcnBufferFormatInfo * getGcnBufferFormatInfo(uint8_t BitsPerComp, uint8_t NumComponents, uint8_t NumFormat, const MCSubtargetInfo &STI)
unsigned mapWMMA3AddrTo2AddrOpcode(unsigned Opc)
bool isPermlane16(unsigned Opc)
bool getMUBUFHasSrsrc(unsigned Opc)
unsigned getDscntBitMask(const IsaVersion &Version)
bool hasAny64BitVGPROperands(const MCInstrDesc &OpDesc, const MCInstrInfo &MII, const MCSubtargetInfo &ST)
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
@ AMDGPU_CS
Used for Mesa/AMDPAL compute shaders.
@ AMDGPU_VS
Used for Mesa vertex shaders, or AMDPAL last shader stage before rasterization (vertex shader if tess...
@ AMDGPU_KERNEL
Used for AMDGPU code object kernels.
@ AMDGPU_Gfx
Used for AMD graphics targets.
@ AMDGPU_CS_ChainPreserve
Used on AMDGPUs to give the middle-end more control over argument placement.
@ AMDGPU_HS
Used for Mesa/AMDPAL hull shaders (= tessellation control shaders).
@ AMDGPU_GS
Used for Mesa/AMDPAL geometry shaders.
@ AMDGPU_CS_Chain
Used on AMDGPUs to give the middle-end more control over argument placement.
@ AMDGPU_PS
Used for Mesa/AMDPAL pixel shaders.
@ SPIR_KERNEL
Used for SPIR kernel functions.
@ AMDGPU_ES
Used for AMDPAL shader stage before geometry shader if geometry is in use.
@ AMDGPU_LS
Used for AMDPAL vertex shader if tessellation is in use.
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
@ ELFABIVERSION_AMDGPU_HSA_V4
Definition ELF.h:384
@ ELFABIVERSION_AMDGPU_HSA_V5
Definition ELF.h:385
@ ELFABIVERSION_AMDGPU_HSA_V6
Definition ELF.h:386
initializer< Ty > init(const Ty &Val)
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > extract_or_null(Y &&MD)
Extract a Value from Metadata, allowing null.
Definition Metadata.h:683
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > extract(Y &&MD)
Extract a Value from Metadata.
Definition Metadata.h:668
This is an optimization pass for GlobalISel generic memory operations.
@ Low
Lower the current thread's priority such that it does not affect foreground tasks significantly.
Definition Threading.h:280
@ Offset
Definition DWP.cpp:558
constexpr T rotr(T V, int R)
Definition bit.h:399
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1738
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
Definition MathExtras.h:165
testing::Matcher< const detail::ErrorHolder & > Failed()
Definition Error.h:198
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:546
std::string utostr(uint64_t X, bool isNeg=false)
constexpr auto equal_to(T &&Arg)
Functor variant of std::equal_to that can be used as a UnaryPredicate in functional algorithms like a...
Definition STLExtras.h:2172
Op::Description Desc
FunctionAddr VTableAddr uintptr_t uintptr_t Version
Definition InstrProf.h:334
constexpr uint32_t Hi_32(uint64_t Value)
Return the high 32 bits of a 64 bit value.
Definition MathExtras.h:150
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:163
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition Alignment.h:144
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
Definition MathExtras.h:189
constexpr uint32_t Lo_32(uint64_t Value)
Return the low 32 bits of a 64 bit value.
Definition MathExtras.h:155
LLVM_ABI 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:394
To bit_cast(const From &from) noexcept
Definition bit.h:90
DWARFExpression::Operation Op
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
constexpr int countr_zero_constexpr(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
Definition bit.h:190
constexpr T maskTrailingOnes(unsigned N)
Create a bitmask with the N right-most bits set to 1, and all other bits set to 0.
Definition MathExtras.h:77
@ AlwaysUniform
The result value is always uniform.
Definition Uniformity.h:23
@ Default
The result value is uniform if and only if all operands are uniform.
Definition Uniformity.h:20
#define N
AMD Kernel Code Object (amd_kernel_code_t).
static std::tuple< typename Fields::ValueType... > decode(uint64_t Encoded)
Instruction set architecture version.