Add support for printing out statistics information when -stats is added to
authorChris Lattner <sabre@nondot.org>
Fri, 10 May 2002 15:38:35 +0000 (15:38 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 10 May 2002 15:38:35 +0000 (15:38 +0000)
the command line

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

17 files changed:
lib/Transforms/IPO/ConstantMerge.cpp
lib/Transforms/IPO/DeadTypeElimination.cpp
lib/Transforms/IPO/GlobalDCE.cpp
lib/Transforms/IPO/InlineSimple.cpp
lib/Transforms/IPO/Internalize.cpp
lib/Transforms/IPO/RaiseAllocations.cpp
lib/Transforms/Scalar/ConstantProp.cpp
lib/Transforms/Scalar/DCE.cpp
lib/Transforms/Scalar/DecomposeMultiDimRefs.cpp
lib/Transforms/Scalar/GCSE.cpp
lib/Transforms/Scalar/IndVarSimplify.cpp
lib/Transforms/Scalar/InstructionCombining.cpp
lib/Transforms/Scalar/PiNodeInsertion.cpp
lib/Transforms/Scalar/Reassociate.cpp
lib/Transforms/Scalar/SCCP.cpp
lib/Transforms/Utils/LowerAllocations.cpp
lib/Transforms/Utils/PromoteMemoryToRegister.cpp

index 146911e818ddb217892a23773b9b94a96b1e1df1..11191f535ab6e4e41bcfda86aeecdfd28043c332 100644 (file)
@@ -19,6 +19,9 @@
 #include "llvm/Module.h"
 #include "llvm/Function.h"
 #include "llvm/Pass.h"
+#include "Support/StatisticReporter.h"
+
+static Statistic<> NumMerged("constmerge\t\t- Number of global constants merged");
 
 // mergeDuplicateConstants - Workhorse for the pass.  This eliminates duplicate
 // constants, starting at global ConstantNo, and adds vars to the map if they
@@ -50,6 +53,7 @@ bool mergeDuplicateConstants(Module *M, unsigned &ConstantNo,
         delete GList.remove(GList.begin()+ConstantNo);
 
         --ConstantNo;  // Don't skip the next constant.
+        ++NumMerged;
         MadeChanges = true;
       }
     }
index 99c092263bb4bcda3d27b28b291c5ec4dd453a7b..97cb30cc6d0d10c49daf6c59fa2f3ee3c4675374 100644 (file)
 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
 #include <algorithm>
 #include <iostream>
+#include "Support/StatisticReporter.h"
+
+static Statistic<> NumResolved("funcresolve\t- Number of varargs functions resolved");
+static Statistic<> NumTypeSymtabEntriesKilled("cleangcc\t- Number of unused typenames removed from symtab");
+static Statistic<> NumCastsMoved("cleangcc\t- Number of casts removed from head of basic block");
+static Statistic<> NumRefactoredPreds("cleangcc\t- Number of predecessor blocks refactored");
+
 using std::vector;
 using std::string;
 using std::cerr;
