From b5257664795d49ada0d4669fe8ed1cd49c04fbf3 Mon Sep 17 00:00:00 2001 From: David Greene Date: Mon, 3 Aug 2009 21:55:09 +0000 Subject: [PATCH] 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 --- include/llvm/CodeGen/Dump.h | 60 +++++++++++++++++++++ include/llvm/CodeGen/LiveIntervalAnalysis.h | 31 +++++++++++ include/llvm/CodeGen/MachineBasicBlock.h | 17 ++++-- include/llvm/CodeGen/MachineFunction.h | 9 +++- lib/CodeGen/Dump.cpp | 18 +++++++ lib/CodeGen/LiveIntervalAnalysis.cpp | 6 +++ lib/CodeGen/MachineBasicBlock.cpp | 10 ++-- lib/CodeGen/MachineFunction.cpp | 9 ++-- 8 files changed, 147 insertions(+), 13 deletions(-) create mode 100644 include/llvm/CodeGen/Dump.h create mode 100644 lib/CodeGen/Dump.cpp diff --git a/include/llvm/CodeGen/Dump.h b/include/llvm/CodeGen/Dump.h new file mode 100644 index 00000000000..439141cb44e --- /dev/null +++ b/include/llvm/CodeGen/Dump.h @@ -0,0 +1,60 @@ +//===- llvm/Support/Dump.h - Easy way to tailor dump output -----*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file provides the PrefixPrinter interface to pass to MachineFunction +// and MachineBasicBlock print methods to output additional information before +// blocks and instructions are printed. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CODEGEN_DUMP_H +#define LLVM_CODEGEN_DUMP_H + +#include + +namespace llvm { + +class MachineBasicBlock; +class MachineInstr; +class raw_ostream; + +/// PrefixPrinter - Print some additional information before printing +/// basic blocks and instructions. +class PrefixPrinter { +public: + virtual ~PrefixPrinter(); + + /// operator() - Print a prefix before each MachineBasicBlock + virtual raw_ostream &operator()(raw_ostream &out, + const MachineBasicBlock &) const { + return out; + } + + /// operator() - Print a prefix before each MachineInstr + virtual raw_ostream &operator()(raw_ostream &out, + const MachineInstr &) const { + return out; + } + + /// operator() - Print a prefix before each MachineBasicBlock + virtual std::ostream &operator()(std::ostream &out, + const MachineBasicBlock &) const { + return out; + } + + /// operator() - Print a prefix before each MachineInstr + virtual std::ostream &operator()(std::ostream &out, + const MachineInstr &) const { + return out; + } +}; + +} // End llvm namespace + +#endif diff --git a/include/llvm/CodeGen/LiveIntervalAnalysis.h b/include/llvm/CodeGen/LiveIntervalAnalysis.h index 32bf67b8cc0..aa5f0ffb014 100644 --- a/include/llvm/CodeGen/LiveIntervalAnalysis.h +++ b/include/llvm/CodeGen/LiveIntervalAnalysis.h @@ -538,6 +538,37 @@ namespace llvm { void printRegName(unsigned reg) const; }; + /// IntervalPrefixPrinter - Print live interval indices before each + /// instruction. + class IntervalPrefixPrinter : public PrefixPrinter { + private: + const LiveIntervals &liinfo; + + public: + IntervalPrefixPrinter(const LiveIntervals &lii) + : liinfo(lii) {}; + + // We need null implementations of the other virtual functions to + // avoid warnings about hidden virtual functions. + + raw_ostream &operator()(raw_ostream &out, + const MachineBasicBlock &instr) const { + return out; + } + + raw_ostream &operator()(raw_ostream &out, + const MachineInstr &instr) const; + + std::ostream &operator()(std::ostream &out, + const MachineBasicBlock &instr) const { + return out; + } + + std::ostream &operator()(std::ostream &out, + const MachineInstr &instr) const { + return out; + } + }; } // End llvm namespace #endif diff --git a/include/llvm/CodeGen/MachineBasicBlock.h b/include/llvm/CodeGen/MachineBasicBlock.h index 90d67e56763..51b2bbf66b6 100644 --- a/include/llvm/CodeGen/MachineBasicBlock.h +++ b/include/llvm/CodeGen/MachineBasicBlock.h @@ -16,6 +16,7 @@ #include "llvm/CodeGen/MachineInstr.h" #include "llvm/ADT/GraphTraits.h" +#include "llvm/CodeGen/Dump.h" namespace llvm { @@ -310,10 +311,18 @@ public: // Debugging methods. void dump() const; - void print(std::ostream &OS) const; - void print(std::ostream *OS) const { if (OS) print(*OS); } - void print(raw_ostream &OS) const; - void print(raw_ostream *OS) const { if (OS) print(*OS); } + void print(std::ostream &OS, + const PrefixPrinter &prefix = PrefixPrinter()) const; + void print(std::ostream *OS, + const PrefixPrinter &prefix = PrefixPrinter()) const { + if (OS) print(*OS, prefix); + } + void print(raw_ostream &OS, + const PrefixPrinter &prefix = PrefixPrinter()) const; + void print(raw_ostream *OS, + const PrefixPrinter &prefix = PrefixPrinter()) const { + if (OS) print(*OS, prefix); + } /// getNumber - MachineBasicBlocks are uniquely numbered at the function /// level, unless they're not in a MachineFunction yet, in which case this diff --git a/include/llvm/CodeGen/MachineFunction.h b/include/llvm/CodeGen/MachineFunction.h index 13e223ff699..57c946c789a 100644 --- a/include/llvm/CodeGen/MachineFunction.h +++ b/include/llvm/CodeGen/MachineFunction.h @@ -20,6 +20,7 @@ #include "llvm/ADT/ilist.h" #include "llvm/Support/DebugLoc.h" +#include "llvm/CodeGen/Dump.h" #include "llvm/CodeGen/MachineBasicBlock.h" #include "llvm/Support/Allocator.h" #include "llvm/Support/Recycler.h" @@ -206,8 +207,12 @@ public: /// print - Print out the MachineFunction in a format suitable for debugging /// to the specified stream. /// - void print(std::ostream &OS) const; - void print(std::ostream *OS) const { if (OS) print(*OS); } + void print(std::ostream &OS, + const PrefixPrinter &prefix = PrefixPrinter()) const; + void print(std::ostream *OS, + const PrefixPrinter &prefix = PrefixPrinter()) const { + if (OS) print(*OS, prefix); + } /// viewCFG - This function is meant for use from the debugger. You can just /// say 'call F->viewCFG()' and a ghostview window should pop up from the diff --git a/lib/CodeGen/Dump.cpp b/lib/CodeGen/Dump.cpp new file mode 100644 index 00000000000..2e70d5f25e9 --- /dev/null +++ b/lib/CodeGen/Dump.cpp @@ -0,0 +1,18 @@ +//===- lib/Support/Dump.h - Virtual function homes --------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file provides the PrefixPrinter virtual function homes. +// +//===----------------------------------------------------------------------===// + +#include "llvm/CodeGen/Dump.h" + +using namespace llvm; + +PrefixPrinter::~PrefixPrinter() {} diff --git a/lib/CodeGen/LiveIntervalAnalysis.cpp b/lib/CodeGen/LiveIntervalAnalysis.cpp index 2c7cc765e4f..63a391a319a 100644 --- a/lib/CodeGen/LiveIntervalAnalysis.cpp +++ b/lib/CodeGen/LiveIntervalAnalysis.cpp @@ -2501,3 +2501,9 @@ LiveRange LiveIntervals::addLiveRangeToEndOfBlock(unsigned reg, return LR; } + +raw_ostream & +IntervalPrefixPrinter::operator()(raw_ostream &out, + const MachineInstr &instr) const { + return out << liinfo.getInstructionIndex(&instr); +} diff --git a/lib/CodeGen/MachineBasicBlock.cpp b/lib/CodeGen/MachineBasicBlock.cpp index 80ca8727f72..b30a3fcf300 100644 --- a/lib/CodeGen/MachineBasicBlock.cpp +++ b/lib/CodeGen/MachineBasicBlock.cpp @@ -153,12 +153,14 @@ static inline void OutputReg(raw_ostream &os, unsigned RegNo, os << " %reg" << RegNo; } -void MachineBasicBlock::print(std::ostream &OS) const { +void MachineBasicBlock::print(std::ostream &OS, + const PrefixPrinter &prefix) const { raw_os_ostream RawOS(OS); - print(RawOS); + print(RawOS, prefix); } -void MachineBasicBlock::print(raw_ostream &OS) const { +void MachineBasicBlock::print(raw_ostream &OS, + const PrefixPrinter &prefix) const { const MachineFunction *MF = getParent(); if(!MF) { OS << "Can't print out MachineBasicBlock because parent MachineFunction" @@ -191,7 +193,7 @@ void MachineBasicBlock::print(raw_ostream &OS) const { } for (const_iterator I = begin(); I != end(); ++I) { - OS << "\t"; + prefix(OS, *I) << "\t"; I->print(OS, &getParent()->getTarget()); } diff --git a/lib/CodeGen/MachineFunction.cpp b/lib/CodeGen/MachineFunction.cpp index 858f40362b0..2e9303aeefb 100644 --- a/lib/CodeGen/MachineFunction.cpp +++ b/lib/CodeGen/MachineFunction.cpp @@ -218,7 +218,8 @@ void MachineFunction::dump() const { print(*cerr.stream()); } -void MachineFunction::print(std::ostream &OS) const { +void MachineFunction::print(std::ostream &OS, + const PrefixPrinter &prefix) const { OS << "# Machine code for " << Fn->getNameStr () << "():\n"; // Print Frame Information @@ -260,8 +261,10 @@ void MachineFunction::print(std::ostream &OS) const { OS << "\n"; } - for (const_iterator BB = begin(); BB != end(); ++BB) - BB->print(OS); + for (const_iterator BB = begin(); BB != end(); ++BB) { + prefix(OS, *BB); + BB->print(OS, prefix); + } OS << "\n# End machine code for " << Fn->getNameStr () << "().\n\n"; } -- 2.34.1