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

Daniel Dunbar daniel at zuster.org
Tue Oct 28 18:02:03 PDT 2008


Author: ddunbar
Date: Tue Oct 28 20:02:02 2008
New Revision: 58355

URL: http://llvm.org/viewvc/llvm-project?rev=58355&view=rev
Log:
Factor shouldInline method out of Inliner.
 - No functionality change.

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=58355&r1=58354&r2=58355&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Transforms/IPO/InlinerPass.h (original)
+++ llvm/trunk/include/llvm/Transforms/IPO/InlinerPass.h Tue Oct 28 20:02:02 2008
@@ -23,7 +23,7 @@
   class CallSite;
 
 /// Inliner - This class contains all of the helper code which is used to
-/// perform the inlining operations that does not depend on the policy.
+/// perform the inlining operations that do not depend on the policy.
 ///
 struct Inliner : public CallGraphSCCPass {
   explicit Inliner(void *ID);
@@ -63,6 +63,10 @@
 private:
   // InlineThreshold - Cache the value here for easy access.
   unsigned InlineThreshold;
+
+  /// shouldInline - Return true if the inliner should attempt to
+  /// inline at the given CallSite.
+  bool shouldInline(CallSite CS);
 };
 
 } // End llvm namespace

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

==============================================================================
--- llvm/trunk/lib/Transforms/IPO/Inliner.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/Inliner.cpp Tue Oct 28 20:02:02 2008
@@ -72,6 +72,31 @@
   }
   return true;
 }
+        
+/// shouldInline - Return true if the inliner should attempt to inline
+/// at the given CallSite.
+bool Inliner::shouldInline(CallSite CS) {
+  int Cost = getInlineCost(CS);
+  float FudgeFactor = getInlineFudgeFactor(CS);
+  
+  int CurrentThreshold = InlineThreshold;
+  Function *Fn = CS.getCaller();
+  if (Fn && !Fn->isDeclaration() 
+      && Fn->hasFnAttr(Attribute::OptimizeForSize)
+      && InlineThreshold != 50) {
+    CurrentThreshold = 50;
+  }
+  
+  if (Cost >= (int)(CurrentThreshold * FudgeFactor)) {
+    DOUT << "    NOT Inlining: cost=" << Cost
+         << ", Call: " << *CS.getInstruction();
+    return false;
+  } else {
+    DOUT << "    Inlining: cost=" << Cost
+         << ", Call: " << *CS.getInstruction();
+    return true;
+  }
+}
 
 bool Inliner::runOnSCC(const std::vector<CallGraphNode*> &SCC) {
   CallGraph &CG = getAnalysis<CallGraph>();
@@ -136,24 +161,7 @@
         // If the policy determines that we should inline this function,
         // try to do so.
         CallSite CS = CallSites[CSi];
-        int InlineCost = getInlineCost(CS);
-        float FudgeFactor = getInlineFudgeFactor(CS);
-        
-        int CurrentThreshold = InlineThreshold;
-        Function *Fn = CS.getCaller();
-        if (Fn && !Fn->isDeclaration() 
-            && Fn->hasFnAttr(Attribute::OptimizeForSize)
-            && InlineThreshold != 50) {
-          CurrentThreshold = 50;
-        }
-        
-        if (InlineCost >= (int)(CurrentThreshold * FudgeFactor)) {
-          DOUT << "    NOT Inlining: cost=" << InlineCost
-               << ", Call: " << *CS.getInstruction();
-        } else {
-          DOUT << "    Inlining: cost=" << InlineCost
-               << ", Call: " << *CS.getInstruction();
-
+        if (shouldInline(CS)) {
           // Attempt to inline the function...
           if (InlineCallIfPossible(CS, CG, SCCFunctions, 
                                    getAnalysis<TargetData>())) {





More information about the llvm-commits mailing list