@@ -112,6 +119,7 @@ bool CleanupGCCOutput::doInitialization(Module *M) {
           Plane.erase(PI);          // Alas, GCC 2.95.3 doesn't  *SIGH*
           PI = Plane.begin();
 #endif
+          ++NumTypeSymtabEntriesKilled;
           Changed = true;
         } else {
           ++PI;
@@ -159,6 +167,9 @@ static inline bool FixCastsAndPHIs(BasicBlock *BB) {
       // Move the cast instruction to the current insert position...
       --InsertPos;                 // New position for cast to go...
       std::swap(*InsertPos, *I);   // Cast goes down, PHI goes up
+      Changed = true;
+
+      ++NumCastsMoved;
 
       if (isa<PHINode>(Src) &&                                // Handle case #1
           cast<PHINode>(Src)->getParent() == BB) {
@@ -196,6 +207,7 @@ static inline bool FixCastsAndPHIs(BasicBlock *BB) {
 
         // Reinsert the cast right before the terminator in Pred.
         Pred->getInstList().insert(Pred->end()-1, CI);
+        Changed = true;
       }
     } else {
       ++I;
@@ -281,6 +293,7 @@ bool CleanupGCCOutput::runOnFunction(Function *M) {
       for (unsigned i = 0; i < Preds.size(); ++i) {
         if (SortedPreds[i] == LastOne) {   // Found a duplicate.
           RefactorPredecessor(BB, SortedPreds[i]);
+          ++NumRefactoredPreds;
           Changed = true;
         }
         LastOne = SortedPreds[i];
@@ -430,6 +443,7 @@ bool FunctionResolvingPass::run(Module *M) {
           delete Functions[i];
           Functions.erase(Functions.begin()+i);
           Changed = true;
+          ++NumResolved;
           continue;
         }
       }
@@ -499,11 +513,13 @@ bool FunctionResolvingPass::run(Module *M) {
                 assert(CI->getOperand(0) == Old);
                 CI->setOperand(0, Concrete);
                 Changed = true;
+                ++NumResolved;
               } else if (CallInst *CI = dyn_cast<CallInst>(U)) {
                 // Can only fix up calls TO the argument, not args passed in.
                 if (CI->getCalledValue() == Old) {
                   ConvertCallTo(CI, Concrete);
                   Changed = true;
+                  ++NumResolved;
                 } else {
                   cerr << "Couldn't cleanup this function call, must be an"
                        << " argument or something!" << CI;
index a0614e2bf3130ebcff840498eb3b7b14fe03c4b1..8da9f0481e3fd44956e6772ad375005e70c8fd85 100644 (file)
@@ -11,6 +11,9 @@
 #include "llvm/GlobalVariable.h"
 #include "llvm/Analysis/CallGraph.h"
 #include "Support/DepthFirstIterator.h"
+#include "Support/StatisticReporter.h"
+
+static Statistic<> NumRemoved("globaldce\t- Number of global values removed");
 
 static bool RemoveUnreachableFunctions(Module *M, CallGraph &CallGraph) {
   // Calculate which functions are reachable from the external functions in the
@@ -30,6 +33,7 @@ static bool RemoveUnreachableFunctions(Module *M, CallGraph &CallGraph) {
       (*I)->dropAllReferences();
       N->removeAllCalledMethods();
       FunctionsToDelete.push_back(N);
+      ++NumRemoved;
     }
   }
 
@@ -57,6 +61,7 @@ static bool RemoveUnreachableGlobalVariables(Module *M) {
       ++I;                     // Cannot eliminate global variable
     else {
       delete M->getGlobalList().remove(I);
+      ++NumRemoved;
       Changed = true;
     }
   return Changed;
index 9e84138b08e34d681eb9c316b2f8c42a66e65609..12430e12702f43d9a9ca152ebc3102645d8e9d41 100644 (file)
@@ -27,6 +27,9 @@
 #include "llvm/iOther.h"
 #include "llvm/Type.h"
 #include "llvm/Argument.h"
+#include "Support/StatisticReporter.h"
+
+static Statistic<> NumInlined("inline\t\t- Number of functions inlined");
 #include <algorithm>
 #include <iostream>
 using std::cerr;
@@ -258,6 +261,7 @@ static bool doFunctionInlining(Function *F) {
   // Loop through now and inline instructions a basic block at a time...
   for (Function::iterator I = F->begin(); I != F->end(); )
     if (DoFunctionInlining(*I)) {
+      ++NumInlined;
       Changed = true;
       // Iterator is now invalidated by new basic blocks inserted
       I = F->begin();
index c84be9b93a295ef61a2d0b843cde37eace2bf1c6..279c7eb887a91e0d3d762f3dc38695695c91c451 100644 (file)
@@ -10,6 +10,9 @@
 #include "llvm/Pass.h"
 #include "llvm/Module.h"
 #include "llvm/Function.h"
+#include "Support/StatisticReporter.h"
+
+static Statistic<> NumChanged("internalize\t- Number of functions internal'd");
 
 class InternalizePass : public Pass {
   const char *getPassName() const { return "Internalize Functions"; }
@@ -28,9 +31,12 @@ class InternalizePass : public Pass {
 
     // Found a main function, mark all functions not named main as internal.
     for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
-      if ((*I)->getName() != "main" &&  // Leave the main function external
-          !(*I)->isExternal())          // Function must be defined here
-        (*I)->setInternalLinkage(Changed = true);
+      if ((*I)->getName() != "main" &&   // Leave the main function external
+          !(*I)->isExternal()) {         // Function must be defined here
+        (*I)->setInternalLinkage(true);
+        Changed = true;
+        ++NumChanged;
+      }
 
     return Changed;
   }
index d5730985e8ae885b0a433fce44f9096707d40905..9b56f6a84d1898ca7fb05d9c371db0f1c43e8eae 100644 (file)
@@ -13,6 +13,9 @@
 #include "llvm/iMemory.h"
 #include "llvm/iOther.h"
 #include "llvm/Pass.h"
+#include "Support/StatisticReporter.h"
+
+static Statistic<> NumRaised("raiseallocs\t- Number of allocations raised");
 
 namespace {
 
@@ -91,11 +94,13 @@ bool RaiseAllocations::runOnBasicBlock(BasicBlock *BB) {
         CI->setName("");
         ReplaceInstWithInst(BIL, BI, MallocI);
         Changed = true;
+        ++NumRaised;
         continue;  // Skip the ++BI
       } else if (CI->getCalledValue() == FreeFunc) { // Replace call to free?
         ReplaceInstWithInst(BIL, BI, new FreeInst(CI->getOperand(1)));
         Changed = true;
         continue;  // Skip the ++BI
+        ++NumRaised;
       }
     }
 
index 7598afe32b318e6c47d71241c805e78ac9363de1..013ddc0107c7bcc96f072f0328bf1ba521062bc5 100644 (file)
@@ -19,6 +19,9 @@
 #include "llvm/Support/InstIterator.h"
 #include <set>
 
+#include "Support/StatisticReporter.h"
+static Statistic<> NumInstKilled("constprop - Number of instructions killed");
+
 namespace {
   struct ConstantPropogation : public FunctionPass {
     const char *getPassName() const { return "Simple Constant Propogation"; }
@@ -55,9 +58,10 @@ bool ConstantPropogation::runOnFunction(Function *F) {
         
         // Replace all of the uses of a variable with uses of the constant.
         I->replaceAllUsesWith(C);
-        
+
         // We made a change to the function...
         Changed = true;
+        ++NumInstKilled;
       }
   }
   return Changed;
index 793b3abb6a3adf30d6446f9055f6c5bbb0830d31..2c9c8b3b0d5fcc848dcf965d1c65b62915158b51 100644 (file)
 #include "llvm/Instruction.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/InstIterator.h"
+#include "Support/StatisticReporter.h"
 #include <set>
 
+static Statistic<> DIEEliminated("die\t\t- Number of insts removed");
+static Statistic<> DCEEliminated("dce\t\t- Number of insts removed");
+
 //===----------------------------------------------------------------------===//
 // DeadInstElimination pass implementation
 //
@@ -28,9 +32,10 @@ namespace {
       BasicBlock::InstListType &Vals = BB->getInstList();
       bool Changed = false;
       for (BasicBlock::iterator DI = Vals.begin(); DI != Vals.end(); )
-        if (dceInstruction(Vals, DI))
+        if (dceInstruction(Vals, DI)) {
           Changed = true;
-        else
+          ++DIEEliminated;
+        } else
           ++DI;
       return Changed;
     }
@@ -103,6 +108,7 @@ bool DCE::runOnFunction(Function *F) {
     for (BasicBlock::iterator BI = BBIL.begin(); BI != BBIL.end(); )
       if (DeadInsts.count(*BI)) {            // Is this instruction dead?
         delete BBIL.remove(BI);              // Yup, remove and delete inst
+        ++DCEEliminated;
       } else {                               // This instruction is not dead
         ++BI;                                // Continue on to the next one...
       }
index a97389999e641f0c6efa9e15aa5d7c56300c0615..90301f8792c91eb71de770956181498a3b757817 100644 (file)
@@ -15,6 +15,9 @@
 #include "llvm/iOther.h"
 #include "llvm/BasicBlock.h"
 #include "llvm/Pass.h"
+#include "Support/StatisticReporter.h"
+
+static Statistic<> NumAdded("lowerrefs\t\t- New instructions added");
 
 namespace {
   struct DecomposePass : public BasicBlockPass {
@@ -112,6 +115,7 @@ void DecomposePass::decomposeArrayRef(BasicBlock::iterator &BBI) {
     if (!indexIsZero) {
       LastPtr = new GetElementPtrInst(LastPtr, Indices, "ptr1");
       NewInsts.push_back(cast<Instruction>(LastPtr));
+      ++NumAdded;
     }
       
     // Instruction 2: nextPtr2 = cast nextPtr1 to NextPtrTy
@@ -120,6 +124,7 @@ void DecomposePass::decomposeArrayRef(BasicBlock::iterator &BBI) {
     if (LastPtr->getType() != NextPtrTy) {
       LastPtr = new CastInst(LastPtr, NextPtrTy, "ptr2");
       NewInsts.push_back(cast<Instruction>(LastPtr));
+      ++NumAdded;
     }
   }
   
index 79fed781f93abb38015065fb204d87ee17d7886b..a716caa4a06865379a0d29e0c974fe2ce1b94887 100644 (file)
 #include "llvm/Analysis/Dominators.h"
 #include "llvm/Support/InstVisitor.h"
 #include "llvm/Support/InstIterator.h"
+#include "Support/StatisticReporter.h"
 #include <algorithm>
 
+static Statistic<> NumInstRemoved("gcse\t\t- Number of instructions removed");
+
 namespace {
   class GCSE : public FunctionPass, public InstVisitor<GCSE, bool> {
     set<Instruction*> WorkList;
@@ -131,6 +134,8 @@ void GCSE::CommonSubExpressionFound(Instruction *I, Instruction *Other) {
 
   WorkList.erase(Other); // Other may not actually be on the worklist anymore...
 
+  ++NumInstRemoved;   // Keep track of number of instructions eliminated
+
   // Handle the easy case, where both instructions are in the same basic block
   BasicBlock *BB1 = I->getParent(), *BB2 = Other->getParent();
   if (BB1 == BB2) {
index 5d2cd87725b8e263698f29f6e9e3456905f2fe3f..7b1eb5d7327535c79f240beb8a012f530ef900ac 100644 (file)
 #include "llvm/Constants.h"
 #include "llvm/Support/CFG.h"
 #include "Support/STLExtras.h"
+#include "Support/StatisticReporter.h"
+
+static Statistic<> NumRemoved ("indvars\t\t- Number of aux indvars removed");
+static Statistic<> NumInserted("indvars\t\t- Number of cannonical indvars added");
 
 #if 0
 #define DEBUG
@@ -38,7 +42,8 @@ static bool TransformLoop(LoopInfo *Loops, Loop *Loop) {
                               std::bind1st(std::ptr_fun(TransformLoop), Loops));
   // Get the header node for this loop.  All of the phi nodes that could be
   // induction variables must live in this basic block.
-  BasicBlock *Header = (BasicBlock*)Loop->getBlocks().front();
+  //
+  BasicBlock *Header = Loop->getBlocks().front();
   
   // Loop over all of the PHI nodes in the basic block, calculating the
   // induction variables that they represent... stuffing the induction variable
@@ -107,6 +112,7 @@ static bool TransformLoop(LoopInfo *Loops, Loop *Loop) {
     assert(IndVars.back().InductionType == InductionVariable::Cannonical &&
            "Just inserted cannonical indvar that is not cannonical!");
     Cannonical = &IndVars.back();
+    ++NumInserted;
     Changed = true;
   }
 
@@ -179,20 +185,13 @@ static bool TransformLoop(LoopInfo *Loops, Loop *Loop) {
       delete IV->Phi;
       InsertPos--;            // Deleted an instr, decrement insert position
       Changed = true;
+      ++NumRemoved;
     }
   }
 
   return Changed;
 }
 
-static bool doit(Function *M, LoopInfo &Loops) {
-  // Induction Variables live in the header nodes of the loops of the function
-  return reduce_apply_bool(Loops.getTopLevelLoops().begin(),
-                           Loops.getTopLevelLoops().end(),
-                           std::bind1st(std::ptr_fun(TransformLoop), &Loops));
-}
-
-
 namespace {
   struct InductionVariableSimplify : public FunctionPass {
     const char *getPassName() const {
@@ -200,7 +199,12 @@ namespace {
     }
 
     virtual bool runOnFunction(Function *F) {
-      return doit(F, getAnalysis<LoopInfo>());
+      LoopInfo &LI = getAnalysis<LoopInfo>();
+
+      // Induction Variables live in the header nodes of loops
+      return reduce_apply_bool(LI.getTopLevelLoops().begin(),
+                               LI.getTopLevelLoops().end(),
+                               std::bind1st(std::ptr_fun(TransformLoop), &LI));
     }
     
     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
index 385c07004d4e7d304f2e7634d81edea69c2d7956..0f676426e1ba3cecdbbdb8579d6a978c1a26fc42 100644 (file)
@@ -25,7 +25,9 @@
 #include "llvm/Pass.h"
 #include "llvm/Support/InstIterator.h"
 #include "llvm/Support/InstVisitor.h"
+#include "Support/StatisticReporter.h"
 
+static Statistic<> NumCombined("instcombine\t- Number of insts combined");
 
 namespace {
   class InstCombiner : public FunctionPass,
@@ -547,6 +549,7 @@ bool InstCombiner::runOnFunction(Function *F) {
     // Now that we have an instruction, try combining it to simplify it...
     Instruction *Result = visit(I);
     if (Result) {
+      ++NumCombined;
       // Should we replace the old instruction with a new one?
       if (Result != I)
         ReplaceInstWithInst(I, Result);
index d7bc08b1a4b36f91545902b97e5b22279b71b588..2e9c32800b6189c5d8123cd30228750fafff1374 100644 (file)
@@ -34,6 +34,9 @@
 #include "llvm/iOperators.h"
 #include "llvm/iPHINode.h"
 #include "llvm/Support/CFG.h"
+#include "Support/StatisticReporter.h"
+
+static Statistic<> NumInserted("pinodes\t\t- Number of Pi nodes inserted");
 
 namespace {
   struct PiNodeInserter : public FunctionPass {
@@ -180,6 +183,8 @@ bool PiNodeInserter::insertPiNodeFor(Value *V, BasicBlock *Succ, Value *Rep) {
   if (Rep == 0)
     cast<PHINode>(Pi)->addIncoming(V, Pred);
  
+
+  ++NumInserted;
   return true;
 }
 
index cb7f47b9884fa238fd919ae327b8e30e2f082a23..02ccfee46a958b711ebfc64cef23d36d99acf994 100644 (file)
 #include "llvm/Constant.h"
 #include "llvm/Support/CFG.h"
 #include "Support/PostOrderIterator.h"
+#include "Support/StatisticReporter.h"
+
+static Statistic<> NumChanged("reassociate\t- Number of insts reassociated");
+static Statistic<> NumSwapped("reassociate\t- Number of insts with operands swapped");
 
 namespace {
   class Reassociate : public FunctionPass {
@@ -115,6 +119,7 @@ bool Reassociate::ReassociateExpr(BinaryOperator *I) {
     std::swap(LHS, RHS);
     std::swap(LHSRank, RHSRank);
     Changed = true;
+    ++NumSwapped;
     //cerr << "Transposed: " << I << " Result BB: " << I->getParent();
   }
   
@@ -136,6 +141,7 @@ bool Reassociate::ReassociateExpr(BinaryOperator *I) {
         LHSI->setOperand(TakeOp, RHS);
         I->setOperand(1, LHSI);
 
+        ++NumChanged;
         //cerr << "Reassociated: " << I << " Result BB: " << I->getParent();
 
         // Since we modified the RHS instruction, make sure that we recheck it.
index b936c6f2c89cb268fea91ca789d134182f9f3232..05945458cb6df65f7afd7e904614404b14705110 100644 (file)
 #include "llvm/Pass.h"
 #include "llvm/Support/InstVisitor.h"
 #include "Support/STLExtras.h"
+#include "Support/StatisticReporter.h"
 #include <algorithm>
 #include <set>
 #include <iostream>
 using std::cerr;
 
+static Statistic<> NumInstRemoved("sccp\t\t- Number of instructions removed");
+
 #if 0    // Enable this to get SCCP debug output
 #define DEBUG_SCCP(X) X
 #else
@@ -315,6 +318,7 @@ bool SCCP::runOnFunction(Function *F) {
 
         // Hey, we just changed something!
         MadeChanges = true;
+        ++NumInstRemoved;
       } else {
         ++BI;
       }
index e5bf88fc00caa70bd65abe4956739d57836b2b3a..80eab61b7587a863554fccfe058681b3e260ae30 100644 (file)
@@ -15,6 +15,9 @@
 #include "llvm/Constants.h"
 #include "llvm/Pass.h"
 #include "llvm/Target/TargetData.h"
+#include "Support/StatisticReporter.h"
+
+static Statistic<> NumLowered("lowerallocs\t- Number of allocations lowered");
 using std::vector;
 
 namespace {
@@ -81,7 +84,7 @@ bool LowerAllocations::runOnBasicBlock(BasicBlock *BB) {
   assert(MallocFunc && FreeFunc && BB && "Pass not initialized!");
 
   // Loop over all of the instructions, looking for malloc or free instructions
-  for (unsigned i = 0; i < BB->size(); ++i) {
+  for (unsigned i = 0; i != BB->size(); ++i) {
     BasicBlock::InstListType &BBIL = BB->getInstList();
     if (MallocInst *MI = dyn_cast<MallocInst>(*(BBIL.begin()+i))) {
       BBIL.remove(BBIL.begin()+i);   // remove the malloc instr...
@@ -116,6 +119,7 @@ bool LowerAllocations::runOnBasicBlock(BasicBlock *BB) {
       MI->replaceAllUsesWith(MCast);
       delete MI;                          // Delete the malloc inst
       Changed = true;
+      ++NumLowered;
     } else if (FreeInst *FI = dyn_cast<FreeInst>(*(BBIL.begin()+i))) {
       BBIL.remove(BB->getInstList().begin()+i);
       
@@ -132,6 +136,7 @@ bool LowerAllocations::runOnBasicBlock(BasicBlock *BB) {
       // Delete the old free instruction
       delete FI;
       Changed = true;
+      ++NumLowered;
     }
   }
 
index f67e6d671fa9d0ccab5625d3b0e511d24b13ac26..1afb11a986f8e2ad6bd6c933d9f3fce92cc7f942 100644 (file)
@@ -26,6 +26,9 @@
 #include "llvm/BasicBlock.h"
 #include "llvm/Constant.h"
 #include "llvm/Type.h"
+#include "Support/StatisticReporter.h"
+
+static Statistic<> NumPromoted("mem2reg\t\t- Number of alloca's promoted");
 
 using std::vector;
 using std::map;
@@ -187,6 +190,8 @@ bool PromotePass::runOnFunction(Function *F) {
     delete I;
   }
 
+  NumPromoted += Allocas.size();
+
   // Purge data structurse so they are available the next iteration...
   Allocas.clear();
   AllocaLookup.clear();