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/TargetParser/X86TargetParser.h"
14#include "llvm/ADT/Bitset.h"
15#include "llvm/ADT/StringSwitch.h"
16#include <numeric>
17
18using namespace llvm;
19using namespace llvm::X86;
20
21namespace {
22
23using FeatureBitset = Bitset<X86::CPU_FEATURE_MAX>;
24
25struct ProcInfo {
26 StringLiteral Name;
27 X86::CPUKind Kind;
28 unsigned KeyFeature;
29 FeatureBitset Features;
30 char Mangling;
31 bool OnlyForCPUDispatchSpecific;
32};
33
34struct FeatureInfo {
35 StringLiteral NameWithPlus;
36 FeatureBitset ImpliedFeatures;
37
38 StringRef getName(bool WithPlus = false) const {
39 assert(NameWithPlus[0] == '+' && "Expected string to start with '+'");
40 if (WithPlus)
41 return NameWithPlus;
42 return NameWithPlus.drop_front();
43 }
44};
45
46} // end anonymous namespace
47
48#define X86_FEATURE(ENUM, STRING) \
49 constexpr FeatureBitset Feature##ENUM = {X86::FEATURE_##ENUM};
50#include "llvm/TargetParser/X86TargetParser.def"
51
52// Pentium with MMX.
53constexpr FeatureBitset FeaturesPentiumMMX =
54 FeatureX87 | FeatureCMPXCHG8B | FeatureMMX;
55
56// Pentium 2 and 3.
57constexpr FeatureBitset FeaturesPentium2 =
58 FeatureX87 | FeatureCMPXCHG8B | FeatureMMX | FeatureFXSR | FeatureCMOV;
59constexpr FeatureBitset FeaturesPentium3 = FeaturesPentium2 | FeatureSSE;
60
61// Pentium 4 CPUs
62constexpr FeatureBitset FeaturesPentium4 = FeaturesPentium3 | FeatureSSE2;
63constexpr FeatureBitset FeaturesPrescott = FeaturesPentium4 | FeatureSSE3;
64constexpr FeatureBitset FeaturesNocona =
65 FeaturesPrescott | Feature64BIT | FeatureCMPXCHG16B;
66
67// Basic 64-bit capable CPU.
68constexpr FeatureBitset FeaturesX86_64 = FeaturesPentium4 | Feature64BIT;
69constexpr FeatureBitset FeaturesX86_64_V2 = FeaturesX86_64 | FeatureSAHF |
70 FeaturePOPCNT | FeatureCRC32 |
71 FeatureSSE4_2 | FeatureCMPXCHG16B;
72constexpr FeatureBitset FeaturesX86_64_V3 =
73 FeaturesX86_64_V2 | FeatureAVX2 | FeatureBMI | FeatureBMI2 | FeatureF16C |
74 FeatureFMA | FeatureLZCNT | FeatureMOVBE | FeatureXSAVE;
75constexpr FeatureBitset FeaturesX86_64_V4 = FeaturesX86_64_V3 | FeatureEVEX512 |
76 FeatureAVX512BW | FeatureAVX512CD |
77 FeatureAVX512DQ | FeatureAVX512VL;
78
79// Intel Core CPUs
80constexpr FeatureBitset FeaturesCore2 =
81 FeaturesNocona | FeatureSAHF | FeatureSSSE3;
82constexpr FeatureBitset FeaturesPenryn = FeaturesCore2 | FeatureSSE4_1;
83constexpr FeatureBitset FeaturesNehalem =
84 FeaturesPenryn | FeaturePOPCNT | FeatureCRC32 | FeatureSSE4_2;
85constexpr FeatureBitset FeaturesWestmere = FeaturesNehalem | FeaturePCLMUL;
86constexpr FeatureBitset FeaturesSandyBridge =
87 FeaturesWestmere | FeatureAVX | FeatureXSAVE | FeatureXSAVEOPT;
88constexpr FeatureBitset FeaturesIvyBridge =
89 FeaturesSandyBridge | FeatureF16C | FeatureFSGSBASE | FeatureRDRND;
90constexpr FeatureBitset FeaturesHaswell =
91 FeaturesIvyBridge | FeatureAVX2 | FeatureBMI | FeatureBMI2 | FeatureFMA |
92 FeatureINVPCID | FeatureLZCNT | FeatureMOVBE;
93constexpr FeatureBitset FeaturesBroadwell =
94 FeaturesHaswell | FeatureADX | FeaturePRFCHW | FeatureRDSEED;
95
96// Intel Knights Landing and Knights Mill
97// Knights Landing has feature parity with Broadwell.
98constexpr FeatureBitset FeaturesKNL = FeaturesBroadwell | FeatureAES |
99 FeatureAVX512F | FeatureEVEX512 |
100 FeatureAVX512CD;
101constexpr FeatureBitset FeaturesKNM = FeaturesKNL | FeatureAVX512VPOPCNTDQ;
102
103// Intel Skylake processors.
104constexpr FeatureBitset FeaturesSkylakeClient =
105 FeaturesBroadwell | FeatureAES | FeatureCLFLUSHOPT | FeatureXSAVEC |
106 FeatureXSAVES | FeatureSGX;
107// SkylakeServer inherits all SkylakeClient features except SGX.
108// FIXME: That doesn't match gcc.
109constexpr FeatureBitset FeaturesSkylakeServer =
110 (FeaturesSkylakeClient & ~FeatureSGX) | FeatureAVX512F | FeatureEVEX512 |
111 FeatureAVX512CD | FeatureAVX512DQ | FeatureAVX512BW | FeatureAVX512VL |
112 FeatureCLWB | FeaturePKU;
113constexpr FeatureBitset FeaturesCascadeLake =
114 FeaturesSkylakeServer | FeatureAVX512VNNI;
115constexpr FeatureBitset FeaturesCooperLake =
116 FeaturesCascadeLake | FeatureAVX512BF16;
117
118// Intel 10nm processors.
119constexpr FeatureBitset FeaturesCannonlake =
120 FeaturesSkylakeClient | FeatureAVX512F | FeatureEVEX512 | FeatureAVX512CD |
121 FeatureAVX512DQ | FeatureAVX512BW | FeatureAVX512VL | FeatureAVX512IFMA |
122 FeatureAVX512VBMI | FeaturePKU | FeatureSHA;
123constexpr FeatureBitset FeaturesICLClient =
124 FeaturesCannonlake | FeatureAVX512BITALG | FeatureAVX512VBMI2 |
125 FeatureAVX512VNNI | FeatureAVX512VPOPCNTDQ | FeatureGFNI | FeatureRDPID |
126 FeatureVAES | FeatureVPCLMULQDQ;
127constexpr FeatureBitset FeaturesRocketlake = FeaturesICLClient & ~FeatureSGX;
128constexpr FeatureBitset FeaturesICLServer =
129 FeaturesICLClient | FeatureCLWB | FeaturePCONFIG | FeatureWBNOINVD;
130constexpr FeatureBitset FeaturesTigerlake =
131 FeaturesICLClient | FeatureAVX512VP2INTERSECT | FeatureMOVDIR64B |
132 FeatureCLWB | FeatureMOVDIRI | FeatureSHSTK | FeatureKL | FeatureWIDEKL;
133constexpr FeatureBitset FeaturesSapphireRapids =
134 FeaturesICLServer | FeatureAMX_BF16 | FeatureAMX_INT8 | FeatureAMX_TILE |
135 FeatureAVX512BF16 | FeatureAVX512FP16 | FeatureAVXVNNI | FeatureCLDEMOTE |
136 FeatureENQCMD | FeatureMOVDIR64B | FeatureMOVDIRI | FeaturePTWRITE |
137 FeatureSERIALIZE | FeatureSHSTK | FeatureTSXLDTRK | FeatureUINTR |
138 FeatureWAITPKG;
139constexpr FeatureBitset FeaturesGraniteRapids =
140 FeaturesSapphireRapids | FeatureAMX_FP16 | FeaturePREFETCHI;
141
142// Intel Atom processors.
143// Bonnell has feature parity with Core2 and adds MOVBE.
144constexpr FeatureBitset FeaturesBonnell = FeaturesCore2 | FeatureMOVBE;
145// Silvermont has parity with Westmere and Bonnell plus PRFCHW and RDRND.
146constexpr FeatureBitset FeaturesSilvermont =
147 FeaturesBonnell | FeaturesWestmere | FeaturePRFCHW | FeatureRDRND;
148constexpr FeatureBitset FeaturesGoldmont =
149 FeaturesSilvermont | FeatureAES | FeatureCLFLUSHOPT | FeatureFSGSBASE |
150 FeatureRDSEED | FeatureSHA | FeatureXSAVE | FeatureXSAVEC |
151 FeatureXSAVEOPT | FeatureXSAVES;
152constexpr FeatureBitset FeaturesGoldmontPlus =
153 FeaturesGoldmont | FeaturePTWRITE | FeatureRDPID | FeatureSGX;
154constexpr FeatureBitset FeaturesTremont =
155 FeaturesGoldmontPlus | FeatureCLWB | FeatureGFNI;
156constexpr FeatureBitset FeaturesAlderlake =
157 FeaturesTremont | FeatureADX | FeatureBMI | FeatureBMI2 | FeatureF16C |
158 FeatureFMA | FeatureINVPCID | FeatureLZCNT | FeaturePCONFIG | FeaturePKU |
159 FeatureSERIALIZE | FeatureSHSTK | FeatureVAES | FeatureVPCLMULQDQ |
160 FeatureCLDEMOTE | FeatureMOVDIR64B | FeatureMOVDIRI | FeatureWAITPKG |
161 FeatureAVXVNNI | FeatureHRESET | FeatureWIDEKL;
162constexpr FeatureBitset FeaturesSierraforest =
163 FeaturesAlderlake | FeatureCMPCCXADD | FeatureAVXIFMA | FeatureUINTR |
164 FeatureENQCMD | FeatureAVXNECONVERT | FeatureAVXVNNIINT8;
165constexpr FeatureBitset FeaturesArrowlakeS = FeaturesSierraforest |
166 FeatureAVXVNNIINT16 | FeatureSHA512 | FeatureSM3 | FeatureSM4;
167constexpr FeatureBitset FeaturesPantherlake =
168 FeaturesArrowlakeS | FeaturePREFETCHI;
169constexpr FeatureBitset FeaturesClearwaterforest =
170 FeaturesArrowlakeS | FeatureUSERMSR | FeaturePREFETCHI;
171
172// Geode Processor.
173constexpr FeatureBitset FeaturesGeode =
174 FeatureX87 | FeatureCMPXCHG8B | FeatureMMX | FeaturePRFCHW;
175
176// K6 processor.
177constexpr FeatureBitset FeaturesK6 = FeatureX87 | FeatureCMPXCHG8B | FeatureMMX;
178
179// K7 and K8 architecture processors.
180constexpr FeatureBitset FeaturesAthlon =
181 FeatureX87 | FeatureCMPXCHG8B | FeatureMMX | FeaturePRFCHW;
182constexpr FeatureBitset FeaturesAthlonXP =
183 FeaturesAthlon | FeatureFXSR | FeatureSSE;
184constexpr FeatureBitset FeaturesK8 =
185 FeaturesAthlonXP | FeatureSSE2 | Feature64BIT;
186constexpr FeatureBitset FeaturesK8SSE3 = FeaturesK8 | FeatureSSE3;
187constexpr FeatureBitset FeaturesAMDFAM10 =
188 FeaturesK8SSE3 | FeatureCMPXCHG16B | FeatureLZCNT | FeaturePOPCNT |
189 FeaturePRFCHW | FeatureSAHF | FeatureSSE4_A;
190
191// Bobcat architecture processors.
192constexpr FeatureBitset FeaturesBTVER1 =
193 FeatureX87 | FeatureCMPXCHG8B | FeatureCMPXCHG16B | Feature64BIT |
194 FeatureFXSR | FeatureLZCNT | FeatureMMX | FeaturePOPCNT | FeaturePRFCHW |
195 FeatureSSE | FeatureSSE2 | FeatureSSE3 | FeatureSSSE3 | FeatureSSE4_A |
196 FeatureSAHF;
197constexpr FeatureBitset FeaturesBTVER2 =
198 FeaturesBTVER1 | FeatureAES | FeatureAVX | FeatureBMI | FeatureCRC32 |
199 FeatureF16C | FeatureMOVBE | FeaturePCLMUL | FeatureXSAVE | FeatureXSAVEOPT;
200
201// AMD Bulldozer architecture processors.
202constexpr FeatureBitset FeaturesBDVER1 =
203 FeatureX87 | FeatureAES | FeatureAVX | FeatureCMPXCHG8B |
204 FeatureCMPXCHG16B | FeatureCRC32 | Feature64BIT | FeatureFMA4 |
205 FeatureFXSR | FeatureLWP | FeatureLZCNT | FeatureMMX | FeaturePCLMUL |
206 FeaturePOPCNT | FeaturePRFCHW | FeatureSAHF | FeatureSSE | FeatureSSE2 |
207 FeatureSSE3 | FeatureSSSE3 | FeatureSSE4_1 | FeatureSSE4_2 | FeatureSSE4_A |
208 FeatureXOP | FeatureXSAVE;
209constexpr FeatureBitset FeaturesBDVER2 =
210 FeaturesBDVER1 | FeatureBMI | FeatureFMA | FeatureF16C | FeatureTBM;
211constexpr FeatureBitset FeaturesBDVER3 =
212 FeaturesBDVER2 | FeatureFSGSBASE | FeatureXSAVEOPT;
213constexpr FeatureBitset FeaturesBDVER4 = FeaturesBDVER3 | FeatureAVX2 |
214 FeatureBMI2 | FeatureMOVBE |
215 FeatureMWAITX | FeatureRDRND;
216
217// AMD Zen architecture processors.
218constexpr FeatureBitset FeaturesZNVER1 =
219 FeatureX87 | FeatureADX | FeatureAES | FeatureAVX | FeatureAVX2 |
220 FeatureBMI | FeatureBMI2 | FeatureCLFLUSHOPT | FeatureCLZERO |
221 FeatureCMPXCHG8B | FeatureCMPXCHG16B | FeatureCRC32 | Feature64BIT |
222 FeatureF16C | FeatureFMA | FeatureFSGSBASE | FeatureFXSR | FeatureLZCNT |
223 FeatureMMX | FeatureMOVBE | FeatureMWAITX | FeaturePCLMUL | FeaturePOPCNT |
224 FeaturePRFCHW | FeatureRDRND | FeatureRDSEED | FeatureSAHF | FeatureSHA |
225 FeatureSSE | FeatureSSE2 | FeatureSSE3 | FeatureSSSE3 | FeatureSSE4_1 |
226 FeatureSSE4_2 | FeatureSSE4_A | FeatureXSAVE | FeatureXSAVEC |
227 FeatureXSAVEOPT | FeatureXSAVES;
228constexpr FeatureBitset FeaturesZNVER2 = FeaturesZNVER1 | FeatureCLWB |
229 FeatureRDPID | FeatureRDPRU |
230 FeatureWBNOINVD;
231static constexpr FeatureBitset FeaturesZNVER3 = FeaturesZNVER2 |
232 FeatureINVPCID | FeaturePKU |
233 FeatureVAES | FeatureVPCLMULQDQ;
234static constexpr FeatureBitset FeaturesZNVER4 =
235 FeaturesZNVER3 | FeatureAVX512F | FeatureEVEX512 | FeatureAVX512CD |
236 FeatureAVX512DQ | FeatureAVX512BW | FeatureAVX512VL | FeatureAVX512IFMA |
237 FeatureAVX512VBMI | FeatureAVX512VBMI2 | FeatureAVX512VNNI |
238 FeatureAVX512BITALG | FeatureAVX512VPOPCNTDQ | FeatureAVX512BF16 |
239 FeatureGFNI | FeatureSHSTK;
240
241static constexpr FeatureBitset FeaturesZNVER5 =
242 FeaturesZNVER4 | FeatureAVXVNNI | FeatureMOVDIRI | FeatureMOVDIR64B |
243 FeatureAVX512VP2INTERSECT | FeaturePREFETCHI | FeatureAVXVNNI;
244
245// D151696 tranplanted Mangling and OnlyForCPUDispatchSpecific from
246// X86TargetParser.def to here. They are assigned by following ways:
247// 1. Copy the mangling from the original CPU_SPEICIFC MACROs. If no, assign
248// to '\0' by default, which means not support cpu_specific/dispatch feature.
249// 2. set OnlyForCPUDispatchSpecific as true if this cpu name was not
250// listed here before, which means it doesn't support -march, -mtune and so on.
251// FIXME: Remove OnlyForCPUDispatchSpecific after all CPUs here support both
252// cpu_dispatch/specific() feature and -march, -mtune, and so on.
253// clang-format off
254constexpr ProcInfo Processors[] = {
255 // Empty processor. Include X87 and CMPXCHG8 for backwards compatibility.
256 { .Name: {""}, .Kind: CK_None, .KeyFeature: ~0U, .Features: FeatureX87 | FeatureCMPXCHG8B, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
257 { .Name: {"generic"}, .Kind: CK_None, .KeyFeature: ~0U, .Features: FeatureX87 | FeatureCMPXCHG8B | Feature64BIT, .Mangling: 'A', .OnlyForCPUDispatchSpecific: true },
258 // i386-generation processors.
259 { .Name: {"i386"}, .Kind: CK_i386, .KeyFeature: ~0U, .Features: FeatureX87, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
260 // i486-generation processors.
261 { .Name: {"i486"}, .Kind: CK_i486, .KeyFeature: ~0U, .Features: FeatureX87, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
262 { .Name: {"winchip-c6"}, .Kind: CK_WinChipC6, .KeyFeature: ~0U, .Features: FeaturesPentiumMMX, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
263 { .Name: {"winchip2"}, .Kind: CK_WinChip2, .KeyFeature: ~0U, .Features: FeaturesPentiumMMX | FeaturePRFCHW, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
264 { .Name: {"c3"}, .Kind: CK_C3, .KeyFeature: ~0U, .Features: FeaturesPentiumMMX | FeaturePRFCHW, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
265 // i586-generation processors, P5 microarchitecture based.
266 { .Name: {"i586"}, .Kind: CK_i586, .KeyFeature: ~0U, .Features: FeatureX87 | FeatureCMPXCHG8B, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
267 { .Name: {"pentium"}, .Kind: CK_Pentium, .KeyFeature: ~0U, .Features: FeatureX87 | FeatureCMPXCHG8B, .Mangling: 'B', .OnlyForCPUDispatchSpecific: false },
268 { .Name: {"pentium-mmx"}, .Kind: CK_PentiumMMX, .KeyFeature: ~0U, .Features: FeaturesPentiumMMX, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
269 { .Name: {"pentium_mmx"}, .Kind: CK_PentiumMMX, .KeyFeature: ~0U, .Features: FeaturesPentiumMMX, .Mangling: 'D', .OnlyForCPUDispatchSpecific: true },
270 // i686-generation processors, P6 / Pentium M microarchitecture based.
271 { .Name: {"pentiumpro"}, .Kind: CK_PentiumPro, .KeyFeature: ~0U, .Features: FeatureCMOV | FeatureX87 | FeatureCMPXCHG8B, .Mangling: 'C', .OnlyForCPUDispatchSpecific: false },
272 { .Name: {"pentium_pro"}, .Kind: CK_PentiumPro, .KeyFeature: ~0U, .Features: FeatureCMOV | FeatureX87 | FeatureCMPXCHG8B, .Mangling: 'C', .OnlyForCPUDispatchSpecific: true },
273 { .Name: {"i686"}, .Kind: CK_i686, .KeyFeature: ~0U, .Features: FeatureCMOV | FeatureX87 | FeatureCMPXCHG8B, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
274 { .Name: {"pentium2"}, .Kind: CK_Pentium2, .KeyFeature: ~0U, .Features: FeaturesPentium2, .Mangling: 'E', .OnlyForCPUDispatchSpecific: false },
275 { .Name: {"pentium_ii"}, .Kind: CK_Pentium2, .KeyFeature: ~0U, .Features: FeaturesPentium2, .Mangling: 'E', .OnlyForCPUDispatchSpecific: true },
276 { .Name: {"pentium3"}, .Kind: CK_Pentium3, .KeyFeature: ~0U, .Features: FeaturesPentium3, .Mangling: 'H', .OnlyForCPUDispatchSpecific: false },
277 { .Name: {"pentium3m"}, .Kind: CK_Pentium3, .KeyFeature: ~0U, .Features: FeaturesPentium3, .Mangling: 'H', .OnlyForCPUDispatchSpecific: false },
278 { .Name: {"pentium_iii"}, .Kind: CK_Pentium3, .KeyFeature: ~0U, .Features: FeaturesPentium3, .Mangling: 'H', .OnlyForCPUDispatchSpecific: true },
279 { .Name: {"pentium_iii_no_xmm_regs"}, .Kind: CK_Pentium3, .KeyFeature: ~0U, .Features: FeaturesPentium3, .Mangling: 'H', .OnlyForCPUDispatchSpecific: true },
280 { .Name: {"pentium-m"}, .Kind: CK_PentiumM, .KeyFeature: ~0U, .Features: FeaturesPentium4, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
281 { .Name: {"pentium_m"}, .Kind: CK_PentiumM, .KeyFeature: ~0U, .Features: FeaturesPentium4, .Mangling: 'K', .OnlyForCPUDispatchSpecific: true },
282 { .Name: {"c3-2"}, .Kind: CK_C3_2, .KeyFeature: ~0U, .Features: FeaturesPentium3, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
283 { .Name: {"yonah"}, .Kind: CK_Yonah, .KeyFeature: ~0U, .Features: FeaturesPrescott, .Mangling: 'L', .OnlyForCPUDispatchSpecific: false },
284 // Netburst microarchitecture based processors.
285 { .Name: {"pentium4"}, .Kind: CK_Pentium4, .KeyFeature: ~0U, .Features: FeaturesPentium4, .Mangling: 'J', .OnlyForCPUDispatchSpecific: false },
286 { .Name: {"pentium4m"}, .Kind: CK_Pentium4, .KeyFeature: ~0U, .Features: FeaturesPentium4, .Mangling: 'J', .OnlyForCPUDispatchSpecific: false },
287 { .Name: {"pentium_4"}, .Kind: CK_Pentium4, .KeyFeature: ~0U, .Features: FeaturesPentium4, .Mangling: 'J', .OnlyForCPUDispatchSpecific: true },
288 { .Name: {"pentium_4_sse3"}, .Kind: CK_Prescott, .KeyFeature: ~0U, .Features: FeaturesPrescott, .Mangling: 'L', .OnlyForCPUDispatchSpecific: true },
289 { .Name: {"prescott"}, .Kind: CK_Prescott, .KeyFeature: ~0U, .Features: FeaturesPrescott, .Mangling: 'L', .OnlyForCPUDispatchSpecific: false },
290 { .Name: {"nocona"}, .Kind: CK_Nocona, .KeyFeature: ~0U, .Features: FeaturesNocona, .Mangling: 'L', .OnlyForCPUDispatchSpecific: false },
291 // Core microarchitecture based processors.
292 { .Name: {"core2"}, .Kind: CK_Core2, .KeyFeature: FEATURE_SSSE3, .Features: FeaturesCore2, .Mangling: 'M', .OnlyForCPUDispatchSpecific: false },
293 { .Name: {"core_2_duo_ssse3"}, .Kind: CK_Core2, .KeyFeature: ~0U, .Features: FeaturesCore2, .Mangling: 'M', .OnlyForCPUDispatchSpecific: true },
294 { .Name: {"penryn"}, .Kind: CK_Penryn, .KeyFeature: ~0U, .Features: FeaturesPenryn, .Mangling: 'N', .OnlyForCPUDispatchSpecific: false },
295 { .Name: {"core_2_duo_sse4_1"}, .Kind: CK_Penryn, .KeyFeature: ~0U, .Features: FeaturesPenryn, .Mangling: 'N', .OnlyForCPUDispatchSpecific: true },
296 // Atom processors
297 { .Name: {"bonnell"}, .Kind: CK_Bonnell, .KeyFeature: FEATURE_SSSE3, .Features: FeaturesBonnell, .Mangling: 'O', .OnlyForCPUDispatchSpecific: false },
298 { .Name: {"atom"}, .Kind: CK_Bonnell, .KeyFeature: FEATURE_SSSE3, .Features: FeaturesBonnell, .Mangling: 'O', .OnlyForCPUDispatchSpecific: false },
299 { .Name: {"silvermont"}, .Kind: CK_Silvermont, .KeyFeature: FEATURE_SSE4_2, .Features: FeaturesSilvermont, .Mangling: 'c', .OnlyForCPUDispatchSpecific: false },
300 { .Name: {"slm"}, .Kind: CK_Silvermont, .KeyFeature: FEATURE_SSE4_2, .Features: FeaturesSilvermont, .Mangling: 'c', .OnlyForCPUDispatchSpecific: false },
301 { .Name: {"atom_sse4_2"}, .Kind: CK_Nehalem, .KeyFeature: FEATURE_SSE4_2, .Features: FeaturesNehalem, .Mangling: 'c', .OnlyForCPUDispatchSpecific: true },
302 { .Name: {"atom_sse4_2_movbe"}, .Kind: CK_Goldmont, .KeyFeature: FEATURE_SSE4_2, .Features: FeaturesGoldmont, .Mangling: 'd', .OnlyForCPUDispatchSpecific: true },
303 { .Name: {"goldmont"}, .Kind: CK_Goldmont, .KeyFeature: FEATURE_SSE4_2, .Features: FeaturesGoldmont, .Mangling: 'i', .OnlyForCPUDispatchSpecific: false },
304 { .Name: {"goldmont-plus"}, .Kind: CK_GoldmontPlus, .KeyFeature: FEATURE_SSE4_2, .Features: FeaturesGoldmontPlus, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
305 { .Name: {"goldmont_plus"}, .Kind: CK_GoldmontPlus, .KeyFeature: FEATURE_SSE4_2, .Features: FeaturesGoldmontPlus, .Mangling: 'd', .OnlyForCPUDispatchSpecific: true },
306 { .Name: {"tremont"}, .Kind: CK_Tremont, .KeyFeature: FEATURE_SSE4_2, .Features: FeaturesTremont, .Mangling: 'd', .OnlyForCPUDispatchSpecific: false },
307 // Nehalem microarchitecture based processors.
308 { .Name: {"nehalem"}, .Kind: CK_Nehalem, .KeyFeature: FEATURE_SSE4_2, .Features: FeaturesNehalem, .Mangling: 'P', .OnlyForCPUDispatchSpecific: false },
309 { .Name: {"core_i7_sse4_2"}, .Kind: CK_Nehalem, .KeyFeature: FEATURE_SSE4_2, .Features: FeaturesNehalem, .Mangling: 'P', .OnlyForCPUDispatchSpecific: true },
310 { .Name: {"corei7"}, .Kind: CK_Nehalem, .KeyFeature: FEATURE_SSE4_2, .Features: FeaturesNehalem, .Mangling: 'P', .OnlyForCPUDispatchSpecific: false },
311 // Westmere microarchitecture based processors.
312 { .Name: {"westmere"}, .Kind: CK_Westmere, .KeyFeature: FEATURE_PCLMUL, .Features: FeaturesWestmere, .Mangling: 'Q', .OnlyForCPUDispatchSpecific: false },
313 { .Name: {"core_aes_pclmulqdq"}, .Kind: CK_Nehalem, .KeyFeature: FEATURE_SSE4_2, .Features: FeaturesNehalem, .Mangling: 'Q', .OnlyForCPUDispatchSpecific: true },
314 // Sandy Bridge microarchitecture based processors.
315 { .Name: {"sandybridge"}, .Kind: CK_SandyBridge, .KeyFeature: FEATURE_AVX, .Features: FeaturesSandyBridge, .Mangling: 'R', .OnlyForCPUDispatchSpecific: false },
316 { .Name: {"core_2nd_gen_avx"}, .Kind: CK_SandyBridge, .KeyFeature: FEATURE_AVX, .Features: FeaturesSandyBridge, .Mangling: 'R', .OnlyForCPUDispatchSpecific: true },
317 { .Name: {"corei7-avx"}, .Kind: CK_SandyBridge, .KeyFeature: FEATURE_AVX, .Features: FeaturesSandyBridge, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
318 // Ivy Bridge microarchitecture based processors.
319 { .Name: {"ivybridge"}, .Kind: CK_IvyBridge, .KeyFeature: FEATURE_AVX, .Features: FeaturesIvyBridge, .Mangling: 'S', .OnlyForCPUDispatchSpecific: false },
320 { .Name: {"core_3rd_gen_avx"}, .Kind: CK_IvyBridge, .KeyFeature: FEATURE_AVX, .Features: FeaturesIvyBridge, .Mangling: 'S', .OnlyForCPUDispatchSpecific: true },
321 { .Name: {"core-avx-i"}, .Kind: CK_IvyBridge, .KeyFeature: FEATURE_AVX, .Features: FeaturesIvyBridge, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
322 // Haswell microarchitecture based processors.
323 { .Name: {"haswell"}, .Kind: CK_Haswell, .KeyFeature: FEATURE_AVX2, .Features: FeaturesHaswell, .Mangling: 'V', .OnlyForCPUDispatchSpecific: false },
324 { .Name: {"core-avx2"}, .Kind: CK_Haswell, .KeyFeature: FEATURE_AVX2, .Features: FeaturesHaswell, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
325 { .Name: {"core_4th_gen_avx"}, .Kind: CK_Haswell, .KeyFeature: FEATURE_AVX2, .Features: FeaturesHaswell, .Mangling: 'V', .OnlyForCPUDispatchSpecific: true },
326 { .Name: {"core_4th_gen_avx_tsx"}, .Kind: CK_Haswell, .KeyFeature: FEATURE_AVX2, .Features: FeaturesHaswell, .Mangling: 'W', .OnlyForCPUDispatchSpecific: true },
327 // Broadwell microarchitecture based processors.
328 { .Name: {"broadwell"}, .Kind: CK_Broadwell, .KeyFeature: FEATURE_AVX2, .Features: FeaturesBroadwell, .Mangling: 'X', .OnlyForCPUDispatchSpecific: false },
329 { .Name: {"core_5th_gen_avx"}, .Kind: CK_Broadwell, .KeyFeature: FEATURE_AVX2, .Features: FeaturesBroadwell, .Mangling: 'X', .OnlyForCPUDispatchSpecific: true },
330 { .Name: {"core_5th_gen_avx_tsx"}, .Kind: CK_Broadwell, .KeyFeature: FEATURE_AVX2, .Features: FeaturesBroadwell, .Mangling: 'Y', .OnlyForCPUDispatchSpecific: true },
331 // Skylake client microarchitecture based processors.
332 { .Name: {"skylake"}, .Kind: CK_SkylakeClient, .KeyFeature: FEATURE_AVX2, .Features: FeaturesSkylakeClient, .Mangling: 'b', .OnlyForCPUDispatchSpecific: false },
333 // Skylake server microarchitecture based processors.
334 { .Name: {"skylake-avx512"}, .Kind: CK_SkylakeServer, .KeyFeature: FEATURE_AVX512F, .Features: FeaturesSkylakeServer, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
335 { .Name: {"skx"}, .Kind: CK_SkylakeServer, .KeyFeature: FEATURE_AVX512F, .Features: FeaturesSkylakeServer, .Mangling: 'a', .OnlyForCPUDispatchSpecific: false },
336 { .Name: {"skylake_avx512"}, .Kind: CK_SkylakeServer, .KeyFeature: FEATURE_AVX512F, .Features: FeaturesSkylakeServer, .Mangling: 'a', .OnlyForCPUDispatchSpecific: true },
337 // Cascadelake Server microarchitecture based processors.
338 { .Name: {"cascadelake"}, .Kind: CK_Cascadelake, .KeyFeature: FEATURE_AVX512VNNI, .Features: FeaturesCascadeLake, .Mangling: 'o', .OnlyForCPUDispatchSpecific: false },
339 // Cooperlake Server microarchitecture based processors.
340 { .Name: {"cooperlake"}, .Kind: CK_Cooperlake, .KeyFeature: FEATURE_AVX512BF16, .Features: FeaturesCooperLake, .Mangling: 'f', .OnlyForCPUDispatchSpecific: false },
341 // Cannonlake client microarchitecture based processors.
342 { .Name: {"cannonlake"}, .Kind: CK_Cannonlake, .KeyFeature: FEATURE_AVX512VBMI, .Features: FeaturesCannonlake, .Mangling: 'e', .OnlyForCPUDispatchSpecific: false },
343 // Icelake client microarchitecture based processors.
344 { .Name: {"icelake-client"}, .Kind: CK_IcelakeClient, .KeyFeature: FEATURE_AVX512VBMI2, .Features: FeaturesICLClient, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
345 { .Name: {"icelake_client"}, .Kind: CK_IcelakeClient, .KeyFeature: FEATURE_AVX512VBMI2, .Features: FeaturesICLClient, .Mangling: 'k', .OnlyForCPUDispatchSpecific: true },
346 // Rocketlake microarchitecture based processors.
347 { .Name: {"rocketlake"}, .Kind: CK_Rocketlake, .KeyFeature: FEATURE_AVX512VBMI2, .Features: FeaturesRocketlake, .Mangling: 'k', .OnlyForCPUDispatchSpecific: false },
348 // Icelake server microarchitecture based processors.
349 { .Name: {"icelake-server"}, .Kind: CK_IcelakeServer, .KeyFeature: FEATURE_AVX512VBMI2, .Features: FeaturesICLServer, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
350 { .Name: {"icelake_server"}, .Kind: CK_IcelakeServer, .KeyFeature: FEATURE_AVX512VBMI2, .Features: FeaturesICLServer, .Mangling: 'k', .OnlyForCPUDispatchSpecific: true },
351 // Tigerlake microarchitecture based processors.
352 { .Name: {"tigerlake"}, .Kind: CK_Tigerlake, .KeyFeature: FEATURE_AVX512VP2INTERSECT, .Features: FeaturesTigerlake, .Mangling: 'l', .OnlyForCPUDispatchSpecific: false },
353 // Sapphire Rapids microarchitecture based processors.
354 { .Name: {"sapphirerapids"}, .Kind: CK_SapphireRapids, .KeyFeature: FEATURE_AVX512FP16, .Features: FeaturesSapphireRapids, .Mangling: 'n', .OnlyForCPUDispatchSpecific: false },
355 // Alderlake microarchitecture based processors.
356 { .Name: {"alderlake"}, .Kind: CK_Alderlake, .KeyFeature: FEATURE_AVX2, .Features: FeaturesAlderlake, .Mangling: 'p', .OnlyForCPUDispatchSpecific: false },
357 // Raptorlake microarchitecture based processors.
358 { .Name: {"raptorlake"}, .Kind: CK_Raptorlake, .KeyFeature: FEATURE_AVX2, .Features: FeaturesAlderlake, .Mangling: 'p', .OnlyForCPUDispatchSpecific: false },
359 // Meteorlake microarchitecture based processors.
360 { .Name: {"meteorlake"}, .Kind: CK_Meteorlake, .KeyFeature: FEATURE_AVX2, .Features: FeaturesAlderlake, .Mangling: 'p', .OnlyForCPUDispatchSpecific: false },
361 // Arrowlake microarchitecture based processors.
362 { .Name: {"arrowlake"}, .Kind: CK_Arrowlake, .KeyFeature: FEATURE_AVX2, .Features: FeaturesSierraforest, .Mangling: 'p', .OnlyForCPUDispatchSpecific: false },
363 { .Name: {"arrowlake-s"}, .Kind: CK_ArrowlakeS, .KeyFeature: FEATURE_AVX2, .Features: FeaturesArrowlakeS, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
364 { .Name: {"arrowlake_s"}, .Kind: CK_ArrowlakeS, .KeyFeature: FEATURE_AVX2, .Features: FeaturesArrowlakeS, .Mangling: 'p', .OnlyForCPUDispatchSpecific: true },
365 // Lunarlake microarchitecture based processors.
366 { .Name: {"lunarlake"}, .Kind: CK_Lunarlake, .KeyFeature: FEATURE_AVX2, .Features: FeaturesArrowlakeS, .Mangling: 'p', .OnlyForCPUDispatchSpecific: false },
367 // Gracemont microarchitecture based processors.
368 { .Name: {"gracemont"}, .Kind: CK_Gracemont, .KeyFeature: FEATURE_AVX2, .Features: FeaturesAlderlake, .Mangling: 'p', .OnlyForCPUDispatchSpecific: false },
369 // Pantherlake microarchitecture based processors.
370 { .Name: {"pantherlake"}, .Kind: CK_Lunarlake, .KeyFeature: FEATURE_AVX2, .Features: FeaturesPantherlake, .Mangling: 'p', .OnlyForCPUDispatchSpecific: false },
371 // Sierraforest microarchitecture based processors.
372 { .Name: {"sierraforest"}, .Kind: CK_Sierraforest, .KeyFeature: FEATURE_AVX2, .Features: FeaturesSierraforest, .Mangling: 'p', .OnlyForCPUDispatchSpecific: false },
373 // Grandridge microarchitecture based processors.
374 { .Name: {"grandridge"}, .Kind: CK_Grandridge, .KeyFeature: FEATURE_AVX2, .Features: FeaturesSierraforest, .Mangling: 'p', .OnlyForCPUDispatchSpecific: false },
375 // Granite Rapids microarchitecture based processors.
376 { .Name: {"graniterapids"}, .Kind: CK_Graniterapids, .KeyFeature: FEATURE_AVX512FP16, .Features: FeaturesGraniteRapids, .Mangling: 'n', .OnlyForCPUDispatchSpecific: false },
377 // Granite Rapids D microarchitecture based processors.
378 { .Name: {"graniterapids-d"}, .Kind: CK_GraniterapidsD, .KeyFeature: FEATURE_AVX512FP16, .Features: FeaturesGraniteRapids | FeatureAMX_COMPLEX, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
379 { .Name: {"graniterapids_d"}, .Kind: CK_GraniterapidsD, .KeyFeature: FEATURE_AVX512FP16, .Features: FeaturesGraniteRapids | FeatureAMX_COMPLEX, .Mangling: 'n', .OnlyForCPUDispatchSpecific: true },
380 // Emerald Rapids microarchitecture based processors.
381 { .Name: {"emeraldrapids"}, .Kind: CK_Emeraldrapids, .KeyFeature: FEATURE_AVX512FP16, .Features: FeaturesSapphireRapids, .Mangling: 'n', .OnlyForCPUDispatchSpecific: false },
382 // Clearwaterforest microarchitecture based processors.
383 { .Name: {"clearwaterforest"}, .Kind: CK_Lunarlake, .KeyFeature: FEATURE_AVX2, .Features: FeaturesClearwaterforest, .Mangling: 'p', .OnlyForCPUDispatchSpecific: false },
384 // Knights Landing processor.
385 { .Name: {"knl"}, .Kind: CK_KNL, .KeyFeature: FEATURE_AVX512F, .Features: FeaturesKNL, .Mangling: 'Z', .OnlyForCPUDispatchSpecific: false },
386 { .Name: {"mic_avx512"}, .Kind: CK_KNL, .KeyFeature: FEATURE_AVX512F, .Features: FeaturesKNL, .Mangling: 'Z', .OnlyForCPUDispatchSpecific: true },
387 // Knights Mill processor.
388 { .Name: {"knm"}, .Kind: CK_KNM, .KeyFeature: FEATURE_AVX5124FMAPS, .Features: FeaturesKNM, .Mangling: 'j', .OnlyForCPUDispatchSpecific: false },
389 // Lakemont microarchitecture based processors.
390 { .Name: {"lakemont"}, .Kind: CK_Lakemont, .KeyFeature: ~0U, .Features: FeatureCMPXCHG8B, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
391 // K6 architecture processors.
392 { .Name: {"k6"}, .Kind: CK_K6, .KeyFeature: ~0U, .Features: FeaturesK6, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
393 { .Name: {"k6-2"}, .Kind: CK_K6_2, .KeyFeature: ~0U, .Features: FeaturesK6 | FeaturePRFCHW, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
394 { .Name: {"k6-3"}, .Kind: CK_K6_3, .KeyFeature: ~0U, .Features: FeaturesK6 | FeaturePRFCHW, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
395 // K7 architecture processors.
396 { .Name: {"athlon"}, .Kind: CK_Athlon, .KeyFeature: ~0U, .Features: FeaturesAthlon, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
397 { .Name: {"athlon-tbird"}, .Kind: CK_Athlon, .KeyFeature: ~0U, .Features: FeaturesAthlon, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
398 { .Name: {"athlon-xp"}, .Kind: CK_AthlonXP, .KeyFeature: ~0U, .Features: FeaturesAthlonXP, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
399 { .Name: {"athlon-mp"}, .Kind: CK_AthlonXP, .KeyFeature: ~0U, .Features: FeaturesAthlonXP, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
400 { .Name: {"athlon-4"}, .Kind: CK_AthlonXP, .KeyFeature: ~0U, .Features: FeaturesAthlonXP, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
401 // K8 architecture processors.
402 { .Name: {"k8"}, .Kind: CK_K8, .KeyFeature: ~0U, .Features: FeaturesK8, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
403 { .Name: {"athlon64"}, .Kind: CK_K8, .KeyFeature: ~0U, .Features: FeaturesK8, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
404 { .Name: {"athlon-fx"}, .Kind: CK_K8, .KeyFeature: ~0U, .Features: FeaturesK8, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
405 { .Name: {"opteron"}, .Kind: CK_K8, .KeyFeature: ~0U, .Features: FeaturesK8, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
406 { .Name: {"k8-sse3"}, .Kind: CK_K8SSE3, .KeyFeature: ~0U, .Features: FeaturesK8SSE3, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
407 { .Name: {"athlon64-sse3"}, .Kind: CK_K8SSE3, .KeyFeature: ~0U, .Features: FeaturesK8SSE3, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
408 { .Name: {"opteron-sse3"}, .Kind: CK_K8SSE3, .KeyFeature: ~0U, .Features: FeaturesK8SSE3, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
409 { .Name: {"amdfam10"}, .Kind: CK_AMDFAM10, .KeyFeature: FEATURE_SSE4_A, .Features: FeaturesAMDFAM10, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
410 { .Name: {"barcelona"}, .Kind: CK_AMDFAM10, .KeyFeature: FEATURE_SSE4_A, .Features: FeaturesAMDFAM10, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
411 // Bobcat architecture processors.
412 { .Name: {"btver1"}, .Kind: CK_BTVER1, .KeyFeature: FEATURE_SSE4_A, .Features: FeaturesBTVER1, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
413 { .Name: {"btver2"}, .Kind: CK_BTVER2, .KeyFeature: FEATURE_BMI, .Features: FeaturesBTVER2, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
414 // Bulldozer architecture processors.
415 { .Name: {"bdver1"}, .Kind: CK_BDVER1, .KeyFeature: FEATURE_XOP, .Features: FeaturesBDVER1, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
416 { .Name: {"bdver2"}, .Kind: CK_BDVER2, .KeyFeature: FEATURE_FMA, .Features: FeaturesBDVER2, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
417 { .Name: {"bdver3"}, .Kind: CK_BDVER3, .KeyFeature: FEATURE_FMA, .Features: FeaturesBDVER3, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
418 { .Name: {"bdver4"}, .Kind: CK_BDVER4, .KeyFeature: FEATURE_AVX2, .Features: FeaturesBDVER4, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
419 // Zen architecture processors.
420 { .Name: {"znver1"}, .Kind: CK_ZNVER1, .KeyFeature: FEATURE_AVX2, .Features: FeaturesZNVER1, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
421 { .Name: {"znver2"}, .Kind: CK_ZNVER2, .KeyFeature: FEATURE_AVX2, .Features: FeaturesZNVER2, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
422 { .Name: {"znver3"}, .Kind: CK_ZNVER3, .KeyFeature: FEATURE_AVX2, .Features: FeaturesZNVER3, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
423 { .Name: {"znver4"}, .Kind: CK_ZNVER4, .KeyFeature: FEATURE_AVX512VBMI2, .Features: FeaturesZNVER4, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
424 { .Name: {"znver5"}, .Kind: CK_ZNVER5, .KeyFeature: FEATURE_AVX512VP2INTERSECT, .Features: FeaturesZNVER5, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
425 // Generic 64-bit processor.
426 { .Name: {"x86-64"}, .Kind: CK_x86_64, .KeyFeature: FEATURE_SSE2 , .Features: FeaturesX86_64, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
427 { .Name: {"x86-64-v2"}, .Kind: CK_x86_64_v2, .KeyFeature: FEATURE_SSE4_2 , .Features: FeaturesX86_64_V2, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
428 { .Name: {"x86-64-v3"}, .Kind: CK_x86_64_v3, .KeyFeature: FEATURE_AVX2, .Features: FeaturesX86_64_V3, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
429 { .Name: {"x86-64-v4"}, .Kind: CK_x86_64_v4, .KeyFeature: FEATURE_AVX512VL, .Features: FeaturesX86_64_V4, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
430 // Geode processors.
431 { .Name: {"geode"}, .Kind: CK_Geode, .KeyFeature: ~0U, .Features: FeaturesGeode, .Mangling: '\0', .OnlyForCPUDispatchSpecific: false },
432};
433// clang-format on
434
435constexpr const char *NoTuneList[] = {"x86-64-v2", "x86-64-v3", "x86-64-v4"};
436
437X86::CPUKind llvm::X86::parseArchX86(StringRef CPU, bool Only64Bit) {
438 for (const auto &P : Processors)
439 if (!P.OnlyForCPUDispatchSpecific && P.Name == CPU &&
440 (P.Features[FEATURE_64BIT] || !Only64Bit))
441 return P.Kind;
442
443 return CK_None;
444}
445
446X86::CPUKind llvm::X86::parseTuneCPU(StringRef CPU, bool Only64Bit) {
447 if (llvm::is_contained(Range: NoTuneList, Element: CPU))
448 return CK_None;
449 return parseArchX86(CPU, Only64Bit);
450}
451
452void llvm::X86::fillValidCPUArchList(SmallVectorImpl<StringRef> &Values,
453 bool Only64Bit) {
454 for (const auto &P : Processors)
455 if (!P.OnlyForCPUDispatchSpecific && !P.Name.empty() &&
456 (P.Features[FEATURE_64BIT] || !Only64Bit))
457 Values.emplace_back(Args: P.Name);
458}
459
460void llvm::X86::fillValidTuneCPUList(SmallVectorImpl<StringRef> &Values,
461 bool Only64Bit) {
462 for (const ProcInfo &P : Processors)
463 if (!P.OnlyForCPUDispatchSpecific && !P.Name.empty() &&
464 (P.Features[FEATURE_64BIT] || !Only64Bit) &&
465 !llvm::is_contained(Range: NoTuneList, Element: P.Name))
466 Values.emplace_back(Args: P.Name);
467}
468
469ProcessorFeatures llvm::X86::getKeyFeature(X86::CPUKind Kind) {
470 // FIXME: Can we avoid a linear search here? The table might be sorted by
471 // CPUKind so we could binary search?
472 for (const auto &P : Processors) {
473 if (P.Kind == Kind) {
474 assert(P.KeyFeature != ~0U && "Processor does not have a key feature.");
475 return static_cast<ProcessorFeatures>(P.KeyFeature);
476 }
477 }
478
479 llvm_unreachable("Unable to find CPU kind!");
480}
481
482// Features with no dependencies.
483constexpr FeatureBitset ImpliedFeatures64BIT = {};
484constexpr FeatureBitset ImpliedFeaturesADX = {};
485constexpr FeatureBitset ImpliedFeaturesBMI = {};
486constexpr FeatureBitset ImpliedFeaturesBMI2 = {};
487constexpr FeatureBitset ImpliedFeaturesCLDEMOTE = {};
488constexpr FeatureBitset ImpliedFeaturesCLFLUSHOPT = {};
489constexpr FeatureBitset ImpliedFeaturesCLWB = {};
490constexpr FeatureBitset ImpliedFeaturesCLZERO = {};
491constexpr FeatureBitset ImpliedFeaturesCMOV = {};
492constexpr FeatureBitset ImpliedFeaturesCMPXCHG16B = {};
493constexpr FeatureBitset ImpliedFeaturesCMPXCHG8B = {};
494constexpr FeatureBitset ImpliedFeaturesCRC32 = {};
495constexpr FeatureBitset ImpliedFeaturesENQCMD = {};
496constexpr FeatureBitset ImpliedFeaturesFSGSBASE = {};
497constexpr FeatureBitset ImpliedFeaturesFXSR = {};
498constexpr FeatureBitset ImpliedFeaturesINVPCID = {};
499constexpr FeatureBitset ImpliedFeaturesLWP = {};
500constexpr FeatureBitset ImpliedFeaturesLZCNT = {};
501constexpr FeatureBitset ImpliedFeaturesMMX = {};
502constexpr FeatureBitset ImpliedFeaturesMWAITX = {};
503constexpr FeatureBitset ImpliedFeaturesMOVBE = {};
504constexpr FeatureBitset ImpliedFeaturesMOVDIR64B = {};
505constexpr FeatureBitset ImpliedFeaturesMOVDIRI = {};
506constexpr FeatureBitset ImpliedFeaturesPCONFIG = {};
507constexpr FeatureBitset ImpliedFeaturesPOPCNT = {};
508constexpr FeatureBitset ImpliedFeaturesPKU = {};
509constexpr FeatureBitset ImpliedFeaturesPRFCHW = {};
510constexpr FeatureBitset ImpliedFeaturesPTWRITE = {};
511constexpr FeatureBitset ImpliedFeaturesRDPID = {};
512constexpr FeatureBitset ImpliedFeaturesRDPRU = {};
513constexpr FeatureBitset ImpliedFeaturesRDRND = {};
514constexpr FeatureBitset ImpliedFeaturesRDSEED = {};
515constexpr FeatureBitset ImpliedFeaturesRTM = {};
516constexpr FeatureBitset ImpliedFeaturesSAHF = {};
517constexpr FeatureBitset ImpliedFeaturesSERIALIZE = {};
518constexpr FeatureBitset ImpliedFeaturesSGX = {};
519constexpr FeatureBitset ImpliedFeaturesSHSTK = {};
520constexpr FeatureBitset ImpliedFeaturesTBM = {};
521constexpr FeatureBitset ImpliedFeaturesTSXLDTRK = {};
522constexpr FeatureBitset ImpliedFeaturesUINTR = {};
523constexpr FeatureBitset ImpliedFeaturesUSERMSR = {};
524constexpr FeatureBitset ImpliedFeaturesWAITPKG = {};
525constexpr FeatureBitset ImpliedFeaturesWBNOINVD = {};
526constexpr FeatureBitset ImpliedFeaturesVZEROUPPER = {};
527constexpr FeatureBitset ImpliedFeaturesX87 = {};
528constexpr FeatureBitset ImpliedFeaturesXSAVE = {};
529constexpr FeatureBitset ImpliedFeaturesDUMMYFEATURE1 = {};
530constexpr FeatureBitset ImpliedFeaturesDUMMYFEATURE2 = {};
531
532// Not really CPU features, but need to be in the table because clang uses
533// target features to communicate them to the backend.
534constexpr FeatureBitset ImpliedFeaturesRETPOLINE_EXTERNAL_THUNK = {};
535constexpr FeatureBitset ImpliedFeaturesRETPOLINE_INDIRECT_BRANCHES = {};
536constexpr FeatureBitset ImpliedFeaturesRETPOLINE_INDIRECT_CALLS = {};
537constexpr FeatureBitset ImpliedFeaturesLVI_CFI = {};
538constexpr FeatureBitset ImpliedFeaturesLVI_LOAD_HARDENING = {};
539
540// XSAVE features are dependent on basic XSAVE.
541constexpr FeatureBitset ImpliedFeaturesXSAVEC = FeatureXSAVE;
542constexpr FeatureBitset ImpliedFeaturesXSAVEOPT = FeatureXSAVE;
543constexpr FeatureBitset ImpliedFeaturesXSAVES = FeatureXSAVE;
544
545// SSE/AVX/AVX512F chain.
546constexpr FeatureBitset ImpliedFeaturesSSE = {};
547constexpr FeatureBitset ImpliedFeaturesSSE2 = FeatureSSE;
548constexpr FeatureBitset ImpliedFeaturesSSE3 = FeatureSSE2;
549constexpr FeatureBitset ImpliedFeaturesSSSE3 = FeatureSSE3;
550constexpr FeatureBitset ImpliedFeaturesSSE4_1 = FeatureSSSE3;
551constexpr FeatureBitset ImpliedFeaturesSSE4_2 = FeatureSSE4_1;
552constexpr FeatureBitset ImpliedFeaturesAVX = FeatureSSE4_2;
553constexpr FeatureBitset ImpliedFeaturesAVX2 = FeatureAVX;
554constexpr FeatureBitset ImpliedFeaturesEVEX512 = {};
555constexpr FeatureBitset ImpliedFeaturesAVX512F =
556 FeatureAVX2 | FeatureF16C | FeatureFMA;
557
558// Vector extensions that build on SSE or AVX.
559constexpr FeatureBitset ImpliedFeaturesAES = FeatureSSE2;
560constexpr FeatureBitset ImpliedFeaturesF16C = FeatureAVX;
561constexpr FeatureBitset ImpliedFeaturesFMA = FeatureAVX;
562constexpr FeatureBitset ImpliedFeaturesGFNI = FeatureSSE2;
563constexpr FeatureBitset ImpliedFeaturesPCLMUL = FeatureSSE2;
564constexpr FeatureBitset ImpliedFeaturesSHA = FeatureSSE2;
565constexpr FeatureBitset ImpliedFeaturesVAES = FeatureAES | FeatureAVX2;
566constexpr FeatureBitset ImpliedFeaturesVPCLMULQDQ = FeatureAVX | FeaturePCLMUL;
567constexpr FeatureBitset ImpliedFeaturesSM3 = FeatureAVX;
568constexpr FeatureBitset ImpliedFeaturesSM4 = FeatureAVX2;
569
570// AVX512 features.
571constexpr FeatureBitset ImpliedFeaturesAVX512CD = FeatureAVX512F;
572constexpr FeatureBitset ImpliedFeaturesAVX512BW = FeatureAVX512F;
573constexpr FeatureBitset ImpliedFeaturesAVX512DQ = FeatureAVX512F;
574constexpr FeatureBitset ImpliedFeaturesAVX512VL = FeatureAVX512F;
575
576constexpr FeatureBitset ImpliedFeaturesAVX512BF16 = FeatureAVX512BW;
577constexpr FeatureBitset ImpliedFeaturesAVX512BITALG = FeatureAVX512BW;
578constexpr FeatureBitset ImpliedFeaturesAVX512IFMA = FeatureAVX512F;
579constexpr FeatureBitset ImpliedFeaturesAVX512VNNI = FeatureAVX512F;
580constexpr FeatureBitset ImpliedFeaturesAVX512VPOPCNTDQ = FeatureAVX512F;
581constexpr FeatureBitset ImpliedFeaturesAVX512VBMI = FeatureAVX512BW;
582constexpr FeatureBitset ImpliedFeaturesAVX512VBMI2 = FeatureAVX512BW;
583constexpr FeatureBitset ImpliedFeaturesAVX512VP2INTERSECT = FeatureAVX512F;
584
585// FIXME: These two aren't really implemented and just exist in the feature
586// list for __builtin_cpu_supports. So omit their dependencies.
587constexpr FeatureBitset ImpliedFeaturesAVX5124FMAPS = {};
588constexpr FeatureBitset ImpliedFeaturesAVX5124VNNIW = {};
589
590// SSE4_A->FMA4->XOP chain.
591constexpr FeatureBitset ImpliedFeaturesSSE4_A = FeatureSSE3;
592constexpr FeatureBitset ImpliedFeaturesFMA4 = FeatureAVX | FeatureSSE4_A;
593constexpr FeatureBitset ImpliedFeaturesXOP = FeatureFMA4;
594
595// AMX Features
596constexpr FeatureBitset ImpliedFeaturesAMX_TILE = {};
597constexpr FeatureBitset ImpliedFeaturesAMX_BF16 = FeatureAMX_TILE;
598constexpr FeatureBitset ImpliedFeaturesAMX_FP16 = FeatureAMX_TILE;
599constexpr FeatureBitset ImpliedFeaturesAMX_INT8 = FeatureAMX_TILE;
600constexpr FeatureBitset ImpliedFeaturesAMX_COMPLEX = FeatureAMX_TILE;
601constexpr FeatureBitset ImpliedFeaturesHRESET = {};
602
603constexpr FeatureBitset ImpliedFeaturesPREFETCHI = {};
604constexpr FeatureBitset ImpliedFeaturesCMPCCXADD = {};
605constexpr FeatureBitset ImpliedFeaturesRAOINT = {};
606constexpr FeatureBitset ImpliedFeaturesAVXVNNIINT16 = FeatureAVX2;
607constexpr FeatureBitset ImpliedFeaturesAVXVNNIINT8 = FeatureAVX2;
608constexpr FeatureBitset ImpliedFeaturesAVXIFMA = FeatureAVX2;
609constexpr FeatureBitset ImpliedFeaturesAVXNECONVERT = FeatureAVX2;
610constexpr FeatureBitset ImpliedFeaturesSHA512 = FeatureAVX2;
611constexpr FeatureBitset ImpliedFeaturesAVX512FP16 =
612 FeatureAVX512BW | FeatureAVX512DQ | FeatureAVX512VL;
613// Key Locker Features
614constexpr FeatureBitset ImpliedFeaturesKL = FeatureSSE2;
615constexpr FeatureBitset ImpliedFeaturesWIDEKL = FeatureKL;
616
617// AVXVNNI Features
618constexpr FeatureBitset ImpliedFeaturesAVXVNNI = FeatureAVX2;
619
620// AVX10 Features
621constexpr FeatureBitset ImpliedFeaturesAVX10_1 =
622 FeatureAVX512CD | FeatureAVX512VBMI | FeatureAVX512IFMA |
623 FeatureAVX512VNNI | FeatureAVX512BF16 | FeatureAVX512VPOPCNTDQ |
624 FeatureAVX512VBMI2 | FeatureAVX512BITALG | FeatureVAES | FeatureVPCLMULQDQ |
625 FeatureAVX512FP16;
626constexpr FeatureBitset ImpliedFeaturesAVX10_1_512 =
627 FeatureAVX10_1 | FeatureEVEX512;
628
629// APX Features
630constexpr FeatureBitset ImpliedFeaturesEGPR = {};
631constexpr FeatureBitset ImpliedFeaturesPush2Pop2 = {};
632constexpr FeatureBitset ImpliedFeaturesPPX = {};
633constexpr FeatureBitset ImpliedFeaturesNDD = {};
634constexpr FeatureBitset ImpliedFeaturesCCMP = {};
635constexpr FeatureBitset ImpliedFeaturesNF = {};
636constexpr FeatureBitset ImpliedFeaturesCF = {};
637constexpr FeatureBitset ImpliedFeaturesZU = {};
638
639constexpr FeatureInfo FeatureInfos[X86::CPU_FEATURE_MAX] = {
640#define X86_FEATURE(ENUM, STR) {{"+" STR}, ImpliedFeatures##ENUM},
641#include "llvm/TargetParser/X86TargetParser.def"
642};
643
644void llvm::X86::getFeaturesForCPU(StringRef CPU,
645 SmallVectorImpl<StringRef> &EnabledFeatures,
646 bool NeedPlus) {
647 auto I = llvm::find_if(Range: Processors,
648 P: [&](const ProcInfo &P) { return P.Name == CPU; });
649 assert(I != std::end(Processors) && "Processor not found!");
650
651 FeatureBitset Bits = I->Features;
652
653 // Remove the 64-bit feature which we only use to validate if a CPU can
654 // be used with 64-bit mode.
655 Bits &= ~Feature64BIT;
656
657 // Add the string version of all set bits.
658 for (unsigned i = 0; i != CPU_FEATURE_MAX; ++i)
659 if (Bits[i] && !FeatureInfos[i].getName(WithPlus: NeedPlus).empty())
660 EnabledFeatures.push_back(Elt: FeatureInfos[i].getName(WithPlus: NeedPlus));
661}
662
663// For each feature that is (transitively) implied by this feature, set it.
664static void getImpliedEnabledFeatures(FeatureBitset &Bits,
665 const FeatureBitset &Implies) {
666 // Fast path: Implies is often empty.
667 if (!Implies.any())
668 return;
669 FeatureBitset Prev;
670 Bits |= Implies;
671 do {
672 Prev = Bits;
673 for (unsigned i = CPU_FEATURE_MAX; i;)
674 if (Bits[--i])
675 Bits |= FeatureInfos[i].ImpliedFeatures;
676 } while (Prev != Bits);
677}
678
679/// Create bit vector of features that are implied disabled if the feature
680/// passed in Value is disabled.
681static void getImpliedDisabledFeatures(FeatureBitset &Bits, unsigned Value) {
682 // Check all features looking for any dependent on this feature. If we find
683 // one, mark it and recursively find any feature that depend on it.
684 FeatureBitset Prev;
685 Bits.set(Value);
686 do {
687 Prev = Bits;
688 for (unsigned i = 0; i != CPU_FEATURE_MAX; ++i)
689 if ((FeatureInfos[i].ImpliedFeatures & Bits).any())
690 Bits.set(i);
691 } while (Prev != Bits);
692}
693
694void llvm::X86::updateImpliedFeatures(
695 StringRef Feature, bool Enabled,
696 StringMap<bool> &Features) {
697 auto I = llvm::find_if(Range: FeatureInfos, P: [&](const FeatureInfo &FI) {
698 return FI.getName() == Feature;
699 });
700 if (I == std::end(arr: FeatureInfos)) {
701 // FIXME: This shouldn't happen, but may not have all features in the table
702 // yet.
703 return;
704 }
705
706 FeatureBitset ImpliedBits;
707 if (Enabled)
708 getImpliedEnabledFeatures(Bits&: ImpliedBits, Implies: I->ImpliedFeatures);
709 else
710 getImpliedDisabledFeatures(Bits&: ImpliedBits,
711 Value: std::distance(first: std::begin(arr: FeatureInfos), last: I));
712
713 // Update the map entry for all implied features.
714 for (unsigned i = 0; i != CPU_FEATURE_MAX; ++i)
715 if (ImpliedBits[i] && !FeatureInfos[i].getName().empty())
716 Features[FeatureInfos[i].getName()] = Enabled;
717}
718
719char llvm::X86::getCPUDispatchMangling(StringRef CPU) {
720 auto I = llvm::find_if(Range: Processors,
721 P: [&](const ProcInfo &P) { return P.Name == CPU; });
722 assert(I != std::end(Processors) && "Processor not found!");
723 assert(I->Mangling != '\0' && "Processor dooesn't support function multiversion!");
724 return I->Mangling;
725}
726
727bool llvm::X86::validateCPUSpecificCPUDispatch(StringRef Name) {
728 auto I = llvm::find_if(Range: Processors,
729 P: [&](const ProcInfo &P) { return P.Name == Name; });
730 return I != std::end(arr: Processors);
731}
732
733std::array<uint32_t, 4>
734llvm::X86::getCpuSupportsMask(ArrayRef<StringRef> FeatureStrs) {
735 // Processor features and mapping to processor feature value.
736 std::array<uint32_t, 4> FeatureMask{};
737 for (StringRef FeatureStr : FeatureStrs) {
738 unsigned Feature = StringSwitch<unsigned>(FeatureStr)
739#define X86_FEATURE_COMPAT(ENUM, STR, PRIORITY) \
740 .Case(STR, llvm::X86::FEATURE_##ENUM)
741#define X86_MICROARCH_LEVEL(ENUM, STR, PRIORITY) \
742 .Case(STR, llvm::X86::FEATURE_##ENUM)
743#include "llvm/TargetParser/X86TargetParser.def"
744 ;
745 assert(Feature / 32 < FeatureMask.size());
746 FeatureMask[Feature / 32] |= 1U << (Feature % 32);
747 }
748 return FeatureMask;
749}
750
751unsigned llvm::X86::getFeaturePriority(ProcessorFeatures Feat) {
752#ifndef NDEBUG
753 // Check that priorities are set properly in the .def file. We expect that
754 // "compat" features are assigned non-duplicate consecutive priorities
755 // starting from one (1, ..., 37) and multiple zeros.
756#define X86_FEATURE_COMPAT(ENUM, STR, PRIORITY) PRIORITY,
757 unsigned Priorities[] = {
758#include "llvm/TargetParser/X86TargetParser.def"
759 };
760 std::array<unsigned, std::size(Priorities)> HelperList;
761 const size_t MaxPriority = 37;
762 std::iota(HelperList.begin(), HelperList.begin() + MaxPriority + 1, 0);
763 for (size_t i = MaxPriority + 1; i != std::size(Priorities); ++i)
764 HelperList[i] = 0;
765 assert(std::is_permutation(HelperList.begin(), HelperList.end(),
766 std::begin(Priorities), std::end(Priorities)) &&
767 "Priorities don't form consecutive range!");
768#endif
769
770 switch (Feat) {
771#define X86_FEATURE_COMPAT(ENUM, STR, PRIORITY) \
772 case X86::FEATURE_##ENUM: \
773 return PRIORITY;
774#include "llvm/TargetParser/X86TargetParser.def"
775 default:
776 llvm_unreachable("No Feature Priority for non-CPUSupports Features");
777 }
778}
779