LLVM 24.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, bool IndexedRsrc,
316 bool IndexedSamp) {
317 const MIMGInfo *Info =
318 getMIMGOpcodeHelper(BaseOpcode, MIMGEncoding, VDataDwords, VAddrDwords,
319 IndexedRsrc, IndexedSamp);
320 return Info ? Info->Opcode : -1;
321}
322
324 const MIMGInfo *Info = getMIMGInfo(Opc);
325 return Info ? getMIMGBaseOpcodeInfo(Info->BaseOpcode) : nullptr;
326}
327
328int getMaskedMIMGOp(unsigned Opc, unsigned NewChannels) {
329 const MIMGInfo *OrigInfo = getMIMGInfo(Opc);
330 const MIMGInfo *NewInfo = getMIMGOpcodeHelper(
331 OrigInfo->BaseOpcode, OrigInfo->MIMGEncoding, NewChannels,
332 OrigInfo->VAddrDwords, OrigInfo->IndexedRsrc, OrigInfo->IndexedSamp);
333 return NewInfo ? NewInfo->Opcode : -1;
334}
335
336unsigned getAddrSizeMIMGOp(const MIMGBaseOpcodeInfo *BaseOpcode,
337 const MIMGDimInfo *Dim, bool IsA16,
338 bool IsG16Supported) {
339 unsigned AddrWords = BaseOpcode->NumExtraArgs;
340 unsigned AddrComponents = (BaseOpcode->Coordinates ? Dim->NumCoords : 0) +
341 (BaseOpcode->LodOrClampOrMip ? 1 : 0);
342 if (IsA16)
343 AddrWords += divideCeil(AddrComponents, 2);
344 else
345 AddrWords += AddrComponents;
346
347 // Note: For subtargets that support A16 but not G16, enabling A16 also
348 // enables 16 bit gradients.
349 // For subtargets that support A16 (operand) and G16 (done with a different
350 // instruction encoding), they are independent.
351
352 if (BaseOpcode->Gradients) {
353 if ((IsA16 && !IsG16Supported) || BaseOpcode->G16)
354 // There are two gradients per coordinate, we pack them separately.
355 // For the 3d case,
356 // we get (dy/du, dx/du) (-, dz/du) (dy/dv, dx/dv) (-, dz/dv)
357 AddrWords += alignTo<2>(Dim->NumGradients / 2);
358 else
359 AddrWords += Dim->NumGradients;
360 }
361 return AddrWords;
362}
363
374
383
388
393
397
401
405
410
418
423
426 bool IsX;
427 bool IsY;
428};
429
430#define GET_FP4FP8DstByteSelTable_DECL
431#define GET_FP4FP8DstByteSelTable_IMPL
432
437
443
444#define GET_DPMACCInstructionTable_DECL
445#define GET_DPMACCInstructionTable_IMPL
446#define GET_MTBUFInfoTable_DECL
447#define GET_MTBUFInfoTable_IMPL
448#define GET_MUBUFInfoTable_DECL
449#define GET_MUBUFInfoTable_IMPL
450#define GET_SMInfoTable_DECL
451#define GET_SMInfoTable_IMPL
452#define GET_VOP1InfoTable_DECL
453#define GET_VOP1InfoTable_IMPL
454#define GET_VOP2InfoTable_DECL
455#define GET_VOP2InfoTable_IMPL
456#define GET_VOP3InfoTable_DECL
457#define GET_VOP3InfoTable_IMPL
458#define GET_VOPC64DPPTable_DECL
459#define GET_VOPC64DPPTable_IMPL
460#define GET_VOPC64DPP8Table_DECL
461#define GET_VOPC64DPP8Table_IMPL
462#define GET_VOPCAsmOnlyInfoTable_DECL
463#define GET_VOPCAsmOnlyInfoTable_IMPL
464#define GET_VOP3CAsmOnlyInfoTable_DECL
465#define GET_VOP3CAsmOnlyInfoTable_IMPL
466#define GET_VOPDComponentTable_DECL
467#define GET_VOPDComponentTable_IMPL
468#define GET_VOPDPairs_DECL
469#define GET_VOPDPairs_IMPL
470#define GET_VOPDXYTable_DECL
471#define GET_VOPDXYTable_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
651bool isValidWMMAScaleFmtCombination(unsigned AFmt, unsigned AScale,
652 unsigned BFmt, unsigned BScale) {
653 auto isValid = [](unsigned Fmt, unsigned Scale) -> bool {
654 switch (Fmt) {
659 if (Scale != WMMA::MATRIX_SCALE_FMT_E8)
660 return false;
661 break;
663 if (Scale != WMMA::MATRIX_SCALE_FMT_E8 &&
666 return false;
667 break;
668 }
669 return true;
670 };
671
672 if (!isValid(AFmt, AScale) || !isValid(BFmt, BScale))
673 return false;
674
675 if (AFmt == WMMA::MATRIX_FMT_FP4 && BFmt == WMMA::MATRIX_FMT_FP4 &&
676 AScale != BScale)
677 return false;
678
679 return true;
680}
681
683 if (ST.hasFeature(AMDGPU::FeatureGFX13Insts))
685 if (ST.hasFeature(AMDGPU::FeatureGFX1250Insts))
687 if (ST.hasFeature(AMDGPU::FeatureGFX12Insts))
689 if (ST.hasFeature(AMDGPU::FeatureGFX11_7Insts))
691 if (ST.hasFeature(AMDGPU::FeatureGFX11Insts))
693 llvm_unreachable("Subtarget generation does not support VOPD!");
694}
695
696CanBeVOPD getCanBeVOPD(unsigned Opc, unsigned EncodingFamily, bool VOPD3) {
697 bool IsConvertibleToBitOp = VOPD3 ? getBitOp2(Opc) : 0;
698 Opc = IsConvertibleToBitOp ? (unsigned)AMDGPU::V_BITOP3_B32_e64 : Opc;
699 // Normalize through VOPDComponentTable so that e32 and e64 variants
700 // of the same logical opcode all share a single entry.
701 const VOPDComponentInfo *Info = getVOPDComponentHelper(Opc);
702 if (!Info)
703 return {false, false};
704 unsigned Key =
705 (Info->VOPDOp << 5) | (EncodingFamily << 1) | (VOPD3 ? 1u : 0u);
706 const VOPDXYInfo *XYInfo = getVOPDXYInfo(Key);
707 if (!XYInfo)
708 return {false, false};
709 return {XYInfo->IsX, XYInfo->IsY};
710}
711
712unsigned getVOPDOpcode(unsigned Opc, bool VOPD3) {
713 bool IsConvertibleToBitOp = VOPD3 ? getBitOp2(Opc) : 0;
714 Opc = IsConvertibleToBitOp ? (unsigned)AMDGPU::V_BITOP3_B32_e64 : Opc;
715 const VOPDComponentInfo *Info = getVOPDComponentHelper(Opc);
716 return Info ? Info->VOPDOp : ~0u;
717}
718
719bool isVOPD(unsigned Opc) {
720 return AMDGPU::hasNamedOperand(Opc, AMDGPU::OpName::src0X);
721}
722
723bool isMAC(unsigned Opc) {
724 return Opc == AMDGPU::V_MAC_F32_e64_gfx6_gfx7 ||
725 Opc == AMDGPU::V_MAC_F32_e64_gfx10 ||
726 Opc == AMDGPU::V_MAC_F32_e64_vi ||
727 Opc == AMDGPU::V_MAC_LEGACY_F32_e64_gfx6_gfx7 ||
728 Opc == AMDGPU::V_MAC_LEGACY_F32_e64_gfx10 ||
729 Opc == AMDGPU::V_MAC_F16_e64_vi ||
730 Opc == AMDGPU::V_FMAC_F64_e64_gfx90a ||
731 Opc == AMDGPU::V_FMAC_F64_e64_gfx12 ||
732 Opc == AMDGPU::V_FMAC_F64_e64_gfx13 ||
733 Opc == AMDGPU::V_FMAC_F32_e64_gfx10 ||
734 Opc == AMDGPU::V_FMAC_F32_e64_gfx11 ||
735 Opc == AMDGPU::V_FMAC_F32_e64_gfx12 ||
736 Opc == AMDGPU::V_FMAC_F32_e64_gfx13 ||
737 Opc == AMDGPU::V_FMAC_F32_e64_vi ||
738 Opc == AMDGPU::V_FMAC_LEGACY_F32_e64_gfx10 ||
739 Opc == AMDGPU::V_FMAC_DX9_ZERO_F32_e64_gfx11 ||
740 Opc == AMDGPU::V_FMAC_F16_e64_gfx10 ||
741 Opc == AMDGPU::V_FMAC_F16_t16_e64_gfx11 ||
742 Opc == AMDGPU::V_FMAC_F16_fake16_e64_gfx11 ||
743 Opc == AMDGPU::V_FMAC_F16_t16_e64_gfx12 ||
744 Opc == AMDGPU::V_FMAC_F16_fake16_e64_gfx12 ||
745 Opc == AMDGPU::V_FMAC_F16_t16_e64_gfx13 ||
746 Opc == AMDGPU::V_FMAC_F16_fake16_e64_gfx13 ||
747 Opc == AMDGPU::V_DOT2C_F32_F16_e64_vi ||
748 Opc == AMDGPU::V_DOT2C_F32_BF16_e64_vi ||
749 Opc == AMDGPU::V_DOT2C_I32_I16_e64_vi ||
750 Opc == AMDGPU::V_DOT4C_I32_I8_e64_vi ||
751 Opc == AMDGPU::V_DOT8C_I32_I4_e64_vi;
752}
753
754bool isPermlane16(unsigned Opc) {
755 return Opc == AMDGPU::V_PERMLANE16_B32_gfx10 ||
756 Opc == AMDGPU::V_PERMLANEX16_B32_gfx10 ||
757 Opc == AMDGPU::V_PERMLANE16_B32_e64_gfx11 ||
758 Opc == AMDGPU::V_PERMLANEX16_B32_e64_gfx11 ||
759 Opc == AMDGPU::V_PERMLANE16_B32_e64_gfx12 ||
760 Opc == AMDGPU::V_PERMLANE16_B32_e64_gfx13 ||
761 Opc == AMDGPU::V_PERMLANEX16_B32_e64_gfx12 ||
762 Opc == AMDGPU::V_PERMLANEX16_B32_e64_gfx13 ||
763 Opc == AMDGPU::V_PERMLANE16_VAR_B32_e64_gfx12 ||
764 Opc == AMDGPU::V_PERMLANE16_VAR_B32_e64_gfx13 ||
765 Opc == AMDGPU::V_PERMLANEX16_VAR_B32_e64_gfx12 ||
766 Opc == AMDGPU::V_PERMLANEX16_VAR_B32_e64_gfx13;
767}
768
770 return Opc == AMDGPU::V_CVT_F32_BF8_e64_gfx12 ||
771 Opc == AMDGPU::V_CVT_F32_FP8_e64_gfx12 ||
772 Opc == AMDGPU::V_CVT_F32_BF8_e64_dpp_gfx12 ||
773 Opc == AMDGPU::V_CVT_F32_FP8_e64_dpp_gfx12 ||
774 Opc == AMDGPU::V_CVT_F32_BF8_e64_dpp8_gfx12 ||
775 Opc == AMDGPU::V_CVT_F32_FP8_e64_dpp8_gfx12 ||
776 Opc == AMDGPU::V_CVT_PK_F32_BF8_fake16_e64_gfx12 ||
777 Opc == AMDGPU::V_CVT_PK_F32_FP8_fake16_e64_gfx12 ||
778 Opc == AMDGPU::V_CVT_PK_F32_BF8_t16_e64_gfx12 ||
779 Opc == AMDGPU::V_CVT_PK_F32_FP8_t16_e64_gfx12;
780}
781
782bool isGenericAtomic(unsigned Opc) {
783 return Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_SWAP ||
784 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_ADD ||
785 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_SUB ||
786 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_SMIN ||
787 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_UMIN ||
788 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_SMAX ||
789 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_UMAX ||
790 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_AND ||
791 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_OR ||
792 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_XOR ||
793 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_INC ||
794 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_DEC ||
795 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_FADD ||
796 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_FMIN ||
797 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_FMAX ||
798 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_CMPSWAP ||
799 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_SUB_CLAMP_U32 ||
800 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_COND_SUB_U32 ||
801 Opc == AMDGPU::G_AMDGPU_ATOMIC_CMPXCHG;
802}
803
804bool isAsyncStore(unsigned Opc) {
805 return Opc == GLOBAL_STORE_ASYNC_FROM_LDS_B8_gfx1250 ||
806 Opc == GLOBAL_STORE_ASYNC_FROM_LDS_B32_gfx1250 ||
807 Opc == GLOBAL_STORE_ASYNC_FROM_LDS_B64_gfx1250 ||
808 Opc == GLOBAL_STORE_ASYNC_FROM_LDS_B128_gfx1250 ||
809 Opc == GLOBAL_STORE_ASYNC_FROM_LDS_B8_SADDR_gfx1250 ||
810 Opc == GLOBAL_STORE_ASYNC_FROM_LDS_B32_SADDR_gfx1250 ||
811 Opc == GLOBAL_STORE_ASYNC_FROM_LDS_B64_SADDR_gfx1250 ||
812 Opc == GLOBAL_STORE_ASYNC_FROM_LDS_B128_SADDR_gfx1250;
813}
814
815bool isTensorStore(unsigned Opc) {
816 return Opc == TENSOR_STORE_FROM_LDS_d2_gfx1250 ||
817 Opc == TENSOR_STORE_FROM_LDS_d4_gfx1250;
818}
819
820unsigned getTemporalHintType(const MCInstrDesc TID) {
821 if (SIInstrFlags::isAtomic(TID))
823 unsigned Opc = TID.getOpcode();
824 // Async and Tensor store should have the temporal hint type of TH_TYPE_STORE
825 if (TID.mayStore() &&
826 (isAsyncStore(Opc) || isTensorStore(Opc) || !TID.mayLoad()))
827 return CPol::TH_TYPE_STORE;
828
829 // This will default to returning TH_TYPE_LOAD when neither MayStore nor
830 // MayLoad flag is present which is the case with instructions like
831 // image_get_resinfo.
832 return CPol::TH_TYPE_LOAD;
833}
834
835bool isTrue16Inst(unsigned Opc) {
836 const VOPTrue16Info *Info = getTrue16OpcodeHelper(Opc);
837 return Info && Info->IsTrue16;
838}
839
841 const FP4FP8DstByteSelInfo *Info = getFP4FP8DstByteSelHelper(Opc);
842 if (!Info)
843 return FPType::None;
844 if (Info->HasFP8DstByteSel)
845 return FPType::FP8;
846 if (Info->HasFP4DstByteSel)
847 return FPType::FP4;
848
849 return FPType::None;
850}
851
852bool isDPMACCInstruction(unsigned Opc) {
853 const DPMACCInstructionInfo *Info = getDPMACCInstructionHelper(Opc);
854 return Info && Info->IsDPMACCInstruction;
855}
856
857unsigned mapWMMA2AddrTo3AddrOpcode(unsigned Opc) {
858 const WMMAOpcodeMappingInfo *Info = getWMMAMappingInfoFrom2AddrOpcode(Opc);
859 return Info ? Info->Opcode3Addr : ~0u;
860}
861
862unsigned mapWMMA3AddrTo2AddrOpcode(unsigned Opc) {
863 const WMMAOpcodeMappingInfo *Info = getWMMAMappingInfoFrom3AddrOpcode(Opc);
864 return Info ? Info->Opcode2Addr : ~0u;
865}
866
867// Wrapper for Tablegen'd function. enum Subtarget is not defined in any
868// header files, so we need to wrap it in a function that takes unsigned
869// instead.
870int32_t getMCOpcode(uint32_t Opcode, unsigned Gen) {
871 return getMCOpcodeGen(Opcode, static_cast<Subtarget>(Gen));
872}
873
874unsigned getBitOp2(unsigned Opc) {
875 switch (Opc) {
876 default:
877 return 0;
878 case AMDGPU::V_AND_B32_e32:
879 return 0x40;
880 case AMDGPU::V_OR_B32_e32:
881 return 0x54;
882 case AMDGPU::V_XOR_B32_e32:
883 return 0x14;
884 case AMDGPU::V_XNOR_B32_e32:
885 return 0x41;
886 }
887}
888
889int getVOPDFull(unsigned OpX, unsigned OpY, unsigned EncodingFamily,
890 bool VOPD3) {
891 bool IsConvertibleToBitOp = VOPD3 ? getBitOp2(OpY) : 0;
892 OpY = IsConvertibleToBitOp ? (unsigned)AMDGPU::V_BITOP3_B32_e64 : OpY;
893 const VOPDInfo *Info =
894 getVOPDInfoFromComponentOpcodes(OpX, OpY, EncodingFamily, VOPD3);
895 return Info ? Info->Opcode : -1;
896}
897
898std::pair<unsigned, unsigned> getVOPDComponents(unsigned VOPDOpcode) {
899 const VOPDInfo *Info = getVOPDOpcodeHelper(VOPDOpcode);
900 assert(Info);
901 const auto *OpX = getVOPDBaseFromComponent(Info->OpX);
902 const auto *OpY = getVOPDBaseFromComponent(Info->OpY);
903 assert(OpX && OpY);
904 return {OpX->BaseVOP, OpY->BaseVOP};
905}
906
907namespace VOPD {
908
909ComponentProps::ComponentProps(const MCInstrDesc &OpDesc, bool VOP3Layout) {
911
914 auto TiedIdx = OpDesc.getOperandConstraint(Component::SRC2, MCOI::TIED_TO);
915 assert(TiedIdx == -1 || TiedIdx == Component::DST);
916 HasSrc2Acc = TiedIdx != -1;
917 Opcode = OpDesc.getOpcode();
918
919 IsVOP3 = VOP3Layout || SIInstrFlags::isVOP3(OpDesc);
920 SrcOperandsNum = AMDGPU::hasNamedOperand(Opcode, AMDGPU::OpName::src2) ? 3
921 : AMDGPU::hasNamedOperand(Opcode, AMDGPU::OpName::imm) ? 3
922 : AMDGPU::hasNamedOperand(Opcode, AMDGPU::OpName::src1) ? 2
923 : 1;
924 assert(SrcOperandsNum <= Component::MAX_SRC_NUM);
925
926 if (Opcode == AMDGPU::V_CNDMASK_B32_e32 ||
927 Opcode == AMDGPU::V_CNDMASK_B32_e64) {
928 // CNDMASK is an awkward exception, it has FP modifiers, but not FP
929 // operands.
930 NumVOPD3Mods = 2;
931 if (IsVOP3)
932 SrcOperandsNum = 3;
933 } else if (Opcode == AMDGPU::V_DOT2_F32_F16 ||
934 Opcode == AMDGPU::V_DOT2_F32_BF16) {
935 // VOP3P opcodes that have VOPD but don't have VOP2 version. Using VOPD3
936 // path in getIndexOfSrcInMCOperands to get correct src operand indexes,
937 // but generating VOPD, not VOPD3.
938 NumVOPD3Mods = SrcOperandsNum;
939 } else if (isSISrcFPOperand(OpDesc,
940 getNamedOperandIdx(Opcode, OpName::src0))) {
941 // All FP VOPD instructions have Neg modifiers for all operands except
942 // for tied src2.
943 NumVOPD3Mods = SrcOperandsNum;
944 if (HasSrc2Acc)
945 --NumVOPD3Mods;
946 }
947
948 if (SIInstrFlags::isVOP3(OpDesc))
949 return;
950
951 auto OperandsNum = OpDesc.getNumOperands();
952 unsigned CompOprIdx;
953 for (CompOprIdx = Component::SRC1; CompOprIdx < OperandsNum; ++CompOprIdx) {
954 if (OpDesc.operands()[CompOprIdx].OperandType == AMDGPU::OPERAND_KIMM32) {
955 MandatoryLiteralIdx = CompOprIdx;
956 break;
957 }
958 }
959}
960
962 return getNamedOperandIdx(Opcode, OpName::bitop3);
963}
964
965unsigned ComponentInfo::getIndexInParsedOperands(unsigned CompOprIdx) const {
966 assert(CompOprIdx < Component::MAX_OPR_NUM);
967
968 if (CompOprIdx == Component::DST)
970
971 auto CompSrcIdx = CompOprIdx - Component::DST_NUM;
972 if (CompSrcIdx < getCompParsedSrcOperandsNum())
973 return getIndexOfSrcInParsedOperands(CompSrcIdx);
974
975 // The specified operand does not exist.
976 return 0;
977}
978
980 std::function<MCRegister(unsigned, unsigned)> GetRegIdx,
981 const MCRegisterInfo &MRI, bool SkipSrc, bool AllowSameVGPR, bool VOPD3,
982 bool HasGFX11InterlockHazard) const {
983
984 auto OpXRegs = getRegIndices(ComponentIndex::X, GetRegIdx,
985 CompInfo[ComponentIndex::X].isVOP3());
986 auto OpYRegs = getRegIndices(ComponentIndex::Y, GetRegIdx,
987 CompInfo[ComponentIndex::Y].isVOP3());
988
989 const auto banksOverlap = [&MRI](MCRegister X, MCRegister Y,
990 unsigned BanksMask) -> bool {
991 MCRegister BaseX = MRI.getSubReg(X, AMDGPU::sub0);
992 MCRegister BaseY = MRI.getSubReg(Y, AMDGPU::sub0);
993 if (!BaseX)
994 BaseX = X;
995 if (!BaseY)
996 BaseY = Y;
997 if ((BaseX.id() & BanksMask) == (BaseY.id() & BanksMask))
998 return true;
999 if (BaseX != X /* This is 64-bit register */ &&
1000 ((BaseX.id() + 1) & BanksMask) == (BaseY.id() & BanksMask))
1001 return true;
1002 if (BaseY != Y &&
1003 (BaseX.id() & BanksMask) == ((BaseY.id() + 1) & BanksMask))
1004 return true;
1005
1006 // If both are 64-bit bank conflict will be detected yet while checking
1007 // the first subreg.
1008 return false;
1009 };
1010
1011 unsigned CompOprIdx;
1012 for (CompOprIdx = 0; CompOprIdx < Component::MAX_OPR_NUM; ++CompOprIdx) {
1013 unsigned BanksMasks = VOPD3 ? VOPD3_VGPR_BANK_MASKS[CompOprIdx]
1014 : HasGFX11InterlockHazard
1015 ? VOPD_GFX11_VGPR_BANK_MASKS[CompOprIdx]
1016 : VOPD_VGPR_BANK_MASKS[CompOprIdx];
1017 if (!OpXRegs[CompOprIdx] || !OpYRegs[CompOprIdx])
1018 continue;
1019
1020 if (getVGPREncodingMSBs(OpXRegs[CompOprIdx], MRI) !=
1021 getVGPREncodingMSBs(OpYRegs[CompOprIdx], MRI))
1022 return CompOprIdx;
1023
1024 if (SkipSrc && CompOprIdx >= Component::DST_NUM)
1025 continue;
1026
1027 if (CompOprIdx < Component::DST_NUM) {
1028 // Even if we do not check vdst parity, vdst operands still shall not
1029 // overlap.
1030 if (MRI.regsOverlap(OpXRegs[CompOprIdx], OpYRegs[CompOprIdx]))
1031 return CompOprIdx;
1032 if (VOPD3) // No need to check dst parity.
1033 continue;
1034 }
1035
1036 if (banksOverlap(OpXRegs[CompOprIdx], OpYRegs[CompOprIdx], BanksMasks) &&
1037 (!AllowSameVGPR || CompOprIdx < Component::DST_NUM ||
1038 OpXRegs[CompOprIdx] != OpYRegs[CompOprIdx]))
1039 return CompOprIdx;
1040 }
1041
1042 return {};
1043}
1044
1045// Return an array of VGPR registers [DST,SRC0,SRC1,SRC2] used
1046// by the specified component. If an operand is unused
1047// or is not a VGPR, the corresponding value is 0.
1048//
1049// GetRegIdx(Component, MCOperandIdx) must return a VGPR register index
1050// for the specified component and MC operand. The callback must return 0
1051// if the operand is not a register or not a VGPR.
1053InstInfo::getRegIndices(unsigned CompIdx,
1054 std::function<MCRegister(unsigned, unsigned)> GetRegIdx,
1055 bool VOPD3) const {
1056 assert(CompIdx < COMPONENTS_NUM);
1057
1058 const auto &Comp = CompInfo[CompIdx];
1060
1061 RegIndices[DST] = GetRegIdx(CompIdx, Comp.getIndexOfDstInMCOperands());
1062
1063 for (unsigned CompOprIdx : {SRC0, SRC1, SRC2}) {
1064 unsigned CompSrcIdx = CompOprIdx - DST_NUM;
1065 RegIndices[CompOprIdx] =
1066 Comp.hasRegSrcOperand(CompSrcIdx)
1067 ? GetRegIdx(CompIdx,
1068 Comp.getIndexOfSrcInMCOperands(CompSrcIdx, VOPD3))
1069 : MCRegister();
1070 }
1071 return RegIndices;
1072}
1073
1074} // namespace VOPD
1075
1077 return VOPD::InstInfo(OpX, OpY);
1078}
1079
1081 const MCInstrInfo *InstrInfo) {
1082 auto [OpX, OpY] = getVOPDComponents(VOPDOpcode);
1083 const auto &OpXDesc = InstrInfo->get(OpX);
1084 const auto &OpYDesc = InstrInfo->get(OpY);
1085 bool VOPD3 = SIInstrFlags::isVOPD3(*InstrInfo, VOPDOpcode);
1087 VOPD::ComponentInfo OpYInfo(OpYDesc, OpXInfo, VOPD3);
1088 return VOPD::InstInfo(OpXInfo, OpYInfo);
1089}
1090
1092 StringRef FeatureString) {
1093 // In codegen the mode comes from module flags and FeatureString is empty, so
1094 // the processor defaults apply. The assembler has no target directive, so it
1095 // pins the mode via the +xnack/-xnack/+sramecc/-sramecc feature string.
1097 STI.getCPU(), FeatureString);
1098}
1099
1100namespace IsaInfo {
1101
1103 if (STI.getFeatureBits().test(FeatureInstCacheLineSize128))
1104 return 128;
1105 if (STI.getFeatureBits().test(FeatureInstCacheLineSize64))
1106 return 64;
1107 return 64;
1108}
1109
1110unsigned getWavefrontSize(const MCSubtargetInfo &STI) {
1111 if (STI.getFeatureBits().test(FeatureWavefrontSize16))
1112 return 16;
1113 if (STI.getFeatureBits().test(FeatureWavefrontSize32))
1114 return 32;
1115
1116 return 64;
1117}
1118
1119// Maximum LDS a single work-group can address. This is a fixed HW cap. It does
1120// not depend on how many SIMDs a work-group runs on.
1122 if (STI.getFeatureBits().test(FeatureAddressableLocalMemorySize32768))
1123 return 32768;
1124 if (STI.getFeatureBits().test(FeatureAddressableLocalMemorySize65536))
1125 return 65536;
1126 if (STI.getFeatureBits().test(FeatureAddressableLocalMemorySize163840))
1127 return 163840;
1128 if (STI.getFeatureBits().test(FeatureAddressableLocalMemorySize196608))
1129 return 196608;
1130 if (STI.getFeatureBits().test(FeatureAddressableLocalMemorySize327680))
1131 return 327680;
1132 return 32768;
1133}
1134
1135// Total physical size of LDS on the block, in bytes. On targets with
1136// FeatureHalfAddressablePhysicalLocalMemory the physical block is twice the
1137// addressable size (gfx6: 64 KiB physical and 32 KiB addressable;
1138// gfx10/11/12: 128 KiB physical and 64 KiB addressable). On other targets it is
1139// equal to the addressable size.
1140static unsigned getPhysicalLocalMemorySize(const MCSubtargetInfo &STI) {
1141 unsigned Addressable = getMaxHWAddressableLocalMemorySize(STI);
1142 if (STI.getFeatureBits().test(FeatureHalfAddressablePhysicalLocalMemory))
1143 return 2 * Addressable;
1144 return Addressable;
1145}
1146
1147// Sizes in use, by generation (addressable / physical block):
1148// gfx6 : 32 KiB addressable, 64 KiB physical block
1149// gfx7 / gfx8 / gfx9: 64 KiB
1150// gfx9.5 (gfx950) : 160 KiB
1151// gfx10 / 11 / 12 : 64 KiB addressable, 128 KiB physical block
1152// gfx12.5 (gfx1250) : 320 KiB (always runs on four SIMDs)
1153// gfx13 : 192 KiB on four SIMDs, 96 KiB on two
1154// Total available in the current mode. The physical size is halved when a
1155// work-group runs on two SIMDs.
1157 unsigned Size = getPhysicalLocalMemorySize(STI);
1158 if (!isFullSIMDMode(STI))
1159 Size /= 2;
1160 return Size;
1161}
1162
1163// What one work-group can allocate in the current mode. This is the HW
1164// addressable cap, but never more than the total available in the current mode.
1166 return std::min(getMaxHWAddressableLocalMemorySize(STI),
1167 getLocalMemorySize(STI));
1168}
1169
1171 unsigned FlatWorkGroupSize) {
1172 assert(FlatWorkGroupSize != 0);
1173 if (!STI.getTargetTriple().isAMDGCN())
1174 return 8;
1175 GPUKind Kind = parseArchAMDGCN(STI.getCPU());
1176 unsigned MaxWaves =
1178 unsigned N = getWavesPerWorkGroup(STI, FlatWorkGroupSize);
1179 if (N == 1) {
1180 // Single-wave workgroups don't consume barrier resources.
1181 return MaxWaves;
1182 }
1183
1184 unsigned MaxBarriers = 16;
1185 if (isGFX10Plus(STI) && !STI.getFeatureBits().test(FeatureCuMode))
1186 MaxBarriers = 32;
1187
1188 return std::min(MaxWaves / N, MaxBarriers);
1189}
1190
1192 unsigned FlatWorkGroupSize) {
1193 return divideCeil(getWavesPerWorkGroup(STI, FlatWorkGroupSize),
1195}
1196
1198 unsigned FlatWorkGroupSize) {
1199 return divideCeil(FlatWorkGroupSize, getWavefrontSize(STI));
1200}
1201
1202unsigned getSGPREncodingGranule(const MCSubtargetInfo &STI) { return 8; }
1203
1204// Per-wave SGPRs reserved for the trap handler when enabled.
1205static unsigned getSGPRTrapHandlerReserve(const MCSubtargetInfo &STI) {
1206 return STI.getFeatureBits().test(FeatureTrapHandler) ? TRAP_NUM_SGPRS : 0;
1207}
1208
1209// Per-wave SGPR budget (before the addressable clamp): take off the trap
1210// reserve, round down to \p Granule. Shared by getMinNumSGPRs() and
1211// getMaxNumSGPRs(); getOccupancyWithNumSGPRs() is the closed-form algebraic
1212// inverse of this same budget (it does not call this helper), so the two encode
1213// one model.
1214static unsigned getSGPRBudgetPerWave(unsigned TotalNumSGPRs,
1215 unsigned WavesPerEU, unsigned TrapReserve,
1216 unsigned Granule) {
1217 assert(WavesPerEU != 0 && Granule != 0);
1218 unsigned Budget = TotalNumSGPRs / WavesPerEU;
1219 Budget -= std::min(Budget, TrapReserve);
1220 return alignDown(Budget, Granule);
1221}
1222
1223unsigned getMinNumSGPRs(const MCSubtargetInfo &STI, unsigned WavesPerEU) {
1224 assert(WavesPerEU != 0);
1225
1227 if (Version.Major >= 10)
1228 return 0;
1229
1230 GPUKind Kind = parseArchAMDGCN(STI.getCPU());
1231 if (WavesPerEU >= getMaxWavesPerEU(Kind))
1232 return 0;
1233
1234 unsigned MinNumSGPRs =
1235 getSGPRBudgetPerWave(getTotalNumSGPRs(Kind), WavesPerEU + 1,
1237 getSGPRAllocGranule(Kind)) +
1238 1;
1239 return std::min(MinNumSGPRs, getAddressableNumSGPRs(Kind));
1240}
1241
1242unsigned getMaxNumSGPRs(const MCSubtargetInfo &STI, unsigned WavesPerEU,
1243 bool Addressable) {
1244 assert(WavesPerEU != 0);
1245
1246 GPUKind Kind = parseArchAMDGCN(STI.getCPU());
1247 unsigned AddressableNumSGPRs = getAddressableNumSGPRs(Kind);
1249 if (Version.Major >= 10)
1250 return Addressable ? AddressableNumSGPRs : 108;
1251 if (Version.Major >= 8 && !Addressable)
1252 AddressableNumSGPRs = 112;
1253 unsigned MaxNumSGPRs = getSGPRBudgetPerWave(
1254 getTotalNumSGPRs(Kind), WavesPerEU, getSGPRTrapHandlerReserve(STI),
1255 getSGPRAllocGranule(Kind));
1256 return std::min(MaxNumSGPRs, AddressableNumSGPRs);
1257}
1258
1260 // From GFX10 on the SGPR file is large enough that SGPRs never limit
1261 // occupancy. Kept as one capability so callers don't each test the version.
1262 return getIsaVersion(STI.getCPU()).Major < 10;
1263}
1264
1265unsigned getNumExtraSGPRs(const MCSubtargetInfo &STI, bool VCCUsed,
1266 bool FlatScrUsed, bool XNACKUsed) {
1267 unsigned ExtraSGPRs = 0;
1268 if (VCCUsed)
1269 ExtraSGPRs = 2;
1270
1272 if (Version.Major >= 10)
1273 return ExtraSGPRs;
1274
1275 if (Version.Major < 8) {
1276 if (FlatScrUsed)
1277 ExtraSGPRs = 4;
1278 } else {
1279 if (XNACKUsed)
1280 ExtraSGPRs = 4;
1281
1282 if (FlatScrUsed ||
1283 STI.getFeatureBits().test(AMDGPU::FeatureArchitectedFlatScratch))
1284 ExtraSGPRs = 6;
1285 }
1286
1287 return ExtraSGPRs;
1288}
1289
1290static unsigned getGranulatedNumRegisterBlocks(unsigned NumRegs,
1291 unsigned Granule) {
1292 return divideCeil(std::max(1u, NumRegs), Granule);
1293}
1294
1295unsigned getNumSGPRBlocks(const MCSubtargetInfo &STI, unsigned NumSGPRs) {
1296 // SGPRBlocks is actual number of SGPR blocks minus 1.
1298 1;
1299}
1300
1302 unsigned DynamicVGPRBlockSize,
1303 std::optional<bool> EnableWavefrontSize32) {
1304 if (STI.getFeatureBits().test(FeatureGFX90AInsts))
1305 return 8;
1306
1307 if (DynamicVGPRBlockSize != 0)
1308 return DynamicVGPRBlockSize;
1309
1310 bool IsWave32 = EnableWavefrontSize32
1311 ? *EnableWavefrontSize32
1312 : STI.getFeatureBits().test(FeatureWavefrontSize32);
1313
1314 if (STI.getFeatureBits().test(Feature1536VGPRs))
1315 return IsWave32 ? 24 : 12;
1316
1317 if (hasGFX10_3Insts(STI))
1318 return IsWave32 ? 16 : 8;
1319
1320 return IsWave32 ? 8 : 4;
1321}
1322
1324 std::optional<bool> EnableWavefrontSize32) {
1325 if (STI.getFeatureBits().test(FeatureGFX90AInsts))
1326 return 8;
1327
1328 bool IsWave32 = EnableWavefrontSize32
1329 ? *EnableWavefrontSize32
1330 : STI.getFeatureBits().test(FeatureWavefrontSize32);
1331
1332 if (STI.getFeatureBits().test(Feature1024AddressableVGPRs))
1333 return IsWave32 ? 16 : 8;
1334
1335 return IsWave32 ? 8 : 4;
1336}
1337
1338unsigned getArchVGPRAllocGranule() { return 4; }
1339
1341 const auto &Features = STI.getFeatureBits();
1342 if (Features.test(Feature1024AddressableVGPRs))
1343 return Features.test(FeatureWavefrontSize32) ? 1024 : 512;
1344 return 256;
1345}
1346
1348 unsigned DynamicVGPRBlockSize) {
1349 const auto &Features = STI.getFeatureBits();
1350 if (Features.test(FeatureGFX90AInsts))
1351 return 512;
1352
1353 if (DynamicVGPRBlockSize != 0) {
1354 // On GFX12 we can allocate at most MaxDynamicVGPRBlocks blocks of VGPRs.
1355 return MaxDynamicVGPRBlocks *
1356 getVGPRAllocGranule(STI, DynamicVGPRBlockSize);
1357 }
1358 return getAddressableNumArchVGPRs(STI);
1359}
1360
1362 unsigned NumVGPRs,
1363 unsigned DynamicVGPRBlockSize) {
1364 GPUKind Kind = parseArchAMDGCN(STI.getCPU());
1365 bool IsWave32 = STI.getFeatureBits().test(FeatureWavefrontSize32);
1367 NumVGPRs, getVGPRAllocGranule(STI, DynamicVGPRBlockSize),
1368 getMaxWavesPerEU(Kind), AMDGPU::getTotalNumVGPRs(Kind, IsWave32));
1369}
1370
1371unsigned getNumWavesPerEUWithNumVGPRs(unsigned NumVGPRs, unsigned Granule,
1372 unsigned MaxWaves,
1373 unsigned TotalNumVGPRs) {
1374 if (NumVGPRs < Granule)
1375 return MaxWaves;
1376 unsigned RoundedRegs = alignTo(NumVGPRs, Granule);
1377 return std::min(std::max(TotalNumVGPRs / RoundedRegs, 1u), MaxWaves);
1378}
1379
1380unsigned getOccupancyWithNumSGPRs(unsigned SGPRs, unsigned MaxWaves,
1381 unsigned TotalNumSGPRs, unsigned Granule,
1382 unsigned TrapReserve) {
1383 // Closed-form inverse of getMaxNumSGPRs(): the budget condition
1384 // SGPRs <= alignDown(TotalNumSGPRs / W - TrapReserve, Granule)
1385 // solves to W <= TotalNumSGPRs / (alignTo(SGPRs, Granule) + TrapReserve).
1386 unsigned PerWave = alignTo(SGPRs, Granule) + TrapReserve;
1387 return PerWave ? std::clamp(TotalNumSGPRs / PerWave, 1u, MaxWaves) : MaxWaves;
1388}
1389
1390unsigned getOccupancyWithNumSGPRs(const MCSubtargetInfo &STI, unsigned SGPRs) {
1391 GPUKind Kind = parseArchAMDGCN(STI.getCPU());
1392 unsigned MaxWaves = getMaxWavesPerEU(Kind);
1393
1394 if (!isSGPROccupancyLimited(STI))
1395 return MaxWaves;
1396
1397 return getOccupancyWithNumSGPRs(SGPRs, MaxWaves, getTotalNumSGPRs(Kind),
1398 getSGPRAllocGranule(Kind),
1400}
1401
1402unsigned getMinNumVGPRs(const MCSubtargetInfo &STI, unsigned WavesPerEU,
1403 unsigned DynamicVGPRBlockSize) {
1404 assert(WavesPerEU != 0);
1405
1406 // In dynamic VGPR mode, (static) occupancy does not depend on VGPR usage,
1407 // so getMaxNumVGPRs does not depend on WavesPerEU, and thus we need to return
1408 // zero because there is no nonzero VGPR usage N where going below N
1409 // achieves higher (static) occupancy.
1410 bool DynamicVGPREnabled = (DynamicVGPRBlockSize != 0);
1411 if (DynamicVGPREnabled)
1412 return 0;
1413
1414 GPUKind Kind = parseArchAMDGCN(STI.getCPU());
1415 unsigned MaxWavesPerEU = getMaxWavesPerEU(Kind);
1416 if (WavesPerEU >= MaxWavesPerEU)
1417 return 0;
1418
1419 unsigned TotNumVGPRs = AMDGPU::getTotalNumVGPRs(
1420 Kind, STI.getFeatureBits().test(FeatureWavefrontSize32));
1421 unsigned AddrsableNumVGPRs =
1422 getAddressableNumVGPRs(STI, DynamicVGPRBlockSize);
1423 unsigned Granule = getVGPRAllocGranule(STI, DynamicVGPRBlockSize);
1424 unsigned MaxNumVGPRs = alignDown(TotNumVGPRs / WavesPerEU, Granule);
1425
1426 if (MaxNumVGPRs == alignDown(TotNumVGPRs / MaxWavesPerEU, Granule))
1427 return 0;
1428
1429 unsigned MinWavesPerEU = getNumWavesPerEUWithNumVGPRs(STI, AddrsableNumVGPRs,
1430 DynamicVGPRBlockSize);
1431 if (WavesPerEU < MinWavesPerEU)
1432 return getMinNumVGPRs(STI, MinWavesPerEU, DynamicVGPRBlockSize);
1433
1434 unsigned MaxNumVGPRsNext = alignDown(TotNumVGPRs / (WavesPerEU + 1), Granule);
1435 unsigned MinNumVGPRs = 1 + std::min(MaxNumVGPRs - Granule, MaxNumVGPRsNext);
1436 return std::min(MinNumVGPRs, AddrsableNumVGPRs);
1437}
1438
1439unsigned getMaxNumVGPRs(const MCSubtargetInfo &STI, unsigned WavesPerEU,
1440 unsigned DynamicVGPRBlockSize) {
1441 assert(WavesPerEU != 0);
1442
1443 unsigned TotNumVGPRs = AMDGPU::getTotalNumVGPRs(
1444 parseArchAMDGCN(STI.getCPU()),
1445 STI.getFeatureBits().test(FeatureWavefrontSize32));
1446
1447 // In dynamic VGPR mode, WavesPerEU does not imply a VGPR limit.
1448 bool DynamicVGPREnabled = (DynamicVGPRBlockSize != 0);
1449 unsigned MaxNumVGPRs =
1450 DynamicVGPREnabled
1451 ? TotNumVGPRs
1452 : alignDown(TotNumVGPRs / WavesPerEU,
1453 getVGPRAllocGranule(STI, DynamicVGPRBlockSize));
1454 unsigned AddressableNumVGPRs =
1455 getAddressableNumVGPRs(STI, DynamicVGPRBlockSize);
1456 return std::min(MaxNumVGPRs, AddressableNumVGPRs);
1457}
1458
1459unsigned getEncodedNumVGPRBlocks(const MCSubtargetInfo &STI, unsigned NumVGPRs,
1460 std::optional<bool> EnableWavefrontSize32) {
1462 NumVGPRs, getVGPREncodingGranule(STI, EnableWavefrontSize32)) -
1463 1;
1464}
1465
1467 unsigned NumVGPRs,
1468 unsigned DynamicVGPRBlockSize,
1469 std::optional<bool> EnableWavefrontSize32) {
1471 NumVGPRs,
1472 getVGPRAllocGranule(STI, DynamicVGPRBlockSize, EnableWavefrontSize32));
1473}
1474} // end namespace IsaInfo
1475
1477 const MCSubtargetInfo &STI) {
1479 KernelCode.amd_kernel_code_version_major = 1;
1480 KernelCode.amd_kernel_code_version_minor = 2;
1481 KernelCode.amd_machine_kind = 1; // AMD_MACHINE_KIND_AMDGPU
1482 KernelCode.amd_machine_version_major = Version.Major;
1483 KernelCode.amd_machine_version_minor = Version.Minor;
1484 KernelCode.amd_machine_version_stepping = Version.Stepping;
1486 if (STI.getFeatureBits().test(FeatureWavefrontSize32)) {
1487 KernelCode.wavefront_size = 5;
1489 } else {
1490 KernelCode.wavefront_size = 6;
1491 }
1492
1493 // If the code object does not support indirect functions, then the value must
1494 // be 0xffffffff.
1495 KernelCode.call_convention = -1;
1496
1497 // These alignment values are specified in powers of two, so alignment =
1498 // 2^n. The minimum alignment is 2^4 = 16.
1499 KernelCode.kernarg_segment_alignment = 4;
1500 KernelCode.group_segment_alignment = 4;
1501 KernelCode.private_segment_alignment = 4;
1502
1503 if (Version.Major >= 10) {
1504 KernelCode.compute_pgm_resource_registers |=
1505 S_00B848_WGP_MODE(STI.getFeatureBits().test(FeatureCuMode) ? 0 : 1) |
1507 }
1508}
1509
1512}
1513
1516}
1517
1519 unsigned AS = GV->getAddressSpace();
1520 return AS == AMDGPUAS::CONSTANT_ADDRESS ||
1522}
1523
1525 return TT.getArch() == Triple::r600;
1526}
1527
1528static bool isValidRegPrefix(char C) {
1529 return C == 'v' || C == 's' || C == 'a';
1530}
1531
1532std::tuple<char, unsigned, unsigned> parseAsmPhysRegName(StringRef RegName) {
1533 if (RegName.empty())
1534 return {};
1535
1536 char Kind = RegName.front();
1537 if (!isValidRegPrefix(Kind))
1538 return {};
1539
1540 RegName = RegName.drop_front();
1541 if (RegName.consume_front("[")) {
1542 unsigned Idx, End;
1543 bool Failed = RegName.consumeInteger(10, Idx);
1544 Failed |= !RegName.consume_front(":");
1545 Failed |= RegName.consumeInteger(10, End);
1546 Failed |= !RegName.consume_back("]");
1547 if (!Failed) {
1548 unsigned NumRegs = End - Idx + 1;
1549 if (NumRegs > 1)
1550 return {Kind, Idx, NumRegs};
1551 }
1552 } else {
1553 unsigned Idx;
1554 bool Failed = RegName.getAsInteger(10, Idx);
1555 if (!Failed)
1556 return {Kind, Idx, 1};
1557 }
1558
1559 return {};
1560}
1561
1562std::tuple<char, unsigned, unsigned>
1564 StringRef RegName = Constraint;
1565 if (!RegName.consume_front("{") || !RegName.consume_back("}"))
1566 return {};
1568}
1569
1570std::pair<unsigned, unsigned>
1572 std::pair<unsigned, unsigned> Default,
1573 bool OnlyFirstRequired) {
1574 if (auto Attr = getIntegerPairAttribute(F, Name, OnlyFirstRequired))
1575 return {Attr->first, Attr->second.value_or(Default.second)};
1576 return Default;
1577}
1578
1579std::optional<std::pair<unsigned, std::optional<unsigned>>>
1581 bool OnlyFirstRequired) {
1582 Attribute A = F.getFnAttribute(Name);
1583 if (!A.isStringAttribute())
1584 return std::nullopt;
1585
1586 LLVMContext &Ctx = F.getContext();
1587 std::pair<unsigned, std::optional<unsigned>> Ints;
1588 std::pair<StringRef, StringRef> Strs = A.getValueAsString().split(',');
1589 if (Strs.first.trim().getAsInteger(0, Ints.first)) {
1590 Ctx.emitError("can't parse first integer attribute " + Name);
1591 return std::nullopt;
1592 }
1593 unsigned Second = 0;
1594 if (Strs.second.trim().getAsInteger(0, Second)) {
1595 if (!OnlyFirstRequired || !Strs.second.trim().empty()) {
1596 Ctx.emitError("can't parse second integer attribute " + Name);
1597 return std::nullopt;
1598 }
1599 } else {
1600 Ints.second = Second;
1601 }
1602
1603 return Ints;
1604}
1605
1607 unsigned Size,
1608 unsigned DefaultVal) {
1609 std::optional<SmallVector<unsigned>> R =
1611 return R.has_value() ? *R : SmallVector<unsigned>(Size, DefaultVal);
1612}
1613
1614std::optional<SmallVector<unsigned>>
1616 assert(Size > 2);
1617 LLVMContext &Ctx = F.getContext();
1618
1619 Attribute A = F.getFnAttribute(Name);
1620 if (!A.isValid())
1621 return std::nullopt;
1622 if (!A.isStringAttribute()) {
1623 Ctx.emitError(Name + " is not a string attribute");
1624 return std::nullopt;
1625 }
1626
1628
1629 StringRef S = A.getValueAsString();
1630 unsigned i = 0;
1631 for (; !S.empty() && i < Size; i++) {
1632 std::pair<StringRef, StringRef> Strs = S.split(',');
1633 unsigned IntVal;
1634 if (Strs.first.trim().getAsInteger(0, IntVal)) {
1635 Ctx.emitError("can't parse integer attribute " + Strs.first + " in " +
1636 Name);
1637 return std::nullopt;
1638 }
1639 Vals[i] = IntVal;
1640 S = Strs.second;
1641 }
1642
1643 if (!S.empty() || i < Size) {
1644 Ctx.emitError("attribute " + Name +
1645 " has incorrect number of integers; expected " +
1647 return std::nullopt;
1648 }
1649 return Vals;
1650}
1651
1653 return getIntegerVecAttribute(F, "amdgpu-max-num-workgroups", 3,
1654 std::numeric_limits<uint32_t>::max());
1655}
1656
1657bool hasValueInRangeLikeMetadata(const MDNode &MD, int64_t Val) {
1658 assert((MD.getNumOperands() % 2 == 0) && "invalid number of operands!");
1659 for (unsigned I = 0, E = MD.getNumOperands() / 2; I != E; ++I) {
1660 auto Low =
1661 mdconst::extract<ConstantInt>(MD.getOperand(2 * I + 0))->getValue();
1662 auto High =
1663 mdconst::extract<ConstantInt>(MD.getOperand(2 * I + 1))->getValue();
1664 // There are two types of [A; B) ranges:
1665 // A < B, e.g. [4; 5) which is a range that only includes 4.
1666 // A > B, e.g. [5; 4) which is a range that wraps around and includes
1667 // everything except 4.
1668 if (Low.ult(High)) {
1669 if (Low.ule(Val) && High.ugt(Val))
1670 return true;
1671 } else {
1672 if (Low.uge(Val) && High.ult(Val))
1673 return true;
1674 }
1675 }
1676
1677 return false;
1678}
1679
1681 return (1 << (getVmcntBitWidthLo(Version.Major) +
1682 getVmcntBitWidthHi(Version.Major))) -
1683 1;
1684}
1685
1687 return (1 << getLoadcntBitWidth(Version.Major)) - 1;
1688}
1689
1691 return (1 << getSamplecntBitWidth(Version.Major)) - 1;
1692}
1693
1695 return (1 << getBvhcntBitWidth(Version.Major)) - 1;
1696}
1697
1699 return (1 << getExpcntBitWidth(Version.Major)) - 1;
1700}
1701
1703 return (1 << getLgkmcntBitWidth(Version.Major)) - 1;
1704}
1705
1707 return (1 << getDscntBitWidth(Version.Major)) - 1;
1708}
1709
1711 return (1 << getKmcntBitWidth(Version.Major)) - 1;
1712}
1713
1715 return (1 << getXcntBitWidth(Version.Major, Version.Minor)) - 1;
1716}
1717
1719 return (1 << getAsynccntBitWidth(Version.Major, Version.Minor)) - 1;
1720}
1721
1723 return (1 << getStorecntBitWidth(Version.Major)) - 1;
1724}
1725
1727 unsigned VmcntLo = getBitMask(getVmcntBitShiftLo(Version.Major),
1728 getVmcntBitWidthLo(Version.Major));
1729 unsigned Expcnt = getBitMask(getExpcntBitShift(Version.Major),
1730 getExpcntBitWidth(Version.Major));
1731 unsigned Lgkmcnt = getBitMask(getLgkmcntBitShift(Version.Major),
1732 getLgkmcntBitWidth(Version.Major));
1733 unsigned VmcntHi = getBitMask(getVmcntBitShiftHi(Version.Major),
1734 getVmcntBitWidthHi(Version.Major));
1735 return VmcntLo | Expcnt | Lgkmcnt | VmcntHi;
1736}
1737
1738unsigned decodeVmcnt(const IsaVersion &Version, unsigned Waitcnt) {
1739 unsigned VmcntLo = unpackBits(Waitcnt, getVmcntBitShiftLo(Version.Major),
1740 getVmcntBitWidthLo(Version.Major));
1741 unsigned VmcntHi = unpackBits(Waitcnt, getVmcntBitShiftHi(Version.Major),
1742 getVmcntBitWidthHi(Version.Major));
1743 return VmcntLo | VmcntHi << getVmcntBitWidthLo(Version.Major);
1744}
1745
1746unsigned decodeExpcnt(const IsaVersion &Version, unsigned Waitcnt) {
1747 return unpackBits(Waitcnt, getExpcntBitShift(Version.Major),
1748 getExpcntBitWidth(Version.Major));
1749}
1750
1751unsigned decodeLgkmcnt(const IsaVersion &Version, unsigned Waitcnt) {
1752 return unpackBits(Waitcnt, getLgkmcntBitShift(Version.Major),
1753 getLgkmcntBitWidth(Version.Major));
1754}
1755
1756unsigned decodeLoadcnt(const IsaVersion &Version, unsigned Waitcnt) {
1757 return unpackBits(Waitcnt, getLoadcntStorecntBitShift(Version.Major),
1758 getLoadcntBitWidth(Version.Major));
1759}
1760
1761unsigned decodeStorecnt(const IsaVersion &Version, unsigned Waitcnt) {
1762 return unpackBits(Waitcnt, getLoadcntStorecntBitShift(Version.Major),
1763 getStorecntBitWidth(Version.Major));
1764}
1765
1766unsigned decodeDscnt(const IsaVersion &Version, unsigned Waitcnt) {
1767 return unpackBits(Waitcnt, getDscntBitShift(Version.Major),
1768 getDscntBitWidth(Version.Major));
1769}
1770
1771void decodeWaitcnt(const IsaVersion &Version, unsigned Waitcnt, unsigned &Vmcnt,
1772 unsigned &Expcnt, unsigned &Lgkmcnt) {
1773 Vmcnt = decodeVmcnt(Version, Waitcnt);
1774 Expcnt = decodeExpcnt(Version, Waitcnt);
1775 Lgkmcnt = decodeLgkmcnt(Version, Waitcnt);
1776}
1777
1778unsigned encodeVmcnt(const IsaVersion &Version, unsigned Waitcnt,
1779 unsigned Vmcnt) {
1780 Waitcnt = packBits(Vmcnt, Waitcnt, getVmcntBitShiftLo(Version.Major),
1781 getVmcntBitWidthLo(Version.Major));
1782 return packBits(Vmcnt >> getVmcntBitWidthLo(Version.Major), Waitcnt,
1783 getVmcntBitShiftHi(Version.Major),
1784 getVmcntBitWidthHi(Version.Major));
1785}
1786
1787unsigned encodeExpcnt(const IsaVersion &Version, unsigned Waitcnt,
1788 unsigned Expcnt) {
1789 return packBits(Expcnt, Waitcnt, getExpcntBitShift(Version.Major),
1790 getExpcntBitWidth(Version.Major));
1791}
1792
1793unsigned encodeLgkmcnt(const IsaVersion &Version, unsigned Waitcnt,
1794 unsigned Lgkmcnt) {
1795 return packBits(Lgkmcnt, Waitcnt, getLgkmcntBitShift(Version.Major),
1796 getLgkmcntBitWidth(Version.Major));
1797}
1798
1799unsigned encodeWaitcnt(const IsaVersion &Version, unsigned Vmcnt,
1800 unsigned Expcnt, unsigned Lgkmcnt) {
1801 unsigned Waitcnt = getWaitcntBitMask(Version);
1803 Waitcnt = encodeExpcnt(Version, Waitcnt, Expcnt);
1804 Waitcnt = encodeLgkmcnt(Version, Waitcnt, Lgkmcnt);
1805 return Waitcnt;
1806}
1807
1809 bool IsStore) {
1810 unsigned Dscnt = getBitMask(getDscntBitShift(Version.Major),
1811 getDscntBitWidth(Version.Major));
1812 if (IsStore) {
1813 unsigned Storecnt = getBitMask(getLoadcntStorecntBitShift(Version.Major),
1814 getStorecntBitWidth(Version.Major));
1815 return Dscnt | Storecnt;
1816 }
1817 unsigned Loadcnt = getBitMask(getLoadcntStorecntBitShift(Version.Major),
1818 getLoadcntBitWidth(Version.Major));
1819 return Dscnt | Loadcnt;
1820}
1821
1822static unsigned encodeLoadcnt(const IsaVersion &Version, unsigned Waitcnt,
1823 unsigned Loadcnt) {
1824 return packBits(Loadcnt, Waitcnt, getLoadcntStorecntBitShift(Version.Major),
1825 getLoadcntBitWidth(Version.Major));
1826}
1827
1828static unsigned encodeStorecnt(const IsaVersion &Version, unsigned Waitcnt,
1829 unsigned Storecnt) {
1830 return packBits(Storecnt, Waitcnt, getLoadcntStorecntBitShift(Version.Major),
1831 getStorecntBitWidth(Version.Major));
1832}
1833
1834static unsigned encodeDscnt(const IsaVersion &Version, unsigned Waitcnt,
1835 unsigned Dscnt) {
1836 return packBits(Dscnt, Waitcnt, getDscntBitShift(Version.Major),
1837 getDscntBitWidth(Version.Major));
1838}
1839
1840unsigned encodeLoadcntDscnt(const IsaVersion &Version, unsigned Loadcnt,
1841 unsigned Dscnt) {
1842 unsigned Waitcnt = getCombinedCountBitMask(Version, false);
1843 Waitcnt = encodeLoadcnt(Version, Waitcnt, Loadcnt);
1845 return Waitcnt;
1846}
1847
1848unsigned encodeStorecntDscnt(const IsaVersion &Version, unsigned Storecnt,
1849 unsigned Dscnt) {
1850 unsigned Waitcnt = getCombinedCountBitMask(Version, true);
1851 Waitcnt = encodeStorecnt(Version, Waitcnt, Storecnt);
1853 return Waitcnt;
1854}
1855
1856//===----------------------------------------------------------------------===//
1857// Custom Operand Values
1858//===----------------------------------------------------------------------===//
1859
1861 int Size,
1862 const MCSubtargetInfo &STI) {
1863 unsigned Enc = 0;
1864 for (int Idx = 0; Idx < Size; ++Idx) {
1865 const auto &Op = Opr[Idx];
1866 if (Op.isSupported(STI))
1867 Enc |= Op.encode(Op.Default);
1868 }
1869 return Enc;
1870}
1871
1873 int Size, unsigned Code,
1874 bool &HasNonDefaultVal,
1875 const MCSubtargetInfo &STI) {
1876 unsigned UsedOprMask = 0;
1877 HasNonDefaultVal = false;
1878 for (int Idx = 0; Idx < Size; ++Idx) {
1879 const auto &Op = Opr[Idx];
1880 if (!Op.isSupported(STI))
1881 continue;
1882 UsedOprMask |= Op.getMask();
1883 unsigned Val = Op.decode(Code);
1884 if (!Op.isValid(Val))
1885 return false;
1886 HasNonDefaultVal |= (Val != Op.Default);
1887 }
1888 return (Code & ~UsedOprMask) == 0;
1889}
1890
1891static bool decodeCustomOperand(const CustomOperandVal *Opr, int Size,
1892 unsigned Code, int &Idx, StringRef &Name,
1893 unsigned &Val, bool &IsDefault,
1894 const MCSubtargetInfo &STI) {
1895 while (Idx < Size) {
1896 const auto &Op = Opr[Idx++];
1897 if (Op.isSupported(STI)) {
1898 Name = Op.Name;
1899 Val = Op.decode(Code);
1900 IsDefault = (Val == Op.Default);
1901 return true;
1902 }
1903 }
1904
1905 return false;
1906}
1907
1909 int64_t InputVal) {
1910 if (InputVal < 0 || InputVal > Op.Max)
1911 return OPR_VAL_INVALID;
1912 return Op.encode(InputVal);
1913}
1914
1915static int encodeCustomOperand(const CustomOperandVal *Opr, int Size,
1916 const StringRef Name, int64_t InputVal,
1917 unsigned &UsedOprMask,
1918 const MCSubtargetInfo &STI) {
1919 int InvalidId = OPR_ID_UNKNOWN;
1920 for (int Idx = 0; Idx < Size; ++Idx) {
1921 const auto &Op = Opr[Idx];
1922 if (Op.Name == Name) {
1923 if (!Op.isSupported(STI)) {
1924 InvalidId = OPR_ID_UNSUPPORTED;
1925 continue;
1926 }
1927 auto OprMask = Op.getMask();
1928 if (OprMask & UsedOprMask)
1929 return OPR_ID_DUPLICATE;
1930 UsedOprMask |= OprMask;
1931 return encodeCustomOperandVal(Op, InputVal);
1932 }
1933 }
1934 return InvalidId;
1935}
1936
1937//===----------------------------------------------------------------------===//
1938// DepCtr
1939//===----------------------------------------------------------------------===//
1940
1941namespace DepCtr {
1942
1944 static int Default = -1;
1945 if (Default == -1)
1947 return Default;
1948}
1949
1950bool isSymbolicDepCtrEncoding(unsigned Code, bool &HasNonDefaultVal,
1951 const MCSubtargetInfo &STI) {
1953 HasNonDefaultVal, STI);
1954}
1955
1956bool decodeDepCtr(unsigned Code, int &Id, StringRef &Name, unsigned &Val,
1957 bool &IsDefault, const MCSubtargetInfo &STI) {
1958 return decodeCustomOperand(DepCtrInfo, DEP_CTR_SIZE, Code, Id, Name, Val,
1959 IsDefault, STI);
1960}
1961
1962int encodeDepCtr(const StringRef Name, int64_t Val, unsigned &UsedOprMask,
1963 const MCSubtargetInfo &STI) {
1964 return encodeCustomOperand(DepCtrInfo, DEP_CTR_SIZE, Name, Val, UsedOprMask,
1965 STI);
1966}
1967
1968unsigned getVaVdstBitMask() { return (1 << getVaVdstBitWidth()) - 1; }
1969
1970unsigned getVaSdstBitMask() { return (1 << getVaSdstBitWidth()) - 1; }
1971
1972unsigned getVaSsrcBitMask() { return (1 << getVaSsrcBitWidth()) - 1; }
1973
1975 return (1 << getHoldCntWidth(Version.Major, Version.Minor)) - 1;
1976}
1977
1978unsigned getVmVsrcBitMask() { return (1 << getVmVsrcBitWidth()) - 1; }
1979
1980unsigned getVaVccBitMask() { return (1 << getVaVccBitWidth()) - 1; }
1981
1982unsigned getSaSdstBitMask() { return (1 << getSaSdstBitWidth()) - 1; }
1983
1984unsigned decodeFieldVmVsrc(unsigned Encoded) {
1985 return unpackBits(Encoded, getVmVsrcBitShift(), getVmVsrcBitWidth());
1986}
1987
1988unsigned decodeFieldVaVdst(unsigned Encoded) {
1989 return unpackBits(Encoded, getVaVdstBitShift(), getVaVdstBitWidth());
1990}
1991
1992unsigned decodeFieldSaSdst(unsigned Encoded) {
1993 return unpackBits(Encoded, getSaSdstBitShift(), getSaSdstBitWidth());
1994}
1995
1996unsigned decodeFieldVaSdst(unsigned Encoded) {
1997 return unpackBits(Encoded, getVaSdstBitShift(), getVaSdstBitWidth());
1998}
1999
2000unsigned decodeFieldVaVcc(unsigned Encoded) {
2001 return unpackBits(Encoded, getVaVccBitShift(), getVaVccBitWidth());
2002}
2003
2004unsigned decodeFieldVaSsrc(unsigned Encoded) {
2005 return unpackBits(Encoded, getVaSsrcBitShift(), getVaSsrcBitWidth());
2006}
2007
2008unsigned decodeFieldHoldCnt(unsigned Encoded, const IsaVersion &Version) {
2009 return unpackBits(Encoded, getHoldCntBitShift(),
2010 getHoldCntWidth(Version.Major, Version.Minor));
2011}
2012
2013unsigned encodeFieldVmVsrc(unsigned Encoded, unsigned VmVsrc) {
2014 return packBits(VmVsrc, Encoded, getVmVsrcBitShift(), getVmVsrcBitWidth());
2015}
2016
2017unsigned encodeFieldVmVsrc(unsigned VmVsrc, const MCSubtargetInfo &STI) {
2018 unsigned Encoded = getDefaultDepCtrEncoding(STI);
2019 return encodeFieldVmVsrc(Encoded, VmVsrc);
2020}
2021
2022unsigned encodeFieldVaVdst(unsigned Encoded, unsigned VaVdst) {
2023 return packBits(VaVdst, Encoded, getVaVdstBitShift(), getVaVdstBitWidth());
2024}
2025
2026unsigned encodeFieldVaVdst(unsigned VaVdst, const MCSubtargetInfo &STI) {
2027 unsigned Encoded = getDefaultDepCtrEncoding(STI);
2028 return encodeFieldVaVdst(Encoded, VaVdst);
2029}
2030
2031unsigned encodeFieldSaSdst(unsigned Encoded, unsigned SaSdst) {
2032 return packBits(SaSdst, Encoded, getSaSdstBitShift(), getSaSdstBitWidth());
2033}
2034
2035unsigned encodeFieldSaSdst(unsigned SaSdst, const MCSubtargetInfo &STI) {
2036 unsigned Encoded = getDefaultDepCtrEncoding(STI);
2037 return encodeFieldSaSdst(Encoded, SaSdst);
2038}
2039
2040unsigned encodeFieldVaSdst(unsigned Encoded, unsigned VaSdst) {
2041 return packBits(VaSdst, Encoded, getVaSdstBitShift(), getVaSdstBitWidth());
2042}
2043
2044unsigned encodeFieldVaSdst(unsigned VaSdst, const MCSubtargetInfo &STI) {
2045 unsigned Encoded = getDefaultDepCtrEncoding(STI);
2046 return encodeFieldVaSdst(Encoded, VaSdst);
2047}
2048
2049unsigned encodeFieldVaVcc(unsigned Encoded, unsigned VaVcc) {
2050 return packBits(VaVcc, Encoded, getVaVccBitShift(), getVaVccBitWidth());
2051}
2052
2053unsigned encodeFieldVaVcc(unsigned VaVcc, const MCSubtargetInfo &STI) {
2054 unsigned Encoded = getDefaultDepCtrEncoding(STI);
2055 return encodeFieldVaVcc(Encoded, VaVcc);
2056}
2057
2058unsigned encodeFieldVaSsrc(unsigned Encoded, unsigned VaSsrc) {
2059 return packBits(VaSsrc, Encoded, getVaSsrcBitShift(), getVaSsrcBitWidth());
2060}
2061
2062unsigned encodeFieldVaSsrc(unsigned VaSsrc, const MCSubtargetInfo &STI) {
2063 unsigned Encoded = getDefaultDepCtrEncoding(STI);
2064 return encodeFieldVaSsrc(Encoded, VaSsrc);
2065}
2066
2067unsigned encodeFieldHoldCnt(unsigned Encoded, unsigned HoldCnt,
2068 const IsaVersion &Version) {
2069 return packBits(HoldCnt, Encoded, getHoldCntBitShift(),
2070 getHoldCntWidth(Version.Major, Version.Minor));
2071}
2072
2073unsigned encodeFieldHoldCnt(unsigned HoldCnt, const MCSubtargetInfo &STI) {
2074 unsigned Encoded = getDefaultDepCtrEncoding(STI);
2075 return encodeFieldHoldCnt(Encoded, HoldCnt, getIsaVersion(STI.getCPU()));
2076}
2077
2078} // namespace DepCtr
2079
2080//===----------------------------------------------------------------------===//
2081// exp tgt
2082//===----------------------------------------------------------------------===//
2083
2084namespace Exp {
2085
2086struct ExpTgt {
2088 unsigned Tgt;
2089 unsigned MaxIndex;
2090};
2091
2092// clang-format off
2093static constexpr ExpTgt ExpTgtInfo[] = {
2094 {{"null"}, ET_NULL, ET_NULL_MAX_IDX},
2095 {{"mrtz"}, ET_MRTZ, ET_MRTZ_MAX_IDX},
2096 {{"prim"}, ET_PRIM, ET_PRIM_MAX_IDX},
2097 {{"mrt"}, ET_MRT0, ET_MRT_MAX_IDX},
2098 {{"pos"}, ET_POS0, ET_POS_MAX_IDX},
2099 {{"dual_src_blend"},ET_DUAL_SRC_BLEND0, ET_DUAL_SRC_BLEND_MAX_IDX},
2100 {{"param"}, ET_PARAM0, ET_PARAM_MAX_IDX},
2101};
2102// clang-format on
2103
2104bool getTgtName(unsigned Id, StringRef &Name, int &Index) {
2105 for (const ExpTgt &Val : ExpTgtInfo) {
2106 if (Val.Tgt <= Id && Id <= Val.Tgt + Val.MaxIndex) {
2107 Index = (Val.MaxIndex == 0) ? -1 : (Id - Val.Tgt);
2108 Name = Val.Name;
2109 return true;
2110 }
2111 }
2112 return false;
2113}
2114
2115unsigned getTgtId(const StringRef Name) {
2116
2117 for (const ExpTgt &Val : ExpTgtInfo) {
2118 if (Val.MaxIndex == 0 && Name == Val.Name)
2119 return Val.Tgt;
2120
2121 if (Val.MaxIndex > 0 && Name.starts_with(Val.Name)) {
2122 StringRef Suffix = Name.drop_front(Val.Name.size());
2123
2124 unsigned Id;
2125 if (Suffix.getAsInteger(10, Id) || Id > Val.MaxIndex)
2126 return ET_INVALID;
2127
2128 // Disable leading zeroes
2129 if (Suffix.size() > 1 && Suffix[0] == '0')
2130 return ET_INVALID;
2131
2132 return Val.Tgt + Id;
2133 }
2134 }
2135 return ET_INVALID;
2136}
2137
2138bool isSupportedTgtId(unsigned Id, const MCSubtargetInfo &STI) {
2139 switch (Id) {
2140 case ET_NULL:
2141 return !isGFX11Plus(STI);
2142 case ET_POS4:
2143 case ET_PRIM:
2144 return isGFX10Plus(STI);
2145 case ET_DUAL_SRC_BLEND0:
2146 case ET_DUAL_SRC_BLEND1:
2147 return isGFX11Plus(STI);
2148 default:
2149 if (Id >= ET_PARAM0 && Id <= ET_PARAM31)
2150 return !isGFX11Plus(STI) || isGFX13Plus(STI);
2151 return true;
2152 }
2153}
2154
2155} // namespace Exp
2156
2157//===----------------------------------------------------------------------===//
2158// MTBUF Format
2159//===----------------------------------------------------------------------===//
2160
2161namespace MTBUFFormat {
2162
2163int64_t getDfmt(const StringRef Name) {
2164 for (int Id = DFMT_MIN; Id <= DFMT_MAX; ++Id) {
2165 if (Name == DfmtSymbolic[Id])
2166 return Id;
2167 }
2168 return DFMT_UNDEF;
2169}
2170
2172 assert(Id <= DFMT_MAX);
2173 return DfmtSymbolic[Id];
2174}
2175
2177 if (isSI(STI) || isCI(STI))
2178 return NfmtSymbolicSICI;
2179 if (isVI(STI) || isGFX9(STI))
2180 return NfmtSymbolicVI;
2181 return NfmtSymbolicGFX10;
2182}
2183
2184int64_t getNfmt(const StringRef Name, const MCSubtargetInfo &STI) {
2185 const auto *lookupTable = getNfmtLookupTable(STI);
2186 for (int Id = NFMT_MIN; Id <= NFMT_MAX; ++Id) {
2187 if (Name == lookupTable[Id])
2188 return Id;
2189 }
2190 return NFMT_UNDEF;
2191}
2192
2193StringRef getNfmtName(unsigned Id, const MCSubtargetInfo &STI) {
2194 assert(Id <= NFMT_MAX);
2195 return getNfmtLookupTable(STI)[Id];
2196}
2197
2198bool isValidDfmtNfmt(unsigned Id, const MCSubtargetInfo &STI) {
2199 unsigned Dfmt;
2200 unsigned Nfmt;
2201 decodeDfmtNfmt(Id, Dfmt, Nfmt);
2202 return isValidNfmt(Nfmt, STI);
2203}
2204
2205bool isValidNfmt(unsigned Id, const MCSubtargetInfo &STI) {
2206 return !getNfmtName(Id, STI).empty();
2207}
2208
2209int64_t encodeDfmtNfmt(unsigned Dfmt, unsigned Nfmt) {
2210 return (Dfmt << DFMT_SHIFT) | (Nfmt << NFMT_SHIFT);
2211}
2212
2213void decodeDfmtNfmt(unsigned Format, unsigned &Dfmt, unsigned &Nfmt) {
2214 Dfmt = (Format >> DFMT_SHIFT) & DFMT_MASK;
2215 Nfmt = (Format >> NFMT_SHIFT) & NFMT_MASK;
2216}
2217
2218int64_t getUnifiedFormat(const StringRef Name, const MCSubtargetInfo &STI) {
2219 if (isGFX11Plus(STI)) {
2220 for (int Id = UfmtGFX11::UFMT_FIRST; Id <= UfmtGFX11::UFMT_LAST; ++Id) {
2221 if (Name == UfmtSymbolicGFX11[Id])
2222 return Id;
2223 }
2224 } else {
2225 for (int Id = UfmtGFX10::UFMT_FIRST; Id <= UfmtGFX10::UFMT_LAST; ++Id) {
2226 if (Name == UfmtSymbolicGFX10[Id])
2227 return Id;
2228 }
2229 }
2230 return UFMT_UNDEF;
2231}
2232
2234 if (isValidUnifiedFormat(Id, STI))
2235 return isGFX10(STI) ? UfmtSymbolicGFX10[Id] : UfmtSymbolicGFX11[Id];
2236 return "";
2237}
2238
2239bool isValidUnifiedFormat(unsigned Id, const MCSubtargetInfo &STI) {
2240 return isGFX10(STI) ? Id <= UfmtGFX10::UFMT_LAST : Id <= UfmtGFX11::UFMT_LAST;
2241}
2242
2243int64_t convertDfmtNfmt2Ufmt(unsigned Dfmt, unsigned Nfmt,
2244 const MCSubtargetInfo &STI) {
2245 int64_t Fmt = encodeDfmtNfmt(Dfmt, Nfmt);
2246 if (isGFX11Plus(STI)) {
2247 for (int Id = UfmtGFX11::UFMT_FIRST; Id <= UfmtGFX11::UFMT_LAST; ++Id) {
2248 if (Fmt == DfmtNfmt2UFmtGFX11[Id])
2249 return Id;
2250 }
2251 } else {
2252 for (int Id = UfmtGFX10::UFMT_FIRST; Id <= UfmtGFX10::UFMT_LAST; ++Id) {
2253 if (Fmt == DfmtNfmt2UFmtGFX10[Id])
2254 return Id;
2255 }
2256 }
2257 return UFMT_UNDEF;
2258}
2259
2260bool isValidFormatEncoding(unsigned Val, const MCSubtargetInfo &STI) {
2261 return isGFX10Plus(STI) ? (Val <= UFMT_MAX) : (Val <= DFMT_NFMT_MAX);
2262}
2263
2265 if (isGFX10Plus(STI))
2266 return UFMT_DEFAULT;
2267 return DFMT_NFMT_DEFAULT;
2268}
2269
2270} // namespace MTBUFFormat
2271
2272//===----------------------------------------------------------------------===//
2273// SendMsg
2274//===----------------------------------------------------------------------===//
2275
2276namespace SendMsg {
2277
2281
2282bool isValidMsgId(int64_t MsgId, const MCSubtargetInfo &STI) {
2283 return (MsgId & ~(getMsgIdMask(STI))) == 0;
2284}
2285
2286bool isValidMsgOp(int64_t MsgId, int64_t OpId, const MCSubtargetInfo &STI,
2287 bool Strict) {
2288 assert(isValidMsgId(MsgId, STI));
2289
2290 if (!Strict)
2291 return 0 <= OpId && isUInt<OP_WIDTH_>(OpId);
2292
2293 if (msgRequiresOp(MsgId, STI)) {
2294 if (MsgId == ID_GS_PreGFX11 && OpId == OP_GS_NOP)
2295 return false;
2296
2297 return !getMsgOpName(MsgId, OpId, STI).empty();
2298 }
2299
2300 return OpId == OP_NONE_;
2301}
2302
2303bool isValidMsgStream(int64_t MsgId, int64_t OpId, int64_t StreamId,
2304 const MCSubtargetInfo &STI, bool Strict) {
2305 assert(isValidMsgOp(MsgId, OpId, STI, Strict));
2306
2307 if (!Strict)
2309
2310 if (!isGFX11Plus(STI)) {
2311 switch (MsgId) {
2312 case ID_GS_PreGFX11:
2315 return (OpId == OP_GS_NOP)
2318 }
2319 }
2320 return StreamId == STREAM_ID_NONE_;
2321}
2322
2323bool msgRequiresOp(int64_t MsgId, const MCSubtargetInfo &STI) {
2324 return MsgId == ID_SYSMSG ||
2325 (!isGFX11Plus(STI) &&
2326 (MsgId == ID_GS_PreGFX11 || MsgId == ID_GS_DONE_PreGFX11));
2327}
2328
2329bool msgSupportsStream(int64_t MsgId, int64_t OpId,
2330 const MCSubtargetInfo &STI) {
2331 return !isGFX11Plus(STI) &&
2332 (MsgId == ID_GS_PreGFX11 || MsgId == ID_GS_DONE_PreGFX11) &&
2333 OpId != OP_GS_NOP;
2334}
2335
2336void decodeMsg(unsigned Val, uint16_t &MsgId, uint16_t &OpId,
2337 uint16_t &StreamId, const MCSubtargetInfo &STI) {
2338 MsgId = Val & getMsgIdMask(STI);
2339 if (isGFX11Plus(STI)) {
2340 OpId = 0;
2341 StreamId = 0;
2342 } else {
2343 OpId = (Val & OP_MASK_) >> OP_SHIFT_;
2345 }
2346}
2347
2349 return MsgId | (OpId << OP_SHIFT_) | (StreamId << STREAM_ID_SHIFT_);
2350}
2351
2352bool msgDoesNotUseM0(int64_t MsgId, const MCSubtargetInfo &STI) {
2353 // Explicitly list message types that are known to not use m0.
2354 // This is safer than excluding only GS_ALLOC_REQ, in case new message
2355 // types are added in the future that do use m0.
2356 if (isGFX11Plus(STI)) {
2357 switch (MsgId) {
2359 return true;
2360 default:
2361 break;
2362 }
2363 }
2364 switch (MsgId) {
2365 case ID_SAVEWAVE:
2366 case ID_STALL_WAVE_GEN:
2367 case ID_HALT_WAVES:
2368 case ID_ORDERED_PS_DONE:
2370 case ID_GET_DOORBELL:
2371 case ID_GET_DDID:
2372 case ID_SYSMSG:
2373 return true;
2374 default:
2375 return false;
2376 }
2377}
2378
2379} // namespace SendMsg
2380
2381//===----------------------------------------------------------------------===//
2382//
2383//===----------------------------------------------------------------------===//
2384
2386 return F.getFnAttributeAsParsedInteger("InitialPSInputAddr", 0);
2387}
2388
2390 // As a safe default always respond as if PS has color exports.
2391 return F.getFnAttributeAsParsedInteger(
2392 "amdgpu-color-export",
2393 F.getCallingConv() == CallingConv::AMDGPU_PS ? 1 : 0) != 0;
2394}
2395
2397 return F.getFnAttributeAsParsedInteger("amdgpu-depth-export", 0) != 0;
2398}
2399
2401 unsigned BlockSize =
2402 F.getFnAttributeAsParsedInteger("amdgpu-dynamic-vgpr-block-size", 0);
2403
2404 if (BlockSize == 16 || BlockSize == 32)
2405 return BlockSize;
2406
2407 return 0;
2408}
2409
2410bool hasXNACK(const MCSubtargetInfo &STI) {
2411 // Only hardwired-on xnack (gfx1250) is knowable from the subtarget alone;
2412 // toggleable targets take their mode from the TargetID.
2413 return STI.hasFeature(AMDGPU::FeatureSupportsXNACK) &&
2414 !STI.hasFeature(AMDGPU::FeatureXNACKOnOffModes);
2415}
2416
2418 return STI.hasFeature(AMDGPU::FeatureMIMG_R128) &&
2419 !STI.hasFeature(AMDGPU::FeatureR128A16);
2420}
2421
2422bool hasA16(const MCSubtargetInfo &STI) {
2423 return STI.hasFeature(AMDGPU::FeatureA16);
2424}
2425
2426bool hasG16(const MCSubtargetInfo &STI) {
2427 return STI.hasFeature(AMDGPU::FeatureG16);
2428}
2429
2431 return !STI.hasFeature(AMDGPU::FeatureUnpackedD16VMem) && !isCI(STI) &&
2432 !isSI(STI);
2433}
2434
2435bool hasGDS(const MCSubtargetInfo &STI) {
2436 return STI.hasFeature(AMDGPU::FeatureGDS);
2437}
2438
2439unsigned getNSAMaxSize(const MCSubtargetInfo &STI, bool HasSampler) {
2440 auto Version = getIsaVersion(STI.getCPU());
2441 if (Version.Major == 10)
2442 return Version.Minor >= 3 ? 13 : 5;
2443 if (Version.Major == 11)
2444 return 5;
2445 if (Version.Major >= 12)
2446 return HasSampler ? 4 : 5;
2447 return 0;
2448}
2449
2451 if (isGFX1250Plus(STI))
2452 return 32;
2453 return 16;
2454}
2455
2456bool isSI(const MCSubtargetInfo &STI) {
2457 return STI.hasFeature(AMDGPU::FeatureSouthernIslands);
2458}
2459
2460bool isCI(const MCSubtargetInfo &STI) {
2461 return STI.hasFeature(AMDGPU::FeatureSeaIslands);
2462}
2463
2464bool isVI(const MCSubtargetInfo &STI) {
2465 return STI.hasFeature(AMDGPU::FeatureVolcanicIslands);
2466}
2467
2468bool isGFX9(const MCSubtargetInfo &STI) {
2469 return STI.hasFeature(AMDGPU::FeatureGFX9);
2470}
2471
2473 return isGFX9(STI) || isGFX10(STI);
2474}
2475
2477 return isGFX9(STI) || isGFX10(STI) || isGFX11(STI);
2478}
2479
2481 return isVI(STI) || isGFX9(STI) || isGFX10(STI);
2482}
2483
2484bool isGFX8Plus(const MCSubtargetInfo &STI) {
2485 return isVI(STI) || isGFX9Plus(STI);
2486}
2487
2488bool isGFX9Plus(const MCSubtargetInfo &STI) {
2489 return isGFX9(STI) || isGFX10Plus(STI);
2490}
2491
2492bool isNotGFX9Plus(const MCSubtargetInfo &STI) { return !isGFX9Plus(STI); }
2493
2495 return STI.hasFeature(AMDGPU::FeaturePopsExitingWaveID);
2496}
2497
2499 return STI.hasFeature(AMDGPU::FeatureApertureRegs) &&
2500 !STI.hasFeature(AMDGPU::FeatureGloballyAddressableScratch);
2501}
2502
2503bool isGFX10(const MCSubtargetInfo &STI) {
2504 return STI.hasFeature(AMDGPU::FeatureGFX10);
2505}
2506
2508 return isGFX10(STI) || isGFX11(STI);
2509}
2510
2512 return isGFX10(STI) || isGFX11Plus(STI);
2513}
2514
2515bool isGFX11(const MCSubtargetInfo &STI) {
2516 return STI.hasFeature(AMDGPU::FeatureGFX11);
2517}
2518
2520 return isGFX11(STI) || isGFX12Plus(STI);
2521}
2522
2523bool isGFX12(const MCSubtargetInfo &STI) {
2524 return STI.getFeatureBits()[AMDGPU::FeatureGFX12];
2525}
2526
2528 return isGFX12(STI) || isGFX13Plus(STI);
2529}
2530
2531bool isNotGFX12Plus(const MCSubtargetInfo &STI) { return !isGFX12Plus(STI); }
2532
2533bool isGFX1250(const MCSubtargetInfo &STI) {
2534 return STI.getFeatureBits()[AMDGPU::FeatureGFX1250Insts] && !isGFX13(STI);
2535}
2536
2538 return isGFX1250(STI) || !STI.getFeatureBits().test(FeatureCuMode);
2539}
2540
2542 return STI.getFeatureBits()[AMDGPU::FeatureGFX1250Insts];
2543}
2544
2545bool isGFX13(const MCSubtargetInfo &STI) {
2546 return STI.getFeatureBits()[AMDGPU::FeatureGFX13];
2547}
2548
2549bool isGFX13Plus(const MCSubtargetInfo &STI) { return isGFX13(STI); }
2550
2552 if (isGFX1250(STI))
2553 return false;
2554 return isGFX10Plus(STI);
2555}
2556
2557bool isNotGFX11Plus(const MCSubtargetInfo &STI) { return !isGFX11Plus(STI); }
2558
2560 return isSI(STI) || isCI(STI) || isVI(STI) || isGFX9(STI);
2561}
2562
2564 return isGFX10(STI) && !AMDGPU::isGFX10_BEncoding(STI);
2565}
2566
2568 return STI.hasFeature(AMDGPU::FeatureGCN3Encoding);
2569}
2570
2572 return STI.hasFeature(AMDGPU::FeatureGFX10_BEncoding);
2573}
2574
2576 return STI.hasFeature(AMDGPU::FeatureGFX10_3Insts);
2577}
2578
2580 return isGFX10_BEncoding(STI) && !isGFX12Plus(STI);
2581}
2582
2583bool isGFX90A(const MCSubtargetInfo &STI) {
2584 return STI.hasFeature(AMDGPU::FeatureGFX90AInsts);
2585}
2586
2587bool isGFX940(const MCSubtargetInfo &STI) {
2588 return STI.hasFeature(AMDGPU::FeatureGFX940Insts);
2589}
2590
2592 return STI.hasFeature(AMDGPU::FeatureArchitectedFlatScratch);
2593}
2594
2596 return STI.hasFeature(AMDGPU::FeatureMAIInsts);
2597}
2598
2599bool hasVOPD(const MCSubtargetInfo &STI) {
2600 return STI.hasFeature(AMDGPU::FeatureVOPDInsts);
2601}
2602
2604 return STI.hasFeature(AMDGPU::FeatureDPPSrc1SGPR);
2605}
2606
2608 return STI.hasFeature(AMDGPU::FeatureKernargPreload);
2609}
2610
2611int32_t getTotalNumVGPRs(bool has90AInsts, int32_t ArgNumAGPR,
2612 int32_t ArgNumVGPR) {
2613 if (has90AInsts && ArgNumAGPR)
2614 return alignTo(ArgNumVGPR, 4) + ArgNumAGPR;
2615 return std::max(ArgNumVGPR, ArgNumAGPR);
2616}
2617
2619 const MCRegisterClass &SGPRClass =
2620 TRI->getRegClass(AMDGPU::SReg_32RegClassID);
2621 const MCRegister FirstSubReg = TRI->getSubReg(Reg, AMDGPU::sub0);
2622 return SGPRClass.contains(FirstSubReg != 0 ? FirstSubReg : Reg) ||
2623 Reg == AMDGPU::SCC;
2624}
2625
2627 return MRI.getRegClass(AMDGPU::RsrcReg32RegClassID).contains(Reg);
2628}
2629
2633
2634#define MAP_REG2REG \
2635 using namespace AMDGPU; \
2636 switch (Reg.id()) { \
2637 default: \
2638 return Reg; \
2639 CASE_CI_VI(FLAT_SCR) \
2640 CASE_CI_VI(FLAT_SCR_LO) \
2641 CASE_CI_VI(FLAT_SCR_HI) \
2642 CASE_VI_GFX9PLUS(TTMP0) \
2643 CASE_VI_GFX9PLUS(TTMP1) \
2644 CASE_VI_GFX9PLUS(TTMP2) \
2645 CASE_VI_GFX9PLUS(TTMP3) \
2646 CASE_VI_GFX9PLUS(TTMP4) \
2647 CASE_VI_GFX9PLUS(TTMP5) \
2648 CASE_VI_GFX9PLUS(TTMP6) \
2649 CASE_VI_GFX9PLUS(TTMP7) \
2650 CASE_VI_GFX9PLUS(TTMP8) \
2651 CASE_VI_GFX9PLUS(TTMP9) \
2652 CASE_VI_GFX9PLUS(TTMP10) \
2653 CASE_VI_GFX9PLUS(TTMP11) \
2654 CASE_VI_GFX9PLUS(TTMP12) \
2655 CASE_VI_GFX9PLUS(TTMP13) \
2656 CASE_VI_GFX9PLUS(TTMP14) \
2657 CASE_VI_GFX9PLUS(TTMP15) \
2658 CASE_VI_GFX9PLUS(TTMP0_TTMP1) \
2659 CASE_VI_GFX9PLUS(TTMP2_TTMP3) \
2660 CASE_VI_GFX9PLUS(TTMP4_TTMP5) \
2661 CASE_VI_GFX9PLUS(TTMP6_TTMP7) \
2662 CASE_VI_GFX9PLUS(TTMP8_TTMP9) \
2663 CASE_VI_GFX9PLUS(TTMP10_TTMP11) \
2664 CASE_VI_GFX9PLUS(TTMP12_TTMP13) \
2665 CASE_VI_GFX9PLUS(TTMP14_TTMP15) \
2666 CASE_VI_GFX9PLUS(TTMP0_TTMP1_TTMP2_TTMP3) \
2667 CASE_VI_GFX9PLUS(TTMP4_TTMP5_TTMP6_TTMP7) \
2668 CASE_VI_GFX9PLUS(TTMP8_TTMP9_TTMP10_TTMP11) \
2669 CASE_VI_GFX9PLUS(TTMP12_TTMP13_TTMP14_TTMP15) \
2670 CASE_VI_GFX9PLUS(TTMP0_TTMP1_TTMP2_TTMP3_TTMP4_TTMP5_TTMP6_TTMP7) \
2671 CASE_VI_GFX9PLUS(TTMP4_TTMP5_TTMP6_TTMP7_TTMP8_TTMP9_TTMP10_TTMP11) \
2672 CASE_VI_GFX9PLUS(TTMP8_TTMP9_TTMP10_TTMP11_TTMP12_TTMP13_TTMP14_TTMP15) \
2673 CASE_VI_GFX9PLUS( \
2674 TTMP0_TTMP1_TTMP2_TTMP3_TTMP4_TTMP5_TTMP6_TTMP7_TTMP8_TTMP9_TTMP10_TTMP11_TTMP12_TTMP13_TTMP14_TTMP15) \
2675 CASE_GFXPRE11_GFX11PLUS(M0) \
2676 CASE_GFXPRE11_GFX11PLUS(SGPR_NULL) \
2677 CASE_GFXPRE11_GFX11PLUS_TO(SGPR_NULL64, SGPR_NULL) \
2678 }
2679
2680#define CASE_CI_VI(node) \
2681 assert(!isSI(STI)); \
2682 case node: \
2683 return isCI(STI) ? node##_ci : node##_vi;
2684
2685#define CASE_VI_GFX9PLUS(node) \
2686 case node: \
2687 return isGFX9Plus(STI) ? node##_gfx9plus : node##_vi;
2688
2689#define CASE_GFXPRE11_GFX11PLUS(node) \
2690 case node: \
2691 return isGFX11Plus(STI) ? node##_gfx11plus : node##_gfxpre11;
2692
2693#define CASE_GFXPRE11_GFX11PLUS_TO(node, result) \
2694 case node: \
2695 return isGFX11Plus(STI) ? result##_gfx11plus : result##_gfxpre11;
2696
2698 if (STI.getTargetTriple().getArch() == Triple::r600)
2699 return Reg;
2701}
2702
2703#undef CASE_CI_VI
2704#undef CASE_VI_GFX9PLUS
2705#undef CASE_GFXPRE11_GFX11PLUS
2706#undef CASE_GFXPRE11_GFX11PLUS_TO
2707
2708#define CASE_CI_VI(node) \
2709 case node##_ci: \
2710 case node##_vi: \
2711 return node;
2712#define CASE_VI_GFX9PLUS(node) \
2713 case node##_vi: \
2714 case node##_gfx9plus: \
2715 return node;
2716#define CASE_GFXPRE11_GFX11PLUS(node) \
2717 case node##_gfx11plus: \
2718 case node##_gfxpre11: \
2719 return node;
2720#define CASE_GFXPRE11_GFX11PLUS_TO(node, result)
2721
2723
2725 switch (Reg.id()) {
2726 case AMDGPU::SRC_SHARED_BASE_LO:
2727 case AMDGPU::SRC_SHARED_BASE:
2728 case AMDGPU::SRC_SHARED_LIMIT_LO:
2729 case AMDGPU::SRC_SHARED_LIMIT:
2730 case AMDGPU::SRC_PRIVATE_BASE_LO:
2731 case AMDGPU::SRC_PRIVATE_BASE:
2732 case AMDGPU::SRC_PRIVATE_LIMIT_LO:
2733 case AMDGPU::SRC_PRIVATE_LIMIT:
2734 case AMDGPU::SRC_FLAT_SCRATCH_BASE_LO:
2735 case AMDGPU::SRC_FLAT_SCRATCH_BASE_HI:
2736 case AMDGPU::SRC_POPS_EXITING_WAVE_ID:
2737 return true;
2738 case AMDGPU::SRC_VCCZ:
2739 case AMDGPU::SRC_EXECZ:
2740 case AMDGPU::SRC_SCC:
2741 return true;
2742 case AMDGPU::SGPR_NULL:
2743 return true;
2744 default:
2745 return false;
2746 }
2747}
2748
2749#undef CASE_CI_VI
2750#undef CASE_VI_GFX9PLUS
2751#undef CASE_GFXPRE11_GFX11PLUS
2752#undef CASE_GFXPRE11_GFX11PLUS_TO
2753#undef MAP_REG2REG
2754
2755bool isKImmOperand(const MCInstrDesc &Desc, unsigned OpNo) {
2756 assert(OpNo < Desc.NumOperands);
2757 unsigned OpType = Desc.operands()[OpNo].OperandType;
2758 return OpType >= AMDGPU::OPERAND_KIMM_FIRST &&
2759 OpType <= AMDGPU::OPERAND_KIMM_LAST;
2760}
2761
2762bool isSISrcFPOperand(const MCInstrDesc &Desc, unsigned OpNo) {
2763 assert(OpNo < Desc.NumOperands);
2764 unsigned OpType = Desc.operands()[OpNo].OperandType;
2765 switch (OpType) {
2781 return true;
2782 default:
2783 return false;
2784 }
2785}
2786
2787bool isSISrcInlinableOperand(const MCInstrDesc &Desc, unsigned OpNo) {
2788 assert(OpNo < Desc.NumOperands);
2789 unsigned OpType = Desc.operands()[OpNo].OperandType;
2790 return (OpType >= AMDGPU::OPERAND_REG_INLINE_C_FIRST &&
2794}
2795
2796// Avoid using MCRegisterClass::getSize, since that function will go away
2797// (move from MC* level to Target* level). Return size in bits.
2798unsigned getRegBitWidth(unsigned RCID) {
2799 switch (RCID) {
2800 case AMDGPU::VGPR_16RegClassID:
2801 case AMDGPU::VGPR_16_Lo128RegClassID:
2802 case AMDGPU::SGPR_LO16RegClassID:
2803 case AMDGPU::AGPR_LO16RegClassID:
2804 return 16;
2805 case AMDGPU::SGPR_32RegClassID:
2806 case AMDGPU::VGPR_32RegClassID:
2807 case AMDGPU::VGPR_32_Lo256RegClassID:
2808 case AMDGPU::VRegOrLds_32RegClassID:
2809 case AMDGPU::AGPR_32RegClassID:
2810 case AMDGPU::VS_32RegClassID:
2811 case AMDGPU::AV_32RegClassID:
2812 case AMDGPU::SReg_32RegClassID:
2813 case AMDGPU::SReg_32_XM0RegClassID:
2814 case AMDGPU::SRegOrLds_32RegClassID:
2815 return 32;
2816 case AMDGPU::SGPR_64RegClassID:
2817 case AMDGPU::VS_64RegClassID:
2818 case AMDGPU::SReg_64RegClassID:
2819 case AMDGPU::VReg_64RegClassID:
2820 case AMDGPU::AReg_64RegClassID:
2821 case AMDGPU::SReg_64_XEXECRegClassID:
2822 case AMDGPU::VReg_64_Align2RegClassID:
2823 case AMDGPU::AReg_64_Align2RegClassID:
2824 case AMDGPU::AV_64RegClassID:
2825 case AMDGPU::AV_64_Align2RegClassID:
2826 case AMDGPU::VReg_64_Lo256_Align2RegClassID:
2827 case AMDGPU::VS_64_Lo256RegClassID:
2828 return 64;
2829 case AMDGPU::SGPR_96RegClassID:
2830 case AMDGPU::SReg_96RegClassID:
2831 case AMDGPU::VReg_96RegClassID:
2832 case AMDGPU::AReg_96RegClassID:
2833 case AMDGPU::VReg_96_Align2RegClassID:
2834 case AMDGPU::AReg_96_Align2RegClassID:
2835 case AMDGPU::AV_96RegClassID:
2836 case AMDGPU::AV_96_Align2RegClassID:
2837 case AMDGPU::VReg_96_Lo256_Align2RegClassID:
2838 return 96;
2839 case AMDGPU::SGPR_128RegClassID:
2840 case AMDGPU::SReg_128RegClassID:
2841 case AMDGPU::VReg_128RegClassID:
2842 case AMDGPU::AReg_128RegClassID:
2843 case AMDGPU::VReg_128_Align2RegClassID:
2844 case AMDGPU::AReg_128_Align2RegClassID:
2845 case AMDGPU::AV_128RegClassID:
2846 case AMDGPU::AV_128_Align2RegClassID:
2847 case AMDGPU::SReg_128_XNULLRegClassID:
2848 case AMDGPU::VReg_128_Lo256_Align2RegClassID:
2849 return 128;
2850 case AMDGPU::SGPR_160RegClassID:
2851 case AMDGPU::SReg_160RegClassID:
2852 case AMDGPU::VReg_160RegClassID:
2853 case AMDGPU::AReg_160RegClassID:
2854 case AMDGPU::VReg_160_Align2RegClassID:
2855 case AMDGPU::AReg_160_Align2RegClassID:
2856 case AMDGPU::AV_160RegClassID:
2857 case AMDGPU::AV_160_Align2RegClassID:
2858 case AMDGPU::VReg_160_Lo256_Align2RegClassID:
2859 return 160;
2860 case AMDGPU::SGPR_192RegClassID:
2861 case AMDGPU::SReg_192RegClassID:
2862 case AMDGPU::VReg_192RegClassID:
2863 case AMDGPU::AReg_192RegClassID:
2864 case AMDGPU::VReg_192_Align2RegClassID:
2865 case AMDGPU::AReg_192_Align2RegClassID:
2866 case AMDGPU::AV_192RegClassID:
2867 case AMDGPU::AV_192_Align2RegClassID:
2868 case AMDGPU::VReg_192_Lo256_Align2RegClassID:
2869 return 192;
2870 case AMDGPU::SGPR_224RegClassID:
2871 case AMDGPU::SReg_224RegClassID:
2872 case AMDGPU::VReg_224RegClassID:
2873 case AMDGPU::AReg_224RegClassID:
2874 case AMDGPU::VReg_224_Align2RegClassID:
2875 case AMDGPU::AReg_224_Align2RegClassID:
2876 case AMDGPU::AV_224RegClassID:
2877 case AMDGPU::AV_224_Align2RegClassID:
2878 case AMDGPU::VReg_224_Lo256_Align2RegClassID:
2879 return 224;
2880 case AMDGPU::SGPR_256RegClassID:
2881 case AMDGPU::SReg_256RegClassID:
2882 case AMDGPU::VReg_256RegClassID:
2883 case AMDGPU::AReg_256RegClassID:
2884 case AMDGPU::VReg_256_Align2RegClassID:
2885 case AMDGPU::AReg_256_Align2RegClassID:
2886 case AMDGPU::AV_256RegClassID:
2887 case AMDGPU::AV_256_Align2RegClassID:
2888 case AMDGPU::SReg_256_XNULLRegClassID:
2889 case AMDGPU::VReg_256_Lo256_Align2RegClassID:
2890 return 256;
2891 case AMDGPU::SGPR_288RegClassID:
2892 case AMDGPU::SReg_288RegClassID:
2893 case AMDGPU::VReg_288RegClassID:
2894 case AMDGPU::AReg_288RegClassID:
2895 case AMDGPU::VReg_288_Align2RegClassID:
2896 case AMDGPU::AReg_288_Align2RegClassID:
2897 case AMDGPU::AV_288RegClassID:
2898 case AMDGPU::AV_288_Align2RegClassID:
2899 case AMDGPU::VReg_288_Lo256_Align2RegClassID:
2900 return 288;
2901 case AMDGPU::SGPR_320RegClassID:
2902 case AMDGPU::SReg_320RegClassID:
2903 case AMDGPU::VReg_320RegClassID:
2904 case AMDGPU::AReg_320RegClassID:
2905 case AMDGPU::VReg_320_Align2RegClassID:
2906 case AMDGPU::AReg_320_Align2RegClassID:
2907 case AMDGPU::AV_320RegClassID:
2908 case AMDGPU::AV_320_Align2RegClassID:
2909 case AMDGPU::VReg_320_Lo256_Align2RegClassID:
2910 return 320;
2911 case AMDGPU::SGPR_352RegClassID:
2912 case AMDGPU::SReg_352RegClassID:
2913 case AMDGPU::VReg_352RegClassID:
2914 case AMDGPU::AReg_352RegClassID:
2915 case AMDGPU::VReg_352_Align2RegClassID:
2916 case AMDGPU::AReg_352_Align2RegClassID:
2917 case AMDGPU::AV_352RegClassID:
2918 case AMDGPU::AV_352_Align2RegClassID:
2919 case AMDGPU::VReg_352_Lo256_Align2RegClassID:
2920 return 352;
2921 case AMDGPU::SGPR_384RegClassID:
2922 case AMDGPU::SReg_384RegClassID:
2923 case AMDGPU::VReg_384RegClassID:
2924 case AMDGPU::AReg_384RegClassID:
2925 case AMDGPU::VReg_384_Align2RegClassID:
2926 case AMDGPU::AReg_384_Align2RegClassID:
2927 case AMDGPU::AV_384RegClassID:
2928 case AMDGPU::AV_384_Align2RegClassID:
2929 case AMDGPU::VReg_384_Lo256_Align2RegClassID:
2930 return 384;
2931 case AMDGPU::SGPR_512RegClassID:
2932 case AMDGPU::SReg_512RegClassID:
2933 case AMDGPU::VReg_512RegClassID:
2934 case AMDGPU::AReg_512RegClassID:
2935 case AMDGPU::VReg_512_Align2RegClassID:
2936 case AMDGPU::AReg_512_Align2RegClassID:
2937 case AMDGPU::AV_512RegClassID:
2938 case AMDGPU::AV_512_Align2RegClassID:
2939 case AMDGPU::VReg_512_Lo256_Align2RegClassID:
2940 return 512;
2941 case AMDGPU::SGPR_1024RegClassID:
2942 case AMDGPU::SReg_1024RegClassID:
2943 case AMDGPU::VReg_1024RegClassID:
2944 case AMDGPU::AReg_1024RegClassID:
2945 case AMDGPU::VReg_1024_Align2RegClassID:
2946 case AMDGPU::AReg_1024_Align2RegClassID:
2947 case AMDGPU::AV_1024RegClassID:
2948 case AMDGPU::AV_1024_Align2RegClassID:
2949 case AMDGPU::VReg_1024_Lo256_Align2RegClassID:
2950 return 1024;
2951 default:
2952 llvm_unreachable("Unexpected register class");
2953 }
2954}
2955
2956unsigned getRegBitWidth(const MCRegisterClass &RC) {
2957 return getRegBitWidth(RC.getID());
2958}
2959
2960bool isInlinableLiteral64(int64_t Literal, bool HasInv2Pi) {
2962 return true;
2963
2964 uint64_t Val = static_cast<uint64_t>(Literal);
2965 return (Val == llvm::bit_cast<uint64_t>(0.0)) ||
2966 (Val == llvm::bit_cast<uint64_t>(1.0)) ||
2967 (Val == llvm::bit_cast<uint64_t>(-1.0)) ||
2968 (Val == llvm::bit_cast<uint64_t>(0.5)) ||
2969 (Val == llvm::bit_cast<uint64_t>(-0.5)) ||
2970 (Val == llvm::bit_cast<uint64_t>(2.0)) ||
2971 (Val == llvm::bit_cast<uint64_t>(-2.0)) ||
2972 (Val == llvm::bit_cast<uint64_t>(4.0)) ||
2973 (Val == llvm::bit_cast<uint64_t>(-4.0)) ||
2974 (Val == 0x3fc45f306dc9c882 && HasInv2Pi);
2975}
2976
2977bool isInlinableLiteral32(int32_t Literal, bool HasInv2Pi) {
2979 return true;
2980
2981 // The actual type of the operand does not seem to matter as long
2982 // as the bits match one of the inline immediate values. For example:
2983 //
2984 // -nan has the hexadecimal encoding of 0xfffffffe which is -2 in decimal,
2985 // so it is a legal inline immediate.
2986 //
2987 // 1065353216 has the hexadecimal encoding 0x3f800000 which is 1.0f in
2988 // floating-point, so it is a legal inline immediate.
2989
2990 uint32_t Val = static_cast<uint32_t>(Literal);
2991 return (Val == llvm::bit_cast<uint32_t>(0.0f)) ||
2992 (Val == llvm::bit_cast<uint32_t>(1.0f)) ||
2993 (Val == llvm::bit_cast<uint32_t>(-1.0f)) ||
2994 (Val == llvm::bit_cast<uint32_t>(0.5f)) ||
2995 (Val == llvm::bit_cast<uint32_t>(-0.5f)) ||
2996 (Val == llvm::bit_cast<uint32_t>(2.0f)) ||
2997 (Val == llvm::bit_cast<uint32_t>(-2.0f)) ||
2998 (Val == llvm::bit_cast<uint32_t>(4.0f)) ||
2999 (Val == llvm::bit_cast<uint32_t>(-4.0f)) ||
3000 (Val == 0x3e22f983 && HasInv2Pi);
3001}
3002
3003bool isInlinableLiteralBF16(int16_t Literal, bool HasInv2Pi) {
3004 if (!HasInv2Pi)
3005 return false;
3007 return true;
3008 uint16_t Val = static_cast<uint16_t>(Literal);
3009 return Val == 0x3F00 || // 0.5
3010 Val == 0xBF00 || // -0.5
3011 Val == 0x3F80 || // 1.0
3012 Val == 0xBF80 || // -1.0
3013 Val == 0x4000 || // 2.0
3014 Val == 0xC000 || // -2.0
3015 Val == 0x4080 || // 4.0
3016 Val == 0xC080 || // -4.0
3017 Val == 0x3E22; // 1.0 / (2.0 * pi)
3018}
3019
3020bool isInlinableLiteralI16(int32_t Literal, bool HasInv2Pi) {
3021 return isInlinableLiteral32(Literal, HasInv2Pi);
3022}
3023
3024bool isInlinableLiteralFP16(int16_t Literal, bool HasInv2Pi) {
3025 if (!HasInv2Pi)
3026 return false;
3028 return true;
3029 uint16_t Val = static_cast<uint16_t>(Literal);
3030 return Val == 0x3C00 || // 1.0
3031 Val == 0xBC00 || // -1.0
3032 Val == 0x3800 || // 0.5
3033 Val == 0xB800 || // -0.5
3034 Val == 0x4000 || // 2.0
3035 Val == 0xC000 || // -2.0
3036 Val == 0x4400 || // 4.0
3037 Val == 0xC400 || // -4.0
3038 Val == 0x3118; // 1/2pi
3039}
3040
3041std::optional<unsigned> getInlineEncodingV216(bool IsFloat, uint32_t Literal) {
3042 // Unfortunately, the Instruction Set Architecture Reference Guide is
3043 // misleading about how the inline operands work for (packed) 16-bit
3044 // instructions. In a nutshell, the actual HW behavior is:
3045 //
3046 // - integer encodings (-16 .. 64) are always produced as sign-extended
3047 // 32-bit values
3048 // - float encodings are produced as:
3049 // - for F16 instructions: corresponding half-precision float values in
3050 // the LSBs, 0 in the MSBs
3051 // - for UI16 instructions: corresponding single-precision float value
3052 int32_t Signed = static_cast<int32_t>(Literal);
3053 if (Signed >= 0 && Signed <= 64)
3054 return 128 + Signed;
3055
3056 if (Signed >= -16 && Signed <= -1)
3057 return 192 + std::abs(Signed);
3058
3059 if (IsFloat) {
3060 // clang-format off
3061 switch (Literal) {
3062 case 0x3800: return 240; // 0.5
3063 case 0xB800: return 241; // -0.5
3064 case 0x3C00: return 242; // 1.0
3065 case 0xBC00: return 243; // -1.0
3066 case 0x4000: return 244; // 2.0
3067 case 0xC000: return 245; // -2.0
3068 case 0x4400: return 246; // 4.0
3069 case 0xC400: return 247; // -4.0
3070 case 0x3118: return 248; // 1.0 / (2.0 * pi)
3071 default: break;
3072 }
3073 // clang-format on
3074 } else {
3075 // clang-format off
3076 switch (Literal) {
3077 case 0x3F000000: return 240; // 0.5
3078 case 0xBF000000: return 241; // -0.5
3079 case 0x3F800000: return 242; // 1.0
3080 case 0xBF800000: return 243; // -1.0
3081 case 0x40000000: return 244; // 2.0
3082 case 0xC0000000: return 245; // -2.0
3083 case 0x40800000: return 246; // 4.0
3084 case 0xC0800000: return 247; // -4.0
3085 case 0x3E22F983: return 248; // 1.0 / (2.0 * pi)
3086 default: break;
3087 }
3088 // clang-format on
3089 }
3090
3091 return {};
3092}
3093
3094// Encoding of the literal as an inline constant for a V_PK_*_IU16 instruction
3095// or nullopt.
3096std::optional<unsigned> getInlineEncodingV2I16(uint32_t Literal) {
3097 return getInlineEncodingV216(false, Literal);
3098}
3099
3100// Encoding of the literal as an inline constant for a V_PK_*_BF16 instruction
3101// or nullopt.
3102std::optional<unsigned> getInlineEncodingV2BF16(uint32_t Literal) {
3103 int32_t Signed = static_cast<int32_t>(Literal);
3104 if (Signed >= 0 && Signed <= 64)
3105 return 128 + Signed;
3106
3107 if (Signed >= -16 && Signed <= -1)
3108 return 192 + std::abs(Signed);
3109
3110 // clang-format off
3111 switch (Literal) {
3112 case 0x3F00: return 240; // 0.5
3113 case 0xBF00: return 241; // -0.5
3114 case 0x3F80: return 242; // 1.0
3115 case 0xBF80: return 243; // -1.0
3116 case 0x4000: return 244; // 2.0
3117 case 0xC000: return 245; // -2.0
3118 case 0x4080: return 246; // 4.0
3119 case 0xC080: return 247; // -4.0
3120 case 0x3E22: return 248; // 1.0 / (2.0 * pi)
3121 default: break;
3122 }
3123 // clang-format on
3124
3125 return std::nullopt;
3126}
3127
3128// Encoding of the literal as an inline constant for a V_PK_*_F16 instruction
3129// or nullopt.
3130std::optional<unsigned> getInlineEncodingV2F16(uint32_t Literal) {
3131 return getInlineEncodingV216(true, Literal);
3132}
3133
3134// Encoding of the literal as an inline constant for V_PK_FMAC_F16 instruction
3135// or nullopt. This accounts for different inline constant behavior:
3136// - Pre-GFX11: fp16 inline constants have the value in low 16 bits, 0 in high
3137// - GFX11+: fp16 inline constants are duplicated into both halves
3139 bool IsGFX11Plus) {
3140 // Pre-GFX11 behavior: f16 in low bits, 0 in high bits
3141 if (!IsGFX11Plus)
3142 return getInlineEncodingV216(/*IsFloat=*/true, Literal);
3143
3144 // GFX11+ behavior: f16 duplicated in both halves
3145 // First, check for sign-extended integer inline constants (-16 to 64)
3146 // These work the same across all generations
3147 int32_t Signed = static_cast<int32_t>(Literal);
3148 if (Signed >= 0 && Signed <= 64)
3149 return 128 + Signed;
3150
3151 if (Signed >= -16 && Signed <= -1)
3152 return 192 + std::abs(Signed);
3153
3154 // For float inline constants on GFX11+, both halves must be equal
3155 uint16_t Lo = static_cast<uint16_t>(Literal);
3156 uint16_t Hi = static_cast<uint16_t>(Literal >> 16);
3157 if (Lo != Hi)
3158 return std::nullopt;
3159 return getInlineEncodingV216(/*IsFloat=*/true, Lo);
3160}
3161
3162// Whether the given literal can be inlined for a V_PK_* instruction.
3164 switch (OpType) {
3167 return getInlineEncodingV216(false, Literal).has_value();
3170 return getInlineEncodingV216(true, Literal).has_value();
3172 llvm_unreachable("OPERAND_REG_IMM_V2FP16_SPLAT is not supported");
3177 return false;
3178 default:
3179 llvm_unreachable("bad packed operand type");
3180 }
3181}
3182
3183// Whether the given literal can be inlined for a V_PK_*_IU16 instruction.
3187
3188// Whether the given literal can be inlined for a V_PK_*_BF16 instruction.
3192
3193// Whether the given literal can be inlined for a V_PK_*_F16 instruction.
3197
3198// Whether the given literal can be inlined for V_PK_FMAC_F16 instruction.
3200 return getPKFMACF16InlineEncoding(Literal, IsGFX11Plus).has_value();
3201}
3202
3203bool isValid32BitLiteral(uint64_t Val, bool IsFP64) {
3204 if (IsFP64)
3205 return !Lo_32(Val);
3206
3207 return isUInt<32>(Val) || isInt<32>(Val);
3208}
3209
3210int64_t encode32BitLiteral(int64_t Imm, OperandType Type, bool IsLit) {
3211 switch (Type) {
3212 default:
3213 break;
3219 return Imm & 0xffff;
3233 return Lo_32(Imm);
3236 return IsLit ? Imm : Hi_32(Imm);
3237 }
3238 return Imm;
3239}
3240
3242 const Function *F = A->getParent();
3243
3244 // Arguments to compute shaders are never a source of divergence.
3245 CallingConv::ID CC = F->getCallingConv();
3246 switch (CC) {
3249 return true;
3260 // For non-compute shaders, SGPR inputs are marked with either inreg or
3261 // byval. Everything else is in VGPRs.
3262 return A->hasAttribute(Attribute::InReg) ||
3263 A->hasAttribute(Attribute::ByVal);
3264 default:
3265 // TODO: treat i1 as divergent?
3266 return A->hasAttribute(Attribute::InReg);
3267 }
3268}
3269
3270bool isArgPassedInSGPR(const CallBase *CB, unsigned ArgNo) {
3271 // Arguments to compute shaders are never a source of divergence.
3273 switch (CC) {
3276 return true;
3287 // For non-compute shaders, SGPR inputs are marked with either inreg or
3288 // byval. Everything else is in VGPRs.
3289 return CB->paramHasAttr(ArgNo, Attribute::InReg) ||
3290 CB->isByValArgument(ArgNo);
3291 default:
3292 return CB->paramHasAttr(ArgNo, Attribute::InReg);
3293 }
3294}
3295
3296static bool hasSMEMByteOffset(const MCSubtargetInfo &ST) {
3297 return isGCN3Encoding(ST) || isGFX10Plus(ST);
3298}
3299
3301 int64_t EncodedOffset) {
3302 if (isGFX12Plus(ST))
3303 return isUInt<23>(EncodedOffset);
3304
3305 return hasSMEMByteOffset(ST) ? isUInt<20>(EncodedOffset)
3306 : isUInt<8>(EncodedOffset);
3307}
3308
3310 int64_t EncodedOffset, bool IsBuffer) {
3311 if (isGFX12Plus(ST)) {
3312 if (IsBuffer && EncodedOffset < 0)
3313 return false;
3314 return isInt<24>(EncodedOffset);
3315 }
3316
3317 return !IsBuffer && hasSMRDSignedImmOffset(ST) && isInt<21>(EncodedOffset);
3318}
3319
3320static bool isDwordAligned(uint64_t ByteOffset) {
3321 return (ByteOffset & 3) == 0;
3322}
3323
3325 uint64_t ByteOffset) {
3326 if (hasSMEMByteOffset(ST))
3327 return ByteOffset;
3328
3329 assert(isDwordAligned(ByteOffset));
3330 return ByteOffset >> 2;
3331}
3332
3333std::optional<int64_t> getSMRDEncodedOffset(const MCSubtargetInfo &ST,
3334 int64_t ByteOffset, bool IsBuffer,
3335 bool HasSOffset) {
3336 // For unbuffered smem loads, it is illegal for the Immediate Offset to be
3337 // negative if the resulting (Offset + (M0 or SOffset or zero) is negative.
3338 // Handle case where SOffset is not present.
3339 if (!IsBuffer && !HasSOffset && ByteOffset < 0 && hasSMRDSignedImmOffset(ST))
3340 return std::nullopt;
3341
3342 if (isGFX12Plus(ST)) // 24 bit signed offsets
3343 return isInt<24>(ByteOffset) ? std::optional<int64_t>(ByteOffset)
3344 : std::nullopt;
3345
3346 // The signed version is always a byte offset.
3347 if (!IsBuffer && hasSMRDSignedImmOffset(ST)) {
3349 return isInt<20>(ByteOffset) ? std::optional<int64_t>(ByteOffset)
3350 : std::nullopt;
3351 }
3352
3353 if (!isDwordAligned(ByteOffset) && !hasSMEMByteOffset(ST))
3354 return std::nullopt;
3355
3356 int64_t EncodedOffset = convertSMRDOffsetUnits(ST, ByteOffset);
3357 return isLegalSMRDEncodedUnsignedOffset(ST, EncodedOffset)
3358 ? std::optional<int64_t>(EncodedOffset)
3359 : std::nullopt;
3360}
3361
3362std::optional<int64_t> getSMRDEncodedLiteralOffset32(const MCSubtargetInfo &ST,
3363 int64_t ByteOffset) {
3364 if (!isCI(ST) || !isDwordAligned(ByteOffset))
3365 return std::nullopt;
3366
3367 int64_t EncodedOffset = convertSMRDOffsetUnits(ST, ByteOffset);
3368 return isUInt<32>(EncodedOffset) ? std::optional<int64_t>(EncodedOffset)
3369 : std::nullopt;
3370}
3371
3373 if (ST.getFeatureBits().test(FeatureFlatOffsetBits12))
3374 return 12;
3375 if (ST.getFeatureBits().test(FeatureFlatOffsetBits24))
3376 return 24;
3377 return 13;
3378}
3379
3380namespace {
3381
3382struct SourceOfDivergence {
3383 unsigned Intr;
3384};
3385const SourceOfDivergence *lookupSourceOfDivergence(unsigned Intr);
3386
3387struct AlwaysUniform {
3388 unsigned Intr;
3389};
3390const AlwaysUniform *lookupAlwaysUniform(unsigned Intr);
3391
3392#define GET_SourcesOfDivergence_IMPL
3393#define GET_UniformIntrinsics_IMPL
3394#define GET_Gfx9BufferFormat_IMPL
3395#define GET_Gfx10BufferFormat_IMPL
3396#define GET_Gfx11PlusBufferFormat_IMPL
3397
3398#include "AMDGPUGenSearchableTables.inc"
3399
3400} // end anonymous namespace
3401
3402bool isIntrinsicSourceOfDivergence(unsigned IntrID) {
3403 return lookupSourceOfDivergence(IntrID);
3404}
3405
3406bool isIntrinsicAlwaysUniform(unsigned IntrID) {
3407 return lookupAlwaysUniform(IntrID);
3408}
3409
3411 uint8_t NumComponents,
3412 uint8_t NumFormat,
3413 const MCSubtargetInfo &STI) {
3414 return isGFX11Plus(STI) ? getGfx11PlusBufferFormatInfo(
3415 BitsPerComp, NumComponents, NumFormat)
3416 : isGFX10(STI)
3417 ? getGfx10BufferFormatInfo(BitsPerComp, NumComponents, NumFormat)
3418 : getGfx9BufferFormatInfo(BitsPerComp, NumComponents, NumFormat);
3419}
3420
3422 const MCSubtargetInfo &STI) {
3423 return isGFX11Plus(STI) ? getGfx11PlusBufferFormatInfo(Format)
3424 : isGFX10(STI) ? getGfx10BufferFormatInfo(Format)
3425 : getGfx9BufferFormatInfo(Format);
3426}
3427
3429 const MCRegisterInfo &MRI) {
3430 const unsigned VGPRClasses[] = {
3431 AMDGPU::VGPR_16RegClassID, AMDGPU::VGPR_32RegClassID,
3432 AMDGPU::VReg_64RegClassID, AMDGPU::VReg_96RegClassID,
3433 AMDGPU::VReg_128RegClassID, AMDGPU::VReg_160RegClassID,
3434 AMDGPU::VReg_192RegClassID, AMDGPU::VReg_224RegClassID,
3435 AMDGPU::VReg_256RegClassID, AMDGPU::VReg_288RegClassID,
3436 AMDGPU::VReg_320RegClassID, AMDGPU::VReg_352RegClassID,
3437 AMDGPU::VReg_384RegClassID, AMDGPU::VReg_512RegClassID,
3438 AMDGPU::VReg_1024RegClassID};
3439
3440 for (unsigned RCID : VGPRClasses) {
3441 const MCRegisterClass &RC = MRI.getRegClass(RCID);
3442 if (RC.contains(Reg))
3443 return &RC;
3444 }
3445
3446 return nullptr;
3447}
3448
3450 unsigned Enc = MRI.getEncodingValue(Reg);
3451 unsigned Idx = Enc & AMDGPU::HWEncoding::REG_IDX_MASK;
3452 return Idx >> 8;
3453}
3454
3456 const MCRegisterInfo &MRI) {
3457 unsigned Enc = MRI.getEncodingValue(Reg);
3458 unsigned Idx = Enc & AMDGPU::HWEncoding::REG_IDX_MASK;
3459 if (Idx >= 0x100)
3460 return MCRegister();
3461
3462 const MCRegisterClass *RC = getVGPRPhysRegClass(Reg, MRI);
3463 if (!RC)
3464 return MCRegister();
3465
3466 Idx |= MSBs << 8;
3467 if (RC->getID() == AMDGPU::VGPR_16RegClassID) {
3468 // This class has 2048 registers with interleaved lo16 and hi16.
3469 Idx *= 2;
3471 ++Idx;
3472 }
3473
3474 return RC->getRegister(Idx);
3475}
3476
3477static std::optional<unsigned>
3478convertSetRegImmToVgprMSBs(unsigned Imm, unsigned Simm16,
3479 bool HasSetregVGPRMSBFixup) {
3480 constexpr unsigned VGPRMSBShift =
3482
3483 auto [HwRegId, Offset, Size] = Hwreg::HwregEncoding::decode(Simm16);
3484 if (HwRegId != Hwreg::ID_MODE ||
3485 (!HasSetregVGPRMSBFixup && (Offset + Size) < VGPRMSBShift))
3486 return {};
3487 // If there is SetregVGPRMSBFixup then Offset is ignored.
3488 if (!HasSetregVGPRMSBFixup)
3489 Imm <<= Offset;
3490 Imm = (Imm & Hwreg::VGPR_MSB_MASK) >> VGPRMSBShift;
3491 if (!HasSetregVGPRMSBFixup)
3493 return llvm::rotr<uint8_t>(static_cast<uint8_t>(Imm), /*R=*/2);
3494}
3495
3496std::optional<unsigned> convertSetRegImmToVgprMSBs(const MachineInstr &MI,
3497 bool HasSetregVGPRMSBFixup) {
3498 assert(MI.getOpcode() == AMDGPU::S_SETREG_IMM32_B32);
3499 return convertSetRegImmToVgprMSBs(MI.getOperand(0).getImm(),
3500 MI.getOperand(1).getImm(),
3501 HasSetregVGPRMSBFixup);
3502}
3503
3504std::optional<unsigned> convertSetRegImmToVgprMSBs(const MCInst &MI,
3505 bool HasSetregVGPRMSBFixup) {
3506 assert(MI.getOpcode() == AMDGPU::S_SETREG_IMM32_B32_gfx12);
3507 return convertSetRegImmToVgprMSBs(MI.getOperand(0).getImm(),
3508 MI.getOperand(1).getImm(),
3509 HasSetregVGPRMSBFixup);
3510}
3511
3512std::pair<const AMDGPU::OpName *, const AMDGPU::OpName *>
3514 static const AMDGPU::OpName VOPOps[4] = {
3515 AMDGPU::OpName::src0, AMDGPU::OpName::src1, AMDGPU::OpName::src2,
3516 AMDGPU::OpName::vdst};
3517 static const AMDGPU::OpName VDSOps[4] = {
3518 AMDGPU::OpName::addr, AMDGPU::OpName::data0, AMDGPU::OpName::data1,
3519 AMDGPU::OpName::vdst};
3520 static const AMDGPU::OpName FLATOps[4] = {
3521 AMDGPU::OpName::vaddr, AMDGPU::OpName::vdata,
3522 AMDGPU::OpName::NUM_OPERAND_NAMES, AMDGPU::OpName::vdst};
3523 static const AMDGPU::OpName BUFOps[4] = {
3524 AMDGPU::OpName::vaddr, AMDGPU::OpName::NUM_OPERAND_NAMES,
3525 AMDGPU::OpName::NUM_OPERAND_NAMES, AMDGPU::OpName::vdata};
3526 static const AMDGPU::OpName VIMGOps[4] = {
3527 AMDGPU::OpName::vaddr0, AMDGPU::OpName::vaddr1, AMDGPU::OpName::vaddr2,
3528 AMDGPU::OpName::vdata};
3529
3530 // For VOPD instructions MSB of a corresponding Y component operand VGPR
3531 // address is supposed to match X operand, otherwise VOPD shall not be
3532 // combined.
3533 static const AMDGPU::OpName VOPDOpsX[4] = {
3534 AMDGPU::OpName::src0X, AMDGPU::OpName::vsrc1X, AMDGPU::OpName::vsrc2X,
3535 AMDGPU::OpName::vdstX};
3536 static const AMDGPU::OpName VOPDOpsY[4] = {
3537 AMDGPU::OpName::src0Y, AMDGPU::OpName::vsrc1Y, AMDGPU::OpName::vsrc2Y,
3538 AMDGPU::OpName::vdstY};
3539
3540 // VOP2 MADMK instructions use src0, imm, src1 scheme.
3541 static const AMDGPU::OpName VOP2MADMKOps[4] = {
3542 AMDGPU::OpName::src0, AMDGPU::OpName::NUM_OPERAND_NAMES,
3543 AMDGPU::OpName::src1, AMDGPU::OpName::vdst};
3544 static const AMDGPU::OpName VOPDFMAMKOpsX[4] = {
3545 AMDGPU::OpName::src0X, AMDGPU::OpName::NUM_OPERAND_NAMES,
3546 AMDGPU::OpName::vsrc1X, AMDGPU::OpName::vdstX};
3547 static const AMDGPU::OpName VOPDFMAMKOpsY[4] = {
3548 AMDGPU::OpName::src0Y, AMDGPU::OpName::NUM_OPERAND_NAMES,
3549 AMDGPU::OpName::vsrc1Y, AMDGPU::OpName::vdstY};
3550
3554 switch (Desc.getOpcode()) {
3555 // LD_SCALE operands ignore MSB.
3556 case AMDGPU::V_WMMA_LD_SCALE_PAIRED_B32:
3557 case AMDGPU::V_WMMA_LD_SCALE_PAIRED_B32_gfx1250:
3558 case AMDGPU::V_WMMA_LD_SCALE16_PAIRED_B64:
3559 case AMDGPU::V_WMMA_LD_SCALE16_PAIRED_B64_gfx1250:
3560 return {};
3561 case AMDGPU::V_FMAMK_F16:
3562 case AMDGPU::V_FMAMK_F16_t16:
3563 case AMDGPU::V_FMAMK_F16_t16_gfx12:
3564 case AMDGPU::V_FMAMK_F16_fake16:
3565 case AMDGPU::V_FMAMK_F16_fake16_gfx12:
3566 case AMDGPU::V_FMAMK_F32:
3567 case AMDGPU::V_FMAMK_F32_gfx12:
3568 case AMDGPU::V_FMAMK_F64:
3569 case AMDGPU::V_FMAMK_F64_gfx1250:
3570 return {VOP2MADMKOps, nullptr};
3571 default:
3572 break;
3573 }
3574 return {VOPOps, nullptr};
3575 }
3576
3578 return {VDSOps, nullptr};
3579
3581 return {FLATOps, nullptr};
3582
3584 return {BUFOps, nullptr};
3585
3587 return {VIMGOps, nullptr};
3588
3589 if (AMDGPU::isVOPD(Desc.getOpcode())) {
3590 auto [OpX, OpY] = getVOPDComponents(Desc.getOpcode());
3591 return {(OpX == AMDGPU::V_FMAMK_F32) ? VOPDFMAMKOpsX : VOPDOpsX,
3592 (OpY == AMDGPU::V_FMAMK_F32) ? VOPDFMAMKOpsY : VOPDOpsY};
3593 }
3594
3596
3598 llvm_unreachable("Sample and export VGPR lowering is not implemented and"
3599 " these instructions are not expected on gfx1250");
3600
3601 return {};
3602}
3603
3604bool supportsScaleOffset(const MCInstrInfo &MII, unsigned Opcode) {
3605 const MCInstrDesc &Desc = MII.get(Opcode);
3607 return Desc.mayLoad() && !Desc.mayStore() && !getSMEMIsBuffer(Opcode);
3609 return false;
3610
3611 // Only SV and SVS modes are supported.
3612 if (SIInstrFlags::isFlatScratch(MII, Opcode))
3613 return hasNamedOperand(Opcode, OpName::vaddr);
3614
3615 // Only GVS mode is supported.
3616 return hasNamedOperand(Opcode, OpName::vaddr) &&
3617 hasNamedOperand(Opcode, OpName::saddr);
3618
3619 return false;
3620}
3621
3622static bool hasAny64BitVGPROperands(const MCInstrDesc &OpDesc,
3623 const MCInstrInfo &MII,
3624 const MCSubtargetInfo &ST) {
3625 for (auto OpName : {OpName::vdst, OpName::src0, OpName::src1, OpName::src2}) {
3626 int Idx = getNamedOperandIdx(OpDesc.getOpcode(), OpName);
3627 if (Idx == -1)
3628 continue;
3629
3630 const MCOperandInfo &OpInfo = OpDesc.operands()[Idx];
3631 int16_t RegClass = MII.getOpRegClassID(
3632 OpInfo, ST.getHwMode(MCSubtargetInfo::HwMode_RegInfo));
3633 if (RegClass == AMDGPU::VReg_64RegClassID ||
3634 RegClass == AMDGPU::VReg_64_Align2RegClassID)
3635 return true;
3636 }
3637
3638 return false;
3639}
3640
3641bool isDPALU_DPP32BitOpc(unsigned Opc) {
3642 switch (Opc) {
3643 case AMDGPU::V_MUL_LO_U32_e64:
3644 case AMDGPU::V_MUL_LO_U32_e64_dpp:
3645 case AMDGPU::V_MUL_LO_U32_e64_dpp_gfx1250:
3646 case AMDGPU::V_MUL_HI_U32_e64:
3647 case AMDGPU::V_MUL_HI_U32_e64_dpp:
3648 case AMDGPU::V_MUL_HI_U32_e64_dpp_gfx1250:
3649 case AMDGPU::V_MUL_HI_I32_e64:
3650 case AMDGPU::V_MUL_HI_I32_e64_dpp:
3651 case AMDGPU::V_MUL_HI_I32_e64_dpp_gfx1250:
3652 case AMDGPU::V_MAD_U32_e64:
3653 case AMDGPU::V_MAD_U32_e64_dpp:
3654 case AMDGPU::V_MAD_U32_e64_dpp_gfx1250:
3655 return true;
3656 default:
3657 return false;
3658 }
3659}
3660
3661bool isDPALU_DPP(const MCInstrDesc &OpDesc, const MCInstrInfo &MII,
3662 const MCSubtargetInfo &ST) {
3663 if (isDPALU_DPP32BitOpc(OpDesc.getOpcode()))
3664 return true;
3665
3666 return hasAny64BitVGPROperands(OpDesc, MII, ST);
3667}
3668
3670 switch (Opc) {
3671 case AMDGPU::V_PK_ADD_F32_gfx1250:
3672 case AMDGPU::V_PK_ADD_F32_gfx1250_gfx12:
3673 case AMDGPU::V_PK_MUL_F32_gfx1250:
3674 case AMDGPU::V_PK_MUL_F32_gfx1250_gfx12:
3675 case AMDGPU::V_PK_FMA_F32_gfx1250:
3676 case AMDGPU::V_PK_FMA_F32_gfx1250_gfx12:
3677 return true;
3678 default:
3679 return false;
3680 }
3681}
3682
3683// NOTE: This function is currently only used before pseudo-expansion.
3685 switch (Opc) {
3686 case AMDGPU::V_PK_ADD_F64:
3687 case AMDGPU::V_PK_MUL_F64:
3688 case AMDGPU::V_PK_FMA_F64:
3689 case AMDGPU::V_PK_MAX_NUM_F64:
3690 case AMDGPU::V_PK_MIN_NUM_F64:
3691 case AMDGPU::V_PK_ADD_NC_U64:
3692 case AMDGPU::V_PK_SUB_NC_U64:
3693 case AMDGPU::V_PK_LSHL_ADD_U64:
3694 return true;
3695 default:
3696 return false;
3697 }
3698}
3699
3703
3704const std::array<unsigned, 3> &ClusterDimsAttr::getDims() const {
3705 assert(isFixedDims() && "expect kind to be FixedDims");
3706 return Dims;
3707}
3708
3709std::string ClusterDimsAttr::to_string() const {
3710 SmallString<10> Buffer;
3711 raw_svector_ostream OS(Buffer);
3712
3713 switch (getKind()) {
3714 case Kind::Unknown:
3715 return "";
3716 case Kind::NoCluster: {
3717 OS << EncoNoCluster << ',' << EncoNoCluster << ',' << EncoNoCluster;
3718 return Buffer.c_str();
3719 }
3720 case Kind::VariableDims: {
3721 OS << EncoVariableDims << ',' << EncoVariableDims << ','
3722 << EncoVariableDims;
3723 return Buffer.c_str();
3724 }
3725 case Kind::FixedDims: {
3726 OS << Dims[0] << ',' << Dims[1] << ',' << Dims[2];
3727 return Buffer.c_str();
3728 }
3729 }
3730 llvm_unreachable("Unknown ClusterDimsAttr kind");
3731}
3732
3734 std::optional<SmallVector<unsigned>> Attr =
3735 getIntegerVecAttribute(F, "amdgpu-cluster-dims", /*Size=*/3);
3737
3738 if (!Attr.has_value())
3739 AttrKind = Kind::Unknown;
3740 else if (all_of(*Attr, equal_to(EncoNoCluster)))
3741 AttrKind = Kind::NoCluster;
3742 else if (all_of(*Attr, equal_to(EncoVariableDims)))
3743 AttrKind = Kind::VariableDims;
3744
3745 ClusterDimsAttr A(AttrKind);
3746 if (AttrKind == Kind::FixedDims)
3747 A.Dims = {(*Attr)[0], (*Attr)[1], (*Attr)[2]};
3748
3749 return A;
3750}
3751
3752std::optional<APFloat> evaluateRcp(const APFloat &Val) {
3753 const fltSemantics &Sem = Val.getSemantics();
3754
3755 // v_rcp_f16/bf16 are correctly rounded.
3756 if (&Sem == &APFloat::IEEEhalf() || &Sem == &APFloat::BFloat())
3757 return APFloat::getOne(Sem) / Val;
3758
3759 // v_rcp_f32/f64 always flush a denormal input to zero (preserving sign)
3760 // before reciprocating.
3761 APFloat Arg = Val;
3762 if (Arg.isDenormal())
3763 Arg = APFloat::getZero(Sem, Arg.isNegative());
3764
3765 APFloat Result = APFloat::getOne(Sem) / Arg;
3766
3767 // v_rcp_f32/f64 always flush a denormal result to zero (preserving sign).
3768 if (Result.isDenormal())
3769 Result = APFloat::getZero(Sem, Result.isNegative());
3770
3771 // v_rcp_f32/f64 only approximate the reciprocal, except for these special
3772 // cases where the result is exact.
3773 if (!Result.isZero() && !Result.isInfinity() && !Result.isNaN() &&
3774 !Result.isOne() && !Result.isMinusOne())
3775 return std::nullopt;
3776
3777 return Result;
3778}
3779
3780} // namespace AMDGPU
3781
3783 switch (S) {
3784 case (AMDGPU::TargetIDSetting::Unsupported):
3785 OS << "Unsupported";
3786 break;
3787 case (AMDGPU::TargetIDSetting::Any):
3788 OS << "Any";
3789 break;
3790 case (AMDGPU::TargetIDSetting::Off):
3791 OS << "Off";
3792 break;
3793 case (AMDGPU::TargetIDSetting::On):
3794 OS << "On";
3795 break;
3796 }
3797 return OS;
3798}
3799
3800} // 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
unsigned uint64_t
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< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
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
Register Reg
Register const TargetRegisterInfo * TRI
This file contains the declarations for metadata subclasses.
#define T
uint64_t High
static bool isValid(const char C)
Returns true if C is a valid mangled character: <0-9a-zA-Z_>.
#define S_00B848_MEM_ORDERED(x)
Definition SIDefines.h:1486
#define S_00B848_WGP_MODE(x)
Definition SIDefines.h:1483
#define S_00B848_FWD_PROGRESS(x)
Definition SIDefines.h:1489
This file contains some functions that are useful when dealing with strings.
static const int BlockSize
Definition TarWriter.cpp:33
static ClusterDimsAttr get(const Function &F)
const std::array< unsigned, 3 > & getDims() const
static TargetID createFromSubtargetFeatures(const Triple &TT, StringRef CPU, StringRef FeatureString)
Construct a TargetID for triple TT and processor CPU, taking the xnack/sramecc modes from the subtarg...
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, bool HasGFX11InterlockHazard=false) const
std::array< MCRegister, Component::MAX_OPR_NUM > RegIndices
Represents the counter values to wait for in an s_waitcnt instruction.
static const fltSemantics & BFloat()
Definition APFloat.h:303
static const fltSemantics & IEEEhalf()
Definition APFloat.h:302
bool isNegative() const
Definition APFloat.h:1583
bool isDenormal() const
Definition APFloat.h:1584
const fltSemantics & getSemantics() const
Definition APFloat.h:1591
static APFloat getOne(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative One.
Definition APFloat.h:1192
static APFloat getZero(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Zero.
Definition APFloat.h:1183
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:106
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.
bool isByValArgument(unsigned ArgNo) const
Determine whether this argument is passed by value.
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:89
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:79
This holds information about one operand of a machine instruction, indicating the register class for ...
Definition MCInstrDesc.h:88
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:1081
const MDOperand & getOperand(unsigned I) const
Definition Metadata.h:1437
unsigned getNumOperands() const
Return number of MDNode operands.
Definition Metadata.h:1443
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:888
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:736
bool getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
Definition StringRef.h:490
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
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
OSType getOS() const
Get the parsed operating system type of this triple.
Definition Triple.h:523
ArchType getArch() const
Get the parsed architecture type of this triple.
Definition Triple.h:514
bool isAMDGCN() const
Tests whether the target is AMDGCN.
Definition Triple.h:992
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 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)
static unsigned getMaxHWAddressableLocalMemorySize(const MCSubtargetInfo &STI)
unsigned getAddressableNumArchVGPRs(const MCSubtargetInfo &STI)
bool isSGPROccupancyLimited(const MCSubtargetInfo &STI)
unsigned getArchVGPRAllocGranule()
For subtargets with a unified VGPR file and mixed ArchVGPR/AGPR usage, returns the allocation granule...
static unsigned getPhysicalLocalMemorySize(const MCSubtargetInfo &STI)
static unsigned getSGPRTrapHandlerReserve(const MCSubtargetInfo &STI)
unsigned getAddressableLocalMemorySize(const MCSubtargetInfo &STI)
unsigned getVGPREncodingGranule(const MCSubtargetInfo &STI, std::optional< bool > EnableWavefrontSize32)
unsigned getEncodedNumVGPRBlocks(const MCSubtargetInfo &STI, unsigned NumVGPRs, std::optional< bool > EnableWavefrontSize32)
unsigned getMaxWorkGroupsPerCU(const MCSubtargetInfo &STI, unsigned FlatWorkGroupSize)
unsigned getMinNumSGPRs(const MCSubtargetInfo &STI, unsigned WavesPerEU)
unsigned getMaxNumSGPRs(const MCSubtargetInfo &STI, unsigned WavesPerEU, bool Addressable)
unsigned getWavefrontSize(const MCSubtargetInfo &STI)
unsigned getWavesPerEUForWorkGroup(const MCSubtargetInfo &STI, unsigned FlatWorkGroupSize)
unsigned getInstCacheLineSize(const MCSubtargetInfo &STI)
static constexpr unsigned MaxDynamicVGPRBlocks
Maximum number of VGPR blocks that can be allocated in dynamic VGPR mode.
unsigned getSGPREncodingGranule(const MCSubtargetInfo &STI)
static unsigned getSGPRBudgetPerWave(unsigned TotalNumSGPRs, unsigned WavesPerEU, unsigned TrapReserve, unsigned Granule)
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)
unsigned getOccupancyWithNumSGPRs(unsigned SGPRs, unsigned MaxWaves, unsigned TotalNumSGPRs, unsigned Granule, unsigned TrapReserve)
unsigned getNumSGPRBlocks(const MCSubtargetInfo &STI, unsigned NumSGPRs)
unsigned getNumExtraSGPRs(const MCSubtargetInfo &STI, bool VCCUsed, bool FlatScrUsed, bool XNACKUsed)
unsigned getLocalMemorySize(const MCSubtargetInfo &STI)
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)
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[]
constexpr unsigned VOPD_GFX11_VGPR_BANK_MASKS[]
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)
LLVM_ABI unsigned getMaxWavesPerEU(GPUKind AK)
bool isVOPCAsmOnly(unsigned Opc)
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)
constexpr unsigned getNumWorkGroupSIMDs(bool FullSIMDMode)
bool isHi16Reg(MCRegister Reg, const MCRegisterInfo &MRI)
static int encodeCustomOperandVal(const CustomOperandVal &Op, int64_t InputVal)
unsigned getTemporalHintType(const MCInstrDesc TID)
bool isGFX10(const MCSubtargetInfo &STI)
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)
bool isFullSIMDMode(const MCSubtargetInfo &STI)
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 isPackedSingleSGPRFP32Inst(unsigned Opc)
The opcode is a packed fp32 instruction which only reads low 32 bits of a scalar operand and propagat...
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.
LLVM_ABI unsigned getAddressableNumSGPRs(GPUKind AK)
TargetID createAMDGPUTargetID(const MCSubtargetInfo &STI, StringRef FeatureString)
Construct TargetID from MCSubtargetInfo.
uint8_t mfmaScaleF8F6F4FormatToNumRegs(unsigned EncodingVal)
unsigned getVOPDOpcode(unsigned Opc, bool VOPD3)
bool isGroupSegment(const GlobalValue *GV)
LLVM_ABI IsaVersion getIsaVersion(StringRef GPU)
bool getMTBUFHasSoffset(unsigned Opc)
unsigned getRegBitWidth(unsigned RCID)
Get the size in bits of a register from the register class RC.
bool hasXNACK(const MCSubtargetInfo &STI)
bool isValid32BitLiteral(uint64_t Val, bool IsFP64)
static unsigned getCombinedCountBitMask(const IsaVersion &Version, bool IsStore)
LLVM_ABI unsigned getTotalNumVGPRs(GPUKind AK, bool IsWave32)
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()
LLVM_ABI unsigned getTotalNumSGPRs(GPUKind AK)
bool hasPrivateApertureRegs(const MCSubtargetInfo &STI)
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 isPackedSingleSGPR64BitInst(unsigned Opc)
The opcode is a packed 64-bit instruction which only reads low 64 bits of a scalar operand and propag...
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 isKImmOperand(const MCInstrDesc &Desc, unsigned OpNo)
Is this a KImm operand?
bool getHasColorExport(const Function &F)
GPUKind
GPU kinds supported by the AMDGPU target.
int getMTBUFBaseOpcode(unsigned Opc)
bool isGFX90A(const MCSubtargetInfo &STI)
unsigned getSamplecntBitMask(const IsaVersion &Version)
unsigned getDefaultQueueImplicitArgPosition(unsigned CodeObjectVersion)
int getMIMGOpcode(unsigned BaseOpcode, unsigned MIMGEncoding, unsigned VDataDwords, unsigned VAddrDwords, bool IndexedRsrc, bool IndexedSamp)
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)
LLVM_ABI unsigned getSGPRAllocGranule(GPUKind AK)
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)
LLVM_ABI GPUKind parseArchAMDGCN(StringRef CPU)
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?
static bool hasAny64BitVGPROperands(const MCInstrDesc &OpDesc, const MCInstrInfo &MII, const MCSubtargetInfo &ST)
std::optional< APFloat > evaluateRcp(const APFloat &Val)
Evaluate the constant-folded result of v_rcp for Val, accounting for the hardware's denormal flushing...
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)
SmallVector< unsigned > getMaxNumWorkGroups(const Function &F)
int64_t encode32BitLiteral(int64_t Imm, OperandType Type, bool IsLit)
bool isValidWMMAScaleFmtCombination(unsigned AFmt, unsigned AScale, unsigned BFmt, unsigned BScale)
@ OPERAND_REG_IMM_V2FP64
Definition SIDefines.h:441
@ OPERAND_KIMM32
Operand with 32-bit immediate that uses the constant bus.
Definition SIDefines.h:459
@ OPERAND_REG_INLINE_C_LAST
Definition SIDefines.h:482
@ OPERAND_REG_IMM_V2FP16
Definition SIDefines.h:434
@ OPERAND_REG_INLINE_C_FP64
Definition SIDefines.h:450
@ OPERAND_REG_IMM_NOINLINE_FP16
Definition SIDefines.h:432
@ OPERAND_REG_INLINE_C_BF16
Definition SIDefines.h:447
@ OPERAND_REG_INLINE_C_V2BF16
Definition SIDefines.h:452
@ OPERAND_REG_IMM_V2INT16
Definition SIDefines.h:436
@ OPERAND_REG_IMM_BF16
Definition SIDefines.h:430
@ OPERAND_REG_IMM_INT32
Operands with register, 32-bit, or 64-bit immediate.
Definition SIDefines.h:425
@ OPERAND_REG_IMM_V2BF16
Definition SIDefines.h:433
@ OPERAND_REG_INLINE_AC_FIRST
Definition SIDefines.h:484
@ OPERAND_REG_IMM_FP16
Definition SIDefines.h:431
@ OPERAND_REG_IMM_V2FP16_SPLAT
Definition SIDefines.h:435
@ OPERAND_REG_IMM_NOINLINE_V2FP16
Definition SIDefines.h:438
@ OPERAND_REG_IMM_FP64
Definition SIDefines.h:429
@ OPERAND_REG_INLINE_C_V2FP16
Definition SIDefines.h:453
@ OPERAND_REG_INLINE_AC_INT32
Operands with an AccVGPR register or inline constant.
Definition SIDefines.h:464
@ OPERAND_REG_INLINE_AC_FP32
Definition SIDefines.h:465
@ OPERAND_REG_IMM_V2INT32
Definition SIDefines.h:439
@ OPERAND_REG_IMM_FP32
Definition SIDefines.h:428
@ OPERAND_REG_INLINE_C_FIRST
Definition SIDefines.h:481
@ OPERAND_REG_INLINE_C_FP32
Definition SIDefines.h:449
@ OPERAND_REG_INLINE_AC_LAST
Definition SIDefines.h:485
@ OPERAND_REG_INLINE_C_INT32
Definition SIDefines.h:445
@ OPERAND_REG_INLINE_C_V2INT16
Definition SIDefines.h:451
@ OPERAND_REG_IMM_V2FP32
Definition SIDefines.h:440
@ OPERAND_REG_INLINE_AC_FP64
Definition SIDefines.h:466
@ OPERAND_REG_INLINE_C_FP16
Definition SIDefines.h:448
@ OPERAND_INLINE_SPLIT_BARRIER_INT32
Definition SIDefines.h:456
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)
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 isRsrcIndexReg(MCRegister Reg, const MCRegisterInfo &MRI)
bool isCvt_F32_Fp8_Bf8_e64(unsigned Opc)
std::optional< unsigned > getInlineEncodingV2I16(uint32_t Literal)
unsigned encodeStorecntDscnt(const IsaVersion &Version, const Waitcnt &Decoded)
bool isGFX1250(const MCSubtargetInfo &STI)
const MIMGBaseOpcodeInfo * getMIMGBaseOpcode(unsigned Opc)
bool isVI(const MCSubtargetInfo &STI)
bool isSingleSGPRReadInst(unsigned Opc)
Packed instructions that read a single SGPR for SGPR operands, except for 64-bit elements which read ...
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)
bool hasPopsExitingWaveID(const MCSubtargetInfo &STI)
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)
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.
@ ELFABIVERSION_AMDGPU_HSA_V4
Definition ELF.h:384
@ ELFABIVERSION_AMDGPU_HSA_V5
Definition ELF.h:385
@ ELFABIVERSION_AMDGPU_HSA_V6
Definition ELF.h:386
constexpr bool isVOPC(const T &...O)
Definition SIDefines.h:233
constexpr bool isVOP3(const T &...O)
Definition SIDefines.h:236
constexpr bool isVOP1(const T &...O)
Definition SIDefines.h:227
constexpr bool isVOP2(const T &...O)
Definition SIDefines.h:230
constexpr bool isFLAT(const T &...O)
Definition SIDefines.h:283
constexpr bool isBuffer(const T &...O)
Definition SIDefines.h:264
constexpr bool isVIMAGE(const T &...O)
Definition SIDefines.h:274
constexpr bool isSMRD(const T &...O)
Definition SIDefines.h:268
constexpr bool isVOP3Like(const T &...O)
Definition SIDefines.h:242
constexpr bool isFlatScratch(const T &...O)
Definition SIDefines.h:355
constexpr bool isMIMG(const T &...O)
Definition SIDefines.h:271
constexpr bool isVOPD3(const T &...O)
Definition SIDefines.h:379
constexpr bool isEXP(const T &...O)
Definition SIDefines.h:280
constexpr bool isVSAMPLE(const T &...O)
Definition SIDefines.h:277
constexpr bool isDS(const T &...O)
Definition SIDefines.h:286
constexpr bool isAtomic(const T &...O)
Definition SIDefines.h:390
constexpr bool isDPP(const T &...O)
Definition SIDefines.h:252
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:694
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > extract(Y &&MD)
Extract a Value from Metadata.
Definition Metadata.h:679
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:577
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:1755
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
Definition MathExtras.h:166
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:541
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:2189
Op::Description Desc
constexpr uint32_t Hi_32(uint64_t Value)
Return the high 32 bits of a 64 bit value.
Definition MathExtras.h:151
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:190
constexpr uint32_t Lo_32(uint64_t Value)
Return the low 32 bits of a 64 bit value.
Definition MathExtras.h:156
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
constexpr T divideCeil(U Numerator, V Denominator)
Returns the integer ceil(Numerator / Denominator).
Definition MathExtras.h:389
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:78
@ 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.