Craig Topper | d5c28c4 | 2020-06-09 12:18:08 -0700 | [diff] [blame] | 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/Support/X86TargetParser.h" |
| 14 | #include "llvm/ADT/StringSwitch.h" |
| 15 | #include "llvm/ADT/Triple.h" |
| 16 | |
| 17 | using namespace llvm; |
Craig Topper | 8dc9214 | 2020-06-24 10:36:02 -0700 | [diff] [blame] | 18 | using namespace llvm::X86; |
Craig Topper | d5c28c4 | 2020-06-09 12:18:08 -0700 | [diff] [blame] | 19 | |
Craig Topper | 8dc9214 | 2020-06-24 10:36:02 -0700 | [diff] [blame] | 20 | namespace { |
| 21 | |
Craig Topper | 3537939 | 2020-06-30 11:59:03 -0700 | [diff] [blame] | 22 | /// Container class for CPU features. |
| 23 | /// This is a constexpr reimplementation of a subset of std::bitset. It would be |
| 24 | /// nice to use std::bitset directly, but it doesn't support constant |
| 25 | /// initialization. |
| 26 | class FeatureBitset { |
| 27 | static constexpr unsigned NUM_FEATURE_WORDS = |
| 28 | (X86::CPU_FEATURE_MAX + 31) / 32; |
| 29 | |
| 30 | // This cannot be a std::array, operator[] is not constexpr until C++17. |
| 31 | uint32_t Bits[NUM_FEATURE_WORDS] = {}; |
| 32 | |
| 33 | public: |
| 34 | constexpr FeatureBitset() = default; |
| 35 | constexpr FeatureBitset(std::initializer_list<unsigned> Init) { |
| 36 | for (auto I : Init) |
| 37 | set(I); |
| 38 | } |
| 39 | |
| 40 | constexpr FeatureBitset &set(unsigned I) { |
| 41 | uint32_t NewBits = Bits[I / 32] | (uint32_t(1) << (I % 32)); |
| 42 | Bits[I / 32] = NewBits; |
| 43 | return *this; |
| 44 | } |
| 45 | |
| 46 | constexpr bool operator[](unsigned I) const { |
| 47 | uint32_t Mask = uint32_t(1) << (I % 32); |
| 48 | return (Bits[I / 32] & Mask) != 0; |
| 49 | } |
| 50 | |
| 51 | constexpr FeatureBitset operator&(const FeatureBitset &RHS) const { |
| 52 | FeatureBitset Result; |
| 53 | for (unsigned I = 0, E = array_lengthof(Bits); I != E; ++I) |
| 54 | Result.Bits[I] = Bits[I] & RHS.Bits[I]; |
| 55 | return Result; |
| 56 | } |
| 57 | |
| 58 | constexpr FeatureBitset operator|(const FeatureBitset &RHS) const { |
| 59 | FeatureBitset Result; |
| 60 | for (unsigned I = 0, E = array_lengthof(Bits); I != E; ++I) |
| 61 | Result.Bits[I] = Bits[I] | RHS.Bits[I]; |
| 62 | return Result; |
| 63 | } |
| 64 | |
| 65 | constexpr FeatureBitset operator~() const { |
| 66 | FeatureBitset Result; |
| 67 | for (unsigned I = 0, E = array_lengthof(Bits); I != E; ++I) |
| 68 | Result.Bits[I] = ~Bits[I]; |
| 69 | return Result; |
| 70 | } |
| 71 | }; |
| 72 | |
Craig Topper | 8dc9214 | 2020-06-24 10:36:02 -0700 | [diff] [blame] | 73 | struct ProcInfo { |
| 74 | StringLiteral Name; |
| 75 | X86::CPUKind Kind; |
| 76 | unsigned KeyFeature; |
Craig Topper | 3537939 | 2020-06-30 11:59:03 -0700 | [diff] [blame] | 77 | FeatureBitset Features; |
Craig Topper | 8dc9214 | 2020-06-24 10:36:02 -0700 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | } // end anonymous namespace |
| 81 | |
Craig Topper | 3537939 | 2020-06-30 11:59:03 -0700 | [diff] [blame] | 82 | #define X86_FEATURE(ENUM, STRING) \ |
| 83 | static constexpr FeatureBitset Feature##ENUM = {X86::FEATURE_##ENUM}; |
| 84 | #include "llvm/Support/X86TargetParser.def" |
| 85 | |
| 86 | // Pentium with MMX. |
| 87 | static constexpr FeatureBitset FeaturesPentiumMMX = |
| 88 | FeatureX87 | FeatureCMPXCHG8B | FeatureMMX; |
| 89 | |
| 90 | // Pentium 2 and 3. |
| 91 | static constexpr FeatureBitset FeaturesPentium2 = |
| 92 | FeatureX87 | FeatureCMPXCHG8B | FeatureMMX | FeatureFXSR; |
| 93 | static constexpr FeatureBitset FeaturesPentium3 = FeaturesPentium2 | FeatureSSE; |
| 94 | |
| 95 | // Pentium 4 CPUs |
| 96 | static constexpr FeatureBitset FeaturesPentium4 = |
| 97 | FeaturesPentium3 | FeatureSSE2; |
| 98 | static constexpr FeatureBitset FeaturesPrescott = |
| 99 | FeaturesPentium4 | FeatureSSE3; |
| 100 | static constexpr FeatureBitset FeaturesNocona = |
| 101 | FeaturesPrescott | FeatureEM64T | FeatureCMPXCHG16B; |
| 102 | |
| 103 | // Basic 64-bit capable CPU. |
| 104 | static constexpr FeatureBitset FeaturesX86_64 = FeaturesPentium4 | FeatureEM64T; |
| 105 | |
| 106 | // Intel Core CPUs |
| 107 | static constexpr FeatureBitset FeaturesCore2 = |
| 108 | FeaturesNocona | FeatureSAHF | FeatureSSSE3; |
| 109 | static constexpr FeatureBitset FeaturesPenryn = FeaturesCore2 | FeatureSSE4_1; |
| 110 | static constexpr FeatureBitset FeaturesNehalem = |
| 111 | FeaturesPenryn | FeaturePOPCNT | FeatureSSE4_2; |
| 112 | static constexpr FeatureBitset FeaturesWestmere = |
| 113 | FeaturesNehalem | FeaturePCLMUL; |
| 114 | static constexpr FeatureBitset FeaturesSandyBridge = |
| 115 | FeaturesWestmere | FeatureAVX | FeatureXSAVE | FeatureXSAVEOPT; |
| 116 | static constexpr FeatureBitset FeaturesIvyBridge = |
| 117 | FeaturesSandyBridge | FeatureF16C | FeatureFSGSBASE | FeatureRDRND; |
| 118 | static constexpr FeatureBitset FeaturesHaswell = |
| 119 | FeaturesIvyBridge | FeatureAVX2 | FeatureBMI | FeatureBMI2 | FeatureFMA | |
| 120 | FeatureINVPCID | FeatureLZCNT | FeatureMOVBE; |
| 121 | static constexpr FeatureBitset FeaturesBroadwell = |
| 122 | FeaturesHaswell | FeatureADX | FeaturePRFCHW | FeatureRDSEED; |
| 123 | |
| 124 | // Intel Knights Landing and Knights Mill |
| 125 | // Knights Landing has feature parity with Broadwell. |
| 126 | static constexpr FeatureBitset FeaturesKNL = |
| 127 | FeaturesBroadwell | FeatureAES | FeatureAVX512F | FeatureAVX512CD | |
| 128 | FeatureAVX512ER | FeatureAVX512PF | FeaturePREFETCHWT1; |
| 129 | static constexpr FeatureBitset FeaturesKNM = |
| 130 | FeaturesKNL | FeatureAVX512VPOPCNTDQ; |
| 131 | |
| 132 | // Intel Skylake processors. |
| 133 | static constexpr FeatureBitset FeaturesSkylakeClient = |
| 134 | FeaturesBroadwell | FeatureAES | FeatureCLFLUSHOPT | FeatureXSAVEC | |
| 135 | FeatureXSAVES | FeatureSGX; |
| 136 | // SkylakeServer inherits all SkylakeClient features except SGX. |
| 137 | // FIXME: That doesn't match gcc. |
| 138 | static constexpr FeatureBitset FeaturesSkylakeServer = |
| 139 | (FeaturesSkylakeClient & ~FeatureSGX) | FeatureAVX512F | FeatureAVX512CD | |
| 140 | FeatureAVX512DQ | FeatureAVX512BW | FeatureAVX512VL | FeatureCLWB | |
| 141 | FeaturePKU; |
| 142 | static constexpr FeatureBitset FeaturesCascadeLake = |
| 143 | FeaturesSkylakeServer | FeatureAVX512VNNI; |
| 144 | static constexpr FeatureBitset FeaturesCooperLake = |
| 145 | FeaturesCascadeLake | FeatureAVX512BF16; |
| 146 | |
| 147 | // Intel 10nm processors. |
| 148 | static constexpr FeatureBitset FeaturesCannonlake = |
| 149 | FeaturesSkylakeClient | FeatureAVX512F | FeatureAVX512CD | FeatureAVX512DQ | |
| 150 | FeatureAVX512BW | FeatureAVX512VL | FeatureAVX512IFMA | FeatureAVX512VBMI | |
| 151 | FeaturePKU | FeatureSHA; |
| 152 | static constexpr FeatureBitset FeaturesICLClient = |
| 153 | FeaturesCannonlake | FeatureAVX512BITALG | FeatureAVX512VBMI2 | |
| 154 | FeatureAVX512VNNI | FeatureAVX512VPOPCNTDQ | FeatureCLWB | FeatureGFNI | |
| 155 | FeatureRDPID | FeatureVAES | FeatureVPCLMULQDQ; |
| 156 | static constexpr FeatureBitset FeaturesICLServer = |
| 157 | FeaturesICLClient | FeaturePCONFIG | FeatureWBNOINVD; |
| 158 | static constexpr FeatureBitset FeaturesTigerlake = |
| 159 | FeaturesICLClient | FeatureAVX512VP2INTERSECT | FeatureMOVDIR64B | |
| 160 | FeatureMOVDIRI | FeatureSHSTK; |
| 161 | |
| 162 | // Intel Atom processors. |
| 163 | // Bonnell has feature parity with Core2 and adds MOVBE. |
| 164 | static constexpr FeatureBitset FeaturesBonnell = FeaturesCore2 | FeatureMOVBE; |
| 165 | // Silvermont has parity with Westmere and Bonnell plus PRFCHW and RDRND. |
| 166 | static constexpr FeatureBitset FeaturesSilvermont = |
| 167 | FeaturesBonnell | FeaturesWestmere | FeaturePRFCHW | FeatureRDRND; |
| 168 | static constexpr FeatureBitset FeaturesGoldmont = |
| 169 | FeaturesSilvermont | FeatureAES | FeatureCLFLUSHOPT | FeatureFSGSBASE | |
| 170 | FeatureRDSEED | FeatureSHA | FeatureXSAVE | FeatureXSAVEC | |
| 171 | FeatureXSAVEOPT | FeatureXSAVES; |
| 172 | static constexpr FeatureBitset FeaturesGoldmontPlus = |
| 173 | FeaturesGoldmont | FeaturePTWRITE | FeatureRDPID | FeatureSGX; |
| 174 | static constexpr FeatureBitset FeaturesTremont = |
| 175 | FeaturesGoldmontPlus | FeatureCLWB | FeatureGFNI; |
| 176 | |
| 177 | // Geode Processor. |
| 178 | static constexpr FeatureBitset FeaturesGeode = |
| 179 | FeatureX87 | FeatureCMPXCHG8B | FeatureMMX | Feature3DNOW | Feature3DNOWA; |
| 180 | |
| 181 | // K6 processor. |
| 182 | static constexpr FeatureBitset FeaturesK6 = |
| 183 | FeatureX87 | FeatureCMPXCHG8B | FeatureMMX; |
| 184 | |
| 185 | // K7 and K8 architecture processors. |
| 186 | static constexpr FeatureBitset FeaturesAthlon = |
| 187 | FeatureX87 | FeatureCMPXCHG8B | FeatureMMX | Feature3DNOW | Feature3DNOWA; |
| 188 | static constexpr FeatureBitset FeaturesAthlonXP = |
| 189 | FeaturesAthlon | FeatureFXSR | FeatureSSE; |
| 190 | static constexpr FeatureBitset FeaturesK8 = |
| 191 | FeaturesAthlonXP | FeatureSSE2 | FeatureEM64T; |
| 192 | static constexpr FeatureBitset FeaturesK8SSE3 = FeaturesK8 | FeatureSSE3; |
| 193 | static constexpr FeatureBitset FeaturesAMDFAM10 = |
| 194 | FeaturesK8SSE3 | FeatureCMPXCHG16B | FeatureLZCNT | FeaturePOPCNT | |
| 195 | FeaturePRFCHW | FeatureSAHF | FeatureSSE4A; |
| 196 | |
| 197 | // Bobcat architecture processors. |
| 198 | static constexpr FeatureBitset FeaturesBTVER1 = |
| 199 | FeatureX87 | FeatureCMPXCHG8B | FeatureCMPXCHG16B | FeatureEM64T | |
| 200 | FeatureFXSR | FeatureLZCNT | FeatureMMX | FeaturePOPCNT | FeaturePRFCHW | |
| 201 | FeatureSSE | FeatureSSE2 | FeatureSSE3 | FeatureSSSE3 | FeatureSSE4A | |
| 202 | FeatureSAHF; |
| 203 | static constexpr FeatureBitset FeaturesBTVER2 = |
| 204 | FeaturesBTVER1 | FeatureAES | FeatureAVX | FeatureBMI | FeatureF16C | |
| 205 | FeatureMOVBE | FeaturePCLMUL | FeatureXSAVE | FeatureXSAVEOPT; |
| 206 | |
| 207 | // AMD Bulldozer architecture processors. |
| 208 | static constexpr FeatureBitset FeaturesBDVER1 = |
| 209 | FeatureX87 | FeatureAES | FeatureAVX | FeatureCMPXCHG8B | |
| 210 | FeatureCMPXCHG16B | FeatureEM64T | FeatureFMA4 | FeatureFXSR | |
| 211 | FeatureLZCNT | FeatureLWP | FeatureLZCNT | FeatureMMX | FeaturePCLMUL | |
| 212 | FeaturePOPCNT | FeaturePRFCHW | FeatureSAHF | FeatureSSE | FeatureSSE2 | |
| 213 | FeatureSSE3 | FeatureSSSE3 | FeatureSSE4_1 | FeatureSSE4_2 | FeatureSSE4A | |
| 214 | FeatureXOP | FeatureXSAVE; |
| 215 | static constexpr FeatureBitset FeaturesBDVER2 = |
| 216 | FeaturesBDVER1 | FeatureBMI | FeatureFMA | FeatureF16C | FeatureTBM; |
| 217 | static constexpr FeatureBitset FeaturesBDVER3 = |
| 218 | FeaturesBDVER2 | FeatureFSGSBASE | FeatureXSAVEOPT; |
| 219 | static constexpr FeatureBitset FeaturesBDVER4 = |
| 220 | FeaturesBDVER3 | FeatureAVX2 | FeatureBMI2 | FeatureMOVBE | FeatureMWAITX | |
| 221 | FeatureRDRND; |
| 222 | |
| 223 | // AMD Zen architecture processors. |
| 224 | static constexpr FeatureBitset FeaturesZNVER1 = |
| 225 | FeatureX87 | FeatureADX | FeatureAES | FeatureAVX | FeatureAVX2 | |
| 226 | FeatureBMI | FeatureBMI2 | FeatureCLFLUSHOPT | FeatureCLZERO | |
| 227 | FeatureCMPXCHG8B | FeatureCMPXCHG16B | FeatureEM64T | FeatureF16C | |
| 228 | FeatureFMA | FeatureFSGSBASE | FeatureFXSR | FeatureLZCNT | FeatureLWP | |
| 229 | FeatureLZCNT | FeatureMOVBE | FeatureMMX | FeatureMWAITX | FeaturePCLMUL | |
| 230 | FeaturePOPCNT | FeaturePRFCHW | FeatureRDRND | FeatureRDSEED | FeatureSAHF | |
| 231 | FeatureSHA | FeatureSSE | FeatureSSE2 | FeatureSSE3 | FeatureSSSE3 | |
| 232 | FeatureSSE4_1 | FeatureSSE4_2 | FeatureSSE4A | FeatureXSAVE | |
| 233 | FeatureXSAVEC | FeatureXSAVEOPT | FeatureXSAVES; |
| 234 | static constexpr FeatureBitset FeaturesZNVER2 = |
| 235 | FeaturesZNVER1 | FeatureCLWB | FeatureRDPID | FeatureWBNOINVD; |
Craig Topper | 8dc9214 | 2020-06-24 10:36:02 -0700 | [diff] [blame] | 236 | |
| 237 | static constexpr ProcInfo Processors[] = { |
Craig Topper | 3537939 | 2020-06-30 11:59:03 -0700 | [diff] [blame] | 238 | // Empty processor. Include X87 and CMPXCHG8 for backwards compatibility. |
| 239 | { {""}, CK_None, ~0U, FeatureX87 | FeatureCMPXCHG8B }, |
Craig Topper | 8dc9214 | 2020-06-24 10:36:02 -0700 | [diff] [blame] | 240 | // i386-generation processors. |
Craig Topper | 3537939 | 2020-06-30 11:59:03 -0700 | [diff] [blame] | 241 | { {"i386"}, CK_i386, ~0U, FeatureX87 }, |
Craig Topper | 8dc9214 | 2020-06-24 10:36:02 -0700 | [diff] [blame] | 242 | // i486-generation processors. |
Craig Topper | 3537939 | 2020-06-30 11:59:03 -0700 | [diff] [blame] | 243 | { {"i486"}, CK_i486, ~0U, FeatureX87 }, |
| 244 | { {"winchip-c6"}, CK_WinChipC6, ~0U, FeaturesPentiumMMX }, |
| 245 | { {"winchip2"}, CK_WinChip2, ~0U, FeaturesPentiumMMX | Feature3DNOW }, |
| 246 | { {"c3"}, CK_C3, ~0U, FeaturesPentiumMMX | Feature3DNOW }, |
Craig Topper | 8dc9214 | 2020-06-24 10:36:02 -0700 | [diff] [blame] | 247 | // i586-generation processors, P5 microarchitecture based. |
Craig Topper | 3537939 | 2020-06-30 11:59:03 -0700 | [diff] [blame] | 248 | { {"i586"}, CK_i586, ~0U, FeatureX87 | FeatureCMPXCHG8B }, |
| 249 | { {"pentium"}, CK_Pentium, ~0U, FeatureX87 | FeatureCMPXCHG8B }, |
| 250 | { {"pentium-mmx"}, CK_PentiumMMX, ~0U, FeaturesPentiumMMX }, |
Craig Topper | 8dc9214 | 2020-06-24 10:36:02 -0700 | [diff] [blame] | 251 | // i686-generation processors, P6 / Pentium M microarchitecture based. |
Craig Topper | 3537939 | 2020-06-30 11:59:03 -0700 | [diff] [blame] | 252 | { {"pentiumpro"}, CK_PentiumPro, ~0U, FeatureX87 | FeatureCMPXCHG8B }, |
| 253 | { {"i686"}, CK_i686, ~0U, FeatureX87 | FeatureCMPXCHG8B }, |
| 254 | { {"pentium2"}, CK_Pentium2, ~0U, FeaturesPentium2 }, |
| 255 | { {"pentium3"}, CK_Pentium3, ~0U, FeaturesPentium3 }, |
| 256 | { {"pentium3m"}, CK_Pentium3, ~0U, FeaturesPentium3 }, |
| 257 | { {"pentium-m"}, CK_PentiumM, ~0U, FeaturesPentium4 }, |
| 258 | { {"c3-2"}, CK_C3_2, ~0U, FeaturesPentium3 }, |
| 259 | { {"yonah"}, CK_Yonah, ~0U, FeaturesPrescott }, |
Craig Topper | 8dc9214 | 2020-06-24 10:36:02 -0700 | [diff] [blame] | 260 | // Netburst microarchitecture based processors. |
Craig Topper | 3537939 | 2020-06-30 11:59:03 -0700 | [diff] [blame] | 261 | { {"pentium4"}, CK_Pentium4, ~0U, FeaturesPentium4 }, |
| 262 | { {"pentium4m"}, CK_Pentium4, ~0U, FeaturesPentium4 }, |
| 263 | { {"prescott"}, CK_Prescott, ~0U, FeaturesPrescott }, |
| 264 | { {"nocona"}, CK_Nocona, ~0U, FeaturesNocona }, |
Craig Topper | 8dc9214 | 2020-06-24 10:36:02 -0700 | [diff] [blame] | 265 | // Core microarchitecture based processors. |
Craig Topper | 3537939 | 2020-06-30 11:59:03 -0700 | [diff] [blame] | 266 | { {"core2"}, CK_Core2, ~0U, FeaturesCore2 }, |
| 267 | { {"penryn"}, CK_Penryn, ~0U, FeaturesPenryn }, |
Craig Topper | 8dc9214 | 2020-06-24 10:36:02 -0700 | [diff] [blame] | 268 | // Atom processors |
Craig Topper | 3537939 | 2020-06-30 11:59:03 -0700 | [diff] [blame] | 269 | { {"bonnell"}, CK_Bonnell, FEATURE_SSSE3, FeaturesBonnell }, |
| 270 | { {"atom"}, CK_Bonnell, FEATURE_SSSE3, FeaturesBonnell }, |
| 271 | { {"silvermont"}, CK_Silvermont, FEATURE_SSE4_2, FeaturesSilvermont }, |
| 272 | { {"slm"}, CK_Silvermont, FEATURE_SSE4_2, FeaturesSilvermont }, |
| 273 | { {"goldmont"}, CK_Goldmont, FEATURE_SSE4_2, FeaturesGoldmont }, |
| 274 | { {"goldmont-plus"}, CK_GoldmontPlus, FEATURE_SSE4_2, FeaturesGoldmontPlus }, |
| 275 | { {"tremont"}, CK_Tremont, FEATURE_SSE4_2, FeaturesTremont }, |
Craig Topper | 8dc9214 | 2020-06-24 10:36:02 -0700 | [diff] [blame] | 276 | // Nehalem microarchitecture based processors. |
Craig Topper | 3537939 | 2020-06-30 11:59:03 -0700 | [diff] [blame] | 277 | { {"nehalem"}, CK_Nehalem, FEATURE_SSE4_2, FeaturesNehalem }, |
| 278 | { {"corei7"}, CK_Nehalem, FEATURE_SSE4_2, FeaturesNehalem }, |
Craig Topper | 8dc9214 | 2020-06-24 10:36:02 -0700 | [diff] [blame] | 279 | // Westmere microarchitecture based processors. |
Craig Topper | 3537939 | 2020-06-30 11:59:03 -0700 | [diff] [blame] | 280 | { {"westmere"}, CK_Westmere, FEATURE_PCLMUL, FeaturesWestmere }, |
Craig Topper | 8dc9214 | 2020-06-24 10:36:02 -0700 | [diff] [blame] | 281 | // Sandy Bridge microarchitecture based processors. |
Craig Topper | 3537939 | 2020-06-30 11:59:03 -0700 | [diff] [blame] | 282 | { {"sandybridge"}, CK_SandyBridge, FEATURE_AVX, FeaturesSandyBridge }, |
| 283 | { {"corei7-avx"}, CK_SandyBridge, FEATURE_AVX, FeaturesSandyBridge }, |
Craig Topper | 8dc9214 | 2020-06-24 10:36:02 -0700 | [diff] [blame] | 284 | // Ivy Bridge microarchitecture based processors. |
Craig Topper | 3537939 | 2020-06-30 11:59:03 -0700 | [diff] [blame] | 285 | { {"ivybridge"}, CK_IvyBridge, FEATURE_AVX, FeaturesIvyBridge }, |
| 286 | { {"core-avx-i"}, CK_IvyBridge, FEATURE_AVX, FeaturesIvyBridge }, |
Craig Topper | 8dc9214 | 2020-06-24 10:36:02 -0700 | [diff] [blame] | 287 | // Haswell microarchitecture based processors. |
Craig Topper | 3537939 | 2020-06-30 11:59:03 -0700 | [diff] [blame] | 288 | { {"haswell"}, CK_Haswell, FEATURE_AVX2, FeaturesHaswell }, |
| 289 | { {"core-avx2"}, CK_Haswell, FEATURE_AVX2, FeaturesHaswell }, |
Craig Topper | 8dc9214 | 2020-06-24 10:36:02 -0700 | [diff] [blame] | 290 | // Broadwell microarchitecture based processors. |
Craig Topper | 3537939 | 2020-06-30 11:59:03 -0700 | [diff] [blame] | 291 | { {"broadwell"}, CK_Broadwell, FEATURE_AVX2, FeaturesBroadwell }, |
Craig Topper | 8dc9214 | 2020-06-24 10:36:02 -0700 | [diff] [blame] | 292 | // Skylake client microarchitecture based processors. |
Craig Topper | 3537939 | 2020-06-30 11:59:03 -0700 | [diff] [blame] | 293 | { {"skylake"}, CK_SkylakeClient, FEATURE_AVX2, FeaturesSkylakeClient }, |
Craig Topper | 8dc9214 | 2020-06-24 10:36:02 -0700 | [diff] [blame] | 294 | // Skylake server microarchitecture based processors. |
Craig Topper | 3537939 | 2020-06-30 11:59:03 -0700 | [diff] [blame] | 295 | { {"skylake-avx512"}, CK_SkylakeServer, FEATURE_AVX512F, FeaturesSkylakeServer }, |
| 296 | { {"skx"}, CK_SkylakeServer, FEATURE_AVX512F, FeaturesSkylakeServer }, |
Craig Topper | 8dc9214 | 2020-06-24 10:36:02 -0700 | [diff] [blame] | 297 | // Cascadelake Server microarchitecture based processors. |
Craig Topper | 3537939 | 2020-06-30 11:59:03 -0700 | [diff] [blame] | 298 | { {"cascadelake"}, CK_Cascadelake, FEATURE_AVX512VNNI, FeaturesCascadeLake }, |
Craig Topper | 8dc9214 | 2020-06-24 10:36:02 -0700 | [diff] [blame] | 299 | // Cooperlake Server microarchitecture based processors. |
Craig Topper | 3537939 | 2020-06-30 11:59:03 -0700 | [diff] [blame] | 300 | { {"cooperlake"}, CK_Cooperlake, FEATURE_AVX512BF16, FeaturesCooperLake }, |
Craig Topper | 8dc9214 | 2020-06-24 10:36:02 -0700 | [diff] [blame] | 301 | // Cannonlake client microarchitecture based processors. |
Craig Topper | 3537939 | 2020-06-30 11:59:03 -0700 | [diff] [blame] | 302 | { {"cannonlake"}, CK_Cannonlake, FEATURE_AVX512VBMI, FeaturesCannonlake }, |
Craig Topper | 8dc9214 | 2020-06-24 10:36:02 -0700 | [diff] [blame] | 303 | // Icelake client microarchitecture based processors. |
Craig Topper | 3537939 | 2020-06-30 11:59:03 -0700 | [diff] [blame] | 304 | { {"icelake-client"}, CK_IcelakeClient, FEATURE_AVX512VBMI2, FeaturesICLClient }, |
Craig Topper | 8dc9214 | 2020-06-24 10:36:02 -0700 | [diff] [blame] | 305 | // Icelake server microarchitecture based processors. |
Craig Topper | 3537939 | 2020-06-30 11:59:03 -0700 | [diff] [blame] | 306 | { {"icelake-server"}, CK_IcelakeServer, FEATURE_AVX512VBMI2, FeaturesICLServer }, |
Craig Topper | 8dc9214 | 2020-06-24 10:36:02 -0700 | [diff] [blame] | 307 | // Tigerlake microarchitecture based processors. |
Craig Topper | 3537939 | 2020-06-30 11:59:03 -0700 | [diff] [blame] | 308 | { {"tigerlake"}, CK_Tigerlake, FEATURE_AVX512VP2INTERSECT, FeaturesTigerlake }, |
Craig Topper | 8dc9214 | 2020-06-24 10:36:02 -0700 | [diff] [blame] | 309 | // Knights Landing processor. |
Craig Topper | 3537939 | 2020-06-30 11:59:03 -0700 | [diff] [blame] | 310 | { {"knl"}, CK_KNL, FEATURE_AVX512F, FeaturesKNL }, |
Craig Topper | 8dc9214 | 2020-06-24 10:36:02 -0700 | [diff] [blame] | 311 | // Knights Mill processor. |
Craig Topper | 3537939 | 2020-06-30 11:59:03 -0700 | [diff] [blame] | 312 | { {"knm"}, CK_KNM, FEATURE_AVX5124FMAPS, FeaturesKNM }, |
Craig Topper | 8dc9214 | 2020-06-24 10:36:02 -0700 | [diff] [blame] | 313 | // Lakemont microarchitecture based processors. |
Craig Topper | 3537939 | 2020-06-30 11:59:03 -0700 | [diff] [blame] | 314 | { {"lakemont"}, CK_Lakemont, ~0U, FeatureCMPXCHG8B }, |
Craig Topper | 8dc9214 | 2020-06-24 10:36:02 -0700 | [diff] [blame] | 315 | // K6 architecture processors. |
Craig Topper | 3537939 | 2020-06-30 11:59:03 -0700 | [diff] [blame] | 316 | { {"k6"}, CK_K6, ~0U, FeaturesK6 }, |
| 317 | { {"k6-2"}, CK_K6_2, ~0U, FeaturesK6 | Feature3DNOW }, |
| 318 | { {"k6-3"}, CK_K6_3, ~0U, FeaturesK6 | Feature3DNOW }, |
Craig Topper | 8dc9214 | 2020-06-24 10:36:02 -0700 | [diff] [blame] | 319 | // K7 architecture processors. |
Craig Topper | 3537939 | 2020-06-30 11:59:03 -0700 | [diff] [blame] | 320 | { {"athlon"}, CK_Athlon, ~0U, FeaturesAthlon }, |
| 321 | { {"athlon-tbird"}, CK_Athlon, ~0U, FeaturesAthlon }, |
| 322 | { {"athlon-xp"}, CK_AthlonXP, ~0U, FeaturesAthlonXP }, |
| 323 | { {"athlon-mp"}, CK_AthlonXP, ~0U, FeaturesAthlonXP }, |
| 324 | { {"athlon-4"}, CK_AthlonXP, ~0U, FeaturesAthlonXP }, |
Craig Topper | 8dc9214 | 2020-06-24 10:36:02 -0700 | [diff] [blame] | 325 | // K8 architecture processors. |
Craig Topper | 3537939 | 2020-06-30 11:59:03 -0700 | [diff] [blame] | 326 | { {"k8"}, CK_K8, ~0U, FeaturesK8 }, |
| 327 | { {"athlon64"}, CK_K8, ~0U, FeaturesK8 }, |
| 328 | { {"athlon-fx"}, CK_K8, ~0U, FeaturesK8 }, |
| 329 | { {"opteron"}, CK_K8, ~0U, FeaturesK8 }, |
| 330 | { {"k8-sse3"}, CK_K8SSE3, ~0U, FeaturesK8SSE3 }, |
| 331 | { {"athlon64-sse3"}, CK_K8SSE3, ~0U, FeaturesK8SSE3 }, |
| 332 | { {"opteron-sse3"}, CK_K8SSE3, ~0U, FeaturesK8SSE3 }, |
| 333 | { {"amdfam10"}, CK_AMDFAM10, FEATURE_SSE4_A, FeaturesAMDFAM10 }, |
| 334 | { {"barcelona"}, CK_AMDFAM10, FEATURE_SSE4_A, FeaturesAMDFAM10 }, |
Craig Topper | 8dc9214 | 2020-06-24 10:36:02 -0700 | [diff] [blame] | 335 | // Bobcat architecture processors. |
Craig Topper | 3537939 | 2020-06-30 11:59:03 -0700 | [diff] [blame] | 336 | { {"btver1"}, CK_BTVER1, FEATURE_SSE4_A, FeaturesBTVER1 }, |
| 337 | { {"btver2"}, CK_BTVER2, FEATURE_BMI, FeaturesBTVER2 }, |
Craig Topper | 8dc9214 | 2020-06-24 10:36:02 -0700 | [diff] [blame] | 338 | // Bulldozer architecture processors. |
Craig Topper | 3537939 | 2020-06-30 11:59:03 -0700 | [diff] [blame] | 339 | { {"bdver1"}, CK_BDVER1, FEATURE_XOP, FeaturesBDVER1 }, |
| 340 | { {"bdver2"}, CK_BDVER2, FEATURE_FMA, FeaturesBDVER2 }, |
| 341 | { {"bdver3"}, CK_BDVER3, FEATURE_FMA, FeaturesBDVER3 }, |
| 342 | { {"bdver4"}, CK_BDVER4, FEATURE_AVX2, FeaturesBDVER4 }, |
Craig Topper | 8dc9214 | 2020-06-24 10:36:02 -0700 | [diff] [blame] | 343 | // Zen architecture processors. |
Craig Topper | 3537939 | 2020-06-30 11:59:03 -0700 | [diff] [blame] | 344 | { {"znver1"}, CK_ZNVER1, FEATURE_AVX2, FeaturesZNVER1 }, |
| 345 | { {"znver2"}, CK_ZNVER2, FEATURE_AVX2, FeaturesZNVER2 }, |
Craig Topper | 8dc9214 | 2020-06-24 10:36:02 -0700 | [diff] [blame] | 346 | // Generic 64-bit processor. |
Craig Topper | 3537939 | 2020-06-30 11:59:03 -0700 | [diff] [blame] | 347 | { {"x86-64"}, CK_x86_64, ~0U, FeaturesX86_64 }, |
Craig Topper | 8dc9214 | 2020-06-24 10:36:02 -0700 | [diff] [blame] | 348 | // Geode processors. |
Craig Topper | 3537939 | 2020-06-30 11:59:03 -0700 | [diff] [blame] | 349 | { {"geode"}, CK_Geode, ~0U, FeaturesGeode }, |
Craig Topper | 8dc9214 | 2020-06-24 10:36:02 -0700 | [diff] [blame] | 350 | }; |
Craig Topper | d5c28c4 | 2020-06-09 12:18:08 -0700 | [diff] [blame] | 351 | |
| 352 | X86::CPUKind llvm::X86::parseArchX86(StringRef CPU, bool Only64Bit) { |
Craig Topper | 8dc9214 | 2020-06-24 10:36:02 -0700 | [diff] [blame] | 353 | for (const auto &P : Processors) |
Craig Topper | 3537939 | 2020-06-30 11:59:03 -0700 | [diff] [blame] | 354 | if (P.Name == CPU && (P.Features[FEATURE_EM64T] || !Only64Bit)) |
Craig Topper | 8dc9214 | 2020-06-24 10:36:02 -0700 | [diff] [blame] | 355 | return P.Kind; |
Craig Topper | d5c28c4 | 2020-06-09 12:18:08 -0700 | [diff] [blame] | 356 | |
Craig Topper | 8dc9214 | 2020-06-24 10:36:02 -0700 | [diff] [blame] | 357 | return CK_None; |
Craig Topper | d5c28c4 | 2020-06-09 12:18:08 -0700 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | void llvm::X86::fillValidCPUArchList(SmallVectorImpl<StringRef> &Values, |
| 361 | bool Only64Bit) { |
Craig Topper | 8dc9214 | 2020-06-24 10:36:02 -0700 | [diff] [blame] | 362 | for (const auto &P : Processors) |
Craig Topper | 3537939 | 2020-06-30 11:59:03 -0700 | [diff] [blame] | 363 | if (!P.Name.empty() && (P.Features[FEATURE_EM64T] || !Only64Bit)) |
Craig Topper | 8dc9214 | 2020-06-24 10:36:02 -0700 | [diff] [blame] | 364 | Values.emplace_back(P.Name); |
| 365 | } |
| 366 | |
| 367 | ProcessorFeatures llvm::X86::getKeyFeature(X86::CPUKind Kind) { |
| 368 | // FIXME: Can we avoid a linear search here? The table might be sorted by |
| 369 | // CPUKind so we could binary search? |
| 370 | for (const auto &P : Processors) { |
| 371 | if (P.Kind == Kind) { |
| 372 | assert(P.KeyFeature != ~0U && "Processor does not have a key feature."); |
| 373 | return static_cast<ProcessorFeatures>(P.KeyFeature); |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | llvm_unreachable("Unable to find CPU kind!"); |
Craig Topper | d5c28c4 | 2020-06-09 12:18:08 -0700 | [diff] [blame] | 378 | } |
Craig Topper | 3537939 | 2020-06-30 11:59:03 -0700 | [diff] [blame] | 379 | |
| 380 | static const char *FeatureStrings[X86::CPU_FEATURE_MAX] = { |
| 381 | #define X86_FEATURE(ENUM, STR) STR, |
| 382 | #include "llvm/Support/X86TargetParser.def" |
| 383 | }; |
| 384 | |
| 385 | void llvm::X86::getFeaturesForCPU(StringRef CPU, |
| 386 | SmallVectorImpl<StringRef> &Features) { |
| 387 | auto I = llvm::find_if(Processors, |
| 388 | [&](const ProcInfo &P) { return P.Name == CPU; }); |
| 389 | assert(I != std::end(Processors) && "Processor not found!"); |
| 390 | |
| 391 | // Add the string version of all set bits. |
| 392 | for (unsigned i = 0; i != CPU_FEATURE_MAX; ++i) |
| 393 | if (FeatureStrings[i] && I->Features[i]) |
| 394 | Features.push_back(FeatureStrings[i]); |
| 395 | } |