summaryrefslogtreecommitdiff
path: root/lib/Transforms/IPO/InlineSimple.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-08-24 05:03:14 +0000
committerChris Lattner <sabre@nondot.org>2003-08-24 05:03:14 +0000
commit6a67393e19632a9829c7ba0d3e7446db322612d9 (patch)
tree14cb05938bc5097bcdd4fa8a9301b680e8477e3b /lib/Transforms/IPO/InlineSimple.cpp
parent66197a9d23ed47b300d8787fd903b58d70a91be9 (diff)
downloadllvm-6a67393e19632a9829c7ba0d3e7446db322612d9.tar.gz
llvm-6a67393e19632a9829c7ba0d3e7446db322612d9.tar.bz2
llvm-6a67393e19632a9829c7ba0d3e7446db322612d9.tar.xz
Big diff for a small change: delete inlined functions if all callees have
inlined the function. Implements: Inline/inline_dce.ll git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8101 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/IPO/InlineSimple.cpp')
-rw-r--r--lib/Transforms/IPO/InlineSimple.cpp53
1 files changed, 32 insertions, 21 deletions
diff --git a/lib/Transforms/IPO/InlineSimple.cpp b/lib/Transforms/IPO/InlineSimple.cpp
index cde2e4a729..26f7165ac6 100644
--- a/lib/Transforms/IPO/InlineSimple.cpp
+++ b/lib/Transforms/IPO/InlineSimple.cpp
@@ -17,6 +17,7 @@
namespace {
Statistic<> NumInlined("inline", "Number of functions inlined");
+ Statistic<> NumDeleted("inline", "Number of functions deleted because all callers found");
cl::opt<unsigned> // FIXME: 200 is VERY conservative
InlineLimit("inline-threshold", cl::Hidden, cl::init(200),
cl::desc("Control the amount of inlining to perform (default = 200)"));
@@ -139,29 +140,39 @@ bool FunctionInlining::doInlining(Function *F) {
bool ShouldInc = true;
// Found a call instruction? FIXME: This should also handle INVOKEs
if (CallInst *CI = dyn_cast<CallInst>(I)) {
- if (Function *Callee = CI->getCalledFunction())
+ if (Function *Callee = CI->getCalledFunction()) {
doInlining(Callee); // Inline in callees before callers!
- // Decide whether we should inline this function...
- if (ShouldInlineFunction(CI)) {
- // Save an iterator to the instruction before the call if it exists,
- // otherwise get an iterator at the end of the block... because the
- // call will be destroyed.
- //
- BasicBlock::iterator SI;
- if (I != BB->begin()) {
- SI = I; --SI; // Instruction before the call...
- } else {
- SI = BB->end();
- }
-
- // Attempt to inline the function...
- if (InlineFunction(CI)) {
- ++NumInlined;
- Changed = true;
- // Move to instruction before the call...
- I = (SI == BB->end()) ? BB->begin() : SI;
- ShouldInc = false; // Don't increment iterator until next time
+ // Decide whether we should inline this function...
+ if (ShouldInlineFunction(CI)) {
+ // Save an iterator to the instruction before the call if it exists,
+ // otherwise get an iterator at the end of the block... because the
+ // call will be destroyed.
+ //
+ BasicBlock::iterator SI;
+ if (I != BB->begin()) {
+ SI = I; --SI; // Instruction before the call...
+ } else {
+ SI = BB->end();
+ }
+
+ // Attempt to inline the function...
+ if (InlineFunction(CI)) {
+ ++NumInlined;
+ Changed = true;
+ // Move to instruction before the call...
+ I = (SI == BB->end()) ? BB->begin() : SI;
+ ShouldInc = false; // Don't increment iterator until next time
+
+ // If we inlined the last possible call site to the function,
+ // delete the function body now.
+ if (Callee->use_empty() &&
+ (Callee->hasInternalLinkage()||Callee->hasLinkOnceLinkage())){
+ F->getParent()->getFunctionList().erase(Callee);
+ ++NumDeleted;
+ if (Callee == F) return true;
+ }
+ }
}
}
}