eliminate the std::ostream form of WriteAsOperand and update clients.
authorChris Lattner <sabre@nondot.org>
Sun, 23 Aug 2009 05:17:37 +0000 (05:17 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 23 Aug 2009 05:17:37 +0000 (05:17 +0000)
This also updates dominator related stuff.

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

16 files changed:
include/llvm/Analysis/AliasSetTracker.h
include/llvm/Analysis/Dominators.h
include/llvm/Analysis/LoopInfo.h
include/llvm/Analysis/PostDominators.h
include/llvm/Assembly/Writer.h
include/llvm/CodeGen/MachineDominators.h
lib/Analysis/AliasAnalysisCounter.cpp
lib/Analysis/AliasAnalysisEvaluator.cpp
lib/Analysis/AliasSetTracker.cpp
lib/Analysis/LoopInfo.cpp
lib/Analysis/PostDominators.cpp
lib/CodeGen/MachineDominators.cpp
lib/Transforms/Scalar/PredicateSimplifier.cpp
lib/VMCore/AsmWriter.cpp
lib/VMCore/Dominators.cpp
lib/VMCore/Verifier.cpp

index 1fb4c8f24721e4607d1b1780d733fb9a389302f6..82c6f392d05115a2ad456b245b2ae61d65e3a82a 100644 (file)
@@ -155,8 +155,7 @@ public:
   iterator end()   const { return iterator(); }
   bool empty() const { return PtrList == 0; }
 
-  void print(std::ostream &OS) const;
-  void print(std::ostream *OS) const { if (OS) print(*OS); }
+  void print(raw_ostream &OS) const;
   void dump() const;
 
   /// Define an iterator for alias sets... this is just a forward iterator.
@@ -245,7 +244,7 @@ private:
   bool aliasesCallSite(CallSite CS, AliasAnalysis &AA) const;
 };
 
-inline std::ostream& operator<<(std::ostream &OS, const AliasSet &AS) {
+inline raw_ostream& operator<<(raw_ostream &OS, const AliasSet &AS) {
   AS.print(OS);
   return OS;
 }
@@ -374,8 +373,7 @@ public:
   iterator begin() { return AliasSets.begin(); }
   iterator end()   { return AliasSets.end(); }
 
-  void print(std::ostream &OS) const;
-  void print(std::ostream *OS) const { if (OS) print(*OS); }
+  void print(raw_ostream &OS) const;
   void dump() const;
 
 private:
@@ -403,7 +401,7 @@ private:
   AliasSet *findAliasSetForCallSite(CallSite CS);
 };
 
