diff --git a/llvm/include/llvm/IR/GlobalAlias.h b/llvm/include/llvm/IR/GlobalAlias.h --- a/llvm/include/llvm/IR/GlobalAlias.h +++ b/llvm/include/llvm/IR/GlobalAlias.h @@ -77,6 +77,12 @@ return getIndirectSymbol(); } + const GlobalObject *getBaseObject() const; + GlobalObject *getBaseObject() { + return const_cast( + static_cast(this)->getBaseObject()); + } + static bool isValidLinkage(LinkageTypes L) { return isExternalLinkage(L) || isLocalLinkage(L) || isWeakLinkage(L) || isLinkOnceLinkage(L); diff --git a/llvm/include/llvm/IR/GlobalIndirectSymbol.h b/llvm/include/llvm/IR/GlobalIndirectSymbol.h --- a/llvm/include/llvm/IR/GlobalIndirectSymbol.h +++ b/llvm/include/llvm/IR/GlobalIndirectSymbol.h @@ -57,12 +57,6 @@ static_cast(this)->getIndirectSymbol()); } - const GlobalObject *getBaseObject() const; - GlobalObject *getBaseObject() { - return const_cast( - static_cast(this)->getBaseObject()); - } - const GlobalObject *getBaseObject(const DataLayout &DL, APInt &Offset) const { return dyn_cast( getIndirectSymbol()->stripAndAccumulateInBoundsConstantOffsets(DL, diff --git a/llvm/lib/IR/Globals.cpp b/llvm/lib/IR/Globals.cpp --- a/llvm/lib/IR/Globals.cpp +++ b/llvm/lib/IR/Globals.cpp @@ -283,7 +283,7 @@ const GlobalObject *GlobalValue::getBaseObject() const { if (auto *GO = dyn_cast(this)) return GO; - if (auto *GA = dyn_cast(this)) + if (auto *GA = dyn_cast(this)) return GA->getBaseObject(); return nullptr; } @@ -464,11 +464,6 @@ return nullptr; } -const GlobalObject *GlobalIndirectSymbol::getBaseObject() const { - DenseSet Aliases; - return findBaseObject(getOperand(0), Aliases); -} - //===----------------------------------------------------------------------===// // GlobalAlias Implementation //===----------------------------------------------------------------------===// @@ -524,6 +519,11 @@ setIndirectSymbol(Aliasee); } +const GlobalObject *GlobalAlias::getBaseObject() const { + DenseSet Aliases; + return findBaseObject(getOperand(0), Aliases); +} + //===----------------------------------------------------------------------===// // GlobalIFunc Implementation //===----------------------------------------------------------------------===// diff --git a/llvm/lib/Object/IRSymtab.cpp b/llvm/lib/Object/IRSymtab.cpp --- a/llvm/lib/Object/IRSymtab.cpp +++ b/llvm/lib/Object/IRSymtab.cpp @@ -284,9 +284,14 @@ } const GlobalObject *Base = GV->getBaseObject(); - if (!Base) - return make_error("Unable to determine comdat of alias!", - inconvertibleErrorCode()); + if (!Base) { + if (isa(GV)) + Base = cast(cast(GV)->getResolver()) + ->getBaseObject(); + if (!Base) + return make_error("Unable to determine comdat of alias!", + inconvertibleErrorCode()); + } if (const Comdat *C = Base->getComdat()) { Expected ComdatIndexOrErr = getComdatIndex(C, GV->getParent()); if (!ComdatIndexOrErr) diff --git a/llvm/lib/Object/ModuleSymbolTable.cpp b/llvm/lib/Object/ModuleSymbolTable.cpp --- a/llvm/lib/Object/ModuleSymbolTable.cpp +++ b/llvm/lib/Object/ModuleSymbolTable.cpp @@ -204,7 +204,7 @@ if (GVar->isConstant()) Res |= BasicSymbolRef::SF_Const; } - if (dyn_cast_or_null(GV->getBaseObject())) + if (isa_and_nonnull(GV->getBaseObject()) || isa(GV)) Res |= BasicSymbolRef::SF_Executable; if (isa(GV)) Res |= BasicSymbolRef::SF_Indirect; diff --git a/llvm/lib/Transforms/Utils/SplitModule.cpp b/llvm/lib/Transforms/Utils/SplitModule.cpp --- a/llvm/lib/Transforms/Utils/SplitModule.cpp +++ b/llvm/lib/Transforms/Utils/SplitModule.cpp @@ -125,9 +125,12 @@ // For aliases we should not separate them from their aliasees regardless // of linkage. - if (auto *GIS = dyn_cast(&GV)) { + if (auto *GIS = dyn_cast(&GV)) { if (const GlobalObject *Base = GIS->getBaseObject()) GVtoClusterMap.unionSets(&GV, Base); + } else if (auto *GIS = dyn_cast(&GV)) { + GVtoClusterMap.unionSets( + &GV, cast(GIS->getResolver())->getBaseObject()); } if (const Function *F = dyn_cast(&GV)) { @@ -225,9 +228,12 @@ // 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 (auto *GIS = dyn_cast(GV)) { if (const GlobalObject *Base = GIS->getBaseObject()) GV = Base; + } else if (auto *GIS = dyn_cast(GV)) { + GV = cast(GIS->getResolver())->getBaseObject(); + } StringRef Name; if (const Comdat *C = GV->getComdat())