From 4cbf70c6f2aeead786e4967a7f717e81b2f9abfc Mon Sep 17 00:00:00 2001 From: Dale Johannesen Date: Thu, 8 Jan 2009 21:45:23 +0000 Subject: 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 --- lib/Transforms/Utils/InlineCost.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'lib/Transforms') 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(II)) { + if (!isa(AI->getArraySize())) + this->usesDynamicAlloca = true; + } + if (isa(II) || isa(II->getType())) ++NumVectorInsts; @@ -173,7 +178,7 @@ InlineCost InlineCostAnalyzer::getInlineCost(CallSite CS, SmallPtrSet &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 -- cgit v1.1