* Standardize how analysis results/passes as printed with the print() virtual
authorChris Lattner <sabre@nondot.org>
Sat, 27 Jul 2002 01:12:15 +0000 (01:12 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 27 Jul 2002 01:12:15 +0000 (01:12 +0000)
  methods
* Eliminate AnalysisID:  Now it is just a typedef for const PassInfo*
* Simplify how AnalysisID's are initialized
* Eliminate Analysis/Writer.cpp/.h: incorporate printing functionality into
  the analyses themselves.

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

17 files changed:
include/llvm/Analysis/DataStructure.h
include/llvm/Analysis/DataStructure/DataStructure.h
include/llvm/Analysis/Dominators.h
include/llvm/Analysis/FindUnsafePointerTypes.h
include/llvm/Analysis/FindUsedTypes.h
include/llvm/Analysis/InductionVariable.h
include/llvm/Analysis/Interval.h
include/llvm/Analysis/IntervalPartition.h
include/llvm/Analysis/LoopInfo.h
include/llvm/Analysis/Writer.h [deleted file]
lib/Analysis/DataStructure/BottomUpClosure.cpp
lib/Analysis/DataStructure/DataStructure.cpp
lib/Analysis/DataStructure/Local.cpp
lib/Analysis/DataStructure/Printer.cpp
lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp
lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.cpp
lib/Transforms/Utils/UnifyFunctionExitNodes.cpp

index c611574eadfc426568575044278bcec7587e3635..dda0adb214ed90c390437c606de95351bc9ccfc2 100644 (file)
@@ -342,7 +342,7 @@ public:
   }
 
   // print - Print out the analysis results...
   }
 
   // print - Print out the analysis results...
-  void print(std::ostream &O, Module *M) const;
+  void print(std::ostream &O, const Module *M) const;
 
   // If the pass pipeline is done with this pass, we can release our memory...
   virtual void releaseMemory();
 
   // If the pass pipeline is done with this pass, we can release our memory...
   virtual void releaseMemory();
@@ -377,7 +377,7 @@ public:
   }
   
   // print - Print out the analysis results...
   }
   
   // print - Print out the analysis results...
-  void print(std::ostream &O, Module *M) const;
+  void print(std::ostream &O, const Module *M) const;
 
   // If the pass pipeline is done with this pass, we can release our memory...
   virtual void releaseMemory();
 
   // If the pass pipeline is done with this pass, we can release our memory...
   virtual void releaseMemory();
@@ -419,7 +419,7 @@ public:
   }
 
   // print - Print out the analysis results...
   }
 
   // print - Print out the analysis results...
-  void print(std::ostream &O, Module *M) const;
+  void print(std::ostream &O, const Module *M) const;
 
   // If the pass pipeline is done with this pass, we can release our memory...
   virtual void releaseMemory();
 
   // If the pass pipeline is done with this pass, we can release our memory...
   virtual void releaseMemory();
index c611574eadfc426568575044278bcec7587e3635..dda0adb214ed90c390437c606de95351bc9ccfc2 100644 (file)
@@ -342,7 +342,7 @@ public:
   }
 
   // print - Print out the analysis results...
   }
 
   // print - Print out the analysis results...
-  void print(std::ostream &O, Module *M) const;
+  void print(std::ostream &O, const Module *M) const;
 
   // If the pass pipeline is done with this pass, we can release our memory...
   virtual void releaseMemory();
 
   // If the pass pipeline is done with this pass, we can release our memory...
   virtual void releaseMemory();
@@ -377,7 +377,7 @@ public:
   }
   
   // print - Print out the analysis results...
   }
   
   // print - Print out the analysis results...
-  void print(std::ostream &O, Module *M) const;
+  void print(std::ostream &O, const Module *M) const;
 
   // If the pass pipeline is done with this pass, we can release our memory...
   virtual void releaseMemory();
 
   // If the pass pipeline is done with this pass, we can release our memory...
   virtual void releaseMemory();
@@ -419,7 +419,7 @@ public:
   }
 
   // print - Print out the analysis results...
   }
 
   // print - Print out the analysis results...
-  void print(std::ostream &O, Module *M) const;
+  void print(std::ostream &O, const Module *M) const;
 
   // If the pass pipeline is done with this pass, we can release our memory...
   virtual void releaseMemory();
 
   // If the pass pipeline is done with this pass, we can release our memory...
   virtual void releaseMemory();
