LLVM 22.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 shift for Loadcnt/Storecnt in combined S_WAIT instructions.
139unsigned getLoadcntStorecntBitShift(unsigned VersionMajor) {
140 return VersionMajor >= 12 ? 8 : 0;
141}
142
143/// \returns VaSdst bit width
144inline unsigned getVaSdstBitWidth() { return 3; }
145
146/// \returns VaSdst bit shift
147inline unsigned getVaSdstBitShift() { return 9; }
148
149/// \returns VmVsrc bit width
150inline unsigned getVmVsrcBitWidth() { return 3; }
151
152/// \returns VmVsrc bit shift
153inline unsigned getVmVsrcBitShift() { return 2; }
154
155/// \returns VaVdst bit width
156inline unsigned getVaVdstBitWidth() { return 4; }
157
158/// \returns VaVdst bit shift
159inline unsigned getVaVdstBitShift() { return 12; }
160
161/// \returns VaVcc bit width
162inline unsigned getVaVccBitWidth() { return 1; }
163
164/// \returns VaVcc bit shift
165inline unsigned getVaVccBitShift() { return 1; }
166
167/// \returns SaSdst bit width
168inline unsigned getSaSdstBitWidth() { return 1; }
169
170/// \returns SaSdst bit shift
171inline unsigned getSaSdstBitShift() { return 0; }
172
173/// \returns VaSsrc width
174inline unsigned getVaSsrcBitWidth() { return 1; }
175
176/// \returns VaSsrc bit shift
177inline unsigned getVaSsrcBitShift() { return 8; }
178
179/// \returns HoldCnt bit shift
180inline unsigned getHoldCntWidth() { return 1; }
181
182/// \returns HoldCnt bit shift
183inline unsigned getHoldCntBitShift() { return 7; }
184
185} // end anonymous namespace
186
187namespace llvm {
188
189namespace AMDGPU {
190
191/// \returns true if the target supports signed immediate offset for SMRD
192/// instructions.
194 return isGFX9Plus(ST);
195}
196
197/// \returns True if \p STI is AMDHSA.
198bool isHsaAbi(const MCSubtargetInfo &STI) {
199 return STI.getTargetTriple().getOS() == Triple::AMDHSA;
200}
201
203 if (auto *Ver = mdconst::extract_or_null<ConstantInt>(
204 M.getModuleFlag("amdhsa_code_object_version"))) {
205 return (unsigned)Ver->getZExtValue() / 100;
206 }
207
209}
210
213}
214
215unsigned getAMDHSACodeObjectVersion(unsigned ABIVersion) {
216 switch (ABIVersion) {
218 return 4;
220 return 5;
222 return 6;
223 default:
225 }
226}
227
228uint8_t getELFABIVersion(const Triple &T, unsigned CodeObjectVersion) {
229 if (T.getOS() != Triple::AMDHSA)
230 return 0;
231
232 switch (CodeObjectVersion) {
233 case 4:
235 case 5:
237 case 6:
239 default:
240 report_fatal_error("Unsupported AMDHSA Code Object Version " +
241 Twine(CodeObjectVersion));
242 }
243}
244
245unsigned getMultigridSyncArgImplicitArgPosition(unsigned CodeObjectVersion) {
246 switch (CodeObjectVersion) {
247 case AMDHSA_COV4:
248 return 48;
249 case AMDHSA_COV5:
250 case AMDHSA_COV6:
251 default:
253 }
254}
255
256// FIXME: All such magic numbers about the ABI should be in a
257// central TD file.
258unsigned getHostcallImplicitArgPosition(unsigned CodeObjectVersion) {
259 switch (CodeObjectVersion) {
260 case AMDHSA_COV4:
261 return 24;
262 case AMDHSA_COV5:
263 case AMDHSA_COV6:
264 default:
266 }
267}
268
269unsigned getDefaultQueueImplicitArgPosition(unsigned CodeObjectVersion) {
270 switch (CodeObjectVersion) {
271 case AMDHSA_COV4:
272 return 32;
273 case AMDHSA_COV5:
274 case AMDHSA_COV6:
275 default:
277 }
278}
279
280unsigned getCompletionActionImplicitArgPosition(unsigned CodeObjectVersion) {
281 switch (CodeObjectVersion) {
282 case AMDHSA_COV4:
283 return 40;
284 case AMDHSA_COV5:
285 case AMDHSA_COV6:
286 default:
288 }
289}
290
291#define GET_MIMGBaseOpcodesTable_IMPL
292#define GET_MIMGDimInfoTable_IMPL
293#define GET_MIMGInfoTable_IMPL
294#define GET_MIMGLZMappingTable_IMPL
295#define GET_MIMGMIPMappingTable_IMPL
296#define GET_MIMGBiasMappingTable_IMPL
297#define GET_MIMGOffsetMappingTable_IMPL
298#define GET_MIMGG16MappingTable_IMPL
299#define GET_MAIInstInfoTable_IMPL
300#define GET_WMMAInstInfoTable_IMPL
301#include "AMDGPUGenSearchableTables.inc"
302
303int getMIMGOpcode(unsigned BaseOpcode, unsigned MIMGEncoding,
304 unsigned VDataDwords, unsigned VAddrDwords) {
305 const MIMGInfo *Info =
306 getMIMGOpcodeHelper(BaseOpcode, MIMGEncoding, VDataDwords, VAddrDwords);
307 return Info ? Info->Opcode : -1;
308}
309
311 const MIMGInfo *Info = getMIMGInfo(Opc);
312 return Info ? getMIMGBaseOpcodeInfo(Info->BaseOpcode) : nullptr;
313}
314
315int getMaskedMIMGOp(unsigned Opc, unsigned NewChannels) {
316 const MIMGInfo *OrigInfo = getMIMGInfo(Opc);
317 const MIMGInfo *NewInfo =
318 getMIMGOpcodeHelper(OrigInfo->BaseOpcode, OrigInfo->MIMGEncoding,
319 NewChannels, OrigInfo->VAddrDwords);
320 return NewInfo ? NewInfo->Opcode : -1;
321}
322
323unsigned getAddrSizeMIMGOp(const MIMGBaseOpcodeInfo *BaseOpcode,
324 const MIMGDimInfo *Dim, bool IsA16,
325 bool IsG16Supported) {
326 unsigned AddrWords = BaseOpcode->NumExtraArgs;
327 unsigned AddrComponents = (BaseOpcode->Coordinates ? Dim->NumCoords : 0) +
328 (BaseOpcode->LodOrClampOrMip ? 1 : 0);
329 if (IsA16)
330 AddrWords += divideCeil(AddrComponents, 2);
331 else
332 AddrWords += AddrComponents;
333
334 // Note: For subtargets that support A16 but not G16, enabling A16 also
335 // enables 16 bit gradients.
336 // For subtargets that support A16 (operand) and G16 (done with a different
337 // instruction encoding), they are independent.
338
339 if (BaseOpcode->Gradients) {
340 if ((IsA16 && !IsG16Supported) || BaseOpcode->G16)
341 // There are two gradients per coordinate, we pack them separately.
342 // For the 3d case,
343 // we get (dy/du, dx/du) (-, dz/du) (dy/dv, dx/dv) (-, dz/dv)
344 AddrWords += alignTo<2>(Dim->NumGradients / 2);
345 else
346 AddrWords += Dim->NumGradients;
347 }
348 return AddrWords;
349}
350
351struct MUBUFInfo {
359 bool tfe;
360};
361
362struct MTBUFInfo {
369};
370
371struct SMInfo {
374};
375
376struct VOPInfo {
379};
380
383};
384
387};
388
391};
392
398};
399
400struct VOPDInfo {
405 bool VOPD3;
406};
407
411};
412
413#define GET_FP4FP8DstByteSelTable_DECL
414#define GET_FP4FP8DstByteSelTable_IMPL
415
419};
420
425};
426
427#define GET_MTBUFInfoTable_DECL
428#define GET_MTBUFInfoTable_IMPL
429#define GET_MUBUFInfoTable_DECL
430#define GET_MUBUFInfoTable_IMPL
431#define GET_SMInfoTable_DECL
432#define GET_SMInfoTable_IMPL
433#define GET_VOP1InfoTable_DECL
434#define GET_VOP1InfoTable_IMPL
435#define GET_VOP2InfoTable_DECL
436#define GET_VOP2InfoTable_IMPL
437#define GET_VOP3InfoTable_DECL
438#define GET_VOP3InfoTable_IMPL
439#define GET_VOPC64DPPTable_DECL
440#define GET_VOPC64DPPTable_IMPL
441#define GET_VOPC64DPP8Table_DECL
442#define GET_VOPC64DPP8Table_IMPL
443#define GET_VOPCAsmOnlyInfoTable_DECL
444#define GET_VOPCAsmOnlyInfoTable_IMPL
445#define GET_VOP3CAsmOnlyInfoTable_DECL
446#define GET_VOP3CAsmOnlyInfoTable_IMPL
447#define GET_VOPDComponentTable_DECL
448#define GET_VOPDComponentTable_IMPL
449#define GET_VOPDPairs_DECL
450#define GET_VOPDPairs_IMPL
451#define GET_VOPTrue16Table_DECL
452#define GET_VOPTrue16Table_IMPL
453#define GET_True16D16Table_IMPL
454#define GET_WMMAOpcode2AddrMappingTable_DECL
455#define GET_WMMAOpcode2AddrMappingTable_IMPL
456#define GET_WMMAOpcode3AddrMappingTable_DECL
457#define GET_WMMAOpcode3AddrMappingTable_IMPL
458#define GET_getMFMA_F8F6F4_WithSize_DECL
459#define GET_getMFMA_F8F6F4_WithSize_IMPL
460#define GET_isMFMA_F8F6F4Table_IMPL
461#define GET_isCvtScaleF32_F32F16ToF8F4Table_IMPL
462
463#include "AMDGPUGenSearchableTables.inc"
464
465int getMTBUFBaseOpcode(unsigned Opc) {
466 const MTBUFInfo *Info = getMTBUFInfoFromOpcode(Opc);
467 return Info ? Info->BaseOpcode : -1;
468}
469
470int getMTBUFOpcode(unsigned BaseOpc, unsigned Elements) {
471 const MTBUFInfo *Info =
472 getMTBUFInfoFromBaseOpcodeAndElements(BaseOpc, Elements);
473 return Info ? Info->Opcode : -1;
474}
475
476int getMTBUFElements(unsigned Opc) {
477 const MTBUFInfo *Info = getMTBUFOpcodeHelper(Opc);
478 return Info ? Info->elements : 0;
479}
480
481bool getMTBUFHasVAddr(unsigned Opc) {
482 const MTBUFInfo *Info = getMTBUFOpcodeHelper(Opc);
483 return Info && Info->has_vaddr;
484}
485
486bool getMTBUFHasSrsrc(unsigned Opc) {
487 const MTBUFInfo *Info = getMTBUFOpcodeHelper(Opc);
488 return Info && Info->has_srsrc;
489}
490
491bool getMTBUFHasSoffset(unsigned Opc) {
492 const MTBUFInfo *Info = getMTBUFOpcodeHelper(Opc);
493 return Info && Info->has_soffset;
494}
495
496int getMUBUFBaseOpcode(unsigned Opc) {
497 const MUBUFInfo *Info = getMUBUFInfoFromOpcode(Opc);
498 return Info ? Info->BaseOpcode : -1;
499}
500
501int getMUBUFOpcode(unsigned BaseOpc, unsigned Elements) {
502 const MUBUFInfo *Info =
503 getMUBUFInfoFromBaseOpcodeAndElements(BaseOpc, Elements);
504 return Info ? Info->Opcode : -1;
505}
506
507int getMUBUFElements(unsigned Opc) {
508 const MUBUFInfo *Info = getMUBUFOpcodeHelper(Opc);
509 return Info ? Info->elements : 0;
510}
511
512bool getMUBUFHasVAddr(unsigned Opc) {
513 const MUBUFInfo *Info = getMUBUFOpcodeHelper(Opc);
514 return Info && Info->has_vaddr;
515}
516
517bool getMUBUFHasSrsrc(unsigned Opc) {
518 const MUBUFInfo *Info = getMUBUFOpcodeHelper(Opc);
519 return Info && Info->has_srsrc;
520}
521
522bool getMUBUFHasSoffset(unsigned Opc) {
523 const MUBUFInfo *Info = getMUBUFOpcodeHelper(Opc);
524 return Info && Info->has_soffset;
525}
526
527bool getMUBUFIsBufferInv(unsigned Opc) {
528 const MUBUFInfo *Info = getMUBUFOpcodeHelper(Opc);
529 return Info && Info->IsBufferInv;
530}
531
532bool getMUBUFTfe(unsigned Opc) {
533 const MUBUFInfo *Info = getMUBUFOpcodeHelper(Opc);
534 return Info && Info->tfe;
535}
536
537bool getSMEMIsBuffer(unsigned Opc) {
538 const SMInfo *Info = getSMEMOpcodeHelper(Opc);
539 return Info && Info->IsBuffer;
540}
541
542bool getVOP1IsSingle(unsigned Opc) {
543 const VOPInfo *Info = getVOP1OpcodeHelper(Opc);
544 return !Info || Info->IsSingle;
545}
546
547bool getVOP2IsSingle(unsigned Opc) {
548 const VOPInfo *Info = getVOP2OpcodeHelper(Opc);
549 return !Info || Info->IsSingle;
550}
551
552bool getVOP3IsSingle(unsigned Opc) {
553 const VOPInfo *Info = getVOP3OpcodeHelper(Opc);
554 return !Info || Info->IsSingle;
555}
556
557bool isVOPC64DPP(unsigned Opc) {
558 return isVOPC64DPPOpcodeHelper(Opc) || isVOPC64DPP8OpcodeHelper(Opc);
559}
560
561bool isVOPCAsmOnly(unsigned Opc) { return isVOPCAsmOnlyOpcodeHelper(Opc); }
562
563bool getMAIIsDGEMM(unsigned Opc) {
564 const MAIInstInfo *Info = getMAIInstInfoHelper(Opc);
565 return Info && Info->is_dgemm;
566}
567
568bool getMAIIsGFX940XDL(unsigned Opc) {
569 const MAIInstInfo *Info = getMAIInstInfoHelper(Opc);
570 return Info && Info->is_gfx940_xdl;
571}
572
573bool getWMMAIsXDL(unsigned Opc) {
574 const WMMAInstInfo *Info = getWMMAInstInfoHelper(Opc);
575 return Info ? Info->is_wmma_xdl : false;
576}
577
579 switch (EncodingVal) {
582 return 6;
584 return 4;
587 default:
588 return 8;
589 }
590
591 llvm_unreachable("covered switch over mfma scale formats");
592}
593
595 unsigned BLGP,
596 unsigned F8F8Opcode) {
597 uint8_t SrcANumRegs = mfmaScaleF8F6F4FormatToNumRegs(CBSZ);
598 uint8_t SrcBNumRegs = mfmaScaleF8F6F4FormatToNumRegs(BLGP);
599 return getMFMA_F8F6F4_InstWithNumRegs(SrcANumRegs, SrcBNumRegs, F8F8Opcode);
600}
601
603 switch (Fmt) {
606 return 16;
609 return 12;
611 return 8;
612 }
613
614 llvm_unreachable("covered switch over wmma scale formats");
615}
616
618 unsigned FmtB,
619 unsigned F8F8Opcode) {
620 uint8_t SrcANumRegs = wmmaScaleF8F6F4FormatToNumRegs(FmtA);
621 uint8_t SrcBNumRegs = wmmaScaleF8F6F4FormatToNumRegs(FmtB);
622 return getMFMA_F8F6F4_InstWithNumRegs(SrcANumRegs, SrcBNumRegs, F8F8Opcode);
623}
624
626 if (ST.hasFeature(AMDGPU::FeatureGFX1250Insts))
628 if (ST.hasFeature(AMDGPU::FeatureGFX12Insts))
630 if (ST.hasFeature(AMDGPU::FeatureGFX11Insts))
632 llvm_unreachable("Subtarget generation does not support VOPD!");
633}
634
635CanBeVOPD getCanBeVOPD(unsigned Opc, unsigned EncodingFamily, bool VOPD3) {
636 bool IsConvertibleToBitOp = VOPD3 ? getBitOp2(Opc) : 0;
637 Opc = IsConvertibleToBitOp ? (unsigned)AMDGPU::V_BITOP3_B32_e64 : Opc;
638 const VOPDComponentInfo *Info = getVOPDComponentHelper(Opc);
639 if (Info) {
640 // Check that Opc can be used as VOPDY for this encoding. V_MOV_B32 as a
641 // VOPDX is just a placeholder here, it is supported on all encodings.
642 // TODO: This can be optimized by creating tables of supported VOPDY
643 // opcodes per encoding.
644 unsigned VOPDMov = AMDGPU::getVOPDOpcode(AMDGPU::V_MOV_B32_e32, VOPD3);
645 bool CanBeVOPDY = getVOPDFull(VOPDMov, AMDGPU::getVOPDOpcode(Opc, VOPD3),
646 EncodingFamily, VOPD3) != -1;
647 return {VOPD3 ? Info->CanBeVOPD3X : Info->CanBeVOPDX, CanBeVOPDY};
648 }
649
650 return {false, false};
651}
652
653unsigned getVOPDOpcode(unsigned Opc, bool VOPD3) {
654 bool IsConvertibleToBitOp = VOPD3 ? getBitOp2(Opc) : 0;
655 Opc = IsConvertibleToBitOp ? (unsigned)AMDGPU::V_BITOP3_B32_e64 : Opc;
656 const VOPDComponentInfo *Info = getVOPDComponentHelper(Opc);
657 return Info ? Info->VOPDOp : ~0u;
658}
659
660bool isVOPD(unsigned Opc) {
661 return AMDGPU::hasNamedOperand(Opc, AMDGPU::OpName::src0X);
662}
663
664bool isMAC(unsigned Opc) {
665 return Opc == AMDGPU::V_MAC_F32_e64_gfx6_gfx7 ||
666 Opc == AMDGPU::V_MAC_F32_e64_gfx10 ||
667 Opc == AMDGPU::V_MAC_F32_e64_vi ||
668 Opc == AMDGPU::V_MAC_LEGACY_F32_e64_gfx6_gfx7 ||
669 Opc == AMDGPU::V_MAC_LEGACY_F32_e64_gfx10 ||
670 Opc == AMDGPU::V_MAC_F16_e64_vi ||
671 Opc == AMDGPU::V_FMAC_F64_e64_gfx90a ||
672 Opc == AMDGPU::V_FMAC_F64_e64_gfx12 ||
673 Opc == AMDGPU::V_FMAC_F32_e64_gfx10 ||
674 Opc == AMDGPU::V_FMAC_F32_e64_gfx11 ||
675 Opc == AMDGPU::V_FMAC_F32_e64_gfx12 ||
676 Opc == AMDGPU::V_FMAC_F32_e64_vi ||
677 Opc == AMDGPU::V_FMAC_LEGACY_F32_e64_gfx10 ||
678 Opc == AMDGPU::V_FMAC_DX9_ZERO_F32_e64_gfx11 ||
679 Opc == AMDGPU::V_FMAC_F16_e64_gfx10 ||
680 Opc == AMDGPU::V_FMAC_F16_t16_e64_gfx11 ||
681 Opc == AMDGPU::V_FMAC_F16_fake16_e64_gfx11 ||
682 Opc == AMDGPU::V_FMAC_F16_t16_e64_gfx12 ||
683 Opc == AMDGPU::V_FMAC_F16_fake16_e64_gfx12 ||
684 Opc == AMDGPU::V_DOT2C_F32_F16_e64_vi ||
685 Opc == AMDGPU::V_DOT2C_F32_BF16_e64_vi ||
686 Opc == AMDGPU::V_DOT2C_I32_I16_e64_vi ||
687 Opc == AMDGPU::V_DOT4C_I32_I8_e64_vi ||
688 Opc == AMDGPU::V_DOT8C_I32_I4_e64_vi;
689}
690
691bool isPermlane16(unsigned Opc) {
692 return Opc == AMDGPU::V_PERMLANE16_B32_gfx10 ||
693 Opc == AMDGPU::V_PERMLANEX16_B32_gfx10 ||
694 Opc == AMDGPU::V_PERMLANE16_B32_e64_gfx11 ||
695 Opc == AMDGPU::V_PERMLANEX16_B32_e64_gfx11 ||
696 Opc == AMDGPU::V_PERMLANE16_B32_e64_gfx12 ||
697 Opc == AMDGPU::V_PERMLANEX16_B32_e64_gfx12 ||
698 Opc == AMDGPU::V_PERMLANE16_VAR_B32_e64_gfx12 ||
699 Opc == AMDGPU::V_PERMLANEX16_VAR_B32_e64_gfx12;
700}
701
703 return Opc == AMDGPU::V_CVT_F32_BF8_e64_gfx12 ||
704 Opc == AMDGPU::V_CVT_F32_FP8_e64_gfx12 ||
705 Opc == AMDGPU::V_CVT_F32_BF8_e64_dpp_gfx12 ||
706 Opc == AMDGPU::V_CVT_F32_FP8_e64_dpp_gfx12 ||
707 Opc == AMDGPU::V_CVT_F32_BF8_e64_dpp8_gfx12 ||
708 Opc == AMDGPU::V_CVT_F32_FP8_e64_dpp8_gfx12 ||
709 Opc == AMDGPU::V_CVT_PK_F32_BF8_fake16_e64_gfx12 ||
710 Opc == AMDGPU::V_CVT_PK_F32_FP8_fake16_e64_gfx12 ||
711 Opc == AMDGPU::V_CVT_PK_F32_BF8_t16_e64_gfx12 ||
712 Opc == AMDGPU::V_CVT_PK_F32_FP8_t16_e64_gfx12;
713}
714
715bool isGenericAtomic(unsigned Opc) {
716 return Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_SWAP ||
717 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_ADD ||
718 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_SUB ||
719 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_SMIN ||
720 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_UMIN ||
721 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_SMAX ||
722 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_UMAX ||
723 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_AND ||
724 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_OR ||
725 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_XOR ||
726 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_INC ||
727 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_DEC ||
728 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_FADD ||
729 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_FMIN ||
730 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_FMAX ||
731 Opc == AMDGPU::G_AMDGPU_BUFFER_ATOMIC_CMPSWAP ||
732 Opc == AMDGPU::G_AMDGPU_ATOMIC_CMPXCHG;
733}
734
735bool isAsyncStore(unsigned Opc) {
736 return Opc == GLOBAL_STORE_ASYNC_FROM_LDS_B8_gfx1250 ||
737 Opc == GLOBAL_STORE_ASYNC_FROM_LDS_B32_gfx1250 ||
738 Opc == GLOBAL_STORE_ASYNC_FROM_LDS_B64_gfx1250 ||
739 Opc == GLOBAL_STORE_ASYNC_FROM_LDS_B128_gfx1250 ||
740 Opc == GLOBAL_STORE_ASYNC_FROM_LDS_B8_SADDR_gfx1250 ||
741 Opc == GLOBAL_STORE_ASYNC_FROM_LDS_B32_SADDR_gfx1250 ||
742 Opc == GLOBAL_STORE_ASYNC_FROM_LDS_B64_SADDR_gfx1250 ||
743 Opc == GLOBAL_STORE_ASYNC_FROM_LDS_B128_SADDR_gfx1250;
744}
745
746bool isTensorStore(unsigned Opc) {
747 return Opc == TENSOR_STORE_FROM_LDS_gfx1250 ||
748 Opc == TENSOR_STORE_FROM_LDS_D2_gfx1250;
749}
750
751unsigned getTemporalHintType(const MCInstrDesc TID) {
754 unsigned Opc = TID.getOpcode();
755 // Async and Tensor store should have the temporal hint type of TH_TYPE_STORE
756 if (TID.mayStore() &&
757 (isAsyncStore(Opc) || isTensorStore(Opc) || !TID.mayLoad()))
758 return CPol::TH_TYPE_STORE;
759
760 // This will default to returning TH_TYPE_LOAD when neither MayStore nor
761 // MayLoad flag is present which is the case with instructions like
762 // image_get_resinfo.
763 return CPol::TH_TYPE_LOAD;
764}
765
766bool isTrue16Inst(unsigned Opc) {
767 const VOPTrue16Info *Info = getTrue16OpcodeHelper(Opc);
768 return Info && Info->IsTrue16;
769}
770
772 const FP4FP8DstByteSelInfo *Info = getFP4FP8DstByteSelHelper(Opc);
773 if (!Info)
774 return FPType::None;
775 if (Info->HasFP8DstByteSel)
776 return FPType::FP8;
777 if (Info->HasFP4DstByteSel)
778 return FPType::FP4;
779
780 return FPType::None;
781}
782
783unsigned mapWMMA2AddrTo3AddrOpcode(unsigned Opc) {
784 const WMMAOpcodeMappingInfo *Info = getWMMAMappingInfoFrom2AddrOpcode(Opc);
785 return Info ? Info->Opcode3Addr : ~0u;
786}
787
788unsigned mapWMMA3AddrTo2AddrOpcode(unsigned Opc) {
789 const WMMAOpcodeMappingInfo *Info = getWMMAMappingInfoFrom3AddrOpcode(Opc);
790 return Info ? Info->Opcode2Addr : ~0u;
791}
792
793// Wrapper for Tablegen'd function. enum Subtarget is not defined in any
794// header files, so we need to wrap it in a function that takes unsigned
795// instead.
796int getMCOpcode(uint16_t Opcode, unsigned Gen) {
797 return getMCOpcodeGen(Opcode, static_cast<Subtarget>(Gen));
798}
799
800unsigned getBitOp2(unsigned Opc) {
801 switch (Opc) {
802 default:
803 return 0;
804 case AMDGPU::V_AND_B32_e32:
805 return 0x40;
806 case AMDGPU::V_OR_B32_e32:
807 return 0x54;
808 case AMDGPU::V_XOR_B32_e32:
809 return 0x14;
810 case AMDGPU::V_XNOR_B32_e32:
811 return 0x41;
812 }
813}
814
815int getVOPDFull(unsigned OpX, unsigned OpY, unsigned EncodingFamily,
816 bool VOPD3) {
817 bool IsConvertibleToBitOp = VOPD3 ? getBitOp2(OpY) : 0;
818 OpY = IsConvertibleToBitOp ? (unsigned)AMDGPU::V_BITOP3_B32_e64 : OpY;
819 const VOPDInfo *Info =
820 getVOPDInfoFromComponentOpcodes(OpX, OpY, EncodingFamily, VOPD3);
821 return Info ? Info->Opcode : -1;
822}
823
824std::pair<unsigned, unsigned> getVOPDComponents(unsigned VOPDOpcode) {
825 const VOPDInfo *Info = getVOPDOpcodeHelper(VOPDOpcode);
826 assert(Info);
827 const auto *OpX = getVOPDBaseFromComponent(Info->OpX);
828 const auto *OpY = getVOPDBaseFromComponent(Info->OpY);
829 assert(OpX && OpY);
830 return {OpX->BaseVOP, OpY->BaseVOP};
831}
832
833namespace VOPD {
834
835ComponentProps::ComponentProps(const MCInstrDesc &OpDesc, bool VOP3Layout) {
837
840 auto TiedIdx = OpDesc.getOperandConstraint(Component::SRC2, MCOI::TIED_TO);
841 assert(TiedIdx == -1 || TiedIdx == Component::DST);
842 HasSrc2Acc = TiedIdx != -1;
843 Opcode = OpDesc.getOpcode();
844
845 IsVOP3 = VOP3Layout || (OpDesc.TSFlags & SIInstrFlags::VOP3);
846 SrcOperandsNum = AMDGPU::hasNamedOperand(Opcode, AMDGPU::OpName::src2) ? 3
847 : AMDGPU::hasNamedOperand(Opcode, AMDGPU::OpName::imm) ? 3
848 : AMDGPU::hasNamedOperand(Opcode, AMDGPU::OpName::src1) ? 2
849 : 1;
850 assert(SrcOperandsNum <= Component::MAX_SRC_NUM);
851
852 if (Opcode == AMDGPU::V_CNDMASK_B32_e32 ||
853 Opcode == AMDGPU::V_CNDMASK_B32_e64) {
854 // CNDMASK is an awkward exception, it has FP modifiers, but not FP
855 // operands.
856 NumVOPD3Mods = 2;
857 if (IsVOP3)
858 SrcOperandsNum = 3;
859 } else if (isSISrcFPOperand(OpDesc,
860 getNamedOperandIdx(Opcode, OpName::src0))) {
861 // All FP VOPD instructions have Neg modifiers for all operands except
862 // for tied src2.
863 NumVOPD3Mods = SrcOperandsNum;
864 if (HasSrc2Acc)
865 --NumVOPD3Mods;
866 }
867
868 if (OpDesc.TSFlags & SIInstrFlags::VOP3)
869 return;
870
871 auto OperandsNum = OpDesc.getNumOperands();
872 unsigned CompOprIdx;
873 for (CompOprIdx = Component::SRC1; CompOprIdx < OperandsNum; ++CompOprIdx) {
874 if (OpDesc.operands()[CompOprIdx].OperandType == AMDGPU::OPERAND_KIMM32) {
875 MandatoryLiteralIdx = CompOprIdx;
876 break;
877 }
878 }
879}
880
882 return getNamedOperandIdx(Opcode, OpName::bitop3);
883}
884
885unsigned ComponentInfo::getIndexInParsedOperands(unsigned CompOprIdx) const {
886 assert(CompOprIdx < Component::MAX_OPR_NUM);
887
888 if (CompOprIdx == Component::DST)
890
891 auto CompSrcIdx = CompOprIdx - Component::DST_NUM;
892 if (CompSrcIdx < getCompParsedSrcOperandsNum())
893 return getIndexOfSrcInParsedOperands(CompSrcIdx);
894
895 // The specified operand does not exist.
896 return 0;
897}
898
900 std::function<unsigned(unsigned, unsigned)> GetRegIdx,
901 const MCRegisterInfo &MRI, bool SkipSrc, bool AllowSameVGPR,
902 bool VOPD3) const {
903
904 auto OpXRegs = getRegIndices(ComponentIndex::X, GetRegIdx,
905 CompInfo[ComponentIndex::X].isVOP3());
906 auto OpYRegs = getRegIndices(ComponentIndex::Y, GetRegIdx,
907 CompInfo[ComponentIndex::Y].isVOP3());
908
909 const auto banksOverlap = [&MRI](MCRegister X, MCRegister Y,
910 unsigned BanksMask) -> bool {
911 MCRegister BaseX = MRI.getSubReg(X, AMDGPU::sub0);
912 MCRegister BaseY = MRI.getSubReg(Y, AMDGPU::sub0);
913 if (!BaseX)
914 BaseX = X;
915 if (!BaseY)
916 BaseY = Y;
917 if ((BaseX & BanksMask) == (BaseY & BanksMask))
918 return true;
919 if (BaseX != X /* This is 64-bit register */ &&
920 ((BaseX + 1) & BanksMask) == (BaseY & BanksMask))
921 return true;
922 if (BaseY != Y && (BaseX & BanksMask) == ((BaseY + 1) & BanksMask))
923 return true;
924
925 // If both are 64-bit bank conflict will be detected yet while checking
926 // the first subreg.
927 return false;
928 };
929
930 unsigned CompOprIdx;
931 for (CompOprIdx = 0; CompOprIdx < Component::MAX_OPR_NUM; ++CompOprIdx) {
932 unsigned BanksMasks = VOPD3 ? VOPD3_VGPR_BANK_MASKS[CompOprIdx]
933 : VOPD_VGPR_BANK_MASKS[CompOprIdx];
934 if (!OpXRegs[CompOprIdx] || !OpYRegs[CompOprIdx])
935 continue;
936
937 if (SkipSrc && CompOprIdx >= Component::DST_NUM)
938 continue;
939
940 if (CompOprIdx < Component::DST_NUM) {
941 // Even if we do not check vdst parity, vdst operands still shall not
942 // overlap.
943 if (MRI.regsOverlap(OpXRegs[CompOprIdx], OpYRegs[CompOprIdx]))
944 return CompOprIdx;
945 if (VOPD3) // No need to check dst parity.
946 continue;
947 }
948
949 if (banksOverlap(OpXRegs[CompOprIdx], OpYRegs[CompOprIdx], BanksMasks) &&
950 (!AllowSameVGPR || CompOprIdx < Component::DST_NUM ||
951 OpXRegs[CompOprIdx] != OpYRegs[CompOprIdx]))
952 return CompOprIdx;
953 }
954
955 return {};
956}
957
958// Return an array of VGPR registers [DST,SRC0,SRC1,SRC2] used
959// by the specified component. If an operand is unused
960// or is not a VGPR, the corresponding value is 0.
961//
962// GetRegIdx(Component, MCOperandIdx) must return a VGPR register index
963// for the specified component and MC operand. The callback must return 0
964// if the operand is not a register or not a VGPR.
966InstInfo::getRegIndices(unsigned CompIdx,
967 std::function<unsigned(unsigned, unsigned)> GetRegIdx,
968 bool VOPD3) const {
969 assert(CompIdx < COMPONENTS_NUM);
970
971 const auto &Comp = CompInfo[CompIdx];
973
974 RegIndices[DST] = GetRegIdx(CompIdx, Comp.getIndexOfDstInMCOperands());
975
976 for (unsigned CompOprIdx : {SRC0, SRC1, SRC2}) {
977 unsigned CompSrcIdx = CompOprIdx - DST_NUM;
978 RegIndices[CompOprIdx] =
979 Comp.hasRegSrcOperand(CompSrcIdx)
980 ? GetRegIdx(CompIdx,
981 Comp.getIndexOfSrcInMCOperands(CompSrcIdx, VOPD3))
982 : 0;
983 }
984 return RegIndices;
985}
986
987} // namespace VOPD
988
990 return VOPD::InstInfo(OpX, OpY);
991}
992
993VOPD::InstInfo getVOPDInstInfo(unsigned VOPDOpcode,
994 const MCInstrInfo *InstrInfo) {
995 auto [OpX, OpY] = getVOPDComponents(VOPDOpcode);
996 const auto &OpXDesc = InstrInfo->get(OpX);
997 const auto &OpYDesc = InstrInfo->get(OpY);
998 bool VOPD3 = InstrInfo->get(VOPDOpcode).TSFlags & SIInstrFlags::VOPD3;
1000 VOPD::ComponentInfo OpYInfo(OpYDesc, OpXInfo, VOPD3);
1001 return VOPD::InstInfo(OpXInfo, OpYInfo);
1002}
1003
1004namespace IsaInfo {
1005
1007 : STI(STI), XnackSetting(TargetIDSetting::Any),
1008 SramEccSetting(TargetIDSetting::Any) {
1009 if (!STI.getFeatureBits().test(FeatureSupportsXNACK))
1010 XnackSetting = TargetIDSetting::Unsupported;
1011 if (!STI.getFeatureBits().test(FeatureSupportsSRAMECC))
1012 SramEccSetting = TargetIDSetting::Unsupported;
1013}
1014
1016 // Check if xnack or sramecc is explicitly enabled or disabled. In the
1017 // absence of the target features we assume we must generate code that can run
1018 // in any environment.
1019 SubtargetFeatures Features(FS);
1020 std::optional<bool> XnackRequested;
1021 std::optional<bool> SramEccRequested;
1022
1023 for (const std::string &Feature : Features.getFeatures()) {
1024 if (Feature == "+xnack")
1025 XnackRequested = true;
1026 else if (Feature == "-xnack")
1027 XnackRequested = false;
1028 else if (Feature == "+sramecc")
1029 SramEccRequested = true;
1030 else if (Feature == "-sramecc")
1031 SramEccRequested = false;
1032 }
1033
1034 bool XnackSupported = isXnackSupported();
1035 bool SramEccSupported = isSramEccSupported();
1036
1037 if (XnackRequested) {
1038 if (XnackSupported) {
1039 XnackSetting =
1040 *XnackRequested ? TargetIDSetting::On : TargetIDSetting::Off;
1041 } else {
1042 // If a specific xnack setting was requested and this GPU does not support
1043 // xnack emit a warning. Setting will remain set to "Unsupported".
1044 if (*XnackRequested) {
1045 errs() << "warning: xnack 'On' was requested for a processor that does "
1046 "not support it!\n";
1047 } else {
1048 errs() << "warning: xnack 'Off' was requested for a processor that "
1049 "does not support it!\n";
1050 }
1051 }
1052 }
1053
1054 if (SramEccRequested) {
1055 if (SramEccSupported) {
1056 SramEccSetting =
1057 *SramEccRequested ? TargetIDSetting::On : TargetIDSetting::Off;
1058 } else {
1059 // If a specific sramecc setting was requested and this GPU does not
1060 // support sramecc emit a warning. Setting will remain set to
1061 // "Unsupported".
1062 if (*SramEccRequested) {
1063 errs() << "warning: sramecc 'On' was requested for a processor that "
1064 "does not support it!\n";
1065 } else {
1066 errs() << "warning: sramecc 'Off' was requested for a processor that "
1067 "does not support it!\n";
1068 }
1069 }
1070 }
1071}
1072
1073static TargetIDSetting
1075 if (FeatureString.ends_with("-"))
1076 return TargetIDSetting::Off;
1077 if (FeatureString.ends_with("+"))
1078 return TargetIDSetting::On;
1079
1080 llvm_unreachable("Malformed feature string");
1081}
1082
1084 SmallVector<StringRef, 3> TargetIDSplit;
1085 TargetID.split(TargetIDSplit, ':');
1086
1087 for (const auto &FeatureString : TargetIDSplit) {
1088 if (FeatureString.starts_with("xnack"))
1089 XnackSetting = getTargetIDSettingFromFeatureString(FeatureString);
1090 if (FeatureString.starts_with("sramecc"))
1091 SramEccSetting = getTargetIDSettingFromFeatureString(FeatureString);
1092 }
1093}
1094
1095std::string AMDGPUTargetID::toString() const {
1096 std::string StringRep;
1097 raw_string_ostream StreamRep(StringRep);
1098
1099 auto TargetTriple = STI.getTargetTriple();
1100 auto Version = getIsaVersion(STI.getCPU());
1101
1102 StreamRep << TargetTriple.getArchName() << '-' << TargetTriple.getVendorName()
1103 << '-' << TargetTriple.getOSName() << '-'
1104 << TargetTriple.getEnvironmentName() << '-';
1105
1106 std::string Processor;
1107 // TODO: Following else statement is present here because we used various
1108 // alias names for GPUs up until GFX9 (e.g. 'fiji' is same as 'gfx803').
1109 // Remove once all aliases are removed from GCNProcessors.td.
1110 if (Version.Major >= 9)
1111 Processor = STI.getCPU().str();
1112 else
1113 Processor = (Twine("gfx") + Twine(Version.Major) + Twine(Version.Minor) +
1114 Twine(Version.Stepping))
1115 .str();
1116
1117 std::string Features;
1118 if (STI.getTargetTriple().getOS() == Triple::AMDHSA) {
1119 // sramecc.
1121 Features += ":sramecc-";
1123 Features += ":sramecc+";
1124 // xnack.
1126 Features += ":xnack-";
1128 Features += ":xnack+";
1129 }
1130
1131 StreamRep << Processor << Features;
1132
1133 return StringRep;
1134}
1135
1136unsigned getWavefrontSize(const MCSubtargetInfo *STI) {
1137 if (STI->getFeatureBits().test(FeatureWavefrontSize16))
1138 return 16;
1139 if (STI->getFeatureBits().test(FeatureWavefrontSize32))
1140 return 32;
1141
1142 return 64;
1143}
1144
1146 unsigned BytesPerCU = getAddressableLocalMemorySize(STI);
1147
1148 // "Per CU" really means "per whatever functional block the waves of a
1149 // workgroup must share". So the effective local memory size is doubled in
1150 // WGP mode on gfx10.
1151 if (isGFX10Plus(*STI) && !STI->getFeatureBits().test(FeatureCuMode))
1152 BytesPerCU *= 2;
1153
1154 return BytesPerCU;
1155}
1156
1158 if (STI->getFeatureBits().test(FeatureAddressableLocalMemorySize32768))
1159 return 32768;
1160 if (STI->getFeatureBits().test(FeatureAddressableLocalMemorySize65536))
1161 return 65536;
1162 if (STI->getFeatureBits().test(FeatureAddressableLocalMemorySize163840))
1163 return 163840;
1164 if (STI->getFeatureBits().test(FeatureAddressableLocalMemorySize327680))
1165 return 327680;
1166 return 32768;
1167}
1168
1169unsigned getEUsPerCU(const MCSubtargetInfo *STI) {
1170 // "Per CU" really means "per whatever functional block the waves of a
1171 // workgroup must share".
1172
1173 // GFX12.5 only supports CU mode, which contains four SIMDs.
1174 if (isGFX1250(*STI)) {
1175 assert(STI->getFeatureBits().test(FeatureCuMode));
1176 return 4;
1177 }
1178
1179 // For gfx10 in CU mode the functional block is the CU, which contains
1180 // two SIMDs.
1181 if (isGFX10Plus(*STI) && STI->getFeatureBits().test(FeatureCuMode))
1182 return 2;
1183
1184 // Pre-gfx10 a CU contains four SIMDs. For gfx10 in WGP mode the WGP
1185 // contains two CUs, so a total of four SIMDs.
1186 return 4;
1187}
1188
1190 unsigned FlatWorkGroupSize) {
1191 assert(FlatWorkGroupSize != 0);
1192 if (!STI->getTargetTriple().isAMDGCN())
1193 return 8;
1194 unsigned MaxWaves = getMaxWavesPerEU(STI) * getEUsPerCU(STI);
1195 unsigned N = getWavesPerWorkGroup(STI, FlatWorkGroupSize);
1196 if (N == 1) {
1197 // Single-wave workgroups don't consume barrier resources.
1198 return MaxWaves;
1199 }
1200
1201 unsigned MaxBarriers = 16;
1202 if (isGFX10Plus(*STI) && !STI->getFeatureBits().test(FeatureCuMode))
1203 MaxBarriers = 32;
1204
1205 return std::min(MaxWaves / N, MaxBarriers);
1206}
1207
1208unsigned getMinWavesPerEU(const MCSubtargetInfo *STI) { return 1; }
1209
1210unsigned getMaxWavesPerEU(const MCSubtargetInfo *STI) {
1211 // FIXME: Need to take scratch memory into account.
1212 if (isGFX90A(*STI))
1213 return 8;
1214 if (!isGFX10Plus(*STI))
1215 return 10;
1216 return hasGFX10_3Insts(*STI) ? 16 : 20;
1217}
1218
1220 unsigned FlatWorkGroupSize) {
1221 return divideCeil(getWavesPerWorkGroup(STI, FlatWorkGroupSize),
1222 getEUsPerCU(STI));
1223}
1224
1225unsigned getMinFlatWorkGroupSize(const MCSubtargetInfo *STI) { return 1; }
1226
1228 // Some subtargets allow encoding 2048, but this isn't tested or supported.
1229 return 1024;
1230}
1231
1233 unsigned FlatWorkGroupSize) {
1234 return divideCeil(FlatWorkGroupSize, getWavefrontSize(STI));
1235}
1236
1239 if (Version.Major >= 10)
1240 return getAddressableNumSGPRs(STI);
1241 if (Version.Major >= 8)
1242 return 16;
1243 return 8;
1244}
1245
1246unsigned getSGPREncodingGranule(const MCSubtargetInfo *STI) { return 8; }
1247
1248unsigned getTotalNumSGPRs(const MCSubtargetInfo *STI) {
1250 if (Version.Major >= 8)
1251 return 800;
1252 return 512;
1253}
1254
1256 if (STI->getFeatureBits().test(FeatureSGPRInitBug))
1258
1260 if (Version.Major >= 10)
1261 return 106;
1262 if (Version.Major >= 8)
1263 return 102;
1264 return 104;
1265}
1266
1267unsigned getMinNumSGPRs(const MCSubtargetInfo *STI, unsigned WavesPerEU) {
1268 assert(WavesPerEU != 0);
1269
1271 if (Version.Major >= 10)
1272 return 0;
1273
1274 if (WavesPerEU >= getMaxWavesPerEU(STI))
1275 return 0;
1276
1277 unsigned MinNumSGPRs = getTotalNumSGPRs(STI) / (WavesPerEU + 1);
1278 if (STI->getFeatureBits().test(FeatureTrapHandler))
1279 MinNumSGPRs -= std::min(MinNumSGPRs, (unsigned)TRAP_NUM_SGPRS);
1280 MinNumSGPRs = alignDown(MinNumSGPRs, getSGPRAllocGranule(STI)) + 1;
1281 return std::min(MinNumSGPRs, getAddressableNumSGPRs(STI));
1282}
1283
1284unsigned getMaxNumSGPRs(const MCSubtargetInfo *STI, unsigned WavesPerEU,
1285 bool Addressable) {
1286 assert(WavesPerEU != 0);
1287
1288 unsigned AddressableNumSGPRs = getAddressableNumSGPRs(STI);
1290 if (Version.Major >= 10)
1291 return Addressable ? AddressableNumSGPRs : 108;
1292 if (Version.Major >= 8 && !Addressable)
1293 AddressableNumSGPRs = 112;
1294 unsigned MaxNumSGPRs = getTotalNumSGPRs(STI) / WavesPerEU;
1295 if (STI->getFeatureBits().test(FeatureTrapHandler))
1296 MaxNumSGPRs -= std::min(MaxNumSGPRs, (unsigned)TRAP_NUM_SGPRS);
1297 MaxNumSGPRs = alignDown(MaxNumSGPRs, getSGPRAllocGranule(STI));
1298 return std::min(MaxNumSGPRs, AddressableNumSGPRs);
1299}
1300
1301unsigned getNumExtraSGPRs(const MCSubtargetInfo *STI, bool VCCUsed,
1302 bool FlatScrUsed, bool XNACKUsed) {
1303 unsigned ExtraSGPRs = 0;
1304 if (VCCUsed)
1305 ExtraSGPRs = 2;
1306
1308 if (Version.Major >= 10)
1309 return ExtraSGPRs;
1310
1311 if (Version.Major < 8) {
1312 if (FlatScrUsed)
1313 ExtraSGPRs = 4;
1314 } else {
1315 if (XNACKUsed)
1316 ExtraSGPRs = 4;
1317
1318 if (FlatScrUsed ||
1319 STI->getFeatureBits().test(AMDGPU::FeatureArchitectedFlatScratch))
1320 ExtraSGPRs = 6;
1321 }
1322
1323 return ExtraSGPRs;
1324}
1325
1326unsigned getNumExtraSGPRs(const MCSubtargetInfo *STI, bool VCCUsed,
1327 bool FlatScrUsed) {
1328 return getNumExtraSGPRs(STI, VCCUsed, FlatScrUsed,
1329 STI->getFeatureBits().test(AMDGPU::FeatureXNACK));
1330}
1331
1332static unsigned getGranulatedNumRegisterBlocks(unsigned NumRegs,
1333 unsigned Granule) {
1334 return divideCeil(std::max(1u, NumRegs), Granule);
1335}
1336
1337unsigned getNumSGPRBlocks(const MCSubtargetInfo *STI, unsigned NumSGPRs) {
1338 // SGPRBlocks is actual number of SGPR blocks minus 1.
1340 1;
1341}
1342
1344 unsigned DynamicVGPRBlockSize,
1345 std::optional<bool> EnableWavefrontSize32) {
1346 if (STI->getFeatureBits().test(FeatureGFX90AInsts))
1347 return 8;
1348
1349 if (DynamicVGPRBlockSize != 0)
1350 return DynamicVGPRBlockSize;
1351
1352 // Temporarily check the subtarget feature, until we fully switch to using
1353 // attributes.
1354 if (STI->getFeatureBits().test(FeatureDynamicVGPR))
1355 return STI->getFeatureBits().test(FeatureDynamicVGPRBlockSize32) ? 32 : 16;
1356
1357 bool IsWave32 = EnableWavefrontSize32
1358 ? *EnableWavefrontSize32
1359 : STI->getFeatureBits().test(FeatureWavefrontSize32);
1360
1361 if (STI->getFeatureBits().test(Feature1_5xVGPRs))
1362 return IsWave32 ? 24 : 12;
1363
1364 if (hasGFX10_3Insts(*STI))
1365 return IsWave32 ? 16 : 8;
1366
1367 return IsWave32 ? 8 : 4;
1368}
1369
1371 std::optional<bool> EnableWavefrontSize32) {
1372 if (STI->getFeatureBits().test(FeatureGFX90AInsts))
1373 return 8;
1374
1375 bool IsWave32 = EnableWavefrontSize32
1376 ? *EnableWavefrontSize32
1377 : STI->getFeatureBits().test(FeatureWavefrontSize32);
1378
1379 if (STI->getFeatureBits().test(Feature1024AddressableVGPRs))
1380 return IsWave32 ? 16 : 8;
1381
1382 return IsWave32 ? 8 : 4;
1383}
1384
1385unsigned getArchVGPRAllocGranule() { return 4; }
1386
1387unsigned getTotalNumVGPRs(const MCSubtargetInfo *STI) {
1388 if (STI->getFeatureBits().test(FeatureGFX90AInsts))
1389 return 512;
1390 if (!isGFX10Plus(*STI))
1391 return 256;
1392 bool IsWave32 = STI->getFeatureBits().test(FeatureWavefrontSize32);
1393 if (STI->getFeatureBits().test(Feature1_5xVGPRs))
1394 return IsWave32 ? 1536 : 768;
1395 return IsWave32 ? 1024 : 512;
1396}
1397
1398unsigned getAddressableNumArchVGPRs(const MCSubtargetInfo *STI) { return 256; }
1399
1401 unsigned DynamicVGPRBlockSize) {
1402 if (STI->getFeatureBits().test(FeatureGFX90AInsts))
1403 return 512;
1404
1405 // Temporarily check the subtarget feature, until we fully switch to using
1406 // attributes.
1407 if (DynamicVGPRBlockSize != 0 ||
1408 STI->getFeatureBits().test(FeatureDynamicVGPR))
1409 // On GFX12 we can allocate at most 8 blocks of VGPRs.
1410 return 8 * getVGPRAllocGranule(STI, DynamicVGPRBlockSize);
1411 return getAddressableNumArchVGPRs(STI);
1412}
1413
1415 unsigned NumVGPRs,
1416 unsigned DynamicVGPRBlockSize) {
1418 NumVGPRs, getVGPRAllocGranule(STI, DynamicVGPRBlockSize),
1420}
1421
1422unsigned getNumWavesPerEUWithNumVGPRs(unsigned NumVGPRs, unsigned Granule,
1423 unsigned MaxWaves,
1424 unsigned TotalNumVGPRs) {
1425 if (NumVGPRs < Granule)
1426 return MaxWaves;
1427 unsigned RoundedRegs = alignTo(NumVGPRs, Granule);
1428 return std::min(std::max(TotalNumVGPRs / RoundedRegs, 1u), MaxWaves);
1429}
1430
1431unsigned getOccupancyWithNumSGPRs(unsigned SGPRs, unsigned MaxWaves,
1433 if (Gen >= AMDGPUSubtarget::GFX10)
1434 return MaxWaves;
1435
1437 if (SGPRs <= 80)
1438 return 10;
1439 if (SGPRs <= 88)
1440 return 9;
1441 if (SGPRs <= 100)
1442 return 8;
1443 return 7;
1444 }
1445 if (SGPRs <= 48)
1446 return 10;
1447 if (SGPRs <= 56)
1448 return 9;
1449 if (SGPRs <= 64)
1450 return 8;
1451 if (SGPRs <= 72)
1452 return 7;
1453 if (SGPRs <= 80)
1454 return 6;
1455 return 5;
1456}
1457
1458unsigned getMinNumVGPRs(const MCSubtargetInfo *STI, unsigned WavesPerEU,
1459 unsigned DynamicVGPRBlockSize) {
1460 assert(WavesPerEU != 0);
1461
1462 unsigned MaxWavesPerEU = getMaxWavesPerEU(STI);
1463 if (WavesPerEU >= MaxWavesPerEU)
1464 return 0;
1465
1466 unsigned TotNumVGPRs = getTotalNumVGPRs(STI);
1467 unsigned AddrsableNumVGPRs =
1468 getAddressableNumVGPRs(STI, DynamicVGPRBlockSize);
1469 unsigned Granule = getVGPRAllocGranule(STI, DynamicVGPRBlockSize);
1470 unsigned MaxNumVGPRs = alignDown(TotNumVGPRs / WavesPerEU, Granule);
1471
1472 if (MaxNumVGPRs == alignDown(TotNumVGPRs / MaxWavesPerEU, Granule))
1473 return 0;
1474
1475 unsigned MinWavesPerEU = getNumWavesPerEUWithNumVGPRs(STI, AddrsableNumVGPRs,
1476 DynamicVGPRBlockSize);
1477 if (WavesPerEU < MinWavesPerEU)
1478 return getMinNumVGPRs(STI, MinWavesPerEU, DynamicVGPRBlockSize);
1479
1480 unsigned MaxNumVGPRsNext = alignDown(TotNumVGPRs / (WavesPerEU + 1), Granule);
1481 unsigned MinNumVGPRs = 1 + std::min(MaxNumVGPRs - Granule, MaxNumVGPRsNext);
1482 return std::min(MinNumVGPRs, AddrsableNumVGPRs);
1483}
1484
1485unsigned getMaxNumVGPRs(const MCSubtargetInfo *STI, unsigned WavesPerEU,
1486 unsigned DynamicVGPRBlockSize) {
1487 assert(WavesPerEU != 0);
1488
1489 unsigned MaxNumVGPRs =
1490 alignDown(getTotalNumVGPRs(STI) / WavesPerEU,
1491 getVGPRAllocGranule(STI, DynamicVGPRBlockSize));
1492 unsigned AddressableNumVGPRs =
1493 getAddressableNumVGPRs(STI, DynamicVGPRBlockSize);
1494 return std::min(MaxNumVGPRs, AddressableNumVGPRs);
1495}
1496
1497unsigned getEncodedNumVGPRBlocks(const MCSubtargetInfo *STI, unsigned NumVGPRs,
1498 std::optional<bool> EnableWavefrontSize32) {
1500 NumVGPRs, getVGPREncodingGranule(STI, EnableWavefrontSize32)) -
1501 1;
1502}
1503
1505 unsigned NumVGPRs,
1506 unsigned DynamicVGPRBlockSize,
1507 std::optional<bool> EnableWavefrontSize32) {
1509 NumVGPRs,
1510 getVGPRAllocGranule(STI, DynamicVGPRBlockSize, EnableWavefrontSize32));
1511}
1512} // end namespace IsaInfo
1513
1515 const MCSubtargetInfo *STI) {
1517 KernelCode.amd_kernel_code_version_major = 1;
1518 KernelCode.amd_kernel_code_version_minor = 2;
1519 KernelCode.amd_machine_kind = 1; // AMD_MACHINE_KIND_AMDGPU
1520 KernelCode.amd_machine_version_major = Version.Major;
1521 KernelCode.amd_machine_version_minor = Version.Minor;
1522 KernelCode.amd_machine_version_stepping = Version.Stepping;
1524 if (STI->getFeatureBits().test(FeatureWavefrontSize32)) {
1525 KernelCode.wavefront_size = 5;
1527 } else {
1528 KernelCode.wavefront_size = 6;
1529 }
1530
1531 // If the code object does not support indirect functions, then the value must
1532 // be 0xffffffff.
1533 KernelCode.call_convention = -1;
1534
1535 // These alignment values are specified in powers of two, so alignment =
1536 // 2^n. The minimum alignment is 2^4 = 16.
1537 KernelCode.kernarg_segment_alignment = 4;
1538 KernelCode.group_segment_alignment = 4;
1539 KernelCode.private_segment_alignment = 4;
1540
1541 if (Version.Major >= 10) {
1542 KernelCode.compute_pgm_resource_registers |=
1543 S_00B848_WGP_MODE(STI->getFeatureBits().test(FeatureCuMode) ? 0 : 1) |
1545 }
1546}
1547
1550}
1551
1554}
1555
1557 unsigned AS = GV->getAddressSpace();
1558 return AS == AMDGPUAS::CONSTANT_ADDRESS ||
1560}
1561
1563 return TT.getArch() == Triple::r600;
1564}
1565
1566static bool isValidRegPrefix(char C) {
1567 return C == 'v' || C == 's' || C == 'a';
1568}
1569
1570std::tuple<char, unsigned, unsigned>
1572 StringRef RegName = Constraint;
1573 if (!RegName.consume_front("{") || !RegName.consume_back("}"))
1574 return {};
1575
1576 char Kind = RegName.front();
1577 if (!isValidRegPrefix(Kind))
1578 return {};
1579
1580 RegName = RegName.drop_front();
1581 if (RegName.consume_front("[")) {
1582 unsigned Idx, End;
1583 bool Failed = RegName.consumeInteger(10, Idx);
1584 Failed |= !RegName.consume_front(":");
1585 Failed |= RegName.consumeInteger(10, End);
1586 Failed |= !RegName.consume_back("]");
1587 if (!Failed) {
1588 unsigned NumRegs = End - Idx + 1;
1589 if (NumRegs > 1)
1590 return {Kind, Idx, NumRegs};
1591 }
1592 } else {
1593 unsigned Idx;
1594 bool Failed = RegName.getAsInteger(10, Idx);
1595 if (!Failed)
1596 return {Kind, Idx, 1};
1597 }
1598
1599 return {};
1600}
1601
1602std::pair<unsigned, unsigned>
1604 std::pair<unsigned, unsigned> Default,
1605 bool OnlyFirstRequired) {
1606 if (auto Attr = getIntegerPairAttribute(F, Name, OnlyFirstRequired))
1607 return {Attr->first, Attr->second.value_or(Default.second)};
1608 return Default;
1609}
1610
1611std::optional<std::pair<unsigned, std::optional<unsigned>>>
1613 bool OnlyFirstRequired) {
1614 Attribute A = F.getFnAttribute(Name);
1615 if (!A.isStringAttribute())
1616 return std::nullopt;
1617
1618 LLVMContext &Ctx = F.getContext();
1619 std::pair<unsigned, std::optional<unsigned>> Ints;
1620 std::pair<StringRef, StringRef> Strs = A.getValueAsString().split(',');
1621 if (Strs.first.trim().getAsInteger(0, Ints.first)) {
1622 Ctx.emitError("can't parse first integer attribute " + Name);
1623 return std::nullopt;
1624 }
1625 unsigned Second = 0;
1626 if (Strs.second.trim().getAsInteger(0, Second)) {
1627 if (!OnlyFirstRequired || !Strs.second.trim().empty()) {
1628 Ctx.emitError("can't parse second integer attribute " + Name);
1629 return std::nullopt;
1630 }
1631 } else {
1632 Ints.second = Second;
1633 }
1634
1635 return Ints;
1636}
1637
1639 unsigned Size,
1640 unsigned DefaultVal) {
1641 std::optional<SmallVector<unsigned>> R =
1643 return R.has_value() ? *R : SmallVector<unsigned>(Size, DefaultVal);
1644}
1645
1646std::optional<SmallVector<unsigned>>
1648 assert(Size > 2);
1649 LLVMContext &Ctx = F.getContext();
1650
1651 Attribute A = F.getFnAttribute(Name);
1652 if (!A.isValid())
1653 return std::nullopt;
1654 if (!A.isStringAttribute()) {
1655 Ctx.emitError(Name + " is not a string attribute");
1656 return std::nullopt;
1657 }
1658
1660
1661 StringRef S = A.getValueAsString();
1662 unsigned i = 0;
1663 for (; !S.empty() && i < Size; i++) {
1664 std::pair<StringRef, StringRef> Strs = S.split(',');
1665 unsigned IntVal;
1666 if (Strs.first.trim().getAsInteger(0, IntVal)) {
1667 Ctx.emitError("can't parse integer attribute " + Strs.first + " in " +
1668 Name);
1669 return std::nullopt;
1670 }
1671 Vals[i] = IntVal;
1672 S = Strs.second;
1673 }
1674
1675 if (!S.empty() || i < Size) {
1676 Ctx.emitError("attribute " + Name +
1677 " has incorrect number of integers; expected " +
1678 llvm::utostr(Size));
1679 return std::nullopt;
1680 }
1681 return Vals;
1682}
1683
1684bool hasValueInRangeLikeMetadata(const MDNode &MD, int64_t Val) {
1685 assert((MD.getNumOperands() % 2 == 0) && "invalid number of operands!");
1686 for (unsigned I = 0, E = MD.getNumOperands() / 2; I != E; ++I) {
1687 auto Low =
1688 mdconst::extract<ConstantInt>(MD.getOperand(2 * I + 0))->getValue();
1689 auto High =
1690 mdconst::extract<ConstantInt>(MD.getOperand(2 * I + 1))->getValue();
1691 // There are two types of [A; B) ranges:
1692 // A < B, e.g. [4; 5) which is a range that only includes 4.
1693 // A > B, e.g. [5; 4) which is a range that wraps around and includes
1694 // everything except 4.
1695 if (Low.ult(High)) {
1696 if (Low.ule(Val) && High.ugt(Val))
1697 return true;
1698 } else {
1699 if (Low.uge(Val) && High.ult(Val))
1700 return true;
1701 }
1702 }
1703
1704 return false;
1705}
1706
1708 return (1 << (getVmcntBitWidthLo(Version.Major) +
1709 getVmcntBitWidthHi(Version.Major))) -
1710 1;
1711}
1712
1714 return (1 << getLoadcntBitWidth(Version.Major)) - 1;
1715}
1716
1718 return (1 << getSamplecntBitWidth(Version.Major)) - 1;
1719}
1720
1722 return (1 << getBvhcntBitWidth(Version.Major)) - 1;
1723}
1724
1726 return (1 << getExpcntBitWidth(Version.Major)) - 1;
1727}
1728
1730 return (1 << getLgkmcntBitWidth(Version.Major)) - 1;
1731}
1732
1734 return (1 << getDscntBitWidth(Version.Major)) - 1;
1735}
1736
1738 return (1 << getKmcntBitWidth(Version.Major)) - 1;
1739}
1740
1742 return (1 << getXcntBitWidth(Version.Major, Version.Minor)) - 1;
1743}
1744
1746 return (1 << getStorecntBitWidth(Version.Major)) - 1;
1747}
1748
1750 unsigned VmcntLo = getBitMask(getVmcntBitShiftLo(Version.Major),
1751 getVmcntBitWidthLo(Version.Major));
1752 unsigned Expcnt = getBitMask(getExpcntBitShift(Version.Major),
1753 getExpcntBitWidth(Version.Major));
1754 unsigned Lgkmcnt = getBitMask(getLgkmcntBitShift(Version.Major),
1755 getLgkmcntBitWidth(Version.Major));
1756 unsigned VmcntHi = getBitMask(getVmcntBitShiftHi(Version.Major),
1757 getVmcntBitWidthHi(Version.Major));
1758 return VmcntLo | Expcnt | Lgkmcnt | VmcntHi;
1759}
1760
1761unsigned decodeVmcnt(const IsaVersion &Version, unsigned Waitcnt) {
1762 unsigned VmcntLo = unpackBits(Waitcnt, getVmcntBitShiftLo(Version.Major),
1763 getVmcntBitWidthLo(Version.Major));
1764 unsigned VmcntHi = unpackBits(Waitcnt, getVmcntBitShiftHi(Version.Major),
1765 getVmcntBitWidthHi(Version.Major));
1766 return VmcntLo | VmcntHi << getVmcntBitWidthLo(Version.Major);
1767}
1768
1769unsigned decodeExpcnt(const IsaVersion &Version, unsigned Waitcnt) {
1770 return unpackBits(Waitcnt, getExpcntBitShift(Version.Major),
1771 getExpcntBitWidth(Version.Major));
1772}
1773
1774unsigned decodeLgkmcnt(const IsaVersion &Version, unsigned Waitcnt) {
1775 return unpackBits(Waitcnt, getLgkmcntBitShift(Version.Major),
1776 getLgkmcntBitWidth(Version.Major));
1777}
1778
1779void decodeWaitcnt(const IsaVersion &Version, unsigned Waitcnt, unsigned &Vmcnt,
1780 unsigned &Expcnt, unsigned &Lgkmcnt) {
1781 Vmcnt = decodeVmcnt(Version, Waitcnt);
1782 Expcnt = decodeExpcnt(Version, Waitcnt);
1783 Lgkmcnt = decodeLgkmcnt(Version, Waitcnt);
1784}
1785
1786Waitcnt decodeWaitcnt(const IsaVersion &Version, unsigned Encoded) {
1787 Waitcnt Decoded;
1788 Decoded.LoadCnt = decodeVmcnt(Version, Encoded);
1789 Decoded.ExpCnt = decodeExpcnt(Version, Encoded);
1790 Decoded.DsCnt = decodeLgkmcnt(Version, Encoded);
1791 return Decoded;
1792}
1793
1794unsigned encodeVmcnt(const IsaVersion &Version, unsigned Waitcnt,
1795 unsigned Vmcnt) {
1796 Waitcnt = packBits(Vmcnt, Waitcnt, getVmcntBitShiftLo(Version.Major),
1797 getVmcntBitWidthLo(Version.Major));
1798 return packBits(Vmcnt >> getVmcntBitWidthLo(Version.Major), Waitcnt,
1799 getVmcntBitShiftHi(Version.Major),
1800 getVmcntBitWidthHi(Version.Major));
1801}
1802
1803unsigned encodeExpcnt(const IsaVersion &Version, unsigned Waitcnt,
1804 unsigned Expcnt) {
1805 return packBits(Expcnt, Waitcnt, getExpcntBitShift(Version.Major),
1806 getExpcntBitWidth(Version.Major));
1807}
1808
1809unsigned encodeLgkmcnt(const IsaVersion &Version, unsigned Waitcnt,
1810 unsigned Lgkmcnt) {
1811 return packBits(Lgkmcnt, Waitcnt, getLgkmcntBitShift(Version.Major),
1812 getLgkmcntBitWidth(Version.Major));
1813}
1814
1815unsigned encodeWaitcnt(const IsaVersion &Version, unsigned Vmcnt,
1816 unsigned Expcnt, unsigned Lgkmcnt) {
1817 unsigned Waitcnt = getWaitcntBitMask(Version);
1819 Waitcnt = encodeExpcnt(Version, Waitcnt, Expcnt);
1820 Waitcnt = encodeLgkmcnt(Version, Waitcnt, Lgkmcnt);
1821 return Waitcnt;
1822}
1823
1824unsigned encodeWaitcnt(const IsaVersion &Version, const Waitcnt &Decoded) {
1825 return encodeWaitcnt(Version, Decoded.LoadCnt, Decoded.ExpCnt, Decoded.DsCnt);
1826}
1827
1829 bool IsStore) {
1830 unsigned Dscnt = getBitMask(getDscntBitShift(Version.Major),
1831 getDscntBitWidth(Version.Major));
1832 if (IsStore) {
1833 unsigned Storecnt = getBitMask(getLoadcntStorecntBitShift(Version.Major),
1834 getStorecntBitWidth(Version.Major));
1835 return Dscnt | Storecnt;
1836 }
1837 unsigned Loadcnt = getBitMask(getLoadcntStorecntBitShift(Version.Major),
1838 getLoadcntBitWidth(Version.Major));
1839 return Dscnt | Loadcnt;
1840}
1841
1842Waitcnt decodeLoadcntDscnt(const IsaVersion &Version, unsigned LoadcntDscnt) {
1843 Waitcnt Decoded;
1844 Decoded.LoadCnt =
1845 unpackBits(LoadcntDscnt, getLoadcntStorecntBitShift(Version.Major),
1846 getLoadcntBitWidth(Version.Major));
1847 Decoded.DsCnt = unpackBits(LoadcntDscnt, getDscntBitShift(Version.Major),
1848 getDscntBitWidth(Version.Major));
1849 return Decoded;
1850}
1851
1852Waitcnt decodeStorecntDscnt(const IsaVersion &Version, unsigned StorecntDscnt) {
1853 Waitcnt Decoded;
1854 Decoded.StoreCnt =
1855 unpackBits(StorecntDscnt, getLoadcntStorecntBitShift(Version.Major),
1856 getStorecntBitWidth(Version.Major));
1857 Decoded.DsCnt = unpackBits(StorecntDscnt, getDscntBitShift(Version.Major),
1858 getDscntBitWidth(Version.Major));
1859 return Decoded;
1860}
1861
1862static unsigned encodeLoadcnt(const IsaVersion &Version, unsigned Waitcnt,
1863 unsigned Loadcnt) {
1864 return packBits(Loadcnt, Waitcnt, getLoadcntStorecntBitShift(Version.Major),
1865 getLoadcntBitWidth(Version.Major));
1866}
1867
1868static unsigned encodeStorecnt(const IsaVersion &Version, unsigned Waitcnt,
1869 unsigned Storecnt) {
1870 return packBits(Storecnt, Waitcnt, getLoadcntStorecntBitShift(Version.Major),
1871 getStorecntBitWidth(Version.Major));
1872}
1873
1874static unsigned encodeDscnt(const IsaVersion &Version, unsigned Waitcnt,
1875 unsigned Dscnt) {
1876 return packBits(Dscnt, Waitcnt, getDscntBitShift(Version.Major),
1877 getDscntBitWidth(Version.Major));
1878}
1879
1880static unsigned encodeLoadcntDscnt(const IsaVersion &Version, unsigned Loadcnt,
1881 unsigned Dscnt) {
1882 unsigned Waitcnt = getCombinedCountBitMask(Version, false);
1883 Waitcnt = encodeLoadcnt(Version, Waitcnt, Loadcnt);
1885 return Waitcnt;
1886}
1887
1888unsigned encodeLoadcntDscnt(const IsaVersion &Version, const Waitcnt &Decoded) {
1889 return encodeLoadcntDscnt(Version, Decoded.LoadCnt, Decoded.DsCnt);
1890}
1891
1893 unsigned Storecnt, unsigned Dscnt) {
1894 unsigned Waitcnt = getCombinedCountBitMask(Version, true);
1895 Waitcnt = encodeStorecnt(Version, Waitcnt, Storecnt);
1897 return Waitcnt;
1898}
1899
1901 const Waitcnt &Decoded) {
1902 return encodeStorecntDscnt(Version, Decoded.StoreCnt, Decoded.DsCnt);
1903}
1904
1905//===----------------------------------------------------------------------===//
1906// Custom Operand Values
1907//===----------------------------------------------------------------------===//
1908
1910 int Size,
1911 const MCSubtargetInfo &STI) {
1912 unsigned Enc = 0;
1913 for (int Idx = 0; Idx < Size; ++Idx) {
1914 const auto &Op = Opr[Idx];
1915 if (Op.isSupported(STI))
1916 Enc |= Op.encode(Op.Default);
1917 }
1918 return Enc;
1919}
1920
1922 int Size, unsigned Code,
1923 bool &HasNonDefaultVal,
1924 const MCSubtargetInfo &STI) {
1925 unsigned UsedOprMask = 0;
1926 HasNonDefaultVal = false;
1927 for (int Idx = 0; Idx < Size; ++Idx) {
1928 const auto &Op = Opr[Idx];
1929 if (!Op.isSupported(STI))
1930 continue;
1931 UsedOprMask |= Op.getMask();
1932 unsigned Val = Op.decode(Code);
1933 if (!Op.isValid(Val))
1934 return false;
1935 HasNonDefaultVal |= (Val != Op.Default);
1936 }
1937 return (Code & ~UsedOprMask) == 0;
1938}
1939
1940static bool decodeCustomOperand(const CustomOperandVal *Opr, int Size,
1941 unsigned Code, int &Idx, StringRef &Name,
1942 unsigned &Val, bool &IsDefault,
1943 const MCSubtargetInfo &STI) {
1944 while (Idx < Size) {
1945 const auto &Op = Opr[Idx++];
1946 if (Op.isSupported(STI)) {
1947 Name = Op.Name;
1948 Val = Op.decode(Code);
1949 IsDefault = (Val == Op.Default);
1950 return true;
1951 }
1952 }
1953
1954 return false;
1955}
1956
1958 int64_t InputVal) {
1959 if (InputVal < 0 || InputVal > Op.Max)
1960 return OPR_VAL_INVALID;
1961 return Op.encode(InputVal);
1962}
1963
1964static int encodeCustomOperand(const CustomOperandVal *Opr, int Size,
1965 const StringRef Name, int64_t InputVal,
1966 unsigned &UsedOprMask,
1967 const MCSubtargetInfo &STI) {
1968 int InvalidId = OPR_ID_UNKNOWN;
1969 for (int Idx = 0; Idx < Size; ++Idx) {
1970 const auto &Op = Opr[Idx];
1971 if (Op.Name == Name) {
1972 if (!Op.isSupported(STI)) {
1973 InvalidId = OPR_ID_UNSUPPORTED;
1974 continue;
1975 }
1976 auto OprMask = Op.getMask();
1977 if (OprMask & UsedOprMask)
1978 return OPR_ID_DUPLICATE;
1979 UsedOprMask |= OprMask;
1980 return encodeCustomOperandVal(Op, InputVal);
1981 }
1982 }
1983 return InvalidId;
1984}
1985
1986//===----------------------------------------------------------------------===//
1987// DepCtr
1988//===----------------------------------------------------------------------===//
1989
1990namespace DepCtr {
1991
1993 static int Default = -1;
1994 if (Default == -1)
1996 return Default;
1997}
1998
1999bool isSymbolicDepCtrEncoding(unsigned Code, bool &HasNonDefaultVal,
2000 const MCSubtargetInfo &STI) {
2002 HasNonDefaultVal, STI);
2003}
2004
2005bool decodeDepCtr(unsigned Code, int &Id, StringRef &Name, unsigned &Val,
2006 bool &IsDefault, const MCSubtargetInfo &STI) {
2007 return decodeCustomOperand(DepCtrInfo, DEP_CTR_SIZE, Code, Id, Name, Val,
2008 IsDefault, STI);
2009}
2010
2011int encodeDepCtr(const StringRef Name, int64_t Val, unsigned &UsedOprMask,
2012 const MCSubtargetInfo &STI) {
2013 return encodeCustomOperand(DepCtrInfo, DEP_CTR_SIZE, Name, Val, UsedOprMask,
2014 STI);
2015}
2016
2017unsigned decodeFieldVmVsrc(unsigned Encoded) {
2018 return unpackBits(Encoded, getVmVsrcBitShift(), getVmVsrcBitWidth());
2019}
2020
2021unsigned decodeFieldVaVdst(unsigned Encoded) {
2022 return unpackBits(Encoded, getVaVdstBitShift(), getVaVdstBitWidth());
2023}
2024
2025unsigned decodeFieldSaSdst(unsigned Encoded) {
2026 return unpackBits(Encoded, getSaSdstBitShift(), getSaSdstBitWidth());
2027}
2028
2029unsigned decodeFieldVaSdst(unsigned Encoded) {
2030 return unpackBits(Encoded, getVaSdstBitShift(), getVaSdstBitWidth());
2031}
2032
2033unsigned decodeFieldVaVcc(unsigned Encoded) {
2034 return unpackBits(Encoded, getVaVccBitShift(), getVaVccBitWidth());
2035}
2036
2037unsigned decodeFieldVaSsrc(unsigned Encoded) {
2038 return unpackBits(Encoded, getVaSsrcBitShift(), getVaSsrcBitWidth());
2039}
2040
2041unsigned decodeFieldHoldCnt(unsigned Encoded) {
2042 return unpackBits(Encoded, getHoldCntBitShift(), getHoldCntWidth());
2043}
2044
2045unsigned encodeFieldVmVsrc(unsigned Encoded, unsigned VmVsrc) {
2046 return packBits(VmVsrc, Encoded, getVmVsrcBitShift(), getVmVsrcBitWidth());
2047}
2048
2049unsigned encodeFieldVmVsrc(unsigned VmVsrc) {
2050 return encodeFieldVmVsrc(0xffff, VmVsrc);
2051}
2052
2053unsigned encodeFieldVaVdst(unsigned Encoded, unsigned VaVdst) {
2054 return packBits(VaVdst, Encoded, getVaVdstBitShift(), getVaVdstBitWidth());
2055}
2056
2057unsigned encodeFieldVaVdst(unsigned VaVdst) {
2058 return encodeFieldVaVdst(0xffff, VaVdst);
2059}
2060
2061unsigned encodeFieldSaSdst(unsigned Encoded, unsigned SaSdst) {
2062 return packBits(SaSdst, Encoded, getSaSdstBitShift(), getSaSdstBitWidth());
2063}
2064
2065unsigned encodeFieldSaSdst(unsigned SaSdst) {
2066 return encodeFieldSaSdst(0xffff, SaSdst);
2067}
2068
2069unsigned encodeFieldVaSdst(unsigned Encoded, unsigned VaSdst) {
2070 return packBits(VaSdst, Encoded, getVaSdstBitShift(), getVaSdstBitWidth());
2071}
2072
2073unsigned encodeFieldVaSdst(unsigned VaSdst) {
2074 return encodeFieldVaSdst(0xffff, VaSdst);
2075}
2076
2077unsigned encodeFieldVaVcc(unsigned Encoded, unsigned VaVcc) {
2078 return packBits(VaVcc, Encoded, getVaVccBitShift(), getVaVccBitWidth());
2079}
2080
2081unsigned encodeFieldVaVcc(unsigned VaVcc) {
2082 return encodeFieldVaVcc(0xffff, VaVcc);
2083}
2084
2085unsigned encodeFieldVaSsrc(unsigned Encoded, unsigned VaSsrc) {
2086 return packBits(VaSsrc, Encoded, getVaSsrcBitShift(), getVaSsrcBitWidth());
2087}
2088
2089unsigned encodeFieldVaSsrc(unsigned VaSsrc) {
2090 return encodeFieldVaSsrc(0xffff, VaSsrc);
2091}
2092
2093unsigned encodeFieldHoldCnt(unsigned Encoded, unsigned HoldCnt) {
2094 return packBits(HoldCnt, Encoded, getHoldCntBitShift(), getHoldCntWidth());
2095}
2096
2097unsigned encodeFieldHoldCnt(unsigned HoldCnt) {
2098 return encodeFieldHoldCnt(0xffff, HoldCnt);
2099}
2100
2101} // namespace DepCtr
2102
2103//===----------------------------------------------------------------------===//
2104// exp tgt
2105//===----------------------------------------------------------------------===//
2106
2107namespace Exp {
2108
2109struct ExpTgt {
2111 unsigned Tgt;
2112 unsigned MaxIndex;
2113};
2114
2115// clang-format off
2116static constexpr ExpTgt ExpTgtInfo[] = {
2117 {{"null"}, ET_NULL, ET_NULL_MAX_IDX},
2118 {{"mrtz"}, ET_MRTZ, ET_MRTZ_MAX_IDX},
2119 {{"prim"}, ET_PRIM, ET_PRIM_MAX_IDX},
2120 {{"mrt"}, ET_MRT0, ET_MRT_MAX_IDX},
2121 {{"pos"}, ET_POS0, ET_POS_MAX_IDX},
2122 {{"dual_src_blend"},ET_DUAL_SRC_BLEND0, ET_DUAL_SRC_BLEND_MAX_IDX},
2123 {{"param"}, ET_PARAM0, ET_PARAM_MAX_IDX},
2124};
2125// clang-format on
2126
2127bool getTgtName(unsigned Id, StringRef &Name, int &Index) {
2128 for (const ExpTgt &Val : ExpTgtInfo) {
2129 if (Val.Tgt <= Id && Id <= Val.Tgt + Val.MaxIndex) {
2130 Index = (Val.MaxIndex == 0) ? -1 : (Id - Val.Tgt);
2131 Name = Val.Name;
2132 return true;
2133 }
2134 }
2135 return false;
2136}
2137
2138unsigned getTgtId(const StringRef Name) {
2139
2140 for (const ExpTgt &Val : ExpTgtInfo) {
2141 if (Val.MaxIndex == 0 && Name == Val.Name)
2142 return Val.Tgt;
2143
2144 if (Val.MaxIndex > 0 && Name.starts_with(Val.Name)) {
2145 StringRef Suffix = Name.drop_front(Val.Name.size());
2146
2147 unsigned Id;
2148 if (Suffix.getAsInteger(10, Id) || Id > Val.MaxIndex)
2149 return ET_INVALID;
2150
2151 // Disable leading zeroes
2152 if (Suffix.size() > 1 && Suffix[0] == '0')
2153 return ET_INVALID;
2154
2155 return Val.Tgt + Id;
2156 }
2157 }
2158 return ET_INVALID;
2159}
2160
2161bool isSupportedTgtId(unsigned Id, const MCSubtargetInfo &STI) {
2162 switch (Id) {
2163 case ET_NULL:
2164 return !isGFX11Plus(STI);
2165 case ET_POS4:
2166 case ET_PRIM:
2167 return isGFX10Plus(STI);
2168 case ET_DUAL_SRC_BLEND0:
2169 case ET_DUAL_SRC_BLEND1:
2170 return isGFX11Plus(STI);
2171 default:
2172 if (Id >= ET_PARAM0 && Id <= ET_PARAM31)
2173 return !isGFX11Plus(STI);
2174 return true;
2175 }
2176}
2177
2178} // namespace Exp
2179
2180//===----------------------------------------------------------------------===//
2181// MTBUF Format
2182//===----------------------------------------------------------------------===//
2183
2184namespace MTBUFFormat {
2185
2186int64_t getDfmt(const StringRef Name) {
2187 for (int Id = DFMT_MIN; Id <= DFMT_MAX; ++Id) {
2188 if (Name == DfmtSymbolic[Id])
2189 return Id;
2190 }
2191 return DFMT_UNDEF;
2192}
2193
2195 assert(Id <= DFMT_MAX);
2196 return DfmtSymbolic[Id];
2197}
2198
2200 if (isSI(STI) || isCI(STI))
2201 return NfmtSymbolicSICI;
2202 if (isVI(STI) || isGFX9(STI))
2203 return NfmtSymbolicVI;
2204 return NfmtSymbolicGFX10;
2205}
2206
2207int64_t getNfmt(const StringRef Name, const MCSubtargetInfo &STI) {
2208 const auto *lookupTable = getNfmtLookupTable(STI);
2209 for (int Id = NFMT_MIN; Id <= NFMT_MAX; ++Id) {
2210 if (Name == lookupTable[Id])
2211 return Id;
2212 }
2213 return NFMT_UNDEF;
2214}
2215
2216StringRef getNfmtName(unsigned Id, const MCSubtargetInfo &STI) {
2217 assert(Id <= NFMT_MAX);
2218 return getNfmtLookupTable(STI)[Id];
2219}
2220
2221bool isValidDfmtNfmt(unsigned Id, const MCSubtargetInfo &STI) {
2222 unsigned Dfmt;
2223 unsigned Nfmt;
2224 decodeDfmtNfmt(Id, Dfmt, Nfmt);
2225 return isValidNfmt(Nfmt, STI);
2226}
2227
2228bool isValidNfmt(unsigned Id, const MCSubtargetInfo &STI) {
2229 return !getNfmtName(Id, STI).empty();
2230}
2231
2232int64_t encodeDfmtNfmt(unsigned Dfmt, unsigned Nfmt) {
2233 return (Dfmt << DFMT_SHIFT) | (Nfmt << NFMT_SHIFT);
2234}
2235
2236void decodeDfmtNfmt(unsigned Format, unsigned &Dfmt, unsigned &Nfmt) {
2237 Dfmt = (Format >> DFMT_SHIFT) & DFMT_MASK;
2238 Nfmt = (Format >> NFMT_SHIFT) & NFMT_MASK;
2239}
2240
2242 if (isGFX11Plus(STI)) {
2243 for (int Id = UfmtGFX11::UFMT_FIRST; Id <= UfmtGFX11::UFMT_LAST; ++Id) {
2244 if (Name == UfmtSymbolicGFX11[Id])
2245 return Id;
2246 }
2247 } else {
2248 for (int Id = UfmtGFX10::UFMT_FIRST; Id <= UfmtGFX10::UFMT_LAST; ++Id) {
2249 if (Name == UfmtSymbolicGFX10[Id])
2250 return Id;
2251 }
2252 }
2253 return UFMT_UNDEF;
2254}
2255
2257 if (isValidUnifiedFormat(Id, STI))
2258 return isGFX10(STI) ? UfmtSymbolicGFX10[Id] : UfmtSymbolicGFX11[Id];
2259 return "";
2260}
2261
2262bool isValidUnifiedFormat(unsigned Id, const MCSubtargetInfo &STI) {
2263 return isGFX10(STI) ? Id <= UfmtGFX10::UFMT_LAST : Id <= UfmtGFX11::UFMT_LAST;
2264}
2265
2266int64_t convertDfmtNfmt2Ufmt(unsigned Dfmt, unsigned Nfmt,
2267 const MCSubtargetInfo &STI) {
2268 int64_t Fmt = encodeDfmtNfmt(Dfmt, Nfmt);
2269 if (isGFX11Plus(STI)) {
2270 for (int Id = UfmtGFX11::UFMT_FIRST; Id <= UfmtGFX11::UFMT_LAST; ++Id) {
2271 if (Fmt == DfmtNfmt2UFmtGFX11[Id])
2272 return Id;
2273 }
2274 } else {
2275 for (int Id = UfmtGFX10::UFMT_FIRST; Id <= UfmtGFX10::UFMT_LAST; ++Id) {
2276 if (Fmt == DfmtNfmt2UFmtGFX10[Id])
2277 return Id;
2278 }
2279 }
2280 return UFMT_UNDEF;
2281}
2282
2283bool isValidFormatEncoding(unsigned Val, const MCSubtargetInfo &STI) {
2284 return isGFX10Plus(STI) ? (Val <= UFMT_MAX) : (Val <= DFMT_NFMT_MAX);
2285}
2286
2288 if (isGFX10Plus(STI))
2289 return UFMT_DEFAULT;
2290 return DFMT_NFMT_DEFAULT;
2291}
2292
2293} // namespace MTBUFFormat
2294
2295//===----------------------------------------------------------------------===//
2296// SendMsg
2297//===----------------------------------------------------------------------===//
2298
2299namespace SendMsg {
2300
2303}
2304
2305bool isValidMsgId(int64_t MsgId, const MCSubtargetInfo &STI) {
2306 return (MsgId & ~(getMsgIdMask(STI))) == 0;
2307}
2308
2309bool isValidMsgOp(int64_t MsgId, int64_t OpId, const MCSubtargetInfo &STI,
2310 bool Strict) {
2311 assert(isValidMsgId(MsgId, STI));
2312
2313 if (!Strict)
2314 return 0 <= OpId && isUInt<OP_WIDTH_>(OpId);
2315
2316 if (msgRequiresOp(MsgId, STI)) {
2317 if (MsgId == ID_GS_PreGFX11 && OpId == OP_GS_NOP)
2318 return false;
2319
2320 return !getMsgOpName(MsgId, OpId, STI).empty();
2321 }
2322
2323 return OpId == OP_NONE_;
2324}
2325
2326bool isValidMsgStream(int64_t MsgId, int64_t OpId, int64_t StreamId,
2327 const MCSubtargetInfo &STI, bool Strict) {
2328 assert(isValidMsgOp(MsgId, OpId, STI, Strict));
2329
2330 if (!Strict)
2331 return 0 <= StreamId && isUInt<STREAM_ID_WIDTH_>(StreamId);
2332
2333 if (!isGFX11Plus(STI)) {
2334 switch (MsgId) {
2335 case ID_GS_PreGFX11:
2338 return (OpId == OP_GS_NOP)
2341 }
2342 }
2343 return StreamId == STREAM_ID_NONE_;
2344}
2345
2346bool msgRequiresOp(int64_t MsgId, const MCSubtargetInfo &STI) {
2347 return MsgId == ID_SYSMSG ||
2348 (!isGFX11Plus(STI) &&
2349 (MsgId == ID_GS_PreGFX11 || MsgId == ID_GS_DONE_PreGFX11));
2350}
2351
2352bool msgSupportsStream(int64_t MsgId, int64_t OpId,
2353 const MCSubtargetInfo &STI) {
2354 return !isGFX11Plus(STI) &&
2355 (MsgId == ID_GS_PreGFX11 || MsgId == ID_GS_DONE_PreGFX11) &&
2356 OpId != OP_GS_NOP;
2357}
2358
2359void decodeMsg(unsigned Val, uint16_t &MsgId, uint16_t &OpId,
2360 uint16_t &StreamId, const MCSubtargetInfo &STI) {
2361 MsgId = Val & getMsgIdMask(STI);
2362 if (isGFX11Plus(STI)) {
2363 OpId = 0;
2364 StreamId = 0;
2365 } else {
2366 OpId = (Val & OP_MASK_) >> OP_SHIFT_;
2368 }
2369}
2370
2372 return MsgId | (OpId << OP_SHIFT_) | (StreamId << STREAM_ID_SHIFT_);
2373}
2374
2375} // namespace SendMsg
2376
2377//===----------------------------------------------------------------------===//
2378//
2379//===----------------------------------------------------------------------===//
2380
2382 return F.getFnAttributeAsParsedInteger("InitialPSInputAddr", 0);
2383}
2384
2386 // As a safe default always respond as if PS has color exports.
2387 return F.getFnAttributeAsParsedInteger(
2388 "amdgpu-color-export",
2389 F.getCallingConv() == CallingConv::AMDGPU_PS ? 1 : 0) != 0;
2390}
2391
2393 return F.getFnAttributeAsParsedInteger("amdgpu-depth-export", 0) != 0;
2394}
2395
2397 unsigned BlockSize =
2398 F.getFnAttributeAsParsedInteger("amdgpu-dynamic-vgpr-block-size", 0);
2399
2400 if (BlockSize == 16 || BlockSize == 32)
2401 return BlockSize;
2402
2403 return 0;
2404}
2405
2406bool hasXNACK(const MCSubtargetInfo &STI) {
2407 return STI.hasFeature(AMDGPU::FeatureXNACK);
2408}
2409
2410bool hasSRAMECC(const MCSubtargetInfo &STI) {
2411 return STI.hasFeature(AMDGPU::FeatureSRAMECC);
2412}
2413
2415 return STI.hasFeature(AMDGPU::FeatureMIMG_R128) &&
2416 !STI.hasFeature(AMDGPU::FeatureR128A16);
2417}
2418
2419bool hasA16(const MCSubtargetInfo &STI) {
2420 return STI.hasFeature(AMDGPU::FeatureA16);
2421}
2422
2423bool hasG16(const MCSubtargetInfo &STI) {
2424 return STI.hasFeature(AMDGPU::FeatureG16);
2425}
2426
2428 return !STI.hasFeature(AMDGPU::FeatureUnpackedD16VMem) && !isCI(STI) &&
2429 !isSI(STI);
2430}
2431
2432bool hasGDS(const MCSubtargetInfo &STI) {
2433 return STI.hasFeature(AMDGPU::FeatureGDS);
2434}
2435
2436unsigned getNSAMaxSize(const MCSubtargetInfo &STI, bool HasSampler) {
2437 auto Version = getIsaVersion(STI.getCPU());
2438 if (Version.Major == 10)
2439 return Version.Minor >= 3 ? 13 : 5;
2440 if (Version.Major == 11)
2441 return 5;
2442 if (Version.Major >= 12)
2443 return HasSampler ? 4 : 5;
2444 return 0;
2445}
2446
2448 if (isGFX1250(STI))
2449 return 32;
2450 return 16;
2451}
2452
2453bool isSI(const MCSubtargetInfo &STI) {
2454 return STI.hasFeature(AMDGPU::FeatureSouthernIslands);
2455}
2456
2457bool isCI(const MCSubtargetInfo &STI) {
2458 return STI.hasFeature(AMDGPU::FeatureSeaIslands);
2459}
2460
2461bool isVI(const MCSubtargetInfo &STI) {
2462 return STI.hasFeature(AMDGPU::FeatureVolcanicIslands);
2463}
2464
2465bool isGFX9(const MCSubtargetInfo &STI) {
2466 return STI.hasFeature(AMDGPU::FeatureGFX9);
2467}
2468
2470 return isGFX9(STI) || isGFX10(STI);
2471}
2472
2474 return isGFX9(STI) || isGFX10(STI) || isGFX11(STI);
2475}
2476
2478 return isVI(STI) || isGFX9(STI) || isGFX10(STI);
2479}
2480
2481bool isGFX8Plus(const MCSubtargetInfo &STI) {
2482 return isVI(STI) || isGFX9Plus(STI);
2483}
2484
2485bool isGFX9Plus(const MCSubtargetInfo &STI) {
2486 return isGFX9(STI) || isGFX10Plus(STI);
2487}
2488
2489bool isNotGFX9Plus(const MCSubtargetInfo &STI) { return !isGFX9Plus(STI); }
2490
2491bool isGFX10(const MCSubtargetInfo &STI) {
2492 return STI.hasFeature(AMDGPU::FeatureGFX10);
2493}
2494
2496 return isGFX10(STI) || isGFX11(STI);
2497}
2498
2500 return isGFX10(STI) || isGFX11Plus(STI);
2501}
2502
2503bool isGFX11(const MCSubtargetInfo &STI) {
2504 return STI.hasFeature(AMDGPU::FeatureGFX11);
2505}
2506
2508 return isGFX11(STI) || isGFX12Plus(STI);
2509}
2510
2511bool isGFX12(const MCSubtargetInfo &STI) {
2512 return STI.getFeatureBits()[AMDGPU::FeatureGFX12];
2513}
2514
2515bool isGFX12Plus(const MCSubtargetInfo &STI) { return isGFX12(STI); }
2516
2517bool isNotGFX12Plus(const MCSubtargetInfo &STI) { return !isGFX12Plus(STI); }
2518
2519bool isGFX1250(const MCSubtargetInfo &STI) {
2520 return STI.getFeatureBits()[AMDGPU::FeatureGFX1250Insts];
2521}
2522
2524 if (isGFX1250(STI))
2525 return false;
2526 return isGFX10Plus(STI);
2527}
2528
2529bool isNotGFX11Plus(const MCSubtargetInfo &STI) { return !isGFX11Plus(STI); }
2530
2532 return isSI(STI) || isCI(STI) || isVI(STI) || isGFX9(STI);
2533}
2534
2536 return isGFX10(STI) && !AMDGPU::isGFX10_BEncoding(STI);
2537}
2538
2540 return STI.hasFeature(AMDGPU::FeatureGCN3Encoding);
2541}
2542
2544 return STI.hasFeature(AMDGPU::FeatureGFX10_AEncoding);
2545}
2546
2548 return STI.hasFeature(AMDGPU::FeatureGFX10_BEncoding);
2549}
2550
2552 return STI.hasFeature(AMDGPU::FeatureGFX10_3Insts);
2553}
2554
2556 return isGFX10_BEncoding(STI) && !isGFX12Plus(STI);
2557}
2558
2559bool isGFX90A(const MCSubtargetInfo &STI) {
2560 return STI.hasFeature(AMDGPU::FeatureGFX90AInsts);
2561}
2562
2563bool isGFX940(const MCSubtargetInfo &STI) {
2564 return STI.hasFeature(AMDGPU::FeatureGFX940Insts);
2565}
2566
2568 return STI.hasFeature(AMDGPU::FeatureArchitectedFlatScratch);
2569}
2570
2572 return STI.hasFeature(AMDGPU::FeatureMAIInsts);
2573}
2574
2575bool hasVOPD(const MCSubtargetInfo &STI) {
2576 return STI.hasFeature(AMDGPU::FeatureVOPD);
2577}
2578
2580 return STI.hasFeature(AMDGPU::FeatureDPPSrc1SGPR);
2581}
2582
2584 return STI.hasFeature(AMDGPU::FeatureKernargPreload);
2585}
2586
2587int32_t getTotalNumVGPRs(bool has90AInsts, int32_t ArgNumAGPR,
2588 int32_t ArgNumVGPR) {
2589 if (has90AInsts && ArgNumAGPR)
2590 return alignTo(ArgNumVGPR, 4) + ArgNumAGPR;
2591 return std::max(ArgNumVGPR, ArgNumAGPR);
2592}
2593
2595 const MCRegisterClass SGPRClass = TRI->getRegClass(AMDGPU::SReg_32RegClassID);
2596 const MCRegister FirstSubReg = TRI->getSubReg(Reg, AMDGPU::sub0);
2597 return SGPRClass.contains(FirstSubReg != 0 ? FirstSubReg : Reg) ||
2598 Reg == AMDGPU::SCC;
2599}
2600
2602 return MRI.getEncodingValue(Reg) & AMDGPU::HWEncoding::IS_HI16;
2603}
2604
2605#define MAP_REG2REG \
2606 using namespace AMDGPU; \
2607 switch (Reg.id()) { \
2608 default: \
2609 return Reg; \
2610 CASE_CI_VI(FLAT_SCR) \
2611 CASE_CI_VI(FLAT_SCR_LO) \
2612 CASE_CI_VI(FLAT_SCR_HI) \
2613 CASE_VI_GFX9PLUS(TTMP0) \
2614 CASE_VI_GFX9PLUS(TTMP1) \
2615 CASE_VI_GFX9PLUS(TTMP2) \
2616 CASE_VI_GFX9PLUS(TTMP3) \
2617 CASE_VI_GFX9PLUS(TTMP4) \
2618 CASE_VI_GFX9PLUS(TTMP5) \
2619 CASE_VI_GFX9PLUS(TTMP6) \
2620 CASE_VI_GFX9PLUS(TTMP7) \
2621 CASE_VI_GFX9PLUS(TTMP8) \
2622 CASE_VI_GFX9PLUS(TTMP9) \
2623 CASE_VI_GFX9PLUS(TTMP10) \
2624 CASE_VI_GFX9PLUS(TTMP11) \
2625 CASE_VI_GFX9PLUS(TTMP12) \
2626 CASE_VI_GFX9PLUS(TTMP13) \
2627 CASE_VI_GFX9PLUS(TTMP14) \
2628 CASE_VI_GFX9PLUS(TTMP15) \
2629 CASE_VI_GFX9PLUS(TTMP0_TTMP1) \
2630 CASE_VI_GFX9PLUS(TTMP2_TTMP3) \
2631 CASE_VI_GFX9PLUS(TTMP4_TTMP5) \
2632 CASE_VI_GFX9PLUS(TTMP6_TTMP7) \
2633 CASE_VI_GFX9PLUS(TTMP8_TTMP9) \
2634 CASE_VI_GFX9PLUS(TTMP10_TTMP11) \
2635 CASE_VI_GFX9PLUS(TTMP12_TTMP13) \
2636 CASE_VI_GFX9PLUS(TTMP14_TTMP15) \
2637 CASE_VI_GFX9PLUS(TTMP0_TTMP1_TTMP2_TTMP3) \
2638 CASE_VI_GFX9PLUS(TTMP4_TTMP5_TTMP6_TTMP7) \
2639 CASE_VI_GFX9PLUS(TTMP8_TTMP9_TTMP10_TTMP11) \
2640 CASE_VI_GFX9PLUS(TTMP12_TTMP13_TTMP14_TTMP15) \
2641 CASE_VI_GFX9PLUS(TTMP0_TTMP1_TTMP2_TTMP3_TTMP4_TTMP5_TTMP6_TTMP7) \
2642 CASE_VI_GFX9PLUS(TTMP4_TTMP5_TTMP6_TTMP7_TTMP8_TTMP9_TTMP10_TTMP11) \
2643 CASE_VI_GFX9PLUS(TTMP8_TTMP9_TTMP10_TTMP11_TTMP12_TTMP13_TTMP14_TTMP15) \
2644 CASE_VI_GFX9PLUS( \
2645 TTMP0_TTMP1_TTMP2_TTMP3_TTMP4_TTMP5_TTMP6_TTMP7_TTMP8_TTMP9_TTMP10_TTMP11_TTMP12_TTMP13_TTMP14_TTMP15) \
2646 CASE_GFXPRE11_GFX11PLUS(M0) \
2647 CASE_GFXPRE11_GFX11PLUS(SGPR_NULL) \
2648 CASE_GFXPRE11_GFX11PLUS_TO(SGPR_NULL64, SGPR_NULL) \
2649 }
2650
2651#define CASE_CI_VI(node) \
2652 assert(!isSI(STI)); \
2653 case node: \
2654 return isCI(STI) ? node##_ci : node##_vi;
2655
2656#define CASE_VI_GFX9PLUS(node) \
2657 case node: \
2658 return isGFX9Plus(STI) ? node##_gfx9plus : node##_vi;
2659
2660#define CASE_GFXPRE11_GFX11PLUS(node) \
2661 case node: \
2662 return isGFX11Plus(STI) ? node##_gfx11plus : node##_gfxpre11;
2663
2664#define CASE_GFXPRE11_GFX11PLUS_TO(node, result) \
2665 case node: \
2666 return isGFX11Plus(STI) ? result##_gfx11plus : result##_gfxpre11;
2667
2669 if (STI.getTargetTriple().getArch() == Triple::r600)
2670 return Reg;
2672}
2673
2674#undef CASE_CI_VI
2675#undef CASE_VI_GFX9PLUS
2676#undef CASE_GFXPRE11_GFX11PLUS
2677#undef CASE_GFXPRE11_GFX11PLUS_TO
2678
2679#define CASE_CI_VI(node) \
2680 case node##_ci: \
2681 case node##_vi: \
2682 return node;
2683#define CASE_VI_GFX9PLUS(node) \
2684 case node##_vi: \
2685 case node##_gfx9plus: \
2686 return node;
2687#define CASE_GFXPRE11_GFX11PLUS(node) \
2688 case node##_gfx11plus: \
2689 case node##_gfxpre11: \
2690 return node;
2691#define CASE_GFXPRE11_GFX11PLUS_TO(node, result)
2692
2694
2695bool isInlineValue(unsigned Reg) {
2696 switch (Reg) {
2697 case AMDGPU::SRC_SHARED_BASE_LO:
2698 case AMDGPU::SRC_SHARED_BASE:
2699 case AMDGPU::SRC_SHARED_LIMIT_LO:
2700 case AMDGPU::SRC_SHARED_LIMIT:
2701 case AMDGPU::SRC_PRIVATE_BASE_LO:
2702 case AMDGPU::SRC_PRIVATE_BASE:
2703 case AMDGPU::SRC_PRIVATE_LIMIT_LO:
2704 case AMDGPU::SRC_PRIVATE_LIMIT:
2705 case AMDGPU::SRC_FLAT_SCRATCH_BASE_LO:
2706 case AMDGPU::SRC_FLAT_SCRATCH_BASE_HI:
2707 case AMDGPU::SRC_POPS_EXITING_WAVE_ID:
2708 return true;
2709 case AMDGPU::SRC_VCCZ:
2710 case AMDGPU::SRC_EXECZ:
2711 case AMDGPU::SRC_SCC:
2712 return true;
2713 case AMDGPU::SGPR_NULL:
2714 return true;
2715 default:
2716 return false;
2717 }
2718}
2719
2720#undef CASE_CI_VI
2721#undef CASE_VI_GFX9PLUS
2722#undef CASE_GFXPRE11_GFX11PLUS
2723#undef CASE_GFXPRE11_GFX11PLUS_TO
2724#undef MAP_REG2REG
2725
2726bool isKImmOperand(const MCInstrDesc &Desc, unsigned OpNo) {
2727 assert(OpNo < Desc.NumOperands);
2728 unsigned OpType = Desc.operands()[OpNo].OperandType;
2729 return OpType >= AMDGPU::OPERAND_KIMM_FIRST &&
2730 OpType <= AMDGPU::OPERAND_KIMM_LAST;
2731}
2732
2733bool isSISrcFPOperand(const MCInstrDesc &Desc, unsigned OpNo) {
2734 assert(OpNo < Desc.NumOperands);
2735 unsigned OpType = Desc.operands()[OpNo].OperandType;
2736 switch (OpType) {
2749 return true;
2750 default:
2751 return false;
2752 }
2753}
2754
2755bool isSISrcInlinableOperand(const MCInstrDesc &Desc, unsigned OpNo) {
2756 assert(OpNo < Desc.NumOperands);
2757 unsigned OpType = Desc.operands()[OpNo].OperandType;
2758 return (OpType >= AMDGPU::OPERAND_REG_INLINE_C_FIRST &&
2762}
2763
2764// Avoid using MCRegisterClass::getSize, since that function will go away
2765// (move from MC* level to Target* level). Return size in bits.
2766unsigned getRegBitWidth(unsigned RCID) {
2767 switch (RCID) {
2768 case AMDGPU::VGPR_16RegClassID:
2769 case AMDGPU::VGPR_16_Lo128RegClassID:
2770 case AMDGPU::SGPR_LO16RegClassID:
2771 case AMDGPU::AGPR_LO16RegClassID:
2772 return 16;
2773 case AMDGPU::SGPR_32RegClassID:
2774 case AMDGPU::VGPR_32RegClassID:
2775 case AMDGPU::VRegOrLds_32RegClassID:
2776 case AMDGPU::AGPR_32RegClassID:
2777 case AMDGPU::VS_32RegClassID:
2778 case AMDGPU::AV_32RegClassID:
2779 case AMDGPU::SReg_32RegClassID:
2780 case AMDGPU::SReg_32_XM0RegClassID:
2781 case AMDGPU::SRegOrLds_32RegClassID:
2782 return 32;
2783 case AMDGPU::SGPR_64RegClassID:
2784 case AMDGPU::VS_64RegClassID:
2785 case AMDGPU::SReg_64RegClassID:
2786 case AMDGPU::VReg_64RegClassID:
2787 case AMDGPU::AReg_64RegClassID:
2788 case AMDGPU::SReg_64_XEXECRegClassID:
2789 case AMDGPU::VReg_64_Align2RegClassID:
2790 case AMDGPU::AReg_64_Align2RegClassID:
2791 case AMDGPU::AV_64RegClassID:
2792 case AMDGPU::AV_64_Align2RegClassID:
2793 return 64;
2794 case AMDGPU::SGPR_96RegClassID:
2795 case AMDGPU::SReg_96RegClassID:
2796 case AMDGPU::VReg_96RegClassID:
2797 case AMDGPU::AReg_96RegClassID:
2798 case AMDGPU::VReg_96_Align2RegClassID:
2799 case AMDGPU::AReg_96_Align2RegClassID:
2800 case AMDGPU::AV_96RegClassID:
2801 case AMDGPU::AV_96_Align2RegClassID:
2802 return 96;
2803 case AMDGPU::SGPR_128RegClassID:
2804 case AMDGPU::SReg_128RegClassID:
2805 case AMDGPU::VReg_128RegClassID:
2806 case AMDGPU::AReg_128RegClassID:
2807 case AMDGPU::VReg_128_Align2RegClassID:
2808 case AMDGPU::AReg_128_Align2RegClassID:
2809 case AMDGPU::AV_128RegClassID:
2810 case AMDGPU::AV_128_Align2RegClassID:
2811 case AMDGPU::SReg_128_XNULLRegClassID:
2812 return 128;
2813 case AMDGPU::SGPR_160RegClassID:
2814 case AMDGPU::SReg_160RegClassID:
2815 case AMDGPU::VReg_160RegClassID:
2816 case AMDGPU::AReg_160RegClassID:
2817 case AMDGPU::VReg_160_Align2RegClassID:
2818 case AMDGPU::AReg_160_Align2RegClassID:
2819 case AMDGPU::AV_160RegClassID:
2820 case AMDGPU::AV_160_Align2RegClassID:
2821 return 160;
2822 case AMDGPU::SGPR_192RegClassID:
2823 case AMDGPU::SReg_192RegClassID:
2824 case AMDGPU::VReg_192RegClassID:
2825 case AMDGPU::AReg_192RegClassID:
2826 case AMDGPU::VReg_192_Align2RegClassID:
2827 case AMDGPU::AReg_192_Align2RegClassID:
2828 case AMDGPU::AV_192RegClassID:
2829 case AMDGPU::AV_192_Align2RegClassID:
2830 return 192;
2831 case AMDGPU::SGPR_224RegClassID:
2832 case AMDGPU::SReg_224RegClassID:
2833 case AMDGPU::VReg_224RegClassID:
2834 case AMDGPU::AReg_224RegClassID:
2835 case AMDGPU::VReg_224_Align2RegClassID:
2836 case AMDGPU::AReg_224_Align2RegClassID:
2837 case AMDGPU::AV_224RegClassID:
2838 case AMDGPU::AV_224_Align2RegClassID:
2839 return 224;
2840 case AMDGPU::SGPR_256RegClassID:
2841 case AMDGPU::SReg_256RegClassID:
2842 case AMDGPU::VReg_256RegClassID:
2843 case AMDGPU::AReg_256RegClassID:
2844 case AMDGPU::VReg_256_Align2RegClassID:
2845 case AMDGPU::AReg_256_Align2RegClassID:
2846 case AMDGPU::AV_256RegClassID:
2847 case AMDGPU::AV_256_Align2RegClassID:
2848 case AMDGPU::SReg_256_XNULLRegClassID:
2849 return 256;
2850 case AMDGPU::SGPR_288RegClassID:
2851 case AMDGPU::SReg_288RegClassID:
2852 case AMDGPU::VReg_288RegClassID:
2853 case AMDGPU::AReg_288RegClassID:
2854 case AMDGPU::VReg_288_Align2RegClassID:
2855 case AMDGPU::AReg_288_Align2RegClassID:
2856 case AMDGPU::AV_288RegClassID:
2857 case AMDGPU::AV_288_Align2RegClassID:
2858 return 288;
2859 case AMDGPU::SGPR_320RegClassID:
2860 case AMDGPU::SReg_320RegClassID:
2861 case AMDGPU::VReg_320RegClassID:
2862 case AMDGPU::AReg_320RegClassID:
2863 case AMDGPU::VReg_320_Align2RegClassID:
2864 case AMDGPU::AReg_320_Align2RegClassID:
2865 case AMDGPU::AV_320RegClassID:
2866 case AMDGPU::AV_320_Align2RegClassID:
2867 return 320;
2868 case AMDGPU::SGPR_352RegClassID:
2869 case AMDGPU::SReg_352RegClassID:
2870 case AMDGPU::VReg_352RegClassID:
2871 case AMDGPU::AReg_352RegClassID:
2872 case AMDGPU::VReg_352_Align2RegClassID:
2873 case AMDGPU::AReg_352_Align2RegClassID:
2874 case AMDGPU::AV_352RegClassID:
2875 case AMDGPU::AV_352_Align2RegClassID:
2876 return 352;
2877 case AMDGPU::SGPR_384RegClassID:
2878 case AMDGPU::SReg_384RegClassID:
2879 case AMDGPU::VReg_384RegClassID:
2880 case AMDGPU::AReg_384RegClassID:
2881 case AMDGPU::VReg_384_Align2RegClassID:
2882 case AMDGPU::AReg_384_Align2RegClassID:
2883 case AMDGPU::AV_384RegClassID:
2884 case AMDGPU::AV_384_Align2RegClassID:
2885 return 384;
2886 case AMDGPU::SGPR_512RegClassID:
2887 case AMDGPU::SReg_512RegClassID:
2888 case AMDGPU::VReg_512RegClassID:
2889 case AMDGPU::AReg_512RegClassID:
2890 case AMDGPU::VReg_512_Align2RegClassID:
2891 case AMDGPU::AReg_512_Align2RegClassID:
2892 case AMDGPU::AV_512RegClassID:
2893 case AMDGPU::AV_512_Align2RegClassID:
2894 return 512;
2895 case AMDGPU::SGPR_1024RegClassID:
2896 case AMDGPU::SReg_1024RegClassID:
2897 case AMDGPU::VReg_1024RegClassID:
2898 case AMDGPU::AReg_1024RegClassID:
2899 case AMDGPU::VReg_1024_Align2RegClassID:
2900 case AMDGPU::AReg_1024_Align2RegClassID:
2901 case AMDGPU::AV_1024RegClassID:
2902 case AMDGPU::AV_1024_Align2RegClassID:
2903 return 1024;
2904 default:
2905 llvm_unreachable("Unexpected register class");
2906 }
2907}
2908
2909unsigned getRegBitWidth(const MCRegisterClass &RC) {
2910 return getRegBitWidth(RC.getID());
2911}
2912
2914 unsigned OpNo) {
2915 assert(OpNo < Desc.NumOperands);
2916 unsigned RCID = Desc.operands()[OpNo].RegClass;
2917 return getRegBitWidth(RCID) / 8;
2918}
2919
2920bool isInlinableLiteral64(int64_t Literal, bool HasInv2Pi) {
2922 return true;
2923
2924 uint64_t Val = static_cast<uint64_t>(Literal);
2925 return (Val == llvm::bit_cast<uint64_t>(0.0)) ||
2926 (Val == llvm::bit_cast<uint64_t>(1.0)) ||
2927 (Val == llvm::bit_cast<uint64_t>(-1.0)) ||
2928 (Val == llvm::bit_cast<uint64_t>(0.5)) ||
2929 (Val == llvm::bit_cast<uint64_t>(-0.5)) ||
2930 (Val == llvm::bit_cast<uint64_t>(2.0)) ||
2931 (Val == llvm::bit_cast<uint64_t>(-2.0)) ||
2932 (Val == llvm::bit_cast<uint64_t>(4.0)) ||
2933 (Val == llvm::bit_cast<uint64_t>(-4.0)) ||
2934 (Val == 0x3fc45f306dc9c882 && HasInv2Pi);
2935}
2936
2937bool isInlinableLiteral32(int32_t Literal, bool HasInv2Pi) {
2939 return true;
2940
2941 // The actual type of the operand does not seem to matter as long
2942 // as the bits match one of the inline immediate values. For example:
2943 //
2944 // -nan has the hexadecimal encoding of 0xfffffffe which is -2 in decimal,
2945 // so it is a legal inline immediate.
2946 //
2947 // 1065353216 has the hexadecimal encoding 0x3f800000 which is 1.0f in
2948 // floating-point, so it is a legal inline immediate.
2949
2950 uint32_t Val = static_cast<uint32_t>(Literal);
2951 return (Val == llvm::bit_cast<uint32_t>(0.0f)) ||
2952 (Val == llvm::bit_cast<uint32_t>(1.0f)) ||
2953 (Val == llvm::bit_cast<uint32_t>(-1.0f)) ||
2954 (Val == llvm::bit_cast<uint32_t>(0.5f)) ||
2955 (Val == llvm::bit_cast<uint32_t>(-0.5f)) ||
2956 (Val == llvm::bit_cast<uint32_t>(2.0f)) ||
2957 (Val == llvm::bit_cast<uint32_t>(-2.0f)) ||
2958 (Val == llvm::bit_cast<uint32_t>(4.0f)) ||
2959 (Val == llvm::bit_cast<uint32_t>(-4.0f)) ||
2960 (Val == 0x3e22f983 && HasInv2Pi);
2961}
2962
2963bool isInlinableLiteralBF16(int16_t Literal, bool HasInv2Pi) {
2964 if (!HasInv2Pi)
2965 return false;
2967 return true;
2968 uint16_t Val = static_cast<uint16_t>(Literal);
2969 return Val == 0x3F00 || // 0.5
2970 Val == 0xBF00 || // -0.5
2971 Val == 0x3F80 || // 1.0
2972 Val == 0xBF80 || // -1.0
2973 Val == 0x4000 || // 2.0
2974 Val == 0xC000 || // -2.0
2975 Val == 0x4080 || // 4.0
2976 Val == 0xC080 || // -4.0
2977 Val == 0x3E22; // 1.0 / (2.0 * pi)
2978}
2979
2980bool isInlinableLiteralI16(int32_t Literal, bool HasInv2Pi) {
2981 return isInlinableLiteral32(Literal, HasInv2Pi);
2982}
2983
2984bool isInlinableLiteralFP16(int16_t Literal, bool HasInv2Pi) {
2985 if (!HasInv2Pi)
2986 return false;
2988 return true;
2989 uint16_t Val = static_cast<uint16_t>(Literal);
2990 return Val == 0x3C00 || // 1.0
2991 Val == 0xBC00 || // -1.0
2992 Val == 0x3800 || // 0.5
2993 Val == 0xB800 || // -0.5
2994 Val == 0x4000 || // 2.0
2995 Val == 0xC000 || // -2.0
2996 Val == 0x4400 || // 4.0
2997 Val == 0xC400 || // -4.0
2998 Val == 0x3118; // 1/2pi
2999}
3000
3001std::optional<unsigned> getInlineEncodingV216(bool IsFloat, uint32_t Literal) {
3002 // Unfortunately, the Instruction Set Architecture Reference Guide is
3003 // misleading about how the inline operands work for (packed) 16-bit
3004 // instructions. In a nutshell, the actual HW behavior is:
3005 //
3006 // - integer encodings (-16 .. 64) are always produced as sign-extended
3007 // 32-bit values
3008 // - float encodings are produced as:
3009 // - for F16 instructions: corresponding half-precision float values in
3010 // the LSBs, 0 in the MSBs
3011 // - for UI16 instructions: corresponding single-precision float value
3012 int32_t Signed = static_cast<int32_t>(Literal);
3013 if (Signed >= 0 && Signed <= 64)
3014 return 128 + Signed;
3015
3016 if (Signed >= -16 && Signed <= -1)
3017 return 192 + std::abs(Signed);
3018
3019 if (IsFloat) {
3020 // clang-format off
3021 switch (Literal) {
3022 case 0x3800: return 240; // 0.5
3023 case 0xB800: return 241; // -0.5
3024 case 0x3C00: return 242; // 1.0
3025 case 0xBC00: return 243; // -1.0
3026 case 0x4000: return 244; // 2.0
3027 case 0xC000: return 245; // -2.0
3028 case 0x4400: return 246; // 4.0
3029 case 0xC400: return 247; // -4.0
3030 case 0x3118: return 248; // 1.0 / (2.0 * pi)
3031 default: break;
3032 }
3033 // clang-format on
3034 } else {
3035 // clang-format off
3036 switch (Literal) {
3037 case 0x3F000000: return 240; // 0.5
3038 case 0xBF000000: return 241; // -0.5
3039 case 0x3F800000: return 242; // 1.0
3040 case 0xBF800000: return 243; // -1.0
3041 case 0x40000000: return 244; // 2.0
3042 case 0xC0000000: return 245; // -2.0
3043 case 0x40800000: return 246; // 4.0
3044 case 0xC0800000: return 247; // -4.0
3045 case 0x3E22F983: return 248; // 1.0 / (2.0 * pi)
3046 default: break;
3047 }
3048 // clang-format on
3049 }
3050
3051 return {};
3052}
3053
3054// Encoding of the literal as an inline constant for a V_PK_*_IU16 instruction
3055// or nullopt.
3056std::optional<unsigned> getInlineEncodingV2I16(uint32_t Literal) {
3057 return getInlineEncodingV216(false, Literal);
3058}
3059
3060// Encoding of the literal as an inline constant for a V_PK_*_BF16 instruction
3061// or nullopt.
3062std::optional<unsigned> getInlineEncodingV2BF16(uint32_t Literal) {
3063 int32_t Signed = static_cast<int32_t>(Literal);
3064 if (Signed >= 0 && Signed <= 64)
3065 return 128 + Signed;
3066
3067 if (Signed >= -16 && Signed <= -1)
3068 return 192 + std::abs(Signed);
3069
3070 // clang-format off
3071 switch (Literal) {
3072 case 0x3F00: return 240; // 0.5
3073 case 0xBF00: return 241; // -0.5
3074 case 0x3F80: return 242; // 1.0
3075 case 0xBF80: return 243; // -1.0
3076 case 0x4000: return 244; // 2.0
3077 case 0xC000: return 245; // -2.0
3078 case 0x4080: return 246; // 4.0
3079 case 0xC080: return 247; // -4.0
3080 case 0x3E22: return 248; // 1.0 / (2.0 * pi)
3081 default: break;
3082 }
3083 // clang-format on
3084
3085 return std::nullopt;
3086}
3087
3088// Encoding of the literal as an inline constant for a V_PK_*_F16 instruction
3089// or nullopt.
3090std::optional<unsigned> getInlineEncodingV2F16(uint32_t Literal) {
3091 return getInlineEncodingV216(true, Literal);
3092}
3093
3094// Whether the given literal can be inlined for a V_PK_* instruction.
3096 switch (OpType) {
3099 return getInlineEncodingV216(false, Literal).has_value();
3102 return getInlineEncodingV216(true, Literal).has_value();
3107 return false;
3108 default:
3109 llvm_unreachable("bad packed operand type");
3110 }
3111}
3112
3113// Whether the given literal can be inlined for a V_PK_*_IU16 instruction.
3115 return getInlineEncodingV2I16(Literal).has_value();
3116}
3117
3118// Whether the given literal can be inlined for a V_PK_*_BF16 instruction.
3120 return getInlineEncodingV2BF16(Literal).has_value();
3121}
3122
3123// Whether the given literal can be inlined for a V_PK_*_F16 instruction.
3125 return getInlineEncodingV2F16(Literal).has_value();
3126}
3127
3128bool isValid32BitLiteral(uint64_t Val, bool IsFP64) {
3129 if (IsFP64)
3130 return !Lo_32(Val);
3131
3132 return isUInt<32>(Val) || isInt<32>(Val);
3133}
3134
3136 const Function *F = A->getParent();
3137
3138 // Arguments to compute shaders are never a source of divergence.
3139 CallingConv::ID CC = F->getCallingConv();
3140 switch (CC) {
3143 return true;
3154 // For non-compute shaders, SGPR inputs are marked with either inreg or
3155 // byval. Everything else is in VGPRs.
3156 return A->hasAttribute(Attribute::InReg) ||
3157 A->hasAttribute(Attribute::ByVal);
3158 default:
3159 // TODO: treat i1 as divergent?
3160 return A->hasAttribute(Attribute::InReg);
3161 }
3162}
3163
3164bool isArgPassedInSGPR(const CallBase *CB, unsigned ArgNo) {
3165 // Arguments to compute shaders are never a source of divergence.
3167 switch (CC) {
3170 return true;
3181 // For non-compute shaders, SGPR inputs are marked with either inreg or
3182 // byval. Everything else is in VGPRs.
3183 return CB->paramHasAttr(ArgNo, Attribute::InReg) ||
3184 CB->paramHasAttr(ArgNo, Attribute::ByVal);
3185 default:
3186 return CB->paramHasAttr(ArgNo, Attribute::InReg);
3187 }
3188}
3189
3190static bool hasSMEMByteOffset(const MCSubtargetInfo &ST) {
3191 return isGCN3Encoding(ST) || isGFX10Plus(ST);
3192}
3193
3195 int64_t EncodedOffset) {
3196 if (isGFX12Plus(ST))
3197 return isUInt<23>(EncodedOffset);
3198
3199 return hasSMEMByteOffset(ST) ? isUInt<20>(EncodedOffset)
3200 : isUInt<8>(EncodedOffset);
3201}
3202
3204 int64_t EncodedOffset, bool IsBuffer) {
3205 if (isGFX12Plus(ST))
3206 return isInt<24>(EncodedOffset);
3207
3208 return !IsBuffer && hasSMRDSignedImmOffset(ST) && isInt<21>(EncodedOffset);
3209}
3210
3211static bool isDwordAligned(uint64_t ByteOffset) {
3212 return (ByteOffset & 3) == 0;
3213}
3214
3216 uint64_t ByteOffset) {
3217 if (hasSMEMByteOffset(ST))
3218 return ByteOffset;
3219
3220 assert(isDwordAligned(ByteOffset));
3221 return ByteOffset >> 2;
3222}
3223
3224std::optional<int64_t> getSMRDEncodedOffset(const MCSubtargetInfo &ST,
3225 int64_t ByteOffset, bool IsBuffer,
3226 bool HasSOffset) {
3227 // For unbuffered smem loads, it is illegal for the Immediate Offset to be
3228 // negative if the resulting (Offset + (M0 or SOffset or zero) is negative.
3229 // Handle case where SOffset is not present.
3230 if (!IsBuffer && !HasSOffset && ByteOffset < 0 && hasSMRDSignedImmOffset(ST))
3231 return std::nullopt;
3232
3233 if (isGFX12Plus(ST)) // 24 bit signed offsets
3234 return isInt<24>(ByteOffset) ? std::optional<int64_t>(ByteOffset)
3235 : std::nullopt;
3236
3237 // The signed version is always a byte offset.
3238 if (!IsBuffer && hasSMRDSignedImmOffset(ST)) {
3240 return isInt<20>(ByteOffset) ? std::optional<int64_t>(ByteOffset)
3241 : std::nullopt;
3242 }
3243
3244 if (!isDwordAligned(ByteOffset) && !hasSMEMByteOffset(ST))
3245 return std::nullopt;
3246
3247 int64_t EncodedOffset = convertSMRDOffsetUnits(ST, ByteOffset);
3248 return isLegalSMRDEncodedUnsignedOffset(ST, EncodedOffset)
3249 ? std::optional<int64_t>(EncodedOffset)
3250 : std::nullopt;
3251}
3252
3253std::optional<int64_t> getSMRDEncodedLiteralOffset32(const MCSubtargetInfo &ST,
3254 int64_t ByteOffset) {
3255 if (!isCI(ST) || !isDwordAligned(ByteOffset))
3256 return std::nullopt;
3257
3258 int64_t EncodedOffset = convertSMRDOffsetUnits(ST, ByteOffset);
3259 return isUInt<32>(EncodedOffset) ? std::optional<int64_t>(EncodedOffset)
3260 : std::nullopt;
3261}
3262
3264 if (AMDGPU::isGFX10(ST))
3265 return 12;
3266
3267 if (AMDGPU::isGFX12(ST))
3268 return 24;
3269 return 13;
3270}
3271
3272namespace {
3273
3274struct SourceOfDivergence {
3275 unsigned Intr;
3276};
3277const SourceOfDivergence *lookupSourceOfDivergence(unsigned Intr);
3278
3279struct AlwaysUniform {
3280 unsigned Intr;
3281};
3282const AlwaysUniform *lookupAlwaysUniform(unsigned Intr);
3283
3284#define GET_SourcesOfDivergence_IMPL
3285#define GET_UniformIntrinsics_IMPL
3286#define GET_Gfx9BufferFormat_IMPL
3287#define GET_Gfx10BufferFormat_IMPL
3288#define GET_Gfx11PlusBufferFormat_IMPL
3289
3290#include "AMDGPUGenSearchableTables.inc"
3291
3292} // end anonymous namespace
3293
3294bool isIntrinsicSourceOfDivergence(unsigned IntrID) {
3295 return lookupSourceOfDivergence(IntrID);
3296}
3297
3298bool isIntrinsicAlwaysUniform(unsigned IntrID) {
3299 return lookupAlwaysUniform(IntrID);
3300}
3301
3303 uint8_t NumComponents,
3304 uint8_t NumFormat,
3305 const MCSubtargetInfo &STI) {
3306 return isGFX11Plus(STI) ? getGfx11PlusBufferFormatInfo(
3307 BitsPerComp, NumComponents, NumFormat)
3308 : isGFX10(STI)
3309 ? getGfx10BufferFormatInfo(BitsPerComp, NumComponents, NumFormat)
3310 : getGfx9BufferFormatInfo(BitsPerComp, NumComponents, NumFormat);
3311}
3312
3314 const MCSubtargetInfo &STI) {
3315 return isGFX11Plus(STI) ? getGfx11PlusBufferFormatInfo(Format)
3316 : isGFX10(STI) ? getGfx10BufferFormatInfo(Format)
3317 : getGfx9BufferFormatInfo(Format);
3318}
3319
3320bool supportsScaleOffset(const MCInstrInfo &MII, unsigned Opcode) {
3321 uint64_t TSFlags = MII.get(Opcode).TSFlags;
3322
3323 if (TSFlags & SIInstrFlags::SMRD)
3324 return !getSMEMIsBuffer(Opcode);
3325 if (!(TSFlags & SIInstrFlags::FLAT))
3326 return false;
3327
3328 // Only SV and SVS modes are supported.
3329 if (TSFlags & SIInstrFlags::FlatScratch)
3330 return hasNamedOperand(Opcode, OpName::vaddr);
3331
3332 // Only GVS mode is supported.
3333 return hasNamedOperand(Opcode, OpName::vaddr) &&
3334 hasNamedOperand(Opcode, OpName::saddr);
3335
3336 return false;
3337}
3338
3340 for (auto OpName : {OpName::vdst, OpName::src0, OpName::src1, OpName::src2}) {
3341 int Idx = getNamedOperandIdx(OpDesc.getOpcode(), OpName);
3342 if (Idx == -1)
3343 continue;
3344
3345 if (OpDesc.operands()[Idx].RegClass == AMDGPU::VReg_64RegClassID ||
3346 OpDesc.operands()[Idx].RegClass == AMDGPU::VReg_64_Align2RegClassID)
3347 return true;
3348 }
3349
3350 return false;
3351}
3352
3353bool isDPALU_DPP32BitOpc(unsigned Opc) {
3354 switch (Opc) {
3355 case AMDGPU::V_MUL_LO_U32_e64:
3356 case AMDGPU::V_MUL_LO_U32_e64_dpp:
3357 case AMDGPU::V_MUL_LO_U32_e64_dpp_gfx1250:
3358 case AMDGPU::V_MUL_HI_U32_e64:
3359 case AMDGPU::V_MUL_HI_U32_e64_dpp:
3360 case AMDGPU::V_MUL_HI_U32_e64_dpp_gfx1250:
3361 case AMDGPU::V_MUL_HI_I32_e64:
3362 case AMDGPU::V_MUL_HI_I32_e64_dpp:
3363 case AMDGPU::V_MUL_HI_I32_e64_dpp_gfx1250:
3364 case AMDGPU::V_MAD_U32_e64:
3365 case AMDGPU::V_MAD_U32_e64_dpp:
3366 case AMDGPU::V_MAD_U32_e64_dpp_gfx1250:
3367 return true;
3368 default:
3369 return false;
3370 }
3371}
3372
3373bool isDPALU_DPP(const MCInstrDesc &OpDesc, const MCSubtargetInfo &ST) {
3374 if (!ST.hasFeature(AMDGPU::FeatureDPALU_DPP))
3375 return false;
3376
3377 if (isDPALU_DPP32BitOpc(OpDesc.getOpcode()))
3378 return ST.hasFeature(AMDGPU::FeatureGFX1250Insts);
3379
3380 return hasAny64BitVGPROperands(OpDesc);
3381}
3382
3384 return ST.hasFeature(AMDGPU::FeatureAddressableLocalMemorySize327680) ? 256
3385 : 128;
3386}
3387
3388bool isPackedFP32Inst(unsigned Opc) {
3389 switch (Opc) {
3390 case AMDGPU::V_PK_ADD_F32:
3391 case AMDGPU::V_PK_ADD_F32_gfx12:
3392 case AMDGPU::V_PK_MUL_F32:
3393 case AMDGPU::V_PK_MUL_F32_gfx12:
3394 case AMDGPU::V_PK_FMA_F32:
3395 case AMDGPU::V_PK_FMA_F32_gfx12:
3396 return true;
3397 default:
3398 return false;
3399 }
3400}
3401
3402} // namespace AMDGPU
3403
3406 switch (S) {
3408 OS << "Unsupported";
3409 break;
3411 OS << "Any";
3412 break;
3414 OS << "Off";
3415 break;
3417 OS << "On";
3418 break;
3419 }
3420 return OS;
3421}
3422
3423} // namespace llvm
unsigned const MachineRegisterInfo * MRI
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 Intr
Provides AMDGPU specific target descriptions.
MC layer struct for AMDGPUMCKernelCodeT, provides MCExpr functionality where required.
@ AMD_CODE_PROPERTY_ENABLE_WAVEFRONT_SIZE32
This file contains the simple types necessary to represent the attributes associated with functions a...
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
std::string Name
uint32_t Index
uint64_t Size
bool End
Definition: ELF_riscv.cpp:480
#define RegName(no)
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
Register Reg
Register const TargetRegisterInfo * TRI
This file contains the declarations for metadata subclasses.
uint64_t High
#define S_00B848_MEM_ORDERED(x)
Definition: SIDefines.h:1223
#define S_00B848_WGP_MODE(x)
Definition: SIDefines.h:1220
#define S_00B848_FWD_PROGRESS(x)
Definition: SIDefines.h:1226
unsigned unsigned DefaultVal
raw_pwrite_stream & OS
This file contains some functions that are useful when dealing with strings.
static const int BlockSize
Definition: TarWriter.cpp:33
TargetIDSetting getXnackSetting() const
AMDGPUTargetID(const MCSubtargetInfo &STI)
void setTargetIDFromTargetIDStream(StringRef TargetID)
TargetIDSetting getSramEccSetting() const
unsigned getIndexInParsedOperands(unsigned CompOprIdx) const
unsigned getIndexOfDstInParsedOperands() const
unsigned getIndexOfSrcInParsedOperands(unsigned CompSrcIdx) const
unsigned getCompParsedSrcOperandsNum() const
std::optional< unsigned > getInvalidCompOperandIndex(std::function< unsigned(unsigned, unsigned)> GetRegIdx, const MCRegisterInfo &MRI, bool SkipSrc=false, bool AllowSameVGPR=false, bool VOPD3=false) const
std::array< unsigned, Component::MAX_OPR_NUM > RegIndices
Definition: Any.h:28
This class represents an incoming formal argument to a Function.
Definition: Argument.h:32
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1116
CallingConv::ID getCallingConv() const
Definition: InstrTypes.h:1406
LLVM_ABI bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Determine whether the argument or parameter has the given attribute.
This class represents an Operation in the Expression.
constexpr bool test(unsigned I) const
unsigned getAddressSpace() const
Definition: GlobalValue.h:207
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
LLVM_ABI void emitError(const Instruction *I, const Twine &ErrorStr)
emitError - Emit an error message to the currently installed error handler with optional location inf...
Describe properties that are true of each instruction in the target description file.
Definition: MCInstrDesc.h:199
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
Definition: MCInstrDesc.h:238
ArrayRef< MCOperandInfo > operands() const
Definition: MCInstrDesc.h:240
bool mayStore() const
Return true if this instruction could possibly modify memory.
Definition: MCInstrDesc.h:446
bool mayLoad() const
Return true if this instruction could possibly read memory.
Definition: MCInstrDesc.h:440
unsigned getNumDefs() const
Return the number of MachineOperands that are register definitions.
Definition: MCInstrDesc.h:249
int getOperandConstraint(unsigned OpNum, MCOI::OperandConstraint Constraint) const
Returns the value of the specified operand constraint if it is present.
Definition: MCInstrDesc.h:220
unsigned getOpcode() const
Return the opcode number for this descriptor.
Definition: MCInstrDesc.h:231
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:64
MCRegisterClass - Base class of TargetRegisterClass.
unsigned getID() const
getID() - Return the register class ID number.
bool contains(MCRegister Reg) const
contains - Return true if the specified register is included in this register class.
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Wrapper class representing physical registers. Should be passed by value.
Definition: MCRegister.h:33
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:1077
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:1445
unsigned getNumOperands() const
Return number of MDNode operands.
Definition: Metadata.h:1451
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1197
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
Definition: StringRef.h:862
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition: StringRef.h:710
bool getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
Definition: StringRef.h:480
std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:233
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:151
constexpr size_t size() const
size - Get the string size.
Definition: StringRef.h:154
bool ends_with(StringRef Suffix) const
Check if this string ends with the given Suffix.
Definition: StringRef.h:281
Manages the enabling and disabling of subtarget specific features.
const std::vector< std::string > & getFeatures() const
Returns the vector of individual subtarget features.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:47
OSType getOS() const
Get the parsed operating system type of this triple.
Definition: Triple.h:418
ArchType getArch() const
Get the parsed architecture type of this triple.
Definition: Triple.h:409
bool isAMDGCN() const
Tests whether the target is AMDGCN.
Definition: Triple.h:902
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:82
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:662
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ CONSTANT_ADDRESS_32BIT
Address space for 32-bit constant memory.
@ LOCAL_ADDRESS
Address space for local memory.
@ CONSTANT_ADDRESS
Address space for constant memory (VTX2).
@ GLOBAL_ADDRESS
Address space for global memory (RAT0, VTX0).
unsigned decodeFieldVaVcc(unsigned Encoded)
unsigned encodeFieldVaVcc(unsigned Encoded, unsigned VaVcc)
unsigned encodeFieldHoldCnt(unsigned Encoded, unsigned HoldCnt)
bool decodeDepCtr(unsigned Code, int &Id, StringRef &Name, unsigned &Val, bool &IsDefault, const MCSubtargetInfo &STI)
unsigned encodeFieldVaSsrc(unsigned Encoded, unsigned VaSsrc)
unsigned encodeFieldVaVdst(unsigned Encoded, unsigned VaVdst)
unsigned decodeFieldSaSdst(unsigned Encoded)
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)
unsigned decodeFieldHoldCnt(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 getVGPREncodingGranule(const MCSubtargetInfo *STI, std::optional< bool > EnableWavefrontSize32)
unsigned getTotalNumVGPRs(const MCSubtargetInfo *STI)
unsigned getArchVGPRAllocGranule()
For subtargets with a unified VGPR file and mixed ArchVGPR/AGPR usage, returns the allocation granule...
unsigned getWavesPerEUForWorkGroup(const MCSubtargetInfo *STI, unsigned FlatWorkGroupSize)
unsigned getWavefrontSize(const MCSubtargetInfo *STI)
unsigned getNumWavesPerEUWithNumVGPRs(const MCSubtargetInfo *STI, unsigned NumVGPRs, unsigned DynamicVGPRBlockSize)
unsigned getMaxWorkGroupsPerCU(const MCSubtargetInfo *STI, unsigned FlatWorkGroupSize)
unsigned getMaxFlatWorkGroupSize(const MCSubtargetInfo *STI)
unsigned getMaxWavesPerEU(const MCSubtargetInfo *STI)
unsigned getWavesPerWorkGroup(const MCSubtargetInfo *STI, unsigned FlatWorkGroupSize)
unsigned getNumExtraSGPRs(const MCSubtargetInfo *STI, bool VCCUsed, bool FlatScrUsed, bool XNACKUsed)
unsigned getSGPREncodingGranule(const MCSubtargetInfo *STI)
unsigned getLocalMemorySize(const MCSubtargetInfo *STI)
unsigned getAddressableLocalMemorySize(const MCSubtargetInfo *STI)
unsigned getEUsPerCU(const MCSubtargetInfo *STI)
unsigned getAddressableNumSGPRs(const MCSubtargetInfo *STI)
unsigned getMinNumSGPRs(const MCSubtargetInfo *STI, unsigned WavesPerEU)
static TargetIDSetting getTargetIDSettingFromFeatureString(StringRef FeatureString)
unsigned getMinFlatWorkGroupSize(const MCSubtargetInfo *STI)
unsigned getVGPRAllocGranule(const MCSubtargetInfo *STI, unsigned DynamicVGPRBlockSize, std::optional< bool > EnableWavefrontSize32)
unsigned getMaxNumSGPRs(const MCSubtargetInfo *STI, unsigned WavesPerEU, bool Addressable)
unsigned getNumSGPRBlocks(const MCSubtargetInfo *STI, unsigned NumSGPRs)
unsigned getMinWavesPerEU(const MCSubtargetInfo *STI)
unsigned getMaxNumVGPRs(const MCSubtargetInfo *STI, unsigned WavesPerEU, unsigned DynamicVGPRBlockSize)
unsigned getSGPRAllocGranule(const MCSubtargetInfo *STI)
unsigned getMinNumVGPRs(const MCSubtargetInfo *STI, unsigned WavesPerEU, unsigned DynamicVGPRBlockSize)
unsigned getAllocatedNumVGPRBlocks(const MCSubtargetInfo *STI, unsigned NumVGPRs, unsigned DynamicVGPRBlockSize, std::optional< bool > EnableWavefrontSize32)
unsigned getEncodedNumVGPRBlocks(const MCSubtargetInfo *STI, unsigned NumVGPRs, std::optional< bool > EnableWavefrontSize32)
unsigned getOccupancyWithNumSGPRs(unsigned SGPRs, unsigned MaxWaves, AMDGPUSubtarget::Generation Gen)
static unsigned getGranulatedNumRegisterBlocks(unsigned NumRegs, unsigned Granule)
unsigned getAddressableNumArchVGPRs(const MCSubtargetInfo *STI)
unsigned getTotalNumSGPRs(const MCSubtargetInfo *STI)
unsigned getAddressableNumVGPRs(const MCSubtargetInfo *STI, unsigned DynamicVGPRBlockSize)
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)
StringRef getMsgOpName(int64_t MsgId, uint64_t Encoding, const MCSubtargetInfo &STI)
Map from an encoding to the symbolic name for a sendmsg operation.
static uint64_t getMsgIdMask(const MCSubtargetInfo &STI)
bool msgRequiresOp(int64_t MsgId, const MCSubtargetInfo &STI)
bool isValidMsgOp(int64_t MsgId, int64_t OpId, const MCSubtargetInfo &STI, bool Strict)
constexpr unsigned VOPD_VGPR_BANK_MASKS[]
constexpr unsigned COMPONENTS_NUM
constexpr unsigned VOPD3_VGPR_BANK_MASKS[]
bool isPackedFP32Inst(unsigned Opc)
bool isGCN3Encoding(const MCSubtargetInfo &STI)
bool isInlinableLiteralBF16(int16_t Literal, bool HasInv2Pi)
bool isGFX10_BEncoding(const MCSubtargetInfo &STI)
bool isGFX10_GFX11(const MCSubtargetInfo &STI)
bool isInlinableLiteralV216(uint32_t Literal, uint8_t OpType)
LLVM_READONLY const MIMGInfo * getMIMGInfo(unsigned Opc)
unsigned getRegOperandSize(const MCRegisterInfo *MRI, const MCInstrDesc &Desc, unsigned OpNo)
Get size of register operand.
void decodeWaitcnt(const IsaVersion &Version, unsigned Waitcnt, unsigned &Vmcnt, unsigned &Expcnt, unsigned &Lgkmcnt)
Decodes Vmcnt, Expcnt and Lgkmcnt from given Waitcnt for given isa Version, and writes decoded values...
bool isInlinableLiteralFP16(int16_t Literal, bool HasInv2Pi)
bool isSGPR(MCRegister Reg, const MCRegisterInfo *TRI)
Is Reg - scalar register.
uint64_t convertSMRDOffsetUnits(const MCSubtargetInfo &ST, uint64_t ByteOffset)
Convert ByteOffset to dwords if the subtarget uses dword SMRD immediate offsets.
static unsigned encodeStorecnt(const IsaVersion &Version, unsigned Waitcnt, unsigned Storecnt)
MCRegister getMCReg(MCRegister Reg, const MCSubtargetInfo &STI)
If Reg is a pseudo reg, return the correct hardware register given STI otherwise return Reg.
static bool hasSMEMByteOffset(const MCSubtargetInfo &ST)
bool isVOPCAsmOnly(unsigned Opc)
int getMIMGOpcode(unsigned BaseOpcode, unsigned MIMGEncoding, unsigned VDataDwords, unsigned VAddrDwords)
bool getMTBUFHasSrsrc(unsigned Opc)
std::optional< int64_t > getSMRDEncodedLiteralOffset32(const MCSubtargetInfo &ST, int64_t ByteOffset)
bool getWMMAIsXDL(unsigned Opc)
uint8_t wmmaScaleF8F6F4FormatToNumRegs(unsigned Fmt)
static bool isSymbolicCustomOperandEncoding(const CustomOperandVal *Opr, int Size, unsigned Code, bool &HasNonDefaultVal, const MCSubtargetInfo &STI)
bool isGFX10Before1030(const MCSubtargetInfo &STI)
bool isSISrcInlinableOperand(const MCInstrDesc &Desc, unsigned OpNo)
Does this operand support only inlinable literals?
unsigned mapWMMA2AddrTo3AddrOpcode(unsigned Opc)
const int OPR_ID_UNSUPPORTED
bool shouldEmitConstantsToTextSection(const Triple &TT)
bool isInlinableLiteralV2I16(uint32_t Literal)
int getMTBUFElements(unsigned Opc)
bool isHi16Reg(MCRegister Reg, const MCRegisterInfo &MRI)
static int encodeCustomOperandVal(const CustomOperandVal &Op, int64_t InputVal)
unsigned getTemporalHintType(const MCInstrDesc TID)
int32_t getTotalNumVGPRs(bool has90AInsts, int32_t ArgNumAGPR, int32_t ArgNumVGPR)
bool isGFX10(const MCSubtargetInfo &STI)
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)
bool hasPackedD16(const MCSubtargetInfo &STI)
unsigned getStorecntBitMask(const IsaVersion &Version)
unsigned getLdsDwGranularity(const MCSubtargetInfo &ST)
bool isGFX940(const MCSubtargetInfo &STI)
bool isInlinableLiteralV2F16(uint32_t Literal)
bool isHsaAbi(const MCSubtargetInfo &STI)
bool isGFX11(const MCSubtargetInfo &STI)
const int OPR_VAL_INVALID
bool getSMEMIsBuffer(unsigned Opc)
bool isGFX10_3_GFX11(const MCSubtargetInfo &STI)
bool hasValueInRangeLikeMetadata(const MDNode &MD, int64_t Val)
Checks if Val is inside MD, a !range-like metadata.
uint8_t mfmaScaleF8F6F4FormatToNumRegs(unsigned EncodingVal)
unsigned getVOPDOpcode(unsigned Opc, bool VOPD3)
bool isGroupSegment(const GlobalValue *GV)
LLVM_ABI IsaVersion getIsaVersion(StringRef GPU)
bool getMTBUFHasSoffset(unsigned Opc)
bool hasXNACK(const MCSubtargetInfo &STI)
bool isValid32BitLiteral(uint64_t Val, bool IsFP64)
static unsigned getCombinedCountBitMask(const IsaVersion &Version, bool IsStore)
CanBeVOPD getCanBeVOPD(unsigned Opc, unsigned EncodingFamily, bool VOPD3)
unsigned encodeWaitcnt(const IsaVersion &Version, unsigned Vmcnt, unsigned Expcnt, unsigned Lgkmcnt)
Encodes Vmcnt, Expcnt and Lgkmcnt into Waitcnt for given isa Version.
bool isVOPC64DPP(unsigned Opc)
int getMUBUFOpcode(unsigned BaseOpc, unsigned Elements)
bool getMAIIsGFX940XDL(unsigned Opc)
bool isSI(const MCSubtargetInfo &STI)
unsigned getDefaultAMDHSACodeObjectVersion()
bool isReadOnlySegment(const GlobalValue *GV)
bool isArgPassedInSGPR(const Argument *A)
bool isIntrinsicAlwaysUniform(unsigned IntrID)
int getMUBUFBaseOpcode(unsigned Opc)
unsigned getAMDHSACodeObjectVersion(const Module &M)
unsigned decodeLgkmcnt(const IsaVersion &Version, unsigned Waitcnt)
unsigned getWaitcntBitMask(const IsaVersion &Version)
LLVM_READONLY bool hasNamedOperand(uint64_t Opcode, OpName NamedIdx)
bool getVOP3IsSingle(unsigned Opc)
bool isGFX9(const MCSubtargetInfo &STI)
bool isDPALU_DPP32BitOpc(unsigned Opc)
bool getVOP1IsSingle(unsigned Opc)
static bool isDwordAligned(uint64_t ByteOffset)
unsigned getVOPDEncodingFamily(const MCSubtargetInfo &ST)
bool isGFX10_AEncoding(const MCSubtargetInfo &STI)
bool isKImmOperand(const MCInstrDesc &Desc, unsigned OpNo)
Is this a KImm operand?
bool getHasColorExport(const Function &F)
int getMTBUFBaseOpcode(unsigned Opc)
bool isGFX90A(const MCSubtargetInfo &STI)
unsigned getSamplecntBitMask(const IsaVersion &Version)
unsigned getDefaultQueueImplicitArgPosition(unsigned CodeObjectVersion)
bool hasSRAMECC(const MCSubtargetInfo &STI)
bool getHasDepthExport(const Function &F)
bool isGFX8_GFX9_GFX10(const MCSubtargetInfo &STI)
bool getMUBUFHasVAddr(unsigned Opc)
bool isTrue16Inst(unsigned Opc)
bool hasAny64BitVGPROperands(const MCInstrDesc &OpDesc)
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)
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)
Waitcnt decodeStorecntDscnt(const IsaVersion &Version, unsigned StorecntDscnt)
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 isDPALU_DPP(const MCInstrDesc &OpDesc, const MCSubtargetInfo &ST)
bool hasSMRDSignedImmOffset(const MCSubtargetInfo &ST)
bool hasMIMG_R128(const MCSubtargetInfo &STI)
bool hasGFX10_3Insts(const MCSubtargetInfo &STI)
bool hasG16(const MCSubtargetInfo &STI)
unsigned getAddrSizeMIMGOp(const MIMGBaseOpcodeInfo *BaseOpcode, const MIMGDimInfo *Dim, bool IsA16, bool IsG16Supported)
int getMTBUFOpcode(unsigned BaseOpc, unsigned Elements)
unsigned getExpcntBitMask(const IsaVersion &Version)
bool hasArchitectedFlatScratch(const MCSubtargetInfo &STI)
bool getMUBUFHasSoffset(unsigned Opc)
bool isNotGFX11Plus(const MCSubtargetInfo &STI)
bool isGFX11Plus(const MCSubtargetInfo &STI)
std::optional< unsigned > getInlineEncodingV2F16(uint32_t Literal)
bool isInlineValue(unsigned Reg)
bool isSISrcFPOperand(const MCInstrDesc &Desc, unsigned OpNo)
Is this floating-point operand?
std::tuple< char, unsigned, unsigned > parseAsmConstraintPhysReg(StringRef Constraint)
Returns a valid charcode or 0 in the first entry if this is a valid physical register constraint.
unsigned getHostcallImplicitArgPosition(unsigned CodeObjectVersion)
static unsigned getDefaultCustomOperandEncoding(const CustomOperandVal *Opr, int Size, const MCSubtargetInfo &STI)
static unsigned encodeLoadcnt(const IsaVersion &Version, unsigned Waitcnt, unsigned Loadcnt)
bool isGFX10Plus(const MCSubtargetInfo &STI)
static bool decodeCustomOperand(const CustomOperandVal *Opr, int Size, unsigned Code, int &Idx, StringRef &Name, unsigned &Val, bool &IsDefault, const MCSubtargetInfo &STI)
static bool isValidRegPrefix(char C)
std::optional< int64_t > getSMRDEncodedOffset(const MCSubtargetInfo &ST, int64_t ByteOffset, bool IsBuffer, bool HasSOffset)
bool isGlobalSegment(const GlobalValue *GV)
@ OPERAND_KIMM_LAST
Definition: SIDefines.h:263
@ OPERAND_KIMM32
Operand with 32-bit immediate that uses the constant bus.
Definition: SIDefines.h:231
@ OPERAND_REG_INLINE_C_LAST
Definition: SIDefines.h:254
@ OPERAND_REG_IMM_V2FP16
Definition: SIDefines.h:209
@ OPERAND_REG_INLINE_C_FP64
Definition: SIDefines.h:222
@ OPERAND_REG_INLINE_C_V2BF16
Definition: SIDefines.h:224
@ OPERAND_REG_IMM_V2INT16
Definition: SIDefines.h:210
@ OPERAND_REG_IMM_V2BF16
Definition: SIDefines.h:208
@ OPERAND_REG_INLINE_AC_FIRST
Definition: SIDefines.h:256
@ OPERAND_KIMM_FIRST
Definition: SIDefines.h:262
@ OPERAND_REG_IMM_FP16
Definition: SIDefines.h:207
@ OPERAND_REG_IMM_NOINLINE_V2FP16
Definition: SIDefines.h:211
@ OPERAND_REG_IMM_FP64
Definition: SIDefines.h:205
@ OPERAND_REG_INLINE_C_V2FP16
Definition: SIDefines.h:225
@ OPERAND_REG_INLINE_AC_FP32
Definition: SIDefines.h:237
@ OPERAND_REG_IMM_FP32
Definition: SIDefines.h:204
@ OPERAND_REG_INLINE_C_FIRST
Definition: SIDefines.h:253
@ OPERAND_REG_INLINE_C_FP32
Definition: SIDefines.h:221
@ OPERAND_REG_INLINE_AC_LAST
Definition: SIDefines.h:257
@ OPERAND_REG_INLINE_C_V2INT16
Definition: SIDefines.h:223
@ OPERAND_REG_IMM_V2FP32
Definition: SIDefines.h:213
@ OPERAND_REG_INLINE_AC_FP64
Definition: SIDefines.h:238
@ OPERAND_REG_INLINE_C_FP16
Definition: SIDefines.h:220
void initDefaultAMDKernelCodeT(AMDGPUMCKernelCodeT &KernelCode, const MCSubtargetInfo *STI)
bool isNotGFX9Plus(const MCSubtargetInfo &STI)
bool hasGDS(const MCSubtargetInfo &STI)
bool isLegalSMRDEncodedUnsignedOffset(const MCSubtargetInfo &ST, int64_t EncodedOffset)
bool isGFX9Plus(const MCSubtargetInfo &STI)
bool hasDPPSrc1SGPR(const MCSubtargetInfo &STI)
const int OPR_ID_DUPLICATE
bool isVOPD(unsigned Opc)
VOPD::InstInfo getVOPDInstInfo(const MCInstrDesc &OpX, const MCInstrDesc &OpY)
unsigned encodeVmcnt(const IsaVersion &Version, unsigned Waitcnt, unsigned Vmcnt)
unsigned decodeExpcnt(const IsaVersion &Version, unsigned Waitcnt)
bool isCvt_F32_Fp8_Bf8_e64(unsigned Opc)
Waitcnt decodeLoadcntDscnt(const IsaVersion &Version, unsigned LoadcntDscnt)
std::optional< unsigned > getInlineEncodingV2I16(uint32_t Literal)
unsigned getRegBitWidth(const TargetRegisterClass &RC)
Get the size in bits of a register from the register class RC.
static unsigned encodeStorecntDscnt(const IsaVersion &Version, unsigned Storecnt, unsigned Dscnt)
bool isGFX1250(const MCSubtargetInfo &STI)
int getMCOpcode(uint16_t Opcode, unsigned Gen)
const MIMGBaseOpcodeInfo * getMIMGBaseOpcode(unsigned Opc)
bool isVI(const MCSubtargetInfo &STI)
bool isTensorStore(unsigned Opc)
bool getMUBUFIsBufferInv(unsigned Opc)
bool supportsScaleOffset(const MCInstrInfo &MII, unsigned Opcode)
MCRegister mc2PseudoReg(MCRegister Reg)
Convert hardware register Reg to a pseudo register.
std::optional< unsigned > getInlineEncodingV2BF16(uint32_t Literal)
static int encodeCustomOperand(const CustomOperandVal *Opr, int Size, const StringRef Name, int64_t InputVal, unsigned &UsedOprMask, const MCSubtargetInfo &STI)
unsigned hasKernargPreload(const MCSubtargetInfo &STI)
bool supportsWGP(const MCSubtargetInfo &STI)
bool isMAC(unsigned Opc)
bool isCI(const MCSubtargetInfo &STI)
unsigned encodeLgkmcnt(const IsaVersion &Version, unsigned Waitcnt, unsigned Lgkmcnt)
bool getVOP2IsSingle(unsigned Opc)
bool getMAIIsDGEMM(unsigned Opc)
Returns true if MAI operation is a double precision GEMM.
LLVM_READONLY const MIMGBaseOpcodeInfo * getMIMGBaseOpcodeInfo(unsigned BaseOpcode)
const int OPR_ID_UNKNOWN
unsigned getCompletionActionImplicitArgPosition(unsigned CodeObjectVersion)
SmallVector< unsigned > getIntegerVecAttribute(const Function &F, StringRef Name, unsigned Size, unsigned DefaultVal)
int getMaskedMIMGOp(unsigned Opc, unsigned NewChannels)
bool isNotGFX12Plus(const MCSubtargetInfo &STI)
bool getMTBUFHasVAddr(unsigned Opc)
unsigned decodeVmcnt(const IsaVersion &Version, unsigned Waitcnt)
uint8_t getELFABIVersion(const Triple &T, unsigned CodeObjectVersion)
std::pair< unsigned, unsigned > getIntegerPairAttribute(const Function &F, StringRef Name, std::pair< unsigned, unsigned > Default, bool OnlyFirstRequired)
unsigned getLoadcntBitMask(const IsaVersion &Version)
bool isInlinableLiteralI16(int32_t Literal, bool HasInv2Pi)
bool hasVOPD(const MCSubtargetInfo &STI)
int getVOPDFull(unsigned OpX, unsigned OpY, unsigned EncodingFamily, bool VOPD3)
static unsigned encodeDscnt(const IsaVersion &Version, unsigned Waitcnt, unsigned Dscnt)
bool isInlinableLiteral64(int64_t Literal, bool HasInv2Pi)
Is this literal inlinable.
const MFMA_F8F6F4_Info * getMFMA_F8F6F4_WithFormatArgs(unsigned CBSZ, unsigned BLGP, unsigned F8F8Opcode)
unsigned getMultigridSyncArgImplicitArgPosition(unsigned CodeObjectVersion)
bool isGFX9_GFX10_GFX11(const MCSubtargetInfo &STI)
bool isGFX9_GFX10(const MCSubtargetInfo &STI)
int getMUBUFElements(unsigned Opc)
static unsigned encodeLoadcntDscnt(const IsaVersion &Version, unsigned Loadcnt, unsigned Dscnt)
const GcnBufferFormatInfo * getGcnBufferFormatInfo(uint8_t BitsPerComp, uint8_t NumComponents, uint8_t NumFormat, const MCSubtargetInfo &STI)
unsigned mapWMMA3AddrTo2AddrOpcode(unsigned Opc)
bool isPermlane16(unsigned Opc)
bool getMUBUFHasSrsrc(unsigned Opc)
unsigned getDscntBitMask(const IsaVersion &Version)
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
Definition: BitmaskEnum.h:126
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.
Definition: CallingConv.h:197
@ AMDGPU_VS
Used for Mesa vertex shaders, or AMDPAL last shader stage before rasterization (vertex shader if tess...
Definition: CallingConv.h:188
@ AMDGPU_KERNEL
Used for AMDGPU code object kernels.
Definition: CallingConv.h:200
@ AMDGPU_Gfx
Used for AMD graphics targets.
Definition: CallingConv.h:232
@ AMDGPU_CS_ChainPreserve
Used on AMDGPUs to give the middle-end more control over argument placement.
Definition: CallingConv.h:249
@ AMDGPU_HS
Used for Mesa/AMDPAL hull shaders (= tessellation control shaders).
Definition: CallingConv.h:206
@ AMDGPU_GS
Used for Mesa/AMDPAL geometry shaders.
Definition: CallingConv.h:191
@ AMDGPU_CS_Chain
Used on AMDGPUs to give the middle-end more control over argument placement.
Definition: CallingConv.h:245
@ AMDGPU_PS
Used for Mesa/AMDPAL pixel shaders.
Definition: CallingConv.h:194
@ SPIR_KERNEL
Used for SPIR kernel functions.
Definition: CallingConv.h:144
@ AMDGPU_ES
Used for AMDPAL shader stage before geometry shader if geometry is in use.
Definition: CallingConv.h:218
@ AMDGPU_LS
Used for AMDPAL vertex shader if tessellation is in use.
Definition: CallingConv.h:213
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
@ ELFABIVERSION_AMDGPU_HSA_V4
Definition: ELF.h:384
@ ELFABIVERSION_AMDGPU_HSA_V5
Definition: ELF.h:385
@ ELFABIVERSION_AMDGPU_HSA_V6
Definition: ELF.h:386
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:444
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Low
Lower the current thread's priority such that it does not affect foreground tasks significantly.
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:551
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition: Error.cpp:167
constexpr uint32_t Lo_32(uint64_t Value)
Return the low 32 bits of a 64 bit value.
Definition: MathExtras.h:164
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
constexpr T divideCeil(U Numerator, V Denominator)
Returns the integer ceil(Numerator / Denominator).
Definition: MathExtras.h:399
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition: Alignment.h:155
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
Definition: APFixedPoint.h:312
@ AlwaysUniform
The result values are always uniform.
@ Default
The result values are uniform if and only if all operands are uniform.
#define N
AMD Kernel Code Object (amd_kernel_code_t).
Instruction set architecture version.
Definition: TargetParser.h:132
Represents the counter values to wait for in an s_waitcnt instruction.
Description of the encoding of one expression Op.