Skip to content

Commit c784d32

Browse files
[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.
1 parent dfb864a commit c784d32

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

llvm/include/llvm/IR/ModuleSummaryIndex.h

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,8 +1399,8 @@ class ModuleSummaryIndex {
13991399
/// True if some of the FunctionSummary contains a ParamAccess.
14001400
bool HasParamAccess = false;
14011401

1402-
std::set<std::string> CfiFunctionDefs;
1403-
std::set<std::string> CfiFunctionDecls;
1402+
std::set<std::string, std::less<>> CfiFunctionDefs;
1403+
std::set<std::string, std::less<>> CfiFunctionDecls;
14041404

14051405
// Used in cases where we want to record the name of a global, but
14061406
// don't have the string owned elsewhere (e.g. the Strtab on a module).
@@ -1647,11 +1647,19 @@ class ModuleSummaryIndex {
16471647
return I == OidGuidMap.end() ? 0 : I->second;
16481648
}
16491649

1650-
std::set<std::string> &cfiFunctionDefs() { return CfiFunctionDefs; }
1651-
const std::set<std::string> &cfiFunctionDefs() const { return CfiFunctionDefs; }
1650+
std::set<std::string, std::less<>> &cfiFunctionDefs() {
1651+
return CfiFunctionDefs;
1652+
}
1653+
const std::set<std::string, std::less<>> &cfiFunctionDefs() const {
1654+
return CfiFunctionDefs;
1655+
}
16521656

1653-
std::set<std::string> &cfiFunctionDecls() { return CfiFunctionDecls; }
1654-
const std::set<std::string> &cfiFunctionDecls() const { return CfiFunctionDecls; }
1657+
std::set<std::string, std::less<>> &cfiFunctionDecls() {
1658+
return CfiFunctionDecls;
1659+
}
1660+
const std::set<std::string, std::less<>> &cfiFunctionDecls() const {
1661+
return CfiFunctionDecls;
1662+
}
16551663

16561664
/// Add a global value summary for a value.
16571665
void addGlobalValueSummary(const GlobalValue &GV,

llvm/lib/Bitcode/Reader/BitcodeReader.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7959,15 +7959,17 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) {
79597959
break;
79607960

79617961
case bitc::FS_CFI_FUNCTION_DEFS: {
7962-
std::set<std::string> &CfiFunctionDefs = TheIndex.cfiFunctionDefs();
7962+
std::set<std::string, std::less<>> &CfiFunctionDefs =
7963+
TheIndex.cfiFunctionDefs();
79637964
for (unsigned I = 0; I != Record.size(); I += 2)
79647965
CfiFunctionDefs.insert(
79657966
{Strtab.data() + Record[I], static_cast<size_t>(Record[I + 1])});
79667967
break;
79677968
}
79687969

79697970
case bitc::FS_CFI_FUNCTION_DECLS: {
7970-
std::set<std::string> &CfiFunctionDecls = TheIndex.cfiFunctionDecls();
7971+
std::set<std::string, std::less<>> &CfiFunctionDecls =
7972+
TheIndex.cfiFunctionDecls();
79717973
for (unsigned I = 0; I != Record.size(); I += 2)
79727974
CfiFunctionDecls.insert(
79737975
{Strtab.data() + Record[I], static_cast<size_t>(Record[I + 1])});

llvm/lib/Transforms/IPO/LowerTypeTests.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2037,10 +2037,9 @@ bool LowerTypeTestsModule::lower() {
20372037
// have the same name, but it's not the one we are looking for.
20382038
if (F.hasLocalLinkage())
20392039
continue;
2040-
if (ImportSummary->cfiFunctionDefs().count(std::string(F.getName())))
2040+
if (ImportSummary->cfiFunctionDefs().count(F.getName()))
20412041
Defs.push_back(&F);
2042-
else if (ImportSummary->cfiFunctionDecls().count(
2043-
std::string(F.getName())))
2042+
else if (ImportSummary->cfiFunctionDecls().count(F.getName()))
20442043
Decls.push_back(&F);
20452044
}
20462045

0 commit comments

Comments
 (0)