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