diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp --- a/clang/lib/Basic/Targets/X86.cpp +++ b/clang/lib/Basic/Targets/X86.cpp @@ -18,7 +18,6 @@ #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/Support/X86TargetParser.h" -#include namespace clang { namespace targets { @@ -1058,34 +1057,6 @@ // correct, so it asserts if the value is out of range. } -static unsigned getFeaturePriority(llvm::X86::ProcessorFeatures Feat) { -#ifndef NDEBUG - // Check that priorities are set properly in the .def file. We expect that - // "compat" features are assigned non-duplicate consecutive priorities - // starting from zero (0, 1, ..., num_features - 1). -#define X86_FEATURE_COMPAT(ENUM, STR, PRIORITY) PRIORITY, - unsigned Priorities[] = { -#include "llvm/Support/X86TargetParser.def" - std::numeric_limits::max() // Need to consume last comma. - }; - std::array HelperList; - std::iota(HelperList.begin(), HelperList.end(), 0); - assert(std::is_permutation(HelperList.begin(), HelperList.end(), - std::begin(Priorities), - std::prev(std::end(Priorities))) && - "Priorities don't form consecutive range!"); -#endif - - switch (Feat) { -#define X86_FEATURE_COMPAT(ENUM, STR, PRIORITY) \ - case llvm::X86::FEATURE_##ENUM: \ - return PRIORITY; -#include "llvm/Support/X86TargetParser.def" - default: - llvm_unreachable("No Feature Priority for non-CPUSupports Features"); - } -} - unsigned X86TargetInfo::multiVersionSortPriority(StringRef Name) const { // Valid CPUs have a 'key feature' that compares just better than its key // feature. diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -12404,24 +12404,8 @@ return EmitX86CpuSupports(FeatureStr); } -uint64_t -CodeGenFunction::GetX86CpuSupportsMask(ArrayRef FeatureStrs) { - // Processor features and mapping to processor feature value. - uint64_t FeaturesMask = 0; - for (const StringRef &FeatureStr : FeatureStrs) { - unsigned Feature = - StringSwitch(FeatureStr) -#define X86_FEATURE_COMPAT(ENUM, STR, PRIORITY) \ - .Case(STR, llvm::X86::FEATURE_##ENUM) -#include "llvm/Support/X86TargetParser.def" - ; - FeaturesMask |= (1ULL << Feature); - } - return FeaturesMask; -} - Value *CodeGenFunction::EmitX86CpuSupports(ArrayRef FeatureStrs) { - return EmitX86CpuSupports(GetX86CpuSupportsMask(FeatureStrs)); + return EmitX86CpuSupports(llvm::X86::getCpuSupportsMask(FeatureStrs)); } llvm::Value *CodeGenFunction::EmitX86CpuSupports(uint64_t FeaturesMask) { diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -4728,8 +4728,6 @@ void EmitMultiVersionResolver(llvm::Function *Resolver, ArrayRef Options); - static uint64_t GetX86CpuSupportsMask(ArrayRef FeatureStrs); - private: QualType getVarArgType(const Expr *Arg); diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -63,6 +63,7 @@ #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MD5.h" #include "llvm/Support/TimeProfiler.h" +#include "llvm/Support/X86TargetParser.h" using namespace clang; using namespace CodeGen; @@ -3396,8 +3397,8 @@ llvm::stable_sort( Options, [](const CodeGenFunction::MultiVersionResolverOption &LHS, const CodeGenFunction::MultiVersionResolverOption &RHS) { - return CodeGenFunction::GetX86CpuSupportsMask(LHS.Conditions.Features) > - CodeGenFunction::GetX86CpuSupportsMask(RHS.Conditions.Features); + return llvm::X86::getCpuSupportsMask(LHS.Conditions.Features) > + llvm::X86::getCpuSupportsMask(RHS.Conditions.Features); }); // If the list contains multiple 'default' versions, such as when it contains @@ -3405,7 +3406,7 @@ // always run on at least a 'pentium'). We do this by deleting the 'least // advanced' (read, lowest mangling letter). while (Options.size() > 1 && - CodeGenFunction::GetX86CpuSupportsMask( + llvm::X86::getCpuSupportsMask( (Options.end() - 2)->Conditions.Features) == 0) { StringRef LHSName = (Options.end() - 2)->Function->getName(); StringRef RHSName = (Options.end() - 1)->Function->getName(); diff --git a/llvm/include/llvm/Support/X86TargetParser.h b/llvm/include/llvm/Support/X86TargetParser.h --- a/llvm/include/llvm/Support/X86TargetParser.h +++ b/llvm/include/llvm/Support/X86TargetParser.h @@ -13,6 +13,7 @@ #ifndef LLVM_SUPPORT_X86TARGETPARSER_H #define LLVM_SUPPORT_X86TARGETPARSER_H +#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringMap.h" @@ -154,6 +155,9 @@ void updateImpliedFeatures(StringRef Feature, bool Enabled, StringMap &Features); +uint64_t getCpuSupportsMask(ArrayRef FeatureStrs); +unsigned getFeaturePriority(ProcessorFeatures Feat); + } // namespace X86 } // namespace llvm diff --git a/llvm/lib/Support/X86TargetParser.cpp b/llvm/lib/Support/X86TargetParser.cpp --- a/llvm/lib/Support/X86TargetParser.cpp +++ b/llvm/lib/Support/X86TargetParser.cpp @@ -11,7 +11,9 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/X86TargetParser.h" +#include "llvm/ADT/StringSwitch.h" #include "llvm/ADT/Triple.h" +#include using namespace llvm; using namespace llvm::X86; @@ -662,3 +664,45 @@ if (ImpliedBits[i] && !FeatureInfos[i].Name.empty()) Features[FeatureInfos[i].Name] = Enabled; } + +uint64_t llvm::X86::getCpuSupportsMask(ArrayRef FeatureStrs) { + // Processor features and mapping to processor feature value. + uint64_t FeaturesMask = 0; + for (const StringRef &FeatureStr : FeatureStrs) { + unsigned Feature = StringSwitch(FeatureStr) +#define X86_FEATURE_COMPAT(ENUM, STR, PRIORITY) \ + .Case(STR, llvm::X86::FEATURE_##ENUM) +#include "llvm/Support/X86TargetParser.def" + ; + FeaturesMask |= (1ULL << Feature); + } + return FeaturesMask; +} + +unsigned llvm::X86::getFeaturePriority(ProcessorFeatures Feat) { +#ifndef NDEBUG + // Check that priorities are set properly in the .def file. We expect that + // "compat" features are assigned non-duplicate consecutive priorities + // starting from zero (0, 1, ..., num_features - 1). +#define X86_FEATURE_COMPAT(ENUM, STR, PRIORITY) PRIORITY, + unsigned Priorities[] = { +#include "llvm/Support/X86TargetParser.def" + std::numeric_limits::max() // Need to consume last comma. + }; + std::array HelperList; + std::iota(HelperList.begin(), HelperList.end(), 0); + assert(std::is_permutation(HelperList.begin(), HelperList.end(), + std::begin(Priorities), + std::prev(std::end(Priorities))) && + "Priorities don't form consecutive range!"); +#endif + + switch (Feat) { +#define X86_FEATURE_COMPAT(ENUM, STR, PRIORITY) \ + case X86::FEATURE_##ENUM: \ + return PRIORITY; +#include "llvm/Support/X86TargetParser.def" + default: + llvm_unreachable("No Feature Priority for non-CPUSupports Features"); + } +}