From 08ed216000b6503a4a4be52f18394d008d5fb8f4 Mon Sep 17 00:00:00 2001 From: Itay Bookstein Date: Wed, 20 Oct 2021 10:29:47 -0700 Subject: [IR] Refactor GlobalIFunc to inherit from GlobalObject, Remove GlobalIndirectSymbol As discussed in: * https://reviews.llvm.org/D94166 * https://lists.llvm.org/pipermail/llvm-dev/2020-September/145031.html The GlobalIndirectSymbol class lost most of its meaning in https://reviews.llvm.org/D109792, which disambiguated getBaseObject (now getAliaseeObject) between GlobalIFunc and everything else. In addition, as long as GlobalIFunc is not a GlobalObject and getAliaseeObject returns GlobalObjects, a GlobalAlias whose aliasee is a GlobalIFunc cannot currently be modeled properly. Creating aliases for GlobalIFuncs does happen in the wild (e.g. glibc). In addition, calling getAliaseeObject on a GlobalIFunc will currently return nullptr, which is undesirable because it should return the object itself for non-aliases. This patch refactors the GlobalIFunc class to inherit directly from GlobalObject, and removes GlobalIndirectSymbol (while inlining the relevant parts into GlobalAlias and GlobalIFunc). This allows for calling getAliaseeObject() on a GlobalIFunc to return the GlobalIFunc itself, making getAliaseeObject() more consistent and enabling alias-to-ifunc to be properly modeled in the IR. I exercised some judgement in the API clients of GlobalIndirectSymbol: some were 'monomorphized' for GlobalAlias and GlobalIFunc, and some remained shared (with the type adapted to become GlobalValue). Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D108872 --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp') diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index b3df3a7..349d40e 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -41,7 +41,6 @@ #include "llvm/IR/GVMaterializer.h" #include "llvm/IR/GlobalAlias.h" #include "llvm/IR/GlobalIFunc.h" -#include "llvm/IR/GlobalIndirectSymbol.h" #include "llvm/IR/GlobalObject.h" #include "llvm/IR/GlobalValue.h" #include "llvm/IR/GlobalVariable.h" @@ -500,7 +499,7 @@ class BitcodeReader : public BitcodeReaderBase, public GVMaterializer { SmallVector InstructionList; std::vector> GlobalInits; - std::vector> IndirectSymbolInits; + std::vector> IndirectSymbolInits; struct FunctionOperandInfo { Function *F; @@ -2253,8 +2252,7 @@ uint64_t BitcodeReader::decodeSignRotatedValue(uint64_t V) { /// Resolve all of the initializers for global values and aliases that we can. Error BitcodeReader::resolveGlobalAndIndirectSymbolInits() { std::vector> GlobalInitWorklist; - std::vector> - IndirectSymbolInitWorklist; + std::vector> IndirectSymbolInitWorklist; std::vector FunctionOperandWorklist; GlobalInitWorklist.swap(GlobalInits); @@ -2283,10 +2281,16 @@ Error BitcodeReader::resolveGlobalAndIndirectSymbolInits() { Constant *C = dyn_cast_or_null(ValueList[ValID]); if (!C) return error("Expected a constant"); - GlobalIndirectSymbol *GIS = IndirectSymbolInitWorklist.back().first; - if (isa(GIS) && C->getType() != GIS->getType()) - return error("Alias and aliasee types don't match"); - GIS->setIndirectSymbol(C); + GlobalValue *GV = IndirectSymbolInitWorklist.back().first; + if (auto *GA = dyn_cast(GV)) { + if (C->getType() != GV->getType()) + return error("Alias and aliasee types don't match"); + GA->setAliasee(C); + } else if (auto *GI = dyn_cast(GV)) { + GI->setResolver(C); + } else { + return error("Expected an alias or an ifunc"); + } } IndirectSymbolInitWorklist.pop_back(); } @@ -3118,8 +3122,7 @@ Error BitcodeReader::globalCleanup() { // Force deallocation of memory for these vectors to favor the client that // want lazy deserialization. std::vector>().swap(GlobalInits); - std::vector>().swap( - IndirectSymbolInits); + std::vector>().swap(IndirectSymbolInits); return Error::success(); } @@ -3499,7 +3502,7 @@ Error BitcodeReader::parseGlobalIndirectSymbolRecord( auto Val = Record[OpNum++]; auto Linkage = Record[OpNum++]; - GlobalIndirectSymbol *NewGA; + GlobalValue *NewGA; if (BitCode == bitc::MODULE_CODE_ALIAS || BitCode == bitc::MODULE_CODE_ALIAS_OLD) NewGA = GlobalAlias::create(Ty, AddrSpace, getDecodedLinkage(Linkage), Name, -- cgit v1.1