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
10#include "GCNSubtarget.h"
13#include "llvm/IR/Function.h"
15
16namespace llvm::AMDGPU {
17
19 "amdgpu-expert-scheduling-mode",
20 cl::desc("Enable expert scheduling mode 2 for all functions (GFX12+ only)"),
21 cl::init(false), cl::Hidden);
22
24 return ST.hasExpertSchedulingMode() &&
25 (ExpertSchedulingModeFlag.getNumOccurrences()
27 : F.getFnAttribute("amdgpu-expert-scheduling-mode")
28 .getValueAsBool());
29}
30
34
36 switch (T) {
37 case LOAD_CNT:
38 return "LOAD_CNT";
39 case DS_CNT:
40 return "DS_CNT";
41 case EXP_CNT:
42 return "EXP_CNT";
43 case STORE_CNT:
44 return "STORE_CNT";
45 case SAMPLE_CNT:
46 return "SAMPLE_CNT";
47 case BVH_CNT:
48 return "BVH_CNT";
49 case KM_CNT:
50 return "KM_CNT";
51 case X_CNT:
52 return "X_CNT";
53 case ASYNC_CNT:
54 return "ASYNC_CNT";
55 case TENSOR_CNT:
56 return "TENSOR_CNT";
57 case VA_VDST_RD:
58 return "VA_VDST_RD";
59 case VA_VDST_WR:
60 return "VA_VDST_WR";
61 case VM_VSRC:
62 return "VM_VSRC";
63 case NUM_INST_CNTS:
64 return "NUM_INST_CNTS";
65 }
66 llvm_unreachable("Unhandled InstCounterType");
67}
68
88
90 switch (T) {
92 return LoadcntMax;
93 case AMDGPU::DS_CNT:
94 return DscntMax;
95 case AMDGPU::EXP_CNT:
96 return ExpcntMax;
98 return StorecntMax;
100 return SamplecntMax;
101 case AMDGPU::BVH_CNT:
102 return BvhcntMax;
103 case AMDGPU::KM_CNT:
104 return KmcntMax;
105 case AMDGPU::X_CNT:
106 return XcntMax;
109 return VaVdstMax;
110 case AMDGPU::VM_VSRC:
111 return VmVsrcMax;
112 default:
113 return 0;
114 }
115}
116
117#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
118void Waitcnt::dump() const { dbgs() << *this << '\n'; }
119#endif
120
121Waitcnt decodeWaitcnt(const IsaVersion &Version, unsigned Encoded) {
122 Waitcnt Decoded;
123 Decoded.set(LOAD_CNT, decodeVmcnt(Version, Encoded));
124 Decoded.set(EXP_CNT, decodeExpcnt(Version, Encoded));
125 Decoded.set(DS_CNT, decodeLgkmcnt(Version, Encoded));
126 return Decoded;
127}
128
129unsigned encodeWaitcnt(const IsaVersion &Version, const Waitcnt &Decoded) {
130 return encodeWaitcnt(Version, Decoded.get(LOAD_CNT), Decoded.get(EXP_CNT),
131 Decoded.get(DS_CNT));
132}
133
134Waitcnt decodeLoadcntDscnt(const IsaVersion &Version, unsigned LoadcntDscnt) {
135 Waitcnt Decoded;
136 Decoded.set(LOAD_CNT, decodeLoadcnt(Version, LoadcntDscnt));
137 Decoded.set(DS_CNT, decodeDscnt(Version, LoadcntDscnt));
138 return Decoded;
139}
140
141Waitcnt decodeStorecntDscnt(const IsaVersion &Version, unsigned StorecntDscnt) {
142 Waitcnt Decoded;
143 Decoded.set(STORE_CNT, decodeStorecnt(Version, StorecntDscnt));
144 Decoded.set(DS_CNT, decodeDscnt(Version, StorecntDscnt));
145 return Decoded;
146}
147
148unsigned encodeLoadcntDscnt(const IsaVersion &Version, const Waitcnt &Decoded) {
149 return encodeLoadcntDscnt(Version, Decoded.get(LOAD_CNT),
150 Decoded.get(DS_CNT));
151}
152
154 const Waitcnt &Decoded) {
155 return encodeStorecntDscnt(Version, Decoded.get(STORE_CNT),
156 Decoded.get(DS_CNT));
157}
158
159std::optional<AMDGPU::InstCounterType> counterTypeForInstr(unsigned Opcode) {
160 switch (Opcode) {
161 case AMDGPU::S_WAIT_LOADCNT:
162 return AMDGPU::LOAD_CNT;
163 case AMDGPU::S_WAIT_EXPCNT:
164 return AMDGPU::EXP_CNT;
165 case AMDGPU::S_WAIT_STORECNT:
166 return AMDGPU::STORE_CNT;
167 case AMDGPU::S_WAIT_SAMPLECNT:
168 return AMDGPU::SAMPLE_CNT;
169 case AMDGPU::S_WAIT_BVHCNT:
170 return AMDGPU::BVH_CNT;
171 case AMDGPU::S_WAIT_DSCNT:
172 return AMDGPU::DS_CNT;
173 case AMDGPU::S_WAIT_KMCNT:
174 return AMDGPU::KM_CNT;
175 case AMDGPU::S_WAIT_XCNT:
176 return AMDGPU::X_CNT;
177 case AMDGPU::S_WAIT_ASYNCCNT:
178 return AMDGPU::ASYNC_CNT;
179 case AMDGPU::S_WAIT_TENSORCNT:
180 return AMDGPU::TENSOR_CNT;
181 default:
182 return {};
183 }
184}
185
186} // namespace llvm::AMDGPU
Provides AMDGPU specific target descriptions.
AMD GCN specific subclass of TargetSubtarget.
#define F(x, y, z)
Definition MD5.cpp:54
#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)
static cl::opt< bool > ExpertSchedulingModeFlag("amdgpu-expert-scheduling-mode", cl::desc("Enable expert scheduling mode 2 for all functions (GFX12+ only)"), cl::init(false), cl::Hidden)
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)
bool isExpertSchedulingMode(const GCNSubtarget &ST, const Function &F)
Return whether expert scheduling mode is available and enabled for F.
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)
initializer< Ty > init(const Ty &Val)
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.