From b7ef72963b2215ca23c27fa8ea777bada06994d0 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 21 Apr 2009 00:47:46 +0000 Subject: [PATCH] Convert ScalarEvolution to use raw_ostream instead of OStream. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@69640 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Analysis/ScalarEvolution.h | 12 +++-- .../Analysis/ScalarEvolutionExpressions.h | 24 +++------ lib/Analysis/ScalarEvolution.cpp | 54 +++++++++++-------- 3 files changed, 49 insertions(+), 41 deletions(-) diff --git a/include/llvm/Analysis/ScalarEvolution.h b/include/llvm/Analysis/ScalarEvolution.h index 36f95f83ba2..9e0965397a3 100644 --- a/include/llvm/Analysis/ScalarEvolution.h +++ b/include/llvm/Analysis/ScalarEvolution.h @@ -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); diff --git a/include/llvm/Analysis/ScalarEvolutionExpressions.h b/include/llvm/Analysis/ScalarEvolutionExpressions.h index c160eb99cfc..1cfc6390ccb 100644 --- a/include/llvm/Analysis/ScalarEvolutionExpressions.h +++ b/include/llvm/Analysis/ScalarEvolutionExpressions.h @@ -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; } diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp index 6f9905d6682..151ea743126 100644 --- a/lib/Analysis/ScalarEvolution.cpp +++ b/lib/Analysis/ScalarEvolution.cpp @@ -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 @@ -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(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(Result)) break; // Couldn't decide for sure if (cast(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(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); +}