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"
22#include "llvm/IR/IntrinsicsAMDGPU.h"
23#include "llvm/IR/IntrinsicsR600.h"
24#include "llvm/IR/LLVMContext.h"
25#include "llvm/IR/Metadata.h"
26#include "llvm/MC/MCInstrInfo.h"
31#include <optional>
32
33#define GET_INSTRINFO_NAMED_OPS
34#define GET_INSTRMAP_INFO
35#include "AMDGPUGenInstrInfo.inc"
36
38 "amdhsa-code-object-version", llvm::cl::Hidden,
40 llvm::cl::desc("Set default AMDHSA Code Object Version (module flag "
41 "or asm directive still take priority if present)"));
42
43namespace {
44
45/// \returns Bit mask for given bit \p Shift and bit \p Width.
46unsigned getBitMask(unsigned Shift, unsigned Width) {
47 return ((1 << Width) - 1) << Shift;
48}
49
50/// Packs \p Src into \p Dst for given bit \p Shift and bit \p Width.
51///
52/// \returns Packed \p Dst.
53unsigned packBits(unsigned Src, unsigned Dst, unsigned Shift, unsigned Width) {
54 unsigned Mask = getBitMask(Shift, Width);
55 return ((Src << Shift) & Mask) | (Dst & ~Mask);
56}
57
58/// Unpacks bits from \p Src for given bit \p Shift and bit \p Width.
59///
60/// \returns Unpacked bits.
61unsigned unpackBits(unsigned Src, unsigned Shift, unsigned Width) {
62 return (Src & getBitMask(Shift, Width)) >> Shift;
63}
64
65/// \returns Vmcnt bit shift (lower bits).
66unsigned getVmcntBitShiftLo(unsigned VersionMajor) {
67 return VersionMajor >= 11 ? 10 : 0;
68}
69
70/// \returns Vmcnt bit width (lower bits).
71unsigned getVmcntBitWidthLo(unsigned VersionMajor) {
72 return VersionMajor >= 11 ? 6 : 4;
73}
74
75/// \returns Expcnt bit shift.
76unsigned getExpcntBitShift(unsigned VersionMajor) {
77 return VersionMajor >= 11 ? 0 : 4;
78}
79
80/// \returns Expcnt bit width.
81unsigned getExpcntBitWidth(unsigned VersionMajor) { return 3; }
82
83/// \returns Lgkmcnt bit shift.
84unsigned getLgkmcntBitShift(unsigned VersionMajor) {
85 return VersionMajor >= 11 ? 4 : 8;
86}
87
88/// \returns Lgkmcnt bit width.
89unsigned getLgkmcntBitWidth(unsigned VersionMajor) {
90 return VersionMajor >= 10 ? 6 : 4;
91}
92
93/// \returns Vmcnt bit shift (higher bits).
94unsigned getVmcntBitShiftHi(unsigned VersionMajor) { return 14; }
95
96/// \returns Vmcnt bit width (higher bits).
97unsigned getVmcntBitWidthHi(unsigned VersionMajor) {
98 return (VersionMajor == 9 || VersionMajor == 10) ? 2 : 0;
99}
100
101/// \returns Loadcnt bit width
102unsigned getLoadcntBitWidth(unsigned VersionMajor) {
103 return VersionMajor >= 12 ? 6 : 0;
104}
105
106/// \returns Samplecnt bit width.
107unsigned getSamplecntBitWidth(unsigned VersionMajor) {
108 return VersionMajor >= 12 ? 6 : 0;
109}
110
111/// \returns Bvhcnt bit width.
112unsigned getBvhcntBitWidth(unsigned VersionMajor) {
113 return VersionMajor >= 12 ? 3 : 0;
114}
115
116/// \returns Dscnt bit width.
117unsigned getDscntBitWidth(unsigned VersionMajor) {
118 return VersionMajor >= 12 ? 6 : 0;
119}
120
121/// \returns Dscnt bit shift in combined S_WAIT instructions.
122unsigned getDscntBitShift(unsigned VersionMajor) { return 0; }
123
124/// \returns Storecnt or Vscnt bit width, depending on VersionMajor.
125unsigned getStorecntBitWidth(unsigned VersionMajor) {
126 return VersionMajor >= 10 ? 6 : 0;
127}
128
129/// \returns Kmcnt bit width.
130unsigned getKmcntBitWidth(unsigned VersionMajor) {
131 return VersionMajor >= 12 ? 5 : 0;
132}
133
134/// \returns Xcnt bit width.
135unsigned getXcntBitWidth(unsigned VersionMajor, unsigned VersionMinor) {
136 return VersionMajor == 12 && VersionMinor == 5 ? 6 : 0;
137}
138
139/// \returns Asynccnt bit width.
140unsigned getAsynccntBitWidth(unsigned VersionMajor, unsigned VersionMinor) {
141 return VersionMajor == 12 && VersionMinor == 5 ? 6 : 0;
142}
143
144/// \returns shift for Loadcnt/Storecnt in combined S_WAIT instructions.
145unsigned getLoadcntStorecntBitShift(unsigned VersionMajor) {
146 return VersionMajor >= 12 ? 8 : 0;
147}
148
149/// \returns barrier member count bit width in M0.
150unsigned getBarrierMemberCountBitWidth(unsigned VersionMajor) {
151 return VersionMajor >= 13 ? 8 : 6;
152}
153
154/// \returns VaSdst bit width
155inline unsigned getVaSdstBitWidth() { return 3; }
156
157/// \returns VaSdst bit shift
158inline unsigned getVaSdstBitShift() { return 9; }
159
160/// \returns VmVsrc bit width
161inline unsigned getVmVsrcBitWidth() { return 3; }
162
163/// \returns VmVsrc bit shift
164inline unsigned getVmVsrcBitShift() { return 2; }
165
166/// \returns VaVdst bit width
167inline unsigned getVaVdstBitWidth() { return 4; }
168
169/// \returns VaVdst bit shift
170inline unsigned getVaVdstBitShift() { return 12; }
171
172/// \returns VaVcc bit width
173inline unsigned getVaVccBitWidth() { return 1; }
174
175/// \returns VaVcc bit shift
176inline unsigned getVaVccBitShift() { return 1; }
177
178/// \returns SaSdst bit width
179inline unsigned getSaSdstBitWidth() { return 1; }
180
181/// \returns SaSdst bit shift
182inline unsigned getSaSdstBitShift() { return 0; }
183
184/// \returns VaSsrc width
185inline unsigned getVaSsrcBitWidth() { return 1; }
186
187/// \returns VaSsrc bit shift
188inline unsigned getVaSsrcBitShift() { return 8; }
189
190/// \returns HoldCnt bit shift
191inline unsigned getHoldCntWidth(unsigned VersionMajor, unsigned VersionMinor) {
192 static constexpr const unsigned MinMajor = 10;
193 static constexpr const unsigned MinMinor = 3;
194 return std::tie(VersionMajor, VersionMinor) >= std::tie(MinMajor, MinMinor)
195 ? 1
196 : 0;
197}
198
199/// \returns HoldCnt bit shift
200inline unsigned getHoldCntBitShift() { return 7; }
201
202} // end anonymous namespace
203
204namespace llvm {
205
206namespace AMDGPU {
207
208/// \returns true if the target supports signed immediate offset for SMRD
209/// instructions.
211 return isGFX9Plus(ST);
212}
213
214/// \returns True if \p STI is AMDHSA.
215bool isHsaAbi(const MCSubtargetInfo &STI) {
216 return STI.getTargetTriple().getOS() == Triple::AMDHSA;
217}
218
221 M.getModuleFlag("amdhsa_code_object_version"))) {
222 return (unsigned)Ver->getZExtValue() / 100;
223 }
224
226}
227
231
232unsigned getAMDHSACodeObjectVersion(unsigned ABIVersion) {
233 switch (ABIVersion) {
235 return 4;
237 return 5;
239 return 6;
240 default:
242 }
243}
244
245uint8_t getELFABIVersion(const Triple &T, unsigned CodeObjectVersion) {
246 if (T.getOS() != Triple::AMDHSA)
247 return 0;
248
249 switch (CodeObjectVersion) {
250 case 4:
252 case 5:
254 case 6:
256 default:
257 report_fatal_error("Unsupported AMDHSA Code Object Version " +
258 Twine(CodeObjectVersion));
259 }
260}
261
262unsigned getMultigridSyncArgImplicitArgPosition(unsigned CodeObjectVersion) {
263 switch (CodeObjectVersion) {
264 case AMDHSA_COV4:
265 return 48;
266 case AMDHSA_COV5:
267 case AMDHSA_COV6:
268 default:
270 }
271}
272
273// FIXME: All such magic numbers about the ABI should be in a
274// central TD file.
275unsigned getHostcallImplicitArgPosition(unsigned CodeObjectVersion) {
276 switch (CodeObjectVersion) {
277 case AMDHSA_COV4:
278 return 24;
279 case AMDHSA_COV5:
280 case AMDHSA_COV6:
281 default:
283 }
284}
285
286unsigned getDefaultQueueImplicitArgPosition(unsigned CodeObjectVersion) {
287 switch (CodeObjectVersion) {
288 case AMDHSA_COV4:
289 return 32;
290 case AMDHSA_COV5:
291 case AMDHSA_COV6:
292 default:
294 }
295}
296
297unsigned getCompletionActionImplicitArgPosition(unsigned CodeObjectVersion) {
298 switch (CodeObjectVersion) {
299 case AMDHSA_COV4:
300 return 40;
301 case AMDHSA_COV5:
302 case AMDHSA_COV6:
303 default:
305 }
306}
307
308#define GET_MIMGBaseOpcodesTable_IMPL
309#define GET_MIMGDimInfoTable_IMPL
310#define GET_MIMGInfoTable_IMPL
311#define GET_MIMGLZMappingTable_IMPL
312#define GET_MIMGMIPMappingTable_IMPL
313#define GET_MIMGBiasMappingTable_IMPL
314#define GET_MIMGOffsetMappingTable_IMPL
315#define GET_MIMGG16MappingTable_IMPL
316#define GET_MAIInstInfoTable_IMPL
317#define GET_WMMAInstInfoTable_IMPL
318#include "AMDGPUGenSearchableTables.inc"
319
320int getMIMGOpcode(unsigned BaseOpcode, unsigned MIMGEncoding,
321 unsigned VDataDwords, unsigned VAddrDwords, bool IndexedRsrc,
322 bool IndexedSamp) {
323 const MIMGInfo *Info =
324 getMIMGOpcodeHelper(BaseOpcode, MIMGEncoding, VDataDwords, VAddrDwords,
325 IndexedRsrc, IndexedSamp);
326 return Info ? Info->Opcode : -1;
327}
328
330 const MIMGInfo *Info = getMIMGInfo(Opc);
331 return Info ? getMIMGBaseOpcodeInfo(Info->BaseOpcode) : nullptr;
332}
333
334int getMaskedMIMGOp(unsigned Opc, unsigned NewChannels) {
335 const MIMGInfo *OrigInfo = getMIMGInfo(Opc);
336 const MIMGInfo *NewInfo = getMIMGOpcodeHelper(
337 OrigInfo->BaseOpcode, OrigInfo->MIMGEncoding, NewChannels,
338 OrigInfo->VAddrDwords, OrigInfo->IndexedRsrc, OrigInfo->IndexedSamp);
339 return NewInfo ? NewInfo->Opcode : -1;
340}
341
342unsigned getAddrSizeMIMGOp(const MIMGBaseOpcodeInfo *BaseOpcode,
343 const MIMGDimInfo *Dim, bool IsA16,
344 bool IsG16Supported) {
345 unsigned AddrWords = BaseOpcode->NumExtraArgs;
346 unsigned AddrComponents = (BaseOpcode->Coordinates ? Dim->NumCoords : 0) +
347 (BaseOpcode->LodOrClampOrMip ? 1 : 0);
348 if (IsA16)
349 AddrWords += divideCeil(AddrComponents, 2);
350 else
351 AddrWords += AddrComponents;
352
353 // Note: For subtargets that support A16 but not G16, enabling A16 also
354 // enables 16 bit gradients.
355 // For subtargets that support A16 (operand) and G16 (done with a different
356 // instruction encoding), they are independent.
357
358 if (BaseOpcode->Gradients) {
359 if ((IsA16 && !IsG16Supported) || BaseOpcode->G16)
360 // There are two gradients per coordinate, we pack them separately.
361 // For the 3d case,
362 // we get (dy/du, dx/du) (-, dz/du) (dy/dv, dx/dv) (-, dz/dv)
363 AddrWords += alignTo<2>(Dim->NumGradients / 2);
364 else
365 AddrWords += Dim->NumGradients;
366 }
367 return AddrWords;
368}
369
380
389
390struct SMInfo {
392};
393
397
401
405
410
418
422
425 bool IsX;
426 bool IsY;
427};
428
429#define GET_FP4FP8DstByteSelTable_DECL
430#define GET_FP4FP8DstByteSelTable_IMPL
431
435
441
445
446#define GET_DPMACCInstructionTable_DECL
447#define GET_DPMACCInstructionTable_IMPL
448#define GET_MTBUFInfoTable_DECL
449#define GET_MTBUFInfoTable_IMPL
450#define GET_MUBUFInfoTable_DECL
451#define GET_MUBUFInfoTable_IMPL
452#define GET_SMInfoTable_DECL
453#define GET_SMInfoTable_IMPL
454#define GET_VOP1InfoTable_DECL
455#define GET_VOP1InfoTable_IMPL
456#define GET_VOP2InfoTable_DECL
457#define GET_VOP2InfoTable_IMPL
458#define GET_VOP3InfoTable_DECL
459#define GET_VOP3InfoTable_IMPL
460#define GET_VOPC64DPPTable_DECL
461#define GET_VOPC64DPPTable_IMPL
462#define GET_VOPC64DPP8Table_DECL
463#define GET_VOPC64DPP8Table_IMPL
464#define GET_VOPCAsmOnlyInfoTable_DECL
465#define GET_VOPCAsmOnlyInfoTable_IMPL
466#define GET_VOP3CAsmOnlyInfoTable_DECL
467#define GET_VOP3CAsmOnlyInfoTable_IMPL
468#define GET_VOPDComponentTable_DECL
469#define GET_VOPDComponentTable_IMPL
470#define GET_VOPDPairs_DECL
471#define GET_VOPDPairs_IMPL
472#define GET_VOPDXYTable_DECL
473#define GET_VOPDXYTable_IMPL
474#define GET_VOPTrue16Table_DECL
475#define GET_VOPTrue16Table_IMPL
476#define GET_VOP3PHasNoOpSelHiTable_DECL
477#define GET_VOP3PHasNoOpSelHiTable_IMPL
478#define GET_True16D16Table_IMPL
479#define GET_WMMAOpcode2AddrMappingTable_DECL
480#define GET_WMMAOpcode2AddrMappingTable_IMPL
481#define GET_WMMAOpcode3AddrMappingTable_DECL
482#define GET_WMMAOpcode3AddrMappingTable_IMPL
483#define GET_getMFMA_F8F6F4_WithSize_DECL
484#define GET_getMFMA_F8F6F4_WithSize_IMPL
485#define GET_isMFMA_F8F6F4Table_IMPL
486#define GET_isCvtScaleF32_F32F16ToF8F4Table_IMPL
487
488#include "AMDGPUGenSearchableTables.inc"
489
490int getMTBUFBaseOpcode(unsigned Opc) {
491 const MTBUFInfo *Info = getMTBUFInfoFromOpcode(Opc);
492 return Info ? Info->BaseOpcode : -1;
493}
494
495int getMTBUFOpcode(unsigned BaseOpc, unsigned Elements) {
496 const MTBUFInfo *Info =
497 getMTBUFInfoFromBaseOpcodeAndElements(BaseOpc, Elements);
498 return Info ? Info->Opcode : -1;
499}
500
501int getMTBUFElements(unsigned Opc) {
502 const MTBUFInfo *Info = getMTBUFOpcodeHelper(Opc);
503 return Info ? Info->elements : 0;
504}
505
506bool getMTBUFHasVAddr(unsigned Opc) {
507 const MTBUFInfo *Info = getMTBUFOpcodeHelper(Opc);
508 return Info && Info->has_vaddr;
509}
510
511bool getMTBUFHasSrsrc(unsigned Opc) {
512 const MTBUFInfo *Info = getMTBUFOpcodeHelper(Opc);
513 return Info && Info->has_srsrc;
514}
515
516bool getMTBUFHasSoffset(unsigned Opc) {
517 const MTBUFInfo *Info = getMTBUFOpcodeHelper(Opc);
518 return Info && Info->has_soffset;
519}
520
521int getMUBUFBaseOpcode(unsigned Opc) {
522 const MUBUFInfo *Info = getMUBUFInfoFromOpcode(Opc);
523 return Info ? Info->BaseOpcode : -1;
524}
525
526int getMUBUFOpcode(unsigned BaseOpc, unsigned Elements) {
527 const MUBUFInfo *Info =
528 getMUBUFInfoFromBaseOpcodeAndElements(BaseOpc, Elements);
529 return Info ? Info->Opcode : -1;
530}
531
532int getMUBUFElements(unsigned Opc) {
533 const MUBUFInfo *Info = getMUBUFOpcodeHelper(Opc);
534 return Info ? Info->elements : 0;
535}
536
537bool getMUBUFHasVAddr(unsigned Opc) {
538 const MUBUFInfo *Info = getMUBUFOpcodeHelper(Opc);
539 return Info && Info->has_vaddr;
540}
541
542bool getMUBUFHasSrsrc(unsigned Opc) {
543 const MUBUFInfo *Info = getMUBUFOpcodeHelper(Opc);
544 return Info && Info->has_srsrc;
545}
546
547bool getMUBUFHasSoffset(unsigned Opc) {
548 const MUBUFInfo *Info = getMUBUFOpcodeHelper(Opc);
549 return Info && Info->has_soffset;
550}
551
552bool getMUBUFIsBufferInv(unsigned Opc) {
553 const MUBUFInfo *Info = getMUBUFOpcodeHelper(Opc);
554 return Info && Info->IsBufferInv;
555}
556
557bool getMUBUFTfe(unsigned Opc) {
558 const MUBUFInfo *Info = getMUBUFOpcodeHelper(Opc);
559 return Info && Info->tfe;
560}
561
562bool getSMEMIsBuffer(unsigned Opc) {
563 return isSMEMOpcodeHelper(Opc) != nullptr;
564}
565
566bool getVOP1IsSingle(unsigned Opc) {
567 return isVOP1SingleOpcodeHelper(Opc) != nullptr;
568}
569
570bool getVOP2IsSingle(unsigned Opc) {
571 return isVOP2SingleOpcodeHelper(Opc) != nullptr;
572}
573
574bool getVOP3IsSingle(unsigned Opc) {
575 return isVOP3SingleOpcodeHelper(Opc) != nullptr;
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(static_cast<uint16_t>(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) { return isTrue16Opcode(Opc) != nullptr; }
836
837bool hasNoOpSelHi(unsigned Opc) {
838 return getVOP3PHasNoOpSelHiHelper(Opc) != nullptr;
839}
840
842 const FP4FP8DstByteSelInfo *Info = getFP4FP8DstByteSelHelper(Opc);
843 if (!Info)
844 return FPType::None;
845 if (Info->HasFP8DstByteSel)
846 return FPType::FP8;
847 if (Info->HasFP4DstByteSel)
848 return FPType::FP4;
849
850 return FPType::None;
851}
852
853bool isDPMACCInstruction(unsigned Opc) {
854 return isDPMACCInstructionHelper(Opc) != nullptr;
855}
856
857unsigned mapWMMA2AddrTo3AddrOpcode(unsigned Opc) {
858 const WMMAOpcodeMappingInfo *Info = getWMMAMappingInfoFrom2AddrOpcode(Opc);
859 return Info ? Info->Opcode3Addr : ~0u;
860}
861
862// Wrapper for Tablegen'd function. enum Subtarget is not defined in any
863// header files, so we need to wrap it in a function that takes unsigned
864// instead.
865int32_t getMCOpcode(uint32_t Opcode, unsigned Gen) {
866 return getMCOpcodeGen(Opcode, static_cast<Subtarget>(Gen));
867}
868
869unsigned getBitOp2(unsigned Opc) {
870 switch (Opc) {
871 default:
872 return 0;
873 case AMDGPU::V_AND_B32_e32:
874 return 0x40;
875 case AMDGPU::V_OR_B32_e32:
876 return 0x54;
877 case AMDGPU::V_XOR_B32_e32:
878 return 0x14;
879 case AMDGPU::V_XNOR_B32_e32:
880 return 0x41;
881 }
882}
883
884int getVOPDFull(unsigned OpX, unsigned OpY, unsigned EncodingFamily,
885 bool VOPD3) {
886 bool IsConvertibleToBitOp = VOPD3 ? getBitOp2(OpY) : 0;
887 OpY = IsConvertibleToBitOp ? (unsigned)AMDGPU::V_BITOP3_B32_e64 : OpY;
888 const VOPDInfo *Info = getVOPDInfoFromComponentOpcodes(
889 static_cast<uint8_t>(OpX), static_cast<uint8_t>(OpY),
890 static_cast<uint8_t>(EncodingFamily), VOPD3);
891 return Info ? Info->Opcode : -1;
892}
893
894std::pair<unsigned, unsigned> getVOPDComponents(unsigned VOPDOpcode) {
895 const VOPDInfo *Info = getVOPDOpcodeHelper(VOPDOpcode);
896 assert(Info);
897 const auto *OpX = getVOPDBaseFromComponent(Info->OpX);
898 const auto *OpY = getVOPDBaseFromComponent(Info->OpY);
899 assert(OpX && OpY);
900 return {OpX->BaseVOP, OpY->BaseVOP};
901}
902
903namespace VOPD {
904
905ComponentProps::ComponentProps(const MCInstrDesc &OpDesc, bool VOP3Layout) {
907
910 auto TiedIdx = OpDesc.getOperandConstraint(Component::SRC2, MCOI::TIED_TO);
911 assert(TiedIdx == -1 || TiedIdx == Component::DST);
912 HasSrc2Acc = TiedIdx != -1;
913 Opcode = OpDesc.getOpcode();
914
915 IsVOP3 = VOP3Layout || SIInstrFlags::isVOP3(OpDesc);
916 SrcOperandsNum = AMDGPU::hasNamedOperand(Opcode, AMDGPU::OpName::src2) ? 3
917 : AMDGPU::hasNamedOperand(Opcode, AMDGPU::OpName::imm) ? 3
918 : AMDGPU::hasNamedOperand(Opcode, AMDGPU::OpName::src1) ? 2
919 : 1;
920 assert(SrcOperandsNum <= Component::MAX_SRC_NUM);
921
922 if (Opcode == AMDGPU::V_CNDMASK_B32_e32 ||
923 Opcode == AMDGPU::V_CNDMASK_B32_e64) {
924 // CNDMASK is an awkward exception, it has FP modifiers, but not FP
925 // operands.
926 NumVOPD3Mods = 2;
927 if (IsVOP3)
928 SrcOperandsNum = 3;
929 } else if (Opcode == AMDGPU::V_DOT2_F32_F16 ||
930 Opcode == AMDGPU::V_DOT2_F32_BF16) {
931 // VOP3P opcodes that have VOPD but don't have VOP2 version. Using VOPD3
932 // path in getIndexOfSrcInMCOperands to get correct src operand indexes,
933 // but generating VOPD, not VOPD3.
934 NumVOPD3Mods = SrcOperandsNum;
935 } else if (isSISrcFPOperand(OpDesc,
936 getNamedOperandIdx(Opcode, OpName::src0))) {
937 // All FP VOPD instructions have Neg modifiers for all operands except
938 // for tied src2.
939 NumVOPD3Mods = SrcOperandsNum;
940 if (HasSrc2Acc)
941 --NumVOPD3Mods;
942 }
943
944 if (SIInstrFlags::isVOP3(OpDesc))
945 return;
946
947 auto OperandsNum = OpDesc.getNumOperands();
948 unsigned CompOprIdx;
949 for (CompOprIdx = Component::SRC1; CompOprIdx < OperandsNum; ++CompOprIdx) {
950 if (OpDesc.operands()[CompOprIdx].OperandType == AMDGPU::OPERAND_KIMM32) {
951 MandatoryLiteralIdx = CompOprIdx;
952 break;
953 }
954 }
955}
956
958 return getNamedOperandIdx(Opcode, OpName::bitop3);
959}
960
961unsigned ComponentInfo::getIndexInParsedOperands(unsigned CompOprIdx) const {
962 assert(CompOprIdx < Component::MAX_OPR_NUM);
963
964 if (CompOprIdx == Component::DST)
966
967 auto CompSrcIdx = CompOprIdx - Component::DST_NUM;
968 if (CompSrcIdx < getCompParsedSrcOperandsNum())
969 return getIndexOfSrcInParsedOperands(CompSrcIdx);
970
971 // The specified operand does not exist.
972 return 0;
973}
974
976 std::function<MCRegister(unsigned, unsigned)> GetRegIdx,
977 const MCRegisterInfo &MRI, bool SkipSrc, bool AllowSameVGPR, bool VOPD3,
978 bool HasGFX11InterlockHazard) const {
979
980 auto OpXRegs = getRegIndices(ComponentIndex::X, GetRegIdx,
981 CompInfo[ComponentIndex::X].isVOP3());
982 auto OpYRegs = getRegIndices(ComponentIndex::Y, GetRegIdx,
983 CompInfo[ComponentIndex::Y].isVOP3());
984
985 const auto banksOverlap = [&MRI](MCRegister X, MCRegister Y,
986 unsigned BanksMask) -> bool {
987 MCRegister BaseX = MRI.getSubReg(X, AMDGPU::sub0);
988 MCRegister BaseY = MRI.getSubReg(Y, AMDGPU::sub0);
989 if (!BaseX)
990 BaseX = X;
991 if (!BaseY)
992 BaseY = Y;
993 if ((BaseX.id() & BanksMask) == (BaseY.id() & BanksMask))
994 return true;
995 if (BaseX != X /* This is 64-bit register */ &&
996 ((BaseX.id() + 1) & BanksMask) == (BaseY.id() & BanksMask))
997 return true;
998 if (BaseY != Y &&
999 (BaseX.id() & BanksMask) == ((BaseY.id() + 1) & BanksMask))
1000 return true;
1001
1002 // If both are 64-bit bank conflict will be detected yet while checking
1003 // the first subreg.
1004 return false;
1005 };
1006
1007 unsigned CompOprIdx;
1008 for (CompOprIdx = 0; CompOprIdx < Component::MAX_OPR_NUM; ++CompOprIdx) {
1009 unsigned BanksMasks = VOPD3 ? VOPD3_VGPR_BANK_MASKS[CompOprIdx]
1010 : HasGFX11InterlockHazard
1011 ? VOPD_GFX11_VGPR_BANK_MASKS[CompOprIdx]
1012 : VOPD_VGPR_BANK_MASKS[CompOprIdx];
1013 if (!OpXRegs[CompOprIdx] || !OpYRegs[CompOprIdx])
1014 continue;
1015
1016 if (getVGPREncodingMSBs(OpXRegs[CompOprIdx], MRI) !=
1017 getVGPREncodingMSBs(OpYRegs[CompOprIdx], MRI))
1018 return CompOprIdx;
1019
1020 if (SkipSrc && CompOprIdx >= Component::DST_NUM)
1021 continue;
1022
1023 if (CompOprIdx < Component::DST_NUM) {
1024 // Even if we do not check vdst parity, vdst operands still shall not
1025 // overlap.
1026 if (MRI.regsOverlap(OpXRegs[CompOprIdx], OpYRegs[CompOprIdx]))
1027 return CompOprIdx;
1028 if (VOPD3) // No need to check dst parity.
1029 continue;
1030 }
1031
1032 if (banksOverlap(OpXRegs[CompOprIdx], OpYRegs[CompOprIdx], BanksMasks) &&
1033 (!AllowSameVGPR || CompOprIdx < Component::DST_NUM ||
1034 OpXRegs[CompOprIdx] != OpYRegs[CompOprIdx]))
1035 return CompOprIdx;
1036 }
1037
1038 return {};
1039}
1040
1041// Return an array of VGPR registers [DST,SRC0,SRC1,SRC2] used
1042// by the specified component. If an operand is unused
1043// or is not a VGPR, the corresponding value is 0.
1044//
1045// GetRegIdx(Component, MCOperandIdx) must return a VGPR register index
1046// for the specified component and MC operand. The callback must return 0
1047// if the operand is not a register or not a VGPR.
1049InstInfo::getRegIndices(unsigned CompIdx,
1050 std::function<MCRegister(unsigned, unsigned)> GetRegIdx,
1051 bool VOPD3) const {
1052 assert(CompIdx < COMPONENTS_NUM);
1053
1054 const auto &Comp = CompInfo[CompIdx];
1056
1057 RegIndices[DST] = GetRegIdx(CompIdx, Comp.getIndexOfDstInMCOperands());
1058
1059 for (unsigned CompOprIdx : {SRC0, SRC1, SRC2}) {
1060 unsigned CompSrcIdx = CompOprIdx - DST_NUM;
1061 RegIndices[CompOprIdx] =
1062 Comp.hasRegSrcOperand(CompSrcIdx)
1063 ? GetRegIdx(CompIdx,
1064 Comp.getIndexOfSrcInMCOperands(CompSrcIdx, VOPD3))
1065 : MCRegister();
1066 }
1067 return RegIndices;
1068}
1069
1070} // namespace VOPD
1071
1073 return VOPD::InstInfo(OpX, OpY);
1074}
1075
1077 const MCInstrInfo *InstrInfo) {
1078 auto [OpX, OpY] = getVOPDComponents(VOPDOpcode);
1079 const auto &OpXDesc = InstrInfo->get(OpX);
1080 const auto &OpYDesc = InstrInfo->get(OpY);
1081 bool VOPD3 = SIInstrFlags::isVOPD3(*InstrInfo, VOPDOpcode);
1083 VOPD::ComponentInfo OpYInfo(OpYDesc, OpXInfo, VOPD3);
1084 return VOPD::InstInfo(OpXInfo, OpYInfo);
1085}
1086
1088 StringRef FeatureString) {
1089 // In codegen the mode comes from module flags and FeatureString is empty, so
1090 // the processor defaults apply. The assembler has no target directive, so it
1091 // pins the mode via the +xnack/-xnack/+sramecc/-sramecc feature string.
1093 STI.getCPU(), FeatureString);
1094}
1095
1096namespace IsaInfo {
1097
1099 if (STI.getFeatureBits().test(FeatureInstCacheLineSize128))
1100 return 128;
1101 if (STI.getFeatureBits().test(FeatureInstCacheLineSize64))
1102 return 64;
1103 return 64;
1104}
1105
1106unsigned getWavefrontSize(const MCSubtargetInfo &STI) {
1107 if (STI.getFeatureBits().test(FeatureWavefrontSize16))
1108 return 16;
1109 if (STI.getFeatureBits().test(FeatureWavefrontSize32))
1110 return 32;
1111
1112 return 64;
1113}
1114
1115// Maximum LDS a single work-group can address. This is a fixed HW cap. It does
1116// not depend on how many SIMDs a work-group runs on.
1118 if (STI.getFeatureBits().test(FeatureAddressableLocalMemorySize32768))
1119 return 32768;
1120 if (STI.getFeatureBits().test(FeatureAddressableLocalMemorySize65536))
1121 return 65536;
1122 if (STI.getFeatureBits().test(FeatureAddressableLocalMemorySize163840))
1123 return 163840;
1124 if (STI.getFeatureBits().test(FeatureAddressableLocalMemorySize196608))
1125 return 196608;
1126 if (STI.getFeatureBits().test(FeatureAddressableLocalMemorySize327680))
1127 return 327680;
1128 return 32768;
1129}
1130
1131// Total physical size of LDS on the block, in bytes. On targets with
1132// FeatureHalfAddressablePhysicalLocalMemory the physical block is twice the
1133// addressable size (gfx6: 64 KiB physical and 32 KiB addressable;
1134// gfx10/11/12: 128 KiB physical and 64 KiB addressable). On other targets it is
1135// equal to the addressable size.
1136static unsigned getPhysicalLocalMemorySize(const MCSubtargetInfo &STI) {
1137 unsigned Addressable = getMaxHWAddressableLocalMemorySize(STI);
1138 if (STI.getFeatureBits().test(FeatureHalfAddressablePhysicalLocalMemory))
1139 return 2 * Addressable;
1140 return Addressable;
1141}
1142
1143// Sizes in use, by generation (addressable / physical block):
1144// gfx6 : 32 KiB addressable, 64 KiB physical block
1145// gfx7 / gfx8 / gfx9: 64 KiB
1146// gfx9.5 (gfx950) : 160 KiB
1147// gfx10 / 11 / 12 : 64 KiB addressable, 128 KiB physical block
1148// gfx12.5 (gfx1250) : 320 KiB (always runs on four SIMDs)
1149// gfx13 : 192 KiB on four SIMDs, 96 KiB on two
1150// Total available in the current mode. The physical size is halved when a
1151// work-group runs on two SIMDs.
1153 unsigned Size = getPhysicalLocalMemorySize(STI);
1154 if (!isFullSIMDMode(STI))
1155 Size /= 2;
1156 return Size;
1157}
1158
1159// What one work-group can allocate in the current mode. This is the HW
1160// addressable cap, but never more than the total available in the current mode.
1162 return std::min(getMaxHWAddressableLocalMemorySize(STI),
1163 getLocalMemorySize(STI));
1164}
1165
1167 unsigned FlatWorkGroupSize) {
1168 assert(FlatWorkGroupSize != 0);
1169 if (!STI.getTargetTriple().isAMDGCN())
1170 return 8;
1171 GPUKind Kind = parseArchAMDGCN(STI.getCPU());
1172 unsigned MaxWaves =
1174 unsigned N = getWavesPerWorkGroup(STI, FlatWorkGroupSize);
1175 if (N == 1) {
1176 // Single-wave workgroups don't consume barrier resources.
1177 return MaxWaves;
1178 }
1179
1180 unsigned MaxBarriers = 16;
1181 if (isGFX10Plus(STI) && !STI.getFeatureBits().test(FeatureCuMode))
1182 MaxBarriers = 32;
1183
1184 return std::min(MaxWaves / N, MaxBarriers);
1185}
1186
1188 unsigned FlatWorkGroupSize) {
1189 return divideCeil(getWavesPerWorkGroup(STI, FlatWorkGroupSize),
1191}
1192
1194 unsigned FlatWorkGroupSize) {
1195 return divideCeil(FlatWorkGroupSize, getWavefrontSize(STI));
1196}
1197
1198unsigned getSGPREncodingGranule(const MCSubtargetInfo &STI) { return 8; }
1199
1200// Per-wave SGPRs reserved for the trap handler when enabled.
1201static unsigned getSGPRTrapHandlerReserve(const MCSubtargetInfo &STI) {
1202 return STI.getFeatureBits().test(FeatureTrapHandler) ? TRAP_NUM_SGPRS : 0;
1203}
1204
1205// Per-wave SGPR budget (before the addressable clamp): take off the trap
1206// reserve, round down to \p Granule. Shared by getMinNumSGPRs() and
1207// getMaxNumSGPRs(); getOccupancyWithNumSGPRs() is the closed-form algebraic
1208// inverse of this same budget (it does not call this helper), so the two encode
1209// one model.
1210static unsigned getSGPRBudgetPerWave(unsigned TotalNumSGPRs,
1211 unsigned WavesPerEU, unsigned TrapReserve,
1212 unsigned Granule) {
1213 assert(WavesPerEU != 0 && Granule != 0);
1214 unsigned Budget = TotalNumSGPRs / WavesPerEU;
1215 Budget -= std::min(Budget, TrapReserve);
1216 return alignDown(Budget, Granule);
1217}
1218
1219unsigned getMinNumSGPRs(const MCSubtargetInfo &STI, unsigned WavesPerEU) {
1220 assert(WavesPerEU != 0);
1221
1223 if (Version.Major >= 10)
1224 return 0;
1225
1226 GPUKind Kind = parseArchAMDGCN(STI.getCPU());
1227 if (WavesPerEU >= getMaxWavesPerEU(Kind))
1228 return 0;
1229
1230 unsigned MinNumSGPRs =
1231 getSGPRBudgetPerWave(getTotalNumSGPRs(Kind), WavesPerEU + 1,
1233 getSGPRAllocGranule(Kind)) +
1234 1;
1235 return std::min(MinNumSGPRs, getAddressableNumSGPRs(Kind));
1236}
1237
1238unsigned getMaxNumSGPRs(const MCSubtargetInfo &STI, unsigned WavesPerEU,
1239 bool Addressable) {
1240 assert(WavesPerEU != 0);
1241
1242 GPUKind Kind = parseArchAMDGCN(STI.getCPU());
1243 unsigned AddressableNumSGPRs = getAddressableNumSGPRs(Kind);
1245 if (Version.Major >= 10)
1246 return Addressable ? AddressableNumSGPRs : 108;
1247 if (Version.Major >= 8 && !Addressable)
1248 AddressableNumSGPRs = 112;
1249 unsigned MaxNumSGPRs = getSGPRBudgetPerWave(
1250 getTotalNumSGPRs(Kind), WavesPerEU, getSGPRTrapHandlerReserve(STI),
1251 getSGPRAllocGranule(Kind));
1252 return std::min(MaxNumSGPRs, AddressableNumSGPRs);
1253}
1254
1256 // From GFX10 on the SGPR file is large enough that SGPRs never limit
1257 // occupancy. Kept as one capability so callers don't each test the version.
1258 return getIsaVersion(STI.getCPU()).Major < 10;
1259}
1260
1261unsigned getNumExtraSGPRs(const MCSubtargetInfo &STI, bool VCCUsed,
1262 bool FlatScrUsed, bool XNACKUsed) {
1263 unsigned ExtraSGPRs = 0;
1264 if (VCCUsed)
1265 ExtraSGPRs = 2;
1266
1268 if (Version.Major >= 10)
1269 return ExtraSGPRs;
1270
1271 if (Version.Major < 8) {
1272 if (FlatScrUsed)
1273 ExtraSGPRs = 4;
1274 } else {
1275 if (XNACKUsed)
1276 ExtraSGPRs = 4;
1277
1278 if (FlatScrUsed ||
1279 STI.getFeatureBits().test(AMDGPU::FeatureArchitectedFlatScratch))
1280 ExtraSGPRs = 6;
1281 }
1282
1283 return ExtraSGPRs;
1284}
1285
1286static unsigned getGranulatedNumRegisterBlocks(unsigned NumRegs,
1287 unsigned Granule) {
1288 return divideCeil(std::max(1u, NumRegs), Granule);
1289}
1290
1291unsigned getNumSGPRBlocks(const MCSubtargetInfo &STI, unsigned NumSGPRs) {
1292 // SGPRBlocks is actual number of SGPR blocks minus 1.
1294 1;
1295}
1296
1298 unsigned DynamicVGPRBlockSize,
1299 std::optional<bool> EnableWavefrontSize32) {
1300 if (STI.getFeatureBits().test(FeatureGFX90AInsts))
1301 return 8;
1302
1303 if (DynamicVGPRBlockSize != 0)
1304 return DynamicVGPRBlockSize;
1305
1306 bool IsWave32 = EnableWavefrontSize32
1307 ? *EnableWavefrontSize32
1308 : STI.getFeatureBits().test(FeatureWavefrontSize32);
1309
1310 if (STI.getFeatureBits().test(Feature1536VGPRs))
1311 return IsWave32 ? 24 : 12;
1312
1313 if (hasGFX10_3Insts(STI))
1314 return IsWave32 ? 16 : 8;
1315
1316 return IsWave32 ? 8 : 4;
1317}
1318
1320 std::optional<bool> EnableWavefrontSize32) {
1321 if (STI.getFeatureBits().test(FeatureGFX90AInsts))
1322 return 8;
1323
1324 bool IsWave32 = EnableWavefrontSize32
1325 ? *EnableWavefrontSize32
1326 : STI.getFeatureBits().test(FeatureWavefrontSize32);
1327
1328 if (STI.getFeatureBits().test(FeatureVGPRMSBs))
1329 return IsWave32 ? 16 : 8;
1330
1331 return IsWave32 ? 8 : 4;
1332}
1333
1334unsigned getArchVGPRAllocGranule() { return 4; }
1335
1337 const auto &Features = STI.getFeatureBits();
1338 if (Features.test(FeatureVGPRMSBs))
1339 return Features.test(FeatureWavefrontSize32) ? 1024 : 512;
1340 return 256;
1341}
1342
1344 unsigned DynamicVGPRBlockSize) {
1345 const auto &Features = STI.getFeatureBits();
1346 if (Features.test(FeatureGFX90AInsts))
1347 return 512;
1348
1349 if (DynamicVGPRBlockSize != 0) {
1350 // On GFX12 we can allocate at most MaxDynamicVGPRBlocks blocks of VGPRs.
1351 return MaxDynamicVGPRBlocks *
1352 getVGPRAllocGranule(STI, DynamicVGPRBlockSize);
1353 }
1354 return getAddressableNumArchVGPRs(STI);
1355}
1356
1358 unsigned NumVGPRs,
1359 unsigned DynamicVGPRBlockSize) {
1360 GPUKind Kind = parseArchAMDGCN(STI.getCPU());
1361 bool IsWave32 = STI.getFeatureBits().test(FeatureWavefrontSize32);
1363 NumVGPRs, getVGPRAllocGranule(STI, DynamicVGPRBlockSize),
1364 getMaxWavesPerEU(Kind), AMDGPU::getTotalNumVGPRs(Kind, IsWave32));
1365}
1366
1367unsigned getNumWavesPerEUWithNumVGPRs(unsigned NumVGPRs, unsigned Granule,
1368 unsigned MaxWaves,
1369 unsigned TotalNumVGPRs) {
1370 if (NumVGPRs < Granule)
1371 return MaxWaves;
1372 unsigned RoundedRegs = alignTo(NumVGPRs, Granule);
1373 return std::min(std::max(TotalNumVGPRs / RoundedRegs, 1u), MaxWaves);
1374}
1375
1376unsigned getOccupancyWithNumSGPRs(unsigned SGPRs, unsigned MaxWaves,
1377 unsigned TotalNumSGPRs, unsigned Granule,
1378 unsigned TrapReserve) {
1379 // Closed-form inverse of getMaxNumSGPRs(): the budget condition
1380 // SGPRs <= alignDown(TotalNumSGPRs / W - TrapReserve, Granule)
1381 // solves to W <= TotalNumSGPRs / (alignTo(SGPRs, Granule) + TrapReserve).
1382 unsigned PerWave = alignTo(SGPRs, Granule) + TrapReserve;
1383 return PerWave ? std::clamp(TotalNumSGPRs / PerWave, 1u, MaxWaves) : MaxWaves;
1384}
1385
1386unsigned getOccupancyWithNumSGPRs(const MCSubtargetInfo &STI, unsigned SGPRs) {
1387 GPUKind Kind = parseArchAMDGCN(STI.getCPU());
1388 unsigned MaxWaves = getMaxWavesPerEU(Kind);
1389
1390 if (!isSGPROccupancyLimited(STI))
1391 return MaxWaves;
1392
1393 return getOccupancyWithNumSGPRs(SGPRs, MaxWaves, getTotalNumSGPRs(Kind),
1394 getSGPRAllocGranule(Kind),
1396}
1397
1398unsigned getMinNumVGPRs(const MCSubtargetInfo &STI, unsigned WavesPerEU,
1399 unsigned DynamicVGPRBlockSize) {
1400 assert(WavesPerEU != 0);
1401
1402 // In dynamic VGPR mode, (static) occupancy does not depend on VGPR usage,
1403 // so getMaxNumVGPRs does not depend on WavesPerEU, and thus we need to return
1404 // zero because there is no nonzero VGPR usage N where going below N
1405 // achieves higher (static) occupancy.
1406 bool DynamicVGPREnabled = (DynamicVGPRBlockSize != 0);
1407 if (DynamicVGPREnabled)
1408 return 0;
1409
1410 GPUKind Kind = parseArchAMDGCN(STI.getCPU());
1411 unsigned MaxWavesPerEU = getMaxWavesPerEU(Kind);
1412 if (WavesPerEU >= MaxWavesPerEU)
1413 return 0;
1414
1415 unsigned TotNumVGPRs = AMDGPU::getTotalNumVGPRs(
1416 Kind, STI.getFeatureBits().test(FeatureWavefrontSize32));
1417 unsigned AddrsableNumVGPRs =
1418 getAddressableNumVGPRs(STI, DynamicVGPRBlockSize);
1419 unsigned Granule = getVGPRAllocGranule(STI, DynamicVGPRBlockSize);
1420 unsigned MaxNumVGPRs = alignDown(TotNumVGPRs / WavesPerEU, Granule);
1421
1422 if (MaxNumVGPRs == alignDown(TotNumVGPRs / MaxWavesPerEU, Granule))
1423 return 0;
1424
1425 unsigned MinWavesPerEU = getNumWavesPerEUWithNumVGPRs(STI, AddrsableNumVGPRs,
1426 DynamicVGPRBlockSize);
1427 if (WavesPerEU < MinWavesPerEU)
1428 return getMinNumVGPRs(STI, MinWavesPerEU, DynamicVGPRBlockSize);
1429
1430 unsigned MaxNumVGPRsNext = alignDown(TotNumVGPRs / (WavesPerEU + 1), Granule);
1431 unsigned MinNumVGPRs = 1 + std::min(MaxNumVGPRs - Granule, MaxNumVGPRsNext);
1432 return std::min(MinNumVGPRs, AddrsableNumVGPRs);
1433}
1434
1435unsigned getMaxNumVGPRs(const MCSubtargetInfo &STI, unsigned WavesPerEU,
1436 unsigned DynamicVGPRBlockSize) {
1437 assert(WavesPerEU != 0);
1438
1439 unsigned TotNumVGPRs = AMDGPU::getTotalNumVGPRs(
1440 parseArchAMDGCN(STI.getCPU()),
1441 STI.getFeatureBits().test(FeatureWavefrontSize32));
1442
1443 // In dynamic VGPR mode, WavesPerEU does not imply a VGPR limit.
1444 bool DynamicVGPREnabled = (DynamicVGPRBlockSize != 0);
1445 unsigned MaxNumVGPRs =
1446 DynamicVGPREnabled
1447 ? TotNumVGPRs
1448 : alignDown(TotNumVGPRs / WavesPerEU,
1449 getVGPRAllocGranule(STI, DynamicVGPRBlockSize));
1450 unsigned AddressableNumVGPRs =
1451 getAddressableNumVGPRs(STI, DynamicVGPRBlockSize);
1452 return std::min(MaxNumVGPRs, AddressableNumVGPRs);
1453}
1454
1456 unsigned NumVGPRs,
1457 unsigned DynamicVGPRBlockSize,
1458 std::optional<bool> EnableWavefrontSize32) {
1460 NumVGPRs,
1461 getVGPRAllocGranule(STI, DynamicVGPRBlockSize, EnableWavefrontSize32));
1462}
1463} // end namespace IsaInfo
1464
1466 const MCSubtargetInfo &STI) {
1468 KernelCode.amd_kernel_code_version_major = 1;
1469 KernelCode.amd_kernel_code_version_minor = 2;
1470 KernelCode.amd_machine_kind = 1; // AMD_MACHINE_KIND_AMDGPU
1471 KernelCode.amd_machine_version_major = Version.Major;
1472 KernelCode.amd_machine_version_minor = Version.Minor;
1473 KernelCode.amd_machine_version_stepping = Version.Stepping;
1475 if (STI.getFeatureBits().test(FeatureWavefrontSize32)) {
1476 KernelCode.wavefront_size = 5;
1478 } else {
1479 KernelCode.wavefront_size = 6;
1480 }
1481
1482 // If the code object does not support indirect functions, then the value must
1483 // be 0xffffffff.
1484 KernelCode.call_convention = -1;
1485
1486 // These alignment values are specified in powers of two, so alignment =
1487 // 2^n. The minimum alignment is 2^4 = 16.
1488 KernelCode.kernarg_segment_alignment = 4;
1489 KernelCode.group_segment_alignment = 4;
1490 KernelCode.private_segment_alignment = 4;
1491
1492 if (Version.Major >= 10) {
1493 KernelCode.compute_pgm_resource_registers |=
1494 S_00B848_WGP_MODE(STI.getFeatureBits().test(FeatureCuMode) ? 0 : 1) |
1496 }
1497}
1498
1500 unsigned AS = GV->getAddressSpace();
1501 return AS == AMDGPUAS::CONSTANT_ADDRESS ||
1503}
1504
1506 return TT.getArch() == Triple::r600;
1507}
1508
1509static bool isValidRegPrefix(char C) {
1510 return C == 'v' || C == 's' || C == 'a';
1511}
1512
1513std::tuple<char, unsigned, unsigned> parseAsmPhysRegName(StringRef RegName) {
1514 if (RegName.empty())
1515 return {};
1516
1517 char Kind = RegName.front();
1518 if (!isValidRegPrefix(Kind))
1519 return {};
1520
1521 RegName = RegName.drop_front();
1522 if (RegName.consume_front("[")) {
1523 unsigned Idx, End;
1524 bool Failed = RegName.consumeInteger(10, Idx);
1525 Failed |= !RegName.consume_front(":");
1526 Failed |= RegName.consumeInteger(10, End);
1527 Failed |= !RegName.consume_back("]");
1528 if (!Failed) {
1529 unsigned NumRegs = End - Idx + 1;
1530 if (NumRegs > 1)
1531 return {Kind, Idx, NumRegs};
1532 }
1533 } else {
1534 unsigned Idx;
1535 bool Failed = RegName.getAsInteger(10, Idx);
1536 if (!Failed)
1537 return {Kind, Idx, 1};
1538 }
1539
1540 return {};
1541}
1542
1543std::tuple<char, unsigned, unsigned>
1545 StringRef RegName = Constraint;
1546 if (!RegName.consume_front("{") || !RegName.consume_back("}"))
1547 return {};
1549}
1550
1551std::pair<unsigned, unsigned>
1553 std::pair<unsigned, unsigned> Default,
1554 bool OnlyFirstRequired) {
1555 if (auto Attr = getIntegerPairAttribute(F, Name, OnlyFirstRequired))
1556 return {Attr->first, Attr->second.value_or(Default.second)};
1557 return Default;
1558}
1559
1560std::optional<std::pair<unsigned, std::optional<unsigned>>>
1562 bool OnlyFirstRequired) {
1563 Attribute A = F.getFnAttribute(Name);
1564 if (!A.isStringAttribute())
1565 return std::nullopt;
1566
1567 LLVMContext &Ctx = F.getContext();
1568 std::pair<unsigned, std::optional<unsigned>> Ints;
1569 std::pair<StringRef, StringRef> Strs = A.getValueAsString().split(',');
1570 if (Strs.first.trim().getAsInteger(0, Ints.first)) {
1571 Ctx.emitError("can't parse first integer attribute " + Name);
1572 return std::nullopt;
1573 }
1574 unsigned Second = 0;
1575 if (Strs.second.trim().getAsInteger(0, Second)) {
1576 if (!OnlyFirstRequired || !Strs.second.trim().empty()) {
1577 Ctx.emitError("can't parse second integer attribute " + Name);
1578 return std::nullopt;
1579 }
1580 } else {
1581 Ints.second = Second;
1582 }
1583
1584 return Ints;
1585}
1586
1588 unsigned Size,
1589 unsigned DefaultVal) {
1590 std::optional<SmallVector<unsigned>> R =
1592 return R.has_value() ? *R : SmallVector<unsigned>(Size, DefaultVal);
1593}
1594
1595std::optional<SmallVector<unsigned>>
1597 assert(Size > 2);
1598 LLVMContext &Ctx = F.getContext();
1599
1600 Attribute A = F.getFnAttribute(Name);
1601 if (!A.isValid())
1602 return std::nullopt;
1603 if (!A.isStringAttribute()) {
1604 Ctx.emitError(Name + " is not a string attribute");
1605 return std::nullopt;
1606 }
1607
1609
1610 StringRef S = A.getValueAsString();
1611 unsigned i = 0;
1612 for (; !S.empty() && i < Size; i++) {
1613 std::pair<StringRef, StringRef> Strs = S.split(',');
1614 unsigned IntVal;
1615 if (Strs.first.trim().getAsInteger(0, IntVal)) {
1616 Ctx.emitError("can't parse integer attribute " + Strs.first + " in " +
1617 Name);
1618 return std::nullopt;
1619 }
1620 Vals[i] = IntVal;
1621 S = Strs.second;
1622 }
1623
1624 if (!S.empty() || i < Size) {
1625 Ctx.emitError("attribute " + Name +
1626 " has incorrect number of integers; expected " +
1628 return std::nullopt;
1629 }
1630 return Vals;
1631}
1632
1634 return getIntegerVecAttribute(F, "amdgpu-max-num-workgroups", 3,
1635 std::numeric_limits<uint32_t>::max());
1636}
1637
1638bool hasValueInRangeLikeMetadata(const MDNode &MD, int64_t Val) {
1639 assert((MD.getNumOperands() % 2 == 0) && "invalid number of operands!");
1640 for (unsigned I = 0, E = MD.getNumOperands() / 2; I != E; ++I) {
1641 auto Low =
1642 mdconst::extract<ConstantInt>(MD.getOperand(2 * I + 0))->getValue();
1643 auto High =
1644 mdconst::extract<ConstantInt>(MD.getOperand(2 * I + 1))->getValue();
1645 // There are two types of [A; B) ranges:
1646 // A < B, e.g. [4; 5) which is a range that only includes 4.
1647 // A > B, e.g. [5; 4) which is a range that wraps around and includes
1648 // everything except 4.
1649 if (Low.ult(High)) {
1650 if (Low.ule(Val) && High.ugt(Val))
1651 return true;
1652 } else {
1653 if (Low.uge(Val) && High.ult(Val))
1654 return true;
1655 }
1656 }
1657
1658 return false;
1659}
1660
1662 return (1 << (getVmcntBitWidthLo(Version.Major) +
1663 getVmcntBitWidthHi(Version.Major))) -
1664 1;
1665}
1666
1668 return (1 << getLoadcntBitWidth(Version.Major)) - 1;
1669}
1670
1672 return (1 << getSamplecntBitWidth(Version.Major)) - 1;
1673}
1674
1676 return (1 << getBvhcntBitWidth(Version.Major)) - 1;
1677}
1678
1680 return (1 << getExpcntBitWidth(Version.Major)) - 1;
1681}
1682
1684 return (1 << getLgkmcntBitWidth(Version.Major)) - 1;
1685}
1686
1688 return (1 << getDscntBitWidth(Version.Major)) - 1;
1689}
1690
1692 return (1 << getKmcntBitWidth(Version.Major)) - 1;
1693}
1694
1696 return (1 << getXcntBitWidth(Version.Major, Version.Minor)) - 1;
1697}
1698
1700 return (1 << getAsynccntBitWidth(Version.Major, Version.Minor)) - 1;
1701}
1702
1704 return (1 << getStorecntBitWidth(Version.Major)) - 1;
1705}
1706
1708 return (1 << getBarrierMemberCountBitWidth(Version.Major)) - 1;
1709}
1710
1712 unsigned VmcntLo = getBitMask(getVmcntBitShiftLo(Version.Major),
1713 getVmcntBitWidthLo(Version.Major));
1714 unsigned Expcnt = getBitMask(getExpcntBitShift(Version.Major),
1715 getExpcntBitWidth(Version.Major));
1716 unsigned Lgkmcnt = getBitMask(getLgkmcntBitShift(Version.Major),
1717 getLgkmcntBitWidth(Version.Major));
1718 unsigned VmcntHi = getBitMask(getVmcntBitShiftHi(Version.Major),
1719 getVmcntBitWidthHi(Version.Major));
1720 return VmcntLo | Expcnt | Lgkmcnt | VmcntHi;
1721}
1722
1723unsigned decodeVmcnt(const IsaVersion &Version, unsigned Waitcnt) {
1724 unsigned VmcntLo = unpackBits(Waitcnt, getVmcntBitShiftLo(Version.Major),
1725 getVmcntBitWidthLo(Version.Major));
1726 unsigned VmcntHi = unpackBits(Waitcnt, getVmcntBitShiftHi(Version.Major),
1727 getVmcntBitWidthHi(Version.Major));
1728 return VmcntLo | VmcntHi << getVmcntBitWidthLo(Version.Major);
1729}
1730
1731unsigned decodeExpcnt(const IsaVersion &Version, unsigned Waitcnt) {
1732 return unpackBits(Waitcnt, getExpcntBitShift(Version.Major),
1733 getExpcntBitWidth(Version.Major));
1734}
1735
1736unsigned decodeLgkmcnt(const IsaVersion &Version, unsigned Waitcnt) {
1737 return unpackBits(Waitcnt, getLgkmcntBitShift(Version.Major),
1738 getLgkmcntBitWidth(Version.Major));
1739}
1740
1741unsigned decodeLoadcnt(const IsaVersion &Version, unsigned Waitcnt) {
1742 return unpackBits(Waitcnt, getLoadcntStorecntBitShift(Version.Major),
1743 getLoadcntBitWidth(Version.Major));
1744}
1745
1746unsigned decodeStorecnt(const IsaVersion &Version, unsigned Waitcnt) {
1747 return unpackBits(Waitcnt, getLoadcntStorecntBitShift(Version.Major),
1748 getStorecntBitWidth(Version.Major));
1749}
1750
1751unsigned decodeDscnt(const IsaVersion &Version, unsigned Waitcnt) {
1752 return unpackBits(Waitcnt, getDscntBitShift(Version.Major),
1753 getDscntBitWidth(Version.Major));
1754}
1755
1756void decodeWaitcnt(const IsaVersion &Version, unsigned Waitcnt, unsigned &Vmcnt,
1757 unsigned &Expcnt, unsigned &Lgkmcnt) {
1758 Vmcnt = decodeVmcnt(Version, Waitcnt);
1759 Expcnt = decodeExpcnt(Version, Waitcnt);
1760 Lgkmcnt = decodeLgkmcnt(Version, Waitcnt);
1761}
1762
1763unsigned encodeVmcnt(const IsaVersion &Version, unsigned Waitcnt,
1764 unsigned Vmcnt) {
1765 Waitcnt = packBits(Vmcnt, Waitcnt, getVmcntBitShiftLo(Version.Major),
1766 getVmcntBitWidthLo(Version.Major));
1767 return packBits(Vmcnt >> getVmcntBitWidthLo(Version.Major), Waitcnt,
1768 getVmcntBitShiftHi(Version.Major),
1769 getVmcntBitWidthHi(Version.Major));
1770}
1771
1772unsigned encodeExpcnt(const IsaVersion &Version, unsigned Waitcnt,
1773 unsigned Expcnt) {
1774 return packBits(Expcnt, Waitcnt, getExpcntBitShift(Version.Major),
1775 getExpcntBitWidth(Version.Major));
1776}
1777
1778unsigned encodeLgkmcnt(const IsaVersion &Version, unsigned Waitcnt,
1779 unsigned Lgkmcnt) {
1780 return packBits(Lgkmcnt, Waitcnt, getLgkmcntBitShift(Version.Major),
1781 getLgkmcntBitWidth(Version.Major));
1782}
1783
1784unsigned encodeWaitcnt(const IsaVersion &Version, unsigned Vmcnt,
1785 unsigned Expcnt, unsigned Lgkmcnt) {
1786 unsigned Waitcnt = getWaitcntBitMask(Version);
1788 Waitcnt = encodeExpcnt(Version, Waitcnt, Expcnt);
1789 Waitcnt = encodeLgkmcnt(Version, Waitcnt, Lgkmcnt);
1790 return Waitcnt;
1791}
1792
1794 bool IsStore) {
1795 unsigned Dscnt = getBitMask(getDscntBitShift(Version.Major),
1796 getDscntBitWidth(Version.Major));
1797 if (IsStore) {
1798 unsigned Storecnt = getBitMask(getLoadcntStorecntBitShift(Version.Major),
1799 getStorecntBitWidth(Version.Major));
1800 return Dscnt | Storecnt;
1801 }
1802 unsigned Loadcnt = getBitMask(getLoadcntStorecntBitShift(Version.Major),
1803 getLoadcntBitWidth(Version.Major));
1804 return Dscnt | Loadcnt;
1805}
1806
1807static unsigned encodeLoadcnt(const IsaVersion &Version, unsigned Waitcnt,
1808 unsigned Loadcnt) {
1809 return packBits(Loadcnt, Waitcnt, getLoadcntStorecntBitShift(Version.Major),
1810 getLoadcntBitWidth(Version.Major));
1811}
1812
1813static unsigned encodeStorecnt(const IsaVersion &Version, unsigned Waitcnt,
1814 unsigned Storecnt) {
1815 return packBits(Storecnt, Waitcnt, getLoadcntStorecntBitShift(Version.Major),
1816 getStorecntBitWidth(Version.Major));
1817}
1818
1819static unsigned encodeDscnt(const IsaVersion &Version, unsigned Waitcnt,
1820 unsigned Dscnt) {
1821 return packBits(Dscnt, Waitcnt, getDscntBitShift(Version.Major),
1822 getDscntBitWidth(Version.Major));
1823}
1824
1825unsigned encodeLoadcntDscnt(const IsaVersion &Version, unsigned Loadcnt,
1826 unsigned Dscnt) {
1827 unsigned Waitcnt = getCombinedCountBitMask(Version, false);
1828 Waitcnt = encodeLoadcnt(Version, Waitcnt, Loadcnt);
1830 return Waitcnt;
1831}
1832
1833unsigned encodeStorecntDscnt(const IsaVersion &Version, unsigned Storecnt,
1834 unsigned Dscnt) {
1835 unsigned Waitcnt = getCombinedCountBitMask(Version, true);
1836 Waitcnt = encodeStorecnt(Version, Waitcnt, Storecnt);
1838 return Waitcnt;
1839}
1840
1841//===----------------------------------------------------------------------===//
1842// Custom Operand Values
1843//===----------------------------------------------------------------------===//
1844
1846 int Size, unsigned Code,
1847 bool &HasNonDefaultVal,
1848 const MCSubtargetInfo &STI) {
1849 unsigned UsedOprMask = 0;
1850 HasNonDefaultVal = false;
1851 for (int Idx = 0; Idx < Size; ++Idx) {
1852 const auto &Op = Opr[Idx];
1853 if (!Op.isSupported(STI))
1854 continue;
1855 UsedOprMask |= Op.getMask();
1856 unsigned Val = Op.decode(Code);
1857 if (!Op.isValid(Val))
1858 return false;
1859 HasNonDefaultVal |= (Val != Op.Default);
1860 }
1861 return (Code & ~UsedOprMask) == 0;
1862}
1863
1864static bool decodeCustomOperand(const CustomOperandVal *Opr, int Size,
1865 unsigned Code, int &Idx, StringRef &Name,
1866 unsigned &Val, bool &IsDefault,
1867 const MCSubtargetInfo &STI) {
1868 while (Idx < Size) {
1869 const auto &Op = Opr[Idx++];
1870 if (Op.isSupported(STI)) {
1871 Name = Op.Name;
1872 Val = Op.decode(Code);
1873 IsDefault = (Val == Op.Default);
1874 return true;
1875 }
1876 }
1877
1878 return false;
1879}
1880
1882 int64_t InputVal) {
1883 if (InputVal < 0 || InputVal > Op.Max)
1884 return OPR_VAL_INVALID;
1885 return Op.encode(static_cast<unsigned>(InputVal));
1886}
1887
1888static int encodeCustomOperand(const CustomOperandVal *Opr, int Size,
1889 const StringRef Name, int64_t InputVal,
1890 unsigned &UsedOprMask,
1891 const MCSubtargetInfo &STI) {
1892 int InvalidId = OPR_ID_UNKNOWN;
1893 for (int Idx = 0; Idx < Size; ++Idx) {
1894 const auto &Op = Opr[Idx];
1895 if (Op.Name == Name) {
1896 if (!Op.isSupported(STI)) {
1897 InvalidId = OPR_ID_UNSUPPORTED;
1898 continue;
1899 }
1900 auto OprMask = Op.getMask();
1901 if (OprMask & UsedOprMask)
1902 return OPR_ID_DUPLICATE;
1903 UsedOprMask |= OprMask;
1904 return encodeCustomOperandVal(Op, InputVal);
1905 }
1906 }
1907 return InvalidId;
1908}
1909
1910//===----------------------------------------------------------------------===//
1911// DepCtr
1912//===----------------------------------------------------------------------===//
1913
1914namespace DepCtr {
1915
1917 unsigned Enc = 0;
1918 for (int Idx = 0; Idx < DEP_CTR_SIZE; ++Idx) {
1919 const auto &Op = DepCtrInfo[Idx];
1920 if (Op.isSupported(STI))
1921 Enc |= Op.encode(Op.Default);
1922 }
1923 return Enc;
1924}
1925
1926bool isSymbolicDepCtrEncoding(unsigned Code, bool &HasNonDefaultVal,
1927 const MCSubtargetInfo &STI) {
1929 HasNonDefaultVal, STI);
1930}
1931
1932bool decodeDepCtr(unsigned Code, int &Id, StringRef &Name, unsigned &Val,
1933 bool &IsDefault, const MCSubtargetInfo &STI) {
1934 return decodeCustomOperand(DepCtrInfo, DEP_CTR_SIZE, Code, Id, Name, Val,
1935 IsDefault, STI);
1936}
1937
1938int encodeDepCtr(const StringRef Name, int64_t Val, unsigned &UsedOprMask,
1939 const MCSubtargetInfo &STI) {
1940 return encodeCustomOperand(DepCtrInfo, DEP_CTR_SIZE, Name, Val, UsedOprMask,
1941 STI);
1942}
1943
1944unsigned getVaVdstBitMask() { return (1 << getVaVdstBitWidth()) - 1; }
1945
1946unsigned getVaSdstBitMask() { return (1 << getVaSdstBitWidth()) - 1; }
1947
1948unsigned getVaSsrcBitMask() { return (1 << getVaSsrcBitWidth()) - 1; }
1949
1951 return (1 << getHoldCntWidth(Version.Major, Version.Minor)) - 1;
1952}
1953
1954unsigned getVmVsrcBitMask() { return (1 << getVmVsrcBitWidth()) - 1; }
1955
1956unsigned getVaVccBitMask() { return (1 << getVaVccBitWidth()) - 1; }
1957
1958unsigned getSaSdstBitMask() { return (1 << getSaSdstBitWidth()) - 1; }
1959
1960unsigned decodeFieldVmVsrc(unsigned Encoded) {
1961 return unpackBits(Encoded, getVmVsrcBitShift(), getVmVsrcBitWidth());
1962}
1963
1964unsigned decodeFieldVaVdst(unsigned Encoded) {
1965 return unpackBits(Encoded, getVaVdstBitShift(), getVaVdstBitWidth());
1966}
1967
1968unsigned decodeFieldSaSdst(unsigned Encoded) {
1969 return unpackBits(Encoded, getSaSdstBitShift(), getSaSdstBitWidth());
1970}
1971
1972unsigned decodeFieldVaSdst(unsigned Encoded) {
1973 return unpackBits(Encoded, getVaSdstBitShift(), getVaSdstBitWidth());
1974}
1975
1976unsigned decodeFieldVaVcc(unsigned Encoded) {
1977 return unpackBits(Encoded, getVaVccBitShift(), getVaVccBitWidth());
1978}
1979
1980unsigned decodeFieldVaSsrc(unsigned Encoded) {
1981 return unpackBits(Encoded, getVaSsrcBitShift(), getVaSsrcBitWidth());
1982}
1983
1984unsigned decodeFieldHoldCnt(unsigned Encoded, const IsaVersion &Version) {
1985 return unpackBits(Encoded, getHoldCntBitShift(),
1986 getHoldCntWidth(Version.Major, Version.Minor));
1987}
1988
1989unsigned encodeFieldVmVsrc(unsigned Encoded, unsigned VmVsrc) {
1990 return packBits(VmVsrc, Encoded, getVmVsrcBitShift(), getVmVsrcBitWidth());
1991}
1992
1993unsigned encodeFieldVmVsrc(unsigned VmVsrc, const MCSubtargetInfo &STI) {
1994 unsigned Encoded = getDefaultDepCtrEncoding(STI);
1995 return encodeFieldVmVsrc(Encoded, VmVsrc);
1996}
1997
1998unsigned encodeFieldVaVdst(unsigned Encoded, unsigned VaVdst) {
1999 return packBits(VaVdst, Encoded, getVaVdstBitShift(), getVaVdstBitWidth());
2000}
2001
2002unsigned encodeFieldVaVdst(unsigned VaVdst, const MCSubtargetInfo &STI) {
2003 unsigned Encoded = getDefaultDepCtrEncoding(STI);
2004 return encodeFieldVaVdst(Encoded, VaVdst);
2005}
2006
2007unsigned encodeFieldSaSdst(unsigned Encoded, unsigned SaSdst) {
2008 return packBits(SaSdst, Encoded, getSaSdstBitShift(), getSaSdstBitWidth());
2009}
2010
2011unsigned encodeFieldSaSdst(unsigned SaSdst, const MCSubtargetInfo &STI) {
2012 unsigned Encoded = getDefaultDepCtrEncoding(STI);
2013 return encodeFieldSaSdst(Encoded, SaSdst);
2014}
2015
2016unsigned encodeFieldVaSdst(unsigned Encoded, unsigned VaSdst) {
2017 return packBits(VaSdst, Encoded, getVaSdstBitShift(), getVaSdstBitWidth());
2018}
2019
2020unsigned encodeFieldVaSdst(unsigned VaSdst, const MCSubtargetInfo &STI) {
2021 unsigned Encoded = getDefaultDepCtrEncoding(STI);
2022 return encodeFieldVaSdst(Encoded, VaSdst);
2023}
2024
2025unsigned encodeFieldVaVcc(unsigned Encoded, unsigned VaVcc) {
2026 return packBits(VaVcc, Encoded, getVaVccBitShift(), getVaVccBitWidth());
2027}
2028
2029unsigned encodeFieldVaVcc(unsigned VaVcc, const MCSubtargetInfo &STI) {
2030 unsigned Encoded = getDefaultDepCtrEncoding(STI);
2031 return encodeFieldVaVcc(Encoded, VaVcc);
2032}
2033
2034unsigned encodeFieldVaSsrc(unsigned Encoded, unsigned VaSsrc) {
2035 return packBits(VaSsrc, Encoded, getVaSsrcBitShift(), getVaSsrcBitWidth());
2036}
2037
2038unsigned encodeFieldVaSsrc(unsigned VaSsrc, const MCSubtargetInfo &STI) {
2039 unsigned Encoded = getDefaultDepCtrEncoding(STI);
2040 return encodeFieldVaSsrc(Encoded, VaSsrc);
2041}
2042
2043unsigned encodeFieldHoldCnt(unsigned Encoded, unsigned HoldCnt,
2044 const IsaVersion &Version) {
2045 return packBits(HoldCnt, Encoded, getHoldCntBitShift(),
2046 getHoldCntWidth(Version.Major, Version.Minor));
2047}
2048
2049unsigned encodeFieldHoldCnt(unsigned HoldCnt, const MCSubtargetInfo &STI) {
2050 unsigned Encoded = getDefaultDepCtrEncoding(STI);
2051 return encodeFieldHoldCnt(Encoded, HoldCnt, getIsaVersion(STI.getCPU()));
2052}
2053
2054} // namespace DepCtr
2055
2056//===----------------------------------------------------------------------===//
2057// exp tgt
2058//===----------------------------------------------------------------------===//
2059
2060namespace Exp {
2061
2062struct ExpTgt {
2064 unsigned Tgt;
2065 unsigned MaxIndex;
2066};
2067
2068// clang-format off
2069static constexpr ExpTgt ExpTgtInfo[] = {
2070 {{"null"}, ET_NULL, ET_NULL_MAX_IDX},
2071 {{"mrtz"}, ET_MRTZ, ET_MRTZ_MAX_IDX},
2072 {{"prim"}, ET_PRIM, ET_PRIM_MAX_IDX},
2073 {{"mrt"}, ET_MRT0, ET_MRT_MAX_IDX},
2074 {{"pos"}, ET_POS0, ET_POS_MAX_IDX},
2075 {{"dual_src_blend"},ET_DUAL_SRC_BLEND0, ET_DUAL_SRC_BLEND_MAX_IDX},
2076 {{"param"}, ET_PARAM0, ET_PARAM_MAX_IDX},
2077};
2078// clang-format on
2079
2080bool getTgtName(unsigned Id, StringRef &Name, int &Index) {
2081 for (const ExpTgt &Val : ExpTgtInfo) {
2082 if (Val.Tgt <= Id && Id <= Val.Tgt + Val.MaxIndex) {
2083 Index = (Val.MaxIndex == 0) ? -1 : (Id - Val.Tgt);
2084 Name = Val.Name;
2085 return true;
2086 }
2087 }
2088 return false;
2089}
2090
2091unsigned getTgtId(const StringRef Name) {
2092
2093 for (const ExpTgt &Val : ExpTgtInfo) {
2094 if (Val.MaxIndex == 0 && Name == Val.Name)
2095 return Val.Tgt;
2096
2097 if (Val.MaxIndex > 0 && Name.starts_with(Val.Name)) {
2098 StringRef Suffix = Name.drop_front(Val.Name.size());
2099
2100 unsigned Id;
2101 if (Suffix.getAsInteger(10, Id) || Id > Val.MaxIndex)
2102 return ET_INVALID;
2103
2104 // Disable leading zeroes
2105 if (Suffix.size() > 1 && Suffix[0] == '0')
2106 return ET_INVALID;
2107
2108 return Val.Tgt + Id;
2109 }
2110 }
2111 return ET_INVALID;
2112}
2113
2114bool isSupportedTgtId(unsigned Id, const MCSubtargetInfo &STI) {
2115 switch (Id) {
2116 case ET_NULL:
2117 return !isGFX11Plus(STI);
2118 case ET_POS4:
2119 case ET_PRIM:
2120 return isGFX10Plus(STI);
2121 case ET_DUAL_SRC_BLEND0:
2122 case ET_DUAL_SRC_BLEND1:
2123 return isGFX11Plus(STI);
2124 default:
2125 if (Id >= ET_PARAM0 && Id <= ET_PARAM31)
2126 return !isGFX11Plus(STI) || isGFX13Plus(STI);
2127 return true;
2128 }
2129}
2130
2131} // namespace Exp
2132
2133//===----------------------------------------------------------------------===//
2134// MTBUF Format
2135//===----------------------------------------------------------------------===//
2136
2137namespace MTBUFFormat {
2138
2139int64_t getDfmt(const StringRef Name) {
2140 for (int Id = DFMT_MIN; Id <= DFMT_MAX; ++Id) {
2141 if (Name == DfmtSymbolic[Id])
2142 return Id;
2143 }
2144 return DFMT_UNDEF;
2145}
2146
2148 assert(Id <= DFMT_MAX);
2149 return DfmtSymbolic[Id];
2150}
2151
2153 if (isSI(STI) || isCI(STI))
2154 return NfmtSymbolicSICI;
2155 if (isVI(STI) || isGFX9(STI))
2156 return NfmtSymbolicVI;
2157 return NfmtSymbolicGFX10;
2158}
2159
2160int64_t getNfmt(const StringRef Name, const MCSubtargetInfo &STI) {
2161 const auto *lookupTable = getNfmtLookupTable(STI);
2162 for (int Id = NFMT_MIN; Id <= NFMT_MAX; ++Id) {
2163 if (Name == lookupTable[Id])
2164 return Id;
2165 }
2166 return NFMT_UNDEF;
2167}
2168
2169StringRef getNfmtName(unsigned Id, const MCSubtargetInfo &STI) {
2170 assert(Id <= NFMT_MAX);
2171 return getNfmtLookupTable(STI)[Id];
2172}
2173
2174bool isValidDfmtNfmt(unsigned Id, const MCSubtargetInfo &STI) {
2175 unsigned Dfmt;
2176 unsigned Nfmt;
2177 decodeDfmtNfmt(Id, Dfmt, Nfmt);
2178 return isValidNfmt(Nfmt, STI);
2179}
2180
2181bool isValidNfmt(unsigned Id, const MCSubtargetInfo &STI) {
2182 return !getNfmtName(Id, STI).empty();
2183}
2184
2185int64_t encodeDfmtNfmt(unsigned Dfmt, unsigned Nfmt) {
2186 return (Dfmt << DFMT_SHIFT) | (Nfmt << NFMT_SHIFT);
2187}
2188
2189void decodeDfmtNfmt(unsigned Format, unsigned &Dfmt, unsigned &Nfmt) {
2190 Dfmt = (Format >> DFMT_SHIFT) & DFMT_MASK;
2191 Nfmt = (Format >> NFMT_SHIFT) & NFMT_MASK;
2192}
2193
2194int64_t getUnifiedFormat(const StringRef Name, const MCSubtargetInfo &STI) {
2195 if (isGFX11Plus(STI)) {
2196 for (int Id = UfmtGFX11::UFMT_FIRST; Id <= UfmtGFX11::UFMT_LAST; ++Id) {
2197 if (Name == UfmtSymbolicGFX11[Id])
2198 return Id;
2199 }
2200 } else {
2201 for (int Id = UfmtGFX10::UFMT_FIRST; Id <= UfmtGFX10::UFMT_LAST; ++Id) {
2202 if (Name == UfmtSymbolicGFX10[Id])
2203 return Id;
2204 }
2205 }
2206 return UFMT_UNDEF;
2207}
2208
2210 if (isValidUnifiedFormat(Id, STI))
2211 return isGFX10(STI) ? UfmtSymbolicGFX10[Id] : UfmtSymbolicGFX11[Id];
2212 return "";
2213}
2214
2215bool isValidUnifiedFormat(unsigned Id, const MCSubtargetInfo &STI) {
2216 return isGFX10(STI) ? Id <= UfmtGFX10::UFMT_LAST : Id <= UfmtGFX11::UFMT_LAST;
2217}
2218
2219int64_t convertDfmtNfmt2Ufmt(unsigned Dfmt, unsigned Nfmt,
2220 const MCSubtargetInfo &STI) {
2221 int64_t Fmt = encodeDfmtNfmt(Dfmt, Nfmt);
2222 if (isGFX11Plus(STI)) {
2223 for (int Id = UfmtGFX11::UFMT_FIRST; Id <= UfmtGFX11::UFMT_LAST; ++Id) {
2224 if (Fmt == DfmtNfmt2UFmtGFX11[Id])
2225 return Id;
2226 }
2227 } else {
2228 for (int Id = UfmtGFX10::UFMT_FIRST; Id <= UfmtGFX10::UFMT_LAST; ++Id) {
2229 if (Fmt == DfmtNfmt2UFmtGFX10[Id])
2230 return Id;
2231 }
2232 }
2233 return UFMT_UNDEF;
2234}
2235
2236bool isValidFormatEncoding(unsigned Val, const MCSubtargetInfo &STI) {
2237 return isGFX10Plus(STI) ? (Val <= UFMT_MAX) : (Val <= DFMT_NFMT_MAX);
2238}
2239
2241 if (isGFX10Plus(STI))
2242 return UFMT_DEFAULT;
2243 return DFMT_NFMT_DEFAULT;
2244}
2245
2246} // namespace MTBUFFormat
2247
2248//===----------------------------------------------------------------------===//
2249// SendMsg
2250//===----------------------------------------------------------------------===//
2251
2252namespace SendMsg {
2253
2257
2258bool isValidMsgId(int64_t MsgId, const MCSubtargetInfo &STI) {
2259 return (MsgId & ~(getMsgIdMask(STI))) == 0;
2260}
2261
2262bool isValidMsgOp(int64_t MsgId, int64_t OpId, const MCSubtargetInfo &STI,
2263 bool Strict) {
2264 assert(isValidMsgId(MsgId, STI));
2265
2266 if (!Strict)
2267 return 0 <= OpId && isUInt<OP_WIDTH_>(OpId);
2268
2269 if (msgRequiresOp(MsgId, STI)) {
2270 if (MsgId == ID_GS_PreGFX11 && OpId == OP_GS_NOP)
2271 return false;
2272
2273 return !getMsgOpName(MsgId, OpId, STI).empty();
2274 }
2275
2276 return OpId == OP_NONE_;
2277}
2278
2279bool isValidMsgStream(int64_t MsgId, int64_t OpId, int64_t StreamId,
2280 const MCSubtargetInfo &STI, bool Strict) {
2281 assert(isValidMsgOp(MsgId, OpId, STI, Strict));
2282
2283 if (!Strict)
2285
2286 if (!isGFX11Plus(STI)) {
2287 switch (MsgId) {
2288 case ID_GS_PreGFX11:
2291 return (OpId == OP_GS_NOP)
2294 }
2295 }
2296 return StreamId == STREAM_ID_NONE_;
2297}
2298
2299bool msgRequiresOp(int64_t MsgId, const MCSubtargetInfo &STI) {
2300 return MsgId == ID_SYSMSG ||
2301 (!isGFX11Plus(STI) &&
2302 (MsgId == ID_GS_PreGFX11 || MsgId == ID_GS_DONE_PreGFX11));
2303}
2304
2305bool msgSupportsStream(int64_t MsgId, int64_t OpId,
2306 const MCSubtargetInfo &STI) {
2307 return !isGFX11Plus(STI) &&
2308 (MsgId == ID_GS_PreGFX11 || MsgId == ID_GS_DONE_PreGFX11) &&
2309 OpId != OP_GS_NOP;
2310}
2311
2312void decodeMsg(unsigned Val, uint16_t &MsgId, uint16_t &OpId,
2313 uint16_t &StreamId, const MCSubtargetInfo &STI) {
2314 MsgId = static_cast<uint16_t>(Val & getMsgIdMask(STI));
2315 if (isGFX11Plus(STI)) {
2316 OpId = 0;
2317 StreamId = 0;
2318 } else {
2319 OpId = (Val & OP_MASK_) >> OP_SHIFT_;
2321 }
2322}
2323
2325 return MsgId | (OpId << OP_SHIFT_) | (StreamId << STREAM_ID_SHIFT_);
2326}
2327
2328bool msgDoesNotUseM0(int64_t MsgId, const MCSubtargetInfo &STI) {
2329 // Explicitly list message types that are known to not use m0.
2330 // This is safer than excluding only GS_ALLOC_REQ, in case new message
2331 // types are added in the future that do use m0.
2332 if (isGFX11Plus(STI)) {
2333 switch (MsgId) {
2335 return true;
2336 default:
2337 break;
2338 }
2339 }
2340 switch (MsgId) {
2341 case ID_SAVEWAVE:
2342 case ID_STALL_WAVE_GEN:
2343 case ID_HALT_WAVES:
2344 case ID_ORDERED_PS_DONE:
2346 case ID_GET_DOORBELL:
2347 case ID_GET_DDID:
2348 case ID_SYSMSG:
2349 return true;
2350 default:
2351 return false;
2352 }
2353}
2354
2355} // namespace SendMsg
2356
2357//===----------------------------------------------------------------------===//
2358//
2359//===----------------------------------------------------------------------===//
2360
2362 return static_cast<unsigned>(
2363 F.getFnAttributeAsParsedInteger("InitialPSInputAddr", 0));
2364}
2365
2367 // As a safe default always respond as if PS has color exports.
2368 return F.getFnAttributeAsParsedInteger(
2369 "amdgpu-color-export",
2370 F.getCallingConv() == CallingConv::AMDGPU_PS ? 1 : 0) != 0;
2371}
2372
2374 return F.getFnAttributeAsParsedInteger("amdgpu-depth-export", 0) != 0;
2375}
2376
2378 unsigned BlockSize = static_cast<unsigned>(
2379 F.getFnAttributeAsParsedInteger("amdgpu-dynamic-vgpr-block-size", 0));
2380
2381 if (BlockSize == 16 || BlockSize == 32)
2382 return BlockSize;
2383
2384 return 0;
2385}
2386
2388 return STI.hasFeature(AMDGPU::FeatureMIMG_R128) &&
2389 !STI.hasFeature(AMDGPU::FeatureR128A16);
2390}
2391
2392bool hasA16(const MCSubtargetInfo &STI) {
2393 return STI.hasFeature(AMDGPU::FeatureA16);
2394}
2395
2396bool hasG16(const MCSubtargetInfo &STI) {
2397 return STI.hasFeature(AMDGPU::FeatureG16);
2398}
2399
2401 return !STI.hasFeature(AMDGPU::FeatureUnpackedD16VMem) && !isCI(STI) &&
2402 !isSI(STI);
2403}
2404
2405bool hasGDS(const MCSubtargetInfo &STI) {
2406 return STI.hasFeature(AMDGPU::FeatureGDS);
2407}
2408
2409unsigned getNSAMaxSize(const MCSubtargetInfo &STI, bool HasSampler) {
2410 auto Version = getIsaVersion(STI.getCPU());
2411 if (Version.Major == 10)
2412 return Version.Minor >= 3 ? 13 : 5;
2413 if (Version.Major == 11)
2414 return 5;
2415 if (Version.Major >= 12)
2416 return HasSampler ? 4 : 5;
2417 return 0;
2418}
2419
2421 if (isGFX1250Plus(STI))
2422 return 32;
2423 return 16;
2424}
2425
2426bool isSI(const MCSubtargetInfo &STI) {
2427 return STI.hasFeature(AMDGPU::FeatureSouthernIslands);
2428}
2429
2430bool isCI(const MCSubtargetInfo &STI) {
2431 return STI.hasFeature(AMDGPU::FeatureSeaIslands);
2432}
2433
2434bool isVI(const MCSubtargetInfo &STI) {
2435 return STI.hasFeature(AMDGPU::FeatureVolcanicIslands);
2436}
2437
2438bool isGFX9(const MCSubtargetInfo &STI) {
2439 return STI.hasFeature(AMDGPU::FeatureGFX9);
2440}
2441
2443 return isGFX9(STI) || isGFX10(STI);
2444}
2445
2447 return isGFX9(STI) || isGFX10(STI) || isGFX11(STI);
2448}
2449
2451 return isVI(STI) || isGFX9(STI) || isGFX10(STI);
2452}
2453
2454bool isGFX8Plus(const MCSubtargetInfo &STI) {
2455 return isVI(STI) || isGFX9Plus(STI);
2456}
2457
2458bool isGFX9Plus(const MCSubtargetInfo &STI) {
2459 return isGFX9(STI) || isGFX10Plus(STI);
2460}
2461
2462bool isNotGFX9Plus(const MCSubtargetInfo &STI) { return !isGFX9Plus(STI); }
2463
2465 return STI.hasFeature(AMDGPU::FeaturePopsExitingWaveID);
2466}
2467
2469 return STI.hasFeature(AMDGPU::FeatureApertureRegs) &&
2470 !STI.hasFeature(AMDGPU::FeatureGloballyAddressableScratch);
2471}
2472
2473bool isGFX10(const MCSubtargetInfo &STI) {
2474 return STI.hasFeature(AMDGPU::FeatureGFX10);
2475}
2476
2478 return isGFX10(STI) || isGFX11(STI);
2479}
2480
2482 return isGFX10(STI) || isGFX11Plus(STI);
2483}
2484
2485bool isGFX11(const MCSubtargetInfo &STI) {
2486 return STI.hasFeature(AMDGPU::FeatureGFX11);
2487}
2488
2490 return isGFX11(STI) || isGFX12Plus(STI);
2491}
2492
2493bool isGFX12(const MCSubtargetInfo &STI) {
2494 return STI.getFeatureBits()[AMDGPU::FeatureGFX12];
2495}
2496
2498 return isGFX12(STI) || isGFX13Plus(STI);
2499}
2500
2501bool isNotGFX12Plus(const MCSubtargetInfo &STI) { return !isGFX12Plus(STI); }
2502
2503bool isGFX1250(const MCSubtargetInfo &STI) {
2504 return STI.getFeatureBits()[AMDGPU::FeatureGFX1250Insts] && !isGFX13(STI);
2505}
2506
2508 return isGFX1250(STI) || !STI.getFeatureBits().test(FeatureCuMode);
2509}
2510
2512 return STI.getFeatureBits()[AMDGPU::FeatureGFX1250Insts];
2513}
2514
2515bool isGFX13(const MCSubtargetInfo &STI) {
2516 return STI.getFeatureBits()[AMDGPU::FeatureGFX13];
2517}
2518
2519bool isGFX13Plus(const MCSubtargetInfo &STI) { return isGFX13(STI); }
2520
2522 if (isGFX1250(STI))
2523 return false;
2524 return isGFX10Plus(STI);
2525}
2526
2527bool isNotGFX11Plus(const MCSubtargetInfo &STI) { return !isGFX11Plus(STI); }
2528
2530 return isSI(STI) || isCI(STI) || isVI(STI) || isGFX9(STI);
2531}
2532
2534 return isGFX10(STI) && !AMDGPU::isGFX10_BEncoding(STI);
2535}
2536
2538 return STI.hasFeature(AMDGPU::FeatureGCN3Encoding);
2539}
2540
2542 return STI.hasFeature(AMDGPU::FeatureGFX10_BEncoding);
2543}
2544
2546 return STI.hasFeature(AMDGPU::FeatureGFX10_3Insts);
2547}
2548
2550 return isGFX10_BEncoding(STI) && !isGFX12Plus(STI);
2551}
2552
2553bool isGFX90A(const MCSubtargetInfo &STI) {
2554 return STI.hasFeature(AMDGPU::FeatureGFX90AInsts);
2555}
2556
2557bool isGFX940(const MCSubtargetInfo &STI) {
2558 return STI.hasFeature(AMDGPU::FeatureGFX940Insts);
2559}
2560
2562 return STI.hasFeature(AMDGPU::FeatureArchitectedFlatScratch);
2563}
2564
2566 return STI.hasFeature(AMDGPU::FeatureMAIInsts);
2567}
2568
2569bool hasVOPD(const MCSubtargetInfo &STI) {
2570 return STI.hasFeature(AMDGPU::FeatureVOPDInsts);
2571}
2572
2574 return STI.hasFeature(AMDGPU::FeatureDPPSrc1SGPR);
2575}
2576
2578 return STI.hasFeature(AMDGPU::FeatureKernargPreload);
2579}
2580
2581int32_t getTotalNumVGPRs(bool has90AInsts, int32_t ArgNumAGPR,
2582 int32_t ArgNumVGPR) {
2583 if (has90AInsts && ArgNumAGPR)
2584 return alignTo(ArgNumVGPR, 4) + ArgNumAGPR;
2585 return std::max(ArgNumVGPR, ArgNumAGPR);
2586}
2587
2589 const MCRegisterClass &SGPRClass =
2590 TRI->getRegClass(AMDGPU::SReg_32RegClassID);
2591 const MCRegister FirstSubReg = TRI->getSubReg(Reg, AMDGPU::sub0);
2592 return SGPRClass.contains(FirstSubReg != 0 ? FirstSubReg : Reg) ||
2593 Reg == AMDGPU::SCC;
2594}
2595
2597 return MRI.getRegClass(AMDGPU::RsrcReg32RegClassID).contains(Reg);
2598}
2599
2601 return MRI.getEncodingValue(Reg) & AMDGPU::HWEncoding::IS_HI16;
2602}
2603
2604#define MAP_REG2REG \
2605 using namespace AMDGPU; \
2606 switch (Reg.id()) { \
2607 default: \
2608 return Reg; \
2609 CASE_CI_VI(FLAT_SCR) \
2610 CASE_CI_VI(FLAT_SCR_LO) \
2611 CASE_CI_VI(FLAT_SCR_HI) \
2612 CASE_VI_GFX9PLUS(TTMP0) \
2613 CASE_VI_GFX9PLUS(TTMP1) \
2614 CASE_VI_GFX9PLUS(TTMP2) \
2615 CASE_VI_GFX9PLUS(TTMP3) \
2616 CASE_VI_GFX9PLUS(TTMP4) \
2617 CASE_VI_GFX9PLUS(TTMP5) \
2618 CASE_VI_GFX9PLUS(TTMP6) \
2619 CASE_VI_GFX9PLUS(TTMP7) \
2620 CASE_VI_GFX9PLUS(TTMP8) \
2621 CASE_VI_GFX9PLUS(TTMP9) \
2622 CASE_VI_GFX9PLUS(TTMP10) \
2623 CASE_VI_GFX9PLUS(TTMP11) \
2624 CASE_VI_GFX9PLUS(TTMP12) \
2625 CASE_VI_GFX9PLUS(TTMP13) \
2626 CASE_VI_GFX9PLUS(TTMP14) \
2627 CASE_VI_GFX9PLUS(TTMP15) \
2628 CASE_VI_GFX9PLUS(TTMP0_TTMP1) \
2629 CASE_VI_GFX9PLUS(TTMP2_TTMP3) \
2630 CASE_VI_GFX9PLUS(TTMP4_TTMP5) \
2631 CASE_VI_GFX9PLUS(TTMP6_TTMP7) \
2632 CASE_VI_GFX9PLUS(TTMP8_TTMP9) \
2633 CASE_VI_GFX9PLUS(TTMP10_TTMP11) \
2634 CASE_VI_GFX9PLUS(TTMP12_TTMP13) \
2635 CASE_VI_GFX9PLUS(TTMP14_TTMP15) \
2636 CASE_VI_GFX9PLUS(TTMP0_TTMP1_TTMP2_TTMP3) \
2637 CASE_VI_GFX9PLUS(TTMP4_TTMP5_TTMP6_TTMP7) \
2638 CASE_VI_GFX9PLUS(TTMP8_TTMP9_TTMP10_TTMP11) \
2639 CASE_VI_GFX9PLUS(TTMP12_TTMP13_TTMP14_TTMP15) \
2640 CASE_VI_GFX9PLUS(TTMP0_TTMP1_TTMP2_TTMP3_TTMP4_TTMP5_TTMP6_TTMP7) \
2641 CASE_VI_GFX9PLUS(TTMP4_TTMP5_TTMP6_TTMP7_TTMP8_TTMP9_TTMP10_TTMP11) \
2642 CASE_VI_GFX9PLUS(TTMP8_TTMP9_TTMP10_TTMP11_TTMP12_TTMP13_TTMP14_TTMP15) \
2643 CASE_VI_GFX9PLUS( \
2644 TTMP0_TTMP1_TTMP2_TTMP3_TTMP4_TTMP5_TTMP6_TTMP7_TTMP8_TTMP9_TTMP10_TTMP11_TTMP12_TTMP13_TTMP14_TTMP15) \
2645 CASE_GFXPRE11_GFX11PLUS(M0) \
2646 CASE_GFXPRE11_GFX11PLUS(SGPR_NULL) \
2647 CASE_GFXPRE11_GFX11PLUS_TO(SGPR_NULL64, SGPR_NULL) \
2648 }
2649
2650#define CASE_CI_VI(node) \
2651 assert(!isSI(STI)); \
2652 case node: \
2653 return isCI(STI) ? node##_ci : node##_vi;
2654
2655#define CASE_VI_GFX9PLUS(node) \
2656 case node: \
2657 return isGFX9Plus(STI) ? node##_gfx9plus : node##_vi;
2658
2659#define CASE_GFXPRE11_GFX11PLUS(node) \
2660 case node: \
2661 return isGFX11Plus(STI) ? node##_gfx11plus : node##_gfxpre11;
2662
2663#define CASE_GFXPRE11_GFX11PLUS_TO(node, result) \
2664 case node: \
2665 return isGFX11Plus(STI) ? result##_gfx11plus : result##_gfxpre11;
2666
2668 if (STI.getTargetTriple().getArch() == Triple::r600)
2669 return Reg;
2671}
2672
2673#undef CASE_CI_VI
2674#undef CASE_VI_GFX9PLUS
2675#undef CASE_GFXPRE11_GFX11PLUS
2676#undef CASE_GFXPRE11_GFX11PLUS_TO
2677
2678#define CASE_CI_VI(node) \
2679 case node##_ci: \
2680 case node##_vi: \
2681 return node;
2682#define CASE_VI_GFX9PLUS(node) \
2683 case node##_vi: \
2684 case node##_gfx9plus: \
2685 return node;
2686#define CASE_GFXPRE11_GFX11PLUS(node) \
2687 case node##_gfx11plus: \
2688 case node##_gfxpre11: \
2689 return node;
2690#define CASE_GFXPRE11_GFX11PLUS_TO(node, result)
2691
2693
2695 switch (Reg.id()) {
2696 case AMDGPU::SRC_SHARED_BASE_LO:
2697 case AMDGPU::SRC_SHARED_BASE:
2698 case AMDGPU::SRC_SHARED_LIMIT_LO:
2699 case AMDGPU::SRC_SHARED_LIMIT:
2700 case AMDGPU::SRC_PRIVATE_BASE_LO:
2701 case AMDGPU::SRC_PRIVATE_BASE:
2702 case AMDGPU::SRC_PRIVATE_LIMIT_LO:
2703 case AMDGPU::SRC_PRIVATE_LIMIT:
2704 case AMDGPU::SRC_FLAT_SCRATCH_BASE_LO:
2705 case AMDGPU::SRC_FLAT_SCRATCH_BASE_HI:
2706 case AMDGPU::SRC_POPS_EXITING_WAVE_ID:
2707 return true;
2708 case AMDGPU::SRC_VCCZ:
2709 case AMDGPU::SRC_EXECZ:
2710 case AMDGPU::SRC_SCC:
2711 return true;
2712 case AMDGPU::SGPR_NULL:
2713 return true;
2714 default:
2715 return false;
2716 }
2717}
2718
2719#undef CASE_CI_VI
2720#undef CASE_VI_GFX9PLUS
2721#undef CASE_GFXPRE11_GFX11PLUS
2722#undef CASE_GFXPRE11_GFX11PLUS_TO
2723#undef MAP_REG2REG
2724
2725bool isKImmOperand(const MCInstrDesc &Desc, unsigned OpNo) {
2726 assert(OpNo < Desc.NumOperands);
2727 unsigned OpType = Desc.operands()[OpNo].OperandType;
2728 return OpType >= AMDGPU::OPERAND_KIMM_FIRST &&
2729 OpType <= AMDGPU::OPERAND_KIMM_LAST;
2730}
2731
2732bool isSISrcFPOperand(const MCInstrDesc &Desc, unsigned OpNo) {
2733 assert(OpNo < Desc.NumOperands);
2734 unsigned OpType = Desc.operands()[OpNo].OperandType;
2735 switch (OpType) {
2751 return true;
2752 default:
2753 return false;
2754 }
2755}
2756
2757// Avoid using MCRegisterClass::getSize, since that function will go away
2758// (move from MC* level to Target* level). Return size in bits.
2759unsigned getRegBitWidth(unsigned RCID) {
2760 switch (RCID) {
2761 case AMDGPU::VGPR_16RegClassID:
2762 case AMDGPU::VGPR_16_Lo128RegClassID:
2763 case AMDGPU::SGPR_LO16RegClassID:
2764 case AMDGPU::AGPR_LO16RegClassID:
2765 return 16;
2766 case AMDGPU::SGPR_32RegClassID:
2767 case AMDGPU::VGPR_32RegClassID:
2768 case AMDGPU::VGPR_32_Lo256RegClassID:
2769 case AMDGPU::VRegOrLds_32RegClassID:
2770 case AMDGPU::AGPR_32RegClassID:
2771 case AMDGPU::VS_32RegClassID:
2772 case AMDGPU::AV_32RegClassID:
2773 case AMDGPU::SReg_32RegClassID:
2774 case AMDGPU::SReg_32_XM0RegClassID:
2775 case AMDGPU::SRegOrLds_32RegClassID:
2776 return 32;
2777 case AMDGPU::SGPR_64RegClassID:
2778 case AMDGPU::VS_64RegClassID:
2779 case AMDGPU::SReg_64RegClassID:
2780 case AMDGPU::VReg_64RegClassID:
2781 case AMDGPU::AReg_64RegClassID:
2782 case AMDGPU::SReg_64_XEXECRegClassID:
2783 case AMDGPU::VReg_64_Align2RegClassID:
2784 case AMDGPU::AReg_64_Align2RegClassID:
2785 case AMDGPU::AV_64RegClassID:
2786 case AMDGPU::AV_64_Align2RegClassID:
2787 case AMDGPU::VReg_64_Lo256_Align2RegClassID:
2788 case AMDGPU::VS_64_Lo256RegClassID:
2789 return 64;
2790 case AMDGPU::SGPR_96RegClassID:
2791 case AMDGPU::SReg_96RegClassID:
2792 case AMDGPU::VReg_96RegClassID:
2793 case AMDGPU::AReg_96RegClassID:
2794 case AMDGPU::VReg_96_Align2RegClassID:
2795 case AMDGPU::AReg_96_Align2RegClassID:
2796 case AMDGPU::AV_96RegClassID:
2797 case AMDGPU::AV_96_Align2RegClassID:
2798 case AMDGPU::VReg_96_Lo256_Align2RegClassID:
2799 return 96;
2800 case AMDGPU::SGPR_128RegClassID:
2801 case AMDGPU::SReg_128RegClassID:
2802 case AMDGPU::VReg_128RegClassID:
2803 case AMDGPU::AReg_128RegClassID:
2804 case AMDGPU::VReg_128_Align2RegClassID:
2805 case AMDGPU::AReg_128_Align2RegClassID:
2806 case AMDGPU::AV_128RegClassID:
2807 case AMDGPU::AV_128_Align2RegClassID:
2808 case AMDGPU::SReg_128_XNULLRegClassID:
2809 case AMDGPU::VReg_128_Lo256_Align2RegClassID:
2810 return 128;
2811 case AMDGPU::SGPR_160RegClassID:
2812 case AMDGPU::SReg_160RegClassID:
2813 case AMDGPU::VReg_160RegClassID:
2814 case AMDGPU::AReg_160RegClassID:
2815 case AMDGPU::VReg_160_Align2RegClassID:
2816 case AMDGPU::AReg_160_Align2RegClassID:
2817 case AMDGPU::AV_160RegClassID:
2818 case AMDGPU::AV_160_Align2RegClassID:
2819 case AMDGPU::VReg_160_Lo256_Align2RegClassID:
2820 return 160;
2821 case AMDGPU::SGPR_192RegClassID:
2822 case AMDGPU::SReg_192RegClassID:
2823 case AMDGPU::VReg_192RegClassID:
2824 case AMDGPU::AReg_192RegClassID:
2825 case AMDGPU::VReg_192_Align2RegClassID:
2826 case AMDGPU::AReg_192_Align2RegClassID:
2827 case AMDGPU::AV_192RegClassID:
2828 case AMDGPU::AV_192_Align2RegClassID:
2829 case AMDGPU::VReg_192_Lo256_Align2RegClassID:
2830 return 192;
2831 case AMDGPU::SGPR_224RegClassID:
2832 case AMDGPU::SReg_224RegClassID:
2833 case AMDGPU::VReg_224RegClassID:
2834 case AMDGPU::AReg_224RegClassID:
2835 case AMDGPU::VReg_224_Align2RegClassID:
2836 case AMDGPU::AReg_224_Align2RegClassID:
2837 case AMDGPU::AV_224RegClassID:
2838 case AMDGPU::AV_224_Align2RegClassID:
2839 case AMDGPU::VReg_224_Lo256_Align2RegClassID:
2840 return 224;
2841 case AMDGPU::SGPR_256RegClassID:
2842 case AMDGPU::SReg_256RegClassID:
2843 case AMDGPU::VReg_256RegClassID:
2844 case AMDGPU::AReg_256RegClassID:
2845 case AMDGPU::VReg_256_Align2RegClassID:
2846 case AMDGPU::AReg_256_Align2RegClassID:
2847 case AMDGPU::AV_256RegClassID:
2848 case AMDGPU::AV_256_Align2RegClassID:
2849 case AMDGPU::SReg_256_XNULLRegClassID:
2850 case AMDGPU::VReg_256_Lo256_Align2RegClassID:
2851 return 256;
2852 case AMDGPU::SGPR_288RegClassID:
2853 case AMDGPU::SReg_288RegClassID:
2854 case AMDGPU::VReg_288RegClassID:
2855 case AMDGPU::AReg_288RegClassID:
2856 case AMDGPU::VReg_288_Align2RegClassID:
2857 case AMDGPU::AReg_288_Align2RegClassID:
2858 case AMDGPU::AV_288RegClassID:
2859 case AMDGPU::AV_288_Align2RegClassID:
2860 case AMDGPU::VReg_288_Lo256_Align2RegClassID:
2861 return 288;
2862 case AMDGPU::SGPR_320RegClassID:
2863 case AMDGPU::SReg_320RegClassID:
2864 case AMDGPU::VReg_320RegClassID:
2865 case AMDGPU::AReg_320RegClassID:
2866 case AMDGPU::VReg_320_Align2RegClassID:
2867 case AMDGPU::AReg_320_Align2RegClassID:
2868 case AMDGPU::AV_320RegClassID:
2869 case AMDGPU::AV_320_Align2RegClassID:
2870 case AMDGPU::VReg_320_Lo256_Align2RegClassID:
2871 return 320;
2872 case AMDGPU::SGPR_352RegClassID:
2873 case AMDGPU::SReg_352RegClassID:
2874 case AMDGPU::VReg_352RegClassID:
2875 case AMDGPU::AReg_352RegClassID:
2876 case AMDGPU::VReg_352_Align2RegClassID:
2877 case AMDGPU::AReg_352_Align2RegClassID:
2878 case AMDGPU::AV_352RegClassID:
2879 case AMDGPU::AV_352_Align2RegClassID:
2880 case AMDGPU::VReg_352_Lo256_Align2RegClassID:
2881 return 352;
2882 case AMDGPU::SGPR_384RegClassID:
2883 case AMDGPU::SReg_384RegClassID:
2884 case AMDGPU::VReg_384RegClassID:
2885 case AMDGPU::AReg_384RegClassID:
2886 case AMDGPU::VReg_384_Align2RegClassID:
2887 case AMDGPU::AReg_384_Align2RegClassID:
2888 case AMDGPU::AV_384RegClassID:
2889 case AMDGPU::AV_384_Align2RegClassID:
2890 case AMDGPU::VReg_384_Lo256_Align2RegClassID:
2891 return 384;
2892 case AMDGPU::SGPR_512RegClassID:
2893 case AMDGPU::SReg_512RegClassID:
2894 case AMDGPU::VReg_512RegClassID:
2895 case AMDGPU::AReg_512RegClassID:
2896 case AMDGPU::VReg_512_Align2RegClassID:
2897 case AMDGPU::AReg_512_Align2RegClassID:
2898 case AMDGPU::AV_512RegClassID:
2899 case AMDGPU::AV_512_Align2RegClassID:
2900 case AMDGPU::VReg_512_Lo256_Align2RegClassID:
2901 return 512;
2902 case AMDGPU::SGPR_1024RegClassID:
2903 case AMDGPU::SReg_1024RegClassID:
2904 case AMDGPU::VReg_1024RegClassID:
2905 case AMDGPU::AReg_1024RegClassID:
2906 case AMDGPU::VReg_1024_Align2RegClassID:
2907 case AMDGPU::AReg_1024_Align2RegClassID:
2908 case AMDGPU::AV_1024RegClassID:
2909 case AMDGPU::AV_1024_Align2RegClassID:
2910 case AMDGPU::VReg_1024_Lo256_Align2RegClassID:
2911 return 1024;
2912 default:
2913 llvm_unreachable("Unexpected register class");
2914 }
2915}
2916
2917unsigned getRegBitWidth(const MCRegisterClass &RC) {
2918 return getRegBitWidth(RC.getID());
2919}
2920
2921bool isInlinableLiteral64(int64_t Literal, bool HasInv2Pi) {
2923 return true;
2924
2925 uint64_t Val = static_cast<uint64_t>(Literal);
2926 return (Val == llvm::bit_cast<uint64_t>(0.0)) ||
2927 (Val == llvm::bit_cast<uint64_t>(1.0)) ||
2928 (Val == llvm::bit_cast<uint64_t>(-1.0)) ||
2929 (Val == llvm::bit_cast<uint64_t>(0.5)) ||
2930 (Val == llvm::bit_cast<uint64_t>(-0.5)) ||
2931 (Val == llvm::bit_cast<uint64_t>(2.0)) ||
2932 (Val == llvm::bit_cast<uint64_t>(-2.0)) ||
2933 (Val == llvm::bit_cast<uint64_t>(4.0)) ||
2934 (Val == llvm::bit_cast<uint64_t>(-4.0)) ||
2935 (Val == 0x3fc45f306dc9c882 && HasInv2Pi);
2936}
2937
2938bool isInlinableLiteral32(int32_t Literal, bool HasInv2Pi) {
2940 return true;
2941
2942 // The actual type of the operand does not seem to matter as long
2943 // as the bits match one of the inline immediate values. For example:
2944 //
2945 // -nan has the hexadecimal encoding of 0xfffffffe which is -2 in decimal,
2946 // so it is a legal inline immediate.
2947 //
2948 // 1065353216 has the hexadecimal encoding 0x3f800000 which is 1.0f in
2949 // floating-point, so it is a legal inline immediate.
2950
2951 uint32_t Val = static_cast<uint32_t>(Literal);
2952 return (Val == llvm::bit_cast<uint32_t>(0.0f)) ||
2953 (Val == llvm::bit_cast<uint32_t>(1.0f)) ||
2954 (Val == llvm::bit_cast<uint32_t>(-1.0f)) ||
2955 (Val == llvm::bit_cast<uint32_t>(0.5f)) ||
2956 (Val == llvm::bit_cast<uint32_t>(-0.5f)) ||
2957 (Val == llvm::bit_cast<uint32_t>(2.0f)) ||
2958 (Val == llvm::bit_cast<uint32_t>(-2.0f)) ||
2959 (Val == llvm::bit_cast<uint32_t>(4.0f)) ||
2960 (Val == llvm::bit_cast<uint32_t>(-4.0f)) ||
2961 (Val == 0x3e22f983 && HasInv2Pi);
2962}
2963
2964bool isInlinableLiteralBF16(int16_t Literal, bool HasInv2Pi, bool *IsBF16) {
2965 if (!HasInv2Pi)
2966 return false;
2967 if (IsBF16)
2968 *IsBF16 = false;
2970 return true;
2971 uint16_t Val = static_cast<uint16_t>(Literal);
2972 if (IsBF16)
2973 *IsBF16 = true;
2974 return Val == 0x3F00 || // 0.5
2975 Val == 0xBF00 || // -0.5
2976 Val == 0x3F80 || // 1.0
2977 Val == 0xBF80 || // -1.0
2978 Val == 0x4000 || // 2.0
2979 Val == 0xC000 || // -2.0
2980 Val == 0x4080 || // 4.0
2981 Val == 0xC080 || // -4.0
2982 Val == 0x3E22; // 1.0 / (2.0 * pi)
2983}
2984
2985bool isInlinableLiteralI16(int32_t Literal, bool HasInv2Pi) {
2986 return isInlinableLiteral32(Literal, HasInv2Pi);
2987}
2988
2989bool isInlinableLiteralFP16(int16_t Literal, bool HasInv2Pi) {
2990 if (!HasInv2Pi)
2991 return false;
2993 return true;
2994 uint16_t Val = static_cast<uint16_t>(Literal);
2995 return Val == 0x3C00 || // 1.0
2996 Val == 0xBC00 || // -1.0
2997 Val == 0x3800 || // 0.5
2998 Val == 0xB800 || // -0.5
2999 Val == 0x4000 || // 2.0
3000 Val == 0xC000 || // -2.0
3001 Val == 0x4400 || // 4.0
3002 Val == 0xC400 || // -4.0
3003 Val == 0x3118; // 1/2pi
3004}
3005
3006std::optional<unsigned> getInlineEncodingV216(bool IsFloat, uint32_t Literal) {
3007 // Unfortunately, the Instruction Set Architecture Reference Guide is
3008 // misleading about how the inline operands work for (packed) 16-bit
3009 // instructions. In a nutshell, the actual HW behavior is:
3010 //
3011 // - integer encodings (-16 .. 64) are always produced as sign-extended
3012 // 32-bit values
3013 // - float encodings are produced as:
3014 // - for F16 instructions: corresponding half-precision float values in
3015 // the LSBs, 0 in the MSBs
3016 // - for UI16 instructions: corresponding single-precision float value
3017 int32_t Signed = static_cast<int32_t>(Literal);
3018 if (Signed >= 0 && Signed <= 64)
3019 return 128 + Signed;
3020
3021 if (Signed >= -16 && Signed <= -1)
3022 return 192 + std::abs(Signed);
3023
3024 if (IsFloat) {
3025 // clang-format off
3026 switch (Literal) {
3027 case 0x3800: return 240; // 0.5
3028 case 0xB800: return 241; // -0.5
3029 case 0x3C00: return 242; // 1.0
3030 case 0xBC00: return 243; // -1.0
3031 case 0x4000: return 244; // 2.0
3032 case 0xC000: return 245; // -2.0
3033 case 0x4400: return 246; // 4.0
3034 case 0xC400: return 247; // -4.0
3035 case 0x3118: return 248; // 1.0 / (2.0 * pi)
3036 default: break;
3037 }
3038 // clang-format on
3039 } else {
3040 // clang-format off
3041 switch (Literal) {
3042 case 0x3F000000: return 240; // 0.5
3043 case 0xBF000000: return 241; // -0.5
3044 case 0x3F800000: return 242; // 1.0
3045 case 0xBF800000: return 243; // -1.0
3046 case 0x40000000: return 244; // 2.0
3047 case 0xC0000000: return 245; // -2.0
3048 case 0x40800000: return 246; // 4.0
3049 case 0xC0800000: return 247; // -4.0
3050 case 0x3E22F983: return 248; // 1.0 / (2.0 * pi)
3051 default: break;
3052 }
3053 // clang-format on
3054 }
3055
3056 return {};
3057}
3058
3059// Encoding of the literal as an inline constant for a V_PK_*_IU16 instruction
3060// or nullopt.
3061std::optional<unsigned> getInlineEncodingV2I16(uint32_t Literal) {
3062 return getInlineEncodingV216(false, Literal);
3063}
3064
3065// Encoding of the literal as an inline constant for a V_PK_*_BF16 instruction
3066// or nullopt.
3067std::optional<unsigned> getInlineEncodingV2BF16(uint32_t Literal) {
3068 int32_t Signed = static_cast<int32_t>(Literal);
3069 if (Signed >= 0 && Signed <= 64)
3070 return 128 + Signed;
3071
3072 if (Signed >= -16 && Signed <= -1)
3073 return 192 + std::abs(Signed);
3074
3075 // clang-format off
3076 switch (Literal) {
3077 case 0x3F00: return 240; // 0.5
3078 case 0xBF00: return 241; // -0.5
3079 case 0x3F80: return 242; // 1.0
3080 case 0xBF80: return 243; // -1.0
3081 case 0x4000: return 244; // 2.0
3082 case 0xC000: return 245; // -2.0
3083 case 0x4080: return 246; // 4.0
3084 case 0xC080: return 247; // -4.0
3085 case 0x3E22: return 248; // 1.0 / (2.0 * pi)
3086 default: break;
3087 }
3088 // clang-format on
3089
3090 return std::nullopt;
3091}
3092
3093// Encoding of the literal as an inline constant for a V_PK_*_F16 instruction
3094// or nullopt.
3095std::optional<unsigned> getInlineEncodingV2F16(uint32_t Literal) {
3096 return getInlineEncodingV216(true, Literal);
3097}
3098
3099// Encoding of the literal as an inline constant for V_PK_FMAC_F16 instruction
3100// or nullopt. This accounts for different inline constant behavior:
3101// - Pre-GFX11: fp16 inline constants have the value in low 16 bits, 0 in high
3102// - GFX11+: fp16 inline constants are duplicated into both halves
3104 bool IsGFX11Plus) {
3105 // Pre-GFX11 behavior: f16 in low bits, 0 in high bits
3106 if (!IsGFX11Plus)
3107 return getInlineEncodingV216(/*IsFloat=*/true, Literal);
3108
3109 // GFX11+ behavior: f16 duplicated in both halves
3110 // First, check for sign-extended integer inline constants (-16 to 64)
3111 // These work the same across all generations
3112 int32_t Signed = static_cast<int32_t>(Literal);
3113 if (Signed >= 0 && Signed <= 64)
3114 return 128 + Signed;
3115
3116 if (Signed >= -16 && Signed <= -1)
3117 return 192 + std::abs(Signed);
3118
3119 // For float inline constants on GFX11+, both halves must be equal
3120 uint16_t Lo = static_cast<uint16_t>(Literal);
3121 uint16_t Hi = static_cast<uint16_t>(Literal >> 16);
3122 if (Lo != Hi)
3123 return std::nullopt;
3124 return getInlineEncodingV216(/*IsFloat=*/true, Lo);
3125}
3126
3127// Whether the given literal can be inlined for a V_PK_* instruction.
3129 switch (OpType) {
3132 return getInlineEncodingV216(false, Literal).has_value();
3135 return getInlineEncodingV216(true, Literal).has_value();
3137 llvm_unreachable("OPERAND_REG_IMM_V2FP16_SPLAT is not supported");
3142 return false;
3143 default:
3144 llvm_unreachable("bad packed operand type");
3145 }
3146}
3147
3148// Whether the given literal can be inlined for a V_PK_*_IU16 instruction.
3152
3153// Whether the given literal can be inlined for a V_PK_*_BF16 instruction.
3157
3158// Whether the given literal can be inlined for a V_PK_*_F16 instruction.
3162
3163// Whether the given literal can be inlined for V_PK_FMAC_F16 instruction.
3165 return getPKFMACF16InlineEncoding(Literal, IsGFX11Plus).has_value();
3166}
3167
3168bool isValid32BitLiteral(uint64_t Val, bool IsFP64) {
3169 if (IsFP64)
3170 return !Lo_32(Val);
3171
3172 return isUInt<32>(Val) || isInt<32>(Val);
3173}
3174
3175int64_t encode32BitLiteral(int64_t Imm, OperandType Type, bool IsLit) {
3176 switch (Type) {
3177 default:
3178 break;
3184 return Imm & 0xffff;
3198 return Lo_32(Imm);
3201 return IsLit ? Imm : Hi_32(Imm);
3202 }
3203 return Imm;
3204}
3205
3207 const Function *F = A->getParent();
3208
3209 // Arguments to compute shaders are never a source of divergence.
3210 CallingConv::ID CC = F->getCallingConv();
3211 switch (CC) {
3214 return true;
3225 // For non-compute shaders, SGPR inputs are marked with either inreg or
3226 // byval. Everything else is in VGPRs.
3227 return A->hasAttribute(Attribute::InReg) ||
3228 A->hasAttribute(Attribute::ByVal);
3229 default:
3230 // TODO: treat i1 as divergent?
3231 return A->hasAttribute(Attribute::InReg);
3232 }
3233}
3234
3235bool isArgPassedInSGPR(const CallBase *CB, unsigned ArgNo) {
3236 // Arguments to compute shaders are never a source of divergence.
3238 switch (CC) {
3241 return true;
3252 // For non-compute shaders, SGPR inputs are marked with either inreg or
3253 // byval. Everything else is in VGPRs.
3254 return CB->paramHasAttr(ArgNo, Attribute::InReg) ||
3255 CB->isByValArgument(ArgNo);
3256 default:
3257 return CB->paramHasAttr(ArgNo, Attribute::InReg);
3258 }
3259}
3260
3261static bool hasSMEMByteOffset(const MCSubtargetInfo &ST) {
3262 return isGCN3Encoding(ST) || isGFX10Plus(ST);
3263}
3264
3266 int64_t EncodedOffset) {
3267 if (isGFX12Plus(ST))
3268 return isUInt<23>(EncodedOffset);
3269
3270 return hasSMEMByteOffset(ST) ? isUInt<20>(EncodedOffset)
3271 : isUInt<8>(EncodedOffset);
3272}
3273
3275 int64_t EncodedOffset, bool IsBuffer) {
3276 if (isGFX12Plus(ST)) {
3277 if (IsBuffer && EncodedOffset < 0)
3278 return false;
3279 return isInt<24>(EncodedOffset);
3280 }
3281
3282 return !IsBuffer && hasSMRDSignedImmOffset(ST) && isInt<21>(EncodedOffset);
3283}
3284
3285static bool isDwordAligned(uint64_t ByteOffset) {
3286 return (ByteOffset & 3) == 0;
3287}
3288
3290 uint64_t ByteOffset) {
3291 if (hasSMEMByteOffset(ST))
3292 return ByteOffset;
3293
3294 assert(isDwordAligned(ByteOffset));
3295 return ByteOffset >> 2;
3296}
3297
3298std::optional<int64_t> getSMRDEncodedOffset(const MCSubtargetInfo &ST,
3299 int64_t ByteOffset, bool IsBuffer,
3300 bool HasSOffset) {
3301 // For unbuffered smem loads, it is illegal for the Immediate Offset to be
3302 // negative if the resulting (Offset + (M0 or SOffset or zero) is negative.
3303 // Handle case where SOffset is not present.
3304 if (!IsBuffer && !HasSOffset && ByteOffset < 0 && hasSMRDSignedImmOffset(ST))
3305 return std::nullopt;
3306
3307 if (isGFX12Plus(ST)) // 24 bit signed offsets
3308 return isInt<24>(ByteOffset) ? std::optional<int64_t>(ByteOffset)
3309 : std::nullopt;
3310
3311 // The signed version is always a byte offset.
3312 if (!IsBuffer && hasSMRDSignedImmOffset(ST)) {
3314 return isInt<20>(ByteOffset) ? std::optional<int64_t>(ByteOffset)
3315 : std::nullopt;
3316 }
3317
3318 if (!isDwordAligned(ByteOffset) && !hasSMEMByteOffset(ST))
3319 return std::nullopt;
3320
3321 int64_t EncodedOffset = convertSMRDOffsetUnits(ST, ByteOffset);
3322 return isLegalSMRDEncodedUnsignedOffset(ST, EncodedOffset)
3323 ? std::optional<int64_t>(EncodedOffset)
3324 : std::nullopt;
3325}
3326
3327std::optional<int64_t> getSMRDEncodedLiteralOffset32(const MCSubtargetInfo &ST,
3328 int64_t ByteOffset) {
3329 if (!isCI(ST) || !isDwordAligned(ByteOffset))
3330 return std::nullopt;
3331
3332 int64_t EncodedOffset = convertSMRDOffsetUnits(ST, ByteOffset);
3333 return isUInt<32>(EncodedOffset) ? std::optional<int64_t>(EncodedOffset)
3334 : std::nullopt;
3335}
3336
3338 if (ST.getFeatureBits().test(FeatureFlatOffsetBits12))
3339 return 12;
3340 if (ST.getFeatureBits().test(FeatureFlatOffsetBits24))
3341 return 24;
3342 return 13;
3343}
3344
3345namespace {
3346
3347struct SourceOfDivergence {
3348 unsigned Intr;
3349};
3350const SourceOfDivergence *lookupSourceOfDivergence(unsigned Intr);
3351
3352struct AlwaysUniform {
3353 unsigned Intr;
3354};
3355const AlwaysUniform *lookupAlwaysUniform(unsigned Intr);
3356
3357struct LDSDMAIntrinsic {
3358 unsigned Intr;
3359};
3360const LDSDMAIntrinsic *lookupLDSDMAIntrinsic(unsigned Intr);
3361
3362struct ExponentOnlyScaleIntrinsic {
3363 unsigned Intr;
3364 uint8_t ScaleArg;
3365};
3366const ExponentOnlyScaleIntrinsic *
3367lookupExponentOnlyScaleIntrinsic(unsigned Intr);
3368
3369#define GET_SourcesOfDivergence_IMPL
3370#define GET_UniformIntrinsics_IMPL
3371#define GET_LDSDMAIntrinsicTable_IMPL
3372#define GET_ExponentOnlyScaleIntrinsics_IMPL
3373#define GET_Gfx9BufferFormat_IMPL
3374#define GET_Gfx10BufferFormat_IMPL
3375#define GET_Gfx11PlusBufferFormat_IMPL
3376
3377#include "AMDGPUGenSearchableTables.inc"
3378
3379} // end anonymous namespace
3380
3381bool isIntrinsicSourceOfDivergence(unsigned IntrID) {
3382 return lookupSourceOfDivergence(IntrID);
3383}
3384
3385bool isIntrinsicAlwaysUniform(unsigned IntrID) {
3386 return lookupAlwaysUniform(IntrID);
3387}
3388
3389bool isTriviallyUniform(const Value *V, const Instruction *CtxI) {
3390 if (isa<Constant>(V))
3391 return true;
3392 if (const auto *A = dyn_cast<Argument>(V))
3393 return isArgPassedInSGPR(A);
3394 if (const auto *II = dyn_cast<IntrinsicInst>(V)) {
3395 if (!isIntrinsicAlwaysUniform(II->getIntrinsicID()))
3396 return false;
3397 // If II and CtxI are in different blocks then there is a possibility of a
3398 // temporal divergence.
3399 return II->getParent() == CtxI->getParent();
3400 }
3401 return false;
3402}
3403
3404bool isTriviallyUniform(const Use &U) {
3405 return isTriviallyUniform(U.get(), cast<Instruction>(U.getUser()));
3406}
3407
3408bool isLDSDMAIntrinsic(unsigned IntrID) {
3409 return lookupLDSDMAIntrinsic(IntrID);
3410}
3411
3412std::optional<unsigned> getExponentOnlyScaleArgIdx(unsigned IntrID) {
3413 if (const ExponentOnlyScaleIntrinsic *Info =
3414 lookupExponentOnlyScaleIntrinsic(IntrID))
3415 return Info->ScaleArg;
3416 return std::nullopt;
3417}
3418
3420 uint8_t NumComponents,
3421 uint8_t NumFormat,
3422 const MCSubtargetInfo &STI) {
3423 return isGFX11Plus(STI) ? getGfx11PlusBufferFormatInfo(
3424 BitsPerComp, NumComponents, NumFormat)
3425 : isGFX10(STI)
3426 ? getGfx10BufferFormatInfo(BitsPerComp, NumComponents, NumFormat)
3427 : getGfx9BufferFormatInfo(BitsPerComp, NumComponents, NumFormat);
3428}
3429
3431 const MCSubtargetInfo &STI) {
3432 return isGFX11Plus(STI) ? getGfx11PlusBufferFormatInfo(Format)
3433 : isGFX10(STI) ? getGfx10BufferFormatInfo(Format)
3434 : getGfx9BufferFormatInfo(Format);
3435}
3436
3438 const MCRegisterInfo &MRI) {
3439 const unsigned VGPRClasses[] = {
3440 AMDGPU::VGPR_16RegClassID, AMDGPU::VGPR_32RegClassID,
3441 AMDGPU::VReg_64RegClassID, AMDGPU::VReg_96RegClassID,
3442 AMDGPU::VReg_128RegClassID, AMDGPU::VReg_160RegClassID,
3443 AMDGPU::VReg_192RegClassID, AMDGPU::VReg_224RegClassID,
3444 AMDGPU::VReg_256RegClassID, AMDGPU::VReg_288RegClassID,
3445 AMDGPU::VReg_320RegClassID, AMDGPU::VReg_352RegClassID,
3446 AMDGPU::VReg_384RegClassID, AMDGPU::VReg_512RegClassID,
3447 AMDGPU::VReg_1024RegClassID};
3448
3449 for (unsigned RCID : VGPRClasses) {
3450 const MCRegisterClass &RC = MRI.getRegClass(RCID);
3451 if (RC.contains(Reg))
3452 return &RC;
3453 }
3454
3455 return nullptr;
3456}
3457
3459 unsigned Enc = MRI.getEncodingValue(Reg);
3460 unsigned Idx = Enc & AMDGPU::HWEncoding::REG_IDX_MASK;
3461 return Idx >> 8;
3462}
3463
3465 const MCRegisterInfo &MRI) {
3466 unsigned Enc = MRI.getEncodingValue(Reg);
3467 unsigned Idx = Enc & AMDGPU::HWEncoding::REG_IDX_MASK;
3468 if (Idx >= 0x100)
3469 return MCRegister();
3470
3472 if (!RC)
3473 return MCRegister();
3474
3475 Idx |= MSBs << 8;
3476 if (RC->getID() == AMDGPU::VGPR_16RegClassID) {
3477 // This class has 2048 registers with interleaved lo16 and hi16.
3478 Idx *= 2;
3480 ++Idx;
3481 }
3482
3483 return RC->getRegister(Idx);
3484}
3485
3486static std::optional<unsigned>
3488 bool HasSetregVGPRMSBFixup) {
3489 constexpr unsigned VGPRMSBShift =
3491
3492 auto [HwRegId, Offset, Size] = Hwreg::HwregEncoding::decode(Simm16);
3493 if (HwRegId != Hwreg::ID_MODE ||
3494 (!HasSetregVGPRMSBFixup && (Offset + Size) < VGPRMSBShift))
3495 return {};
3496 // If there is SetregVGPRMSBFixup then Offset is ignored.
3497 if (!HasSetregVGPRMSBFixup)
3498 Imm <<= Offset;
3499 Imm = (Imm & Hwreg::VGPR_MSB_MASK) >> VGPRMSBShift;
3500 if (!HasSetregVGPRMSBFixup)
3502 return llvm::rotr<uint8_t>(static_cast<uint8_t>(Imm), /*R=*/2);
3503}
3504
3505std::optional<unsigned> convertSetRegImmToVgprMSBs(const MachineInstr &MI,
3506 bool HasSetregVGPRMSBFixup) {
3507 assert(MI.getOpcode() == AMDGPU::S_SETREG_IMM32_B32);
3508 return convertSetRegImmToVgprMSBs(MI.getOperand(0).getImm(),
3509 MI.getOperand(1).getImm(),
3510 HasSetregVGPRMSBFixup);
3511}
3512
3513std::optional<unsigned> convertSetRegImmToVgprMSBs(const MCInst &MI,
3514 bool HasSetregVGPRMSBFixup) {
3515 assert(MI.getOpcode() == AMDGPU::S_SETREG_IMM32_B32_gfx12);
3516 return convertSetRegImmToVgprMSBs(MI.getOperand(0).getImm(),
3517 MI.getOperand(1).getImm(),
3518 HasSetregVGPRMSBFixup);
3519}
3520
3521std::pair<const AMDGPU::OpName *, const AMDGPU::OpName *>
3523 static const AMDGPU::OpName VOPOps[4] = {
3524 AMDGPU::OpName::src0, AMDGPU::OpName::src1, AMDGPU::OpName::src2,
3525 AMDGPU::OpName::vdst};
3526 static const AMDGPU::OpName VDSOps[4] = {
3527 AMDGPU::OpName::addr, AMDGPU::OpName::data0, AMDGPU::OpName::data1,
3528 AMDGPU::OpName::vdst};
3529 static const AMDGPU::OpName FLATOps[4] = {
3530 AMDGPU::OpName::vaddr, AMDGPU::OpName::vdata,
3531 AMDGPU::OpName::NUM_OPERAND_NAMES, AMDGPU::OpName::vdst};
3532 static const AMDGPU::OpName BUFOps[4] = {
3533 AMDGPU::OpName::vaddr, AMDGPU::OpName::NUM_OPERAND_NAMES,
3534 AMDGPU::OpName::NUM_OPERAND_NAMES, AMDGPU::OpName::vdata};
3535 static const AMDGPU::OpName VIMGOps[4] = {
3536 AMDGPU::OpName::vaddr0, AMDGPU::OpName::vaddr1, AMDGPU::OpName::vaddr2,
3537 AMDGPU::OpName::vdata};
3538
3539 // For VOPD instructions MSB of a corresponding Y component operand VGPR
3540 // address is supposed to match X operand, otherwise VOPD shall not be
3541 // combined.
3542 static const AMDGPU::OpName VOPDOpsX[4] = {
3543 AMDGPU::OpName::src0X, AMDGPU::OpName::vsrc1X, AMDGPU::OpName::vsrc2X,
3544 AMDGPU::OpName::vdstX};
3545 static const AMDGPU::OpName VOPDOpsY[4] = {
3546 AMDGPU::OpName::src0Y, AMDGPU::OpName::vsrc1Y, AMDGPU::OpName::vsrc2Y,
3547 AMDGPU::OpName::vdstY};
3548
3549 // VOP2 MADMK instructions use src0, imm, src1 scheme.
3550 static const AMDGPU::OpName VOP2MADMKOps[4] = {
3551 AMDGPU::OpName::src0, AMDGPU::OpName::NUM_OPERAND_NAMES,
3552 AMDGPU::OpName::src1, AMDGPU::OpName::vdst};
3553 static const AMDGPU::OpName VOPDFMAMKOpsX[4] = {
3554 AMDGPU::OpName::src0X, AMDGPU::OpName::NUM_OPERAND_NAMES,
3555 AMDGPU::OpName::vsrc1X, AMDGPU::OpName::vdstX};
3556 static const AMDGPU::OpName VOPDFMAMKOpsY[4] = {
3557 AMDGPU::OpName::src0Y, AMDGPU::OpName::NUM_OPERAND_NAMES,
3558 AMDGPU::OpName::vsrc1Y, AMDGPU::OpName::vdstY};
3559
3563 switch (Desc.getOpcode()) {
3564 // LD_SCALE operands ignore MSB.
3565 case AMDGPU::V_WMMA_LD_SCALE_PAIRED_B32:
3566 case AMDGPU::V_WMMA_LD_SCALE_PAIRED_B32_gfx1250:
3567 case AMDGPU::V_WMMA_LD_SCALE16_PAIRED_B64:
3568 case AMDGPU::V_WMMA_LD_SCALE16_PAIRED_B64_gfx1250:
3569 return {};
3570 case AMDGPU::V_FMAMK_F16:
3571 case AMDGPU::V_FMAMK_F16_t16:
3572 case AMDGPU::V_FMAMK_F16_t16_gfx12:
3573 case AMDGPU::V_FMAMK_F16_fake16:
3574 case AMDGPU::V_FMAMK_F16_fake16_gfx12:
3575 case AMDGPU::V_FMAMK_F32:
3576 case AMDGPU::V_FMAMK_F32_gfx12:
3577 case AMDGPU::V_FMAMK_F64:
3578 case AMDGPU::V_FMAMK_F64_gfx1250:
3579 return {VOP2MADMKOps, nullptr};
3580 default:
3581 break;
3582 }
3583 return {VOPOps, nullptr};
3584 }
3585
3587 return {VDSOps, nullptr};
3588
3590 return {FLATOps, nullptr};
3591
3593 return {BUFOps, nullptr};
3594
3596 return {VIMGOps, nullptr};
3597
3598 if (AMDGPU::isVOPD(Desc.getOpcode())) {
3599 auto [OpX, OpY] = getVOPDComponents(Desc.getOpcode());
3600 return {(OpX == AMDGPU::V_FMAMK_F32) ? VOPDFMAMKOpsX : VOPDOpsX,
3601 (OpY == AMDGPU::V_FMAMK_F32) ? VOPDFMAMKOpsY : VOPDOpsY};
3602 }
3603
3605
3607 llvm_unreachable("Sample and export VGPR lowering is not implemented and"
3608 " these instructions are not expected on gfx1250");
3609
3610 return {};
3611}
3612
3613bool supportsScaleOffset(const MCInstrInfo &MII, unsigned Opcode) {
3614 const MCInstrDesc &Desc = MII.get(Opcode);
3616 return Desc.mayLoad() && !Desc.mayStore() && !getSMEMIsBuffer(Opcode);
3618 return false;
3619
3620 // Only SV and SVS modes are supported.
3621 if (SIInstrFlags::isFlatScratch(MII, Opcode))
3622 return hasNamedOperand(Opcode, OpName::vaddr);
3623
3624 // Only GVS mode is supported.
3625 return hasNamedOperand(Opcode, OpName::vaddr) &&
3626 hasNamedOperand(Opcode, OpName::saddr);
3627
3628 return false;
3629}
3630
3631static bool hasAny64BitVGPROperands(const MCInstrDesc &OpDesc,
3632 const MCInstrInfo &MII,
3633 const MCSubtargetInfo &ST) {
3634 for (auto OpName : {OpName::vdst, OpName::src0, OpName::src1, OpName::src2}) {
3635 int Idx = getNamedOperandIdx(OpDesc.getOpcode(), OpName);
3636 if (Idx == -1)
3637 continue;
3638
3639 const MCOperandInfo &OpInfo = OpDesc.operands()[Idx];
3640 int16_t RegClass = MII.getOpRegClassID(
3641 OpInfo, ST.getHwMode(MCSubtargetInfo::HwMode_RegInfo));
3642 if (RegClass == AMDGPU::VReg_64RegClassID ||
3643 RegClass == AMDGPU::VReg_64_Align2RegClassID)
3644 return true;
3645 }
3646
3647 return false;
3648}
3649
3650bool isDPALU_DPP32BitOpc(unsigned Opc) {
3651 switch (Opc) {
3652 case AMDGPU::V_MUL_LO_U32_e64:
3653 case AMDGPU::V_MUL_LO_U32_e64_dpp:
3654 case AMDGPU::V_MUL_LO_U32_e64_dpp_gfx1250:
3655 case AMDGPU::V_MUL_HI_U32_e64:
3656 case AMDGPU::V_MUL_HI_U32_e64_dpp:
3657 case AMDGPU::V_MUL_HI_U32_e64_dpp_gfx1250:
3658 case AMDGPU::V_MUL_HI_I32_e64:
3659 case AMDGPU::V_MUL_HI_I32_e64_dpp:
3660 case AMDGPU::V_MUL_HI_I32_e64_dpp_gfx1250:
3661 case AMDGPU::V_MAD_U32_e64:
3662 case AMDGPU::V_MAD_U32_e64_dpp:
3663 case AMDGPU::V_MAD_U32_e64_dpp_gfx1250:
3664 return true;
3665 default:
3666 return false;
3667 }
3668}
3669
3670bool isDPALU_DPP(const MCInstrDesc &OpDesc, const MCInstrInfo &MII,
3671 const MCSubtargetInfo &ST) {
3672 if (isDPALU_DPP32BitOpc(OpDesc.getOpcode()))
3673 return true;
3674
3675 return hasAny64BitVGPROperands(OpDesc, MII, ST);
3676}
3677
3679 switch (Opc) {
3680 case AMDGPU::V_PK_ADD_F32_gfx1250:
3681 case AMDGPU::V_PK_ADD_F32_gfx1250_gfx12:
3682 case AMDGPU::V_PK_MUL_F32_gfx1250:
3683 case AMDGPU::V_PK_MUL_F32_gfx1250_gfx12:
3684 case AMDGPU::V_PK_FMA_F32_gfx1250:
3685 case AMDGPU::V_PK_FMA_F32_gfx1250_gfx12:
3686 return true;
3687 default:
3688 return false;
3689 }
3690}
3691
3692// NOTE: This function is currently only used before pseudo-expansion.
3694 switch (Opc) {
3695 case AMDGPU::V_PK_ADD_F64:
3696 case AMDGPU::V_PK_MUL_F64:
3697 case AMDGPU::V_PK_FMA_F64:
3698 case AMDGPU::V_PK_MAX_NUM_F64:
3699 case AMDGPU::V_PK_MIN_NUM_F64:
3700 case AMDGPU::V_PK_ADD_NC_U64:
3701 case AMDGPU::V_PK_SUB_NC_U64:
3702 case AMDGPU::V_PK_LSHL_ADD_U64:
3703 return true;
3704 default:
3705 return false;
3706 }
3707}
3708
3712
3713const std::array<unsigned, 3> &ClusterDimsAttr::getDims() const {
3714 assert(isFixedDims() && "expect kind to be FixedDims");
3715 return Dims;
3716}
3717
3718std::string ClusterDimsAttr::to_string() const {
3719 SmallString<10> Buffer;
3720 raw_svector_ostream OS(Buffer);
3721
3722 switch (getKind()) {
3723 case Kind::Unknown:
3724 return "";
3725 case Kind::NoCluster: {
3726 OS << EncoNoCluster << ',' << EncoNoCluster << ',' << EncoNoCluster;
3727 return Buffer.c_str();
3728 }
3729 case Kind::VariableDims: {
3730 OS << EncoVariableDims << ',' << EncoVariableDims << ','
3731 << EncoVariableDims;
3732 return Buffer.c_str();
3733 }
3734 case Kind::FixedDims: {
3735 OS << Dims[0] << ',' << Dims[1] << ',' << Dims[2];
3736 return Buffer.c_str();
3737 }
3738 }
3739 llvm_unreachable("Unknown ClusterDimsAttr kind");
3740}
3741
3743 std::optional<SmallVector<unsigned>> Attr =
3744 getIntegerVecAttribute(F, "amdgpu-cluster-dims", /*Size=*/3);
3746
3747 if (!Attr.has_value())
3748 AttrKind = Kind::Unknown;
3749 else if (all_of(*Attr, equal_to(EncoNoCluster)))
3750 AttrKind = Kind::NoCluster;
3751 else if (all_of(*Attr, equal_to(EncoVariableDims)))
3752 AttrKind = Kind::VariableDims;
3753
3754 ClusterDimsAttr A(AttrKind);
3755 if (AttrKind == Kind::FixedDims)
3756 A.Dims = {(*Attr)[0], (*Attr)[1], (*Attr)[2]};
3757
3758 return A;
3759}
3760
3761std::optional<APFloat> evaluateRcp(const APFloat &Val) {
3762 const fltSemantics &Sem = Val.getSemantics();
3763
3764 // v_rcp_f16/bf16 are correctly rounded.
3765 if (&Sem == &APFloat::IEEEhalf() || &Sem == &APFloat::BFloat())
3766 return APFloat::getOne(Sem) / Val;
3767
3768 // v_rcp_f32/f64 always flush a denormal input to zero (preserving sign)
3769 // before reciprocating.
3770 APFloat Arg = Val;
3771 if (Arg.isDenormal())
3772 Arg = APFloat::getZero(Sem, Arg.isNegative());
3773
3774 APFloat Result = APFloat::getOne(Sem) / Arg;
3775
3776 // v_rcp_f32/f64 always flush a denormal result to zero (preserving sign).
3777 if (Result.isDenormal())
3778 Result = APFloat::getZero(Sem, Result.isNegative());
3779
3780 // v_rcp_f32/f64 only approximate the reciprocal, except for these special
3781 // cases where the result is exact.
3782 if (!Result.isZero() && !Result.isInfinity() && !Result.isNaN() &&
3783 !Result.isOne() && !Result.isMinusOne())
3784 return std::nullopt;
3785
3786 return Result;
3787}
3788
3789} // namespace AMDGPU
3790
3792 switch (S) {
3793 case (AMDGPU::TargetIDSetting::Unsupported):
3794 OS << "Unsupported";
3795 break;
3796 case (AMDGPU::TargetIDSetting::Any):
3797 OS << "Any";
3798 break;
3799 case (AMDGPU::TargetIDSetting::Off):
3800 OS << "Off";
3801 break;
3802 case (AMDGPU::TargetIDSetting::On):
3803 OS << "On";
3804 break;
3805 }
3806 return OS;
3807}
3808
3809} // namespace llvm
const AArch64Subtarget & Subtarget
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
uint64_t 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
uint64_t IntrinsicInst * II
RISCVCC::CondCode CC
MachineRegisterInfo & MRI
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:1495
#define S_00B848_WGP_MODE(x)
Definition SIDefines.h:1492
#define S_00B848_FWD_PROGRESS(x)
Definition SIDefines.h:1498
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:76
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...
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:28
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:524
ArchType getArch() const
Get the parsed architecture type of this triple.
Definition Triple.h:515
bool isAMDGCN() const
Tests whether the target is AMDGCN.
Definition Triple.h:996
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
A Use represents the edge between a Value definition and its users.
Definition Use.h:35
LLVM Value Representation.
Definition Value.h:75
const ParentTy * getParent() const
Definition ilist_node.h:34
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.
@ CONSTANT_ADDRESS
Address space for constant memory (VTX2).
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 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 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)
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)
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)
std::optional< unsigned > getExponentOnlyScaleArgIdx(unsigned IntrID)
bool isInlinableLiteralV2F16(uint32_t Literal)
bool isHsaAbi(const MCSubtargetInfo &STI)
bool isGFX11(const MCSubtargetInfo &STI)
static std::optional< unsigned > convertSetRegImmToVgprMSBs(uint64_t Imm, uint64_t Simm16, bool HasSetregVGPRMSBFixup)
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)
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 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)
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)
LLVM_READONLY bool hasNamedOperand(uint32_t Opcode, OpName NamedIdx)
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 isLDSDMAIntrinsic(unsigned IntrID)
bool getHasDepthExport(const Function &F)
bool isGFX8_GFX9_GFX10(const MCSubtargetInfo &STI)
bool getMUBUFHasVAddr(unsigned Opc)
bool hasNoOpSelHi(unsigned Opc)
Returns true if this VOP3P opcode has no op_sel_hi field, in which case those bits are encoded as zer...
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)
bool isTriviallyUniform(const Value *V, const Instruction *CtxI)
Return true if we can easily prove that V is uniform at CtxI.
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 isInlinableLiteralBF16(int16_t Literal, bool HasInv2Pi, bool *IsBF16)
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 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)
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_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_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_FP32
Definition SIDefines.h:449
@ 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)
unsigned getBarrierMemberCountBitMask(const IsaVersion &Version)
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)
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:192
@ ELFABIVERSION_AMDGPU_HSA_V5
Definition ELF.h:193
@ ELFABIVERSION_AMDGPU_HSA_V6
Definition ELF.h:194
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
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
testing::Matcher< const detail::ErrorHolder & > Failed()
Definition Error.h:198
constexpr T alignDown(U Value, V Align, W Skew=0)
Returns the largest unsigned integer less than or equal to Value and is Skew mod Align.
Definition MathExtras.h:546
std::string utostr(uint64_t X, bool isNeg=false)
constexpr auto equal_to(T &&Arg)
Functor variant of std::equal_to that can be used as a UnaryPredicate in functional algorithms like a...
Definition STLExtras.h: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:149
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
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
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
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
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
@ End
Run the machine verifier once, at the end of the pipeline.
Definition CodeGen.h:320
@ AlwaysUniform
The result value is always uniform.
Definition Uniformity.h:23
#define N
AMD Kernel Code Object (amd_kernel_code_t).
static std::tuple< typename Fields::ValueType... > decode(uint64_t Encoded)
Instruction set architecture version.