LLVM 24.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_RD:
42 return "VA_VDST_RD";
43 case VA_VDST_WR:
44 return "VA_VDST_WR";
45 case VM_VSRC:
46 return "VM_VSRC";
47 case NUM_INST_CNTS:
48 return "NUM_INST_CNTS";
49 }
50 llvm_unreachable("Unhandled InstCounterType");
51}
52
72
74 switch (T) {
76 return LoadcntMax;
77 case AMDGPU::DS_CNT:
78 return DscntMax;
79 case AMDGPU::EXP_CNT:
80 return ExpcntMax;
82 return StorecntMax;
84 return SamplecntMax;
85 case AMDGPU::BVH_CNT:
86 return BvhcntMax;
87 case AMDGPU::KM_CNT:
88 return KmcntMax;
89 case AMDGPU::X_CNT:
90 return XcntMax;
93 return VaVdstMax;
94 case AMDGPU::VM_VSRC:
95 return VmVsrcMax;
96 default:
97 return 0;
98 }
99}
100
101#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
102void Waitcnt::dump() const { dbgs() << *this << '\n'; }
103#endif
104
105Waitcnt decodeWaitcnt(const IsaVersion &Version, unsigned Encoded) {
106 Waitcnt Decoded;
107 Decoded.set(LOAD_CNT, decodeVmcnt(Version, Encoded));
108 Decoded.set(EXP_CNT, decodeExpcnt(Version, Encoded));
109 Decoded.set(DS_CNT, decodeLgkmcnt(Version, Encoded));
110 return Decoded;
111}
112
113unsigned encodeWaitcnt(const IsaVersion &Version, const Waitcnt &Decoded) {
114 return encodeWaitcnt(Version, Decoded.get(LOAD_CNT), Decoded.get(EXP_CNT),
115 Decoded.get(DS_CNT));
116}
117
118Waitcnt decodeLoadcntDscnt(const IsaVersion &Version, unsigned LoadcntDscnt) {
119 Waitcnt Decoded;
120 Decoded.set(LOAD_CNT, decodeLoadcnt(Version, LoadcntDscnt));
121 Decoded.set(DS_CNT, decodeDscnt(Version, LoadcntDscnt));
122 return Decoded;
123}
124
125Waitcnt decodeStorecntDscnt(const IsaVersion &Version, unsigned StorecntDscnt) {
126 Waitcnt Decoded;
127 Decoded.set(STORE_CNT, decodeStorecnt(Version, StorecntDscnt));
128 Decoded.set(DS_CNT, decodeDscnt(Version, StorecntDscnt));
129 return Decoded;
130}
131
132unsigned encodeLoadcntDscnt(const IsaVersion &Version, const Waitcnt &Decoded) {
133 return encodeLoadcntDscnt(Version, Decoded.get(LOAD_CNT),
134 Decoded.get(DS_CNT));
135}
136
138 const Waitcnt &Decoded) {
139 return encodeStorecntDscnt(Version, Decoded.get(STORE_CNT),
140 Decoded.get(DS_CNT));
141}
142
143std::optional<AMDGPU::InstCounterType> counterTypeForInstr(unsigned Opcode) {
144 switch (Opcode) {
145 case AMDGPU::S_WAIT_LOADCNT:
146 return AMDGPU::LOAD_CNT;
147 case AMDGPU::S_WAIT_EXPCNT:
148 return AMDGPU::EXP_CNT;
149 case AMDGPU::S_WAIT_STORECNT:
150 return AMDGPU::STORE_CNT;
151 case AMDGPU::S_WAIT_SAMPLECNT:
152 return AMDGPU::SAMPLE_CNT;
153 case AMDGPU::S_WAIT_BVHCNT:
154 return AMDGPU::BVH_CNT;
155 case AMDGPU::S_WAIT_DSCNT:
156 return AMDGPU::DS_CNT;
157 case AMDGPU::S_WAIT_KMCNT:
158 return AMDGPU::KM_CNT;
159 case AMDGPU::S_WAIT_XCNT:
160 return AMDGPU::X_CNT;
161 case AMDGPU::S_WAIT_ASYNCCNT:
162 return AMDGPU::ASYNC_CNT;
163 case AMDGPU::S_WAIT_TENSORCNT:
164 return AMDGPU::TENSOR_CNT;
165 default:
166 return {};
167 }
168}
169
170} // 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)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
constexpr auto enum_seq(EnumT Begin, EnumT End)
Iterate over an enum type from Begin up to - but not including - End.
Definition Sequence.h:373
unsigned get(InstCounterType T) const
Instruction set architecture version.