[clang] [llvm] [LTO] Reduce memory usage for import lists (PR #106772)
Mingming Liu via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 30 15:00:12 PDT 2024
================
@@ -215,13 +215,49 @@ class FunctionImporter {
SmallVector<StringRef, 0> getSourceModules() const;
std::optional<GlobalValueSummary::ImportKind>
- getImportType(const FunctionsToImportTy &GUIDToImportType,
- GlobalValue::GUID GUID) const;
+ 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); }
+
+ friend class SortedImportList;
+
+ private:
+ ImportIDTable &IDs;
+ DenseSet<ImportIDTable::ImportIDTy> Imports;
+ };
+
+ // A read-only copy of ImportMapTy with its contents sorted according to the
+ // given comparison function.
+ class SortedImportList {
+ public:
+ SortedImportList(const ImportMapTy &ImportMap,
+ llvm::function_ref<
+ bool(const std::pair<StringRef, GlobalValue::GUID> &,
+ const std::pair<StringRef, GlobalValue::GUID> &)>
+ Comp)
+ : IDs(ImportMap.IDs), Imports(iterator_range(ImportMap.Imports)) {
+ llvm::sort(Imports, [&](ImportIDTable::ImportIDTy L,
----------------
minglotus-6 wrote:
I suggest using `llvm::stable_sort` to make it explicit it's a stable sort (i.e., even if the existing implementation is stable already)
https://github.com/llvm/llvm-project/pull/106772
More information about the cfe-commits
mailing list