[llvm] [llvm][transforms] Add a new algorithm to SplitModule (PR #95941)
Ilia Sergachev via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 2 13:43:51 PDT 2024
================
@@ -268,6 +268,38 @@ void llvm::SplitModule(
ClusterIDMapType ClusterIDMap;
findPartitions(M, ClusterIDMap, N);
+ // Find empty modules and functions not mapped to modules in ClusterIDMap.
+ // Map these functions to the empty modules so that they skip being
+ // distributed by isInPartition() based on function name hashes below.
+ // This provides better uniformity of distribution of functions to modules
+ // in some cases - for example when the number of functions equals to N.
+ if (TryToAvoidEmptyModules) {
+ DenseSet<unsigned> NonEmptyModules;
+ SmallVector<const GlobalValue *> UnmappedFunctions;
+ for (const auto &F : M.functions()) {
+ if (F.isDeclaration() ||
+ F.getLinkage() != GlobalValue::LinkageTypes::ExternalLinkage)
+ continue;
+ auto It = ClusterIDMap.find(&F);
+ if (It == ClusterIDMap.end())
+ UnmappedFunctions.push_back(&F);
+ else
+ NonEmptyModules.insert(It->second);
+ }
+ SmallVector<unsigned> EmptyModules;
+ for (unsigned I = 0; I < N; ++I) {
+ if (!NonEmptyModules.contains(I))
+ EmptyModules.push_back(I);
+ }
+ auto NextEmptyModuleIt = EmptyModules.begin();
+ for (const auto F : UnmappedFunctions) {
+ if (NextEmptyModuleIt == EmptyModules.end())
+ break;
+ ClusterIDMap.insert({F, *NextEmptyModuleIt});
+ ++NextEmptyModuleIt;
+ }
----------------
sergachev wrote:
>"why would anyone use this algorithm as is?"
To get less useless empty modules.
> only really suited for this case it seems
It's best suited for this use case but works fine in the other cases too and does the same - reduces the number of empty modules as compared to what hash-based distribution does.
https://github.com/llvm/llvm-project/pull/95941
More information about the llvm-commits
mailing list