Adjustments to last patch based on review.
authorDale Johannesen <dalej@apple.com>
Fri, 9 Jan 2009 01:30:11 +0000 (01:30 +0000)
committerDale Johannesen <dalej@apple.com>
Fri, 9 Jan 2009 01:30:11 +0000 (01:30 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@61969 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Transforms/IPO/InlinerPass.h
include/llvm/Transforms/Utils/InlineCost.h
lib/Transforms/IPO/InlineAlways.cpp
lib/Transforms/IPO/InlineSimple.cpp
lib/Transforms/IPO/Inliner.cpp
lib/Transforms/Utils/InlineCost.cpp

index 7c3632fdce111ba2fd6e930f7da0774ed862e012..3aed6494b7cc6fca9fccf2cbdc8afa7ff29b8762 100644 (file)
@@ -61,6 +61,11 @@ struct Inliner : public CallGraphSCCPass {
   ///
   virtual float getInlineFudgeFactor(CallSite CS) = 0;
 
+  /// resetCachedCostInfo - erase any cached cost data from the derived class.
+  /// If the derived class has no such data this can be empty.
+  /// 
+  virtual void resetCachedCostInfo(Function* Caller) = 0;
+
   /// removeDeadFunctions - Remove dead functions that are not included in
   /// DNR (Do Not Remove) list.
   bool removeDeadFunctions(CallGraph &CG, 
index 415fc1e91b8068953f891ab1c2558af6e19dd67c..d78a0f0818ed37c19e556794a5585bc59296a461 100644 (file)
@@ -128,6 +128,11 @@ namespace llvm {
     /// getInlineFudgeFactor - Return a > 1.0 factor if the inliner should use a
     /// higher threshold to determine if the function call should be inlined.
     float getInlineFudgeFactor(CallSite CS);
+
+    /// resetCachedFunctionInfo - erase any cached cost info for this function.
+    void resetCachedCostInfo(Function* Caller) {
+      CachedFunctionInfo[Caller].NumBlocks = 0;
+    }
   };
 }
 
index 9031432162e07b2970e098a8f9264c6d84257a12..5f9ea5453c1f6d8139ecb6173a591c43184de01a 100644 (file)
@@ -45,6 +45,9 @@ namespace {
     float getInlineFudgeFactor(CallSite CS) {
       return CA.getInlineFudgeFactor(CS);
     }
+    void resetCachedCostInfo(Function *Caller) {
+      return CA.resetCachedCostInfo(Caller);
+    }
     virtual bool doFinalization(CallGraph &CG) { 
       return removeDeadFunctions(CG, &NeverInline); 
     }
index 8ae5235383360ca2f77351c21c23a94b6d33a132..e107a0023ce6ccad28bfefa11e465d164c094499 100644 (file)
@@ -43,6 +43,9 @@ namespace {
     float getInlineFudgeFactor(CallSite CS) {
       return CA.getInlineFudgeFactor(CS);
     }
+    void resetCachedCostInfo(Function *Caller) {
+      CA.resetCachedCostInfo(Caller);
+    }
     virtual bool doInitialization(CallGraph &CG);
   };
 }
index f97fce6e06c01ed994cbb1c4a388f45afa16d3f7..639f3a84cb5f21b92f6db2fc983ecdb1fae70e1a 100644 (file)
@@ -185,9 +185,14 @@ bool Inliner::runOnSCC(const std::vector<CallGraphNode*> &SCC) {
         // try to do so.
         CallSite CS = CallSites[CSi];
         if (shouldInline(CS)) {
+          Function *Caller = CS.getCaller();
           // Attempt to inline the function...
           if (InlineCallIfPossible(CS, CG, SCCFunctions, 
                                    getAnalysis<TargetData>())) {
+            // Remove any cached cost info for this caller, as inlining the callee
+            // has increased the size of the caller.
+            resetCachedCostInfo(Caller);
+
             // Remove this call site from the list.  If possible, use 
             // swap/pop_back for efficiency, but do not use it if doing so would
             // move a call site to a function in this SCC before the
index 82e310b38c49d2145d5cc83f934db4d0abb9201e..90d72efa36ddeca6c2f9c536f62ef2ad3dee652b 100644 (file)
@@ -127,7 +127,7 @@ void InlineCostAnalyzer::FunctionInfo::analyzeFunction(Function *F) {
       }
       
       if (const AllocaInst *AI = dyn_cast<AllocaInst>(II)) {
-        if (!isa<ConstantInt>(AI->getArraySize()))
+        if (!AI->isStaticAlloca())
           this->usesDynamicAlloca = true;
       }
 
@@ -229,18 +229,20 @@ InlineCost InlineCostAnalyzer::getInlineCost(CallSite CS,
   if (CalleeFI.NeverInline)
     return InlineCost::getNever();
 
-  // Get infomation about the caller...
-  FunctionInfo &CallerFI = CachedFunctionInfo[Caller];
+  if (CalleeFI.usesDynamicAlloca) {
+    // 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);
+    // 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();
+    // 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 (!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