X86TargetParser.cpp 33 KB

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