diff options
| author | Teresa Johnson <tejohnson@google.com> | 2018-02-06 00:43:39 +0000 |
|---|---|---|
| committer | Teresa Johnson <tejohnson@google.com> | 2018-02-06 00:43:39 +0000 |
| commit | 791c98e4c82bcaa245c9b57e5d0de1cf1a16e182 (patch) | |
| tree | 840c676d316c8a68a2c04c2a6866fc7113be8dd0 /llvm/lib/LTO | |
| parent | 7b98be2c192ceeccd18daafb5129400866ff5188 (diff) | |
| download | bcm5719-llvm-791c98e4c82bcaa245c9b57e5d0de1cf1a16e182.tar.gz bcm5719-llvm-791c98e4c82bcaa245c9b57e5d0de1cf1a16e182.zip | |
[ThinLTO] Remove dead and dropped symbol declarations when possible
Summary:
Removing the dropped symbols will prevent indirect call promotion in the
ThinLTO Backend from adding a new reference to a symbol, which can
result in linker unsats. This can happen when we compile with a sample
profile collected from one binary by used for another, which may have
profiled targets that aren't used in the new binary.
Note that until dropDeadSymbols handles variables and aliases (in
progress), we may not be able to remove the declaration and can still
have an issue.
Reviewers: grimar, davidxl
Subscribers: mehdi_amini, inglorion, llvm-commits, eraman
Differential Revision: https://reviews.llvm.org/D42816
llvm-svn: 324299
Diffstat (limited to 'llvm/lib/LTO')
| -rw-r--r-- | llvm/lib/LTO/LTOBackend.cpp | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp index 49c0c2e15b3..4dbdd26be9d 100644 --- a/llvm/lib/LTO/LTOBackend.cpp +++ b/llvm/lib/LTO/LTOBackend.cpp @@ -401,14 +401,23 @@ Error lto::backend(Config &C, AddStreamFn AddStream, static void dropDeadSymbols(Module &Mod, const GVSummaryMapTy &DefinedGlobals, const ModuleSummaryIndex &Index) { - std::vector<GlobalValue *> ReplacedGlobals; + std::vector<GlobalValue*> DeadGVs; for (auto &GV : Mod.global_values()) if (GlobalValueSummary *GVS = DefinedGlobals.lookup(GV.getGUID())) - if (!Index.isGlobalValueLive(GVS) && !convertToDeclaration(GV)) - ReplacedGlobals.push_back(&GV); - - for (GlobalValue *GV : ReplacedGlobals) - GV->eraseFromParent(); + if (!Index.isGlobalValueLive(GVS)) { + DeadGVs.push_back(&GV); + convertToDeclaration(GV); + } + + // Now that all dead bodies have been dropped, delete the actual objects + // themselves when possible. + for (GlobalValue *GV : DeadGVs) { + GV->removeDeadConstantUsers(); + // Might reference something defined in native object (i.e. dropped a + // non-prevailing IR def, but we need to keep the declaration). + if (GV->use_empty()) + GV->eraseFromParent(); + } } Error lto::thinBackend(Config &Conf, unsigned Task, AddStreamFn AddStream, |

