LLVM 19.0.0git
AMDGPUBaseInfo.h
Go to the documentation of this file.
1//===- AMDGPUBaseInfo.h - Top level definitions for AMDGPU ------*- C++ -*-===//
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#ifndef LLVM_LIB_TARGET_AMDGPU_UTILS_AMDGPUBASEINFO_H
10#define LLVM_LIB_TARGET_AMDGPU_UTILS_AMDGPUBASEINFO_H
11
12#include "AMDGPUSubtarget.h"
13#include "SIDefines.h"
14#include "llvm/IR/CallingConv.h"
15#include "llvm/IR/InstrTypes.h"
16#include "llvm/IR/Module.h"
18#include <array>
19#include <functional>
20#include <utility>
21
23
24namespace llvm {
25
26struct Align;
27class Argument;
28class Function;
29class GlobalValue;
30class MCInstrInfo;
31class MCRegisterClass;
32class MCRegisterInfo;
33class MCSubtargetInfo;
34class StringRef;
35class Triple;
36class raw_ostream;
37
38namespace AMDGPU {
39
40struct IsaVersion;
41
42/// Generic target versions emitted by this version of LLVM.
43///
44/// These numbers are incremented every time a codegen breaking change occurs
45/// within a generic family.
46namespace GenericVersion {
47static constexpr unsigned GFX9 = 1;
48static constexpr unsigned GFX10_1 = 1;
49static constexpr unsigned GFX10_3 = 1;
50static constexpr unsigned GFX11 = 1;
51} // namespace GenericVersion
52
53enum { AMDHSA_COV4 = 4, AMDHSA_COV5 = 5, AMDHSA_COV6 = 6 };
54
55/// \returns True if \p STI is AMDHSA.
56bool isHsaAbi(const MCSubtargetInfo &STI);
57
58/// \returns Code object version from the IR module flag.
59unsigned getAMDHSACodeObjectVersion(const Module &M);
60
61/// \returns Code object version from ELF's e_ident[EI_ABIVERSION].
62unsigned getAMDHSACodeObjectVersion(unsigned ABIVersion);
63
64/// \returns The default HSA code object version. This should only be used when
65/// we lack a more accurate CodeObjectVersion value (e.g. from the IR module
66/// flag or a .amdhsa_code_object_version directive)
68
69/// \returns ABIVersion suitable for use in ELF's e_ident[EI_ABIVERSION]. \param
70/// CodeObjectVersion is a value returned by getAMDHSACodeObjectVersion().
71uint8_t getELFABIVersion(const Triple &OS, unsigned CodeObjectVersion);
72
73/// \returns The offset of the multigrid_sync_arg argument from implicitarg_ptr
74unsigned getMultigridSyncArgImplicitArgPosition(unsigned COV);
75
76/// \returns The offset of the hostcall pointer argument from implicitarg_ptr
77unsigned getHostcallImplicitArgPosition(unsigned COV);
78
79unsigned getDefaultQueueImplicitArgPosition(unsigned COV);
80unsigned getCompletionActionImplicitArgPosition(unsigned COV);
81
83 unsigned Format;
84 unsigned BitsPerComp;
85 unsigned NumComponents;
86 unsigned NumFormat;
87 unsigned DataFormat;
88};
89
94};
95
96#define GET_MIMGBaseOpcode_DECL
97#define GET_MIMGDim_DECL
98#define GET_MIMGEncoding_DECL
99#define GET_MIMGLZMapping_DECL
100#define GET_MIMGMIPMapping_DECL
101#define GET_MIMGBiASMapping_DECL
102#define GET_MAIInstInfoTable_DECL
103#include "AMDGPUGenSearchableTables.inc"
104
105namespace IsaInfo {
106
107enum {
108 // The closed Vulkan driver sets 96, which limits the wave count to 8 but
109 // doesn't spill SGPRs as much as when 80 is set.
111 TRAP_NUM_SGPRS = 16
113
114enum class TargetIDSetting {
116 Any,
117 Off,
118 On
119};
120
122private:
123 const MCSubtargetInfo &STI;
124 TargetIDSetting XnackSetting;
125 TargetIDSetting SramEccSetting;
126
127public:
128 explicit AMDGPUTargetID(const MCSubtargetInfo &STI);
129 ~AMDGPUTargetID() = default;
130
131 /// \return True if the current xnack setting is not "Unsupported".
132 bool isXnackSupported() const {
133 return XnackSetting != TargetIDSetting::Unsupported;
134 }
135
136 /// \returns True if the current xnack setting is "On" or "Any".
137 bool isXnackOnOrAny() const {
138 return XnackSetting == TargetIDSetting::On ||
139 XnackSetting == TargetIDSetting::Any;
140 }
141
142 /// \returns True if current xnack setting is "On" or "Off",
143 /// false otherwise.
144 bool isXnackOnOrOff() const {
147 }
148
149 /// \returns The current xnack TargetIDSetting, possible options are
150 /// "Unsupported", "Any", "Off", and "On".
152 return XnackSetting;
153 }
154
155 /// Sets xnack setting to \p NewXnackSetting.
156 void setXnackSetting(TargetIDSetting NewXnackSetting) {
157 XnackSetting = NewXnackSetting;
158 }
159
160 /// \return True if the current sramecc setting is not "Unsupported".
161 bool isSramEccSupported() const {
162 return SramEccSetting != TargetIDSetting::Unsupported;
163 }
164
165 /// \returns True if the current sramecc setting is "On" or "Any".
166 bool isSramEccOnOrAny() const {
167 return SramEccSetting == TargetIDSetting::On ||
168 SramEccSetting == TargetIDSetting::Any;
169 }
170
171 /// \returns True if current sramecc setting is "On" or "Off",
172 /// false otherwise.
173 bool isSramEccOnOrOff() const {
176 }
177
178 /// \returns The current sramecc TargetIDSetting, possible options are
179 /// "Unsupported", "Any", "Off", and "On".
181 return SramEccSetting;
182 }
183
184 /// Sets sramecc setting to \p NewSramEccSetting.
185 void setSramEccSetting(TargetIDSetting NewSramEccSetting) {
186 SramEccSetting = NewSramEccSetting;
187 }
188
191
192 /// \returns String representation of an object.
193 std::string toString() const;
194};
195
196/// \returns Wavefront size for given subtarget \p STI.
197unsigned getWavefrontSize(const MCSubtargetInfo *STI);
198
199/// \returns Local memory size in bytes for given subtarget \p STI.
200unsigned getLocalMemorySize(const MCSubtargetInfo *STI);
201
202/// \returns Maximum addressable local memory size in bytes for given subtarget
203/// \p STI.
205
206/// \returns Number of execution units per compute unit for given subtarget \p
207/// STI.
208unsigned getEUsPerCU(const MCSubtargetInfo *STI);
209
210/// \returns Maximum number of work groups per compute unit for given subtarget
211/// \p STI and limited by given \p FlatWorkGroupSize.
212unsigned getMaxWorkGroupsPerCU(const MCSubtargetInfo *STI,
213 unsigned FlatWorkGroupSize);
214
215/// \returns Minimum number of waves per execution unit for given subtarget \p
216/// STI.
217unsigned getMinWavesPerEU(const MCSubtargetInfo *STI);
218
219/// \returns Maximum number of waves per execution unit for given subtarget \p
220/// STI without any kind of limitation.
221unsigned getMaxWavesPerEU(const MCSubtargetInfo *STI);
222
223/// \returns Number of waves per execution unit required to support the given \p
224/// FlatWorkGroupSize.
226 unsigned FlatWorkGroupSize);
227
228/// \returns Minimum flat work group size for given subtarget \p STI.
229unsigned getMinFlatWorkGroupSize(const MCSubtargetInfo *STI);
230
231/// \returns Maximum flat work group size for given subtarget \p STI.
232unsigned getMaxFlatWorkGroupSize(const MCSubtargetInfo *STI);
233
234/// \returns Number of waves per work group for given subtarget \p STI and
235/// \p FlatWorkGroupSize.
236unsigned getWavesPerWorkGroup(const MCSubtargetInfo *STI,
237 unsigned FlatWorkGroupSize);
238
239/// \returns SGPR allocation granularity for given subtarget \p STI.
240unsigned getSGPRAllocGranule(const MCSubtargetInfo *STI);
241
242/// \returns SGPR encoding granularity for given subtarget \p STI.
243unsigned getSGPREncodingGranule(const MCSubtargetInfo *STI);
244
245/// \returns Total number of SGPRs for given subtarget \p STI.
246unsigned getTotalNumSGPRs(const MCSubtargetInfo *STI);
247
248/// \returns Addressable number of SGPRs for given subtarget \p STI.
249unsigned getAddressableNumSGPRs(const MCSubtargetInfo *STI);
250
251/// \returns Minimum number of SGPRs that meets the given number of waves per
252/// execution unit requirement for given subtarget \p STI.
253unsigned getMinNumSGPRs(const MCSubtargetInfo *STI, unsigned WavesPerEU);
254
255/// \returns Maximum number of SGPRs that meets the given number of waves per
256/// execution unit requirement for given subtarget \p STI.
257unsigned getMaxNumSGPRs(const MCSubtargetInfo *STI, unsigned WavesPerEU,
258 bool Addressable);
259
260/// \returns Number of extra SGPRs implicitly required by given subtarget \p
261/// STI when the given special registers are used.
262unsigned getNumExtraSGPRs(const MCSubtargetInfo *STI, bool VCCUsed,
263 bool FlatScrUsed, bool XNACKUsed);
264
265/// \returns Number of extra SGPRs implicitly required by given subtarget \p
266/// STI when the given special registers are used. XNACK is inferred from
267/// \p STI.
268unsigned getNumExtraSGPRs(const MCSubtargetInfo *STI, bool VCCUsed,
269 bool FlatScrUsed);
270
271/// \returns Number of SGPR blocks needed for given subtarget \p STI when
272/// \p NumSGPRs are used. \p NumSGPRs should already include any special
273/// register counts.
274unsigned getNumSGPRBlocks(const MCSubtargetInfo *STI, unsigned NumSGPRs);
275
276/// \returns VGPR allocation granularity for given subtarget \p STI.
277///
278/// For subtargets which support it, \p EnableWavefrontSize32 should match
279/// the ENABLE_WAVEFRONT_SIZE32 kernel descriptor field.
280unsigned
282 std::optional<bool> EnableWavefrontSize32 = std::nullopt);
283
284/// \returns VGPR encoding granularity for given subtarget \p STI.
285///
286/// For subtargets which support it, \p EnableWavefrontSize32 should match
287/// the ENABLE_WAVEFRONT_SIZE32 kernel descriptor field.
289 const MCSubtargetInfo *STI,
290 std::optional<bool> EnableWavefrontSize32 = std::nullopt);
291
292/// \returns Total number of VGPRs for given subtarget \p STI.
293unsigned getTotalNumVGPRs(const MCSubtargetInfo *STI);
294
295/// \returns Addressable number of architectural VGPRs for a given subtarget \p
296/// STI.
298
299/// \returns Addressable number of VGPRs for given subtarget \p STI.
300unsigned getAddressableNumVGPRs(const MCSubtargetInfo *STI);
301
302/// \returns Minimum number of VGPRs that meets given number of waves per
303/// execution unit requirement for given subtarget \p STI.
304unsigned getMinNumVGPRs(const MCSubtargetInfo *STI, unsigned WavesPerEU);
305
306/// \returns Maximum number of VGPRs that meets given number of waves per
307/// execution unit requirement for given subtarget \p STI.
308unsigned getMaxNumVGPRs(const MCSubtargetInfo *STI, unsigned WavesPerEU);
309
310/// \returns Number of waves reachable for a given \p NumVGPRs usage for given
311/// subtarget \p STI.
313 unsigned NumVGPRs);
314
315/// \returns Number of waves reachable for a given \p NumVGPRs usage, \p Granule
316/// size, \p MaxWaves possible, and \p TotalNumVGPRs available.
317unsigned getNumWavesPerEUWithNumVGPRs(unsigned NumVGPRs, unsigned Granule,
318 unsigned MaxWaves,
319 unsigned TotalNumVGPRs);
320
321/// \returns Occupancy for a given \p SGPRs usage, \p MaxWaves possible, and \p
322/// Gen.
323unsigned getOccupancyWithNumSGPRs(unsigned SGPRs, unsigned MaxWaves,
325
326/// \returns Number of VGPR blocks needed for given subtarget \p STI when
327/// \p NumVGPRs are used. We actually return the number of blocks -1, since
328/// that's what we encode.
329///
330/// For subtargets which support it, \p EnableWavefrontSize32 should match the
331/// ENABLE_WAVEFRONT_SIZE32 kernel descriptor field.
333 const MCSubtargetInfo *STI, unsigned NumVGPRs,
334 std::optional<bool> EnableWavefrontSize32 = std::nullopt);
335
336/// \returns Number of VGPR blocks that need to be allocated for the given
337/// subtarget \p STI when \p NumVGPRs are used.
339 const MCSubtargetInfo *STI, unsigned NumVGPRs,
340 std::optional<bool> EnableWavefrontSize32 = std::nullopt);
341
342} // end namespace IsaInfo
343
344// Represents a field in an encoded value.
345template <unsigned HighBit, unsigned LowBit, unsigned D = 0>
347 static_assert(HighBit >= LowBit, "Invalid bit range!");
348 static constexpr unsigned Offset = LowBit;
349 static constexpr unsigned Width = HighBit - LowBit + 1;
350
352 static constexpr ValueType Default = D;
353
356
357 constexpr uint64_t encode() const { return Value; }
358 static ValueType decode(uint64_t Encoded) { return Encoded; }
359};
360
361// A helper for encoding and decoding multiple fields.
362template <typename... Fields> struct EncodingFields {
363 static constexpr uint64_t encode(Fields... Values) {
364 return ((Values.encode() << Values.Offset) | ...);
365 }
366
367 static std::tuple<typename Fields::ValueType...> decode(uint64_t Encoded) {
368 return {Fields::decode((Encoded >> Fields::Offset) &
369 maxUIntN(Fields::Width))...};
370 }
371};
372
374int16_t getNamedOperandIdx(uint16_t Opcode, uint16_t NamedIdx);
375
377inline bool hasNamedOperand(uint64_t Opcode, uint64_t NamedIdx) {
378 return getNamedOperandIdx(Opcode, NamedIdx) != -1;
379}
380
383
385 MIMGBaseOpcode BaseOpcode;
386 bool Store;
387 bool Atomic;
391
394 bool G16;
397 bool HasD16;
398 bool MSAA;
399 bool BVH;
400 bool A16;
401};
402
404const MIMGBaseOpcodeInfo *getMIMGBaseOpcode(unsigned Opc);
405
407const MIMGBaseOpcodeInfo *getMIMGBaseOpcodeInfo(unsigned BaseOpcode);
408
410 MIMGDim Dim;
411 uint8_t NumCoords;
413 bool MSAA;
414 bool DA;
415 uint8_t Encoding;
416 const char *AsmSuffix;
417};
418
420const MIMGDimInfo *getMIMGDimInfo(unsigned DimEnum);
421
424
427
429 MIMGBaseOpcode L;
430 MIMGBaseOpcode LZ;
431};
432
434 MIMGBaseOpcode MIP;
435 MIMGBaseOpcode NONMIP;
436};
437
439 MIMGBaseOpcode Bias;
440 MIMGBaseOpcode NoBias;
441};
442
444 MIMGBaseOpcode Offset;
445 MIMGBaseOpcode NoOffset;
446};
447
449 MIMGBaseOpcode G;
450 MIMGBaseOpcode G16;
451};
452
455
457 unsigned Opcode2Addr;
458 unsigned Opcode3Addr;
459};
460
463
466
469
472
474int getMIMGOpcode(unsigned BaseOpcode, unsigned MIMGEncoding,
475 unsigned VDataDwords, unsigned VAddrDwords);
476
478int getMaskedMIMGOp(unsigned Opc, unsigned NewChannels);
479
481unsigned getAddrSizeMIMGOp(const MIMGBaseOpcodeInfo *BaseOpcode,
482 const MIMGDimInfo *Dim, bool IsA16,
483 bool IsG16Supported);
484
485struct MIMGInfo {
489 uint8_t VDataDwords;
490 uint8_t VAddrDwords;
492};
493
495const MIMGInfo *getMIMGInfo(unsigned Opc);
496
498int getMTBUFBaseOpcode(unsigned Opc);
499
501int getMTBUFOpcode(unsigned BaseOpc, unsigned Elements);
502
504int getMTBUFElements(unsigned Opc);
505
507bool getMTBUFHasVAddr(unsigned Opc);
508
510bool getMTBUFHasSrsrc(unsigned Opc);
511
513bool getMTBUFHasSoffset(unsigned Opc);
514
516int getMUBUFBaseOpcode(unsigned Opc);
517
519int getMUBUFOpcode(unsigned BaseOpc, unsigned Elements);
520
522int getMUBUFElements(unsigned Opc);
523
525bool getMUBUFHasVAddr(unsigned Opc);
526
528bool getMUBUFHasSrsrc(unsigned Opc);
529
531bool getMUBUFHasSoffset(unsigned Opc);
532
534bool getMUBUFIsBufferInv(unsigned Opc);
535
537bool getMUBUFTfe(unsigned Opc);
538
540bool getSMEMIsBuffer(unsigned Opc);
541
543bool getVOP1IsSingle(unsigned Opc);
544
546bool getVOP2IsSingle(unsigned Opc);
547
549bool getVOP3IsSingle(unsigned Opc);
550
552bool isVOPC64DPP(unsigned Opc);
553
555bool isVOPCAsmOnly(unsigned Opc);
556
557/// Returns true if MAI operation is a double precision GEMM.
559bool getMAIIsDGEMM(unsigned Opc);
560
562bool getMAIIsGFX940XDL(unsigned Opc);
563
564struct CanBeVOPD {
565 bool X;
566 bool Y;
567};
568
569/// \returns SIEncodingFamily used for VOPD encoding on a \p ST.
571unsigned getVOPDEncodingFamily(const MCSubtargetInfo &ST);
572
574CanBeVOPD getCanBeVOPD(unsigned Opc);
575
577const GcnBufferFormatInfo *getGcnBufferFormatInfo(uint8_t BitsPerComp,
578 uint8_t NumComponents,
579 uint8_t NumFormat,
580 const MCSubtargetInfo &STI);
583 const MCSubtargetInfo &STI);
584
586int getMCOpcode(uint16_t Opcode, unsigned Gen);
587
589unsigned getVOPDOpcode(unsigned Opc);
590
592int getVOPDFull(unsigned OpX, unsigned OpY, unsigned EncodingFamily);
593
595bool isVOPD(unsigned Opc);
596
598bool isMAC(unsigned Opc);
599
601bool isPermlane16(unsigned Opc);
602
604bool isGenericAtomic(unsigned Opc);
605
607bool isCvt_F32_Fp8_Bf8_e64(unsigned Opc);
608
609namespace VOPD {
610
611enum Component : unsigned {
612 DST = 0,
616
621
622// LSB mask for VGPR banks per VOPD component operand.
623// 4 banks result in a mask 3, setting 2 lower bits.
624constexpr unsigned VOPD_VGPR_BANK_MASKS[] = {1, 3, 3, 1};
625
626enum ComponentIndex : unsigned { X = 0, Y = 1 };
628constexpr unsigned COMPONENTS_NUM = 2;
629
630// Properties of VOPD components.
632private:
633 unsigned SrcOperandsNum = 0;
634 unsigned MandatoryLiteralIdx = ~0u;
635 bool HasSrc2Acc = false;
636
637public:
638 ComponentProps() = default;
639 ComponentProps(const MCInstrDesc &OpDesc);
640
641 // Return the total number of src operands this component has.
642 unsigned getCompSrcOperandsNum() const { return SrcOperandsNum; }
643
644 // Return the number of src operands of this component visible to the parser.
646 return SrcOperandsNum - HasSrc2Acc;
647 }
648
649 // Return true iif this component has a mandatory literal.
650 bool hasMandatoryLiteral() const { return MandatoryLiteralIdx != ~0u; }
651
652 // If this component has a mandatory literal, return component operand
653 // index of this literal (i.e. either Component::SRC1 or Component::SRC2).
656 return MandatoryLiteralIdx;
657 }
658
659 // Return true iif this component has operand
660 // with component index CompSrcIdx and this operand may be a register.
661 bool hasRegSrcOperand(unsigned CompSrcIdx) const {
662 assert(CompSrcIdx < Component::MAX_SRC_NUM);
663 return SrcOperandsNum > CompSrcIdx && !hasMandatoryLiteralAt(CompSrcIdx);
664 }
665
666 // Return true iif this component has tied src2.
667 bool hasSrc2Acc() const { return HasSrc2Acc; }
668
669private:
670 bool hasMandatoryLiteralAt(unsigned CompSrcIdx) const {
671 assert(CompSrcIdx < Component::MAX_SRC_NUM);
672 return MandatoryLiteralIdx == Component::DST_NUM + CompSrcIdx;
673 }
674};
675
676enum ComponentKind : unsigned {
677 SINGLE = 0, // A single VOP1 or VOP2 instruction which may be used in VOPD.
678 COMPONENT_X, // A VOPD instruction, X component.
679 COMPONENT_Y, // A VOPD instruction, Y component.
682
683// Interface functions of this class map VOPD component operand indices
684// to indices of operands in MachineInstr/MCInst or parsed operands array.
685//
686// Note that this class operates with 3 kinds of indices:
687// - VOPD component operand indices (Component::DST, Component::SRC0, etc.);
688// - MC operand indices (they refer operands in a MachineInstr/MCInst);
689// - parsed operand indices (they refer operands in parsed operands array).
690//
691// For SINGLE components mapping between these indices is trivial.
692// But things get more complicated for COMPONENT_X and
693// COMPONENT_Y because these components share the same
694// MachineInstr/MCInst and the same parsed operands array.
695// Below is an example of component operand to parsed operand
696// mapping for the following instruction:
697//
698// v_dual_add_f32 v255, v4, v5 :: v_dual_mov_b32 v6, v1
699//
700// PARSED COMPONENT PARSED
701// COMPONENT OPERANDS OPERAND INDEX OPERAND INDEX
702// -------------------------------------------------------------------
703// "v_dual_add_f32" 0
704// v_dual_add_f32 v255 0 (DST) --> 1
705// v4 1 (SRC0) --> 2
706// v5 2 (SRC1) --> 3
707// "::" 4
708// "v_dual_mov_b32" 5
709// v_dual_mov_b32 v6 0 (DST) --> 6
710// v1 1 (SRC0) --> 7
711// -------------------------------------------------------------------
712//
714private:
715 // Regular MachineInstr/MCInst operands are ordered as follows:
716 // dst, src0 [, other src operands]
717 // VOPD MachineInstr/MCInst operands are ordered as follows:
718 // dstX, dstY, src0X [, other OpX operands], src0Y [, other OpY operands]
719 // Each ComponentKind has operand indices defined below.
720 static constexpr unsigned MC_DST_IDX[] = {0, 0, 1};
721 static constexpr unsigned FIRST_MC_SRC_IDX[] = {1, 2, 2 /* + OpX.MCSrcNum */};
722
723 // Parsed operands of regular instructions are ordered as follows:
724 // Mnemo dst src0 [vsrc1 ...]
725 // Parsed VOPD operands are ordered as follows:
726 // OpXMnemo dstX src0X [vsrc1X|imm vsrc1X|vsrc1X imm] '::'
727 // OpYMnemo dstY src0Y [vsrc1Y|imm vsrc1Y|vsrc1Y imm]
728 // Each ComponentKind has operand indices defined below.
729 static constexpr unsigned PARSED_DST_IDX[] = {1, 1,
730 4 /* + OpX.ParsedSrcNum */};
731 static constexpr unsigned FIRST_PARSED_SRC_IDX[] = {
732 2, 2, 5 /* + OpX.ParsedSrcNum */};
733
734private:
735 const ComponentKind Kind;
736 const ComponentProps PrevComp;
737
738public:
739 // Create layout for COMPONENT_X or SINGLE component.
740 ComponentLayout(ComponentKind Kind) : Kind(Kind) {
742 }
743
744 // Create layout for COMPONENT_Y which depends on COMPONENT_X layout.
746 : Kind(ComponentKind::COMPONENT_Y), PrevComp(OpXProps) {}
747
748public:
749 // Return the index of dst operand in MCInst operands.
750 unsigned getIndexOfDstInMCOperands() const { return MC_DST_IDX[Kind]; }
751
752 // Return the index of the specified src operand in MCInst operands.
753 unsigned getIndexOfSrcInMCOperands(unsigned CompSrcIdx) const {
754 assert(CompSrcIdx < Component::MAX_SRC_NUM);
755 return FIRST_MC_SRC_IDX[Kind] + getPrevCompSrcNum() + CompSrcIdx;
756 }
757
758 // Return the index of dst operand in the parsed operands array.
760 return PARSED_DST_IDX[Kind] + getPrevCompParsedSrcNum();
761 }
762
763 // Return the index of the specified src operand in the parsed operands array.
764 unsigned getIndexOfSrcInParsedOperands(unsigned CompSrcIdx) const {
765 assert(CompSrcIdx < Component::MAX_SRC_NUM);
766 return FIRST_PARSED_SRC_IDX[Kind] + getPrevCompParsedSrcNum() + CompSrcIdx;
767 }
768
769private:
770 unsigned getPrevCompSrcNum() const {
771 return PrevComp.getCompSrcOperandsNum();
772 }
773 unsigned getPrevCompParsedSrcNum() const {
774 return PrevComp.getCompParsedSrcOperandsNum();
775 }
776};
777
778// Layout and properties of VOPD components.
780public:
781 // Create ComponentInfo for COMPONENT_X or SINGLE component.
784 : ComponentLayout(Kind), ComponentProps(OpDesc) {}
785
786 // Create ComponentInfo for COMPONENT_Y which depends on COMPONENT_X layout.
787 ComponentInfo(const MCInstrDesc &OpDesc, const ComponentProps &OpXProps)
788 : ComponentLayout(OpXProps), ComponentProps(OpDesc) {}
789
790 // Map component operand index to parsed operand index.
791 // Return 0 if the specified operand does not exist.
792 unsigned getIndexInParsedOperands(unsigned CompOprIdx) const;
793};
794
795// Properties of VOPD instructions.
796class InstInfo {
797private:
798 const ComponentInfo CompInfo[COMPONENTS_NUM];
799
800public:
801 using RegIndices = std::array<unsigned, Component::MAX_OPR_NUM>;
802
803 InstInfo(const MCInstrDesc &OpX, const MCInstrDesc &OpY)
804 : CompInfo{OpX, OpY} {}
805
806 InstInfo(const ComponentInfo &OprInfoX, const ComponentInfo &OprInfoY)
807 : CompInfo{OprInfoX, OprInfoY} {}
808
809 const ComponentInfo &operator[](size_t ComponentIdx) const {
810 assert(ComponentIdx < COMPONENTS_NUM);
811 return CompInfo[ComponentIdx];
812 }
813
814 // Check VOPD operands constraints.
815 // GetRegIdx(Component, MCOperandIdx) must return a VGPR register index
816 // for the specified component and MC operand. The callback must return 0
817 // if the operand is not a register or not a VGPR.
818 // If \p SkipSrc is set to true then constraints for source operands are not
819 // checked.
820 bool hasInvalidOperand(std::function<unsigned(unsigned, unsigned)> GetRegIdx,
821 bool SkipSrc = false) const {
822 return getInvalidCompOperandIndex(GetRegIdx, SkipSrc).has_value();
823 }
824
825 // Check VOPD operands constraints.
826 // Return the index of an invalid component operand, if any.
827 // If \p SkipSrc is set to true then constraints for source operands are not
828 // checked.
829 std::optional<unsigned> getInvalidCompOperandIndex(
830 std::function<unsigned(unsigned, unsigned)> GetRegIdx,
831 bool SkipSrc = false) const;
832
833private:
835 getRegIndices(unsigned ComponentIdx,
836 std::function<unsigned(unsigned, unsigned)> GetRegIdx) const;
837};
838
839} // namespace VOPD
840
842std::pair<unsigned, unsigned> getVOPDComponents(unsigned VOPDOpcode);
843
845// Get properties of 2 single VOP1/VOP2 instructions
846// used as components to create a VOPD instruction.
847VOPD::InstInfo getVOPDInstInfo(const MCInstrDesc &OpX, const MCInstrDesc &OpY);
848
850// Get properties of VOPD X and Y components.
851VOPD::InstInfo
852getVOPDInstInfo(unsigned VOPDOpcode, const MCInstrInfo *InstrInfo);
853
855bool isTrue16Inst(unsigned Opc);
856
858unsigned mapWMMA2AddrTo3AddrOpcode(unsigned Opc);
859
861unsigned mapWMMA3AddrTo2AddrOpcode(unsigned Opc);
862
864 const MCSubtargetInfo *STI);
865
866bool isGroupSegment(const GlobalValue *GV);
867bool isGlobalSegment(const GlobalValue *GV);
868bool isReadOnlySegment(const GlobalValue *GV);
869
870/// \returns True if constants should be emitted to .text section for given
871/// target triple \p TT, false otherwise.
873
874/// \returns Integer value requested using \p F's \p Name attribute.
875///
876/// \returns \p Default if attribute is not present.
877///
878/// \returns \p Default and emits error if requested value cannot be converted
879/// to integer.
881
882/// \returns A pair of integer values requested using \p F's \p Name attribute
883/// in "first[,second]" format ("second" is optional unless \p OnlyFirstRequired
884/// is false).
885///
886/// \returns \p Default if attribute is not present.
887///
888/// \returns \p Default and emits error if one of the requested values cannot be
889/// converted to integer, or \p OnlyFirstRequired is false and "second" value is
890/// not present.
891std::pair<unsigned, unsigned>
893 std::pair<unsigned, unsigned> Default,
894 bool OnlyFirstRequired = false);
895
896/// \returns Generate a vector of integer values requested using \p F's \p Name
897/// attribute.
898///
899/// \returns true if exactly Size (>2) number of integers are found in the
900/// attribute.
901///
902/// \returns false if any error occurs.
904 unsigned Size);
905
906/// Represents the counter values to wait for in an s_waitcnt instruction.
907///
908/// Large values (including the maximum possible integer) can be used to
909/// represent "don't care" waits.
910struct Waitcnt {
911 unsigned LoadCnt = ~0u; // Corresponds to Vmcnt prior to gfx12.
912 unsigned ExpCnt = ~0u;
913 unsigned DsCnt = ~0u; // Corresponds to LGKMcnt prior to gfx12.
914 unsigned StoreCnt = ~0u; // Corresponds to VScnt on gfx10/gfx11.
915 unsigned SampleCnt = ~0u; // gfx12+ only.
916 unsigned BvhCnt = ~0u; // gfx12+ only.
917 unsigned KmCnt = ~0u; // gfx12+ only.
918
919 Waitcnt() = default;
920 // Pre-gfx12 constructor.
921 Waitcnt(unsigned VmCnt, unsigned ExpCnt, unsigned LgkmCnt, unsigned VsCnt)
922 : LoadCnt(VmCnt), ExpCnt(ExpCnt), DsCnt(LgkmCnt), StoreCnt(VsCnt),
923 SampleCnt(~0u), BvhCnt(~0u), KmCnt(~0u) {}
924
925 // gfx12+ constructor.
926 Waitcnt(unsigned LoadCnt, unsigned ExpCnt, unsigned DsCnt, unsigned StoreCnt,
927 unsigned SampleCnt, unsigned BvhCnt, unsigned KmCnt)
930
931 bool hasWait() const { return StoreCnt != ~0u || hasWaitExceptStoreCnt(); }
932
934 return LoadCnt != ~0u || ExpCnt != ~0u || DsCnt != ~0u ||
935 SampleCnt != ~0u || BvhCnt != ~0u || KmCnt != ~0u;
936 }
937
938 bool hasWaitStoreCnt() const { return StoreCnt != ~0u; }
939
941 // Does the right thing provided self and Other are either both pre-gfx12
942 // or both gfx12+.
943 return Waitcnt(
944 std::min(LoadCnt, Other.LoadCnt), std::min(ExpCnt, Other.ExpCnt),
945 std::min(DsCnt, Other.DsCnt), std::min(StoreCnt, Other.StoreCnt),
946 std::min(SampleCnt, Other.SampleCnt), std::min(BvhCnt, Other.BvhCnt),
947 std::min(KmCnt, Other.KmCnt));
948 }
949};
950
951// The following methods are only meaningful on targets that support
952// S_WAITCNT.
953
954/// \returns Vmcnt bit mask for given isa \p Version.
955unsigned getVmcntBitMask(const IsaVersion &Version);
956
957/// \returns Expcnt bit mask for given isa \p Version.
958unsigned getExpcntBitMask(const IsaVersion &Version);
959
960/// \returns Lgkmcnt bit mask for given isa \p Version.
961unsigned getLgkmcntBitMask(const IsaVersion &Version);
962
963/// \returns Waitcnt bit mask for given isa \p Version.
964unsigned getWaitcntBitMask(const IsaVersion &Version);
965
966/// \returns Decoded Vmcnt from given \p Waitcnt for given isa \p Version.
967unsigned decodeVmcnt(const IsaVersion &Version, unsigned Waitcnt);
968
969/// \returns Decoded Expcnt from given \p Waitcnt for given isa \p Version.
970unsigned decodeExpcnt(const IsaVersion &Version, unsigned Waitcnt);
971
972/// \returns Decoded Lgkmcnt from given \p Waitcnt for given isa \p Version.
973unsigned decodeLgkmcnt(const IsaVersion &Version, unsigned Waitcnt);
974
975/// Decodes Vmcnt, Expcnt and Lgkmcnt from given \p Waitcnt for given isa
976/// \p Version, and writes decoded values into \p Vmcnt, \p Expcnt and
977/// \p Lgkmcnt respectively. Should not be used on gfx12+, the instruction
978/// which needs it is deprecated
979///
980/// \details \p Vmcnt, \p Expcnt and \p Lgkmcnt are decoded as follows:
981/// \p Vmcnt = \p Waitcnt[3:0] (pre-gfx9)
982/// \p Vmcnt = \p Waitcnt[15:14,3:0] (gfx9,10)
983/// \p Vmcnt = \p Waitcnt[15:10] (gfx11)
984/// \p Expcnt = \p Waitcnt[6:4] (pre-gfx11)
985/// \p Expcnt = \p Waitcnt[2:0] (gfx11)
986/// \p Lgkmcnt = \p Waitcnt[11:8] (pre-gfx10)
987/// \p Lgkmcnt = \p Waitcnt[13:8] (gfx10)
988/// \p Lgkmcnt = \p Waitcnt[9:4] (gfx11)
989///
990void decodeWaitcnt(const IsaVersion &Version, unsigned Waitcnt,
991 unsigned &Vmcnt, unsigned &Expcnt, unsigned &Lgkmcnt);
992
993Waitcnt decodeWaitcnt(const IsaVersion &Version, unsigned Encoded);
994
995/// \returns \p Waitcnt with encoded \p Vmcnt for given isa \p Version.
996unsigned encodeVmcnt(const IsaVersion &Version, unsigned Waitcnt,
997 unsigned Vmcnt);
998
999/// \returns \p Waitcnt with encoded \p Expcnt for given isa \p Version.
1000unsigned encodeExpcnt(const IsaVersion &Version, unsigned Waitcnt,
1001 unsigned Expcnt);
1002
1003/// \returns \p Waitcnt with encoded \p Lgkmcnt for given isa \p Version.
1004unsigned encodeLgkmcnt(const IsaVersion &Version, unsigned Waitcnt,
1005 unsigned Lgkmcnt);
1006
1007/// Encodes \p Vmcnt, \p Expcnt and \p Lgkmcnt into Waitcnt for given isa
1008/// \p Version. Should not be used on gfx12+, the instruction which needs
1009/// it is deprecated
1010///
1011/// \details \p Vmcnt, \p Expcnt and \p Lgkmcnt are encoded as follows:
1012/// Waitcnt[2:0] = \p Expcnt (gfx11+)
1013/// Waitcnt[3:0] = \p Vmcnt (pre-gfx9)
1014/// Waitcnt[3:0] = \p Vmcnt[3:0] (gfx9,10)
1015/// Waitcnt[6:4] = \p Expcnt (pre-gfx11)
1016/// Waitcnt[9:4] = \p Lgkmcnt (gfx11)
1017/// Waitcnt[11:8] = \p Lgkmcnt (pre-gfx10)
1018/// Waitcnt[13:8] = \p Lgkmcnt (gfx10)
1019/// Waitcnt[15:10] = \p Vmcnt (gfx11)
1020/// Waitcnt[15:14] = \p Vmcnt[5:4] (gfx9,10)
1021///
1022/// \returns Waitcnt with encoded \p Vmcnt, \p Expcnt and \p Lgkmcnt for given
1023/// isa \p Version.
1024///
1025unsigned encodeWaitcnt(const IsaVersion &Version,
1026 unsigned Vmcnt, unsigned Expcnt, unsigned Lgkmcnt);
1027
1028unsigned encodeWaitcnt(const IsaVersion &Version, const Waitcnt &Decoded);
1029
1030// The following methods are only meaningful on targets that support
1031// S_WAIT_*CNT, introduced with gfx12.
1032
1033/// \returns Loadcnt bit mask for given isa \p Version.
1034/// Returns 0 for versions that do not support LOADcnt
1035unsigned getLoadcntBitMask(const IsaVersion &Version);
1036
1037/// \returns Samplecnt bit mask for given isa \p Version.
1038/// Returns 0 for versions that do not support SAMPLEcnt
1039unsigned getSamplecntBitMask(const IsaVersion &Version);
1040
1041/// \returns Bvhcnt bit mask for given isa \p Version.
1042/// Returns 0 for versions that do not support BVHcnt
1043unsigned getBvhcntBitMask(const IsaVersion &Version);
1044
1045/// \returns Dscnt bit mask for given isa \p Version.
1046/// Returns 0 for versions that do not support DScnt
1047unsigned getDscntBitMask(const IsaVersion &Version);
1048
1049/// \returns Dscnt bit mask for given isa \p Version.
1050/// Returns 0 for versions that do not support KMcnt
1051unsigned getKmcntBitMask(const IsaVersion &Version);
1052
1053/// \return STOREcnt or VScnt bit mask for given isa \p Version.
1054/// returns 0 for versions that do not support STOREcnt or VScnt.
1055/// STOREcnt and VScnt are the same counter, the name used
1056/// depends on the ISA version.
1057unsigned getStorecntBitMask(const IsaVersion &Version);
1058
1059// The following are only meaningful on targets that support
1060// S_WAIT_LOADCNT_DSCNT and S_WAIT_STORECNT_DSCNT.
1061
1062/// \returns Decoded Waitcnt structure from given \p LoadcntDscnt for given
1063/// isa \p Version.
1064Waitcnt decodeLoadcntDscnt(const IsaVersion &Version, unsigned LoadcntDscnt);
1065
1066/// \returns Decoded Waitcnt structure from given \p StorecntDscnt for given
1067/// isa \p Version.
1068Waitcnt decodeStorecntDscnt(const IsaVersion &Version, unsigned StorecntDscnt);
1069
1070/// \returns \p Loadcnt and \p Dscnt components of \p Decoded encoded as an
1071/// immediate that can be used with S_WAIT_LOADCNT_DSCNT for given isa
1072/// \p Version.
1073unsigned encodeLoadcntDscnt(const IsaVersion &Version, const Waitcnt &Decoded);
1074
1075/// \returns \p Storecnt and \p Dscnt components of \p Decoded encoded as an
1076/// immediate that can be used with S_WAIT_STORECNT_DSCNT for given isa
1077/// \p Version.
1078unsigned encodeStorecntDscnt(const IsaVersion &Version, const Waitcnt &Decoded);
1079
1080namespace Hwreg {
1081
1084
1085struct HwregSize : EncodingField<15, 11, 32> {
1087 constexpr uint64_t encode() const { return Value - 1; }
1088 static ValueType decode(uint64_t Encoded) { return Encoded + 1; }
1089};
1090
1092
1093} // namespace Hwreg
1094
1095namespace DepCtr {
1096
1098int encodeDepCtr(const StringRef Name, int64_t Val, unsigned &UsedOprMask,
1099 const MCSubtargetInfo &STI);
1100bool isSymbolicDepCtrEncoding(unsigned Code, bool &HasNonDefaultVal,
1101 const MCSubtargetInfo &STI);
1102bool decodeDepCtr(unsigned Code, int &Id, StringRef &Name, unsigned &Val,
1103 bool &IsDefault, const MCSubtargetInfo &STI);
1104
1105/// \returns Decoded VaVdst from given immediate \p Encoded.
1106unsigned decodeFieldVaVdst(unsigned Encoded);
1107
1108/// \returns Decoded VmVsrc from given immediate \p Encoded.
1109unsigned decodeFieldVmVsrc(unsigned Encoded);
1110
1111/// \returns Decoded SaSdst from given immediate \p Encoded.
1112unsigned decodeFieldSaSdst(unsigned Encoded);
1113
1114/// \returns \p VmVsrc as an encoded Depctr immediate.
1115unsigned encodeFieldVmVsrc(unsigned VmVsrc);
1116
1117/// \returns \p Encoded combined with encoded \p VmVsrc.
1118unsigned encodeFieldVmVsrc(unsigned Encoded, unsigned VmVsrc);
1119
1120/// \returns \p VaVdst as an encoded Depctr immediate.
1121unsigned encodeFieldVaVdst(unsigned VaVdst);
1122
1123/// \returns \p Encoded combined with encoded \p VaVdst.
1124unsigned encodeFieldVaVdst(unsigned Encoded, unsigned VaVdst);
1125
1126/// \returns \p SaSdst as an encoded Depctr immediate.
1127unsigned encodeFieldSaSdst(unsigned SaSdst);
1128
1129/// \returns \p Encoded combined with encoded \p SaSdst.
1130unsigned encodeFieldSaSdst(unsigned Encoded, unsigned SaSdst);
1131
1132} // namespace DepCtr
1133
1134namespace Exp {
1135
1136bool getTgtName(unsigned Id, StringRef &Name, int &Index);
1137
1139unsigned getTgtId(const StringRef Name);
1140
1142bool isSupportedTgtId(unsigned Id, const MCSubtargetInfo &STI);
1143
1144} // namespace Exp
1145
1146namespace MTBUFFormat {
1147
1149int64_t encodeDfmtNfmt(unsigned Dfmt, unsigned Nfmt);
1150
1151void decodeDfmtNfmt(unsigned Format, unsigned &Dfmt, unsigned &Nfmt);
1152
1153int64_t getDfmt(const StringRef Name);
1154
1155StringRef getDfmtName(unsigned Id);
1156
1157int64_t getNfmt(const StringRef Name, const MCSubtargetInfo &STI);
1158
1159StringRef getNfmtName(unsigned Id, const MCSubtargetInfo &STI);
1160
1161bool isValidDfmtNfmt(unsigned Val, const MCSubtargetInfo &STI);
1162
1163bool isValidNfmt(unsigned Val, const MCSubtargetInfo &STI);
1164
1165int64_t getUnifiedFormat(const StringRef Name, const MCSubtargetInfo &STI);
1166
1167StringRef getUnifiedFormatName(unsigned Id, const MCSubtargetInfo &STI);
1168
1169bool isValidUnifiedFormat(unsigned Val, const MCSubtargetInfo &STI);
1170
1171int64_t convertDfmtNfmt2Ufmt(unsigned Dfmt, unsigned Nfmt,
1172 const MCSubtargetInfo &STI);
1173
1174bool isValidFormatEncoding(unsigned Val, const MCSubtargetInfo &STI);
1175
1176unsigned getDefaultFormatEncoding(const MCSubtargetInfo &STI);
1177
1178} // namespace MTBUFFormat
1179
1180namespace SendMsg {
1181
1183bool isValidMsgId(int64_t MsgId, const MCSubtargetInfo &STI);
1184
1186bool isValidMsgOp(int64_t MsgId, int64_t OpId, const MCSubtargetInfo &STI,
1187 bool Strict = true);
1188
1190bool isValidMsgStream(int64_t MsgId, int64_t OpId, int64_t StreamId,
1191 const MCSubtargetInfo &STI, bool Strict = true);
1192
1194bool msgRequiresOp(int64_t MsgId, const MCSubtargetInfo &STI);
1195
1197bool msgSupportsStream(int64_t MsgId, int64_t OpId, const MCSubtargetInfo &STI);
1198
1199void decodeMsg(unsigned Val, uint16_t &MsgId, uint16_t &OpId,
1200 uint16_t &StreamId, const MCSubtargetInfo &STI);
1201
1204 uint64_t OpId,
1206
1207} // namespace SendMsg
1208
1209
1210unsigned getInitialPSInputAddr(const Function &F);
1211
1212bool getHasColorExport(const Function &F);
1213
1214bool getHasDepthExport(const Function &F);
1215
1218
1221
1224
1227
1228// These functions are considered entrypoints into the current module, i.e. they
1229// are allowed to be called from outside the current module. This is different
1230// from isEntryFunctionCC, which is only true for functions that are entered by
1231// the hardware. Module entry points include all entry functions but also
1232// include functions that can be called from other functions inside or outside
1233// the current module. Module entry functions are allowed to allocate LDS.
1236
1239
1240bool isKernelCC(const Function *Func);
1241
1242// FIXME: Remove this when calling conventions cleaned up
1245 switch (CC) {
1248 return true;
1249 default:
1250 return false;
1251 }
1252}
1253
1254bool hasXNACK(const MCSubtargetInfo &STI);
1255bool hasSRAMECC(const MCSubtargetInfo &STI);
1256bool hasMIMG_R128(const MCSubtargetInfo &STI);
1257bool hasA16(const MCSubtargetInfo &STI);
1258bool hasG16(const MCSubtargetInfo &STI);
1259bool hasPackedD16(const MCSubtargetInfo &STI);
1260bool hasGDS(const MCSubtargetInfo &STI);
1261unsigned getNSAMaxSize(const MCSubtargetInfo &STI, bool HasSampler = false);
1262unsigned getMaxNumUserSGPRs(const MCSubtargetInfo &STI);
1263
1264bool isSI(const MCSubtargetInfo &STI);
1265bool isCI(const MCSubtargetInfo &STI);
1266bool isVI(const MCSubtargetInfo &STI);
1267bool isGFX9(const MCSubtargetInfo &STI);
1268bool isGFX9_GFX10(const MCSubtargetInfo &STI);
1269bool isGFX9_GFX10_GFX11(const MCSubtargetInfo &STI);
1270bool isGFX8_GFX9_GFX10(const MCSubtargetInfo &STI);
1271bool isGFX8Plus(const MCSubtargetInfo &STI);
1272bool isGFX9Plus(const MCSubtargetInfo &STI);
1273bool isNotGFX9Plus(const MCSubtargetInfo &STI);
1274bool isGFX10(const MCSubtargetInfo &STI);
1275bool isGFX10_GFX11(const MCSubtargetInfo &STI);
1276bool isGFX10Plus(const MCSubtargetInfo &STI);
1277bool isNotGFX10Plus(const MCSubtargetInfo &STI);
1278bool isGFX10Before1030(const MCSubtargetInfo &STI);
1279bool isGFX11(const MCSubtargetInfo &STI);
1280bool isGFX11Plus(const MCSubtargetInfo &STI);
1281bool isGFX12(const MCSubtargetInfo &STI);
1282bool isGFX12Plus(const MCSubtargetInfo &STI);
1283bool isNotGFX12Plus(const MCSubtargetInfo &STI);
1284bool isNotGFX11Plus(const MCSubtargetInfo &STI);
1285bool isGCN3Encoding(const MCSubtargetInfo &STI);
1286bool isGFX10_AEncoding(const MCSubtargetInfo &STI);
1287bool isGFX10_BEncoding(const MCSubtargetInfo &STI);
1288bool hasGFX10_3Insts(const MCSubtargetInfo &STI);
1289bool isGFX10_3_GFX11(const MCSubtargetInfo &STI);
1290bool isGFX90A(const MCSubtargetInfo &STI);
1291bool isGFX940(const MCSubtargetInfo &STI);
1293bool hasMAIInsts(const MCSubtargetInfo &STI);
1294bool hasVOPD(const MCSubtargetInfo &STI);
1295bool hasDPPSrc1SGPR(const MCSubtargetInfo &STI);
1296int getTotalNumVGPRs(bool has90AInsts, int32_t ArgNumAGPR, int32_t ArgNumVGPR);
1297unsigned hasKernargPreload(const MCSubtargetInfo &STI);
1298
1299/// Is Reg - scalar register
1300bool isSGPR(unsigned Reg, const MCRegisterInfo* TRI);
1301
1302/// \returns if \p Reg occupies the high 16-bits of a 32-bit register.
1303/// The bit indicating isHi is the LSB of the encoding.
1304bool isHi(unsigned Reg, const MCRegisterInfo &MRI);
1305
1306/// If \p Reg is a pseudo reg, return the correct hardware register given
1307/// \p STI otherwise return \p Reg.
1308unsigned getMCReg(unsigned Reg, const MCSubtargetInfo &STI);
1309
1310/// Convert hardware register \p Reg to a pseudo register
1312unsigned mc2PseudoReg(unsigned Reg);
1313
1315bool isInlineValue(unsigned Reg);
1316
1317/// Is this an AMDGPU specific source operand? These include registers,
1318/// inline constants, literals and mandatory literals (KImm).
1319bool isSISrcOperand(const MCInstrDesc &Desc, unsigned OpNo);
1320
1321/// Is this a KImm operand?
1322bool isKImmOperand(const MCInstrDesc &Desc, unsigned OpNo);
1323
1324/// Is this floating-point operand?
1325bool isSISrcFPOperand(const MCInstrDesc &Desc, unsigned OpNo);
1326
1327/// Does this operand support only inlinable literals?
1328bool isSISrcInlinableOperand(const MCInstrDesc &Desc, unsigned OpNo);
1329
1330/// Get the size in bits of a register from the register class \p RC.
1331unsigned getRegBitWidth(unsigned RCID);
1332
1333/// Get the size in bits of a register from the register class \p RC.
1334unsigned getRegBitWidth(const MCRegisterClass &RC);
1335
1336/// Get size of register operand
1337unsigned getRegOperandSize(const MCRegisterInfo *MRI, const MCInstrDesc &Desc,
1338 unsigned OpNo);
1339
1341inline unsigned getOperandSize(const MCOperandInfo &OpInfo) {
1342 switch (OpInfo.OperandType) {
1355 case AMDGPU::OPERAND_KIMM16: // mandatory literal is always size 4
1357 return 4;
1358
1364 return 8;
1365
1386 return 2;
1387
1388 default:
1389 llvm_unreachable("unhandled operand type");
1390 }
1391}
1392
1394inline unsigned getOperandSize(const MCInstrDesc &Desc, unsigned OpNo) {
1395 return getOperandSize(Desc.operands()[OpNo]);
1396}
1397
1398/// Is this literal inlinable, and not one of the values intended for floating
1399/// point values.
1401inline bool isInlinableIntLiteral(int64_t Literal) {
1402 return Literal >= -16 && Literal <= 64;
1403}
1404
1405/// Is this literal inlinable
1407bool isInlinableLiteral64(int64_t Literal, bool HasInv2Pi);
1408
1410bool isInlinableLiteral32(int32_t Literal, bool HasInv2Pi);
1411
1413bool isInlinableLiteralBF16(int16_t Literal, bool HasInv2Pi);
1414
1416bool isInlinableLiteralFP16(int16_t Literal, bool HasInv2Pi);
1417
1419bool isInlinableLiteralBF16(int16_t Literal, bool HasInv2Pi);
1420
1422bool isInlinableLiteralI16(int32_t Literal, bool HasInv2Pi);
1423
1425std::optional<unsigned> getInlineEncodingV2I16(uint32_t Literal);
1426
1428std::optional<unsigned> getInlineEncodingV2BF16(uint32_t Literal);
1429
1431std::optional<unsigned> getInlineEncodingV2F16(uint32_t Literal);
1432
1434bool isInlinableLiteralV216(uint32_t Literal, uint8_t OpType);
1435
1438
1441
1444
1446bool isValid32BitLiteral(uint64_t Val, bool IsFP64);
1447
1448bool isArgPassedInSGPR(const Argument *Arg);
1449
1450bool isArgPassedInSGPR(const CallBase *CB, unsigned ArgNo);
1451
1454 int64_t EncodedOffset);
1455
1458 int64_t EncodedOffset,
1459 bool IsBuffer);
1460
1461/// Convert \p ByteOffset to dwords if the subtarget uses dword SMRD immediate
1462/// offsets.
1464
1465/// \returns The encoding that will be used for \p ByteOffset in the
1466/// SMRD offset field, or std::nullopt if it won't fit. On GFX9 and GFX10
1467/// S_LOAD instructions have a signed offset, on other subtargets it is
1468/// unsigned. S_BUFFER has an unsigned offset for all subtargets.
1469std::optional<int64_t> getSMRDEncodedOffset(const MCSubtargetInfo &ST,
1470 int64_t ByteOffset, bool IsBuffer);
1471
1472/// \return The encoding that can be used for a 32-bit literal offset in an SMRD
1473/// instruction. This is only useful on CI.s
1474std::optional<int64_t> getSMRDEncodedLiteralOffset32(const MCSubtargetInfo &ST,
1475 int64_t ByteOffset);
1476
1477/// For pre-GFX12 FLAT instructions the offset must be positive;
1478/// MSB is ignored and forced to zero.
1479///
1480/// \return The number of bits available for the signed offset field in flat
1481/// instructions. Note that some forms of the instruction disallow negative
1482/// offsets.
1483unsigned getNumFlatOffsetBits(const MCSubtargetInfo &ST);
1484
1485/// \returns true if this offset is small enough to fit in the SMRD
1486/// offset field. \p ByteOffset should be the offset in bytes and
1487/// not the encoded offset.
1488bool isLegalSMRDImmOffset(const MCSubtargetInfo &ST, int64_t ByteOffset);
1489
1491inline bool isLegalDPALU_DPPControl(unsigned DC) {
1492 return DC >= DPP::ROW_NEWBCAST_FIRST && DC <= DPP::ROW_NEWBCAST_LAST;
1493}
1494
1495/// \returns true if an instruction may have a 64-bit VGPR operand.
1496bool hasAny64BitVGPROperands(const MCInstrDesc &OpDesc);
1497
1498/// \returns true if an instruction is a DP ALU DPP.
1499bool isDPALU_DPP(const MCInstrDesc &OpDesc);
1500
1501/// \returns true if the intrinsic is divergent
1502bool isIntrinsicSourceOfDivergence(unsigned IntrID);
1503
1504/// \returns true if the intrinsic is uniform
1505bool isIntrinsicAlwaysUniform(unsigned IntrID);
1506
1507/// \returns lds block size in terms of dwords. \p
1508/// This is used to calculate the lds size encoded for PAL metadata 3.0+ which
1509/// must be defined in terms of bytes.
1510unsigned getLdsDwGranularity(const MCSubtargetInfo &ST);
1511
1512} // end namespace AMDGPU
1513
1514raw_ostream &operator<<(raw_ostream &OS,
1516
1517} // end namespace llvm
1518
1519#endif // LLVM_LIB_TARGET_AMDGPU_UTILS_AMDGPUBASEINFO_H
unsigned const MachineRegisterInfo * MRI
Base class for AMDGPU specific classes of TargetSubtarget.
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
#define LLVM_READNONE
Definition: Compiler.h:220
#define LLVM_READONLY
Definition: Compiler.h:227
uint64_t Align
std::string Name
uint64_t Size
#define F(x, y, z)
Definition: MD5.cpp:55
#define G(x, y, z)
Definition: MD5.cpp:56
unsigned const TargetRegisterInfo * TRI
unsigned Reg
Module.h This file contains the declarations for the Module class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
void setTargetIDFromFeaturesString(StringRef FS)
void setXnackSetting(TargetIDSetting NewXnackSetting)
Sets xnack setting to NewXnackSetting.
TargetIDSetting getXnackSetting() const
void setTargetIDFromTargetIDStream(StringRef TargetID)
void setSramEccSetting(TargetIDSetting NewSramEccSetting)
Sets sramecc setting to NewSramEccSetting.
TargetIDSetting getSramEccSetting() const
unsigned getIndexInParsedOperands(unsigned CompOprIdx) const
ComponentInfo(const MCInstrDesc &OpDesc, ComponentKind Kind=ComponentKind::SINGLE)
ComponentInfo(const MCInstrDesc &OpDesc, const ComponentProps &OpXProps)
unsigned getIndexOfSrcInMCOperands(unsigned CompSrcIdx) const
unsigned getIndexOfDstInParsedOperands() const
ComponentLayout(const ComponentProps &OpXProps)
unsigned getIndexOfSrcInParsedOperands(unsigned CompSrcIdx) const
bool hasRegSrcOperand(unsigned CompSrcIdx) const
unsigned getMandatoryLiteralCompOperandIndex() const
unsigned getCompParsedSrcOperandsNum() const
InstInfo(const ComponentInfo &OprInfoX, const ComponentInfo &OprInfoY)
bool hasInvalidOperand(std::function< unsigned(unsigned, unsigned)> GetRegIdx, bool SkipSrc=false) const
const ComponentInfo & operator[](size_t ComponentIdx) const
InstInfo(const MCInstrDesc &OpX, const MCInstrDesc &OpY)
std::optional< unsigned > getInvalidCompOperandIndex(std::function< unsigned(unsigned, unsigned)> GetRegIdx, bool SkipSrc=false) const
std::array< unsigned, Component::MAX_OPR_NUM > RegIndices
This class represents an incoming formal argument to a Function.
Definition: Argument.h:31
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1494
Describe properties that are true of each instruction in the target description file.
Definition: MCInstrDesc.h:198
Interface to description of machine instruction set.
Definition: MCInstrInfo.h:26
This holds information about one operand of a machine instruction, indicating the register class for ...
Definition: MCInstrDesc.h:85
uint8_t OperandType
Information about the type of the operand.
Definition: MCInstrDesc.h:97
MCRegisterClass - Base class of TargetRegisterClass.
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Generic base class for all target subtargets.
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
LLVM Value Representation.
Definition: Value.h:74
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
bool decodeDepCtr(unsigned Code, int &Id, StringRef &Name, unsigned &Val, bool &IsDefault, const MCSubtargetInfo &STI)
unsigned encodeFieldVaVdst(unsigned Encoded, unsigned VaVdst)
unsigned decodeFieldSaSdst(unsigned Encoded)
unsigned encodeFieldVmVsrc(unsigned Encoded, unsigned VmVsrc)
int encodeDepCtr(const StringRef Name, int64_t Val, unsigned &UsedOprMask, const MCSubtargetInfo &STI)
unsigned encodeFieldSaSdst(unsigned Encoded, unsigned SaSdst)
bool isSymbolicDepCtrEncoding(unsigned Code, bool &HasNonDefaultVal, const MCSubtargetInfo &STI)
unsigned decodeFieldVaVdst(unsigned Encoded)
int getDefaultDepCtrEncoding(const MCSubtargetInfo &STI)
unsigned decodeFieldVmVsrc(unsigned Encoded)
bool isSupportedTgtId(unsigned Id, const MCSubtargetInfo &STI)
bool getTgtName(unsigned Id, StringRef &Name, int &Index)
unsigned getTgtId(const StringRef Name)
static constexpr unsigned GFX10_1
static constexpr unsigned GFX10_3
static constexpr unsigned GFX11
static constexpr unsigned GFX9
unsigned getVGPREncodingGranule(const MCSubtargetInfo *STI, std::optional< bool > EnableWavefrontSize32)
unsigned getTotalNumVGPRs(const MCSubtargetInfo *STI)
unsigned getWavesPerEUForWorkGroup(const MCSubtargetInfo *STI, unsigned FlatWorkGroupSize)
unsigned getWavefrontSize(const MCSubtargetInfo *STI)
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 getMinNumVGPRs(const MCSubtargetInfo *STI, unsigned WavesPerEU)
unsigned getEUsPerCU(const MCSubtargetInfo *STI)
unsigned getAddressableNumSGPRs(const MCSubtargetInfo *STI)
unsigned getAddressableNumVGPRs(const MCSubtargetInfo *STI)
unsigned getMinNumSGPRs(const MCSubtargetInfo *STI, unsigned WavesPerEU)
unsigned getMinFlatWorkGroupSize(const MCSubtargetInfo *STI)
unsigned getMaxNumSGPRs(const MCSubtargetInfo *STI, unsigned WavesPerEU, bool Addressable)
unsigned getNumSGPRBlocks(const MCSubtargetInfo *STI, unsigned NumSGPRs)
unsigned getMinWavesPerEU(const MCSubtargetInfo *STI)
unsigned getSGPRAllocGranule(const MCSubtargetInfo *STI)
unsigned getNumWavesPerEUWithNumVGPRs(const MCSubtargetInfo *STI, unsigned NumVGPRs)
unsigned getMaxNumVGPRs(const MCSubtargetInfo *STI, unsigned WavesPerEU)
unsigned getEncodedNumVGPRBlocks(const MCSubtargetInfo *STI, unsigned NumVGPRs, std::optional< bool > EnableWavefrontSize32)
unsigned getOccupancyWithNumSGPRs(unsigned SGPRs, unsigned MaxWaves, AMDGPUSubtarget::Generation Gen)
unsigned getVGPRAllocGranule(const MCSubtargetInfo *STI, std::optional< bool > EnableWavefrontSize32)
unsigned getAddressableNumArchVGPRs(const MCSubtargetInfo *STI)
unsigned getAllocatedNumVGPRBlocks(const MCSubtargetInfo *STI, unsigned NumVGPRs, std::optional< bool > EnableWavefrontSize32)
unsigned getTotalNumSGPRs(const MCSubtargetInfo *STI)
bool isValidUnifiedFormat(unsigned Id, const MCSubtargetInfo &STI)
unsigned getDefaultFormatEncoding(const MCSubtargetInfo &STI)
StringRef getUnifiedFormatName(unsigned Id, const MCSubtargetInfo &STI)
bool isValidNfmt(unsigned Id, const MCSubtargetInfo &STI)
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)
int64_t getNfmt(const StringRef Name, const MCSubtargetInfo &STI)
int64_t getDfmt(const StringRef Name)
void decodeDfmtNfmt(unsigned Format, unsigned &Dfmt, unsigned &Nfmt)
uint64_t encodeMsg(uint64_t MsgId, uint64_t OpId, uint64_t StreamId)
bool msgSupportsStream(int64_t MsgId, int64_t OpId, const MCSubtargetInfo &STI)
void decodeMsg(unsigned Val, uint16_t &MsgId, uint16_t &OpId, uint16_t &StreamId, const MCSubtargetInfo &STI)
bool isValidMsgId(int64_t MsgId, const MCSubtargetInfo &STI)
bool isValidMsgStream(int64_t MsgId, int64_t OpId, int64_t StreamId, const MCSubtargetInfo &STI, bool Strict)
bool 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 COMPONENTS[]
bool isGCN3Encoding(const MCSubtargetInfo &STI)
bool isInlinableLiteralBF16(int16_t Literal, bool HasInv2Pi)
bool isGFX10_BEncoding(const MCSubtargetInfo &STI)
LLVM_READONLY const MIMGG16MappingInfo * getMIMGG16MappingInfo(unsigned G)
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)
SmallVector< unsigned > getIntegerVecAttribute(const Function &F, StringRef Name, unsigned Size)
uint64_t convertSMRDOffsetUnits(const MCSubtargetInfo &ST, uint64_t ByteOffset)
Convert ByteOffset to dwords if the subtarget uses dword SMRD immediate offsets.
LLVM_READONLY const MIMGOffsetMappingInfo * getMIMGOffsetMappingInfo(unsigned Offset)
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)
LLVM_READNONE bool isLegalDPALU_DPPControl(unsigned DC)
bool isGFX10Before1030(const MCSubtargetInfo &STI)
bool isSISrcInlinableOperand(const MCInstrDesc &Desc, unsigned OpNo)
Does this operand support only inlinable literals?
unsigned mapWMMA2AddrTo3AddrOpcode(unsigned Opc)
bool shouldEmitConstantsToTextSection(const Triple &TT)
bool isInlinableLiteralV2I16(uint32_t Literal)
int getMTBUFElements(unsigned Opc)
int32_t getTotalNumVGPRs(bool has90AInsts, int32_t ArgNumAGPR, int32_t ArgNumVGPR)
bool isGFX10(const MCSubtargetInfo &STI)
LLVM_READONLY int16_t getNamedOperandIdx(uint16_t Opcode, uint16_t NamedIdx)
void initDefaultAMDKernelCodeT(amd_kernel_code_t &Header, const MCSubtargetInfo *STI)
bool isInlinableLiteralV2BF16(uint32_t Literal)
unsigned getMaxNumUserSGPRs(const MCSubtargetInfo &STI)
unsigned getNumFlatOffsetBits(const MCSubtargetInfo &ST)
For pre-GFX12 FLAT instructions the offset must be positive; MSB is ignored and forced to zero.
unsigned mc2PseudoReg(unsigned Reg)
Convert hardware register Reg to a pseudo register.
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)
CanBeVOPD getCanBeVOPD(unsigned Opc)
int getIntegerAttribute(const Function &F, StringRef Name, int Default)
bool hasPackedD16(const MCSubtargetInfo &STI)
unsigned getStorecntBitMask(const IsaVersion &Version)
unsigned getLdsDwGranularity(const MCSubtargetInfo &ST)
bool isGFX940(const MCSubtargetInfo &STI)
bool isEntryFunctionCC(CallingConv::ID CC)
LLVM_READNONE bool isKernel(CallingConv::ID CC)
bool isInlinableLiteralV2F16(uint32_t Literal)
bool isHsaAbi(const MCSubtargetInfo &STI)
bool isGFX11(const MCSubtargetInfo &STI)
bool getSMEMIsBuffer(unsigned Opc)
bool isGFX10_3_GFX11(const MCSubtargetInfo &STI)
bool isGroupSegment(const GlobalValue *GV)
LLVM_READONLY const MIMGMIPMappingInfo * getMIMGMIPMappingInfo(unsigned MIP)
bool getMTBUFHasSoffset(unsigned Opc)
bool hasXNACK(const MCSubtargetInfo &STI)
bool isValid32BitLiteral(uint64_t Val, bool IsFP64)
unsigned getVOPDOpcode(unsigned Opc)
bool isDPALU_DPP(const MCInstrDesc &OpDesc)
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 isCompute(CallingConv::ID cc)
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)
bool getVOP3IsSingle(unsigned Opc)
bool isGFX9(const MCSubtargetInfo &STI)
bool getVOP1IsSingle(unsigned Opc)
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 isChainCC(CallingConv::ID CC)
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)
int getVOPDFull(unsigned OpX, unsigned OpY, unsigned EncodingFamily)
bool isTrue16Inst(unsigned Opc)
bool hasAny64BitVGPROperands(const MCInstrDesc &OpDesc)
std::pair< unsigned, unsigned > getVOPDComponents(unsigned VOPDOpcode)
LLVM_READONLY const MIMGDimInfo * getMIMGDimInfoByEncoding(uint8_t DimEnc)
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 isSISrcOperand(const MCInstrDesc &Desc, unsigned OpNo)
Is this an AMDGPU specific source operand? These include registers, inline constants,...
bool isLegalSMRDImmOffset(const MCSubtargetInfo &ST, int64_t ByteOffset)
unsigned getKmcntBitMask(const IsaVersion &Version)
unsigned getVmcntBitMask(const IsaVersion &Version)
bool isNotGFX10Plus(const MCSubtargetInfo &STI)
bool hasMAIInsts(const MCSubtargetInfo &STI)
bool isIntrinsicSourceOfDivergence(unsigned IntrID)
bool isKernelCC(const Function *Func)
bool isGenericAtomic(unsigned Opc)
Waitcnt decodeStorecntDscnt(const IsaVersion &Version, unsigned StorecntDscnt)
bool isGFX8Plus(const MCSubtargetInfo &STI)
LLVM_READONLY bool hasNamedOperand(uint64_t Opcode, uint64_t NamedIdx)
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)
std::optional< int64_t > getSMRDEncodedOffset(const MCSubtargetInfo &ST, int64_t ByteOffset, bool IsBuffer)
LLVM_READONLY const MIMGBiasMappingInfo * getMIMGBiasMappingInfo(unsigned Bias)
bool isSGPR(unsigned Reg, const MCRegisterInfo *TRI)
Is Reg - scalar register.
bool isHi(unsigned Reg, const MCRegisterInfo &MRI)
unsigned getBvhcntBitMask(const IsaVersion &Version)
LLVM_READONLY const MIMGDimInfo * getMIMGDimInfoByAsmSuffix(StringRef AsmSuffix)
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?
bool isShader(CallingConv::ID cc)
unsigned getHostcallImplicitArgPosition(unsigned CodeObjectVersion)
bool isGFX10Plus(const MCSubtargetInfo &STI)
unsigned getMCReg(unsigned Reg, const MCSubtargetInfo &STI)
If Reg is a pseudo reg, return the correct hardware register given STI otherwise return Reg.
bool isGlobalSegment(const GlobalValue *GV)
@ OPERAND_KIMM32
Operand with 32-bit immediate that uses the constant bus.
Definition: SIDefines.h:234
@ OPERAND_REG_IMM_INT64
Definition: SIDefines.h:201
@ OPERAND_REG_IMM_V2FP16
Definition: SIDefines.h:211
@ OPERAND_REG_INLINE_C_V2INT32
Definition: SIDefines.h:227
@ OPERAND_REG_INLINE_C_FP64
Definition: SIDefines.h:223
@ OPERAND_REG_INLINE_C_BF16
Definition: SIDefines.h:220
@ OPERAND_REG_INLINE_C_V2BF16
Definition: SIDefines.h:225
@ OPERAND_REG_IMM_V2INT16
Definition: SIDefines.h:212
@ OPERAND_REG_IMM_BF16
Definition: SIDefines.h:205
@ OPERAND_REG_INLINE_AC_V2FP16
Definition: SIDefines.h:246
@ OPERAND_REG_IMM_INT32
Operands with register or 32-bit immediate.
Definition: SIDefines.h:200
@ OPERAND_REG_IMM_V2BF16
Definition: SIDefines.h:210
@ OPERAND_REG_IMM_BF16_DEFERRED
Definition: SIDefines.h:207
@ OPERAND_REG_IMM_FP16
Definition: SIDefines.h:206
@ OPERAND_REG_INLINE_C_INT64
Definition: SIDefines.h:219
@ OPERAND_REG_INLINE_AC_BF16
Definition: SIDefines.h:240
@ OPERAND_REG_INLINE_C_INT16
Operands with register or inline constant.
Definition: SIDefines.h:217
@ OPERAND_REG_INLINE_AC_INT16
Operands with an AccVGPR register or inline constant.
Definition: SIDefines.h:238
@ OPERAND_REG_IMM_FP64
Definition: SIDefines.h:204
@ OPERAND_REG_INLINE_C_V2FP16
Definition: SIDefines.h:226
@ OPERAND_REG_INLINE_AC_V2INT16
Definition: SIDefines.h:244
@ OPERAND_REG_INLINE_AC_FP16
Definition: SIDefines.h:241
@ OPERAND_REG_INLINE_AC_INT32
Definition: SIDefines.h:239
@ OPERAND_REG_INLINE_AC_FP32
Definition: SIDefines.h:242
@ OPERAND_REG_INLINE_AC_V2BF16
Definition: SIDefines.h:245
@ OPERAND_REG_IMM_V2INT32
Definition: SIDefines.h:213
@ OPERAND_REG_IMM_FP32
Definition: SIDefines.h:203
@ OPERAND_REG_INLINE_C_FP32
Definition: SIDefines.h:222
@ OPERAND_REG_INLINE_C_INT32
Definition: SIDefines.h:218
@ OPERAND_REG_INLINE_C_V2INT16
Definition: SIDefines.h:224
@ OPERAND_REG_IMM_V2FP32
Definition: SIDefines.h:214
@ OPERAND_REG_INLINE_AC_FP64
Definition: SIDefines.h:243
@ OPERAND_REG_INLINE_C_FP16
Definition: SIDefines.h:221
@ OPERAND_REG_IMM_INT16
Definition: SIDefines.h:202
@ OPERAND_REG_INLINE_C_V2FP32
Definition: SIDefines.h:228
@ OPERAND_INLINE_SPLIT_BARRIER_INT32
Definition: SIDefines.h:231
@ OPERAND_REG_IMM_FP32_DEFERRED
Definition: SIDefines.h:209
@ OPERAND_REG_IMM_FP16_DEFERRED
Definition: SIDefines.h:208
bool isNotGFX9Plus(const MCSubtargetInfo &STI)
LLVM_READONLY const MIMGLZMappingInfo * getMIMGLZMappingInfo(unsigned L)
bool hasGDS(const MCSubtargetInfo &STI)
bool isLegalSMRDEncodedUnsignedOffset(const MCSubtargetInfo &ST, int64_t EncodedOffset)
bool isGFX9Plus(const MCSubtargetInfo &STI)
bool hasDPPSrc1SGPR(const MCSubtargetInfo &STI)
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)
int getMCOpcode(uint16_t Opcode, unsigned Gen)
const MIMGBaseOpcodeInfo * getMIMGBaseOpcode(unsigned Opc)
bool isVI(const MCSubtargetInfo &STI)
LLVM_READONLY const MIMGDimInfo * getMIMGDimInfo(unsigned DimEnum)
bool getMUBUFIsBufferInv(unsigned Opc)
std::optional< unsigned > getInlineEncodingV2BF16(uint32_t Literal)
unsigned hasKernargPreload(const MCSubtargetInfo &STI)
bool isMAC(unsigned Opc)
LLVM_READNONE unsigned getOperandSize(const MCOperandInfo &OpInfo)
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)
unsigned getCompletionActionImplicitArgPosition(unsigned CodeObjectVersion)
int getMaskedMIMGOp(unsigned Opc, unsigned NewChannels)
bool isModuleEntryFunctionCC(CallingConv::ID CC)
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)
bool isInlinableLiteral64(int64_t Literal, bool HasInv2Pi)
Is this literal inlinable.
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)
bool isGraphics(CallingConv::ID cc)
unsigned mapWMMA3AddrTo2AddrOpcode(unsigned Opc)
bool isPermlane16(unsigned Opc)
LLVM_READONLY int getSOPPWithRelaxation(uint16_t Opcode)
bool getMUBUFHasSrsrc(unsigned Opc)
unsigned getDscntBitMask(const IsaVersion &Version)
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
@ AMDGPU_KERNEL
Used for AMDGPU code object kernels.
Definition: CallingConv.h:200
@ SPIR_KERNEL
Used for SPIR kernel functions.
Definition: CallingConv.h:144
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:456
@ Other
Any other memory.
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
Definition: APFixedPoint.h:293
@ Default
The result values are uniform if and only if all operands are uniform.
uint64_t maxUIntN(uint64_t N)
Gets the maximum value for a N-bit unsigned integer.
Definition: MathExtras.h:203
AMD Kernel Code Object (amd_kernel_code_t).
static constexpr unsigned Width
constexpr EncodingField(ValueType Value)
static constexpr unsigned Offset
static constexpr ValueType Default
static ValueType decode(uint64_t Encoded)
constexpr uint64_t encode() const
static constexpr uint64_t encode(Fields... Values)
static std::tuple< typename Fields::ValueType... > decode(uint64_t Encoded)
constexpr uint64_t encode() const
static ValueType decode(uint64_t Encoded)
Represents the counter values to wait for in an s_waitcnt instruction.
Waitcnt(unsigned LoadCnt, unsigned ExpCnt, unsigned DsCnt, unsigned StoreCnt, unsigned SampleCnt, unsigned BvhCnt, unsigned KmCnt)
bool hasWaitExceptStoreCnt() const
bool hasWaitStoreCnt() const
Waitcnt(unsigned VmCnt, unsigned ExpCnt, unsigned LgkmCnt, unsigned VsCnt)
Waitcnt combined(const Waitcnt &Other) const
Description of the encoding of one expression Op.