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 76d8c5725f
commit b1d782bec9
16 changed files with 101 additions and 124 deletions

View File

@ -155,8 +155,7 @@ public:
iterator end() const { return iterator(); }
bool empty() const { return PtrList == 0; }
void print(std::ostream &OS) const;
void print(std::ostream *OS) const { if (OS) print(*OS); }
void print(raw_ostream &OS) const;
void dump() const;
/// Define an iterator for alias sets... this is just a forward iterator.
@ -245,7 +244,7 @@ private:
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);
return OS;
}
@ -374,8 +373,7 @@ public:
iterator begin() { return AliasSets.begin(); }
iterator end() { return AliasSets.end(); }
void print(std::ostream &OS) const;
void print(std::ostream *OS) const { if (OS) print(*OS); }
void print(raw_ostream &OS) const;
void dump() const;
private:
@ -403,7 +401,7 @@ private:
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);
return OS;
}

View File

@ -32,6 +32,7 @@
#include "llvm/Assembly/Writer.h"
#include "llvm/Support/CFG.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <map>
#include <set>
@ -161,8 +162,8 @@ EXTERN_TEMPLATE_INSTANTIATION(class DomTreeNodeBase<BasicBlock>);
EXTERN_TEMPLATE_INSTANTIATION(class DomTreeNodeBase<MachineBasicBlock>);
template<class NodeT>
static std::ostream &operator<<(std::ostream &o,
const DomTreeNodeBase<NodeT> *Node) {
static raw_ostream &operator<<(raw_ostream &o,
const DomTreeNodeBase<NodeT> *Node) {
if (Node->getBlock())
WriteAsOperand(o, Node->getBlock(), false);
else
@ -174,9 +175,9 @@ static std::ostream &operator<<(std::ostream &o,
}
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) {
o << std::string(2*Lev, ' ') << "[" << Lev << "] " << N;
o.indent(2*Lev) << "[" << Lev << "] " << N;
for (typename DomTreeNodeBase<NodeT>::const_iterator I = N->begin(),
E = N->end(); I != E; ++I)
PrintDomTree<NodeT>(*I, o, Lev+1);
@ -534,7 +535,7 @@ public:
/// print - Convert to human readable form
///
virtual void print(std::ostream &o, const Module* ) const {
void print(raw_ostream &o) const {
o << "=============================--------------------------------\n";
if (this->isPostDominator())
o << "Inorder PostDominator Tree: ";
@ -547,14 +548,6 @@ public:
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:
template<class GraphT>
friend void Compress(DominatorTreeBase<typename GraphT::NodeType>& DT,
@ -837,9 +830,7 @@ public:
DT->releaseMemory();
}
virtual void print(std::ostream &OS, const Module* M= 0) const {
DT->print(OS, M);
}
virtual void print(std::ostream &OS, const Module* M= 0) const;
};
//===-------------------------------------
@ -988,10 +979,6 @@ public:
/// print - Convert to human readable form
///
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
}
void print(std::ostream &OS, unsigned Depth = 0) const {
OS << std::string(Depth*2, ' ') << "Loop at depth " << getLoopDepth()
void print(raw_ostream &OS, unsigned Depth = 0) const {
OS.indent(Depth*2) << "Loop at depth " << getLoopDepth()
<< " containing: ";
for (unsigned i = 0; i < getBlocks().size(); ++i) {
@ -472,12 +472,8 @@ public:
(*I)->print(OS, Depth+2);
}
void print(std::ostream *O, unsigned Depth = 0) const {
if (O) print(*O, Depth);
}
void dump() const {
print(cerr);
print(errs());
}
protected:
@ -878,7 +874,7 @@ public:
// Debugging
void print(std::ostream &OS, const Module* ) const {
void print(raw_ostream &OS) const {
for (unsigned i = 0; i < TopLevelLoops.size(); ++i)
TopLevelLoops[i]->print(OS);
#if 0
@ -942,10 +938,8 @@ public:
virtual void releaseMemory() { LI.releaseMemory(); }
virtual void print(std::ostream &O, const Module* M = 0) const {
LI.print(O, M);
}
virtual void print(std::ostream &O, const Module* M = 0) const;
virtual void getAnalysisUsage(AnalysisUsage &AU) const;
/// removeLoop - This removes the specified top-level loop from this loop info

View File

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

View File

@ -17,7 +17,6 @@
#ifndef LLVM_ASSEMBLY_WRITER_H
#define LLVM_ASSEMBLY_WRITER_H
#include <iosfwd>
#include <string>
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
// 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,
const Module *Context = 0);

View File

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

View File

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

View File

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

View File

@ -22,7 +22,8 @@
#include "llvm/Support/Compiler.h"
#include "llvm/Support/ErrorHandling.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;
/// 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
//===----------------------------------------------------------------------===//
void AliasSet::print(std::ostream &OS) const {
OS << " AliasSet[" << (void*)this << "," << RefCount << "] ";
void AliasSet::print(raw_ostream &OS) const {
OS << " AliasSet[" << format("0x%p", (void*)this) << "," << RefCount << "] ";
OS << (AliasTy == MustAlias ? "must" : "may") << " alias, ";
switch (AccessTy) {
case NoModRef: OS << "No access "; break;
@ -564,7 +565,7 @@ void AliasSet::print(std::ostream &OS) const {
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 "
<< PointerMap.size() << " pointer values.\n";
for (const_iterator I = begin(), E = end(); I != E; ++I)
@ -572,8 +573,8 @@ void AliasSetTracker::print(std::ostream &OS) const {
OS << "\n";
}
void AliasSet::dump() const { print (cerr); }
void AliasSetTracker::dump() const { print(cerr); }
void AliasSet::dump() const { print(errs()); }
void AliasSetTracker::dump() const { print(errs()); }
//===----------------------------------------------------------------------===//
// ASTCallbackVH Class Implementation
@ -614,7 +615,7 @@ namespace {
for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I)
Tracker->add(&*I);
Tracker->print(cerr);
Tracker->print(errs());
delete Tracker;
return false;
}

View File

@ -308,3 +308,9 @@ void LoopInfo::getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
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) {
DT->recalculate(F);
DEBUG(DT->dump());
DEBUG(DT->print(errs()));
return false;
}
PostDominatorTree::~PostDominatorTree()
{
PostDominatorTree::~PostDominatorTree() {
delete DT;
}
void PostDominatorTree::print(std::ostream &OS, const Module *) const {
raw_os_ostream OSS(OS);
DT->print(OSS);
}
FunctionPass* llvm::createPostDomTree() {
return new PostDominatorTree();
}

View File

@ -51,3 +51,8 @@ MachineDominatorTree::~MachineDominatorTree() {
void MachineDominatorTree::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
virtual ~ValueNumbering() {}
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) {
os << i << " = ";
WriteAsOperand(os, Values[i-1]);

View File

@ -1218,16 +1218,6 @@ static void WriteAsOperandInternal(raw_ostream &Out, const Value *V,
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,
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.
void Value::dump() const { print(errs()); errs() << '\n'; }

View File

@ -23,23 +23,10 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/Analysis/DominatorInternals.h"
#include "llvm/Instructions.h"
#include "llvm/Support/Streams.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
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
//===----------------------------------------------------------------------===//
@ -61,6 +48,13 @@ bool DominatorTree::runOnFunction(Function &F) {
return false;
}
void DominatorTree::print(std::ostream &OS, const Module *) const {
raw_os_ostream OSS(OS);
DT->print(OSS);
}
//===----------------------------------------------------------------------===//
// DominanceFrontier Implementation
//===----------------------------------------------------------------------===//
@ -270,18 +264,25 @@ DominanceFrontier::calculate(const DominatorTree &DT,
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) {
o << " DomFrontier for BB";
OS << " DomFrontier for BB";
if (I->first)
WriteAsOperand(o, I->first, false);
WriteAsOperand(OS, I->first, false);
else
o << " <<exit node>>";
o << " is:\t" << I->second << "\n";
OS << " <<exit node>>";
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) {
if (I->empty() || !I->back().isTerminator()) {
cerr << "Basic Block does not have terminator!\n";
WriteAsOperand(*cerr, I, true);
WriteAsOperand(errs(), I, true);
cerr << "\n";
Broken = true;
}