One instruction may start (or end) multiple lexical scopes.

There is no need to remember labels identifying regions marked by such instructions in each scope.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@100781 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Devang Patel
2010-04-08 16:50:29 +00:00
parent fcf0f082f4
commit 1c246358a0
2 changed files with 28 additions and 58 deletions

View File

@ -192,8 +192,6 @@ class DbgScope {
// Location at which this scope is inlined. // Location at which this scope is inlined.
AssertingVH<MDNode> InlinedAtLocation; AssertingVH<MDNode> InlinedAtLocation;
bool AbstractScope; // Abstract Scope bool AbstractScope; // Abstract Scope
MCSymbol *StartLabel; // Label ID of the beginning of scope.
MCSymbol *EndLabel; // Label ID of the end of scope.
const MachineInstr *LastInsn; // Last instruction of this scope. const MachineInstr *LastInsn; // Last instruction of this scope.
const MachineInstr *FirstInsn; // First instruction of this scope. const MachineInstr *FirstInsn; // First instruction of this scope.
// Scopes defined in scope. Contents not owned. // Scopes defined in scope. Contents not owned.
@ -206,7 +204,6 @@ class DbgScope {
public: public:
DbgScope(DbgScope *P, DIDescriptor D, MDNode *I = 0) DbgScope(DbgScope *P, DIDescriptor D, MDNode *I = 0)
: Parent(P), Desc(D), InlinedAtLocation(I), AbstractScope(false), : Parent(P), Desc(D), InlinedAtLocation(I), AbstractScope(false),
StartLabel(0), EndLabel(0),
LastInsn(0), FirstInsn(0), IndentLevel(0) {} LastInsn(0), FirstInsn(0), IndentLevel(0) {}
virtual ~DbgScope(); virtual ~DbgScope();
@ -216,12 +213,8 @@ public:
DIDescriptor getDesc() const { return Desc; } DIDescriptor getDesc() const { return Desc; }
MDNode *getInlinedAt() const { return InlinedAtLocation; } MDNode *getInlinedAt() const { return InlinedAtLocation; }
MDNode *getScopeNode() const { return Desc.getNode(); } MDNode *getScopeNode() const { return Desc.getNode(); }
MCSymbol *getStartLabel() const { return StartLabel; }
MCSymbol *getEndLabel() const { return EndLabel; }
const SmallVector<DbgScope *, 4> &getScopes() { return Scopes; } const SmallVector<DbgScope *, 4> &getScopes() { return Scopes; }
const SmallVector<DbgVariable *, 8> &getVariables() { return Variables; } const SmallVector<DbgVariable *, 8> &getVariables() { return Variables; }
void setStartLabel(MCSymbol *S) { StartLabel = S; }
void setEndLabel(MCSymbol *E) { EndLabel = E; }
void setLastInsn(const MachineInstr *MI) { LastInsn = MI; } void setLastInsn(const MachineInstr *MI) { LastInsn = MI; }
const MachineInstr *getLastInsn() { return LastInsn; } const MachineInstr *getLastInsn() { return LastInsn; }
void setFirstInsn(const MachineInstr *MI) { FirstInsn = MI; } void setFirstInsn(const MachineInstr *MI) { FirstInsn = MI; }
@ -287,7 +280,6 @@ void DbgScope::dump() const {
err.indent(IndentLevel); err.indent(IndentLevel);
MDNode *N = Desc.getNode(); MDNode *N = Desc.getNode();
N->dump(); N->dump();
err << " [" << StartLabel << ", " << EndLabel << "]\n";
if (AbstractScope) if (AbstractScope)
err << "Abstract Scope\n"; err << "Abstract Scope\n";
@ -1406,8 +1398,9 @@ DIE *DwarfDebug::updateSubprogramScopeDIE(MDNode *SPNode) {
/// constructLexicalScope - Construct new DW_TAG_lexical_block /// constructLexicalScope - Construct new DW_TAG_lexical_block
/// for this scope and attach DW_AT_low_pc/DW_AT_high_pc labels. /// for this scope and attach DW_AT_low_pc/DW_AT_high_pc labels.
DIE *DwarfDebug::constructLexicalScopeDIE(DbgScope *Scope) { DIE *DwarfDebug::constructLexicalScopeDIE(DbgScope *Scope) {
MCSymbol *Start = Scope->getStartLabel();
MCSymbol *End = Scope->getEndLabel(); MCSymbol *Start = InsnBeforeLabelMap.lookup(Scope->getFirstInsn());
MCSymbol *End = InsnAfterLabelMap.lookup(Scope->getLastInsn());
if (Start == 0 || End == 0) return 0; if (Start == 0 || End == 0) return 0;
assert(Start->isDefined() && "Invalid starting label for an inlined scope!"); assert(Start->isDefined() && "Invalid starting label for an inlined scope!");
@ -1430,8 +1423,8 @@ DIE *DwarfDebug::constructLexicalScopeDIE(DbgScope *Scope) {
/// a function. Construct DIE to represent this concrete inlined copy /// a function. Construct DIE to represent this concrete inlined copy
/// of the function. /// of the function.
DIE *DwarfDebug::constructInlinedScopeDIE(DbgScope *Scope) { DIE *DwarfDebug::constructInlinedScopeDIE(DbgScope *Scope) {
MCSymbol *StartLabel = Scope->getStartLabel(); MCSymbol *StartLabel = InsnBeforeLabelMap.lookup(Scope->getFirstInsn());
MCSymbol *EndLabel = Scope->getEndLabel(); MCSymbol *EndLabel = InsnAfterLabelMap.lookup(Scope->getLastInsn());
if (StartLabel == 0 || EndLabel == 0) return 0; if (StartLabel == 0 || EndLabel == 0) return 0;
assert(StartLabel->isDefined() && assert(StartLabel->isDefined() &&
@ -2137,15 +2130,9 @@ void DwarfDebug::beginScope(const MachineInstr *MI) {
MCSymbol *Label = recordSourceLine(DL.getLine(), DL.getCol(), Scope); MCSymbol *Label = recordSourceLine(DL.getLine(), DL.getCol(), Scope);
PrevInstLoc = DL; PrevInstLoc = DL;
// update DbgScope if this instruction starts a new scope. // If this instruction begins a scope then note down corresponding label.
InsnToDbgScopeMapTy::iterator I = DbgScopeBeginMap.find(MI); if (InsnsBeginScopeSet.count(MI) != 0)
if (I == DbgScopeBeginMap.end()) InsnBeforeLabelMap[MI] = Label;
return;
ScopeVector &SD = I->second;
for (ScopeVector::iterator SDI = SD.begin(), SDE = SD.end();
SDI != SDE; ++SDI)
(*SDI)->setStartLabel(Label);
} }
/// endScope - Process end of a scope. /// endScope - Process end of a scope.
@ -2159,19 +2146,12 @@ void DwarfDebug::endScope(const MachineInstr *MI) {
if (DL.isUnknown()) if (DL.isUnknown())
return; return;
// Emit a label and update DbgScope if this instruction ends a scope. if (InsnsEndScopeSet.count(MI) != 0) {
InsnToDbgScopeMapTy::iterator I = DbgScopeEndMap.find(MI); // Emit a label if this instruction ends a scope.
if (I == DbgScopeEndMap.end())
return;
MCSymbol *Label = MMI->getContext().CreateTempSymbol(); MCSymbol *Label = MMI->getContext().CreateTempSymbol();
Asm->OutStreamer.EmitLabel(Label); Asm->OutStreamer.EmitLabel(Label);
InsnAfterLabelMap[MI] = Label;
SmallVector<DbgScope*, 2> &SD = I->second; }
for (SmallVector<DbgScope *, 2>::iterator SDI = SD.begin(), SDE = SD.end();
SDI != SDE; ++SDI)
(*SDI)->setEndLabel(Label);
return;
} }
/// createDbgScope - Create DbgScope for the scope. /// createDbgScope - Create DbgScope for the scope.
@ -2288,22 +2268,11 @@ void DwarfDebug::populateDbgScopeInverseMaps() {
if (S->isAbstractScope()) if (S->isAbstractScope())
continue; continue;
const MachineInstr *MI = S->getFirstInsn(); assert(S->getFirstInsn() && "DbgScope does not have first instruction!");
assert(MI && "DbgScope does not have first instruction!"); InsnsBeginScopeSet.insert(S->getFirstInsn());
InsnToDbgScopeMapTy::iterator IDI = DbgScopeBeginMap.find(MI); assert(S->getLastInsn() && "DbgScope does not have last instruction!");
if (IDI != DbgScopeBeginMap.end()) InsnsEndScopeSet.insert(S->getLastInsn());
IDI->second.push_back(S);
else
DbgScopeBeginMap[MI].push_back(S);
MI = S->getLastInsn();
assert(MI && "DbgScope does not have last instruction!");
IDI = DbgScopeEndMap.find(MI);
if (IDI != DbgScopeEndMap.end())
IDI->second.push_back(S);
else
DbgScopeEndMap[MI].push_back(S);
} }
} }
@ -2374,8 +2343,6 @@ void DwarfDebug::endFunction(const MachineFunction *MF) {
// Clear debug info // Clear debug info
CurrentFnDbgScope = NULL; CurrentFnDbgScope = NULL;
DeleteContainerSeconds(DbgScopeMap); DeleteContainerSeconds(DbgScopeMap);
DbgScopeBeginMap.clear();
DbgScopeEndMap.clear();
DbgValueStartMap.clear(); DbgValueStartMap.clear();
ConcreteScopes.clear(); ConcreteScopes.clear();
DeleteContainerSeconds(AbstractScopes); DeleteContainerSeconds(AbstractScopes);

View File

@ -179,14 +179,9 @@ class DwarfDebug {
SmallPtrSet<DIE *, 4> AbstractSubprogramDIEs; SmallPtrSet<DIE *, 4> AbstractSubprogramDIEs;
typedef SmallVector<DbgScope *, 2> ScopeVector; typedef SmallVector<DbgScope *, 2> ScopeVector;
typedef DenseMap<const MachineInstr *, ScopeVector>
InsnToDbgScopeMapTy;
/// DbgScopeBeginMap - Maps instruction with a list of DbgScopes it starts. SmallPtrSet<const MachineInstr *, 8> InsnsBeginScopeSet;
InsnToDbgScopeMapTy DbgScopeBeginMap; SmallPtrSet<const MachineInstr *, 8> InsnsEndScopeSet;
/// DbgScopeEndMap - Maps instruction with a list DbgScopes it ends.
InsnToDbgScopeMapTy DbgScopeEndMap;
/// InlineInfo - Keep track of inlined functions and their location. This /// InlineInfo - Keep track of inlined functions and their location. This
/// information is used to populate debug_inlined section. /// information is used to populate debug_inlined section.
@ -194,6 +189,14 @@ class DwarfDebug {
DenseMap<MDNode*, SmallVector<InlineInfoLabels, 4> > InlineInfo; DenseMap<MDNode*, SmallVector<InlineInfoLabels, 4> > InlineInfo;
SmallVector<MDNode *, 4> InlinedSPNodes; SmallVector<MDNode *, 4> InlinedSPNodes;
/// InsnBeforeLabelMap - Maps instruction with label emitted before
/// instruction.
DenseMap<const MachineInstr *, MCSymbol *> InsnBeforeLabelMap;
/// InsnAfterLabelMap - Maps instruction with label emitted after
/// instruction.
DenseMap<const MachineInstr *, MCSymbol *> InsnAfterLabelMap;
/// CompileUnitOffsets - A vector of the offsets of the compile units. This is /// CompileUnitOffsets - A vector of the offsets of the compile units. This is
/// used when calculating the "origin" of a concrete instance of an inlined /// used when calculating the "origin" of a concrete instance of an inlined
/// function. /// function.