forked from OSchip/llvm-project
Teach MachineBasicBlock::print() to annotate instructions and blocks with
SlotIndexes when available. llvm-svn: 117392
This commit is contained in:
parent
db594373bd
commit
b7050233fb
|
@ -23,6 +23,7 @@ class Pass;
|
||||||
class BasicBlock;
|
class BasicBlock;
|
||||||
class MachineFunction;
|
class MachineFunction;
|
||||||
class MCSymbol;
|
class MCSymbol;
|
||||||
|
class SlotIndexes;
|
||||||
class StringRef;
|
class StringRef;
|
||||||
class raw_ostream;
|
class raw_ostream;
|
||||||
|
|
||||||
|
@ -361,7 +362,7 @@ public:
|
||||||
|
|
||||||
// Debugging methods.
|
// Debugging methods.
|
||||||
void dump() const;
|
void dump() const;
|
||||||
void print(raw_ostream &OS) const;
|
void print(raw_ostream &OS, SlotIndexes* = 0) const;
|
||||||
|
|
||||||
/// getNumber - MachineBasicBlocks are uniquely numbered at the function
|
/// getNumber - MachineBasicBlocks are uniquely numbered at the function
|
||||||
/// level, unless they're not in a MachineFunction yet, in which case this
|
/// level, unless they're not in a MachineFunction yet, in which case this
|
||||||
|
|
|
@ -244,7 +244,7 @@ public:
|
||||||
/// print - Print out the MachineFunction in a format suitable for debugging
|
/// print - Print out the MachineFunction in a format suitable for debugging
|
||||||
/// to the specified stream.
|
/// to the specified stream.
|
||||||
///
|
///
|
||||||
void print(raw_ostream &OS) const;
|
void print(raw_ostream &OS, SlotIndexes* = 0) const;
|
||||||
|
|
||||||
/// viewCFG - This function is meant for use from the debugger. You can just
|
/// 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
|
/// say 'call F->viewCFG()' and a ghostview window should pop up from the
|
||||||
|
|
|
@ -141,19 +141,7 @@ void LiveIntervals::print(raw_ostream &OS, const Module* ) const {
|
||||||
|
|
||||||
void LiveIntervals::printInstrs(raw_ostream &OS) const {
|
void LiveIntervals::printInstrs(raw_ostream &OS) const {
|
||||||
OS << "********** MACHINEINSTRS **********\n";
|
OS << "********** MACHINEINSTRS **********\n";
|
||||||
|
mf_->print(OS, indexes_);
|
||||||
for (MachineFunction::iterator mbbi = mf_->begin(), mbbe = mf_->end();
|
|
||||||
mbbi != mbbe; ++mbbi) {
|
|
||||||
OS << "BB#" << mbbi->getNumber()
|
|
||||||
<< ":\t\t# derived from " << mbbi->getName() << "\n";
|
|
||||||
for (MachineBasicBlock::iterator mii = mbbi->begin(),
|
|
||||||
mie = mbbi->end(); mii != mie; ++mii) {
|
|
||||||
if (mii->isDebugValue())
|
|
||||||
OS << " \t" << *mii;
|
|
||||||
else
|
|
||||||
OS << getInstructionIndex(mii) << '\t' << *mii;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LiveIntervals::dumpInstrs() const {
|
void LiveIntervals::dumpInstrs() const {
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include "llvm/CodeGen/MachineDominators.h"
|
#include "llvm/CodeGen/MachineDominators.h"
|
||||||
#include "llvm/CodeGen/MachineFunction.h"
|
#include "llvm/CodeGen/MachineFunction.h"
|
||||||
#include "llvm/CodeGen/MachineLoopInfo.h"
|
#include "llvm/CodeGen/MachineLoopInfo.h"
|
||||||
|
#include "llvm/CodeGen/SlotIndexes.h"
|
||||||
#include "llvm/MC/MCAsmInfo.h"
|
#include "llvm/MC/MCAsmInfo.h"
|
||||||
#include "llvm/MC/MCContext.h"
|
#include "llvm/MC/MCContext.h"
|
||||||
#include "llvm/Target/TargetRegisterInfo.h"
|
#include "llvm/Target/TargetRegisterInfo.h"
|
||||||
|
@ -176,7 +177,7 @@ StringRef MachineBasicBlock::getName() const {
|
||||||
return "(null)";
|
return "(null)";
|
||||||
}
|
}
|
||||||
|
|
||||||
void MachineBasicBlock::print(raw_ostream &OS) const {
|
void MachineBasicBlock::print(raw_ostream &OS, SlotIndexes *Indexes) const {
|
||||||
const MachineFunction *MF = getParent();
|
const MachineFunction *MF = getParent();
|
||||||
if (!MF) {
|
if (!MF) {
|
||||||
OS << "Can't print out MachineBasicBlock because parent MachineFunction"
|
OS << "Can't print out MachineBasicBlock because parent MachineFunction"
|
||||||
|
@ -186,6 +187,9 @@ void MachineBasicBlock::print(raw_ostream &OS) const {
|
||||||
|
|
||||||
if (Alignment) { OS << "Alignment " << Alignment << "\n"; }
|
if (Alignment) { OS << "Alignment " << Alignment << "\n"; }
|
||||||
|
|
||||||
|
if (Indexes)
|
||||||
|
OS << Indexes->getMBBStartIdx(this) << '\t';
|
||||||
|
|
||||||
OS << "BB#" << getNumber() << ": ";
|
OS << "BB#" << getNumber() << ": ";
|
||||||
|
|
||||||
const char *Comma = "";
|
const char *Comma = "";
|
||||||
|
@ -198,8 +202,9 @@ void MachineBasicBlock::print(raw_ostream &OS) const {
|
||||||
if (hasAddressTaken()) { OS << Comma << "ADDRESS TAKEN"; Comma = ", "; }
|
if (hasAddressTaken()) { OS << Comma << "ADDRESS TAKEN"; Comma = ", "; }
|
||||||
OS << '\n';
|
OS << '\n';
|
||||||
|
|
||||||
const TargetRegisterInfo *TRI = MF->getTarget().getRegisterInfo();
|
const TargetRegisterInfo *TRI = MF->getTarget().getRegisterInfo();
|
||||||
if (!livein_empty()) {
|
if (!livein_empty()) {
|
||||||
|
if (Indexes) OS << '\t';
|
||||||
OS << " Live Ins:";
|
OS << " Live Ins:";
|
||||||
for (livein_iterator I = livein_begin(),E = livein_end(); I != E; ++I)
|
for (livein_iterator I = livein_begin(),E = livein_end(); I != E; ++I)
|
||||||
OutputReg(OS, *I, TRI);
|
OutputReg(OS, *I, TRI);
|
||||||
|
@ -207,19 +212,26 @@ void MachineBasicBlock::print(raw_ostream &OS) const {
|
||||||
}
|
}
|
||||||
// Print the preds of this block according to the CFG.
|
// Print the preds of this block according to the CFG.
|
||||||
if (!pred_empty()) {
|
if (!pred_empty()) {
|
||||||
|
if (Indexes) OS << '\t';
|
||||||
OS << " Predecessors according to CFG:";
|
OS << " Predecessors according to CFG:";
|
||||||
for (const_pred_iterator PI = pred_begin(), E = pred_end(); PI != E; ++PI)
|
for (const_pred_iterator PI = pred_begin(), E = pred_end(); PI != E; ++PI)
|
||||||
OS << " BB#" << (*PI)->getNumber();
|
OS << " BB#" << (*PI)->getNumber();
|
||||||
OS << '\n';
|
OS << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const_iterator I = begin(); I != end(); ++I) {
|
for (const_iterator I = begin(); I != end(); ++I) {
|
||||||
|
if (Indexes) {
|
||||||
|
if (Indexes->hasIndex(I))
|
||||||
|
OS << Indexes->getInstructionIndex(I);
|
||||||
|
OS << '\t';
|
||||||
|
}
|
||||||
OS << '\t';
|
OS << '\t';
|
||||||
I->print(OS, &getParent()->getTarget());
|
I->print(OS, &getParent()->getTarget());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print the successors of this block according to the CFG.
|
// Print the successors of this block according to the CFG.
|
||||||
if (!succ_empty()) {
|
if (!succ_empty()) {
|
||||||
|
if (Indexes) OS << '\t';
|
||||||
OS << " Successors according to CFG:";
|
OS << " Successors according to CFG:";
|
||||||
for (const_succ_iterator SI = succ_begin(), E = succ_end(); SI != E; ++SI)
|
for (const_succ_iterator SI = succ_begin(), E = succ_end(); SI != E; ++SI)
|
||||||
OS << " BB#" << (*SI)->getNumber();
|
OS << " BB#" << (*SI)->getNumber();
|
||||||
|
|
|
@ -280,7 +280,7 @@ void MachineFunction::dump() const {
|
||||||
print(dbgs());
|
print(dbgs());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MachineFunction::print(raw_ostream &OS) const {
|
void MachineFunction::print(raw_ostream &OS, SlotIndexes *Indexes) const {
|
||||||
OS << "# Machine code for function " << Fn->getName() << ":\n";
|
OS << "# Machine code for function " << Fn->getName() << ":\n";
|
||||||
|
|
||||||
// Print Frame Information
|
// Print Frame Information
|
||||||
|
@ -329,7 +329,7 @@ void MachineFunction::print(raw_ostream &OS) const {
|
||||||
|
|
||||||
for (const_iterator BB = begin(), E = end(); BB != E; ++BB) {
|
for (const_iterator BB = begin(), E = end(); BB != E; ++BB) {
|
||||||
OS << '\n';
|
OS << '\n';
|
||||||
BB->print(OS);
|
BB->print(OS, Indexes);
|
||||||
}
|
}
|
||||||
|
|
||||||
OS << "\n# End machine code for function " << Fn->getName() << ".\n\n";
|
OS << "\n# End machine code for function " << Fn->getName() << ".\n\n";
|
||||||
|
|
|
@ -168,6 +168,7 @@ namespace {
|
||||||
// Analysis information if available
|
// Analysis information if available
|
||||||
LiveVariables *LiveVars;
|
LiveVariables *LiveVars;
|
||||||
const LiveIntervals *LiveInts;
|
const LiveIntervals *LiveInts;
|
||||||
|
SlotIndexes *Indexes;
|
||||||
|
|
||||||
void visitMachineFunctionBefore();
|
void visitMachineFunctionBefore();
|
||||||
void visitMachineBasicBlockBefore(const MachineBasicBlock *MBB);
|
void visitMachineBasicBlockBefore(const MachineBasicBlock *MBB);
|
||||||
|
@ -249,11 +250,13 @@ bool MachineVerifier::runOnMachineFunction(MachineFunction &MF) {
|
||||||
|
|
||||||
LiveVars = NULL;
|
LiveVars = NULL;
|
||||||
LiveInts = NULL;
|
LiveInts = NULL;
|
||||||
|
Indexes = NULL;
|
||||||
if (PASS) {
|
if (PASS) {
|
||||||
LiveInts = PASS->getAnalysisIfAvailable<LiveIntervals>();
|
LiveInts = PASS->getAnalysisIfAvailable<LiveIntervals>();
|
||||||
// We don't want to verify LiveVariables if LiveIntervals is available.
|
// We don't want to verify LiveVariables if LiveIntervals is available.
|
||||||
if (!LiveInts)
|
if (!LiveInts)
|
||||||
LiveVars = PASS->getAnalysisIfAvailable<LiveVariables>();
|
LiveVars = PASS->getAnalysisIfAvailable<LiveVariables>();
|
||||||
|
Indexes = PASS->getAnalysisIfAvailable<SlotIndexes>();
|
||||||
}
|
}
|
||||||
|
|
||||||
visitMachineFunctionBefore();
|
visitMachineFunctionBefore();
|
||||||
|
@ -291,7 +294,7 @@ void MachineVerifier::report(const char *msg, const MachineFunction *MF) {
|
||||||
assert(MF);
|
assert(MF);
|
||||||
*OS << '\n';
|
*OS << '\n';
|
||||||
if (!foundErrors++)
|
if (!foundErrors++)
|
||||||
MF->print(*OS);
|
MF->print(*OS, Indexes);
|
||||||
*OS << "*** Bad machine code: " << msg << " ***\n"
|
*OS << "*** Bad machine code: " << msg << " ***\n"
|
||||||
<< "- function: " << MF->getFunction()->getNameStr() << "\n";
|
<< "- function: " << MF->getFunction()->getNameStr() << "\n";
|
||||||
}
|
}
|
||||||
|
@ -301,13 +304,19 @@ void MachineVerifier::report(const char *msg, const MachineBasicBlock *MBB) {
|
||||||
report(msg, MBB->getParent());
|
report(msg, MBB->getParent());
|
||||||
*OS << "- basic block: " << MBB->getName()
|
*OS << "- basic block: " << MBB->getName()
|
||||||
<< " " << (void*)MBB
|
<< " " << (void*)MBB
|
||||||
<< " (BB#" << MBB->getNumber() << ")\n";
|
<< " (BB#" << MBB->getNumber() << ")";
|
||||||
|
if (Indexes)
|
||||||
|
*OS << " [" << Indexes->getMBBStartIdx(MBB)
|
||||||
|
<< ';' << Indexes->getMBBEndIdx(MBB) << ')';
|
||||||
|
*OS << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
void MachineVerifier::report(const char *msg, const MachineInstr *MI) {
|
void MachineVerifier::report(const char *msg, const MachineInstr *MI) {
|
||||||
assert(MI);
|
assert(MI);
|
||||||
report(msg, MI->getParent());
|
report(msg, MI->getParent());
|
||||||
*OS << "- instruction: ";
|
*OS << "- instruction: ";
|
||||||
|
if (Indexes && Indexes->hasIndex(MI))
|
||||||
|
*OS << Indexes->getInstructionIndex(MI) << '\t';
|
||||||
MI->print(*OS, TM);
|
MI->print(*OS, TM);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue