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 ~TargetID() = default;
171
172 /// \return True if the current xnack setting is not "Unsupported".
173 bool isXnackSupported() const {
174 return XnackSetting != TargetIDSetting::Unsupported;
175 }
176
177 /// \returns True if the current xnack setting is "On" or "Any".
178 bool isXnackOnOrAny() const {
179 return XnackSetting == TargetIDSetting::On ||
180 XnackSetting == TargetIDSetting::Any;
181 }
182
183 /// \returns True if current xnack setting is "On" or "Off",
184 /// false otherwise.
185 bool isXnackOnOrOff() const {
186 return getXnackSetting() == TargetIDSetting::On ||
187 getXnackSetting() == TargetIDSetting::Off;
188 }
189
190 /// \returns The current xnack TargetIDSetting, possible options are
191 /// "Unsupported", "Any", "Off", and "On".
192 TargetIDSetting getXnackSetting() const { return XnackSetting; }
193
194 /// Sets xnack setting to \p NewXnackSetting.
195 void setXnackSetting(TargetIDSetting NewXnackSetting) {
196 XnackSetting = NewXnackSetting;
197 }
199 /// \return True if the current sramecc setting is not "Unsupported".
200 bool isSramEccSupported() const {
201 return SramEccSetting != TargetIDSetting::Unsupported;
202 }
203
204 /// \returns True if the current sramecc setting is "On" or "Any".
205 bool isSramEccOnOrAny() const {
206 return SramEccSetting == TargetIDSetting::On ||
207 SramEccSetting == TargetIDSetting::Any;
208 }
209
210 /// \returns True if current sramecc setting is "On" or "Off",
211 /// false otherwise.
212 bool isSramEccOnOrOff() const {
213 return getSramEccSetting() == TargetIDSetting::On ||
214 getSramEccSetting() == TargetIDSetting::Off;
215 }
216
217 /// \returns The current sramecc TargetIDSetting, possible options are
218 /// "Unsupported", "Any", "Off", and "On".
219 TargetIDSetting getSramEccSetting() const { return SramEccSetting; }
220
221 /// Sets sramecc setting to \p NewSramEccSetting.
222 void setSramEccSetting(TargetIDSetting NewSramEccSetting) {
223 SramEccSetting = NewSramEccSetting;
224 }
225
226 void setTargetIDFromTargetIDStream(StringRef TargetID);
227
228 GPUKind getGPUKind() const { return Arch; }
229
230 StringRef getTargetTripleString() const { return TargetTripleString; }
231
232 /// \returns True if this is an AMDHSA target.
233 bool isAMDHSA() const { return IsAMDHSA; }
234
235 static std::optional<TargetID>
236 parseTargetIDString(StringRef TargetIDDirective);
237
238 void print(raw_ostream &OS) const;
239
240 std::string toString() const;
241
242 bool operator==(const TargetID &Other) const;
243 bool operator!=(const TargetID &Other) const { return !(*this == Other); }
244};
245
247 TargetID.print(OS);
248 return OS;
249}
250
251} // namespace AMDGPU
252
253} // namespace llvm
254
255#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