llvm.org GIT mirror llvm / b525766
Re-apply LiveInterval index dumping patch, with fixes suggested by Bill and others. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78003 91177308-0d34-0410-b5e6-96231b3b80d8 David Greene 11 years ago
8 changed file(s) with 149 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
0 //===- llvm/Support/Dump.h - Easy way to tailor dump output -----*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file provides the PrefixPrinter interface to pass to MachineFunction
10 // and MachineBasicBlock print methods to output additional information before
11 // blocks and instructions are printed.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_CODEGEN_DUMP_H
16 #define LLVM_CODEGEN_DUMP_H
17
18 #include
19
20 namespace llvm {
21
22 class MachineBasicBlock;
23 class MachineInstr;
24 class raw_ostream;
25
26 /// PrefixPrinter - Print some additional information before printing
27 /// basic blocks and instructions.
28 class PrefixPrinter {
29 public:
30 virtual ~PrefixPrinter();
31
32 /// operator() - Print a prefix before each MachineBasicBlock
33 virtual raw_ostream &operator()(raw_ostream &out,
34 const MachineBasicBlock &) const {
35 return out;
36 }
37
38 /// operator() - Print a prefix before each MachineInstr
39 virtual raw_ostream &operator()(raw_ostream &out,
40 const MachineInstr &) const {
41 return out;
42 }
43
44 /// operator() - Print a prefix before each MachineBasicBlock
45 virtual std::ostream &operator()(std::ostream &out,
46 const MachineBasicBlock &) const {
47 return out;
48 }
49
50 /// operator() - Print a prefix before each MachineInstr
51 virtual std::ostream &operator()(std::ostream &out,
52 const MachineInstr &) const {
53 return out;
54 }
55 };
56
57 } // End llvm namespace
58
59 #endif
537537 void printRegName(unsigned reg) const;
538538 };
539539
540 /// IntervalPrefixPrinter - Print live interval indices before each
541 /// instruction.
542 class IntervalPrefixPrinter : public PrefixPrinter {
543 private:
544 const LiveIntervals &liinfo;
545
546 public:
547 IntervalPrefixPrinter(const LiveIntervals &lii)
548 : liinfo(lii) {};
549
550 // We need null implementations of the other virtual functions to
551 // avoid warnings about hidden virtual functions.
552
553 raw_ostream &operator()(raw_ostream &out,
554 const MachineBasicBlock &instr) const {
555 return out;
556 }
557
558 raw_ostream &operator()(raw_ostream &out,
559 const MachineInstr &instr) const;
560
561 std::ostream &operator()(std::ostream &out,
562 const MachineBasicBlock &instr) const {
563 return out;
564 }
565
566 std::ostream &operator()(std::ostream &out,
567 const MachineInstr &instr) const {
568 return out;
569 }
570 };
540571 } // End llvm namespace
541572
542573 #endif
1515
1616 #include "llvm/CodeGen/MachineInstr.h"
1717 #include "llvm/ADT/GraphTraits.h"
18 #include "llvm/CodeGen/Dump.h"
1819
1920 namespace llvm {
2021
309310
310311 // Debugging methods.
311312 void dump() const;
312 void print(std::ostream &OS) const;
313 void print(std::ostream *OS) const { if (OS) print(*OS); }
314 void print(raw_ostream &OS) const;
315 void print(raw_ostream *OS) const { if (OS) print(*OS); }
313 void print(std::ostream &OS,
314 const PrefixPrinter &prefix = PrefixPrinter()) const;
315 void print(std::ostream *OS,
316 const PrefixPrinter &prefix = PrefixPrinter()) const {
317 if (OS) print(*OS, prefix);
318 }
319 void print(raw_ostream &OS,
320 const PrefixPrinter &prefix = PrefixPrinter()) const;
321 void print(raw_ostream *OS,
322 const PrefixPrinter &prefix = PrefixPrinter()) const {
323 if (OS) print(*OS, prefix);
324 }
316325
317326 /// getNumber - MachineBasicBlocks are uniquely numbered at the function
318327 /// level, unless they're not in a MachineFunction yet, in which case this
1919
2020 #include "llvm/ADT/ilist.h"
2121 #include "llvm/Support/DebugLoc.h"
22 #include "llvm/CodeGen/Dump.h"
2223 #include "llvm/CodeGen/MachineBasicBlock.h"
2324 #include "llvm/Support/Allocator.h"
2425 #include "llvm/Support/Recycler.h"
205206 /// print - Print out the MachineFunction in a format suitable for debugging
206207 /// to the specified stream.
207208 ///
208 void print(std::ostream &OS) const;
209 void print(std::ostream *OS) const { if (OS) print(*OS); }
209 void print(std::ostream &OS,
210 const PrefixPrinter &prefix = PrefixPrinter()) const;
211 void print(std::ostream *OS,
212 const PrefixPrinter &prefix = PrefixPrinter()) const {
213 if (OS) print(*OS, prefix);
214 }
210215
211216 /// viewCFG - This function is meant for use from the debugger. You can just
212217 /// say 'call F->viewCFG()' and a ghostview window should pop up from the
0 //===- lib/Support/Dump.h - Virtual function homes --------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file provides the PrefixPrinter virtual function homes.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "llvm/CodeGen/Dump.h"
14
15 using namespace llvm;
16
17 PrefixPrinter::~PrefixPrinter() {}
25002500
25012501 return LR;
25022502 }
2503
2504 raw_ostream &
2505 IntervalPrefixPrinter::operator()(raw_ostream &out,
2506 const MachineInstr &instr) const {
2507 return out << liinfo.getInstructionIndex(&instr);
2508 }
152152 os << " %reg" << RegNo;
153153 }
154154
155 void MachineBasicBlock::print(std::ostream &OS) const {
155 void MachineBasicBlock::print(std::ostream &OS,
156 const PrefixPrinter &prefix) const {
156157 raw_os_ostream RawOS(OS);
157 print(RawOS);
158 }
159
160 void MachineBasicBlock::print(raw_ostream &OS) const {
158 print(RawOS, prefix);
159 }
160
161 void MachineBasicBlock::print(raw_ostream &OS,
162 const PrefixPrinter &prefix) const {
161163 const MachineFunction *MF = getParent();
162164 if(!MF) {
163165 OS << "Can't print out MachineBasicBlock because parent MachineFunction"
190192 }
191193
192194 for (const_iterator I = begin(); I != end(); ++I) {
193 OS << "\t";
195 prefix(OS, *I) << "\t";
194196 I->print(OS, &getParent()->getTarget());
195197 }
196198
217217 print(*cerr.stream());
218218 }
219219
220 void MachineFunction::print(std::ostream &OS) const {
220 void MachineFunction::print(std::ostream &OS,
221 const PrefixPrinter &prefix) const {
221222 OS << "# Machine code for " << Fn->getNameStr () << "():\n";
222223
223224 // Print Frame Information
259260 OS << "\n";
260261 }
261262
262 for (const_iterator BB = begin(); BB != end(); ++BB)
263 BB->print(OS);
263 for (const_iterator BB = begin(); BB != end(); ++BB) {
264 prefix(OS, *BB);
265 BB->print(OS, prefix);
266 }
264267
265268 OS << "\n# End machine code for " << Fn->getNameStr () << "().\n\n";
266269 }