From c0981da47d5696fe36474fcf86b4ce03ae3ff818 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Fri, 19 Nov 2021 21:06:13 +0100 Subject: Vendor import of llvm-project main llvmorg-14-init-10186-gff7f2cfa959b. --- llvm/lib/Transforms/Utils/SplitModule.cpp | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'llvm/lib/Transforms/Utils/SplitModule.cpp') diff --git a/llvm/lib/Transforms/Utils/SplitModule.cpp b/llvm/lib/Transforms/Utils/SplitModule.cpp index 32f2f4e233b2..7e12bbd2851c 100644 --- a/llvm/lib/Transforms/Utils/SplitModule.cpp +++ b/llvm/lib/Transforms/Utils/SplitModule.cpp @@ -24,7 +24,6 @@ #include "llvm/IR/Function.h" #include "llvm/IR/GlobalAlias.h" #include "llvm/IR/GlobalObject.h" -#include "llvm/IR/GlobalIndirectSymbol.h" #include "llvm/IR/GlobalValue.h" #include "llvm/IR/GlobalVariable.h" #include "llvm/IR/Instruction.h" @@ -65,9 +64,8 @@ static void addNonConstUser(ClusterMapType &GVtoClusterMap, if (const Instruction *I = dyn_cast(U)) { const GlobalValue *F = I->getParent()->getParent(); GVtoClusterMap.unionSets(GV, F); - } else if (isa(U) || isa(U) || - isa(U)) { - GVtoClusterMap.unionSets(GV, cast(U)); + } else if (const GlobalValue *GVU = dyn_cast(U)) { + GVtoClusterMap.unionSets(GV, GVU); } else { llvm_unreachable("Underimplemented use case"); } @@ -91,6 +89,13 @@ static void addAllGlobalValueUsers(ClusterMapType &GVtoClusterMap, } } +static const GlobalObject *getGVPartitioningRoot(const GlobalValue *GV) { + const GlobalObject *GO = GV->getAliaseeObject(); + if (const auto *GI = dyn_cast_or_null(GO)) + GO = GI->getResolverFunction(); + return GO; +} + // Find partitions for module in the way that no locals need to be // globalized. // Try to balance pack those partitions into N files since this roughly equals @@ -123,12 +128,11 @@ static void findPartitions(Module &M, ClusterIDMapType &ClusterIDMap, Member = &GV; } - // For aliases we should not separate them from their aliasees regardless - // of linkage. - if (auto *GIS = dyn_cast(&GV)) { - if (const GlobalObject *Base = GIS->getBaseObject()) - GVtoClusterMap.unionSets(&GV, Base); - } + // Aliases should not be separated from their aliasees and ifuncs should + // not be separated from their resolvers regardless of linkage. + if (const GlobalObject *Root = getGVPartitioningRoot(&GV)) + if (&GV != Root) + GVtoClusterMap.unionSets(&GV, Root); if (const Function *F = dyn_cast(&GV)) { for (const BasicBlock &BB : *F) { @@ -225,9 +229,8 @@ static void externalize(GlobalValue *GV) { // Returns whether GV should be in partition (0-based) I of N. static bool isInPartition(const GlobalValue *GV, unsigned I, unsigned N) { - if (auto *GIS = dyn_cast(GV)) - if (const GlobalObject *Base = GIS->getBaseObject()) - GV = Base; + if (const GlobalObject *Root = getGVPartitioningRoot(GV)) + GV = Root; StringRef Name; if (const Comdat *C = GV->getComdat()) -- cgit v1.2.3