[PATCH] D157951: [NFC][TLI] Replace std::lower_bound call in getLibFunc with DenseMap lookup
Dhruv Chawla via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 15 05:26:14 PDT 2023
0xdc03 updated this revision to Diff 550281.
0xdc03 added a comment.
- Change map from unsigned to LibFunc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D157951/new/
https://reviews.llvm.org/D157951
Files:
llvm/lib/Analysis/TargetLibraryInfo.cpp
Index: llvm/lib/Analysis/TargetLibraryInfo.cpp
===================================================================
--- llvm/lib/Analysis/TargetLibraryInfo.cpp
+++ 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"
@@ -940,16 +941,26 @@
return GlobalValue::dropLLVMManglingEscape(funcName);
}
+static DenseMap<StringRef, LibFunc>
+buildIndexMap(const StringLiteral (&StandardNames)[LibFunc::NumLibFuncs]) {
+ DenseMap<StringRef, LibFunc> Indices;
+ unsigned Idx = 0;
+ Indices.reserve(LibFunc::NumLibFuncs);
+ for (const auto &Func : StandardNames)
+ Indices[Func] = static_cast<LibFunc>(Idx++);
+ return Indices;
+}
+
bool TargetLibraryInfoImpl::getLibFunc(StringRef funcName, LibFunc &F) const {
funcName = sanitizeFunctionName(funcName);
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 const DenseMap<StringRef, LibFunc> Indices =
+ buildIndexMap(StandardNames);
+
+ if (auto Loc = Indices.find(funcName); Loc != Indices.end()) {
+ F = Loc->second;
return true;
}
return false;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157951.550281.patch
Type: text/x-patch
Size: 1525 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230815/b67760a6/attachment.bin>
More information about the llvm-commits
mailing list