From 051454a16f1db9c4081baa786ab7b724be00bb30 Mon Sep 17 00:00:00 2001 From: Devang Patel Date: Tue, 6 Oct 2009 02:19:11 +0000 Subject: [PATCH] Update processDebugLoc() so that it can be used to process debug info before and after printing an instruction. llvm-svn: 83363 --- llvm/include/llvm/CodeGen/AsmPrinter.h | 6 +++--- llvm/include/llvm/CodeGen/MachineCodeEmitter.h | 2 +- llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 14 ++++++++------ llvm/lib/Target/ARM/ARMCodeEmitter.cpp | 3 ++- llvm/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp | 3 ++- llvm/lib/Target/Alpha/AlphaCodeEmitter.cpp | 3 ++- .../Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp | 4 ++-- .../Blackfin/AsmPrinter/BlackfinAsmPrinter.cpp | 3 ++- .../Target/CellSPU/AsmPrinter/SPUAsmPrinter.cpp | 4 ++-- .../Target/MSP430/AsmPrinter/MSP430AsmPrinter.cpp | 4 +++- llvm/lib/Target/Mips/AsmPrinter/MipsAsmPrinter.cpp | 5 +++-- .../Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp | 5 ++--- .../Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp | 4 +++- llvm/lib/Target/PowerPC/PPCCodeEmitter.cpp | 3 ++- .../Target/Sparc/AsmPrinter/SparcAsmPrinter.cpp | 4 ++-- .../SystemZ/AsmPrinter/SystemZAsmPrinter.cpp | 4 +++- llvm/lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp | 4 +++- llvm/lib/Target/X86/X86CodeEmitter.cpp | 4 +++- .../Target/XCore/AsmPrinter/XCoreAsmPrinter.cpp | 4 +++- 19 files changed, 51 insertions(+), 32 deletions(-) diff --git a/llvm/include/llvm/CodeGen/AsmPrinter.h b/llvm/include/llvm/CodeGen/AsmPrinter.h index 2f0e8d05417c..62d0679fb738 100644 --- a/llvm/include/llvm/CodeGen/AsmPrinter.h +++ b/llvm/include/llvm/CodeGen/AsmPrinter.h @@ -141,7 +141,7 @@ namespace llvm { mutable const Function *LastFn; mutable unsigned Counter; - // Private state for processDebugLock() + // Private state for processDebugLoc() mutable DebugLocTuple PrevDLT; protected: @@ -357,8 +357,8 @@ namespace llvm { virtual void EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV); /// processDebugLoc - Processes the debug information of each machine - /// instruction's DebugLoc. - void processDebugLoc(const MachineInstr *MI); + /// instruction's DebugLoc. + void processDebugLoc(const MachineInstr *MI, bool BeforePrintingInsn); /// printInlineAsm - This method formats and prints the specified machine /// instruction that is an inline asm. diff --git a/llvm/include/llvm/CodeGen/MachineCodeEmitter.h b/llvm/include/llvm/CodeGen/MachineCodeEmitter.h index 707b020f9573..abb6dd9cd087 100644 --- a/llvm/include/llvm/CodeGen/MachineCodeEmitter.h +++ b/llvm/include/llvm/CodeGen/MachineCodeEmitter.h @@ -237,7 +237,7 @@ public: /// MachineInstruction. This is called before emitting any bytes associated /// with the instruction. Even if successive instructions have the same debug /// 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 virtual void emitLabel(uint64_t LabelID) = 0; diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 500693971c35..00f398083f1d 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -1353,18 +1353,20 @@ void AsmPrinter::PrintSpecial(const MachineInstr *MI, const char *Code) const { /// processDebugLoc - Processes the debug information of each machine /// instruction's DebugLoc. -void AsmPrinter::processDebugLoc(const MachineInstr *MI) { +void AsmPrinter::processDebugLoc(const MachineInstr *MI, + bool BeforePrintingInsn) { if (!MAI || !DW) return; DebugLoc DL = MI->getDebugLoc(); if (MAI->doesSupportDebugInformation() && DW->ShouldEmitDwarfDebug()) { if (!DL.isUnknown()) { DebugLocTuple CurDLT = MF->getDebugLocTuple(DL); - - if (CurDLT.CompileUnit != 0 && PrevDLT != CurDLT) { - printLabel(DW->RecordSourceLine(CurDLT.Line, CurDLT.Col, - CurDLT.CompileUnit)); - O << '\n'; + if (BeforePrintingInsn) { + if (CurDLT.CompileUnit != 0 && PrevDLT != CurDLT) { + printLabel(DW->RecordSourceLine(CurDLT.Line, CurDLT.Col, + CurDLT.CompileUnit)); + O << '\n'; + } } PrevDLT = CurDLT; diff --git a/llvm/lib/Target/ARM/ARMCodeEmitter.cpp b/llvm/lib/Target/ARM/ARMCodeEmitter.cpp index 0f682e2535e6..6f1c624cbf52 100644 --- a/llvm/lib/Target/ARM/ARMCodeEmitter.cpp +++ b/llvm/lib/Target/ARM/ARMCodeEmitter.cpp @@ -346,7 +346,7 @@ template void Emitter::emitInstruction(const MachineInstr &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 switch (MI.getDesc().TSFlags & ARMII::FormMask) { @@ -409,6 +409,7 @@ void Emitter::emitInstruction(const MachineInstr &MI) { emitMiscInstruction(MI); break; } + MCE.processDebugLoc(MI.getDebugLoc(), false); } template diff --git a/llvm/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp b/llvm/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp index a441993d1b11..cb241dc1b455 100644 --- a/llvm/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp +++ b/llvm/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp @@ -1038,11 +1038,12 @@ void ARMAsmPrinter::printMachineInstruction(const MachineInstr *MI) { }} // Call the autogenerated instruction printer routines. - processDebugLoc(MI); + processDebugLoc(MI, true); printInstruction(MI); if (VerboseAsm && !MI->getDebugLoc().isUnknown()) EmitComments(*MI); O << '\n'; + processDebugLoc(MI, false); } void ARMAsmPrinter::EmitStartOfAsmFile(Module &M) { diff --git a/llvm/lib/Target/Alpha/AlphaCodeEmitter.cpp b/llvm/lib/Target/Alpha/AlphaCodeEmitter.cpp index ac90e4627e23..8023add97914 100644 --- a/llvm/lib/Target/Alpha/AlphaCodeEmitter.cpp +++ b/llvm/lib/Target/Alpha/AlphaCodeEmitter.cpp @@ -116,7 +116,7 @@ void Emitter::emitBasicBlock(MachineBasicBlock &MBB) { for (MachineBasicBlock::iterator I = MBB.begin(), E = MBB.end(); I != E; ++I) { const MachineInstr &MI = *I; - MCE.processDebugLoc(MI.getDebugLoc()); + MCE.processDebugLoc(MI.getDebugLoc(), true); switch(MI.getOpcode()) { default: MCE.emitWordLE(getBinaryCodeForInstr(*I)); @@ -128,6 +128,7 @@ void Emitter::emitBasicBlock(MachineBasicBlock &MBB) { case TargetInstrInfo::KILL: break; //skip these } + MCE.processDebugLoc(MI.getDebugLoc(), false); } } diff --git a/llvm/lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp b/llvm/lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp index aed3b9a78985..fd4a99a06407 100644 --- a/llvm/lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp +++ b/llvm/lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp @@ -177,13 +177,13 @@ bool AlphaAsmPrinter::runOnMachineFunction(MachineFunction &MF) { II != E; ++II) { // Print the assembly for the instruction. ++EmittedInsts; - processDebugLoc(II); - + processDebugLoc(II, true); printInstruction(II); if (VerboseAsm && !II->getDebugLoc().isUnknown()) EmitComments(*II); O << '\n'; + processDebugLoc(II, false); } } diff --git a/llvm/lib/Target/Blackfin/AsmPrinter/BlackfinAsmPrinter.cpp b/llvm/lib/Target/Blackfin/AsmPrinter/BlackfinAsmPrinter.cpp index 1bb7678ec8f3..9807fd25be29 100644 --- a/llvm/lib/Target/Blackfin/AsmPrinter/BlackfinAsmPrinter.cpp +++ b/llvm/lib/Target/Blackfin/AsmPrinter/BlackfinAsmPrinter.cpp @@ -146,13 +146,14 @@ bool BlackfinAsmPrinter::runOnMachineFunction(MachineFunction &MF) { for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end(); II != E; ++II) { // Print the assembly for the instruction. - processDebugLoc(II); + processDebugLoc(II, true); printInstruction(II); if (VerboseAsm && !II->getDebugLoc().isUnknown()) EmitComments(*II); O << '\n'; + processDebugLoc(II, false); ++EmittedInsts; } } diff --git a/llvm/lib/Target/CellSPU/AsmPrinter/SPUAsmPrinter.cpp b/llvm/lib/Target/CellSPU/AsmPrinter/SPUAsmPrinter.cpp index 02809aff5bef..c334e509ce54 100644 --- a/llvm/lib/Target/CellSPU/AsmPrinter/SPUAsmPrinter.cpp +++ b/llvm/lib/Target/CellSPU/AsmPrinter/SPUAsmPrinter.cpp @@ -405,11 +405,11 @@ bool SPUAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, /// void SPUAsmPrinter::printMachineInstruction(const MachineInstr *MI) { ++EmittedInsts; - processDebugLoc(MI); + processDebugLoc(MI, true); printInstruction(MI); - if (VerboseAsm && !MI->getDebugLoc().isUnknown()) EmitComments(*MI); + processDebugLoc(MI, false); O << '\n'; } diff --git a/llvm/lib/Target/MSP430/AsmPrinter/MSP430AsmPrinter.cpp b/llvm/lib/Target/MSP430/AsmPrinter/MSP430AsmPrinter.cpp index 7dbd5ab483a0..b6d268d5f7a5 100644 --- a/llvm/lib/Target/MSP430/AsmPrinter/MSP430AsmPrinter.cpp +++ b/llvm/lib/Target/MSP430/AsmPrinter/MSP430AsmPrinter.cpp @@ -148,7 +148,7 @@ bool MSP430AsmPrinter::runOnMachineFunction(MachineFunction &MF) { void MSP430AsmPrinter::printMachineInstruction(const MachineInstr *MI) { ++EmittedInsts; - processDebugLoc(MI); + processDebugLoc(MI, true); // Call the autogenerated instruction printer routines. printInstruction(MI); @@ -156,6 +156,8 @@ void MSP430AsmPrinter::printMachineInstruction(const MachineInstr *MI) { if (VerboseAsm && !MI->getDebugLoc().isUnknown()) EmitComments(*MI); O << '\n'; + + processDebugLoc(MI, false); } void MSP430AsmPrinter::printOperand(const MachineInstr *MI, int OpNum, diff --git a/llvm/lib/Target/Mips/AsmPrinter/MipsAsmPrinter.cpp b/llvm/lib/Target/Mips/AsmPrinter/MipsAsmPrinter.cpp index fd6d13eb3a30..2159555849a0 100644 --- a/llvm/lib/Target/Mips/AsmPrinter/MipsAsmPrinter.cpp +++ b/llvm/lib/Target/Mips/AsmPrinter/MipsAsmPrinter.cpp @@ -278,7 +278,7 @@ bool MipsAsmPrinter::runOnMachineFunction(MachineFunction &MF) { for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end(); II != E; ++II) { - processDebugLoc(II); + processDebugLoc(II, true); // Print the assembly for the instruction. printInstruction(II); @@ -286,7 +286,8 @@ bool MipsAsmPrinter::runOnMachineFunction(MachineFunction &MF) { if (VerboseAsm && !II->getDebugLoc().isUnknown()) EmitComments(*II); O << '\n'; - + + processDebugLoc(II, false); ++EmittedInsts; } diff --git a/llvm/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp b/llvm/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp index a74ad661bc47..60ad2c7f8f9b 100644 --- a/llvm/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp +++ b/llvm/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp @@ -43,13 +43,12 @@ PIC16AsmPrinter::PIC16AsmPrinter(formatted_raw_ostream &O, TargetMachine &TM, } bool PIC16AsmPrinter::printMachineInstruction(const MachineInstr *MI) { - processDebugLoc(MI); - + processDebugLoc(MI, true); printInstruction(MI); - if (VerboseAsm && !MI->getDebugLoc().isUnknown()) EmitComments(*MI); O << '\n'; + processDebugLoc(MI, false); return true; } diff --git a/llvm/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp b/llvm/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp index 750cec93b6bc..8ac93050071e 100644 --- a/llvm/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp +++ b/llvm/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp @@ -545,7 +545,7 @@ void PPCAsmPrinter::printPredicateOperand(const MachineInstr *MI, unsigned OpNo, void PPCAsmPrinter::printMachineInstruction(const MachineInstr *MI) { ++EmittedInsts; - processDebugLoc(MI); + processDebugLoc(MI, true); // Check for slwi/srwi mnemonics. if (MI->getOpcode() == PPC::RLWINM) { @@ -595,6 +595,8 @@ void PPCAsmPrinter::printMachineInstruction(const MachineInstr *MI) { if (VerboseAsm && !MI->getDebugLoc().isUnknown()) EmitComments(*MI); O << '\n'; + + processDebugLoc(MI, false); } /// runOnMachineFunction - This uses the printMachineInstruction() diff --git a/llvm/lib/Target/PowerPC/PPCCodeEmitter.cpp b/llvm/lib/Target/PowerPC/PPCCodeEmitter.cpp index 16d55a3ccdb3..0675293e1144 100644 --- a/llvm/lib/Target/PowerPC/PPCCodeEmitter.cpp +++ b/llvm/lib/Target/PowerPC/PPCCodeEmitter.cpp @@ -132,7 +132,7 @@ void Emitter::emitBasicBlock(MachineBasicBlock &MBB) { for (MachineBasicBlock::iterator I = MBB.begin(), E = MBB.end(); I != E; ++I){ const MachineInstr &MI = *I; - MCE.processDebugLoc(MI.getDebugLoc()); + MCE.processDebugLoc(MI.getDebugLoc(), true); switch (MI.getOpcode()) { default: MCE.emitWordBE(getBinaryCodeForInstr(MI)); @@ -151,6 +151,7 @@ void Emitter::emitBasicBlock(MachineBasicBlock &MBB) { MCE.emitWordBE(0x48000005); // bl 1 break; } + MCE.processDebugLoc(MI.getDebugLoc(), false); } } diff --git a/llvm/lib/Target/Sparc/AsmPrinter/SparcAsmPrinter.cpp b/llvm/lib/Target/Sparc/AsmPrinter/SparcAsmPrinter.cpp index 04e5b69c3541..bf479a4c1b08 100644 --- a/llvm/lib/Target/Sparc/AsmPrinter/SparcAsmPrinter.cpp +++ b/llvm/lib/Target/Sparc/AsmPrinter/SparcAsmPrinter.cpp @@ -124,13 +124,13 @@ bool SparcAsmPrinter::runOnMachineFunction(MachineFunction &MF) { for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end(); II != E; ++II) { // Print the assembly for the instruction. - processDebugLoc(II); + processDebugLoc(II, true); printInstruction(II); if (VerboseAsm && !II->getDebugLoc().isUnknown()) EmitComments(*II); O << '\n'; - + processDebugLoc(II, false); ++EmittedInsts; } } diff --git a/llvm/lib/Target/SystemZ/AsmPrinter/SystemZAsmPrinter.cpp b/llvm/lib/Target/SystemZ/AsmPrinter/SystemZAsmPrinter.cpp index 5ba964940596..89d365cef14c 100644 --- a/llvm/lib/Target/SystemZ/AsmPrinter/SystemZAsmPrinter.cpp +++ b/llvm/lib/Target/SystemZ/AsmPrinter/SystemZAsmPrinter.cpp @@ -156,7 +156,7 @@ bool SystemZAsmPrinter::runOnMachineFunction(MachineFunction &MF) { void SystemZAsmPrinter::printMachineInstruction(const MachineInstr *MI) { ++EmittedInsts; - processDebugLoc(MI); + processDebugLoc(MI, true); // Call the autogenerated instruction printer routines. printInstruction(MI); @@ -164,6 +164,8 @@ void SystemZAsmPrinter::printMachineInstruction(const MachineInstr *MI) { if (VerboseAsm && !MI->getDebugLoc().isUnknown()) EmitComments(*MI); O << '\n'; + + processDebugLoc(MI, false); } void SystemZAsmPrinter::printPCRelImmOperand(const MachineInstr *MI, int OpNum){ diff --git a/llvm/lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp b/llvm/lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp index 4f89b716c12f..f75359454faa 100644 --- a/llvm/lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp +++ b/llvm/lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp @@ -653,13 +653,15 @@ bool X86AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, void X86AsmPrinter::printMachineInstruction(const MachineInstr *MI) { ++EmittedInsts; - processDebugLoc(MI); + processDebugLoc(MI, true); printInstructionThroughMCStreamer(MI); if (VerboseAsm && !MI->getDebugLoc().isUnknown()) EmitComments(*MI); O << '\n'; + + processDebugLoc(MI, false); } void X86AsmPrinter::PrintGlobalVariable(const GlobalVariable* GVar) { diff --git a/llvm/lib/Target/X86/X86CodeEmitter.cpp b/llvm/lib/Target/X86/X86CodeEmitter.cpp index 4c12edd2a010..6527dd70d925 100644 --- a/llvm/lib/Target/X86/X86CodeEmitter.cpp +++ b/llvm/lib/Target/X86/X86CodeEmitter.cpp @@ -481,7 +481,7 @@ void Emitter::emitInstruction(const MachineInstr &MI, const TargetInstrDesc *Desc) { DEBUG(errs() << MI); - MCE.processDebugLoc(MI.getDebugLoc()); + MCE.processDebugLoc(MI.getDebugLoc(), true); unsigned Opcode = Desc->Opcode; @@ -859,6 +859,8 @@ void Emitter::emitInstruction(const MachineInstr &MI, #endif llvm_unreachable(0); } + + MCE.processDebugLoc(MI.getDebugLoc(), false); } // Adapt the Emitter / CodeEmitter interfaces to MCCodeEmitter. diff --git a/llvm/lib/Target/XCore/AsmPrinter/XCoreAsmPrinter.cpp b/llvm/lib/Target/XCore/AsmPrinter/XCoreAsmPrinter.cpp index 4f17f2f9ff11..a4b1d114b7d0 100644 --- a/llvm/lib/Target/XCore/AsmPrinter/XCoreAsmPrinter.cpp +++ b/llvm/lib/Target/XCore/AsmPrinter/XCoreAsmPrinter.cpp @@ -352,7 +352,7 @@ bool XCoreAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, void XCoreAsmPrinter::printMachineInstruction(const MachineInstr *MI) { ++EmittedInsts; - processDebugLoc(MI); + processDebugLoc(MI, true); // Check for mov mnemonic unsigned src, dst, srcSR, dstSR; @@ -365,6 +365,8 @@ void XCoreAsmPrinter::printMachineInstruction(const MachineInstr *MI) { if (VerboseAsm && !MI->getDebugLoc().isUnknown()) EmitComments(*MI); O << '\n'; + + processDebugLoc(MI, false); } // Force static initialization.