From c7eae5ca4a5c9fd760ec3c38e1e46cd9fda113aa Mon Sep 17 00:00:00 2001 From: Devang Patel Date: Sun, 28 Mar 2010 18:57:09 +0000 Subject: [PATCH] Refactoring. Push DILocation processing in to DwarfDebug from AsmPrinter. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@99772 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/AsmPrinter.h | 4 ---- include/llvm/CodeGen/DwarfWriter.h | 10 +--------- lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 21 ++++---------------- lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 36 +++++++++++++++++++++++++++++++--- lib/CodeGen/AsmPrinter/DwarfDebug.h | 8 ++++++-- lib/CodeGen/AsmPrinter/DwarfWriter.cpp | 17 ++-------------- 6 files changed, 46 insertions(+), 50 deletions(-) diff --git a/include/llvm/CodeGen/AsmPrinter.h b/include/llvm/CodeGen/AsmPrinter.h index 2cd477e8065..ffeb44da7bc 100644 --- a/include/llvm/CodeGen/AsmPrinter.h +++ b/include/llvm/CodeGen/AsmPrinter.h @@ -47,7 +47,6 @@ namespace llvm { class MCSection; class MCStreamer; class MCSymbol; - class MDNode; class DwarfWriter; class Mangler; class MCAsmInfo; @@ -138,9 +137,6 @@ namespace llvm { mutable unsigned Counter; mutable unsigned SetCounter; - // Private state for processDebugLoc() - mutable const MDNode *PrevDLT; - protected: explicit AsmPrinter(formatted_raw_ostream &o, TargetMachine &TM, MCStreamer &Streamer); diff --git a/include/llvm/CodeGen/DwarfWriter.h b/include/llvm/CodeGen/DwarfWriter.h index 3c7f8024d9c..494400ee2c9 100644 --- a/include/llvm/CodeGen/DwarfWriter.h +++ b/include/llvm/CodeGen/DwarfWriter.h @@ -83,19 +83,11 @@ public: /// void EndFunction(const MachineFunction *MF); - /// RecordSourceLine - Register a source line with debug info. Returns the - /// unique label that was emitted and which provides correspondence to - /// the source line list. - MCSymbol *RecordSourceLine(unsigned Line, unsigned Col, MDNode *Scope); - - /// getRecordSourceLineCount - Count source lines. - unsigned getRecordSourceLineCount(); - /// ShouldEmitDwarfDebug - Returns true if Dwarf debugging declarations should /// be emitted. bool ShouldEmitDwarfDebug() const; - void BeginScope(const MachineInstr *MI, MCSymbol *Label); + void BeginScope(const MachineInstr *MI); void EndScope(const MachineInstr *MI); }; diff --git a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 1d4f7f7ae68..7601199488e 100644 --- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -62,7 +62,7 @@ AsmPrinter::AsmPrinter(formatted_raw_ostream &o, TargetMachine &tm, TM(tm), MAI(tm.getMCAsmInfo()), TRI(tm.getRegisterInfo()), OutContext(Streamer.getContext()), OutStreamer(Streamer), - LastMI(0), LastFn(0), Counter(~0U), SetCounter(0), PrevDLT(NULL) { + LastMI(0), LastFn(0), Counter(~0U), SetCounter(0) { DW = 0; MMI = 0; VerboseAsm = Streamer.isVerboseAsm(); } @@ -1337,25 +1337,12 @@ void AsmPrinter::processDebugLoc(const MachineInstr *MI, if (!MAI || !DW || !MAI->doesSupportDebugInformation() || !DW->ShouldEmitDwarfDebug()) return; - if (MI->getOpcode() == TargetOpcode::DBG_VALUE) - return; - DebugLoc DL = MI->getDebugLoc(); - if (DL.isUnknown()) - return; - DILocation CurDLT = MF->getDILocation(DL); - if (!CurDLT.getScope().Verify()) - return; - if (!BeforePrintingInsn) { + if (!BeforePrintingInsn) // After printing instruction DW->EndScope(MI); - } else if (CurDLT.getNode() != PrevDLT) { - MCSymbol *L = DW->RecordSourceLine(CurDLT.getLineNumber(), - CurDLT.getColumnNumber(), - CurDLT.getScope().getNode()); - DW->BeginScope(MI, L); - PrevDLT = CurDLT.getNode(); - } + else + DW->BeginScope(MI); } diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index e2421eb0702..8861699f4bb 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -296,7 +296,7 @@ DwarfDebug::DwarfDebug(raw_ostream &OS, AsmPrinter *A, const MCAsmInfo *T) : DwarfPrinter(OS, A, T), ModuleCU(0), AbbreviationsSet(InitAbbreviationsSetSize), Abbreviations(), DIEValues(), SectionSourceLines(), didInitial(false), shouldEmit(false), - CurrentFnDbgScope(0), DebugTimer(0) { + CurrentFnDbgScope(0), PrevDILoc(0), DebugTimer(0) { NextStringPoolNumber = 0; if (TimePassesIsEnabled) DebugTimer = new Timer("Dwarf Debug Writer"); @@ -2036,19 +2036,49 @@ void DwarfDebug::collectVariableInfo() { } } -/// beginScope - Process beginning of a scope starting at Label. -void DwarfDebug::beginScope(const MachineInstr *MI, MCSymbol *Label) { +/// beginScope - Process beginning of a scope. +void DwarfDebug::beginScope(const MachineInstr *MI) { + if (MI->getOpcode() == TargetOpcode::DBG_VALUE) + return; + + DebugLoc DL = MI->getDebugLoc(); + if (DL.isUnknown()) + return; + DILocation DILoc = MF->getDILocation(DL); + if (!DILoc.getScope().Verify()) + return; + + if(DILoc.getNode() == PrevDILoc) + return; + InsnToDbgScopeMapTy::iterator I = DbgScopeBeginMap.find(MI); if (I == DbgScopeBeginMap.end()) return; + + MCSymbol *Label = recordSourceLine(DILoc.getLineNumber(), + DILoc.getColumnNumber(), + DILoc.getScope().getNode()); + ScopeVector &SD = I->second; for (ScopeVector::iterator SDI = SD.begin(), SDE = SD.end(); SDI != SDE; ++SDI) (*SDI)->setStartLabel(Label); + + PrevDILoc = DILoc.getNode(); } /// endScope - Process end of a scope. void DwarfDebug::endScope(const MachineInstr *MI) { + if (MI->getOpcode() == TargetOpcode::DBG_VALUE) + return; + + DebugLoc DL = MI->getDebugLoc(); + if (DL.isUnknown()) + return; + DILocation DILoc = MF->getDILocation(DL); + if (!DILoc.getScope().Verify()) + return; + InsnToDbgScopeMapTy::iterator I = DbgScopeEndMap.find(MI); if (I == DbgScopeEndMap.end()) return; diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.h b/lib/CodeGen/AsmPrinter/DwarfDebug.h index d173f322b68..4a29091128a 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.h +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.h @@ -184,6 +184,10 @@ class DwarfDebug : public DwarfPrinter { /// function. DenseMap CompileUnitOffsets; + /// Previous instruction's location information. This is used to determine + /// label location to indicate scope boundries in dwarf debug info. + mutable const MDNode *PrevDILoc; + /// DebugTimer - Timer for the Dwarf debug writer. Timer *DebugTimer; @@ -542,8 +546,8 @@ public: /// collectVariableInfo - Populate DbgScope entries with variables' info. void collectVariableInfo(); - /// beginScope - Process beginning of a scope starting at Label. - void beginScope(const MachineInstr *MI, MCSymbol *Label); + /// beginScope - Process beginning of a scope. + void beginScope(const MachineInstr *MI); /// endScope - Prcess end of a scope. void endScope(const MachineInstr *MI); diff --git a/lib/CodeGen/AsmPrinter/DwarfWriter.cpp b/lib/CodeGen/AsmPrinter/DwarfWriter.cpp index 9fd4c447854..a2d7ab1224e 100644 --- a/lib/CodeGen/AsmPrinter/DwarfWriter.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfWriter.cpp @@ -73,27 +73,14 @@ void DwarfWriter::EndFunction(const MachineFunction *MF) { MMI->EndFunction(); } -/// RecordSourceLine - Register a source line with debug info. Returns the -/// unique label that was emitted and which provides correspondence to -/// the source line list. -MCSymbol *DwarfWriter::RecordSourceLine(unsigned Line, unsigned Col, - MDNode *Scope) { - return DD->recordSourceLine(Line, Col, Scope); -} - -/// getRecordSourceLineCount - Count source lines. -unsigned DwarfWriter::getRecordSourceLineCount() { - return DD->getSourceLineCount(); -} - /// ShouldEmitDwarfDebug - Returns true if Dwarf debugging declarations should /// be emitted. bool DwarfWriter::ShouldEmitDwarfDebug() const { return DD && DD->ShouldEmitDwarfDebug(); } -void DwarfWriter::BeginScope(const MachineInstr *MI, MCSymbol *L) { - DD->beginScope(MI, L); +void DwarfWriter::BeginScope(const MachineInstr *MI) { + DD->beginScope(MI); } void DwarfWriter::EndScope(const MachineInstr *MI) { DD->endScope(MI); -- 2.11.0