diff options
author | Mehdi Amini <mehdi.amini@apple.com> | 2016-09-15 20:26:27 +0000 |
---|---|---|
committer | Mehdi Amini <mehdi.amini@apple.com> | 2016-09-15 20:26:27 +0000 |
commit | d880309835d89413b5cbf4e586d9d0ece4556ece (patch) | |
tree | c6eadbba3efbe70f012e8a56f226490b396491fc /llvm/lib | |
parent | 3045d703f6a6fb73edafb80f3142d2d7266af9ec (diff) | |
download | bcm5719-llvm-d880309835d89413b5cbf4e586d9d0ece4556ece.tar.gz bcm5719-llvm-d880309835d89413b5cbf4e586d9d0ece4556ece.zip |
[GlobalOpt] Dead Eliminate declarations
GlobalOpt is already dead-code-eliminating global definitions. With
this change it also takes care of declarations.
Hopefully this should make it now a strict superset of GlobalDCE.
This is important for LTO/ThinLTO as we don't want the linker to see
"undefined reference" when it processes the input files: it could
prevent proper internalization (or even load an extra file from a
static archive, changing the behavior of the program!).
llvm-svn: 281653
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Transforms/IPO/GlobalOpt.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp index 52c1cc5d279..f1686a0a615 100644 --- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp +++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp @@ -1653,7 +1653,7 @@ static bool deleteIfDead(GlobalValue &GV, SmallSet<const Comdat *, 8> &NotDiscardableComdats) { GV.removeDeadConstantUsers(); - if (!GV.isDiscardableIfUnused()) + if (!GV.isDiscardableIfUnused() && !GV.isDeclaration()) return false; if (const Comdat *C = GV.getComdat()) @@ -1662,7 +1662,7 @@ static bool deleteIfDead(GlobalValue &GV, bool Dead; if (auto *F = dyn_cast<Function>(&GV)) - Dead = F->isDefTriviallyDead(); + Dead = (F->isDeclaration() && F->use_empty()) || F->isDefTriviallyDead(); else Dead = GV.use_empty(); if (!Dead) |