|
11 | 11 | //===----------------------------------------------------------------------===//
|
12 | 12 |
|
13 | 13 | #include "llvm/Analysis/TargetLibraryInfo.h"
|
| 14 | +#include "llvm/ADT/DenseMap.h" |
14 | 15 | #include "llvm/IR/Constants.h"
|
15 | 16 | #include "llvm/InitializePasses.h"
|
16 | 17 | #include "llvm/Support/CommandLine.h"
|
@@ -940,16 +941,26 @@ static StringRef sanitizeFunctionName(StringRef funcName) {
|
940 | 941 | return GlobalValue::dropLLVMManglingEscape(funcName);
|
941 | 942 | }
|
942 | 943 |
|
| 944 | +static DenseMap<StringRef, LibFunc> |
| 945 | +buildIndexMap(ArrayRef<StringLiteral> StandardNames) { |
| 946 | + DenseMap<StringRef, LibFunc> Indices; |
| 947 | + unsigned Idx = 0; |
| 948 | + Indices.reserve(LibFunc::NumLibFuncs); |
| 949 | + for (const auto &Func : StandardNames) |
| 950 | + Indices[Func] = static_cast<LibFunc>(Idx++); |
| 951 | + return Indices; |
| 952 | +} |
| 953 | + |
943 | 954 | bool TargetLibraryInfoImpl::getLibFunc(StringRef funcName, LibFunc &F) const {
|
944 | 955 | funcName = sanitizeFunctionName(funcName);
|
945 | 956 | if (funcName.empty())
|
946 | 957 | return false;
|
947 | 958 |
|
948 |
| - const auto *Start = std::begin(StandardNames); |
949 |
| - const auto *End = std::end(StandardNames); |
950 |
| - const auto *I = std::lower_bound(Start, End, funcName); |
951 |
| - if (I != End && *I == funcName) { |
952 |
| - F = (LibFunc)(I - Start); |
| 959 | + static const DenseMap<StringRef, LibFunc> Indices = |
| 960 | + buildIndexMap(StandardNames); |
| 961 | + |
| 962 | + if (auto Loc = Indices.find(funcName); Loc != Indices.end()) { |
| 963 | + F = Loc->second; |
953 | 964 | return true;
|
954 | 965 | }
|
955 | 966 | return false;
|
|
0 commit comments