Update processDebugLoc() so that it can be used to process debug info before and after printing an instruction.

llvm-svn: 83363
This commit is contained in:
Devang Patel 2009-10-06 02:19:11 +00:00
parent 2980a22028
commit 051454a16f
19 changed files with 51 additions and 32 deletions

View File

@ -141,7 +141,7 @@ namespace llvm {
mutable const Function *LastFn; mutable const Function *LastFn;
mutable unsigned Counter; mutable unsigned Counter;
// Private state for processDebugLock() // Private state for processDebugLoc()
mutable DebugLocTuple PrevDLT; mutable DebugLocTuple PrevDLT;
protected: protected:
@ -357,8 +357,8 @@ namespace llvm {
virtual void EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV); virtual void EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV);
/// processDebugLoc - Processes the debug information of each machine /// processDebugLoc - Processes the debug information of each machine
/// instruction's DebugLoc. /// instruction's DebugLoc.
void processDebugLoc(const MachineInstr *MI); void processDebugLoc(const MachineInstr *MI, bool BeforePrintingInsn);
/// printInlineAsm - This method formats and prints the specified machine /// printInlineAsm - This method formats and prints the specified machine
/// instruction that is an inline asm. /// instruction that is an inline asm.

View File

@ -237,7 +237,7 @@ public:
/// MachineInstruction. This is called before emitting any bytes associated /// MachineInstruction. This is called before emitting any bytes associated
/// with the instruction. Even if successive instructions have the same debug /// with the instruction. Even if successive instructions have the same debug
/// location, this method will be called for each one. /// location, this method will be called for each one.
virtual void processDebugLoc(DebugLoc DL) {} virtual void processDebugLoc(DebugLoc DL, bool BeforePrintintInsn) {}
/// emitLabel - Emits a label /// emitLabel - Emits a label
virtual void emitLabel(uint64_t LabelID) = 0; virtual void emitLabel(uint64_t LabelID) = 0;

View File

