[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
This commit is contained in:
committed by
Fangrui Song
parent
7562f3df89
commit
08ed216000
@@ -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<Instruction *, 64> InstructionList;
|
||||
|
||||
std::vector<std::pair<GlobalVariable *, unsigned>> GlobalInits;
|
||||
std::vector<std::pair<GlobalIndirectSymbol *, unsigned>> IndirectSymbolInits;
|
||||
std::vector<std::pair<GlobalValue *, unsigned>> 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<std::pair<GlobalVariable *, unsigned>> GlobalInitWorklist;
|
||||
std::vector<std::pair<GlobalIndirectSymbol *, unsigned>>
|
||||
IndirectSymbolInitWorklist;
|
||||
std::vector<std::pair<GlobalValue *, unsigned>> IndirectSymbolInitWorklist;
|
||||
std::vector<FunctionOperandInfo> FunctionOperandWorklist;
|
||||
|
||||
GlobalInitWorklist.swap(GlobalInits);
|
||||
@@ -2283,10 +2281,16 @@ Error BitcodeReader::resolveGlobalAndIndirectSymbolInits() {
|
||||
Constant *C = dyn_cast_or_null<Constant>(ValueList[ValID]);
|
||||
if (!C)
|
||||
return error("Expected a constant");
|
||||
GlobalIndirectSymbol *GIS = IndirectSymbolInitWorklist.back().first;
|
||||
if (isa<GlobalAlias>(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<GlobalAlias>(GV)) {
|
||||
if (C->getType() != GV->getType())
|
||||
return error("Alias and aliasee types don't match");
|
||||
GA->setAliasee(C);
|
||||
} else if (auto *GI = dyn_cast<GlobalIFunc>(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<std::pair<GlobalVariable *, unsigned>>().swap(GlobalInits);
|
||||
std::vector<std::pair<GlobalIndirectSymbol *, unsigned>>().swap(
|
||||
IndirectSymbolInits);
|
||||
std::vector<std::pair<GlobalValue *, unsigned>>().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,
|
||||
|
||||
Reference in New Issue
Block a user