From cf143a4d917699f8f4202f331fa9e184070471fb Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 23 Aug 2009 03:13:20 +0000 Subject: [PATCH] remove std::ostream versions of printing stuff for MBB and MF, upgrading a few things to use raw_ostream git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79811 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/MachineBasicBlock.h | 2 -- include/llvm/CodeGen/MachineFunction.h | 1 - include/llvm/CodeGen/Passes.h | 6 ++--- lib/CodeGen/GCMetadata.cpp | 12 ++++----- lib/CodeGen/LLVMTargetMachine.cpp | 12 ++++----- lib/CodeGen/MachineBasicBlock.cpp | 11 +------- lib/CodeGen/MachineFunction.cpp | 32 ++++++++++-------------- lib/CodeGen/MachineSink.cpp | 6 ++--- lib/CodeGen/MachineVerifier.cpp | 6 ++--- 9 files changed, 35 insertions(+), 53 deletions(-) diff --git a/include/llvm/CodeGen/MachineBasicBlock.h b/include/llvm/CodeGen/MachineBasicBlock.h index 7d6ecf9f1b5..9b989b2304f 100644 --- a/include/llvm/CodeGen/MachineBasicBlock.h +++ b/include/llvm/CodeGen/MachineBasicBlock.h @@ -310,7 +310,6 @@ public: // Debugging methods. void dump() const; - void print(std::ostream &OS) const; void print(raw_ostream &OS) const; /// getNumber - MachineBasicBlocks are uniquely numbered at the function @@ -339,7 +338,6 @@ private: // Methods used to maintain doubly linked list of blocks... void removePredecessor(MachineBasicBlock *pred); }; -std::ostream& operator<<(std::ostream &OS, const MachineBasicBlock &MBB); raw_ostream& operator<<(raw_ostream &OS, const MachineBasicBlock &MBB); //===--------------------------------------------------------------------===// diff --git a/include/llvm/CodeGen/MachineFunction.h b/include/llvm/CodeGen/MachineFunction.h index da25d61d5e0..51200cb2bbe 100644 --- a/include/llvm/CodeGen/MachineFunction.h +++ b/include/llvm/CodeGen/MachineFunction.h @@ -207,7 +207,6 @@ public: /// print - Print out the MachineFunction in a format suitable for debugging /// to the specified stream. /// - void print(std::ostream &OS) const; void print(raw_ostream &OS) const; /// viewCFG - This function is meant for use from the debugger. You can just diff --git a/include/llvm/CodeGen/Passes.h b/include/llvm/CodeGen/Passes.h index d8ec67f9163..b0db4c99933 100644 --- a/include/llvm/CodeGen/Passes.h +++ b/include/llvm/CodeGen/Passes.h @@ -15,7 +15,6 @@ #ifndef LLVM_CODEGEN_PASSES_H #define LLVM_CODEGEN_PASSES_H -#include #include namespace llvm { @@ -25,6 +24,7 @@ namespace llvm { class TargetMachine; class TargetLowering; class RegisterCoalescer; + class raw_ostream; /// createUnreachableBlockEliminationPass - The LLVM code generator does not /// work well with unreachable basic blocks (what live ranges make sense for a @@ -36,7 +36,7 @@ namespace llvm { /// MachineFunctionPrinter pass - This pass prints out the machine function to /// the given stream, as a debugging tool. - FunctionPass *createMachineFunctionPrinterPass(std::ostream *OS, + FunctionPass *createMachineFunctionPrinterPass(raw_ostream &OS, const std::string &Banner =""); /// MachineLoopInfo pass - This pass is a loop analysis pass. @@ -166,7 +166,7 @@ namespace llvm { /// Creates a pass to print GC metadata. /// - FunctionPass *createGCInfoPrinter(std::ostream &OS); + FunctionPass *createGCInfoPrinter(raw_ostream &OS); /// createMachineLICMPass - This pass performs LICM on machine instructions. /// diff --git a/lib/CodeGen/GCMetadata.cpp b/lib/CodeGen/GCMetadata.cpp index cc8f82fbe53..a2a7fa192c8 100644 --- a/lib/CodeGen/GCMetadata.cpp +++ b/lib/CodeGen/GCMetadata.cpp @@ -19,17 +19,19 @@ #include "llvm/Function.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/ErrorHandling.h" - +#include "llvm/Support/raw_ostream.h" using namespace llvm; namespace { class VISIBILITY_HIDDEN Printer : public FunctionPass { static char ID; - std::ostream &OS; + raw_ostream &OS; public: - explicit Printer(std::ostream &OS = *cerr); + Printer() : FunctionPass(&ID), OS(errs()) {} + explicit Printer(raw_ostream &OS) : FunctionPass(&ID), OS(OS) {} + const char *getPassName() const; void getAnalysisUsage(AnalysisUsage &AU) const; @@ -122,12 +124,10 @@ void GCModuleInfo::clear() { char Printer::ID = 0; -FunctionPass *llvm::createGCInfoPrinter(std::ostream &OS) { +FunctionPass *llvm::createGCInfoPrinter(raw_ostream &OS) { return new Printer(OS); } -Printer::Printer(std::ostream &OS) - : FunctionPass(&ID), OS(OS) {} const char *Printer::getPassName() const { return "Print Garbage Collector Information"; diff --git a/lib/CodeGen/LLVMTargetMachine.cpp b/lib/CodeGen/LLVMTargetMachine.cpp index adce1f30b36..01cf3af50a0 100644 --- a/lib/CodeGen/LLVMTargetMachine.cpp +++ b/lib/CodeGen/LLVMTargetMachine.cpp @@ -78,10 +78,10 @@ LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM, PM.add(createDebugLabelFoldingPass()); if (PrintMachineCode) - PM.add(createMachineFunctionPrinterPass(cerr)); + PM.add(createMachineFunctionPrinterPass(errs())); if (addPreEmitPass(PM, OptLevel) && PrintMachineCode) - PM.add(createMachineFunctionPrinterPass(cerr)); + PM.add(createMachineFunctionPrinterPass(errs())); if (OptLevel != CodeGenOpt::None) PM.add(createCodePlacementOptPass()); @@ -178,7 +178,7 @@ bool LLVMTargetMachine::addPassesToEmitMachineCode(PassManagerBase &PM, return true; if (addPreEmitPass(PM, OptLevel) && PrintMachineCode) - PM.add(createMachineFunctionPrinterPass(cerr)); + PM.add(createMachineFunctionPrinterPass(errs())); addCodeEmitter(PM, OptLevel, MCE); if (PrintEmittedAsm) @@ -203,7 +203,7 @@ bool LLVMTargetMachine::addPassesToEmitMachineCode(PassManagerBase &PM, return true; if (addPreEmitPass(PM, OptLevel) && PrintMachineCode) - PM.add(createMachineFunctionPrinterPass(cerr)); + PM.add(createMachineFunctionPrinterPass(errs())); addCodeEmitter(PM, OptLevel, JCE); if (PrintEmittedAsm) @@ -217,7 +217,7 @@ bool LLVMTargetMachine::addPassesToEmitMachineCode(PassManagerBase &PM, static void printAndVerify(PassManagerBase &PM, bool allowDoubleDefs = false) { if (PrintMachineCode) - PM.add(createMachineFunctionPrinterPass(cerr)); + PM.add(createMachineFunctionPrinterPass(errs())); if (VerifyMachineCode) PM.add(createMachineVerifierPass(allowDoubleDefs)); @@ -334,7 +334,7 @@ bool LLVMTargetMachine::addCommonCodeGenPasses(PassManagerBase &PM, printAndVerify(PM); if (PrintGCInfo) - PM.add(createGCInfoPrinter(*cerr)); + PM.add(createGCInfoPrinter(errs())); return false; } diff --git a/lib/CodeGen/MachineBasicBlock.cpp b/lib/CodeGen/MachineBasicBlock.cpp index 7ec9aab8c2c..b3eb2da7628 100644 --- a/lib/CodeGen/MachineBasicBlock.cpp +++ b/lib/CodeGen/MachineBasicBlock.cpp @@ -32,10 +32,6 @@ MachineBasicBlock::~MachineBasicBlock() { LeakDetector::removeGarbageObject(this); } -std::ostream &llvm::operator<<(std::ostream &OS, const MachineBasicBlock &MBB) { - MBB.print(OS); - return OS; -} raw_ostream &llvm::operator<<(raw_ostream &OS, const MachineBasicBlock &MBB) { MBB.print(OS); return OS; @@ -159,7 +155,7 @@ bool MachineBasicBlock::isOnlyReachableByFallthrough() const { } void MachineBasicBlock::dump() const { - print(*cerr.stream()); + print(errs()); } static inline void OutputReg(raw_ostream &os, unsigned RegNo, @@ -173,11 +169,6 @@ static inline void OutputReg(raw_ostream &os, unsigned RegNo, os << " %reg" << RegNo; } -void MachineBasicBlock::print(std::ostream &OS) const { - raw_os_ostream RawOS(OS); - print(RawOS); -} - void MachineBasicBlock::print(raw_ostream &OS) const { const MachineFunction *MF = getParent(); if (!MF) { diff --git a/lib/CodeGen/MachineFunction.cpp b/lib/CodeGen/MachineFunction.cpp index e904b28a634..5bf86e3630f 100644 --- a/lib/CodeGen/MachineFunction.cpp +++ b/lib/CodeGen/MachineFunction.cpp @@ -33,18 +33,16 @@ #include "llvm/Support/Compiler.h" #include "llvm/Support/GraphWriter.h" #include "llvm/Support/raw_ostream.h" -#include -#include using namespace llvm; namespace { struct VISIBILITY_HIDDEN Printer : public MachineFunctionPass { static char ID; - std::ostream *OS; + raw_ostream &OS; const std::string Banner; - Printer(std::ostream *os, const std::string &banner) + Printer(raw_ostream &os, const std::string &banner) : MachineFunctionPass(&ID), OS(os), Banner(banner) {} const char *getPassName() const { return "MachineFunction Printer"; } @@ -55,8 +53,8 @@ namespace { } bool runOnMachineFunction(MachineFunction &MF) { - (*OS) << Banner; - MF.print (*OS); + OS << Banner; + MF.print(OS); return false; } }; @@ -66,7 +64,7 @@ namespace { /// Returns a newly-created MachineFunction Printer pass. The default banner is /// empty. /// -FunctionPass *llvm::createMachineFunctionPrinterPass(std::ostream *OS, +FunctionPass *llvm::createMachineFunctionPrinterPass(raw_ostream &OS, const std::string &Banner){ return new Printer(OS, Banner); } @@ -220,11 +218,6 @@ void MachineFunction::dump() const { print(errs()); } -void MachineFunction::print(std::ostream &OS) const { - raw_os_ostream RawOS(OS); - print(RawOS); -} - void MachineFunction::print(raw_ostream &OS) const { OS << "# Machine code for " << Fn->getName() << "():\n"; @@ -284,15 +277,16 @@ namespace llvm { !Node->getBasicBlock()->getName().empty()) return Node->getBasicBlock()->getNameStr() + ":"; - std::ostringstream Out; - if (ShortNames) { - Out << Node->getNumber() << ':'; - return Out.str(); + std::string OutStr; + { + raw_string_ostream OSS(OutStr); + + if (ShortNames) + OSS << Node->getNumber() << ':'; + else + Node->print(OSS); } - Node->print(Out); - - std::string OutStr = Out.str(); if (OutStr[0] == '\n') OutStr.erase(OutStr.begin()); // Process string output to make it nicer... diff --git a/lib/CodeGen/MachineSink.cpp b/lib/CodeGen/MachineSink.cpp index fbb8867be47..7fb33c6e4ce 100644 --- a/lib/CodeGen/MachineSink.cpp +++ b/lib/CodeGen/MachineSink.cpp @@ -239,15 +239,15 @@ bool MachineSinking::SinkInstruction(MachineInstr *MI, bool &SawStore) { if (MI->getParent() == SuccToSinkTo) return false; - DEBUG(cerr << "Sink instr " << *MI); - DEBUG(cerr << "to block " << *SuccToSinkTo); + DEBUG(errs() << "Sink instr " << *MI); + DEBUG(errs() << "to block " << *SuccToSinkTo); // If the block has multiple predecessors, this would introduce computation on // a path that it doesn't already exist. We could split the critical edge, // but for now we just punt. // FIXME: Split critical edges if not backedges. if (SuccToSinkTo->pred_size() > 1) { - DEBUG(cerr << " *** PUNTING: Critical edge found\n"); + DEBUG(errs() << " *** PUNTING: Critical edge found\n"); return false; } diff --git a/lib/CodeGen/MachineVerifier.cpp b/lib/CodeGen/MachineVerifier.cpp index ea2f8279d74..0eb05353e7a 100644 --- a/lib/CodeGen/MachineVerifier.cpp +++ b/lib/CodeGen/MachineVerifier.cpp @@ -23,9 +23,6 @@ // the verifier errors. //===----------------------------------------------------------------------===// -#include "llvm/ADT/DenseSet.h" -#include "llvm/ADT/SetOperations.h" -#include "llvm/ADT/SmallVector.h" #include "llvm/Function.h" #include "llvm/CodeGen/LiveVariables.h" #include "llvm/CodeGen/MachineFunctionPass.h" @@ -35,6 +32,9 @@ #include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetRegisterInfo.h" #include "llvm/Target/TargetInstrInfo.h" +#include "llvm/ADT/DenseSet.h" +#include "llvm/ADT/SetOperations.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/Debug.h" #include "llvm/Support/ErrorHandling.h" -- 2.34.1