From 944fac71e082cc2664cc71b4d3f6c72bab7143fb Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 23 Aug 2008 22:23:09 +0000 Subject: Switch the asmprinter (.ll) and all the stuff it requires over to use raw_ostream instead of std::ostream. Among other goodness, this speeds up llvm-dis of kc++ with a release build from 0.85s to 0.49s (88% faster). Other interesting changes: 1) This makes Value::print be non-virtual. 2) AP[S]Int and ConstantRange can no longer print to ostream directly, use raw_ostream instead. 3) This fixes a bug in raw_os_ostream where it didn't flush itself when destroyed. 4) This adds a new SDNode::print method, instead of only allowing "dump". A lot of APIs have both std::ostream and raw_ostream versions, it would be useful to go through and systematically anihilate the std::ostream versions. This passes dejagnu, but there may be minor fallout, plz let me know if so and I'll fix it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@55263 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/LoopVR.cpp | 13 ++- lib/CodeGen/MachineFunction.cpp | 5 + lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 148 ++++++++++++------------- lib/Support/APInt.cpp | 9 +- lib/Support/ConstantRange.cpp | 7 +- lib/Support/raw_ostream.cpp | 10 ++ lib/Target/ARM/ARMConstantPoolValue.cpp | 3 +- lib/Target/ARM/ARMConstantPoolValue.h | 2 +- lib/Target/PIC16/PIC16ConstantPoolValue.cpp | 3 +- lib/Target/PIC16/PIC16ConstantPoolValue.h | 2 +- lib/Transforms/Scalar/PredicateSimplifier.cpp | 2 +- lib/Transforms/Utils/LowerSwitch.cpp | 8 +- lib/VMCore/AsmWriter.cpp | 154 +++++++++++++++----------- lib/VMCore/Module.cpp | 5 - 14 files changed, 201 insertions(+), 170 deletions(-) (limited to 'lib') diff --git a/lib/Analysis/LoopVR.cpp b/lib/Analysis/LoopVR.cpp index eb7524a9c2..7f5de259ca 100644 --- a/lib/Analysis/LoopVR.cpp +++ b/lib/Analysis/LoopVR.cpp @@ -6,6 +6,10 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// +// +// FIXME: What does this do? +// +//===----------------------------------------------------------------------===// #define DEBUG_TYPE "loopvr" #include "llvm/Analysis/LoopVR.h" @@ -15,13 +19,11 @@ #include "llvm/Assembly/Writer.h" #include "llvm/Support/CFG.h" #include "llvm/Support/Debug.h" -#include "llvm/Support/Streams.h" +#include "llvm/Support/raw_ostream.h" using namespace llvm; char LoopVR::ID = 0; -namespace { static RegisterPass X("loopvr", "Loop Value Ranges", true, true); -} /// getRange - determine the range for a particular SCEV within a given Loop ConstantRange LoopVR::getRange(SCEVHandle S, Loop *L, ScalarEvolution &SE) { @@ -220,11 +222,10 @@ ConstantRange LoopVR::getRange(SCEVHandle S, SCEVHandle T, ScalarEvolution &SE){ bool LoopVR::runOnFunction(Function &F) { Map.clear(); return false; } void LoopVR::print(std::ostream &os, const Module *) const { + raw_os_ostream OS(os); for (std::map::const_iterator I = Map.begin(), E = Map.end(); I != E; ++I) { - os << *I->first << ": "; - I->second->print(os); - os << "\n"; + OS << *I->first << ": " << *I->second << '\n'; } } diff --git a/lib/CodeGen/MachineFunction.cpp b/lib/CodeGen/MachineFunction.cpp index b243297253..bc5d59e8be 100644 --- a/lib/CodeGen/MachineFunction.cpp +++ b/lib/CodeGen/MachineFunction.cpp @@ -28,6 +28,7 @@ #include "llvm/Instructions.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/GraphWriter.h" +#include "llvm/Support/raw_ostream.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Config/config.h" #include @@ -525,6 +526,10 @@ unsigned MachineConstantPool::getConstantPoolIndex(MachineConstantPoolValue *V, return Constants.size()-1; } +void MachineConstantPoolValue::print(std::ostream &o) const { + raw_os_ostream OS(o); + print(OS); +} void MachineConstantPool::print(std::ostream &OS) const { for (unsigned i = 0, e = Constants.size(); i != e; ++i) { diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 9275a21f9f..fa73e73de0 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -24,12 +24,13 @@ #include "llvm/CodeGen/MachineFrameInfo.h" #include "llvm/CodeGen/MachineModuleInfo.h" #include "llvm/CodeGen/PseudoSourceValue.h" -#include "llvm/Support/MathExtras.h" #include "llvm/Target/TargetRegisterInfo.h" #include "llvm/Target/TargetData.h" #include "llvm/Target/TargetLowering.h" #include "llvm/Target/TargetInstrInfo.h" #include "llvm/Target/TargetMachine.h" +#include "llvm/Support/MathExtras.h" +#include "llvm/Support/raw_ostream.h" #include "llvm/ADT/SetVector.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallSet.h" @@ -4980,169 +4981,166 @@ std::string ISD::ArgFlagsTy::getArgFlagsString() { void SDNode::dump() const { dump(0); } void SDNode::dump(const SelectionDAG *G) const { - cerr << (void*)this << ": "; + print(errs(), G); +} + +void SDNode::print(raw_ostream &OS, const SelectionDAG *G) const { + OS << (void*)this << ": "; for (unsigned i = 0, e = getNumValues(); i != e; ++i) { - if (i) cerr << ","; + if (i) OS << ","; if (getValueType(i) == MVT::Other) - cerr << "ch"; + OS << "ch"; else - cerr << getValueType(i).getMVTString(); + OS << getValueType(i).getMVTString(); } - cerr << " = " << getOperationName(G); + OS << " = " << getOperationName(G); - cerr << " "; + OS << " "; for (unsigned i = 0, e = getNumOperands(); i != e; ++i) { - if (i) cerr << ", "; - cerr << (void*)getOperand(i).Val; + if (i) OS << ", "; + OS << (void*)getOperand(i).Val; if (unsigned RN = getOperand(i).ResNo) - cerr << ":" << RN; + OS << ":" << RN; } if (!isTargetOpcode() && getOpcode() == ISD::VECTOR_SHUFFLE) { SDNode *Mask = getOperand(2).Val; - cerr << "<"; + OS << "<"; for (unsigned i = 0, e = Mask->getNumOperands(); i != e; ++i) { - if (i) cerr << ","; + if (i) OS << ","; if (Mask->getOperand(i).getOpcode() == ISD::UNDEF) - cerr << "u"; + OS << "u"; else - cerr << cast(Mask->getOperand(i))->getValue(); + OS << cast(Mask->getOperand(i))->getValue(); } - cerr << ">"; + OS << ">"; } if (const ConstantSDNode *CSDN = dyn_cast(this)) { - cerr << '<' << CSDN->getAPIntValue() << '>'; + OS << '<' << CSDN->getAPIntValue() << '>'; } else if (const ConstantFPSDNode *CSDN = dyn_cast(this)) { if (&CSDN->getValueAPF().getSemantics()==&APFloat::IEEEsingle) - cerr << '<' << CSDN->getValueAPF().convertToFloat() << '>'; + OS << '<' << CSDN->getValueAPF().convertToFloat() << '>'; else if (&CSDN->getValueAPF().getSemantics()==&APFloat::IEEEdouble) - cerr << '<' << CSDN->getValueAPF().convertToDouble() << '>'; + OS << '<' << CSDN->getValueAPF().convertToDouble() << '>'; else { - cerr << "getValueAPF().convertToAPInt().dump(); - cerr << ")>"; + OS << ")>"; } } else if (const GlobalAddressSDNode *GADN = dyn_cast(this)) { int offset = GADN->getOffset(); - cerr << '<'; - WriteAsOperand(*cerr.stream(), GADN->getGlobal()); - cerr << '>'; + OS << '<'; + WriteAsOperand(OS, GADN->getGlobal()); + OS << '>'; if (offset > 0) - cerr << " + " << offset; + OS << " + " << offset; else - cerr << " " << offset; + OS << " " << offset; } else if (const FrameIndexSDNode *FIDN = dyn_cast(this)) { - cerr << "<" << FIDN->getIndex() << ">"; + OS << "<" << FIDN->getIndex() << ">"; } else if (const JumpTableSDNode *JTDN = dyn_cast(this)) { - cerr << "<" << JTDN->getIndex() << ">"; + OS << "<" << JTDN->getIndex() << ">"; } else if (const ConstantPoolSDNode *CP = dyn_cast(this)){ int offset = CP->getOffset(); if (CP->isMachineConstantPoolEntry()) - cerr << "<" << *CP->getMachineCPVal() << ">"; + OS << "<" << *CP->getMachineCPVal() << ">"; else - cerr << "<" << *CP->getConstVal() << ">"; + OS << "<" << *CP->getConstVal() << ">"; if (offset > 0) - cerr << " + " << offset; + OS << " + " << offset; else - cerr << " " << offset; + OS << " " << offset; } else if (const BasicBlockSDNode *BBDN = dyn_cast(this)) { - cerr << "<"; + OS << "<"; const Value *LBB = (const Value*)BBDN->getBasicBlock()->getBasicBlock(); if (LBB) - cerr << LBB->getName() << " "; - cerr << (const void*)BBDN->getBasicBlock() << ">"; + OS << LBB->getName() << " "; + OS << (const void*)BBDN->getBasicBlock() << ">"; } else if (const RegisterSDNode *R = dyn_cast(this)) { if (G && R->getReg() && TargetRegisterInfo::isPhysicalRegister(R->getReg())) { - cerr << " " << G->getTarget().getRegisterInfo()->getName(R->getReg()); + OS << " " << G->getTarget().getRegisterInfo()->getName(R->getReg()); } else { - cerr << " #" << R->getReg(); + OS << " #" << R->getReg(); } } else if (const ExternalSymbolSDNode *ES = dyn_cast(this)) { - cerr << "'" << ES->getSymbol() << "'"; + OS << "'" << ES->getSymbol() << "'"; } else if (const SrcValueSDNode *M = dyn_cast(this)) { if (M->getValue()) - cerr << "<" << M->getValue() << ">"; + OS << "<" << M->getValue() << ">"; else - cerr << ""; + OS << ""; } else if (const MemOperandSDNode *M = dyn_cast(this)) { if (M->MO.getValue()) - cerr << "<" << M->MO.getValue() << ":" << M->MO.getOffset() << ">"; + OS << "<" << M->MO.getValue() << ":" << M->MO.getOffset() << ">"; else - cerr << "MO.getOffset() << ">"; + OS << "MO.getOffset() << ">"; } else if (const ARG_FLAGSSDNode *N = dyn_cast(this)) { - cerr << N->getArgFlags().getArgFlagsString(); + OS << N->getArgFlags().getArgFlagsString(); } else if (const VTSDNode *N = dyn_cast(this)) { - cerr << ":" << N->getVT().getMVTString(); + OS << ":" << N->getVT().getMVTString(); } else if (const LoadSDNode *LD = dyn_cast(this)) { const Value *SrcValue = LD->getSrcValue(); int SrcOffset = LD->getSrcValueOffset(); - cerr << " <"; + OS << " <"; if (SrcValue) - cerr << SrcValue; + OS << SrcValue; else - cerr << "null"; - cerr << ":" << SrcOffset << ">"; + OS << "null"; + OS << ":" << SrcOffset << ">"; bool doExt = true; switch (LD->getExtensionType()) { default: doExt = false; break; - case ISD::EXTLOAD: - cerr << " getMemoryVT().getMVTString() << ">"; + OS << LD->getMemoryVT().getMVTString() << ">"; const char *AM = getIndexedModeName(LD->getAddressingMode()); if (*AM) - cerr << " " << AM; + OS << " " << AM; if (LD->isVolatile()) - cerr << " "; - cerr << " alignment=" << LD->getAlignment(); + OS << " "; + OS << " alignment=" << LD->getAlignment(); } else if (const StoreSDNode *ST = dyn_cast(this)) { const Value *SrcValue = ST->getSrcValue(); int SrcOffset = ST->getSrcValueOffset(); - cerr << " <"; + OS << " <"; if (SrcValue) - cerr << SrcValue; + OS << SrcValue; else - cerr << "null"; - cerr << ":" << SrcOffset << ">"; + OS << "null"; + OS << ":" << SrcOffset << ">"; if (ST->isTruncatingStore()) - cerr << " getMemoryVT().getMVTString() << ">"; + OS << " getMemoryVT().getMVTString() << ">"; const char *AM = getIndexedModeName(ST->getAddressingMode()); if (*AM) - cerr << " " << AM; + OS << " " << AM; if (ST->isVolatile()) - cerr << " "; - cerr << " alignment=" << ST->getAlignment(); + OS << " "; + OS << " alignment=" << ST->getAlignment(); } else if (const AtomicSDNode* AT = dyn_cast(this)) { const Value *SrcValue = AT->getSrcValue(); int SrcOffset = AT->getSrcValueOffset(); - cerr << " <"; + OS << " <"; if (SrcValue) - cerr << SrcValue; + OS << SrcValue; else - cerr << "null"; - cerr << ":" << SrcOffset << ">"; + OS << "null"; + OS << ":" << SrcOffset << ">"; if (AT->isVolatile()) - cerr << " "; - cerr << " alignment=" << AT->getAlignment(); + OS << " "; + OS << " alignment=" << AT->getAlignment(); } } diff --git a/lib/Support/APInt.cpp b/lib/Support/APInt.cpp index f415313060..8f506bc720 100644 --- a/lib/Support/APInt.cpp +++ b/lib/Support/APInt.cpp @@ -18,6 +18,7 @@ #include "llvm/ADT/SmallString.h" #include "llvm/Support/Debug.h" #include "llvm/Support/MathExtras.h" +#include "llvm/Support/raw_ostream.h" #include #include #include @@ -41,8 +42,7 @@ inline static uint64_t* getMemory(uint32_t numWords) { return result; } -void APInt::initSlowCase(uint32_t numBits, uint64_t val, bool isSigned) -{ +void APInt::initSlowCase(uint32_t numBits, uint64_t val, bool isSigned) { pVal = getClearedMemory(getNumWords()); pVal[0] = val; if (isSigned && int64_t(val) < 0) @@ -51,7 +51,7 @@ void APInt::initSlowCase(uint32_t numBits, uint64_t val, bool isSigned) } APInt::APInt(uint32_t numBits, uint32_t numWords, const uint64_t bigVal[]) - : BitWidth(numBits), VAL(0) { + : BitWidth(numBits), VAL(0) { assert(BitWidth && "bitwidth too small"); assert(bigVal && "Null pointer detected!"); if (isSingleWord()) @@ -1995,13 +1995,12 @@ void APInt::dump() const { fprintf(stderr, "APInt(%db, %su %ss)", BitWidth, U.c_str(), S.c_str()); } -void APInt::print(std::ostream &OS, bool isSigned) const { +void APInt::print(raw_ostream &OS, bool isSigned) const { SmallString<40> S; this->toString(S, 10, isSigned); OS << S.c_str(); } - // This implements a variety of operations on a representation of // arbitrary precision, two's-complement, bignum integer values. diff --git a/lib/Support/ConstantRange.cpp b/lib/Support/ConstantRange.cpp index 9c83b7c59d..cb8c4b013c 100644 --- a/lib/Support/ConstantRange.cpp +++ b/lib/Support/ConstantRange.cpp @@ -22,8 +22,7 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/ConstantRange.h" -#include "llvm/Support/Streams.h" -#include +#include "llvm/Support/raw_ostream.h" using namespace llvm; /// Initialize a full (the default) or empty set for the specified type. @@ -462,12 +461,12 @@ ConstantRange ConstantRange::truncate(uint32_t DstTySize) const { /// print - Print out the bounds to a stream... /// -void ConstantRange::print(std::ostream &OS) const { +void ConstantRange::print(raw_ostream &OS) const { OS << "[" << Lower << "," << Upper << ")"; } /// dump - Allow printing from a debugger easily... /// void ConstantRange::dump() const { - print(cerr); + print(errs()); } diff --git a/lib/Support/raw_ostream.cpp b/lib/Support/raw_ostream.cpp index 432e603194..9827ca776a 100644 --- a/lib/Support/raw_ostream.cpp +++ b/lib/Support/raw_ostream.cpp @@ -99,6 +99,12 @@ raw_ostream &raw_ostream::operator<<(long long N) { return this->operator<<(static_cast(N)); } +raw_ostream &raw_ostream::operator<<(const void *P) { + // FIXME: This could be much faster if it matters. + return *this << format("%p", P); +} + + raw_ostream &raw_ostream::write(const char *Ptr, unsigned Size) { if (OutBufCur+Size > OutBufEnd) flush_impl(); @@ -250,6 +256,10 @@ raw_ostream &llvm::errs() { // raw_os_ostream //===----------------------------------------------------------------------===// +raw_os_ostream::~raw_os_ostream() { + flush(); +} + /// flush_impl - The is the piece of the class that is implemented by /// subclasses. This outputs the currently buffered data and resets the /// buffer to empty. diff --git a/lib/Target/ARM/ARMConstantPoolValue.cpp b/lib/Target/ARM/ARMConstantPoolValue.cpp index 6add3c38d3..04db1644f8 100644 --- a/lib/Target/ARM/ARMConstantPoolValue.cpp +++ b/lib/Target/ARM/ARMConstantPoolValue.cpp @@ -15,6 +15,7 @@ #include "llvm/ADT/FoldingSet.h" #include "llvm/GlobalValue.h" #include "llvm/Type.h" +#include "llvm/Support/raw_ostream.h" using namespace llvm; ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv, unsigned id, @@ -72,7 +73,7 @@ ARMConstantPoolValue::AddSelectionDAGCSEId(FoldingSetNodeID &ID) { ID.AddInteger(PCAdjust); } -void ARMConstantPoolValue::print(std::ostream &O) const { +void ARMConstantPoolValue::print(raw_ostream &O) const { if (GV) O << GV->getName(); else diff --git a/lib/Target/ARM/ARMConstantPoolValue.h b/lib/Target/ARM/ARMConstantPoolValue.h index 636166349a..caf8d54f16 100644 --- a/lib/Target/ARM/ARMConstantPoolValue.h +++ b/lib/Target/ARM/ARMConstantPoolValue.h @@ -69,7 +69,7 @@ public: virtual void AddSelectionDAGCSEId(FoldingSetNodeID &ID); - virtual void print(std::ostream &O) const; + virtual void print(raw_ostream &O) const; }; } diff --git a/lib/Target/PIC16/PIC16ConstantPoolValue.cpp b/lib/Target/PIC16/PIC16ConstantPoolValue.cpp index 6e324f9e4d..152c7377ab 100644 --- a/lib/Target/PIC16/PIC16ConstantPoolValue.cpp +++ b/lib/Target/PIC16/PIC16ConstantPoolValue.cpp @@ -15,6 +15,7 @@ #include "llvm/ADT/FoldingSet.h" #include "llvm/GlobalValue.h" #include "llvm/Type.h" +#include "llvm/Support/raw_ostream.h" using namespace llvm; PIC16ConstantPoolValue::PIC16ConstantPoolValue(GlobalValue *gv, unsigned id, @@ -70,7 +71,7 @@ PIC16ConstantPoolValue::AddSelectionDAGCSEId(FoldingSetNodeID &ID) { ID.AddInteger(PCAdjust); } -void PIC16ConstantPoolValue::print(std::ostream &O) const { +void PIC16ConstantPoolValue::print(raw_ostream &O) const { if (GV) O << GV->getName(); else diff --git a/lib/Target/PIC16/PIC16ConstantPoolValue.h b/lib/Target/PIC16/PIC16ConstantPoolValue.h index c8faf59337..657fb15171 100644 --- a/lib/Target/PIC16/PIC16ConstantPoolValue.h +++ b/lib/Target/PIC16/PIC16ConstantPoolValue.h @@ -69,7 +69,7 @@ public: virtual void AddSelectionDAGCSEId(FoldingSetNodeID &ID); - virtual void print(std::ostream &O) const; + virtual void print(raw_ostream &O) const; }; } diff --git a/lib/Transforms/Scalar/PredicateSimplifier.cpp b/lib/Transforms/Scalar/PredicateSimplifier.cpp index 2672e4e762..9a94fad932 100644 --- a/lib/Transforms/Scalar/PredicateSimplifier.cpp +++ b/lib/Transforms/Scalar/PredicateSimplifier.cpp @@ -922,7 +922,7 @@ namespace { void dump(std::ostream &os) const { os << "{"; for (const_iterator I = begin(), E = end(); I != E; ++I) { - os << I->second << " (" << I->first->getDFSNumIn() << "), "; + os << &I->second << " (" << I->first->getDFSNumIn() << "), "; } os << "}"; } diff --git a/lib/Transforms/Utils/LowerSwitch.cpp b/lib/Transforms/Utils/LowerSwitch.cpp index 7409e779f8..99e938416e 100644 --- a/lib/Transforms/Utils/LowerSwitch.cpp +++ b/lib/Transforms/Utils/LowerSwitch.cpp @@ -22,6 +22,7 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/Support/Debug.h" #include "llvm/Support/Compiler.h" +#include "llvm/Support/raw_ostream.h" #include using namespace llvm; @@ -144,9 +145,10 @@ BasicBlock* LowerSwitch::switchConvert(CaseItr Begin, CaseItr End, DOUT << "RHS: " << RHS << "\n"; CaseRange& Pivot = *(Begin + Mid); - DEBUG(cerr << "Pivot ==> " - << cast(Pivot.Low)->getValue() << " -" - << cast(Pivot.High)->getValue() << "\n"); + DEBUG(errs() << "Pivot ==> " + << cast(Pivot.Low)->getValue() << " -" + << cast(Pivot.High)->getValue() << "\n"; + errs().flush()); BasicBlock* LBranch = switchConvert(LHS.begin(), LHS.end(), Val, OrigBlock, Default); diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp index 146cabaeb4..ee73d7225c 100644 --- a/lib/VMCore/AsmWriter.cpp +++ b/lib/VMCore/AsmWriter.cpp @@ -31,7 +31,6 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/Support/CFG.h" #include "llvm/Support/MathExtras.h" -#include "llvm/Support/Streams.h" #include "llvm/Support/raw_ostream.h" #include #include @@ -126,7 +125,7 @@ enum PrefixType { /// PrintLLVMName - Turn the specified name into an 'LLVM name', which is either /// prefixed with % (if the string only contains simple characters) or is /// surrounded with ""'s (if it has special chars in it). Print it out. -static void PrintLLVMName(std::ostream &OS, const char *NameStr, +static void PrintLLVMName(raw_ostream &OS, const char *NameStr, unsigned NameLen, PrefixType Prefix) { assert(NameStr && "Cannot get empty name!"); switch (Prefix) { @@ -184,7 +183,7 @@ static void PrintLLVMName(std::ostream &OS, const char *NameStr, /// PrintLLVMName - Turn the specified name into an 'LLVM name', which is either /// prefixed with % (if the string only contains simple characters) or is /// surrounded with ""'s (if it has special chars in it). Print it out. -static void PrintLLVMName(std::ostream &OS, const Value *V) { +static void PrintLLVMName(raw_ostream &OS, const Value *V) { PrintLLVMName(OS, V->getNameStart(), V->getNameLen(), isa(V) ? GlobalPrefix : LocalPrefix); } @@ -439,7 +438,7 @@ void SlotTracker::CreateFunctionSlot(const Value *V) { // AsmWriter Implementation //===----------------------------------------------------------------------===// -static void WriteAsOperandInternal(std::ostream &Out, const Value *V, +static void WriteAsOperandInternal(raw_ostream &Out, const Value *V, std::map &TypeTable, SlotTracker *Machine); @@ -579,7 +578,7 @@ static void calcTypeName(const Type *Ty, /// printTypeInt - The internal guts of printing out a type that has a /// potentially named portion. /// -static void printTypeInt(std::ostream &Out, const Type *Ty, +static void printTypeInt(raw_ostream &Out, const Type *Ty, std::map &TypeNames) { // Primitive types always print out their description, regardless of whether // they have been named or not. @@ -614,6 +613,11 @@ static void printTypeInt(std::ostream &Out, const Type *Ty, /// void llvm::WriteTypeSymbolic(std::ostream &Out, const Type *Ty, const Module *M) { + raw_os_ostream RO(Out); + WriteTypeSymbolic(RO, Ty, M); +} + +void llvm::WriteTypeSymbolic(raw_ostream &Out, const Type *Ty, const Module *M){ Out << ' '; // If they want us to print out a type, but there is no context, we can't @@ -629,7 +633,7 @@ void llvm::WriteTypeSymbolic(std::ostream &Out, const Type *Ty, // PrintEscapedString - Print each character of the specified string, escaping // it if it is not printable or if it is an escape char. -static void PrintEscapedString(const std::string &Str, std::ostream &Out) { +static void PrintEscapedString(const std::string &Str, raw_ostream &Out) { for (unsigned i = 0, e = Str.size(); i != e; ++i) { unsigned char C = Str[i]; if (isprint(C) && C != '"' && C != '\\') { @@ -675,7 +679,7 @@ static const char *getPredicateText(unsigned predicate) { return pred; } -static void WriteConstantInt(std::ostream &Out, const Constant *CV, +static void WriteConstantInt(raw_ostream &Out, const Constant *CV, std::map &TypeTable, SlotTracker *Machine) { if (const ConstantInt *CI = dyn_cast(CV)) { @@ -873,7 +877,7 @@ static void WriteConstantInt(std::ostream &Out, const Constant *CV, /// ostream. This can be useful when you just want to print int %reg126, not /// the whole instruction that generated it. /// -static void WriteAsOperandInternal(std::ostream &Out, const Value *V, +static void WriteAsOperandInternal(raw_ostream &Out, const Value *V, std::map &TypeTable, SlotTracker *Machine) { Out << ' '; @@ -936,6 +940,12 @@ static void WriteAsOperandInternal(std::ostream &Out, const Value *V, /// 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) { std::map TypeNames; if (Context == 0) Context = getModuleFromVal(V); @@ -952,13 +962,13 @@ void llvm::WriteAsOperand(std::ostream &Out, const Value *V, bool PrintType, namespace { class AssemblyWriter { - std::ostream &Out; + raw_ostream &Out; SlotTracker &Machine; const Module *TheModule; std::map TypeNames; AssemblyAnnotationWriter *AnnotationWriter; public: - inline AssemblyWriter(std::ostream &o, SlotTracker &Mac, const Module *M, + inline AssemblyWriter(raw_ostream &o, SlotTracker &Mac, const Module *M, AssemblyAnnotationWriter *AAW) : Out(o), Machine(Mac), TheModule(M), AnnotationWriter(AAW) { @@ -968,10 +978,19 @@ public: fillTypeNameTable(M, TypeNames); } - void write(const Module *M) { printModule(M); } - void write(const GlobalVariable *G) { printGlobal(G); } - void write(const GlobalAlias *G) { printAlias(G); } - void write(const Function *F) { printFunction(F); } + void write(const Module *M) { printModule(M); } + + void write(const GlobalValue *G) { + if (const GlobalVariable *GV = dyn_cast(G)) + printGlobal(GV); + else if (const GlobalAlias *GA = dyn_cast(G)) + printAlias(GA); + else if (const Function *F = dyn_cast(G)) + printFunction(F); + else + assert(0 && "Unknown global"); + } + void write(const BasicBlock *BB) { printBasicBlock(BB); } void write(const Instruction *I) { printInstruction(*I); } void write(const Type *Ty) { printType(Ty); } @@ -1176,7 +1195,7 @@ void AssemblyWriter::printModule(const Module *M) { printFunction(I); } -static void PrintLinkage(GlobalValue::LinkageTypes LT, std::ostream &Out) { +static void PrintLinkage(GlobalValue::LinkageTypes LT, raw_ostream &Out) { switch (LT) { case GlobalValue::InternalLinkage: Out << "internal "; break; case GlobalValue::LinkOnceLinkage: Out << "linkonce "; break; @@ -1195,7 +1214,7 @@ static void PrintLinkage(GlobalValue::LinkageTypes LT, std::ostream &Out) { static void PrintVisibility(GlobalValue::VisibilityTypes Vis, - std::ostream &Out) { + raw_ostream &Out) { switch (Vis) { default: assert(0 && "Invalid visibility style!"); case GlobalValue::DefaultVisibility: break; @@ -1705,74 +1724,75 @@ void AssemblyWriter::printInstruction(const Instruction &I) { //===----------------------------------------------------------------------===// void Module::print(std::ostream &o, AssemblyAnnotationWriter *AAW) const { - SlotTracker SlotTable(this); - AssemblyWriter W(o, SlotTable, this, AAW); - W.write(this); -} - -void GlobalVariable::print(std::ostream &o) const { - SlotTracker SlotTable(getParent()); - AssemblyWriter W(o, SlotTable, getParent(), 0); - W.write(this); -} - -void GlobalAlias::print(std::ostream &o) const { - SlotTracker SlotTable(getParent()); - AssemblyWriter W(o, SlotTable, getParent(), 0); - W.write(this); -} - -void Function::print(std::ostream &o, AssemblyAnnotationWriter *AAW) const { - SlotTracker SlotTable(getParent()); - AssemblyWriter W(o, SlotTable, getParent(), AAW); - - W.write(this); + raw_os_ostream OS(o); + print(OS, AAW); } - -void InlineAsm::print(std::ostream &o, AssemblyAnnotationWriter *AAW) const { - WriteAsOperand(o, this, true, 0); -} - -void BasicBlock::print(std::ostream &o, AssemblyAnnotationWriter *AAW) const { - SlotTracker SlotTable(getParent()); - AssemblyWriter W(o, SlotTable, - getParent() ? getParent()->getParent() : 0, AAW); - W.write(this); -} - -void Instruction::print(std::ostream &o, AssemblyAnnotationWriter *AAW) const { - const Function *F = getParent() ? getParent()->getParent() : 0; - SlotTracker SlotTable(F); - AssemblyWriter W(o, SlotTable, F ? F->getParent() : 0, AAW); - +void Module::print(raw_ostream &OS, AssemblyAnnotationWriter *AAW) const { + SlotTracker SlotTable(this); + AssemblyWriter W(OS, SlotTable, this, AAW); W.write(this); } -void Constant::print(std::ostream &o) const { - if (this == 0) { o << " constant value\n"; return; } - - o << ' ' << getType()->getDescription() << ' '; - - std::map TypeTable; - WriteConstantInt(o, this, TypeTable, 0); +void Type::print(std::ostream &o) const { + raw_os_ostream OS(o); + print(OS); } -void Type::print(std::ostream &o) const { +void Type::print(raw_ostream &o) const { if (this == 0) o << ""; else o << getDescription(); } -void Argument::print(std::ostream &o) const { - WriteAsOperand(o, this, true, getParent() ? getParent()->getParent() : 0); +void Value::print(raw_ostream &OS, AssemblyAnnotationWriter *AAW) const { + if (this == 0) { + OS << "printing a value\n"; + return; + } + + if (const Instruction *I = dyn_cast(this)) { + const Function *F = I->getParent() ? I->getParent()->getParent() : 0; + SlotTracker SlotTable(F); + AssemblyWriter W(OS, SlotTable, F ? F->getParent() : 0, AAW); + W.write(I); + } else if (const BasicBlock *BB = dyn_cast(this)) { + SlotTracker SlotTable(BB->getParent()); + AssemblyWriter W(OS, SlotTable, + BB->getParent() ? BB->getParent()->getParent() : 0, AAW); + W.write(BB); + } else if (const GlobalValue *GV = dyn_cast(this)) { + SlotTracker SlotTable(GV->getParent()); + AssemblyWriter W(OS, SlotTable, GV->getParent(), 0); + W.write(GV); + } else if (const Constant *C = dyn_cast(this)) { + OS << ' ' << C->getType()->getDescription() << ' '; + std::map TypeTable; + WriteConstantInt(OS, C, TypeTable, 0); + } else if (const Argument *A = dyn_cast(this)) { + WriteAsOperand(OS, this, true, + A->getParent() ? A->getParent()->getParent() : 0); + } else if (isa(this)) { + WriteAsOperand(OS, this, true, 0); + } else { + assert(0 && "Unknown value to print out!"); + } +} + +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. // Located here because so much of the needed functionality is here. -void Value::dump() const { print(*cerr.stream()); cerr << '\n'; } +void Value::dump() const { print(errs()); errs() << '\n'; } // Type::dump - allow easy printing of Values from the debugger. // Located here because so much of the needed functionality is here. -void Type::dump() const { print(*cerr.stream()); cerr << '\n'; } +void Type::dump() const { print(errs()); errs() << '\n'; } + +// Module::dump() - Allow printing from debugger +void Module::dump() const { print(errs(), 0); } + diff --git a/lib/VMCore/Module.cpp b/lib/VMCore/Module.cpp index 94f5d81e0f..b95f6e3fa8 100644 --- a/lib/VMCore/Module.cpp +++ b/lib/VMCore/Module.cpp @@ -88,11 +88,6 @@ Module::~Module() { delete TypeSymTab; } -// Module::dump() - Allow printing from debugger -void Module::dump() const { - print(*cerr.stream()); -} - /// Target endian information... Module::Endianness Module::getEndianness() const { std::string temp = DataLayout; -- cgit v1.2.3