diff options
author | Itay Bookstein <ibookstein@gmail.com> | 2021-10-20 10:29:47 -0700 |
---|---|---|
committer | Fangrui Song <i@maskray.me> | 2021-10-20 10:29:47 -0700 |
commit | 08ed216000b6503a4a4be52f18394d008d5fb8f4 (patch) | |
tree | ca6e548769b20dc1d85b84be27a7e1be101042da /llvm/lib/Transforms/Utils/ValueMapper.cpp | |
parent | 7562f3df89066ab92a816dc23005c45fd642bdf9 (diff) | |
download | llvm-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/Transforms/Utils/ValueMapper.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/ValueMapper.cpp | 54 |
1 files changed, 34 insertions, 20 deletions
diff --git a/llvm/lib/Transforms/Utils/ValueMapper.cpp b/llvm/lib/Transforms/Utils/ValueMapper.cpp index 468c044..c3eafd6 100644 --- a/llvm/lib/Transforms/Utils/ValueMapper.cpp +++ b/llvm/lib/Transforms/Utils/ValueMapper.cpp @@ -26,7 +26,8 @@ #include "llvm/IR/DebugInfoMetadata.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/Function.h" -#include "llvm/IR/GlobalIndirectSymbol.h" +#include "llvm/IR/GlobalAlias.h" +#include "llvm/IR/GlobalIFunc.h" #include "llvm/IR/GlobalObject.h" #include "llvm/IR/GlobalVariable.h" #include "llvm/IR/InlineAsm.h" @@ -68,7 +69,7 @@ struct WorklistEntry { enum EntryKind { MapGlobalInit, MapAppendingVar, - MapGlobalIndirectSymbol, + MapAliasOrIFunc, RemapFunction }; struct GVInitTy { @@ -79,8 +80,8 @@ struct WorklistEntry { GlobalVariable *GV; Constant *InitPrefix; }; - struct GlobalIndirectSymbolTy { - GlobalIndirectSymbol *GIS; + struct AliasOrIFuncTy { + GlobalValue *GV; Constant *Target; }; @@ -91,7 +92,7 @@ struct WorklistEntry { union { GVInitTy GVInit; AppendingGVTy AppendingGV; - GlobalIndirectSymbolTy GlobalIndirectSymbol; + AliasOrIFuncTy AliasOrIFunc; Function *RemapF; } Data; }; @@ -163,8 +164,8 @@ public: bool IsOldCtorDtor, ArrayRef<Constant *> NewMembers, unsigned MCID); - void scheduleMapGlobalIndirectSymbol(GlobalIndirectSymbol &GIS, Constant &Target, - unsigned MCID); + void scheduleMapAliasOrIFunc(GlobalValue &GV, Constant &Target, + unsigned MCID); void scheduleRemapFunction(Function &F, unsigned MCID); void flush(); @@ -873,10 +874,17 @@ void Mapper::flush() { E.AppendingGVIsOldCtorDtor, makeArrayRef(NewInits)); break; } - case WorklistEntry::MapGlobalIndirectSymbol: - E.Data.GlobalIndirectSymbol.GIS->setIndirectSymbol( - mapConstant(E.Data.GlobalIndirectSymbol.Target)); + case WorklistEntry::MapAliasOrIFunc: { + GlobalValue *GV = E.Data.AliasOrIFunc.GV; + Constant *Target = mapConstant(E.Data.AliasOrIFunc.Target); + if (auto *GA = dyn_cast<GlobalAlias>(GV)) + GA->setAliasee(Target); + else if (auto *GI = dyn_cast<GlobalIFunc>(GV)) + GI->setResolver(Target); + else + llvm_unreachable("Not alias or ifunc"); break; + } case WorklistEntry::RemapFunction: remapFunction(*E.Data.RemapF); break; @@ -1069,16 +1077,18 @@ void Mapper::scheduleMapAppendingVariable(GlobalVariable &GV, AppendingInits.append(NewMembers.begin(), NewMembers.end()); } -void Mapper::scheduleMapGlobalIndirectSymbol(GlobalIndirectSymbol &GIS, - Constant &Target, unsigned MCID) { - assert(AlreadyScheduled.insert(&GIS).second && "Should not reschedule"); +void Mapper::scheduleMapAliasOrIFunc(GlobalValue &GV, Constant &Target, + unsigned MCID) { + assert(AlreadyScheduled.insert(&GV).second && "Should not reschedule"); + assert((isa<GlobalAlias>(GV) || isa<GlobalIFunc>(GV)) && + "Should be alias or ifunc"); assert(MCID < MCs.size() && "Invalid mapping context"); WorklistEntry WE; - WE.Kind = WorklistEntry::MapGlobalIndirectSymbol; + WE.Kind = WorklistEntry::MapAliasOrIFunc; WE.MCID = MCID; - WE.Data.GlobalIndirectSymbol.GIS = &GIS; - WE.Data.GlobalIndirectSymbol.Target = &Target; + WE.Data.AliasOrIFunc.GV = &GV; + WE.Data.AliasOrIFunc.Target = &Target; Worklist.push_back(WE); } @@ -1175,10 +1185,14 @@ void ValueMapper::scheduleMapAppendingVariable(GlobalVariable &GV, GV, InitPrefix, IsOldCtorDtor, NewMembers, MCID); } -void ValueMapper::scheduleMapGlobalIndirectSymbol(GlobalIndirectSymbol &GIS, - Constant &Target, - unsigned MCID) { - getAsMapper(pImpl)->scheduleMapGlobalIndirectSymbol(GIS, Target, MCID); +void ValueMapper::scheduleMapGlobalAlias(GlobalAlias &GA, Constant &Aliasee, + unsigned MCID) { + getAsMapper(pImpl)->scheduleMapAliasOrIFunc(GA, Aliasee, MCID); +} + +void ValueMapper::scheduleMapGlobalIFunc(GlobalIFunc &GI, Constant &Resolver, + unsigned MCID) { + getAsMapper(pImpl)->scheduleMapAliasOrIFunc(GI, Resolver, MCID); } void ValueMapper::scheduleRemapFunction(Function &F, unsigned MCID) { |