[llvm] 991154d - [LTO] Use .at instead of .lookup to avoid copies. (NFC) (#117888)

via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 27 09:41:33 PST 2024


Author: Krzysztof Pszeniczny
Date: 2024-11-27T18:41:29+01:00
New Revision: 991154d0fbc951e2b999589a95dabc7deff7acd1

URL: https://github.com/llvm/llvm-project/commit/991154d0fbc951e2b999589a95dabc7deff7acd1
DIFF: https://github.com/llvm/llvm-project/commit/991154d0fbc951e2b999589a95dabc7deff7acd1.diff

LOG: [LTO] Use .at instead of .lookup to avoid copies. (NFC) (#117888)

`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 then destroying dense maps here is responsible for 60% of
the time spent in LTO indexing in a large internal build.

Added: 
    

Modified: 
    llvm/lib/Transforms/IPO/FunctionImport.cpp

Removed: 
    


################################################################################
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