From 5e07fb3545b145b3da05433c66e32afb697d5c24 Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Sat, 1 Oct 2016 03:10:48 +0000 Subject: [PATCH] Use StringRef in TLI instead of raw pointer (NFC) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@283005 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Analysis/TargetLibraryInfo.h | 6 ++--- lib/Analysis/TargetLibraryInfo.cpp | 28 +++++++++++------------ 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/include/llvm/Analysis/TargetLibraryInfo.h b/include/llvm/Analysis/TargetLibraryInfo.h index 41e4241ec73..b555343b35a 100644 --- a/include/llvm/Analysis/TargetLibraryInfo.h +++ b/include/llvm/Analysis/TargetLibraryInfo.h @@ -25,8 +25,8 @@ template class ArrayRef; /// Function 'VectorFnName' is equivalent to 'ScalarFnName' vectorized /// by a factor 'VectorizationFactor'. struct VecDesc { - const char *ScalarFnName; - const char *VectorFnName; + StringRef ScalarFnName; + StringRef VectorFnName; unsigned VectorizationFactor; }; @@ -50,7 +50,7 @@ class TargetLibraryInfoImpl { unsigned char AvailableArray[(LibFunc::NumLibFuncs+3)/4]; llvm::DenseMap CustomNames; - static const char *const StandardNames[LibFunc::NumLibFuncs]; + static StringRef const StandardNames[LibFunc::NumLibFuncs]; enum AvailabilityState { StandardName = 3, // (memset to all ones) diff --git a/lib/Analysis/TargetLibraryInfo.cpp b/lib/Analysis/TargetLibraryInfo.cpp index 988ccaa0a4e..7df15071053 100644 --- a/lib/Analysis/TargetLibraryInfo.cpp +++ b/lib/Analysis/TargetLibraryInfo.cpp @@ -27,7 +27,7 @@ static cl::opt ClVectorLibrary( "Intel SVML library"), clEnumValEnd)); -const char *const TargetLibraryInfoImpl::StandardNames[LibFunc::NumLibFuncs] = { +StringRef const TargetLibraryInfoImpl::StandardNames[LibFunc::NumLibFuncs] = { #define TLI_DEFINE_STRING #include "llvm/Analysis/TargetLibraryInfo.def" }; @@ -54,11 +54,11 @@ static bool hasSinCosPiStret(const Triple &T) { /// specified target triple. This should be carefully written so that a missing /// target triple gets a sane set of defaults. static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T, - ArrayRef StandardNames) { + ArrayRef StandardNames) { // Verify that the StandardNames array is in alphabetical order. assert(std::is_sorted(StandardNames.begin(), StandardNames.end(), - [](const char *LHS, const char *RHS) { - return strcmp(LHS, RHS) < 0; + [](StringRef LHS, StringRef RHS) { + return LHS < RHS; }) && "TargetLibraryInfoImpl function names must be sorted"); @@ -472,16 +472,16 @@ static StringRef sanitizeFunctionName(StringRef funcName) { bool TargetLibraryInfoImpl::getLibFunc(StringRef funcName, LibFunc::Func &F) const { - const char *const *Start = &StandardNames[0]; - const char *const *End = &StandardNames[LibFunc::NumLibFuncs]; + StringRef const *Start = &StandardNames[0]; + StringRef const *End = &StandardNames[LibFunc::NumLibFuncs]; funcName = sanitizeFunctionName(funcName); if (funcName.empty()) return false; - const char *const *I = std::lower_bound( - Start, End, funcName, [](const char *LHS, StringRef RHS) { - return std::strncmp(LHS, RHS.data(), RHS.size()) < 0; + StringRef const *I = std::lower_bound( + Start, End, funcName, [](StringRef LHS, StringRef RHS) { + return LHS < RHS; }); if (I != End && *I == funcName) { F = (LibFunc::Func)(I - Start); @@ -1011,21 +1011,19 @@ void TargetLibraryInfoImpl::disableAllFunctions() { } static bool compareByScalarFnName(const VecDesc &LHS, const VecDesc &RHS) { - return std::strncmp(LHS.ScalarFnName, RHS.ScalarFnName, - std::strlen(RHS.ScalarFnName)) < 0; + return LHS.ScalarFnName < RHS.ScalarFnName; } static bool compareByVectorFnName(const VecDesc &LHS, const VecDesc &RHS) { - return std::strncmp(LHS.VectorFnName, RHS.VectorFnName, - std::strlen(RHS.VectorFnName)) < 0; + return LHS.VectorFnName < RHS.VectorFnName; } static bool compareWithScalarFnName(const VecDesc &LHS, StringRef S) { - return std::strncmp(LHS.ScalarFnName, S.data(), S.size()) < 0; + return LHS.ScalarFnName < S; } static bool compareWithVectorFnName(const VecDesc &LHS, StringRef S) { - return std::strncmp(LHS.VectorFnName, S.data(), S.size()) < 0; + return LHS.VectorFnName < S; } void TargetLibraryInfoImpl::addVectorizableFunctions(ArrayRef Fns) {