Skip to content

Commit 9a1d14a

Browse files
[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.
1 parent ba3c1ed commit 9a1d14a

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

llvm/include/llvm/Transforms/IPO/FunctionImport.h

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ class FunctionImporter {
113113
public:
114114
using ImportIDTy = uint32_t;
115115

116+
ImportIDTable() = default;
117+
118+
// Something is wrong with the application logic if we need to make a copy
119+
// of this and potentially make a fork.
120+
ImportIDTable(const ImportIDTable &) = delete;
121+
ImportIDTable &operator=(const ImportIDTable &) = delete;
122+
116123
// Create a pair of import IDs [Def, Decl] for a given pair of FromModule
117124
// and GUID.
118125
std::pair<ImportIDTy, ImportIDTy> createImportIDs(StringRef FromModule,
@@ -218,9 +225,10 @@ class FunctionImporter {
218225
getImportType(StringRef FromModule, GlobalValue::GUID GUID) const;
219226

220227
// Iterate over the import list. The caller gets tuples of FromModule,
221-
// GUID, and ImportKind instead of import IDs.
222-
auto begin() const { return map_iterator(Imports.begin(), IDs); }
223-
auto end() const { return map_iterator(Imports.end(), IDs); }
228+
// GUID, and ImportKind instead of import IDs. std::cref below prevents
229+
// map_iterator from deep-copying IDs.
230+
auto begin() const { return map_iterator(Imports.begin(), std::cref(IDs)); }
231+
auto end() const { return map_iterator(Imports.end(), std::cref(IDs)); }
224232

225233
friend class SortedImportList;
226234

@@ -251,9 +259,10 @@ class FunctionImporter {
251259
}
252260

253261
// Iterate over the import list. The caller gets tuples of FromModule,
254-
// GUID, and ImportKind instead of import IDs.
255-
auto begin() const { return map_iterator(Imports.begin(), IDs); }
256-
auto end() const { return map_iterator(Imports.end(), IDs); }
262+
// GUID, and ImportKind instead of import IDs. std::cref below prevents
263+
// map_iterator from deep-copying IDs.
264+
auto begin() const { return map_iterator(Imports.begin(), std::cref(IDs)); }
265+
auto end() const { return map_iterator(Imports.end(), std::cref(IDs)); }
257266

258267
private:
259268
const ImportIDTable &IDs;

0 commit comments

Comments
 (0)