diff --git a/llvm/include/llvm/TargetParser/X86TargetParser.h b/llvm/include/llvm/TargetParser/X86TargetParser.h --- a/llvm/include/llvm/TargetParser/X86TargetParser.h +++ b/llvm/include/llvm/TargetParser/X86TargetParser.h @@ -160,9 +160,9 @@ ProcessorFeatures getKeyFeature(CPUKind Kind); /// Fill in the features that \p CPU supports into \p Features. -/// "+" will be append in front of each feature if IfNeedPlus is true. +/// "+" will be append in front of each feature if NeedPlus is true. void getFeaturesForCPU(StringRef CPU, SmallVectorImpl &Features, - bool IfNeedPlus = false); + bool NeedPlus = false); /// Set or clear entries in \p Features that are implied to be enabled/disabled /// by the provided \p Feature. diff --git a/llvm/lib/TargetParser/X86TargetParser.cpp b/llvm/lib/TargetParser/X86TargetParser.cpp --- a/llvm/lib/TargetParser/X86TargetParser.cpp +++ b/llvm/lib/TargetParser/X86TargetParser.cpp @@ -32,8 +32,14 @@ }; struct FeatureInfo { - StringLiteral Name; + StringLiteral NameWithPlus; FeatureBitset ImpliedFeatures; + + StringRef getName(bool WithPlus = false) const { + if (WithPlus) + return NameWithPlus; + return NameWithPlus.drop_front(); + } }; } // end anonymous namespace @@ -603,18 +609,13 @@ constexpr FeatureBitset ImpliedFeaturesAVXVNNI = FeatureAVX2; constexpr FeatureInfo FeatureInfos[X86::CPU_FEATURE_MAX] = { -#define X86_FEATURE(ENUM, STR) {{STR}, ImpliedFeatures##ENUM}, -#include "llvm/TargetParser/X86TargetParser.def" -}; - -constexpr FeatureInfo FeatureInfos_WithPLUS[X86::CPU_FEATURE_MAX] = { #define X86_FEATURE(ENUM, STR) {{"+" STR}, ImpliedFeatures##ENUM}, #include "llvm/TargetParser/X86TargetParser.def" }; void llvm::X86::getFeaturesForCPU(StringRef CPU, SmallVectorImpl &EnabledFeatures, - bool IfNeedPlus) { + bool NeedPlus) { auto I = llvm::find_if(Processors, [&](const ProcInfo &P) { return P.Name == CPU; }); assert(I != std::end(Processors) && "Processor not found!"); @@ -627,11 +628,8 @@ // Add the string version of all set bits. for (unsigned i = 0; i != CPU_FEATURE_MAX; ++i) - if (Bits[i] && !FeatureInfos[i].Name.empty() && - !FeatureInfos_WithPLUS[i].Name.empty()){ - EnabledFeatures.push_back(IfNeedPlus ? FeatureInfos_WithPLUS[i].Name - : FeatureInfos[i].Name); - } + if (Bits[i] && !FeatureInfos[i].getName(NeedPlus).empty()) + EnabledFeatures.push_back(FeatureInfos[i].getName(NeedPlus)); } // For each feature that is (transitively) implied by this feature, set it. @@ -668,8 +666,9 @@ void llvm::X86::updateImpliedFeatures( StringRef Feature, bool Enabled, StringMap &Features) { - auto I = llvm::find_if( - FeatureInfos, [&](const FeatureInfo &FI) { return FI.Name == Feature; }); + auto I = llvm::find_if(FeatureInfos, [&](const FeatureInfo &FI) { + return FI.getName() == Feature; + }); if (I == std::end(FeatureInfos)) { // FIXME: This shouldn't happen, but may not have all features in the table // yet. @@ -685,8 +684,8 @@ // Update the map entry for all implied features. for (unsigned i = 0; i != CPU_FEATURE_MAX; ++i) - if (ImpliedBits[i] && !FeatureInfos[i].Name.empty()) - Features[FeatureInfos[i].Name] = Enabled; + if (ImpliedBits[i] && !FeatureInfos[i].getName().empty()) + Features[FeatureInfos[i].getName()] = Enabled; } char llvm::X86::getCPUDispatchMangling(StringRef CPU) {