[llvm] [LTO] Introduce getSourceModules (NFC) (PR #105955)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 24 11:58:02 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
This patch introduces getSourceModules to compute the list of source
modules in the ascending alphabetical order. The new function is
intended to hide implementation details of ImportMapTy while
simplifying FunctionImporter::importFunctions a little bit.
---
Full diff: https://github.com/llvm/llvm-project/pull/105955.diff
2 Files Affected:
- (modified) llvm/include/llvm/Transforms/IPO/FunctionImport.h (+4)
- (modified) llvm/lib/Transforms/IPO/FunctionImport.cpp (+12-6)
``````````diff
diff --git a/llvm/include/llvm/Transforms/IPO/FunctionImport.h b/llvm/include/llvm/Transforms/IPO/FunctionImport.h
index 93d831c26938bb..b5b969220df85b 100644
--- a/llvm/include/llvm/Transforms/IPO/FunctionImport.h
+++ b/llvm/include/llvm/Transforms/IPO/FunctionImport.h
@@ -139,6 +139,10 @@ class FunctionImporter {
maybeAddDeclaration(FromModule, GUID);
}
+ // Return the list of source modules sorted in the ascending alphabetical
+ // order.
+ SmallVector<StringRef, 0> getSourceModules() const;
+
const ImportMapTyImpl &getImportMap() const { return ImportMap; }
private:
diff --git a/llvm/lib/Transforms/IPO/FunctionImport.cpp b/llvm/lib/Transforms/IPO/FunctionImport.cpp
index 74a71cbf101b5d..cc70d5ceb81bfc 100644
--- a/llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionImport.cpp
@@ -352,6 +352,16 @@ void FunctionImporter::ImportMapTy::maybeAddDeclaration(
ImportMap[FromModule].try_emplace(GUID, GlobalValueSummary::Declaration);
}
+SmallVector<StringRef, 0>
+FunctionImporter::ImportMapTy::getSourceModules() const {
+ SetVector<StringRef> ModuleSet;
+ for (const auto &[SrcMod, GUID] : ImportMap)
+ ModuleSet.insert(SrcMod);
+ SmallVector<StringRef, 0> Modules = ModuleSet.takeVector();
+ llvm::sort(Modules);
+ return Modules;
+}
+
/// Import globals referenced by a function or other globals that are being
/// imported, if importing such global is possible.
class GlobalsImporter final {
@@ -1770,11 +1780,6 @@ Expected<bool> FunctionImporter::importFunctions(
unsigned ImportedCount = 0, ImportedGVCount = 0;
IRMover Mover(DestModule);
- // Do the actual import of functions now, one Module at a time
- std::set<StringRef> ModuleNameOrderedList;
- for (const auto &FunctionsToImportPerModule : ImportList.getImportMap()) {
- ModuleNameOrderedList.insert(FunctionsToImportPerModule.first);
- }
auto getImportType = [&](const FunctionsToImportTy &GUIDToImportType,
GlobalValue::GUID GUID)
@@ -1785,7 +1790,8 @@ Expected<bool> FunctionImporter::importFunctions(
return Iter->second;
};
- for (const auto &Name : ModuleNameOrderedList) {
+ // Do the actual import of functions now, one Module at a time
+ for (const auto &Name : ImportList.getSourceModules()) {
// Get the module for the import
const auto &FunctionsToImportPerModule =
ImportList.getImportMap().find(Name);
``````````
</details>
https://github.com/llvm/llvm-project/pull/105955
More information about the llvm-commits
mailing list