Add some statistics to SSI so we can see what it's up to.
authorNick Lewycky <nicholas@mxc.ca>
Thu, 9 Jul 2009 15:33:14 +0000 (15:33 +0000)
committerNick Lewycky <nicholas@mxc.ca>
Thu, 9 Jul 2009 15:33:14 +0000 (15:33 +0000)
Add an -ssi-everything pass which calls createSSI on everything in the function.

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

lib/Transforms/Utils/SSI.cpp

index 4c4dd37ddf754b7ce0f050a16e802827bbe9e5c7..caafb318e8b3c0f8a46241600ff31ca8c5d4ce69 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "llvm/Transforms/Scalar.h"
 #include "llvm/Transforms/Utils/SSI.h"
+#include "llvm/ADT/Statistic.h"
 #include "llvm/Analysis/Dominators.h"
 
 using namespace llvm;
@@ -32,6 +33,9 @@ static const std::string SSI_SIG = "SSI_sigma";
 
 static const unsigned UNSIGNED_INFINITE = ~0U;
 
+STATISTIC(NumSigmaInserted, "Number of sigma functions inserted");
+STATISTIC(NumPhiInserted, "Number of phi functions inserted");
+
 void SSI::getAnalysisUsage(AnalysisUsage &AU) const {
   AU.addRequired<DominanceFrontier>();
   AU.addRequired<DominatorTree>();
@@ -100,6 +104,7 @@ void SSI::insertSigmaFunctions(SmallVectorImpl<Instruction *> &value) {
             created.insert(PN);
             need = true;
             defsites[i].push_back(BB_next);
+            ++NumSigmaInserted;
           }
         }
       }
@@ -143,6 +148,7 @@ void SSI::insertPhiFunctions(SmallVectorImpl<Instruction *> &value) {
             created.insert(PN);
 
             defsites[i].push_back(BB_dominated);
+            ++NumPhiInserted;
           }
         }
       }
@@ -388,3 +394,40 @@ FunctionPass *llvm::createSSIPass() { return new SSI(); }
 char SSI::ID = 0;
 static RegisterPass<SSI> X("ssi", "Static Single Information Construction");
 
+/// SSIEverything - A pass that runs createSSI on every non-void variable,
+/// intended for debugging.
+namespace {
+  struct VISIBILITY_HIDDEN SSIEverything : public FunctionPass {
+    static char ID; // Pass identification, replacement for typeid
+    SSIEverything() : FunctionPass((intptr_t)&ID) {}
+
+    bool runOnFunction(Function &F);
+
+    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
+      AU.addRequired<SSI>();
+    }
+  };
+}
+
+bool SSIEverything::runOnFunction(Function &F) {
+  SmallVector<Instruction *, 16> Insts;
+  SSI &ssi = getAnalysis<SSI>();
+
+  if (F.isDeclaration() || F.isIntrinsic()) return false;
+
+  for (Function::iterator B = F.begin(), BE = F.end(); B != BE; ++B)
+    for (BasicBlock::iterator I = B->begin(), E = B->end(); I != E; ++I)
+      if (I->getType() != Type::VoidTy)
+        Insts.push_back(I);
+
+  ssi.createSSI(Insts);
+  return true;
+}
+
+/// createSSIEverythingPass - The public interface to this file...
+///
+FunctionPass *llvm::createSSIEverythingPass() { return new SSIEverything(); }
+
+char SSIEverything::ID = 0;
+static RegisterPass<SSIEverything>
+Y("ssi-everything", "Static Single Information Construction");