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 GET_R600_GPU_ENUM
39#include "llvm/TargetParser/R600TargetParserDef.inc"
40
41#define GET_AMDGPU_GPU_ENUM
42#include "llvm/TargetParser/AMDGPUTargetParserDef.inc"
43};
44
45/// Instruction set architecture version.
46struct IsaVersion {
50
51 bool operator==(const IsaVersion &Other) const {
52 return Major == Other.Major && Minor == Other.Minor &&
53 Stepping == Other.Stepping;
54 }
55 bool operator!=(const IsaVersion &Other) const { return !(*this == Other); }
56};
57
58// This isn't comprehensive for now, just things that are needed from the
59// frontend driver.
62
63 // Has fma instructions.
65};
66
67// GFX6+ features. This isn't comprehensive for now, just things that are needed
68// from the frontend driver.
71
72 // Common features.
75
76 // Wavefront 32 is available.
78
79 // Xnack is available.
80 FEATURE_XNACK = 1 << 3,
81
82 // Sram-ecc is available.
84
85 // WGP mode is supported.
86 FEATURE_WGP = 1 << 5,
87
88 // Xnack on/off modes are supported.
90
91 // VI SGPR initialization bug requiring a fixed SGPR allocation size.
93};
94
100
104
105/// Return true if subarch \p A is compatible with subarch \p B, i.e. they are
106/// equal or one is the major-family subarch of the other (e.g. AMDGPUSubArch9
107/// is compatible with AMDGPUSubArch900). NoSubArch is compatible with anything.
108LLVM_ABI bool isSubArchCompatible(const Triple &A, const Triple &B);
110
111/// Return true if the GPU \p AK is usable with the triple subarch \p SubArch.
112/// A NoSubArch triple (legacy "amdgcn") accepts any GPU. Otherwise the GPU's
113/// subarch must equal \p SubArch, or \p SubArch must be the major-family
114/// subarch of the GPU (e.g. the amdgpu9 triple accepts gfx900).
115LLVM_ABI bool isCPUValidForSubArch(Triple::SubArchType SubArch, GPUKind AK);
116
117/// Convenience overload of isCPUValidForSubArch taking a GPU name \p CPU, which
118/// is parsed via parseArchAMDGCN. An unrecognized name is never valid.
120
121/// Return true if \p AK is a pseudo target (e.g. "generic"/"generic-hsa"): a
122/// recognized AMDGCN GPU that represents no concrete hardware and has no
123/// subarch of its own. Such targets are resolved by the backend as a default
124/// device but are not valid as an explicit -mcpu.
125LLVM_ABI bool isPseudoTarget(GPUKind AK);
126
127/// Convenience overload of isPseudoTarget taking a GPU name \p CPU, which is
128/// parsed via parseArchAMDGCN.
130
131/// Returns the effective triple appropriate to use when linking \p B into \p A
132/// by merging the subarches in case of inexact match.
133///
134/// In cases where isSubArchCompatible would return / false, returns \p B. This
135/// assumes that the non-arch triple components are the same
136LLVM_ABI std::string mergeSubArch(const Triple &A, const Triple &B);
137
140
141/// Returns the canonical GPU name for an AMDGPU subarch, e.g.
142/// AMDGPUSubArch1030 -> "gfx1030", AMDGPUSubArch9 -> "gfx9-generic",
143/// AMDGPUSubArch6 -> "gfx600". Returns "" for NoSubArch or a non-AMDGPU
144/// subarch. The major-only subarches map to their generic/lowest
145/// representative, matching the default subtarget for an unspecified -mcpu.
147
148/// Returns the triple subarch name for an AMDGPU subarch, e.g.
149/// AMDGPUSubArch900 -> "amdgpu9.00". Returns "amdgpu" for NoSubArch.
153LLVM_ABI GPUKind parseArchR600(StringRef CPU);
155LLVM_ABI unsigned getArchAttrAMDGCN(GPUKind AK);
158
159/// Append the valid AMDGCN GPU names to \p Values. If \p SubArch is not
160/// NoSubArch, only GPUs compatible with that subarch (see isCPUValidForSubArch)
161/// are appended.
162LLVM_ABI void
166
167LLVM_ABI IsaVersion getIsaVersion(StringRef GPU);
168LLVM_ABI IsaVersion getIsaVersion(Triple::SubArchType SubArch);
169
171
172LLVM_ABI unsigned getTotalNumSGPRs(GPUKind AK);
174
175LLVM_ABI unsigned getAddressableNumSGPRs(GPUKind AK);
177
178LLVM_ABI unsigned getSGPRAllocGranule(GPUKind AK);
180
181/// Fills Features map with default values for given target GPU.
182/// \p Features contains overriding target features and this function returns
183/// default target features with entries overridden by \p Features.
184LLVM_ABI std::pair<FeatureError, StringRef>
186
188
190private:
191 GPUKind Arch;
192 std::string TargetTripleString;
193 TargetIDSetting XnackSetting;
194 TargetIDSetting SramEccSetting;
195 bool IsAMDHSA;
196
197public:
198 TargetID(GPUKind Arch, const Triple &TT, TargetIDSetting XnackSetting,
199 TargetIDSetting SramEccSetting);
200
201 /// Construct a TargetID from a triple \p TT and the processor+features string
202 /// e.g. "gfx90a", "gfx90a:xnack+:sramecc-", "".
203 TargetID(const Triple &TT, StringRef TargetIDStr);
204
205 ~TargetID() = default;
206
207 /// \return True if the current xnack setting is not "Unsupported".
208 bool isXnackSupported() const {
209 return XnackSetting != TargetIDSetting::Unsupported;
210 }
211
212 /// \returns True if the current xnack setting is "On" or "Any".
213 bool isXnackOnOrAny() const {
214 return XnackSetting == TargetIDSetting::On ||
215 XnackSetting == TargetIDSetting::Any;
216 }
217
218 /// \returns True if current xnack setting is "On" or "Off",
219 /// false otherwise.
220 bool isXnackOnOrOff() const {
221 return getXnackSetting() == TargetIDSetting::On ||
222 getXnackSetting() == TargetIDSetting::Off;
223 }
224
225 /// \returns The current xnack TargetIDSetting, possible options are
226 /// "Unsupported", "Any", "Off", and "On".
227 TargetIDSetting getXnackSetting() const { return XnackSetting; }
228
229 /// Sets xnack setting to \p NewXnackSetting.
230 void setXnackSetting(TargetIDSetting NewXnackSetting) {
231 XnackSetting = NewXnackSetting;
232 }
233
234 /// \return True if the current sramecc setting is not "Unsupported".
235 bool isSramEccSupported() const {
236 return SramEccSetting != TargetIDSetting::Unsupported;
237 }
238
239 /// \returns True if the current sramecc setting is "On" or "Any".
240 bool isSramEccOnOrAny() const {
241 return SramEccSetting == TargetIDSetting::On ||
242 SramEccSetting == TargetIDSetting::Any;
243 }
244
245 /// \returns True if current sramecc setting is "On" or "Off",
246 /// false otherwise.
247 bool isSramEccOnOrOff() const {
248 return getSramEccSetting() == TargetIDSetting::On ||
249 getSramEccSetting() == TargetIDSetting::Off;
250 }
251
252 /// \returns The current sramecc TargetIDSetting, possible options are
253 /// "Unsupported", "Any", "Off", and "On".
254 TargetIDSetting getSramEccSetting() const { return SramEccSetting; }
255
256 /// Sets sramecc setting to \p NewSramEccSetting.
257 void setSramEccSetting(TargetIDSetting NewSramEccSetting) {
258 SramEccSetting = NewSramEccSetting;
259 }
260
261 GPUKind getGPUKind() const { return Arch; }
262
263 StringRef getTargetTripleString() const { return TargetTripleString; }
264
265 /// \returns True if this is an AMDHSA target.
266 bool isAMDHSA() const { return IsAMDHSA; }
267
268 /// Parse and validate a TargetID for triple \p TT from the processor+features
269 /// string \p ProcAndFeatures (e.g. "gfx90a", "gfx90a:xnack+:sramecc-", "").
270 /// Returns std::nullopt if the triple is not AMDGCN, the processor is
271 /// unrecognized, or a feature modifier is invalid for the processor.
272 static std::optional<TargetID> parse(const Triple &TT,
273 StringRef ProcAndFeatures);
274
275 /// Parse and validate a TargetID from a full
276 /// "<triple>-<processor>:<features>" directive string.
277 static std::optional<TargetID>
278 parseTargetIDString(StringRef TargetIDDirective);
279
280 /// Returns true if \p Other denotes the same target as *this, i.e. the same
281 /// processor and xnack/sramecc settings on a compatible triple. This is a
282 /// semantic equality that looks through spelling differences.
283 bool isEquivalent(const TargetID &Other) const;
284
285 /// Returns true if a device image for *this can provide the device code for a
286 /// request for \p Other. This is directional and models logical-linking
287 /// compatibility.
288 bool providesFor(const TargetID &Other) const;
289
290 void print(raw_ostream &OS) const;
291
292 std::string toString() const;
293
294 /// Print the canonical processor name followed by any explicit xnack and
295 /// sramecc feature modifiers (e.g. "gfx908:sramecc-:xnack+"), without the
296 /// triple prefix.
297 void printCanonicalTargetIDString(raw_ostream &OS) const;
298
299 /// \returns the canonical processor name followed by any explicit xnack and
300 /// sramecc feature modifiers order (e.g. "gfx908:sramecc-:xnack+"), without
301 /// the triple prefix.
302 std::string getCanonicalFeatureString() const;
303
304 bool operator==(const TargetID &Other) const;
305 bool operator!=(const TargetID &Other) const { return !(*this == Other); }
306};
307
309 TargetID.print(OS);
310 return OS;
311}
312
313} // namespace AMDGPU
314
315} // namespace llvm
316
317#endif
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_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.
LLVM_ABI StringRef getCanonicalArchName(const Triple &T, StringRef Arch)
LLVM_ABI void fillValidArchListR600(SmallVectorImpl< StringRef > &Values)
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 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.
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 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 StringRef getArchNameAMDGCN(GPUKind AK)
LLVM_ABI unsigned getArchAttrAMDGCN(GPUKind AK)
LLVM_ABI Triple::SubArchType getMajorSubArch(Triple::SubArchType SubArch)
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