diff --git a/llvm/lib/Analysis/TargetLibraryInfo.cpp b/llvm/lib/Analysis/TargetLibraryInfo.cpp --- a/llvm/lib/Analysis/TargetLibraryInfo.cpp +++ b/llvm/lib/Analysis/TargetLibraryInfo.cpp @@ -11,6 +11,7 @@ //===----------------------------------------------------------------------===// #include "llvm/Analysis/TargetLibraryInfo.h" +#include "llvm/ADT/DenseMap.h" #include "llvm/IR/Constants.h" #include "llvm/InitializePasses.h" #include "llvm/Support/CommandLine.h" @@ -945,11 +946,18 @@ if (funcName.empty()) return false; - const auto *Start = std::begin(StandardNames); - const auto *End = std::end(StandardNames); - const auto *I = std::lower_bound(Start, End, funcName); - if (I != End && *I == funcName) { - F = (LibFunc)(I - Start); + static bool IsInitialized = false; + static DenseMap Indices; + if (!IsInitialized) { + unsigned Idx = 0; + Indices.reserve(LibFunc::NumLibFuncs); + for (const auto &Func : StandardNames) + Indices[Func] = Idx++; + IsInitialized = true; + } + + if (auto Loc = Indices.find(funcName); Loc != Indices.end()) { + F = (LibFunc)Loc->second; return true; } return false;