@ -1353,18 +1353,20 @@ void AsmPrinter::PrintSpecial(const MachineInstr *MI, const char *Code) const {
/// processDebugLoc - Processes the debug information of each machine /// processDebugLoc - Processes the debug information of each machine
/// instruction's DebugLoc. /// instruction's DebugLoc.
void AsmPrinter::processDebugLoc(const MachineInstr *MI) { void AsmPrinter::processDebugLoc(const MachineInstr *MI,
bool BeforePrintingInsn) {
if (!MAI || !DW) if (!MAI || !DW)
return; return;
DebugLoc DL = MI->getDebugLoc(); DebugLoc DL = MI->getDebugLoc();
if (MAI->doesSupportDebugInformation() && DW->ShouldEmitDwarfDebug()) { if (MAI->doesSupportDebugInformation() && DW->ShouldEmitDwarfDebug()) {
if (!DL.isUnknown()) { if (!DL.isUnknown()) {
DebugLocTuple CurDLT = MF->getDebugLocTuple(DL); DebugLocTuple CurDLT = MF->getDebugLocTuple(DL);
if (BeforePrintingInsn) {
if (CurDLT.CompileUnit != 0 && PrevDLT != CurDLT) { if (CurDLT.CompileUnit != 0 && PrevDLT != CurDLT) {
printLabel(DW->RecordSourceLine(CurDLT.Line, CurDLT.Col, printLabel(DW->RecordSourceLine(CurDLT.Line, CurDLT.Col,
CurDLT.CompileUnit)); CurDLT.CompileUnit));
O << '\n'; O << '\n';
}
} }
PrevDLT = CurDLT; PrevDLT = CurDLT;

View File

@ -346,7 +346,7 @@ template<class CodeEmitter>
void Emitter<CodeEmitter>::emitInstruction(const MachineInstr &MI) { void Emitter<CodeEmitter>::emitInstruction(const MachineInstr &MI) {
DEBUG(errs() << "JIT: " << (void*)MCE.getCurrentPCValue() << ":\t" << MI); DEBUG(errs() << "JIT: " << (void*)MCE.getCurrentPCValue() << ":\t" << MI);
MCE.processDebugLoc(MI.getDebugLoc()); MCE.processDebugLoc(MI.getDebugLoc(), true);
NumEmitted++; // Keep track of the # of mi's emitted NumEmitted++; // Keep track of the # of mi's emitted
switch (MI.getDesc().TSFlags & ARMII::FormMask) { switch (MI.getDesc().TSFlags & ARMII::FormMask) {
@ -409,6 +409,7 @@ void Emitter<CodeEmitter>::emitInstruction(const MachineInstr &MI) {
emitMiscInstruction(MI); emitMiscInstruction(MI);
break; break;
} }
MCE.processDebugLoc(MI.getDebugLoc(), false);
} }
template<class CodeEmitter> template<class CodeEmitter>

View File

@ -1038,11 +1038,12 @@ void ARMAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
}} }}
// Call the autogenerated instruction printer routines. // Call the autogenerated instruction printer routines.
processDebugLoc(MI); processDebugLoc(MI, true);
printInstruction(MI); printInstruction(MI);
if (VerboseAsm && !MI->getDebugLoc().isUnknown()) if (VerboseAsm && !MI->getDebugLoc().isUnknown())
EmitComments(*MI); EmitComments(*MI);
O << '\n'; O << '\n';
processDebugLoc(MI, false);
} }
void ARMAsmPrinter::EmitStartOfAsmFile(Module &M) { void ARMAsmPrinter::EmitStartOfAsmFile(Module &M) {

View File

@ -116,7 +116,7 @@ void Emitter<CodeEmitter>::emitBasicBlock(MachineBasicBlock &MBB) {
for (MachineBasicBlock::iterator I = MBB.begin(), E = MBB.end(); for (MachineBasicBlock::iterator I = MBB.begin(), E = MBB.end();
I != E; ++I) { I != E; ++I) {
const MachineInstr &MI = *I; const MachineInstr &MI = *I;
MCE.processDebugLoc(MI.getDebugLoc()); MCE.processDebugLoc(MI.getDebugLoc(), true);
switch(MI.getOpcode()) { switch(MI.getOpcode()) {
default: default:
MCE.emitWordLE(getBinaryCodeForInstr(*I)); MCE.emitWordLE(getBinaryCodeForInstr(*I));
@ -128,6 +128,7 @@ void Emitter<CodeEmitter>::emitBasicBlock(MachineBasicBlock &MBB) {
case TargetInstrInfo::KILL: case TargetInstrInfo::KILL:
break; //skip these break; //skip these
} }
MCE.processDebugLoc(MI.getDebugLoc(), false);
} }
} }

View File

@ -177,13 +177,13 @@ bool AlphaAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
II != E; ++II) { II != E; ++II) {
// Print the assembly for the instruction. // Print the assembly for the instruction.
++EmittedInsts; ++EmittedInsts;
processDebugLoc(II); processDebugLoc(II, true);
printInstruction(II); printInstruction(II);
if (VerboseAsm && !II->getDebugLoc().isUnknown()) if (VerboseAsm && !II->getDebugLoc().isUnknown())
EmitComments(*II); EmitComments(*II);
O << '\n'; O << '\n';
processDebugLoc(II, false);
} }
} }

View File

@ -146,13 +146,14 @@ bool BlackfinAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end(); for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
II != E; ++II) { II != E; ++II) {
// Print the assembly for the instruction. // Print the assembly for the instruction.
processDebugLoc(II); processDebugLoc(II, true);
printInstruction(II); printInstruction(II);
if (VerboseAsm && !II->getDebugLoc().isUnknown()) if (VerboseAsm && !II->getDebugLoc().isUnknown())
EmitComments(*II); EmitComments(*II);
O << '\n'; O << '\n';
processDebugLoc(II, false);
++EmittedInsts; ++EmittedInsts;
} }
} }

View File

@ -405,11 +405,11 @@ bool SPUAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
/// ///
void SPUAsmPrinter::printMachineInstruction(const MachineInstr *MI) { void SPUAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
++EmittedInsts; ++EmittedInsts;
processDebugLoc(MI); processDebugLoc(MI, true);
printInstruction(MI); printInstruction(MI);
if (VerboseAsm && !MI->getDebugLoc().isUnknown()) if (VerboseAsm && !MI->getDebugLoc().isUnknown())
EmitComments(*MI); EmitComments(*MI);
processDebugLoc(MI, false);
O << '\n'; O << '\n';
} }

View File