index 154b31ddd5a44d5e52e3c9049e573fa74827e354..8c9df644513e919b191d53164e256c448573931c 100644 (file)
@@ -82,6 +82,9 @@ public:
     return getDominators(B).count(A) != 0;
   }
 
     return getDominators(B).count(A) != 0;
   }
 
+  // print - Convert to human readable form
+  virtual void print(std::ostream &OS) const;
+
   // dominates - Return true if A dominates B.  This performs the special checks
   // neccesary if A and B are in the same basic block.
   //
   // dominates - Return true if A dominates B.  This performs the special checks
   // neccesary if A and B are in the same basic block.
   //
@@ -157,6 +160,9 @@ public:
     std::map<BasicBlock*, BasicBlock*>::const_iterator I = IDoms.find(BB);
     return I != IDoms.end() ? I->second : 0;
   }
     std::map<BasicBlock*, BasicBlock*>::const_iterator I = IDoms.find(BB);
     return I != IDoms.end() ? I->second : 0;
   }
+
+  // print - Convert to human readable form
+  virtual void print(std::ostream &OS) const;
 };
 
 //===-------------------------------------
 };
 
 //===-------------------------------------
@@ -259,6 +265,9 @@ public:
     NodeMapType::const_iterator i = Nodes.find(BB);
     return (i != Nodes.end()) ? i->second : 0;
   }
     NodeMapType::const_iterator i = Nodes.find(BB);
     return (i != Nodes.end()) ? i->second : 0;
   }
+
+  // print - Convert to human readable form
+  virtual void print(std::ostream &OS) const;
 };
 
 
 };
 
 
@@ -336,6 +345,9 @@ public:
   inline const_iterator begin() const { return Frontiers.begin(); }
   inline const_iterator end()   const { return Frontiers.end(); }
   inline const_iterator find(BasicBlock* B) const { return Frontiers.find(B); }
   inline const_iterator begin() const { return Frontiers.begin(); }
   inline const_iterator end()   const { return Frontiers.end(); }
   inline const_iterator find(BasicBlock* B) const { return Frontiers.find(B); }
+
+  // print - Convert to human readable form
+  virtual void print(std::ostream &OS) const;
 };
 
 
 };
 
 
index 038d7639c3b5b96e7baf42cacf0e5da75d046876..59fc78e3f78287f093f97377a12e2a3ecb4f016f 100644 (file)
@@ -39,10 +39,9 @@ public:
   //
   virtual bool run(Module &M);
 
   //
   virtual bool run(Module &M);
 
-  // printResults - Loop over the results of the analysis, printing out unsafe
-  // types.
+  // print - Loop over the results of the analysis, printing out unsafe types.
   //
   //
-  void printResults(const Module *Mod, std::ostream &o) const;
+  void print(std::ostream &o, const Module *Mod) const;
 
   // getAnalysisUsage - Of course, we provide ourself...
   //
 
   // getAnalysisUsage - Of course, we provide ourself...
   //
index 4888dda39359cf5cdc08f56e43f3d573c14fb3e1..2f3e81c5a68fe26be13dc3422b1414c42341b28d 100644 (file)
@@ -29,7 +29,7 @@ public:
   // passed in, then the types are printed symbolically if possible, using the
   // symbol table from the module.
   //
   // passed in, then the types are printed symbolically if possible, using the
   // symbol table from the module.
   //
-  void printTypes(std::ostream &o, const Module *M = 0) const;
+  void print(std::ostream &o, const Module *M) const;
 
 private:
   // IncorporateType - Incorporate one type and all of its subtypes into the
 
 private:
   // IncorporateType - Incorporate one type and all of its subtypes into the
index 951ac05135214ffc2f54dbf81ea5ad82e68a7ec6..36dcaebda00e01e51597317a547f7ddd6258a691 100644 (file)
@@ -19,6 +19,7 @@
 #ifndef LLVM_ANALYSIS_INDUCTIONVARIABLE_H
 #define LLVM_ANALYSIS_INDUCTIONVARIABLE_H
 
 #ifndef LLVM_ANALYSIS_INDUCTIONVARIABLE_H
 #define LLVM_ANALYSIS_INDUCTIONVARIABLE_H
 
+#include <iosfwd>
 class Value;
 class PHINode;
 class Instruction;
 class Value;
 class PHINode;
 class Instruction;
