* Standardize how analysis results/passes as printed with the print() virtual
  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
diff --git a/include/llvm/Analysis/DataStructure.h b/include/llvm/Analysis/DataStructure.h
index c611574..dda0adb 100644
--- a/include/llvm/Analysis/DataStructure.h
+++ b/include/llvm/Analysis/DataStructure.h
@@ -342,7 +342,7 @@
   }
 
   // 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();
@@ -377,7 +377,7 @@
   }
   
   // 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();
@@ -419,7 +419,7 @@
   }
 
   // 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();
diff --git a/include/llvm/Analysis/DataStructure/DataStructure.h b/include/llvm/Analysis/DataStructure/DataStructure.h
index c611574..dda0adb 100644
--- a/include/llvm/Analysis/DataStructure/DataStructure.h
+++ b/include/llvm/Analysis/DataStructure/DataStructure.h
@@ -342,7 +342,7 @@
   }
 
   // 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();
@@ -377,7 +377,7 @@
   }
   
   // 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();
@@ -419,7 +419,7 @@
   }
 
   // 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();
diff --git a/include/llvm/Analysis/Dominators.h b/include/llvm/Analysis/Dominators.h
index 154b31d..8c9df64 100644
--- a/include/llvm/Analysis/Dominators.h
+++ b/include/llvm/Analysis/Dominators.h
@@ -82,6 +82,9 @@
     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.
   //
@@ -157,6 +160,9 @@
     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 @@
     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 @@
   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;
 };
 
 
diff --git a/include/llvm/Analysis/FindUnsafePointerTypes.h b/include/llvm/Analysis/FindUnsafePointerTypes.h
index 038d763..59fc78e 100644
--- a/include/llvm/Analysis/FindUnsafePointerTypes.h
+++ b/include/llvm/Analysis/FindUnsafePointerTypes.h
@@ -39,10 +39,9 @@
   //
   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...
   //
diff --git a/include/llvm/Analysis/FindUsedTypes.h b/include/llvm/Analysis/FindUsedTypes.h
index 4888dda..2f3e81c 100644
--- a/include/llvm/Analysis/FindUsedTypes.h
+++ b/include/llvm/Analysis/FindUsedTypes.h
@@ -29,7 +29,7 @@
   // 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
diff --git a/include/llvm/Analysis/InductionVariable.h b/include/llvm/Analysis/InductionVariable.h
index 951ac05..36dcaeb 100644
--- a/include/llvm/Analysis/InductionVariable.h
+++ b/include/llvm/Analysis/InductionVariable.h
@@ -19,6 +19,7 @@
 #ifndef LLVM_ANALYSIS_INDUCTIONVARIABLE_H
 #define LLVM_ANALYSIS_INDUCTIONVARIABLE_H
 
+#include <iosfwd>
 class Value;
 class PHINode;
 class Instruction;
@@ -45,6 +46,8 @@
   // Classify Induction
   static enum iType Classify(const Value *Start, const Value *Step,
 			     const Loop *L = 0);
+
+  void print(std::ostream &OS) const;
 };
 
 #endif
diff --git a/include/llvm/Analysis/Interval.h b/include/llvm/Analysis/Interval.h
index b297441..13a6f45 100644
--- a/include/llvm/Analysis/Interval.h
+++ b/include/llvm/Analysis/Interval.h
@@ -14,6 +14,7 @@
 #define LLVM_INTERVAL_H
 
 #include <vector>
+#include <iosfwd>
 
 class BasicBlock;
 
@@ -85,6 +86,9 @@
 
   // 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
diff --git a/include/llvm/Analysis/IntervalPartition.h b/include/llvm/Analysis/IntervalPartition.h
index f21083f..4fd388e 100644
--- a/include/llvm/Analysis/IntervalPartition.h
+++ b/include/llvm/Analysis/IntervalPartition.h
@@ -51,6 +51,9 @@
   // 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; }
diff --git a/include/llvm/Analysis/LoopInfo.h b/include/llvm/Analysis/LoopInfo.h
index 03eda29..ae150d4 100644
--- a/include/llvm/Analysis/LoopInfo.h
+++ b/include/llvm/Analysis/LoopInfo.h
@@ -40,6 +40,7 @@
   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; }
@@ -105,6 +106,7 @@
   virtual bool runOnFunction(Function &F);
 
   virtual void releaseMemory();
