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