Factor shouldInline method out of Inliner.
authorDaniel Dunbar <daniel@zuster.org>
Wed, 29 Oct 2008 01:02:02 +0000 (01:02 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Wed, 29 Oct 2008 01:02:02 +0000 (01:02 +0000)
 - No functionality change.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@58355 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Transforms/IPO/InlinerPass.h
lib/Transforms/IPO/Inliner.cpp

index e0a3d2943e5633b42c15b1ea04313be28c33fb1e..00950f78e8cfda5c781b60cb6aa059af84bc8722 100644 (file)
@@ -23,7 +23,7 @@ namespace llvm {
   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 @@ struct Inliner : public CallGraphSCCPass {
 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
index c267272004004d28c4ecf7ef6e35de0c8dd13e37..74af18396d4adfc277fa765531fde28be6997360 100644 (file)
@@ -72,6 +72,31 @@ static bool InlineCallIfPossible(CallSite CS, CallGraph &CG,
   }
   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 @@ bool Inliner::runOnSCC(const std::vector<CallGraphNode*> &SCC) {
         // 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>())) {