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 8 blocks of VGPRs.
1478 return 8 * getVGPRAllocGranule(STI, DynamicVGPRBlockSize);
1479 return getAddressableNumArchVGPRs(STI);
1480}
1481
1483 unsigned NumVGPRs,
1484 unsigned DynamicVGPRBlockSize) {
1486 NumVGPRs, getVGPRAllocGranule(STI, DynamicVGPRBlockSize),
1488}
1489
1490unsigned getNumWavesPerEUWithNumVGPRs(unsigned NumVGPRs, unsigned Granule,
1491 unsigned MaxWaves,
1492 unsigned TotalNumVGPRs) {
1493 if (NumVGPRs < Granule)
1494 return MaxWaves;
1495 unsigned RoundedRegs = alignTo(NumVGPRs, Granule);
1496 return std::min(std::max(TotalNumVGPRs / RoundedRegs, 1u), MaxWaves);
1497}
1498
1499unsigned getOccupancyWithNumSGPRs(unsigned SGPRs, unsigned MaxWaves,
1501 if (Gen >= AMDGPUSubtarget::GFX10)
1502 return MaxWaves;
1503
1505 if (SGPRs <= 80)
1506 return 10;
1507 if (SGPRs <= 88)
1508 return 9;
1509 if (SGPRs <= 100)
1510 return 8;
1511 return 7;
1512 }
1513 if (SGPRs <= 48)
1514 return 10;
1515 if (SGPRs <= 56)
1516 return 9;
1517 if (SGPRs <= 64)
1518 return 8;
1519 if (SGPRs <= 72)
1520 return 7;
1521 if (SGPRs <= 80)
1522 return 6;
1523 return 5;
1524}
1525
1526unsigned getMinNumVGPRs(const MCSubtargetInfo &STI, unsigned WavesPerEU,
1527 unsigned DynamicVGPRBlockSize) {
1528 assert(WavesPerEU != 0);
1529
1530 // In dynamic VGPR mode, (static) occupancy does not depend on VGPR usage,
1531 // so getMaxNumVGPRs does not depend on WavesPerEU, and thus we need to return
1532 // zero because there is no nonzero VGPR usage N where going below N
1533 // achieves higher (static) occupancy.
1534 bool DynamicVGPREnabled = (DynamicVGPRBlockSize != 0);
1535 if (DynamicVGPREnabled)
1536 return 0;
1537
1538 unsigned MaxWavesPerEU = getMaxWavesPerEU(STI);
1539 if (WavesPerEU >= MaxWavesPerEU)
1540 return 0;
1541
1542 unsigned TotNumVGPRs = getTotalNumVGPRs(STI);
1543 unsigned AddrsableNumVGPRs =
1544 getAddressableNumVGPRs(STI, DynamicVGPRBlockSize);
1545 unsigned Granule = getVGPRAllocGranule(STI, DynamicVGPRBlockSize);
1546 unsigned MaxNumVGPRs = alignDown(TotNumVGPRs / WavesPerEU, Granule);
1547
1548 if (MaxNumVGPRs == alignDown(TotNumVGPRs / MaxWavesPerEU, Granule))
1549 return 0;
1550
1551 unsigned MinWavesPerEU = getNumWavesPerEUWithNumVGPRs(STI, AddrsableNumVGPRs,
1552 DynamicVGPRBlockSize);
1553 if (WavesPerEU < MinWavesPerEU)
1554 return getMinNumVGPRs(STI, MinWavesPerEU, DynamicVGPRBlockSize);
1555
1556 unsigned MaxNumVGPRsNext = alignDown(TotNumVGPRs / (WavesPerEU + 1), Granule);
1557 unsigned MinNumVGPRs = 1 + std::min(MaxNumVGPRs - Granule, MaxNumVGPRsNext);
1558 return std::min(MinNumVGPRs, AddrsableNumVGPRs);
1559}
1560
1561unsigned getMaxNumVGPRs(const MCSubtargetInfo &STI, unsigned WavesPerEU,
1562 unsigned DynamicVGPRBlockSize) {
1563 assert(WavesPerEU != 0);
1564
1565 // In dynamic VGPR mode, WavesPerEU does not imply a VGPR limit.
1566 bool DynamicVGPREnabled = (DynamicVGPRBlockSize != 0);
1567 unsigned MaxNumVGPRs =
1568 DynamicVGPREnabled
1569 ? getTotalNumVGPRs(STI)
1570 : alignDown(getTotalNumVGPRs(STI) / WavesPerEU,
1571 getVGPRAllocGranule(STI, DynamicVGPRBlockSize));
1572 unsigned AddressableNumVGPRs =
1573 getAddressableNumVGPRs(STI, DynamicVGPRBlockSize);
1574 return std::min(MaxNumVGPRs, AddressableNumVGPRs);
1575}
1576
1577unsigned getEncodedNumVGPRBlocks(const MCSubtargetInfo &STI, unsigned NumVGPRs,
1578 std::optional<bool> EnableWavefrontSize32) {
1580 NumVGPRs, getVGPREncodingGranule(STI, EnableWavefrontSize32)) -
1581 1;
1582}
1583
1585 unsigned NumVGPRs,
1586 unsigned DynamicVGPRBlockSize,
1587 std::optional<bool> EnableWavefrontSize32) {
1589 NumVGPRs,
1590 getVGPRAllocGranule(STI, DynamicVGPRBlockSize, EnableWavefrontSize32));
1591}
1592} // end namespace IsaInfo
1593
1595 const MCSubtargetInfo &STI) {
1597 KernelCode.amd_kernel_code_version_major = 1;
1598 KernelCode.amd_kernel_code_version_minor = 2;
1599 KernelCode.amd_machine_kind = 1; // AMD_MACHINE_KIND_AMDGPU
1600 KernelCode.amd_machine_version_major = Version.Major;
1601 KernelCode.amd_machine_version_minor = Version.Minor;
1602 KernelCode.amd_machine_version_stepping = Version.Stepping;
1604 if (STI.getFeatureBits().test(FeatureWavefrontSize32)) {
1605 KernelCode.wavefront_size = 5;
1607 } else {
1608 KernelCode.wavefront_size = 6;
1609 }
1610
1611 // If the code object does not support indirect functions, then the value must
1612 // be 0xffffffff.
1613 KernelCode.call_convention = -1;
1614
1615 // These alignment values are specified in powers of two, so alignment =
1616 // 2^n. The minimum alignment is 2^4 = 16.
1617 KernelCode.kernarg_segment_alignment = 4;
1618 KernelCode.group_segment_alignment = 4;
1619 KernelCode.private_segment_alignment = 4;
1620
1621 if (Version.Major >= 10) {
1622 KernelCode.compute_pgm_resource_registers |=
1623 S_00B848_WGP_MODE(STI.getFeatureBits().test(FeatureCuMode) ? 0 : 1) |
1625 }
1626}
1627
1630}
1631
1634}
1635
1637 unsigned AS = GV->getAddressSpace();
1638 return AS == AMDGPUAS::CONSTANT_ADDRESS ||
1640}
1641
1643 return TT.getArch() == Triple::r600;
1644}
1645
1646static bool isValidRegPrefix(char C) {
1647 return C == 'v' || C == 's' || C == 'a';
1648}
1649
1650std::tuple<char, unsigned, unsigned> parseAsmPhysRegName(StringRef RegName) {
1651 char Kind = RegName.front();
1652 if (!isValidRegPrefix(Kind))
1653 return {};
1654
1655 RegName = RegName.drop_front();
1656 if (RegName.consume_front("[")) {
1657 unsigned Idx, End;
1658 bool Failed = RegName.consumeInteger(10, Idx);
1659 Failed |= !RegName.consume_front(":");
1660 Failed |= RegName.consumeInteger(10, End);
1661 Failed |= !RegName.consume_back("]");
1662 if (!Failed) {
1663 unsigned NumRegs = End - Idx + 1;
1664 if (NumRegs > 1)
1665 return {Kind, Idx, NumRegs};
1666 }
1667 } else {
1668 unsigned Idx;
1669 bool Failed = RegName.getAsInteger(10, Idx);
1670 if (!Failed)
1671 return {Kind, Idx, 1};
1672 }
1673
1674 return {};
1675}
1676
1677std::tuple<char, unsigned, unsigned>
1679 StringRef RegName = Constraint;
1680 if (!RegName.consume_front("{") || !RegName.consume_back("}"))
1681 return {};
1683}
1684
1685std::pair<unsigned, unsigned>
1687 std::pair<unsigned, unsigned> Default,
1688 bool OnlyFirstRequired) {
1689 if (auto Attr = getIntegerPairAttribute(F, Name, OnlyFirstRequired))
1690 return {Attr->first, Attr->second.value_or(Default.second)};
1691 return Default;
1692}
1693
1694std::optional<std::pair<unsigned, std::optional<unsigned>>>
1696 bool OnlyFirstRequired) {
1697 Attribute A = F.getFnAttribute(Name);
1698 if (!A.isStringAttribute())
1699 return std::nullopt;
1700
1701 LLVMContext &Ctx = F.getContext();
1702 std::pair<unsigned, std::optional<unsigned>> Ints;
1703 std::pair<StringRef, StringRef> Strs = A.getValueAsString().split(',');
1704 if (Strs.first.trim().getAsInteger(0, Ints.first)) {
1705 Ctx.emitError("can't parse first integer attribute " + Name);
1706 return std::nullopt;
1707 }
1708 unsigned Second = 0;
1709 if (Strs.second.trim().getAsInteger(0, Second)) {
1710 if (!OnlyFirstRequired || !Strs.second.trim().empty()) {
1711 Ctx.emitError("can't parse second integer attribute " + Name);
1712 return std::nullopt;
1713 }
1714 } else {
1715 Ints.second = Second;
1716 }
1717
1718 return Ints;
1719}
1720
1722 unsigned Size,
1723 unsigned DefaultVal) {
1724 std::optional<SmallVector<unsigned>> R =
1726 return R.has_value() ? *R : SmallVector<unsigned>(Size, DefaultVal);
1727}
1728
1729std::optional<SmallVector<unsigned>>
1731 assert(Size > 2);
1732 LLVMContext &Ctx = F.getContext();
1733
1734 Attribute A = F.getFnAttribute(Name);
1735 if (!A.isValid())
1736 return std::nullopt;
1737 if (!A.isStringAttribute()) {
1738 Ctx.emitError(Name + " is not a string attribute");
1739 return std::nullopt;
1740 }
1741
1743
1744 StringRef S = A.getValueAsString();
1745 unsigned i = 0;
1746 for (; !S.empty() && i < Size; i++) {
1747 std::pair<StringRef, StringRef> Strs = S.split(',');
1748 unsigned IntVal;
1749 if (Strs.first.trim().getAsInteger(0, IntVal)) {
1750 Ctx.emitError("can't parse integer attribute " + Strs.first + " in " +
1751 Name);
1752 return std::nullopt;
1753 }
1754 Vals[i] = IntVal;
1755 S = Strs.second;
1756 }
1757
1758 if (!S.empty() || i < Size) {
1759 Ctx.emitError("attribute " + Name +
1760 " has incorrect number of integers; expected " +
1762 return std::nullopt;
1763 }
1764 return Vals;
1765}
1766
1767bool hasValueInRangeLikeMetadata(const MDNode &MD, int64_t Val) {
1768 assert((MD.getNumOperands() % 2 == 0) && "invalid number of operands!");
1769 for (unsigned I = 0, E = MD.getNumOperands() / 2; I != E; ++I) {
1770 auto Low =
1771 mdconst::extract<ConstantInt>(MD.getOperand(2 * I + 0))->getValue();
1772 auto High =
1773 mdconst::extract<ConstantInt>(MD.getOperand(2 * I + 1))->getValue();
1774 // There are two types of [A; B) ranges:
1775 // A < B, e.g. [4; 5) which is a range that only includes 4.
1776 // A > B, e.g. [5; 4) which is a range that wraps around and includes
1777 // everything except 4.
1778 if (Low.ult(High)) {
1779 if (Low.ule(Val) && High.ugt(Val))
1780 return true;
1781 } else {
1782 if (Low.uge(Val) && High.ult(Val))
1783 return true;
1784 }
1785 }
1786
1787 return false;
1788}
1789
1791 return (1 << (getVmcntBitWidthLo(Version.Major) +
1792 getVmcntBitWidthHi(Version.Major))) -
1793 1;
1794}
1795
1797 return (1 << getLoadcntBitWidth(Version.Major)) - 1;
1798}
1799
1801 return (1 << getSamplecntBitWidth(Version.Major)) - 1;
1802}
1803
1805 return (1 << getBvhcntBitWidth(Version.Major)) - 1;
1806}
1807
1809 return (1 << getExpcntBitWidth(Version.Major)) - 1;
1810}
1811
1813 return (1 << getLgkmcntBitWidth(Version.Major)) - 1;
1814}
1815
1817 return (1 << getDscntBitWidth(Version.Major)) - 1;
1818}
1819
1821 return (1 << getKmcntBitWidth(Version.Major)) - 1;
1822}
1823
1825 return (1 << getXcntBitWidth(Version.Major, Version.Minor)) - 1;
1826}
1827
1829 return (1 << getAsynccntBitWidth(Version.Major, Version.Minor)) - 1;
1830}
1831
1833 return (1 << getStorecntBitWidth(Version.Major)) - 1;
1834}
1835
1837 bool HasExtendedWaitCounts = IV.Major >= 12;
1838 if (HasExtendedWaitCounts) {
1841 } else {
1844 }
1854}
1855
1857 unsigned VmcntLo = getBitMask(getVmcntBitShiftLo(Version.Major),
1858 getVmcntBitWidthLo(Version.Major));
1859 unsigned Expcnt = getBitMask(getExpcntBitShift(Version.Major),
1860 getExpcntBitWidth(Version.Major));
1861 unsigned Lgkmcnt = getBitMask(getLgkmcntBitShift(Version.Major),
1862 getLgkmcntBitWidth(Version.Major));
1863 unsigned VmcntHi = getBitMask(getVmcntBitShiftHi(Version.Major),
1864 getVmcntBitWidthHi(Version.Major));
1865 return VmcntLo | Expcnt | Lgkmcnt | VmcntHi;
1866}
1867
1868unsigned decodeVmcnt(const IsaVersion &Version, unsigned Waitcnt) {
1869 unsigned VmcntLo = unpackBits(Waitcnt, getVmcntBitShiftLo(Version.Major),
1870 getVmcntBitWidthLo(Version.Major));
1871 unsigned VmcntHi = unpackBits(Waitcnt, getVmcntBitShiftHi(Version.Major),
1872 getVmcntBitWidthHi(Version.Major));
1873 return VmcntLo | VmcntHi << getVmcntBitWidthLo(Version.Major);
1874}
1875
1876unsigned decodeExpcnt(const IsaVersion &Version, unsigned Waitcnt) {
1877 return unpackBits(Waitcnt, getExpcntBitShift(Version.Major),
1878 getExpcntBitWidth(Version.Major));
1879}
1880
1881unsigned decodeLgkmcnt(const IsaVersion &Version, unsigned Waitcnt) {
1882 return unpackBits(Waitcnt, getLgkmcntBitShift(Version.Major),
1883 getLgkmcntBitWidth(Version.Major));
1884}
1885
1886unsigned decodeLoadcnt(const IsaVersion &Version, unsigned Waitcnt) {
1887 return unpackBits(Waitcnt, getLoadcntStorecntBitShift(Version.Major),
1888 getLoadcntBitWidth(Version.Major));
1889}
1890
1891unsigned decodeStorecnt(const IsaVersion &Version, unsigned Waitcnt) {
1892 return unpackBits(Waitcnt, getLoadcntStorecntBitShift(Version.Major),
1893 getStorecntBitWidth(Version.Major));
1894}
1895
1896unsigned decodeDscnt(const IsaVersion &Version, unsigned Waitcnt) {
1897 return unpackBits(Waitcnt, getDscntBitShift(Version.Major),
1898 getDscntBitWidth(Version.Major));
1899}
1900
1901void decodeWaitcnt(const IsaVersion &Version, unsigned Waitcnt, unsigned &Vmcnt,
1902 unsigned &Expcnt, unsigned &Lgkmcnt) {
1903 Vmcnt = decodeVmcnt(Version, Waitcnt);
1904 Expcnt = decodeExpcnt(Version, Waitcnt);
1905 Lgkmcnt = decodeLgkmcnt(Version, Waitcnt);
1906}
1907
1908unsigned encodeVmcnt(const IsaVersion &Version, unsigned Waitcnt,
1909 unsigned Vmcnt) {
1910 Waitcnt = packBits(Vmcnt, Waitcnt, getVmcntBitShiftLo(Version.Major),
1911 getVmcntBitWidthLo(Version.Major));
1912 return packBits(Vmcnt >> getVmcntBitWidthLo(Version.Major), Waitcnt,
1913 getVmcntBitShiftHi(Version.Major),
1914 getVmcntBitWidthHi(Version.Major));
1915}
1916
1917unsigned encodeExpcnt(const IsaVersion &Version, unsigned Waitcnt,
1918 unsigned Expcnt) {
1919 return packBits(Expcnt, Waitcnt, getExpcntBitShift(Version.Major),
1920 getExpcntBitWidth(Version.Major));
1921}
1922
1923unsigned encodeLgkmcnt(const IsaVersion &Version, unsigned Waitcnt,
1924 unsigned Lgkmcnt) {
1925 return packBits(Lgkmcnt, Waitcnt, getLgkmcntBitShift(Version.Major),
1926 getLgkmcntBitWidth(Version.Major));
1927}
1928
1929unsigned encodeWaitcnt(const IsaVersion &Version, unsigned Vmcnt,
1930 unsigned Expcnt, unsigned Lgkmcnt) {
1931 unsigned Waitcnt = getWaitcntBitMask(Version);
1933 Waitcnt = encodeExpcnt(Version, Waitcnt, Expcnt);
1934 Waitcnt = encodeLgkmcnt(Version, Waitcnt, Lgkmcnt);
1935 return Waitcnt;
1936}
1937
1939 bool IsStore) {
1940 unsigned Dscnt = getBitMask(getDscntBitShift(Version.Major),
1941 getDscntBitWidth(Version.Major));
1942 if (IsStore) {
1943 unsigned Storecnt = getBitMask(getLoadcntStorecntBitShift(Version.Major),
1944 getStorecntBitWidth(Version.Major));
1945 return Dscnt | Storecnt;
1946 }
1947 unsigned Loadcnt = getBitMask(getLoadcntStorecntBitShift(Version.Major),
1948 getLoadcntBitWidth(Version.Major));
1949 return Dscnt | Loadcnt;
1950}
1951
1952static unsigned encodeLoadcnt(const IsaVersion &Version, unsigned Waitcnt,
1953 unsigned Loadcnt) {
1954 return packBits(Loadcnt, Waitcnt, getLoadcntStorecntBitShift(Version.Major),
1955 getLoadcntBitWidth(Version.Major));
1956}
1957
1958static unsigned encodeStorecnt(const IsaVersion &Version, unsigned Waitcnt,
1959 unsigned Storecnt) {
1960 return packBits(Storecnt, Waitcnt, getLoadcntStorecntBitShift(Version.Major),
1961 getStorecntBitWidth(Version.Major));
1962}
1963
1964static unsigned encodeDscnt(const IsaVersion &Version, unsigned Waitcnt,
1965 unsigned Dscnt) {
1966 return packBits(Dscnt, Waitcnt, getDscntBitShift(Version.Major),
1967 getDscntBitWidth(Version.Major));
1968}
1969
1970unsigned encodeLoadcntDscnt(const IsaVersion &Version, unsigned Loadcnt,
1971 unsigned Dscnt) {
1972 unsigned Waitcnt = getCombinedCountBitMask(Version, false);
1973 Waitcnt = encodeLoadcnt(Version, Waitcnt, Loadcnt);
1975 return Waitcnt;
1976}
1977
1978unsigned encodeStorecntDscnt(const IsaVersion &Version, unsigned Storecnt,
1979 unsigned Dscnt) {
1980 unsigned Waitcnt = getCombinedCountBitMask(Version, true);
1981 Waitcnt = encodeStorecnt(Version, Waitcnt, Storecnt);
1983 return Waitcnt;
1984}
1985
1986//===----------------------------------------------------------------------===//
1987// Custom Operand Values
1988//===----------------------------------------------------------------------===//
1989
1991 int Size,
1992 const MCSubtargetInfo &STI) {
1993 unsigned Enc = 0;
1994 for (int Idx = 0; Idx < Size; ++Idx) {
1995 const auto &Op = Opr[Idx];
1996 if (Op.isSupported(STI))
1997 Enc |= Op.encode(Op.Default);
1998 }
1999 return Enc;
2000}
2001
2003 int Size, unsigned Code,
2004 bool &HasNonDefaultVal,
2005 const MCSubtargetInfo &STI) {
2006 unsigned UsedOprMask = 0;
2007 HasNonDefaultVal = false;
2008 for (int Idx = 0; Idx < Size; ++Idx) {
2009 const auto &Op = Opr[Idx];
2010 if (!Op.isSupported(STI))
2011 continue;
2012 UsedOprMask |= Op.getMask();
2013 unsigned Val = Op.decode(Code);
2014 if (!Op.isValid(Val))
2015 return false;
2016 HasNonDefaultVal |= (Val != Op.Default);
2017 }
2018 return (Code & ~UsedOprMask) == 0;
2019}
2020
2021static bool decodeCustomOperand(const CustomOperandVal *Opr, int Size,
2022 unsigned Code, int &Idx, StringRef &Name,
2023 unsigned &Val, bool &IsDefault,
2024 const MCSubtargetInfo &STI) {
2025 while (Idx < Size) {
2026 const auto &Op = Opr[Idx++];
2027 if (Op.isSupported(STI)) {
2028 Name = Op.Name;
2029 Val = Op.decode(Code);
2030 IsDefault = (Val == Op.Default);
2031 return true;
2032 }
2033 }
2034
2035 return false;
2036}
2037
2039 int64_t InputVal) {
2040 if (InputVal < 0 || InputVal > Op.Max)
2041 return OPR_VAL_INVALID;
2042 return Op.encode(InputVal);
2043}
2044
2045static int encodeCustomOperand(const CustomOperandVal *Opr, int Size,
2046 const StringRef Name, int64_t InputVal,
2047 unsigned &UsedOprMask,
2048 const MCSubtargetInfo &STI) {
2049 int InvalidId = OPR_ID_UNKNOWN;
2050 for (int Idx = 0; Idx < Size; ++Idx) {
2051 const auto &Op = Opr[Idx];
2052 if (Op.Name == Name) {
2053 if (!Op.isSupported(STI)) {
2054 InvalidId = OPR_ID_UNSUPPORTED;
2055 continue;
2056 }
2057 auto OprMask = Op.getMask();
2058 if (OprMask & UsedOprMask)
2059 return OPR_ID_DUPLICATE;
2060 UsedOprMask |= OprMask;
2061 return encodeCustomOperandVal(Op, InputVal);
2062 }
2063 }
2064 return InvalidId;
2065}
2066
2067//===----------------------------------------------------------------------===//
2068// DepCtr
2069//===----------------------------------------------------------------------===//
2070
2071namespace DepCtr {
2072
2074 static int Default = -1;
2075 if (Default == -1)
2077 return Default;
2078}
2079
2080bool isSymbolicDepCtrEncoding(unsigned Code, bool &HasNonDefaultVal,
2081 const MCSubtargetInfo &STI) {
2083 HasNonDefaultVal, STI);
2084}
2085
2086bool decodeDepCtr(unsigned Code, int &Id, StringRef &Name, unsigned &Val,
2087 bool &IsDefault, const MCSubtargetInfo &STI) {
2088 return decodeCustomOperand(DepCtrInfo, DEP_CTR_SIZE, Code, Id, Name, Val,
2089 IsDefault, STI);
2090}
2091
2092int encodeDepCtr(const StringRef Name, int64_t Val, unsigned &UsedOprMask,
2093 const MCSubtargetInfo &STI) {
2094 return encodeCustomOperand(DepCtrInfo, DEP_CTR_SIZE, Name, Val, UsedOprMask,
2095 STI);
2096}
2097
2098unsigned getVaVdstBitMask() { return (1 << getVaVdstBitWidth()) - 1; }
2099
2100unsigned getVaSdstBitMask() { return (1 << getVaSdstBitWidth()) - 1; }
2101
2102unsigned getVaSsrcBitMask() { return (1 << getVaSsrcBitWidth()) - 1; }
2103
2105 return (1 << getHoldCntWidth(Version.Major, Version.Minor)) - 1;
2106}
2107
2108unsigned getVmVsrcBitMask() { return (1 << getVmVsrcBitWidth()) - 1; }
2109
2110unsigned getVaVccBitMask() { return (1 << getVaVccBitWidth()) - 1; }
2111
2112unsigned getSaSdstBitMask() { return (1 << getSaSdstBitWidth()) - 1; }
2113
2114unsigned decodeFieldVmVsrc(unsigned Encoded) {
2115 return unpackBits(Encoded, getVmVsrcBitShift(), getVmVsrcBitWidth());
2116}
2117
2118unsigned decodeFieldVaVdst(unsigned Encoded) {
2119 return unpackBits(Encoded, getVaVdstBitShift(), getVaVdstBitWidth());
2120}
2121
2122unsigned decodeFieldSaSdst(unsigned Encoded) {
2123 return unpackBits(Encoded, getSaSdstBitShift(), getSaSdstBitWidth());
2124}
2125
2126unsigned decodeFieldVaSdst(unsigned Encoded) {
2127 return unpackBits(Encoded, getVaSdstBitShift(), getVaSdstBitWidth());
2128}
2129
2130unsigned decodeFieldVaVcc(unsigned Encoded) {
2131 return unpackBits(Encoded, getVaVccBitShift(), getVaVccBitWidth());
2132}
2133
2134unsigned decodeFieldVaSsrc(unsigned Encoded) {
2135 return unpackBits(Encoded, getVaSsrcBitShift(), getVaSsrcBitWidth());
2136}
2137
2138unsigned decodeFieldHoldCnt(unsigned Encoded, const IsaVersion &Version) {
2139 return unpackBits(Encoded, getHoldCntBitShift(),
2140 getHoldCntWidth(Version.Major, Version.Minor));
2141}
2142
2143unsigned encodeFieldVmVsrc(unsigned Encoded, unsigned VmVsrc) {
2144 return packBits(VmVsrc, Encoded, getVmVsrcBitShift(), getVmVsrcBitWidth());
2145}
2146
2147unsigned encodeFieldVmVsrc(unsigned VmVsrc, const MCSubtargetInfo &STI) {
2148 unsigned Encoded = getDefaultDepCtrEncoding(STI);
2149 return encodeFieldVmVsrc(Encoded, VmVsrc);
2150}
2151
2152unsigned encodeFieldVaVdst(unsigned Encoded, unsigned VaVdst) {
2153 return packBits(VaVdst, Encoded, getVaVdstBitShift(), getVaVdstBitWidth());
2154}
2155
2156unsigned encodeFieldVaVdst(unsigned VaVdst, const MCSubtargetInfo &STI) {
2157 unsigned Encoded = getDefaultDepCtrEncoding(STI);
2158 return encodeFieldVaVdst(Encoded, VaVdst);
2159}
2160
2161unsigned encodeFieldSaSdst(unsigned Encoded, unsigned SaSdst) {
2162 return packBits(SaSdst, Encoded, getSaSdstBitShift(), getSaSdstBitWidth());
2163}
2164
2165unsigned encodeFieldSaSdst(unsigned SaSdst, const MCSubtargetInfo &STI) {
2166 unsigned Encoded = getDefaultDepCtrEncoding(STI);
2167 return encodeFieldSaSdst(Encoded, SaSdst);
2168}
2169
2170unsigned encodeFieldVaSdst(unsigned Encoded, unsigned VaSdst) {
2171 return packBits(VaSdst, Encoded, getVaSdstBitShift(), getVaSdstBitWidth());
2172}
2173
2174unsigned encodeFieldVaSdst(unsigned VaSdst, const MCSubtargetInfo &STI) {
2175 unsigned Encoded = getDefaultDepCtrEncoding(STI);
2176 return encodeFieldVaSdst(Encoded, VaSdst);
2177}
2178
2179unsigned encodeFieldVaVcc(unsigned Encoded, unsigned VaVcc) {
2180 return packBits(VaVcc, Encoded, getVaVccBitShift(), getVaVccBitWidth());
2181}
2182
2183unsigned encodeFieldVaVcc(unsigned VaVcc, const MCSubtargetInfo &STI) {
2184 unsigned Encoded = getDefaultDepCtrEncoding(STI);
2185 return encodeFieldVaVcc(Encoded, VaVcc);
2186}
2187
2188unsigned encodeFieldVaSsrc(unsigned Encoded, unsigned VaSsrc) {
2189 return packBits(VaSsrc, Encoded, getVaSsrcBitShift(), getVaSsrcBitWidth());
2190}
2191
2192unsigned encodeFieldVaSsrc(unsigned VaSsrc, const MCSubtargetInfo &STI) {
2193 unsigned Encoded = getDefaultDepCtrEncoding(STI);
2194 return encodeFieldVaSsrc(Encoded, VaSsrc);
2195}
2196
2197unsigned encodeFieldHoldCnt(unsigned Encoded, unsigned HoldCnt,
2198 const IsaVersion &Version) {
2199 return packBits(HoldCnt, Encoded, getHoldCntBitShift(),
2200 getHoldCntWidth(Version.Major, Version.Minor));
2201}
2202
2203unsigned encodeFieldHoldCnt(unsigned HoldCnt, const MCSubtargetInfo &STI) {
2204 unsigned Encoded = getDefaultDepCtrEncoding(STI);
2205 return encodeFieldHoldCnt(Encoded, HoldCnt, getIsaVersion(STI.getCPU()));
2206}
2207
2208} // namespace DepCtr
2209
2210//===----------------------------------------------------------------------===//
2211// exp tgt
2212//===----------------------------------------------------------------------===//
2213
2214namespace Exp {
2215
2216struct ExpTgt {
2218 unsigned Tgt;
2219 unsigned MaxIndex;
2220};
2221
2222// clang-format off
2223static constexpr ExpTgt ExpTgtInfo[] = {
2224 {{"null"}, ET_NULL, ET_NULL_MAX_IDX},
2225 {{"mrtz"}, ET_MRTZ, ET_MRTZ_MAX_IDX},
2226 {{"prim"}, ET_PRIM, ET_PRIM_MAX_IDX},
2227 {{"mrt"}, ET_MRT0, ET_MRT_MAX_IDX},
2228 {{"pos"}, ET_POS0, ET_POS_MAX_IDX},
2229 {{"dual_src_blend"},ET_DUAL_SRC_BLEND0, ET_DUAL_SRC_BLEND_MAX_IDX},
2230 {{"param"}, ET_PARAM0, ET_PARAM_MAX_IDX},
2231};
2232// clang-format on
2233
2234bool getTgtName(unsigned Id, StringRef &Name, int &Index) {
2235 for (const ExpTgt &Val : ExpTgtInfo) {
2236 if (Val.Tgt <= Id && Id <= Val.Tgt + Val.MaxIndex) {
2237 Index = (Val.MaxIndex == 0) ? -1 : (Id - Val.Tgt);
2238 Name = Val.Name;
2239 return true;
2240 }
2241 }
2242 return false;
2243}
2244
2245unsigned getTgtId(const StringRef Name) {
2246
2247 for (const ExpTgt &Val : ExpTgtInfo) {
2248 if (Val.MaxIndex == 0 && Name == Val.Name)
2249 return Val.Tgt;
2250
2251 if (Val.MaxIndex > 0 && Name.starts_with(Val.Name)) {
2252 StringRef Suffix = Name.drop_front(Val.Name.size());
2253
2254 unsigned Id;
2255 if (Suffix.getAsInteger(10, Id) || Id > Val.MaxIndex)
2256 return ET_INVALID;
2257
2258 // Disable leading zeroes
2259 if (Suffix.size() > 1 && Suffix[0] == '0')
2260 return ET_INVALID;
2261
2262 return Val.Tgt + Id;
2263 }
2264 }
2265 return ET_INVALID;
2266}
2267
2268bool isSupportedTgtId(unsigned Id, const MCSubtargetInfo &STI) {
2269 switch (Id) {
2270 case ET_NULL:
2271 return !isGFX11Plus(STI);
2272 case ET_POS4:
2273 case ET_PRIM:
2274 return isGFX10Plus(STI);
2275 case ET_DUAL_SRC_BLEND0:
2276 case ET_DUAL_SRC_BLEND1:
2277 return isGFX11Plus(STI);
2278 default:
2279 if (Id >= ET_PARAM0 && Id <= ET_PARAM31)
2280 return !isGFX11Plus(STI) || isGFX13Plus(STI);
2281 return true;
2282 }
2283}
2284
2285} // namespace Exp
2286
2287//===----------------------------------------------------------------------===//
2288// MTBUF Format
2289//===----------------------------------------------------------------------===//
2290
2291namespace MTBUFFormat {
2292
2293int64_t getDfmt(const StringRef Name) {
2294 for (int Id = DFMT_MIN; Id <= DFMT_MAX; ++Id) {
2295 if (Name == DfmtSymbolic[Id])
2296 return Id;
2297 }
2298 return DFMT_UNDEF;
2299}
2300
2302 assert(Id <= DFMT_MAX);
2303 return DfmtSymbolic[Id];
2304}
2305
2307 if (isSI(STI) || isCI(STI))
2308 return NfmtSymbolicSICI;
2309 if (isVI(STI) || isGFX9(STI))
2310 return NfmtSymbolicVI;
2311 return NfmtSymbolicGFX10;
2312}
2313
2314int64_t getNfmt(const StringRef Name, const MCSubtargetInfo &STI) {
2315 const auto *lookupTable = getNfmtLookupTable(STI);
2316 for (int Id = NFMT_MIN; Id <= NFMT_MAX; ++Id) {
2317 if (Name == lookupTable[Id])
2318 return Id;
2319 }
2320 return NFMT_UNDEF;
2321}
2322
2323StringRef getNfmtName(unsigned Id, const MCSubtargetInfo &STI) {
2324 assert(Id <= NFMT_MAX);
2325 return getNfmtLookupTable(STI)[Id];
2326}
2327
2328bool isValidDfmtNfmt(unsigned Id, const MCSubtargetInfo &STI) {
2329 unsigned Dfmt;
2330 unsigned Nfmt;
2331 decodeDfmtNfmt(Id, Dfmt, Nfmt);
2332 return isValidNfmt(Nfmt, STI);
2333}
2334
2335bool isValidNfmt(unsigned Id, const MCSubtargetInfo &STI) {
2336 return !getNfmtName(Id, STI).empty();
2337}
2338
2339int64_t encodeDfmtNfmt(unsigned Dfmt, unsigned Nfmt) {
2340 return (Dfmt << DFMT_SHIFT) | (Nfmt << NFMT_SHIFT);
2341}
2342
2343void decodeDfmtNfmt(unsigned Format, unsigned &Dfmt, unsigned &Nfmt) {
2344 Dfmt = (Format >> DFMT_SHIFT) & DFMT_MASK;
2345 Nfmt = (Format >> NFMT_SHIFT) & NFMT_MASK;
2346}
2347
2348int64_t getUnifiedFormat(const StringRef Name, const MCSubtargetInfo &STI) {
2349 if (isGFX11Plus(STI)) {
2350 for (int Id = UfmtGFX11::UFMT_FIRST; Id <= UfmtGFX11::UFMT_LAST; ++Id) {
2351 if (Name == UfmtSymbolicGFX11[Id])
2352 return Id;
2353 }
2354 } else {
2355 for (int Id = UfmtGFX10::UFMT_FIRST; Id <= UfmtGFX10::UFMT_LAST; ++Id) {
2356 if (Name == UfmtSymbolicGFX10[Id])
2357 return Id;
2358 }
2359 }
2360 return UFMT_UNDEF;
2361}
2362
2364 if (isValidUnifiedFormat(Id, STI))
2365 return isGFX10(STI) ? UfmtSymbolicGFX10[Id] : UfmtSymbolicGFX11[Id];
2366 return "";
2367}
2368
2369bool isValidUnifiedFormat(unsigned Id, const MCSubtargetInfo &STI) {
2370 return isGFX10(STI) ? Id <= UfmtGFX10::UFMT_LAST : Id <= UfmtGFX11::UFMT_LAST;
2371}
2372
2373int64_t convertDfmtNfmt2Ufmt(unsigned Dfmt, unsigned Nfmt,
2374 const MCSubtargetInfo &STI) {
2375 int64_t Fmt = encodeDfmtNfmt(Dfmt, Nfmt);
2376 if (isGFX11Plus(STI)) {
2377 for (int Id = UfmtGFX11::UFMT_FIRST; Id <= UfmtGFX11::UFMT_LAST; ++Id) {
2378 if (Fmt == DfmtNfmt2UFmtGFX11[Id])
2379 return Id;
2380 }
2381 } else {
2382 for (int Id = UfmtGFX10::UFMT_FIRST; Id <= UfmtGFX10::UFMT_LAST; ++Id) {
2383 if (Fmt == DfmtNfmt2UFmtGFX10[Id])
2384 return Id;
2385 }
2386 }
2387 return UFMT_UNDEF;
2388}
2389
2390bool isValidFormatEncoding(unsigned Val, const MCSubtargetInfo &STI) {
2391 return isGFX10Plus(STI) ? (Val <= UFMT_MAX) : (Val <= DFMT_NFMT_MAX);
2392}
2393
2395 if (isGFX10Plus(STI))
2396 return UFMT_DEFAULT;
2397 return DFMT_NFMT_DEFAULT;
2398}
2399
2400} // namespace MTBUFFormat
2401
2402//===----------------------------------------------------------------------===//
2403// SendMsg
2404//===----------------------------------------------------------------------===//
2405
2406namespace SendMsg {
2407
2411
2412bool isValidMsgId(int64_t MsgId, const MCSubtargetInfo &STI) {
2413 return (MsgId & ~(getMsgIdMask(STI))) == 0;
2414}
2415
2416bool isValidMsgOp(int64_t MsgId, int64_t OpId, const MCSubtargetInfo &STI,
2417 bool Strict) {
2418 assert(isValidMsgId(MsgId, STI));
2419
2420 if (!Strict)
2421 return 0 <= OpId && isUInt<OP_WIDTH_>(OpId);
2422
2423 if (msgRequiresOp(MsgId, STI)) {
2424 if (MsgId == ID_GS_PreGFX11 && OpId == OP_GS_NOP)
2425 return false;
2426
2427 return !getMsgOpName(MsgId, OpId, STI).empty();
2428 }
2429
2430 return OpId == OP_NONE_;
2431}
2432
2433bool isValidMsgStream(int64_t MsgId, int64_t OpId, int64_t StreamId,
2434 const MCSubtargetInfo &STI, bool Strict) {
2435 assert(isValidMsgOp(MsgId, OpId, STI, Strict));
2436
2437 if (!Strict)
2439
2440 if (!isGFX11Plus(STI)) {
2441 switch (MsgId) {
2442 case ID_GS_PreGFX11:
2445 return (OpId == OP_GS_NOP)
2448 }
2449 }
2450 return StreamId == STREAM_ID_NONE_;
2451}
2452
2453bool msgRequiresOp(int64_t MsgId, const MCSubtargetInfo &STI) {
2454 return MsgId == ID_SYSMSG ||
2455 (!isGFX11Plus(STI) &&
2456 (MsgId == ID_GS_PreGFX11 || MsgId == ID_GS_DONE_PreGFX11));
2457}
2458
2459bool msgSupportsStream(int64_t MsgId, int64_t OpId,
2460 const MCSubtargetInfo &STI) {
2461 return !isGFX11Plus(STI) &&
2462 (MsgId == ID_GS_PreGFX11 || MsgId == ID_GS_DONE_PreGFX11) &&
2463 OpId != OP_GS_NOP;
2464}
2465
2466void decodeMsg(unsigned Val, uint16_t &MsgId, uint16_t &OpId,
2467 uint16_t &StreamId, const MCSubtargetInfo &STI) {
2468 MsgId = Val & getMsgIdMask(STI);
2469 if (isGFX11Plus(STI)) {
2470 OpId = 0;
2471 StreamId = 0;
2472 } else {
2473 OpId = (Val & OP_MASK_) >> OP_SHIFT_;
2475 }
2476}
2477
2479 return MsgId | (OpId << OP_SHIFT_) | (StreamId << STREAM_ID_SHIFT_);
2480}
2481
2482bool msgDoesNotUseM0(int64_t MsgId, const MCSubtargetInfo &STI) {
2483 // Explicitly list message types that are known to not use m0.
2484 // This is safer than excluding only GS_ALLOC_REQ, in case new message
2485 // types are added in the future that do use m0.
2486 if (isGFX11Plus(STI)) {
2487 switch (MsgId) {
2489 return true;
2490 default:
2491 break;
2492 }
2493 }
2494 switch (MsgId) {
2495 case ID_SAVEWAVE:
2496 case ID_STALL_WAVE_GEN:
2497 case ID_HALT_WAVES:
2498 case ID_ORDERED_PS_DONE:
2500 case ID_GET_DOORBELL:
2501 case ID_GET_DDID:
2502 case ID_SYSMSG:
2503 return true;
2504 default:
2505 return false;
2506 }
2507}
2508
2509} // namespace SendMsg
2510
2511//===----------------------------------------------------------------------===//
2512//
2513//===----------------------------------------------------------------------===//
2514
2516 return F.getFnAttributeAsParsedInteger("InitialPSInputAddr", 0);
2517}
2518
2520 // As a safe default always respond as if PS has color exports.
2521 return F.getFnAttributeAsParsedInteger(
2522 "amdgpu-color-export",
2523 F.getCallingConv() == CallingConv::AMDGPU_PS ? 1 : 0) != 0;
2524}
2525
2527 return F.getFnAttributeAsParsedInteger("amdgpu-depth-export", 0) != 0;
2528}
2529
2531 unsigned BlockSize =
2532 F.getFnAttributeAsParsedInteger("amdgpu-dynamic-vgpr-block-size", 0);
2533
2534 if (BlockSize == 16 || BlockSize == 32)
2535 return BlockSize;
2536
2537 return 0;
2538}
2539
2540bool hasXNACK(const MCSubtargetInfo &STI) {
2541 return STI.hasFeature(AMDGPU::FeatureXNACK);
2542}
2543
2545 return STI.hasFeature(AMDGPU::FeatureMIMG_R128) &&
2546 !STI.hasFeature(AMDGPU::FeatureR128A16);
2547}
2548
2549bool hasA16(const MCSubtargetInfo &STI) {
2550 return STI.hasFeature(AMDGPU::FeatureA16);
2551}
2552
2553bool hasG16(const MCSubtargetInfo &STI) {
2554 return STI.hasFeature(AMDGPU::FeatureG16);
2555}
2556
2558 return !STI.hasFeature(AMDGPU::FeatureUnpackedD16VMem) && !isCI(STI) &&
2559 !isSI(STI);
2560}
2561
2562bool hasGDS(const MCSubtargetInfo &STI) {
2563 return STI.hasFeature(AMDGPU::FeatureGDS);
2564}
2565
2566unsigned getNSAMaxSize(const MCSubtargetInfo &STI, bool HasSampler) {
2567 auto Version = getIsaVersion(STI.getCPU());
2568 if (Version.Major == 10)
2569 return Version.Minor >= 3 ? 13 : 5;
2570 if (Version.Major == 11)
2571 return 5;
2572 if (Version.Major >= 12)
2573 return HasSampler ? 4 : 5;
2574 return 0;
2575}
2576
2578 if (isGFX1250Plus(STI))
2579 return 32;
2580 return 16;
2581}
2582
2583bool isSI(const MCSubtargetInfo &STI) {
2584 return STI.hasFeature(AMDGPU::FeatureSouthernIslands);
2585}
2586
2587bool isCI(const MCSubtargetInfo &STI) {
2588 return STI.hasFeature(AMDGPU::FeatureSeaIslands);
2589}
2590
2591bool isVI(const MCSubtargetInfo &STI) {
2592 return STI.hasFeature(AMDGPU::FeatureVolcanicIslands);
2593}
2594
2595bool isGFX9(const MCSubtargetInfo &STI) {
2596 return STI.hasFeature(AMDGPU::FeatureGFX9);
2597}
2598
2600 return isGFX9(STI) || isGFX10(STI);
2601}
2602
2604 return isGFX9(STI) || isGFX10(STI) || isGFX11(STI);
2605}
2606
2608 return isVI(STI) || isGFX9(STI) || isGFX10(STI);
2609}
2610
2611bool isGFX8Plus(const MCSubtargetInfo &STI) {
2612 return isVI(STI) || isGFX9Plus(STI);
2613}
2614
2615bool isGFX9Plus(const MCSubtargetInfo &STI) {
2616 return isGFX9(STI) || isGFX10Plus(STI);
2617}
2618
2619bool isNotGFX9Plus(const MCSubtargetInfo &STI) { return !isGFX9Plus(STI); }
2620
2621bool isGFX10(const MCSubtargetInfo &STI) {
2622 return STI.hasFeature(AMDGPU::FeatureGFX10);
2623}
2624
2626 return isGFX10(STI) || isGFX11(STI);
2627}
2628
2630 return isGFX10(STI) || isGFX11Plus(STI);
2631}
2632
2633bool isGFX11(const MCSubtargetInfo &STI) {
2634 return STI.hasFeature(AMDGPU::FeatureGFX11);
2635}
2636
2638 return isGFX11(STI) || isGFX12Plus(STI);
2639}
2640
2641bool isGFX12(const MCSubtargetInfo &STI) {
2642 return STI.getFeatureBits()[AMDGPU::FeatureGFX12];
2643}
2644
2646 return isGFX12(STI) || isGFX13Plus(STI);
2647}
2648
2649bool isNotGFX12Plus(const MCSubtargetInfo &STI) { return !isGFX12Plus(STI); }
2650
2651bool isGFX1250(const MCSubtargetInfo &STI) {
2652 return STI.getFeatureBits()[AMDGPU::FeatureGFX1250Insts] && !isGFX13(STI);
2653}
2654
2656 return STI.getFeatureBits()[AMDGPU::FeatureGFX1250Insts];
2657}
2658
2659bool isGFX13(const MCSubtargetInfo &STI) {
2660 return STI.getFeatureBits()[AMDGPU::FeatureGFX13];
2661}
2662
2663bool isGFX13Plus(const MCSubtargetInfo &STI) { return isGFX13(STI); }
2664
2666 if (isGFX1250(STI))
2667 return false;
2668 return isGFX10Plus(STI);
2669}
2670
2671bool isNotGFX11Plus(const MCSubtargetInfo &STI) { return !isGFX11Plus(STI); }
2672
2674 return isSI(STI) || isCI(STI) || isVI(STI) || isGFX9(STI);
2675}
2676
2678 return isGFX10(STI) && !AMDGPU::isGFX10_BEncoding(STI);
2679}
2680
2682 return STI.hasFeature(AMDGPU::FeatureGCN3Encoding);
2683}
2684
2686 return STI.hasFeature(AMDGPU::FeatureGFX10_AEncoding);
2687}
2688
2690 return STI.hasFeature(AMDGPU::FeatureGFX10_BEncoding);
2691}
2692
2694 return STI.hasFeature(AMDGPU::FeatureGFX10_3Insts);
2695}
2696
2698 return isGFX10_BEncoding(STI) && !isGFX12Plus(STI);
2699}
2700
2701bool isGFX90A(const MCSubtargetInfo &STI) {
2702 return STI.hasFeature(AMDGPU::FeatureGFX90AInsts);
2703}
2704
2705bool isGFX940(const MCSubtargetInfo &STI) {
2706 return STI.hasFeature(AMDGPU::FeatureGFX940Insts);
2707}
2708
2710 return STI.hasFeature(AMDGPU::FeatureArchitectedFlatScratch);
2711}
2712
2714 return STI.hasFeature(AMDGPU::FeatureMAIInsts);
2715}
2716
2717bool hasVOPD(const MCSubtargetInfo &STI) {
2718 return STI.hasFeature(AMDGPU::FeatureVOPDInsts);
2719}
2720
2722 return STI.hasFeature(AMDGPU::FeatureDPPSrc1SGPR);
2723}
2724
2726 return STI.hasFeature(AMDGPU::FeatureKernargPreload);
2727}
2728
2729int32_t getTotalNumVGPRs(bool has90AInsts, int32_t ArgNumAGPR,
2730 int32_t ArgNumVGPR) {
2731 if (has90AInsts && ArgNumAGPR)
2732 return alignTo(ArgNumVGPR, 4) + ArgNumAGPR;
2733 return std::max(ArgNumVGPR, ArgNumAGPR);
2734}
2735
2737 const MCRegisterClass SGPRClass = TRI->getRegClass(AMDGPU::SReg_32RegClassID);
2738 const MCRegister FirstSubReg = TRI->getSubReg(Reg, AMDGPU::sub0);
2739 return SGPRClass.contains(FirstSubReg != 0 ? FirstSubReg : Reg) ||
2740 Reg == AMDGPU::SCC;
2741}
2742
2746
2747#define MAP_REG2REG \
2748 using namespace AMDGPU; \
2749 switch (Reg.id()) { \
2750 default: \
2751 return Reg; \
2752 CASE_CI_VI(FLAT_SCR) \
2753 CASE_CI_VI(FLAT_SCR_LO) \
2754 CASE_CI_VI(FLAT_SCR_HI) \
2755 CASE_VI_GFX9PLUS(TTMP0) \
2756 CASE_VI_GFX9PLUS(TTMP1) \
2757 CASE_VI_GFX9PLUS(TTMP2) \
2758 CASE_VI_GFX9PLUS(TTMP3) \
2759 CASE_VI_GFX9PLUS(TTMP4) \
2760 CASE_VI_GFX9PLUS(TTMP5) \
2761 CASE_VI_GFX9PLUS(TTMP6) \
2762 CASE_VI_GFX9PLUS(TTMP7) \
2763 CASE_VI_GFX9PLUS(TTMP8) \
2764 CASE_VI_GFX9PLUS(TTMP9) \
2765 CASE_VI_GFX9PLUS(TTMP10) \
2766 CASE_VI_GFX9PLUS(TTMP11) \
2767 CASE_VI_GFX9PLUS(TTMP12) \
2768 CASE_VI_GFX9PLUS(TTMP13) \
2769 CASE_VI_GFX9PLUS(TTMP14) \
2770 CASE_VI_GFX9PLUS(TTMP15) \
2771 CASE_VI_GFX9PLUS(TTMP0_TTMP1) \
2772 CASE_VI_GFX9PLUS(TTMP2_TTMP3) \
2773 CASE_VI_GFX9PLUS(TTMP4_TTMP5) \
2774 CASE_VI_GFX9PLUS(TTMP6_TTMP7) \
2775 CASE_VI_GFX9PLUS(TTMP8_TTMP9) \
2776 CASE_VI_GFX9PLUS(TTMP10_TTMP11) \
2777 CASE_VI_GFX9PLUS(TTMP12_TTMP13) \
2778 CASE_VI_GFX9PLUS(TTMP14_TTMP15) \
2779 CASE_VI_GFX9PLUS(TTMP0_TTMP1_TTMP2_TTMP3) \
2780 CASE_VI_GFX9PLUS(TTMP4_TTMP5_TTMP6_TTMP7) \
2781 CASE_VI_GFX9PLUS(TTMP8_TTMP9_TTMP10_TTMP11) \
2782 CASE_VI_GFX9PLUS(TTMP12_TTMP13_TTMP14_TTMP15) \
2783 CASE_VI_GFX9PLUS(TTMP0_TTMP1_TTMP2_TTMP3_TTMP4_TTMP5_TTMP6_TTMP7) \
2784 CASE_VI_GFX9PLUS(TTMP4_TTMP5_TTMP6_TTMP7_TTMP8_TTMP9_TTMP10_TTMP11) \
2785 CASE_VI_GFX9PLUS(TTMP8_TTMP9_TTMP10_TTMP11_TTMP12_TTMP13_TTMP14_TTMP15) \
2786 CASE_VI_GFX9PLUS( \
2787 TTMP0_TTMP1_TTMP2_TTMP3_TTMP4_TTMP5_TTMP6_TTMP7_TTMP8_TTMP9_TTMP10_TTMP11_TTMP12_TTMP13_TTMP14_TTMP15) \
2788 CASE_GFXPRE11_GFX11PLUS(M0) \
2789 CASE_GFXPRE11_GFX11PLUS(SGPR_NULL) \
2790 CASE_GFXPRE11_GFX11PLUS_TO(SGPR_NULL64, SGPR_NULL) \
2791 }
2792
2793#define CASE_CI_VI(node) \
2794 assert(!isSI(STI)); \
2795 case node: \
2796 return isCI(STI) ? node##_ci : node##_vi;
2797
2798#define CASE_VI_GFX9PLUS(node) \
2799 case node: \
2800 return isGFX9Plus(STI) ? node##_gfx9plus : node##_vi;
2801
2802#define CASE_GFXPRE11_GFX11PLUS(node) \
2803 case node: \
2804 return isGFX11Plus(STI) ? node##_gfx11plus : node##_gfxpre11;
2805
2806#define CASE_GFXPRE11_GFX11PLUS_TO(node, result) \
2807 case node: \
2808 return isGFX11Plus(STI) ? result##_gfx11plus : result##_gfxpre11;
2809
2811 if (STI.getTargetTriple().getArch() == Triple::r600)
2812 return Reg;
2814}
2815
2816#undef CASE_CI_VI
2817#undef CASE_VI_GFX9PLUS
2818#undef CASE_GFXPRE11_GFX11PLUS
2819#undef CASE_GFXPRE11_GFX11PLUS_TO
2820
2821#define CASE_CI_VI(node) \
2822 case node##_ci: \
2823 case node##_vi: \
2824 return node;
2825#define CASE_VI_GFX9PLUS(node) \
2826 case node##_vi: \
2827 case node##_gfx9plus: \
2828 return node;
2829#define CASE_GFXPRE11_GFX11PLUS(node) \
2830 case node##_gfx11plus: \
2831 case node##_gfxpre11: \
2832 return node;
2833#define CASE_GFXPRE11_GFX11PLUS_TO(node, result)
2834
2836
2838 switch (Reg.id()) {
2839 case AMDGPU::SRC_SHARED_BASE_LO:
2840 case AMDGPU::SRC_SHARED_BASE:
2841 case AMDGPU::SRC_SHARED_LIMIT_LO:
2842 case AMDGPU::SRC_SHARED_LIMIT:
2843 case AMDGPU::SRC_PRIVATE_BASE_LO:
2844 case AMDGPU::SRC_PRIVATE_BASE:
2845 case AMDGPU::SRC_PRIVATE_LIMIT_LO:
2846 case AMDGPU::SRC_PRIVATE_LIMIT:
2847 case AMDGPU::SRC_FLAT_SCRATCH_BASE_LO:
2848 case AMDGPU::SRC_FLAT_SCRATCH_BASE_HI:
2849 case AMDGPU::SRC_POPS_EXITING_WAVE_ID:
2850 return true;
2851 case AMDGPU::SRC_VCCZ:
2852 case AMDGPU::SRC_EXECZ:
2853 case AMDGPU::SRC_SCC:
2854 return true;
2855 case AMDGPU::SGPR_NULL:
2856 return true;
2857 default:
2858 return false;
2859 }
2860}
2861
2862#undef CASE_CI_VI
2863#undef CASE_VI_GFX9PLUS
2864#undef CASE_GFXPRE11_GFX11PLUS
2865#undef CASE_GFXPRE11_GFX11PLUS_TO
2866#undef MAP_REG2REG
2867
2868bool isKImmOperand(const MCInstrDesc &Desc, unsigned OpNo) {
2869 assert(OpNo < Desc.NumOperands);
2870 unsigned OpType = Desc.operands()[OpNo].OperandType;
2871 return OpType >= AMDGPU::OPERAND_KIMM_FIRST &&
2872 OpType <= AMDGPU::OPERAND_KIMM_LAST;
2873}
2874
2875bool isSISrcFPOperand(const MCInstrDesc &Desc, unsigned OpNo) {
2876 assert(OpNo < Desc.NumOperands);
2877 unsigned OpType = Desc.operands()[OpNo].OperandType;
2878 switch (OpType) {
2892 return true;
2893 default:
2894 return false;
2895 }
2896}
2897
2898bool isSISrcInlinableOperand(const MCInstrDesc &Desc, unsigned OpNo) {
2899 assert(OpNo < Desc.NumOperands);
2900 unsigned OpType = Desc.operands()[OpNo].OperandType;
2901 return (OpType >= AMDGPU::OPERAND_REG_INLINE_C_FIRST &&
2905}
2906
2907// Avoid using MCRegisterClass::getSize, since that function will go away
2908// (move from MC* level to Target* level). Return size in bits.
2909unsigned getRegBitWidth(unsigned RCID) {
2910 switch (RCID) {
2911 case AMDGPU::VGPR_16RegClassID:
2912 case AMDGPU::VGPR_16_Lo128RegClassID:
2913 case AMDGPU::SGPR_LO16RegClassID:
2914 case AMDGPU::AGPR_LO16RegClassID:
2915 return 16;
2916 case AMDGPU::SGPR_32RegClassID:
2917 case AMDGPU::VGPR_32RegClassID:
2918 case AMDGPU::VGPR_32_Lo256RegClassID:
2919 case AMDGPU::VRegOrLds_32RegClassID:
2920 case AMDGPU::AGPR_32RegClassID:
2921 case AMDGPU::VS_32RegClassID:
2922 case AMDGPU::AV_32RegClassID:
2923 case AMDGPU::SReg_32RegClassID:
2924 case AMDGPU::SReg_32_XM0RegClassID:
2925 case AMDGPU::SRegOrLds_32RegClassID:
2926 return 32;
2927 case AMDGPU::SGPR_64RegClassID:
2928 case AMDGPU::VS_64RegClassID:
2929 case AMDGPU::SReg_64RegClassID:
2930 case AMDGPU::VReg_64RegClassID:
2931 case AMDGPU::AReg_64RegClassID:
2932 case AMDGPU::SReg_64_XEXECRegClassID:
2933 case AMDGPU::VReg_64_Align2RegClassID:
2934 case AMDGPU::AReg_64_Align2RegClassID:
2935 case AMDGPU::AV_64RegClassID:
2936 case AMDGPU::AV_64_Align2RegClassID:
2937 case AMDGPU::VReg_64_Lo256_Align2RegClassID:
2938 case AMDGPU::VS_64_Lo256RegClassID:
2939 return 64;
2940 case AMDGPU::SGPR_96RegClassID:
2941 case AMDGPU::SReg_96RegClassID:
2942 case AMDGPU::VReg_96RegClassID:
2943 case AMDGPU::AReg_96RegClassID:
2944 case AMDGPU::VReg_96_Align2RegClassID:
2945 case AMDGPU::AReg_96_Align2RegClassID:
2946 case AMDGPU::AV_96RegClassID:
2947 case AMDGPU::AV_96_Align2RegClassID:
2948 case AMDGPU::VReg_96_Lo256_Align2RegClassID:
2949 return 96;
2950 case AMDGPU::SGPR_128RegClassID:
2951 case AMDGPU::SReg_128RegClassID:
2952 case AMDGPU::VReg_128RegClassID:
2953 case AMDGPU::AReg_128RegClassID:
2954 case AMDGPU::VReg_128_Align2RegClassID:
2955 case AMDGPU::AReg_128_Align2RegClassID:
2956 case AMDGPU::AV_128RegClassID:
2957 case AMDGPU::AV_128_Align2RegClassID:
2958 case AMDGPU::SReg_128_XNULLRegClassID:
2959 case AMDGPU::VReg_128_Lo256_Align2RegClassID:
2960 return 128;
2961 case AMDGPU::SGPR_160RegClassID:
2962 case AMDGPU::SReg_160RegClassID:
2963 case AMDGPU::VReg_160RegClassID:
2964 case AMDGPU::AReg_160RegClassID:
2965 case AMDGPU::VReg_160_Align2RegClassID:
2966 case AMDGPU::AReg_160_Align2RegClassID:
2967 case AMDGPU::AV_160RegClassID:
2968 case AMDGPU::AV_160_Align2RegClassID:
2969 case AMDGPU::VReg_160_Lo256_Align2RegClassID:
2970 return 160;
2971 case AMDGPU::SGPR_192RegClassID:
2972 case AMDGPU::SReg_192RegClassID:
2973 case AMDGPU::VReg_192RegClassID:
2974 case AMDGPU::AReg_192RegClassID:
2975 case AMDGPU::VReg_192_Align2RegClassID:
2976 case AMDGPU::AReg_192_Align2RegClassID:
2977 case AMDGPU::AV_192RegClassID:
2978 case AMDGPU::AV_192_Align2RegClassID:
2979 case AMDGPU::VReg_192_Lo256_Align2RegClassID:
2980 return 192;
2981 case AMDGPU::SGPR_224RegClassID:
2982 case AMDGPU::SReg_224RegClassID:
2983 case AMDGPU::VReg_224RegClassID:
2984 case AMDGPU::AReg_224RegClassID:
2985 case AMDGPU::VReg_224_Align2RegClassID:
2986 case AMDGPU::AReg_224_Align2RegClassID:
2987 case AMDGPU::AV_224RegClassID:
2988 case AMDGPU::AV_224_Align2RegClassID:
2989 case AMDGPU::VReg_224_Lo256_Align2RegClassID:
2990 return 224;
2991 case AMDGPU::SGPR_256RegClassID:
2992 case AMDGPU::SReg_256RegClassID:
2993 case AMDGPU::VReg_256RegClassID:
2994 case AMDGPU::AReg_256RegClassID:
2995 case AMDGPU::VReg_256_Align2RegClassID:
2996 case AMDGPU::AReg_256_Align2RegClassID:
2997 case AMDGPU::AV_256RegClassID:
2998 case AMDGPU::AV_256_Align2RegClassID:
2999 case AMDGPU::SReg_256_XNULLRegClassID:
3000 case AMDGPU::VReg_256_Lo256_Align2RegClassID:
3001 return 256;
3002 case AMDGPU::SGPR_288RegClassID:
3003 case AMDGPU::SReg_288RegClassID:
3004 case AMDGPU::VReg_288RegClassID:
3005 case AMDGPU::AReg_288RegClassID:
3006 case AMDGPU::VReg_288_Align2RegClassID:
3007 case AMDGPU::AReg_288_Align2RegClassID:
3008 case AMDGPU::AV_288RegClassID:
3009 case AMDGPU::AV_288_Align2RegClassID:
3010 case AMDGPU::VReg_288_Lo256_Align2RegClassID:
3011 return 288;
3012 case AMDGPU::SGPR_320RegClassID:
3013 case AMDGPU::SReg_320RegClassID:
3014 case AMDGPU::VReg_320RegClassID:
3015 case AMDGPU::AReg_320RegClassID:
3016 case AMDGPU::VReg_320_Align2RegClassID:
3017 case AMDGPU::AReg_320_Align2RegClassID:
3018 case AMDGPU::AV_320RegClassID:
3019 case AMDGPU::AV_320_Align2RegClassID:
3020 case AMDGPU::VReg_320_Lo256_Align2RegClassID:
3021 return 320;
3022 case AMDGPU::SGPR_352RegClassID:
3023 case AMDGPU::SReg_352RegClassID:
3024 case AMDGPU::VReg_352RegClassID:
3025 case AMDGPU::AReg_352RegClassID:
3026 case AMDGPU::VReg_352_Align2RegClassID:
3027 case AMDGPU::AReg_352_Align2RegClassID:
3028 case AMDGPU::AV_352RegClassID:
3029 case AMDGPU::AV_352_Align2RegClassID:
3030 case AMDGPU::VReg_352_Lo256_Align2RegClassID:
3031 return 352;
3032 case AMDGPU::SGPR_384RegClassID:
3033 case AMDGPU::SReg_384RegClassID:
3034 case AMDGPU::VReg_384RegClassID:
3035 case AMDGPU::AReg_384RegClassID:
3036 case AMDGPU::VReg_384_Align2RegClassID:
3037 case AMDGPU::AReg_384_Align2RegClassID:
3038 case AMDGPU::AV_384RegClassID:
3039 case AMDGPU::AV_384_Align2RegClassID:
3040 case AMDGPU::VReg_384_Lo256_Align2RegClassID:
3041 return 384;
3042 case AMDGPU::SGPR_512RegClassID:
3043 case AMDGPU::SReg_512RegClassID:
3044 case AMDGPU::VReg_512RegClassID:
3045 case AMDGPU::AReg_512RegClassID:
3046 case AMDGPU::VReg_512_Align2RegClassID:
3047 case AMDGPU::AReg_512_Align2RegClassID:
3048 case AMDGPU::AV_512RegClassID:
3049 case AMDGPU::AV_512_Align2RegClassID:
3050 case AMDGPU::VReg_512_Lo256_Align2RegClassID:
3051 return 512;
3052 case AMDGPU::SGPR_1024RegClassID:
3053 case AMDGPU::SReg_1024RegClassID:
3054 case AMDGPU::VReg_1024RegClassID:
3055 case AMDGPU::AReg_1024RegClassID:
3056 case AMDGPU::VReg_1024_Align2RegClassID:
3057 case AMDGPU::AReg_1024_Align2RegClassID:
3058 case AMDGPU::AV_1024RegClassID:
3059 case AMDGPU::AV_1024_Align2RegClassID:
3060 case AMDGPU::VReg_1024_Lo256_Align2RegClassID:
3061 return 1024;
3062 default:
3063 llvm_unreachable("Unexpected register class");
3064 }
3065}
3066
3067unsigned getRegBitWidth(const MCRegisterClass &RC) {
3068 return getRegBitWidth(RC.getID());
3069}
3070
3071bool isInlinableLiteral64(int64_t Literal, bool HasInv2Pi) {
3073 return true;
3074
3075 uint64_t Val = static_cast<uint64_t>(Literal);
3076 return (Val == llvm::bit_cast<uint64_t>(0.0)) ||
3077 (Val == llvm::bit_cast<uint64_t>(1.0)) ||
3078 (Val == llvm::bit_cast<uint64_t>(-1.0)) ||
3079 (Val == llvm::bit_cast<uint64_t>(0.5)) ||
3080 (Val == llvm::bit_cast<uint64_t>(-0.5)) ||
3081 (Val == llvm::bit_cast<uint64_t>(2.0)) ||
3082 (Val == llvm::bit_cast<uint64_t>(-2.0)) ||
3083 (Val == llvm::bit_cast<uint64_t>(4.0)) ||
3084 (Val == llvm::bit_cast<uint64_t>(-4.0)) ||
3085 (Val == 0x3fc45f306dc9c882 && HasInv2Pi);
3086}
3087
3088bool isInlinableLiteral32(int32_t Literal, bool HasInv2Pi) {
3090 return true;
3091
3092 // The actual type of the operand does not seem to matter as long
3093 // as the bits match one of the inline immediate values. For example:
3094 //
3095 // -nan has the hexadecimal encoding of 0xfffffffe which is -2 in decimal,
3096 // so it is a legal inline immediate.
3097 //
3098 // 1065353216 has the hexadecimal encoding 0x3f800000 which is 1.0f in
3099 // floating-point, so it is a legal inline immediate.
3100
3101 uint32_t Val = static_cast<uint32_t>(Literal);
3102 return (Val == llvm::bit_cast<uint32_t>(0.0f)) ||
3103 (Val == llvm::bit_cast<uint32_t>(1.0f)) ||
3104 (Val == llvm::bit_cast<uint32_t>(-1.0f)) ||
3105 (Val == llvm::bit_cast<uint32_t>(0.5f)) ||
3106 (Val == llvm::bit_cast<uint32_t>(-0.5f)) ||
3107 (Val == llvm::bit_cast<uint32_t>(2.0f)) ||
3108 (Val == llvm::bit_cast<uint32_t>(-2.0f)) ||
3109 (Val == llvm::bit_cast<uint32_t>(4.0f)) ||
3110 (Val == llvm::bit_cast<uint32_t>(-4.0f)) ||
3111 (Val == 0x3e22f983 && HasInv2Pi);
3112}
3113
3114bool isInlinableLiteralBF16(int16_t Literal, bool HasInv2Pi) {
3115 if (!HasInv2Pi)
3116 return false;
3118 return true;
3119 uint16_t Val = static_cast<uint16_t>(Literal);
3120 return Val == 0x3F00 || // 0.5
3121 Val == 0xBF00 || // -0.5
3122 Val == 0x3F80 || // 1.0
3123 Val == 0xBF80 || // -1.0
3124 Val == 0x4000 || // 2.0
3125 Val == 0xC000 || // -2.0
3126 Val == 0x4080 || // 4.0
3127 Val == 0xC080 || // -4.0
3128 Val == 0x3E22; // 1.0 / (2.0 * pi)
3129}
3130
3131bool isInlinableLiteralI16(int32_t Literal, bool HasInv2Pi) {
3132 return isInlinableLiteral32(Literal, HasInv2Pi);
3133}
3134
3135bool isInlinableLiteralFP16(int16_t Literal, bool HasInv2Pi) {
3136 if (!HasInv2Pi)
3137 return false;
3139 return true;
3140 uint16_t Val = static_cast<uint16_t>(Literal);
3141 return Val == 0x3C00 || // 1.0
3142 Val == 0xBC00 || // -1.0
3143 Val == 0x3800 || // 0.5
3144 Val == 0xB800 || // -0.5
3145 Val == 0x4000 || // 2.0
3146 Val == 0xC000 || // -2.0
3147 Val == 0x4400 || // 4.0
3148 Val == 0xC400 || // -4.0
3149 Val == 0x3118; // 1/2pi
3150}
3151
3152std::optional<unsigned> getInlineEncodingV216(bool IsFloat, uint32_t Literal) {
3153 // Unfortunately, the Instruction Set Architecture Reference Guide is
3154 // misleading about how the inline operands work for (packed) 16-bit
3155 // instructions. In a nutshell, the actual HW behavior is:
3156 //
3157 // - integer encodings (-16 .. 64) are always produced as sign-extended
3158 // 32-bit values
3159 // - float encodings are produced as:
3160 // - for F16 instructions: corresponding half-precision float values in
3161 // the LSBs, 0 in the MSBs
3162 // - for UI16 instructions: corresponding single-precision float value
3163 int32_t Signed = static_cast<int32_t>(Literal);
3164 if (Signed >= 0 && Signed <= 64)
3165 return 128 + Signed;
3166
3167 if (Signed >= -16 && Signed <= -1)
3168 return 192 + std::abs(Signed);
3169
3170 if (IsFloat) {
3171 // clang-format off
3172 switch (Literal) {
3173 case 0x3800: return 240; // 0.5
3174 case 0xB800: return 241; // -0.5
3175 case 0x3C00: return 242; // 1.0
3176 case 0xBC00: return 243; // -1.0
3177 case 0x4000: return 244; // 2.0
3178 case 0xC000: return 245; // -2.0
3179 case 0x4400: return 246; // 4.0
3180 case 0xC400: return 247; // -4.0
3181 case 0x3118: return 248; // 1.0 / (2.0 * pi)
3182 default: break;
3183 }
3184 // clang-format on
3185 } else {
3186 // clang-format off
3187 switch (Literal) {
3188 case 0x3F000000: return 240; // 0.5
3189 case 0xBF000000: return 241; // -0.5
3190 case 0x3F800000: return 242; // 1.0
3191 case 0xBF800000: return 243; // -1.0
3192 case 0x40000000: return 244; // 2.0
3193 case 0xC0000000: return 245; // -2.0
3194 case 0x40800000: return 246; // 4.0
3195 case 0xC0800000: return 247; // -4.0
3196 case 0x3E22F983: return 248; // 1.0 / (2.0 * pi)
3197 default: break;
3198 }
3199 // clang-format on
3200 }
3201
3202 return {};
3203}
3204
3205// Encoding of the literal as an inline constant for a V_PK_*_IU16 instruction
3206// or nullopt.
3207std::optional<unsigned> getInlineEncodingV2I16(uint32_t Literal) {
3208 return getInlineEncodingV216(false, Literal);
3209}
3210
3211// Encoding of the literal as an inline constant for a V_PK_*_BF16 instruction
3212// or nullopt.
3213std::optional<unsigned> getInlineEncodingV2BF16(uint32_t Literal) {
3214 int32_t Signed = static_cast<int32_t>(Literal);
3215 if (Signed >= 0 && Signed <= 64)
3216 return 128 + Signed;
3217
3218 if (Signed >= -16 && Signed <= -1)
3219 return 192 + std::abs(Signed);
3220
3221 // clang-format off
3222 switch (Literal) {
3223 case 0x3F00: return 240; // 0.5
3224 case 0xBF00: return 241; // -0.5
3225 case 0x3F80: return 242; // 1.0
3226 case 0xBF80: return 243; // -1.0
3227 case 0x4000: return 244; // 2.0
3228 case 0xC000: return 245; // -2.0
3229 case 0x4080: return 246; // 4.0
3230 case 0xC080: return 247; // -4.0
3231 case 0x3E22: return 248; // 1.0 / (2.0 * pi)
3232 default: break;
3233 }
3234 // clang-format on
3235
3236 return std::nullopt;
3237}
3238
3239// Encoding of the literal as an inline constant for a V_PK_*_F16 instruction
3240// or nullopt.
3241std::optional<unsigned> getInlineEncodingV2F16(uint32_t Literal) {
3242 return getInlineEncodingV216(true, Literal);
3243}
3244
3245// Encoding of the literal as an inline constant for V_PK_FMAC_F16 instruction
3246// or nullopt. This accounts for different inline constant behavior:
3247// - Pre-GFX11: fp16 inline constants have the value in low 16 bits, 0 in high
3248// - GFX11+: fp16 inline constants are duplicated into both halves
3250 bool IsGFX11Plus) {
3251 // Pre-GFX11 behavior: f16 in low bits, 0 in high bits
3252 if (!IsGFX11Plus)
3253 return getInlineEncodingV216(/*IsFloat=*/true, Literal);
3254
3255 // GFX11+ behavior: f16 duplicated in both halves
3256 // First, check for sign-extended integer inline constants (-16 to 64)
3257 // These work the same across all generations
3258 int32_t Signed = static_cast<int32_t>(Literal);
3259 if (Signed >= 0 && Signed <= 64)
3260 return 128 + Signed;
3261
3262 if (Signed >= -16 && Signed <= -1)
3263 return 192 + std::abs(Signed);
3264
3265 // For float inline constants on GFX11+, both halves must be equal
3266 uint16_t Lo = static_cast<uint16_t>(Literal);
3267 uint16_t Hi = static_cast<uint16_t>(Literal >> 16);
3268 if (Lo != Hi)
3269 return std::nullopt;
3270 return getInlineEncodingV216(/*IsFloat=*/true, Lo);
3271}
3272
3273// Whether the given literal can be inlined for a V_PK_* instruction.
3275 switch (OpType) {
3278 return getInlineEncodingV216(false, Literal).has_value();
3281 return getInlineEncodingV216(true, Literal).has_value();
3283 llvm_unreachable("OPERAND_REG_IMM_V2FP16_SPLAT is not supported");
3288 return false;
3289 default:
3290 llvm_unreachable("bad packed operand type");
3291 }
3292}
3293
3294// Whether the given literal can be inlined for a V_PK_*_IU16 instruction.
3298
3299// Whether the given literal can be inlined for a V_PK_*_BF16 instruction.
3303
3304// Whether the given literal can be inlined for a V_PK_*_F16 instruction.
3308
3309// Whether the given literal can be inlined for V_PK_FMAC_F16 instruction.
3311 return getPKFMACF16InlineEncoding(Literal, IsGFX11Plus).has_value();
3312}
3313
3314bool isValid32BitLiteral(uint64_t Val, bool IsFP64) {
3315 if (IsFP64)
3316 return !Lo_32(Val);
3317
3318 return isUInt<32>(Val) || isInt<32>(Val);
3319}
3320
3321int64_t encode32BitLiteral(int64_t Imm, OperandType Type, bool IsLit) {
3322 switch (Type) {
3323 default:
3324 break;
3329 return Imm & 0xffff;
3343 return Lo_32(Imm);
3345 return IsLit ? Imm : Hi_32(Imm);
3346 }
3347 return Imm;
3348}
3349
3351 const Function *F = A->getParent();
3352
3353 // Arguments to compute shaders are never a source of divergence.
3354 CallingConv::ID CC = F->getCallingConv();
3355 switch (CC) {
3358 return true;
3369 // For non-compute shaders, SGPR inputs are marked with either inreg or
3370 // byval. Everything else is in VGPRs.
3371 return A->hasAttribute(Attribute::InReg) ||
3372 A->hasAttribute(Attribute::ByVal);
3373 default:
3374 // TODO: treat i1 as divergent?
3375 return A->hasAttribute(Attribute::InReg);
3376 }
3377}
3378
3379bool isArgPassedInSGPR(const CallBase *CB, unsigned ArgNo) {
3380 // Arguments to compute shaders are never a source of divergence.
3382 switch (CC) {
3385 return true;
3396 // For non-compute shaders, SGPR inputs are marked with either inreg or
3397 // byval. Everything else is in VGPRs.
3398 return CB->paramHasAttr(ArgNo, Attribute::InReg) ||
3399 CB->paramHasAttr(ArgNo, Attribute::ByVal);
3400 default:
3401 return CB->paramHasAttr(ArgNo, Attribute::InReg);
3402 }
3403}
3404
3405static bool hasSMEMByteOffset(const MCSubtargetInfo &ST) {
3406 return isGCN3Encoding(ST) || isGFX10Plus(ST);
3407}
3408
3410 int64_t EncodedOffset) {
3411 if (isGFX12Plus(ST))
3412 return isUInt<23>(EncodedOffset);
3413
3414 return hasSMEMByteOffset(ST) ? isUInt<20>(EncodedOffset)
3415 : isUInt<8>(EncodedOffset);
3416}
3417
3419 int64_t EncodedOffset, bool IsBuffer) {
3420 if (isGFX12Plus(ST)) {
3421 if (IsBuffer && EncodedOffset < 0)
3422 return false;
3423 return isInt<24>(EncodedOffset);
3424 }
3425
3426 return !IsBuffer && hasSMRDSignedImmOffset(ST) && isInt<21>(EncodedOffset);
3427}
3428
3429static bool isDwordAligned(uint64_t ByteOffset) {
3430 return (ByteOffset & 3) == 0;
3431}
3432
3434 uint64_t ByteOffset) {
3435 if (hasSMEMByteOffset(ST))
3436 return ByteOffset;
3437
3438 assert(isDwordAligned(ByteOffset));
3439 return ByteOffset >> 2;
3440}
3441
3442std::optional<int64_t> getSMRDEncodedOffset(const MCSubtargetInfo &ST,
3443 int64_t ByteOffset, bool IsBuffer,
3444 bool HasSOffset) {
3445 // For unbuffered smem loads, it is illegal for the Immediate Offset to be
3446 // negative if the resulting (Offset + (M0 or SOffset or zero) is negative.
3447 // Handle case where SOffset is not present.
3448 if (!IsBuffer && !HasSOffset && ByteOffset < 0 && hasSMRDSignedImmOffset(ST))
3449 return std::nullopt;
3450
3451 if (isGFX12Plus(ST)) // 24 bit signed offsets
3452 return isInt<24>(ByteOffset) ? std::optional<int64_t>(ByteOffset)
3453 : std::nullopt;
3454
3455 // The signed version is always a byte offset.
3456 if (!IsBuffer && hasSMRDSignedImmOffset(ST)) {
3458 return isInt<20>(ByteOffset) ? std::optional<int64_t>(ByteOffset)
3459 : std::nullopt;
3460 }
3461
3462 if (!isDwordAligned(ByteOffset) && !hasSMEMByteOffset(ST))
3463 return std::nullopt;
3464
3465 int64_t EncodedOffset = convertSMRDOffsetUnits(ST, ByteOffset);
3466 return isLegalSMRDEncodedUnsignedOffset(ST, EncodedOffset)
3467 ? std::optional<int64_t>(EncodedOffset)
3468 : std::nullopt;
3469}
3470
3471std::optional<int64_t> getSMRDEncodedLiteralOffset32(const MCSubtargetInfo &ST,
3472 int64_t ByteOffset) {
3473 if (!isCI(ST) || !isDwordAligned(ByteOffset))
3474 return std::nullopt;
3475
3476 int64_t EncodedOffset = convertSMRDOffsetUnits(ST, ByteOffset);
3477 return isUInt<32>(EncodedOffset) ? std::optional<int64_t>(EncodedOffset)
3478 : std::nullopt;
3479}
3480
3482 if (ST.getFeatureBits().test(FeatureFlatOffsetBits12))
3483 return 12;
3484 if (ST.getFeatureBits().test(FeatureFlatOffsetBits24))
3485 return 24;
3486 return 13;
3487}
3488
3489namespace {
3490
3491struct SourceOfDivergence {
3492 unsigned Intr;
3493};
3494const SourceOfDivergence *lookupSourceOfDivergence(unsigned Intr);
3495
3496struct AlwaysUniform {
3497 unsigned Intr;
3498};
3499const AlwaysUniform *lookupAlwaysUniform(unsigned Intr);
3500
3501#define GET_SourcesOfDivergence_IMPL
3502#define GET_UniformIntrinsics_IMPL
3503#define GET_Gfx9BufferFormat_IMPL
3504#define GET_Gfx10BufferFormat_IMPL
3505#define GET_Gfx11PlusBufferFormat_IMPL
3506
3507#include "AMDGPUGenSearchableTables.inc"
3508
3509} // end anonymous namespace
3510
3511bool isIntrinsicSourceOfDivergence(unsigned IntrID) {
3512 return lookupSourceOfDivergence(IntrID);
3513}
3514
3515bool isIntrinsicAlwaysUniform(unsigned IntrID) {
3516 return lookupAlwaysUniform(IntrID);
3517}
3518
3520 uint8_t NumComponents,
3521 uint8_t NumFormat,
3522 const MCSubtargetInfo &STI) {
3523 return isGFX11Plus(STI) ? getGfx11PlusBufferFormatInfo(
3524 BitsPerComp, NumComponents, NumFormat)
3525 : isGFX10(STI)
3526 ? getGfx10BufferFormatInfo(BitsPerComp, NumComponents, NumFormat)
3527 : getGfx9BufferFormatInfo(BitsPerComp, NumComponents, NumFormat);
3528}
3529
3531 const MCSubtargetInfo &STI) {
3532 return isGFX11Plus(STI) ? getGfx11PlusBufferFormatInfo(Format)
3533 : isGFX10(STI) ? getGfx10BufferFormatInfo(Format)
3534 : getGfx9BufferFormatInfo(Format);
3535}
3536
3538 const MCRegisterInfo &MRI) {
3539 const unsigned VGPRClasses[] = {
3540 AMDGPU::VGPR_16RegClassID, AMDGPU::VGPR_32RegClassID,
3541 AMDGPU::VReg_64RegClassID, AMDGPU::VReg_96RegClassID,
3542 AMDGPU::VReg_128RegClassID, AMDGPU::VReg_160RegClassID,
3543 AMDGPU::VReg_192RegClassID, AMDGPU::VReg_224RegClassID,
3544 AMDGPU::VReg_256RegClassID, AMDGPU::VReg_288RegClassID,
3545 AMDGPU::VReg_320RegClassID, AMDGPU::VReg_352RegClassID,
3546 AMDGPU::VReg_384RegClassID, AMDGPU::VReg_512RegClassID,
3547 AMDGPU::VReg_1024RegClassID};
3548
3549 for (unsigned RCID : VGPRClasses) {
3550 const MCRegisterClass &RC = MRI.getRegClass(RCID);
3551 if (RC.contains(Reg))
3552 return &RC;
3553 }
3554
3555 return nullptr;
3556}
3557
3559 unsigned Enc = MRI.getEncodingValue(Reg);
3560 unsigned Idx = Enc & AMDGPU::HWEncoding::REG_IDX_MASK;
3561 return Idx >> 8;
3562}
3563
3565 const MCRegisterInfo &MRI) {
3566 unsigned Enc = MRI.getEncodingValue(Reg);
3567 unsigned Idx = Enc & AMDGPU::HWEncoding::REG_IDX_MASK;
3568 if (Idx >= 0x100)
3569 return MCRegister();
3570
3571 const MCRegisterClass *RC = getVGPRPhysRegClass(Reg, MRI);
3572 if (!RC)
3573 return MCRegister();
3574
3575 Idx |= MSBs << 8;
3576 if (RC->getID() == AMDGPU::VGPR_16RegClassID) {
3577 // This class has 2048 registers with interleaved lo16 and hi16.
3578 Idx *= 2;
3580 ++Idx;
3581 }
3582
3583 return RC->getRegister(Idx);
3584}
3585
3586static std::optional<unsigned>
3587convertSetRegImmToVgprMSBs(unsigned Imm, unsigned Simm16,
3588 bool HasSetregVGPRMSBFixup) {
3589 constexpr unsigned VGPRMSBShift =
3591
3592 auto [HwRegId, Offset, Size] = Hwreg::HwregEncoding::decode(Simm16);
3593 if (HwRegId != Hwreg::ID_MODE ||
3594 (!HasSetregVGPRMSBFixup && (Offset + Size) < VGPRMSBShift))
3595 return {};
3596 // If there is SetregVGPRMSBFixup then Offset is ignored.
3597 if (!HasSetregVGPRMSBFixup)
3598 Imm <<= Offset;
3599 Imm = (Imm & Hwreg::VGPR_MSB_MASK) >> VGPRMSBShift;
3600 if (!HasSetregVGPRMSBFixup)
3602 return llvm::rotr<uint8_t>(static_cast<uint8_t>(Imm), /*R=*/2);
3603}
3604
3605std::optional<unsigned> convertSetRegImmToVgprMSBs(const MachineInstr &MI,
3606 bool HasSetregVGPRMSBFixup) {
3607 assert(MI.getOpcode() == AMDGPU::S_SETREG_IMM32_B32);
3608 return convertSetRegImmToVgprMSBs(MI.getOperand(0).getImm(),
3609 MI.getOperand(1).getImm(),
3610 HasSetregVGPRMSBFixup);
3611}
3612
3613std::optional<unsigned> convertSetRegImmToVgprMSBs(const MCInst &MI,
3614 bool HasSetregVGPRMSBFixup) {
3615 assert(MI.getOpcode() == AMDGPU::S_SETREG_IMM32_B32_gfx12);
3616 return convertSetRegImmToVgprMSBs(MI.getOperand(0).getImm(),
3617 MI.getOperand(1).getImm(),
3618 HasSetregVGPRMSBFixup);
3619}
3620
3621std::pair<const AMDGPU::OpName *, const AMDGPU::OpName *>
3623 static const AMDGPU::OpName VOPOps[4] = {
3624 AMDGPU::OpName::src0, AMDGPU::OpName::src1, AMDGPU::OpName::src2,
3625 AMDGPU::OpName::vdst};
3626 static const AMDGPU::OpName VDSOps[4] = {
3627 AMDGPU::OpName::addr, AMDGPU::OpName::data0, AMDGPU::OpName::data1,
3628 AMDGPU::OpName::vdst};
3629 static const AMDGPU::OpName FLATOps[4] = {
3630 AMDGPU::OpName::vaddr, AMDGPU::OpName::vdata,
3631 AMDGPU::OpName::NUM_OPERAND_NAMES, AMDGPU::OpName::vdst};
3632 static const AMDGPU::OpName BUFOps[4] = {
3633 AMDGPU::OpName::vaddr, AMDGPU::OpName::NUM_OPERAND_NAMES,
3634 AMDGPU::OpName::NUM_OPERAND_NAMES, AMDGPU::OpName::vdata};
3635 static const AMDGPU::OpName VIMGOps[4] = {
3636 AMDGPU::OpName::vaddr0, AMDGPU::OpName::vaddr1, AMDGPU::OpName::vaddr2,
3637 AMDGPU::OpName::vdata};
3638
3639 // For VOPD instructions MSB of a corresponding Y component operand VGPR
3640 // address is supposed to match X operand, otherwise VOPD shall not be
3641 // combined.
3642 static const AMDGPU::OpName VOPDOpsX[4] = {
3643 AMDGPU::OpName::src0X, AMDGPU::OpName::vsrc1X, AMDGPU::OpName::vsrc2X,
3644 AMDGPU::OpName::vdstX};
3645 static const AMDGPU::OpName VOPDOpsY[4] = {
3646 AMDGPU::OpName::src0Y, AMDGPU::OpName::vsrc1Y, AMDGPU::OpName::vsrc2Y,
3647 AMDGPU::OpName::vdstY};
3648
3649 // VOP2 MADMK instructions use src0, imm, src1 scheme.
3650 static const AMDGPU::OpName VOP2MADMKOps[4] = {
3651 AMDGPU::OpName::src0, AMDGPU::OpName::NUM_OPERAND_NAMES,
3652 AMDGPU::OpName::src1, AMDGPU::OpName::vdst};
3653 static const AMDGPU::OpName VOPDFMAMKOpsX[4] = {
3654 AMDGPU::OpName::src0X, AMDGPU::OpName::NUM_OPERAND_NAMES,
3655 AMDGPU::OpName::vsrc1X, AMDGPU::OpName::vdstX};
3656 static const AMDGPU::OpName VOPDFMAMKOpsY[4] = {
3657 AMDGPU::OpName::src0Y, AMDGPU::OpName::NUM_OPERAND_NAMES,
3658 AMDGPU::OpName::vsrc1Y, AMDGPU::OpName::vdstY};
3659
3660 unsigned TSFlags = Desc.TSFlags;
3661
3662 if (TSFlags &
3665 switch (Desc.getOpcode()) {
3666 // LD_SCALE operands ignore MSB.
3667 case AMDGPU::V_WMMA_LD_SCALE_PAIRED_B32:
3668 case AMDGPU::V_WMMA_LD_SCALE_PAIRED_B32_gfx1250:
3669 case AMDGPU::V_WMMA_LD_SCALE16_PAIRED_B64:
3670 case AMDGPU::V_WMMA_LD_SCALE16_PAIRED_B64_gfx1250:
3671 return {};
3672 case AMDGPU::V_FMAMK_F16:
3673 case AMDGPU::V_FMAMK_F16_t16:
3674 case AMDGPU::V_FMAMK_F16_t16_gfx12:
3675 case AMDGPU::V_FMAMK_F16_fake16:
3676 case AMDGPU::V_FMAMK_F16_fake16_gfx12:
3677 case AMDGPU::V_FMAMK_F32:
3678 case AMDGPU::V_FMAMK_F32_gfx12:
3679 case AMDGPU::V_FMAMK_F64:
3680 case AMDGPU::V_FMAMK_F64_gfx1250:
3681 return {VOP2MADMKOps, nullptr};
3682 default:
3683 break;
3684 }
3685 return {VOPOps, nullptr};
3686 }
3687
3688 if (TSFlags & SIInstrFlags::DS)
3689 return {VDSOps, nullptr};
3690
3691 if (TSFlags & SIInstrFlags::FLAT)
3692 return {FLATOps, nullptr};
3693
3694 if (TSFlags & (SIInstrFlags::MUBUF | SIInstrFlags::MTBUF))
3695 return {BUFOps, nullptr};
3696
3697 if (TSFlags & SIInstrFlags::VIMAGE)
3698 return {VIMGOps, nullptr};
3699
3700 if (AMDGPU::isVOPD(Desc.getOpcode())) {
3701 auto [OpX, OpY] = getVOPDComponents(Desc.getOpcode());
3702 return {(OpX == AMDGPU::V_FMAMK_F32) ? VOPDFMAMKOpsX : VOPDOpsX,
3703 (OpY == AMDGPU::V_FMAMK_F32) ? VOPDFMAMKOpsY : VOPDOpsY};
3704 }
3705
3706 assert(!(TSFlags & SIInstrFlags::MIMG));
3707
3708 if (TSFlags & (SIInstrFlags::VSAMPLE | SIInstrFlags::EXP))
3709 llvm_unreachable("Sample and export VGPR lowering is not implemented and"
3710 " these instructions are not expected on gfx1250");
3711
3712 return {};
3713}
3714
3715bool supportsScaleOffset(const MCInstrInfo &MII, unsigned Opcode) {
3716 uint64_t TSFlags = MII.get(Opcode).TSFlags;
3717
3718 if (TSFlags & SIInstrFlags::SMRD)
3719 return !getSMEMIsBuffer(Opcode);
3720 if (!(TSFlags & SIInstrFlags::FLAT))
3721 return false;
3722
3723 // Only SV and SVS modes are supported.
3724 if (TSFlags & SIInstrFlags::FlatScratch)
3725 return hasNamedOperand(Opcode, OpName::vaddr);
3726
3727 // Only GVS mode is supported.
3728 return hasNamedOperand(Opcode, OpName::vaddr) &&
3729 hasNamedOperand(Opcode, OpName::saddr);
3730
3731 return false;
3732}
3733
3734bool hasAny64BitVGPROperands(const MCInstrDesc &OpDesc, const MCInstrInfo &MII,
3735 const MCSubtargetInfo &ST) {
3736 for (auto OpName : {OpName::vdst, OpName::src0, OpName::src1, OpName::src2}) {
3737 int Idx = getNamedOperandIdx(OpDesc.getOpcode(), OpName);
3738 if (Idx == -1)
3739 continue;
3740
3741 const MCOperandInfo &OpInfo = OpDesc.operands()[Idx];
3742 int16_t RegClass = MII.getOpRegClassID(
3743 OpInfo, ST.getHwMode(MCSubtargetInfo::HwMode_RegInfo));
3744 if (RegClass == AMDGPU::VReg_64RegClassID ||
3745 RegClass == AMDGPU::VReg_64_Align2RegClassID)
3746 return true;
3747 }
3748
3749 return false;
3750}
3751
3752bool isDPALU_DPP32BitOpc(unsigned Opc) {
3753 switch (Opc) {
3754 case AMDGPU::V_MUL_LO_U32_e64:
3755 case AMDGPU::V_MUL_LO_U32_e64_dpp:
3756 case AMDGPU::V_MUL_LO_U32_e64_dpp_gfx1250:
3757 case AMDGPU::V_MUL_HI_U32_e64:
3758 case AMDGPU::V_MUL_HI_U32_e64_dpp:
3759 case AMDGPU::V_MUL_HI_U32_e64_dpp_gfx1250:
3760 case AMDGPU::V_MUL_HI_I32_e64:
3761 case AMDGPU::V_MUL_HI_I32_e64_dpp:
3762 case AMDGPU::V_MUL_HI_I32_e64_dpp_gfx1250:
3763 case AMDGPU::V_MAD_U32_e64:
3764 case AMDGPU::V_MAD_U32_e64_dpp:
3765 case AMDGPU::V_MAD_U32_e64_dpp_gfx1250:
3766 return true;
3767 default:
3768 return false;
3769 }
3770}
3771
3772bool isDPALU_DPP(const MCInstrDesc &OpDesc, const MCInstrInfo &MII,
3773 const MCSubtargetInfo &ST) {
3774 if (!ST.hasFeature(AMDGPU::FeatureDPALU_DPP))
3775 return false;
3776
3777 if (isDPALU_DPP32BitOpc(OpDesc.getOpcode()))
3778 return ST.hasFeature(AMDGPU::FeatureGFX1250Insts);
3779
3780 return hasAny64BitVGPROperands(OpDesc, MII, ST);
3781}
3782
3784 if (ST.getFeatureBits().test(FeatureAddressableLocalMemorySize32768))
3785 return 64;
3786 if (ST.getFeatureBits().test(FeatureAddressableLocalMemorySize65536))
3787 return 128;
3788 if (ST.getFeatureBits().test(FeatureAddressableLocalMemorySize163840))
3789 return 320;
3790 if (ST.getFeatureBits().test(FeatureAddressableLocalMemorySize327680))
3791 return 512;
3792 return 64; // In sync with getAddressableLocalMemorySize
3793}
3794
3795bool isPackedFP32Inst(unsigned Opc) {
3796 switch (Opc) {
3797 case AMDGPU::V_PK_ADD_F32:
3798 case AMDGPU::V_PK_ADD_F32_gfx12:
3799 case AMDGPU::V_PK_MUL_F32:
3800 case AMDGPU::V_PK_MUL_F32_gfx12:
3801 case AMDGPU::V_PK_FMA_F32:
3802 case AMDGPU::V_PK_FMA_F32_gfx12:
3803 return true;
3804 default:
3805 return false;
3806 }
3807}
3808
3809const std::array<unsigned, 3> &ClusterDimsAttr::getDims() const {
3810 assert(isFixedDims() && "expect kind to be FixedDims");
3811 return Dims;
3812}
3813
3814std::string ClusterDimsAttr::to_string() const {
3815 SmallString<10> Buffer;
3816 raw_svector_ostream OS(Buffer);
3817
3818 switch (getKind()) {
3819 case Kind::Unknown:
3820 return "";
3821 case Kind::NoCluster: {
3822 OS << EncoNoCluster << ',' << EncoNoCluster << ',' << EncoNoCluster;
3823 return Buffer.c_str();
3824 }
3825 case Kind::VariableDims: {
3826 OS << EncoVariableDims << ',' << EncoVariableDims << ','
3827 << EncoVariableDims;
3828 return Buffer.c_str();
3829 }
3830 case Kind::FixedDims: {
3831 OS << Dims[0] << ',' << Dims[1] << ',' << Dims[2];
3832 return Buffer.c_str();
3833 }
3834 }
3835 llvm_unreachable("Unknown ClusterDimsAttr kind");
3836}
3837
3839 std::optional<SmallVector<unsigned>> Attr =
3840 getIntegerVecAttribute(F, "amdgpu-cluster-dims", /*Size=*/3);
3842
3843 if (!Attr.has_value())
3844 AttrKind = Kind::Unknown;
3845 else if (all_of(*Attr, equal_to(EncoNoCluster)))
3846 AttrKind = Kind::NoCluster;
3847 else if (all_of(*Attr, equal_to(EncoVariableDims)))
3848 AttrKind = Kind::VariableDims;
3849
3850 ClusterDimsAttr A(AttrKind);
3851 if (AttrKind == Kind::FixedDims)
3852 A.Dims = {(*Attr)[0], (*Attr)[1], (*Attr)[2]};
3853
3854 return A;
3855}
3856
3857} // namespace AMDGPU
3858
3861 switch (S) {
3863 OS << "Unsupported";
3864 break;
3866 OS << "Any";
3867 break;
3869 OS << "Off";
3870 break;
3872 OS << "On";
3873 break;
3874 }
3875 return OS;
3876}
3877
3878} // 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:1252
#define S_00B848_WGP_MODE(x)
Definition SIDefines.h:1249
#define S_00B848_FWD_PROGRESS(x)
Definition SIDefines.h:1255
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:1080
const MDOperand & getOperand(unsigned I) const
Definition Metadata.h:1444
unsigned getNumOperands() const
Return number of MDNode operands.
Definition Metadata.h:1450
Representation of each machine instruction.
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
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)
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:234
@ OPERAND_REG_INLINE_C_LAST
Definition SIDefines.h:257
@ OPERAND_REG_IMM_V2FP16
Definition SIDefines.h:211
@ OPERAND_REG_INLINE_C_FP64
Definition SIDefines.h:225
@ OPERAND_REG_INLINE_C_BF16
Definition SIDefines.h:222
@ OPERAND_REG_INLINE_C_V2BF16
Definition SIDefines.h:227
@ OPERAND_REG_IMM_V2INT16
Definition SIDefines.h:213
@ OPERAND_REG_IMM_BF16
Definition SIDefines.h:208
@ OPERAND_REG_IMM_INT32
Operands with register, 32-bit, or 64-bit immediate.
Definition SIDefines.h:203
@ OPERAND_REG_IMM_V2BF16
Definition SIDefines.h:210
@ OPERAND_REG_INLINE_AC_FIRST
Definition SIDefines.h:259
@ OPERAND_REG_IMM_FP16
Definition SIDefines.h:209
@ OPERAND_REG_IMM_V2FP16_SPLAT
Definition SIDefines.h:212
@ OPERAND_REG_IMM_NOINLINE_V2FP16
Definition SIDefines.h:214
@ OPERAND_REG_IMM_FP64
Definition SIDefines.h:207
@ OPERAND_REG_INLINE_C_V2FP16
Definition SIDefines.h:228
@ OPERAND_REG_INLINE_AC_INT32
Operands with an AccVGPR register or inline constant.
Definition SIDefines.h:239
@ OPERAND_REG_INLINE_AC_FP32
Definition SIDefines.h:240
@ OPERAND_REG_IMM_V2INT32
Definition SIDefines.h:215
@ OPERAND_REG_IMM_FP32
Definition SIDefines.h:206
@ OPERAND_REG_INLINE_C_FIRST
Definition SIDefines.h:256
@ OPERAND_REG_INLINE_C_FP32
Definition SIDefines.h:224
@ OPERAND_REG_INLINE_AC_LAST
Definition SIDefines.h:260
@ OPERAND_REG_INLINE_C_INT32
Definition SIDefines.h:220
@ OPERAND_REG_INLINE_C_V2INT16
Definition SIDefines.h:226
@ OPERAND_REG_IMM_V2FP32
Definition SIDefines.h:216
@ OPERAND_REG_INLINE_AC_FP64
Definition SIDefines.h:241
@ OPERAND_REG_INLINE_C_FP16
Definition SIDefines.h:223
@ OPERAND_INLINE_SPLIT_BARRIER_INT32
Definition SIDefines.h:231
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.