Skip to content

[LTO] Don't make unnecessary copies of ImportIDTable #106998

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions llvm/include/llvm/Transforms/IPO/FunctionImport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
Loading