@ -148,7 +148,7 @@ bool MSP430AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
void MSP430AsmPrinter::printMachineInstruction(const MachineInstr *MI) { void MSP430AsmPrinter::printMachineInstruction(const MachineInstr *MI) {
++EmittedInsts; ++EmittedInsts;
processDebugLoc(MI); processDebugLoc(MI, true);
// Call the autogenerated instruction printer routines. // Call the autogenerated instruction printer routines.
printInstruction(MI); printInstruction(MI);
@ -156,6 +156,8 @@ void MSP430AsmPrinter::printMachineInstruction(const MachineInstr *MI) {
if (VerboseAsm && !MI->getDebugLoc().isUnknown()) if (VerboseAsm && !MI->getDebugLoc().isUnknown())
EmitComments(*MI); EmitComments(*MI);
O << '\n'; O << '\n';
processDebugLoc(MI, false);
} }
void MSP430AsmPrinter::printOperand(const MachineInstr *MI, int OpNum, void MSP430AsmPrinter::printOperand(const MachineInstr *MI, int OpNum,

View File

@ -278,7 +278,7 @@ bool MipsAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end(); for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
II != E; ++II) { II != E; ++II) {
processDebugLoc(II); processDebugLoc(II, true);
// Print the assembly for the instruction. // Print the assembly for the instruction.
printInstruction(II); printInstruction(II);
@ -286,7 +286,8 @@ bool MipsAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
if (VerboseAsm && !II->getDebugLoc().isUnknown()) if (VerboseAsm && !II->getDebugLoc().isUnknown())
EmitComments(*II); EmitComments(*II);
O << '\n'; O << '\n';
processDebugLoc(II, false);
++EmittedInsts; ++EmittedInsts;
} }

View File

@ -43,13 +43,12 @@ PIC16AsmPrinter::PIC16AsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
} }
bool PIC16AsmPrinter::printMachineInstruction(const MachineInstr *MI) { bool PIC16AsmPrinter::printMachineInstruction(const MachineInstr *MI) {
processDebugLoc(MI); processDebugLoc(MI, true);
printInstruction(MI); printInstruction(MI);
if (VerboseAsm && !MI->getDebugLoc().isUnknown()) if (VerboseAsm && !MI->getDebugLoc().isUnknown())
EmitComments(*MI); EmitComments(*MI);
O << '\n'; O << '\n';
processDebugLoc(MI, false);
return true; return true;
} }

View File

@ -545,7 +545,7 @@ void PPCAsmPrinter::printPredicateOperand(const MachineInstr *MI, unsigned OpNo,
void PPCAsmPrinter::printMachineInstruction(const MachineInstr *MI) { void PPCAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
++EmittedInsts; ++EmittedInsts;
processDebugLoc(MI); processDebugLoc(MI, true);
// Check for slwi/srwi mnemonics. // Check for slwi/srwi mnemonics.
if (MI->getOpcode() == PPC::RLWINM) { if (MI->getOpcode() == PPC::RLWINM) {
@ -595,6 +595,8 @@ void PPCAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
if (VerboseAsm && !MI->getDebugLoc().isUnknown()) if (VerboseAsm && !MI->getDebugLoc().isUnknown())
EmitComments(*MI); EmitComments(*MI);
O << '\n'; O << '\n';
processDebugLoc(MI, false);
} }
/// runOnMachineFunction - This uses the printMachineInstruction() /// runOnMachineFunction - This uses the printMachineInstruction()

View File

@ -132,7 +132,7 @@ void Emitter<CodeEmitter>::emitBasicBlock(MachineBasicBlock &MBB) {
for (MachineBasicBlock::iterator I = MBB.begin(), E = MBB.end(); I != E; ++I){ for (MachineBasicBlock::iterator I = MBB.begin(), E = MBB.end(); I != E; ++I){
const MachineInstr &MI = *I; const MachineInstr &MI = *I;
MCE.processDebugLoc(MI.getDebugLoc()); MCE.processDebugLoc(MI.getDebugLoc(), true);
switch (MI.getOpcode()) { switch (MI.getOpcode()) {
default: default:
MCE.emitWordBE(getBinaryCodeForInstr(MI)); MCE.emitWordBE(getBinaryCodeForInstr(MI));
@ -151,6 +151,7 @@ void Emitter<CodeEmitter>::emitBasicBlock(MachineBasicBlock &MBB) {
MCE.emitWordBE(0x48000005); // bl 1 MCE.emitWordBE(0x48000005); // bl 1
break; break;
} }
MCE.processDebugLoc(MI.getDebugLoc(), false);
} }
} }

View File

@ -124,13 +124,13 @@ bool SparcAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end(); for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
II != E; ++II) { II != E; ++II) {
// Print the assembly for the instruction. // Print the assembly for the instruction.
processDebugLoc(II); processDebugLoc(II, true);
printInstruction(II); printInstruction(II);
if (VerboseAsm && !II->getDebugLoc().isUnknown()) if (VerboseAsm && !II->getDebugLoc().isUnknown())
EmitComments(*II); EmitComments(*II);
O << '\n'; O << '\n';
processDebugLoc(II, false);
++EmittedInsts; ++EmittedInsts;
} }
} }

