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" 14*5f757f3fSDimitry 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 23*5f757f3fSDimitry 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 { 35*5f757f3fSDimitry Andric StringLiteral NameWithPlus; 36bdd1243dSDimitry Andric FeatureBitset ImpliedFeatures; 37*5f757f3fSDimitry Andric 38*5f757f3fSDimitry Andric StringRef getName(bool WithPlus = false) const { 39*5f757f3fSDimitry Andric assert(NameWithPlus[0] == '+' && "Expected string to start with '+'"); 40*5f757f3fSDimitry Andric if (WithPlus) 41*5f757f3fSDimitry Andric return NameWithPlus; 42*5f757f3fSDimitry Andric return NameWithPlus.drop_front(); 43*5f757f3fSDimitry 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; 75*5f757f3fSDimitry 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 = 99*5f757f3fSDimitry Andric FeaturesBroadwell | FeatureAES | FeatureAVX512F | FeatureEVEX512 | 100*5f757f3fSDimitry 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 = 110*5f757f3fSDimitry Andric (FeaturesSkylakeClient & ~FeatureSGX) | FeatureAVX512F | FeatureEVEX512 | 111*5f757f3fSDimitry Andric FeatureAVX512CD | FeatureAVX512DQ | FeatureAVX512BW | FeatureAVX512VL | 112*5f757f3fSDimitry 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 = 120*5f757f3fSDimitry Andric FeaturesSkylakeClient | FeatureAVX512F | FeatureEVEX512 | FeatureAVX512CD | 121*5f757f3fSDimitry Andric FeatureAVX512DQ | FeatureAVX512BW | FeatureAVX512VL | FeatureAVX512IFMA | 122*5f757f3fSDimitry 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; 165bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesGrandridge = 166bdd1243dSDimitry Andric FeaturesSierraforest | FeatureRAOINT; 167*5f757f3fSDimitry Andric constexpr FeatureBitset FeaturesArrowlakeS = FeaturesSierraforest | 168*5f757f3fSDimitry Andric FeatureAVXVNNIINT16 | FeatureSHA512 | FeatureSM3 | FeatureSM4; 169*5f757f3fSDimitry Andric constexpr FeatureBitset FeaturesPantherlake = 170*5f757f3fSDimitry Andric FeaturesArrowlakeS | FeaturePREFETCHI; 171*5f757f3fSDimitry Andric constexpr FeatureBitset FeaturesClearwaterforest = 172*5f757f3fSDimitry Andric FeaturesArrowlakeS | FeatureUSERMSR | FeaturePREFETCHI; 173bdd1243dSDimitry Andric 174bdd1243dSDimitry Andric // Geode Processor. 175bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesGeode = 176bdd1243dSDimitry Andric FeatureX87 | FeatureCMPXCHG8B | FeatureMMX | Feature3DNOW | Feature3DNOWA; 177bdd1243dSDimitry Andric 178bdd1243dSDimitry Andric // K6 processor. 179bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesK6 = FeatureX87 | FeatureCMPXCHG8B | FeatureMMX; 180bdd1243dSDimitry Andric 181bdd1243dSDimitry Andric // K7 and K8 architecture processors. 182bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesAthlon = 183bdd1243dSDimitry Andric FeatureX87 | FeatureCMPXCHG8B | FeatureMMX | Feature3DNOW | Feature3DNOWA; 184bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesAthlonXP = 185bdd1243dSDimitry Andric FeaturesAthlon | FeatureFXSR | FeatureSSE; 186bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesK8 = 187bdd1243dSDimitry Andric FeaturesAthlonXP | FeatureSSE2 | Feature64BIT; 188bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesK8SSE3 = FeaturesK8 | FeatureSSE3; 189bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesAMDFAM10 = 190bdd1243dSDimitry Andric FeaturesK8SSE3 | FeatureCMPXCHG16B | FeatureLZCNT | FeaturePOPCNT | 191bdd1243dSDimitry Andric FeaturePRFCHW | FeatureSAHF | FeatureSSE4_A; 192bdd1243dSDimitry Andric 193bdd1243dSDimitry Andric // Bobcat architecture processors. 194bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesBTVER1 = 195bdd1243dSDimitry Andric FeatureX87 | FeatureCMPXCHG8B | FeatureCMPXCHG16B | Feature64BIT | 196bdd1243dSDimitry Andric FeatureFXSR | FeatureLZCNT | FeatureMMX | FeaturePOPCNT | FeaturePRFCHW | 197bdd1243dSDimitry Andric FeatureSSE | FeatureSSE2 | FeatureSSE3 | FeatureSSSE3 | FeatureSSE4_A | 198bdd1243dSDimitry Andric FeatureSAHF; 199bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesBTVER2 = 200bdd1243dSDimitry Andric FeaturesBTVER1 | FeatureAES | FeatureAVX | FeatureBMI | FeatureCRC32 | 201bdd1243dSDimitry Andric FeatureF16C | FeatureMOVBE | FeaturePCLMUL | FeatureXSAVE | FeatureXSAVEOPT; 202bdd1243dSDimitry Andric 203bdd1243dSDimitry Andric // AMD Bulldozer architecture processors. 204bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesBDVER1 = 205bdd1243dSDimitry Andric FeatureX87 | FeatureAES | FeatureAVX | FeatureCMPXCHG8B | 206bdd1243dSDimitry Andric FeatureCMPXCHG16B | FeatureCRC32 | Feature64BIT | FeatureFMA4 | 207bdd1243dSDimitry Andric FeatureFXSR | FeatureLWP | FeatureLZCNT | FeatureMMX | FeaturePCLMUL | 208bdd1243dSDimitry Andric FeaturePOPCNT | FeaturePRFCHW | FeatureSAHF | FeatureSSE | FeatureSSE2 | 209bdd1243dSDimitry Andric FeatureSSE3 | FeatureSSSE3 | FeatureSSE4_1 | FeatureSSE4_2 | FeatureSSE4_A | 210bdd1243dSDimitry Andric FeatureXOP | FeatureXSAVE; 211bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesBDVER2 = 212bdd1243dSDimitry Andric FeaturesBDVER1 | FeatureBMI | FeatureFMA | FeatureF16C | FeatureTBM; 213bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesBDVER3 = 214bdd1243dSDimitry Andric FeaturesBDVER2 | FeatureFSGSBASE | FeatureXSAVEOPT; 215bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesBDVER4 = FeaturesBDVER3 | FeatureAVX2 | 216bdd1243dSDimitry Andric FeatureBMI2 | FeatureMOVBE | 217bdd1243dSDimitry Andric FeatureMWAITX | FeatureRDRND; 218bdd1243dSDimitry Andric 219bdd1243dSDimitry Andric // AMD Zen architecture processors. 220bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesZNVER1 = 221bdd1243dSDimitry Andric FeatureX87 | FeatureADX | FeatureAES | FeatureAVX | FeatureAVX2 | 222bdd1243dSDimitry Andric FeatureBMI | FeatureBMI2 | FeatureCLFLUSHOPT | FeatureCLZERO | 223bdd1243dSDimitry Andric FeatureCMPXCHG8B | FeatureCMPXCHG16B | FeatureCRC32 | Feature64BIT | 224bdd1243dSDimitry Andric FeatureF16C | FeatureFMA | FeatureFSGSBASE | FeatureFXSR | FeatureLZCNT | 225bdd1243dSDimitry Andric FeatureMMX | FeatureMOVBE | FeatureMWAITX | FeaturePCLMUL | FeaturePOPCNT | 226bdd1243dSDimitry Andric FeaturePRFCHW | FeatureRDRND | FeatureRDSEED | FeatureSAHF | FeatureSHA | 227bdd1243dSDimitry Andric FeatureSSE | FeatureSSE2 | FeatureSSE3 | FeatureSSSE3 | FeatureSSE4_1 | 228bdd1243dSDimitry Andric FeatureSSE4_2 | FeatureSSE4_A | FeatureXSAVE | FeatureXSAVEC | 229bdd1243dSDimitry Andric FeatureXSAVEOPT | FeatureXSAVES; 230bdd1243dSDimitry Andric constexpr FeatureBitset FeaturesZNVER2 = FeaturesZNVER1 | FeatureCLWB | 231bdd1243dSDimitry Andric FeatureRDPID | FeatureRDPRU | 232bdd1243dSDimitry Andric FeatureWBNOINVD; 233bdd1243dSDimitry Andric static constexpr FeatureBitset FeaturesZNVER3 = FeaturesZNVER2 | 234bdd1243dSDimitry Andric FeatureINVPCID | FeaturePKU | 235bdd1243dSDimitry Andric FeatureVAES | FeatureVPCLMULQDQ; 236bdd1243dSDimitry Andric static constexpr FeatureBitset FeaturesZNVER4 = 237*5f757f3fSDimitry Andric FeaturesZNVER3 | FeatureAVX512F | FeatureEVEX512 | FeatureAVX512CD | 238*5f757f3fSDimitry Andric FeatureAVX512DQ | FeatureAVX512BW | FeatureAVX512VL | FeatureAVX512IFMA | 239*5f757f3fSDimitry Andric FeatureAVX512VBMI | FeatureAVX512VBMI2 | FeatureAVX512VNNI | 240*5f757f3fSDimitry Andric FeatureAVX512BITALG | FeatureAVX512VPOPCNTDQ | FeatureAVX512BF16 | 241*5f757f3fSDimitry Andric FeatureGFNI | FeatureSHSTK; 242bdd1243dSDimitry Andric 24306c3fb27SDimitry Andric // D151696 tranplanted Mangling and OnlyForCPUDispatchSpecific from 24406c3fb27SDimitry Andric // X86TargetParser.def to here. They are assigned by following ways: 24506c3fb27SDimitry Andric // 1. Copy the mangling from the original CPU_SPEICIFC MACROs. If no, assign 24606c3fb27SDimitry Andric // to '\0' by default, which means not support cpu_specific/dispatch feature. 24706c3fb27SDimitry Andric // 2. set OnlyForCPUDispatchSpecific as true if this cpu name was not 24806c3fb27SDimitry Andric // listed here before, which means it doesn't support -march, -mtune and so on. 24906c3fb27SDimitry Andric // FIXME: Remove OnlyForCPUDispatchSpecific after all CPUs here support both 25006c3fb27SDimitry Andric // cpu_dispatch/specific() feature and -march, -mtune, and so on. 251*5f757f3fSDimitry Andric // clang-format off 252bdd1243dSDimitry Andric constexpr ProcInfo Processors[] = { 253bdd1243dSDimitry Andric // Empty processor. Include X87 and CMPXCHG8 for backwards compatibility. 25406c3fb27SDimitry Andric { {""}, CK_None, ~0U, FeatureX87 | FeatureCMPXCHG8B, '\0', false }, 25506c3fb27SDimitry Andric { {"generic"}, CK_None, ~0U, FeatureX87 | FeatureCMPXCHG8B | Feature64BIT, 'A', true }, 256bdd1243dSDimitry Andric // i386-generation processors. 25706c3fb27SDimitry Andric { {"i386"}, CK_i386, ~0U, FeatureX87, '\0', false }, 258bdd1243dSDimitry Andric // i486-generation processors. 25906c3fb27SDimitry Andric { {"i486"}, CK_i486, ~0U, FeatureX87, '\0', false }, 26006c3fb27SDimitry Andric { {"winchip-c6"}, CK_WinChipC6, ~0U, FeaturesPentiumMMX, '\0', false }, 26106c3fb27SDimitry Andric { {"winchip2"}, CK_WinChip2, ~0U, FeaturesPentiumMMX | Feature3DNOW, '\0', false }, 26206c3fb27SDimitry Andric { {"c3"}, CK_C3, ~0U, FeaturesPentiumMMX | Feature3DNOW, '\0', false }, 263bdd1243dSDimitry Andric // i586-generation processors, P5 microarchitecture based. 26406c3fb27SDimitry Andric { {"i586"}, CK_i586, ~0U, FeatureX87 | FeatureCMPXCHG8B, '\0', false }, 26506c3fb27SDimitry Andric { {"pentium"}, CK_Pentium, ~0U, FeatureX87 | FeatureCMPXCHG8B, 'B', false }, 26606c3fb27SDimitry Andric { {"pentium-mmx"}, CK_PentiumMMX, ~0U, FeaturesPentiumMMX, '\0', false }, 26706c3fb27SDimitry Andric { {"pentium_mmx"}, CK_PentiumMMX, ~0U, FeaturesPentiumMMX, 'D', true }, 268bdd1243dSDimitry Andric // i686-generation processors, P6 / Pentium M microarchitecture based. 26906c3fb27SDimitry Andric { {"pentiumpro"}, CK_PentiumPro, ~0U, FeatureCMOV | FeatureX87 | FeatureCMPXCHG8B, 'C', false }, 27006c3fb27SDimitry Andric { {"pentium_pro"}, CK_PentiumPro, ~0U, FeatureCMOV | FeatureX87 | FeatureCMPXCHG8B, 'C', true }, 27106c3fb27SDimitry Andric { {"i686"}, CK_i686, ~0U, FeatureCMOV | FeatureX87 | FeatureCMPXCHG8B, '\0', false }, 27206c3fb27SDimitry Andric { {"pentium2"}, CK_Pentium2, ~0U, FeaturesPentium2, 'E', false }, 27306c3fb27SDimitry Andric { {"pentium_ii"}, CK_Pentium2, ~0U, FeaturesPentium2, 'E', true }, 27406c3fb27SDimitry Andric { {"pentium3"}, CK_Pentium3, ~0U, FeaturesPentium3, 'H', false }, 27506c3fb27SDimitry Andric { {"pentium3m"}, CK_Pentium3, ~0U, FeaturesPentium3, 'H', false }, 27606c3fb27SDimitry Andric { {"pentium_iii"}, CK_Pentium3, ~0U, FeaturesPentium3, 'H', true }, 27706c3fb27SDimitry Andric { {"pentium_iii_no_xmm_regs"}, CK_Pentium3, ~0U, FeaturesPentium3, 'H', true }, 27806c3fb27SDimitry Andric { {"pentium-m"}, CK_PentiumM, ~0U, FeaturesPentium4, '\0', false }, 27906c3fb27SDimitry Andric { {"pentium_m"}, CK_PentiumM, ~0U, FeaturesPentium4, 'K', true }, 28006c3fb27SDimitry Andric { {"c3-2"}, CK_C3_2, ~0U, FeaturesPentium3, '\0', false }, 28106c3fb27SDimitry Andric { {"yonah"}, CK_Yonah, ~0U, FeaturesPrescott, 'L', false }, 282bdd1243dSDimitry Andric // Netburst microarchitecture based processors. 28306c3fb27SDimitry Andric { {"pentium4"}, CK_Pentium4, ~0U, FeaturesPentium4, 'J', false }, 28406c3fb27SDimitry Andric { {"pentium4m"}, CK_Pentium4, ~0U, FeaturesPentium4, 'J', false }, 28506c3fb27SDimitry Andric { {"pentium_4"}, CK_Pentium4, ~0U, FeaturesPentium4, 'J', true }, 28606c3fb27SDimitry Andric { {"pentium_4_sse3"}, CK_Prescott, ~0U, FeaturesPrescott, 'L', true }, 28706c3fb27SDimitry Andric { {"prescott"}, CK_Prescott, ~0U, FeaturesPrescott, 'L', false }, 28806c3fb27SDimitry Andric { {"nocona"}, CK_Nocona, ~0U, FeaturesNocona, 'L', false }, 289bdd1243dSDimitry Andric // Core microarchitecture based processors. 29006c3fb27SDimitry Andric { {"core2"}, CK_Core2, FEATURE_SSSE3, FeaturesCore2, 'M', false }, 29106c3fb27SDimitry Andric { {"core_2_duo_ssse3"}, CK_Core2, ~0U, FeaturesCore2, 'M', true }, 29206c3fb27SDimitry Andric { {"penryn"}, CK_Penryn, ~0U, FeaturesPenryn, 'N', false }, 29306c3fb27SDimitry Andric { {"core_2_duo_sse4_1"}, CK_Penryn, ~0U, FeaturesPenryn, 'N', true }, 294bdd1243dSDimitry Andric // Atom processors 29506c3fb27SDimitry Andric { {"bonnell"}, CK_Bonnell, FEATURE_SSSE3, FeaturesBonnell, 'O', false }, 29606c3fb27SDimitry Andric { {"atom"}, CK_Bonnell, FEATURE_SSSE3, FeaturesBonnell, 'O', false }, 29706c3fb27SDimitry Andric { {"silvermont"}, CK_Silvermont, FEATURE_SSE4_2, FeaturesSilvermont, 'c', false }, 29806c3fb27SDimitry Andric { {"slm"}, CK_Silvermont, FEATURE_SSE4_2, FeaturesSilvermont, 'c', false }, 29906c3fb27SDimitry Andric { {"atom_sse4_2"}, CK_Nehalem, FEATURE_SSE4_2, FeaturesNehalem, 'c', true }, 30006c3fb27SDimitry Andric { {"atom_sse4_2_movbe"}, CK_Goldmont, FEATURE_SSE4_2, FeaturesGoldmont, 'd', true }, 30106c3fb27SDimitry Andric { {"goldmont"}, CK_Goldmont, FEATURE_SSE4_2, FeaturesGoldmont, 'i', false }, 30206c3fb27SDimitry Andric { {"goldmont-plus"}, CK_GoldmontPlus, FEATURE_SSE4_2, FeaturesGoldmontPlus, '\0', false }, 30306c3fb27SDimitry Andric { {"goldmont_plus"}, CK_GoldmontPlus, FEATURE_SSE4_2, FeaturesGoldmontPlus, 'd', true }, 30406c3fb27SDimitry Andric { {"tremont"}, CK_Tremont, FEATURE_SSE4_2, FeaturesTremont, 'd', false }, 305bdd1243dSDimitry Andric // Nehalem microarchitecture based processors. 30606c3fb27SDimitry Andric { {"nehalem"}, CK_Nehalem, FEATURE_SSE4_2, FeaturesNehalem, 'P', false }, 30706c3fb27SDimitry Andric { {"core_i7_sse4_2"}, CK_Nehalem, FEATURE_SSE4_2, FeaturesNehalem, 'P', true }, 30806c3fb27SDimitry Andric { {"corei7"}, CK_Nehalem, FEATURE_SSE4_2, FeaturesNehalem, 'P', false }, 309bdd1243dSDimitry Andric // Westmere microarchitecture based processors. 31006c3fb27SDimitry Andric { {"westmere"}, CK_Westmere, FEATURE_PCLMUL, FeaturesWestmere, 'Q', false }, 31106c3fb27SDimitry Andric { {"core_aes_pclmulqdq"}, CK_Nehalem, FEATURE_SSE4_2, FeaturesNehalem, 'Q', true }, 312bdd1243dSDimitry Andric // Sandy Bridge microarchitecture based processors. 31306c3fb27SDimitry Andric { {"sandybridge"}, CK_SandyBridge, FEATURE_AVX, FeaturesSandyBridge, 'R', false }, 31406c3fb27SDimitry Andric { {"core_2nd_gen_avx"}, CK_SandyBridge, FEATURE_AVX, FeaturesSandyBridge, 'R', true }, 31506c3fb27SDimitry Andric { {"corei7-avx"}, CK_SandyBridge, FEATURE_AVX, FeaturesSandyBridge, '\0', false }, 316bdd1243dSDimitry Andric // Ivy Bridge microarchitecture based processors. 31706c3fb27SDimitry Andric { {"ivybridge"}, CK_IvyBridge, FEATURE_AVX, FeaturesIvyBridge, 'S', false }, 31806c3fb27SDimitry Andric { {"core_3rd_gen_avx"}, CK_IvyBridge, FEATURE_AVX, FeaturesIvyBridge, 'S', true }, 31906c3fb27SDimitry Andric { {"core-avx-i"}, CK_IvyBridge, FEATURE_AVX, FeaturesIvyBridge, '\0', false }, 320bdd1243dSDimitry Andric // Haswell microarchitecture based processors. 32106c3fb27SDimitry Andric { {"haswell"}, CK_Haswell, FEATURE_AVX2, FeaturesHaswell, 'V', false }, 32206c3fb27SDimitry Andric { {"core-avx2"}, CK_Haswell, FEATURE_AVX2, FeaturesHaswell, '\0', false }, 32306c3fb27SDimitry Andric { {"core_4th_gen_avx"}, CK_Haswell, FEATURE_AVX2, FeaturesHaswell, 'V', true }, 32406c3fb27SDimitry Andric { {"core_4th_gen_avx_tsx"}, CK_Haswell, FEATURE_AVX2, FeaturesHaswell, 'W', true }, 325bdd1243dSDimitry Andric // Broadwell microarchitecture based processors. 32606c3fb27SDimitry Andric { {"broadwell"}, CK_Broadwell, FEATURE_AVX2, FeaturesBroadwell, 'X', false }, 32706c3fb27SDimitry Andric { {"core_5th_gen_avx"}, CK_Broadwell, FEATURE_AVX2, FeaturesBroadwell, 'X', true }, 32806c3fb27SDimitry Andric { {"core_5th_gen_avx_tsx"}, CK_Broadwell, FEATURE_AVX2, FeaturesBroadwell, 'Y', true }, 329bdd1243dSDimitry Andric // Skylake client microarchitecture based processors. 33006c3fb27SDimitry Andric { {"skylake"}, CK_SkylakeClient, FEATURE_AVX2, FeaturesSkylakeClient, 'b', false }, 331bdd1243dSDimitry Andric // Skylake server microarchitecture based processors. 33206c3fb27SDimitry Andric { {"skylake-avx512"}, CK_SkylakeServer, FEATURE_AVX512F, FeaturesSkylakeServer, '\0', false }, 33306c3fb27SDimitry Andric { {"skx"}, CK_SkylakeServer, FEATURE_AVX512F, FeaturesSkylakeServer, 'a', false }, 33406c3fb27SDimitry Andric { {"skylake_avx512"}, CK_SkylakeServer, FEATURE_AVX512F, FeaturesSkylakeServer, 'a', true }, 335bdd1243dSDimitry Andric // Cascadelake Server microarchitecture based processors. 33606c3fb27SDimitry Andric { {"cascadelake"}, CK_Cascadelake, FEATURE_AVX512VNNI, FeaturesCascadeLake, 'o', false }, 337bdd1243dSDimitry Andric // Cooperlake Server microarchitecture based processors. 33806c3fb27SDimitry Andric { {"cooperlake"}, CK_Cooperlake, FEATURE_AVX512BF16, FeaturesCooperLake, 'f', false }, 339bdd1243dSDimitry Andric // Cannonlake client microarchitecture based processors. 34006c3fb27SDimitry Andric { {"cannonlake"}, CK_Cannonlake, FEATURE_AVX512VBMI, FeaturesCannonlake, 'e', false }, 341bdd1243dSDimitry Andric // Icelake client microarchitecture based processors. 34206c3fb27SDimitry Andric { {"icelake-client"}, CK_IcelakeClient, FEATURE_AVX512VBMI2, FeaturesICLClient, '\0', false }, 34306c3fb27SDimitry Andric { {"icelake_client"}, CK_IcelakeClient, FEATURE_AVX512VBMI2, FeaturesICLClient, 'k', true }, 344bdd1243dSDimitry Andric // Rocketlake microarchitecture based processors. 34506c3fb27SDimitry Andric { {"rocketlake"}, CK_Rocketlake, FEATURE_AVX512VBMI2, FeaturesRocketlake, 'k', false }, 346bdd1243dSDimitry Andric // Icelake server microarchitecture based processors. 34706c3fb27SDimitry Andric { {"icelake-server"}, CK_IcelakeServer, FEATURE_AVX512VBMI2, FeaturesICLServer, '\0', false }, 34806c3fb27SDimitry Andric { {"icelake_server"}, CK_IcelakeServer, FEATURE_AVX512VBMI2, FeaturesICLServer, 'k', true }, 349bdd1243dSDimitry Andric // Tigerlake microarchitecture based processors. 35006c3fb27SDimitry Andric { {"tigerlake"}, CK_Tigerlake, FEATURE_AVX512VP2INTERSECT, FeaturesTigerlake, 'l', false }, 351bdd1243dSDimitry Andric // Sapphire Rapids microarchitecture based processors. 35206c3fb27SDimitry Andric { {"sapphirerapids"}, CK_SapphireRapids, FEATURE_AVX512BF16, FeaturesSapphireRapids, 'n', false }, 353bdd1243dSDimitry Andric // Alderlake microarchitecture based processors. 35406c3fb27SDimitry Andric { {"alderlake"}, CK_Alderlake, FEATURE_AVX2, FeaturesAlderlake, 'p', false }, 355bdd1243dSDimitry Andric // Raptorlake microarchitecture based processors. 35606c3fb27SDimitry Andric { {"raptorlake"}, CK_Raptorlake, FEATURE_AVX2, FeaturesAlderlake, 'p', false }, 357bdd1243dSDimitry Andric // Meteorlake microarchitecture based processors. 35806c3fb27SDimitry Andric { {"meteorlake"}, CK_Meteorlake, FEATURE_AVX2, FeaturesAlderlake, 'p', false }, 359*5f757f3fSDimitry Andric // Arrowlake microarchitecture based processors. 360*5f757f3fSDimitry Andric { {"arrowlake"}, CK_Arrowlake, FEATURE_AVX2, FeaturesSierraforest, 'p', false }, 361*5f757f3fSDimitry Andric { {"arrowlake-s"}, CK_ArrowlakeS, FEATURE_AVX2, FeaturesArrowlakeS, '\0', false }, 362*5f757f3fSDimitry Andric { {"arrowlake_s"}, CK_ArrowlakeS, FEATURE_AVX2, FeaturesArrowlakeS, 'p', true }, 363*5f757f3fSDimitry Andric // Lunarlake microarchitecture based processors. 364*5f757f3fSDimitry Andric { {"lunarlake"}, CK_Lunarlake, FEATURE_AVX2, FeaturesArrowlakeS, 'p', false }, 365*5f757f3fSDimitry Andric // Gracemont microarchitecture based processors. 366*5f757f3fSDimitry Andric { {"gracemont"}, CK_Gracemont, FEATURE_AVX2, FeaturesAlderlake, 'p', false }, 367*5f757f3fSDimitry Andric // Pantherlake microarchitecture based processors. 368*5f757f3fSDimitry Andric { {"pantherlake"}, CK_Lunarlake, FEATURE_AVX2, FeaturesPantherlake, 'p', false }, 369bdd1243dSDimitry Andric // Sierraforest microarchitecture based processors. 37006c3fb27SDimitry Andric { {"sierraforest"}, CK_Sierraforest, FEATURE_AVX2, FeaturesSierraforest, 'p', false }, 371bdd1243dSDimitry Andric // Grandridge microarchitecture based processors. 37206c3fb27SDimitry Andric { {"grandridge"}, CK_Grandridge, FEATURE_AVX2, FeaturesGrandridge, 'p', false }, 373bdd1243dSDimitry Andric // Granite Rapids microarchitecture based processors. 37406c3fb27SDimitry Andric { {"graniterapids"}, CK_Graniterapids, FEATURE_AVX512BF16, FeaturesGraniteRapids, 'n', false }, 37506c3fb27SDimitry Andric // Granite Rapids D microarchitecture based processors. 37606c3fb27SDimitry Andric { {"graniterapids-d"}, CK_GraniterapidsD, FEATURE_AVX512BF16, FeaturesGraniteRapids | FeatureAMX_COMPLEX, '\0', false }, 37706c3fb27SDimitry Andric { {"graniterapids_d"}, CK_GraniterapidsD, FEATURE_AVX512BF16, FeaturesGraniteRapids | FeatureAMX_COMPLEX, 'n', true }, 378bdd1243dSDimitry Andric // Emerald Rapids microarchitecture based processors. 37906c3fb27SDimitry Andric { {"emeraldrapids"}, CK_Emeraldrapids, FEATURE_AVX512BF16, FeaturesSapphireRapids, 'n', false }, 380*5f757f3fSDimitry Andric // Clearwaterforest microarchitecture based processors. 381*5f757f3fSDimitry Andric { {"clearwaterforest"}, CK_Lunarlake, FEATURE_AVX2, FeaturesClearwaterforest, 'p', false }, 382bdd1243dSDimitry Andric // Knights Landing processor. 38306c3fb27SDimitry Andric { {"knl"}, CK_KNL, FEATURE_AVX512F, FeaturesKNL, 'Z', false }, 38406c3fb27SDimitry Andric { {"mic_avx512"}, CK_KNL, FEATURE_AVX512F, FeaturesKNL, 'Z', true }, 385bdd1243dSDimitry Andric // Knights Mill processor. 38606c3fb27SDimitry Andric { {"knm"}, CK_KNM, FEATURE_AVX5124FMAPS, FeaturesKNM, 'j', false }, 387bdd1243dSDimitry Andric // Lakemont microarchitecture based processors. 38806c3fb27SDimitry Andric { {"lakemont"}, CK_Lakemont, ~0U, FeatureCMPXCHG8B, '\0', false }, 389bdd1243dSDimitry Andric // K6 architecture processors. 39006c3fb27SDimitry Andric { {"k6"}, CK_K6, ~0U, FeaturesK6, '\0', false }, 39106c3fb27SDimitry Andric { {"k6-2"}, CK_K6_2, ~0U, FeaturesK6 | Feature3DNOW, '\0', false }, 39206c3fb27SDimitry Andric { {"k6-3"}, CK_K6_3, ~0U, FeaturesK6 | Feature3DNOW, '\0', false }, 393bdd1243dSDimitry Andric // K7 architecture processors. 39406c3fb27SDimitry Andric { {"athlon"}, CK_Athlon, ~0U, FeaturesAthlon, '\0', false }, 39506c3fb27SDimitry Andric { {"athlon-tbird"}, CK_Athlon, ~0U, FeaturesAthlon, '\0', false }, 39606c3fb27SDimitry Andric { {"athlon-xp"}, CK_AthlonXP, ~0U, FeaturesAthlonXP, '\0', false }, 39706c3fb27SDimitry Andric { {"athlon-mp"}, CK_AthlonXP, ~0U, FeaturesAthlonXP, '\0', false }, 39806c3fb27SDimitry Andric { {"athlon-4"}, CK_AthlonXP, ~0U, FeaturesAthlonXP, '\0', false }, 399bdd1243dSDimitry Andric // K8 architecture processors. 40006c3fb27SDimitry Andric { {"k8"}, CK_K8, ~0U, FeaturesK8, '\0', false }, 40106c3fb27SDimitry Andric { {"athlon64"}, CK_K8, ~0U, FeaturesK8, '\0', false }, 40206c3fb27SDimitry Andric { {"athlon-fx"}, CK_K8, ~0U, FeaturesK8, '\0', false }, 40306c3fb27SDimitry Andric { {"opteron"}, CK_K8, ~0U, FeaturesK8, '\0', false }, 40406c3fb27SDimitry Andric { {"k8-sse3"}, CK_K8SSE3, ~0U, FeaturesK8SSE3, '\0', false }, 40506c3fb27SDimitry Andric { {"athlon64-sse3"}, CK_K8SSE3, ~0U, FeaturesK8SSE3, '\0', false }, 40606c3fb27SDimitry Andric { {"opteron-sse3"}, CK_K8SSE3, ~0U, FeaturesK8SSE3, '\0', false }, 40706c3fb27SDimitry Andric { {"amdfam10"}, CK_AMDFAM10, FEATURE_SSE4_A, FeaturesAMDFAM10, '\0', false }, 40806c3fb27SDimitry Andric { {"barcelona"}, CK_AMDFAM10, FEATURE_SSE4_A, FeaturesAMDFAM10, '\0', false }, 409bdd1243dSDimitry Andric // Bobcat architecture processors. 41006c3fb27SDimitry Andric { {"btver1"}, CK_BTVER1, FEATURE_SSE4_A, FeaturesBTVER1, '\0', false }, 41106c3fb27SDimitry Andric { {"btver2"}, CK_BTVER2, FEATURE_BMI, FeaturesBTVER2, '\0', false }, 412bdd1243dSDimitry Andric // Bulldozer architecture processors. 41306c3fb27SDimitry Andric { {"bdver1"}, CK_BDVER1, FEATURE_XOP, FeaturesBDVER1, '\0', false }, 41406c3fb27SDimitry Andric { {"bdver2"}, CK_BDVER2, FEATURE_FMA, FeaturesBDVER2, '\0', false }, 41506c3fb27SDimitry Andric { {"bdver3"}, CK_BDVER3, FEATURE_FMA, FeaturesBDVER3, '\0', false }, 41606c3fb27SDimitry Andric { {"bdver4"}, CK_BDVER4, FEATURE_AVX2, FeaturesBDVER4, '\0', false }, 417bdd1243dSDimitry Andric // Zen architecture processors. 41806c3fb27SDimitry Andric { {"znver1"}, CK_ZNVER1, FEATURE_AVX2, FeaturesZNVER1, '\0', false }, 41906c3fb27SDimitry Andric { {"znver2"}, CK_ZNVER2, FEATURE_AVX2, FeaturesZNVER2, '\0', false }, 42006c3fb27SDimitry Andric { {"znver3"}, CK_ZNVER3, FEATURE_AVX2, FeaturesZNVER3, '\0', false }, 42106c3fb27SDimitry Andric { {"znver4"}, CK_ZNVER4, FEATURE_AVX512VBMI2, FeaturesZNVER4, '\0', false }, 422bdd1243dSDimitry Andric // Generic 64-bit processor. 423*5f757f3fSDimitry Andric { {"x86-64"}, CK_x86_64, FEATURE_SSE2 , FeaturesX86_64, '\0', false }, 424*5f757f3fSDimitry Andric { {"x86-64-v2"}, CK_x86_64_v2, FEATURE_SSE4_2 , FeaturesX86_64_V2, '\0', false }, 425*5f757f3fSDimitry Andric { {"x86-64-v3"}, CK_x86_64_v3, FEATURE_AVX2, FeaturesX86_64_V3, '\0', false }, 426*5f757f3fSDimitry Andric { {"x86-64-v4"}, CK_x86_64_v4, FEATURE_AVX512VL, FeaturesX86_64_V4, '\0', false }, 427bdd1243dSDimitry Andric // Geode processors. 42806c3fb27SDimitry Andric { {"geode"}, CK_Geode, ~0U, FeaturesGeode, '\0', false }, 429bdd1243dSDimitry Andric }; 430*5f757f3fSDimitry Andric // clang-format on 431bdd1243dSDimitry Andric 432bdd1243dSDimitry Andric constexpr const char *NoTuneList[] = {"x86-64-v2", "x86-64-v3", "x86-64-v4"}; 433bdd1243dSDimitry Andric 434bdd1243dSDimitry Andric X86::CPUKind llvm::X86::parseArchX86(StringRef CPU, bool Only64Bit) { 435bdd1243dSDimitry Andric for (const auto &P : Processors) 43606c3fb27SDimitry Andric if (!P.OnlyForCPUDispatchSpecific && P.Name == CPU && 43706c3fb27SDimitry Andric (P.Features[FEATURE_64BIT] || !Only64Bit)) 438bdd1243dSDimitry Andric return P.Kind; 439bdd1243dSDimitry Andric 440bdd1243dSDimitry Andric return CK_None; 441bdd1243dSDimitry Andric } 442bdd1243dSDimitry Andric 443bdd1243dSDimitry Andric X86::CPUKind llvm::X86::parseTuneCPU(StringRef CPU, bool Only64Bit) { 444bdd1243dSDimitry Andric if (llvm::is_contained(NoTuneList, CPU)) 445bdd1243dSDimitry Andric return CK_None; 446bdd1243dSDimitry Andric return parseArchX86(CPU, Only64Bit); 447bdd1243dSDimitry Andric } 448bdd1243dSDimitry Andric 449bdd1243dSDimitry Andric void llvm::X86::fillValidCPUArchList(SmallVectorImpl<StringRef> &Values, 450bdd1243dSDimitry Andric bool Only64Bit) { 451bdd1243dSDimitry Andric for (const auto &P : Processors) 45206c3fb27SDimitry Andric if (!P.OnlyForCPUDispatchSpecific && !P.Name.empty() && 45306c3fb27SDimitry Andric (P.Features[FEATURE_64BIT] || !Only64Bit)) 454bdd1243dSDimitry Andric Values.emplace_back(P.Name); 455bdd1243dSDimitry Andric } 456bdd1243dSDimitry Andric 457bdd1243dSDimitry Andric void llvm::X86::fillValidTuneCPUList(SmallVectorImpl<StringRef> &Values, 458bdd1243dSDimitry Andric bool Only64Bit) { 459bdd1243dSDimitry Andric for (const ProcInfo &P : Processors) 46006c3fb27SDimitry Andric if (!P.OnlyForCPUDispatchSpecific && !P.Name.empty() && 46106c3fb27SDimitry Andric (P.Features[FEATURE_64BIT] || !Only64Bit) && 462bdd1243dSDimitry Andric !llvm::is_contained(NoTuneList, P.Name)) 463bdd1243dSDimitry Andric Values.emplace_back(P.Name); 464bdd1243dSDimitry Andric } 465bdd1243dSDimitry Andric 466bdd1243dSDimitry Andric ProcessorFeatures llvm::X86::getKeyFeature(X86::CPUKind Kind) { 467bdd1243dSDimitry Andric // FIXME: Can we avoid a linear search here? The table might be sorted by 468bdd1243dSDimitry Andric // CPUKind so we could binary search? 469bdd1243dSDimitry Andric for (const auto &P : Processors) { 470bdd1243dSDimitry Andric if (P.Kind == Kind) { 471bdd1243dSDimitry Andric assert(P.KeyFeature != ~0U && "Processor does not have a key feature."); 472bdd1243dSDimitry Andric return static_cast<ProcessorFeatures>(P.KeyFeature); 473bdd1243dSDimitry Andric } 474bdd1243dSDimitry Andric } 475bdd1243dSDimitry Andric 476bdd1243dSDimitry Andric llvm_unreachable("Unable to find CPU kind!"); 477bdd1243dSDimitry Andric } 478bdd1243dSDimitry Andric 479bdd1243dSDimitry Andric // Features with no dependencies. 480bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeatures64BIT = {}; 481bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesADX = {}; 482bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesBMI = {}; 483bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesBMI2 = {}; 484bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesCLDEMOTE = {}; 485bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesCLFLUSHOPT = {}; 486bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesCLWB = {}; 487bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesCLZERO = {}; 488bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesCMOV = {}; 489bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesCMPXCHG16B = {}; 490bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesCMPXCHG8B = {}; 491bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesCRC32 = {}; 492bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesENQCMD = {}; 493bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesFSGSBASE = {}; 494bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesFXSR = {}; 495bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesINVPCID = {}; 496bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesLWP = {}; 497bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesLZCNT = {}; 498bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesMWAITX = {}; 499bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesMOVBE = {}; 500bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesMOVDIR64B = {}; 501bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesMOVDIRI = {}; 502bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesPCONFIG = {}; 503bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesPOPCNT = {}; 504bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesPKU = {}; 505bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesPREFETCHWT1 = {}; 506bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesPRFCHW = {}; 507bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesPTWRITE = {}; 508bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesRDPID = {}; 509bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesRDPRU = {}; 510bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesRDRND = {}; 511bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesRDSEED = {}; 512bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesRTM = {}; 513bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesSAHF = {}; 514bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesSERIALIZE = {}; 515bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesSGX = {}; 516bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesSHSTK = {}; 517bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesTBM = {}; 518bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesTSXLDTRK = {}; 519bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesUINTR = {}; 520*5f757f3fSDimitry Andric constexpr FeatureBitset ImpliedFeaturesUSERMSR = {}; 521bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesWAITPKG = {}; 522bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesWBNOINVD = {}; 523bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesVZEROUPPER = {}; 524bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesX87 = {}; 525bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesXSAVE = {}; 526bdd1243dSDimitry Andric 527bdd1243dSDimitry Andric // Not really CPU features, but need to be in the table because clang uses 528bdd1243dSDimitry Andric // target features to communicate them to the backend. 529bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesRETPOLINE_EXTERNAL_THUNK = {}; 530bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesRETPOLINE_INDIRECT_BRANCHES = {}; 531bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesRETPOLINE_INDIRECT_CALLS = {}; 532bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesLVI_CFI = {}; 533bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesLVI_LOAD_HARDENING = {}; 534bdd1243dSDimitry Andric 535bdd1243dSDimitry Andric // XSAVE features are dependent on basic XSAVE. 536bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesXSAVEC = FeatureXSAVE; 537bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesXSAVEOPT = FeatureXSAVE; 538bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesXSAVES = FeatureXSAVE; 539bdd1243dSDimitry Andric 540bdd1243dSDimitry Andric // MMX->3DNOW->3DNOWA chain. 541bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesMMX = {}; 542bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeatures3DNOW = FeatureMMX; 543bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeatures3DNOWA = Feature3DNOW; 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; 554*5f757f3fSDimitry 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; 565*5f757f3fSDimitry Andric constexpr FeatureBitset ImpliedFeaturesVAES = FeatureAES | FeatureAVX2; 566bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesVPCLMULQDQ = FeatureAVX | FeaturePCLMUL; 56706c3fb27SDimitry Andric constexpr FeatureBitset ImpliedFeaturesSM3 = FeatureAVX; 568*5f757f3fSDimitry 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 ImpliedFeaturesAVX512ER = FeatureAVX512F; 575bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVX512PF = FeatureAVX512F; 576bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVX512VL = FeatureAVX512F; 577bdd1243dSDimitry Andric 578bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVX512BF16 = FeatureAVX512BW; 579bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVX512BITALG = FeatureAVX512BW; 580bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVX512IFMA = FeatureAVX512F; 581bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVX512VNNI = FeatureAVX512F; 582bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVX512VPOPCNTDQ = FeatureAVX512F; 583bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVX512VBMI = FeatureAVX512BW; 584bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVX512VBMI2 = FeatureAVX512BW; 585bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVX512VP2INTERSECT = FeatureAVX512F; 586bdd1243dSDimitry Andric 587bdd1243dSDimitry Andric // FIXME: These two aren't really implemented and just exist in the feature 588bdd1243dSDimitry Andric // list for __builtin_cpu_supports. So omit their dependencies. 589bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVX5124FMAPS = {}; 590bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVX5124VNNIW = {}; 591bdd1243dSDimitry Andric 592bdd1243dSDimitry Andric // SSE4_A->FMA4->XOP chain. 593bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesSSE4_A = FeatureSSE3; 594bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesFMA4 = FeatureAVX | FeatureSSE4_A; 595bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesXOP = FeatureFMA4; 596bdd1243dSDimitry Andric 597bdd1243dSDimitry Andric // AMX Features 598bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAMX_TILE = {}; 599bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAMX_BF16 = FeatureAMX_TILE; 600bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAMX_FP16 = FeatureAMX_TILE; 601bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAMX_INT8 = FeatureAMX_TILE; 60206c3fb27SDimitry Andric constexpr FeatureBitset ImpliedFeaturesAMX_COMPLEX = FeatureAMX_TILE; 603bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesHRESET = {}; 604bdd1243dSDimitry Andric 605bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesPREFETCHI = {}; 606bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesCMPCCXADD = {}; 607bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesRAOINT = {}; 60806c3fb27SDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVXVNNIINT16 = FeatureAVX2; 609bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVXVNNIINT8 = FeatureAVX2; 610bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVXIFMA = FeatureAVX2; 611bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVXNECONVERT = FeatureAVX2; 612*5f757f3fSDimitry Andric constexpr FeatureBitset ImpliedFeaturesSHA512 = FeatureAVX2; 613bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVX512FP16 = 614bdd1243dSDimitry Andric FeatureAVX512BW | FeatureAVX512DQ | FeatureAVX512VL; 615bdd1243dSDimitry Andric // Key Locker Features 616bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesKL = FeatureSSE2; 617bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesWIDEKL = FeatureKL; 618bdd1243dSDimitry Andric 619bdd1243dSDimitry Andric // AVXVNNI Features 620bdd1243dSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVXVNNI = FeatureAVX2; 621bdd1243dSDimitry Andric 622*5f757f3fSDimitry Andric // AVX10 Features 623*5f757f3fSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVX10_1 = 624*5f757f3fSDimitry Andric FeatureAVX512CD | FeatureAVX512VBMI | FeatureAVX512IFMA | 625*5f757f3fSDimitry Andric FeatureAVX512VNNI | FeatureAVX512BF16 | FeatureAVX512VPOPCNTDQ | 626*5f757f3fSDimitry Andric FeatureAVX512VBMI2 | FeatureAVX512BITALG | FeatureVAES | FeatureVPCLMULQDQ | 627*5f757f3fSDimitry Andric FeatureAVX512FP16; 628*5f757f3fSDimitry Andric constexpr FeatureBitset ImpliedFeaturesAVX10_1_512 = 629*5f757f3fSDimitry Andric FeatureAVX10_1 | FeatureEVEX512; 630bdd1243dSDimitry Andric 631*5f757f3fSDimitry Andric // APX Features 632*5f757f3fSDimitry Andric constexpr FeatureBitset ImpliedFeaturesEGPR = {}; 633*5f757f3fSDimitry Andric constexpr FeatureBitset ImpliedFeaturesPush2Pop2 = {}; 634*5f757f3fSDimitry Andric constexpr FeatureBitset ImpliedFeaturesPPX = {}; 635*5f757f3fSDimitry Andric constexpr FeatureBitset ImpliedFeaturesNDD = {}; 636*5f757f3fSDimitry Andric constexpr FeatureBitset ImpliedFeaturesCCMP = {}; 637*5f757f3fSDimitry Andric constexpr FeatureBitset ImpliedFeaturesCF = {}; 638*5f757f3fSDimitry Andric 639*5f757f3fSDimitry 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, 646*5f757f3fSDimitry 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) 659*5f757f3fSDimitry Andric if (Bits[i] && !FeatureInfos[i].getName(NeedPlus).empty()) 660*5f757f3fSDimitry 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) { 697*5f757f3fSDimitry Andric auto I = llvm::find_if(FeatureInfos, [&](const FeatureInfo &FI) { 698*5f757f3fSDimitry Andric return FI.getName() == Feature; 699*5f757f3fSDimitry 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) 715*5f757f3fSDimitry Andric if (ImpliedBits[i] && !FeatureInfos[i].getName().empty()) 716*5f757f3fSDimitry 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 733*5f757f3fSDimitry Andric std::array<uint32_t, 4> 734*5f757f3fSDimitry Andric llvm::X86::getCpuSupportsMask(ArrayRef<StringRef> FeatureStrs) { 735bdd1243dSDimitry Andric // Processor features and mapping to processor feature value. 736*5f757f3fSDimitry Andric std::array<uint32_t, 4> FeatureMask{}; 737*5f757f3fSDimitry 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) 741*5f757f3fSDimitry Andric #define X86_MICROARCH_LEVEL(ENUM, STR, PRIORITY) \ 742*5f757f3fSDimitry Andric .Case(STR, llvm::X86::FEATURE_##ENUM) 743bdd1243dSDimitry Andric #include "llvm/TargetParser/X86TargetParser.def" 744bdd1243dSDimitry Andric ; 745*5f757f3fSDimitry Andric assert(Feature / 32 < FeatureMask.size()); 746*5f757f3fSDimitry Andric FeatureMask[Feature / 32] |= 1U << (Feature % 32); 747bdd1243dSDimitry Andric } 748*5f757f3fSDimitry 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 755bdd1243dSDimitry Andric // starting from zero (0, 1, ..., num_features - 1). 756bdd1243dSDimitry Andric #define X86_FEATURE_COMPAT(ENUM, STR, PRIORITY) PRIORITY, 757bdd1243dSDimitry Andric unsigned Priorities[] = { 758bdd1243dSDimitry Andric #include "llvm/TargetParser/X86TargetParser.def" 759bdd1243dSDimitry Andric }; 760*5f757f3fSDimitry Andric std::array<unsigned, std::size(Priorities)> HelperList; 761bdd1243dSDimitry Andric std::iota(HelperList.begin(), HelperList.end(), 0); 762bdd1243dSDimitry Andric assert(std::is_permutation(HelperList.begin(), HelperList.end(), 763*5f757f3fSDimitry Andric std::begin(Priorities), std::end(Priorities)) && 764bdd1243dSDimitry Andric "Priorities don't form consecutive range!"); 765bdd1243dSDimitry Andric #endif 766bdd1243dSDimitry Andric 767bdd1243dSDimitry Andric switch (Feat) { 768bdd1243dSDimitry Andric #define X86_FEATURE_COMPAT(ENUM, STR, PRIORITY) \ 769bdd1243dSDimitry Andric case X86::FEATURE_##ENUM: \ 770bdd1243dSDimitry Andric return PRIORITY; 771bdd1243dSDimitry Andric #include "llvm/TargetParser/X86TargetParser.def" 772bdd1243dSDimitry Andric default: 773bdd1243dSDimitry Andric llvm_unreachable("No Feature Priority for non-CPUSupports Features"); 774bdd1243dSDimitry Andric } 775bdd1243dSDimitry Andric } 776