aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKazu Hirata <kazu@google.com>2024-11-12 10:09:28 -0800
committerGitHub <noreply@github.com>2024-11-12 10:09:28 -0800
commitc784d321d90a3609caeacfb525b7ccadd41a5195 (patch)
treee811a5d6933afccf2a67d82c97e2f08a267864c6
parentdfb864a735da9153ab8a4bb107d4b01ac81ee364 (diff)
downloadllvm-c784d321d90a3609caeacfb525b7ccadd41a5195.zip
llvm-c784d321d90a3609caeacfb525b7ccadd41a5195.tar.gz
llvm-c784d321d90a3609caeacfb525b7ccadd41a5195.tar.bz2
[ThinLTO] Use heterogenous lookups with std::map (NFC) (#115812)
Heterogenous lookups allow us to call find with StringRef, avoiding a temporary heap allocation of std::string.
-rw-r--r--llvm/include/llvm/IR/ModuleSummaryIndex.h20
-rw-r--r--llvm/lib/Bitcode/Reader/BitcodeReader.cpp6
-rw-r--r--llvm/lib/Transforms/IPO/LowerTypeTests.cpp5
3 files changed, 20 insertions, 11 deletions
diff --git a/llvm/include/llvm/IR/ModuleSummaryIndex.h b/llvm/include/llvm/IR/ModuleSummaryIndex.h
index 1cfe7c1..2ff5b4a 100644
--- a/llvm/include/llvm/IR/ModuleSummaryIndex.h
+++ b/llvm/include/llvm/IR/ModuleSummaryIndex.h
@@ -1399,8 +1399,8 @@ private:
/// True if some of the FunctionSummary contains a ParamAccess.
bool HasParamAccess = false;
- std::set<std::string> CfiFunctionDefs;
- std::set<std::string> CfiFunctionDecls;
+ std::set<std::string, std::less<>> CfiFunctionDefs;
+ std::set<std::string, std::less<>> CfiFunctionDecls;
// Used in cases where we want to record the name of a global, but
// don't have the string owned elsewhere (e.g. the Strtab on a module).
@@ -1647,11 +1647,19 @@ public:
return I == OidGuidMap.end() ? 0 : I->second;
}
- std::set<std::string> &cfiFunctionDefs() { return CfiFunctionDefs; }
- const std::set<std::string> &cfiFunctionDefs() const { return CfiFunctionDefs; }
+ std::set<std::string, std::less<>> &cfiFunctionDefs() {
+ return CfiFunctionDefs;
+ }
+ const std::set<std::string, std::less<>> &cfiFunctionDefs() const {
+ return CfiFunctionDefs;
+ }
- std::set<std::string> &cfiFunctionDecls() { return CfiFunctionDecls; }
- const std::set<std::string> &cfiFunctionDecls() const { return CfiFunctionDecls; }
+ std::set<std::string, std::less<>> &cfiFunctionDecls() {
+ return CfiFunctionDecls;
+ }
+ const std::set<std::string, std::less<>> &cfiFunctionDecls() const {
+ return CfiFunctionDecls;
+ }
/// Add a global value summary for a value.
void addGlobalValueSummary(const GlobalValue &GV,
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 3e82aa7..91b1917 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -7959,7 +7959,8 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) {
break;
case bitc::FS_CFI_FUNCTION_DEFS: {
- std::set<std::string> &CfiFunctionDefs = TheIndex.cfiFunctionDefs();
+ std::set<std::string, std::less<>> &CfiFunctionDefs =
+ TheIndex.cfiFunctionDefs();
for (unsigned I = 0; I != Record.size(); I += 2)
CfiFunctionDefs.insert(
{Strtab.data() + Record[I], static_cast<size_t>(Record[I + 1])});
@@ -7967,7 +7968,8 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) {
}
case bitc::FS_CFI_FUNCTION_DECLS: {
- std::set<std::string> &CfiFunctionDecls = TheIndex.cfiFunctionDecls();
+ std::set<std::string, std::less<>> &CfiFunctionDecls =
+ TheIndex.cfiFunctionDecls();
for (unsigned I = 0; I != Record.size(); I += 2)
CfiFunctionDecls.insert(
{Strtab.data() + Record[I], static_cast<size_t>(Record[I + 1])});
diff --git a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
index 70f8389..bfcf491 100644
--- a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
+++ b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
@@ -2037,10 +2037,9 @@ bool LowerTypeTestsModule::lower() {
// have the same name, but it's not the one we are looking for.
if (F.hasLocalLinkage())
continue;
- if (ImportSummary->cfiFunctionDefs().count(std::string(F.getName())))
+ if (ImportSummary->cfiFunctionDefs().count(F.getName()))
Defs.push_back(&F);
- else if (ImportSummary->cfiFunctionDecls().count(
- std::string(F.getName())))
+ else if (ImportSummary->cfiFunctionDecls().count(F.getName()))
Decls.push_back(&F);
}