llvm.org GIT mirror llvm / 791102f
eliminate the std::ostream form of WriteAsOperand and update clients. This also updates dominator related stuff. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79825 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 11 years ago
16 changed file(s) with 106 addition(s) and 129 deletion(s). Raw diff Collapse all Expand all
154154 iterator end() const { return iterator(); }
155155 bool empty() const { return PtrList == 0; }
156156
157 void print(std::ostream &OS) const;
158 void print(std::ostream *OS) const { if (OS) print(*OS); }
157 void print(raw_ostream &OS) const;
159158 void dump() const;
160159
161160 /// Define an iterator for alias sets... this is just a forward iterator.
244243 bool aliasesCallSite(CallSite CS, AliasAnalysis &AA) const;
245244 };
246245
247 inline std::ostream& operator<<(std::ostream &OS, const AliasSet &AS) {
246 inline raw_ostream& operator<<(raw_ostream &OS, const AliasSet &AS) {
248247 AS.print(OS);
249248 return OS;
250249 }
373372 iterator begin() { return AliasSets.begin(); }
374373 iterator end() { return AliasSets.end(); }
375374
376 void print(std::ostream &OS) const;
377 void print(std::ostream *OS) const { if (OS) print(*OS); }
375 void print(raw_ostream &OS) const;
378376 void dump() const;
379377
380378 private:
402400 AliasSet *findAliasSetForCallSite(CallSite CS);
403401 };
404402
405 inline std::ostream& operator<<(std::ostream &OS, const AliasSetTracker &AST) {
403 inline raw_ostream& operator<<(raw_ostream &OS, const AliasSetTracker &AST) {
406404 AST.print(OS);
407405 return OS;
408406 }
3131 #include "llvm/Assembly/Writer.h"
3232 #include "llvm/Support/CFG.h"
3333 #include "llvm/Support/Compiler.h"
34 #include "llvm/Support/raw_ostream.h"
3435 #include
3536 #include
3637 #include
160161 EXTERN_TEMPLATE_INSTANTIATION(class DomTreeNodeBase);
161162
162163 template
163 static std::ostream &operator<<(std::ostream &o,
164 const DomTreeNodeBase *Node) {
164 static raw_ostream &operator<<(raw_ostream &o,
165 const DomTreeNodeBase *Node) {
165166 if (Node->getBlock())
166167 WriteAsOperand(o, Node->getBlock(), false);
167168 else
173174 }
174175
175176 template
176 static void PrintDomTree(const DomTreeNodeBase *N, std::ostream &o,
177 static void PrintDomTree(const DomTreeNodeBase *N, raw_ostream &o,
177178 unsigned Lev) {
178 o << std::string(2*Lev, ' ') << "[" << Lev << "] " << N;
179 o.indent(2*Lev) << "[" << Lev << "] " << N;
179180 for (typename DomTreeNodeBase::const_iterator I = N->begin(),
180181 E = N->end(); I != E; ++I)
181182 PrintDomTree(*I, o, Lev+1);
533534
534535 /// print - Convert to human readable form
535536 ///
536 virtual void print(std::ostream &o, const Module* ) const {
537 void print(raw_ostream &o) const {
537538 o << "=============================--------------------------------\n";
538539 if (this->isPostDominator())
539540 o << "Inorder PostDominator Tree: ";
544545 o << "\n";
545546
546547 PrintDomTree(getRootNode(), o, 1);
547 }
548
549 void print(std::ostream *OS, const Module* M = 0) const {
550 if (OS) print(*OS, M);
551 }
552
553 virtual void dump() {
554 print(llvm::cerr);
555548 }
556549
557550 protected:
836829 DT->releaseMemory();
837830 }
838831
839 virtual void print(std::ostream &OS, const Module* M= 0) const {
840 DT->print(OS, M);
841 }
832 virtual void print(std::ostream &OS, const Module* M= 0) const;
842833 };
843834
844835 //===-------------------------------------
987978 /// print - Convert to human readable form
988979 ///
989980 virtual void print(std::ostream &OS, const Module* = 0) const;
990 void print(std::ostream *OS, const Module* M = 0) const {
991 if (OS) print(*OS, M);
992 }
993 virtual void dump();
994981 };
995982
996983
453453 #endif
454454 }
455455
456 void print(std::ostream &OS, unsigned Depth = 0) const {
457 OS << std::string(Depth*2, ' ') << "Loop at depth " << getLoopDepth()
456 void print(raw_ostream &OS, unsigned Depth = 0) const {
457 OS.indent(Depth*2) << "Loop at depth " << getLoopDepth()
458458 << " containing: ";
459459
460460 for (unsigned i = 0; i < getBlocks().size(); ++i) {
471471 (*I)->print(OS, Depth+2);
472472 }
473473
474 void print(std::ostream *O, unsigned Depth = 0) const {
475 if (O) print(*O, Depth);
476 }
477
478474 void dump() const {
479 print(cerr);
475 print(errs());
480476 }
481477
482478 protected:
877873
878874 // Debugging
879875
880 void print(std::ostream &OS, const Module* ) const {
876 void print(raw_ostream &OS) const {
881877 for (unsigned i = 0; i < TopLevelLoops.size(); ++i)
882878 TopLevelLoops[i]->print(OS);
883879 #if 0
941937
942938 virtual void releaseMemory() { LI.releaseMemory(); }
943939
944 virtual void print(std::ostream &O, const Module* M = 0) const {
945 LI.print(O, M);
946 }
947
940 virtual void print(std::ostream &O, const Module* M = 0) const;
941
948942 virtual void getAnalysisUsage(AnalysisUsage &AU) const;
949943
950944 /// removeLoop - This removes the specified top-level loop from this loop info
5656 return DT->properlyDominates(A, B);
5757 }
5858
59 virtual void print(std::ostream &OS, const Module* M= 0) const {
60 DT->print(OS, M);
61 }
59 virtual void print(std::ostream &OS, const Module*) const;
6260 };
6361
6462 FunctionPass* createPostDomTree();
1616 #ifndef LLVM_ASSEMBLY_WRITER_H
1717 #define LLVM_ASSEMBLY_WRITER_H
1818
19 #include
2019 #include
2120
2221 namespace llvm {
7069 // then even constants get pretty-printed; for example, the type of a null
7170 // pointer is printed symbolically.
7271 //
73 void WriteAsOperand(std::ostream &, const Value *, bool PrintTy = true,
74 const Module *Context = 0);
7572 void WriteAsOperand(raw_ostream &, const Value *, bool PrintTy = true,
7673 const Module *Context = 0);
7774
2222
2323 namespace llvm {
2424
25 inline void WriteAsOperand(std::ostream &, const MachineBasicBlock*, bool t) { }
25 inline void WriteAsOperand(raw_ostream &, const MachineBasicBlock*, bool t) { }
2626
2727 template<>
2828 inline void DominatorTreeBase::addRoot(MachineBasicBlock* MBB) {
161161
162162 virtual void releaseMemory();
163163
164 virtual void print(std::ostream &OS, const Module* M= 0) const {
165 DT->print(OS, M);
166 }
164 virtual void print(std::ostream &OS, const Module*) const;
167165 };
168166
169167 //===-------------------------------------
4141 }
4242
4343 void printLine(const char *Desc, unsigned Val, unsigned Sum) {
44 cerr << " " << Val << " " << Desc << " responses ("
45 << Val*100/Sum << "%)\n";
44 errs() << " " << Val << " " << Desc << " responses ("
45 << Val*100/Sum << "%)\n";
4646 }
4747 ~AliasAnalysisCounter() {
4848 unsigned AASum = No+May+Must;
4949 unsigned MRSum = NoMR+JustRef+JustMod+MR;
5050 if (AASum + MRSum) { // Print a report if any counted queries occurred...
51 cerr << "\n===== Alias Analysis Counter Report =====\n"
52 << " Analysis counted: " << Name << "\n"
53 << " " << AASum << " Total Alias Queries Performed\n";
51 errs() << "\n===== Alias Analysis Counter Report =====\n"
52 << " Analysis counted: " << Name << "\n"
53 << " " << AASum << " Total Alias Queries Performed\n";
5454 if (AASum) {
5555 printLine("no alias", No, AASum);
5656 printLine("may alias", May, AASum);
5757 printLine("must alias", Must, AASum);
58 cerr << " Alias Analysis Counter Summary: " << No*100/AASum << "%/"
59 << May*100/AASum << "%/" << Must*100/AASum<<"%\n\n";
58 errs() << " Alias Analysis Counter Summary: " << No*100/AASum << "%/"
59 << May*100/AASum << "%/" << Must*100/AASum<<"%\n\n";
6060 }
6161
62 cerr << " " << MRSum << " Total Mod/Ref Queries Performed\n";
62 errs() << " " << MRSum << " Total Mod/Ref Queries Performed\n";
6363 if (MRSum) {
6464 printLine("no mod/ref", NoMR, MRSum);
6565 printLine("ref", JustRef, MRSum);
6666 printLine("mod", JustMod, MRSum);
6767 printLine("mod/ref", MR, MRSum);
68 cerr << " Mod/Ref Analysis Counter Summary: " <
69 << JustRef*100/MRSum << "%/" << JustMod*100/MRSum << "%/"
70 << MR*100/MRSum <<"%\n\n";
68 errs() << " Mod/Ref Analysis Counter Summary: " <
69 << "%/" << JustRef*100/MRSum << "%/" << JustMod*100/MRSum
70 << "%/" << MR*100/MRSum <<"%\n\n";
7171 }
7272 }
7373 }
138138 }
139139
140140 if (PrintAll || (PrintAllFailures && R == MayAlias)) {
141 cerr << AliasString << ":\t";
142 cerr << "[" << V1Size << "B] ";
143 WriteAsOperand(*cerr.stream(), V1, true, M);
144 cerr << ", ";
145 cerr << "[" << V2Size << "B] ";
146 WriteAsOperand(*cerr.stream(), V2, true, M);
147 cerr << "\n";
141 errs() << AliasString << ":\t";
142 errs() << "[" << V1Size << "B] ";
143 WriteAsOperand(errs(), V1, true, M);
144 errs() << ", ";
145 errs() << "[" << V2Size << "B] ";
146 WriteAsOperand(errs(), V2, true, M);
147 errs() << "\n";
148148 }
149149
150150 return R;
8080
8181 FunctionPass *llvm::createAAEvalPass() { return new AAEval(); }
8282
83 static void PrintResults(const char *Msg, bool P, const Value *V1, const Value *V2,
84 const Module *M) {
83 static void PrintResults(const char *Msg, bool P, const Value *V1,
84 const Value *V2, const Module *M) {
8585 if (P) {
86 std::stringstream s1, s2;
87 WriteAsOperand(s1, V1, true, M);
88 WriteAsOperand(s2, V2, true, M);
89 std::string o1(s1.str()), o2(s2.str());
86 std::string o1, o2;
87 {
88 raw_string_ostream os1(o1), os2(o2);
89 WriteAsOperand(os1, V1, true, M);
90 WriteAsOperand(os2, V2, true, M);
91 }
92
9093 if (o2 < o1)
9194 std::swap(o1, o2);
9295 errs() << " " << Msg << ":\t"
2121 #include "llvm/Support/Compiler.h"
2222 #include "llvm/Support/ErrorHandling.h"
2323 #include "llvm/Support/InstIterator.h"
24 #include "llvm/Support/Streams.h"
24 #include "llvm/Support/Format.h"
25 #include "llvm/Support/raw_ostream.h"
2526 using namespace llvm;
2627
2728 /// mergeSetIn - Merge the specified alias set into this alias set.
530531 // AliasSet/AliasSetTracker Printing Support
531532 //===----------------------------------------------------------------------===//
532533
533 void AliasSet::print(std::ostream &OS) const {
534 OS << " AliasSet[" << (void*)this << "," << RefCount << "] ";
534 void AliasSet::print(raw_ostream &OS) const {
535 OS << " AliasSet[" << format("0x%p", (void*)this) << "," << RefCount << "] ";
535536 OS << (AliasTy == MustAlias ? "must" : "may") << " alias, ";
536537 switch (AccessTy) {
537538 case NoModRef: OS << "No access "; break;
563564 OS << "\n";
564565 }
565566
566 void AliasSetTracker::print(std::ostream &OS) const {
567 void AliasSetTracker::print(raw_ostream &OS) const {
567568 OS << "Alias Set Tracker: " << AliasSets.size() << " alias sets for "
568569 << PointerMap.size() << " pointer values.\n";
569570 for (const_iterator I = begin(), E = end(); I != E; ++I)
571572 OS << "\n";
572573 }
573574
574 void AliasSet::dump() const { print (cerr); }
575 void AliasSetTracker::dump() const { print(cerr); }
575 void AliasSet::dump() const { print(errs()); }
576 void AliasSetTracker::dump() const { print(errs()); }
576577
577578 //===----------------------------------------------------------------------===//
578579 // ASTCallbackVH Class Implementation
613614
614615 for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I)
615616 Tracker->add(&*I);
616 Tracker->print(cerr);
617 Tracker->print(errs());
617618 delete Tracker;
618619 return false;
619620 }
307307 AU.setPreservesAll();
308308 AU.addRequired();
309309 }
310
311 void LoopInfo::print(std::ostream &OS, const Module*) const {
312 raw_os_ostream OSS(OS);
313 LI.print(OSS);
314 }
315
3232
3333 bool PostDominatorTree::runOnFunction(Function &F) {
3434 DT->recalculate(F);
35 DEBUG(DT->dump());
35 DEBUG(DT->print(errs()));
3636 return false;
3737 }
3838
39 PostDominatorTree::~PostDominatorTree()
40 {
39 PostDominatorTree::~PostDominatorTree() {
4140 delete DT;
4241 }
42
43 void PostDominatorTree::print(std::ostream &OS, const Module *) const {
44 raw_os_ostream OSS(OS);
45 DT->print(OSS);
46 }
47
4348
4449 FunctionPass* llvm::createPostDomTree() {
4550 return new PostDominatorTree();
5050 void MachineDominatorTree::releaseMemory() {
5151 DT->releaseMemory();
5252 }
53
54 void MachineDominatorTree::print(std::ostream &OS, const Module*) const {
55 raw_os_ostream OSS(OS);
56 DT->print(OSS);
57 }
424424 #ifndef NDEBUG
425425 virtual ~ValueNumbering() {}
426426 virtual void dump() {
427 dump(*cerr.stream());
428 }
429
430 void dump(std::ostream &os) {
427 print(errs());
428 }
429
430 void print(raw_ostream &os) {
431431 for (unsigned i = 1; i <= Values.size(); ++i) {
432432 os << i << " = ";
433433 WriteAsOperand(os, Values[i-1]);
12171217 Out << "";
12181218 }
12191219
1220 /// WriteAsOperand - Write the name of the specified value out to the specified
1221 /// ostream. This can be useful when you just want to print int %reg126, not
1222 /// the whole instruction that generated it.
1223 ///
1224 void llvm::WriteAsOperand(std::ostream &Out, const Value *V, bool PrintType,
1225 const Module *Context) {
1226 raw_os_ostream OS(Out);
1227 WriteAsOperand(OS, V, PrintType, Context);
1228 }
1229
12301220 void llvm::WriteAsOperand(raw_ostream &Out, const Value *V,
12311221 bool PrintType, const Module *Context) {
12321222
20752065 }
20762066 }
20772067
2078 /*
2079 void Value::print(std::ostream &O, AssemblyAnnotationWriter *AAW) const {
2080 raw_os_ostream OS(O);
2081 print(OS, AAW);
2082 }*/
2083
20842068 // Value::dump - allow easy printing of Values from the debugger.
20852069 void Value::dump() const { print(errs()); errs() << '\n'; }
20862070
2222 #include "llvm/ADT/SmallVector.h"
2323 #include "llvm/Analysis/DominatorInternals.h"
2424 #include "llvm/Instructions.h"
25 #include "llvm/Support/Streams.h"
25 #include "llvm/Support/raw_ostream.h"
2626 #include
2727 using namespace llvm;
28
29 namespace llvm {
30 static std::ostream &operator<<(std::ostream &o,
31 const std::set &BBs) {
32 for (std::set::const_iterator I = BBs.begin(), E = BBs.end();
33 I != E; ++I)
34 if (*I)
35 WriteAsOperand(o, *I, false);
36 else
37 o << " <>";
38 return o;
39 }
40 }
4128
4229 //===----------------------------------------------------------------------===//
4330 // DominatorTree Implementation
5946 DT->recalculate(F);
6047 return false;
6148 }
49
50 void DominatorTree::print(std::ostream &OS, const Module *) const {
51 raw_os_ostream OSS(OS);
52 DT->print(OSS);
53 }
54
55
6256
6357 //===----------------------------------------------------------------------===//
6458 // DominanceFrontier Implementation
269263 return *Result;
270264 }
271265
272 void DominanceFrontierBase::print(std::ostream &o, const Module* ) const {
266 void DominanceFrontierBase::print(std::ostream &O, const Module* ) const {
267 raw_os_ostream OS(O);
273268 for (const_iterator I = begin(), E = end(); I != E; ++I) {
274 o << " DomFrontier for BB";
269 OS << " DomFrontier for BB";
275270 if (I->first)
276 WriteAsOperand(o, I->first, false);
271 WriteAsOperand(OS, I->first, false);
277272 else
278 o << " <>";
279 o << " is:\t" << I->second << "\n";
280 }
281 }
282
283 void DominanceFrontierBase::dump() {
284 print (llvm::cerr);
285 }
286
273 OS << " <>";
274 OS << " is:\t";
275
276 const std::set &BBs = I->second;
277
278 for (std::set::const_iterator I = BBs.begin(), E = BBs.end();
279 I != E; ++I)
280 if (*I)
281 WriteAsOperand(OS, *I, false);
282 else
283 OS << " <>";
284 OS << "\n";
285 }
286 }
287
8585 for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) {
8686 if (I->empty() || !I->back().isTerminator()) {
8787 cerr << "Basic Block does not have terminator!\n";
88 WriteAsOperand(*cerr, I, true);
88 WriteAsOperand(errs(), I, true);
8989 cerr << "\n";
9090 Broken = true;
9191 }