diff options
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, |