1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 20:51:52 +01:00

eliminate the std::ostream form of WriteAsOperand and update clients.

This also updates dominator related stuff.

llvm-svn: 79825
This commit is contained in:
Chris Lattner 2009-08-23 05:17:37 +00:00
parent 8500c36f86
commit ea2bfd7a9f
16 changed files with 101 additions and 124 deletions

View File

@ -155,8 +155,7 @@ public:
iterator end() const { return iterator(); } iterator end() const { return iterator(); }
bool empty() const { return PtrList == 0; } bool empty() const { return PtrList == 0; }
void print(std::ostream &OS) const; void print(raw_ostream &OS) const;
void print(std::ostream *OS) const { if (OS) print(*OS); }
void dump() const; void dump() const;
/// Define an iterator for alias sets... this is just a forward iterator. /// Define an iterator for alias sets... this is just a forward iterator.
@ -245,7 +244,7 @@ private:
bool aliasesCallSite(CallSite CS, AliasAnalysis &AA) const; bool aliasesCallSite(CallSite CS, AliasAnalysis &AA) const;
}; };
inline std::ostream& operator<<(std::ostream &OS, const AliasSet &AS) { inline raw_ostream& operator<<(raw_ostream &OS, const AliasSet &AS) {
AS.print(OS); AS.print(OS);
return OS; return OS;
} }
@ -374,8 +373,7 @@ public:
iterator begin() { return AliasSets.begin(); } iterator begin() { return AliasSets.begin(); }
iterator end() { return AliasSets.end(); } iterator end() { return AliasSets.end(); }
void print(std::ostream &OS) const; void print(raw_ostream &OS) const;
void print(std::ostream *OS) const { if (OS) print(*OS); }
void dump() const; void dump() const;
private: private:
@ -403,7 +401,7 @@ private:
AliasSet *findAliasSetForCallSite(CallSite CS); AliasSet *findAliasSetForCallSite(CallSite CS);
}; };
inline std::ostream& operator<<(std::ostream &OS, const AliasSetTracker &AST) { inline raw_ostream& operator<<(raw_ostream &OS, const AliasSetTracker &AST) {
AST.print(OS); AST.print(OS);
return OS; return OS;
} }

View File

