1 //===-- 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 
17 using namespace llvm;
18 using namespace llvm::X86;
19 
20 namespace {
21 
22 /// 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.
26 class 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 
33 public:
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 
73 struct ProcInfo {
74   StringLiteral Name;
75   X86::CPUKind Kind;
76   unsigned KeyFeature;
77   FeatureBitset Features;
78 };
79 
80 } // end anonymous namespace
81 
82 #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.
87 static constexpr FeatureBitset FeaturesPentiumMMX =
88     FeatureX87 | FeatureCMPXCHG8B | FeatureMMX;
89 
90 // Pentium 2 and 3.
91 static constexpr FeatureBitset FeaturesPentium2 =
92     FeatureX87 | FeatureCMPXCHG8B | FeatureMMX | FeatureFXSR;
93 static constexpr FeatureBitset FeaturesPentium3 = FeaturesPentium2 | FeatureSSE;
94 
95 // Pentium 4 CPUs
96 static constexpr FeatureBitset FeaturesPentium4 =
97     FeaturesPentium3 | FeatureSSE2;
98 static constexpr FeatureBitset FeaturesPrescott =
99     FeaturesPentium4 | FeatureSSE3;
100 static constexpr FeatureBitset FeaturesNocona =
101     FeaturesPrescott | FeatureEM64T | FeatureCMPXCHG16B;
102 
103 // Basic 64-bit capable CPU.
104 static constexpr FeatureBitset FeaturesX86_64 = FeaturesPentium4 | FeatureEM64T;
105 
106 // Intel Core CPUs
107 static constexpr FeatureBitset FeaturesCore2 =
108     FeaturesNocona | FeatureSAHF | FeatureSSSE3;
109 static constexpr FeatureBitset FeaturesPenryn = FeaturesCore2 | FeatureSSE4_1;
110 static constexpr FeatureBitset FeaturesNehalem =
111     FeaturesPenryn | FeaturePOPCNT | FeatureSSE4_2;
112 static constexpr FeatureBitset FeaturesWestmere =
113     FeaturesNehalem | FeaturePCLMUL;
114 static constexpr FeatureBitset FeaturesSandyBridge =
115     FeaturesWestmere | FeatureAVX | FeatureXSAVE | FeatureXSAVEOPT;
116 static constexpr FeatureBitset FeaturesIvyBridge =
117     FeaturesSandyBridge | FeatureF16C | FeatureFSGSBASE | FeatureRDRND;
118 static constexpr FeatureBitset FeaturesHaswell =
119     FeaturesIvyBridge | FeatureAVX2 | FeatureBMI | FeatureBMI2 | FeatureFMA |
120     FeatureINVPCID | FeatureLZCNT | FeatureMOVBE;
121 static constexpr FeatureBitset FeaturesBroadwell =
122     FeaturesHaswell | FeatureADX | FeaturePRFCHW | FeatureRDSEED;
123 
124 // Intel Knights Landing and Knights Mill
125 // Knights Landing has feature parity with Broadwell.
126 static constexpr FeatureBitset FeaturesKNL =
127     FeaturesBroadwell | FeatureAES | FeatureAVX512F | FeatureAVX512CD |
128     FeatureAVX512ER | FeatureAVX512PF | FeaturePREFETCHWT1;
129 static constexpr FeatureBitset FeaturesKNM =
130     FeaturesKNL | FeatureAVX512VPOPCNTDQ;
131 
132 // Intel Skylake processors.
133 static 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.
138 static constexpr FeatureBitset FeaturesSkylakeServer =
139     (FeaturesSkylakeClient & ~FeatureSGX) | FeatureAVX512F | FeatureAVX512CD |
140     FeatureAVX512DQ | FeatureAVX512BW | FeatureAVX512VL | FeatureCLWB |
141     FeaturePKU;
142 static constexpr FeatureBitset FeaturesCascadeLake =
143     FeaturesSkylakeServer | FeatureAVX512VNNI;
144 static constexpr FeatureBitset FeaturesCooperLake =
145     FeaturesCascadeLake | FeatureAVX512BF16;
146 
147 // Intel 10nm processors.
148 static constexpr FeatureBitset FeaturesCannonlake =
149     FeaturesSkylakeClient | FeatureAVX512F | FeatureAVX512CD | FeatureAVX512DQ |
150     FeatureAVX512BW | FeatureAVX512VL | FeatureAVX512IFMA | FeatureAVX512VBMI |
151     FeaturePKU | FeatureSHA;
152 static constexpr FeatureBitset FeaturesICLClient =
153     FeaturesCannonlake | FeatureAVX512BITALG | FeatureAVX512VBMI2 |
154     FeatureAVX512VNNI | FeatureAVX512VPOPCNTDQ | FeatureCLWB | FeatureGFNI |
155     FeatureRDPID | FeatureVAES | FeatureVPCLMULQDQ;
156 static constexpr FeatureBitset FeaturesICLServer =
157     FeaturesICLClient | FeaturePCONFIG | FeatureWBNOINVD;
158 static 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.
164 static constexpr FeatureBitset FeaturesBonnell = FeaturesCore2 | FeatureMOVBE;
165 // Silvermont has parity with Westmere and Bonnell plus PRFCHW and RDRND.
166 static constexpr FeatureBitset FeaturesSilvermont =
167     FeaturesBonnell | FeaturesWestmere | FeaturePRFCHW | FeatureRDRND;
168 static constexpr FeatureBitset FeaturesGoldmont =
169     FeaturesSilvermont | FeatureAES | FeatureCLFLUSHOPT | FeatureFSGSBASE |
170     FeatureRDSEED | FeatureSHA | FeatureXSAVE | FeatureXSAVEC |
171     FeatureXSAVEOPT | FeatureXSAVES;
172 static constexpr FeatureBitset FeaturesGoldmontPlus =
173     FeaturesGoldmont | FeaturePTWRITE | FeatureRDPID | FeatureSGX;
174 static constexpr FeatureBitset FeaturesTremont =
175     FeaturesGoldmontPlus | FeatureCLWB | FeatureGFNI;
176 
177 // Geode Processor.
178 static constexpr FeatureBitset FeaturesGeode =
179     FeatureX87 | FeatureCMPXCHG8B | FeatureMMX | Feature3DNOW | Feature3DNOWA;
180 
181 // K6 processor.
182 static constexpr FeatureBitset FeaturesK6 =
183     FeatureX87 | FeatureCMPXCHG8B | FeatureMMX;
184 
185 // K7 and K8 architecture processors.
186 static constexpr FeatureBitset FeaturesAthlon =
187     FeatureX87 | FeatureCMPXCHG8B | FeatureMMX | Feature3DNOW | Feature3DNOWA;
188 static constexpr FeatureBitset FeaturesAthlonXP =
189     FeaturesAthlon | FeatureFXSR | FeatureSSE;
190 static constexpr FeatureBitset FeaturesK8 =
191     FeaturesAthlonXP | FeatureSSE2 | FeatureEM64T;
192 static constexpr FeatureBitset FeaturesK8SSE3 = FeaturesK8 | FeatureSSE3;
193 static constexpr FeatureBitset FeaturesAMDFAM10 =
194     FeaturesK8SSE3 | FeatureCMPXCHG16B | FeatureLZCNT | FeaturePOPCNT |
195     FeaturePRFCHW | FeatureSAHF | FeatureSSE4A;
196 
197 // Bobcat architecture processors.
198 static constexpr FeatureBitset FeaturesBTVER1 =
199     FeatureX87 | FeatureCMPXCHG8B | FeatureCMPXCHG16B | FeatureEM64T |
200     FeatureFXSR | FeatureLZCNT | FeatureMMX | FeaturePOPCNT | FeaturePRFCHW |
201     FeatureSSE | FeatureSSE2 | FeatureSSE3 | FeatureSSSE3 | FeatureSSE4A |
202     FeatureSAHF;
203 static constexpr FeatureBitset FeaturesBTVER2 =
204     FeaturesBTVER1 | FeatureAES | FeatureAVX | FeatureBMI | FeatureF16C |
205     FeatureMOVBE | FeaturePCLMUL | FeatureXSAVE | FeatureXSAVEOPT;
206 
207 // AMD Bulldozer architecture processors.
208 static constexpr FeatureBitset FeaturesBDVER1 =
209     FeatureX87 | FeatureAES | FeatureAVX | FeatureCMPXCHG8B |
210     FeatureCMPXCHG16B | FeatureEM64T | FeatureFMA4 | FeatureFXSR | FeatureLWP |
211     FeatureLZCNT | FeatureMMX | FeaturePCLMUL | FeaturePOPCNT | FeaturePRFCHW |
212     FeatureSAHF | FeatureSSE | FeatureSSE2 | FeatureSSE3 | FeatureSSSE3 |
213     FeatureSSE4_1 | FeatureSSE4_2 | FeatureSSE4A | FeatureXOP | FeatureXSAVE;
214 static constexpr FeatureBitset FeaturesBDVER2 =
215     FeaturesBDVER1 | FeatureBMI | FeatureFMA | FeatureF16C | FeatureTBM;
216 static constexpr FeatureBitset FeaturesBDVER3 =
217     FeaturesBDVER2 | FeatureFSGSBASE | FeatureXSAVEOPT;
218 static constexpr FeatureBitset FeaturesBDVER4 =
219     FeaturesBDVER3 | FeatureAVX2 | FeatureBMI2 | FeatureMOVBE | FeatureMWAITX |
220     FeatureRDRND;
221 
222 // AMD Zen architecture processors.
223 static constexpr FeatureBitset FeaturesZNVER1 =
224     FeatureX87 | FeatureADX | FeatureAES | FeatureAVX | FeatureAVX2 |
225     FeatureBMI | FeatureBMI2 | FeatureCLFLUSHOPT | FeatureCLZERO |
226     FeatureCMPXCHG8B | FeatureCMPXCHG16B | FeatureEM64T | FeatureF16C |
227     FeatureFMA | FeatureFSGSBASE | FeatureFXSR | FeatureLZCNT | FeatureMMX |
228     FeatureMOVBE | FeatureMWAITX | FeaturePCLMUL | FeaturePOPCNT |
229     FeaturePRFCHW | FeatureRDRND | FeatureRDSEED | FeatureSAHF | FeatureSHA |
230     FeatureSSE | FeatureSSE2 | FeatureSSE3 | FeatureSSSE3 | FeatureSSE4_1 |
231     FeatureSSE4_2 | FeatureSSE4A | FeatureXSAVE | FeatureXSAVEC |
232     FeatureXSAVEOPT | FeatureXSAVES;
233 static constexpr FeatureBitset FeaturesZNVER2 =
234     FeaturesZNVER1 | FeatureCLWB | FeatureRDPID | FeatureWBNOINVD;
235 
236 static constexpr ProcInfo Processors[] = {
237   // Empty processor. Include X87 and CMPXCHG8 for backwards compatibility.
238   { {""}, CK_None, ~0U, FeatureX87 | FeatureCMPXCHG8B },
239   // i386-generation processors.
240   { {"i386"}, CK_i386, ~0U, FeatureX87 },
241   // i486-generation processors.
242   { {"i486"}, CK_i486, ~0U, FeatureX87 },
243   { {"winchip-c6"}, CK_WinChipC6, ~0U, FeaturesPentiumMMX },
244   { {"winchip2"}, CK_WinChip2, ~0U, FeaturesPentiumMMX | Feature3DNOW },
245   { {"c3"}, CK_C3, ~0U, FeaturesPentiumMMX | Feature3DNOW },
246   // i586-generation processors, P5 microarchitecture based.
247   { {"i586"}, CK_i586, ~0U, FeatureX87 | FeatureCMPXCHG8B },
248   { {"pentium"}, CK_Pentium, ~0U, FeatureX87 | FeatureCMPXCHG8B },
249   { {"pentium-mmx"}, CK_PentiumMMX, ~0U, FeaturesPentiumMMX },
250   // i686-generation processors, P6 / Pentium M microarchitecture based.
251   { {"pentiumpro"}, CK_PentiumPro, ~0U, FeatureX87 | FeatureCMPXCHG8B },
252   { {"i686"}, CK_i686, ~0U, FeatureX87 | FeatureCMPXCHG8B },
253   { {"pentium2"}, CK_Pentium2, ~0U, FeaturesPentium2 },
254   { {"pentium3"}, CK_Pentium3, ~0U, FeaturesPentium3 },
255   { {"pentium3m"}, CK_Pentium3, ~0U, FeaturesPentium3 },
256   { {"pentium-m"}, CK_PentiumM, ~0U, FeaturesPentium4 },
257   { {"c3-2"}, CK_C3_2, ~0U, FeaturesPentium3 },
258   { {"yonah"}, CK_Yonah, ~0U, FeaturesPrescott },
259   // Netburst microarchitecture based processors.
260   { {"pentium4"}, CK_Pentium4, ~0U, FeaturesPentium4 },
261   { {"pentium4m"}, CK_Pentium4, ~0U, FeaturesPentium4 },
262   { {"prescott"}, CK_Prescott, ~0U, FeaturesPrescott },
263   { {"nocona"}, CK_Nocona, ~0U, FeaturesNocona },
264   // Core microarchitecture based processors.
265   { {"core2"}, CK_Core2, ~0U, FeaturesCore2 },
266   { {"penryn"}, CK_Penryn, ~0U, FeaturesPenryn },
267   // Atom processors
268   { {"bonnell"}, CK_Bonnell, FEATURE_SSSE3, FeaturesBonnell },
269   { {"atom"}, CK_Bonnell, FEATURE_SSSE3, FeaturesBonnell },
270   { {"silvermont"}, CK_Silvermont, FEATURE_SSE4_2, FeaturesSilvermont },
271   { {"slm"}, CK_Silvermont, FEATURE_SSE4_2, FeaturesSilvermont },
272   { {"goldmont"}, CK_Goldmont, FEATURE_SSE4_2, FeaturesGoldmont },
273   { {"goldmont-plus"}, CK_GoldmontPlus, FEATURE_SSE4_2, FeaturesGoldmontPlus },
274   { {"tremont"}, CK_Tremont, FEATURE_SSE4_2, FeaturesTremont },
275   // Nehalem microarchitecture based processors.
276   { {"nehalem"}, CK_Nehalem, FEATURE_SSE4_2, FeaturesNehalem },
277   { {"corei7"}, CK_Nehalem, FEATURE_SSE4_2, FeaturesNehalem },
278   // Westmere microarchitecture based processors.
279   { {"westmere"}, CK_Westmere, FEATURE_PCLMUL, FeaturesWestmere },
280   // Sandy Bridge microarchitecture based processors.
281   { {"sandybridge"}, CK_SandyBridge, FEATURE_AVX, FeaturesSandyBridge },
282   { {"corei7-avx"}, CK_SandyBridge, FEATURE_AVX, FeaturesSandyBridge },
283   // Ivy Bridge microarchitecture based processors.
284   { {"ivybridge"}, CK_IvyBridge, FEATURE_AVX, FeaturesIvyBridge },
285   { {"core-avx-i"}, CK_IvyBridge, FEATURE_AVX, FeaturesIvyBridge },
286   // Haswell microarchitecture based processors.
287   { {"haswell"}, CK_Haswell, FEATURE_AVX2, FeaturesHaswell },
288   { {"core-avx2"}, CK_Haswell, FEATURE_AVX2, FeaturesHaswell },
289   // Broadwell microarchitecture based processors.
290   { {"broadwell"}, CK_Broadwell, FEATURE_AVX2, FeaturesBroadwell },
291   // Skylake client microarchitecture based processors.
292   { {"skylake"}, CK_SkylakeClient, FEATURE_AVX2, FeaturesSkylakeClient },
293   // Skylake server microarchitecture based processors.
294   { {"skylake-avx512"}, CK_SkylakeServer, FEATURE_AVX512F, FeaturesSkylakeServer },
295   { {"skx"}, CK_SkylakeServer, FEATURE_AVX512F, FeaturesSkylakeServer },
296   // Cascadelake Server microarchitecture based processors.
297   { {"cascadelake"}, CK_Cascadelake, FEATURE_AVX512VNNI, FeaturesCascadeLake },
298   // Cooperlake Server microarchitecture based processors.
299   { {"cooperlake"}, CK_Cooperlake, FEATURE_AVX512BF16, FeaturesCooperLake },
300   // Cannonlake client microarchitecture based processors.
301   { {"cannonlake"}, CK_Cannonlake, FEATURE_AVX512VBMI, FeaturesCannonlake },
302   // Icelake client microarchitecture based processors.
303   { {"icelake-client"}, CK_IcelakeClient, FEATURE_AVX512VBMI2, FeaturesICLClient },
304   // Icelake server microarchitecture based processors.
305   { {"icelake-server"}, CK_IcelakeServer, FEATURE_AVX512VBMI2, FeaturesICLServer },
306   // Tigerlake microarchitecture based processors.
307   { {"tigerlake"}, CK_Tigerlake, FEATURE_AVX512VP2INTERSECT, FeaturesTigerlake },
308   // Knights Landing processor.
309   { {"knl"}, CK_KNL, FEATURE_AVX512F, FeaturesKNL },
310   // Knights Mill processor.
311   { {"knm"}, CK_KNM, FEATURE_AVX5124FMAPS, FeaturesKNM },
312   // Lakemont microarchitecture based processors.
313   { {"lakemont"}, CK_Lakemont, ~0U, FeatureCMPXCHG8B },
314   // K6 architecture processors.
315   { {"k6"}, CK_K6, ~0U, FeaturesK6 },
316   { {"k6-2"}, CK_K6_2, ~0U, FeaturesK6 | Feature3DNOW },
317   { {"k6-3"}, CK_K6_3, ~0U, FeaturesK6 | Feature3DNOW },
318   // K7 architecture processors.
319   { {"athlon"}, CK_Athlon, ~0U, FeaturesAthlon },
320   { {"athlon-tbird"}, CK_Athlon, ~0U, FeaturesAthlon },
321   { {"athlon-xp"}, CK_AthlonXP, ~0U, FeaturesAthlonXP },
322   { {"athlon-mp"}, CK_AthlonXP, ~0U, FeaturesAthlonXP },
323   { {"athlon-4"}, CK_AthlonXP, ~0U, FeaturesAthlonXP },
324   // K8 architecture processors.
325   { {"k8"}, CK_K8, ~0U, FeaturesK8 },
326   { {"athlon64"}, CK_K8, ~0U, FeaturesK8 },
327   { {"athlon-fx"}, CK_K8, ~0U, FeaturesK8 },
328   { {"opteron"}, CK_K8, ~0U, FeaturesK8 },
329   { {"k8-sse3"}, CK_K8SSE3, ~0U, FeaturesK8SSE3 },
330   { {"athlon64-sse3"}, CK_K8SSE3, ~0U, FeaturesK8SSE3 },
331   { {"opteron-sse3"}, CK_K8SSE3, ~0U, FeaturesK8SSE3 },
332   { {"amdfam10"}, CK_AMDFAM10, FEATURE_SSE4_A, FeaturesAMDFAM10 },
333   { {"barcelona"}, CK_AMDFAM10, FEATURE_SSE4_A, FeaturesAMDFAM10 },
334   // Bobcat architecture processors.
335   { {"btver1"}, CK_BTVER1, FEATURE_SSE4_A, FeaturesBTVER1 },
336   { {"btver2"}, CK_BTVER2, FEATURE_BMI, FeaturesBTVER2 },
337   // Bulldozer architecture processors.
338   { {"bdver1"}, CK_BDVER1, FEATURE_XOP, FeaturesBDVER1 },
339   { {"bdver2"}, CK_BDVER2, FEATURE_FMA, FeaturesBDVER2 },
340   { {"bdver3"}, CK_BDVER3, FEATURE_FMA, FeaturesBDVER3 },
341   { {"bdver4"}, CK_BDVER4, FEATURE_AVX2, FeaturesBDVER4 },
342   // Zen architecture processors.
343   { {"znver1"}, CK_ZNVER1, FEATURE_AVX2, FeaturesZNVER1 },
344   { {"znver2"}, CK_ZNVER2, FEATURE_AVX2, FeaturesZNVER2 },
345   // Generic 64-bit processor.
346   { {"x86-64"}, CK_x86_64, ~0U, FeaturesX86_64 },
347   // Geode processors.
348   { {"geode"}, CK_Geode, ~0U, FeaturesGeode },
349 };
350 
351 X86::CPUKind llvm::X86::parseArchX86(StringRef CPU, bool Only64Bit) {
352   for (const auto &P : Processors)
353     if (P.Name == CPU && (P.Features[FEATURE_EM64T] || !Only64Bit))
354       return P.Kind;
355 
356   return CK_None;
357 }
358 
359 void llvm::X86::fillValidCPUArchList(SmallVectorImpl<StringRef> &Values,
360                                      bool Only64Bit) {
361   for (const auto &P : Processors)
362     if (!P.Name.empty() && (P.Features[FEATURE_EM64T] || !Only64Bit))
363       Values.emplace_back(P.Name);
364 }
365 
366 ProcessorFeatures llvm::X86::getKeyFeature(X86::CPUKind Kind) {
367   // FIXME: Can we avoid a linear search here? The table might be sorted by
368   // CPUKind so we could binary search?
369   for (const auto &P : Processors) {
370     if (P.Kind == Kind) {
371       assert(P.KeyFeature != ~0U && "Processor does not have a key feature.");
372       return static_cast<ProcessorFeatures>(P.KeyFeature);
373     }
374   }
375 
376   llvm_unreachable("Unable to find CPU kind!");
377 }
378 
379 static const char *FeatureStrings[X86::CPU_FEATURE_MAX] = {
380 #define X86_FEATURE(ENUM, STR) STR,
381 #include "llvm/Support/X86TargetParser.def"
382 };
383 
384 void llvm::X86::getFeaturesForCPU(StringRef CPU,
385                                   SmallVectorImpl<StringRef> &Features) {
386   auto I = llvm::find_if(Processors,
387                          [&](const ProcInfo &P) { return P.Name == CPU; });
388   assert(I != std::end(Processors) && "Processor not found!");
389 
390   // Add the string version of all set bits.
391   for (unsigned i = 0; i != CPU_FEATURE_MAX; ++i)
392     if (FeatureStrings[i] && I->Features[i])
393       Features.push_back(FeatureStrings[i]);
394 }
395