Update processDebugLoc() so that it can be used to process debug info before and...
authorDevang Patel <dpatel@apple.com>
Tue, 6 Oct 2009 02:19:11 +0000 (02:19 +0000)
committerDevang Patel <dpatel@apple.com>
Tue, 6 Oct 2009 02:19:11 +0000 (02:19 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@83363 91177308-0d34-0410-b5e6-96231b3b80d8

19 files changed:
include/llvm/CodeGen/AsmPrinter.h
include/llvm/CodeGen/MachineCodeEmitter.h
lib/CodeGen/AsmPrinter/AsmPrinter.cpp
lib/Target/ARM/ARMCodeEmitter.cpp
lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp
lib/Target/Alpha/AlphaCodeEmitter.cpp
lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp
lib/Target/Blackfin/AsmPrinter/BlackfinAsmPrinter.cpp
lib/Target/CellSPU/AsmPrinter/SPUAsmPrinter.cpp
lib/Target/MSP430/AsmPrinter/MSP430AsmPrinter.cpp
lib/Target/Mips/AsmPrinter/MipsAsmPrinter.cpp
lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp
lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp
lib/Target/PowerPC/PPCCodeEmitter.cpp
lib/Target/Sparc/AsmPrinter/SparcAsmPrinter.cpp
lib/Target/SystemZ/AsmPrinter/SystemZAsmPrinter.cpp
lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp
lib/Target/X86/X86CodeEmitter.cpp
lib/Target/XCore/AsmPrinter/XCoreAsmPrinter.cpp

index 2f0e8d05417ca88efa4a94a77fde52f5fb97cd37..62d0679fb738790f139f4799ae11ef38086e951c 100644 (file)
@@ -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.
index 707b020f9573c4e647c0b1e708ee6e175310d09a..abb6dd9cd087f3b91bf1e76fd51796bde0617d2c 100644 (file)
@@ -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;
index 500693971c353a11270275a7f5851afdc75745e9..00f398083f1d701d04bf9a3a17d1743298656fc2 100644 (file)
@@ -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;
index 0f682e2535e6c9cb35161ebfbb714acdd0378b85..6f1c624cbf524b9dd78779dd8cfc2d1164e50536 100644 (file)
@@ -346,7 +346,7 @@ template<class CodeEmitter>
 void Emitter<CodeEmitter>::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<CodeEmitter>::emitInstruction(const MachineInstr &MI) {
     emitMiscInstruction(MI);
     break;
   }
+  MCE.processDebugLoc(MI.getDebugLoc(), false);
 }
 
 template<class CodeEmitter>
index a441993d1b11651d603cba413042c701fd7360ac..cb241dc1b4550906293a4dd013e4434a61382209 100644 (file)
@@ -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) {
index ac90e4627e23039df5017f0d04be5d264ab6cf0c..8023add97914215293e16f28a96a4befabcba26d 100644 (file)
@@ -116,7 +116,7 @@ void Emitter<CodeEmitter>::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<CodeEmitter>::emitBasicBlock(MachineBasicBlock &MBB) {
     case TargetInstrInfo::KILL:
       break; //skip these
     }
+    MCE.processDebugLoc(MI.getDebugLoc(), false);
   }
 }
 
index aed3b9a7898547bd0d4039d8694b272a4e76433c..fd4a99a0640768314fc60e97e9b44ba03c7d5554 100644 (file)
@@ -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);
     }
   }
 
index 1bb7678ec8f36f1268ec15a28573f93a3b756b2d..9807fd25be29005c08f0b9eecfa3ded3eee992c1 100644 (file)
@@ -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;
     }
   }
index 02809aff5bef95cf1419b627dce2ab0ecc2fb77e..c334e509ce540ef156d6a912a9f2cb047769851b 100644 (file)
@@ -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';
 }
 
index 7dbd5ab483a03479332a355fdb8ec51dd9dea03d..b6d268d5f7a559fdf5c20193fc342e5b7f97bb1f 100644 (file)
@@ -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,
index fd6d13eb3a304e3e647e38db91d5fe9057e9f434..2159555849a0583401ac36155a574b73e5d2d2c3 100644 (file)
@@ -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;
     }
 
index a74ad661bc4784c125a8cc3e46fd702422455d3d..60ad2c7f8f9b5a7e6e3852f3e1553615f635879e 100644 (file)
@@ -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;
 }
 
index 750cec93b6bcd4c0b3ef2cb279a6d9c9b920f5c7..8ac93050071eae9f252e12d720474f4d5d1eed08 100644 (file)
@@ -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()
index 16d55a3ccdb30cb1279f45d2f875b2c9d208e740..0675293e1144d2af238c6fcc9be5dc116a45c6ac 100644 (file)
@@ -132,7 +132,7 @@ void Emitter<CodeEmitter>::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<CodeEmitter>::emitBasicBlock(MachineBasicBlock &MBB) {
       MCE.emitWordBE(0x48000005);   // bl 1
       break;
     }
+    MCE.processDebugLoc(MI.getDebugLoc(), false);
   }
 }
 
index 04e5b69c35416d5350a44c8d18aa49a57c058644..bf479a4c1b08b8185dd9a9958a915a3a8d2f4210 100644 (file)
@@ -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;
     }
   }
index 5ba964940596c4b1d9a922376a0d9eb47debf6f2..89d365cef14ccf96f0d5bf590dddc65f0fb4d196 100644 (file)
@@ -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){
index 4f89b716c12fd8d5cfdfe12ff959b1188a96dd50..f75359454faa5df58a243579560e15aefb8208dd 100644 (file)
@@ -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) {
index 4c12edd2a010e0a56976b6023a9020984021fa11..6527dd70d925ce700f866f883b02276caee63fc6 100644 (file)
@@ -481,7 +481,7 @@ void Emitter<CodeEmitter>::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<CodeEmitter>::emitInstruction(const MachineInstr &MI,
 #endif
     llvm_unreachable(0);
   }
+
+  MCE.processDebugLoc(MI.getDebugLoc(), false);
 }
 
 // Adapt the Emitter / CodeEmitter interfaces to MCCodeEmitter.
index 4f17f2f9ff1178e5df161dc31753bb8c3d3a5341..a4b1d114b7d054c7736cfd95ce1da0c22d83a269 100644 (file)
@@ -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.