LLVM  8.0.1
TargetParser.cpp
Go to the documentation of this file.
1 //===-- TargetParser - Parser for target features ---------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements a target parser to recognise hardware features such as
11 // FPU/CPU/ARCH names as well as specific support such as HDIV, etc.
12 //
13 //===----------------------------------------------------------------------===//
14 
17 #include "llvm/ADT/ArrayRef.h"
18 #include "llvm/ADT/StringSwitch.h"
19 #include "llvm/ADT/Twine.h"
20 
21 using namespace llvm;
22 using namespace AMDGPU;
23 
24 namespace {
25 
26 struct GPUInfo {
28  StringLiteral CanonicalName;
30  unsigned Features;
31 };
32 
33 constexpr GPUInfo R600GPUs[26] = {
34  // Name Canonical Kind Features
35  // Name
36  {{"r600"}, {"r600"}, GK_R600, FEATURE_NONE },
37  {{"rv630"}, {"r600"}, GK_R600, FEATURE_NONE },
38  {{"rv635"}, {"r600"}, GK_R600, FEATURE_NONE },
39  {{"r630"}, {"r630"}, GK_R630, FEATURE_NONE },
40  {{"rs780"}, {"rs880"}, GK_RS880, FEATURE_NONE },
41  {{"rs880"}, {"rs880"}, GK_RS880, FEATURE_NONE },
42  {{"rv610"}, {"rs880"}, GK_RS880, FEATURE_NONE },
43  {{"rv620"}, {"rs880"}, GK_RS880, FEATURE_NONE },
44  {{"rv670"}, {"rv670"}, GK_RV670, FEATURE_NONE },
45  {{"rv710"}, {"rv710"}, GK_RV710, FEATURE_NONE },
46  {{"rv730"}, {"rv730"}, GK_RV730, FEATURE_NONE },
47  {{"rv740"}, {"rv770"}, GK_RV770, FEATURE_NONE },
48  {{"rv770"}, {"rv770"}, GK_RV770, FEATURE_NONE },
49  {{"cedar"}, {"cedar"}, GK_CEDAR, FEATURE_NONE },
50  {{"palm"}, {"cedar"}, GK_CEDAR, FEATURE_NONE },
51  {{"cypress"}, {"cypress"}, GK_CYPRESS, FEATURE_FMA },
52  {{"hemlock"}, {"cypress"}, GK_CYPRESS, FEATURE_FMA },
53  {{"juniper"}, {"juniper"}, GK_JUNIPER, FEATURE_NONE },
54  {{"redwood"}, {"redwood"}, GK_REDWOOD, FEATURE_NONE },
55  {{"sumo"}, {"sumo"}, GK_SUMO, FEATURE_NONE },
56  {{"sumo2"}, {"sumo"}, GK_SUMO, FEATURE_NONE },
57  {{"barts"}, {"barts"}, GK_BARTS, FEATURE_NONE },
58  {{"caicos"}, {"caicos"}, GK_CAICOS, FEATURE_NONE },
59  {{"aruba"}, {"cayman"}, GK_CAYMAN, FEATURE_FMA },
60  {{"cayman"}, {"cayman"}, GK_CAYMAN, FEATURE_FMA },
61  {{"turks"}, {"turks"}, GK_TURKS, FEATURE_NONE }
62 };
63 
64 // This table should be sorted by the value of GPUKind
65 // Don't bother listing the implicitly true features
66 constexpr GPUInfo AMDGCNGPUs[33] = {
67  // Name Canonical Kind Features
68  // Name
69  {{"gfx600"}, {"gfx600"}, GK_GFX600, FEATURE_FAST_FMA_F32},
70  {{"tahiti"}, {"gfx600"}, GK_GFX600, FEATURE_FAST_FMA_F32},
71  {{"gfx601"}, {"gfx601"}, GK_GFX601, FEATURE_NONE},
72  {{"hainan"}, {"gfx601"}, GK_GFX601, FEATURE_NONE},
73  {{"oland"}, {"gfx601"}, GK_GFX601, FEATURE_NONE},
74  {{"pitcairn"}, {"gfx601"}, GK_GFX601, FEATURE_NONE},
75  {{"verde"}, {"gfx601"}, GK_GFX601, FEATURE_NONE},
76  {{"gfx700"}, {"gfx700"}, GK_GFX700, FEATURE_NONE},
77  {{"kaveri"}, {"gfx700"}, GK_GFX700, FEATURE_NONE},
78  {{"gfx701"}, {"gfx701"}, GK_GFX701, FEATURE_FAST_FMA_F32},
79  {{"hawaii"}, {"gfx701"}, GK_GFX701, FEATURE_FAST_FMA_F32},
80  {{"gfx702"}, {"gfx702"}, GK_GFX702, FEATURE_FAST_FMA_F32},
81  {{"gfx703"}, {"gfx703"}, GK_GFX703, FEATURE_NONE},
82  {{"kabini"}, {"gfx703"}, GK_GFX703, FEATURE_NONE},
83  {{"mullins"}, {"gfx703"}, GK_GFX703, FEATURE_NONE},
84  {{"gfx704"}, {"gfx704"}, GK_GFX704, FEATURE_NONE},
85  {{"bonaire"}, {"gfx704"}, GK_GFX704, FEATURE_NONE},
86  {{"gfx801"}, {"gfx801"}, GK_GFX801, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32},
87  {{"carrizo"}, {"gfx801"}, GK_GFX801, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32},
88  {{"gfx802"}, {"gfx802"}, GK_GFX802, FEATURE_FAST_DENORMAL_F32},
89  {{"iceland"}, {"gfx802"}, GK_GFX802, FEATURE_FAST_DENORMAL_F32},
90  {{"tonga"}, {"gfx802"}, GK_GFX802, FEATURE_FAST_DENORMAL_F32},
91  {{"gfx803"}, {"gfx803"}, GK_GFX803, FEATURE_FAST_DENORMAL_F32},
92  {{"fiji"}, {"gfx803"}, GK_GFX803, FEATURE_FAST_DENORMAL_F32},
93  {{"polaris10"}, {"gfx803"}, GK_GFX803, FEATURE_FAST_DENORMAL_F32},
94  {{"polaris11"}, {"gfx803"}, GK_GFX803, FEATURE_FAST_DENORMAL_F32},
95  {{"gfx810"}, {"gfx810"}, GK_GFX810, FEATURE_FAST_DENORMAL_F32},
96  {{"stoney"}, {"gfx810"}, GK_GFX810, FEATURE_FAST_DENORMAL_F32},
97  {{"gfx900"}, {"gfx900"}, GK_GFX900, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32},
98  {{"gfx902"}, {"gfx902"}, GK_GFX902, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32},
99  {{"gfx904"}, {"gfx904"}, GK_GFX904, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32},
100  {{"gfx906"}, {"gfx906"}, GK_GFX906, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32},
101  {{"gfx909"}, {"gfx909"}, GK_GFX909, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32},
102 };
103 
104 const GPUInfo *getArchEntry(AMDGPU::GPUKind AK, ArrayRef<GPUInfo> Table) {
105  GPUInfo Search = { {""}, {""}, AK, AMDGPU::FEATURE_NONE };
106 
107  auto I = std::lower_bound(Table.begin(), Table.end(), Search,
108  [](const GPUInfo &A, const GPUInfo &B) {
109  return A.Kind < B.Kind;
110  });
111 
112  if (I == Table.end())
113  return nullptr;
114  return I;
115 }
116 
117 } // namespace
118 
120  if (const auto *Entry = getArchEntry(AK, AMDGCNGPUs))
121  return Entry->CanonicalName;
122  return "";
123 }
124 
126  if (const auto *Entry = getArchEntry(AK, R600GPUs))
127  return Entry->CanonicalName;
128  return "";
129 }
130 
132  for (const auto C : AMDGCNGPUs) {
133  if (CPU == C.Name)
134  return C.Kind;
135  }
136 
138 }
139 
141  for (const auto C : R600GPUs) {
142  if (CPU == C.Name)
143  return C.Kind;
144  }
145 
147 }
148 
150  if (const auto *Entry = getArchEntry(AK, AMDGCNGPUs))
151  return Entry->Features;
152  return FEATURE_NONE;
153 }
154 
156  if (const auto *Entry = getArchEntry(AK, R600GPUs))
157  return Entry->Features;
158  return FEATURE_NONE;
159 }
160 
162  // XXX: Should this only report unique canonical names?
163  for (const auto C : AMDGCNGPUs)
164  Values.push_back(C.Name);
165 }
166 
168  for (const auto C : R600GPUs)
169  Values.push_back(C.Name);
170 }
171 
173  if (GPU == "generic")
174  return {7, 0, 0};
175 
177  if (AK == AMDGPU::GPUKind::GK_NONE)
178  return {0, 0, 0};
179 
180  switch (AK) {
181  case GK_GFX600: return {6, 0, 0};
182  case GK_GFX601: return {6, 0, 1};
183  case GK_GFX700: return {7, 0, 0};
184  case GK_GFX701: return {7, 0, 1};
185  case GK_GFX702: return {7, 0, 2};
186  case GK_GFX703: return {7, 0, 3};
187  case GK_GFX704: return {7, 0, 4};
188  case GK_GFX801: return {8, 0, 1};
189  case GK_GFX802: return {8, 0, 2};
190  case GK_GFX803: return {8, 0, 3};
191  case GK_GFX810: return {8, 1, 0};
192  case GK_GFX900: return {9, 0, 0};
193  case GK_GFX902: return {9, 0, 2};
194  case GK_GFX904: return {9, 0, 4};
195  case GK_GFX906: return {9, 0, 6};
196  case GK_GFX909: return {9, 0, 9};
197  default: return {0, 0, 0};
198  }
199 }
uint64_t CallInst * C
StringRef getArchNameR600(GPUKind AK)
This class represents lattice values for constants.
Definition: AllocatorList.h:24
iterator begin() const
Definition: ArrayRef.h:137
void push_back(const T &Elt)
Definition: SmallVector.h:218
const FeatureBitset Features
Instruction set architecture version.
Definition: TargetParser.h:132
void fillValidArchListAMDGCN(SmallVectorImpl< StringRef > &Values)
amdgpu Simplify well known AMD library false Value Value const Twine & Name
StringRef getArchNameAMDGCN(GPUKind AK)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
auto lower_bound(R &&Range, ForwardIt I) -> decltype(adl_begin(Range))
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:1282
unsigned getArchAttrR600(GPUKind AK)
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
Definition: StringRef.h:869
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
void fillValidArchListR600(SmallVectorImpl< StringRef > &Values)
GPUKind
GPU kinds supported by the AMDGPU target.
Definition: TargetParser.h:81
GPUKind parseArchAMDGCN(StringRef CPU)
unsigned getArchAttrAMDGCN(GPUKind AK)
IsaVersion getIsaVersion(StringRef GPU)
iterator end() const
Definition: ArrayRef.h:138
#define I(x, y, z)
Definition: MD5.cpp:58
const unsigned Kind
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
GPUKind parseArchR600(StringRef CPU)