@ -32,6 +32,7 @@
#include "llvm/Assembly/Writer.h" #include "llvm/Assembly/Writer.h"
#include "llvm/Support/CFG.h" #include "llvm/Support/CFG.h"
#include "llvm/Support/Compiler.h" #include "llvm/Support/Compiler.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm> #include <algorithm>
#include <map> #include <map>
#include <set> #include <set>
@ -161,7 +162,7 @@ EXTERN_TEMPLATE_INSTANTIATION(class DomTreeNodeBase<BasicBlock>);
EXTERN_TEMPLATE_INSTANTIATION(class DomTreeNodeBase<MachineBasicBlock>); EXTERN_TEMPLATE_INSTANTIATION(class DomTreeNodeBase<MachineBasicBlock>);
template<class NodeT> template<class NodeT>
static std::ostream &operator<<(std::ostream &o, static raw_ostream &operator<<(raw_ostream &o,
const DomTreeNodeBase<NodeT> *Node) { const DomTreeNodeBase<NodeT> *Node) {
if (Node->getBlock()) if (Node->getBlock())
WriteAsOperand(o, Node->getBlock(), false); WriteAsOperand(o, Node->getBlock(), false);
@ -174,9 +175,9 @@ static std::ostream &operator<<(std::ostream &o,
} }
template<class NodeT> template<class NodeT>
static void PrintDomTree(const DomTreeNodeBase<NodeT> *N, std::ostream &o, static void PrintDomTree(const DomTreeNodeBase<NodeT> *N, raw_ostream &o,
unsigned Lev) { unsigned Lev) {
o << std::string(2*Lev, ' ') << "[" << Lev << "] " << N; o.indent(2*Lev) << "[" << Lev << "] " << N;
for (typename DomTreeNodeBase<NodeT>::const_iterator I = N->begin(), for (typename DomTreeNodeBase<NodeT>::const_iterator I = N->begin(),
E = N->end(); I != E; ++I) E = N->end(); I != E; ++I)
PrintDomTree<NodeT>(*I, o, Lev+1); PrintDomTree<NodeT>(*I, o, Lev+1);
@ -534,7 +535,7 @@ public:
/// print - Convert to human readable form /// print - Convert to human readable form
/// ///
virtual void print(std::ostream &o, const Module* ) const { void print(raw_ostream &o) const {
o << "=============================--------------------------------\n"; o << "=============================--------------------------------\n";
if (this->isPostDominator()) if (this->isPostDominator())
o << "Inorder PostDominator Tree: "; o << "Inorder PostDominator Tree: ";
@ -547,14 +548,6 @@ public:
PrintDomTree<NodeT>(getRootNode(), o, 1); PrintDomTree<NodeT>(getRootNode(), o, 1);
} }
void print(std::ostream *OS, const Module* M = 0) const {
if (OS) print(*OS, M);
}
virtual void dump() {
print(llvm::cerr);
}
protected: protected:
template<class GraphT> template<class GraphT>
friend void Compress(DominatorTreeBase<typename GraphT::NodeType>& DT, friend void Compress(DominatorTreeBase<typename GraphT::NodeType>& DT,
@ -837,9 +830,7 @@ public:
DT->releaseMemory(); DT->releaseMemory();
} }
virtual void print(std::ostream &OS, const Module* M= 0) const { virtual void print(std::ostream &OS, const Module* M= 0) const;
DT->print(OS, M);
}
}; };
//===------------------------------------- //===-------------------------------------
@ -988,10 +979,6 @@ public:
/// print - Convert to human readable form /// print - Convert to human readable form
/// ///
virtual void print(std::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);
}
virtual void dump();
}; };

View File