@@ -45,6 +46,8 @@ public:
   // Classify Induction
   static enum iType Classify(const Value *Start, const Value *Step,
                             const Loop *L = 0);
   // Classify Induction
   static enum iType Classify(const Value *Start, const Value *Step,
                             const Loop *L = 0);
+
+  void print(std::ostream &OS) const;
 };
 
 #endif
 };
 
 #endif
index b297441ecae8574c8d2582cff08b3da53a6e0dea..13a6f45e86040afc7a5800731eb1937cb11d5001 100644 (file)
@@ -14,6 +14,7 @@
 #define LLVM_INTERVAL_H
 
 #include <vector>
 #define LLVM_INTERVAL_H
 
 #include <vector>
+#include <iosfwd>
 
 class BasicBlock;
 
 
 class BasicBlock;
 
@@ -85,6 +86,9 @@ public:
 
   // isLoop - Find out if there is a back edge in this interval...
   bool isLoop() const;
 
   // isLoop - Find out if there is a back edge in this interval...
   bool isLoop() const;
+
+  // print - Show contents in human readable format...
+  void print(std::ostream &O) const;
 };
 
 // succ_begin/succ_end - define methods so that Intervals may be used
 };
 
 // succ_begin/succ_end - define methods so that Intervals may be used
index f21083f3bb400fc63515a70660b912cdc4811a12..4fd388e7c812e45518b708ad465890e9444b4ba4 100644 (file)
@@ -51,6 +51,9 @@ public:
   // Destructor - Free memory
   ~IntervalPartition() { destroy(); }
 
   // Destructor - Free memory
   ~IntervalPartition() { destroy(); }
 
+  // print - Show contents in human readable format...
+  virtual void print(std::ostream &O) const;
+
   // getRootInterval() - Return the root interval that contains the starting
   // block of the function.
   inline Interval *getRootInterval() { return RootInterval; }
   // getRootInterval() - Return the root interval that contains the starting
   // block of the function.
   inline Interval *getRootInterval() { return RootInterval; }
index 03eda2973a4e6406ceff81646b61fc40b982c82c..ae150d4619b674662d613fd02a17ff1d095bdb6d 100644 (file)
@@ -40,6 +40,7 @@ public:
   inline const std::vector<Loop*> &getSubLoops() const { return SubLoops; }
   inline const std::vector<BasicBlock*> &getBlocks() const { return Blocks; }
 
   inline const std::vector<Loop*> &getSubLoops() const { return SubLoops; }
   inline const std::vector<BasicBlock*> &getBlocks() const { return Blocks; }
 
+  void print(std::ostream &O) const;
 private:
   friend class LoopInfo;
   inline Loop(BasicBlock *BB) { Blocks.push_back(BB); LoopDepth = 0; }
 private:
   friend class LoopInfo;
   inline Loop(BasicBlock *BB) { Blocks.push_back(BB); LoopDepth = 0; }
@@ -105,6 +106,7 @@ public:
   virtual bool runOnFunction(Function &F);
 
   virtual void releaseMemory();
   virtual bool runOnFunction(Function &F);
 
   virtual void releaseMemory();
+  void print(std::ostream &O) const;
 
   // getAnalysisUsage - Provide loop info, require dominator set
   //
 
   // getAnalysisUsage - Provide loop info, require dominator set
   //
