Refactor code to push DILocation prcessing into DwarfDebug.cpp from AsmPrinter.cpp.

This is same as r99772 (which was reverted) with just one meaningful difference where two source lines exchanged their positions.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@99816 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Devang Patel
2010-03-29 17:20:31 +00:00
parent f283e40b6a
commit 553881bddc
6 changed files with 55 additions and 50 deletions

View File

@ -47,7 +47,6 @@ namespace llvm {
class MCSection; class MCSection;
class MCStreamer; class MCStreamer;
class MCSymbol; class MCSymbol;
class MDNode;
class DwarfWriter; class DwarfWriter;
class Mangler; class Mangler;
class MCAsmInfo; class MCAsmInfo;
@ -138,9 +137,6 @@ namespace llvm {
mutable unsigned Counter; mutable unsigned Counter;
mutable unsigned SetCounter; mutable unsigned SetCounter;
// Private state for processDebugLoc()
mutable const MDNode *PrevDLT;
protected: protected:
explicit AsmPrinter(formatted_raw_ostream &o, TargetMachine &TM, explicit AsmPrinter(formatted_raw_ostream &o, TargetMachine &TM,
MCStreamer &Streamer); MCStreamer &Streamer);

View File

@ -83,19 +83,11 @@ public:
/// ///
void EndFunction(const MachineFunction *MF); 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 /// ShouldEmitDwarfDebug - Returns true if Dwarf debugging declarations should
/// be emitted. /// be emitted.
bool ShouldEmitDwarfDebug() const; bool ShouldEmitDwarfDebug() const;
void BeginScope(const MachineInstr *MI, MCSymbol *Label); void BeginScope(const MachineInstr *MI);
void EndScope(const MachineInstr *MI); void EndScope(const MachineInstr *MI);
}; };

View File

@ -62,7 +62,7 @@ AsmPrinter::AsmPrinter(formatted_raw_ostream &o, TargetMachine &tm,
TM(tm), MAI(tm.getMCAsmInfo()), TRI(tm.getRegisterInfo()), TM(tm), MAI(tm.getMCAsmInfo()), TRI(tm.getRegisterInfo()),
OutContext(Streamer.getContext()), OutContext(Streamer.getContext()),
OutStreamer(Streamer), OutStreamer(Streamer),
LastMI(0), LastFn(0), Counter(~0U), SetCounter(0), PrevDLT(NULL) { LastMI(0), LastFn(0), Counter(~0U), SetCounter(0) {
DW = 0; MMI = 0; DW = 0; MMI = 0;
VerboseAsm = Streamer.isVerboseAsm(); VerboseAsm = Streamer.isVerboseAsm();
} }
@ -1337,25 +1337,12 @@ void AsmPrinter::processDebugLoc(const MachineInstr *MI,
if (!MAI || !DW || !MAI->doesSupportDebugInformation() if (!MAI || !DW || !MAI->doesSupportDebugInformation()
|| !DW->ShouldEmitDwarfDebug()) || !DW->ShouldEmitDwarfDebug())
return; 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 // After printing instruction
DW->EndScope(MI); DW->EndScope(MI);
} else if (CurDLT.getNode() != PrevDLT) { else
MCSymbol *L = DW->RecordSourceLine(CurDLT.getLineNumber(), DW->BeginScope(MI);
CurDLT.getColumnNumber(),
CurDLT.getScope().getNode());
DW->BeginScope(MI, L);
PrevDLT = CurDLT.getNode();
}
} }

View File