View File

@ -156,7 +156,7 @@ bool SystemZAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
void SystemZAsmPrinter::printMachineInstruction(const MachineInstr *MI) { void SystemZAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
++EmittedInsts; ++EmittedInsts;
processDebugLoc(MI); processDebugLoc(MI, true);
// Call the autogenerated instruction printer routines. // Call the autogenerated instruction printer routines.
printInstruction(MI); printInstruction(MI);
@ -164,6 +164,8 @@ void SystemZAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
if (VerboseAsm && !MI->getDebugLoc().isUnknown()) if (VerboseAsm && !MI->getDebugLoc().isUnknown())
EmitComments(*MI); EmitComments(*MI);
O << '\n'; O << '\n';
processDebugLoc(MI, false);
} }
void SystemZAsmPrinter::printPCRelImmOperand(const MachineInstr *MI, int OpNum){ void SystemZAsmPrinter::printPCRelImmOperand(const MachineInstr *MI, int OpNum){

View File

@ -653,13 +653,15 @@ bool X86AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
void X86AsmPrinter::printMachineInstruction(const MachineInstr *MI) { void X86AsmPrinter::printMachineInstruction(const MachineInstr *MI) {
++EmittedInsts; ++EmittedInsts;
processDebugLoc(MI); processDebugLoc(MI, true);
printInstructionThroughMCStreamer(MI); printInstructionThroughMCStreamer(MI);
if (VerboseAsm && !MI->getDebugLoc().isUnknown()) if (VerboseAsm && !MI->getDebugLoc().isUnknown())
EmitComments(*MI); EmitComments(*MI);
O << '\n'; O << '\n';
processDebugLoc(MI, false);
} }
void X86AsmPrinter::PrintGlobalVariable(const GlobalVariable* GVar) { void X86AsmPrinter::PrintGlobalVariable(const GlobalVariable* GVar) {

View File

@ -481,7 +481,7 @@ void Emitter<CodeEmitter>::emitInstruction(const MachineInstr &MI,
const TargetInstrDesc *Desc) { const TargetInstrDesc *Desc) {
DEBUG(errs() << MI); DEBUG(errs() << MI);
MCE.processDebugLoc(MI.getDebugLoc()); MCE.processDebugLoc(MI.getDebugLoc(), true);
unsigned Opcode = Desc->Opcode; unsigned Opcode = Desc->Opcode;
@ -859,6 +859,8 @@ void Emitter<CodeEmitter>::emitInstruction(const MachineInstr &MI,
#endif #endif
llvm_unreachable(0); llvm_unreachable(0);
} }
MCE.processDebugLoc(MI.getDebugLoc(), false);
} }
// Adapt the Emitter / CodeEmitter interfaces to MCCodeEmitter. // Adapt the Emitter / CodeEmitter interfaces to MCCodeEmitter.

View File

@ -352,7 +352,7 @@ bool XCoreAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
void XCoreAsmPrinter::printMachineInstruction(const MachineInstr *MI) { void XCoreAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
++EmittedInsts; ++EmittedInsts;
processDebugLoc(MI); processDebugLoc(MI, true);
// Check for mov mnemonic // Check for mov mnemonic
unsigned src, dst, srcSR, dstSR; unsigned src, dst, srcSR, dstSR;
@ -365,6 +365,8 @@ void XCoreAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
if (VerboseAsm && !MI->getDebugLoc().isUnknown()) if (VerboseAsm && !MI->getDebugLoc().isUnknown())
EmitComments(*MI); EmitComments(*MI);
O << '\n'; O << '\n';
processDebugLoc(MI, false);
} }
// Force static initialization. // Force static initialization.