From a358c1db5c744f7c524b18f2860c2d48613adbd1 Mon Sep 17 00:00:00 2001 From: David Greene Date: Tue, 21 Jul 2009 18:56:32 +0000 Subject: [PATCH] Prefix IR dumps with LiveInterval indices when possible. This turns this: %ESI = MOV32rr %EDI ADJCALLSTACKDOWN64 0, %RSP, %EFLAGS, %RSP %reg1027 = MOVZX64rr32 %ESI %reg1027 = ADD64ri8 %reg1027, 15, %EFLAGS %reg1027 = AND64ri8 %reg1027, -16, %EFLAGS %RDI = MOV64rr %RSP %RDI = SUB64rr %RDI, %reg1027, %EFLAGS %RSP = MOV64rr %RDI into this: 4 %reg1024 = MOV32rr %EDI 12 ADJCALLSTACKDOWN64 0, %RSP, %EFLAGS, %RSP 20 %reg1025 = MOVZX64rr32 %reg1024 28 %reg1026 = MOV64rr %reg1025 36 %reg1026 = ADD64ri8 %reg1026, 15, %EFLAGS 44 %reg1027 = MOV64rr %reg1026 52 %reg1027 = AND64ri8 %reg1027, -16, %EFLAGS 60 %reg1028 = MOV64rr %RSP 68 %reg1029 = MOV64rr %reg1028 76 %reg1029 = SUB64rr %reg1029, %reg1027, %EFLAGS 84 %RSP = MOV64rr %reg1029 This helps greatly when debugging register allocation and coalescing problems. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76615 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/LiveIntervalAnalysis.h | 26 +++++++++++++++++++-- lib/CodeGen/LiveIntervalAnalysis.cpp | 11 ++------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/include/llvm/CodeGen/LiveIntervalAnalysis.h b/include/llvm/CodeGen/LiveIntervalAnalysis.h index 40991e74e3c..ea67cdbba24 100644 --- a/include/llvm/CodeGen/LiveIntervalAnalysis.h +++ b/include/llvm/CodeGen/LiveIntervalAnalysis.h @@ -27,7 +27,9 @@ #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Support/Allocator.h" +#include "llvm/Support/Dump.h" #include +#include namespace llvm { @@ -79,7 +81,7 @@ namespace llvm { /// FunctionSize - The number of instructions present in the function uint64_t FunctionSize; - typedef DenseMap Mi2IndexMap; + typedef DenseMap Mi2IndexMap; Mi2IndexMap mi2iMap_; typedef std::vector Index2MiMap; @@ -198,7 +200,7 @@ namespace llvm { } /// getInstructionIndex - returns the base index of instr - unsigned getInstructionIndex(MachineInstr* instr) const { + unsigned getInstructionIndex(const MachineInstr* instr) const { Mi2IndexMap::const_iterator it = mi2iMap_.find(instr); assert(it != mi2iMap_.end() && "Invalid instruction!"); return it->second; @@ -538,6 +540,26 @@ 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) {}; + + std::string operator()(const MachineBasicBlock &) const { + return(""); + }; + + std::string operator()(const MachineInstr &instr) const { + std::stringstream out; + out << liinfo.getInstructionIndex(&instr); + return(out.str()); + }; + }; } // End llvm namespace #endif diff --git a/lib/CodeGen/LiveIntervalAnalysis.cpp b/lib/CodeGen/LiveIntervalAnalysis.cpp index 261fa5e0f86..aba6ff11b42 100644 --- a/lib/CodeGen/LiveIntervalAnalysis.cpp +++ b/lib/CodeGen/LiveIntervalAnalysis.cpp @@ -464,7 +464,7 @@ void LiveIntervals::scaleNumbering(int factor) { i2miMap_.resize(highestSlot + 1); for (Mi2IndexMap::iterator MI = mi2iMap_.begin(), ME = mi2iMap_.end(); MI != ME; ++MI) { - i2miMap_[MI->second] = MI->first; + i2miMap_[MI->second] = const_cast(MI->first); } } @@ -501,14 +501,7 @@ void LiveIntervals::print(std::ostream &O, const Module* ) const { } O << "********** MACHINEINSTRS **********\n"; - for (MachineFunction::iterator mbbi = mf_->begin(), mbbe = mf_->end(); - mbbi != mbbe; ++mbbi) { - O << ((Value*)mbbi->getBasicBlock())->getName() << ":\n"; - for (MachineBasicBlock::iterator mii = mbbi->begin(), - mie = mbbi->end(); mii != mie; ++mii) { - O << getInstructionIndex(mii) << '\t' << *mii; - } - } + mf_->print(O, IntervalPrefixPrinter(*this)); } /// conflictsWithPhysRegDef - Returns true if the specified register