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#define GET_VLdStIdxOpcodeInfoTable_IMPL
488
489#include "AMDGPUGenSearchableTables.inc"
490
491const VLdStIdxOpcodeInfo *
492getVLdStIdxOpcodeInfoByKey(unsigned BitWidth, bool IsStore, bool IsGPRIdx) {
493 assert(isUInt<16>(BitWidth) && "the table's key is 16 bits");
494 return getVLdStIdxOpcodeInfoByKeyImpl(BitWidth, IsStore, IsGPRIdx);
495}
496
497int getMTBUFBaseOpcode(unsigned Opc) {
498 const MTBUFInfo *Info = getMTBUFInfoFromOpcode(Opc);
499 return Info ? Info->BaseOpcode : -1;
500}
501
502int getMTBUFOpcode(unsigned BaseOpc, unsigned Elements) {
503 const MTBUFInfo *Info =
504 getMTBUFInfoFromBaseOpcodeAndElements(BaseOpc, Elements);
505 return Info ? Info->Opcode : -1;
506}
507
508int getMTBUFElements(unsigned Opc) {
509 const MTBUFInfo *Info = getMTBUFOpcodeHelper(Opc);
510 return Info ? Info->elements : 0;
511}
512
513bool getMTBUFHasVAddr(unsigned Opc) {
514 const MTBUFInfo *Info = getMTBUFOpcodeHelper(Opc);
515 return Info && Info->has_vaddr;
516}
517
518bool getMTBUFHasSrsrc(unsigned Opc) {
519 const MTBUFInfo *Info = getMTBUFOpcodeHelper(Opc);
520 return Info && Info->has_srsrc;
521}
522
523bool getMTBUFHasSoffset(unsigned Opc) {
524 const MTBUFInfo *Info = getMTBUFOpcodeHelper(Opc);
525 return Info && Info->has_soffset;
526}
527
528int getMUBUFBaseOpcode(unsigned Opc) {
529 const MUBUFInfo *Info = getMUBUFInfoFromOpcode(Opc);
530 return Info ? Info->BaseOpcode : -1;
531}
532
533int getMUBUFOpcode(unsigned BaseOpc, unsigned Elements) {
534 const MUBUFInfo *Info =
535 getMUBUFInfoFromBaseOpcodeAndElements(BaseOpc, Elements);
536 return Info ? Info->Opcode : -1;
537}
538
539int getMUBUFElements(unsigned Opc) {
540 const MUBUFInfo *Info = getMUBUFOpcodeHelper(Opc);
541 return Info ? Info->elements : 0;
542}
543
544bool getMUBUFHasVAddr(unsigned Opc) {
545 const MUBUFInfo *Info = getMUBUFOpcodeHelper(Opc);
546 return Info && Info->has_vaddr;
547}
548
549bool getMUBUFHasSrsrc(unsigned Opc) {
550 const MUBUFInfo *Info = getMUBUFOpcodeHelper(Opc);
551 return Info && Info->has_srsrc;
552}
553
554bool getMUBUFHasSoffset(unsigned Opc) {
555 const MUBUFInfo *Info = getMUBUFOpcodeHelper(Opc);
556 return Info && Info->has_soffset;
557}
558
559bool getMUBUFIsBufferInv(unsigned Opc) {
560 const MUBUFInfo *Info = getMUBUFOpcodeHelper(Opc);
561 return Info && Info->IsBufferInv;
562}
563
564bool getMUBUFTfe(unsigned Opc) {
565 const MUBUFInfo *Info = getMUBUFOpcodeHelper(Opc);
566 return Info && Info->tfe;
567}
568
569bool getSMEMIsBuffer(unsigned Opc) {
570 return isSMEMOpcodeHelper(Opc) != nullptr;
571}
572
573bool getVOP1IsSingle(unsigned Opc) {
574 return isVOP1SingleOpcodeHelper(Opc) != nullptr;
575}
576
577bool getVOP2IsSingle(unsigned Opc) {
578 return isVOP2SingleOpcodeHelper(Opc) != nullptr;
579}
580
581bool getVOP3IsSingle(unsigned Opc) {
582 return isVOP3SingleOpcodeHelper(Opc) != nullptr;
583}
584
585bool isVOPC64DPP(unsigned Opc) {
586 return isVOPC64DPPOpcodeHelper(Opc) || isVOPC64DPP8OpcodeHelper(Opc);
587}
588
589bool isVOPCAsmOnly(unsigned Opc) { return isVOPCAsmOnlyOpcodeHelper(Opc); }
590
591bool getMAIIsDGEMM(unsigned Opc) {
592 const MAIInstInfo *Info = getMAIInstInfoHelper(Opc);
593 return Info && (Info->Variant == MFMAVariant::DGEMM_4Pass ||
594 Info->Variant == MFMAVariant::DGEMM_16x16x4);
595}
596
597bool getMAIIsGFX940XDL(unsigned Opc) {
598 const MAIInstInfo *Info = getMAIInstInfoHelper(Opc);
599 if (!Info)
600 return false;
601
602 switch (Info->Variant) {
609 return false;
622 return true;
623 }
624 llvm_unreachable("unknown MFMA variant");
625}
626
627bool getWMMAIsXDL(unsigned Opc) {
628 const WMMAInstInfo *Info = getWMMAInstInfoHelper(Opc);
629 return Info ? Info->is_wmma_xdl : false;
630}
631
632bool getHasMatrixScale(unsigned Opc) {
633 const WMMAInstInfo *Info = getWMMAInstInfoHelper(Opc);
634 return Info && Info->HasMatrixScale;
635}
636
638 switch (EncodingVal) {
641 return 6;
643 return 4;
646 default:
647 return 8;
648 }
649
650 llvm_unreachable("covered switch over mfma scale formats");
651}
652
654 unsigned BLGP,
655 unsigned F8F8Opcode) {
656 uint8_t SrcANumRegs = mfmaScaleF8F6F4FormatToNumRegs(CBSZ);
657 uint8_t SrcBNumRegs = mfmaScaleF8F6F4FormatToNumRegs(BLGP);
658 return getMFMA_F8F6F4_InstWithNumRegs(SrcANumRegs, SrcBNumRegs, F8F8Opcode);
659}
660
662 switch (Fmt) {
665 return 16;
668 return 12;
670 return 8;
671 }
672
673 llvm_unreachable("covered switch over wmma scale formats");
674}
675
677 unsigned FmtB,
678 unsigned F8F8Opcode) {
679 uint8_t SrcANumRegs = wmmaScaleF8F6F4FormatToNumRegs(FmtA);
680 uint8_t SrcBNumRegs = wmmaScaleF8F6F4FormatToNumRegs(FmtB);
681 return getMFMA_F8F6F4_InstWithNumRegs(SrcANumRegs, SrcBNumRegs, F8F8Opcode);
682}
683
684bool isValidWMMAScaleFmtCombination(unsigned AFmt, unsigned AScale,
685 unsigned BFmt, unsigned BScale) {
686 auto isValid = [](unsigned Fmt, unsigned Scale) -> bool {
687 switch (Fmt) {
692 if (Scale != WMMA::MATRIX_SCALE_FMT_E8)
693 return false;
694 break;
696 if (Scale != WMMA::MATRIX_SCALE_FMT_E8 &&
699 return false;
700 break;
701 }
702 return true;
703 };
704
705 if (!isValid(AFmt, AScale) || !isValid(BFmt, BScale))
706 return false;
707
708 if (AFmt == WMMA::MATRIX_FMT_FP4 && BFmt == WMMA::MATRIX_FMT_FP4 &&
709 AScale != BScale)
710 return false;
711
712 return true;
713}
714
716 if (ST.hasFeature(AMDGPU::FeatureGFX13Insts))
718 if (ST.hasFeature(AMDGPU::FeatureGFX1250Insts))
720 if (ST.hasFeature(AMDGPU::FeatureGFX12Insts))
722 if (ST.hasFeature(AMDGPU::FeatureGFX11_7Insts))
724 if (ST.hasFeature(AMDGPU::FeatureGFX11Insts))
726 llvm_unreachable("Subtarget generation does not support VOPD!");
727}
728
729CanBeVOPD getCanBeVOPD(unsigned Opc, unsigned EncodingFamily, bool VOPD3) {
730 bool IsConvertibleToBitOp = VOPD3 ? getBitOp2(Opc) : 0;
731 Opc = IsConvertibleToBitOp ? (unsigned)AMDGPU::V_BITOP3_B32_e64 : Opc;
732 // Normalize through VOPDComponentTable so that e32 and e64 variants
733 // of the same logical opcode all share a single entry.
734 const VOPDComponentInfo *Info = getVOPDComponentHelper(Opc);
735 if (!Info)
736 return {false, false};
737 unsigned Key =
738 (Info->VOPDOp << 5) | (EncodingFamily << 1) | (VOPD3 ? 1u : 0u);
739 const VOPDXYInfo *XYInfo = getVOPDXYInfo(static_cast<uint16_t>(Key));
740 if (!XYInfo)
741 return {false, false};
742 return {XYInfo->IsX, XYInfo->IsY};
743}
744
745unsigned getVOPDOpcode(unsigned Opc, bool VOPD3) {
746 bool IsConvertibleToBitOp = VOPD3 ? getBitOp2(Opc) : 0;
747 Opc = IsConvertibleToBitOp ? (unsigned)AMDGPU::V_BITOP3_B32_e64 : Opc;
748 const VOPDComponentInfo *Info = getVOPDComponentHelper(Opc);
749 return Info ? Info->VOPDOp : ~0u;
750}
751
752bool isVOPD(unsigned Opc) {
753 return AMDGPU::hasNamedOperand(Opc, AMDGPU::OpName::src0X);
754}
755
756bool isMAC(unsigned Opc) {
757 return Opc == AMDGPU::V_MAC_F32_e64_gfx6_gfx7 ||
758 Opc == AMDGPU::V_MAC_F32_e64_gfx10 ||
759 Opc == AMDGPU::V_MAC_F32_e64_vi ||
760 Opc == AMDGPU::V_MAC_LEGACY_F32_e64_gfx6_gfx7 ||
761 Opc == AMDGPU::V_MAC_LEGACY_F32_e64_gfx10 ||
762 Opc == AMDGPU::V_MAC_F16_e64_vi ||
763 Opc == AMDGPU::V_FMAC_F64_e64_gfx90a ||
764 Opc == AMDGPU::V_FMAC_F64_e64_gfx12 ||
765 Opc == AMDGPU::V_FMAC_F64_e64_gfx13 ||
766 Opc == AMDGPU::V_FMAC_F32_e64_gfx10 ||
767 Opc == AMDGPU::V_FMAC_F32_e64_gfx11 ||
768 Opc == AMDGPU::V_FMAC_F32_e64_gfx12 ||
769 Opc == AMDGPU::V_FMAC_F32_e64_gfx13 ||
770 Opc == AMDGPU::V_FMAC_F32_e64_vi ||
771 Opc == AMDGPU::V_FMAC_LEGACY_F32_e64_gfx10 ||
772 Opc == AMDGPU::V_FMAC_DX9_ZERO_F32_e64_gfx11 ||
773 Opc == AMDGPU::V_FMAC_F16_e64_gfx10 ||
774 Opc == AMDGPU::V_FMAC_F16_t16_e64_gfx11 ||
775 Opc == AMDGPU::V_FMAC_F16_fake16_e64_gfx11 ||
776 Opc == AMDGPU::V_FMAC_F16_t16_e64_gfx12 ||
777 Opc == AMDGPU::V_FMAC_F16_fake16_e64_gfx12 ||
778 Opc == AMDGPU::V_FMAC_F16_t16_e64_gfx13 ||
779 Opc == AMDGPU::V_FMAC_F16_fake16_e64_gfx13 ||
780 Opc == AMDGPU::V_DOT2C_F32_F16_e64_vi ||
781 Opc == AMDGPU::V_DOT2C_F32_BF16_e64_vi ||
782 Opc == AMDGPU::V_DOT2C_I32_I16_e64_vi ||
783 Opc == AMDGPU::V_DOT4C_I32_I8_e64_vi ||
784 Opc == AMDGPU::V_DOT8C_I32_I4_e64_vi;
785}
786
787bool isPermlane16(unsigned Opc) {
788 return Opc == AMDGPU::V_PERMLANE16_B32_gfx10 ||
789 Opc == AMDGPU::V_PERMLANEX16_B32_gfx10 ||
790 Opc == AMDGPU::V_PERMLANE16_B32_e64_gfx11 ||
791 Opc == AMDGPU::V_PERMLANEX16_B32_e64_gfx11 ||
792 Opc == AMDGPU::V_PERMLANE16_B32_e64_gfx12 ||
793 Opc == AMDGPU::V_PERMLANE16_B32_e64_gfx13 ||
794 Opc == AMDGPU::V_PERMLANEX16_B32_e64_gfx12 ||
795 Opc == AMDGPU::V_PERMLANEX16_B32_e64_gfx13 ||
796 Opc == AMDGPU::V_PERMLANE16_VAR_B32_e64_gfx12 ||
797 Opc == AMDGPU::V_PERMLANE16_VAR_B32_e64_gfx13 ||
798 Opc == AMDGPU::V_PERMLANEX16_VAR_B32_e64_gfx12 ||
799 Opc == AMDGPU::V_PERMLANEX16_VAR_B32_e64_gfx13;
800}
801
803 return Opc == AMDGPU::V_CVT_F32_BF8_e64_gfx12 ||
804 Opc == AMDGPU::V_CVT_F32_FP8_e64_gfx12 ||
805 Opc == AMDGPU::V_CVT_F32_BF8_e64_dpp_gfx12 ||
806 Opc == AMDGPU::V_CVT_F32_FP8_e64_dpp_gfx12 ||
807 Opc == AMDGPU::V_CVT_F32_BF8_e64_dpp8_gfx12 ||
808 Opc == AMDGPU::V_CVT_F32_FP8_e64_dpp8_gfx12 ||
809 Opc == AMDGPU::V_CVT_PK_F32_BF8_fake16_e64_gfx12 ||
810 Opc == AMDGPU::V_CVT_PK_F32_FP8_fake16_e64_gfx12 ||
811 Opc == AMDGPU::V_CVT_PK_F32_BF8_t16_e64_gfx12 ||
812 Opc == AMDGPU::V_CVT_PK_F32_FP8_t16_e64_gfx12;
813}
814
815bool isGenericAtomic(unsigned Opc) {
816 return Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_SWAP ||
817 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_ADD ||
818 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_SUB ||
819 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_SMIN ||
820 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_UMIN ||
821 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_SMAX ||
822 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_UMAX ||
823 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_AND ||
824 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_OR ||
825 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_XOR ||
826 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_INC ||
827 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_DEC ||
828 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_FADD ||
829 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_FMIN ||
830 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_FMAX ||
831 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_CMPSWAP ||
832 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_SUB_CLAMP_U32 ||
833 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_COND_SUB_U32 ||
834 Opc == AMDGPU::G_AMDGPU_ATOMIC_CMPXCHG;
835}
836
837bool isAsyncStore(unsigned Opc) {
838 switch (Opc) {
839 case GLOBAL_STORE_ASYNC_FROM_LDS_B8:
840 case GLOBAL_STORE_ASYNC_FROM_LDS_B8_gfx1250:
841 case GLOBAL_STORE_ASYNC_FROM_LDS_B8_SADDR:
842 case GLOBAL_STORE_ASYNC_FROM_LDS_B8_SADDR_gfx1250:
843 case GLOBAL_STORE_ASYNC_FROM_LDS_B32:
844 case GLOBAL_STORE_ASYNC_FROM_LDS_B32_gfx1250:
845 case GLOBAL_STORE_ASYNC_FROM_LDS_B32_SADDR:
846 case GLOBAL_STORE_ASYNC_FROM_LDS_B32_SADDR_gfx1250:
847 case GLOBAL_STORE_ASYNC_FROM_LDS_B64:
848 case GLOBAL_STORE_ASYNC_FROM_LDS_B64_gfx1250:
849 case GLOBAL_STORE_ASYNC_FROM_LDS_B64_SADDR:
850 case GLOBAL_STORE_ASYNC_FROM_LDS_B64_SADDR_gfx1250:
851 case GLOBAL_STORE_ASYNC_FROM_LDS_B128:
852 case GLOBAL_STORE_ASYNC_FROM_LDS_B128_gfx1250:
853 case GLOBAL_STORE_ASYNC_FROM_LDS_B128_SADDR:
854 case GLOBAL_STORE_ASYNC_FROM_LDS_B128_SADDR_gfx1250:
855 return true;
856 default:
857 return false;
858 }
859}
860
861bool isTensorStore(unsigned Opc) {
862 return Opc == TENSOR_STORE_FROM_LDS_d2_gfx1250 ||
863 Opc == TENSOR_STORE_FROM_LDS_d4_gfx1250;
864}
865
866unsigned getTemporalHintType(const MCInstrDesc TID) {
867 if (SIInstrFlags::isAtomic(TID))
869 unsigned Opc = TID.getOpcode();
870 // Async and Tensor store should have the temporal hint type of TH_TYPE_STORE
871 if (TID.mayStore() &&
872 (isAsyncStore(Opc) || isTensorStore(Opc) || !TID.mayLoad()))
873 return CPol::TH_TYPE_STORE;
874
875 // This will default to returning TH_TYPE_LOAD when neither MayStore nor
876 // MayLoad flag is present which is the case with instructions like
877 // image_get_resinfo.
878 return CPol::TH_TYPE_LOAD;
879}
880
881bool isTrue16Inst(unsigned Opc) { return isTrue16Opcode(Opc) != nullptr; }
882
883bool hasNoOpSelHi(unsigned Opc) {
884 return getVOP3PHasNoOpSelHiHelper(Opc) != nullptr;
885}
886
888 const FP4FP8DstByteSelInfo *Info = getFP4FP8DstByteSelHelper(Opc);
889 if (!Info)
890 return FPType::None;
891 if (Info->HasFP8DstByteSel)
892 return FPType::FP8;
893 if (Info->HasFP4DstByteSel)
894 return FPType::FP4;
895
896 return FPType::None;
897}
898
899bool isDPMACCInstruction(unsigned Opc) {
900 return isDPMACCInstructionHelper(Opc) != nullptr;
901}
902
903unsigned mapWMMA2AddrTo3AddrOpcode(unsigned Opc) {
904 const WMMAOpcodeMappingInfo *Info = getWMMAMappingInfoFrom2AddrOpcode(Opc);
905 return Info ? Info->Opcode3Addr : ~0u;
906}
907
908// Wrapper for Tablegen'd function. enum Subtarget is not defined in any
909// header files, so we need to wrap it in a function that takes unsigned
910// instead.
911int32_t getMCOpcode(uint32_t Opcode, unsigned Gen) {
912 return getMCOpcodeGen(Opcode, static_cast<Subtarget>(Gen));
913}
914
915unsigned getBitOp2(unsigned Opc) {
916 switch (Opc) {
917 default:
918 return 0;
919 case AMDGPU::V_AND_B32_e32:
920 return 0x40;
921 case AMDGPU::V_OR_B32_e32:
922 return 0x54;
923 case AMDGPU::V_XOR_B32_e32:
924 return 0x14;
925 case AMDGPU::V_XNOR_B32_e32:
926 return 0x41;
927 }
928}
929
930int getVOPDFull(unsigned OpX, unsigned OpY, unsigned EncodingFamily,
931 bool VOPD3) {
932 bool IsConvertibleToBitOp = VOPD3 ? getBitOp2(OpY) : 0;
933 OpY = IsConvertibleToBitOp ? (unsigned)AMDGPU::V_BITOP3_B32_e64 : OpY;
934 const VOPDInfo *Info = getVOPDInfoFromComponentOpcodes(
935 static_cast<uint8_t>(OpX), static_cast<uint8_t>(OpY),
936 static_cast<uint8_t>(EncodingFamily), VOPD3);
937 return Info ? Info->Opcode : -1;
938}
939
940std::pair<unsigned, unsigned> getVOPDComponents(unsigned VOPDOpcode) {
941 const VOPDInfo *Info = getVOPDOpcodeHelper(VOPDOpcode);
942 assert(Info);
943 const auto *OpX = getVOPDBaseFromComponent(Info->OpX);
944 const auto *OpY = getVOPDBaseFromComponent(Info->OpY);
945 assert(OpX && OpY);
946 return {OpX->BaseVOP, OpY->BaseVOP};
947}
948
949namespace VOPD {
950
951ComponentProps::ComponentProps(const MCInstrDesc &OpDesc, bool VOP3Layout) {
953
956 auto TiedIdx = OpDesc.getOperandConstraint(Component::SRC2, MCOI::TIED_TO);
957 assert(TiedIdx == -1 || TiedIdx == Component::DST);
958 HasSrc2Acc = TiedIdx != -1;
959 Opcode = OpDesc.getOpcode();
960
961 IsVOP3 = VOP3Layout || SIInstrFlags::isVOP3(OpDesc);
962 SrcOperandsNum = AMDGPU::hasNamedOperand(Opcode, AMDGPU::OpName::src2) ? 3
963 : AMDGPU::hasNamedOperand(Opcode, AMDGPU::OpName::imm) ? 3
964 : AMDGPU::hasNamedOperand(Opcode, AMDGPU::OpName::src1) ? 2
965 : 1;
966 assert(SrcOperandsNum <= Component::MAX_SRC_NUM);
967
968 if (Opcode == AMDGPU::V_CNDMASK_B32_e32 ||
969 Opcode == AMDGPU::V_CNDMASK_B32_e64) {
970 // CNDMASK is an awkward exception, it has FP modifiers, but not FP
971 // operands.
972 NumVOPD3Mods = 2;
973 if (IsVOP3)
974 SrcOperandsNum = 3;
975 } else if (Opcode == AMDGPU::V_DOT2_F32_F16 ||
976 Opcode == AMDGPU::V_DOT2_F32_BF16) {
977 // VOP3P opcodes that have VOPD but don't have VOP2 version. Using VOPD3
978 // path in getIndexOfSrcInMCOperands to get correct src operand indexes,
979 // but generating VOPD, not VOPD3.
980 NumVOPD3Mods = SrcOperandsNum;
981 } else if (isSISrcFPOperand(OpDesc,
982 getNamedOperandIdx(Opcode, OpName::src0))) {
983 // All FP VOPD instructions have Neg modifiers for all operands except
984 // for tied src2.
985 NumVOPD3Mods = SrcOperandsNum;
986 if (HasSrc2Acc)
987 --NumVOPD3Mods;
988 }
989
990 if (SIInstrFlags::isVOP3(OpDesc))
991 return;
992
993 auto OperandsNum = OpDesc.getNumOperands();
994 unsigned CompOprIdx;
995 for (CompOprIdx = Component::SRC1; CompOprIdx < OperandsNum; ++CompOprIdx) {
996 if (OpDesc.operands()[CompOprIdx].OperandType == AMDGPU::OPERAND_KIMM32) {
997 MandatoryLiteralIdx = CompOprIdx;
998 break;
999 }
1000 }
1001}
1002
1004 return getNamedOperandIdx(Opcode, OpName::bitop3);
1005}
1006
1007unsigned ComponentInfo::getIndexInParsedOperands(unsigned CompOprIdx) const {
1008 assert(CompOprIdx < Component::MAX_OPR_NUM);
1009
1010 if (CompOprIdx == Component::DST)
1012
1013 auto CompSrcIdx = CompOprIdx - Component::DST_NUM;
1014 if (CompSrcIdx < getCompParsedSrcOperandsNum())
1015 return getIndexOfSrcInParsedOperands(CompSrcIdx);
1016
1017 // The specified operand does not exist.
1018 return 0;
1019}
1020
1022 std::function<MCRegister(unsigned, unsigned)> GetRegIdx,
1023 const MCRegisterInfo &MRI, bool SkipSrc, bool AllowSameVGPR, bool VOPD3,
1024 bool HasGFX11InterlockHazard) const {
1025
1026 auto OpXRegs = getRegIndices(ComponentIndex::X, GetRegIdx,
1027 CompInfo[ComponentIndex::X].isVOP3());
1028 auto OpYRegs = getRegIndices(ComponentIndex::Y, GetRegIdx,
1029 CompInfo[ComponentIndex::Y].isVOP3());
1030
1031 const auto banksOverlap = [&MRI](MCRegister X, MCRegister Y,
1032 unsigned BanksMask) -> bool {
1033 MCRegister BaseX = MRI.getSubReg(X, AMDGPU::sub0);
1034 MCRegister BaseY = MRI.getSubReg(Y, AMDGPU::sub0);
1035 if (!BaseX)
1036 BaseX = X;
1037 if (!BaseY)
1038 BaseY = Y;
1039 if ((BaseX.id() & BanksMask) == (BaseY.id() & BanksMask))
1040 return true;
1041 if (BaseX != X /* This is 64-bit register */ &&
1042 ((BaseX.id() + 1) & BanksMask) == (BaseY.id() & BanksMask))
1043 return true;
1044 if (BaseY != Y &&
1045 (BaseX.id() & BanksMask) == ((BaseY.id() + 1) & BanksMask))
1046 return true;
1047
1048 // If both are 64-bit bank conflict will be detected yet while checking
1049 // the first subreg.
1050 return false;
1051 };
1052
1053 unsigned CompOprIdx;
1054 for (CompOprIdx = 0; CompOprIdx < Component::MAX_OPR_NUM; ++CompOprIdx) {
1055 unsigned BanksMasks = VOPD3 ? VOPD3_VGPR_BANK_MASKS[CompOprIdx]
1056 : HasGFX11InterlockHazard
1057 ? VOPD_GFX11_VGPR_BANK_MASKS[CompOprIdx]
1058 : VOPD_VGPR_BANK_MASKS[CompOprIdx];
1059 if (!OpXRegs[CompOprIdx] || !OpYRegs[CompOprIdx])
1060 continue;
1061
1062 if (getVGPREncodingMSBs(OpXRegs[CompOprIdx], MRI) !=
1063 getVGPREncodingMSBs(OpYRegs[CompOprIdx], MRI))
1064 return CompOprIdx;
1065
1066 if (SkipSrc && CompOprIdx >= Component::DST_NUM)
1067 continue;
1068
1069 if (CompOprIdx < Component::DST_NUM) {
1070 // Even if we do not check vdst parity, vdst operands still shall not
1071 // overlap.
1072 if (MRI.regsOverlap(OpXRegs[CompOprIdx], OpYRegs[CompOprIdx]))
1073 return CompOprIdx;
1074 if (VOPD3) // No need to check dst parity.
1075 continue;
1076 }
1077
1078 if (banksOverlap(OpXRegs[CompOprIdx], OpYRegs[CompOprIdx], BanksMasks) &&
1079 (!AllowSameVGPR || CompOprIdx < Component::DST_NUM ||
1080 OpXRegs[CompOprIdx] != OpYRegs[CompOprIdx]))
1081 return CompOprIdx;
1082 }
1083
1084 return {};
1085}
1086
1087// Return an array of VGPR registers [DST,SRC0,SRC1,SRC2] used
1088// by the specified component. If an operand is unused
1089// or is not a VGPR, the corresponding value is 0.
1090//
1091// GetRegIdx(Component, MCOperandIdx) must return a VGPR register index
1092// for the specified component and MC operand. The callback must return 0
1093// if the operand is not a register or not a VGPR.
1095InstInfo::getRegIndices(unsigned CompIdx,
1096 std::function<MCRegister(unsigned, unsigned)> GetRegIdx,
1097 bool VOPD3) const {
1098 assert(CompIdx < COMPONENTS_NUM);
1099
1100 const auto &Comp = CompInfo[CompIdx];
1102
1103 RegIndices[DST] = GetRegIdx(CompIdx, Comp.getIndexOfDstInMCOperands());
1104
1105 for (unsigned CompOprIdx : {SRC0, SRC1, SRC2}) {
1106 unsigned CompSrcIdx = CompOprIdx - DST_NUM;
1107 RegIndices[CompOprIdx] =
1108 Comp.hasRegSrcOperand(CompSrcIdx)
1109 ? GetRegIdx(CompIdx,
1110 Comp.getIndexOfSrcInMCOperands(CompSrcIdx, VOPD3))
1111 : MCRegister();
1112 }
1113 return RegIndices;
1114}
1115
1116} // namespace VOPD
1117
1119 return VOPD::InstInfo(OpX, OpY);
1120}
1121
1123 const MCInstrInfo *InstrInfo) {
1124 auto [OpX, OpY] = getVOPDComponents(VOPDOpcode);
1125 const auto &OpXDesc = InstrInfo->get(OpX);
1126 const auto &OpYDesc = InstrInfo->get(OpY);
1127 bool VOPD3 = SIInstrFlags::isVOPD3(*InstrInfo, VOPDOpcode);
1129 VOPD::ComponentInfo OpYInfo(OpYDesc, OpXInfo, VOPD3);
1130 return VOPD::InstInfo(OpXInfo, OpYInfo);
1131}
1132
1134 StringRef FeatureString) {
1135 // In codegen the mode comes from module flags and FeatureString is empty, so
1136 // the processor defaults apply. The assembler has no target directive, so it
1137 // pins the mode via the +xnack/-xnack/+sramecc/-sramecc feature string.
1139 STI.getCPU(), FeatureString);
1140}
1141
1142namespace IsaInfo {
1143
1145 if (STI.getFeatureBits().test(FeatureInstCacheLineSize128))
1146 return 128;
1147 if (STI.getFeatureBits().test(FeatureInstCacheLineSize64))
1148 return 64;
1149 return 64;
1150}
1151
1152unsigned getWavefrontSize(const MCSubtargetInfo &STI) {
1153 if (STI.getFeatureBits().test(FeatureWavefrontSize16))
1154 return 16;
1155 if (STI.getFeatureBits().test(FeatureWavefrontSize32))
1156 return 32;
1157
1158 return 64;
1159}
1160
1161// Maximum LDS a single work-group can address. This is a fixed HW cap. It does
1162// not depend on how many SIMDs a work-group runs on.
1164 if (STI.getFeatureBits().test(FeatureAddressableLocalMemorySize32768))
1165 return 32768;
1166 if (STI.getFeatureBits().test(FeatureAddressableLocalMemorySize65536))
1167 return 65536;
1168 if (STI.getFeatureBits().test(FeatureAddressableLocalMemorySize163840))
1169 return 163840;
1170 if (STI.getFeatureBits().test(FeatureAddressableLocalMemorySize196608))
1171 return 196608;
1172 if (STI.getFeatureBits().test(FeatureAddressableLocalMemorySize327680))
1173 return 327680;
1174 return 32768;
1175}
1176
1177// Total physical size of LDS on the block, in bytes. On targets with
1178// FeatureHalfAddressablePhysicalLocalMemory the physical block is twice the
1179// addressable size (gfx6: 64 KiB physical and 32 KiB addressable;
1180// gfx10/11/12: 128 KiB physical and 64 KiB addressable). On other targets it is
1181// equal to the addressable size.
1182static unsigned getPhysicalLocalMemorySize(const MCSubtargetInfo &STI) {
1183 unsigned Addressable = getMaxHWAddressableLocalMemorySize(STI);
1184 if (STI.getFeatureBits().test(FeatureHalfAddressablePhysicalLocalMemory))
1185 return 2 * Addressable;
1186 return Addressable;
1187}
1188
1189// Sizes in use, by generation (addressable / physical block):
1190// gfx6 : 32 KiB addressable, 64 KiB physical block
1191// gfx7 / gfx8 / gfx9: 64 KiB
1192// gfx9.5 (gfx950) : 160 KiB
1193// gfx10 / 11 / 12 : 64 KiB addressable, 128 KiB physical block
1194// gfx12.5 (gfx1250) : 320 KiB (always runs on four SIMDs)
1195// gfx13 : 192 KiB on four SIMDs, 96 KiB on two
1196// Total available in the current mode. The physical size is halved when a
1197// work-group runs on two SIMDs.
1199 unsigned Size = getPhysicalLocalMemorySize(STI);
1200 if (!isFullSIMDMode(STI))
1201 Size /= 2;
1202 return Size;
1203}
1204
1205// What one work-group can allocate in the current mode. This is the HW
1206// addressable cap, but never more than the total available in the current mode.
1208 return std::min(getMaxHWAddressableLocalMemorySize(STI),
1209 getLocalMemorySize(STI));
1210}
1211
1213 unsigned FlatWorkGroupSize) {
1214 assert(FlatWorkGroupSize != 0);
1215 if (!STI.getTargetTriple().isAMDGCN())
1216 return 8;
1217 GPUKind Kind = parseArchAMDGCN(STI.getCPU());
1218 unsigned MaxWaves =
1220 unsigned N = getWavesPerWorkGroup(STI, FlatWorkGroupSize);
1221 if (N == 1) {
1222 // Single-wave workgroups don't consume barrier resources.
1223 return MaxWaves;
1224 }
1225
1226 unsigned MaxBarriers = 16;
1227 if (isGFX10Plus(STI) && !STI.getFeatureBits().test(FeatureCuMode))
1228 MaxBarriers = 32;
1229
1230 return std::min(MaxWaves / N, MaxBarriers);
1231}
1232
1234 unsigned FlatWorkGroupSize) {
1235 return divideCeil(getWavesPerWorkGroup(STI, FlatWorkGroupSize),
1237}
1238
1240 unsigned FlatWorkGroupSize) {
1241 return divideCeil(FlatWorkGroupSize, getWavefrontSize(STI));
1242}
1243
1244unsigned getSGPREncodingGranule(const MCSubtargetInfo &STI) { return 8; }
1245
1246// Per-wave SGPRs reserved for the trap handler when enabled.
1247static unsigned getSGPRTrapHandlerReserve(const MCSubtargetInfo &STI) {
1248 return STI.getFeatureBits().test(FeatureTrapHandler) ? TRAP_NUM_SGPRS : 0;
1249}
1250
1251// Per-wave SGPR budget (before the addressable clamp): take off the trap
1252// reserve, round down to \p Granule. Shared by getMinNumSGPRs() and
1253// getMaxNumSGPRs(); getOccupancyWithNumSGPRs() is the closed-form algebraic
1254// inverse of this same budget (it does not call this helper), so the two encode
1255// one model.
1256static unsigned getSGPRBudgetPerWave(unsigned TotalNumSGPRs,
1257 unsigned WavesPerEU, unsigned TrapReserve,
1258 unsigned Granule) {
1259 assert(WavesPerEU != 0 && Granule != 0);
1260 unsigned Budget = TotalNumSGPRs / WavesPerEU;
1261 Budget -= std::min(Budget, TrapReserve);
1262 return alignDown(Budget, Granule);
1263}
1264
1265unsigned getMinNumSGPRs(const MCSubtargetInfo &STI, unsigned WavesPerEU) {
1266 assert(WavesPerEU != 0);
1267
1269 if (Version.Major >= 10)
1270 return 0;
1271
1272 GPUKind Kind = parseArchAMDGCN(STI.getCPU());
1273 if (WavesPerEU >= getMaxWavesPerEU(Kind))
1274 return 0;
1275
1276 unsigned MinNumSGPRs =
1277 getSGPRBudgetPerWave(getTotalNumSGPRs(Kind), WavesPerEU + 1,
1279 getSGPRAllocGranule(Kind)) +
1280 1;
1281 return std::min(MinNumSGPRs, getAddressableNumSGPRs(Kind));
1282}
1283
1284unsigned getMaxNumSGPRs(const MCSubtargetInfo &STI, unsigned WavesPerEU,
1285 bool Addressable) {
1286 assert(WavesPerEU != 0);
1287
1288 GPUKind Kind = parseArchAMDGCN(STI.getCPU());
1289 unsigned AddressableNumSGPRs = getAddressableNumSGPRs(Kind);
1291 if (Version.Major >= 10)
1292 return Addressable ? AddressableNumSGPRs : 108;
1293 if (Version.Major >= 8 && !Addressable)
1294 AddressableNumSGPRs = 112;
1295 unsigned MaxNumSGPRs = getSGPRBudgetPerWave(
1296 getTotalNumSGPRs(Kind), WavesPerEU, getSGPRTrapHandlerReserve(STI),
1297 getSGPRAllocGranule(Kind));
1298 return std::min(MaxNumSGPRs, AddressableNumSGPRs);
1299}
1300
1302 // From GFX10 on the SGPR file is large enough that SGPRs never limit
1303 // occupancy. Kept as one capability so callers don't each test the version.
1304 return getIsaVersion(STI.getCPU()).Major < 10;
1305}
1306
1307unsigned getNumExtraSGPRs(const MCSubtargetInfo &STI, bool VCCUsed,
1308 bool FlatScrUsed, bool XNACKUsed) {
1309 unsigned ExtraSGPRs = 0;
1310 if (VCCUsed)
1311 ExtraSGPRs = 2;
1312
1314 if (Version.Major >= 10)
1315 return ExtraSGPRs;
1316
1317 if (Version.Major < 8) {
1318 if (FlatScrUsed)
1319 ExtraSGPRs = 4;
1320 } else {
1321 if (XNACKUsed)
1322 ExtraSGPRs = 4;
1323
1324 if (FlatScrUsed ||
1325 STI.getFeatureBits().test(AMDGPU::FeatureArchitectedFlatScratch))
1326 ExtraSGPRs = 6;
1327 }
1328
1329 return ExtraSGPRs;
1330}
1331
1332static unsigned getGranulatedNumRegisterBlocks(unsigned NumRegs,
1333 unsigned Granule) {
1334 return divideCeil(std::max(1u, NumRegs), Granule);
1335}
1336
1337unsigned getNumSGPRBlocks(const MCSubtargetInfo &STI, unsigned NumSGPRs) {
1338 // SGPRBlocks is actual number of SGPR blocks minus 1.
1340 1;
1341}
1342
1344 unsigned DynamicVGPRBlockSize,
1345 std::optional<bool> EnableWavefrontSize32) {
1346 if (STI.getFeatureBits().test(FeatureGFX90AInsts))
1347 return 8;
1348
1349 if (DynamicVGPRBlockSize != 0)
1350 return DynamicVGPRBlockSize;
1351
1352 bool IsWave32 = EnableWavefrontSize32
1353 ? *EnableWavefrontSize32
1354 : STI.getFeatureBits().test(FeatureWavefrontSize32);
1355
1356 if (STI.getFeatureBits().test(Feature1536VGPRs))
1357 return IsWave32 ? 24 : 12;
1358
1359 if (hasGFX10_3Insts(STI))
1360 return IsWave32 ? 16 : 8;
1361
1362 return IsWave32 ? 8 : 4;
1363}
1364
1366 std::optional<bool> EnableWavefrontSize32) {
1367 if (STI.getFeatureBits().test(FeatureGFX90AInsts))
1368 return 8;
1369
1370 bool IsWave32 = EnableWavefrontSize32
1371 ? *EnableWavefrontSize32
1372 : STI.getFeatureBits().test(FeatureWavefrontSize32);
1373
1374 if (STI.getFeatureBits().test(FeatureVGPRMSBs))
1375 return IsWave32 ? 16 : 8;
1376
1377 return IsWave32 ? 8 : 4;
1378}
1379
1380unsigned getArchVGPRAllocGranule() { return 4; }
1381
1383 const auto &Features = STI.getFeatureBits();
1384 if (Features.test(FeatureVGPRMSBs))
1385 return Features.test(FeatureWavefrontSize32) ? 1024 : 512;
1386 return 256;
1387}
1388
1390 unsigned DynamicVGPRBlockSize) {
1391 const auto &Features = STI.getFeatureBits();
1392 if (Features.test(FeatureGFX90AInsts))
1393 return 512;
1394
1395 if (DynamicVGPRBlockSize != 0) {
1396 // On GFX12 we can allocate at most MaxDynamicVGPRBlocks blocks of VGPRs.
1397 return MaxDynamicVGPRBlocks *
1398 getVGPRAllocGranule(STI, DynamicVGPRBlockSize);
1399 }
1400 return getAddressableNumArchVGPRs(STI);
1401}
1402
1404 unsigned NumVGPRs,
1405 unsigned DynamicVGPRBlockSize) {
1406 GPUKind Kind = parseArchAMDGCN(STI.getCPU());
1407 bool IsWave32 = STI.getFeatureBits().test(FeatureWavefrontSize32);
1409 NumVGPRs, getVGPRAllocGranule(STI, DynamicVGPRBlockSize),
1410 getMaxWavesPerEU(Kind), AMDGPU::getTotalNumVGPRs(Kind, IsWave32));
1411}
1412
1413unsigned getNumWavesPerEUWithNumVGPRs(unsigned NumVGPRs, unsigned Granule,
1414 unsigned MaxWaves,
1415 unsigned TotalNumVGPRs) {
1416 if (NumVGPRs < Granule)
1417 return MaxWaves;
1418 unsigned RoundedRegs = alignTo(NumVGPRs, Granule);
1419 return std::min(std::max(TotalNumVGPRs / RoundedRegs, 1u), MaxWaves);
1420}
1421
1422unsigned getOccupancyWithNumSGPRs(unsigned SGPRs, unsigned MaxWaves,
1423 unsigned TotalNumSGPRs, unsigned Granule,
1424 unsigned TrapReserve) {
1425 // Closed-form inverse of getMaxNumSGPRs(): the budget condition
1426 // SGPRs <= alignDown(TotalNumSGPRs / W - TrapReserve, Granule)
1427 // solves to W <= TotalNumSGPRs / (alignTo(SGPRs, Granule) + TrapReserve).
1428 unsigned PerWave = alignTo(SGPRs, Granule) + TrapReserve;
1429 return PerWave ? std::clamp(TotalNumSGPRs / PerWave, 1u, MaxWaves) : MaxWaves;
1430}
1431
1432unsigned getOccupancyWithNumSGPRs(const MCSubtargetInfo &STI, unsigned SGPRs) {
1433 GPUKind Kind = parseArchAMDGCN(STI.getCPU());
1434 unsigned MaxWaves = getMaxWavesPerEU(Kind);
1435
1436 if (!isSGPROccupancyLimited(STI))
1437 return MaxWaves;
1438
1439 return getOccupancyWithNumSGPRs(SGPRs, MaxWaves, getTotalNumSGPRs(Kind),
1440 getSGPRAllocGranule(Kind),
1442}
1443
1444unsigned getMinNumVGPRs(const MCSubtargetInfo &STI, unsigned WavesPerEU,
1445 unsigned DynamicVGPRBlockSize) {
1446 assert(WavesPerEU != 0);
1447
1448 // In dynamic VGPR mode, (static) occupancy does not depend on VGPR usage,
1449 // so getMaxNumVGPRs does not depend on WavesPerEU, and thus we need to return
1450 // zero because there is no nonzero VGPR usage N where going below N
1451 // achieves higher (static) occupancy.
1452 bool DynamicVGPREnabled = (DynamicVGPRBlockSize != 0);
1453 if (DynamicVGPREnabled)
1454 return 0;
1455
1456 GPUKind Kind = parseArchAMDGCN(STI.getCPU());
1457 unsigned MaxWavesPerEU = getMaxWavesPerEU(Kind);
1458 if (WavesPerEU >= MaxWavesPerEU)
1459 return 0;
1460
1461 unsigned TotNumVGPRs = AMDGPU::getTotalNumVGPRs(
1462 Kind, STI.getFeatureBits().test(FeatureWavefrontSize32));
1463 unsigned AddrsableNumVGPRs =
1464 getAddressableNumVGPRs(STI, DynamicVGPRBlockSize);
1465 unsigned Granule = getVGPRAllocGranule(STI, DynamicVGPRBlockSize);
1466 unsigned MaxNumVGPRs = alignDown(TotNumVGPRs / WavesPerEU, Granule);
1467
1468 if (MaxNumVGPRs == alignDown(TotNumVGPRs / MaxWavesPerEU, Granule))
1469 return 0;
1470
1471 unsigned MinWavesPerEU = getNumWavesPerEUWithNumVGPRs(STI, AddrsableNumVGPRs,
1472 DynamicVGPRBlockSize);
1473 if (WavesPerEU < MinWavesPerEU)
1474 return getMinNumVGPRs(STI, MinWavesPerEU, DynamicVGPRBlockSize);
1475
1476 unsigned MaxNumVGPRsNext = alignDown(TotNumVGPRs / (WavesPerEU + 1), Granule);
1477 unsigned MinNumVGPRs = 1 + std::min(MaxNumVGPRs - Granule, MaxNumVGPRsNext);
1478 return std::min(MinNumVGPRs, AddrsableNumVGPRs);
1479}
1480
1481unsigned getMaxNumVGPRs(const MCSubtargetInfo &STI, unsigned WavesPerEU,
1482 unsigned DynamicVGPRBlockSize) {
1483 assert(WavesPerEU != 0);
1484
1485 unsigned TotNumVGPRs = AMDGPU::getTotalNumVGPRs(
1486 parseArchAMDGCN(STI.getCPU()),
1487 STI.getFeatureBits().test(FeatureWavefrontSize32));
1488
1489 // In dynamic VGPR mode, WavesPerEU does not imply a VGPR limit.
1490 bool DynamicVGPREnabled = (DynamicVGPRBlockSize != 0);
1491 unsigned MaxNumVGPRs =
1492 DynamicVGPREnabled
1493 ? TotNumVGPRs
1494 : alignDown(TotNumVGPRs / WavesPerEU,
1495 getVGPRAllocGranule(STI, DynamicVGPRBlockSize));
1496 unsigned AddressableNumVGPRs =
1497 getAddressableNumVGPRs(STI, DynamicVGPRBlockSize);
1498 return std::min(MaxNumVGPRs, AddressableNumVGPRs);
1499}
1500
1502 unsigned NumVGPRs,
1503 unsigned DynamicVGPRBlockSize,
1504 std::optional<bool> EnableWavefrontSize32) {
1506 NumVGPRs,
1507 getVGPRAllocGranule(STI, DynamicVGPRBlockSize, EnableWavefrontSize32));
1508}
1509} // end namespace IsaInfo
1510
1512 const MCSubtargetInfo &STI) {
1514 KernelCode.amd_kernel_code_version_major = 1;
1515 KernelCode.amd_kernel_code_version_minor = 2;
1516 KernelCode.amd_machine_kind = 1; // AMD_MACHINE_KIND_AMDGPU
1517 KernelCode.amd_machine_version_major = Version.Major;
1518 KernelCode.amd_machine_version_minor = Version.Minor;
1519 KernelCode.amd_machine_version_stepping = Version.Stepping;
1521 if (STI.getFeatureBits().test(FeatureWavefrontSize32)) {
1522 KernelCode.wavefront_size = 5;
1524 } else {
1525 KernelCode.wavefront_size = 6;
1526 }
1527
1528 // If the code object does not support indirect functions, then the value must
1529 // be 0xffffffff.
1530 KernelCode.call_convention = -1;
1531
1532 // These alignment values are specified in powers of two, so alignment =
1533 // 2^n. The minimum alignment is 2^4 = 16.
1534 KernelCode.kernarg_segment_alignment = 4;
1535 KernelCode.group_segment_alignment = 4;
1536 KernelCode.private_segment_alignment = 4;
1537
1538 if (Version.Major >= 10) {
1539 KernelCode.compute_pgm_resource_registers |=
1540 S_00B848_WGP_MODE(STI.getFeatureBits().test(FeatureCuMode) ? 0 : 1) |
1542 }
1543}
1544
1546 unsigned AS = GV->getAddressSpace();
1547 return AS == AMDGPUAS::CONSTANT_ADDRESS ||
1549}
1550
1552 return TT.getArch() == Triple::r600;
1553}
1554
1555static bool isValidRegPrefix(char C) {
1556 return C == 'v' || C == 's' || C == 'a';
1557}
1558
1559std::tuple<char, unsigned, unsigned> parseAsmPhysRegName(StringRef RegName) {
1560 if (RegName.empty())
1561 return {};
1562
1563 char Kind = RegName.front();
1564 if (!isValidRegPrefix(Kind))
1565 return {};
1566
1567 RegName = RegName.drop_front();
1568 if (RegName.consume_front("[")) {
1569 unsigned Idx, End;
1570 bool Failed = RegName.consumeInteger(10, Idx);
1571 Failed |= !RegName.consume_front(":");
1572 Failed |= RegName.consumeInteger(10, End);
1573 Failed |= !RegName.consume_back("]");
1574 if (!Failed) {
1575 unsigned NumRegs = End - Idx + 1;
1576 if (NumRegs > 1)
1577 return {Kind, Idx, NumRegs};
1578 }
1579 } else {
1580 unsigned Idx;
1581 bool Failed = RegName.getAsInteger(10, Idx);
1582 if (!Failed)
1583 return {Kind, Idx, 1};
1584 }
1585
1586 return {};
1587}
1588
1589std::tuple<char, unsigned, unsigned>
1591 StringRef RegName = Constraint;
1592 if (!RegName.consume_front("{") || !RegName.consume_back("}"))
1593 return {};
1595}
1596
1597std::pair<unsigned, unsigned>
1599 std::pair<unsigned, unsigned> Default,
1600 bool OnlyFirstRequired) {
1601 if (auto Attr = getIntegerPairAttribute(F, Name, OnlyFirstRequired))
1602 return {Attr->first, Attr->second.value_or(Default.second)};
1603 return Default;
1604}
1605
1606std::optional<std::pair<unsigned, std::optional<unsigned>>>
1608 bool OnlyFirstRequired) {
1609 Attribute A = F.getFnAttribute(Name);
1610 if (!A.isStringAttribute())
1611 return std::nullopt;
1612
1613 LLVMContext &Ctx = F.getContext();
1614 std::pair<unsigned, std::optional<unsigned>> Ints;
1615 std::pair<StringRef, StringRef> Strs = A.getValueAsString().split(',');
1616 if (Strs.first.trim().getAsInteger(0, Ints.first)) {
1617 Ctx.emitError("can't parse first integer attribute " + Name);
1618 return std::nullopt;
1619 }
1620 unsigned Second = 0;
1621 if (Strs.second.trim().getAsInteger(0, Second)) {
1622 if (!OnlyFirstRequired || !Strs.second.trim().empty()) {
1623 Ctx.emitError("can't parse second integer attribute " + Name);
1624 return std::nullopt;
1625 }
1626 } else {
1627 Ints.second = Second;
1628 }
1629
1630 return Ints;
1631}
1632
1634 unsigned Size,
1635 unsigned DefaultVal) {
1636 std::optional<SmallVector<unsigned>> R =
1638 return R.has_value() ? *R : SmallVector<unsigned>(Size, DefaultVal);
1639}
1640
1641std::optional<SmallVector<unsigned>>
1643 assert(Size > 2);
1644 LLVMContext &Ctx = F.getContext();
1645
1646 Attribute A = F.getFnAttribute(Name);
1647 if (!A.isValid())
1648 return std::nullopt;
1649 if (!A.isStringAttribute()) {
1650 Ctx.emitError(Name + " is not a string attribute");
1651 return std::nullopt;
1652 }
1653
1655
1656 StringRef S = A.getValueAsString();
1657 unsigned i = 0;
1658 for (; !S.empty() && i < Size; i++) {
1659 std::pair<StringRef, StringRef> Strs = S.split(',');
1660 unsigned IntVal;
1661 if (Strs.first.trim().getAsInteger(0, IntVal)) {
1662 Ctx.emitError("can't parse integer attribute " + Strs.first + " in " +
1663 Name);
1664 return std::nullopt;
1665 }
1666 Vals[i] = IntVal;
1667 S = Strs.second;
1668 }
1669
1670 if (!S.empty() || i < Size) {
1671 Ctx.emitError("attribute " + Name +
1672 " has incorrect number of integers; expected " +
1674 return std::nullopt;
1675 }
1676 return Vals;
1677}
1678
1680 return getIntegerVecAttribute(F, "amdgpu-max-num-workgroups", 3,
1681 std::numeric_limits<uint32_t>::max());
1682}
1683
1684bool hasValueInRangeLikeMetadata(const MDNode &MD, int64_t Val) {
1685 assert((MD.getNumOperands() % 2 == 0) && "invalid number of operands!");
1686 for (unsigned I = 0, E = MD.getNumOperands() / 2; I != E; ++I) {
1687 auto Low =
1688 mdconst::extract<ConstantInt>(MD.getOperand(2 * I + 0))->getValue();
1689 auto High =
1690 mdconst::extract<ConstantInt>(MD.getOperand(2 * I + 1))->getValue();
1691 // There are two types of [A; B) ranges:
1692 // A < B, e.g. [4; 5) which is a range that only includes 4.
1693 // A > B, e.g. [5; 4) which is a range that wraps around and includes
1694 // everything except 4.
1695 if (Low.ult(High)) {
1696 if (Low.ule(Val) && High.ugt(Val))
1697 return true;
1698 } else {
1699 if (Low.uge(Val) && High.ult(Val))
1700 return true;
1701 }
1702 }
1703
1704 return false;
1705}
1706
1708 return (1 << (getVmcntBitWidthLo(Version.Major) +
1709 getVmcntBitWidthHi(Version.Major))) -
1710 1;
1711}
1712
1714 return (1 << getLoadcntBitWidth(Version.Major)) - 1;
1715}
1716
1718 return (1 << getSamplecntBitWidth(Version.Major)) - 1;
1719}
1720
1722 return (1 << getBvhcntBitWidth(Version.Major)) - 1;
1723}
1724
1726 return (1 << getExpcntBitWidth(Version.Major)) - 1;
1727}
1728
1730 return (1 << getLgkmcntBitWidth(Version.Major)) - 1;
1731}
1732
1734 return (1 << getDscntBitWidth(Version.Major)) - 1;
1735}
1736
1738 return (1 << getKmcntBitWidth(Version.Major)) - 1;
1739}
1740
1742 return (1 << getXcntBitWidth(Version.Major, Version.Minor)) - 1;
1743}
1744
1746 return (1 << getAsynccntBitWidth(Version.Major, Version.Minor)) - 1;
1747}
1748
1750 return (1 << getStorecntBitWidth(Version.Major)) - 1;
1751}
1752
1754 return (1 << getBarrierMemberCountBitWidth(Version.Major)) - 1;
1755}
1756
1758 unsigned VmcntLo = getBitMask(getVmcntBitShiftLo(Version.Major),
1759 getVmcntBitWidthLo(Version.Major));
1760 unsigned Expcnt = getBitMask(getExpcntBitShift(Version.Major),
1761 getExpcntBitWidth(Version.Major));
1762 unsigned Lgkmcnt = getBitMask(getLgkmcntBitShift(Version.Major),
1763 getLgkmcntBitWidth(Version.Major));
1764 unsigned VmcntHi = getBitMask(getVmcntBitShiftHi(Version.Major),
1765 getVmcntBitWidthHi(Version.Major));
1766 return VmcntLo | Expcnt | Lgkmcnt | VmcntHi;
1767}
1768
1769unsigned decodeVmcnt(const IsaVersion &Version, unsigned Waitcnt) {
1770 unsigned VmcntLo = unpackBits(Waitcnt, getVmcntBitShiftLo(Version.Major),
1771 getVmcntBitWidthLo(Version.Major));
1772 unsigned VmcntHi = unpackBits(Waitcnt, getVmcntBitShiftHi(Version.Major),
1773 getVmcntBitWidthHi(Version.Major));
1774 return VmcntLo | VmcntHi << getVmcntBitWidthLo(Version.Major);
1775}
1776
1777unsigned decodeExpcnt(const IsaVersion &Version, unsigned Waitcnt) {
1778 return unpackBits(Waitcnt, getExpcntBitShift(Version.Major),
1779 getExpcntBitWidth(Version.Major));
1780}
1781
1782unsigned decodeLgkmcnt(const IsaVersion &Version, unsigned Waitcnt) {
1783 return unpackBits(Waitcnt, getLgkmcntBitShift(Version.Major),
1784 getLgkmcntBitWidth(Version.Major));
1785}
1786
1787unsigned decodeLoadcnt(const IsaVersion &Version, unsigned Waitcnt) {
1788 return unpackBits(Waitcnt, getLoadcntStorecntBitShift(Version.Major),
1789 getLoadcntBitWidth(Version.Major));
1790}
1791
1792unsigned decodeStorecnt(const IsaVersion &Version, unsigned Waitcnt) {
1793 return unpackBits(Waitcnt, getLoadcntStorecntBitShift(Version.Major),
1794 getStorecntBitWidth(Version.Major));
1795}
1796
1797unsigned decodeDscnt(const IsaVersion &Version, unsigned Waitcnt) {
1798 return unpackBits(Waitcnt, getDscntBitShift(Version.Major),
1799 getDscntBitWidth(Version.Major));
1800}
1801
1802void decodeWaitcnt(const IsaVersion &Version, unsigned Waitcnt, unsigned &Vmcnt,
1803 unsigned &Expcnt, unsigned &Lgkmcnt) {
1804 Vmcnt = decodeVmcnt(Version, Waitcnt);
1805 Expcnt = decodeExpcnt(Version, Waitcnt);
1806 Lgkmcnt = decodeLgkmcnt(Version, Waitcnt);
1807}
1808
1809unsigned encodeVmcnt(const IsaVersion &Version, unsigned Waitcnt,
1810 unsigned Vmcnt) {
1811 Waitcnt = packBits(Vmcnt, Waitcnt, getVmcntBitShiftLo(Version.Major),
1812 getVmcntBitWidthLo(Version.Major));
1813 return packBits(Vmcnt >> getVmcntBitWidthLo(Version.Major), Waitcnt,
1814 getVmcntBitShiftHi(Version.Major),
1815 getVmcntBitWidthHi(Version.Major));
1816}
1817
1818unsigned encodeExpcnt(const IsaVersion &Version, unsigned Waitcnt,
1819 unsigned Expcnt) {
1820 return packBits(Expcnt, Waitcnt, getExpcntBitShift(Version.Major),
1821 getExpcntBitWidth(Version.Major));
1822}
1823
1824unsigned encodeLgkmcnt(const IsaVersion &Version, unsigned Waitcnt,
1825 unsigned Lgkmcnt) {
1826 return packBits(Lgkmcnt, Waitcnt, getLgkmcntBitShift(Version.Major),
1827 getLgkmcntBitWidth(Version.Major));
1828}
1829
1830unsigned encodeWaitcnt(const IsaVersion &Version, unsigned Vmcnt,
1831 unsigned Expcnt, unsigned Lgkmcnt) {
1832 unsigned Waitcnt = getWaitcntBitMask(Version);
1834 Waitcnt = encodeExpcnt(Version, Waitcnt, Expcnt);
1835 Waitcnt = encodeLgkmcnt(Version, Waitcnt, Lgkmcnt);
1836 return Waitcnt;
1837}
1838
1840 bool IsStore) {
1841 unsigned Dscnt = getBitMask(getDscntBitShift(Version.Major),
1842 getDscntBitWidth(Version.Major));
1843 if (IsStore) {
1844 unsigned Storecnt = getBitMask(getLoadcntStorecntBitShift(Version.Major),
1845 getStorecntBitWidth(Version.Major));
1846 return Dscnt | Storecnt;
1847 }
1848 unsigned Loadcnt = getBitMask(getLoadcntStorecntBitShift(Version.Major),
1849 getLoadcntBitWidth(Version.Major));
1850 return Dscnt | Loadcnt;
1851}
1852
1853static unsigned encodeLoadcnt(const IsaVersion &Version, unsigned Waitcnt,
1854 unsigned Loadcnt) {
1855 return packBits(Loadcnt, Waitcnt, getLoadcntStorecntBitShift(Version.Major),
1856 getLoadcntBitWidth(Version.Major));
1857}
1858
1859static unsigned encodeStorecnt(const IsaVersion &Version, unsigned Waitcnt,
1860 unsigned Storecnt) {
1861 return packBits(Storecnt, Waitcnt, getLoadcntStorecntBitShift(Version.Major),
1862 getStorecntBitWidth(Version.Major));
1863}
1864
1865static unsigned encodeDscnt(const IsaVersion &Version, unsigned Waitcnt,
1866 unsigned Dscnt) {
1867 return packBits(Dscnt, Waitcnt, getDscntBitShift(Version.Major),
1868 getDscntBitWidth(Version.Major));
1869}
1870
1871unsigned encodeLoadcntDscnt(const IsaVersion &Version, unsigned Loadcnt,
1872 unsigned Dscnt) {
1873 unsigned Waitcnt = getCombinedCountBitMask(Version, false);
1874 Waitcnt = encodeLoadcnt(Version, Waitcnt, Loadcnt);
1876 return Waitcnt;
1877}
1878
1879unsigned encodeStorecntDscnt(const IsaVersion &Version, unsigned Storecnt,
1880 unsigned Dscnt) {
1881 unsigned Waitcnt = getCombinedCountBitMask(Version, true);
1882 Waitcnt = encodeStorecnt(Version, Waitcnt, Storecnt);
1884 return Waitcnt;
1885}
1886
1887//===----------------------------------------------------------------------===//
1888// Custom Operand Values
1889//===----------------------------------------------------------------------===//
1890
1892 int Size, unsigned Code,
1893 bool &HasNonDefaultVal,
1894 const MCSubtargetInfo &STI) {
1895 unsigned UsedOprMask = 0;
1896 HasNonDefaultVal = false;
1897 for (int Idx = 0; Idx < Size; ++Idx) {
1898 const auto &Op = Opr[Idx];
1899 if (!Op.isSupported(STI))
1900 continue;
1901 UsedOprMask |= Op.getMask();
1902 unsigned Val = Op.decode(Code);
1903 if (!Op.isValid(Val))
1904 return false;
1905 HasNonDefaultVal |= (Val != Op.Default);
1906 }
1907 return (Code & ~UsedOprMask) == 0;
1908}
1909
1910static bool decodeCustomOperand(const CustomOperandVal *Opr, int Size,
1911 unsigned Code, int &Idx, StringRef &Name,
1912 unsigned &Val, bool &IsDefault,
1913 const MCSubtargetInfo &STI) {
1914 while (Idx < Size) {
1915 const auto &Op = Opr[Idx++];
1916 if (Op.isSupported(STI)) {
1917 Name = Op.Name;
1918 Val = Op.decode(Code);
1919 IsDefault = (Val == Op.Default);
1920 return true;
1921 }
1922 }
1923
1924 return false;
1925}
1926
1928 int64_t InputVal) {
1929 if (InputVal < 0 || InputVal > Op.Max)
1930 return OPR_VAL_INVALID;
1931 return Op.encode(static_cast<unsigned>(InputVal));
1932}
1933
1934static int encodeCustomOperand(const CustomOperandVal *Opr, int Size,
1935 const StringRef Name, int64_t InputVal,
1936 unsigned &UsedOprMask,
1937 const MCSubtargetInfo &STI) {
1938 int InvalidId = OPR_ID_UNKNOWN;
1939 for (int Idx = 0; Idx < Size; ++Idx) {
1940 const auto &Op = Opr[Idx];
1941 if (Op.Name == Name) {
1942 if (!Op.isSupported(STI)) {
1943 InvalidId = OPR_ID_UNSUPPORTED;
1944 continue;
1945 }
1946 auto OprMask = Op.getMask();
1947 if (OprMask & UsedOprMask)
1948 return OPR_ID_DUPLICATE;
1949 UsedOprMask |= OprMask;
1950 return encodeCustomOperandVal(Op, InputVal);
1951 }
1952 }
1953 return InvalidId;
1954}
1955
1956//===----------------------------------------------------------------------===//
1957// DepCtr
1958//===----------------------------------------------------------------------===//
1959
1960namespace DepCtr {
1961
1963 unsigned Enc = 0;
1964 for (int Idx = 0; Idx < DEP_CTR_SIZE; ++Idx) {
1965 const auto &Op = DepCtrInfo[Idx];
1966 if (Op.isSupported(STI))
1967 Enc |= Op.encode(Op.Default);
1968 }
1969 return Enc;
1970}
1971
1972bool isSymbolicDepCtrEncoding(unsigned Code, bool &HasNonDefaultVal,
1973 const MCSubtargetInfo &STI) {
1975 HasNonDefaultVal, STI);
1976}
1977
1978bool decodeDepCtr(unsigned Code, int &Id, StringRef &Name, unsigned &Val,
1979 bool &IsDefault, const MCSubtargetInfo &STI) {
1980 return decodeCustomOperand(DepCtrInfo, DEP_CTR_SIZE, Code, Id, Name, Val,
1981 IsDefault, STI);
1982}
1983
1984int encodeDepCtr(const StringRef Name, int64_t Val, unsigned &UsedOprMask,
1985 const MCSubtargetInfo &STI) {
1986 return encodeCustomOperand(DepCtrInfo, DEP_CTR_SIZE, Name, Val, UsedOprMask,
1987 STI);
1988}
1989
1990unsigned getVaVdstBitMask() { return (1 << getVaVdstBitWidth()) - 1; }
1991
1992unsigned getVaSdstBitMask() { return (1 << getVaSdstBitWidth()) - 1; }
1993
1994unsigned getVaSsrcBitMask() { return (1 << getVaSsrcBitWidth()) - 1; }
1995
1997 return (1 << getHoldCntWidth(Version.Major, Version.Minor)) - 1;
1998}
1999
2000unsigned getVmVsrcBitMask() { return (1 << getVmVsrcBitWidth()) - 1; }
2001
2002unsigned getVaVccBitMask() { return (1 << getVaVccBitWidth()) - 1; }
2003
2004unsigned getSaSdstBitMask() { return (1 << getSaSdstBitWidth()) - 1; }
2005
2006unsigned decodeFieldVmVsrc(unsigned Encoded) {
2007 return unpackBits(Encoded, getVmVsrcBitShift(), getVmVsrcBitWidth());
2008}
2009
2010unsigned decodeFieldVaVdst(unsigned Encoded) {
2011 return unpackBits(Encoded, getVaVdstBitShift(), getVaVdstBitWidth());
2012}
2013
2014unsigned decodeFieldSaSdst(unsigned Encoded) {
2015 return unpackBits(Encoded, getSaSdstBitShift(), getSaSdstBitWidth());
2016}
2017
2018unsigned decodeFieldVaSdst(unsigned Encoded) {
2019 return unpackBits(Encoded, getVaSdstBitShift(), getVaSdstBitWidth());
2020}
2021
2022unsigned decodeFieldVaVcc(unsigned Encoded) {
2023 return unpackBits(Encoded, getVaVccBitShift(), getVaVccBitWidth());
2024}
2025
2026unsigned decodeFieldVaSsrc(unsigned Encoded) {
2027 return unpackBits(Encoded, getVaSsrcBitShift(), getVaSsrcBitWidth());
2028}
2029
2030unsigned decodeFieldHoldCnt(unsigned Encoded, const IsaVersion &Version) {
2031 return unpackBits(Encoded, getHoldCntBitShift(),
2032 getHoldCntWidth(Version.Major, Version.Minor));
2033}
2034
2035unsigned encodeFieldVmVsrc(unsigned Encoded, unsigned VmVsrc) {
2036 return packBits(VmVsrc, Encoded, getVmVsrcBitShift(), getVmVsrcBitWidth());
2037}
2038
2039unsigned encodeFieldVmVsrc(unsigned VmVsrc, const MCSubtargetInfo &STI) {
2040 unsigned Encoded = getDefaultDepCtrEncoding(STI);
2041 return encodeFieldVmVsrc(Encoded, VmVsrc);
2042}
2043
2044unsigned encodeFieldVaVdst(unsigned Encoded, unsigned VaVdst) {
2045 return packBits(VaVdst, Encoded, getVaVdstBitShift(), getVaVdstBitWidth());
2046}
2047
2048unsigned encodeFieldVaVdst(unsigned VaVdst, const MCSubtargetInfo &STI) {
2049 unsigned Encoded = getDefaultDepCtrEncoding(STI);
2050 return encodeFieldVaVdst(Encoded, VaVdst);
2051}
2052
2053unsigned encodeFieldSaSdst(unsigned Encoded, unsigned SaSdst) {
2054 return packBits(SaSdst, Encoded, getSaSdstBitShift(), getSaSdstBitWidth());
2055}
2056
2057unsigned encodeFieldSaSdst(unsigned SaSdst, const MCSubtargetInfo &STI) {
2058 unsigned Encoded = getDefaultDepCtrEncoding(STI);
2059 return encodeFieldSaSdst(Encoded, SaSdst);
2060}
2061
2062unsigned encodeFieldVaSdst(unsigned Encoded, unsigned VaSdst) {
2063 return packBits(VaSdst, Encoded, getVaSdstBitShift(), getVaSdstBitWidth());
2064}
2065
2066unsigned encodeFieldVaSdst(unsigned VaSdst, const MCSubtargetInfo &STI) {
2067 unsigned Encoded = getDefaultDepCtrEncoding(STI);
2068 return encodeFieldVaSdst(Encoded, VaSdst);
2069}
2070
2071unsigned encodeFieldVaVcc(unsigned Encoded, unsigned VaVcc) {
2072 return packBits(VaVcc, Encoded, getVaVccBitShift(), getVaVccBitWidth());
2073}
2074
2075unsigned encodeFieldVaVcc(unsigned VaVcc, const MCSubtargetInfo &STI) {
2076 unsigned Encoded = getDefaultDepCtrEncoding(STI);
2077 return encodeFieldVaVcc(Encoded, VaVcc);
2078}
2079
2080unsigned encodeFieldVaSsrc(unsigned Encoded, unsigned VaSsrc) {
2081 return packBits(VaSsrc, Encoded, getVaSsrcBitShift(), getVaSsrcBitWidth());
2082}
2083
2084unsigned encodeFieldVaSsrc(unsigned VaSsrc, const MCSubtargetInfo &STI) {
2085 unsigned Encoded = getDefaultDepCtrEncoding(STI);
2086 return encodeFieldVaSsrc(Encoded, VaSsrc);
2087}
2088
2089unsigned encodeFieldHoldCnt(unsigned Encoded, unsigned HoldCnt,
2090 const IsaVersion &Version) {
2091 return packBits(HoldCnt, Encoded, getHoldCntBitShift(),
2092 getHoldCntWidth(Version.Major, Version.Minor));
2093}
2094
2095unsigned encodeFieldHoldCnt(unsigned HoldCnt, const MCSubtargetInfo &STI) {
2096 unsigned Encoded = getDefaultDepCtrEncoding(STI);
2097 return encodeFieldHoldCnt(Encoded, HoldCnt, getIsaVersion(STI.getCPU()));
2098}
2099
2100} // namespace DepCtr
2101
2102//===----------------------------------------------------------------------===//
2103// exp tgt
2104//===----------------------------------------------------------------------===//
2105
2106namespace Exp {
2107
2108struct ExpTgt {
2110 unsigned Tgt;
2111 unsigned MaxIndex;
2112};
2113
2114// clang-format off
2115static constexpr ExpTgt ExpTgtInfo[] = {
2116 {{"null"}, ET_NULL, ET_NULL_MAX_IDX},
2117 {{"mrtz"}, ET_MRTZ, ET_MRTZ_MAX_IDX},
2118 {{"prim"}, ET_PRIM, ET_PRIM_MAX_IDX},
2119 {{"mrt"}, ET_MRT0, ET_MRT_MAX_IDX},
2120 {{"pos"}, ET_POS0, ET_POS_MAX_IDX},
2121 {{"dual_src_blend"},ET_DUAL_SRC_BLEND0, ET_DUAL_SRC_BLEND_MAX_IDX},
2122 {{"param"}, ET_PARAM0, ET_PARAM_MAX_IDX},
2123};
2124// clang-format on
2125
2126bool getTgtName(unsigned Id, StringRef &Name, int &Index) {
2127 for (const ExpTgt &Val : ExpTgtInfo) {
2128 if (Val.Tgt <= Id && Id <= Val.Tgt + Val.MaxIndex) {
2129 Index = (Val.MaxIndex == 0) ? -1 : (Id - Val.Tgt);
2130 Name = Val.Name;
2131 return true;
2132 }
2133 }
2134 return false;
2135}
2136
2137unsigned getTgtId(const StringRef Name) {
2138
2139 for (const ExpTgt &Val : ExpTgtInfo) {
2140 if (Val.MaxIndex == 0 && Name == Val.Name)
2141 return Val.Tgt;
2142
2143 if (Val.MaxIndex > 0 && Name.starts_with(Val.Name)) {
2144 StringRef Suffix = Name.drop_front(Val.Name.size());
2145
2146 unsigned Id;
2147 if (Suffix.getAsInteger(10, Id) || Id > Val.MaxIndex)
2148 return ET_INVALID;
2149
2150 // Disable leading zeroes
2151 if (Suffix.size() > 1 && Suffix[0] == '0')
2152 return ET_INVALID;
2153
2154 return Val.Tgt + Id;
2155 }
2156 }
2157 return ET_INVALID;
2158}
2159
2160bool isSupportedTgtId(unsigned Id, const MCSubtargetInfo &STI) {
2161 switch (Id) {
2162 case ET_NULL:
2163 return !isGFX11Plus(STI);
2164 case ET_POS4:
2165 case ET_PRIM:
2166 return isGFX10Plus(STI);
2167 case ET_DUAL_SRC_BLEND0:
2168 case ET_DUAL_SRC_BLEND1:
2169 return isGFX11Plus(STI);
2170 default:
2171 if (Id >= ET_PARAM0 && Id <= ET_PARAM31)
2172 return !isGFX11Plus(STI) || isGFX13Plus(STI);
2173 return true;
2174 }
2175}
2176
2177} // namespace Exp
2178
2179//===----------------------------------------------------------------------===//
2180// MTBUF Format
2181//===----------------------------------------------------------------------===//
2182
2183namespace MTBUFFormat {
2184
2185int64_t getDfmt(const StringRef Name) {
2186 for (int Id = DFMT_MIN; Id <= DFMT_MAX; ++Id) {
2187 if (Name == DfmtSymbolic[Id])
2188 return Id;
2189 }
2190 return DFMT_UNDEF;
2191}
2192
2194 assert(Id <= DFMT_MAX);
2195 return DfmtSymbolic[Id];
2196}
2197
2199 if (isSI(STI) || isCI(STI))
2200 return NfmtSymbolicSICI;
2201 if (isVI(STI) || isGFX9(STI))
2202 return NfmtSymbolicVI;
2203 return NfmtSymbolicGFX10;
2204}
2205
2206int64_t getNfmt(const StringRef Name, const MCSubtargetInfo &STI) {
2207 const auto *lookupTable = getNfmtLookupTable(STI);
2208 for (int Id = NFMT_MIN; Id <= NFMT_MAX; ++Id) {
2209 if (Name == lookupTable[Id])
2210 return Id;
2211 }
2212 return NFMT_UNDEF;
2213}
2214
2215StringRef getNfmtName(unsigned Id, const MCSubtargetInfo &STI) {
2216 assert(Id <= NFMT_MAX);
2217 return getNfmtLookupTable(STI)[Id];
2218}
2219
2220bool isValidDfmtNfmt(unsigned Id, const MCSubtargetInfo &STI) {
2221 unsigned Dfmt;
2222 unsigned Nfmt;
2223 decodeDfmtNfmt(Id, Dfmt, Nfmt);
2224 return isValidNfmt(Nfmt, STI);
2225}
2226
2227bool isValidNfmt(unsigned Id, const MCSubtargetInfo &STI) {
2228 return !getNfmtName(Id, STI).empty();
2229}
2230
2231int64_t encodeDfmtNfmt(unsigned Dfmt, unsigned Nfmt) {
2232 return (Dfmt << DFMT_SHIFT) | (Nfmt << NFMT_SHIFT);
2233}
2234
2235void decodeDfmtNfmt(unsigned Format, unsigned &Dfmt, unsigned &Nfmt) {
2236 Dfmt = (Format >> DFMT_SHIFT) & DFMT_MASK;
2237 Nfmt = (Format >> NFMT_SHIFT) & NFMT_MASK;
2238}
2239
2240int64_t getUnifiedFormat(const StringRef Name, const MCSubtargetInfo &STI) {
2241 if (isGFX11Plus(STI)) {
2242 for (int Id = UfmtGFX11::UFMT_FIRST; Id <= UfmtGFX11::UFMT_LAST; ++Id) {
2243 if (Name == UfmtSymbolicGFX11[Id])
2244 return Id;
2245 }
2246 } else {
2247 for (int Id = UfmtGFX10::UFMT_FIRST; Id <= UfmtGFX10::UFMT_LAST; ++Id) {
2248 if (Name == UfmtSymbolicGFX10[Id])
2249 return Id;
2250 }
2251 }
2252 return UFMT_UNDEF;
2253}
2254
2256 if (isValidUnifiedFormat(Id, STI))
2257 return isGFX10(STI) ? UfmtSymbolicGFX10[Id] : UfmtSymbolicGFX11[Id];
2258 return "";
2259}
2260
2261bool isValidUnifiedFormat(unsigned Id, const MCSubtargetInfo &STI) {
2262 return isGFX10(STI) ? Id <= UfmtGFX10::UFMT_LAST : Id <= UfmtGFX11::UFMT_LAST;
2263}
2264
2265int64_t convertDfmtNfmt2Ufmt(unsigned Dfmt, unsigned Nfmt,
2266 const MCSubtargetInfo &STI) {
2267 int64_t Fmt = encodeDfmtNfmt(Dfmt, Nfmt);
2268 if (isGFX11Plus(STI)) {
2269 for (int Id = UfmtGFX11::UFMT_FIRST; Id <= UfmtGFX11::UFMT_LAST; ++Id) {
2270 if (Fmt == DfmtNfmt2UFmtGFX11[Id])
2271 return Id;
2272 }
2273 } else {
2274 for (int Id = UfmtGFX10::UFMT_FIRST; Id <= UfmtGFX10::UFMT_LAST; ++Id) {
2275 if (Fmt == DfmtNfmt2UFmtGFX10[Id])
2276 return Id;
2277 }
2278 }
2279 return UFMT_UNDEF;
2280}
2281
2282bool isValidFormatEncoding(unsigned Val, const MCSubtargetInfo &STI) {
2283 return isGFX10Plus(STI) ? (Val <= UFMT_MAX) : (Val <= DFMT_NFMT_MAX);
2284}
2285
2287 if (isGFX10Plus(STI))
2288 return UFMT_DEFAULT;
2289 return DFMT_NFMT_DEFAULT;
2290}
2291
2292} // namespace MTBUFFormat
2293
2294//===----------------------------------------------------------------------===//
2295// SendMsg
2296//===----------------------------------------------------------------------===//
2297
2298namespace SendMsg {
2299
2303
2304bool isValidMsgId(int64_t MsgId, const MCSubtargetInfo &STI) {
2305 return (MsgId & ~(getMsgIdMask(STI))) == 0;
2306}
2307
2308bool isValidMsgOp(int64_t MsgId, int64_t OpId, const MCSubtargetInfo &STI,
2309 bool Strict) {
2310 assert(isValidMsgId(MsgId, STI));
2311
2312 if (!Strict)
2313 return 0 <= OpId && isUInt<OP_WIDTH_>(OpId);
2314
2315 if (msgRequiresOp(MsgId, STI)) {
2316 if (MsgId == ID_GS_PreGFX11 && OpId == OP_GS_NOP)
2317 return false;
2318
2319 return !getMsgOpName(MsgId, OpId, STI).empty();
2320 }
2321
2322 return OpId == OP_NONE_;
2323}
2324
2325bool isValidMsgStream(int64_t MsgId, int64_t OpId, int64_t StreamId,
2326 const MCSubtargetInfo &STI, bool Strict) {
2327 assert(isValidMsgOp(MsgId, OpId, STI, Strict));
2328
2329 if (!Strict)
2331
2332 if (!isGFX11Plus(STI)) {
2333 switch (MsgId) {
2334 case ID_GS_PreGFX11:
2337 return (OpId == OP_GS_NOP)
2340 }
2341 }
2342 return StreamId == STREAM_ID_NONE_;
2343}
2344
2345bool msgRequiresOp(int64_t MsgId, const MCSubtargetInfo &STI) {
2346 return MsgId == ID_SYSMSG ||
2347 (!isGFX11Plus(STI) &&
2348 (MsgId == ID_GS_PreGFX11 || MsgId == ID_GS_DONE_PreGFX11));
2349}
2350
2351bool msgSupportsStream(int64_t MsgId, int64_t OpId,
2352 const MCSubtargetInfo &STI) {
2353 return !isGFX11Plus(STI) &&
2354 (MsgId == ID_GS_PreGFX11 || MsgId == ID_GS_DONE_PreGFX11) &&
2355 OpId != OP_GS_NOP;
2356}
2357
2358void decodeMsg(unsigned Val, uint16_t &MsgId, uint16_t &OpId,
2359 uint16_t &StreamId, const MCSubtargetInfo &STI) {
2360 MsgId = static_cast<uint16_t>(Val & getMsgIdMask(STI));
2361 if (isGFX11Plus(STI)) {
2362 OpId = 0;
2363 StreamId = 0;
2364 } else {
2365 OpId = (Val & OP_MASK_) >> OP_SHIFT_;
2367 }
2368}
2369
2371 return MsgId | (OpId << OP_SHIFT_) | (StreamId << STREAM_ID_SHIFT_);
2372}
2373
2374bool msgDoesNotUseM0(int64_t MsgId, const MCSubtargetInfo &STI) {
2375 // Explicitly list message types that are known to not use m0.
2376 // This is safer than excluding only GS_ALLOC_REQ, in case new message
2377 // types are added in the future that do use m0.
2378 if (isGFX11Plus(STI)) {
2379 switch (MsgId) {
2381 return true;
2382 default:
2383 break;
2384 }
2385 }
2386 switch (MsgId) {
2387 case ID_SAVEWAVE:
2388 case ID_STALL_WAVE_GEN:
2389 case ID_HALT_WAVES:
2390 case ID_ORDERED_PS_DONE:
2392 case ID_GET_DOORBELL:
2393 case ID_GET_DDID:
2394 case ID_SYSMSG:
2395 return true;
2396 default:
2397 return false;
2398 }
2399}
2400
2401} // namespace SendMsg
2402
2403//===----------------------------------------------------------------------===//
2404//
2405//===----------------------------------------------------------------------===//
2406
2408 return static_cast<unsigned>(
2409 F.getFnAttributeAsParsedInteger("InitialPSInputAddr", 0));
2410}
2411
2413 // As a safe default always respond as if PS has color exports.
2414 return F.getFnAttributeAsParsedInteger(
2415 "amdgpu-color-export",
2416 F.getCallingConv() == CallingConv::AMDGPU_PS ? 1 : 0) != 0;
2417}
2418
2420 return F.getFnAttributeAsParsedInteger("amdgpu-depth-export", 0) != 0;
2421}
2422
2424 unsigned BlockSize = static_cast<unsigned>(
2425 F.getFnAttributeAsParsedInteger("amdgpu-dynamic-vgpr-block-size", 0));
2426
2427 if (BlockSize == 16 || BlockSize == 32)
2428 return BlockSize;
2429
2430 return 0;
2431}
2432
2434 return STI.hasFeature(AMDGPU::FeatureMIMG_R128) &&
2435 !STI.hasFeature(AMDGPU::FeatureR128A16);
2436}
2437
2438bool hasA16(const MCSubtargetInfo &STI) {
2439 return STI.hasFeature(AMDGPU::FeatureA16);
2440}
2441
2442bool hasG16(const MCSubtargetInfo &STI) {
2443 return STI.hasFeature(AMDGPU::FeatureG16);
2444}
2445
2447 return !STI.hasFeature(AMDGPU::FeatureUnpackedD16VMem) && !isCI(STI) &&
2448 !isSI(STI);
2449}
2450
2451bool hasGDS(const MCSubtargetInfo &STI) {
2452 return STI.hasFeature(AMDGPU::FeatureGDS);
2453}
2454
2455unsigned getNSAMaxSize(const MCSubtargetInfo &STI, bool HasSampler) {
2456 auto Version = getIsaVersion(STI.getCPU());
2457 if (Version.Major == 10)
2458 return Version.Minor >= 3 ? 13 : 5;
2459 if (Version.Major == 11)
2460 return 5;
2461 if (Version.Major >= 12)
2462 return HasSampler ? 4 : 5;
2463 return 0;
2464}
2465
2467 if (isGFX1250Plus(STI))
2468 return 32;
2469 return 16;
2470}
2471
2472bool isSI(const MCSubtargetInfo &STI) {
2473 return STI.hasFeature(AMDGPU::FeatureSouthernIslands);
2474}
2475
2476bool isCI(const MCSubtargetInfo &STI) {
2477 return STI.hasFeature(AMDGPU::FeatureSeaIslands);
2478}
2479
2480bool isVI(const MCSubtargetInfo &STI) {
2481 return STI.hasFeature(AMDGPU::FeatureVolcanicIslands);
2482}
2483
2484bool isGFX9(const MCSubtargetInfo &STI) {
2485 return STI.hasFeature(AMDGPU::FeatureGFX9);
2486}
2487
2489 return isGFX9(STI) || isGFX10(STI);
2490}
2491
2493 return isGFX9(STI) || isGFX10(STI) || isGFX11(STI);
2494}
2495
2497 return isVI(STI) || isGFX9(STI) || isGFX10(STI);
2498}
2499
2500bool isGFX8Plus(const MCSubtargetInfo &STI) {
2501 return isVI(STI) || isGFX9Plus(STI);
2502}
2503
2504bool isGFX9Plus(const MCSubtargetInfo &STI) {
2505 return isGFX9(STI) || isGFX10Plus(STI);
2506}
2507
2508bool isNotGFX9Plus(const MCSubtargetInfo &STI) { return !isGFX9Plus(STI); }
2509
2511 return STI.hasFeature(AMDGPU::FeaturePopsExitingWaveID);
2512}
2513
2515 return STI.hasFeature(AMDGPU::FeatureApertureRegs) &&
2516 !STI.hasFeature(AMDGPU::FeatureGloballyAddressableScratch);
2517}
2518
2519bool isGFX10(const MCSubtargetInfo &STI) {
2520 return STI.hasFeature(AMDGPU::FeatureGFX10);
2521}
2522
2524 return isGFX10(STI) || isGFX11(STI);
2525}
2526
2528 return isGFX10(STI) || isGFX11Plus(STI);
2529}
2530
2531bool isGFX11(const MCSubtargetInfo &STI) {
2532 return STI.hasFeature(AMDGPU::FeatureGFX11);
2533}
2534
2536 return isGFX11(STI) || isGFX12Plus(STI);
2537}
2538
2539bool isGFX12(const MCSubtargetInfo &STI) {
2540 return STI.getFeatureBits()[AMDGPU::FeatureGFX12];
2541}
2542
2544 return isGFX12(STI) || isGFX13Plus(STI);
2545}
2546
2547bool isNotGFX12Plus(const MCSubtargetInfo &STI) { return !isGFX12Plus(STI); }
2548
2549bool isGFX1250(const MCSubtargetInfo &STI) {
2550 return STI.getFeatureBits()[AMDGPU::FeatureGFX1250Insts] && !isGFX13(STI);
2551}
2552
2554 return isGFX1250(STI) || !STI.getFeatureBits().test(FeatureCuMode);
2555}
2556
2558 return STI.getFeatureBits()[AMDGPU::FeatureGFX1250Insts];
2559}
2560
2561bool isGFX13(const MCSubtargetInfo &STI) {
2562 return STI.getFeatureBits()[AMDGPU::FeatureGFX13];
2563}
2564
2565bool isGFX13Plus(const MCSubtargetInfo &STI) { return isGFX13(STI); }
2566
2568 if (isGFX1250(STI))
2569 return false;
2570 return isGFX10Plus(STI);
2571}
2572
2573bool isNotGFX11Plus(const MCSubtargetInfo &STI) { return !isGFX11Plus(STI); }
2574
2576 return isSI(STI) || isCI(STI) || isVI(STI) || isGFX9(STI);
2577}
2578
2580 return isGFX10(STI) && !AMDGPU::isGFX10_BEncoding(STI);
2581}
2582
2584 return STI.hasFeature(AMDGPU::FeatureGCN3Encoding);
2585}
2586
2588 return STI.hasFeature(AMDGPU::FeatureGFX10_BEncoding);
2589}
2590
2592 return STI.hasFeature(AMDGPU::FeatureGFX10_3Insts);
2593}
2594
2596 return isGFX10_BEncoding(STI) && !isGFX12Plus(STI);
2597}
2598
2599bool isGFX90A(const MCSubtargetInfo &STI) {
2600 return STI.hasFeature(AMDGPU::FeatureGFX90AInsts);
2601}
2602
2603bool isGFX940(const MCSubtargetInfo &STI) {
2604 return STI.hasFeature(AMDGPU::FeatureGFX940Insts);
2605}
2606
2608 return STI.hasFeature(AMDGPU::FeatureArchitectedFlatScratch);
2609}
2610
2612 return STI.hasFeature(AMDGPU::FeatureMAIInsts);
2613}
2614
2615bool hasVOPD(const MCSubtargetInfo &STI) {
2616 return STI.hasFeature(AMDGPU::FeatureVOPDInsts);
2617}
2618
2620 return STI.hasFeature(AMDGPU::FeatureDPPSrc1SGPR);
2621}
2622
2624 return STI.hasFeature(AMDGPU::FeatureKernargPreload);
2625}
2626
2627uint32_t getTotalNumVGPRs(bool has90AInsts, uint32_t ArgNumAGPR,
2628 uint32_t ArgNumVGPR) {
2629 if (has90AInsts && ArgNumAGPR)
2630 return alignTo(ArgNumVGPR, 4) + ArgNumAGPR;
2631 return std::max(ArgNumVGPR, ArgNumAGPR);
2632}
2633
2635 const MCRegisterClass &SGPRClass =
2636 TRI->getRegClass(AMDGPU::SReg_32RegClassID);
2637 const MCRegister FirstSubReg = TRI->getSubReg(Reg, AMDGPU::sub0);
2638 return SGPRClass.contains(FirstSubReg != 0 ? FirstSubReg : Reg) ||
2639 Reg == AMDGPU::SCC;
2640}
2641
2643 return MRI.getRegClass(AMDGPU::RsrcReg32RegClassID).contains(Reg);
2644}
2645
2647 return MRI.getEncodingValue(Reg) & AMDGPU::HWEncoding::IS_HI16;
2648}
2649
2650#define MAP_REG2REG \
2651 using namespace AMDGPU; \
2652 switch (Reg.id()) { \
2653 default: \
2654 return Reg; \
2655 CASE_CI_VI(FLAT_SCR) \
2656 CASE_CI_VI(FLAT_SCR_LO) \
2657 CASE_CI_VI(FLAT_SCR_HI) \
2658 CASE_VI_GFX9PLUS(TTMP0) \
2659 CASE_VI_GFX9PLUS(TTMP1) \
2660 CASE_VI_GFX9PLUS(TTMP2) \
2661 CASE_VI_GFX9PLUS(TTMP3) \
2662 CASE_VI_GFX9PLUS(TTMP4) \
2663 CASE_VI_GFX9PLUS(TTMP5) \
2664 CASE_VI_GFX9PLUS(TTMP6) \
2665 CASE_VI_GFX9PLUS(TTMP7) \
2666 CASE_VI_GFX9PLUS(TTMP8) \
2667 CASE_VI_GFX9PLUS(TTMP9) \
2668 CASE_VI_GFX9PLUS(TTMP10) \
2669 CASE_VI_GFX9PLUS(TTMP11) \
2670 CASE_VI_GFX9PLUS(TTMP12) \
2671 CASE_VI_GFX9PLUS(TTMP13) \
2672 CASE_VI_GFX9PLUS(TTMP14) \
2673 CASE_VI_GFX9PLUS(TTMP15) \
2674 CASE_VI_GFX9PLUS(TTMP0_TTMP1) \
2675 CASE_VI_GFX9PLUS(TTMP2_TTMP3) \
2676 CASE_VI_GFX9PLUS(TTMP4_TTMP5) \
2677 CASE_VI_GFX9PLUS(TTMP6_TTMP7) \
2678 CASE_VI_GFX9PLUS(TTMP8_TTMP9) \
2679 CASE_VI_GFX9PLUS(TTMP10_TTMP11) \
2680 CASE_VI_GFX9PLUS(TTMP12_TTMP13) \
2681 CASE_VI_GFX9PLUS(TTMP14_TTMP15) \
2682 CASE_VI_GFX9PLUS(TTMP0_TTMP1_TTMP2_TTMP3) \
2683 CASE_VI_GFX9PLUS(TTMP4_TTMP5_TTMP6_TTMP7) \
2684 CASE_VI_GFX9PLUS(TTMP8_TTMP9_TTMP10_TTMP11) \
2685 CASE_VI_GFX9PLUS(TTMP12_TTMP13_TTMP14_TTMP15) \
2686 CASE_VI_GFX9PLUS(TTMP0_TTMP1_TTMP2_TTMP3_TTMP4_TTMP5_TTMP6_TTMP7) \
2687 CASE_VI_GFX9PLUS(TTMP4_TTMP5_TTMP6_TTMP7_TTMP8_TTMP9_TTMP10_TTMP11) \
2688 CASE_VI_GFX9PLUS(TTMP8_TTMP9_TTMP10_TTMP11_TTMP12_TTMP13_TTMP14_TTMP15) \
2689 CASE_VI_GFX9PLUS( \
2690 TTMP0_TTMP1_TTMP2_TTMP3_TTMP4_TTMP5_TTMP6_TTMP7_TTMP8_TTMP9_TTMP10_TTMP11_TTMP12_TTMP13_TTMP14_TTMP15) \
2691 CASE_GFXPRE11_GFX11PLUS(M0) \
2692 CASE_GFXPRE11_GFX11PLUS(SGPR_NULL) \
2693 CASE_GFXPRE11_GFX11PLUS_TO(SGPR_NULL64, SGPR_NULL) \
2694 }
2695
2696#define CASE_CI_VI(node) \
2697 assert(!isSI(STI)); \
2698 case node: \
2699 return isCI(STI) ? node##_ci : node##_vi;
2700
2701#define CASE_VI_GFX9PLUS(node) \
2702 case node: \
2703 return isGFX9Plus(STI) ? node##_gfx9plus : node##_vi;
2704
2705#define CASE_GFXPRE11_GFX11PLUS(node) \
2706 case node: \
2707 return isGFX11Plus(STI) ? node##_gfx11plus : node##_gfxpre11;
2708
2709#define CASE_GFXPRE11_GFX11PLUS_TO(node, result) \
2710 case node: \
2711 return isGFX11Plus(STI) ? result##_gfx11plus : result##_gfxpre11;
2712
2714 if (STI.getTargetTriple().getArch() == Triple::r600)
2715 return Reg;
2717}
2718
2719#undef CASE_CI_VI
2720#undef CASE_VI_GFX9PLUS
2721#undef CASE_GFXPRE11_GFX11PLUS
2722#undef CASE_GFXPRE11_GFX11PLUS_TO
2723
2724#define CASE_CI_VI(node) \
2725 case node##_ci: \
2726 case node##_vi: \
2727 return node;
2728#define CASE_VI_GFX9PLUS(node) \
2729 case node##_vi: \
2730 case node##_gfx9plus: \
2731 return node;
2732#define CASE_GFXPRE11_GFX11PLUS(node) \
2733 case node##_gfx11plus: \
2734 case node##_gfxpre11: \
2735 return node;
2736#define CASE_GFXPRE11_GFX11PLUS_TO(node, result)
2737
2739
2741 switch (Reg.id()) {
2742 case AMDGPU::SRC_SHARED_BASE_LO:
2743 case AMDGPU::SRC_SHARED_BASE:
2744 case AMDGPU::SRC_SHARED_LIMIT_LO:
2745 case AMDGPU::SRC_SHARED_LIMIT:
2746 case AMDGPU::SRC_PRIVATE_BASE_LO:
2747 case AMDGPU::SRC_PRIVATE_BASE:
2748 case AMDGPU::SRC_PRIVATE_LIMIT_LO:
2749 case AMDGPU::SRC_PRIVATE_LIMIT:
2750 case AMDGPU::SRC_FLAT_SCRATCH_BASE_LO:
2751 case AMDGPU::SRC_FLAT_SCRATCH_BASE_HI:
2752 case AMDGPU::SRC_POPS_EXITING_WAVE_ID:
2753 return true;
2754 case AMDGPU::SRC_VCCZ:
2755 case AMDGPU::SRC_EXECZ:
2756 case AMDGPU::SRC_SCC:
2757 return true;
2758 case AMDGPU::SGPR_NULL:
2759 return true;
2760 default:
2761 return false;
2762 }
2763}
2764
2765#undef CASE_CI_VI
2766#undef CASE_VI_GFX9PLUS
2767#undef CASE_GFXPRE11_GFX11PLUS
2768#undef CASE_GFXPRE11_GFX11PLUS_TO
2769#undef MAP_REG2REG
2770
2771bool isKImmOperand(const MCInstrDesc &Desc, unsigned OpNo) {
2772 assert(OpNo < Desc.NumOperands);
2773 unsigned OpType = Desc.operands()[OpNo].OperandType;
2774 return OpType >= AMDGPU::OPERAND_KIMM_FIRST &&
2775 OpType <= AMDGPU::OPERAND_KIMM_LAST;
2776}
2777
2778bool isSISrcFPOperand(const MCInstrDesc &Desc, unsigned OpNo) {
2779 assert(OpNo < Desc.NumOperands);
2780 unsigned OpType = Desc.operands()[OpNo].OperandType;
2781 switch (OpType) {
2797 return true;
2798 default:
2799 return false;
2800 }
2801}
2802
2803// Avoid using MCRegisterClass::getSize, since that function will go away
2804// (move from MC* level to Target* level). Return size in bits.
2805unsigned getRegBitWidth(unsigned RCID) {
2806 switch (RCID) {
2807 case AMDGPU::VGPR_16RegClassID:
2808 case AMDGPU::VGPR_16_Lo128RegClassID:
2809 case AMDGPU::SGPR_LO16RegClassID:
2810 case AMDGPU::AGPR_LO16RegClassID:
2811 return 16;
2812 case AMDGPU::SGPR_32RegClassID:
2813 case AMDGPU::VGPR_32RegClassID:
2814 case AMDGPU::VGPR_32_Lo256RegClassID:
2815 case AMDGPU::VRegOrLds_32RegClassID:
2816 case AMDGPU::AGPR_32RegClassID:
2817 case AMDGPU::VS_32RegClassID:
2818 case AMDGPU::AV_32RegClassID:
2819 case AMDGPU::SReg_32RegClassID:
2820 case AMDGPU::SReg_32_XM0RegClassID:
2821 case AMDGPU::SRegOrLds_32RegClassID:
2822 return 32;
2823 case AMDGPU::SGPR_64RegClassID:
2824 case AMDGPU::VS_64RegClassID:
2825 case AMDGPU::SReg_64RegClassID:
2826 case AMDGPU::VReg_64RegClassID:
2827 case AMDGPU::AReg_64RegClassID:
2828 case AMDGPU::SReg_64_XEXECRegClassID:
2829 case AMDGPU::VReg_64_Align2RegClassID:
2830 case AMDGPU::AReg_64_Align2RegClassID:
2831 case AMDGPU::AV_64RegClassID:
2832 case AMDGPU::AV_64_Align2RegClassID:
2833 case AMDGPU::VReg_64_Lo256_Align2RegClassID:
2834 case AMDGPU::VS_64_Lo256RegClassID:
2835 return 64;
2836 case AMDGPU::SGPR_96RegClassID:
2837 case AMDGPU::SReg_96RegClassID:
2838 case AMDGPU::VReg_96RegClassID:
2839 case AMDGPU::AReg_96RegClassID:
2840 case AMDGPU::VReg_96_Align2RegClassID:
2841 case AMDGPU::AReg_96_Align2RegClassID:
2842 case AMDGPU::AV_96RegClassID:
2843 case AMDGPU::AV_96_Align2RegClassID:
2844 case AMDGPU::VReg_96_Lo256_Align2RegClassID:
2845 return 96;
2846 case AMDGPU::SGPR_128RegClassID:
2847 case AMDGPU::SReg_128RegClassID:
2848 case AMDGPU::VReg_128RegClassID:
2849 case AMDGPU::AReg_128RegClassID:
2850 case AMDGPU::VReg_128_Align2RegClassID:
2851 case AMDGPU::AReg_128_Align2RegClassID:
2852 case AMDGPU::AV_128RegClassID:
2853 case AMDGPU::AV_128_Align2RegClassID:
2854 case AMDGPU::SReg_128_XNULLRegClassID:
2855 case AMDGPU::VReg_128_Lo256_Align2RegClassID:
2856 return 128;
2857 case AMDGPU::SGPR_160RegClassID:
2858 case AMDGPU::SReg_160RegClassID:
2859 case AMDGPU::VReg_160RegClassID:
2860 case AMDGPU::AReg_160RegClassID:
2861 case AMDGPU::VReg_160_Align2RegClassID:
2862 case AMDGPU::AReg_160_Align2RegClassID:
2863 case AMDGPU::AV_160RegClassID:
2864 case AMDGPU::AV_160_Align2RegClassID:
2865 case AMDGPU::VReg_160_Lo256_Align2RegClassID:
2866 return 160;
2867 case AMDGPU::SGPR_192RegClassID:
2868 case AMDGPU::SReg_192RegClassID:
2869 case AMDGPU::VReg_192RegClassID:
2870 case AMDGPU::AReg_192RegClassID:
2871 case AMDGPU::VReg_192_Align2RegClassID:
2872 case AMDGPU::AReg_192_Align2RegClassID:
2873 case AMDGPU::AV_192RegClassID:
2874 case AMDGPU::AV_192_Align2RegClassID:
2875 case AMDGPU::VReg_192_Lo256_Align2RegClassID:
2876 return 192;
2877 case AMDGPU::SGPR_224RegClassID:
2878 case AMDGPU::SReg_224RegClassID:
2879 case AMDGPU::VReg_224RegClassID:
2880 case AMDGPU::AReg_224RegClassID:
2881 case AMDGPU::VReg_224_Align2RegClassID:
2882 case AMDGPU::AReg_224_Align2RegClassID:
2883 case AMDGPU::AV_224RegClassID:
2884 case AMDGPU::AV_224_Align2RegClassID:
2885 case AMDGPU::VReg_224_Lo256_Align2RegClassID:
2886 return 224;
2887 case AMDGPU::SGPR_256RegClassID:
2888 case AMDGPU::SReg_256RegClassID:
2889 case AMDGPU::VReg_256RegClassID:
2890 case AMDGPU::AReg_256RegClassID:
2891 case AMDGPU::VReg_256_Align2RegClassID:
2892 case AMDGPU::AReg_256_Align2RegClassID:
2893 case AMDGPU::AV_256RegClassID:
2894 case AMDGPU::AV_256_Align2RegClassID:
2895 case AMDGPU::SReg_256_XNULLRegClassID:
2896 case AMDGPU::VReg_256_Lo256_Align2RegClassID:
2897 return 256;
2898 case AMDGPU::SGPR_288RegClassID:
2899 case AMDGPU::SReg_288RegClassID:
2900 case AMDGPU::VReg_288RegClassID:
2901 case AMDGPU::AReg_288RegClassID:
2902 case AMDGPU::VReg_288_Align2RegClassID:
2903 case AMDGPU::AReg_288_Align2RegClassID:
2904 case AMDGPU::AV_288RegClassID:
2905 case AMDGPU::AV_288_Align2RegClassID:
2906 case AMDGPU::VReg_288_Lo256_Align2RegClassID:
2907 return 288;
2908 case AMDGPU::SGPR_320RegClassID:
2909 case AMDGPU::SReg_320RegClassID:
2910 case AMDGPU::VReg_320RegClassID:
2911 case AMDGPU::AReg_320RegClassID:
2912 case AMDGPU::VReg_320_Align2RegClassID:
2913 case AMDGPU::AReg_320_Align2RegClassID:
2914 case AMDGPU::AV_320RegClassID:
2915 case AMDGPU::AV_320_Align2RegClassID:
2916 case AMDGPU::VReg_320_Lo256_Align2RegClassID:
2917 return 320;
2918 case AMDGPU::SGPR_352RegClassID:
2919 case AMDGPU::SReg_352RegClassID:
2920 case AMDGPU::VReg_352RegClassID:
2921 case AMDGPU::AReg_352RegClassID:
2922 case AMDGPU::VReg_352_Align2RegClassID:
2923 case AMDGPU::AReg_352_Align2RegClassID:
2924 case AMDGPU::AV_352RegClassID:
2925 case AMDGPU::AV_352_Align2RegClassID:
2926 case AMDGPU::VReg_352_Lo256_Align2RegClassID:
2927 return 352;
2928 case AMDGPU::SGPR_384RegClassID:
2929 case AMDGPU::SReg_384RegClassID:
2930 case AMDGPU::VReg_384RegClassID:
2931 case AMDGPU::AReg_384RegClassID:
2932 case AMDGPU::VReg_384_Align2RegClassID:
2933 case AMDGPU::AReg_384_Align2RegClassID:
2934 case AMDGPU::AV_384RegClassID:
2935 case AMDGPU::AV_384_Align2RegClassID:
2936 case AMDGPU::VReg_384_Lo256_Align2RegClassID:
2937 return 384;
2938 case AMDGPU::SGPR_512RegClassID:
2939 case AMDGPU::SReg_512RegClassID:
2940 case AMDGPU::VReg_512RegClassID:
2941 case AMDGPU::AReg_512RegClassID:
2942 case AMDGPU::VReg_512_Align2RegClassID:
2943 case AMDGPU::AReg_512_Align2RegClassID:
2944 case AMDGPU::AV_512RegClassID:
2945 case AMDGPU::AV_512_Align2RegClassID:
2946 case AMDGPU::VReg_512_Lo256_Align2RegClassID:
2947 return 512;
2948 case AMDGPU::SGPR_1024RegClassID:
2949 case AMDGPU::SReg_1024RegClassID:
2950 case AMDGPU::VReg_1024RegClassID:
2951 case AMDGPU::AReg_1024RegClassID:
2952 case AMDGPU::VReg_1024_Align2RegClassID:
2953 case AMDGPU::AReg_1024_Align2RegClassID:
2954 case AMDGPU::AV_1024RegClassID:
2955 case AMDGPU::AV_1024_Align2RegClassID:
2956 case AMDGPU::VReg_1024_Lo256_Align2RegClassID:
2957 return 1024;
2958 default:
2959 llvm_unreachable("Unexpected register class");
2960 }
2961}
2962
2963unsigned getRegBitWidth(const MCRegisterClass &RC) {
2964 return getRegBitWidth(RC.getID());
2965}
2966
2967bool isInlinableLiteral64(int64_t Literal, bool HasInv2Pi) {
2969 return true;
2970
2971 uint64_t Val = static_cast<uint64_t>(Literal);
2972 return (Val == llvm::bit_cast<uint64_t>(0.0)) ||
2973 (Val == llvm::bit_cast<uint64_t>(1.0)) ||
2974 (Val == llvm::bit_cast<uint64_t>(-1.0)) ||
2975 (Val == llvm::bit_cast<uint64_t>(0.5)) ||
2976 (Val == llvm::bit_cast<uint64_t>(-0.5)) ||
2977 (Val == llvm::bit_cast<uint64_t>(2.0)) ||
2978 (Val == llvm::bit_cast<uint64_t>(-2.0)) ||
2979 (Val == llvm::bit_cast<uint64_t>(4.0)) ||
2980 (Val == llvm::bit_cast<uint64_t>(-4.0)) ||
2981 (Val == 0x3fc45f306dc9c882 && HasInv2Pi);
2982}
2983
2984bool isInlinableLiteral32(int32_t Literal, bool HasInv2Pi) {
2986 return true;
2987
2988 // The actual type of the operand does not seem to matter as long
2989 // as the bits match one of the inline immediate values. For example:
2990 //
2991 // -nan has the hexadecimal encoding of 0xfffffffe which is -2 in decimal,
2992 // so it is a legal inline immediate.
2993 //
2994 // 1065353216 has the hexadecimal encoding 0x3f800000 which is 1.0f in
2995 // floating-point, so it is a legal inline immediate.
2996
2997 uint32_t Val = static_cast<uint32_t>(Literal);
2998 return (Val == llvm::bit_cast<uint32_t>(0.0f)) ||
2999 (Val == llvm::bit_cast<uint32_t>(1.0f)) ||
3000 (Val == llvm::bit_cast<uint32_t>(-1.0f)) ||
3001 (Val == llvm::bit_cast<uint32_t>(0.5f)) ||
3002 (Val == llvm::bit_cast<uint32_t>(-0.5f)) ||
3003 (Val == llvm::bit_cast<uint32_t>(2.0f)) ||
3004 (Val == llvm::bit_cast<uint32_t>(-2.0f)) ||
3005 (Val == llvm::bit_cast<uint32_t>(4.0f)) ||
3006 (Val == llvm::bit_cast<uint32_t>(-4.0f)) ||
3007 (Val == 0x3e22f983 && HasInv2Pi);
3008}
3009
3010bool isInlinableLiteralBF16(int16_t Literal, bool HasInv2Pi, bool *IsBF16) {
3011 if (!HasInv2Pi)
3012 return false;
3013 if (IsBF16)
3014 *IsBF16 = false;
3016 return true;
3017 uint16_t Val = static_cast<uint16_t>(Literal);
3018 if (IsBF16)
3019 *IsBF16 = true;
3020 return Val == 0x3F00 || // 0.5
3021 Val == 0xBF00 || // -0.5
3022 Val == 0x3F80 || // 1.0
3023 Val == 0xBF80 || // -1.0
3024 Val == 0x4000 || // 2.0
3025 Val == 0xC000 || // -2.0
3026 Val == 0x4080 || // 4.0
3027 Val == 0xC080 || // -4.0
3028 Val == 0x3E22; // 1.0 / (2.0 * pi)
3029}
3030
3031bool isInlinableLiteralI16(int32_t Literal, bool HasInv2Pi) {
3032 return isInlinableLiteral32(Literal, HasInv2Pi);
3033}
3034
3035bool isInlinableLiteralFP16(int16_t Literal, bool HasInv2Pi) {
3036 if (!HasInv2Pi)
3037 return false;
3039 return true;
3040 uint16_t Val = static_cast<uint16_t>(Literal);
3041 return Val == 0x3C00 || // 1.0
3042 Val == 0xBC00 || // -1.0
3043 Val == 0x3800 || // 0.5
3044 Val == 0xB800 || // -0.5
3045 Val == 0x4000 || // 2.0
3046 Val == 0xC000 || // -2.0
3047 Val == 0x4400 || // 4.0
3048 Val == 0xC400 || // -4.0
3049 Val == 0x3118; // 1/2pi
3050}
3051
3052std::optional<unsigned> getInlineEncodingV216(bool IsFloat, uint32_t Literal) {
3053 // Unfortunately, the Instruction Set Architecture Reference Guide is
3054 // misleading about how the inline operands work for (packed) 16-bit
3055 // instructions. In a nutshell, the actual HW behavior is:
3056 //
3057 // - integer encodings (-16 .. 64) are always produced as sign-extended
3058 // 32-bit values
3059 // - float encodings are produced as:
3060 // - for F16 instructions: corresponding half-precision float values in
3061 // the LSBs, 0 in the MSBs
3062 // - for UI16 instructions: corresponding single-precision float value
3063 int32_t Signed = static_cast<int32_t>(Literal);
3064 if (Signed >= 0 && Signed <= 64)
3065 return 128 + Signed;
3066
3067 if (Signed >= -16 && Signed <= -1)
3068 return 192 + std::abs(Signed);
3069
3070 if (IsFloat) {
3071 // clang-format off
3072 switch (Literal) {
3073 case 0x3800: return 240; // 0.5
3074 case 0xB800: return 241; // -0.5
3075 case 0x3C00: return 242; // 1.0
3076 case 0xBC00: return 243; // -1.0
3077 case 0x4000: return 244; // 2.0
3078 case 0xC000: return 245; // -2.0
3079 case 0x4400: return 246; // 4.0
3080 case 0xC400: return 247; // -4.0
3081 case 0x3118: return 248; // 1.0 / (2.0 * pi)
3082 default: break;
3083 }
3084 // clang-format on
3085 } else {
3086 // clang-format off
3087 switch (Literal) {
3088 case 0x3F000000: return 240; // 0.5
3089 case 0xBF000000: return 241; // -0.5
3090 case 0x3F800000: return 242; // 1.0
3091 case 0xBF800000: return 243; // -1.0
3092 case 0x40000000: return 244; // 2.0
3093 case 0xC0000000: return 245; // -2.0
3094 case 0x40800000: return 246; // 4.0
3095 case 0xC0800000: return 247; // -4.0
3096 case 0x3E22F983: return 248; // 1.0 / (2.0 * pi)
3097 default: break;
3098 }
3099 // clang-format on
3100 }
3101
3102 return {};
3103}
3104
3105// Encoding of the literal as an inline constant for a V_PK_*_IU16 instruction
3106// or nullopt.
3107std::optional<unsigned> getInlineEncodingV2I16(uint32_t Literal) {
3108 return getInlineEncodingV216(false, Literal);
3109}
3110
3111// Encoding of the literal as an inline constant for a V_PK_*_BF16 instruction
3112// or nullopt.
3113std::optional<unsigned> getInlineEncodingV2BF16(uint32_t Literal) {
3114 int32_t Signed = static_cast<int32_t>(Literal);
3115 if (Signed >= 0 && Signed <= 64)
3116 return 128 + Signed;
3117
3118 if (Signed >= -16 && Signed <= -1)
3119 return 192 + std::abs(Signed);
3120
3121 // clang-format off
3122 switch (Literal) {
3123 case 0x3F00: return 240; // 0.5
3124 case 0xBF00: return 241; // -0.5
3125 case 0x3F80: return 242; // 1.0
3126 case 0xBF80: return 243; // -1.0
3127 case 0x4000: return 244; // 2.0
3128 case 0xC000: return 245; // -2.0
3129 case 0x4080: return 246; // 4.0
3130 case 0xC080: return 247; // -4.0
3131 case 0x3E22: return 248; // 1.0 / (2.0 * pi)
3132 default: break;
3133 }
3134 // clang-format on
3135
3136 return std::nullopt;
3137}
3138
3139// Encoding of the literal as an inline constant for a V_PK_*_F16 instruction
3140// or nullopt.
3141std::optional<unsigned> getInlineEncodingV2F16(uint32_t Literal) {
3142 return getInlineEncodingV216(true, Literal);
3143}
3144
3145// Encoding of the literal as an inline constant for V_PK_FMAC_F16 instruction
3146// or nullopt. This accounts for different inline constant behavior:
3147// - Pre-GFX11: fp16 inline constants have the value in low 16 bits, 0 in high
3148// - GFX11+: fp16 inline constants are duplicated into both halves
3150 bool IsGFX11Plus) {
3151 // Pre-GFX11 behavior: f16 in low bits, 0 in high bits
3152 if (!IsGFX11Plus)
3153 return getInlineEncodingV216(/*IsFloat=*/true, Literal);
3154
3155 // GFX11+ behavior: f16 duplicated in both halves
3156 // First, check for sign-extended integer inline constants (-16 to 64)
3157 // These work the same across all generations
3158 int32_t Signed = static_cast<int32_t>(Literal);
3159 if (Signed >= 0 && Signed <= 64)
3160 return 128 + Signed;
3161
3162 if (Signed >= -16 && Signed <= -1)
3163 return 192 + std::abs(Signed);
3164
3165 // For float inline constants on GFX11+, both halves must be equal
3166 uint16_t Lo = static_cast<uint16_t>(Literal);
3167 uint16_t Hi = static_cast<uint16_t>(Literal >> 16);
3168 if (Lo != Hi)
3169 return std::nullopt;
3170 return getInlineEncodingV216(/*IsFloat=*/true, Lo);
3171}
3172
3173// Whether the given literal can be inlined for a V_PK_* instruction.
3175 switch (OpType) {
3178 return getInlineEncodingV216(false, Literal).has_value();
3181 return getInlineEncodingV216(true, Literal).has_value();
3183 llvm_unreachable("OPERAND_REG_IMM_V2FP16_SPLAT is not supported");
3188 return false;
3189 default:
3190 llvm_unreachable("bad packed operand type");
3191 }
3192}
3193
3194// Whether the given literal can be inlined for a V_PK_*_IU16 instruction.
3198
3199// Whether the given literal can be inlined for a V_PK_*_BF16 instruction.
3203
3204// Whether the given literal can be inlined for a V_PK_*_F16 instruction.
3208
3209// Whether the given literal can be inlined for V_PK_FMAC_F16 instruction.
3211 return getPKFMACF16InlineEncoding(Literal, IsGFX11Plus).has_value();
3212}
3213
3214bool isValid32BitLiteral(uint64_t Val, bool IsFP64) {
3215 if (IsFP64)
3216 return !Lo_32(Val);
3217
3218 return isUInt<32>(Val) || isInt<32>(Val);
3219}
3220
3221int64_t encode32BitLiteral(int64_t Imm, OperandType Type, bool IsLit) {
3222 switch (Type) {
3223 default:
3224 break;
3230 return Imm & 0xffff;
3244 return Lo_32(Imm);
3247 return IsLit ? Imm : Hi_32(Imm);
3248 }
3249 return Imm;
3250}
3251
3253 const Function *F = A->getParent();
3254
3255 // Arguments to compute shaders are never a source of divergence.
3256 CallingConv::ID CC = F->getCallingConv();
3257 switch (CC) {
3260 return true;
3271 // For non-compute shaders, SGPR inputs are marked with either inreg or
3272 // byval. Everything else is in VGPRs.
3273 return A->hasAttribute(Attribute::InReg) ||
3274 A->hasAttribute(Attribute::ByVal);
3275 default:
3276 // TODO: treat i1 as divergent?
3277 return A->hasAttribute(Attribute::InReg);
3278 }
3279}
3280
3281bool isArgPassedInSGPR(const CallBase *CB, unsigned ArgNo) {
3282 // Arguments to compute shaders are never a source of divergence.
3284 switch (CC) {
3287 return true;
3298 // For non-compute shaders, SGPR inputs are marked with either inreg or
3299 // byval. Everything else is in VGPRs.
3300 return CB->paramHasAttr(ArgNo, Attribute::InReg) ||
3301 CB->isByValArgument(ArgNo);
3302 default:
3303 return CB->paramHasAttr(ArgNo, Attribute::InReg);
3304 }
3305}
3306
3307static bool hasSMEMByteOffset(const MCSubtargetInfo &ST) {
3308 return isGCN3Encoding(ST) || isGFX10Plus(ST);
3309}
3310
3312 int64_t EncodedOffset) {
3313 if (isGFX12Plus(ST))
3314 return isUInt<23>(EncodedOffset);
3315
3316 return hasSMEMByteOffset(ST) ? isUInt<20>(EncodedOffset)
3317 : isUInt<8>(EncodedOffset);
3318}
3319
3321 int64_t EncodedOffset, bool IsBuffer) {
3322 if (isGFX12Plus(ST)) {
3323 if (IsBuffer && EncodedOffset < 0)
3324 return false;
3325 return isInt<24>(EncodedOffset);
3326 }
3327
3328 return !IsBuffer && hasSMRDSignedImmOffset(ST) && isInt<21>(EncodedOffset);
3329}
3330
3331static bool isDwordAligned(uint64_t ByteOffset) {
3332 return (ByteOffset & 3) == 0;
3333}
3334
3336 uint64_t ByteOffset) {
3337 if (hasSMEMByteOffset(ST))
3338 return ByteOffset;
3339
3340 assert(isDwordAligned(ByteOffset));
3341 return ByteOffset >> 2;
3342}
3343
3344std::optional<int64_t> getSMRDEncodedOffset(const MCSubtargetInfo &ST,
3345 int64_t ByteOffset, bool IsBuffer,
3346 bool HasSOffset) {
3347 // For unbuffered smem loads, it is illegal for the Immediate Offset to be
3348 // negative if the resulting (Offset + (M0 or SOffset or zero) is negative.
3349 // Handle case where SOffset is not present.
3350 if (!IsBuffer && !HasSOffset && ByteOffset < 0 && hasSMRDSignedImmOffset(ST))
3351 return std::nullopt;
3352
3353 if (isGFX12Plus(ST)) // 24 bit signed offsets
3354 return isInt<24>(ByteOffset) ? std::optional<int64_t>(ByteOffset)
3355 : std::nullopt;
3356
3357 // The signed version is always a byte offset.
3358 if (!IsBuffer && hasSMRDSignedImmOffset(ST)) {
3360 return isInt<20>(ByteOffset) ? std::optional<int64_t>(ByteOffset)
3361 : std::nullopt;
3362 }
3363
3364 if (!isDwordAligned(ByteOffset) && !hasSMEMByteOffset(ST))
3365 return std::nullopt;
3366
3367 int64_t EncodedOffset = convertSMRDOffsetUnits(ST, ByteOffset);
3368 return isLegalSMRDEncodedUnsignedOffset(ST, EncodedOffset)
3369 ? std::optional<int64_t>(EncodedOffset)
3370 : std::nullopt;
3371}
3372
3373std::optional<int64_t> getSMRDEncodedLiteralOffset32(const MCSubtargetInfo &ST,
3374 int64_t ByteOffset) {
3375 if (!isCI(ST) || !isDwordAligned(ByteOffset))
3376 return std::nullopt;
3377
3378 int64_t EncodedOffset = convertSMRDOffsetUnits(ST, ByteOffset);
3379 return isUInt<32>(EncodedOffset) ? std::optional<int64_t>(EncodedOffset)
3380 : std::nullopt;
3381}
3382
3384 if (ST.getFeatureBits().test(FeatureFlatOffsetBits12))
3385 return 12;
3386 if (ST.getFeatureBits().test(FeatureFlatOffsetBits24))
3387 return 24;
3388 return 13;
3389}
3390
3391namespace {
3392
3393struct SourceOfDivergence {
3394 unsigned Intr;
3395};
3396const SourceOfDivergence *lookupSourceOfDivergence(unsigned Intr);
3397
3398struct AlwaysUniform {
3399 unsigned Intr;
3400};
3401const AlwaysUniform *lookupAlwaysUniform(unsigned Intr);
3402
3403struct LDSDMAIntrinsic {
3404 unsigned Intr;
3405};
3406const LDSDMAIntrinsic *lookupLDSDMAIntrinsic(unsigned Intr);
3407
3408struct ExponentOnlyScaleIntrinsic {
3409 unsigned Intr;
3410 uint8_t ScaleArg;
3411};
3412const ExponentOnlyScaleIntrinsic *
3413lookupExponentOnlyScaleIntrinsic(unsigned Intr);
3414
3415#define GET_SourcesOfDivergence_IMPL
3416#define GET_UniformIntrinsics_IMPL
3417#define GET_LDSDMAIntrinsicTable_IMPL
3418#define GET_ExponentOnlyScaleIntrinsics_IMPL
3419#define GET_Gfx9BufferFormat_IMPL
3420#define GET_Gfx10BufferFormat_IMPL
3421#define GET_Gfx11PlusBufferFormat_IMPL
3422
3423#include "AMDGPUGenSearchableTables.inc"
3424
3425} // end anonymous namespace
3426
3427bool isIntrinsicSourceOfDivergence(unsigned IntrID) {
3428 return lookupSourceOfDivergence(IntrID);
3429}
3430
3431bool isIntrinsicAlwaysUniform(unsigned IntrID) {
3432 return lookupAlwaysUniform(IntrID);
3433}
3434
3435bool isTriviallyUniform(const Value *V, const Instruction *CtxI) {
3436 if (isa<Constant>(V))
3437 return true;
3438 if (const auto *A = dyn_cast<Argument>(V))
3439 return isArgPassedInSGPR(A);
3440 if (const auto *II = dyn_cast<IntrinsicInst>(V)) {
3441 if (!isIntrinsicAlwaysUniform(II->getIntrinsicID()))
3442 return false;
3443 // If II and CtxI are in different blocks then there is a possibility of a
3444 // temporal divergence.
3445 return II->getParent() == CtxI->getParent();
3446 }
3447 return false;
3448}
3449
3450bool isTriviallyUniform(const Use &U) {
3451 return isTriviallyUniform(U.get(), cast<Instruction>(U.getUser()));
3452}
3453
3454bool isLDSDMAIntrinsic(unsigned IntrID) {
3455 return lookupLDSDMAIntrinsic(IntrID);
3456}
3457
3458std::optional<unsigned> getExponentOnlyScaleArgIdx(unsigned IntrID) {
3459 if (const ExponentOnlyScaleIntrinsic *Info =
3460 lookupExponentOnlyScaleIntrinsic(IntrID))
3461 return Info->ScaleArg;
3462 return std::nullopt;
3463}
3464
3466 uint8_t NumComponents,
3467 uint8_t NumFormat,
3468 const MCSubtargetInfo &STI) {
3469 return isGFX11Plus(STI) ? getGfx11PlusBufferFormatInfo(
3470 BitsPerComp, NumComponents, NumFormat)
3471 : isGFX10(STI)
3472 ? getGfx10BufferFormatInfo(BitsPerComp, NumComponents, NumFormat)
3473 : getGfx9BufferFormatInfo(BitsPerComp, NumComponents, NumFormat);
3474}
3475
3477 const MCSubtargetInfo &STI) {
3478 return isGFX11Plus(STI) ? getGfx11PlusBufferFormatInfo(Format)
3479 : isGFX10(STI) ? getGfx10BufferFormatInfo(Format)
3480 : getGfx9BufferFormatInfo(Format);
3481}
3482
3484 const MCRegisterInfo &MRI) {
3485 const unsigned VGPRClasses[] = {
3486 AMDGPU::VGPR_16RegClassID, AMDGPU::VGPR_32RegClassID,
3487 AMDGPU::VReg_64RegClassID, AMDGPU::VReg_96RegClassID,
3488 AMDGPU::VReg_128RegClassID, AMDGPU::VReg_160RegClassID,
3489 AMDGPU::VReg_192RegClassID, AMDGPU::VReg_224RegClassID,
3490 AMDGPU::VReg_256RegClassID, AMDGPU::VReg_288RegClassID,
3491 AMDGPU::VReg_320RegClassID, AMDGPU::VReg_352RegClassID,
3492 AMDGPU::VReg_384RegClassID, AMDGPU::VReg_512RegClassID,
3493 AMDGPU::VReg_1024RegClassID};
3494
3495 for (unsigned RCID : VGPRClasses) {
3496 const MCRegisterClass &RC = MRI.getRegClass(RCID);
3497 if (RC.contains(Reg))
3498 return &RC;
3499 }
3500
3501 return nullptr;
3502}
3503
3505 unsigned Enc = MRI.getEncodingValue(Reg);
3506 unsigned Idx = Enc & AMDGPU::HWEncoding::REG_IDX_MASK;
3507 return Idx >> 8;
3508}
3509
3511 const MCRegisterInfo &MRI) {
3512 unsigned Enc = MRI.getEncodingValue(Reg);
3513 unsigned Idx = Enc & AMDGPU::HWEncoding::REG_IDX_MASK;
3514 if (Idx >= 0x100)
3515 return MCRegister();
3516
3518 if (!RC)
3519 return MCRegister();
3520
3521 Idx |= MSBs << 8;
3522 if (RC->getID() == AMDGPU::VGPR_16RegClassID) {
3523 // This class has 2048 registers with interleaved lo16 and hi16.
3524 Idx *= 2;
3526 ++Idx;
3527 }
3528
3529 return RC->getRegister(Idx);
3530}
3531
3532static std::optional<unsigned>
3534 bool HasSetregVGPRMSBFixup) {
3535 constexpr unsigned VGPRMSBShift =
3537
3538 auto [HwRegId, Offset, Size] = Hwreg::HwregEncoding::decode(Simm16);
3539 if (HwRegId != Hwreg::ID_MODE ||
3540 (!HasSetregVGPRMSBFixup && (Offset + Size) < VGPRMSBShift))
3541 return {};
3542 // If there is SetregVGPRMSBFixup then Offset is ignored.
3543 if (!HasSetregVGPRMSBFixup)
3544 Imm <<= Offset;
3545 Imm = (Imm & Hwreg::VGPR_MSB_MASK) >> VGPRMSBShift;
3546 if (!HasSetregVGPRMSBFixup)
3548 return llvm::rotr<uint8_t>(static_cast<uint8_t>(Imm), /*R=*/2);
3549}
3550
3551std::optional<unsigned> convertSetRegImmToVgprMSBs(const MachineInstr &MI,
3552 bool HasSetregVGPRMSBFixup) {
3553 assert(MI.getOpcode() == AMDGPU::S_SETREG_IMM32_B32);
3554 return convertSetRegImmToVgprMSBs(MI.getOperand(0).getImm(),
3555 MI.getOperand(1).getImm(),
3556 HasSetregVGPRMSBFixup);
3557}
3558
3559std::optional<unsigned> convertSetRegImmToVgprMSBs(const MCInst &MI,
3560 bool HasSetregVGPRMSBFixup) {
3561 assert(MI.getOpcode() == AMDGPU::S_SETREG_IMM32_B32_gfx12);
3562 return convertSetRegImmToVgprMSBs(MI.getOperand(0).getImm(),
3563 MI.getOperand(1).getImm(),
3564 HasSetregVGPRMSBFixup);
3565}
3566
3567std::pair<const AMDGPU::OpName *, const AMDGPU::OpName *>
3569 static const AMDGPU::OpName VOPOps[4] = {
3570 AMDGPU::OpName::src0, AMDGPU::OpName::src1, AMDGPU::OpName::src2,
3571 AMDGPU::OpName::vdst};
3572 static const AMDGPU::OpName VDSOps[4] = {
3573 AMDGPU::OpName::addr, AMDGPU::OpName::data0, AMDGPU::OpName::data1,
3574 AMDGPU::OpName::vdst};
3575 static const AMDGPU::OpName FLATOps[4] = {
3576 AMDGPU::OpName::vaddr, AMDGPU::OpName::vdata,
3577 AMDGPU::OpName::NUM_OPERAND_NAMES, AMDGPU::OpName::vdst};
3578 static const AMDGPU::OpName BUFOps[4] = {
3579 AMDGPU::OpName::vaddr, AMDGPU::OpName::NUM_OPERAND_NAMES,
3580 AMDGPU::OpName::NUM_OPERAND_NAMES, AMDGPU::OpName::vdata};
3581 static const AMDGPU::OpName VIMGOps[4] = {
3582 AMDGPU::OpName::vaddr0, AMDGPU::OpName::vaddr1, AMDGPU::OpName::vaddr2,
3583 AMDGPU::OpName::vdata};
3584
3585 // For VOPD instructions MSB of a corresponding Y component operand VGPR
3586 // address is supposed to match X operand, otherwise VOPD shall not be
3587 // combined.
3588 static const AMDGPU::OpName VOPDOpsX[4] = {
3589 AMDGPU::OpName::src0X, AMDGPU::OpName::vsrc1X, AMDGPU::OpName::vsrc2X,
3590 AMDGPU::OpName::vdstX};
3591 static const AMDGPU::OpName VOPDOpsY[4] = {
3592 AMDGPU::OpName::src0Y, AMDGPU::OpName::vsrc1Y, AMDGPU::OpName::vsrc2Y,
3593 AMDGPU::OpName::vdstY};
3594
3595 // VOP2 MADMK instructions use src0, imm, src1 scheme.
3596 static const AMDGPU::OpName VOP2MADMKOps[4] = {
3597 AMDGPU::OpName::src0, AMDGPU::OpName::NUM_OPERAND_NAMES,
3598 AMDGPU::OpName::src1, AMDGPU::OpName::vdst};
3599 static const AMDGPU::OpName VOPDFMAMKOpsX[4] = {
3600 AMDGPU::OpName::src0X, AMDGPU::OpName::NUM_OPERAND_NAMES,
3601 AMDGPU::OpName::vsrc1X, AMDGPU::OpName::vdstX};
3602 static const AMDGPU::OpName VOPDFMAMKOpsY[4] = {
3603 AMDGPU::OpName::src0Y, AMDGPU::OpName::NUM_OPERAND_NAMES,
3604 AMDGPU::OpName::vsrc1Y, AMDGPU::OpName::vdstY};
3605
3609 switch (Desc.getOpcode()) {
3610 // LD_SCALE operands ignore MSB.
3611 case AMDGPU::V_WMMA_LD_SCALE_PAIRED_B32:
3612 case AMDGPU::V_WMMA_LD_SCALE_PAIRED_B32_gfx1250:
3613 case AMDGPU::V_WMMA_LD_SCALE16_PAIRED_B64:
3614 case AMDGPU::V_WMMA_LD_SCALE16_PAIRED_B64_gfx1250:
3615 return {};
3616 case AMDGPU::V_FMAMK_F16:
3617 case AMDGPU::V_FMAMK_F16_t16:
3618 case AMDGPU::V_FMAMK_F16_t16_gfx12:
3619 case AMDGPU::V_FMAMK_F16_fake16:
3620 case AMDGPU::V_FMAMK_F16_fake16_gfx12:
3621 case AMDGPU::V_FMAMK_F32:
3622 case AMDGPU::V_FMAMK_F32_gfx12:
3623 case AMDGPU::V_FMAMK_F64:
3624 case AMDGPU::V_FMAMK_F64_gfx1250:
3625 return {VOP2MADMKOps, nullptr};
3626 default:
3627 break;
3628 }
3629 return {VOPOps, nullptr};
3630 }
3631
3633 return {VDSOps, nullptr};
3634
3636 return {FLATOps, nullptr};
3637
3639 return {BUFOps, nullptr};
3640
3642 return {VIMGOps, nullptr};
3643
3644 if (AMDGPU::isVOPD(Desc.getOpcode())) {
3645 auto [OpX, OpY] = getVOPDComponents(Desc.getOpcode());
3646 return {(OpX == AMDGPU::V_FMAMK_F32) ? VOPDFMAMKOpsX : VOPDOpsX,
3647 (OpY == AMDGPU::V_FMAMK_F32) ? VOPDFMAMKOpsY : VOPDOpsY};
3648 }
3649
3651
3653 llvm_unreachable("Sample and export VGPR lowering is not implemented and"
3654 " these instructions are not expected on gfx1250");
3655
3656 return {};
3657}
3658
3659bool supportsScaleOffset(const MCInstrInfo &MII, unsigned Opcode) {
3660 const MCInstrDesc &Desc = MII.get(Opcode);
3662 return Desc.mayLoad() && !Desc.mayStore() && !getSMEMIsBuffer(Opcode);
3664 return false;
3665
3666 // Only SV and SVS modes are supported.
3667 if (SIInstrFlags::isFlatScratch(MII, Opcode))
3668 return hasNamedOperand(Opcode, OpName::vaddr);
3669
3670 // Only GVS mode is supported.
3671 return hasNamedOperand(Opcode, OpName::vaddr) &&
3672 hasNamedOperand(Opcode, OpName::saddr);
3673
3674 return false;
3675}
3676
3677static bool hasAny64BitVGPROperands(const MCInstrDesc &OpDesc,
3678 const MCInstrInfo &MII,
3679 const MCSubtargetInfo &ST) {
3680 for (auto OpName : {OpName::vdst, OpName::src0, OpName::src1, OpName::src2}) {
3681 int Idx = getNamedOperandIdx(OpDesc.getOpcode(), OpName);
3682 if (Idx == -1)
3683 continue;
3684
3685 const MCOperandInfo &OpInfo = OpDesc.operands()[Idx];
3686 int16_t RegClass = MII.getOpRegClassID(
3687 OpInfo, ST.getHwMode(MCSubtargetInfo::HwMode_RegInfo));
3688 if (RegClass == AMDGPU::VReg_64RegClassID ||
3689 RegClass == AMDGPU::VReg_64_Align2RegClassID)
3690 return true;
3691 }
3692
3693 return false;
3694}
3695
3696bool isDPALU_DPP32BitOpc(unsigned Opc) {
3697 switch (Opc) {
3698 case AMDGPU::V_MUL_LO_U32_e64:
3699 case AMDGPU::V_MUL_LO_U32_e64_dpp:
3700 case AMDGPU::V_MUL_LO_U32_e64_dpp_gfx1250:
3701 case AMDGPU::V_MUL_HI_U32_e64:
3702 case AMDGPU::V_MUL_HI_U32_e64_dpp:
3703 case AMDGPU::V_MUL_HI_U32_e64_dpp_gfx1250:
3704 case AMDGPU::V_MUL_HI_I32_e64:
3705 case AMDGPU::V_MUL_HI_I32_e64_dpp:
3706 case AMDGPU::V_MUL_HI_I32_e64_dpp_gfx1250:
3707 case AMDGPU::V_MAD_U32_e64:
3708 case AMDGPU::V_MAD_U32_e64_dpp:
3709 case AMDGPU::V_MAD_U32_e64_dpp_gfx1250:
3710 return true;
3711 default:
3712 return false;
3713 }
3714}
3715
3716bool isDPALU_DPP(const MCInstrDesc &OpDesc, const MCInstrInfo &MII,
3717 const MCSubtargetInfo &ST) {
3718 if (isDPALU_DPP32BitOpc(OpDesc.getOpcode()))
3719 return true;
3720
3721 return hasAny64BitVGPROperands(OpDesc, MII, ST);
3722}
3723
3724bool isVOP3DPPSrc1RevOpc(const MCSubtargetInfo &STI, unsigned Opc) {
3725 switch (Opc) {
3726 // The integer subtracts are REV-type on every generation that has them.
3727 case AMDGPU::V_SUBREV_U32_e64_dpp:
3728 case AMDGPU::V_SUBREV_NC_U32_e64_dpp_gfx11:
3729 case AMDGPU::V_SUBREV_NC_U32_e64_dpp_gfx12:
3730 case AMDGPU::V_SUBREV_NC_U32_e64_dpp_gfx13:
3731 case AMDGPU::V_SUBREV_NC_U32_e64_dpp8_gfx11:
3732 case AMDGPU::V_SUBREV_NC_U32_e64_dpp8_gfx12:
3733 case AMDGPU::V_SUBREV_NC_U32_e64_dpp8_gfx13:
3734 case AMDGPU::V_SUBREV_CO_U32_e64_dpp:
3735 case AMDGPU::V_SUBREV_CO_U32_e64_dpp_gfx11:
3736 case AMDGPU::V_SUBREV_CO_U32_e64_dpp_gfx12:
3737 case AMDGPU::V_SUBREV_CO_U32_e64_dpp_gfx13:
3738 case AMDGPU::V_SUBREV_CO_U32_e64_dpp8_gfx11:
3739 case AMDGPU::V_SUBREV_CO_U32_e64_dpp8_gfx12:
3740 case AMDGPU::V_SUBREV_CO_U32_e64_dpp8_gfx13:
3741 case AMDGPU::V_SUBBREV_U32_e64_dpp:
3742 case AMDGPU::V_SUBREV_CO_CI_U32_e64_dpp_gfx11:
3743 case AMDGPU::V_SUBREV_CO_CI_U32_e64_dpp_gfx12:
3744 case AMDGPU::V_SUBREV_CO_CI_U32_e64_dpp_gfx13:
3745 case AMDGPU::V_SUBREV_CO_CI_U32_e64_dpp8_gfx11:
3746 case AMDGPU::V_SUBREV_CO_CI_U32_e64_dpp8_gfx12:
3747 case AMDGPU::V_SUBREV_CO_CI_U32_e64_dpp8_gfx13:
3748 return true;
3749
3750 // The 16- and 32-bit shift REVs are REV-type on GFX13 only. The 64-bit forms
3751 // are not, and are deliberately absent.
3752 case AMDGPU::V_ASHRREV_I32_e64_dpp_gfx13:
3753 case AMDGPU::V_ASHRREV_I32_e64_dpp8_gfx13:
3754 case AMDGPU::V_ASHRREV_I16_t16_e64_dpp_gfx13:
3755 case AMDGPU::V_ASHRREV_I16_t16_e64_dpp8_gfx13:
3756 case AMDGPU::V_ASHRREV_I16_fake16_e64_dpp_gfx13:
3757 case AMDGPU::V_ASHRREV_I16_fake16_e64_dpp8_gfx13:
3758 case AMDGPU::V_LSHLREV_B32_e64_dpp_gfx13:
3759 case AMDGPU::V_LSHLREV_B32_e64_dpp8_gfx13:
3760 case AMDGPU::V_LSHLREV_B16_t16_e64_dpp_gfx13:
3761 case AMDGPU::V_LSHLREV_B16_t16_e64_dpp8_gfx13:
3762 case AMDGPU::V_LSHLREV_B16_fake16_e64_dpp_gfx13:
3763 case AMDGPU::V_LSHLREV_B16_fake16_e64_dpp8_gfx13:
3764 case AMDGPU::V_LSHRREV_B32_e64_dpp_gfx13:
3765 case AMDGPU::V_LSHRREV_B32_e64_dpp8_gfx13:
3766 case AMDGPU::V_LSHRREV_B16_t16_e64_dpp_gfx13:
3767 case AMDGPU::V_LSHRREV_B16_t16_e64_dpp8_gfx13:
3768 case AMDGPU::V_LSHRREV_B16_fake16_e64_dpp_gfx13:
3769 case AMDGPU::V_LSHRREV_B16_fake16_e64_dpp8_gfx13:
3770 return true;
3771 // The pseudos are shared across generations, so ask the subtarget.
3772 case AMDGPU::V_ASHRREV_I32_e64_dpp:
3773 case AMDGPU::V_ASHRREV_I16_e64_dpp:
3774 case AMDGPU::V_ASHRREV_I16_t16_e64_dpp:
3775 case AMDGPU::V_ASHRREV_I16_fake16_e64_dpp:
3776 case AMDGPU::V_LSHLREV_B32_e64_dpp:
3777 case AMDGPU::V_LSHLREV_B16_e64_dpp:
3778 case AMDGPU::V_LSHLREV_B16_t16_e64_dpp:
3779 case AMDGPU::V_LSHLREV_B16_fake16_e64_dpp:
3780 case AMDGPU::V_LSHRREV_B32_e64_dpp:
3781 case AMDGPU::V_LSHRREV_B16_e64_dpp:
3782 case AMDGPU::V_LSHRREV_B16_t16_e64_dpp:
3783 case AMDGPU::V_LSHRREV_B16_fake16_e64_dpp:
3784 return isGFX13Plus(STI);
3785
3786 default:
3787 return false;
3788 }
3789}
3790
3792 switch (Opc) {
3793 case AMDGPU::V_PK_ADD_F32_gfx1250:
3794 case AMDGPU::V_PK_ADD_F32_gfx1250_gfx12:
3795 case AMDGPU::V_PK_MUL_F32_gfx1250:
3796 case AMDGPU::V_PK_MUL_F32_gfx1250_gfx12:
3797 case AMDGPU::V_PK_FMA_F32_gfx1250:
3798 case AMDGPU::V_PK_FMA_F32_gfx1250_gfx12:
3799 return true;
3800 default:
3801 return false;
3802 }
3803}
3804
3805// NOTE: This function is currently only used before pseudo-expansion.
3807 switch (Opc) {
3808 case AMDGPU::V_PK_ADD_F64:
3809 case AMDGPU::V_PK_MUL_F64:
3810 case AMDGPU::V_PK_FMA_F64:
3811 case AMDGPU::V_PK_MAX_NUM_F64:
3812 case AMDGPU::V_PK_MIN_NUM_F64:
3813 case AMDGPU::V_PK_ADD_NC_U64:
3814 case AMDGPU::V_PK_SUB_NC_U64:
3815 case AMDGPU::V_PK_LSHL_ADD_U64:
3816 return true;
3817 default:
3818 return false;
3819 }
3820}
3821
3825
3826const std::array<unsigned, 3> &ClusterDimsAttr::getDims() const {
3827 assert(isFixedDims() && "expect kind to be FixedDims");
3828 return Dims;
3829}
3830
3831std::string ClusterDimsAttr::to_string() const {
3832 SmallString<10> Buffer;
3833 raw_svector_ostream OS(Buffer);
3834
3835 switch (getKind()) {
3836 case Kind::Unknown:
3837 return "";
3838 case Kind::NoCluster: {
3839 OS << EncoNoCluster << ',' << EncoNoCluster << ',' << EncoNoCluster;
3840 return Buffer.c_str();
3841 }
3842 case Kind::VariableDims: {
3843 OS << EncoVariableDims << ',' << EncoVariableDims << ','
3844 << EncoVariableDims;
3845 return Buffer.c_str();
3846 }
3847 case Kind::FixedDims: {
3848 OS << Dims[0] << ',' << Dims[1] << ',' << Dims[2];
3849 return Buffer.c_str();
3850 }
3851 }
3852 llvm_unreachable("Unknown ClusterDimsAttr kind");
3853}
3854
3856 std::optional<SmallVector<unsigned>> Attr =
3857 getIntegerVecAttribute(F, "amdgpu-cluster-dims", /*Size=*/3);
3859
3860 if (!Attr.has_value())
3861 AttrKind = Kind::Unknown;
3862 else if (all_of(*Attr, equal_to(EncoNoCluster)))
3863 AttrKind = Kind::NoCluster;
3864 else if (all_of(*Attr, equal_to(EncoVariableDims)))
3865 AttrKind = Kind::VariableDims;
3866
3867 ClusterDimsAttr A(AttrKind);
3868 if (AttrKind == Kind::FixedDims)
3869 A.Dims = {(*Attr)[0], (*Attr)[1], (*Attr)[2]};
3870
3871 return A;
3872}
3873
3874std::optional<APFloat> evaluateRcp(const APFloat &Val) {
3875 const fltSemantics &Sem = Val.getSemantics();
3876
3877 // v_rcp_f16/bf16 are correctly rounded.
3878 if (&Sem == &APFloat::IEEEhalf() || &Sem == &APFloat::BFloat())
3879 return APFloat::getOne(Sem) / Val;
3880
3881 // v_rcp_f32/f64 always flush a denormal input to zero (preserving sign)
3882 // before reciprocating.
3883 APFloat Arg = Val;
3884 if (Arg.isDenormal())
3885 Arg = APFloat::getZero(Sem, Arg.isNegative());
3886
3887 APFloat Result = APFloat::getOne(Sem) / Arg;
3888
3889 // v_rcp_f32/f64 always flush a denormal result to zero (preserving sign).
3890 if (Result.isDenormal())
3891 Result = APFloat::getZero(Sem, Result.isNegative());
3892
3893 // v_rcp_f32/f64 only approximate the reciprocal, except for these special
3894 // cases where the result is exact.
3895 if (!Result.isZero() && !Result.isInfinity() && !Result.isNaN() &&
3896 !Result.isOne() && !Result.isMinusOne())
3897 return std::nullopt;
3898
3899 return Result;
3900}
3901
3902} // namespace AMDGPU
3903
3905 switch (S) {
3906 case (AMDGPU::TargetIDSetting::Unsupported):
3907 OS << "Unsupported";
3908 break;
3909 case (AMDGPU::TargetIDSetting::Any):
3910 OS << "Any";
3911 break;
3912 case (AMDGPU::TargetIDSetting::Off):
3913 OS << "Off";
3914 break;
3915 case (AMDGPU::TargetIDSetting::On):
3916 OS << "On";
3917 break;
3918 }
3919 return OS;
3920}
3921
3922} // 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)
unsigned Opc
#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:1502
#define S_00B848_WGP_MODE(x)
Definition SIDefines.h:1499
#define S_00B848_FWD_PROGRESS(x)
Definition SIDefines.h:1505
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 constexpr const fltSemantics & IEEEhalf()
Definition APFloat.h:302
static constexpr const fltSemantics & BFloat()
Definition APFloat.h:303
bool isNegative() const
Definition APFloat.h:1616
bool isDenormal() const
Definition APFloat.h:1617
const fltSemantics & getSemantics() const
Definition APFloat.h:1624
static APFloat getOne(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative One.
Definition APFloat.h:1225
static APFloat getZero(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Zero.
Definition APFloat.h:1216
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:187
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 and target specific virtual registers.
Definition MCRegister.h:42
constexpr unsigned id() const
Definition MCRegister.h:85
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:1087
const MDOperand & getOperand(unsigned I) const
Definition Metadata.h:1443
unsigned getNumOperands() const
Return number of MDNode operands.
Definition Metadata.h:1449
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:880
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:728
bool getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
Definition StringRef.h:482
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:526
ArchType getArch() const
Get the parsed architecture type of this triple.
Definition Triple.h:517
bool isAMDGCN() const
Tests whether the target is AMDGCN.
Definition Triple.h:998
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 isVOP3DPPSrc1RevOpc(const MCSubtargetInfo &STI, 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)
const VLdStIdxOpcodeInfo * getVLdStIdxOpcodeInfoByKey(unsigned BitWidth, bool IsStore, bool IsGPRIdx)
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:447
@ OPERAND_KIMM32
Operand with 32-bit immediate that uses the constant bus.
Definition SIDefines.h:465
@ OPERAND_REG_IMM_V2FP16
Definition SIDefines.h:440
@ OPERAND_REG_INLINE_C_FP64
Definition SIDefines.h:456
@ OPERAND_REG_IMM_NOINLINE_FP16
Definition SIDefines.h:438
@ OPERAND_REG_INLINE_C_BF16
Definition SIDefines.h:453
@ OPERAND_REG_INLINE_C_V2BF16
Definition SIDefines.h:458
@ OPERAND_REG_IMM_V2INT16
Definition SIDefines.h:442
@ OPERAND_REG_IMM_BF16
Definition SIDefines.h:436
@ OPERAND_REG_IMM_INT32
Operands with register, 32-bit, or 64-bit immediate.
Definition SIDefines.h:431
@ OPERAND_REG_IMM_V2BF16
Definition SIDefines.h:439
@ OPERAND_REG_IMM_FP16
Definition SIDefines.h:437
@ OPERAND_REG_IMM_V2FP16_SPLAT
Definition SIDefines.h:441
@ OPERAND_REG_IMM_NOINLINE_V2FP16
Definition SIDefines.h:444
@ OPERAND_REG_IMM_FP64
Definition SIDefines.h:435
@ OPERAND_REG_INLINE_C_V2FP16
Definition SIDefines.h:459
@ OPERAND_REG_INLINE_AC_INT32
Operands with an AccVGPR register or inline constant.
Definition SIDefines.h:470
@ OPERAND_REG_INLINE_AC_FP32
Definition SIDefines.h:471
@ OPERAND_REG_IMM_V2INT32
Definition SIDefines.h:445
@ OPERAND_REG_IMM_FP32
Definition SIDefines.h:434
@ OPERAND_REG_INLINE_C_FP32
Definition SIDefines.h:455
@ OPERAND_REG_INLINE_C_INT32
Definition SIDefines.h:451
@ OPERAND_REG_INLINE_C_V2INT16
Definition SIDefines.h:457
@ OPERAND_REG_IMM_V2FP32
Definition SIDefines.h:446
@ OPERAND_REG_INLINE_AC_FP64
Definition SIDefines.h:472
@ OPERAND_REG_INLINE_C_FP16
Definition SIDefines.h:454
@ OPERAND_INLINE_SPLIT_BARRIER_INT32
Definition SIDefines.h:462
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:236
constexpr bool isVOP3(const T &...O)
Definition SIDefines.h:239
constexpr bool isVOP1(const T &...O)
Definition SIDefines.h:230
constexpr bool isVOP2(const T &...O)
Definition SIDefines.h:233
constexpr bool isFLAT(const T &...O)
Definition SIDefines.h:286
constexpr bool isBuffer(const T &...O)
Definition SIDefines.h:267
constexpr bool isVIMAGE(const T &...O)
Definition SIDefines.h:277
constexpr bool isSMRD(const T &...O)
Definition SIDefines.h:271
constexpr bool isVOP3Like(const T &...O)
Definition SIDefines.h:245
constexpr bool isFlatScratch(const T &...O)
Definition SIDefines.h:361
constexpr bool isMIMG(const T &...O)
Definition SIDefines.h:274
constexpr bool isVOPD3(const T &...O)
Definition SIDefines.h:385
constexpr bool isEXP(const T &...O)
Definition SIDefines.h:283
constexpr bool isVSAMPLE(const T &...O)
Definition SIDefines.h:280
constexpr bool isDS(const T &...O)
Definition SIDefines.h:289
constexpr bool isAtomic(const T &...O)
Definition SIDefines.h:396
constexpr bool isDPP(const T &...O)
Definition SIDefines.h:255
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:695
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > extract(Y &&MD)
Extract a Value from Metadata.
Definition Metadata.h:680
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 unsigned BitWidth
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.