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
94
98
99/// Return true if subarch \p A is compatible with subarch \p B, i.e. they are
100/// equal or one is the major-family subarch of the other (e.g. AMDGPUSubArch9
101/// is compatible with AMDGPUSubArch900). NoSubArch is compatible with anything.
102LLVM_ABI bool isSubArchCompatible(const Triple &A, const Triple &B);
104
105/// Return true if the GPU \p AK is usable with the triple subarch \p SubArch.
106/// A NoSubArch triple (legacy "amdgcn") accepts any GPU. Otherwise the GPU's
107/// subarch must equal \p SubArch, or \p SubArch must be the major-family
108/// subarch of the GPU (e.g. the amdgpu9 triple accepts gfx900).
109LLVM_ABI bool isCPUValidForSubArch(Triple::SubArchType SubArch, GPUKind AK);
110
111/// Convenience overload of isCPUValidForSubArch taking a GPU name \p CPU, which
112/// is parsed via parseArchAMDGCN. An unrecognized name is never valid.
113LLVM_ABI bool isCPUValidForSubArch(Triple::SubArchType SubArch, StringRef CPU);
114
115/// Returns the effective triple appropriate to use when linking \p B into \p A
116/// by merging the subarches in case of inexact match.
117///
118/// In cases where isSubArchCompatible would return / false, returns \p B. This
119/// assumes that the non-arch triple components are the same
120LLVM_ABI std::string mergeSubArch(const Triple &A, const Triple &B);
121
122LLVM_ABI StringRef getArchNameAMDGCN(GPUKind AK);
123LLVM_ABI StringRef getArchNameR600(GPUKind AK);
124
125/// Returns the canonical GPU name for an AMDGPU subarch, e.g.
126/// AMDGPUSubArch1030 -> "gfx1030", AMDGPUSubArch9 -> "gfx9-generic",
127/// AMDGPUSubArch6 -> "gfx600". Returns "" for NoSubArch or a non-AMDGPU
128/// subarch. The major-only subarches map to their generic/lowest
129/// representative, matching the default subtarget for an unspecified -mcpu.
131LLVM_ABI StringRef getCanonicalArchName(const Triple &T, StringRef Arch);
132LLVM_ABI GPUKind parseArchAMDGCN(StringRef CPU);
133LLVM_ABI GPUKind parseArchR600(StringRef CPU);
135LLVM_ABI unsigned getArchAttrAMDGCN(GPUKind AK);
137LLVM_ABI unsigned getArchAttrR600(GPUKind AK);
138
139/// Append the valid AMDGCN GPU names to \p Values. If \p SubArch is not
140/// NoSubArch, only GPUs compatible with that subarch (see isCPUValidForSubArch)
141/// are appended.
142LLVM_ABI void
143fillValidArchListAMDGCN(SmallVectorImpl<StringRef> &Values,
145LLVM_ABI void fillValidArchListR600(SmallVectorImpl<StringRef> &Values);
146
147LLVM_ABI IsaVersion getIsaVersion(StringRef GPU);
148LLVM_ABI IsaVersion getIsaVersion(Triple::SubArchType SubArch);
149
150/// Fills Features map with default values for given target GPU.
151/// \p Features contains overriding target features and this function returns
152/// default target features with entries overridden by \p Features.
153LLVM_ABI std::pair<FeatureError, StringRef>
154fillAMDGPUFeatureMap(StringRef GPU, const Triple &T, StringMap<bool> &Features);
155
157
159private:
160 GPUKind Arch;
161 std::string TargetTripleString;
162 TargetIDSetting XnackSetting;
163 TargetIDSetting SramEccSetting;
164 bool IsAMDHSA;
165
166public:
167 TargetID(GPUKind Arch, const Triple &TT, TargetIDSetting XnackSetting,
168 TargetIDSetting SramEccSetting);
169
170 /// Construct a TargetID from a triple \p TT and the processor+features string
171 /// e.g. "gfx90a", "gfx90a:xnack+:sramecc-", "".
172 TargetID(const Triple &TT, StringRef TargetIDStr);
173
174 ~TargetID() = default;
175
176 /// \return True if the current xnack setting is not "Unsupported".
177 bool isXnackSupported() const {
178 return XnackSetting != TargetIDSetting::Unsupported;
179 }
180
181 /// \returns True if the current xnack setting is "On" or "Any".
182 bool isXnackOnOrAny() const {
183 return XnackSetting == TargetIDSetting::On ||
184 XnackSetting == TargetIDSetting::Any;
185 }
186
187 /// \returns True if current xnack setting is "On" or "Off",
188 /// false otherwise.
189 bool isXnackOnOrOff() const {
190 return getXnackSetting() == TargetIDSetting::On ||
191 getXnackSetting() == TargetIDSetting::Off;
192 }
193
194 /// \returns The current xnack TargetIDSetting, possible options are
195 /// "Unsupported", "Any", "Off", and "On".
196 TargetIDSetting getXnackSetting() const { return XnackSetting; }
197
198 /// Sets xnack setting to \p NewXnackSetting.
199 void setXnackSetting(TargetIDSetting NewXnackSetting) {
200 XnackSetting = NewXnackSetting;
201 }
202
203 /// \return True if the current sramecc setting is not "Unsupported".
204 bool isSramEccSupported() const {
205 return SramEccSetting != TargetIDSetting::Unsupported;
206 }
207
208 /// \returns True if the current sramecc setting is "On" or "Any".
209 bool isSramEccOnOrAny() const {
210 return SramEccSetting == TargetIDSetting::On ||
211 SramEccSetting == TargetIDSetting::Any;
212 }
213
214 /// \returns True if current sramecc setting is "On" or "Off",
215 /// false otherwise.
216 bool isSramEccOnOrOff() const {
217 return getSramEccSetting() == TargetIDSetting::On ||
218 getSramEccSetting() == TargetIDSetting::Off;
219 }
220
221 /// \returns The current sramecc TargetIDSetting, possible options are
222 /// "Unsupported", "Any", "Off", and "On".
223 TargetIDSetting getSramEccSetting() const { return SramEccSetting; }
224
225 /// Sets sramecc setting to \p NewSramEccSetting.
226 void setSramEccSetting(TargetIDSetting NewSramEccSetting) {
227 SramEccSetting = NewSramEccSetting;
228 }
229
230 void setTargetIDFromTargetIDStream(StringRef TargetID);
231
232 GPUKind getGPUKind() const { return Arch; }
233
234 StringRef getTargetTripleString() const { return TargetTripleString; }
235
236 /// \returns True if this is an AMDHSA target.
237 bool isAMDHSA() const { return IsAMDHSA; }
238
239 static std::optional<TargetID>
240 parseTargetIDString(StringRef TargetIDDirective);
241
242 /// Returns true if \p Other denotes the same target as *this, i.e. the same
243 /// processor and xnack/sramecc settings on a compatible triple. This is a
244 /// semantic equality that looks through spelling differences.
245 bool isEquivalent(const TargetID &Other) const;
246
247 /// Returns true if a device image for *this can provide the device code for a
248 /// request for \p Other. This is directional and models logical-linking
249 /// compatibility.
250 bool providesFor(const TargetID &Other) const;
251
252 void print(raw_ostream &OS) const;
253
254 std::string toString() const;
255
256 bool operator==(const TargetID &Other) const;
257 bool operator!=(const TargetID &Other) const { return !(*this == Other); }
258};
259
261 TargetID.print(OS);
262 return OS;
263}
264
265} // namespace AMDGPU
266
267} // namespace llvm
268
269#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 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...
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:47
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 IsaVersion getIsaVersion(StringRef GPU)
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