aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff options
context:
space:
mode:
authorItay Bookstein <ibookstein@gmail.com>2021-10-20 10:29:47 -0700
committerFangrui Song <i@maskray.me>2021-10-20 10:29:47 -0700
commit08ed216000b6503a4a4be52f18394d008d5fb8f4 (patch)
treeca6e548769b20dc1d85b84be27a7e1be101042da /llvm/lib/Bitcode/Reader/BitcodeReader.cpp
parent7562f3df89066ab92a816dc23005c45fd642bdf9 (diff)
downloadllvm-08ed216000b6503a4a4be52f18394d008d5fb8f4.zip
llvm-08ed216000b6503a4a4be52f18394d008d5fb8f4.tar.gz
llvm-08ed216000b6503a4a4be52f18394d008d5fb8f4.tar.bz2
[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
Diffstat (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp')
-rw-r--r--llvm/lib/Bitcode/Reader/BitcodeReader.cpp25
1 files changed, 14 insertions, 11 deletions
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<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,