@ -454,8 +454,8 @@ public:
#endif #endif
} }
void print(std::ostream &OS, unsigned Depth = 0) const { void print(raw_ostream &OS, unsigned Depth = 0) const {
OS << std::string(Depth*2, ' ') << "Loop at depth " << getLoopDepth() OS.indent(Depth*2) << "Loop at depth " << getLoopDepth()
<< " containing: "; << " containing: ";
for (unsigned i = 0; i < getBlocks().size(); ++i) { for (unsigned i = 0; i < getBlocks().size(); ++i) {
@ -472,12 +472,8 @@ public:
(*I)->print(OS, Depth+2); (*I)->print(OS, Depth+2);
} }
void print(std::ostream *O, unsigned Depth = 0) const {
if (O) print(*O, Depth);
}
void dump() const { void dump() const {
print(cerr); print(errs());
} }
protected: protected:
@ -878,7 +874,7 @@ public:
// Debugging // Debugging
void print(std::ostream &OS, const Module* ) const { void print(raw_ostream &OS) const {
for (unsigned i = 0; i < TopLevelLoops.size(); ++i) for (unsigned i = 0; i < TopLevelLoops.size(); ++i)
TopLevelLoops[i]->print(OS); TopLevelLoops[i]->print(OS);
#if 0 #if 0
@ -942,9 +938,7 @@ public:
virtual void releaseMemory() { LI.releaseMemory(); } virtual void releaseMemory() { LI.releaseMemory(); }
virtual void print(std::ostream &O, const Module* M = 0) const { virtual void print(std::ostream &O, const Module* M = 0) const;
LI.print(O, M);
}
virtual void getAnalysisUsage(AnalysisUsage &AU) const; virtual void getAnalysisUsage(AnalysisUsage &AU) const;

View File

@ -57,9 +57,7 @@ struct PostDominatorTree : public FunctionPass {
return DT->properlyDominates(A, B); return DT->properlyDominates(A, B);
} }
virtual void print(std::ostream &OS, const Module* M= 0) const { virtual void print(std::ostream &OS, const Module*) const;
DT->print(OS, M);
}
}; };
FunctionPass* createPostDomTree(); FunctionPass* createPostDomTree();

View File

@ -17,7 +17,6 @@
#ifndef LLVM_ASSEMBLY_WRITER_H #ifndef LLVM_ASSEMBLY_WRITER_H
#define LLVM_ASSEMBLY_WRITER_H #define LLVM_ASSEMBLY_WRITER_H
#include <iosfwd>
#include <string> #include <string>
namespace llvm { namespace llvm {
@ -71,8 +70,6 @@ void WriteTypeSymbolic(raw_ostream &, const Type *, const Module *M);
// then even constants get pretty-printed; for example, the type of a null // then even constants get pretty-printed; for example, the type of a null
// pointer is printed symbolically. // pointer is printed symbolically.
// //
void WriteAsOperand(std::ostream &, const Value *, bool PrintTy = true,
const Module *Context = 0);
void WriteAsOperand(raw_ostream &, const Value *, bool PrintTy = true, void WriteAsOperand(raw_ostream &, const Value *, bool PrintTy = true,
const Module *Context = 0); const Module *Context = 0);

View File

@ -23,7 +23,7 @@
namespace llvm { namespace llvm {
inline void WriteAsOperand(std::ostream &, const MachineBasicBlock*, bool t) { } inline void WriteAsOperand(raw_ostream &, const MachineBasicBlock*, bool t) { }
template<> template<>
inline void DominatorTreeBase<MachineBasicBlock>::addRoot(MachineBasicBlock* MBB) { inline void DominatorTreeBase<MachineBasicBlock>::addRoot(MachineBasicBlock* MBB) {
@ -162,9 +162,7 @@ public:
virtual void releaseMemory(); virtual void releaseMemory();
virtual void print(std::ostream &OS, const Module* M= 0) const { virtual void print(std::ostream &OS, const Module*) const;
DT->print(OS, M);
}
}; };
//===------------------------------------- //===-------------------------------------

View File

@ -42,33 +42,33 @@ namespace {
} }
void printLine(const char *Desc, unsigned Val, unsigned Sum) { void printLine(const char *Desc, unsigned Val, unsigned Sum) {
cerr << " " << Val << " " << Desc << " responses (" errs() << " " << Val << " " << Desc << " responses ("
<< Val*100/Sum << "%)\n"; << Val*100/Sum << "%)\n";
} }
~AliasAnalysisCounter() { ~AliasAnalysisCounter() {
unsigned AASum = No+May+Must; unsigned AASum = No+May+Must;
unsigned MRSum = NoMR+JustRef+JustMod+MR; unsigned MRSum = NoMR+JustRef+JustMod+MR;
if (AASum + MRSum) { // Print a report if any counted queries occurred... if (AASum + MRSum) { // Print a report if any counted queries occurred...
cerr << "\n===== Alias Analysis Counter Report =====\n" errs() << "\n===== Alias Analysis Counter Report =====\n"
<< " Analysis counted: " << Name << "\n" << " Analysis counted: " << Name << "\n"
<< " " << AASum << " Total Alias Queries Performed\n"; << " " << AASum << " Total Alias Queries Performed\n";
if (AASum) { if (AASum) {
printLine("no alias", No, AASum); printLine("no alias", No, AASum);
printLine("may alias", May, AASum); printLine("may alias", May, AASum);
printLine("must alias", Must, AASum); printLine("must alias", Must, AASum);
cerr << " Alias Analysis Counter Summary: " << No*100/AASum << "%/" errs() << " Alias Analysis Counter Summary: " << No*100/AASum << "%/"
<< May*100/AASum << "%/" << Must*100/AASum<<"%\n\n"; << May*100/AASum << "%/" << Must*100/AASum<<"%\n\n";
} }
cerr << " " << MRSum << " Total Mod/Ref Queries Performed\n"; errs() << " " << MRSum << " Total Mod/Ref Queries Performed\n";
if (MRSum) { if (MRSum) {
printLine("no mod/ref", NoMR, MRSum); printLine("no mod/ref", NoMR, MRSum);
printLine("ref", JustRef, MRSum); printLine("ref", JustRef, MRSum);
printLine("mod", JustMod, MRSum); printLine("mod", JustMod, MRSum);
printLine("mod/ref", MR, MRSum); printLine("mod/ref", MR, MRSum);
cerr << " Mod/Ref Analysis Counter Summary: " <<NoMR*100/MRSum<< "%/" errs() << " Mod/Ref Analysis Counter Summary: " <<NoMR*100/MRSum
<< JustRef*100/MRSum << "%/" << JustMod*100/MRSum << "%/" << "%/" << JustRef*100/MRSum << "%/" << JustMod*100/MRSum
<< MR*100/MRSum <<"%\n\n"; << "%/" << MR*100/MRSum <<"%\n\n";
} }
} }
} }
@ -139,13 +139,13 @@ AliasAnalysisCounter::alias(const Value *V1, unsigned V1Size,
} }
if (PrintAll || (PrintAllFailures && R == MayAlias)) { if (PrintAll || (PrintAllFailures && R == MayAlias)) {
cerr << AliasString << ":\t"; errs() << AliasString << ":\t";
cerr << "[" << V1Size << "B] "; errs() << "[" << V1Size << "B] ";
WriteAsOperand(*cerr.stream(), V1, true, M); WriteAsOperand(errs(), V1, true, M);
cerr << ", "; errs() << ", ";
cerr << "[" << V2Size << "B] "; errs() << "[" << V2Size << "B] ";
WriteAsOperand(*cerr.stream(), V2, true, M); WriteAsOperand(errs(), V2, true, M);
cerr << "\n"; errs() << "\n";
} }
return R; return R;

View File

@ -81,13 +81,16 @@ X("aa-eval", "Exhaustive Alias Analysis Precision Evaluator", false, true);
FunctionPass *llvm::createAAEvalPass() { return new AAEval(); } FunctionPass *llvm::createAAEvalPass() { return new AAEval(); }
static void PrintResults(const char *Msg, bool P, const Value *V1, const Value *V2, static void PrintResults(const char *Msg, bool P, const Value *V1,
const Module *M) { const Value *V2, const Module *M) {
if (P) { if (P) {
std::stringstream s1, s2; std::string o1, o2;
WriteAsOperand(s1, V1, true, M); {
WriteAsOperand(s2, V2, true, M); raw_string_ostream os1(o1), os2(o2);
std::string o1(s1.str()), o2(s2.str()); WriteAsOperand(os1, V1, true, M);
WriteAsOperand(os2, V2, true, M);
}
if (o2 < o1) if (o2 < o1)
std::swap(o1, o2); std::swap(o1, o2);
errs() << " " << Msg << ":\t" errs() << " " << Msg << ":\t"

View File

@ -22,7 +22,8 @@
#include "llvm/Support/Compiler.h" #include "llvm/Support/Compiler.h"
#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/InstIterator.h" #include "llvm/Support/InstIterator.h"
#include "llvm/Support/Streams.h" #include "llvm/Support/Format.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm; using namespace llvm;
/// mergeSetIn - Merge the specified alias set into this alias set. /// mergeSetIn - Merge the specified alias set into this alias set.
@ -531,8 +532,8 @@ void AliasSetTracker::copyValue(Value *From, Value *To) {
// AliasSet/AliasSetTracker Printing Support // AliasSet/AliasSetTracker Printing Support
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
void AliasSet::print(std::ostream &OS) const { void AliasSet::print(raw_ostream &OS) const {
OS << " AliasSet[" << (void*)this << "," << RefCount << "] "; OS << " AliasSet[" << format("0x%p", (void*)this) << "," << RefCount << "] ";
OS << (AliasTy == MustAlias ? "must" : "may") << " alias, "; OS << (AliasTy == MustAlias ? "must" : "may") << " alias, ";
switch (AccessTy) { switch (AccessTy) {
case NoModRef: OS << "No access "; break; case NoModRef: OS << "No access "; break;
@ -564,7 +565,7 @@ void AliasSet::print(std::ostream &OS) const {
OS << "\n"; OS << "\n";
} }
void AliasSetTracker::print(std::ostream &OS) const { void AliasSetTracker::print(raw_ostream &OS) const {
OS << "Alias Set Tracker: " << AliasSets.size() << " alias sets for " OS << "Alias Set Tracker: " << AliasSets.size() << " alias sets for "
<< PointerMap.size() << " pointer values.\n"; << PointerMap.size() << " pointer values.\n";
for (const_iterator I = begin(), E = end(); I != E; ++I) for (const_iterator I = begin(), E = end(); I != E; ++I)
@ -572,8 +573,8 @@ void AliasSetTracker::print(std::ostream &OS) const {
OS << "\n"; OS << "\n";
} }
void AliasSet::dump() const { print (cerr); } void AliasSet::dump() const { print(errs()); }
void AliasSetTracker::dump() const { print(cerr); } void AliasSetTracker::dump() const { print(errs()); }
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// ASTCallbackVH Class Implementation // ASTCallbackVH Class Implementation
@ -614,7 +615,7 @@ namespace {
for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I)
Tracker->add(&*I); Tracker->add(&*I);
Tracker->print(cerr); Tracker->print(errs());
delete Tracker; delete Tracker;
return false; return false;
} }

View File

@ -308,3 +308,9 @@ void LoopInfo::getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll(); AU.setPreservesAll();
AU.addRequired<DominatorTree>(); AU.addRequired<DominatorTree>();
} }
void LoopInfo::print(std::ostream &OS, const Module*) const {
raw_os_ostream OSS(OS);
LI.print(OSS);
}

View File

@ -33,15 +33,20 @@ F("postdomtree", "Post-Dominator Tree Construction", true, true);
bool PostDominatorTree::runOnFunction(Function &F) { bool PostDominatorTree::runOnFunction(Function &F) {
DT->recalculate(F); DT->recalculate(F);
DEBUG(DT->dump()); DEBUG(DT->print(errs()));
return false; return false;
} }
PostDominatorTree::~PostDominatorTree() PostDominatorTree::~PostDominatorTree() {
{
delete DT; delete DT;
} }
void PostDominatorTree::print(std::ostream &OS, const Module *) const {
raw_os_ostream OSS(OS);
DT->print(OSS);
}
FunctionPass* llvm::createPostDomTree() { FunctionPass* llvm::createPostDomTree() {
return new PostDominatorTree(); return new PostDominatorTree();
} }

View File

@ -51,3 +51,8 @@ MachineDominatorTree::~MachineDominatorTree() {
void MachineDominatorTree::releaseMemory() { void MachineDominatorTree::releaseMemory() {
DT->releaseMemory(); DT->releaseMemory();
} }
void MachineDominatorTree::print(std::ostream &OS, const Module*) const {
raw_os_ostream OSS(OS);
DT->print(OSS);
}

View File

@ -425,10 +425,10 @@ namespace {
#ifndef NDEBUG #ifndef NDEBUG
virtual ~ValueNumbering() {} virtual ~ValueNumbering() {}
virtual void dump() { virtual void dump() {
dump(*cerr.stream()); print(errs());
} }
void dump(std::ostream &os) { void print(raw_ostream &os) {
for (unsigned i = 1; i <= Values.size(); ++i) { for (unsigned i = 1; i <= Values.size(); ++i) {
os << i << " = "; os << i << " = ";
WriteAsOperand(os, Values[i-1]); WriteAsOperand(os, Values[i-1]);

View File

@ -1218,16 +1218,6 @@ static void WriteAsOperandInternal(raw_ostream &Out, const Value *V,
Out << "<badref>"; Out << "<badref>";
} }
/// WriteAsOperand - Write the name of the specified value out to the specified
/// ostream. This can be useful when you just want to print int %reg126, not
/// the whole instruction that generated it.
///
void llvm::WriteAsOperand(std::ostream &Out, const Value *V, bool PrintType,
const Module *Context) {
raw_os_ostream OS(Out);
WriteAsOperand(OS, V, PrintType, Context);
}
void llvm::WriteAsOperand(raw_ostream &Out, const Value *V, void llvm::WriteAsOperand(raw_ostream &Out, const Value *V,
bool PrintType, const Module *Context) { bool PrintType, const Module *Context) {
@ -2076,12 +2066,6 @@ void Value::print(raw_ostream &ROS, AssemblyAnnotationWriter *AAW) const {
} }
} }
/*
void Value::print(std::ostream &O, AssemblyAnnotationWriter *AAW) const {
raw_os_ostream OS(O);
print(OS, AAW);
}*/
// Value::dump - allow easy printing of Values from the debugger. // Value::dump - allow easy printing of Values from the debugger.
void Value::dump() const { print(errs()); errs() << '\n'; } void Value::dump() const { print(errs()); errs() << '\n'; }

View File

@ -23,23 +23,10 @@
#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/SmallVector.h"
#include "llvm/Analysis/DominatorInternals.h" #include "llvm/Analysis/DominatorInternals.h"
#include "llvm/Instructions.h" #include "llvm/Instructions.h"
#include "llvm/Support/Streams.h" #include "llvm/Support/raw_ostream.h"
#include <algorithm> #include <algorithm>
using namespace llvm; using namespace llvm;
namespace llvm {
static std::ostream &operator<<(std::ostream &o,
const std::set<BasicBlock*> &BBs) {
for (std::set<BasicBlock*>::const_iterator I = BBs.begin(), E = BBs.end();
I != E; ++I)
if (*I)
WriteAsOperand(o, *I, false);
else
o << " <<exit node>>";
return o;
}
}
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// DominatorTree Implementation // DominatorTree Implementation
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@ -61,6 +48,13 @@ bool DominatorTree::runOnFunction(Function &F) {
return false; return false;
} }
void DominatorTree::print(std::ostream &OS, const Module *) const {
raw_os_ostream OSS(OS);
DT->print(OSS);
}
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// DominanceFrontier Implementation // DominanceFrontier Implementation
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@ -270,18 +264,25 @@ DominanceFrontier::calculate(const DominatorTree &DT,
return *Result; return *Result;
} }
void DominanceFrontierBase::print(std::ostream &o, const Module* ) const { void DominanceFrontierBase::print(std::ostream &O, const Module* ) const {
raw_os_ostream OS(O);
for (const_iterator I = begin(), E = end(); I != E; ++I) { for (const_iterator I = begin(), E = end(); I != E; ++I) {
o << " DomFrontier for BB"; OS << " DomFrontier for BB";
if (I->first) if (I->first)
WriteAsOperand(o, I->first, false); WriteAsOperand(OS, I->first, false);
else else
o << " <<exit node>>"; OS << " <<exit node>>";
o << " is:\t" << I->second << "\n"; OS << " is:\t";
const std::set<BasicBlock*> &BBs = I->second;
for (std::set<BasicBlock*>::const_iterator I = BBs.begin(), E = BBs.end();
I != E; ++I)
if (*I)
WriteAsOperand(OS, *I, false);
else
OS << " <<exit node>>";
OS << "\n";
} }
} }
void DominanceFrontierBase::dump() {
print (llvm::cerr);
}

View File

@ -86,7 +86,7 @@ namespace { // Anonymous namespace for class
for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) { for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) {
if (I->empty() || !I->back().isTerminator()) { if (I->empty() || !I->back().isTerminator()) {
cerr << "Basic Block does not have terminator!\n"; cerr << "Basic Block does not have terminator!\n";
WriteAsOperand(*cerr, I, true); WriteAsOperand(errs(), I, true);
cerr << "\n"; cerr << "\n";
Broken = true; Broken = true;
} }