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"
19#include <cstdint>
20#include <optional>
21#include <string>
22#include <utility>
23
24namespace llvm {
25
26class raw_ostream;
27template <typename T> class SmallVectorImpl;
28class Triple;
29
30namespace AMDGPU {
31
32/// GPU kinds supported by the AMDGPU target.
34 // Not specified processor.
36
37#define R600_GPU(NAME, ENUM, FEATURES) ENUM,
38#define AMDGCN_GPU(NAME, ENUM, ISAVERSION, FEATURES) ENUM,
39#include "AMDGPUTargetParser.def"
40
41 GK_AMDGCN_GENERIC_FIRST = GK_GFX9_GENERIC,
42 GK_AMDGCN_GENERIC_LAST = GK_GFX13_GENERIC,
43};
44
45/// Instruction set architecture version.
46struct IsaVersion {
47 unsigned Major;
48 unsigned Minor;
49 unsigned Stepping;
50};
51
52// This isn't comprehensive for now, just things that are needed from the
53// frontend driver.
56
57 // These features only exist for r600, and are implied true for amdgcn.
58 FEATURE_FMA = 1 << 1,
59 FEATURE_LDEXP = 1 << 2,
60 FEATURE_FP64 = 1 << 3,
61
62 // Common features.
65
66 // Wavefront 32 is available.
68
69 // Xnack is available.
70 FEATURE_XNACK = 1 << 7,
71
72 // Sram-ecc is available.
74
75 // WGP mode is supported.
76 FEATURE_WGP = 1 << 9,
77
78 // Xnack on/off modes are supported.
80};
81
87
89
95LLVM_ABI unsigned getArchAttrAMDGCN(GPUKind AK);
96LLVM_ABI unsigned getArchAttrR600(GPUKind AK);
97
98LLVM_ABI void fillValidArchListAMDGCN(SmallVectorImpl<StringRef> &Values);
99LLVM_ABI void fillValidArchListR600(SmallVectorImpl<StringRef> &Values);
100
101LLVM_ABI IsaVersion getIsaVersion(StringRef GPU);
102
103/// Fills Features map with default values for given target GPU.
104/// \p Features contains overriding target features and this function returns
105/// default target features with entries overridden by \p Features.
106LLVM_ABI std::pair<FeatureError, StringRef>
107fillAMDGPUFeatureMap(StringRef GPU, const Triple &T, StringMap<bool> &Features);
108
110
112private:
113 GPUKind Arch;
114 std::string TargetTripleString;
115 TargetIDSetting XnackSetting;
116 TargetIDSetting SramEccSetting;
117 bool IsAMDHSA;
118
119public:
120 TargetID(GPUKind Arch, const Triple &TT, TargetIDSetting XnackSetting,
121 TargetIDSetting SramEccSetting);
122
123 ~TargetID() = default;
124
125 /// \return True if the current xnack setting is not "Unsupported".
126 bool isXnackSupported() const {
127 return XnackSetting != TargetIDSetting::Unsupported;
128 }
129
130 /// \returns True if the current xnack setting is "On" or "Any".
131 bool isXnackOnOrAny() const {
132 return XnackSetting == TargetIDSetting::On ||
133 XnackSetting == TargetIDSetting::Any;
134 }
135
136 /// \returns True if current xnack setting is "On" or "Off",
137 /// false otherwise.
138 bool isXnackOnOrOff() const {
139 return getXnackSetting() == TargetIDSetting::On ||
140 getXnackSetting() == TargetIDSetting::Off;
141 }
142
143 /// \returns The current xnack TargetIDSetting, possible options are
144 /// "Unsupported", "Any", "Off", and "On".
145 TargetIDSetting getXnackSetting() const { return XnackSetting; }
146
147 /// Sets xnack setting to \p NewXnackSetting.
148 void setXnackSetting(TargetIDSetting NewXnackSetting) {
149 XnackSetting = NewXnackSetting;
150 }
151
152 /// \return True if the current sramecc setting is not "Unsupported".
153 bool isSramEccSupported() const {
154 return SramEccSetting != TargetIDSetting::Unsupported;
155 }
156
157 /// \returns True if the current sramecc setting is "On" or "Any".
158 bool isSramEccOnOrAny() const {
159 return SramEccSetting == TargetIDSetting::On ||
160 SramEccSetting == TargetIDSetting::Any;
161 }
162
163 /// \returns True if current sramecc setting is "On" or "Off",
164 /// false otherwise.
165 bool isSramEccOnOrOff() const {
166 return getSramEccSetting() == TargetIDSetting::On ||
167 getSramEccSetting() == TargetIDSetting::Off;
168 }
169
170 /// \returns The current sramecc TargetIDSetting, possible options are
171 /// "Unsupported", "Any", "Off", and "On".
172 TargetIDSetting getSramEccSetting() const { return SramEccSetting; }
173
174 /// Sets sramecc setting to \p NewSramEccSetting.
175 void setSramEccSetting(TargetIDSetting NewSramEccSetting) {
176 SramEccSetting = NewSramEccSetting;
177 }
178
179 void setTargetIDFromTargetIDStream(StringRef TargetID);
180
181 GPUKind getGPUKind() const { return Arch; }
182
183 StringRef getTargetTripleString() const { return TargetTripleString; }
184
185 /// \returns True if this is an AMDHSA target.
186 bool isAMDHSA() const { return IsAMDHSA; }
187
188 static std::optional<TargetID>
189 parseTargetIDString(StringRef TargetIDDirective);
190
191 void print(raw_ostream &OS) const;
192
193 std::string toString() const;
194
195 bool operator==(const TargetID &Other) const;
196 bool operator!=(const TargetID &Other) const { return !(*this == Other); }
200 TargetID.print(OS);
201 return OS;
202}
203
204} // namespace AMDGPU
205
206} // namespace llvm
207
208#endif
This file defines the StringMap class.
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
#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)
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 StringRef getArchFamilyNameAMDGCN(GPUKind AK)
LLVM_ABI IsaVersion getIsaVersion(StringRef GPU)
LLVM_ABI void fillValidArchListAMDGCN(SmallVectorImpl< StringRef > &Values)
LLVM_ABI GPUKind parseArchAMDGCN(StringRef CPU)
raw_ostream & operator<<(raw_ostream &OS, const TargetID &TargetID)
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 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.