blob: 2d70ec49c94bdea6f274b3b3feac815d722ec1df [file] [log] [blame]
Craig Topperd5c28c42020-06-09 12:18:08 -07001//===-- X86TargetParser - Parser for X86 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 X86 hardware features.
10//
11//===----------------------------------------------------------------------===//
12
13#include "llvm/Support/X86TargetParser.h"
14#include "llvm/ADT/StringSwitch.h"
15#include "llvm/ADT/Triple.h"
16
17using namespace llvm;
Craig Topper8dc92142020-06-24 10:36:02 -070018using namespace llvm::X86;
Craig Topperd5c28c42020-06-09 12:18:08 -070019
Craig Topper8dc92142020-06-24 10:36:02 -070020namespace {
21
Craig Topper35379392020-06-30 11:59:03 -070022/// Container class for CPU features.
23/// This is a constexpr reimplementation of a subset of std::bitset. It would be
24/// nice to use std::bitset directly, but it doesn't support constant
25/// initialization.
26class FeatureBitset {
27 static constexpr unsigned NUM_FEATURE_WORDS =
28 (X86::CPU_FEATURE_MAX + 31) / 32;
29
30 // This cannot be a std::array, operator[] is not constexpr until C++17.
31 uint32_t Bits[NUM_FEATURE_WORDS] = {};
32
33public:
34 constexpr FeatureBitset() = default;
35 constexpr FeatureBitset(std::initializer_list<unsigned> Init) {
36 for (auto I : Init)
37 set(I);
38 }
39
40 constexpr FeatureBitset &set(unsigned I) {
41 uint32_t NewBits = Bits[I / 32] | (uint32_t(1) << (I % 32));
42 Bits[I / 32] = NewBits;
43 return *this;
44 }
45
46 constexpr bool operator[](unsigned I) const {
47 uint32_t Mask = uint32_t(1) << (I % 32);
48 return (Bits[I / 32] & Mask) != 0;
49 }
50
51 constexpr FeatureBitset operator&(const FeatureBitset &RHS) const {
52 FeatureBitset Result;
53 for (unsigned I = 0, E = array_lengthof(Bits); I != E; ++I)
54 Result.Bits[I] = Bits[I] & RHS.Bits[I];
55 return Result;
56 }
57
58 constexpr FeatureBitset operator|(const FeatureBitset &RHS) const {
59 FeatureBitset Result;
60 for (unsigned I = 0, E = array_lengthof(Bits); I != E; ++I)
61 Result.Bits[I] = Bits[I] | RHS.Bits[I];
62 return Result;
63 }
64
65 constexpr FeatureBitset operator~() const {
66 FeatureBitset Result;
67 for (unsigned I = 0, E = array_lengthof(Bits); I != E; ++I)
68 Result.Bits[I] = ~Bits[I];
69 return Result;
70 }
71};
72
Craig Topper8dc92142020-06-24 10:36:02 -070073struct ProcInfo {
74 StringLiteral Name;
75 X86::CPUKind Kind;
76 unsigned KeyFeature;
Craig Topper35379392020-06-30 11:59:03 -070077 FeatureBitset Features;
Craig Topper8dc92142020-06-24 10:36:02 -070078};
79
80} // end anonymous namespace
81
Craig Topper35379392020-06-30 11:59:03 -070082#define X86_FEATURE(ENUM, STRING) \
83 static constexpr FeatureBitset Feature##ENUM = {X86::FEATURE_##ENUM};
84#include "llvm/Support/X86TargetParser.def"
85
86// Pentium with MMX.
87static constexpr FeatureBitset FeaturesPentiumMMX =
88 FeatureX87 | FeatureCMPXCHG8B | FeatureMMX;
89
90// Pentium 2 and 3.
91static constexpr FeatureBitset FeaturesPentium2 =
92 FeatureX87 | FeatureCMPXCHG8B | FeatureMMX | FeatureFXSR;
93static constexpr FeatureBitset FeaturesPentium3 = FeaturesPentium2 | FeatureSSE;
94
95// Pentium 4 CPUs
96static constexpr FeatureBitset FeaturesPentium4 =
97 FeaturesPentium3 | FeatureSSE2;
98static constexpr FeatureBitset FeaturesPrescott =
99 FeaturesPentium4 | FeatureSSE3;
100static constexpr FeatureBitset FeaturesNocona =
101 FeaturesPrescott | FeatureEM64T | FeatureCMPXCHG16B;
102
103// Basic 64-bit capable CPU.
104static constexpr FeatureBitset FeaturesX86_64 = FeaturesPentium4 | FeatureEM64T;
105
106// Intel Core CPUs
107static constexpr FeatureBitset FeaturesCore2 =
108 FeaturesNocona | FeatureSAHF | FeatureSSSE3;
109static constexpr FeatureBitset FeaturesPenryn = FeaturesCore2 | FeatureSSE4_1;
110static constexpr FeatureBitset FeaturesNehalem =
111 FeaturesPenryn | FeaturePOPCNT | FeatureSSE4_2;
112static constexpr FeatureBitset FeaturesWestmere =
113 FeaturesNehalem | FeaturePCLMUL;
114static constexpr FeatureBitset FeaturesSandyBridge =
115 FeaturesWestmere | FeatureAVX | FeatureXSAVE | FeatureXSAVEOPT;
116static constexpr FeatureBitset FeaturesIvyBridge =
117 FeaturesSandyBridge | FeatureF16C | FeatureFSGSBASE | FeatureRDRND;
118static constexpr FeatureBitset FeaturesHaswell =
119 FeaturesIvyBridge | FeatureAVX2 | FeatureBMI | FeatureBMI2 | FeatureFMA |
120 FeatureINVPCID | FeatureLZCNT | FeatureMOVBE;
121static constexpr FeatureBitset FeaturesBroadwell =
122 FeaturesHaswell | FeatureADX | FeaturePRFCHW | FeatureRDSEED;
123
124// Intel Knights Landing and Knights Mill
125// Knights Landing has feature parity with Broadwell.
126static constexpr FeatureBitset FeaturesKNL =
127 FeaturesBroadwell | FeatureAES | FeatureAVX512F | FeatureAVX512CD |
128 FeatureAVX512ER | FeatureAVX512PF | FeaturePREFETCHWT1;
129static constexpr FeatureBitset FeaturesKNM =
130 FeaturesKNL | FeatureAVX512VPOPCNTDQ;
131
132// Intel Skylake processors.
133static constexpr FeatureBitset FeaturesSkylakeClient =
134 FeaturesBroadwell | FeatureAES | FeatureCLFLUSHOPT | FeatureXSAVEC |
135 FeatureXSAVES | FeatureSGX;
136// SkylakeServer inherits all SkylakeClient features except SGX.
137// FIXME: That doesn't match gcc.
138static constexpr FeatureBitset FeaturesSkylakeServer =
139 (FeaturesSkylakeClient & ~FeatureSGX) | FeatureAVX512F | FeatureAVX512CD |
140 FeatureAVX512DQ | FeatureAVX512BW | FeatureAVX512VL | FeatureCLWB |
141 FeaturePKU;
142static constexpr FeatureBitset FeaturesCascadeLake =
143 FeaturesSkylakeServer | FeatureAVX512VNNI;
144static constexpr FeatureBitset FeaturesCooperLake =
145 FeaturesCascadeLake | FeatureAVX512BF16;
146
147// Intel 10nm processors.
148static constexpr FeatureBitset FeaturesCannonlake =
149 FeaturesSkylakeClient | FeatureAVX512F | FeatureAVX512CD | FeatureAVX512DQ |
150 FeatureAVX512BW | FeatureAVX512VL | FeatureAVX512IFMA | FeatureAVX512VBMI |
151 FeaturePKU | FeatureSHA;
152static constexpr FeatureBitset FeaturesICLClient =
153 FeaturesCannonlake | FeatureAVX512BITALG | FeatureAVX512VBMI2 |
154 FeatureAVX512VNNI | FeatureAVX512VPOPCNTDQ | FeatureCLWB | FeatureGFNI |
155 FeatureRDPID | FeatureVAES | FeatureVPCLMULQDQ;
156static constexpr FeatureBitset FeaturesICLServer =
157 FeaturesICLClient | FeaturePCONFIG | FeatureWBNOINVD;
158static constexpr FeatureBitset FeaturesTigerlake =
159 FeaturesICLClient | FeatureAVX512VP2INTERSECT | FeatureMOVDIR64B |
160 FeatureMOVDIRI | FeatureSHSTK;
161
162// Intel Atom processors.
163// Bonnell has feature parity with Core2 and adds MOVBE.
164static constexpr FeatureBitset FeaturesBonnell = FeaturesCore2 | FeatureMOVBE;
165// Silvermont has parity with Westmere and Bonnell plus PRFCHW and RDRND.
166static constexpr FeatureBitset FeaturesSilvermont =
167 FeaturesBonnell | FeaturesWestmere | FeaturePRFCHW | FeatureRDRND;
168static constexpr FeatureBitset FeaturesGoldmont =
169 FeaturesSilvermont | FeatureAES | FeatureCLFLUSHOPT | FeatureFSGSBASE |
170 FeatureRDSEED | FeatureSHA | FeatureXSAVE | FeatureXSAVEC |
171 FeatureXSAVEOPT | FeatureXSAVES;
172static constexpr FeatureBitset FeaturesGoldmontPlus =
173 FeaturesGoldmont | FeaturePTWRITE | FeatureRDPID | FeatureSGX;
174static constexpr FeatureBitset FeaturesTremont =
175 FeaturesGoldmontPlus | FeatureCLWB | FeatureGFNI;
176
177// Geode Processor.
178static constexpr FeatureBitset FeaturesGeode =
179 FeatureX87 | FeatureCMPXCHG8B | FeatureMMX | Feature3DNOW | Feature3DNOWA;
180
181// K6 processor.
182static constexpr FeatureBitset FeaturesK6 =
183 FeatureX87 | FeatureCMPXCHG8B | FeatureMMX;
184
185// K7 and K8 architecture processors.
186static constexpr FeatureBitset FeaturesAthlon =
187 FeatureX87 | FeatureCMPXCHG8B | FeatureMMX | Feature3DNOW | Feature3DNOWA;
188static constexpr FeatureBitset FeaturesAthlonXP =
189 FeaturesAthlon | FeatureFXSR | FeatureSSE;
190static constexpr FeatureBitset FeaturesK8 =
191 FeaturesAthlonXP | FeatureSSE2 | FeatureEM64T;
192static constexpr FeatureBitset FeaturesK8SSE3 = FeaturesK8 | FeatureSSE3;
193static constexpr FeatureBitset FeaturesAMDFAM10 =
194 FeaturesK8SSE3 | FeatureCMPXCHG16B | FeatureLZCNT | FeaturePOPCNT |
195 FeaturePRFCHW | FeatureSAHF | FeatureSSE4A;
196
197// Bobcat architecture processors.
198static constexpr FeatureBitset FeaturesBTVER1 =
199 FeatureX87 | FeatureCMPXCHG8B | FeatureCMPXCHG16B | FeatureEM64T |
200 FeatureFXSR | FeatureLZCNT | FeatureMMX | FeaturePOPCNT | FeaturePRFCHW |
201 FeatureSSE | FeatureSSE2 | FeatureSSE3 | FeatureSSSE3 | FeatureSSE4A |
202 FeatureSAHF;
203static constexpr FeatureBitset FeaturesBTVER2 =
204 FeaturesBTVER1 | FeatureAES | FeatureAVX | FeatureBMI | FeatureF16C |
205 FeatureMOVBE | FeaturePCLMUL | FeatureXSAVE | FeatureXSAVEOPT;
206
207// AMD Bulldozer architecture processors.
208static constexpr FeatureBitset FeaturesBDVER1 =
209 FeatureX87 | FeatureAES | FeatureAVX | FeatureCMPXCHG8B |
210 FeatureCMPXCHG16B | FeatureEM64T | FeatureFMA4 | FeatureFXSR |
211 FeatureLZCNT | FeatureLWP | FeatureLZCNT | FeatureMMX | FeaturePCLMUL |
212 FeaturePOPCNT | FeaturePRFCHW | FeatureSAHF | FeatureSSE | FeatureSSE2 |
213 FeatureSSE3 | FeatureSSSE3 | FeatureSSE4_1 | FeatureSSE4_2 | FeatureSSE4A |
214 FeatureXOP | FeatureXSAVE;
215static constexpr FeatureBitset FeaturesBDVER2 =
216 FeaturesBDVER1 | FeatureBMI | FeatureFMA | FeatureF16C | FeatureTBM;
217static constexpr FeatureBitset FeaturesBDVER3 =
218 FeaturesBDVER2 | FeatureFSGSBASE | FeatureXSAVEOPT;
219static constexpr FeatureBitset FeaturesBDVER4 =
220 FeaturesBDVER3 | FeatureAVX2 | FeatureBMI2 | FeatureMOVBE | FeatureMWAITX |
221 FeatureRDRND;
222
223// AMD Zen architecture processors.
224static constexpr FeatureBitset FeaturesZNVER1 =
225 FeatureX87 | FeatureADX | FeatureAES | FeatureAVX | FeatureAVX2 |
226 FeatureBMI | FeatureBMI2 | FeatureCLFLUSHOPT | FeatureCLZERO |
227 FeatureCMPXCHG8B | FeatureCMPXCHG16B | FeatureEM64T | FeatureF16C |
228 FeatureFMA | FeatureFSGSBASE | FeatureFXSR | FeatureLZCNT | FeatureLWP |
229 FeatureLZCNT | FeatureMOVBE | FeatureMMX | FeatureMWAITX | FeaturePCLMUL |
230 FeaturePOPCNT | FeaturePRFCHW | FeatureRDRND | FeatureRDSEED | FeatureSAHF |
231 FeatureSHA | FeatureSSE | FeatureSSE2 | FeatureSSE3 | FeatureSSSE3 |
232 FeatureSSE4_1 | FeatureSSE4_2 | FeatureSSE4A | FeatureXSAVE |
233 FeatureXSAVEC | FeatureXSAVEOPT | FeatureXSAVES;
234static constexpr FeatureBitset FeaturesZNVER2 =
235 FeaturesZNVER1 | FeatureCLWB | FeatureRDPID | FeatureWBNOINVD;
Craig Topper8dc92142020-06-24 10:36:02 -0700236
237static constexpr ProcInfo Processors[] = {
Craig Topper35379392020-06-30 11:59:03 -0700238 // Empty processor. Include X87 and CMPXCHG8 for backwards compatibility.
239 { {""}, CK_None, ~0U, FeatureX87 | FeatureCMPXCHG8B },
Craig Topper8dc92142020-06-24 10:36:02 -0700240 // i386-generation processors.
Craig Topper35379392020-06-30 11:59:03 -0700241 { {"i386"}, CK_i386, ~0U, FeatureX87 },
Craig Topper8dc92142020-06-24 10:36:02 -0700242 // i486-generation processors.
Craig Topper35379392020-06-30 11:59:03 -0700243 { {"i486"}, CK_i486, ~0U, FeatureX87 },
244 { {"winchip-c6"}, CK_WinChipC6, ~0U, FeaturesPentiumMMX },
245 { {"winchip2"}, CK_WinChip2, ~0U, FeaturesPentiumMMX | Feature3DNOW },
246 { {"c3"}, CK_C3, ~0U, FeaturesPentiumMMX | Feature3DNOW },
Craig Topper8dc92142020-06-24 10:36:02 -0700247 // i586-generation processors, P5 microarchitecture based.
Craig Topper35379392020-06-30 11:59:03 -0700248 { {"i586"}, CK_i586, ~0U, FeatureX87 | FeatureCMPXCHG8B },
249 { {"pentium"}, CK_Pentium, ~0U, FeatureX87 | FeatureCMPXCHG8B },
250 { {"pentium-mmx"}, CK_PentiumMMX, ~0U, FeaturesPentiumMMX },
Craig Topper8dc92142020-06-24 10:36:02 -0700251 // i686-generation processors, P6 / Pentium M microarchitecture based.
Craig Topper35379392020-06-30 11:59:03 -0700252 { {"pentiumpro"}, CK_PentiumPro, ~0U, FeatureX87 | FeatureCMPXCHG8B },
253 { {"i686"}, CK_i686, ~0U, FeatureX87 | FeatureCMPXCHG8B },
254 { {"pentium2"}, CK_Pentium2, ~0U, FeaturesPentium2 },
255 { {"pentium3"}, CK_Pentium3, ~0U, FeaturesPentium3 },
256 { {"pentium3m"}, CK_Pentium3, ~0U, FeaturesPentium3 },
257 { {"pentium-m"}, CK_PentiumM, ~0U, FeaturesPentium4 },
258 { {"c3-2"}, CK_C3_2, ~0U, FeaturesPentium3 },
259 { {"yonah"}, CK_Yonah, ~0U, FeaturesPrescott },
Craig Topper8dc92142020-06-24 10:36:02 -0700260 // Netburst microarchitecture based processors.
Craig Topper35379392020-06-30 11:59:03 -0700261 { {"pentium4"}, CK_Pentium4, ~0U, FeaturesPentium4 },
262 { {"pentium4m"}, CK_Pentium4, ~0U, FeaturesPentium4 },
263 { {"prescott"}, CK_Prescott, ~0U, FeaturesPrescott },
264 { {"nocona"}, CK_Nocona, ~0U, FeaturesNocona },
Craig Topper8dc92142020-06-24 10:36:02 -0700265 // Core microarchitecture based processors.
Craig Topper35379392020-06-30 11:59:03 -0700266 { {"core2"}, CK_Core2, ~0U, FeaturesCore2 },
267 { {"penryn"}, CK_Penryn, ~0U, FeaturesPenryn },
Craig Topper8dc92142020-06-24 10:36:02 -0700268 // Atom processors
Craig Topper35379392020-06-30 11:59:03 -0700269 { {"bonnell"}, CK_Bonnell, FEATURE_SSSE3, FeaturesBonnell },
270 { {"atom"}, CK_Bonnell, FEATURE_SSSE3, FeaturesBonnell },
271 { {"silvermont"}, CK_Silvermont, FEATURE_SSE4_2, FeaturesSilvermont },
272 { {"slm"}, CK_Silvermont, FEATURE_SSE4_2, FeaturesSilvermont },
273 { {"goldmont"}, CK_Goldmont, FEATURE_SSE4_2, FeaturesGoldmont },
274 { {"goldmont-plus"}, CK_GoldmontPlus, FEATURE_SSE4_2, FeaturesGoldmontPlus },
275 { {"tremont"}, CK_Tremont, FEATURE_SSE4_2, FeaturesTremont },
Craig Topper8dc92142020-06-24 10:36:02 -0700276 // Nehalem microarchitecture based processors.
Craig Topper35379392020-06-30 11:59:03 -0700277 { {"nehalem"}, CK_Nehalem, FEATURE_SSE4_2, FeaturesNehalem },
278 { {"corei7"}, CK_Nehalem, FEATURE_SSE4_2, FeaturesNehalem },
Craig Topper8dc92142020-06-24 10:36:02 -0700279 // Westmere microarchitecture based processors.
Craig Topper35379392020-06-30 11:59:03 -0700280 { {"westmere"}, CK_Westmere, FEATURE_PCLMUL, FeaturesWestmere },
Craig Topper8dc92142020-06-24 10:36:02 -0700281 // Sandy Bridge microarchitecture based processors.
Craig Topper35379392020-06-30 11:59:03 -0700282 { {"sandybridge"}, CK_SandyBridge, FEATURE_AVX, FeaturesSandyBridge },
283 { {"corei7-avx"}, CK_SandyBridge, FEATURE_AVX, FeaturesSandyBridge },
Craig Topper8dc92142020-06-24 10:36:02 -0700284 // Ivy Bridge microarchitecture based processors.
Craig Topper35379392020-06-30 11:59:03 -0700285 { {"ivybridge"}, CK_IvyBridge, FEATURE_AVX, FeaturesIvyBridge },
286 { {"core-avx-i"}, CK_IvyBridge, FEATURE_AVX, FeaturesIvyBridge },
Craig Topper8dc92142020-06-24 10:36:02 -0700287 // Haswell microarchitecture based processors.
Craig Topper35379392020-06-30 11:59:03 -0700288 { {"haswell"}, CK_Haswell, FEATURE_AVX2, FeaturesHaswell },
289 { {"core-avx2"}, CK_Haswell, FEATURE_AVX2, FeaturesHaswell },
Craig Topper8dc92142020-06-24 10:36:02 -0700290 // Broadwell microarchitecture based processors.
Craig Topper35379392020-06-30 11:59:03 -0700291 { {"broadwell"}, CK_Broadwell, FEATURE_AVX2, FeaturesBroadwell },
Craig Topper8dc92142020-06-24 10:36:02 -0700292 // Skylake client microarchitecture based processors.
Craig Topper35379392020-06-30 11:59:03 -0700293 { {"skylake"}, CK_SkylakeClient, FEATURE_AVX2, FeaturesSkylakeClient },
Craig Topper8dc92142020-06-24 10:36:02 -0700294 // Skylake server microarchitecture based processors.
Craig Topper35379392020-06-30 11:59:03 -0700295 { {"skylake-avx512"}, CK_SkylakeServer, FEATURE_AVX512F, FeaturesSkylakeServer },
296 { {"skx"}, CK_SkylakeServer, FEATURE_AVX512F, FeaturesSkylakeServer },
Craig Topper8dc92142020-06-24 10:36:02 -0700297 // Cascadelake Server microarchitecture based processors.
Craig Topper35379392020-06-30 11:59:03 -0700298 { {"cascadelake"}, CK_Cascadelake, FEATURE_AVX512VNNI, FeaturesCascadeLake },
Craig Topper8dc92142020-06-24 10:36:02 -0700299 // Cooperlake Server microarchitecture based processors.
Craig Topper35379392020-06-30 11:59:03 -0700300 { {"cooperlake"}, CK_Cooperlake, FEATURE_AVX512BF16, FeaturesCooperLake },
Craig Topper8dc92142020-06-24 10:36:02 -0700301 // Cannonlake client microarchitecture based processors.
Craig Topper35379392020-06-30 11:59:03 -0700302 { {"cannonlake"}, CK_Cannonlake, FEATURE_AVX512VBMI, FeaturesCannonlake },
Craig Topper8dc92142020-06-24 10:36:02 -0700303 // Icelake client microarchitecture based processors.
Craig Topper35379392020-06-30 11:59:03 -0700304 { {"icelake-client"}, CK_IcelakeClient, FEATURE_AVX512VBMI2, FeaturesICLClient },
Craig Topper8dc92142020-06-24 10:36:02 -0700305 // Icelake server microarchitecture based processors.
Craig Topper35379392020-06-30 11:59:03 -0700306 { {"icelake-server"}, CK_IcelakeServer, FEATURE_AVX512VBMI2, FeaturesICLServer },
Craig Topper8dc92142020-06-24 10:36:02 -0700307 // Tigerlake microarchitecture based processors.
Craig Topper35379392020-06-30 11:59:03 -0700308 { {"tigerlake"}, CK_Tigerlake, FEATURE_AVX512VP2INTERSECT, FeaturesTigerlake },
Craig Topper8dc92142020-06-24 10:36:02 -0700309 // Knights Landing processor.
Craig Topper35379392020-06-30 11:59:03 -0700310 { {"knl"}, CK_KNL, FEATURE_AVX512F, FeaturesKNL },
Craig Topper8dc92142020-06-24 10:36:02 -0700311 // Knights Mill processor.
Craig Topper35379392020-06-30 11:59:03 -0700312 { {"knm"}, CK_KNM, FEATURE_AVX5124FMAPS, FeaturesKNM },
Craig Topper8dc92142020-06-24 10:36:02 -0700313 // Lakemont microarchitecture based processors.
Craig Topper35379392020-06-30 11:59:03 -0700314 { {"lakemont"}, CK_Lakemont, ~0U, FeatureCMPXCHG8B },
Craig Topper8dc92142020-06-24 10:36:02 -0700315 // K6 architecture processors.
Craig Topper35379392020-06-30 11:59:03 -0700316 { {"k6"}, CK_K6, ~0U, FeaturesK6 },
317 { {"k6-2"}, CK_K6_2, ~0U, FeaturesK6 | Feature3DNOW },
318 { {"k6-3"}, CK_K6_3, ~0U, FeaturesK6 | Feature3DNOW },
Craig Topper8dc92142020-06-24 10:36:02 -0700319 // K7 architecture processors.
Craig Topper35379392020-06-30 11:59:03 -0700320 { {"athlon"}, CK_Athlon, ~0U, FeaturesAthlon },
321 { {"athlon-tbird"}, CK_Athlon, ~0U, FeaturesAthlon },
322 { {"athlon-xp"}, CK_AthlonXP, ~0U, FeaturesAthlonXP },
323 { {"athlon-mp"}, CK_AthlonXP, ~0U, FeaturesAthlonXP },
324 { {"athlon-4"}, CK_AthlonXP, ~0U, FeaturesAthlonXP },
Craig Topper8dc92142020-06-24 10:36:02 -0700325 // K8 architecture processors.
Craig Topper35379392020-06-30 11:59:03 -0700326 { {"k8"}, CK_K8, ~0U, FeaturesK8 },
327 { {"athlon64"}, CK_K8, ~0U, FeaturesK8 },
328 { {"athlon-fx"}, CK_K8, ~0U, FeaturesK8 },
329 { {"opteron"}, CK_K8, ~0U, FeaturesK8 },
330 { {"k8-sse3"}, CK_K8SSE3, ~0U, FeaturesK8SSE3 },
331 { {"athlon64-sse3"}, CK_K8SSE3, ~0U, FeaturesK8SSE3 },
332 { {"opteron-sse3"}, CK_K8SSE3, ~0U, FeaturesK8SSE3 },
333 { {"amdfam10"}, CK_AMDFAM10, FEATURE_SSE4_A, FeaturesAMDFAM10 },
334 { {"barcelona"}, CK_AMDFAM10, FEATURE_SSE4_A, FeaturesAMDFAM10 },
Craig Topper8dc92142020-06-24 10:36:02 -0700335 // Bobcat architecture processors.
Craig Topper35379392020-06-30 11:59:03 -0700336 { {"btver1"}, CK_BTVER1, FEATURE_SSE4_A, FeaturesBTVER1 },
337 { {"btver2"}, CK_BTVER2, FEATURE_BMI, FeaturesBTVER2 },
Craig Topper8dc92142020-06-24 10:36:02 -0700338 // Bulldozer architecture processors.
Craig Topper35379392020-06-30 11:59:03 -0700339 { {"bdver1"}, CK_BDVER1, FEATURE_XOP, FeaturesBDVER1 },
340 { {"bdver2"}, CK_BDVER2, FEATURE_FMA, FeaturesBDVER2 },
341 { {"bdver3"}, CK_BDVER3, FEATURE_FMA, FeaturesBDVER3 },
342 { {"bdver4"}, CK_BDVER4, FEATURE_AVX2, FeaturesBDVER4 },
Craig Topper8dc92142020-06-24 10:36:02 -0700343 // Zen architecture processors.
Craig Topper35379392020-06-30 11:59:03 -0700344 { {"znver1"}, CK_ZNVER1, FEATURE_AVX2, FeaturesZNVER1 },
345 { {"znver2"}, CK_ZNVER2, FEATURE_AVX2, FeaturesZNVER2 },
Craig Topper8dc92142020-06-24 10:36:02 -0700346 // Generic 64-bit processor.
Craig Topper35379392020-06-30 11:59:03 -0700347 { {"x86-64"}, CK_x86_64, ~0U, FeaturesX86_64 },
Craig Topper8dc92142020-06-24 10:36:02 -0700348 // Geode processors.
Craig Topper35379392020-06-30 11:59:03 -0700349 { {"geode"}, CK_Geode, ~0U, FeaturesGeode },
Craig Topper8dc92142020-06-24 10:36:02 -0700350};
Craig Topperd5c28c42020-06-09 12:18:08 -0700351
352X86::CPUKind llvm::X86::parseArchX86(StringRef CPU, bool Only64Bit) {
Craig Topper8dc92142020-06-24 10:36:02 -0700353 for (const auto &P : Processors)
Craig Topper35379392020-06-30 11:59:03 -0700354 if (P.Name == CPU && (P.Features[FEATURE_EM64T] || !Only64Bit))
Craig Topper8dc92142020-06-24 10:36:02 -0700355 return P.Kind;
Craig Topperd5c28c42020-06-09 12:18:08 -0700356
Craig Topper8dc92142020-06-24 10:36:02 -0700357 return CK_None;
Craig Topperd5c28c42020-06-09 12:18:08 -0700358}
359
360void llvm::X86::fillValidCPUArchList(SmallVectorImpl<StringRef> &Values,
361 bool Only64Bit) {
Craig Topper8dc92142020-06-24 10:36:02 -0700362 for (const auto &P : Processors)
Craig Topper35379392020-06-30 11:59:03 -0700363 if (!P.Name.empty() && (P.Features[FEATURE_EM64T] || !Only64Bit))
Craig Topper8dc92142020-06-24 10:36:02 -0700364 Values.emplace_back(P.Name);
365}
366
367ProcessorFeatures llvm::X86::getKeyFeature(X86::CPUKind Kind) {
368 // FIXME: Can we avoid a linear search here? The table might be sorted by
369 // CPUKind so we could binary search?
370 for (const auto &P : Processors) {
371 if (P.Kind == Kind) {
372 assert(P.KeyFeature != ~0U && "Processor does not have a key feature.");
373 return static_cast<ProcessorFeatures>(P.KeyFeature);
374 }
375 }
376
377 llvm_unreachable("Unable to find CPU kind!");
Craig Topperd5c28c42020-06-09 12:18:08 -0700378}
Craig Topper35379392020-06-30 11:59:03 -0700379
380static const char *FeatureStrings[X86::CPU_FEATURE_MAX] = {
381#define X86_FEATURE(ENUM, STR) STR,
382#include "llvm/Support/X86TargetParser.def"
383};
384
385void llvm::X86::getFeaturesForCPU(StringRef CPU,
386 SmallVectorImpl<StringRef> &Features) {
387 auto I = llvm::find_if(Processors,
388 [&](const ProcInfo &P) { return P.Name == CPU; });
389 assert(I != std::end(Processors) && "Processor not found!");
390
391 // Add the string version of all set bits.
392 for (unsigned i = 0; i != CPU_FEATURE_MAX; ++i)
393 if (FeatureStrings[i] && I->Features[i])
394 Features.push_back(FeatureStrings[i]);
395}