diff --git a/include/llvm/Analysis/Writer.h b/include/llvm/Analysis/Writer.h
deleted file mode 100644 (file)
index b005094..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-//===-- llvm/Analysis/Writer.h - Printer for Analysis routines ---*- C++ -*--=//
-//
-// This library provides routines to print out various analysis results to 
-// an output stream.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_ANALYSIS_WRITER_H
-#define LLVM_ANALYSIS_WRITER_H
-
-#include <iosfwd>
-
-// This library provides support for printing out Intervals.
-class Interval;
-class IntervalPartition;
-
-void WriteToOutput(const Interval *I, std::ostream &o);
-inline std::ostream &operator <<(std::ostream &o, const Interval *I) {
-  WriteToOutput(I, o); return o;
-}
-
-void WriteToOutput(const IntervalPartition &IP, std::ostream &o);
-inline std::ostream &operator <<(std::ostream &o,
-                                 const IntervalPartition &IP) {
-  WriteToOutput(IP, o); return o;
-}
-
-// Stuff for printing out Dominator data structures...
-class DominatorSetBase;
-class ImmediateDominatorsBase;
-class DominatorTreeBase;
-class DominanceFrontierBase;
-
-void WriteToOutput(const DominatorSetBase &, std::ostream &o);
-inline std::ostream &operator <<(std::ostream &o, const DominatorSetBase &DS) {
-  WriteToOutput(DS, o); return o;
-}
-
-void WriteToOutput(const ImmediateDominatorsBase &, std::ostream &o);
-inline std::ostream &operator <<(std::ostream &o,
-                                 const ImmediateDominatorsBase &ID) {
-  WriteToOutput(ID, o); return o;
-}
-
-void WriteToOutput(const DominatorTreeBase &, std::ostream &o);
-inline std::ostream &operator <<(std::ostream &o, const DominatorTreeBase &DT) {
-  WriteToOutput(DT, o); return o;
-}
-
-void WriteToOutput(const DominanceFrontierBase &, std::ostream &o);
-inline std::ostream &operator <<(std::ostream &o,
-                                 const DominanceFrontierBase &DF) {
-  WriteToOutput(DF, o); return o;
-}
-
-// Stuff for printing out Loop information
-class Loop;
-class LoopInfo;
-
-void WriteToOutput(const LoopInfo &, std::ostream &o);
-inline std::ostream &operator <<(std::ostream &o, const LoopInfo &LI) {
-  WriteToOutput(LI, o); return o;
-}
-
-void WriteToOutput(const Loop *, std::ostream &o);
-inline std::ostream &operator <<(std::ostream &o, const Loop *L) {
-  WriteToOutput(L, o); return o;
-}
-
-class InductionVariable;
-void WriteToOutput(const InductionVariable &, std::ostream &o);
-inline std::ostream &operator <<(std::ostream &o, const InductionVariable &IV) {
-  WriteToOutput(IV, o); return o;
-}
-
-#endif
index 62206d9b0e9fe65b05672ae79947e3474ac89a56..c8b45b50ccd6bacb653d1b35dfa47204282869a5 100644 (file)
@@ -15,7 +15,7 @@ using std::map;
 
 static RegisterAnalysis<BUDataStructures>
 X("budatastructure", "Bottom-Up Data Structure Analysis Closure");
 
 static RegisterAnalysis<BUDataStructures>
 X("budatastructure", "Bottom-Up Data Structure Analysis Closure");
-AnalysisID BUDataStructures::ID(AnalysisID::create<BUDataStructures>());
+AnalysisID BUDataStructures::ID = X;
 
 // releaseMemory - If the pass pipeline is done with this pass, we can release
 // our memory... here...
 
 // releaseMemory - If the pass pipeline is done with this pass, we can release
 // our memory... here...
index f573a0be1a639e05d30caf1d6aee9b81b34d47c5..5d62f0907300cbefdf7709f739f898769598b673 100644 (file)
 
 using std::vector;
 
 
 using std::vector;
 
-static RegisterAnalysis<LocalDataStructures>
-X("datastructure", "Local Data Structure Analysis");
-AnalysisID LocalDataStructures::ID(AnalysisID::create<LocalDataStructures>());
-
 //===----------------------------------------------------------------------===//
 // DSNode Implementation
 //===----------------------------------------------------------------------===//
 //===----------------------------------------------------------------------===//
 // DSNode Implementation
 //===----------------------------------------------------------------------===//
index 6ce3ae085807eff3f24015c1adcdbed18bb034e0..296195cb1f9942a43e6f158aedefd81bfd874284 100644 (file)
 using std::map;
 using std::vector;
 
 using std::map;
 using std::vector;
 
+static RegisterAnalysis<LocalDataStructures>
+X("datastructure", "Local Data Structure Analysis");
+AnalysisID LocalDataStructures::ID = X;
+
 //===----------------------------------------------------------------------===//
 //  GraphBuilder Class
 //===----------------------------------------------------------------------===//
 //===----------------------------------------------------------------------===//
 //  GraphBuilder Class
 //===----------------------------------------------------------------------===//
index 4a58c69afd3dfe6ccb6d4ac100a72257c26d0ec0..03ce297c4a9dad198e1297b7266724743b85e93f 100644 (file)
@@ -147,16 +147,21 @@ void DSGraph::print(std::ostream &O) const {
 }
 
 template <typename Collection>
 }
 
 template <typename Collection>