-inline std::ostream& operator<<(std::ostream &OS, const AliasSetTracker &AST) {
+inline raw_ostream& operator<<(raw_ostream &OS, const AliasSetTracker &AST) {
   AST.print(OS);
   return OS;
 }
index 366d492b11456d374f69d039b63aa982c92b4d38..094fecf107d1f6efe4d320a4f8c5ba12090b89cd 100644 (file)
@@ -32,6 +32,7 @@
 #include "llvm/Assembly/Writer.h"
 #include "llvm/Support/CFG.h"
 #include "llvm/Support/Compiler.h"
+#include "llvm/Support/raw_ostream.h"
 #include <algorithm>
 #include <map>
 #include <set>
@@ -161,8 +162,8 @@ EXTERN_TEMPLATE_INSTANTIATION(class DomTreeNodeBase<BasicBlock>);
 EXTERN_TEMPLATE_INSTANTIATION(class DomTreeNodeBase<MachineBasicBlock>);
 
 template<class NodeT>
-static std::ostream &operator<<(std::ostream &o,
-                                const DomTreeNodeBase<NodeT> *Node) {
+static raw_ostream &operator<<(raw_ostream &o,
+                               const DomTreeNodeBase<NodeT> *Node) {
   if (Node->getBlock())
     WriteAsOperand(o, Node->getBlock(), false);
   else
@@ -174,9 +175,9 @@ static std::ostream &operator<<(std::ostream &o,
 }
 
 template<class NodeT>
-static void PrintDomTree(const DomTreeNodeBase<NodeT> *N, std::ostream &o,
+static void PrintDomTree(const DomTreeNodeBase<NodeT> *N, raw_ostream &o,
                          unsigned Lev) {
-  o << std::string(2*Lev, ' ') << "[" << Lev << "] " << N;
+  o.indent(2*Lev) << "[" << Lev << "] " << N;
   for (typename DomTreeNodeBase<NodeT>::const_iterator I = N->begin(),
        E = N->end(); I != E; ++I)
     PrintDomTree<NodeT>(*I, o, Lev+1);
@@ -534,7 +535,7 @@ public:
 
   /// print - Convert to human readable form
   ///
-  virtual void print(std::ostream &o, const Module* ) const {
+  void print(raw_ostream &o) const {
     o << "=============================--------------------------------\n";
     if (this->isPostDominator())
       o << "Inorder PostDominator Tree: ";
@@ -547,14 +548,6 @@ public:
     PrintDomTree<NodeT>(getRootNode(), o, 1);
   }
   
-  void print(std::ostream *OS, const Module* M = 0) const {
-    if (OS) print(*OS, M);
-  }
-  
-  virtual void dump() {
-    print(llvm::cerr);
-  }
-  
 protected:
   template<class GraphT>
   friend void Compress(DominatorTreeBase<typename GraphT::NodeType>& DT,
@@ -837,9 +830,7 @@ public:
     DT->releaseMemory();
   }
   
-  virtual void print(std::ostream &OS, const Module* M= 0) const {
-    DT->print(OS, M);
-  }
+  virtual void print(std::ostream &OS, const Module* M= 0) const;
 };
 
 //===-------------------------------------
@@ -988,10 +979,6 @@ public:
   /// print - Convert to human readable form
   ///
   virtual void print(std::ostream &OS, const Module* = 0) const;
-  void print(std::ostream *OS, const Module* M = 0) const {
-    if (OS) print(*OS, M);
-  }
-  virtual void dump();
 };
 
 
index fb204069dcdadf19dd8b23bdb0ff4f8bc6efb48a..54352262830a29c8c29f763617f8e3e3f44ba7dd 100644 (file)
@@ -454,8 +454,8 @@ public:
 #endif
   }
 
-  void print(std::ostream &OS, unsigned Depth = 0) const {
-    OS << std::string(Depth*2, ' ') << "Loop at depth " << getLoopDepth()
+  void print(raw_ostream &OS, unsigned Depth = 0) const {
+    OS.indent(Depth*2) << "Loop at depth " << getLoopDepth()
        << " containing: ";
 
     for (unsigned i = 0; i < getBlocks().size(); ++i) {
@@ -472,12 +472,8 @@ public:
       (*I)->print(OS, Depth+2);
   }
   
-  void print(std::ostream *O, unsigned Depth = 0) const {
-    if (O) print(*O, Depth);
-  }
-  
   void dump() const {
-    print(cerr);
+    print(errs());
   }
   
 protected:
@@ -878,7 +874,7 @@ public:
   
   // Debugging
   
-  void print(std::ostream &OS, const Module* ) const {
+  void print(raw_ostream &OS) const {
     for (unsigned i = 0; i < TopLevelLoops.size(); ++i)
       TopLevelLoops[i]->print(OS);
   #if 0
@@ -942,10 +938,8 @@ public:
 
   virtual void releaseMemory() { LI.releaseMemory(); }
 
-  virtual void print(std::ostream &O, const Module* M = 0) const {
-    LI.print(O, M);
-  }
-
+  virtual void print(std::ostream &O, const Module* M = 0) const;
+  
   virtual void getAnalysisUsage(AnalysisUsage &AU) const;
 
   /// removeLoop - This removes the specified top-level loop from this loop info
index cd6af74024a547adabce9e2ccbad3e6f183abddb..ff579e3c4a31162b0094da8d96ba78c667c82b5c 100644 (file)
@@ -57,9 +57,7 @@ struct PostDominatorTree : public FunctionPass {
     return DT->properlyDominates(A, B);
   }
 
-  virtual void print(std::ostream &OS, const Module* M= 0) const {
-    DT->print(OS, M);
-  }
+  virtual void print(std::ostream &OS, const Module*) const;
 };
 
 FunctionPass* createPostDomTree();
index 5e5fe1560585da65c631baf6e45ebfcc4c1dcdcb..c5b239079a0d0853026628eced64807d4cc717a8 100644 (file)
@@ -17,7 +17,6 @@
 #ifndef LLVM_ASSEMBLY_WRITER_H
 #define LLVM_ASSEMBLY_WRITER_H
 
-#include <iosfwd>
 #include <string>
 
 namespace llvm {
@@ -71,8 +70,6 @@ void WriteTypeSymbolic(raw_ostream &, const Type *, const Module *M);
 // then even constants get pretty-printed; for example, the type of a null
 // pointer is printed symbolically.
 //
-void WriteAsOperand(std::ostream &, const Value *, bool PrintTy = true,
-                    const Module *Context = 0);
 void WriteAsOperand(raw_ostream &, const Value *, bool PrintTy = true,
                     const Module *Context = 0);
 
index 7b3d5f71b5f8348c3db06ce7a064b92a53af5226..1439b1bdfe5988006f4e1cdd66709a77baeed667 100644 (file)
@@ -23,7 +23,7 @@
 
 namespace llvm {
 
-inline void WriteAsOperand(std::ostream &, const MachineBasicBlock*, bool t) {  }
+inline void WriteAsOperand(raw_ostream &, const MachineBasicBlock*, bool t) {  }
 
 template<>
 inline void DominatorTreeBase<MachineBasicBlock>::addRoot(MachineBasicBlock* MBB) {
@@ -162,9 +162,7 @@ public:
   
   virtual void releaseMemory();
   
-  virtual void print(std::ostream &OS, const Module* M= 0) const {
-    DT->print(OS, M);
-  }
+  virtual void print(std::ostream &OS, const Module*) const;
 };
 
 //===-------------------------------------
index f1bd7c1d17c50afd152aee26972faa8d870f76ef..73956a15a8ceb108271f8bf05be8b7390f796342 100644 (file)
@@ -42,33 +42,33 @@ namespace {
     }
 
     void printLine(const char *Desc, unsigned Val, unsigned Sum) {
-      cerr <<  "  " << Val << " " << Desc << " responses ("
-           << Val*100/Sum << "%)\n";
+      errs() <<  "  " << Val << " " << Desc << " responses ("
+             << Val*100/Sum << "%)\n";
     }
     ~AliasAnalysisCounter() {
       unsigned AASum = No+May+Must;
       unsigned MRSum = NoMR+JustRef+JustMod+MR;
       if (AASum + MRSum) { // Print a report if any counted queries occurred...
-        cerr << "\n===== Alias Analysis Counter Report =====\n"
-             << "  Analysis counted: " << Name << "\n"
-             << "  " << AASum << " Total Alias Queries Performed\n";
+        errs() << "\n===== Alias Analysis Counter Report =====\n"
+               << "  Analysis counted: " << Name << "\n"
+               << "  " << AASum << " Total Alias Queries Performed\n";
         if (AASum) {
           printLine("no alias",     No, AASum);
           printLine("may alias",   May, AASum);
           printLine("must alias", Must, AASum);
-          cerr << "  Alias Analysis Counter Summary: " << No*100/AASum << "%/"
-               << May*100/AASum << "%/" << Must*100/AASum<<"%\n\n";
+          errs() << "  Alias Analysis Counter Summary: " << No*100/AASum << "%/"
+                 << May*100/AASum << "%/" << Must*100/AASum<<"%\n\n";
         }
 
-        cerr << "  " << MRSum    << " Total Mod/Ref Queries Performed\n";
+        errs() << "  " << MRSum    << " Total Mod/Ref Queries Performed\n";
         if (MRSum) {
           printLine("no mod/ref",    NoMR, MRSum);
           printLine("ref",        JustRef, MRSum);
           printLine("mod",        JustMod, MRSum);
           printLine("mod/ref",         MR, MRSum);
-          cerr << "  Mod/Ref Analysis Counter Summary: " <<NoMR*100/MRSum<< "%/"
-               << JustRef*100/MRSum << "%/" << JustMod*100/MRSum << "%/"
-               << MR*100/MRSum <<"%\n\n";
+          errs() << "  Mod/Ref Analysis Counter Summary: " <<NoMR*100/MRSum
+                 << "%/" << JustRef*100/MRSum << "%/" << JustMod*100/MRSum
+                 << "%/" << MR*100/MRSum <<"%\n\n";
         }
       }
     }
@@ -139,13 +139,13 @@ AliasAnalysisCounter::alias(const Value *V1, unsigned V1Size,
   }
 
   if (PrintAll || (PrintAllFailures && R == MayAlias)) {
-    cerr << AliasString << ":\t";
-    cerr << "[" << V1Size << "B] ";
-    WriteAsOperand(*cerr.stream(), V1, true, M);
-    cerr << ", ";
-    cerr << "[" << V2Size << "B] ";
-    WriteAsOperand(*cerr.stream(), V2, true, M);
-    cerr << "\n";
+    errs() << AliasString << ":\t";
+    errs() << "[" << V1Size << "B] ";
+    WriteAsOperand(errs(), V1, true, M);
+    errs() << ", ";
+    errs() << "[" << V2Size << "B] ";
+    WriteAsOperand(errs(), V2, true, M);
+    errs() << "\n";
   }
 
   return R;
index 942bc4b1ebd265f739ab145eb1c104d5233f56f5..5194e494e623ee7eb5231e1e376b82ece8c86ca5 100644 (file)
@@ -81,13 +81,16 @@ X("aa-eval", "Exhaustive Alias Analysis Precision Evaluator", false, true);
 
 FunctionPass *llvm::createAAEvalPass() { return new AAEval(); }
 
-static void PrintResults(const char *Msg, bool P, const Value *V1, const Value *V2,
-                         const Module *M) {
+static void PrintResults(const char *Msg, bool P, const Value *V1,
+                         const Value *V2, const Module *M) {
   if (P) {
-    std::stringstream s1, s2;
-    WriteAsOperand(s1, V1, true, M);
-    WriteAsOperand(s2, V2, true, M);
-    std::string o1(s1.str()), o2(s2.str());
+    std::string o1, o2;
+    {
+      raw_string_ostream os1(o1), os2(o2);
+      WriteAsOperand(os1, V1, true, M);
+      WriteAsOperand(os2, V2, true, M);
+    }
+    
     if (o2 < o1)
       std::swap(o1, o2);
     errs() << "  " << Msg << ":\t"
index 760964c806b9ac5e7bc4d89791a4df4c81679151..b056d0091a099a0f2ffe134d482b333418badee1 100644 (file)
@@ -22,7 +22,8 @@
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/InstIterator.h"
-#include "llvm/Support/Streams.h"
+#include "llvm/Support/Format.h"
+#include "llvm/Support/raw_ostream.h"
 using namespace llvm;
 
 /// mergeSetIn - Merge the specified alias set into this alias set.
@@ -531,8 +532,8 @@ void AliasSetTracker::copyValue(Value *From, Value *To) {
 //               AliasSet/AliasSetTracker Printing Support
 //===----------------------------------------------------------------------===//
 
-void AliasSet::print(std::ostream &OS) const {
-  OS << "  AliasSet[" << (void*)this << "," << RefCount << "] ";
+void AliasSet::print(raw_ostream &OS) const {
+  OS << "  AliasSet[" << format("0x%p", (void*)this) << "," << RefCount << "] ";
   OS << (AliasTy == MustAlias ? "must" : "may") << " alias, ";
   switch (AccessTy) {
   case NoModRef: OS << "No access "; break;
@@ -564,7 +565,7 @@ void AliasSet::print(std::ostream &OS) const {
   OS << "\n";
 }
 
-void AliasSetTracker::print(std::ostream &OS) const {
+void AliasSetTracker::print(raw_ostream &OS) const {
   OS << "Alias Set Tracker: " << AliasSets.size() << " alias sets for "
      << PointerMap.size() << " pointer values.\n";
   for (const_iterator I = begin(), E = end(); I != E; ++I)
@@ -572,8 +573,8 @@ void AliasSetTracker::print(std::ostream &OS) const {
   OS << "\n";
 }
 
-void AliasSet::dump() const { print (cerr); }
-void AliasSetTracker::dump() const { print(cerr); }
+void AliasSet::dump() const { print(errs()); }
+void AliasSetTracker::dump() const { print(errs()); }
 
 //===----------------------------------------------------------------------===//
 //                     ASTCallbackVH Class Implementation
@@ -614,7 +615,7 @@ namespace {
 
       for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I)
         Tracker->add(&*I);
-      Tracker->print(cerr);
+      Tracker->print(errs());
       delete Tracker;
       return false;
     }
index bef6bef337013c9a19b10c8ef744e3a5058d3d19..75d89af2a59a13727b235503017adca3dcde5016 100644 (file)
@@ -308,3 +308,9 @@ void LoopInfo::getAnalysisUsage(AnalysisUsage &AU) const {
   AU.setPreservesAll();
   AU.addRequired<DominatorTree>();
 }
+
+void LoopInfo::print(std::ostream &OS, const Module*) const {
+  raw_os_ostream OSS(OS);
+  LI.print(OSS);
+}
+
index 4853c2ac87b7998cabca44b0305eead84dc5991a..69522e8a39dd68dae5defd23f08ac754d8740f91 100644 (file)
@@ -33,15 +33,20 @@ F("postdomtree", "Post-Dominator Tree Construction", true, true);
 
 bool PostDominatorTree::runOnFunction(Function &F) {
   DT->recalculate(F);
-  DEBUG(DT->dump());
+  DEBUG(DT->print(errs()));
   return false;
 }
 
-PostDominatorTree::~PostDominatorTree()
-{
+PostDominatorTree::~PostDominatorTree() {
   delete DT;
 }
 
+void PostDominatorTree::print(std::ostream &OS, const Module *) const {
+  raw_os_ostream OSS(OS);
+  DT->print(OSS);
+}
+
+
 FunctionPass* llvm::createPostDomTree() {
   return new PostDominatorTree();
 }
index 37c86019d4a22182a629d34c7144b748dbe64361..78de02abc1b42c15386f79bb34c23393427c7a47 100644 (file)
@@ -51,3 +51,8 @@ MachineDominatorTree::~MachineDominatorTree() {
 void MachineDominatorTree::releaseMemory() {
   DT->releaseMemory();
 }
+
+void MachineDominatorTree::print(std::ostream &OS, const Module*) const {
+  raw_os_ostream OSS(OS);
+  DT->print(OSS);
+}
index e069cea2201f5a8a1673ff6517487219d25d10d4..08d5096d9ea90eba37bf9d1f10741342adda30f2 100644 (file)
@@ -425,10 +425,10 @@ namespace {
 #ifndef NDEBUG
     virtual ~ValueNumbering() {}
     virtual void dump() {
-      dump(*cerr.stream());
+      print(errs());
     }
 
-    void dump(std::ostream &os) {
+    void print(raw_ostream &os) {
       for (unsigned i = 1; i <= Values.size(); ++i) {
         os << i << " = ";
         WriteAsOperand(os, Values[i-1]);
index dc72031482b6a01f6daff240e5b5a7097b999e84..5062075a46c2f9b764109036b937e0858d7677be 100644 (file)
@@ -1218,16 +1218,6 @@ static void WriteAsOperandInternal(raw_ostream &Out, const Value *V,
     Out << "<badref>";
 }
 
-/// WriteAsOperand - Write the name of the specified value out to the specified
-/// ostream.  This can be useful when you just want to print int %reg126, not
-/// the whole instruction that generated it.
-///
-void llvm::WriteAsOperand(std::ostream &Out, const Value *V, bool PrintType,
-                          const Module *Context) {
-  raw_os_ostream OS(Out);
-  WriteAsOperand(OS, V, PrintType, Context);
-}
-
 void llvm::WriteAsOperand(raw_ostream &Out, const Value *V,
                           bool PrintType, const Module *Context) {
 
@@ -2076,12 +2066,6 @@ void Value::print(raw_ostream &ROS, AssemblyAnnotationWriter *AAW) const {
   }
 }
 
-/*
-void Value::print(std::ostream &O, AssemblyAnnotationWriter *AAW) const {
-  raw_os_ostream OS(O);
-  print(OS, AAW);
-}*/
-
 // Value::dump - allow easy printing of Values from the debugger.
 void Value::dump() const { print(errs()); errs() << '\n'; }
 
index 9b6f5c2c946e5ad8bf95390ca47ce7da49898f4c..e3bcbb754240ef7ac30a65efb945e9ca42e13bcb 100644 (file)
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Analysis/DominatorInternals.h"
 #include "llvm/Instructions.h"
-#include "llvm/Support/Streams.h"
+#include "llvm/Support/raw_ostream.h"
 #include <algorithm>
 using namespace llvm;
 
-namespace llvm {
-static std::ostream &operator<<(std::ostream &o,
-                                const std::set<BasicBlock*> &BBs) {
-  for (std::set<BasicBlock*>::const_iterator I = BBs.begin(), E = BBs.end();
-       I != E; ++I)
-    if (*I)
-      WriteAsOperand(o, *I, false);
-    else
-      o << " <<exit node>>";
-  return o;
-}
-}
-
 //===----------------------------------------------------------------------===//
 //  DominatorTree Implementation
 //===----------------------------------------------------------------------===//
@@ -61,6 +48,13 @@ bool DominatorTree::runOnFunction(Function &F) {
   return false;
 }
 
+void DominatorTree::print(std::ostream &OS, const Module *) const {
+  raw_os_ostream OSS(OS);
+  DT->print(OSS);
+}
+
+
+
 //===----------------------------------------------------------------------===//
 //  DominanceFrontier Implementation
 //===----------------------------------------------------------------------===//
@@ -270,18 +264,25 @@ DominanceFrontier::calculate(const DominatorTree &DT,
   return *Result;
 }
 
-void DominanceFrontierBase::print(std::ostream &o, const Module* ) const {
+void DominanceFrontierBase::print(std::ostream &O, const Module* ) const {
+  raw_os_ostream OS(O);
   for (const_iterator I = begin(), E = end(); I != E; ++I) {
-    o << "  DomFrontier for BB";
+    OS << "  DomFrontier for BB";
     if (I->first)
-      WriteAsOperand(o, I->first, false);
+      WriteAsOperand(OS, I->first, false);
     else
-      o << " <<exit node>>";
-    o << " is:\t" << I->second << "\n";
+      OS << " <<exit node>>";
+    OS << " is:\t";
+    
+    const std::set<BasicBlock*> &BBs = I->second;
+    
+    for (std::set<BasicBlock*>::const_iterator I = BBs.begin(), E = BBs.end();
+         I != E; ++I)
+      if (*I)
+        WriteAsOperand(OS, *I, false);
+      else
+        OS << " <<exit node>>";
+    OS << "\n";
   }
 }
 
-void DominanceFrontierBase::dump() {
-  print (llvm::cerr);
-}
-
index 05ccc631e5d61aba883f488691751e22f134a8f9..ddea84d52c09cbd6e3abf5afb4ec91c7c1ea0cff 100644 (file)
@@ -86,7 +86,7 @@ namespace {  // Anonymous namespace for class
       for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) {
         if (I->empty() || !I->back().isTerminator()) {
           cerr << "Basic Block does not have terminator!\n";
-          WriteAsOperand(*cerr, I, true);
+          WriteAsOperand(errs(), I, true);
           cerr << "\n";
           Broken = true;
         }