llvm.org GIT mirror llvm / cf143a4
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 Chris Lattner 10 years ago
9 changed file(s) with 35 addition(s) and 53 deletion(s). Raw diff Collapse all Expand all
309309
310310 // Debugging methods.
311311 void dump() const;
312 void print(std::ostream &OS) const;
313312 void print(raw_ostream &OS) const;
314313
315314 /// getNumber - MachineBasicBlocks are uniquely numbered at the function
338337 void removePredecessor(MachineBasicBlock *pred);
339338 };
340339
341 std::ostream& operator<<(std::ostream &OS, const MachineBasicBlock &MBB);
342340 raw_ostream& operator<<(raw_ostream &OS, const MachineBasicBlock &MBB);
343341
344342 //===--------------------------------------------------------------------===//
206206 /// print - Print out the MachineFunction in a format suitable for debugging
207207 /// to the specified stream.
208208 ///
209 void print(std::ostream &OS) const;
210209 void print(raw_ostream &OS) const;
211210
212211 /// viewCFG - This function is meant for use from the debugger. You can just
1414 #ifndef LLVM_CODEGEN_PASSES_H
1515 #define LLVM_CODEGEN_PASSES_H
1616
17 #include
1817 #include
1918
2019 namespace llvm {
2423 class TargetMachine;
2524 class TargetLowering;
2625 class RegisterCoalescer;
26 class raw_ostream;
2727
2828 /// createUnreachableBlockEliminationPass - The LLVM code generator does not
2929 /// work well with unreachable basic blocks (what live ranges make sense for a
3535
3636 /// MachineFunctionPrinter pass - This pass prints out the machine function to
3737 /// the given stream, as a debugging tool.
38 FunctionPass *createMachineFunctionPrinterPass(std::ostream *OS,
38 FunctionPass *createMachineFunctionPrinterPass(raw_ostream &OS,
3939 const std::string &Banner ="");
4040
4141 /// MachineLoopInfo pass - This pass is a loop analysis pass.
165165
166166 /// Creates a pass to print GC metadata.
167167 ///
168 FunctionPass *createGCInfoPrinter(std::ostream &OS);
168 FunctionPass *createGCInfoPrinter(raw_ostream &OS);
169169
170170 /// createMachineLICMPass - This pass performs LICM on machine instructions.
171171 ///
1818 #include "llvm/Function.h"
1919 #include "llvm/Support/Compiler.h"
2020 #include "llvm/Support/ErrorHandling.h"
21
21 #include "llvm/Support/raw_ostream.h"
2222 using namespace llvm;
2323
2424 namespace {
2525
2626 class VISIBILITY_HIDDEN Printer : public FunctionPass {
2727 static char ID;
28 std::ostream &OS;
28 raw_ostream &OS;
2929
3030 public:
31 explicit Printer(std::ostream &OS = *cerr);
31 Printer() : FunctionPass(&ID), OS(errs()) {}
32 explicit Printer(raw_ostream &OS) : FunctionPass(&ID), OS(OS) {}
33
3234
3335 const char *getPassName() const;
3436 void getAnalysisUsage(AnalysisUsage &AU) const;
121123
122124 char Printer::ID = 0;
123125
124 FunctionPass *llvm::createGCInfoPrinter(std::ostream &OS) {
126 FunctionPass *llvm::createGCInfoPrinter(raw_ostream &OS) {
125127 return new Printer(OS);
126128 }
127129
128 Printer::Printer(std::ostream &OS)
129 : FunctionPass(&ID), OS(OS) {}
130130
131131 const char *Printer::getPassName() const {
132132 return "Print Garbage Collector Information";
7777 PM.add(createDebugLabelFoldingPass());
7878
7979 if (PrintMachineCode)
80 PM.add(createMachineFunctionPrinterPass(cerr));
80 PM.add(createMachineFunctionPrinterPass(errs()));
8181
8282 if (addPreEmitPass(PM, OptLevel) && PrintMachineCode)
83 PM.add(createMachineFunctionPrinterPass(cerr));
83 PM.add(createMachineFunctionPrinterPass(errs()));
8484
8585 if (OptLevel != CodeGenOpt::None)
8686 PM.add(createCodePlacementOptPass());
177177 return true;
178178
179179 if (addPreEmitPass(PM, OptLevel) && PrintMachineCode)
180 PM.add(createMachineFunctionPrinterPass(cerr));
180 PM.add(createMachineFunctionPrinterPass(errs()));
181181
182182 addCodeEmitter(PM, OptLevel, MCE);
183183 if (PrintEmittedAsm)
202202 return true;
203203
204204 if (addPreEmitPass(PM, OptLevel) && PrintMachineCode)
205 PM.add(createMachineFunctionPrinterPass(cerr));
205 PM.add(createMachineFunctionPrinterPass(errs()));
206206
207207 addCodeEmitter(PM, OptLevel, JCE);
208208 if (PrintEmittedAsm)
216216 static void printAndVerify(PassManagerBase &PM,
217217 bool allowDoubleDefs = false) {
218218 if (PrintMachineCode)
219 PM.add(createMachineFunctionPrinterPass(cerr));
219 PM.add(createMachineFunctionPrinterPass(errs()));
220220
221221 if (VerifyMachineCode)
222222 PM.add(createMachineVerifierPass(allowDoubleDefs));
333333 printAndVerify(PM);
334334
335335 if (PrintGCInfo)
336 PM.add(createGCInfoPrinter(*cerr));
336 PM.add(createGCInfoPrinter(errs()));
337337
338338 return false;
339339 }
3131 LeakDetector::removeGarbageObject(this);
3232 }
3333
34 std::ostream &llvm::operator<<(std::ostream &OS, const MachineBasicBlock &MBB) {
35 MBB.print(OS);
36 return OS;
37 }
3834 raw_ostream &llvm::operator<<(raw_ostream &OS, const MachineBasicBlock &MBB) {
3935 MBB.print(OS);
4036 return OS;
158154 }
159155
160156 void MachineBasicBlock::dump() const {
161 print(*cerr.stream());
157 print(errs());
162158 }
163159
164160 static inline void OutputReg(raw_ostream &os, unsigned RegNo,
170166 os << " %mreg(" << RegNo << ")";
171167 } else
172168 os << " %reg" << RegNo;
173 }
174
175 void MachineBasicBlock::print(std::ostream &OS) const {
176 raw_os_ostream RawOS(OS);
177 print(RawOS);
178169 }
179170
180171 void MachineBasicBlock::print(raw_ostream &OS) const {
3232 #include "llvm/Support/Compiler.h"
3333 #include "llvm/Support/GraphWriter.h"
3434 #include "llvm/Support/raw_ostream.h"
35 #include
36 #include
3735 using namespace llvm;
3836
3937 namespace {
4038 struct VISIBILITY_HIDDEN Printer : public MachineFunctionPass {
4139 static char ID;
4240
43 std::ostream *OS;
41 raw_ostream &OS;
4442 const std::string Banner;
4543
46 Printer(std::ostream *os, const std::string &banner)
44 Printer(raw_ostream &os, const std::string &banner)
4745 : MachineFunctionPass(&ID), OS(os), Banner(banner) {}
4846
4947 const char *getPassName() const { return "MachineFunction Printer"; }
5452 }
5553
5654 bool runOnMachineFunction(MachineFunction &MF) {
57 (*OS) << Banner;
58 MF.print (*OS);
55 OS << Banner;
56 MF.print(OS);
5957 return false;
6058 }
6159 };
6563 /// Returns a newly-created MachineFunction Printer pass. The default banner is
6664 /// empty.
6765 ///
68 FunctionPass *llvm::createMachineFunctionPrinterPass(std::ostream *OS,
66 FunctionPass *llvm::createMachineFunctionPrinterPass(raw_ostream &OS,
6967 const std::string &Banner){
7068 return new Printer(OS, Banner);
7169 }
219217 print(errs());
220218 }
221219
222 void MachineFunction::print(std::ostream &OS) const {
223 raw_os_ostream RawOS(OS);
224 print(RawOS);
225 }
226
227220 void MachineFunction::print(raw_ostream &OS) const {
228221 OS << "# Machine code for " << Fn->getName() << "():\n";
229222
283276 !Node->getBasicBlock()->getName().empty())
284277 return Node->getBasicBlock()->getNameStr() + ":";
285278
286 std::ostringstream Out;
287 if (ShortNames) {
288 Out << Node->getNumber() << ':';
289 return Out.str();
279 std::string OutStr;
280 {
281 raw_string_ostream OSS(OutStr);
282
283 if (ShortNames)
284 OSS << Node->getNumber() << ':';
285 else
286 Node->print(OSS);
290287 }
291288
292 Node->print(Out);
293
294 std::string OutStr = Out.str();
295289 if (OutStr[0] == '\n') OutStr.erase(OutStr.begin());
296290
297291 // Process string output to make it nicer...
238238 if (MI->getParent() == SuccToSinkTo)
239239 return false;
240240
241 DEBUG(cerr << "Sink instr " << *MI);
242 DEBUG(cerr << "to block " << *SuccToSinkTo);
241 DEBUG(errs() << "Sink instr " << *MI);
242 DEBUG(errs() << "to block " << *SuccToSinkTo);
243243
244244 // If the block has multiple predecessors, this would introduce computation on
245245 // a path that it doesn't already exist. We could split the critical edge,
246246 // but for now we just punt.
247247 // FIXME: Split critical edges if not backedges.
248248 if (SuccToSinkTo->pred_size() > 1) {
249 DEBUG(cerr << " *** PUNTING: Critical edge found\n");
249 DEBUG(errs() << " *** PUNTING: Critical edge found\n");
250250 return false;
251251 }
252252
2222 // the verifier errors.
2323 //===----------------------------------------------------------------------===//
2424
25 #include "llvm/ADT/DenseSet.h"
26 #include "llvm/ADT/SetOperations.h"
27 #include "llvm/ADT/SmallVector.h"
2825 #include "llvm/Function.h"
2926 #include "llvm/CodeGen/LiveVariables.h"
3027 #include "llvm/CodeGen/MachineFunctionPass.h"
3431 #include "llvm/Target/TargetMachine.h"
3532 #include "llvm/Target/TargetRegisterInfo.h"
3633 #include "llvm/Target/TargetInstrInfo.h"
34 #include "llvm/ADT/DenseSet.h"
35 #include "llvm/ADT/SetOperations.h"
36 #include "llvm/ADT/SmallVector.h"
3737 #include "llvm/Support/Compiler.h"
3838 #include "llvm/Support/Debug.h"
3939 #include "llvm/Support/ErrorHandling.h"