[llvm] [LTO] Use .at instead of .lookup to avoid copies. (PR #117888)
Krzysztof Pszeniczny via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 27 06:35:02 PST 2024
https://github.com/amharc updated https://github.com/llvm/llvm-project/pull/117888
>From 8ee3dc2b3aefc9fd92dea25d54f0b1ad7362d602 Mon Sep 17 00:00:00 2001
From: Krzysztof Pszeniczny <kpszeniczny at google.com>
Date: Wed, 27 Nov 2024 15:11:28 +0100
Subject: [PATCH] [LTO] Use .at instead of .lookup to avoid copies. (NFC)
`DenseMap::lookup` returns by value (because it default-creates the
returned value if the key isn't present in the map), which means that we
do a lot of copying here. Since we assert that something is present in
the returned value two lines below this call, it's safe to use `.at`
here instead.
Copying and destroying the dense maps here is responsible for 60% of the
time spent in LTO indexing in a large internal build.
---
llvm/lib/Transforms/IPO/FunctionImport.cpp | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/llvm/lib/Transforms/IPO/FunctionImport.cpp b/llvm/lib/Transforms/IPO/FunctionImport.cpp
index fee27f72f208b0..9cca3cdc761451 100644
--- a/llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionImport.cpp
@@ -1540,8 +1540,7 @@ void llvm::gatherImportedSummariesForModule(
auto &SummariesForIndex =
LookupOrCreate(ModuleToSummariesForIndex, FromModule);
- const auto &DefinedGVSummaries =
- ModuleToDefinedGVSummaries.lookup(FromModule);
+ const auto &DefinedGVSummaries = ModuleToDefinedGVSummaries.at(FromModule);
const auto &DS = DefinedGVSummaries.find(GUID);
assert(DS != DefinedGVSummaries.end() &&
"Expected a defined summary for imported global value");
More information about the llvm-commits
mailing list