+  void print(std::ostream &O) const;
 
   // 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
index b005094..0000000
--- a/include/llvm/Analysis/Writer.h
+++ /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
diff --git a/lib/Analysis/DataStructure/BottomUpClosure.cpp b/lib/Analysis/DataStructure/BottomUpClosure.cpp
index 62206d9..c8b45b5 100644
--- a/lib/Analysis/DataStructure/BottomUpClosure.cpp
+++ b/lib/Analysis/DataStructure/BottomUpClosure.cpp
@@ -15,7 +15,7 @@
 
 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...
diff --git a/lib/Analysis/DataStructure/DataStructure.cpp b/lib/Analysis/DataStructure/DataStructure.cpp
index f573a0b..5d62f09 100644
--- a/lib/Analysis/DataStructure/DataStructure.cpp
+++ b/lib/Analysis/DataStructure/DataStructure.cpp
@@ -15,10 +15,6 @@
 
 using std::vector;
 
-static RegisterAnalysis<LocalDataStructures>
-X("datastructure", "Local Data Structure Analysis");
-AnalysisID LocalDataStructures::ID(AnalysisID::create<LocalDataStructures>());
-
 //===----------------------------------------------------------------------===//
 // DSNode Implementation
 //===----------------------------------------------------------------------===//
diff --git a/lib/Analysis/DataStructure/Local.cpp b/lib/Analysis/DataStructure/Local.cpp
index 6ce3ae0..296195c 100644
--- a/lib/Analysis/DataStructure/Local.cpp
+++ b/lib/Analysis/DataStructure/Local.cpp
@@ -18,6 +18,10 @@
 using std::map;
 using std::vector;
 
+static RegisterAnalysis<LocalDataStructures>
+X("datastructure", "Local Data Structure Analysis");
+AnalysisID LocalDataStructures::ID = X;
+
 //===----------------------------------------------------------------------===//
 //  GraphBuilder Class
 //===----------------------------------------------------------------------===//
diff --git a/lib/Analysis/DataStructure/Printer.cpp b/lib/Analysis/DataStructure/Printer.cpp
index 4a58c69..03ce297 100644
--- a/lib/Analysis/DataStructure/Printer.cpp
+++ b/lib/Analysis/DataStructure/Printer.cpp
@@ -147,16 +147,21 @@
 }
 
 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()) {
-        DSGraph &Graph = C.getDSGraph(*I);
+        DSGraph &Graph = C.getDSGraph((Function&)*I);
         Graph.print(F);
         O << " [" << Graph.getGraphSize() << "+"
           << Graph.getFunctionCalls().size() << "]\n";
@@ -168,10 +173,10 @@
 
 
 // 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");
 }
 
-void BUDataStructures::print(std::ostream &O, Module *M) const {
+void BUDataStructures::print(std::ostream &O, const Module *M) const {
   printCollection(*this, O, M, "bu");
 }
diff --git a/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp b/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp
index e730f49..3acef1b 100644
--- a/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp
+++ b/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp
@@ -17,7 +17,7 @@
 
 static RegisterAnalysis<FunctionLiveVarInfo>
 X("livevar", "Live Variable Analysis");
-AnalysisID FunctionLiveVarInfo::ID(AnalysisID::create<FunctionLiveVarInfo>());
+AnalysisID FunctionLiveVarInfo::ID = X;
 
 LiveVarDebugLevel_t DEBUG_LV;
 
diff --git a/lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.cpp b/lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.cpp
index e730f49..3acef1b 100644
--- a/lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.cpp
+++ b/lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.cpp
@@ -17,7 +17,7 @@
 
 static RegisterAnalysis<FunctionLiveVarInfo>
 X("livevar", "Live Variable Analysis");
-AnalysisID FunctionLiveVarInfo::ID(AnalysisID::create<FunctionLiveVarInfo>());
+AnalysisID FunctionLiveVarInfo::ID = X;
 
 LiveVarDebugLevel_t DEBUG_LV;
 
diff --git a/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp b/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp
index d3e20ac..caa29fd 100644
--- a/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp
+++ b/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp
@@ -15,10 +15,9 @@
 #include "llvm/Type.h"
 using std::vector;
 
-AnalysisID UnifyFunctionExitNodes::ID(AnalysisID::create<UnifyFunctionExitNodes>());
-
 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