Skip to content

Commit b25de3f

Browse files
committed
eliminate the "Value" printing methods that print to a std::ostream.
This required converting a bunch of stuff off DOUT and other cleanups. llvm-svn: 79819
1 parent 82e57a6 commit b25de3f

35 files changed

+298
-292
lines changed

Diff for: llvm/include/llvm/Analysis/SparsePropagation.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
#include "llvm/ADT/DenseMap.h"
1919
#include "llvm/ADT/SmallPtrSet.h"
20-
#include <iosfwd>
2120
#include <vector>
2221
#include <set>
2322

@@ -32,6 +31,7 @@ namespace llvm {
3231
class Function;
3332
class SparseSolver;
3433
class LLVMContext;
34+
class raw_ostream;
3535

3636
template<typename T> class SmallVectorImpl;
3737

@@ -100,7 +100,7 @@ class AbstractLatticeFunction {
100100
}
101101

102102
/// PrintValue - Render the specified lattice value to the specified stream.
103-
virtual void PrintValue(LatticeVal V, std::ostream &OS);
103+
virtual void PrintValue(LatticeVal V, raw_ostream &OS);
104104
};
105105

106106

@@ -141,7 +141,7 @@ class SparseSolver {
141141
///
142142
void Solve(Function &F);
143143

144-
void Print(Function &F, std::ostream &OS) const;
144+
void Print(Function &F, raw_ostream &OS) const;
145145

146146
/// getLatticeState - Return the LatticeVal object that corresponds to the
147147
/// value. If an value is not in the map, it is returned as untracked,

Diff for: llvm/include/llvm/Analysis/Trace.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020

2121
#include <vector>
2222
#include <cassert>
23-
#include <iosfwd>
2423

2524
namespace llvm {
2625
class BasicBlock;
2726
class Function;
2827
class Module;
28+
class raw_ostream;
2929

3030
class Trace {
3131
typedef std::vector<BasicBlock *> BasicBlockListType;
@@ -106,13 +106,12 @@ class Trace {
106106

107107
/// print - Write trace to output stream.
108108
///
109-
void print (std::ostream &O) const;
110-
void print (std::ostream *O) const { if (O) print(*O); }
109+
void print(raw_ostream &O) const;
111110

112111
/// dump - Debugger convenience method; writes trace to standard error
113112
/// output stream.
114113
///
115-
void dump () const;
114+
void dump() const;
116115
};
117116

118117
} // end namespace llvm

Diff for: llvm/include/llvm/Value.h

-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "llvm/ADT/StringRef.h"
2020
#include "llvm/ADT/Twine.h"
2121
#include "llvm/Support/Casting.h"
22-
#include <iosfwd>
2322
#include <string>
2423

2524
namespace llvm {
@@ -97,7 +96,6 @@ class Value {
9796

9897
/// print - Implement operator<< on Value.
9998
///
100-
void print(std::ostream &O, AssemblyAnnotationWriter *AAW = 0) const;
10199
void print(raw_ostream &O, AssemblyAnnotationWriter *AAW = 0) const;
102100

103101
/// All values are typed, get the type of this value.
@@ -280,10 +278,6 @@ class Value {
280278
}
281279
};
282280

283-
inline std::ostream &operator<<(std::ostream &OS, const Value &V) {
284-
V.print(OS);
285-
return OS;
286-
}
287281
inline raw_ostream &operator<<(raw_ostream &OS, const Value &V) {
288282
V.print(OS);
289283
return OS;

Diff for: llvm/lib/Analysis/AliasAnalysisCounter.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "llvm/Support/CommandLine.h"
2020
#include "llvm/Support/Compiler.h"
2121
#include "llvm/Support/ErrorHandling.h"
22-
#include "llvm/Support/Streams.h"
22+
#include "llvm/Support/raw_ostream.h"
2323
using namespace llvm;
2424

2525
static cl::opt<bool>
@@ -165,10 +165,10 @@ AliasAnalysisCounter::getModRefInfo(CallSite CS, Value *P, unsigned Size) {
165165
}
166166

167167
if (PrintAll || (PrintAllFailures && R == ModRef)) {
168-
cerr << MRString << ": Ptr: ";
169-
cerr << "[" << Size << "B] ";
170-
WriteAsOperand(*cerr.stream(), P, true, M);
171-
cerr << "\t<->" << *CS.getInstruction();
168+
errs() << MRString << ": Ptr: ";
169+
errs() << "[" << Size << "B] ";
170+
WriteAsOperand(errs(), P, true, M);
171+
errs() << "\t<->" << *CS.getInstruction();
172172
}
173173
return R;
174174
}

Diff for: llvm/lib/Analysis/CFGPrinter.cpp

+10-8
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,21 @@ struct DOTGraphTraits<const Function*> : public DefaultDOTGraphTraits {
4444
if (ShortNames && !Node->getName().empty())
4545
return Node->getNameStr() + ":";
4646

47-
std::ostringstream Out;
47+
std::string Str;
48+
raw_string_ostream OS(Str);
49+
4850
if (ShortNames) {
49-
WriteAsOperand(Out, Node, false);
50-
return Out.str();
51+
WriteAsOperand(OS, Node, false);
52+
return OS.str();
5153
}
5254

5355
if (Node->getName().empty()) {
54-
WriteAsOperand(Out, Node, false);
55-
Out << ":";
56+
WriteAsOperand(OS, Node, false);
57+
OS << ":";
5658
}
57-
58-
Out << *Node;
59-
std::string OutStr = Out.str();
59+
60+
OS << *Node;
61+
std::string OutStr = OS.str();
6062
if (OutStr[0] == '\n') OutStr.erase(OutStr.begin());
6163

6264
// Process string output to make it nicer...

Diff for: llvm/lib/Analysis/IVUsers.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,14 @@ bool IVUsers::AddUsersIfInteresting(Instruction *I) {
228228
if (LI->getLoopFor(User->getParent()) != L) {
229229
if (isa<PHINode>(User) || Processed.count(User) ||
230230
!AddUsersIfInteresting(User)) {
231-
DOUT << "FOUND USER in other loop: " << *User << '\n'
232-
<< " OF SCEV: " << *ISE << "\n";
231+
DEBUG(errs() << "FOUND USER in other loop: " << *User << '\n'
232+
<< " OF SCEV: " << *ISE << '\n');
233233
AddUserToIVUsers = true;
234234
}
235235
} else if (Processed.count(User) ||
236236
!AddUsersIfInteresting(User)) {
237-
DOUT << "FOUND USER: " << *User << '\n'
238-
<< " OF SCEV: " << *ISE << "\n";
237+
DEBUG(errs() << "FOUND USER: " << *User << '\n'
238+
<< " OF SCEV: " << *ISE << '\n');
239239
AddUserToIVUsers = true;
240240
}
241241

Diff for: llvm/lib/Analysis/InstCount.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "llvm/Support/Compiler.h"
1919
#include "llvm/Support/ErrorHandling.h"
2020
#include "llvm/Support/InstVisitor.h"
21-
#include "llvm/Support/Streams.h"
21+
#include "llvm/Support/raw_ostream.h"
2222
#include "llvm/ADT/Statistic.h"
2323
using namespace llvm;
2424

@@ -47,7 +47,7 @@ namespace {
4747
#include "llvm/Instruction.def"
4848

4949
void visitInstruction(Instruction &I) {
50-
cerr << "Instruction Count does not know about " << I;
50+
errs() << "Instruction Count does not know about " << I;
5151
llvm_unreachable(0);
5252
}
5353
public:

Diff for: llvm/lib/Analysis/Interval.cpp

+12-10
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "llvm/Analysis/Interval.h"
1616
#include "llvm/BasicBlock.h"
1717
#include "llvm/Support/CFG.h"
18+
#include "llvm/Support/raw_ostream.h"
1819
#include <algorithm>
1920

2021
using namespace llvm;
@@ -29,29 +30,30 @@ bool Interval::isLoop() const {
2930
// There is a loop in this interval iff one of the predecessors of the header
3031
// node lives in the interval.
3132
for (::pred_iterator I = ::pred_begin(HeaderNode), E = ::pred_end(HeaderNode);
32-
I != E; ++I) {
33-
if (contains(*I)) return true;
34-
}
33+
I != E; ++I)
34+
if (contains(*I))
35+
return true;
3536
return false;
3637
}
3738

3839

39-
void Interval::print(std::ostream &o) const {
40-
o << "-------------------------------------------------------------\n"
40+
void Interval::print(std::ostream &O) const {
41+
raw_os_ostream OS(O);
42+
OS << "-------------------------------------------------------------\n"
4143
<< "Interval Contents:\n";
4244

4345
// Print out all of the basic blocks in the interval...
4446
for (std::vector<BasicBlock*>::const_iterator I = Nodes.begin(),
4547
E = Nodes.end(); I != E; ++I)
46-
o << **I << "\n";
48+
OS << **I << "\n";
4749

48-
o << "Interval Predecessors:\n";
50+
OS << "Interval Predecessors:\n";
4951
for (std::vector<BasicBlock*>::const_iterator I = Predecessors.begin(),
5052
E = Predecessors.end(); I != E; ++I)
51-
o << **I << "\n";
53+
OS << **I << "\n";
5254

53-
o << "Interval Successors:\n";
55+
OS << "Interval Successors:\n";
5456
for (std::vector<BasicBlock*>::const_iterator I = Successors.begin(),
5557
E = Successors.end(); I != E; ++I)
56-
o << **I << "\n";
58+
OS << **I << "\n";
5759
}

Diff for: llvm/lib/Analysis/SparsePropagation.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ using namespace llvm;
2929
AbstractLatticeFunction::~AbstractLatticeFunction() {}
3030

3131
/// PrintValue - Render the specified lattice value to the specified stream.
32-
void AbstractLatticeFunction::PrintValue(LatticeVal V, std::ostream &OS) {
32+
void AbstractLatticeFunction::PrintValue(LatticeVal V, raw_ostream &OS) {
3333
if (V == UndefVal)
3434
OS << "undefined";
3535
else if (V == OverdefinedVal)
@@ -312,7 +312,7 @@ void SparseSolver::Solve(Function &F) {
312312
}
313313
}
314314

315-
void SparseSolver::Print(Function &F, std::ostream &OS) const {
315+
void SparseSolver::Print(Function &F, raw_ostream &OS) const {
316316
OS << "\nFUNCTION: " << F.getNameStr() << "\n";
317317
for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
318318
if (!BBExecutable.count(BB))

Diff for: llvm/lib/Analysis/Trace.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "llvm/Analysis/Trace.h"
1919
#include "llvm/Function.h"
2020
#include "llvm/Assembly/Writer.h"
21-
#include "llvm/Support/Streams.h"
21+
#include "llvm/Support/raw_ostream.h"
2222
using namespace llvm;
2323

2424
Function *Trace::getFunction() const {
@@ -31,8 +31,8 @@ Module *Trace::getModule() const {
3131

3232
/// print - Write trace to output stream.
3333
///
34-
void Trace::print(std::ostream &O) const {
35-
Function *F = getFunction ();
34+
void Trace::print(raw_ostream &O) const {
35+
Function *F = getFunction();
3636
O << "; Trace from function " << F->getNameStr() << ", blocks:\n";
3737
for (const_iterator i = begin(), e = end(); i != e; ++i) {
3838
O << "; ";
@@ -46,5 +46,5 @@ void Trace::print(std::ostream &O) const {
4646
/// output stream.
4747
///
4848
void Trace::dump() const {
49-
print(cerr);
49+
print(errs());
5050
}

Diff for: llvm/lib/CodeGen/MachOWriter.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ void MachOWriter::InitMem(const Constant *C, uintptr_t Offset,
634634
}
635635
case Instruction::Add:
636636
default:
637-
cerr << "ConstantExpr not handled as global var init: " << *CE << "\n";
637+
errs() << "ConstantExpr not handled as global var init: " << *CE <<"\n";
638638
llvm_unreachable(0);
639639
}
640640
} else if (PC->getType()->isSingleValueType()) {
@@ -732,7 +732,7 @@ void MachOWriter::InitMem(const Constant *C, uintptr_t Offset,
732732
WorkList.push_back(CPair(CPS->getOperand(i),
733733
PA+SL->getElementOffset(i)));
734734
} else {
735-
cerr << "Bad Type: " << *PC->getType() << "\n";
735+
errs() << "Bad Type: " << *PC->getType() << "\n";
736736
llvm_unreachable("Unknown constant type to initialize memory with!");
737737
}
738738
}

0 commit comments

Comments
 (0)