[llvm-commits] [llvm] r152283 - in /llvm/trunk: include/llvm/Analysis/CodeMetrics.h include/llvm/Analysis/InlineCost.h lib/Analysis/InlineCost.cpp

Chandler Carruth chandlerc at gmail.com
Wed Mar 7 18:04:19 PST 2012


Author: chandlerc
Date: Wed Mar  7 20:04:19 2012
New Revision: 152283

URL: http://llvm.org/viewvc/llvm-project?rev=152283&view=rev
Log:
Rotate two of the functions used to count bonuses for the inline cost
analysis to be methods on the cost analysis's function info object
instead of the code metrics object. These really are just users of the
code metrics, they're building the information for the function's
analysis.

This is the first step of growing the amount of information we collect
about a function in order to cope with pair-wise simplifications due to
allocas.

Modified:
    llvm/trunk/include/llvm/Analysis/CodeMetrics.h
    llvm/trunk/include/llvm/Analysis/InlineCost.h
    llvm/trunk/lib/Analysis/InlineCost.cpp

Modified: llvm/trunk/include/llvm/Analysis/CodeMetrics.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/CodeMetrics.h?rev=152283&r1=152282&r2=152283&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/CodeMetrics.h (original)
+++ llvm/trunk/include/llvm/Analysis/CodeMetrics.h Wed Mar  7 20:04:19 2012
@@ -81,21 +81,10 @@
     /// to the current structure.
     void analyzeFunction(Function *F, const TargetData *TD = 0);
 
-    /// CountCodeReductionForConstant - Figure out an approximation for how
-    /// many instructions will be constant folded if the specified value is
-    /// constant.
-    unsigned CountCodeReductionForConstant(Value *V);
-
     /// CountBonusForConstant - Figure out an approximation for how much
     /// per-call performance boost we can expect if the specified value is
     /// constant.
     unsigned CountBonusForConstant(Value *V);
-
-    /// CountCodeReductionForAlloca - Figure out an approximation of how much
-    /// smaller the function will be if it is inlined into a context where an
-    /// argument becomes an alloca.
-    ///
-    unsigned CountCodeReductionForAlloca(Value *V);
   };
 }
 

Modified: llvm/trunk/include/llvm/Analysis/InlineCost.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/InlineCost.h?rev=152283&r1=152282&r2=152283&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/InlineCost.h (original)
+++ llvm/trunk/include/llvm/Analysis/InlineCost.h Wed Mar  7 20:04:19 2012
@@ -110,6 +110,18 @@
       /// entry here.
       std::vector<ArgInfo> ArgumentWeights;
 
+      /// countCodeReductionForConstant - Figure out an approximation for how
+      /// many instructions will be constant folded if the specified value is
+      /// constant.
+      unsigned countCodeReductionForConstant(const CodeMetrics &Metrics,
+                                             Value *V);
+
+      /// countCodeReductionForAlloca - Figure out an approximation of how much
+      /// smaller the function will be if it is inlined into a context where an
+      /// argument becomes an alloca.
+      unsigned countCodeReductionForAlloca(const CodeMetrics &Metrics,
+                                           Value *V);
+
       /// analyzeFunction - Add information about the specified function
       /// to the current structure.
       void analyzeFunction(Function *F, const TargetData *TD);

Modified: llvm/trunk/lib/Analysis/InlineCost.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InlineCost.cpp?rev=152283&r1=152282&r2=152283&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InlineCost.cpp (original)
+++ llvm/trunk/lib/Analysis/InlineCost.cpp Wed Mar  7 20:04:19 2012
@@ -162,10 +162,8 @@
   NumBBInsts[BB] = NumInsts - NumInstsBeforeThisBB;
 }
 
-// CountCodeReductionForConstant - Figure out an approximation for how many
-// instructions will be constant folded if the specified value is constant.
-//
-unsigned CodeMetrics::CountCodeReductionForConstant(Value *V) {
+unsigned InlineCostAnalyzer::FunctionInfo::countCodeReductionForConstant(
+    const CodeMetrics &Metrics, Value *V) {
   unsigned Reduction = 0;
   for (Value::use_iterator UI = V->use_begin(), E = V->use_end(); UI != E;++UI){
     User *U = *UI;
@@ -175,7 +173,7 @@
       const unsigned NumSucc = TI.getNumSuccessors();
       unsigned Instrs = 0;
       for (unsigned I = 0; I != NumSucc; ++I)
-        Instrs += NumBBInsts[TI.getSuccessor(I)];
+        Instrs += Metrics.NumBBInsts.lookup(TI.getSuccessor(I));
       // We don't know which blocks will be eliminated, so use the average size.
       Reduction += InlineConstants::InstrCost*Instrs*(NumSucc-1)/NumSucc;
     } else {
@@ -207,18 +205,15 @@
 
         // And any other instructions that use it which become constants
         // themselves.
-        Reduction += CountCodeReductionForConstant(&Inst);
+        Reduction += countCodeReductionForConstant(Metrics, &Inst);
       }
     }
   }
   return Reduction;
 }
 
-// CountCodeReductionForAlloca - Figure out an approximation of how much smaller
-// the function will be if it is inlined into a context where an argument
-// becomes an alloca.
-//
-unsigned CodeMetrics::CountCodeReductionForAlloca(Value *V) {
+unsigned InlineCostAnalyzer::FunctionInfo::countCodeReductionForAlloca(
+    const CodeMetrics &Metrics, Value *V) {
   if (!V->getType()->isPointerTy()) return 0;  // Not a pointer
   unsigned Reduction = 0;
 
@@ -331,7 +326,8 @@
         if (BranchInst *BI = dyn_cast<BranchInst>(I)) {
           BasicBlock *BB = BI->getSuccessor(Result ? 0 : 1);
           if (BB->getSinglePredecessor())
-            Reduction += InlineConstants::InstrCost * NumBBInsts[BB];
+            Reduction
+              += InlineConstants::InstrCost * Metrics.NumBBInsts.lookup(BB);
         }
       }
     } while (!Worklist.empty());
@@ -372,8 +368,8 @@
   // code can be eliminated if one of the arguments is a constant.
   ArgumentWeights.reserve(F->arg_size());
   for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end(); I != E; ++I)
-    ArgumentWeights.push_back(ArgInfo(Metrics.CountCodeReductionForConstant(I),
-                                      Metrics.CountCodeReductionForAlloca(I)));
+    ArgumentWeights.push_back(ArgInfo(countCodeReductionForConstant(Metrics, I),
+                                      countCodeReductionForAlloca(Metrics, I)));
 }
 
 /// NeverInline - returns true if the function should never be inlined into





More information about the llvm-commits mailing list