From b2b31a6f93f5329c86e41c04ec8c33799d012f9e Mon Sep 17 00:00:00 2001 From: Devang Patel Date: Wed, 26 May 2010 19:37:24 +0000 Subject: [PATCH] Identify instructions, that needs a label to mark debug info entity, in advance. This simplifies beginScope(). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@104720 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 98 +++++++++++++++++---------- lib/CodeGen/AsmPrinter/DwarfDebug.h | 7 ++ 2 files changed, 68 insertions(+), 37 deletions(-) diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index 048268fa7ca..9aee5937dd0 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -2274,50 +2274,38 @@ const MCSymbol *DwarfDebug::getLabelAfterInsn(const MachineInstr *MI) { /// beginScope - Process beginning of a scope. void DwarfDebug::beginScope(const MachineInstr *MI) { + if (InsnNeedsLabel.count(MI) == 0) { + LabelsBeforeInsn[MI] = PrevLabel; + return; + } + // Check location. DebugLoc DL = MI->getDebugLoc(); - if (DL.isUnknown() && !UnknownLocations) { - if (MI->isDebugValue() && PrevLabel) - LabelsBeforeInsn[MI] = PrevLabel; + if (!DL.isUnknown()) { + const MDNode *Scope = DL.getScope(Asm->MF->getFunction()->getContext()); + PrevLabel = recordSourceLine(DL.getLine(), DL.getCol(), Scope); + PrevInstLoc = DL; + LabelsBeforeInsn[MI] = PrevLabel; return; } - - bool LocalVar = false; + + // If location is unknown then Use last known location for this DBG_VALUE + // instruction. if (MI->isDebugValue()) { - assert (MI->getNumOperands() > 1 && "Invalid machine instruction!"); - DIVariable DV(MI->getOperand(MI->getNumOperands() - 1).getMetadata()); - if (!DV.Verify()) return; - if (DV.getTag() != dwarf::DW_TAG_arg_variable - && !isDbgValueInUndefinedReg(MI)) - LocalVar = true; - } - - MCSymbol *Label = NULL; - if (DL == PrevInstLoc) - Label = PrevLabel; - // Do not emit line number entry for arguments. - else if (!MI->isDebugValue() || LocalVar) { - const MDNode *Scope = 0; - if (DL.isUnknown() == false) { - Scope = DL.getScope(Asm->MF->getFunction()->getContext()); - // FIXME: Should only verify each scope once! - if (!DIScope(Scope).Verify()) - return; - } - // else ... - // This instruction has no debug location. If the preceding instruction - // did, emit debug location information to indicate that the debug - // location is now unknown. - - Label = recordSourceLine(DL.getLine(), DL.getCol(), Scope); - PrevInstLoc = DL; - PrevLabel = Label; + const MDNode *Scope = + PrevInstLoc.getScope(Asm->MF->getFunction()->getContext()); + PrevLabel = recordSourceLine(PrevInstLoc.getLine(), PrevInstLoc.getCol(), Scope); + LabelsBeforeInsn[MI] = PrevLabel; + return; + } + + if (UnknownLocations) { + PrevLabel = recordSourceLine(0, 0, 0); + LabelsBeforeInsn[MI] = PrevLabel; + return; } - // If this instruction begins a scope then note down corresponding label - // even if previous label is reused. - if (Label && (InsnsBeginScopeSet.count(MI) != 0 || MI->isDebugValue())) - LabelsBeforeInsn[MI] = Label; + assert (0 && "Instruction is not processed!"); } /// endScope - Process end of a scope. @@ -2627,6 +2615,40 @@ void DwarfDebug::beginFunction(const MachineFunction *MF) { } recordSourceLine(Line, Col, Scope); + + DebugLoc PrevLoc; + for (MachineFunction::const_iterator I = MF->begin(), E = MF->end(); + I != E; ++I) + for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end(); + II != IE; ++II) { + const MachineInstr *MI = II; + DebugLoc DL = MI->getDebugLoc(); + if (MI->isDebugValue()) { + // DBG_VALUE needs a label if the variable is local variable or + // an argument whose location is changing. + assert (MI->getNumOperands() > 1 && "Invalid machine instruction!"); + DIVariable DV(MI->getOperand(MI->getNumOperands() - 1).getMetadata()); + if (!DV.Verify()) continue; + if (DV.getTag() != dwarf::DW_TAG_arg_variable) + InsnNeedsLabel.insert(MI); + else if (!ProcessedArgs.insert(DV)) + InsnNeedsLabel.insert(MI); + } else { + // If location is unknown then instruction needs a location only if + // UnknownLocations flag is set. + if (DL.isUnknown()) { + if (UnknownLocations && !PrevLoc.isUnknown()) + InsnNeedsLabel.insert(MI); + } else if (DL != PrevLoc) + // Otherwise, instruction needs a location only if it is new location. + InsnNeedsLabel.insert(MI); + } + + if (!DL.isUnknown() || UnknownLocations) + PrevLoc = DL; + } + + PrevLabel = FunctionBeginSym; } /// endFunction - Gather and emit post-function debug information. @@ -2673,6 +2695,8 @@ void DwarfDebug::endFunction(const MachineFunction *MF) { // Clear debug info CurrentFnDbgScope = NULL; + InsnNeedsLabel.clear(); + ProcessedArgs.clear(); DbgVariableToFrameIndexMap.clear(); VarToAbstractVarMap.clear(); DbgVariableToDbgInstMap.clear(); diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.h b/lib/CodeGen/AsmPrinter/DwarfDebug.h index 5d2294918e6..0d6116fc986 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.h +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.h @@ -227,6 +227,13 @@ class DwarfDebug { /// instruction. DenseMap LabelsAfterInsn; + /// insnNeedsLabel - Collection of instructions that need a label to mark + /// a debuggging information entity. + SmallPtrSet InsnNeedsLabel; + + /// ProcessedArgs - Collection of arguments already processed. + SmallPtrSet ProcessedArgs; + SmallVector DebugRangeSymbols; /// Previous instruction's location information. This is used to determine -- 2.34.1