[llvm] 9a1d14a - [LTO] Don't make unnecessary copies of ImportIDTable (#106998)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 2 18:40:50 PDT 2024
Author: Kazu Hirata
Date: 2024-09-02T18:40:47-07:00
New Revision: 9a1d14a8d26778a5d2d24928ba11cc557c2df24b
URL: https://github.com/llvm/llvm-project/commit/9a1d14a8d26778a5d2d24928ba11cc557c2df24b
DIFF: https://github.com/llvm/llvm-project/commit/9a1d14a8d26778a5d2d24928ba11cc557c2df24b.diff
LOG: [LTO] Don't make unnecessary copies of ImportIDTable (#106998)
Without this patch, {ImportMapTy,SortedImportList}::{begin,end} make
unnecessary copies of ImportIDTable via:
map_iterator(Imports.begin(), IDs);
The second parameter, IDs, is passed by value, so we make a copy of
MapVector inside ImportIDTable every time we call begin and end.
These begin and end show up as time-consuming functions in the
performance profile.
This patch fixes the problem by passing IDs by reference with
std::cref.
While we are at it, this patch deletes the copy constructor and
assignment operator. I cannot think of any legitimate need reason to
make a copy of the deduplication table.
Added:
Modified:
llvm/include/llvm/Transforms/IPO/FunctionImport.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/Transforms/IPO/FunctionImport.h b/llvm/include/llvm/Transforms/IPO/FunctionImport.h
index b5b328d96b2737..0a6cc5951b706a 100644
--- a/llvm/include/llvm/Transforms/IPO/FunctionImport.h
+++ b/llvm/include/llvm/Transforms/IPO/FunctionImport.h
@@ -113,6 +113,13 @@ class FunctionImporter {
public:
using ImportIDTy = uint32_t;
+ ImportIDTable() = default;
+
+ // Something is wrong with the application logic if we need to make a copy
+ // of this and potentially make a fork.
+ ImportIDTable(const ImportIDTable &) = delete;
+ ImportIDTable &operator=(const ImportIDTable &) = delete;
+
// Create a pair of import IDs [Def, Decl] for a given pair of FromModule
// and GUID.
std::pair<ImportIDTy, ImportIDTy> createImportIDs(StringRef FromModule,
@@ -218,9 +225,10 @@ class FunctionImporter {
getImportType(StringRef FromModule, GlobalValue::GUID GUID) const;
// Iterate over the import list. The caller gets tuples of FromModule,
- // GUID, and ImportKind instead of import IDs.
- auto begin() const { return map_iterator(Imports.begin(), IDs); }
- auto end() const { return map_iterator(Imports.end(), IDs); }
+ // GUID, and ImportKind instead of import IDs. std::cref below prevents
+ // map_iterator from deep-copying IDs.
+ auto begin() const { return map_iterator(Imports.begin(), std::cref(IDs)); }
+ auto end() const { return map_iterator(Imports.end(), std::cref(IDs)); }
friend class SortedImportList;
@@ -251,9 +259,10 @@ class FunctionImporter {
}
// Iterate over the import list. The caller gets tuples of FromModule,
- // GUID, and ImportKind instead of import IDs.
- auto begin() const { return map_iterator(Imports.begin(), IDs); }
- auto end() const { return map_iterator(Imports.end(), IDs); }
+ // GUID, and ImportKind instead of import IDs. std::cref below prevents
+ // map_iterator from deep-copying IDs.
+ auto begin() const { return map_iterator(Imports.begin(), std::cref(IDs)); }
+ auto end() const { return map_iterator(Imports.end(), std::cref(IDs)); }
private:
const ImportIDTable &IDs;
More information about the llvm-commits
mailing list