LLVM 23.0.0git
AMDGPUWaitcntUtils.cpp
Go to the documentation of this file.
1//===- AMDGPUWaitcntUtils.cpp ---------------------------------------------===//
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
12
13namespace llvm::AMDGPU {
14
18
20 switch (T) {
21 case LOAD_CNT:
22 return "LOAD_CNT";
23 case DS_CNT:
24 return "DS_CNT";
25 case EXP_CNT:
26 return "EXP_CNT";
27 case STORE_CNT:
28 return "STORE_CNT";
29 case SAMPLE_CNT:
30 return "SAMPLE_CNT";
31 case BVH_CNT:
32 return "BVH_CNT";
33 case KM_CNT:
34 return "KM_CNT";
35 case X_CNT:
36 return "X_CNT";
37 case ASYNC_CNT:
38 return "ASYNC_CNT";
39 case TENSOR_CNT:
40 return "TENSOR_CNT";
41 case VA_VDST:
42 return "VA_VDST";
43 case VM_VSRC:
44 return "VM_VSRC";
45 case NUM_INST_CNTS:
46 return "NUM_INST_CNTS";
47 }
48 llvm_unreachable("Unhandled InstCounterType");
49}
50
70
72 switch (T) {
74 return LoadcntMax;
75 case AMDGPU::DS_CNT:
76 return DscntMax;
77 case AMDGPU::EXP_CNT:
78 return ExpcntMax;
80 return StorecntMax;
82 return SamplecntMax;
83 case AMDGPU::BVH_CNT:
84 return BvhcntMax;
85 case AMDGPU::KM_CNT:
86 return KmcntMax;
87 case AMDGPU::X_CNT:
88 return XcntMax;
89 case AMDGPU::VA_VDST:
90 return VaVdstMax;
91 case AMDGPU::VM_VSRC:
92 return VmVsrcMax;
93 default:
94 return 0;
95 }
96}
97
98#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
99void Waitcnt::dump() const { dbgs() << *this << '\n'; }
100#endif
101
102Waitcnt decodeWaitcnt(const IsaVersion &Version, unsigned Encoded) {
103 Waitcnt Decoded;
104 Decoded.set(LOAD_CNT, decodeVmcnt(Version, Encoded));
105 Decoded.set(EXP_CNT, decodeExpcnt(Version, Encoded));
106 Decoded.set(DS_CNT, decodeLgkmcnt(Version, Encoded));
107 return Decoded;
108}
109
110unsigned encodeWaitcnt(const IsaVersion &Version, const Waitcnt &Decoded) {
111 return encodeWaitcnt(Version, Decoded.get(LOAD_CNT), Decoded.get(EXP_CNT),
112 Decoded.get(DS_CNT));
113}
114
115Waitcnt decodeLoadcntDscnt(const IsaVersion &Version, unsigned LoadcntDscnt) {
116 Waitcnt Decoded;
117 Decoded.set(LOAD_CNT, decodeLoadcnt(Version, LoadcntDscnt));
118 Decoded.set(DS_CNT, decodeDscnt(Version, LoadcntDscnt));
119 return Decoded;
120}
121
122Waitcnt decodeStorecntDscnt(const IsaVersion &Version, unsigned StorecntDscnt) {
123 Waitcnt Decoded;
124 Decoded.set(STORE_CNT, decodeStorecnt(Version, StorecntDscnt));
125 Decoded.set(DS_CNT, decodeDscnt(Version, StorecntDscnt));
126 return Decoded;
127}
128
129unsigned encodeLoadcntDscnt(const IsaVersion &Version, const Waitcnt &Decoded) {
130 return encodeLoadcntDscnt(Version, Decoded.get(LOAD_CNT),
131 Decoded.get(DS_CNT));
132}
133
135 const Waitcnt &Decoded) {
136 return encodeStorecntDscnt(Version, Decoded.get(STORE_CNT),
137 Decoded.get(DS_CNT));
138}
139
140std::optional<AMDGPU::InstCounterType> counterTypeForInstr(unsigned Opcode) {
141 switch (Opcode) {
142 case AMDGPU::S_WAIT_LOADCNT:
143 return AMDGPU::LOAD_CNT;
144 case AMDGPU::S_WAIT_EXPCNT:
145 return AMDGPU::EXP_CNT;
146 case AMDGPU::S_WAIT_STORECNT:
147 return AMDGPU::STORE_CNT;
148 case AMDGPU::S_WAIT_SAMPLECNT:
149 return AMDGPU::SAMPLE_CNT;
150 case AMDGPU::S_WAIT_BVHCNT:
151 return AMDGPU::BVH_CNT;
152 case AMDGPU::S_WAIT_DSCNT:
153 return AMDGPU::DS_CNT;
154 case AMDGPU::S_WAIT_KMCNT:
155 return AMDGPU::KM_CNT;
156 case AMDGPU::S_WAIT_XCNT:
157 return AMDGPU::X_CNT;
158 case AMDGPU::S_WAIT_ASYNCCNT:
159 return AMDGPU::ASYNC_CNT;
160 case AMDGPU::S_WAIT_TENSORCNT:
161 return AMDGPU::TENSOR_CNT;
162 default:
163 return {};
164 }
165}
166
167} // namespace llvm::AMDGPU
Provides AMDGPU specific target descriptions.
#define T
static const uint32_t IV[8]
Definition blake3_impl.h:83
Represents the counter values to wait for in an s_waitcnt instruction.
LLVM_DUMP_METHOD void dump() const
unsigned get(InstCounterType T) const
void set(InstCounterType T, unsigned Val)
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
Definition StringRef.h:888
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
iota_range< InstCounterType > inst_counter_types(InstCounterType MaxCounter)
unsigned encodeLoadcntDscnt(const IsaVersion &Version, const Waitcnt &Decoded)
unsigned getStorecntBitMask(const IsaVersion &Version)
unsigned getAsynccntBitMask(const IsaVersion &Version)
Waitcnt decodeWaitcnt(const IsaVersion &Version, unsigned Encoded)
unsigned encodeWaitcnt(const IsaVersion &Version, const Waitcnt &Decoded)
unsigned decodeLgkmcnt(const IsaVersion &Version, unsigned Waitcnt)
unsigned getSamplecntBitMask(const IsaVersion &Version)
unsigned getKmcntBitMask(const IsaVersion &Version)
unsigned getVmcntBitMask(const IsaVersion &Version)
unsigned getXcntBitMask(const IsaVersion &Version)
Waitcnt decodeStorecntDscnt(const IsaVersion &Version, unsigned StorecntDscnt)
unsigned getLgkmcntBitMask(const IsaVersion &Version)
unsigned getBvhcntBitMask(const IsaVersion &Version)
unsigned decodeDscnt(const IsaVersion &Version, unsigned Waitcnt)
unsigned getExpcntBitMask(const IsaVersion &Version)
std::optional< AMDGPU::InstCounterType > counterTypeForInstr(unsigned Opcode)
Determine if MI is a gfx12+ single-counter S_WAIT_*CNT instruction, and if so, which counter it is wa...
StringLiteral getInstCounterName(InstCounterType T)
unsigned decodeExpcnt(const IsaVersion &Version, unsigned Waitcnt)
Waitcnt decodeLoadcntDscnt(const IsaVersion &Version, unsigned LoadcntDscnt)
unsigned encodeStorecntDscnt(const IsaVersion &Version, const Waitcnt &Decoded)
unsigned decodeStorecnt(const IsaVersion &Version, unsigned Waitcnt)
unsigned decodeVmcnt(const IsaVersion &Version, unsigned Waitcnt)
unsigned getLoadcntBitMask(const IsaVersion &Version)
unsigned decodeLoadcnt(const IsaVersion &Version, unsigned Waitcnt)
unsigned getDscntBitMask(const IsaVersion &Version)
auto enum_seq(EnumT Begin, EnumT End)
Iterate over an enum type from Begin up to - but not including - End.
Definition Sequence.h:337
FunctionAddr VTableAddr uintptr_t uintptr_t Version
Definition InstrProf.h:334
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
unsigned get(InstCounterType T) const
Instruction set architecture version.