summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2011-10-20 05:23:42 +0000
committerEli Friedman <eli.friedman@gmail.com>2011-10-20 05:23:42 +0000
commit1923a330e66073944560fe7d751b399798656d89 (patch)
treec5cf6c5182ab557feeb6a77d11a513ccc82d639f /llvm/lib/Transforms
parent337c5b880c5f5328cf557ab4177726bbf0a93100 (diff)
downloadbcm5719-llvm-1923a330e66073944560fe7d751b399798656d89.tar.gz
bcm5719-llvm-1923a330e66073944560fe7d751b399798656d89.zip
Refactor code from inlining and globalopt that checks whether a function definition is unused, and enhance it so it can tell that functions which are only used by a blockaddress are in fact dead. This probably doesn't happen much on most code, but the Linux kernel's _THIS_IP_ can trigger this issue with blockaddress. (GlobalDCE can also handle the given tescase, but we only run that at -O3.) Found while looking at PR11180.
llvm-svn: 142572
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/IPO/GlobalOpt.cpp2
-rw-r--r--llvm/lib/Transforms/IPO/Inliner.cpp5
-rw-r--r--llvm/lib/Transforms/Utils/BasicInliner.cpp4
3 files changed, 4 insertions, 7 deletions
diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
index 3552d03919b..c57e9fc0e8d 100644
--- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
@@ -1890,7 +1890,7 @@ bool GlobalOpt::OptimizeFunctions(Module &M) {
if (!F->hasName() && !F->isDeclaration())
F->setLinkage(GlobalValue::InternalLinkage);
F->removeDeadConstantUsers();
- if (F->use_empty() && (F->hasLocalLinkage() || F->hasLinkOnceLinkage())) {
+ if (F->isDefTriviallyDead()) {
F->eraseFromParent();
Changed = true;
++NumFnDeleted;
diff --git a/llvm/lib/Transforms/IPO/Inliner.cpp b/llvm/lib/Transforms/IPO/Inliner.cpp
index f00935b0888..bdc9fe45d34 100644
--- a/llvm/lib/Transforms/IPO/Inliner.cpp
+++ b/llvm/lib/Transforms/IPO/Inliner.cpp
@@ -533,10 +533,7 @@ bool Inliner::removeDeadFunctions(CallGraph &CG,
if (DNR && DNR->count(F))
continue;
- if (!F->hasLinkOnceLinkage() && !F->hasLocalLinkage() &&
- !F->hasAvailableExternallyLinkage())
- continue;
- if (!F->use_empty())
+ if (!F->isDefTriviallyDead())
continue;
// Remove any call graph edges from the function to its callees.
diff --git a/llvm/lib/Transforms/Utils/BasicInliner.cpp b/llvm/lib/Transforms/Utils/BasicInliner.cpp
index 23a30cc5850..50c91b6af87 100644
--- a/llvm/lib/Transforms/Utils/BasicInliner.cpp
+++ b/llvm/lib/Transforms/Utils/BasicInliner.cpp
@@ -131,8 +131,8 @@ void BasicInlinerImpl::inlineFunctions() {
// Inline
InlineFunctionInfo IFI(0, TD);
if (InlineFunction(CS, IFI)) {
- if (Callee->use_empty() && (Callee->hasLocalLinkage() ||
- Callee->hasAvailableExternallyLinkage()))
+ Callee->removeDeadConstantUsers();
+ if (Callee->isDefTriviallyDead())
DeadFunctions.insert(Callee);
Changed = true;
CallSites.erase(CallSites.begin() + index);
OpenPOWER on IntegriCloud