LLVM 23.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};
57
58// This isn't comprehensive for now, just things that are needed from the
59// frontend driver.
62
63 // These features only exist for r600, and are implied true for amdgcn.
64 FEATURE_FMA = 1 << 1,
65 FEATURE_LDEXP = 1 << 2,
66 FEATURE_FP64 = 1 << 3,
67
68 // Common features.
71
72 // Wavefront 32 is available.
74
75 // Xnack is available.
76 FEATURE_XNACK = 1 << 7,
77
78 // Sram-ecc is available.
80
81 // WGP mode is supported.
82 FEATURE_WGP = 1 << 9,
83
84 // Xnack on/off modes are supported.
86};
87
93
97
98/// Return true if subarch \p A is compatible with subarch \p B, i.e. they are
99/// equal or one is the major-family subarch of the other (e.g. AMDGPUSubArch9
100/// is compatible with AMDGPUSubArch900). NoSubArch is compatible with anything.
101LLVM_ABI bool isSubArchCompatible(const Triple &A, const Triple &B);
103
104/// Return true if the GPU \p AK is usable with the triple subarch \p SubArch.
105/// A NoSubArch triple (legacy "amdgcn") accepts any GPU. Otherwise the GPU's
106/// subarch must equal \p SubArch, or \p SubArch must be the major-family
107/// subarch of the GPU (e.g. the amdgpu9 triple accepts gfx900).
108LLVM_ABI bool isCPUValidForSubArch(Triple::SubArchType SubArch, GPUKind AK);
109
110/// Convenience overload of isCPUValidForSubArch taking a GPU name \p CPU, which
111/// is parsed via parseArchAMDGCN. An unrecognized name is never valid.
112LLVM_ABI bool isCPUValidForSubArch(Triple::SubArchType SubArch, StringRef CPU);
113
114/// Returns the effective triple appropriate to use when linking \p B into \p A
115/// by merging the subarches in case of inexact match.
116///
117/// In cases where isSubArchCompatible would return / false, returns \p B. This
118/// assumes that the non-arch triple components are the same
119LLVM_ABI std::string mergeSubArch(const Triple &A, const Triple &B);
120
121LLVM_ABI StringRef getArchNameAMDGCN(GPUKind AK);
122LLVM_ABI StringRef getArchNameR600(GPUKind AK);
123
124/// Returns the canonical GPU name for an AMDGPU subarch, e.g.
125/// AMDGPUSubArch1030 -> "gfx1030", AMDGPUSubArch9 -> "gfx9-generic",
126/// AMDGPUSubArch6 -> "gfx600". Returns "" for NoSubArch or a non-AMDGPU
127/// subarch. The major-only subarches map to their generic/lowest
128/// representative, matching the default subtarget for an unspecified -mcpu.
130LLVM_ABI StringRef getCanonicalArchName(const Triple &T, StringRef Arch);
131LLVM_ABI GPUKind parseArchAMDGCN(StringRef CPU);
132LLVM_ABI GPUKind parseArchR600(StringRef CPU);
134LLVM_ABI unsigned getArchAttrAMDGCN(GPUKind AK);
136LLVM_ABI unsigned getArchAttrR600(GPUKind AK);
137
138/// Append the valid AMDGCN GPU names to \p Values. If \p SubArch is not
139/// NoSubArch, only GPUs compatible with that subarch (see isCPUValidForSubArch)
140/// are appended.
141LLVM_ABI void
142fillValidArchListAMDGCN(SmallVectorImpl<StringRef> &Values,
144LLVM_ABI void fillValidArchListR600(SmallVectorImpl<StringRef> &Values);
145
146LLVM_ABI IsaVersion getIsaVersion(StringRef GPU);
147LLVM_ABI IsaVersion getIsaVersion(Triple::SubArchType SubArch);
148
149/// Fills Features map with default values for given target GPU.
150/// \p Features contains overriding target features and this function returns
151/// default target features with entries overridden by \p Features.
152LLVM_ABI std::pair<FeatureError, StringRef>
153fillAMDGPUFeatureMap(StringRef GPU, const Triple &T, StringMap<bool> &Features);
154
156
158private:
159 GPUKind Arch;
160 std::string TargetTripleString;
161 TargetIDSetting XnackSetting;
162 TargetIDSetting SramEccSetting;
163 bool IsAMDHSA;
164
165public:
166 TargetID(GPUKind Arch, const Triple &TT, TargetIDSetting XnackSetting,
167 TargetIDSetting SramEccSetting);
168
169 /// Construct a TargetID from a triple \p TT and the processor+features string
170 /// e.g. "gfx90a", "gfx90a:xnack+:sramecc-", "".
171 TargetID(const Triple &TT, StringRef TargetIDStr);
172
173 ~TargetID() = default;
174
175 /// \return True if the current xnack setting is not "Unsupported".
176 bool isXnackSupported() const {
177 return XnackSetting != TargetIDSetting::Unsupported;
178 }
179
180 /// \returns True if the current xnack setting is "On" or "Any".
181 bool isXnackOnOrAny() const {
182 return XnackSetting == TargetIDSetting::On ||
183 XnackSetting == TargetIDSetting::Any;
184 }
185
186 /// \returns True if current xnack setting is "On" or "Off",
187 /// false otherwise.
188 bool isXnackOnOrOff() const {
189 return getXnackSetting() == TargetIDSetting::On ||
190 getXnackSetting() == TargetIDSetting::Off;
191 }
192
193 /// \returns The current xnack TargetIDSetting, possible options are
194 /// "Unsupported", "Any", "Off", and "On".
195 TargetIDSetting getXnackSetting() const { return XnackSetting; }
196
197 /// Sets xnack setting to \p NewXnackSetting.
198 void setXnackSetting(TargetIDSetting NewXnackSetting) {
199 XnackSetting = NewXnackSetting;
200 }
201
202 /// \return True if the current sramecc setting is not "Unsupported".
203 bool isSramEccSupported() const {
204 return SramEccSetting != TargetIDSetting::Unsupported;
205 }
206
207 /// \returns True if the current sramecc setting is "On" or "Any".
208 bool isSramEccOnOrAny() const {
209 return SramEccSetting == TargetIDSetting::On ||
210 SramEccSetting == TargetIDSetting::Any;
211 }
212
213 /// \returns True if current sramecc setting is "On" or "Off",
214 /// false otherwise.
215 bool isSramEccOnOrOff() const {
216 return getSramEccSetting() == TargetIDSetting::On ||
217 getSramEccSetting() == TargetIDSetting::Off;
218 }
219
220 /// \returns The current sramecc TargetIDSetting, possible options are
221 /// "Unsupported", "Any", "Off", and "On".
222 TargetIDSetting getSramEccSetting() const { return SramEccSetting; }
223
224 /// Sets sramecc setting to \p NewSramEccSetting.
225 void setSramEccSetting(TargetIDSetting NewSramEccSetting) {
226 SramEccSetting = NewSramEccSetting;
227 }
228
229 void setTargetIDFromTargetIDStream(StringRef TargetID);
230
231 GPUKind getGPUKind() const { return Arch; }
232
233 StringRef getTargetTripleString() const { return TargetTripleString; }
234
235 /// \returns True if this is an AMDHSA target.
236 bool isAMDHSA() const { return IsAMDHSA; }
237
238 static std::optional<TargetID>
239 parseTargetIDString(StringRef TargetIDDirective);
240
241 /// Returns true if a device image built for *this can satisfy a request for
242 /// \p Other (i.e. they are compatible and can be grouped together).
243 bool isCompatibleWith(const TargetID &Other) const;
244
245 void print(raw_ostream &OS) const;
246
247 std::string toString() const;
248
249 bool operator==(const TargetID &Other) const;
250 bool operator!=(const TargetID &Other) const { return !(*this == Other); }
251};
252
254 TargetID.print(OS);
255 return OS;
256}
257
258} // namespace AMDGPU
259
260} // namespace llvm
261
262#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