[llvm-commits] [llvm] r94007 - in /llvm/trunk: include/llvm/Transforms/IPO/InlinerPass.h lib/Transforms/IPO/Inliner.cpp

Jakob Stoklund Olesen stoklund at 2pi.dk
Wed Jan 20 09:51:28 PST 2010


Author: stoklund
Date: Wed Jan 20 11:51:28 2010
New Revision: 94007

URL: http://llvm.org/viewvc/llvm-project?rev=94007&view=rev
Log:
Move per-function inline threshold calculation to a method.

No functional change except the forgotten test for
InlineLimit.getNumOccurrences() == 0 in the CurrentThreshold2 calculation.

Modified:
    llvm/trunk/include/llvm/Transforms/IPO/InlinerPass.h
    llvm/trunk/lib/Transforms/IPO/Inliner.cpp

Modified: llvm/trunk/include/llvm/Transforms/IPO/InlinerPass.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/IPO/InlinerPass.h?rev=94007&r1=94006&r2=94007&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Transforms/IPO/InlinerPass.h (original)
+++ llvm/trunk/include/llvm/Transforms/IPO/InlinerPass.h Wed Jan 20 11:51:28 2010
@@ -51,6 +51,12 @@
   ///
   unsigned getInlineThreshold() const { return InlineThreshold; }
 
+  /// Calculate the inline threshold for given Caller. This threshold is lower
+  /// if Caller is marked with OptimizeForSize and -inline-threshold is not
+  /// given on the comand line.
+  ///
+  unsigned getInlineThreshold(Function* Caller) const;
+
   /// getInlineCost - This method must be implemented by the subclass to
   /// determine the cost of inlining the specified call site.  If the cost
   /// returned is greater than the current inline threshold, the call site is

Modified: llvm/trunk/lib/Transforms/IPO/Inliner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/Inliner.cpp?rev=94007&r1=94006&r2=94007&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/IPO/Inliner.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/Inliner.cpp Wed Jan 20 11:51:28 2010
@@ -171,7 +171,16 @@
   
   return true;
 }
-        
+
+unsigned Inliner::getInlineThreshold(Function* Caller) const {
+  if (Caller && !Caller->isDeclaration() &&
+      Caller->hasFnAttr(Attribute::OptimizeForSize) &&
+      InlineLimit.getNumOccurrences() == 0)
+    return 50;
+  else
+    return InlineThreshold;
+}
+
 /// shouldInline - Return true if the inliner should attempt to inline
 /// at the given CallSite.
 bool Inliner::shouldInline(CallSite CS) {
@@ -190,14 +199,8 @@
   }
   
   int Cost = IC.getValue();
-  int CurrentThreshold = InlineThreshold;
   Function *Caller = CS.getCaller();
-  if (Caller && !Caller->isDeclaration() &&
-      Caller->hasFnAttr(Attribute::OptimizeForSize) &&
-      InlineLimit.getNumOccurrences() == 0 &&
-      InlineThreshold != 50)
-    CurrentThreshold = 50;
-  
+  int CurrentThreshold = getInlineThreshold(Caller);
   float FudgeFactor = getInlineFudgeFactor(CS);
   if (Cost >= (int)(CurrentThreshold * FudgeFactor)) {
     DEBUG(dbgs() << "    NOT Inlining: cost=" << Cost
@@ -233,13 +236,8 @@
 
       outerCallsFound = true;
       int Cost2 = IC2.getValue();
-      int CurrentThreshold2 = InlineThreshold;
       Function *Caller2 = CS2.getCaller();
-      if (Caller2 && !Caller2->isDeclaration() &&
-          Caller2->hasFnAttr(Attribute::OptimizeForSize) &&
-          InlineThreshold != 50)
-        CurrentThreshold2 = 50;
-
+      int CurrentThreshold2 = getInlineThreshold(Caller2);
       float FudgeFactor2 = getInlineFudgeFactor(CS2);
 
       if (Cost2 >= (int)(CurrentThreshold2 * FudgeFactor2))





More information about the llvm-commits mailing list