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"
14
15namespace llvm::AMDGPU {
16
18 return ST.hasExpertSchedulingMode() &&
19 valueOr(ST.getCLOpts().expert_scheduling_mode,
20 F.getFnAttribute("amdgpu-expert-scheduling-mode")
21 .getValueAsBool());
22}
23
27
29 switch (T) {
30 case LOAD_CNT:
31 return "LOAD_CNT";
32 case DS_CNT:
33 return "DS_CNT";
34 case EXP_CNT:
35 return "EXP_CNT";
36 case STORE_CNT:
37 return "STORE_CNT";
38 case SAMPLE_CNT:
39 return "SAMPLE_CNT";
40 case BVH_CNT:
41 return "BVH_CNT";
42 case KM_CNT:
43 return "KM_CNT";
44 case X_CNT:
45 return "X_CNT";
46 case ASYNC_CNT:
47 return "ASYNC_CNT";
48 case TENSOR_CNT:
49 return "TENSOR_CNT";
50 case VA_VDST_RD:
51 return "VA_VDST_RD";
52 case VA_VDST_WR:
53 return "VA_VDST_WR";
54 case VM_VSRC:
55 return "VM_VSRC";
56 case NUM_INST_CNTS:
57 return "NUM_INST_CNTS";
58 }
59 llvm_unreachable("Unhandled InstCounterType");
60}
61
81
83 switch (T) {
85 return LoadcntMax;
86 case AMDGPU::DS_CNT:
87 return DscntMax;
88 case AMDGPU::EXP_CNT:
89 return ExpcntMax;
91 return StorecntMax;
93 return SamplecntMax;
94 case AMDGPU::BVH_CNT:
95 return BvhcntMax;
96 case AMDGPU::KM_CNT:
97 return KmcntMax;
98 case AMDGPU::X_CNT:
99 return XcntMax;
102 return VaVdstMax;
103 case AMDGPU::VM_VSRC:
104 return VmVsrcMax;
105 default:
106 return 0;
107 }
108}
109
110#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
111void Waitcnt::dump() const { dbgs() << *this << '\n'; }
112#endif
113
114Waitcnt decodeWaitcnt(const IsaVersion &Version, unsigned Encoded) {
115 Waitcnt Decoded;
116 Decoded.set(LOAD_CNT, decodeVmcnt(Version, Encoded));
117 Decoded.set(EXP_CNT, decodeExpcnt(Version, Encoded));
118 Decoded.set(DS_CNT, decodeLgkmcnt(Version, Encoded));
119 return Decoded;
120}
121
122unsigned encodeWaitcnt(const IsaVersion &Version, const Waitcnt &Decoded) {
123 return encodeWaitcnt(Version, Decoded.get(LOAD_CNT), Decoded.get(EXP_CNT),
124 Decoded.get(DS_CNT));
125}
126
127Waitcnt decodeLoadcntDscnt(const IsaVersion &Version, unsigned LoadcntDscnt) {
128 Waitcnt Decoded;
129 Decoded.set(LOAD_CNT, decodeLoadcnt(Version, LoadcntDscnt));
130 Decoded.set(DS_CNT, decodeDscnt(Version, LoadcntDscnt));
131 return Decoded;
132}
133
134Waitcnt decodeStorecntDscnt(const IsaVersion &Version, unsigned StorecntDscnt) {
135 Waitcnt Decoded;
136 Decoded.set(STORE_CNT, decodeStorecnt(Version, StorecntDscnt));
137 Decoded.set(DS_CNT, decodeDscnt(Version, StorecntDscnt));
138 return Decoded;
139}
140
141unsigned encodeLoadcntDscnt(const IsaVersion &Version, const Waitcnt &Decoded) {
142 return encodeLoadcntDscnt(Version, Decoded.get(LOAD_CNT),
143 Decoded.get(DS_CNT));
144}
145
147 const Waitcnt &Decoded) {
148 return encodeStorecntDscnt(Version, Decoded.get(STORE_CNT),
149 Decoded.get(DS_CNT));
150}
151
152std::optional<AMDGPU::InstCounterType> counterTypeForInstr(unsigned Opcode) {
153 switch (Opcode) {
154 case AMDGPU::S_WAIT_LOADCNT:
155 return AMDGPU::LOAD_CNT;
156 case AMDGPU::S_WAIT_EXPCNT:
157 return AMDGPU::EXP_CNT;
158 case AMDGPU::S_WAIT_STORECNT:
159 return AMDGPU::STORE_CNT;
160 case AMDGPU::S_WAIT_SAMPLECNT:
161 return AMDGPU::SAMPLE_CNT;
162 case AMDGPU::S_WAIT_BVHCNT:
163 return AMDGPU::BVH_CNT;
164 case AMDGPU::S_WAIT_DSCNT:
165 return AMDGPU::DS_CNT;
166 case AMDGPU::S_WAIT_KMCNT:
167 return AMDGPU::KM_CNT;
168 case AMDGPU::S_WAIT_XCNT:
169 return AMDGPU::X_CNT;
170 case AMDGPU::S_WAIT_ASYNCCNT:
171 return AMDGPU::ASYNC_CNT;
172 case AMDGPU::S_WAIT_TENSORCNT:
173 return AMDGPU::TENSOR_CNT;
174 default:
175 return {};
176 }
177}
178
179} // 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)
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)
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
constexpr bool valueOr(BoolOrDefault X, bool Default)
unsigned get(InstCounterType T) const
Instruction set architecture version.