-static void printCollection(const Collection &C, std::ostream &O, Module *M,
-                            const string &Prefix) {
-  for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
+static void printCollection(const Collection &C, std::ostream &O,
+                            const Module *M, const string &Prefix) {
+  if (M == 0) {
+    O << "Null Module pointer, cannot continue!\n";
+    return;
+  }
+
+  for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I)
     if (!I->isExternal()) {
       string Filename = Prefix + "." + I->getName() + ".dot";
       O << "Writing '" << Filename << "'...";
       std::ofstream F(Filename.c_str());
       
       if (F.good()) {
     if (!I->isExternal()) {
       string Filename = Prefix + "." + I->getName() + ".dot";
       O << "Writing '" << Filename << "'...";
       std::ofstream F(Filename.c_str());
       
       if (F.good()) {
-        DSGraph &Graph = C.getDSGraph(*I);
+        DSGraph &Graph = C.getDSGraph((Function&)*I);
         Graph.print(F);
         O << " [" << Graph.getGraphSize() << "+"
           << Graph.getFunctionCalls().size() << "]\n";
         Graph.print(F);
         O << " [" << Graph.getGraphSize() << "+"
           << Graph.getFunctionCalls().size() << "]\n";
@@ -168,10 +173,10 @@ static void printCollection(const Collection &C, std::ostream &O, Module *M,
 
 
 // print - Print out the analysis results...
 
 
 // print - Print out the analysis results...
-void LocalDataStructures::print(std::ostream &O, Module *M) const {
+void LocalDataStructures::print(std::ostream &O, const Module *M) const {
   printCollection(*this, O, M, "ds");
 }
 
   printCollection(*this, O, M, "ds");
 }
 
-void BUDataStructures::print(std::ostream &O, Module *M) const {
+void BUDataStructures::print(std::ostream &O, const Module *M) const {
   printCollection(*this, O, M, "bu");
 }
   printCollection(*this, O, M, "bu");
 }
index e730f49e692d3121711f0fe46002eb3108bb5dec..3acef1bfd189459ba54823f39a18369b688c81ef 100644 (file)
@@ -17,7 +17,7 @@
 
 static RegisterAnalysis<FunctionLiveVarInfo>
 X("livevar", "Live Variable Analysis");
 
 static RegisterAnalysis<FunctionLiveVarInfo>
 X("livevar", "Live Variable Analysis");
-AnalysisID FunctionLiveVarInfo::ID(AnalysisID::create<FunctionLiveVarInfo>());
+AnalysisID FunctionLiveVarInfo::ID = X;
 
 LiveVarDebugLevel_t DEBUG_LV;
 
 
 LiveVarDebugLevel_t DEBUG_LV;
 
index e730f49e692d3121711f0fe46002eb3108bb5dec..3acef1bfd189459ba54823f39a18369b688c81ef 100644 (file)
@@ -17,7 +17,7 @@
 
 static RegisterAnalysis<FunctionLiveVarInfo>
 X("livevar", "Live Variable Analysis");
 
 static RegisterAnalysis<FunctionLiveVarInfo>
 X("livevar", "Live Variable Analysis");
-AnalysisID FunctionLiveVarInfo::ID(AnalysisID::create<FunctionLiveVarInfo>());
+AnalysisID FunctionLiveVarInfo::ID = X;
 
 LiveVarDebugLevel_t DEBUG_LV;
 
 
 LiveVarDebugLevel_t DEBUG_LV;
 
index d3e20ac8353e26908c1dd17a4dfe9e13246dc57c..caa29fdd152e64a97157048e6fd39fabd51fa6cd 100644 (file)
 #include "llvm/Type.h"
 using std::vector;
 
 #include "llvm/Type.h"
 using std::vector;
 
-AnalysisID UnifyFunctionExitNodes::ID(AnalysisID::create<UnifyFunctionExitNodes>());
-
 static RegisterOpt<UnifyFunctionExitNodes>
 X("mergereturn", "Unify function exit nodes");
 static RegisterOpt<UnifyFunctionExitNodes>
 X("mergereturn", "Unify function exit nodes");
+AnalysisID UnifyFunctionExitNodes::ID = X;
 
 // UnifyAllExitNodes - Unify all exit nodes of the CFG by creating a new
 // BasicBlock, and converting all returns to unconditional branches to this
 
 // UnifyAllExitNodes - Unify all exit nodes of the CFG by creating a new
 // BasicBlock, and converting all returns to unconditional branches to this