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