• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- TargetParser - Parser for target 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 hardware features such as
10 // FPU/CPU/ARCH names as well as specific support such as HDIV, etc.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "llvm/Support/ARMBuildAttributes.h"
15 #include "llvm/Support/TargetParser.h"
16 #include "llvm/ADT/ArrayRef.h"
17 #include "llvm/ADT/StringSwitch.h"
18 #include "llvm/ADT/Twine.h"
19 
20 using namespace llvm;
21 using namespace AMDGPU;
22 
23 namespace {
24 
25 struct GPUInfo {
26   StringLiteral Name;
27   StringLiteral CanonicalName;
28   AMDGPU::GPUKind Kind;
29   unsigned Features;
30 };
31 
32 constexpr GPUInfo R600GPUs[26] = {
33   // Name       Canonical    Kind        Features
34   //            Name
35   {{"r600"},    {"r600"},    GK_R600,    FEATURE_NONE },
36   {{"rv630"},   {"r600"},    GK_R600,    FEATURE_NONE },
37   {{"rv635"},   {"r600"},    GK_R600,    FEATURE_NONE },
38   {{"r630"},    {"r630"},    GK_R630,    FEATURE_NONE },
39   {{"rs780"},   {"rs880"},   GK_RS880,   FEATURE_NONE },
40   {{"rs880"},   {"rs880"},   GK_RS880,   FEATURE_NONE },
41   {{"rv610"},   {"rs880"},   GK_RS880,   FEATURE_NONE },
42   {{"rv620"},   {"rs880"},   GK_RS880,   FEATURE_NONE },
43   {{"rv670"},   {"rv670"},   GK_RV670,   FEATURE_NONE },
44   {{"rv710"},   {"rv710"},   GK_RV710,   FEATURE_NONE },
45   {{"rv730"},   {"rv730"},   GK_RV730,   FEATURE_NONE },
46   {{"rv740"},   {"rv770"},   GK_RV770,   FEATURE_NONE },
47   {{"rv770"},   {"rv770"},   GK_RV770,   FEATURE_NONE },
48   {{"cedar"},   {"cedar"},   GK_CEDAR,   FEATURE_NONE },
49   {{"palm"},    {"cedar"},   GK_CEDAR,   FEATURE_NONE },
50   {{"cypress"}, {"cypress"}, GK_CYPRESS, FEATURE_FMA  },
51   {{"hemlock"}, {"cypress"}, GK_CYPRESS, FEATURE_FMA  },
52   {{"juniper"}, {"juniper"}, GK_JUNIPER, FEATURE_NONE },
53   {{"redwood"}, {"redwood"}, GK_REDWOOD, FEATURE_NONE },
54   {{"sumo"},    {"sumo"},    GK_SUMO,    FEATURE_NONE },
55   {{"sumo2"},   {"sumo"},    GK_SUMO,    FEATURE_NONE },
56   {{"barts"},   {"barts"},   GK_BARTS,   FEATURE_NONE },
57   {{"caicos"},  {"caicos"},  GK_CAICOS,  FEATURE_NONE },
58   {{"aruba"},   {"cayman"},  GK_CAYMAN,  FEATURE_FMA  },
59   {{"cayman"},  {"cayman"},  GK_CAYMAN,  FEATURE_FMA  },
60   {{"turks"},   {"turks"},   GK_TURKS,   FEATURE_NONE }
61 };
62 
63 // This table should be sorted by the value of GPUKind
64 // Don't bother listing the implicitly true features
65 constexpr GPUInfo AMDGCNGPUs[37] = {
66   // Name         Canonical    Kind        Features
67   //              Name
68   {{"gfx600"},    {"gfx600"},  GK_GFX600,  FEATURE_FAST_FMA_F32},
69   {{"tahiti"},    {"gfx600"},  GK_GFX600,  FEATURE_FAST_FMA_F32},
70   {{"gfx601"},    {"gfx601"},  GK_GFX601,  FEATURE_NONE},
71   {{"hainan"},    {"gfx601"},  GK_GFX601,  FEATURE_NONE},
72   {{"oland"},     {"gfx601"},  GK_GFX601,  FEATURE_NONE},
73   {{"pitcairn"},  {"gfx601"},  GK_GFX601,  FEATURE_NONE},
74   {{"verde"},     {"gfx601"},  GK_GFX601,  FEATURE_NONE},
75   {{"gfx700"},    {"gfx700"},  GK_GFX700,  FEATURE_NONE},
76   {{"kaveri"},    {"gfx700"},  GK_GFX700,  FEATURE_NONE},
77   {{"gfx701"},    {"gfx701"},  GK_GFX701,  FEATURE_FAST_FMA_F32},
78   {{"hawaii"},    {"gfx701"},  GK_GFX701,  FEATURE_FAST_FMA_F32},
79   {{"gfx702"},    {"gfx702"},  GK_GFX702,  FEATURE_FAST_FMA_F32},
80   {{"gfx703"},    {"gfx703"},  GK_GFX703,  FEATURE_NONE},
81   {{"kabini"},    {"gfx703"},  GK_GFX703,  FEATURE_NONE},
82   {{"mullins"},   {"gfx703"},  GK_GFX703,  FEATURE_NONE},
83   {{"gfx704"},    {"gfx704"},  GK_GFX704,  FEATURE_NONE},
84   {{"bonaire"},   {"gfx704"},  GK_GFX704,  FEATURE_NONE},
85   {{"gfx801"},    {"gfx801"},  GK_GFX801,  FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32},
86   {{"carrizo"},   {"gfx801"},  GK_GFX801,  FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32},
87   {{"gfx802"},    {"gfx802"},  GK_GFX802,  FEATURE_FAST_DENORMAL_F32},
88   {{"iceland"},   {"gfx802"},  GK_GFX802,  FEATURE_FAST_DENORMAL_F32},
89   {{"tonga"},     {"gfx802"},  GK_GFX802,  FEATURE_FAST_DENORMAL_F32},
90   {{"gfx803"},    {"gfx803"},  GK_GFX803,  FEATURE_FAST_DENORMAL_F32},
91   {{"fiji"},      {"gfx803"},  GK_GFX803,  FEATURE_FAST_DENORMAL_F32},
92   {{"polaris10"}, {"gfx803"},  GK_GFX803,  FEATURE_FAST_DENORMAL_F32},
93   {{"polaris11"}, {"gfx803"},  GK_GFX803,  FEATURE_FAST_DENORMAL_F32},
94   {{"gfx810"},    {"gfx810"},  GK_GFX810,  FEATURE_FAST_DENORMAL_F32},
95   {{"stoney"},    {"gfx810"},  GK_GFX810,  FEATURE_FAST_DENORMAL_F32},
96   {{"gfx900"},    {"gfx900"},  GK_GFX900,  FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32},
97   {{"gfx902"},    {"gfx902"},  GK_GFX902,  FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32},
98   {{"gfx904"},    {"gfx904"},  GK_GFX904,  FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32},
99   {{"gfx906"},    {"gfx906"},  GK_GFX906,  FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32},
100   {{"gfx908"},    {"gfx908"},  GK_GFX908,  FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32},
101   {{"gfx909"},    {"gfx909"},  GK_GFX909,  FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32},
102   {{"gfx1010"},   {"gfx1010"}, GK_GFX1010, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32},
103   {{"gfx1011"},   {"gfx1011"}, GK_GFX1011, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32},
104   {{"gfx1012"},   {"gfx1012"}, GK_GFX1012, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32},
105 };
106 
getArchEntry(AMDGPU::GPUKind AK,ArrayRef<GPUInfo> Table)107 const GPUInfo *getArchEntry(AMDGPU::GPUKind AK, ArrayRef<GPUInfo> Table) {
108   GPUInfo Search = { {""}, {""}, AK, AMDGPU::FEATURE_NONE };
109 
110   auto I = std::lower_bound(Table.begin(), Table.end(), Search,
111     [](const GPUInfo &A, const GPUInfo &B) {
112       return A.Kind < B.Kind;
113     });
114 
115   if (I == Table.end())
116     return nullptr;
117   return I;
118 }
119 
120 } // namespace
121 
getArchNameAMDGCN(GPUKind AK)122 StringRef llvm::AMDGPU::getArchNameAMDGCN(GPUKind AK) {
123   if (const auto *Entry = getArchEntry(AK, AMDGCNGPUs))
124     return Entry->CanonicalName;
125   return "";
126 }
127 
getArchNameR600(GPUKind AK)128 StringRef llvm::AMDGPU::getArchNameR600(GPUKind AK) {
129   if (const auto *Entry = getArchEntry(AK, R600GPUs))
130     return Entry->CanonicalName;
131   return "";
132 }
133 
parseArchAMDGCN(StringRef CPU)134 AMDGPU::GPUKind llvm::AMDGPU::parseArchAMDGCN(StringRef CPU) {
135   for (const auto &C : AMDGCNGPUs) {
136     if (CPU == C.Name)
137       return C.Kind;
138   }
139 
140   return AMDGPU::GPUKind::GK_NONE;
141 }
142 
parseArchR600(StringRef CPU)143 AMDGPU::GPUKind llvm::AMDGPU::parseArchR600(StringRef CPU) {
144   for (const auto &C : R600GPUs) {
145     if (CPU == C.Name)
146       return C.Kind;
147   }
148 
149   return AMDGPU::GPUKind::GK_NONE;
150 }
151 
getArchAttrAMDGCN(GPUKind AK)152 unsigned AMDGPU::getArchAttrAMDGCN(GPUKind AK) {
153   if (const auto *Entry = getArchEntry(AK, AMDGCNGPUs))
154     return Entry->Features;
155   return FEATURE_NONE;
156 }
157 
getArchAttrR600(GPUKind AK)158 unsigned AMDGPU::getArchAttrR600(GPUKind AK) {
159   if (const auto *Entry = getArchEntry(AK, R600GPUs))
160     return Entry->Features;
161   return FEATURE_NONE;
162 }
163 
fillValidArchListAMDGCN(SmallVectorImpl<StringRef> & Values)164 void AMDGPU::fillValidArchListAMDGCN(SmallVectorImpl<StringRef> &Values) {
165   // XXX: Should this only report unique canonical names?
166   for (const auto &C : AMDGCNGPUs)
167     Values.push_back(C.Name);
168 }
169 
fillValidArchListR600(SmallVectorImpl<StringRef> & Values)170 void AMDGPU::fillValidArchListR600(SmallVectorImpl<StringRef> &Values) {
171   for (const auto &C : R600GPUs)
172     Values.push_back(C.Name);
173 }
174 
getIsaVersion(StringRef GPU)175 AMDGPU::IsaVersion AMDGPU::getIsaVersion(StringRef GPU) {
176   AMDGPU::GPUKind AK = parseArchAMDGCN(GPU);
177   if (AK == AMDGPU::GPUKind::GK_NONE) {
178     if (GPU == "generic-hsa")
179       return {7, 0, 0};
180     if (GPU == "generic")
181       return {6, 0, 0};
182     return {0, 0, 0};
183   }
184 
185   switch (AK) {
186   case GK_GFX600:  return {6, 0, 0};
187   case GK_GFX601:  return {6, 0, 1};
188   case GK_GFX700:  return {7, 0, 0};
189   case GK_GFX701:  return {7, 0, 1};
190   case GK_GFX702:  return {7, 0, 2};
191   case GK_GFX703:  return {7, 0, 3};
192   case GK_GFX704:  return {7, 0, 4};
193   case GK_GFX801:  return {8, 0, 1};
194   case GK_GFX802:  return {8, 0, 2};
195   case GK_GFX803:  return {8, 0, 3};
196   case GK_GFX810:  return {8, 1, 0};
197   case GK_GFX900:  return {9, 0, 0};
198   case GK_GFX902:  return {9, 0, 2};
199   case GK_GFX904:  return {9, 0, 4};
200   case GK_GFX906:  return {9, 0, 6};
201   case GK_GFX908:  return {9, 0, 8};
202   case GK_GFX909:  return {9, 0, 9};
203   case GK_GFX1010: return {10, 1, 0};
204   case GK_GFX1011: return {10, 1, 1};
205   case GK_GFX1012: return {10, 1, 2};
206   default:         return {0, 0, 0};
207   }
208 }
209