diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Transforms/IPO/InlineAlways.cpp | 2 | ||||
-rw-r--r-- | lib/Transforms/IPO/InlineSimple.cpp | 2 | ||||
-rw-r--r-- | lib/Transforms/IPO/Inliner.cpp | 15 | ||||
-rw-r--r-- | lib/Transforms/Utils/BasicInliner.cpp | 25 | ||||
-rw-r--r-- | lib/Transforms/Utils/InlineCost.cpp | 14 |
5 files changed, 43 insertions, 15 deletions
diff --git a/lib/Transforms/IPO/InlineAlways.cpp b/lib/Transforms/IPO/InlineAlways.cpp index 2799d6b..d809b5a 100644 --- a/lib/Transforms/IPO/InlineAlways.cpp +++ b/lib/Transforms/IPO/InlineAlways.cpp @@ -39,7 +39,7 @@ namespace { // Use extremely low threshold. AlwaysInliner() : Inliner(&ID, -2000000000) {} static char ID; // Pass identification, replacement for typeid - int getInlineCost(CallSite CS) { + InlineCost getInlineCost(CallSite CS) { return CA.getInlineCost(CS, NeverInline); } float getInlineFudgeFactor(CallSite CS) { diff --git a/lib/Transforms/IPO/InlineSimple.cpp b/lib/Transforms/IPO/InlineSimple.cpp index 02cae2a..8ae5235 100644 --- a/lib/Transforms/IPO/InlineSimple.cpp +++ b/lib/Transforms/IPO/InlineSimple.cpp @@ -37,7 +37,7 @@ namespace { SimpleInliner() : Inliner(&ID) {} SimpleInliner(int Threshold) : Inliner(&ID, Threshold) {} static char ID; // Pass identification, replacement for typeid - int getInlineCost(CallSite CS) { + InlineCost getInlineCost(CallSite CS) { return CA.getInlineCost(CS, NeverInline); } float getInlineFudgeFactor(CallSite CS) { diff --git a/lib/Transforms/IPO/Inliner.cpp b/lib/Transforms/IPO/Inliner.cpp index 74af183..2321047 100644 --- a/lib/Transforms/IPO/Inliner.cpp +++ b/lib/Transforms/IPO/Inliner.cpp @@ -76,9 +76,22 @@ static bool InlineCallIfPossible(CallSite CS, CallGraph &CG, /// shouldInline - Return true if the inliner should attempt to inline /// at the given CallSite. bool Inliner::shouldInline(CallSite CS) { - int Cost = getInlineCost(CS); + InlineCost IC = getInlineCost(CS); float FudgeFactor = getInlineFudgeFactor(CS); + if (IC.isAlways()) { + DOUT << " Inlining: cost=always" + << ", Call: " << *CS.getInstruction(); + return true; + } + + if (IC.isNever()) { + DOUT << " NOT Inlining: cost=never" + << ", Call: " << *CS.getInstruction(); + return false; + } + + int Cost = IC.getValue(); int CurrentThreshold = InlineThreshold; Function *Fn = CS.getCaller(); if (Fn && !Fn->isDeclaration() diff --git a/lib/Transforms/Utils/BasicInliner.cpp b/lib/Transforms/Utils/BasicInliner.cpp index ba1fb3d..73e8bd8 100644 --- a/lib/Transforms/Utils/BasicInliner.cpp +++ b/lib/Transforms/Utils/BasicInliner.cpp @@ -107,16 +107,27 @@ void BasicInlinerImpl::inlineFunctions() { --index; continue; } - int InlineCost = CA.getInlineCost(CS, NeverInline); - if (InlineCost >= (int) BasicInlineThreshold) { - DOUT << " NOT Inlining: cost = " << InlineCost - << ", call: " << *CS.getInstruction(); + InlineCost IC = CA.getInlineCost(CS, NeverInline); + if (IC.isAlways()) { + DOUT << " Inlining: cost=always" + <<", call: " << *CS.getInstruction(); + } else if (IC.isNever()) { + DOUT << " NOT Inlining: cost=never" + <<", call: " << *CS.getInstruction(); continue; + } else { + int Cost = IC.getValue(); + + if (Cost >= BasicInlineThreshold) { + DOUT << " NOT Inlining: cost = " << Cost + << ", call: " << *CS.getInstruction(); + continue; + } else { + DOUT << " Inlining: cost = " << Cost + << ", call: " << *CS.getInstruction(); + } } - DOUT << " Inlining: cost=" << InlineCost - <<", call: " << *CS.getInstruction(); - // Inline if (InlineFunction(CS, NULL, TD)) { if (Callee->use_empty() && Callee->hasInternalLinkage()) diff --git a/lib/Transforms/Utils/InlineCost.cpp b/lib/Transforms/Utils/InlineCost.cpp index c665b12..b85a455 100644 --- a/lib/Transforms/Utils/InlineCost.cpp +++ b/lib/Transforms/Utils/InlineCost.cpp @@ -169,7 +169,7 @@ void InlineCostAnalyzer::FunctionInfo::analyzeFunction(Function *F) { // getInlineCost - The heuristic used to determine if we should inline the // function call or not. // -int InlineCostAnalyzer::getInlineCost(CallSite CS, +InlineCost InlineCostAnalyzer::getInlineCost(CallSite CS, SmallPtrSet<const Function *, 16> &NeverInline) { Instruction *TheCall = CS.getInstruction(); Function *Callee = CS.getCalledFunction(); @@ -187,7 +187,7 @@ int InlineCostAnalyzer::getInlineCost(CallSite CS, // Don't inline functions marked noinline. NeverInline.count(Callee)) - return 2000000000; + return llvm::InlineCost::getNever(); // InlineCost - This value measures how good of an inline candidate this call // site is to inline. A lower inline cost make is more likely for the call to @@ -224,10 +224,14 @@ int InlineCostAnalyzer::getInlineCost(CallSite CS, // If we should never inline this, return a huge cost. if (CalleeFI.NeverInline) - return 2000000000; + 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 + // requires handling setjmp somewhere else, however. if (!Callee->isDeclaration() && Callee->hasFnAttr(Attribute::AlwaysInline)) - return -2000000000; + return InlineCost::getAlways(); // Add to the inline quality for properties that make the call valuable to // inline. This includes factors that indicate that the result of inlining @@ -274,7 +278,7 @@ int InlineCostAnalyzer::getInlineCost(CallSite CS, // Look at the size of the callee. Each instruction counts as 5. InlineCost += CalleeFI.NumInsts*5; - return InlineCost; + return llvm::InlineCost::get(InlineCost); } // getInlineFudgeFactor - Return a > 1.0 factor if the inliner should use a |