Simplify and delay extracting DebugLoc elements, scope and InlinedAt, as much as possible.

llvm-svn: 135124
This commit is contained in:
Devang Patel 2011-07-14 01:14:57 +00:00
parent d6300d2956
commit 07d61edc30
4 changed files with 34 additions and 19 deletions

View File

@ -61,7 +61,10 @@ namespace llvm {
/// getFromDILocation - Translate the DILocation quad into a DebugLoc. /// getFromDILocation - Translate the DILocation quad into a DebugLoc.
static DebugLoc getFromDILocation(MDNode *N); static DebugLoc getFromDILocation(MDNode *N);
/// getFromDILexicalBlock - Translate the DILexicalBlock into a DebugLoc.
static DebugLoc getFromDILexicalBlock(MDNode *N);
/// isUnknown - Return true if this is an unknown location. /// isUnknown - Return true if this is an unknown location.
bool isUnknown() const { return ScopeIdx == 0; } bool isUnknown() const { return ScopeIdx == 0; }

View File

@ -1566,8 +1566,11 @@ void DwarfDebug::endInstruction(const MachineInstr *MI) {
} }
/// getOrCreateDbgScope - Create DbgScope for the scope. /// getOrCreateDbgScope - Create DbgScope for the scope.
DbgScope *DwarfDebug::getOrCreateDbgScope(const MDNode *Scope, DbgScope *DwarfDebug::getOrCreateDbgScope(DebugLoc DL, LLVMContext &Ctx) {
const MDNode *InlinedAt) { MDNode *Scope = NULL;
MDNode *InlinedAt = NULL;
DL.getScopeAndInlinedAt(Scope, InlinedAt, Ctx);
if (!InlinedAt) { if (!InlinedAt) {
DbgScope *WScope = DbgScopeMap.lookup(Scope); DbgScope *WScope = DbgScopeMap.lookup(Scope);
if (WScope) if (WScope)
@ -1576,7 +1579,7 @@ DbgScope *DwarfDebug::getOrCreateDbgScope(const MDNode *Scope,
DbgScopeMap.insert(std::make_pair(Scope, WScope)); DbgScopeMap.insert(std::make_pair(Scope, WScope));
if (DIDescriptor(Scope).isLexicalBlock()) { if (DIDescriptor(Scope).isLexicalBlock()) {
DbgScope *Parent = DbgScope *Parent =
getOrCreateDbgScope(DILexicalBlock(Scope).getContext(), NULL); getOrCreateDbgScope(DebugLoc::getFromDILexicalBlock(Scope), Ctx);
WScope->setParent(Parent); WScope->setParent(Parent);
Parent->addScope(WScope); Parent->addScope(WScope);
} }
@ -1603,9 +1606,8 @@ DbgScope *DwarfDebug::getOrCreateDbgScope(const MDNode *Scope,
WScope = new DbgScope(NULL, DIDescriptor(Scope), InlinedAt); WScope = new DbgScope(NULL, DIDescriptor(Scope), InlinedAt);
DbgScopeMap.insert(std::make_pair(InlinedAt, WScope)); DbgScopeMap.insert(std::make_pair(InlinedAt, WScope));
DILocation DL(InlinedAt);
DbgScope *Parent = DbgScope *Parent =
getOrCreateDbgScope(DL.getScope(), DL.getOrigLocation()); getOrCreateDbgScope(DebugLoc::getFromDILocation(InlinedAt), Ctx);
WScope->setParent(Parent); WScope->setParent(Parent);
Parent->addScope(WScope); Parent->addScope(WScope);
@ -1693,8 +1695,7 @@ bool DwarfDebug::extractScopeInformation() {
LLVMContext &Ctx = Asm->MF->getFunction()->getContext(); LLVMContext &Ctx = Asm->MF->getFunction()->getContext();
SmallVector<DbgRange, 4> MIRanges; SmallVector<DbgRange, 4> MIRanges;
DenseMap<const MachineInstr *, DbgScope *> MI2ScopeMap; DenseMap<const MachineInstr *, DbgScope *> MI2ScopeMap;
const MDNode *PrevScope = NULL; DebugLoc PrevDL;
const MDNode *PrevInlinedAt = NULL;
const MachineInstr *RangeBeginMI = NULL; const MachineInstr *RangeBeginMI = NULL;
const MachineInstr *PrevMI = NULL; const MachineInstr *PrevMI = NULL;
for (MachineFunction::const_iterator I = Asm->MF->begin(), E = Asm->MF->end(); for (MachineFunction::const_iterator I = Asm->MF->begin(), E = Asm->MF->end();
@ -1702,8 +1703,6 @@ bool DwarfDebug::extractScopeInformation() {
for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end(); for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end();
II != IE; ++II) { II != IE; ++II) {
const MachineInstr *MInsn = II; const MachineInstr *MInsn = II;
MDNode *Scope = NULL;
MDNode *InlinedAt = NULL;
// Check if instruction has valid location information. // Check if instruction has valid location information.
const DebugLoc MIDL = MInsn->getDebugLoc(); const DebugLoc MIDL = MInsn->getDebugLoc();
@ -1711,10 +1710,9 @@ bool DwarfDebug::extractScopeInformation() {
PrevMI = MInsn; PrevMI = MInsn;
continue; continue;
} }
MIDL.getScopeAndInlinedAt(Scope, InlinedAt, Ctx);
// If scope has not changed then skip this instruction. // If scope has not changed then skip this instruction.
if (Scope == PrevScope && PrevInlinedAt == InlinedAt) { if (MIDL == PrevDL) {
PrevMI = MInsn; PrevMI = MInsn;
continue; continue;
} }
@ -1733,8 +1731,7 @@ bool DwarfDebug::extractScopeInformation() {
DEBUG(dbgs() << "Next Range starting at " << *MInsn); DEBUG(dbgs() << "Next Range starting at " << *MInsn);
DEBUG(dbgs() << "------------------------\n"); DEBUG(dbgs() << "------------------------\n");
DbgRange R(RangeBeginMI, PrevMI); DbgRange R(RangeBeginMI, PrevMI);
MI2ScopeMap[RangeBeginMI] = getOrCreateDbgScope(PrevScope, MI2ScopeMap[RangeBeginMI] = getOrCreateDbgScope(PrevDL, Ctx);
PrevInlinedAt);
MIRanges.push_back(R); MIRanges.push_back(R);
} }
@ -1743,16 +1740,15 @@ bool DwarfDebug::extractScopeInformation() {
// Reset previous markers. // Reset previous markers.
PrevMI = MInsn; PrevMI = MInsn;
PrevScope = Scope; PrevDL = MIDL;
PrevInlinedAt = InlinedAt;
} }
} }
// Create last instruction range. // Create last instruction range.
if (RangeBeginMI && PrevMI && PrevScope) { if (RangeBeginMI && PrevMI && !PrevDL.isUnknown()) {
DbgRange R(RangeBeginMI, PrevMI); DbgRange R(RangeBeginMI, PrevMI);
MIRanges.push_back(R); MIRanges.push_back(R);
MI2ScopeMap[RangeBeginMI] = getOrCreateDbgScope(PrevScope, PrevInlinedAt); MI2ScopeMap[RangeBeginMI] = getOrCreateDbgScope(PrevDL, Ctx);
} }
if (!CurrentFnDbgScope) if (!CurrentFnDbgScope)

View File

@ -319,7 +319,7 @@ private:
void assignAbbrevNumber(DIEAbbrev &Abbrev); void assignAbbrevNumber(DIEAbbrev &Abbrev);
/// getOrCreateDbgScope - Create DbgScope for the scope. /// getOrCreateDbgScope - Create DbgScope for the scope.
DbgScope *getOrCreateDbgScope(const MDNode *Scope, const MDNode *InlinedAt); DbgScope *getOrCreateDbgScope(DebugLoc DL, LLVMContext &Ctx);
DbgScope *getOrCreateAbstractScope(const MDNode *N); DbgScope *getOrCreateAbstractScope(const MDNode *N);

View File

@ -128,6 +128,22 @@ DebugLoc DebugLoc::getFromDILocation(MDNode *N) {
return get(LineNo, ColNo, Scope, dyn_cast_or_null<MDNode>(N->getOperand(3))); return get(LineNo, ColNo, Scope, dyn_cast_or_null<MDNode>(N->getOperand(3)));
} }
/// getFromDILexicalBlock - Translate the DILexicalBlock into a DebugLoc.
DebugLoc DebugLoc::getFromDILexicalBlock(MDNode *N) {
if (N == 0 || N->getNumOperands() < 3) return DebugLoc();
MDNode *Scope = dyn_cast_or_null<MDNode>(N->getOperand(1));
if (Scope == 0) return DebugLoc();
unsigned LineNo = 0, ColNo = 0;
if (ConstantInt *Line = dyn_cast_or_null<ConstantInt>(N->getOperand(2)))
LineNo = Line->getZExtValue();
if (ConstantInt *Col = dyn_cast_or_null<ConstantInt>(N->getOperand(3)))
ColNo = Col->getZExtValue();
return get(LineNo, ColNo, Scope, NULL);
}
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// DenseMap specialization // DenseMap specialization
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//