Convert ScalarEvolution to use raw_ostream instead of OStream.
authorDan Gohman <gohman@apple.com>
Tue, 21 Apr 2009 00:47:46 +0000 (00:47 +0000)
committerDan Gohman <gohman@apple.com>
Tue, 21 Apr 2009 00:47:46 +0000 (00:47 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@69640 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Analysis/ScalarEvolution.h
include/llvm/Analysis/ScalarEvolutionExpressions.h
lib/Analysis/ScalarEvolution.cpp

index 36f95f83ba2b6ab5eedb80a891cc7fd69c03d523..9e0965397a35d10dc417dc261cf69554e4e8be78 100644 (file)
@@ -93,7 +93,8 @@ namespace llvm {
     /// print - Print out the internal representation of this scalar to the
     /// specified stream.  This should really only be used for debugging
     /// purposes.
-    virtual void print(std::ostream &OS) const = 0;
+    virtual void print(raw_ostream &OS) const = 0;
+    void print(std::ostream &OS) const;
     void print(std::ostream *OS) const { if (OS) print(*OS); }
 
     /// dump - This method is used for debugging.
@@ -101,6 +102,11 @@ namespace llvm {
     void dump() const;
   };
 
+  inline raw_ostream &operator<<(raw_ostream &OS, const SCEV &S) {
+    S.print(OS);
+    return OS;
+  }
+
   inline std::ostream &operator<<(std::ostream &OS, const SCEV &S) {
     S.print(OS);
     return OS;
@@ -118,8 +124,7 @@ namespace llvm {
     virtual bool isLoopInvariant(const Loop *L) const;
     virtual const Type *getType() const;
     virtual bool hasComputableLoopEvolution(const Loop *L) const;
-    virtual void print(std::ostream &OS) const;
-    void print(std::ostream *OS) const { if (OS) print(*OS); }
+    virtual void print(raw_ostream &OS) const;
     virtual SCEVHandle
     replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym,
                                       const SCEVHandle &Conc,
@@ -331,6 +336,7 @@ namespace llvm {
     virtual bool runOnFunction(Function &F);
     virtual void releaseMemory();
     virtual void getAnalysisUsage(AnalysisUsage &AU) const;
+    void print(raw_ostream &OS, const Module* = 0) const;
     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);
index c160eb99cfc83c91ad01f565a43f3574b4f6e364..1cfc6390ccb4b95712b1512d70638f43c99f3c4f 100644 (file)
@@ -63,8 +63,7 @@ namespace llvm {
       return true;
     }
 
-    virtual void print(std::ostream &OS) const;
-    void print(std::ostream *OS) const { if (OS) print(*OS); }
+    virtual void print(raw_ostream &OS) const;
 
     /// Methods for support type inquiry through isa, cast, and dyn_cast:
     static inline bool classof(const SCEVConstant *S) { return true; }
@@ -107,8 +106,7 @@ namespace llvm {
 
     virtual bool dominates(BasicBlock *BB, DominatorTree *DT) const;
 
-    virtual void print(std::ostream &OS) const;
-    void print(std::ostream *OS) const { if (OS) print(*OS); }
+    virtual void print(raw_ostream &OS) const;
 
     /// Methods for support type inquiry through isa, cast, and dyn_cast:
     static inline bool classof(const SCEVTruncateExpr *S) { return true; }
@@ -151,8 +149,7 @@ namespace llvm {
 
     bool dominates(BasicBlock *BB, DominatorTree *DT) const;
 
-    virtual void print(std::ostream &OS) const;
-    void print(std::ostream *OS) const { if (OS) print(*OS); }
+    virtual void print(raw_ostream &OS) const;
 
     /// Methods for support type inquiry through isa, cast, and dyn_cast:
     static inline bool classof(const SCEVZeroExtendExpr *S) { return true; }
@@ -195,8 +192,7 @@ namespace llvm {
 
     bool dominates(BasicBlock *BB, DominatorTree *DT) const;
 
-    virtual void print(std::ostream &OS) const;
-    void print(std::ostream *OS) const { if (OS) print(*OS); }
+    virtual void print(raw_ostream &OS) const;
 
     /// Methods for support type inquiry through isa, cast, and dyn_cast:
     static inline bool classof(const SCEVSignExtendExpr *S) { return true; }
@@ -266,8 +262,7 @@ namespace llvm {
     virtual const char *getOperationStr() const = 0;
 
     virtual const Type *getType() const { return getOperand(0)->getType(); }
-    virtual void print(std::ostream &OS) const;
-    void print(std::ostream *OS) const { if (OS) print(*OS); }
+    virtual void print(raw_ostream &OS) const;
 
     /// Methods for support type inquiry through isa, cast, and dyn_cast:
     static inline bool classof(const SCEVCommutativeExpr *S) { return true; }
@@ -360,8 +355,7 @@ namespace llvm {
 
     virtual const Type *getType() const;
 
-    void print(std::ostream &OS) const;
-    void print(std::ostream *OS) const { if (OS) print(*OS); }
+    void print(raw_ostream &OS) const;
 
     /// Methods for support type inquiry through isa, cast, and dyn_cast:
     static inline bool classof(const SCEVUDivExpr *S) { return true; }
@@ -453,8 +447,7 @@ namespace llvm {
 
     bool dominates(BasicBlock *BB, DominatorTree *DT) const;
 
-    virtual void print(std::ostream &OS) const;
-    void print(std::ostream *OS) const { if (OS) print(*OS); }
+    virtual void print(raw_ostream &OS) const;
 
     /// Methods for support type inquiry through isa, cast, and dyn_cast:
     static inline bool classof(const SCEVAddRecExpr *S) { return true; }
@@ -538,8 +531,7 @@ namespace llvm {
 
     virtual const Type *getType() const;
 
-    virtual void print(std::ostream &OS) const;
-    void print(std::ostream *OS) const { if (OS) print(*OS); }
+    virtual void print(raw_ostream &OS) const;
 
     /// Methods for support type inquiry through isa, cast, and dyn_cast:
     static inline bool classof(const SCEVUnknown *S) { return true; }
index 6f9905d668253526479d22d5fa105506a130d42c..151ea743126a7ad6983980a0a49ecfdb7ea3b87c 100644 (file)
@@ -79,7 +79,7 @@
 #include "llvm/Support/InstIterator.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/MathExtras.h"
-#include "llvm/Support/Streams.h"
+#include "llvm/Support/raw_ostream.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/ADT/STLExtras.h"
 #include <ostream>
@@ -115,8 +115,13 @@ char ScalarEvolution::ID = 0;
 //
 SCEV::~SCEV() {}
 void SCEV::dump() const {
-  print(cerr);
-  cerr << '\n';
+  print(errs());
+  errs() << '\n';
+}
+
+void SCEV::print(std::ostream &o) const {
+  raw_os_ostream OS(o);
+  print(OS);
 }
 
 bool SCEV::isZero() const {
@@ -150,7 +155,7 @@ replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym,
   return this;
 }
 
-void SCEVCouldNotCompute::print(std::ostream &OS) const {
+void SCEVCouldNotCompute::print(raw_ostream &OS) const {
   OS << "***COULDNOTCOMPUTE***";
 }
 
@@ -181,7 +186,7 @@ SCEVHandle ScalarEvolution::getConstant(const APInt& Val) {
 
 const Type *SCEVConstant::getType() const { return V->getType(); }
 
-void SCEVConstant::print(std::ostream &OS) const {
+void SCEVConstant::print(raw_ostream &OS) const {
   WriteAsOperand(OS, V, false);
 }
 
@@ -210,7 +215,7 @@ bool SCEVTruncateExpr::dominates(BasicBlock *BB, DominatorTree *DT) const {
   return Op->dominates(BB, DT);
 }
 
-void SCEVTruncateExpr::print(std::ostream &OS) const {
+void SCEVTruncateExpr::print(raw_ostream &OS) const {
   OS << "(truncate " << *Op << " to " << *Ty << ")";
 }
 
@@ -235,7 +240,7 @@ bool SCEVZeroExtendExpr::dominates(BasicBlock *BB, DominatorTree *DT) const {
   return Op->dominates(BB, DT);
 }
 
-void SCEVZeroExtendExpr::print(std::ostream &OS) const {
+void SCEVZeroExtendExpr::print(raw_ostream &OS) const {
   OS << "(zeroextend " << *Op << " to " << *Ty << ")";
 }
 
@@ -262,7 +267,7 @@ bool SCEVSignExtendExpr::dominates(BasicBlock *BB, DominatorTree *DT) const {
   return Op->dominates(BB, DT);
 }
 
-void SCEVSignExtendExpr::print(std::ostream &OS) const {
+void SCEVSignExtendExpr::print(raw_ostream &OS) const {
   OS << "(signextend " << *Op << " to " << *Ty << ")";
 }
 
@@ -278,7 +283,7 @@ SCEVCommutativeExpr::~SCEVCommutativeExpr() {
                                                          Operands.end())));
 }
 
-void SCEVCommutativeExpr::print(std::ostream &OS) const {
+void SCEVCommutativeExpr::print(raw_ostream &OS) const {
   assert(Operands.size() > 1 && "This plus expr shouldn't exist!");
   const char *OpStr = getOperationStr();
   OS << "(" << *Operands[0];
@@ -342,7 +347,7 @@ bool SCEVUDivExpr::dominates(BasicBlock *BB, DominatorTree *DT) const {
   return LHS->dominates(BB, DT) && RHS->dominates(BB, DT);
 }
 
-void SCEVUDivExpr::print(std::ostream &OS) const {
+void SCEVUDivExpr::print(raw_ostream &OS) const {
   OS << "(" << *LHS << " /u " << *RHS << ")";
 }
 
@@ -403,7 +408,7 @@ bool SCEVAddRecExpr::isLoopInvariant(const Loop *QueryLoop) const {
 }
 
 
-void SCEVAddRecExpr::print(std::ostream &OS) const {
+void SCEVAddRecExpr::print(raw_ostream &OS) const {
   OS << "{" << *Operands[0];
   for (unsigned i = 1, e = Operands.size(); i != e; ++i)
     OS << ",+," << *Operands[i];
@@ -435,7 +440,7 @@ const Type *SCEVUnknown::getType() const {
   return V->getType();
 }
 
-void SCEVUnknown::print(std::ostream &OS) const {
+void SCEVUnknown::print(raw_ostream &OS) const {
   if (isa<PointerType>(V->getType()))
     OS << "(ptrtoint " << *V->getType() << " ";
   WriteAsOperand(OS, V, false);
@@ -2245,10 +2250,10 @@ SCEVHandle ScalarEvolutionsImpl::ComputeBackedgeTakenCount(const Loop *L) {
   }
   default:
 #if 0
-    cerr << "ComputeBackedgeTakenCount ";
+    errs() << "ComputeBackedgeTakenCount ";
     if (ExitCond->getOperand(0)->getType()->isUnsigned())
-      cerr << "[unsigned] ";
-    cerr << *LHS << "   "
+      errs() << "[unsigned] ";
+    errs() << *LHS << "   "
          << Instruction::getOpcodeName(Instruction::ICmp) 
          << "   " << *RHS << "\n";
 #endif
@@ -2369,9 +2374,9 @@ ComputeLoadConstantCompareBackedgeTakenCount(LoadInst *LI, Constant *RHS,
     if (!isa<ConstantInt>(Result)) break;  // Couldn't decide for sure
     if (cast<ConstantInt>(Result)->getValue().isMinValue()) {
 #if 0
-      cerr << "\n***\n*** Computed loop count " << *ItCst
-           << "\n*** From global " << *GV << "*** BB: " << *L->getHeader()
-           << "***\n";
+      errs() << "\n***\n*** Computed loop count " << *ItCst
+             << "\n*** From global " << *GV << "*** BB: " << *L->getHeader()
+             << "***\n";
 #endif
       ++NumArrayLenItCounts;
       return SE.getConstant(ItCst);   // Found terminating iteration!
@@ -2873,8 +2878,8 @@ SCEVHandle ScalarEvolutionsImpl::HowFarToZero(SCEV *V, const Loop *L) {
     SCEVConstant *R2 = dyn_cast<SCEVConstant>(Roots.second);
     if (R1) {
 #if 0
-      cerr << "HFTZ: " << *V << " - sol#1: " << *R1
-           << "  sol#2: " << *R2 << "\n";
+      errs() << "HFTZ: " << *V << " - sol#1: " << *R1
+             << "  sol#2: " << *R2 << "\n";
 #endif
       // Pick the smallest positive root value.
       if (ConstantInt *CB =
@@ -3326,7 +3331,7 @@ void ScalarEvolution::deleteValueFromRecords(Value *V) const {
   return ((ScalarEvolutionsImpl*)Impl)->deleteValueFromRecords(V);
 }
 
-static void PrintLoopInfo(std::ostream &OS, const ScalarEvolution *SE,
+static void PrintLoopInfo(raw_ostream &OS, const ScalarEvolution *SE,
                           const Loop *L) {
   // Print all inner loops first
   for (Loop::iterator I = L->begin(), E = L->end(); I != E; ++I)
@@ -3348,7 +3353,7 @@ static void PrintLoopInfo(std::ostream &OS, const ScalarEvolution *SE,
   OS << "\n";
 }
 
-void ScalarEvolution::print(std::ostream &OS, const Module* ) const {
+void ScalarEvolution::print(raw_ostream &OS, const Module* ) const {
   Function &F = ((ScalarEvolutionsImpl*)Impl)->F;
   LoopInfo &LI = ((ScalarEvolutionsImpl*)Impl)->LI;
 
@@ -3379,3 +3384,8 @@ void ScalarEvolution::print(std::ostream &OS, const Module* ) const {
   for (LoopInfo::iterator I = LI.begin(), E = LI.end(); I != E; ++I)
     PrintLoopInfo(OS, this, *I);
 }
+
+void ScalarEvolution::print(std::ostream &o, const Module *M) const {
+  raw_os_ostream OS(o);
+  print(OS, M);
+}