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/StringMap.h"
17#include "llvm/ADT/StringRef.h"
20#include <cstdint>
21#include <optional>
22#include <string>
23#include <utility>
24
25namespace llvm {
26
27class raw_ostream;
28template <typename T> class SmallVectorImpl;
29class Triple;
30
31namespace AMDGPU {
32
33/// GPU kinds supported by the AMDGPU target.
35 // Not specified processor.
37
38#define R600_GPU(NAME, ENUM, FEATURES) ENUM,
39#define AMDGCN_GPU(NAME, ENUM, SUBARCH, ISAVERSION, FEATURES) ENUM,
40#include "AMDGPUTargetParser.def"
41
42 GK_AMDGCN_GENERIC_FIRST = GK_GFX9_GENERIC,
43 GK_AMDGCN_GENERIC_LAST = GK_GFX13_GENERIC,
44};
45
46/// Instruction set architecture version.
47struct IsaVersion {
48 unsigned Major;
49 unsigned Minor;
50 unsigned Stepping;
51
52 bool operator==(const IsaVersion &Other) const {
53 return Major == Other.Major && Minor == Other.Minor &&
54 Stepping == Other.Stepping;
55 }
56 bool operator!=(const IsaVersion &Other) const { return !(*this == Other); }
57};
59// This isn't comprehensive for now, just things that are needed from the
60// frontend driver.
63
64 // These features only exist for r600, and are implied true for amdgcn.
65 FEATURE_FMA = 1 << 1,
66 FEATURE_LDEXP = 1 << 2,
67 FEATURE_FP64 = 1 << 3,
68
69 // Common features.
72
73 // Wavefront 32 is available.
75
76 // Xnack is available.
77 FEATURE_XNACK = 1 << 7,
78
79 // Sram-ecc is available.
81
82 // WGP mode is supported.
83 FEATURE_WGP = 1 << 9,
84
85 // Xnack on/off modes are supported.
87
88 // VI SGPR initialization bug requiring a fixed SGPR allocation size.
90};
91
97
101
102/// Return true if subarch \p A is compatible with subarch \p B, i.e. they are
103/// equal or one is the major-family subarch of the other (e.g. AMDGPUSubArch9
104/// is compatible with AMDGPUSubArch900). NoSubArch is compatible with anything.
105LLVM_ABI bool isSubArchCompatible(const Triple &A, const Triple &B);
107
108/// Return true if the GPU \p AK is usable with the triple subarch \p SubArch.
109/// A NoSubArch triple (legacy "amdgcn") accepts any GPU. Otherwise the GPU's
110/// subarch must equal \p SubArch, or \p SubArch must be the major-family
111/// subarch of the GPU (e.g. the amdgpu9 triple accepts gfx900).
113
114/// Convenience overload of isCPUValidForSubArch taking a GPU name \p CPU, which
115/// is parsed via parseArchAMDGCN. An unrecognized name is never valid.
116LLVM_ABI bool isCPUValidForSubArch(Triple::SubArchType SubArch, StringRef CPU);
117
118/// Returns the effective triple appropriate to use when linking \p B into \p A
119/// by merging the subarches in case of inexact match.
120///
121/// In cases where isSubArchCompatible would return / false, returns \p B. This
122/// assumes that the non-arch triple components are the same
123LLVM_ABI std::string mergeSubArch(const Triple &A, const Triple &B);
124
126LLVM_ABI StringRef getArchNameR600(GPUKind AK);
127
128/// Returns the canonical GPU name for an AMDGPU subarch, e.g.
129/// AMDGPUSubArch1030 -> "gfx1030", AMDGPUSubArch9 -> "gfx9-generic",
130/// AMDGPUSubArch6 -> "gfx600". Returns "" for NoSubArch or a non-AMDGPU
131/// subarch. The major-only subarches map to their generic/lowest
132/// representative, matching the default subtarget for an unspecified -mcpu.
134LLVM_ABI StringRef getCanonicalArchName(const Triple &T, StringRef Arch);
135LLVM_ABI GPUKind parseArchAMDGCN(StringRef CPU);
136LLVM_ABI GPUKind parseArchR600(StringRef CPU);
140LLVM_ABI unsigned getArchAttrR600(GPUKind AK);
141
142/// Append the valid AMDGCN GPU names to \p Values. If \p SubArch is not
143/// NoSubArch, only GPUs compatible with that subarch (see isCPUValidForSubArch)
144/// are appended.
145LLVM_ABI void
146fillValidArchListAMDGCN(SmallVectorImpl<StringRef> &Values,
148LLVM_ABI void fillValidArchListR600(SmallVectorImpl<StringRef> &Values);
149
150LLVM_ABI IsaVersion getIsaVersion(StringRef GPU);
152
154
155LLVM_ABI unsigned getTotalNumSGPRs(GPUKind AK);
157
158LLVM_ABI unsigned getAddressableNumSGPRs(GPUKind AK);
160
161LLVM_ABI unsigned getSGPRAllocGranule(GPUKind AK);
163
164/// Fills Features map with default values for given target GPU.
165/// \p Features contains overriding target features and this function returns
166/// default target features with entries overridden by \p Features.
167LLVM_ABI std::pair<FeatureError, StringRef>
169
171
173private:
174 GPUKind Arch;
175 std::string TargetTripleString;
176 TargetIDSetting XnackSetting;
177 TargetIDSetting SramEccSetting;
178 bool IsAMDHSA;
179
180public:
181 TargetID(GPUKind Arch, const Triple &TT, TargetIDSetting XnackSetting,
182 TargetIDSetting SramEccSetting);
183
184 /// Construct a TargetID from a triple \p TT and the processor+features string
185 /// e.g. "gfx90a", "gfx90a:xnack+:sramecc-", "".
186 TargetID(const Triple &TT, StringRef TargetIDStr);
187
188 ~TargetID() = default;
189
190 /// \return True if the current xnack setting is not "Unsupported".
191 bool isXnackSupported() const {
192 return XnackSetting != TargetIDSetting::Unsupported;
193 }
194
195 /// \returns True if the current xnack setting is "On" or "Any".
196 bool isXnackOnOrAny() const {
197 return XnackSetting == TargetIDSetting::On ||
198 XnackSetting == TargetIDSetting::Any;
200
201 /// \returns True if current xnack setting is "On" or "Off",
202 /// false otherwise.
203 bool isXnackOnOrOff() const {
204 return getXnackSetting() == TargetIDSetting::On ||
205 getXnackSetting() == TargetIDSetting::Off;
206 }
207
208 /// \returns The current xnack TargetIDSetting, possible options are
209 /// "Unsupported", "Any", "Off", and "On".
210 TargetIDSetting getXnackSetting() const { return XnackSetting; }
211
212 /// Sets xnack setting to \p NewXnackSetting.
213 void setXnackSetting(TargetIDSetting NewXnackSetting) {
214 XnackSetting = NewXnackSetting;
215 }
216
217 /// \return True if the current sramecc setting is not "Unsupported".
218 bool isSramEccSupported() const {
219 return SramEccSetting != TargetIDSetting::Unsupported;
220 }
221
222 /// \returns True if the current sramecc setting is "On" or "Any".
223 bool isSramEccOnOrAny() const {
224 return SramEccSetting == TargetIDSetting::On ||
225 SramEccSetting == TargetIDSetting::Any;
226 }
227
228 /// \returns True if current sramecc setting is "On" or "Off",
229 /// false otherwise.
230 bool isSramEccOnOrOff() const {
231 return getSramEccSetting() == TargetIDSetting::On ||
232 getSramEccSetting() == TargetIDSetting::Off;
233 }
234
235 /// \returns The current sramecc TargetIDSetting, possible options are
236 /// "Unsupported", "Any", "Off", and "On".
237 TargetIDSetting getSramEccSetting() const { return SramEccSetting; }
238
239 /// Sets sramecc setting to \p NewSramEccSetting.
240 void setSramEccSetting(TargetIDSetting NewSramEccSetting) {
241 SramEccSetting = NewSramEccSetting;
242 }
243
244 GPUKind getGPUKind() const { return Arch; }
245
246 StringRef getTargetTripleString() const { return TargetTripleString; }
247
248 /// \returns True if this is an AMDHSA target.
249 bool isAMDHSA() const { return IsAMDHSA; }
250
251 /// Parse and validate a TargetID for triple \p TT from the processor+features
252 /// string \p ProcAndFeatures (e.g. "gfx90a", "gfx90a:xnack+:sramecc-", "").
253 /// Returns std::nullopt if the triple is not AMDGCN, the processor is
254 /// unrecognized, or a feature modifier is invalid for the processor.
255 static std::optional<TargetID> parse(const Triple &TT,
256 StringRef ProcAndFeatures);
257
258 /// Parse and validate a TargetID from a full
259 /// "<triple>-<processor>:<features>" directive string.
260 static std::optional<TargetID>
261 parseTargetIDString(StringRef TargetIDDirective);
262
263 /// Returns true if \p Other denotes the same target as *this, i.e. the same
264 /// processor and xnack/sramecc settings on a compatible triple. This is a
265 /// semantic equality that looks through spelling differences.
266 bool isEquivalent(const TargetID &Other) const;
267
268 /// Returns true if a device image for *this can provide the device code for a
269 /// request for \p Other. This is directional and models logical-linking
270 /// compatibility.
271 bool providesFor(const TargetID &Other) const;
272
273 void print(raw_ostream &OS) const;
274
275 std::string toString() const;
276
277 /// Print the canonical processor name followed by any explicit xnack and
278 /// sramecc feature modifiers (e.g. "gfx908:sramecc-:xnack+"), without the
279 /// triple prefix.
280 void printCanonicalTargetIDString(raw_ostream &OS) const;
281
282 /// \returns the canonical processor name followed by any explicit xnack and
283 /// sramecc feature modifiers order (e.g. "gfx908:sramecc-:xnack+"), without
284 /// the triple prefix.
285 std::string getCanonicalFeatureString() const;
286
287 bool operator==(const TargetID &Other) const;
288 bool operator!=(const TargetID &Other) const { return !(*this == Other); }
289};
290
292 TargetID.print(OS);
293 return OS;
294}
295
296} // namespace AMDGPU
297
298} // namespace llvm
299
300#endif
This file defines the StringMap class.
static cl::opt< bool > XnackSetting("amdgpu-xnack", cl::desc("Force amdgpu.xnack value for testing"), cl::ReallyHidden)
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_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 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.
GPUKind
GPU kinds supported by the AMDGPU target.
LLVM_ABI StringRef getCanonicalArchName(const Triple &T, StringRef Arch)
LLVM_ABI void fillValidArchListR600(SmallVectorImpl< StringRef > &Values)
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 StringRef getArchFamilyNameAMDGCN(GPUKind AK)
LLVM_ABI unsigned getAddressableNumSGPRs(GPUKind AK)
LLVM_ABI IsaVersion getIsaVersion(StringRef GPU)
LLVM_ABI unsigned getTotalNumSGPRs(GPUKind AK)
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.
LLVM_ABI GPUKind parseArchAMDGCN(StringRef CPU)
raw_ostream & operator<<(raw_ostream &OS, const TargetID &TargetID)
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 StringRef getArchNameAMDGCN(GPUKind AK)
LLVM_ABI unsigned getArchAttrAMDGCN(GPUKind AK)
LLVM_ABI Triple::SubArchType getMajorSubArch(Triple::SubArchType SubArch)
LLVM_ABI unsigned getArchAttrR600(GPUKind AK)
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