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