@ -296,7 +296,7 @@ DwarfDebug::DwarfDebug(raw_ostream &OS, AsmPrinter *A, const MCAsmInfo *T)
: DwarfPrinter(OS, A, T), ModuleCU(0), : DwarfPrinter(OS, A, T), ModuleCU(0),
AbbreviationsSet(InitAbbreviationsSetSize), Abbreviations(), AbbreviationsSet(InitAbbreviationsSetSize), Abbreviations(),
DIEValues(), SectionSourceLines(), didInitial(false), shouldEmit(false), DIEValues(), SectionSourceLines(), didInitial(false), shouldEmit(false),
CurrentFnDbgScope(0), DebugTimer(0) { CurrentFnDbgScope(0), PrevDILoc(0), DebugTimer(0) {
NextStringPoolNumber = 0; NextStringPoolNumber = 0;
if (TimePassesIsEnabled) if (TimePassesIsEnabled)
DebugTimer = new Timer("Dwarf Debug Writer"); DebugTimer = new Timer("Dwarf Debug Writer");
@ -2036,19 +2036,58 @@ void DwarfDebug::collectVariableInfo() {
} }
} }
/// beginScope - Process beginning of a scope starting at Label. /// beginScope - Process beginning of a scope.
void DwarfDebug::beginScope(const MachineInstr *MI, MCSymbol *Label) { void DwarfDebug::beginScope(const MachineInstr *MI) {
// Ignore DBG_VALUE instructions.
if (MI->getOpcode() == TargetOpcode::DBG_VALUE)
return;
// Check location.
DebugLoc DL = MI->getDebugLoc();
if (DL.isUnknown())
return;
DILocation DILoc = MF->getDILocation(DL);
if (!DILoc.getScope().Verify())
return;
// Check and update last known location info.
if(DILoc.getNode() == PrevDILoc)
return;
PrevDILoc = DILoc.getNode();
// Emit a label to indicate location change. This is used for line
// table even if this instruction does start a new scope.
MCSymbol *Label = recordSourceLine(DILoc.getLineNumber(),
DILoc.getColumnNumber(),
DILoc.getScope().getNode());
// update DbgScope if this instruction starts a new scope.
InsnToDbgScopeMapTy::iterator I = DbgScopeBeginMap.find(MI); InsnToDbgScopeMapTy::iterator I = DbgScopeBeginMap.find(MI);
if (I == DbgScopeBeginMap.end()) if (I == DbgScopeBeginMap.end())
return; return;
ScopeVector &SD = I->second; ScopeVector &SD = I->second;
for (ScopeVector::iterator SDI = SD.begin(), SDE = SD.end(); for (ScopeVector::iterator SDI = SD.begin(), SDE = SD.end();
SDI != SDE; ++SDI) SDI != SDE; ++SDI)
(*SDI)->setStartLabel(Label); (*SDI)->setStartLabel(Label);
} }
/// endScope - Process end of a scope. /// endScope - Process end of a scope.
void DwarfDebug::endScope(const MachineInstr *MI) { void DwarfDebug::endScope(const MachineInstr *MI) {
// Ignore DBG_VALUE instruction.
if (MI->getOpcode() == TargetOpcode::DBG_VALUE)
return;
// Check location.
DebugLoc DL = MI->getDebugLoc();
if (DL.isUnknown())
return;
DILocation DILoc = MF->getDILocation(DL);
if (!DILoc.getScope().Verify())
return;
// Emit a label and update DbgScope if this instruction ends a scope.
InsnToDbgScopeMapTy::iterator I = DbgScopeEndMap.find(MI); InsnToDbgScopeMapTy::iterator I = DbgScopeEndMap.find(MI);
if (I == DbgScopeEndMap.end()) if (I == DbgScopeEndMap.end())
return; return;

View File

@ -184,6 +184,10 @@ class DwarfDebug : public DwarfPrinter {
/// function. /// function.
DenseMap<CompileUnit *, unsigned> CompileUnitOffsets; DenseMap<CompileUnit *, unsigned> 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. /// DebugTimer - Timer for the Dwarf debug writer.
Timer *DebugTimer; Timer *DebugTimer;
@ -542,8 +546,8 @@ public:
/// collectVariableInfo - Populate DbgScope entries with variables' info. /// collectVariableInfo - Populate DbgScope entries with variables' info.
void collectVariableInfo(); void collectVariableInfo();
/// beginScope - Process beginning of a scope starting at Label. /// beginScope - Process beginning of a scope.
void beginScope(const MachineInstr *MI, MCSymbol *Label); void beginScope(const MachineInstr *MI);
/// endScope - Prcess end of a scope. /// endScope - Prcess end of a scope.
void endScope(const MachineInstr *MI); void endScope(const MachineInstr *MI);

View File

@ -73,27 +73,14 @@ void DwarfWriter::EndFunction(const MachineFunction *MF) {
MMI->EndFunction(); 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 /// ShouldEmitDwarfDebug - Returns true if Dwarf debugging declarations should
/// be emitted. /// be emitted.
bool DwarfWriter::ShouldEmitDwarfDebug() const { bool DwarfWriter::ShouldEmitDwarfDebug() const {
return DD && DD->ShouldEmitDwarfDebug(); return DD && DD->ShouldEmitDwarfDebug();
} }
void DwarfWriter::BeginScope(const MachineInstr *MI, MCSymbol *L) { void DwarfWriter::BeginScope(const MachineInstr *MI) {
DD->beginScope(MI, L); DD->beginScope(MI);
} }
void DwarfWriter::EndScope(const MachineInstr *MI) { void DwarfWriter::EndScope(const MachineInstr *MI) {
DD->endScope(MI); DD->endScope(MI);