LLVM 24.0.0git
AMDGPUTargetParser.h
Go to the documentation of this file.
1//===-- AMDGPUTargetParser - Parser for AMDGPU features ---------*- 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// This file implements a target parser to recognise AMDGPU hardware features.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_TARGETPARSER_AMDGPUTARGETPARSER_H
14#define LLVM_TARGETPARSER_AMDGPUTARGETPARSER_H
15
16#include "llvm/ADT/Bitset.h"
17#include "llvm/ADT/StringMap.h"
18#include "llvm/ADT/StringRef.h"
21#include <cstdint>
22#include <optional>
23#include <string>
24#include <utility>
25
26namespace llvm {
27
28class raw_ostream;
29template <typename T> class SmallVectorImpl;
30class Triple;
31
32namespace AMDGPU {
33
34/// GPU kinds supported by the AMDGPU target.
36 // Not specified processor.
38
39#define GET_R600_GPU_ENUM
40#include "llvm/TargetParser/R600TargetParserDef.inc"
41
42#define GET_AMDGPU_GPU_ENUM
43#include "llvm/TargetParser/AMDGPUTargetParserDef.inc"
44};
45
46/// One enumerator per frontend-visible feature bit; NUM_FEATURES is the count.
47enum AMDGPUFeature : unsigned {
48#define GET_AMDGPU_FEATURE_ENUM
49#include "llvm/TargetParser/AMDGPUTargetParserDef.inc"
50};
51
53
54/// Instruction set architecture version.
55struct IsaVersion {
59
60 bool operator==(const IsaVersion &Other) const {
61 return Major == Other.Major && Minor == Other.Minor &&
62 Stepping == Other.Stepping;
63 }
64 bool operator!=(const IsaVersion &Other) const { return !(*this == Other); }
65};
66
67// This isn't comprehensive for now, just things that are needed from the
68// frontend driver.
71
72 // Has fma instructions.
74};
75
76// GFX6+ features. This isn't comprehensive for now, just things that are needed
77// from the frontend driver.
80
81 // Common features.
84
85 // Wavefront 32 is available.
87
88 // Xnack is available.
89 FEATURE_XNACK = 1 << 3,
90
91 // Sram-ecc is available.
93
94 // WGP mode is supported.
95 FEATURE_WGP = 1 << 5,
96
97 // Xnack on/off modes are supported.
99
100 // VI SGPR initialization bug requiring a fixed SGPR allocation size.
102};
103
109
111
112/// The canonical GPU name for a variant name.
114
117
118/// Return true if subarch \p A is compatible with subarch \p B, i.e. they are
119/// equal or one is the major-family subarch of the other (e.g. AMDGPUSubArch9
120/// is compatible with AMDGPUSubArch900). NoSubArch is compatible with anything.
121LLVM_ABI bool isSubArchCompatible(const Triple &A, const Triple &B);
123
124/// Return true if the GPU \p AK is usable with the triple subarch \p SubArch.
125/// A NoSubArch triple (legacy "amdgcn") accepts any GPU. Otherwise the GPU's
126/// subarch must equal \p SubArch, or \p SubArch must be the major-family
127/// subarch of the GPU (e.g. the amdgpu9 triple accepts gfx900).
128LLVM_ABI bool isCPUValidForSubArch(Triple::SubArchType SubArch, GPUKind AK);
129
130/// Convenience overload of isCPUValidForSubArch taking a GPU name \p CPU, which
131/// is parsed via parseArchAMDGCN. An unrecognized name is never valid.
133
134/// Return true if \p AK is a pseudo target (e.g. "generic"/"generic-hsa"): a
135/// recognized AMDGCN GPU that represents no concrete hardware and has no
136/// subarch of its own. Such targets are resolved by the backend as a default
137/// device but are not valid as an explicit -mcpu.
138LLVM_ABI bool isPseudoTarget(GPUKind AK);
139
140/// Convenience overload of isPseudoTarget taking a GPU name \p CPU, which is
141/// parsed via parseArchAMDGCN.
143
144/// Returns the effective triple appropriate to use when linking \p B into \p A
145/// by merging the subarches in case of inexact match.
146///
147/// In cases where isSubArchCompatible would return / false, returns \p B. This
148/// assumes that the non-arch triple components are the same
149LLVM_ABI std::string mergeSubArch(const Triple &A, const Triple &B);
150
153
154/// Returns the canonical GPU name for an AMDGPU subarch, e.g.
155/// AMDGPUSubArch1030 -> "gfx1030", AMDGPUSubArch9 -> "gfx9-generic",
156/// AMDGPUSubArch6 -> "gfx600". Returns "" for NoSubArch or a non-AMDGPU
157/// subarch. The major-only subarches map to their generic/lowest
158/// representative, matching the default subtarget for an unspecified -mcpu.
160
161/// Returns the triple subarch name for an AMDGPU subarch, e.g.
162/// AMDGPUSubArch900 -> "amdgpu9.00". Returns "amdgpu" for NoSubArch.
166LLVM_ABI GPUKind parseArchR600(StringRef CPU);
168/// \deprecated Use getFeatureBitset and test the relevant FEAT_* bits instead.
169/// The legacy ArchFeatureKind bitfield is being removed.
170LLVM_DEPRECATED("use getFeatureBitset instead", "getFeatureBitset")
171LLVM_ABI unsigned getArchAttrAMDGCN(GPUKind AK);
172LLVM_DEPRECATED("use getFeatureBitset instead", "getFeatureBitset")
173LLVM_ABI unsigned getArchAttrAMDGCN(Triple::SubArchType SubArch);
175
176/// Returns \p AK's feature bitset, or an empty bitset if unknown.
178
179/// Appends the feature name of each bit set in \p Features to \p Names.
181 SmallVectorImpl<StringRef> &Names);
182
183/// Append the valid AMDGCN GPU names to \p Values. If \p SubArch is not
184/// NoSubArch, only GPUs compatible with that subarch (see isCPUValidForSubArch)
185/// are appended.
186LLVM_ABI void
188 Triple::SubArchType SubArch = Triple::NoSubArch);
190
191LLVM_ABI IsaVersion getIsaVersion(StringRef GPU);
192LLVM_ABI IsaVersion getIsaVersion(Triple::SubArchType SubArch);
193
195
196LLVM_ABI unsigned getTotalNumSGPRs(GPUKind AK);
198
199LLVM_ABI unsigned getAddressableNumSGPRs(GPUKind AK);
201
202LLVM_ABI unsigned getSGPRAllocGranule(GPUKind AK);
204
205/// \returns Maximum LDS in bytes a single work-group can address. This is a
206/// fixed hardware cap and does not depend on how many SIMDs a work-group runs
207/// on.
209LLVM_ABI unsigned
211
212/// \returns Number of SIMDs a work-group's waves run on. All four SIMDs of the
213/// functional block in full-SIMD mode, half of them otherwise.
214constexpr unsigned getNumWorkGroupSIMDs(bool FullSIMDMode) {
215 return FullSIMDMode ? 4 : 2;
216}
217
218/// \returns Minimum number of waves per execution unit.
219constexpr unsigned getMinWavesPerEU() { return 1; }
220
221/// \returns Maximum number of waves per execution unit without any kind of
222/// limitation.
223LLVM_ABI unsigned getMaxWavesPerEU(GPUKind AK);
225
226/// Fills Features map with default values for given target GPU.
227/// \p Features contains overriding target features and this function returns
228/// default target features with entries overridden by \p Features.
229LLVM_ABI std::pair<FeatureError, StringRef>
231
233
235private:
236 GPUKind Arch;
237 std::string TargetTripleString;
238 TargetIDSetting XnackSetting;
239 TargetIDSetting SramEccSetting;
240 bool IsAMDHSA;
241
242public:
243 TargetID(GPUKind Arch, const Triple &TT, TargetIDSetting XnackSetting,
244 TargetIDSetting SramEccSetting);
245
246 /// Construct a TargetID from a triple \p TT and the processor+features string
247 /// e.g. "gfx90a", "gfx90a:xnack+:sramecc-", "".
248 TargetID(const Triple &TT, StringRef TargetIDStr);
249
250 ~TargetID() = default;
251
252 /// \return True if the current xnack setting is not "Unsupported".
253 bool isXnackSupported() const {
254 return XnackSetting != TargetIDSetting::Unsupported;
255 }
256
257 /// \returns True if the current xnack setting is "On" or "Any".
258 bool isXnackOnOrAny() const {
259 return XnackSetting == TargetIDSetting::On ||
260 XnackSetting == TargetIDSetting::Any;
261 }
262
263 /// \returns True if current xnack setting is "On" or "Off",
264 /// false otherwise.
265 bool isXnackOnOrOff() const {
266 return getXnackSetting() == TargetIDSetting::On ||
267 getXnackSetting() == TargetIDSetting::Off;
268 }
269
270 /// \returns The current xnack TargetIDSetting, possible options are
271 /// "Unsupported", "Any", "Off", and "On".
272 TargetIDSetting getXnackSetting() const { return XnackSetting; }
273
274 /// Sets xnack setting to \p NewXnackSetting.
275 void setXnackSetting(TargetIDSetting NewXnackSetting) {
276 XnackSetting = NewXnackSetting;
277 }
278
279 /// \return True if the current sramecc setting is not "Unsupported".
280 bool isSramEccSupported() const {
281 return SramEccSetting != TargetIDSetting::Unsupported;
282 }
283
284 /// \returns True if the current sramecc setting is "On" or "Any".
285 bool isSramEccOnOrAny() const {
286 return SramEccSetting == TargetIDSetting::On ||
287 SramEccSetting == TargetIDSetting::Any;
288 }
289
290 /// \returns True if current sramecc setting is "On" or "Off",
291 /// false otherwise.
292 bool isSramEccOnOrOff() const {
293 return getSramEccSetting() == TargetIDSetting::On ||
294 getSramEccSetting() == TargetIDSetting::Off;
295 }
296
297 /// \returns The current sramecc TargetIDSetting, possible options are
298 /// "Unsupported", "Any", "Off", and "On".
299 TargetIDSetting getSramEccSetting() const { return SramEccSetting; }
300
301 /// Sets sramecc setting to \p NewSramEccSetting.
302 void setSramEccSetting(TargetIDSetting NewSramEccSetting) {
303 SramEccSetting = NewSramEccSetting;
304 }
305
306 GPUKind getGPUKind() const { return Arch; }
307
308 StringRef getTargetTripleString() const { return TargetTripleString; }
309
310 /// \returns True if this is an AMDHSA target.
311 bool isAMDHSA() const { return IsAMDHSA; }
312
313 /// Parse and validate a TargetID for triple \p TT from the processor+features
314 /// string \p ProcAndFeatures (e.g. "gfx90a", "gfx90a:xnack+:sramecc-", "").
315 /// Returns std::nullopt if the triple is not AMDGCN, the processor is
316 /// unrecognized, or a feature modifier is invalid for the processor.
317 static std::optional<TargetID> parse(const Triple &TT,
318 StringRef ProcAndFeatures);
319
320 /// Parse and validate a TargetID from a full
321 /// "<triple>-<processor>:<features>" directive string.
322 static std::optional<TargetID>
323 parseTargetIDString(StringRef TargetIDDirective);
324
325 /// Returns true if \p Other denotes the same target as *this, i.e. the same
326 /// processor and xnack/sramecc settings on a compatible triple. This is a
327 /// semantic equality that looks through spelling differences.
328 bool isEquivalent(const TargetID &Other) const;
329
330 /// Returns true if a device image for *this can provide the device code for a
331 /// request for \p Other. This is directional and models logical-linking
332 /// compatibility.
333 bool providesFor(const TargetID &Other) const;
334
335 void print(raw_ostream &OS) const;
336
337 std::string toString() const;
338
339 /// Print the canonical processor name followed by any explicit xnack and
340 /// sramecc feature modifiers (e.g. "gfx908:sramecc-:xnack+"), without the
341 /// triple prefix.
342 void printCanonicalTargetIDString(raw_ostream &OS) const;
343
344 /// \returns the canonical processor name followed by any explicit xnack and
345 /// sramecc feature modifiers order (e.g. "gfx908:sramecc-:xnack+"), without
346 /// the triple prefix.
347 std::string getCanonicalFeatureString() const;
348
349 bool operator==(const TargetID &Other) const;
350 bool operator!=(const TargetID &Other) const { return !(*this == Other); }
351};
352
354 TargetID.print(OS);
355 return OS;
356}
357
358} // namespace AMDGPU
359
360} // namespace llvm
361
362#endif
aarch64 promote const
This file defines the StringMap class.
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_DEPRECATED(MSG, FIX)
Definition Compiler.h:260
#define LLVM_ABI
Definition Compiler.h:215
static llvm::Error parse(GsymDataExtractor &Data, uint64_t BaseAddr, LineEntryCallback const &Callback)
Definition LineTable.cpp:54
static const char * toString(MIToken::TokenKind TokenKind)
Definition MIParser.cpp:630
bool operator==(const MergedFunctionsInfo &LHS, const MergedFunctionsInfo &RHS)
#define T
void setSramEccSetting(TargetIDSetting NewSramEccSetting)
Sets sramecc setting to NewSramEccSetting.
void print(raw_ostream &OS) const
TargetIDSetting getXnackSetting() const
bool operator!=(const TargetID &Other) const
StringRef getTargetTripleString() const
TargetID(GPUKind Arch, const Triple &TT, TargetIDSetting XnackSetting, TargetIDSetting SramEccSetting)
void setXnackSetting(TargetIDSetting NewXnackSetting)
Sets xnack setting to NewXnackSetting.
TargetIDSetting getSramEccSetting() const
This is a constexpr reimplementation of a subset of std::bitset.
Definition Bitset.h:30
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition StringMap.h:128
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
LLVM_ABI StringRef getArchNameR600(GPUKind AK)
LLVM_ABI void fillValidArchListAMDGCN(SmallVectorImpl< StringRef > &Values, Triple::SubArchType SubArch=Triple::NoSubArch)
Append the valid AMDGCN GPU names to Values.
LLVM_ABI unsigned getMaxWavesPerEU(GPUKind AK)
LLVM_ABI StringRef getCanonicalArchName(const Triple &T, StringRef Arch)
LLVM_ABI StringRef getBaseArchNameAMDGCN(GPUKind AK)
The canonical GPU name for a variant name.
LLVM_ABI void fillValidArchListR600(SmallVectorImpl< StringRef > &Values)
constexpr unsigned getNumWorkGroupSIMDs(bool FullSIMDMode)
LLVM_ABI R600FeatureKind getArchAttrR600(GPUKind AK)
LLVM_ABI std::string mergeSubArch(const Triple &A, const Triple &B)
Returns the effective triple appropriate to use when linking B into A by merging the subarches in cas...
LLVM_ABI bool isCPUValidForSubArch(Triple::SubArchType SubArch, GPUKind AK)
Return true if the GPU AK is usable with the triple subarch SubArch.
LLVM_ABI bool isSubArchCompatible(const Triple &A, const Triple &B)
Return true if subarch A is compatible with subarch B, i.e.
LLVM_ABI unsigned getMaxHWAddressableLocalMemorySize(GPUKind AK)
LLVM_ABI StringRef getArchFamilyNameAMDGCN(GPUKind AK)
LLVM_ABI StringRef getSubArchName(Triple::SubArchType SubArch)
Returns the triple subarch name for an AMDGPU subarch, e.g.
LLVM_ABI unsigned getAddressableNumSGPRs(GPUKind AK)
LLVM_ABI IsaVersion getIsaVersion(StringRef GPU)
LLVM_ABI unsigned getTotalNumSGPRs(GPUKind AK)
GPUKind
GPU kinds supported by the AMDGPU target.
Bitset< NUM_FEATURES > AMDGPUFeatureBitset
LLVM_ABI unsigned getSGPRAllocGranule(GPUKind AK)
LLVM_ABI Triple::SubArchType getSubArch(GPUKind AK)
LLVM_ABI StringRef getArchNameFromSubArch(Triple::SubArchType SubArch)
Returns the canonical GPU name for an AMDGPU subarch, e.g.
constexpr unsigned getMinWavesPerEU()
LLVM_ABI GPUKind parseArchAMDGCN(StringRef CPU)
AMDGPUFeature
One enumerator per frontend-visible feature bit; NUM_FEATURES is the count.
raw_ostream & operator<<(raw_ostream &OS, const TargetID &TargetID)
LLVM_ABI bool isPseudoTarget(GPUKind AK)
Return true if AK is a pseudo target (e.g.
LLVM_ABI GPUKind getGPUKindFromSubArch(Triple::SubArchType SubArch)
LLVM_ABI std::pair< FeatureError, StringRef > fillAMDGPUFeatureMap(StringRef GPU, const Triple &T, StringMap< bool > &Features)
Fills Features map with default values for given target GPU.
LLVM_ABI void getFeatureNames(const AMDGPUFeatureBitset &Features, SmallVectorImpl< StringRef > &Names)
Appends the feature name of each bit set in Features to Names.
LLVM_ABI StringRef getArchNameAMDGCN(GPUKind AK)
LLVM_ABI unsigned getArchAttrAMDGCN(GPUKind AK)
LLVM_ABI Triple::SubArchType getMajorSubArch(Triple::SubArchType SubArch)
LLVM_ABI const AMDGPUFeatureBitset & getFeatureBitset(GPUKind AK)
Returns AK's feature bitset, or an empty bitset if unknown.
LLVM_ABI GPUKind parseArchR600(StringRef CPU)
This is an optimization pass for GlobalISel generic memory operations.
RelativeUniformCounterPtr Values
Definition InstrProf.h:91
Instruction set architecture version.
bool operator==(const IsaVersion &Other) const
bool operator!=(const IsaVersion &Other) const