xref: /freebsd-src/contrib/llvm-project/llvm/lib/TargetParser/X86TargetParser.cpp (revision c80e69b00d976a5a3b3e84527f270fa7e72a8205)
1bdd1243dSDimitry Andric //===-- X86TargetParser - Parser for X86 features ---------------*- C++ -*-===//
2bdd1243dSDimitry Andric //
3bdd1243dSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4bdd1243dSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5bdd1243dSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6bdd1243dSDimitry Andric //
7bdd1243dSDimitry Andric //===----------------------------------------------------------------------===//
8bdd1243dSDimitry Andric //
9bdd1243dSDimitry Andric // This file implements a target parser to recognise X86 hardware features.
10bdd1243dSDimitry Andric //
11bdd1243dSDimitry Andric //===----------------------------------------------------------------------===//
12bdd1243dSDimitry Andric 
13bdd1243dSDimitry Andric #include "llvm/TargetParser/X86TargetParser.h"
145f757f3fSDimitry Andric #include "llvm/ADT/Bitset.h"
15bdd1243dSDimitry Andric #include "llvm/ADT/StringSwitch.h"
16bdd1243dSDimitry Andric #include <numeric>
17bdd1243dSDimitry Andric 
18bdd1243dSDimitry Andric using namespace llvm;
19bdd1243dSDimitry Andric using namespace llvm::X86;
20bdd1243dSDimitry Andric 
21bdd1243dSDimitry Andric namespace {
22bdd1243dSDimitry Andric 
235f757f3fSDimitry Andric using FeatureBitset = Bitset<X86::CPU_FEATURE_MAX>;
24bdd1243dSDimitry Andric 
25bdd1243dSDimitry Andric struct ProcInfo {
26bdd1243dSDimitry Andric   StringLiteral Name;
27bdd1243dSDimitry Andric   X86::CPUKind Kind;
28bdd1243dSDimitry Andric   unsigned KeyFeature;
29bdd1243dSDimitry Andric   FeatureBitset Features;
3006c3fb27SDimitry Andric   char Mangling;
3106c3fb27SDimitry Andric   bool OnlyForCPUDispatchSpecific;
32bdd1243dSDimitry Andric };
33bdd1243dSDimitry Andric 
34bdd1243dSDimitry Andric struct FeatureInfo {
355f757f3fSDimitry Andric   StringLiteral NameWithPlus;
36bdd1243dSDimitry Andric   FeatureBitset ImpliedFeatures;
375f757f3fSDimitry Andric 
385f757f3fSDimitry Andric   StringRef getName(bool WithPlus = false) const {
395f757f3fSDimitry Andric     assert(NameWithPlus[0] == '+' && "Expected string to start with '+'");
405f757f3fSDimitry Andric     if (WithPlus)
415f757f3fSDimitry Andric       return NameWithPlus;
425f757f3fSDimitry Andric     return NameWithPlus.drop_front();
435f757f3fSDimitry Andric   }
44bdd1243dSDimitry Andric };
45bdd1243dSDimitry Andric 
46bdd1243dSDimitry Andric } // end anonymous namespace
47bdd1243dSDimitry Andric 
48bdd1243dSDimitry Andric #define X86_FEATURE(ENUM, STRING)                                              \
49bdd1243dSDimitry Andric   constexpr FeatureBitset Feature##ENUM = {X86::FEATURE_##ENUM};
50bdd1243dSDimitry Andric #include "llvm/TargetParser/X86TargetParser.def"
51bdd1243dSDimitry Andric 
52bdd1243dSDimitry Andric // Pentium with MMX.
53bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesPentiumMMX =
54bdd1243dSDimitry Andric     FeatureX87 | FeatureCMPXCHG8B | FeatureMMX;
55bdd1243dSDimitry Andric 
56bdd1243dSDimitry Andric // Pentium 2 and 3.
57bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesPentium2 =
5806c3fb27SDimitry Andric     FeatureX87 | FeatureCMPXCHG8B | FeatureMMX | FeatureFXSR | FeatureCMOV;
59bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesPentium3 = FeaturesPentium2 | FeatureSSE;
60bdd1243dSDimitry Andric 
61bdd1243dSDimitry Andric // Pentium 4 CPUs
62bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesPentium4 = FeaturesPentium3 | FeatureSSE2;
63bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesPrescott = FeaturesPentium4 | FeatureSSE3;
64bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesNocona =
65bdd1243dSDimitry Andric     FeaturesPrescott | Feature64BIT | FeatureCMPXCHG16B;
66bdd1243dSDimitry Andric 
67bdd1243dSDimitry Andric // Basic 64-bit capable CPU.
68bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesX86_64 = FeaturesPentium4 | Feature64BIT;
69bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesX86_64_V2 = FeaturesX86_64 | FeatureSAHF |
70bdd1243dSDimitry Andric                                             FeaturePOPCNT | FeatureCRC32 |
71bdd1243dSDimitry Andric                                             FeatureSSE4_2 | FeatureCMPXCHG16B;
72bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesX86_64_V3 =
73bdd1243dSDimitry Andric     FeaturesX86_64_V2 | FeatureAVX2 | FeatureBMI | FeatureBMI2 | FeatureF16C |
74bdd1243dSDimitry Andric     FeatureFMA | FeatureLZCNT | FeatureMOVBE | FeatureXSAVE;
755f757f3fSDimitry Andric constexpr FeatureBitset FeaturesX86_64_V4 = FeaturesX86_64_V3 | FeatureEVEX512 |
76bdd1243dSDimitry Andric                                             FeatureAVX512BW | FeatureAVX512CD |
77bdd1243dSDimitry Andric                                             FeatureAVX512DQ | FeatureAVX512VL;
78bdd1243dSDimitry Andric 
79bdd1243dSDimitry Andric // Intel Core CPUs
80bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesCore2 =
81bdd1243dSDimitry Andric     FeaturesNocona | FeatureSAHF | FeatureSSSE3;
82bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesPenryn = FeaturesCore2 | FeatureSSE4_1;
83bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesNehalem =
84bdd1243dSDimitry Andric     FeaturesPenryn | FeaturePOPCNT | FeatureCRC32 | FeatureSSE4_2;
85bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesWestmere = FeaturesNehalem | FeaturePCLMUL;
86bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesSandyBridge =
87bdd1243dSDimitry Andric     FeaturesWestmere | FeatureAVX | FeatureXSAVE | FeatureXSAVEOPT;
88bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesIvyBridge =
89bdd1243dSDimitry Andric     FeaturesSandyBridge | FeatureF16C | FeatureFSGSBASE | FeatureRDRND;
90bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesHaswell =
91bdd1243dSDimitry Andric     FeaturesIvyBridge | FeatureAVX2 | FeatureBMI | FeatureBMI2 | FeatureFMA |
92bdd1243dSDimitry Andric     FeatureINVPCID | FeatureLZCNT | FeatureMOVBE;
93bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesBroadwell =
94bdd1243dSDimitry Andric     FeaturesHaswell | FeatureADX | FeaturePRFCHW | FeatureRDSEED;
95bdd1243dSDimitry Andric 
96bdd1243dSDimitry Andric // Intel Knights Landing and Knights Mill
97bdd1243dSDimitry Andric // Knights Landing has feature parity with Broadwell.
980fca6ea1SDimitry Andric constexpr FeatureBitset FeaturesKNL = FeaturesBroadwell | FeatureAES |
990fca6ea1SDimitry Andric                                       FeatureAVX512F | FeatureEVEX512 |
1000fca6ea1SDimitry Andric                                       FeatureAVX512CD;
101bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesKNM = FeaturesKNL | FeatureAVX512VPOPCNTDQ;
102bdd1243dSDimitry Andric 
103bdd1243dSDimitry Andric // Intel Skylake processors.
104bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesSkylakeClient =
105bdd1243dSDimitry Andric     FeaturesBroadwell | FeatureAES | FeatureCLFLUSHOPT | FeatureXSAVEC |
106bdd1243dSDimitry Andric     FeatureXSAVES | FeatureSGX;
107bdd1243dSDimitry Andric // SkylakeServer inherits all SkylakeClient features except SGX.
108bdd1243dSDimitry Andric // FIXME: That doesn't match gcc.
109bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesSkylakeServer =
1105f757f3fSDimitry Andric     (FeaturesSkylakeClient & ~FeatureSGX) | FeatureAVX512F | FeatureEVEX512 |
1115f757f3fSDimitry Andric     FeatureAVX512CD | FeatureAVX512DQ | FeatureAVX512BW | FeatureAVX512VL |
1125f757f3fSDimitry Andric     FeatureCLWB | FeaturePKU;
113bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesCascadeLake =
114bdd1243dSDimitry Andric     FeaturesSkylakeServer | FeatureAVX512VNNI;
115bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesCooperLake =
116bdd1243dSDimitry Andric     FeaturesCascadeLake | FeatureAVX512BF16;
117bdd1243dSDimitry Andric 
118bdd1243dSDimitry Andric // Intel 10nm processors.
119bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesCannonlake =
1205f757f3fSDimitry Andric     FeaturesSkylakeClient | FeatureAVX512F | FeatureEVEX512 | FeatureAVX512CD |
1215f757f3fSDimitry Andric     FeatureAVX512DQ | FeatureAVX512BW | FeatureAVX512VL | FeatureAVX512IFMA |
1225f757f3fSDimitry Andric     FeatureAVX512VBMI | FeaturePKU | FeatureSHA;
123bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesICLClient =
124bdd1243dSDimitry Andric     FeaturesCannonlake | FeatureAVX512BITALG | FeatureAVX512VBMI2 |
125bdd1243dSDimitry Andric     FeatureAVX512VNNI | FeatureAVX512VPOPCNTDQ | FeatureGFNI | FeatureRDPID |
126bdd1243dSDimitry Andric     FeatureVAES | FeatureVPCLMULQDQ;
127bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesRocketlake = FeaturesICLClient & ~FeatureSGX;
128bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesICLServer =
129bdd1243dSDimitry Andric     FeaturesICLClient | FeatureCLWB | FeaturePCONFIG | FeatureWBNOINVD;
130bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesTigerlake =
131bdd1243dSDimitry Andric     FeaturesICLClient | FeatureAVX512VP2INTERSECT | FeatureMOVDIR64B |
132bdd1243dSDimitry Andric     FeatureCLWB | FeatureMOVDIRI | FeatureSHSTK | FeatureKL | FeatureWIDEKL;
133bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesSapphireRapids =
134bdd1243dSDimitry Andric     FeaturesICLServer | FeatureAMX_BF16 | FeatureAMX_INT8 | FeatureAMX_TILE |
135bdd1243dSDimitry Andric     FeatureAVX512BF16 | FeatureAVX512FP16 | FeatureAVXVNNI | FeatureCLDEMOTE |
136bdd1243dSDimitry Andric     FeatureENQCMD | FeatureMOVDIR64B | FeatureMOVDIRI | FeaturePTWRITE |
137bdd1243dSDimitry Andric     FeatureSERIALIZE | FeatureSHSTK | FeatureTSXLDTRK | FeatureUINTR |
138bdd1243dSDimitry Andric     FeatureWAITPKG;
139bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesGraniteRapids =
140bdd1243dSDimitry Andric     FeaturesSapphireRapids | FeatureAMX_FP16 | FeaturePREFETCHI;
141bdd1243dSDimitry Andric 
142bdd1243dSDimitry Andric // Intel Atom processors.
143bdd1243dSDimitry Andric // Bonnell has feature parity with Core2 and adds MOVBE.
144bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesBonnell = FeaturesCore2 | FeatureMOVBE;
145bdd1243dSDimitry Andric // Silvermont has parity with Westmere and Bonnell plus PRFCHW and RDRND.
146bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesSilvermont =
147bdd1243dSDimitry Andric     FeaturesBonnell | FeaturesWestmere | FeaturePRFCHW | FeatureRDRND;
148bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesGoldmont =
149bdd1243dSDimitry Andric     FeaturesSilvermont | FeatureAES | FeatureCLFLUSHOPT | FeatureFSGSBASE |
150bdd1243dSDimitry Andric     FeatureRDSEED | FeatureSHA | FeatureXSAVE | FeatureXSAVEC |
151bdd1243dSDimitry Andric     FeatureXSAVEOPT | FeatureXSAVES;
152bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesGoldmontPlus =
153bdd1243dSDimitry Andric     FeaturesGoldmont | FeaturePTWRITE | FeatureRDPID | FeatureSGX;
154bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesTremont =
155bdd1243dSDimitry Andric     FeaturesGoldmontPlus | FeatureCLWB | FeatureGFNI;
156bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesAlderlake =
157bdd1243dSDimitry Andric     FeaturesTremont | FeatureADX | FeatureBMI | FeatureBMI2 | FeatureF16C |
158bdd1243dSDimitry Andric     FeatureFMA | FeatureINVPCID | FeatureLZCNT | FeaturePCONFIG | FeaturePKU |
159bdd1243dSDimitry Andric     FeatureSERIALIZE | FeatureSHSTK | FeatureVAES | FeatureVPCLMULQDQ |
160bdd1243dSDimitry Andric     FeatureCLDEMOTE | FeatureMOVDIR64B | FeatureMOVDIRI | FeatureWAITPKG |
161bdd1243dSDimitry Andric     FeatureAVXVNNI | FeatureHRESET | FeatureWIDEKL;
162bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesSierraforest =
16306c3fb27SDimitry Andric     FeaturesAlderlake | FeatureCMPCCXADD | FeatureAVXIFMA | FeatureUINTR |
16406c3fb27SDimitry Andric     FeatureENQCMD | FeatureAVXNECONVERT | FeatureAVXVNNIINT8;
1655f757f3fSDimitry Andric constexpr FeatureBitset FeaturesArrowlakeS = FeaturesSierraforest |
1665f757f3fSDimitry Andric     FeatureAVXVNNIINT16 | FeatureSHA512 | FeatureSM3 | FeatureSM4;
1675f757f3fSDimitry Andric constexpr FeatureBitset FeaturesPantherlake =
1685f757f3fSDimitry Andric     FeaturesArrowlakeS | FeaturePREFETCHI;
1695f757f3fSDimitry Andric constexpr FeatureBitset FeaturesClearwaterforest =
1705f757f3fSDimitry Andric     FeaturesArrowlakeS | FeatureUSERMSR | FeaturePREFETCHI;
171bdd1243dSDimitry Andric 
172bdd1243dSDimitry Andric // Geode Processor.
173bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesGeode =
1740fca6ea1SDimitry Andric     FeatureX87 | FeatureCMPXCHG8B | FeatureMMX | FeaturePRFCHW;
175bdd1243dSDimitry Andric 
176bdd1243dSDimitry Andric // K6 processor.
177bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesK6 = FeatureX87 | FeatureCMPXCHG8B | FeatureMMX;
178bdd1243dSDimitry Andric 
179bdd1243dSDimitry Andric // K7 and K8 architecture processors.
180bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesAthlon =
1810fca6ea1SDimitry Andric     FeatureX87 | FeatureCMPXCHG8B | FeatureMMX | FeaturePRFCHW;
182bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesAthlonXP =
183bdd1243dSDimitry Andric     FeaturesAthlon | FeatureFXSR | FeatureSSE;
184bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesK8 =
185bdd1243dSDimitry Andric     FeaturesAthlonXP | FeatureSSE2 | Feature64BIT;
186bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesK8SSE3 = FeaturesK8 | FeatureSSE3;
187bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesAMDFAM10 =
188bdd1243dSDimitry Andric     FeaturesK8SSE3 | FeatureCMPXCHG16B | FeatureLZCNT | FeaturePOPCNT |
189bdd1243dSDimitry Andric     FeaturePRFCHW | FeatureSAHF | FeatureSSE4_A;
190bdd1243dSDimitry Andric 
191bdd1243dSDimitry Andric // Bobcat architecture processors.
192bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesBTVER1 =
193bdd1243dSDimitry Andric     FeatureX87 | FeatureCMPXCHG8B | FeatureCMPXCHG16B | Feature64BIT |
194bdd1243dSDimitry Andric     FeatureFXSR | FeatureLZCNT | FeatureMMX | FeaturePOPCNT | FeaturePRFCHW |
195bdd1243dSDimitry Andric     FeatureSSE | FeatureSSE2 | FeatureSSE3 | FeatureSSSE3 | FeatureSSE4_A |
196bdd1243dSDimitry Andric     FeatureSAHF;
197bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesBTVER2 =
198bdd1243dSDimitry Andric     FeaturesBTVER1 | FeatureAES | FeatureAVX | FeatureBMI | FeatureCRC32 |
199bdd1243dSDimitry Andric     FeatureF16C | FeatureMOVBE | FeaturePCLMUL | FeatureXSAVE | FeatureXSAVEOPT;
200bdd1243dSDimitry Andric 
201bdd1243dSDimitry Andric // AMD Bulldozer architecture processors.
202bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesBDVER1 =
203bdd1243dSDimitry Andric     FeatureX87 | FeatureAES | FeatureAVX | FeatureCMPXCHG8B |
204bdd1243dSDimitry Andric     FeatureCMPXCHG16B | FeatureCRC32 | Feature64BIT | FeatureFMA4 |
205bdd1243dSDimitry Andric     FeatureFXSR | FeatureLWP | FeatureLZCNT | FeatureMMX | FeaturePCLMUL |
206bdd1243dSDimitry Andric     FeaturePOPCNT | FeaturePRFCHW | FeatureSAHF | FeatureSSE | FeatureSSE2 |
207bdd1243dSDimitry Andric     FeatureSSE3 | FeatureSSSE3 | FeatureSSE4_1 | FeatureSSE4_2 | FeatureSSE4_A |
208bdd1243dSDimitry Andric     FeatureXOP | FeatureXSAVE;
209bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesBDVER2 =
210bdd1243dSDimitry Andric     FeaturesBDVER1 | FeatureBMI | FeatureFMA | FeatureF16C | FeatureTBM;
211bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesBDVER3 =
212bdd1243dSDimitry Andric     FeaturesBDVER2 | FeatureFSGSBASE | FeatureXSAVEOPT;
213bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesBDVER4 = FeaturesBDVER3 | FeatureAVX2 |
214bdd1243dSDimitry Andric                                          FeatureBMI2 | FeatureMOVBE |
215bdd1243dSDimitry Andric                                          FeatureMWAITX | FeatureRDRND;
216bdd1243dSDimitry Andric 
217bdd1243dSDimitry Andric // AMD Zen architecture processors.
218bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesZNVER1 =
219bdd1243dSDimitry Andric     FeatureX87 | FeatureADX | FeatureAES | FeatureAVX | FeatureAVX2 |
220bdd1243dSDimitry Andric     FeatureBMI | FeatureBMI2 | FeatureCLFLUSHOPT | FeatureCLZERO |
221bdd1243dSDimitry Andric     FeatureCMPXCHG8B | FeatureCMPXCHG16B | FeatureCRC32 | Feature64BIT |
222bdd1243dSDimitry Andric     FeatureF16C | FeatureFMA | FeatureFSGSBASE | FeatureFXSR | FeatureLZCNT |
223bdd1243dSDimitry Andric     FeatureMMX | FeatureMOVBE | FeatureMWAITX | FeaturePCLMUL | FeaturePOPCNT |
224bdd1243dSDimitry Andric     FeaturePRFCHW | FeatureRDRND | FeatureRDSEED | FeatureSAHF | FeatureSHA |
225bdd1243dSDimitry Andric     FeatureSSE | FeatureSSE2 | FeatureSSE3 | FeatureSSSE3 | FeatureSSE4_1 |
226bdd1243dSDimitry Andric     FeatureSSE4_2 | FeatureSSE4_A | FeatureXSAVE | FeatureXSAVEC |
227bdd1243dSDimitry Andric     FeatureXSAVEOPT | FeatureXSAVES;
228bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesZNVER2 = FeaturesZNVER1 | FeatureCLWB |
229bdd1243dSDimitry Andric                                          FeatureRDPID | FeatureRDPRU |
230bdd1243dSDimitry Andric                                          FeatureWBNOINVD;
231bdd1243dSDimitry Andric static constexpr FeatureBitset FeaturesZNVER3 = FeaturesZNVER2 |
232bdd1243dSDimitry Andric                                                 FeatureINVPCID | FeaturePKU |
233bdd1243dSDimitry Andric                                                 FeatureVAES | FeatureVPCLMULQDQ;
234bdd1243dSDimitry Andric static constexpr FeatureBitset FeaturesZNVER4 =
2355f757f3fSDimitry Andric     FeaturesZNVER3 | FeatureAVX512F | FeatureEVEX512 | FeatureAVX512CD |
2365f757f3fSDimitry Andric     FeatureAVX512DQ | FeatureAVX512BW | FeatureAVX512VL | FeatureAVX512IFMA |
2375f757f3fSDimitry Andric     FeatureAVX512VBMI | FeatureAVX512VBMI2 | FeatureAVX512VNNI |
2385f757f3fSDimitry Andric     FeatureAVX512BITALG | FeatureAVX512VPOPCNTDQ | FeatureAVX512BF16 |
2395f757f3fSDimitry Andric     FeatureGFNI | FeatureSHSTK;
240bdd1243dSDimitry Andric 
241*c80e69b0SDimitry Andric static constexpr FeatureBitset FeaturesZNVER5 =
242*c80e69b0SDimitry Andric     FeaturesZNVER4 | FeatureAVXVNNI | FeatureMOVDIRI | FeatureMOVDIR64B |
243*c80e69b0SDimitry Andric     FeatureAVX512VP2INTERSECT | FeaturePREFETCHI | FeatureAVXVNNI;
244*c80e69b0SDimitry Andric 
24506c3fb27SDimitry Andric // D151696 tranplanted Mangling and OnlyForCPUDispatchSpecific from
24606c3fb27SDimitry Andric // X86TargetParser.def to here. They are assigned by following ways:
24706c3fb27SDimitry Andric // 1. Copy the mangling from the original CPU_SPEICIFC MACROs. If no, assign
24806c3fb27SDimitry Andric // to '\0' by default, which means not support cpu_specific/dispatch feature.
24906c3fb27SDimitry Andric // 2. set OnlyForCPUDispatchSpecific as true if this cpu name was not
25006c3fb27SDimitry Andric // listed here before, which means it doesn't support -march, -mtune and so on.
25106c3fb27SDimitry Andric // FIXME: Remove OnlyForCPUDispatchSpecific after all CPUs here support both
25206c3fb27SDimitry Andric // cpu_dispatch/specific() feature and -march, -mtune, and so on.
2535f757f3fSDimitry Andric // clang-format off
254bdd1243dSDimitry Andric constexpr ProcInfo Processors[] = {
255bdd1243dSDimitry Andric  // Empty processor. Include X87 and CMPXCHG8 for backwards compatibility.
25606c3fb27SDimitry Andric   { {""}, CK_None, ~0U, FeatureX87 | FeatureCMPXCHG8B, '\0', false },
25706c3fb27SDimitry Andric   { {"generic"}, CK_None, ~0U, FeatureX87 | FeatureCMPXCHG8B | Feature64BIT, 'A', true },
258bdd1243dSDimitry Andric   // i386-generation processors.
25906c3fb27SDimitry Andric   { {"i386"}, CK_i386, ~0U, FeatureX87, '\0', false },
260bdd1243dSDimitry Andric   // i486-generation processors.
26106c3fb27SDimitry Andric   { {"i486"}, CK_i486, ~0U, FeatureX87, '\0', false },
26206c3fb27SDimitry Andric   { {"winchip-c6"}, CK_WinChipC6, ~0U, FeaturesPentiumMMX, '\0', false },
2630fca6ea1SDimitry Andric   { {"winchip2"}, CK_WinChip2, ~0U, FeaturesPentiumMMX | FeaturePRFCHW, '\0', false },
2640fca6ea1SDimitry Andric   { {"c3"}, CK_C3, ~0U, FeaturesPentiumMMX | FeaturePRFCHW, '\0', false },
265bdd1243dSDimitry Andric   // i586-generation processors, P5 microarchitecture based.
26606c3fb27SDimitry Andric   { {"i586"}, CK_i586, ~0U, FeatureX87 | FeatureCMPXCHG8B, '\0', false },
26706c3fb27SDimitry Andric   { {"pentium"}, CK_Pentium, ~0U, FeatureX87 | FeatureCMPXCHG8B, 'B', false },
26806c3fb27SDimitry Andric   { {"pentium-mmx"}, CK_PentiumMMX, ~0U, FeaturesPentiumMMX, '\0', false },
26906c3fb27SDimitry Andric   { {"pentium_mmx"}, CK_PentiumMMX, ~0U, FeaturesPentiumMMX, 'D', true },
270bdd1243dSDimitry Andric   // i686-generation processors, P6 / Pentium M microarchitecture based.
27106c3fb27SDimitry Andric   { {"pentiumpro"}, CK_PentiumPro, ~0U, FeatureCMOV | FeatureX87 | FeatureCMPXCHG8B, 'C', false },
27206c3fb27SDimitry Andric   { {"pentium_pro"}, CK_PentiumPro, ~0U, FeatureCMOV | FeatureX87 | FeatureCMPXCHG8B, 'C', true },
27306c3fb27SDimitry Andric   { {"i686"}, CK_i686, ~0U, FeatureCMOV | FeatureX87 | FeatureCMPXCHG8B, '\0', false },
27406c3fb27SDimitry Andric   { {"pentium2"}, CK_Pentium2, ~0U, FeaturesPentium2, 'E', false },
27506c3fb27SDimitry Andric   { {"pentium_ii"}, CK_Pentium2, ~0U, FeaturesPentium2, 'E', true },
27606c3fb27SDimitry Andric   { {"pentium3"}, CK_Pentium3, ~0U, FeaturesPentium3, 'H', false },
27706c3fb27SDimitry Andric   { {"pentium3m"}, CK_Pentium3, ~0U, FeaturesPentium3, 'H', false },
27806c3fb27SDimitry Andric   { {"pentium_iii"}, CK_Pentium3, ~0U, FeaturesPentium3, 'H', true },
27906c3fb27SDimitry Andric   { {"pentium_iii_no_xmm_regs"}, CK_Pentium3, ~0U, FeaturesPentium3, 'H', true },
28006c3fb27SDimitry Andric   { {"pentium-m"}, CK_PentiumM, ~0U, FeaturesPentium4, '\0', false },
28106c3fb27SDimitry Andric   { {"pentium_m"}, CK_PentiumM, ~0U, FeaturesPentium4, 'K', true },
28206c3fb27SDimitry Andric   { {"c3-2"}, CK_C3_2, ~0U, FeaturesPentium3, '\0', false },
28306c3fb27SDimitry Andric   { {"yonah"}, CK_Yonah, ~0U, FeaturesPrescott, 'L', false },
284bdd1243dSDimitry Andric   // Netburst microarchitecture based processors.
28506c3fb27SDimitry Andric   { {"pentium4"}, CK_Pentium4, ~0U, FeaturesPentium4, 'J', false },
28606c3fb27SDimitry Andric   { {"pentium4m"}, CK_Pentium4, ~0U, FeaturesPentium4, 'J', false },
28706c3fb27SDimitry Andric   { {"pentium_4"}, CK_Pentium4, ~0U, FeaturesPentium4, 'J', true },
28806c3fb27SDimitry Andric   { {"pentium_4_sse3"}, CK_Prescott, ~0U, FeaturesPrescott, 'L', true },
28906c3fb27SDimitry Andric   { {"prescott"}, CK_Prescott, ~0U, FeaturesPrescott, 'L', false },
29006c3fb27SDimitry Andric   { {"nocona"}, CK_Nocona, ~0U, FeaturesNocona, 'L', false },
291bdd1243dSDimitry Andric   // Core microarchitecture based processors.
29206c3fb27SDimitry Andric   { {"core2"}, CK_Core2, FEATURE_SSSE3, FeaturesCore2, 'M', false },
29306c3fb27SDimitry Andric   { {"core_2_duo_ssse3"}, CK_Core2, ~0U, FeaturesCore2, 'M', true },
29406c3fb27SDimitry Andric   { {"penryn"}, CK_Penryn, ~0U, FeaturesPenryn, 'N', false },
29506c3fb27SDimitry Andric   { {"core_2_duo_sse4_1"}, CK_Penryn, ~0U, FeaturesPenryn, 'N', true },
296bdd1243dSDimitry Andric   // Atom processors
29706c3fb27SDimitry Andric   { {"bonnell"}, CK_Bonnell, FEATURE_SSSE3, FeaturesBonnell, 'O', false },
29806c3fb27SDimitry Andric   { {"atom"}, CK_Bonnell, FEATURE_SSSE3, FeaturesBonnell, 'O', false },
29906c3fb27SDimitry Andric   { {"silvermont"}, CK_Silvermont, FEATURE_SSE4_2, FeaturesSilvermont, 'c', false },
30006c3fb27SDimitry Andric   { {"slm"}, CK_Silvermont, FEATURE_SSE4_2, FeaturesSilvermont, 'c', false },
30106c3fb27SDimitry Andric   { {"atom_sse4_2"}, CK_Nehalem, FEATURE_SSE4_2, FeaturesNehalem, 'c', true },
30206c3fb27SDimitry Andric   { {"atom_sse4_2_movbe"}, CK_Goldmont, FEATURE_SSE4_2, FeaturesGoldmont, 'd', true },
30306c3fb27SDimitry Andric   { {"goldmont"}, CK_Goldmont, FEATURE_SSE4_2, FeaturesGoldmont, 'i', false },
30406c3fb27SDimitry Andric   { {"goldmont-plus"}, CK_GoldmontPlus, FEATURE_SSE4_2, FeaturesGoldmontPlus, '\0', false },
30506c3fb27SDimitry Andric   { {"goldmont_plus"}, CK_GoldmontPlus, FEATURE_SSE4_2, FeaturesGoldmontPlus, 'd', true },
30606c3fb27SDimitry Andric   { {"tremont"}, CK_Tremont, FEATURE_SSE4_2, FeaturesTremont, 'd', false },
307bdd1243dSDimitry Andric   // Nehalem microarchitecture based processors.
30806c3fb27SDimitry Andric   { {"nehalem"}, CK_Nehalem, FEATURE_SSE4_2, FeaturesNehalem, 'P', false },
30906c3fb27SDimitry Andric   { {"core_i7_sse4_2"}, CK_Nehalem, FEATURE_SSE4_2, FeaturesNehalem, 'P', true },
31006c3fb27SDimitry Andric   { {"corei7"}, CK_Nehalem, FEATURE_SSE4_2, FeaturesNehalem, 'P', false },
311bdd1243dSDimitry Andric   // Westmere microarchitecture based processors.
31206c3fb27SDimitry Andric   { {"westmere"}, CK_Westmere, FEATURE_PCLMUL, FeaturesWestmere, 'Q', false },
31306c3fb27SDimitry Andric   { {"core_aes_pclmulqdq"}, CK_Nehalem, FEATURE_SSE4_2, FeaturesNehalem, 'Q', true },
314bdd1243dSDimitry Andric   // Sandy Bridge microarchitecture based processors.
31506c3fb27SDimitry Andric   { {"sandybridge"}, CK_SandyBridge, FEATURE_AVX, FeaturesSandyBridge, 'R', false },
31606c3fb27SDimitry Andric   { {"core_2nd_gen_avx"}, CK_SandyBridge, FEATURE_AVX, FeaturesSandyBridge, 'R', true },
31706c3fb27SDimitry Andric   { {"corei7-avx"}, CK_SandyBridge, FEATURE_AVX, FeaturesSandyBridge, '\0', false },
318bdd1243dSDimitry Andric   // Ivy Bridge microarchitecture based processors.
31906c3fb27SDimitry Andric   { {"ivybridge"}, CK_IvyBridge, FEATURE_AVX, FeaturesIvyBridge, 'S', false },
32006c3fb27SDimitry Andric   { {"core_3rd_gen_avx"}, CK_IvyBridge, FEATURE_AVX, FeaturesIvyBridge, 'S', true },
32106c3fb27SDimitry Andric   { {"core-avx-i"}, CK_IvyBridge, FEATURE_AVX, FeaturesIvyBridge, '\0', false },
322bdd1243dSDimitry Andric   // Haswell microarchitecture based processors.
32306c3fb27SDimitry Andric   { {"haswell"}, CK_Haswell, FEATURE_AVX2, FeaturesHaswell, 'V', false },
32406c3fb27SDimitry Andric   { {"core-avx2"}, CK_Haswell, FEATURE_AVX2, FeaturesHaswell, '\0', false },
32506c3fb27SDimitry Andric   { {"core_4th_gen_avx"}, CK_Haswell, FEATURE_AVX2, FeaturesHaswell, 'V', true },
32606c3fb27SDimitry Andric   { {"core_4th_gen_avx_tsx"}, CK_Haswell, FEATURE_AVX2, FeaturesHaswell, 'W', true },
327bdd1243dSDimitry Andric   // Broadwell microarchitecture based processors.
32806c3fb27SDimitry Andric   { {"broadwell"}, CK_Broadwell, FEATURE_AVX2, FeaturesBroadwell, 'X', false },
32906c3fb27SDimitry Andric   { {"core_5th_gen_avx"}, CK_Broadwell, FEATURE_AVX2, FeaturesBroadwell, 'X', true },
33006c3fb27SDimitry Andric   { {"core_5th_gen_avx_tsx"}, CK_Broadwell, FEATURE_AVX2, FeaturesBroadwell, 'Y', true },
331bdd1243dSDimitry Andric   // Skylake client microarchitecture based processors.
33206c3fb27SDimitry Andric   { {"skylake"}, CK_SkylakeClient, FEATURE_AVX2, FeaturesSkylakeClient, 'b', false },
333bdd1243dSDimitry Andric   // Skylake server microarchitecture based processors.
33406c3fb27SDimitry Andric   { {"skylake-avx512"}, CK_SkylakeServer, FEATURE_AVX512F, FeaturesSkylakeServer, '\0', false },
33506c3fb27SDimitry Andric   { {"skx"}, CK_SkylakeServer, FEATURE_AVX512F, FeaturesSkylakeServer, 'a', false },
33606c3fb27SDimitry Andric   { {"skylake_avx512"}, CK_SkylakeServer, FEATURE_AVX512F, FeaturesSkylakeServer, 'a', true },
337bdd1243dSDimitry Andric   // Cascadelake Server microarchitecture based processors.
33806c3fb27SDimitry Andric   { {"cascadelake"}, CK_Cascadelake, FEATURE_AVX512VNNI, FeaturesCascadeLake, 'o', false },
339bdd1243dSDimitry Andric   // Cooperlake Server microarchitecture based processors.
34006c3fb27SDimitry Andric   { {"cooperlake"}, CK_Cooperlake, FEATURE_AVX512BF16, FeaturesCooperLake, 'f', false },
341bdd1243dSDimitry Andric   // Cannonlake client microarchitecture based processors.
34206c3fb27SDimitry Andric   { {"cannonlake"}, CK_Cannonlake, FEATURE_AVX512VBMI, FeaturesCannonlake, 'e', false },
343bdd1243dSDimitry Andric   // Icelake client microarchitecture based processors.
34406c3fb27SDimitry Andric   { {"icelake-client"}, CK_IcelakeClient, FEATURE_AVX512VBMI2, FeaturesICLClient, '\0', false },
34506c3fb27SDimitry Andric   { {"icelake_client"}, CK_IcelakeClient, FEATURE_AVX512VBMI2, FeaturesICLClient, 'k', true },
346bdd1243dSDimitry Andric   // Rocketlake microarchitecture based processors.
34706c3fb27SDimitry Andric   { {"rocketlake"}, CK_Rocketlake, FEATURE_AVX512VBMI2, FeaturesRocketlake, 'k', false },
348bdd1243dSDimitry Andric   // Icelake server microarchitecture based processors.
34906c3fb27SDimitry Andric   { {"icelake-server"}, CK_IcelakeServer, FEATURE_AVX512VBMI2, FeaturesICLServer, '\0', false },
35006c3fb27SDimitry Andric   { {"icelake_server"}, CK_IcelakeServer, FEATURE_AVX512VBMI2, FeaturesICLServer, 'k', true },
351bdd1243dSDimitry Andric   // Tigerlake microarchitecture based processors.
35206c3fb27SDimitry Andric   { {"tigerlake"}, CK_Tigerlake, FEATURE_AVX512VP2INTERSECT, FeaturesTigerlake, 'l', false },
353bdd1243dSDimitry Andric   // Sapphire Rapids microarchitecture based processors.
3547a6dacacSDimitry Andric   { {"sapphirerapids"}, CK_SapphireRapids, FEATURE_AVX512FP16, FeaturesSapphireRapids, 'n', false },
355bdd1243dSDimitry Andric   // Alderlake microarchitecture based processors.
35606c3fb27SDimitry Andric   { {"alderlake"}, CK_Alderlake, FEATURE_AVX2, FeaturesAlderlake, 'p', false },
357bdd1243dSDimitry Andric   // Raptorlake microarchitecture based processors.
35806c3fb27SDimitry Andric   { {"raptorlake"}, CK_Raptorlake, FEATURE_AVX2, FeaturesAlderlake, 'p', false },
359bdd1243dSDimitry Andric   // Meteorlake microarchitecture based processors.
36006c3fb27SDimitry Andric   { {"meteorlake"}, CK_Meteorlake, FEATURE_AVX2, FeaturesAlderlake, 'p', false },
3615f757f3fSDimitry Andric   // Arrowlake microarchitecture based processors.
3625f757f3fSDimitry Andric   { {"arrowlake"}, CK_Arrowlake, FEATURE_AVX2, FeaturesSierraforest, 'p', false },
3635f757f3fSDimitry Andric   { {"arrowlake-s"}, CK_ArrowlakeS, FEATURE_AVX2, FeaturesArrowlakeS, '\0', false },
3645f757f3fSDimitry Andric   { {"arrowlake_s"}, CK_ArrowlakeS, FEATURE_AVX2, FeaturesArrowlakeS, 'p', true },
3655f757f3fSDimitry Andric   // Lunarlake microarchitecture based processors.
3665f757f3fSDimitry Andric   { {"lunarlake"}, CK_Lunarlake, FEATURE_AVX2, FeaturesArrowlakeS, 'p', false },
3675f757f3fSDimitry Andric   // Gracemont microarchitecture based processors.
3685f757f3fSDimitry Andric   { {"gracemont"}, CK_Gracemont, FEATURE_AVX2, FeaturesAlderlake, 'p', false },
3695f757f3fSDimitry Andric   // Pantherlake microarchitecture based processors.
3705f757f3fSDimitry Andric   { {"pantherlake"}, CK_Lunarlake, FEATURE_AVX2, FeaturesPantherlake, 'p', false },
371bdd1243dSDimitry Andric   // Sierraforest microarchitecture based processors.
37206c3fb27SDimitry Andric   { {"sierraforest"}, CK_Sierraforest, FEATURE_AVX2, FeaturesSierraforest, 'p', false },
373bdd1243dSDimitry Andric   // Grandridge microarchitecture based processors.
374647cbc5dSDimitry Andric   { {"grandridge"}, CK_Grandridge, FEATURE_AVX2, FeaturesSierraforest, 'p', false },
375bdd1243dSDimitry Andric   // Granite Rapids microarchitecture based processors.
3767a6dacacSDimitry Andric   { {"graniterapids"}, CK_Graniterapids, FEATURE_AVX512FP16, FeaturesGraniteRapids, 'n', false },
37706c3fb27SDimitry Andric   // Granite Rapids D microarchitecture based processors.
3787a6dacacSDimitry Andric   { {"graniterapids-d"}, CK_GraniterapidsD, FEATURE_AVX512FP16, FeaturesGraniteRapids | FeatureAMX_COMPLEX, '\0', false },
3797a6dacacSDimitry Andric   { {"graniterapids_d"}, CK_GraniterapidsD, FEATURE_AVX512FP16, FeaturesGraniteRapids | FeatureAMX_COMPLEX, 'n', true },
380bdd1243dSDimitry Andric   // Emerald Rapids microarchitecture based processors.
3817a6dacacSDimitry Andric   { {"emeraldrapids"}, CK_Emeraldrapids, FEATURE_AVX512FP16, FeaturesSapphireRapids, 'n', false },
3825f757f3fSDimitry Andric   // Clearwaterforest microarchitecture based processors.
3835f757f3fSDimitry Andric   { {"clearwaterforest"}, CK_Lunarlake, FEATURE_AVX2, FeaturesClearwaterforest, 'p', false },
384bdd1243dSDimitry Andric   // Knights Landing processor.
38506c3fb27SDimitry Andric   { {"knl"}, CK_KNL, FEATURE_AVX512F, FeaturesKNL, 'Z', false },
38606c3fb27SDimitry Andric   { {"mic_avx512"}, CK_KNL, FEATURE_AVX512F, FeaturesKNL, 'Z', true },
387bdd1243dSDimitry Andric   // Knights Mill processor.
38806c3fb27SDimitry Andric   { {"knm"}, CK_KNM, FEATURE_AVX5124FMAPS, FeaturesKNM, 'j', false },
389bdd1243dSDimitry Andric   // Lakemont microarchitecture based processors.
39006c3fb27SDimitry Andric   { {"lakemont"}, CK_Lakemont, ~0U, FeatureCMPXCHG8B, '\0', false },
391bdd1243dSDimitry Andric   // K6 architecture processors.
39206c3fb27SDimitry Andric   { {"k6"}, CK_K6, ~0U, FeaturesK6, '\0', false },
3930fca6ea1SDimitry Andric   { {"k6-2"}, CK_K6_2, ~0U, FeaturesK6 | FeaturePRFCHW, '\0', false },
3940fca6ea1SDimitry Andric   { {"k6-3"}, CK_K6_3, ~0U, FeaturesK6 | FeaturePRFCHW, '\0', false },
395bdd1243dSDimitry Andric   // K7 architecture processors.
39606c3fb27SDimitry Andric   { {"athlon"}, CK_Athlon, ~0U, FeaturesAthlon, '\0', false },
39706c3fb27SDimitry Andric   { {"athlon-tbird"}, CK_Athlon, ~0U, FeaturesAthlon, '\0', false },
39806c3fb27SDimitry Andric   { {"athlon-xp"}, CK_AthlonXP, ~0U, FeaturesAthlonXP, '\0', false },
39906c3fb27SDimitry Andric   { {"athlon-mp"}, CK_AthlonXP, ~0U, FeaturesAthlonXP, '\0', false },
40006c3fb27SDimitry Andric   { {"athlon-4"}, CK_AthlonXP, ~0U, FeaturesAthlonXP, '\0', false },
401bdd1243dSDimitry Andric   // K8 architecture processors.
40206c3fb27SDimitry Andric   { {"k8"}, CK_K8, ~0U, FeaturesK8, '\0', false },
40306c3fb27SDimitry Andric   { {"athlon64"}, CK_K8, ~0U, FeaturesK8, '\0', false },
40406c3fb27SDimitry Andric   { {"athlon-fx"}, CK_K8, ~0U, FeaturesK8, '\0', false },
40506c3fb27SDimitry Andric   { {"opteron"}, CK_K8, ~0U, FeaturesK8, '\0', false },
40606c3fb27SDimitry Andric   { {"k8-sse3"}, CK_K8SSE3, ~0U, FeaturesK8SSE3, '\0', false },
40706c3fb27SDimitry Andric   { {"athlon64-sse3"}, CK_K8SSE3, ~0U, FeaturesK8SSE3, '\0', false },
40806c3fb27SDimitry Andric   { {"opteron-sse3"}, CK_K8SSE3, ~0U, FeaturesK8SSE3, '\0', false },
40906c3fb27SDimitry Andric   { {"amdfam10"}, CK_AMDFAM10, FEATURE_SSE4_A, FeaturesAMDFAM10, '\0', false },
41006c3fb27SDimitry Andric   { {"barcelona"}, CK_AMDFAM10, FEATURE_SSE4_A, FeaturesAMDFAM10, '\0', false },
411bdd1243dSDimitry Andric   // Bobcat architecture processors.
41206c3fb27SDimitry Andric   { {"btver1"}, CK_BTVER1, FEATURE_SSE4_A, FeaturesBTVER1, '\0', false },
41306c3fb27SDimitry Andric   { {"btver2"}, CK_BTVER2, FEATURE_BMI, FeaturesBTVER2, '\0', false },
414bdd1243dSDimitry Andric   // Bulldozer architecture processors.
41506c3fb27SDimitry Andric   { {"bdver1"}, CK_BDVER1, FEATURE_XOP, FeaturesBDVER1, '\0', false },
41606c3fb27SDimitry Andric   { {"bdver2"}, CK_BDVER2, FEATURE_FMA, FeaturesBDVER2, '\0', false },
41706c3fb27SDimitry Andric   { {"bdver3"}, CK_BDVER3, FEATURE_FMA, FeaturesBDVER3, '\0', false },
41806c3fb27SDimitry Andric   { {"bdver4"}, CK_BDVER4, FEATURE_AVX2, FeaturesBDVER4, '\0', false },
419bdd1243dSDimitry Andric   // Zen architecture processors.
42006c3fb27SDimitry Andric   { {"znver1"}, CK_ZNVER1, FEATURE_AVX2, FeaturesZNVER1, '\0', false },
42106c3fb27SDimitry Andric   { {"znver2"}, CK_ZNVER2, FEATURE_AVX2, FeaturesZNVER2, '\0', false },
42206c3fb27SDimitry Andric   { {"znver3"}, CK_ZNVER3, FEATURE_AVX2, FeaturesZNVER3, '\0', false },
42306c3fb27SDimitry Andric   { {"znver4"}, CK_ZNVER4, FEATURE_AVX512VBMI2, FeaturesZNVER4, '\0', false },
424*c80e69b0SDimitry Andric   { {"znver5"}, CK_ZNVER5, FEATURE_AVX512VP2INTERSECT, FeaturesZNVER5, '\0', false },
425bdd1243dSDimitry Andric   // Generic 64-bit processor.
4265f757f3fSDimitry Andric   { {"x86-64"}, CK_x86_64, FEATURE_SSE2 , FeaturesX86_64, '\0', false },
4275f757f3fSDimitry Andric   { {"x86-64-v2"}, CK_x86_64_v2, FEATURE_SSE4_2 , FeaturesX86_64_V2, '\0', false },
4285f757f3fSDimitry Andric   { {"x86-64-v3"}, CK_x86_64_v3, FEATURE_AVX2, FeaturesX86_64_V3, '\0', false },
4295f757f3fSDimitry Andric   { {"x86-64-v4"}, CK_x86_64_v4, FEATURE_AVX512VL, FeaturesX86_64_V4, '\0', false },
430bdd1243dSDimitry Andric   // Geode processors.
43106c3fb27SDimitry Andric   { {"geode"}, CK_Geode, ~0U, FeaturesGeode, '\0', false },
432bdd1243dSDimitry Andric };
4335f757f3fSDimitry Andric // clang-format on
434bdd1243dSDimitry Andric 
435bdd1243dSDimitry Andric constexpr const char *NoTuneList[] = {"x86-64-v2", "x86-64-v3", "x86-64-v4"};
436bdd1243dSDimitry Andric 
437bdd1243dSDimitry Andric X86::CPUKind llvm::X86::parseArchX86(StringRef CPU, bool Only64Bit) {
438bdd1243dSDimitry Andric   for (const auto &P : Processors)
43906c3fb27SDimitry Andric     if (!P.OnlyForCPUDispatchSpecific && P.Name == CPU &&
44006c3fb27SDimitry Andric         (P.Features[FEATURE_64BIT] || !Only64Bit))
441bdd1243dSDimitry Andric       return P.Kind;
442bdd1243dSDimitry Andric 
443bdd1243dSDimitry Andric   return CK_None;
444bdd1243dSDimitry Andric }
445bdd1243dSDimitry Andric 
446bdd1243dSDimitry Andric X86::CPUKind llvm::X86::parseTuneCPU(StringRef CPU, bool Only64Bit) {
447bdd1243dSDimitry Andric   if (llvm::is_contained(NoTuneList, CPU))
448bdd1243dSDimitry Andric     return CK_None;
449bdd1243dSDimitry Andric   return parseArchX86(CPU, Only64Bit);
450bdd1243dSDimitry Andric }
451bdd1243dSDimitry Andric 
452bdd1243dSDimitry Andric void llvm::X86::fillValidCPUArchList(SmallVectorImpl<StringRef> &Values,
453bdd1243dSDimitry Andric                                      bool Only64Bit) {
454bdd1243dSDimitry Andric   for (const auto &P : Processors)
45506c3fb27SDimitry Andric     if (!P.OnlyForCPUDispatchSpecific && !P.Name.empty() &&
45606c3fb27SDimitry Andric         (P.Features[FEATURE_64BIT] || !Only64Bit))
457bdd1243dSDimitry Andric       Values.emplace_back(P.Name);
458bdd1243dSDimitry Andric }
459bdd1243dSDimitry Andric 
460bdd1243dSDimitry Andric void llvm::X86::fillValidTuneCPUList(SmallVectorImpl<StringRef> &Values,
461bdd1243dSDimitry Andric                                      bool Only64Bit) {
462bdd1243dSDimitry Andric   for (const ProcInfo &P : Processors)
46306c3fb27SDimitry Andric     if (!P.OnlyForCPUDispatchSpecific && !P.Name.empty() &&
46406c3fb27SDimitry Andric         (P.Features[FEATURE_64BIT] || !Only64Bit) &&
465bdd1243dSDimitry Andric         !llvm::is_contained(NoTuneList, P.Name))
466bdd1243dSDimitry Andric       Values.emplace_back(P.Name);
467bdd1243dSDimitry Andric }
468bdd1243dSDimitry Andric 
469bdd1243dSDimitry Andric ProcessorFeatures llvm::X86::getKeyFeature(X86::CPUKind Kind) {
470bdd1243dSDimitry Andric   // FIXME: Can we avoid a linear search here? The table might be sorted by
471bdd1243dSDimitry Andric   // CPUKind so we could binary search?
472bdd1243dSDimitry Andric   for (const auto &P : Processors) {
473bdd1243dSDimitry Andric     if (P.Kind == Kind) {
474bdd1243dSDimitry Andric       assert(P.KeyFeature != ~0U && "Processor does not have a key feature.");
475bdd1243dSDimitry Andric       return static_cast<ProcessorFeatures>(P.KeyFeature);
476bdd1243dSDimitry Andric     }
477bdd1243dSDimitry Andric   }
478bdd1243dSDimitry Andric 
479bdd1243dSDimitry Andric   llvm_unreachable("Unable to find CPU kind!");
480bdd1243dSDimitry Andric }
481bdd1243dSDimitry Andric 
482bdd1243dSDimitry Andric // Features with no dependencies.
483bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeatures64BIT = {};
484bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesADX = {};
485bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesBMI = {};
486bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesBMI2 = {};
487bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesCLDEMOTE = {};
488bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesCLFLUSHOPT = {};
489bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesCLWB = {};
490bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesCLZERO = {};
491bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesCMOV = {};
492bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesCMPXCHG16B = {};
493bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesCMPXCHG8B = {};
494bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesCRC32 = {};
495bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesENQCMD = {};
496bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesFSGSBASE = {};
497bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesFXSR = {};
498bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesINVPCID = {};
499bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesLWP = {};
500bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesLZCNT = {};
5010fca6ea1SDimitry Andric constexpr FeatureBitset ImpliedFeaturesMMX = {};
502bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesMWAITX = {};
503bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesMOVBE = {};
504bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesMOVDIR64B = {};
505bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesMOVDIRI = {};
506bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesPCONFIG = {};
507bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesPOPCNT = {};
508bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesPKU = {};
509bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesPRFCHW = {};
510bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesPTWRITE = {};
511bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesRDPID = {};
512bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesRDPRU = {};
513bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesRDRND = {};
514bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesRDSEED = {};
515bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesRTM = {};
516bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesSAHF = {};
517bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesSERIALIZE = {};
518bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesSGX = {};
519bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesSHSTK = {};
520bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesTBM = {};
521bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesTSXLDTRK = {};
522bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesUINTR = {};
5235f757f3fSDimitry Andric constexpr FeatureBitset ImpliedFeaturesUSERMSR = {};
524bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesWAITPKG = {};
525bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesWBNOINVD = {};
526bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesVZEROUPPER = {};
527bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesX87 = {};
528bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesXSAVE = {};
5290fca6ea1SDimitry Andric constexpr FeatureBitset ImpliedFeaturesDUMMYFEATURE1 = {};
5300fca6ea1SDimitry Andric constexpr FeatureBitset ImpliedFeaturesDUMMYFEATURE2 = {};
531bdd1243dSDimitry Andric 
532bdd1243dSDimitry Andric // Not really CPU features, but need to be in the table because clang uses
533bdd1243dSDimitry Andric // target features to communicate them to the backend.
534bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesRETPOLINE_EXTERNAL_THUNK = {};
535bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesRETPOLINE_INDIRECT_BRANCHES = {};
536bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesRETPOLINE_INDIRECT_CALLS = {};
537bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesLVI_CFI = {};
538bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesLVI_LOAD_HARDENING = {};
539bdd1243dSDimitry Andric 
540bdd1243dSDimitry Andric // XSAVE features are dependent on basic XSAVE.
541bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesXSAVEC = FeatureXSAVE;
542bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesXSAVEOPT = FeatureXSAVE;
543bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesXSAVES = FeatureXSAVE;
544bdd1243dSDimitry Andric 
545bdd1243dSDimitry Andric // SSE/AVX/AVX512F chain.
546bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesSSE = {};
547bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesSSE2 = FeatureSSE;
548bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesSSE3 = FeatureSSE2;
549bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesSSSE3 = FeatureSSE3;
550bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesSSE4_1 = FeatureSSSE3;
551bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesSSE4_2 = FeatureSSE4_1;
552bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVX = FeatureSSE4_2;
553bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVX2 = FeatureAVX;
5545f757f3fSDimitry Andric constexpr FeatureBitset ImpliedFeaturesEVEX512 = {};
555bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVX512F =
556bdd1243dSDimitry Andric     FeatureAVX2 | FeatureF16C | FeatureFMA;
557bdd1243dSDimitry Andric 
558bdd1243dSDimitry Andric // Vector extensions that build on SSE or AVX.
559bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAES = FeatureSSE2;
560bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesF16C = FeatureAVX;
561bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesFMA = FeatureAVX;
562bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesGFNI = FeatureSSE2;
563bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesPCLMUL = FeatureSSE2;
564bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesSHA = FeatureSSE2;
5655f757f3fSDimitry Andric constexpr FeatureBitset ImpliedFeaturesVAES = FeatureAES | FeatureAVX2;
566bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesVPCLMULQDQ = FeatureAVX | FeaturePCLMUL;
56706c3fb27SDimitry Andric constexpr FeatureBitset ImpliedFeaturesSM3 = FeatureAVX;
5685f757f3fSDimitry Andric constexpr FeatureBitset ImpliedFeaturesSM4 = FeatureAVX2;
569bdd1243dSDimitry Andric 
570bdd1243dSDimitry Andric // AVX512 features.
571bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVX512CD = FeatureAVX512F;
572bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVX512BW = FeatureAVX512F;
573bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVX512DQ = FeatureAVX512F;
574bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVX512VL = FeatureAVX512F;
575bdd1243dSDimitry Andric 
576bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVX512BF16 = FeatureAVX512BW;
577bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVX512BITALG = FeatureAVX512BW;
578bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVX512IFMA = FeatureAVX512F;
579bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVX512VNNI = FeatureAVX512F;
580bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVX512VPOPCNTDQ = FeatureAVX512F;
581bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVX512VBMI = FeatureAVX512BW;
582bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVX512VBMI2 = FeatureAVX512BW;
583bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVX512VP2INTERSECT = FeatureAVX512F;
584bdd1243dSDimitry Andric 
585bdd1243dSDimitry Andric // FIXME: These two aren't really implemented and just exist in the feature
586bdd1243dSDimitry Andric // list for __builtin_cpu_supports. So omit their dependencies.
587bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVX5124FMAPS = {};
588bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVX5124VNNIW = {};
589bdd1243dSDimitry Andric 
590bdd1243dSDimitry Andric // SSE4_A->FMA4->XOP chain.
591bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesSSE4_A = FeatureSSE3;
592bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesFMA4 = FeatureAVX | FeatureSSE4_A;
593bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesXOP = FeatureFMA4;
594bdd1243dSDimitry Andric 
595bdd1243dSDimitry Andric // AMX Features
596bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAMX_TILE = {};
597bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAMX_BF16 = FeatureAMX_TILE;
598bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAMX_FP16 = FeatureAMX_TILE;
599bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAMX_INT8 = FeatureAMX_TILE;
60006c3fb27SDimitry Andric constexpr FeatureBitset ImpliedFeaturesAMX_COMPLEX = FeatureAMX_TILE;
601bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesHRESET = {};
602bdd1243dSDimitry Andric 
603bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesPREFETCHI = {};
604bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesCMPCCXADD = {};
605bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesRAOINT = {};
60606c3fb27SDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVXVNNIINT16 = FeatureAVX2;
607bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVXVNNIINT8 = FeatureAVX2;
608bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVXIFMA = FeatureAVX2;
609bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVXNECONVERT = FeatureAVX2;
6105f757f3fSDimitry Andric constexpr FeatureBitset ImpliedFeaturesSHA512 = FeatureAVX2;
611bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVX512FP16 =
612bdd1243dSDimitry Andric     FeatureAVX512BW | FeatureAVX512DQ | FeatureAVX512VL;
613bdd1243dSDimitry Andric // Key Locker Features
614bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesKL = FeatureSSE2;
615bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesWIDEKL = FeatureKL;
616bdd1243dSDimitry Andric 
617bdd1243dSDimitry Andric // AVXVNNI Features
618bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVXVNNI = FeatureAVX2;
619bdd1243dSDimitry Andric 
6205f757f3fSDimitry Andric // AVX10 Features
6215f757f3fSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVX10_1 =
6225f757f3fSDimitry Andric     FeatureAVX512CD | FeatureAVX512VBMI | FeatureAVX512IFMA |
6235f757f3fSDimitry Andric     FeatureAVX512VNNI | FeatureAVX512BF16 | FeatureAVX512VPOPCNTDQ |
6245f757f3fSDimitry Andric     FeatureAVX512VBMI2 | FeatureAVX512BITALG | FeatureVAES | FeatureVPCLMULQDQ |
6255f757f3fSDimitry Andric     FeatureAVX512FP16;
6265f757f3fSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVX10_1_512 =
6275f757f3fSDimitry Andric     FeatureAVX10_1 | FeatureEVEX512;
628bdd1243dSDimitry Andric 
6295f757f3fSDimitry Andric // APX Features
6305f757f3fSDimitry Andric constexpr FeatureBitset ImpliedFeaturesEGPR = {};
6315f757f3fSDimitry Andric constexpr FeatureBitset ImpliedFeaturesPush2Pop2 = {};
6325f757f3fSDimitry Andric constexpr FeatureBitset ImpliedFeaturesPPX = {};
6335f757f3fSDimitry Andric constexpr FeatureBitset ImpliedFeaturesNDD = {};
6345f757f3fSDimitry Andric constexpr FeatureBitset ImpliedFeaturesCCMP = {};
6350fca6ea1SDimitry Andric constexpr FeatureBitset ImpliedFeaturesNF = {};
6365f757f3fSDimitry Andric constexpr FeatureBitset ImpliedFeaturesCF = {};
6370fca6ea1SDimitry Andric constexpr FeatureBitset ImpliedFeaturesZU = {};
6385f757f3fSDimitry Andric 
6395f757f3fSDimitry Andric constexpr FeatureInfo FeatureInfos[X86::CPU_FEATURE_MAX] = {
64006c3fb27SDimitry Andric #define X86_FEATURE(ENUM, STR) {{"+" STR}, ImpliedFeatures##ENUM},
64106c3fb27SDimitry Andric #include "llvm/TargetParser/X86TargetParser.def"
64206c3fb27SDimitry Andric };
64306c3fb27SDimitry Andric 
644bdd1243dSDimitry Andric void llvm::X86::getFeaturesForCPU(StringRef CPU,
64506c3fb27SDimitry Andric                                   SmallVectorImpl<StringRef> &EnabledFeatures,
6465f757f3fSDimitry Andric                                   bool NeedPlus) {
647bdd1243dSDimitry Andric   auto I = llvm::find_if(Processors,
648bdd1243dSDimitry Andric                          [&](const ProcInfo &P) { return P.Name == CPU; });
649bdd1243dSDimitry Andric   assert(I != std::end(Processors) && "Processor not found!");
650bdd1243dSDimitry Andric 
651bdd1243dSDimitry Andric   FeatureBitset Bits = I->Features;
652bdd1243dSDimitry Andric 
653bdd1243dSDimitry Andric   // Remove the 64-bit feature which we only use to validate if a CPU can
654bdd1243dSDimitry Andric   // be used with 64-bit mode.
655bdd1243dSDimitry Andric   Bits &= ~Feature64BIT;
656bdd1243dSDimitry Andric 
657bdd1243dSDimitry Andric   // Add the string version of all set bits.
658bdd1243dSDimitry Andric   for (unsigned i = 0; i != CPU_FEATURE_MAX; ++i)
6595f757f3fSDimitry Andric     if (Bits[i] && !FeatureInfos[i].getName(NeedPlus).empty())
6605f757f3fSDimitry Andric       EnabledFeatures.push_back(FeatureInfos[i].getName(NeedPlus));
661bdd1243dSDimitry Andric }
662bdd1243dSDimitry Andric 
663bdd1243dSDimitry Andric // For each feature that is (transitively) implied by this feature, set it.
664bdd1243dSDimitry Andric static void getImpliedEnabledFeatures(FeatureBitset &Bits,
665bdd1243dSDimitry Andric                                       const FeatureBitset &Implies) {
666bdd1243dSDimitry Andric   // Fast path: Implies is often empty.
667bdd1243dSDimitry Andric   if (!Implies.any())
668bdd1243dSDimitry Andric     return;
669bdd1243dSDimitry Andric   FeatureBitset Prev;
670bdd1243dSDimitry Andric   Bits |= Implies;
671bdd1243dSDimitry Andric   do {
672bdd1243dSDimitry Andric     Prev = Bits;
673bdd1243dSDimitry Andric     for (unsigned i = CPU_FEATURE_MAX; i;)
674bdd1243dSDimitry Andric       if (Bits[--i])
675bdd1243dSDimitry Andric         Bits |= FeatureInfos[i].ImpliedFeatures;
676bdd1243dSDimitry Andric   } while (Prev != Bits);
677bdd1243dSDimitry Andric }
678bdd1243dSDimitry Andric 
679bdd1243dSDimitry Andric /// Create bit vector of features that are implied disabled if the feature
680bdd1243dSDimitry Andric /// passed in Value is disabled.
681bdd1243dSDimitry Andric static void getImpliedDisabledFeatures(FeatureBitset &Bits, unsigned Value) {
682bdd1243dSDimitry Andric   // Check all features looking for any dependent on this feature. If we find
683bdd1243dSDimitry Andric   // one, mark it and recursively find any feature that depend on it.
684bdd1243dSDimitry Andric   FeatureBitset Prev;
685bdd1243dSDimitry Andric   Bits.set(Value);
686bdd1243dSDimitry Andric   do {
687bdd1243dSDimitry Andric     Prev = Bits;
688bdd1243dSDimitry Andric     for (unsigned i = 0; i != CPU_FEATURE_MAX; ++i)
689bdd1243dSDimitry Andric       if ((FeatureInfos[i].ImpliedFeatures & Bits).any())
690bdd1243dSDimitry Andric         Bits.set(i);
691bdd1243dSDimitry Andric   } while (Prev != Bits);
692bdd1243dSDimitry Andric }
693bdd1243dSDimitry Andric 
694bdd1243dSDimitry Andric void llvm::X86::updateImpliedFeatures(
695bdd1243dSDimitry Andric     StringRef Feature, bool Enabled,
696bdd1243dSDimitry Andric     StringMap<bool> &Features) {
6975f757f3fSDimitry Andric   auto I = llvm::find_if(FeatureInfos, [&](const FeatureInfo &FI) {
6985f757f3fSDimitry Andric     return FI.getName() == Feature;
6995f757f3fSDimitry Andric   });
700bdd1243dSDimitry Andric   if (I == std::end(FeatureInfos)) {
701bdd1243dSDimitry Andric     // FIXME: This shouldn't happen, but may not have all features in the table
702bdd1243dSDimitry Andric     // yet.
703bdd1243dSDimitry Andric     return;
704bdd1243dSDimitry Andric   }
705bdd1243dSDimitry Andric 
706bdd1243dSDimitry Andric   FeatureBitset ImpliedBits;
707bdd1243dSDimitry Andric   if (Enabled)
708bdd1243dSDimitry Andric     getImpliedEnabledFeatures(ImpliedBits, I->ImpliedFeatures);
709bdd1243dSDimitry Andric   else
710bdd1243dSDimitry Andric     getImpliedDisabledFeatures(ImpliedBits,
711bdd1243dSDimitry Andric                                std::distance(std::begin(FeatureInfos), I));
712bdd1243dSDimitry Andric 
713bdd1243dSDimitry Andric   // Update the map entry for all implied features.
714bdd1243dSDimitry Andric   for (unsigned i = 0; i != CPU_FEATURE_MAX; ++i)
7155f757f3fSDimitry Andric     if (ImpliedBits[i] && !FeatureInfos[i].getName().empty())
7165f757f3fSDimitry Andric       Features[FeatureInfos[i].getName()] = Enabled;
717bdd1243dSDimitry Andric }
718bdd1243dSDimitry Andric 
71906c3fb27SDimitry Andric char llvm::X86::getCPUDispatchMangling(StringRef CPU) {
72006c3fb27SDimitry Andric   auto I = llvm::find_if(Processors,
72106c3fb27SDimitry Andric                          [&](const ProcInfo &P) { return P.Name == CPU; });
72206c3fb27SDimitry Andric   assert(I != std::end(Processors) && "Processor not found!");
72306c3fb27SDimitry Andric   assert(I->Mangling != '\0' && "Processor dooesn't support function multiversion!");
72406c3fb27SDimitry Andric   return I->Mangling;
72506c3fb27SDimitry Andric }
72606c3fb27SDimitry Andric 
72706c3fb27SDimitry Andric bool llvm::X86::validateCPUSpecificCPUDispatch(StringRef Name) {
72806c3fb27SDimitry Andric   auto I = llvm::find_if(Processors,
72906c3fb27SDimitry Andric                          [&](const ProcInfo &P) { return P.Name == Name; });
73006c3fb27SDimitry Andric   return I != std::end(Processors);
73106c3fb27SDimitry Andric }
73206c3fb27SDimitry Andric 
7335f757f3fSDimitry Andric std::array<uint32_t, 4>
7345f757f3fSDimitry Andric llvm::X86::getCpuSupportsMask(ArrayRef<StringRef> FeatureStrs) {
735bdd1243dSDimitry Andric   // Processor features and mapping to processor feature value.
7365f757f3fSDimitry Andric   std::array<uint32_t, 4> FeatureMask{};
7375f757f3fSDimitry Andric   for (StringRef FeatureStr : FeatureStrs) {
738bdd1243dSDimitry Andric     unsigned Feature = StringSwitch<unsigned>(FeatureStr)
739bdd1243dSDimitry Andric #define X86_FEATURE_COMPAT(ENUM, STR, PRIORITY)                                \
740bdd1243dSDimitry Andric   .Case(STR, llvm::X86::FEATURE_##ENUM)
7415f757f3fSDimitry Andric #define X86_MICROARCH_LEVEL(ENUM, STR, PRIORITY)                               \
7425f757f3fSDimitry Andric   .Case(STR, llvm::X86::FEATURE_##ENUM)
743bdd1243dSDimitry Andric #include "llvm/TargetParser/X86TargetParser.def"
744bdd1243dSDimitry Andric         ;
7455f757f3fSDimitry Andric     assert(Feature / 32 < FeatureMask.size());
7465f757f3fSDimitry Andric     FeatureMask[Feature / 32] |= 1U << (Feature % 32);
747bdd1243dSDimitry Andric   }
7485f757f3fSDimitry Andric   return FeatureMask;
749bdd1243dSDimitry Andric }
750bdd1243dSDimitry Andric 
751bdd1243dSDimitry Andric unsigned llvm::X86::getFeaturePriority(ProcessorFeatures Feat) {
752bdd1243dSDimitry Andric #ifndef NDEBUG
753bdd1243dSDimitry Andric   // Check that priorities are set properly in the .def file. We expect that
754bdd1243dSDimitry Andric   // "compat" features are assigned non-duplicate consecutive priorities
7550fca6ea1SDimitry Andric   // starting from one (1, ..., 37) and multiple zeros.
756bdd1243dSDimitry Andric #define X86_FEATURE_COMPAT(ENUM, STR, PRIORITY) PRIORITY,
757bdd1243dSDimitry Andric   unsigned Priorities[] = {
758bdd1243dSDimitry Andric #include "llvm/TargetParser/X86TargetParser.def"
759bdd1243dSDimitry Andric   };
7605f757f3fSDimitry Andric   std::array<unsigned, std::size(Priorities)> HelperList;
7610fca6ea1SDimitry Andric   const size_t MaxPriority = 37;
7620fca6ea1SDimitry Andric   std::iota(HelperList.begin(), HelperList.begin() + MaxPriority + 1, 0);
7630fca6ea1SDimitry Andric   for (size_t i = MaxPriority + 1; i != std::size(Priorities); ++i)
7640fca6ea1SDimitry Andric     HelperList[i] = 0;
765bdd1243dSDimitry Andric   assert(std::is_permutation(HelperList.begin(), HelperList.end(),
7665f757f3fSDimitry Andric                              std::begin(Priorities), std::end(Priorities)) &&
767bdd1243dSDimitry Andric          "Priorities don't form consecutive range!");
768bdd1243dSDimitry Andric #endif
769bdd1243dSDimitry Andric 
770bdd1243dSDimitry Andric   switch (Feat) {
771bdd1243dSDimitry Andric #define X86_FEATURE_COMPAT(ENUM, STR, PRIORITY)                                \
772bdd1243dSDimitry Andric   case X86::FEATURE_##ENUM:                                                    \
773bdd1243dSDimitry Andric     return PRIORITY;
774bdd1243dSDimitry Andric #include "llvm/TargetParser/X86TargetParser.def"
775bdd1243dSDimitry Andric   default:
776bdd1243dSDimitry Andric     llvm_unreachable("No Feature Priority for non-CPUSupports Features");
777bdd1243dSDimitry Andric   }
778bdd1243dSDimitry Andric }
779