diff options
author | Dale Johannesen <dalej@apple.com> | 2009-01-08 21:45:23 +0000 |
---|---|---|
committer | Dale Johannesen <dalej@apple.com> | 2009-01-08 21:45:23 +0000 |
commit | 4cbf70c6f2aeead786e4967a7f717e81b2f9abfc (patch) | |
tree | 0c7c4308429d7eea8c254da50dfa688bf5c64fc3 /lib/Transforms | |
parent | e2abfc2d8f0c8274f90b751ccdec1d01f27763fc (diff) | |
download | external_llvm-4cbf70c6f2aeead786e4967a7f717e81b2f9abfc.zip external_llvm-4cbf70c6f2aeead786e4967a7f717e81b2f9abfc.tar.gz external_llvm-4cbf70c6f2aeead786e4967a7f717e81b2f9abfc.tar.bz2 |
Do not inline functions with (dynamic) alloca into
functions that don't already have a (dynamic) alloca.
Dynamic allocas cause inefficient codegen and we shouldn't
propagate this (behavior follows gcc). Two existing tests
assumed such inlining would be done; they are hacked by
adding an alloca in the caller, preserving the point of
the tests.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@61946 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r-- | lib/Transforms/Utils/InlineCost.cpp | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/lib/Transforms/Utils/InlineCost.cpp b/lib/Transforms/Utils/InlineCost.cpp index 29d4f79..82e310b 100644 --- a/lib/Transforms/Utils/InlineCost.cpp +++ b/lib/Transforms/Utils/InlineCost.cpp @@ -126,6 +126,11 @@ void InlineCostAnalyzer::FunctionInfo::analyzeFunction(Function *F) { NumInsts += 5; } + if (const AllocaInst *AI = dyn_cast<AllocaInst>(II)) { + if (!isa<ConstantInt>(AI->getArraySize())) + this->usesDynamicAlloca = true; + } + if (isa<ExtractElementInst>(II) || isa<VectorType>(II->getType())) ++NumVectorInsts; @@ -173,7 +178,7 @@ InlineCost InlineCostAnalyzer::getInlineCost(CallSite CS, SmallPtrSet<const Function *, 16> &NeverInline) { Instruction *TheCall = CS.getInstruction(); Function *Callee = CS.getCalledFunction(); - const Function *Caller = TheCall->getParent()->getParent(); + Function *Caller = TheCall->getParent()->getParent(); // Don't inline a directly recursive call. if (Caller == Callee || @@ -219,11 +224,24 @@ InlineCost InlineCostAnalyzer::getInlineCost(CallSite CS, // If we haven't calculated this information yet, do so now. if (CalleeFI.NumBlocks == 0) CalleeFI.analyzeFunction(Callee); - + // If we should never inline this, return a huge cost. if (CalleeFI.NeverInline) return InlineCost::getNever(); + // Get infomation about the caller... + FunctionInfo &CallerFI = CachedFunctionInfo[Caller]; + + // If we haven't calculated this information yet, do so now. + if (CallerFI.NumBlocks == 0) + CallerFI.analyzeFunction(Caller); + + // Don't inline a callee with dynamic alloca into a caller without them. + // Functions containing dynamic alloca's are inefficient in various ways; + // don't create more inefficiency. + if (CalleeFI.usesDynamicAlloca && !CallerFI.usesDynamicAlloca) + return InlineCost::getNever(); + // FIXME: It would be nice to kill off CalleeFI.NeverInline. Then we // could move this up and avoid computing the FunctionInfo for // things we are going to just return always inline for. This |