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"
14c9157d92SDimitry 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
23c9157d92SDimitry 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;
30fe013be4SDimitry Andric char Mangling;
31fe013be4SDimitry Andric bool OnlyForCPUDispatchSpecific;
32bdd1243dSDimitry Andric };
33bdd1243dSDimitry Andric
34bdd1243dSDimitry Andric struct FeatureInfo {
35c9157d92SDimitry Andric StringLiteral NameWithPlus;
36bdd1243dSDimitry Andric FeatureBitset ImpliedFeatures;
37c9157d92SDimitry Andric
getName__anon087f6b630111::FeatureInfo38c9157d92SDimitry Andric StringRef getName(bool WithPlus = false) const {
39c9157d92SDimitry Andric assert(NameWithPlus[0] == '+' && "Expected string to start with '+'");
40c9157d92SDimitry Andric if (WithPlus)
41c9157d92SDimitry Andric return NameWithPlus;
42c9157d92SDimitry Andric return NameWithPlus.drop_front();
43c9157d92SDimitry 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 =
58fe013be4SDimitry 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;
75c9157d92SDimitry 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.
98bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesKNL =
99c9157d92SDimitry Andric FeaturesBroadwell | FeatureAES | FeatureAVX512F | FeatureEVEX512 |
100c9157d92SDimitry Andric FeatureAVX512CD | FeatureAVX512ER | FeatureAVX512PF | FeaturePREFETCHWT1;
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 =
110c9157d92SDimitry Andric (FeaturesSkylakeClient & ~FeatureSGX) | FeatureAVX512F | FeatureEVEX512 |
111c9157d92SDimitry Andric FeatureAVX512CD | FeatureAVX512DQ | FeatureAVX512BW | FeatureAVX512VL |
112c9157d92SDimitry 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 =
120c9157d92SDimitry Andric FeaturesSkylakeClient | FeatureAVX512F | FeatureEVEX512 | FeatureAVX512CD |
121c9157d92SDimitry Andric FeatureAVX512DQ | FeatureAVX512BW | FeatureAVX512VL | FeatureAVX512IFMA |
122c9157d92SDimitry 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 =
163fe013be4SDimitry Andric FeaturesAlderlake | FeatureCMPCCXADD | FeatureAVXIFMA | FeatureUINTR |
164fe013be4SDimitry Andric FeatureENQCMD | FeatureAVXNECONVERT | FeatureAVXVNNIINT8;
165c9157d92SDimitry Andric constexpr FeatureBitset FeaturesArrowlakeS = FeaturesSierraforest |
166c9157d92SDimitry Andric FeatureAVXVNNIINT16 | FeatureSHA512 | FeatureSM3 | FeatureSM4;
167c9157d92SDimitry Andric constexpr FeatureBitset FeaturesPantherlake =
168c9157d92SDimitry Andric FeaturesArrowlakeS | FeaturePREFETCHI;
169c9157d92SDimitry Andric constexpr FeatureBitset FeaturesClearwaterforest =
170c9157d92SDimitry Andric FeaturesArrowlakeS | FeatureUSERMSR | FeaturePREFETCHI;
171bdd1243dSDimitry Andric
172bdd1243dSDimitry Andric // Geode Processor.
173bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesGeode =
174bdd1243dSDimitry Andric FeatureX87 | FeatureCMPXCHG8B | FeatureMMX | Feature3DNOW | Feature3DNOWA;
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 =
181bdd1243dSDimitry Andric FeatureX87 | FeatureCMPXCHG8B | FeatureMMX | Feature3DNOW | Feature3DNOWA;
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 =
235c9157d92SDimitry Andric FeaturesZNVER3 | FeatureAVX512F | FeatureEVEX512 | FeatureAVX512CD |
236c9157d92SDimitry Andric FeatureAVX512DQ | FeatureAVX512BW | FeatureAVX512VL | FeatureAVX512IFMA |
237c9157d92SDimitry Andric FeatureAVX512VBMI | FeatureAVX512VBMI2 | FeatureAVX512VNNI |
238c9157d92SDimitry Andric FeatureAVX512BITALG | FeatureAVX512VPOPCNTDQ | FeatureAVX512BF16 |
239c9157d92SDimitry Andric FeatureGFNI | FeatureSHSTK;
240bdd1243dSDimitry Andric
241fe013be4SDimitry Andric // D151696 tranplanted Mangling and OnlyForCPUDispatchSpecific from
242fe013be4SDimitry Andric // X86TargetParser.def to here. They are assigned by following ways:
243fe013be4SDimitry Andric // 1. Copy the mangling from the original CPU_SPEICIFC MACROs. If no, assign
244fe013be4SDimitry Andric // to '\0' by default, which means not support cpu_specific/dispatch feature.
245fe013be4SDimitry Andric // 2. set OnlyForCPUDispatchSpecific as true if this cpu name was not
246fe013be4SDimitry Andric // listed here before, which means it doesn't support -march, -mtune and so on.
247fe013be4SDimitry Andric // FIXME: Remove OnlyForCPUDispatchSpecific after all CPUs here support both
248fe013be4SDimitry Andric // cpu_dispatch/specific() feature and -march, -mtune, and so on.
249c9157d92SDimitry Andric // clang-format off
250bdd1243dSDimitry Andric constexpr ProcInfo Processors[] = {
251bdd1243dSDimitry Andric // Empty processor. Include X87 and CMPXCHG8 for backwards compatibility.
252fe013be4SDimitry Andric { {""}, CK_None, ~0U, FeatureX87 | FeatureCMPXCHG8B, '\0', false },
253fe013be4SDimitry Andric { {"generic"}, CK_None, ~0U, FeatureX87 | FeatureCMPXCHG8B | Feature64BIT, 'A', true },
254bdd1243dSDimitry Andric // i386-generation processors.
255fe013be4SDimitry Andric { {"i386"}, CK_i386, ~0U, FeatureX87, '\0', false },
256bdd1243dSDimitry Andric // i486-generation processors.
257fe013be4SDimitry Andric { {"i486"}, CK_i486, ~0U, FeatureX87, '\0', false },
258fe013be4SDimitry Andric { {"winchip-c6"}, CK_WinChipC6, ~0U, FeaturesPentiumMMX, '\0', false },
259fe013be4SDimitry Andric { {"winchip2"}, CK_WinChip2, ~0U, FeaturesPentiumMMX | Feature3DNOW, '\0', false },
260fe013be4SDimitry Andric { {"c3"}, CK_C3, ~0U, FeaturesPentiumMMX | Feature3DNOW, '\0', false },
261bdd1243dSDimitry Andric // i586-generation processors, P5 microarchitecture based.
262fe013be4SDimitry Andric { {"i586"}, CK_i586, ~0U, FeatureX87 | FeatureCMPXCHG8B, '\0', false },
263fe013be4SDimitry Andric { {"pentium"}, CK_Pentium, ~0U, FeatureX87 | FeatureCMPXCHG8B, 'B', false },
264fe013be4SDimitry Andric { {"pentium-mmx"}, CK_PentiumMMX, ~0U, FeaturesPentiumMMX, '\0', false },
265fe013be4SDimitry Andric { {"pentium_mmx"}, CK_PentiumMMX, ~0U, FeaturesPentiumMMX, 'D', true },
266bdd1243dSDimitry Andric // i686-generation processors, P6 / Pentium M microarchitecture based.
267fe013be4SDimitry Andric { {"pentiumpro"}, CK_PentiumPro, ~0U, FeatureCMOV | FeatureX87 | FeatureCMPXCHG8B, 'C', false },
268fe013be4SDimitry Andric { {"pentium_pro"}, CK_PentiumPro, ~0U, FeatureCMOV | FeatureX87 | FeatureCMPXCHG8B, 'C', true },
269fe013be4SDimitry Andric { {"i686"}, CK_i686, ~0U, FeatureCMOV | FeatureX87 | FeatureCMPXCHG8B, '\0', false },
270fe013be4SDimitry Andric { {"pentium2"}, CK_Pentium2, ~0U, FeaturesPentium2, 'E', false },
271fe013be4SDimitry Andric { {"pentium_ii"}, CK_Pentium2, ~0U, FeaturesPentium2, 'E', true },
272fe013be4SDimitry Andric { {"pentium3"}, CK_Pentium3, ~0U, FeaturesPentium3, 'H', false },
273fe013be4SDimitry Andric { {"pentium3m"}, CK_Pentium3, ~0U, FeaturesPentium3, 'H', false },
274fe013be4SDimitry Andric { {"pentium_iii"}, CK_Pentium3, ~0U, FeaturesPentium3, 'H', true },
275fe013be4SDimitry Andric { {"pentium_iii_no_xmm_regs"}, CK_Pentium3, ~0U, FeaturesPentium3, 'H', true },
276fe013be4SDimitry Andric { {"pentium-m"}, CK_PentiumM, ~0U, FeaturesPentium4, '\0', false },
277fe013be4SDimitry Andric { {"pentium_m"}, CK_PentiumM, ~0U, FeaturesPentium4, 'K', true },
278fe013be4SDimitry Andric { {"c3-2"}, CK_C3_2, ~0U, FeaturesPentium3, '\0', false },
279fe013be4SDimitry Andric { {"yonah"}, CK_Yonah, ~0U, FeaturesPrescott, 'L', false },
280bdd1243dSDimitry Andric // Netburst microarchitecture based processors.
281fe013be4SDimitry Andric { {"pentium4"}, CK_Pentium4, ~0U, FeaturesPentium4, 'J', false },
282fe013be4SDimitry Andric { {"pentium4m"}, CK_Pentium4, ~0U, FeaturesPentium4, 'J', false },
283fe013be4SDimitry Andric { {"pentium_4"}, CK_Pentium4, ~0U, FeaturesPentium4, 'J', true },
284fe013be4SDimitry Andric { {"pentium_4_sse3"}, CK_Prescott, ~0U, FeaturesPrescott, 'L', true },
285fe013be4SDimitry Andric { {"prescott"}, CK_Prescott, ~0U, FeaturesPrescott, 'L', false },
286fe013be4SDimitry Andric { {"nocona"}, CK_Nocona, ~0U, FeaturesNocona, 'L', false },
287bdd1243dSDimitry Andric // Core microarchitecture based processors.
288fe013be4SDimitry Andric { {"core2"}, CK_Core2, FEATURE_SSSE3, FeaturesCore2, 'M', false },
289fe013be4SDimitry Andric { {"core_2_duo_ssse3"}, CK_Core2, ~0U, FeaturesCore2, 'M', true },
290fe013be4SDimitry Andric { {"penryn"}, CK_Penryn, ~0U, FeaturesPenryn, 'N', false },
291fe013be4SDimitry Andric { {"core_2_duo_sse4_1"}, CK_Penryn, ~0U, FeaturesPenryn, 'N', true },
292bdd1243dSDimitry Andric // Atom processors
293fe013be4SDimitry Andric { {"bonnell"}, CK_Bonnell, FEATURE_SSSE3, FeaturesBonnell, 'O', false },
294fe013be4SDimitry Andric { {"atom"}, CK_Bonnell, FEATURE_SSSE3, FeaturesBonnell, 'O', false },
295fe013be4SDimitry Andric { {"silvermont"}, CK_Silvermont, FEATURE_SSE4_2, FeaturesSilvermont, 'c', false },
296fe013be4SDimitry Andric { {"slm"}, CK_Silvermont, FEATURE_SSE4_2, FeaturesSilvermont, 'c', false },
297fe013be4SDimitry Andric { {"atom_sse4_2"}, CK_Nehalem, FEATURE_SSE4_2, FeaturesNehalem, 'c', true },
298fe013be4SDimitry Andric { {"atom_sse4_2_movbe"}, CK_Goldmont, FEATURE_SSE4_2, FeaturesGoldmont, 'd', true },
299fe013be4SDimitry Andric { {"goldmont"}, CK_Goldmont, FEATURE_SSE4_2, FeaturesGoldmont, 'i', false },
300fe013be4SDimitry Andric { {"goldmont-plus"}, CK_GoldmontPlus, FEATURE_SSE4_2, FeaturesGoldmontPlus, '\0', false },
301fe013be4SDimitry Andric { {"goldmont_plus"}, CK_GoldmontPlus, FEATURE_SSE4_2, FeaturesGoldmontPlus, 'd', true },
302fe013be4SDimitry Andric { {"tremont"}, CK_Tremont, FEATURE_SSE4_2, FeaturesTremont, 'd', false },
303bdd1243dSDimitry Andric // Nehalem microarchitecture based processors.
304fe013be4SDimitry Andric { {"nehalem"}, CK_Nehalem, FEATURE_SSE4_2, FeaturesNehalem, 'P', false },
305fe013be4SDimitry Andric { {"core_i7_sse4_2"}, CK_Nehalem, FEATURE_SSE4_2, FeaturesNehalem, 'P', true },
306fe013be4SDimitry Andric { {"corei7"}, CK_Nehalem, FEATURE_SSE4_2, FeaturesNehalem, 'P', false },
307bdd1243dSDimitry Andric // Westmere microarchitecture based processors.
308fe013be4SDimitry Andric { {"westmere"}, CK_Westmere, FEATURE_PCLMUL, FeaturesWestmere, 'Q', false },
309fe013be4SDimitry Andric { {"core_aes_pclmulqdq"}, CK_Nehalem, FEATURE_SSE4_2, FeaturesNehalem, 'Q', true },
310bdd1243dSDimitry Andric // Sandy Bridge microarchitecture based processors.
311fe013be4SDimitry Andric { {"sandybridge"}, CK_SandyBridge, FEATURE_AVX, FeaturesSandyBridge, 'R', false },
312fe013be4SDimitry Andric { {"core_2nd_gen_avx"}, CK_SandyBridge, FEATURE_AVX, FeaturesSandyBridge, 'R', true },
313fe013be4SDimitry Andric { {"corei7-avx"}, CK_SandyBridge, FEATURE_AVX, FeaturesSandyBridge, '\0', false },
314bdd1243dSDimitry Andric // Ivy Bridge microarchitecture based processors.
315fe013be4SDimitry Andric { {"ivybridge"}, CK_IvyBridge, FEATURE_AVX, FeaturesIvyBridge, 'S', false },
316fe013be4SDimitry Andric { {"core_3rd_gen_avx"}, CK_IvyBridge, FEATURE_AVX, FeaturesIvyBridge, 'S', true },
317fe013be4SDimitry Andric { {"core-avx-i"}, CK_IvyBridge, FEATURE_AVX, FeaturesIvyBridge, '\0', false },
318bdd1243dSDimitry Andric // Haswell microarchitecture based processors.
319fe013be4SDimitry Andric { {"haswell"}, CK_Haswell, FEATURE_AVX2, FeaturesHaswell, 'V', false },
320fe013be4SDimitry Andric { {"core-avx2"}, CK_Haswell, FEATURE_AVX2, FeaturesHaswell, '\0', false },
321fe013be4SDimitry Andric { {"core_4th_gen_avx"}, CK_Haswell, FEATURE_AVX2, FeaturesHaswell, 'V', true },
322fe013be4SDimitry Andric { {"core_4th_gen_avx_tsx"}, CK_Haswell, FEATURE_AVX2, FeaturesHaswell, 'W', true },
323bdd1243dSDimitry Andric // Broadwell microarchitecture based processors.
324fe013be4SDimitry Andric { {"broadwell"}, CK_Broadwell, FEATURE_AVX2, FeaturesBroadwell, 'X', false },
325fe013be4SDimitry Andric { {"core_5th_gen_avx"}, CK_Broadwell, FEATURE_AVX2, FeaturesBroadwell, 'X', true },
326fe013be4SDimitry Andric { {"core_5th_gen_avx_tsx"}, CK_Broadwell, FEATURE_AVX2, FeaturesBroadwell, 'Y', true },
327bdd1243dSDimitry Andric // Skylake client microarchitecture based processors.
328fe013be4SDimitry Andric { {"skylake"}, CK_SkylakeClient, FEATURE_AVX2, FeaturesSkylakeClient, 'b', false },
329bdd1243dSDimitry Andric // Skylake server microarchitecture based processors.
330fe013be4SDimitry Andric { {"skylake-avx512"}, CK_SkylakeServer, FEATURE_AVX512F, FeaturesSkylakeServer, '\0', false },
331fe013be4SDimitry Andric { {"skx"}, CK_SkylakeServer, FEATURE_AVX512F, FeaturesSkylakeServer, 'a', false },
332fe013be4SDimitry Andric { {"skylake_avx512"}, CK_SkylakeServer, FEATURE_AVX512F, FeaturesSkylakeServer, 'a', true },
333bdd1243dSDimitry Andric // Cascadelake Server microarchitecture based processors.
334fe013be4SDimitry Andric { {"cascadelake"}, CK_Cascadelake, FEATURE_AVX512VNNI, FeaturesCascadeLake, 'o', false },
335bdd1243dSDimitry Andric // Cooperlake Server microarchitecture based processors.
336fe013be4SDimitry Andric { {"cooperlake"}, CK_Cooperlake, FEATURE_AVX512BF16, FeaturesCooperLake, 'f', false },
337bdd1243dSDimitry Andric // Cannonlake client microarchitecture based processors.
338fe013be4SDimitry Andric { {"cannonlake"}, CK_Cannonlake, FEATURE_AVX512VBMI, FeaturesCannonlake, 'e', false },
339bdd1243dSDimitry Andric // Icelake client microarchitecture based processors.
340fe013be4SDimitry Andric { {"icelake-client"}, CK_IcelakeClient, FEATURE_AVX512VBMI2, FeaturesICLClient, '\0', false },
341fe013be4SDimitry Andric { {"icelake_client"}, CK_IcelakeClient, FEATURE_AVX512VBMI2, FeaturesICLClient, 'k', true },
342bdd1243dSDimitry Andric // Rocketlake microarchitecture based processors.
343fe013be4SDimitry Andric { {"rocketlake"}, CK_Rocketlake, FEATURE_AVX512VBMI2, FeaturesRocketlake, 'k', false },
344bdd1243dSDimitry Andric // Icelake server microarchitecture based processors.
345fe013be4SDimitry Andric { {"icelake-server"}, CK_IcelakeServer, FEATURE_AVX512VBMI2, FeaturesICLServer, '\0', false },
346fe013be4SDimitry Andric { {"icelake_server"}, CK_IcelakeServer, FEATURE_AVX512VBMI2, FeaturesICLServer, 'k', true },
347bdd1243dSDimitry Andric // Tigerlake microarchitecture based processors.
348fe013be4SDimitry Andric { {"tigerlake"}, CK_Tigerlake, FEATURE_AVX512VP2INTERSECT, FeaturesTigerlake, 'l', false },
349bdd1243dSDimitry Andric // Sapphire Rapids microarchitecture based processors.
350*a58f00eaSDimitry Andric { {"sapphirerapids"}, CK_SapphireRapids, FEATURE_AVX512FP16, FeaturesSapphireRapids, 'n', false },
351bdd1243dSDimitry Andric // Alderlake microarchitecture based processors.
352fe013be4SDimitry Andric { {"alderlake"}, CK_Alderlake, FEATURE_AVX2, FeaturesAlderlake, 'p', false },
353bdd1243dSDimitry Andric // Raptorlake microarchitecture based processors.
354fe013be4SDimitry Andric { {"raptorlake"}, CK_Raptorlake, FEATURE_AVX2, FeaturesAlderlake, 'p', false },
355bdd1243dSDimitry Andric // Meteorlake microarchitecture based processors.
356fe013be4SDimitry Andric { {"meteorlake"}, CK_Meteorlake, FEATURE_AVX2, FeaturesAlderlake, 'p', false },
357c9157d92SDimitry Andric // Arrowlake microarchitecture based processors.
358c9157d92SDimitry Andric { {"arrowlake"}, CK_Arrowlake, FEATURE_AVX2, FeaturesSierraforest, 'p', false },
359c9157d92SDimitry Andric { {"arrowlake-s"}, CK_ArrowlakeS, FEATURE_AVX2, FeaturesArrowlakeS, '\0', false },
360c9157d92SDimitry Andric { {"arrowlake_s"}, CK_ArrowlakeS, FEATURE_AVX2, FeaturesArrowlakeS, 'p', true },
361c9157d92SDimitry Andric // Lunarlake microarchitecture based processors.
362c9157d92SDimitry Andric { {"lunarlake"}, CK_Lunarlake, FEATURE_AVX2, FeaturesArrowlakeS, 'p', false },
363c9157d92SDimitry Andric // Gracemont microarchitecture based processors.
364c9157d92SDimitry Andric { {"gracemont"}, CK_Gracemont, FEATURE_AVX2, FeaturesAlderlake, 'p', false },
365c9157d92SDimitry Andric // Pantherlake microarchitecture based processors.
366c9157d92SDimitry Andric { {"pantherlake"}, CK_Lunarlake, FEATURE_AVX2, FeaturesPantherlake, 'p', false },
367bdd1243dSDimitry Andric // Sierraforest microarchitecture based processors.
368fe013be4SDimitry Andric { {"sierraforest"}, CK_Sierraforest, FEATURE_AVX2, FeaturesSierraforest, 'p', false },
369bdd1243dSDimitry Andric // Grandridge microarchitecture based processors.
370de8261c4SDimitry Andric { {"grandridge"}, CK_Grandridge, FEATURE_AVX2, FeaturesSierraforest, 'p', false },
371bdd1243dSDimitry Andric // Granite Rapids microarchitecture based processors.
372*a58f00eaSDimitry Andric { {"graniterapids"}, CK_Graniterapids, FEATURE_AVX512FP16, FeaturesGraniteRapids, 'n', false },
373fe013be4SDimitry Andric // Granite Rapids D microarchitecture based processors.
374*a58f00eaSDimitry Andric { {"graniterapids-d"}, CK_GraniterapidsD, FEATURE_AVX512FP16, FeaturesGraniteRapids | FeatureAMX_COMPLEX, '\0', false },
375*a58f00eaSDimitry Andric { {"graniterapids_d"}, CK_GraniterapidsD, FEATURE_AVX512FP16, FeaturesGraniteRapids | FeatureAMX_COMPLEX, 'n', true },
376bdd1243dSDimitry Andric // Emerald Rapids microarchitecture based processors.
377*a58f00eaSDimitry Andric { {"emeraldrapids"}, CK_Emeraldrapids, FEATURE_AVX512FP16, FeaturesSapphireRapids, 'n', false },
378c9157d92SDimitry Andric // Clearwaterforest microarchitecture based processors.
379c9157d92SDimitry Andric { {"clearwaterforest"}, CK_Lunarlake, FEATURE_AVX2, FeaturesClearwaterforest, 'p', false },
380bdd1243dSDimitry Andric // Knights Landing processor.
381fe013be4SDimitry Andric { {"knl"}, CK_KNL, FEATURE_AVX512F, FeaturesKNL, 'Z', false },
382fe013be4SDimitry Andric { {"mic_avx512"}, CK_KNL, FEATURE_AVX512F, FeaturesKNL, 'Z', true },
383bdd1243dSDimitry Andric // Knights Mill processor.
384fe013be4SDimitry Andric { {"knm"}, CK_KNM, FEATURE_AVX5124FMAPS, FeaturesKNM, 'j', false },
385bdd1243dSDimitry Andric // Lakemont microarchitecture based processors.
386fe013be4SDimitry Andric { {"lakemont"}, CK_Lakemont, ~0U, FeatureCMPXCHG8B, '\0', false },
387bdd1243dSDimitry Andric // K6 architecture processors.
388fe013be4SDimitry Andric { {"k6"}, CK_K6, ~0U, FeaturesK6, '\0', false },
389fe013be4SDimitry Andric { {"k6-2"}, CK_K6_2, ~0U, FeaturesK6 | Feature3DNOW, '\0', false },
390fe013be4SDimitry Andric { {"k6-3"}, CK_K6_3, ~0U, FeaturesK6 | Feature3DNOW, '\0', false },
391bdd1243dSDimitry Andric // K7 architecture processors.
392fe013be4SDimitry Andric { {"athlon"}, CK_Athlon, ~0U, FeaturesAthlon, '\0', false },
393fe013be4SDimitry Andric { {"athlon-tbird"}, CK_Athlon, ~0U, FeaturesAthlon, '\0', false },
394fe013be4SDimitry Andric { {"athlon-xp"}, CK_AthlonXP, ~0U, FeaturesAthlonXP, '\0', false },
395fe013be4SDimitry Andric { {"athlon-mp"}, CK_AthlonXP, ~0U, FeaturesAthlonXP, '\0', false },
396fe013be4SDimitry Andric { {"athlon-4"}, CK_AthlonXP, ~0U, FeaturesAthlonXP, '\0', false },
397bdd1243dSDimitry Andric // K8 architecture processors.
398fe013be4SDimitry Andric { {"k8"}, CK_K8, ~0U, FeaturesK8, '\0', false },
399fe013be4SDimitry Andric { {"athlon64"}, CK_K8, ~0U, FeaturesK8, '\0', false },
400fe013be4SDimitry Andric { {"athlon-fx"}, CK_K8, ~0U, FeaturesK8, '\0', false },
401fe013be4SDimitry Andric { {"opteron"}, CK_K8, ~0U, FeaturesK8, '\0', false },
402fe013be4SDimitry Andric { {"k8-sse3"}, CK_K8SSE3, ~0U, FeaturesK8SSE3, '\0', false },
403fe013be4SDimitry Andric { {"athlon64-sse3"}, CK_K8SSE3, ~0U, FeaturesK8SSE3, '\0', false },
404fe013be4SDimitry Andric { {"opteron-sse3"}, CK_K8SSE3, ~0U, FeaturesK8SSE3, '\0', false },
405fe013be4SDimitry Andric { {"amdfam10"}, CK_AMDFAM10, FEATURE_SSE4_A, FeaturesAMDFAM10, '\0', false },
406fe013be4SDimitry Andric { {"barcelona"}, CK_AMDFAM10, FEATURE_SSE4_A, FeaturesAMDFAM10, '\0', false },
407bdd1243dSDimitry Andric // Bobcat architecture processors.
408fe013be4SDimitry Andric { {"btver1"}, CK_BTVER1, FEATURE_SSE4_A, FeaturesBTVER1, '\0', false },
409fe013be4SDimitry Andric { {"btver2"}, CK_BTVER2, FEATURE_BMI, FeaturesBTVER2, '\0', false },
410bdd1243dSDimitry Andric // Bulldozer architecture processors.
411fe013be4SDimitry Andric { {"bdver1"}, CK_BDVER1, FEATURE_XOP, FeaturesBDVER1, '\0', false },
412fe013be4SDimitry Andric { {"bdver2"}, CK_BDVER2, FEATURE_FMA, FeaturesBDVER2, '\0', false },
413fe013be4SDimitry Andric { {"bdver3"}, CK_BDVER3, FEATURE_FMA, FeaturesBDVER3, '\0', false },
414fe013be4SDimitry Andric { {"bdver4"}, CK_BDVER4, FEATURE_AVX2, FeaturesBDVER4, '\0', false },
415bdd1243dSDimitry Andric // Zen architecture processors.
416fe013be4SDimitry Andric { {"znver1"}, CK_ZNVER1, FEATURE_AVX2, FeaturesZNVER1, '\0', false },
417fe013be4SDimitry Andric { {"znver2"}, CK_ZNVER2, FEATURE_AVX2, FeaturesZNVER2, '\0', false },
418fe013be4SDimitry Andric { {"znver3"}, CK_ZNVER3, FEATURE_AVX2, FeaturesZNVER3, '\0', false },
419fe013be4SDimitry Andric { {"znver4"}, CK_ZNVER4, FEATURE_AVX512VBMI2, FeaturesZNVER4, '\0', false },
420bdd1243dSDimitry Andric // Generic 64-bit processor.
421c9157d92SDimitry Andric { {"x86-64"}, CK_x86_64, FEATURE_SSE2 , FeaturesX86_64, '\0', false },
422c9157d92SDimitry Andric { {"x86-64-v2"}, CK_x86_64_v2, FEATURE_SSE4_2 , FeaturesX86_64_V2, '\0', false },
423c9157d92SDimitry Andric { {"x86-64-v3"}, CK_x86_64_v3, FEATURE_AVX2, FeaturesX86_64_V3, '\0', false },
424c9157d92SDimitry Andric { {"x86-64-v4"}, CK_x86_64_v4, FEATURE_AVX512VL, FeaturesX86_64_V4, '\0', false },
425bdd1243dSDimitry Andric // Geode processors.
426fe013be4SDimitry Andric { {"geode"}, CK_Geode, ~0U, FeaturesGeode, '\0', false },
427bdd1243dSDimitry Andric };
428c9157d92SDimitry Andric // clang-format on
429bdd1243dSDimitry Andric
430bdd1243dSDimitry Andric constexpr const char *NoTuneList[] = {"x86-64-v2", "x86-64-v3", "x86-64-v4"};
431bdd1243dSDimitry Andric
parseArchX86(StringRef CPU,bool Only64Bit)432bdd1243dSDimitry Andric X86::CPUKind llvm::X86::parseArchX86(StringRef CPU, bool Only64Bit) {
433bdd1243dSDimitry Andric for (const auto &P : Processors)
434fe013be4SDimitry Andric if (!P.OnlyForCPUDispatchSpecific && P.Name == CPU &&
435fe013be4SDimitry Andric (P.Features[FEATURE_64BIT] || !Only64Bit))
436bdd1243dSDimitry Andric return P.Kind;
437bdd1243dSDimitry Andric
438bdd1243dSDimitry Andric return CK_None;
439bdd1243dSDimitry Andric }
440bdd1243dSDimitry Andric
parseTuneCPU(StringRef CPU,bool Only64Bit)441bdd1243dSDimitry Andric X86::CPUKind llvm::X86::parseTuneCPU(StringRef CPU, bool Only64Bit) {
442bdd1243dSDimitry Andric if (llvm::is_contained(NoTuneList, CPU))
443bdd1243dSDimitry Andric return CK_None;
444bdd1243dSDimitry Andric return parseArchX86(CPU, Only64Bit);
445bdd1243dSDimitry Andric }
446bdd1243dSDimitry Andric
fillValidCPUArchList(SmallVectorImpl<StringRef> & Values,bool Only64Bit)447bdd1243dSDimitry Andric void llvm::X86::fillValidCPUArchList(SmallVectorImpl<StringRef> &Values,
448bdd1243dSDimitry Andric bool Only64Bit) {
449bdd1243dSDimitry Andric for (const auto &P : Processors)
450fe013be4SDimitry Andric if (!P.OnlyForCPUDispatchSpecific && !P.Name.empty() &&
451fe013be4SDimitry Andric (P.Features[FEATURE_64BIT] || !Only64Bit))
452bdd1243dSDimitry Andric Values.emplace_back(P.Name);
453bdd1243dSDimitry Andric }
454bdd1243dSDimitry Andric
fillValidTuneCPUList(SmallVectorImpl<StringRef> & Values,bool Only64Bit)455bdd1243dSDimitry Andric void llvm::X86::fillValidTuneCPUList(SmallVectorImpl<StringRef> &Values,
456bdd1243dSDimitry Andric bool Only64Bit) {
457bdd1243dSDimitry Andric for (const ProcInfo &P : Processors)
458fe013be4SDimitry Andric if (!P.OnlyForCPUDispatchSpecific && !P.Name.empty() &&
459fe013be4SDimitry Andric (P.Features[FEATURE_64BIT] || !Only64Bit) &&
460bdd1243dSDimitry Andric !llvm::is_contained(NoTuneList, P.Name))
461bdd1243dSDimitry Andric Values.emplace_back(P.Name);
462bdd1243dSDimitry Andric }
463bdd1243dSDimitry Andric
getKeyFeature(X86::CPUKind Kind)464bdd1243dSDimitry Andric ProcessorFeatures llvm::X86::getKeyFeature(X86::CPUKind Kind) {
465bdd1243dSDimitry Andric // FIXME: Can we avoid a linear search here? The table might be sorted by
466bdd1243dSDimitry Andric // CPUKind so we could binary search?
467bdd1243dSDimitry Andric for (const auto &P : Processors) {
468bdd1243dSDimitry Andric if (P.Kind == Kind) {
469bdd1243dSDimitry Andric assert(P.KeyFeature != ~0U && "Processor does not have a key feature.");
470bdd1243dSDimitry Andric return static_cast<ProcessorFeatures>(P.KeyFeature);
471bdd1243dSDimitry Andric }
472bdd1243dSDimitry Andric }
473bdd1243dSDimitry Andric
474bdd1243dSDimitry Andric llvm_unreachable("Unable to find CPU kind!");
475bdd1243dSDimitry Andric }
476bdd1243dSDimitry Andric
477bdd1243dSDimitry Andric // Features with no dependencies.
478bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeatures64BIT = {};
479bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesADX = {};
480bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesBMI = {};
481bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesBMI2 = {};
482bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesCLDEMOTE = {};
483bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesCLFLUSHOPT = {};
484bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesCLWB = {};
485bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesCLZERO = {};
486bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesCMOV = {};
487bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesCMPXCHG16B = {};
488bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesCMPXCHG8B = {};
489bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesCRC32 = {};
490bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesENQCMD = {};
491bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesFSGSBASE = {};
492bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesFXSR = {};
493bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesINVPCID = {};
494bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesLWP = {};
495bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesLZCNT = {};
496bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesMWAITX = {};
497bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesMOVBE = {};
498bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesMOVDIR64B = {};
499bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesMOVDIRI = {};
500bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesPCONFIG = {};
501bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesPOPCNT = {};
502bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesPKU = {};
503bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesPREFETCHWT1 = {};
504bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesPRFCHW = {};
505bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesPTWRITE = {};
506bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesRDPID = {};
507bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesRDPRU = {};
508bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesRDRND = {};
509bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesRDSEED = {};
510bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesRTM = {};
511bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesSAHF = {};
512bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesSERIALIZE = {};
513bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesSGX = {};
514bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesSHSTK = {};
515bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesTBM = {};
516bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesTSXLDTRK = {};
517bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesUINTR = {};
518c9157d92SDimitry Andric constexpr FeatureBitset ImpliedFeaturesUSERMSR = {};
519bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesWAITPKG = {};
520bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesWBNOINVD = {};
521bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesVZEROUPPER = {};
522bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesX87 = {};
523bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesXSAVE = {};
524bdd1243dSDimitry Andric
525bdd1243dSDimitry Andric // Not really CPU features, but need to be in the table because clang uses
526bdd1243dSDimitry Andric // target features to communicate them to the backend.
527bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesRETPOLINE_EXTERNAL_THUNK = {};
528bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesRETPOLINE_INDIRECT_BRANCHES = {};
529bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesRETPOLINE_INDIRECT_CALLS = {};
530bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesLVI_CFI = {};
531bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesLVI_LOAD_HARDENING = {};
532bdd1243dSDimitry Andric
533bdd1243dSDimitry Andric // XSAVE features are dependent on basic XSAVE.
534bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesXSAVEC = FeatureXSAVE;
535bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesXSAVEOPT = FeatureXSAVE;
536bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesXSAVES = FeatureXSAVE;
537bdd1243dSDimitry Andric
538bdd1243dSDimitry Andric // MMX->3DNOW->3DNOWA chain.
539bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesMMX = {};
540bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeatures3DNOW = FeatureMMX;
541bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeatures3DNOWA = Feature3DNOW;
542bdd1243dSDimitry Andric
543bdd1243dSDimitry Andric // SSE/AVX/AVX512F chain.
544bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesSSE = {};
545bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesSSE2 = FeatureSSE;
546bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesSSE3 = FeatureSSE2;
547bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesSSSE3 = FeatureSSE3;
548bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesSSE4_1 = FeatureSSSE3;
549bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesSSE4_2 = FeatureSSE4_1;
550bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVX = FeatureSSE4_2;
551bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVX2 = FeatureAVX;
552c9157d92SDimitry Andric constexpr FeatureBitset ImpliedFeaturesEVEX512 = {};
553bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVX512F =
554bdd1243dSDimitry Andric FeatureAVX2 | FeatureF16C | FeatureFMA;
555bdd1243dSDimitry Andric
556bdd1243dSDimitry Andric // Vector extensions that build on SSE or AVX.
557bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAES = FeatureSSE2;
558bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesF16C = FeatureAVX;
559bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesFMA = FeatureAVX;
560bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesGFNI = FeatureSSE2;
561bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesPCLMUL = FeatureSSE2;
562bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesSHA = FeatureSSE2;
563c9157d92SDimitry Andric constexpr FeatureBitset ImpliedFeaturesVAES = FeatureAES | FeatureAVX2;
564bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesVPCLMULQDQ = FeatureAVX | FeaturePCLMUL;
565fe013be4SDimitry Andric constexpr FeatureBitset ImpliedFeaturesSM3 = FeatureAVX;
566c9157d92SDimitry Andric constexpr FeatureBitset ImpliedFeaturesSM4 = FeatureAVX2;
567bdd1243dSDimitry Andric
568bdd1243dSDimitry Andric // AVX512 features.
569bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVX512CD = FeatureAVX512F;
570bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVX512BW = FeatureAVX512F;
571bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVX512DQ = FeatureAVX512F;
572bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVX512ER = FeatureAVX512F;
573bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVX512PF = 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;
600fe013be4SDimitry 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 = {};
606fe013be4SDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVXVNNIINT16 = FeatureAVX2;
607bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVXVNNIINT8 = FeatureAVX2;
608bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVXIFMA = FeatureAVX2;
609bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVXNECONVERT = FeatureAVX2;
610c9157d92SDimitry 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
620c9157d92SDimitry Andric // AVX10 Features
621c9157d92SDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVX10_1 =
622c9157d92SDimitry Andric FeatureAVX512CD | FeatureAVX512VBMI | FeatureAVX512IFMA |
623c9157d92SDimitry Andric FeatureAVX512VNNI | FeatureAVX512BF16 | FeatureAVX512VPOPCNTDQ |
624c9157d92SDimitry Andric FeatureAVX512VBMI2 | FeatureAVX512BITALG | FeatureVAES | FeatureVPCLMULQDQ |
625c9157d92SDimitry Andric FeatureAVX512FP16;
626c9157d92SDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVX10_1_512 =
627c9157d92SDimitry Andric FeatureAVX10_1 | FeatureEVEX512;
628bdd1243dSDimitry Andric
629c9157d92SDimitry Andric // APX Features
630c9157d92SDimitry Andric constexpr FeatureBitset ImpliedFeaturesEGPR = {};
631c9157d92SDimitry Andric constexpr FeatureBitset ImpliedFeaturesPush2Pop2 = {};
632c9157d92SDimitry Andric constexpr FeatureBitset ImpliedFeaturesPPX = {};
633c9157d92SDimitry Andric constexpr FeatureBitset ImpliedFeaturesNDD = {};
634c9157d92SDimitry Andric constexpr FeatureBitset ImpliedFeaturesCCMP = {};
635c9157d92SDimitry Andric constexpr FeatureBitset ImpliedFeaturesCF = {};
636c9157d92SDimitry Andric
637c9157d92SDimitry Andric constexpr FeatureInfo FeatureInfos[X86::CPU_FEATURE_MAX] = {
638fe013be4SDimitry Andric #define X86_FEATURE(ENUM, STR) {{"+" STR}, ImpliedFeatures##ENUM},
639fe013be4SDimitry Andric #include "llvm/TargetParser/X86TargetParser.def"
640fe013be4SDimitry Andric };
641fe013be4SDimitry Andric
getFeaturesForCPU(StringRef CPU,SmallVectorImpl<StringRef> & EnabledFeatures,bool NeedPlus)642bdd1243dSDimitry Andric void llvm::X86::getFeaturesForCPU(StringRef CPU,
643fe013be4SDimitry Andric SmallVectorImpl<StringRef> &EnabledFeatures,
644c9157d92SDimitry Andric bool NeedPlus) {
645bdd1243dSDimitry Andric auto I = llvm::find_if(Processors,
646bdd1243dSDimitry Andric [&](const ProcInfo &P) { return P.Name == CPU; });
647bdd1243dSDimitry Andric assert(I != std::end(Processors) && "Processor not found!");
648bdd1243dSDimitry Andric
649bdd1243dSDimitry Andric FeatureBitset Bits = I->Features;
650bdd1243dSDimitry Andric
651bdd1243dSDimitry Andric // Remove the 64-bit feature which we only use to validate if a CPU can
652bdd1243dSDimitry Andric // be used with 64-bit mode.
653bdd1243dSDimitry Andric Bits &= ~Feature64BIT;
654bdd1243dSDimitry Andric
655bdd1243dSDimitry Andric // Add the string version of all set bits.
656bdd1243dSDimitry Andric for (unsigned i = 0; i != CPU_FEATURE_MAX; ++i)
657c9157d92SDimitry Andric if (Bits[i] && !FeatureInfos[i].getName(NeedPlus).empty())
658c9157d92SDimitry Andric EnabledFeatures.push_back(FeatureInfos[i].getName(NeedPlus));
659bdd1243dSDimitry Andric }
660bdd1243dSDimitry Andric
661bdd1243dSDimitry Andric // For each feature that is (transitively) implied by this feature, set it.
getImpliedEnabledFeatures(FeatureBitset & Bits,const FeatureBitset & Implies)662bdd1243dSDimitry Andric static void getImpliedEnabledFeatures(FeatureBitset &Bits,
663bdd1243dSDimitry Andric const FeatureBitset &Implies) {
664bdd1243dSDimitry Andric // Fast path: Implies is often empty.
665bdd1243dSDimitry Andric if (!Implies.any())
666bdd1243dSDimitry Andric return;
667bdd1243dSDimitry Andric FeatureBitset Prev;
668bdd1243dSDimitry Andric Bits |= Implies;
669bdd1243dSDimitry Andric do {
670bdd1243dSDimitry Andric Prev = Bits;
671bdd1243dSDimitry Andric for (unsigned i = CPU_FEATURE_MAX; i;)
672bdd1243dSDimitry Andric if (Bits[--i])
673bdd1243dSDimitry Andric Bits |= FeatureInfos[i].ImpliedFeatures;
674bdd1243dSDimitry Andric } while (Prev != Bits);
675bdd1243dSDimitry Andric }
676bdd1243dSDimitry Andric
677bdd1243dSDimitry Andric /// Create bit vector of features that are implied disabled if the feature
678bdd1243dSDimitry Andric /// passed in Value is disabled.
getImpliedDisabledFeatures(FeatureBitset & Bits,unsigned Value)679bdd1243dSDimitry Andric static void getImpliedDisabledFeatures(FeatureBitset &Bits, unsigned Value) {
680bdd1243dSDimitry Andric // Check all features looking for any dependent on this feature. If we find
681bdd1243dSDimitry Andric // one, mark it and recursively find any feature that depend on it.
682bdd1243dSDimitry Andric FeatureBitset Prev;
683bdd1243dSDimitry Andric Bits.set(Value);
684bdd1243dSDimitry Andric do {
685bdd1243dSDimitry Andric Prev = Bits;
686bdd1243dSDimitry Andric for (unsigned i = 0; i != CPU_FEATURE_MAX; ++i)
687bdd1243dSDimitry Andric if ((FeatureInfos[i].ImpliedFeatures & Bits).any())
688bdd1243dSDimitry Andric Bits.set(i);
689bdd1243dSDimitry Andric } while (Prev != Bits);
690bdd1243dSDimitry Andric }
691bdd1243dSDimitry Andric
updateImpliedFeatures(StringRef Feature,bool Enabled,StringMap<bool> & Features)692bdd1243dSDimitry Andric void llvm::X86::updateImpliedFeatures(
693bdd1243dSDimitry Andric StringRef Feature, bool Enabled,
694bdd1243dSDimitry Andric StringMap<bool> &Features) {
695c9157d92SDimitry Andric auto I = llvm::find_if(FeatureInfos, [&](const FeatureInfo &FI) {
696c9157d92SDimitry Andric return FI.getName() == Feature;
697c9157d92SDimitry Andric });
698bdd1243dSDimitry Andric if (I == std::end(FeatureInfos)) {
699bdd1243dSDimitry Andric // FIXME: This shouldn't happen, but may not have all features in the table
700bdd1243dSDimitry Andric // yet.
701bdd1243dSDimitry Andric return;
702bdd1243dSDimitry Andric }
703bdd1243dSDimitry Andric
704bdd1243dSDimitry Andric FeatureBitset ImpliedBits;
705bdd1243dSDimitry Andric if (Enabled)
706bdd1243dSDimitry Andric getImpliedEnabledFeatures(ImpliedBits, I->ImpliedFeatures);
707bdd1243dSDimitry Andric else
708bdd1243dSDimitry Andric getImpliedDisabledFeatures(ImpliedBits,
709bdd1243dSDimitry Andric std::distance(std::begin(FeatureInfos), I));
710bdd1243dSDimitry Andric
711bdd1243dSDimitry Andric // Update the map entry for all implied features.
712bdd1243dSDimitry Andric for (unsigned i = 0; i != CPU_FEATURE_MAX; ++i)
713c9157d92SDimitry Andric if (ImpliedBits[i] && !FeatureInfos[i].getName().empty())
714c9157d92SDimitry Andric Features[FeatureInfos[i].getName()] = Enabled;
715bdd1243dSDimitry Andric }
716bdd1243dSDimitry Andric
getCPUDispatchMangling(StringRef CPU)717fe013be4SDimitry Andric char llvm::X86::getCPUDispatchMangling(StringRef CPU) {
718fe013be4SDimitry Andric auto I = llvm::find_if(Processors,
719fe013be4SDimitry Andric [&](const ProcInfo &P) { return P.Name == CPU; });
720fe013be4SDimitry Andric assert(I != std::end(Processors) && "Processor not found!");
721fe013be4SDimitry Andric assert(I->Mangling != '\0' && "Processor dooesn't support function multiversion!");
722fe013be4SDimitry Andric return I->Mangling;
723fe013be4SDimitry Andric }
724fe013be4SDimitry Andric
validateCPUSpecificCPUDispatch(StringRef Name)725fe013be4SDimitry Andric bool llvm::X86::validateCPUSpecificCPUDispatch(StringRef Name) {
726fe013be4SDimitry Andric auto I = llvm::find_if(Processors,
727fe013be4SDimitry Andric [&](const ProcInfo &P) { return P.Name == Name; });
728fe013be4SDimitry Andric return I != std::end(Processors);
729fe013be4SDimitry Andric }
730fe013be4SDimitry Andric
731c9157d92SDimitry Andric std::array<uint32_t, 4>
getCpuSupportsMask(ArrayRef<StringRef> FeatureStrs)732c9157d92SDimitry Andric llvm::X86::getCpuSupportsMask(ArrayRef<StringRef> FeatureStrs) {
733bdd1243dSDimitry Andric // Processor features and mapping to processor feature value.
734c9157d92SDimitry Andric std::array<uint32_t, 4> FeatureMask{};
735c9157d92SDimitry Andric for (StringRef FeatureStr : FeatureStrs) {
736bdd1243dSDimitry Andric unsigned Feature = StringSwitch<unsigned>(FeatureStr)
737bdd1243dSDimitry Andric #define X86_FEATURE_COMPAT(ENUM, STR, PRIORITY) \
738bdd1243dSDimitry Andric .Case(STR, llvm::X86::FEATURE_##ENUM)
739c9157d92SDimitry Andric #define X86_MICROARCH_LEVEL(ENUM, STR, PRIORITY) \
740c9157d92SDimitry Andric .Case(STR, llvm::X86::FEATURE_##ENUM)
741bdd1243dSDimitry Andric #include "llvm/TargetParser/X86TargetParser.def"
742bdd1243dSDimitry Andric ;
743c9157d92SDimitry Andric assert(Feature / 32 < FeatureMask.size());
744c9157d92SDimitry Andric FeatureMask[Feature / 32] |= 1U << (Feature % 32);
745bdd1243dSDimitry Andric }
746c9157d92SDimitry Andric return FeatureMask;
747bdd1243dSDimitry Andric }
748bdd1243dSDimitry Andric
getFeaturePriority(ProcessorFeatures Feat)749bdd1243dSDimitry Andric unsigned llvm::X86::getFeaturePriority(ProcessorFeatures Feat) {
750bdd1243dSDimitry Andric #ifndef NDEBUG
751bdd1243dSDimitry Andric // Check that priorities are set properly in the .def file. We expect that
752bdd1243dSDimitry Andric // "compat" features are assigned non-duplicate consecutive priorities
753bdd1243dSDimitry Andric // starting from zero (0, 1, ..., num_features - 1).
754bdd1243dSDimitry Andric #define X86_FEATURE_COMPAT(ENUM, STR, PRIORITY) PRIORITY,
755bdd1243dSDimitry Andric unsigned Priorities[] = {
756bdd1243dSDimitry Andric #include "llvm/TargetParser/X86TargetParser.def"
757bdd1243dSDimitry Andric };
758c9157d92SDimitry Andric std::array<unsigned, std::size(Priorities)> HelperList;
759bdd1243dSDimitry Andric std::iota(HelperList.begin(), HelperList.end(), 0);
760bdd1243dSDimitry Andric assert(std::is_permutation(HelperList.begin(), HelperList.end(),
761c9157d92SDimitry Andric std::begin(Priorities), std::end(Priorities)) &&
762bdd1243dSDimitry Andric "Priorities don't form consecutive range!");
763bdd1243dSDimitry Andric #endif
764bdd1243dSDimitry Andric
765bdd1243dSDimitry Andric switch (Feat) {
766bdd1243dSDimitry Andric #define X86_FEATURE_COMPAT(ENUM, STR, PRIORITY) \
767bdd1243dSDimitry Andric case X86::FEATURE_##ENUM: \
768bdd1243dSDimitry Andric return PRIORITY;
769bdd1243dSDimitry Andric #include "llvm/TargetParser/X86TargetParser.def"
770bdd1243dSDimitry Andric default:
771bdd1243dSDimitry Andric llvm_unreachable("No Feature Priority for non-CPUSupports Features");
772bdd1243dSDimitry Andric }
773bdd1243dSDimitry Andric }
774