[X86] Rename X86::getImpliedFeatures to X86::updateImpliedFeatures and pass clang's StringMap directly to it.

No point in building a vector of StringRefs for clang to apply to the
StringMap. Just pass the StringMap and modify it directly.
This commit is contained in:
Craig Topper 2020-08-06 00:13:40 -07:00
parent 4a8e4b5c74
commit 504a197fe5
3 changed files with 14 additions and 21 deletions

View File

@ -159,11 +159,7 @@ void X86TargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features,
} }
Features[Name] = Enabled; Features[Name] = Enabled;
llvm::X86::updateImpliedFeatures(Name, Enabled, Features);
SmallVector<StringRef, 8> ImpliedFeatures;
llvm::X86::getImpliedFeatures(Name, Enabled, ImpliedFeatures);
for (const auto &F : ImpliedFeatures)
Features[F] = Enabled;
} }
/// handleTargetFeatures - Perform initialization based on the user /// handleTargetFeatures - Perform initialization based on the user

View File

@ -14,6 +14,7 @@
#define LLVM_SUPPORT_X86TARGETPARSERCOMMON_H #define LLVM_SUPPORT_X86TARGETPARSERCOMMON_H
#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringMap.h"
namespace llvm { namespace llvm {
class StringRef; class StringRef;
@ -137,10 +138,10 @@ ProcessorFeatures getKeyFeature(CPUKind Kind);
/// Fill in the features that \p CPU supports into \p Features. /// Fill in the features that \p CPU supports into \p Features.
void getFeaturesForCPU(StringRef CPU, SmallVectorImpl<StringRef> &Features); void getFeaturesForCPU(StringRef CPU, SmallVectorImpl<StringRef> &Features);
/// Fill \p Features with the features that are implied to be enabled/disabled /// Set or clear entries in \p Features that are implied to be enabled/disabled
/// by the provided \p Feature. /// by the provided \p Feature.
void getImpliedFeatures(StringRef Feature, bool Enabled, void updateImpliedFeatures(StringRef Feature, bool Enabled,
SmallVectorImpl<StringRef> &Features); StringMap<bool> &Features);
} // namespace X86 } // namespace X86
} // namespace llvm } // namespace llvm

View File

@ -536,14 +536,6 @@ static constexpr FeatureInfo FeatureInfos[X86::CPU_FEATURE_MAX] = {
#include "llvm/Support/X86TargetParser.def" #include "llvm/Support/X86TargetParser.def"
}; };
// Convert the set bits in FeatureBitset to a list of strings.
static void getFeatureBitsAsStrings(const FeatureBitset &Bits,
SmallVectorImpl<StringRef> &Features) {
for (unsigned i = 0; i != CPU_FEATURE_MAX; ++i)
if (Bits[i] && !FeatureInfos[i].Name.empty())
Features.push_back(FeatureInfos[i].Name);
}
void llvm::X86::getFeaturesForCPU(StringRef CPU, void llvm::X86::getFeaturesForCPU(StringRef CPU,
SmallVectorImpl<StringRef> &EnabledFeatures) { SmallVectorImpl<StringRef> &EnabledFeatures) {
auto I = llvm::find_if(Processors, auto I = llvm::find_if(Processors,
@ -557,7 +549,9 @@ void llvm::X86::getFeaturesForCPU(StringRef CPU,
Bits &= ~Feature64BIT; Bits &= ~Feature64BIT;
// Add the string version of all set bits. // Add the string version of all set bits.
getFeatureBitsAsStrings(Bits, EnabledFeatures); for (unsigned i = 0; i != CPU_FEATURE_MAX; ++i)
if (Bits[i] && !FeatureInfos[i].Name.empty())
EnabledFeatures.push_back(FeatureInfos[i].Name);
} }
// For each feature that is (transitively) implied by this feature, set it. // For each feature that is (transitively) implied by this feature, set it.
@ -591,9 +585,9 @@ static void getImpliedDisabledFeatures(FeatureBitset &Bits, unsigned Value) {
} while (Prev != Bits); } while (Prev != Bits);
} }
void llvm::X86::getImpliedFeatures( void llvm::X86::updateImpliedFeatures(
StringRef Feature, bool Enabled, StringRef Feature, bool Enabled,
SmallVectorImpl<StringRef> &ImpliedFeatures) { StringMap<bool> &Features) {
auto I = llvm::find_if( auto I = llvm::find_if(
FeatureInfos, [&](const FeatureInfo &FI) { return FI.Name == Feature; }); FeatureInfos, [&](const FeatureInfo &FI) { return FI.Name == Feature; });
if (I == std::end(FeatureInfos)) { if (I == std::end(FeatureInfos)) {
@ -609,6 +603,8 @@ void llvm::X86::getImpliedFeatures(
getImpliedDisabledFeatures(ImpliedBits, getImpliedDisabledFeatures(ImpliedBits,
std::distance(std::begin(FeatureInfos), I)); std::distance(std::begin(FeatureInfos), I));
// Convert all the found bits into strings. // Update the map entry for all implied features.
getFeatureBitsAsStrings(ImpliedBits, ImpliedFeatures); for (unsigned i = 0; i != CPU_FEATURE_MAX; ++i)
if (ImpliedBits[i] && !FeatureInfos[i].Name.empty())
Features[FeatureInfos[i].Name] = Enabled;
} }