[llvm-commits] [llvm] r69640 - in /llvm/trunk: include/llvm/Analysis/ScalarEvolution.h include/llvm/Analysis/ScalarEvolutionExpressions.h lib/Analysis/ScalarEvolution.cpp

Dan Gohman gohman at apple.com
Mon Apr 20 17:47:47 PDT 2009


Author: djg
Date: Mon Apr 20 19:47:46 2009
New Revision: 69640

URL: http://llvm.org/viewvc/llvm-project?rev=69640&view=rev
Log:
Convert ScalarEvolution to use raw_ostream instead of OStream.

Modified:
    llvm/trunk/include/llvm/Analysis/ScalarEvolution.h
    llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpressions.h
    llvm/trunk/lib/Analysis/ScalarEvolution.cpp

Modified: llvm/trunk/include/llvm/Analysis/ScalarEvolution.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ScalarEvolution.h?rev=69640&r1=69639&r2=69640&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Analysis/ScalarEvolution.h (original)
+++ llvm/trunk/include/llvm/Analysis/ScalarEvolution.h Mon Apr 20 19:47:46 2009
@@ -93,7 +93,8 @@
     /// 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 @@
     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 @@
     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 @@
     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);

Modified: llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpressions.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpressions.h?rev=69640&r1=69639&r2=69640&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpressions.h (original)
+++ llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpressions.h Mon Apr 20 19:47:46 2009
@@ -63,8 +63,7 @@
       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 @@
 
     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 @@
 
     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 @@
 
     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 @@
     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 @@
 
     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 @@
 
     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 @@
 
     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; }

Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=69640&r1=69639&r2=69640&view=diff

==============================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original)
+++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Mon Apr 20 19:47:46 2009
@@ -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 @@
 //
 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 @@
   return this;
 }
 
-void SCEVCouldNotCompute::print(std::ostream &OS) const {
+void SCEVCouldNotCompute::print(raw_ostream &OS) const {
   OS << "***COULDNOTCOMPUTE***";
 }
 
@@ -181,7 +186,7 @@
 
 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 @@
   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 @@
   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 @@
   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 @@
                                                          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 @@
   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 @@
 }
 
 
-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 @@
   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 @@
   }
   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 @@
     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 @@
     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 @@
   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 @@
   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 @@
   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);
+}





More information about the llvm-commits mailing list