mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-14 11:32:34 +00:00
Refactor code that finds context for a given die.
Create global variable DIEs after creating subprogram DIEs. This allows function level static variable's to find their context at the time of DIE creation. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@91055 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
cbd77d2cb1
commit
c366f83d89
@ -738,6 +738,19 @@ void DwarfDebug::addAddress(DIE *Die, unsigned Attribute,
|
||||
addBlock(Die, Attribute, 0, Block);
|
||||
}
|
||||
|
||||
/// addToContextOwner - Add Die into the list of its context owner's children.
|
||||
void DwarfDebug::addToContextOwner(DIE *Die, DIDescriptor Context) {
|
||||
if (Context.isNull())
|
||||
ModuleCU->addDie(Die);
|
||||
else if (Context.isType()) {
|
||||
DIE *ContextDIE = getOrCreateTypeDIE(DIType(Context.getNode()));
|
||||
ContextDIE->addChild(Die);
|
||||
} else if (DIE *ContextDIE = ModuleCU->getDIE(Context.getNode()))
|
||||
ContextDIE->addChild(Die);
|
||||
else
|
||||
ModuleCU->addDie(Die);
|
||||
}
|
||||
|
||||
/// getOrCreateTypeDIE - Find existing DIE or create new DIE for the
|
||||
/// given DIType.
|
||||
DIE *DwarfDebug::getOrCreateTypeDIE(DIType Ty) {
|
||||
@ -757,18 +770,7 @@ DIE *DwarfDebug::getOrCreateTypeDIE(DIType Ty) {
|
||||
constructTypeDIE(*TyDIE, DIDerivedType(Ty.getNode()));
|
||||
}
|
||||
|
||||
DIDescriptor Context = Ty.getContext();
|
||||
if (Context.isNull())
|
||||
// Add this type into the module cu.
|
||||
ModuleCU->addDie(TyDIE);
|
||||
else if (Context.isType()) {
|
||||
DIE *ContextDIE = getOrCreateTypeDIE(DIType(Context.getNode()));
|
||||
ContextDIE->addChild(TyDIE);
|
||||
} else if (DIE *ContextDIE = ModuleCU->getDIE(Context.getNode()))
|
||||
ContextDIE->addChild(TyDIE);
|
||||
else
|
||||
ModuleCU->addDie(TyDIE);
|
||||
|
||||
addToContextOwner(TyDIE, Ty.getContext());
|
||||
return TyDIE;
|
||||
}
|
||||
|
||||
@ -1317,19 +1319,6 @@ DIE *DwarfDebug::updateSubprogramScopeDIE(MDNode *SPNode) {
|
||||
if (!DISubprogram(SPNode).isLocalToUnit())
|
||||
addUInt(SPDie, dwarf::DW_AT_external, dwarf::DW_FORM_flag, 1);
|
||||
|
||||
// If there are global variables at this scope then add their dies.
|
||||
for (SmallVector<WeakVH, 4>::iterator SGI = ScopedGVs.begin(),
|
||||
SGE = ScopedGVs.end(); SGI != SGE; ++SGI) {
|
||||
MDNode *N = dyn_cast_or_null<MDNode>(*SGI);
|
||||
if (!N) continue;
|
||||
DIGlobalVariable GV(N);
|
||||
if (GV.getContext().getNode() == SPNode) {
|
||||
DIE *ScopedGVDie = createGlobalVariableDIE(GV);
|
||||
if (ScopedGVDie)
|
||||
SPDie->addChild(ScopedGVDie);
|
||||
}
|
||||
}
|
||||
|
||||
return SPDie;
|
||||
}
|
||||
|
||||
@ -1648,9 +1637,8 @@ void DwarfDebug::constructGlobalVariableDIE(MDNode *N) {
|
||||
ModuleCU->insertDIE(N, VariableDie);
|
||||
|
||||
// Add to context owner.
|
||||
if (TopLevelDIEs.insert(VariableDie))
|
||||
TopLevelDIEsVector.push_back(VariableDie);
|
||||
|
||||
addToContextOwner(VariableDie, DI_GV.getContext());
|
||||
|
||||
// Expose as global. FIXME - need to check external flag.
|
||||
ModuleCU->addGlobal(DI_GV.getName(), VariableDie);
|
||||
|
||||
@ -1723,21 +1711,16 @@ void DwarfDebug::beginModule(Module *M, MachineModuleInfo *mmi) {
|
||||
if (!ModuleCU)
|
||||
ModuleCU = CompileUnits[0];
|
||||
|
||||
// Create DIEs for each of the externally visible global variables.
|
||||
for (DebugInfoFinder::iterator I = DbgFinder.global_variable_begin(),
|
||||
E = DbgFinder.global_variable_end(); I != E; ++I) {
|
||||
DIGlobalVariable GV(*I);
|
||||
if (GV.getContext().getNode() != GV.getCompileUnit().getNode())
|
||||
ScopedGVs.push_back(*I);
|
||||
else
|
||||
constructGlobalVariableDIE(*I);
|
||||
}
|
||||
|
||||
// Create DIEs for each subprogram.
|
||||
for (DebugInfoFinder::iterator I = DbgFinder.subprogram_begin(),
|
||||
E = DbgFinder.subprogram_end(); I != E; ++I)
|
||||
constructSubprogramDIE(*I);
|
||||
|
||||
// Create DIEs for each global variable.
|
||||
for (DebugInfoFinder::iterator I = DbgFinder.global_variable_begin(),
|
||||
E = DbgFinder.global_variable_end(); I != E; ++I)
|
||||
constructGlobalVariableDIE(*I);
|
||||
|
||||
MMI = mmi;
|
||||
shouldEmit = true;
|
||||
MMI->setDebugInfoAvailability(true);
|
||||
|
@ -163,10 +163,6 @@ class DwarfDebug : public Dwarf {
|
||||
SmallPtrSet<DIE *, 4> TopLevelDIEs;
|
||||
SmallVector<DIE *, 4> TopLevelDIEsVector;
|
||||
|
||||
/// ScopedGVs - Tracks global variables that are not at file scope.
|
||||
/// For example void f() { static int b = 42; }
|
||||
SmallVector<WeakVH, 4> ScopedGVs;
|
||||
|
||||
typedef SmallVector<DbgScope *, 2> ScopeVector;
|
||||
typedef DenseMap<const MachineInstr *, ScopeVector>
|
||||
InsnToDbgScopeMapTy;
|
||||
@ -313,6 +309,9 @@ class DwarfDebug : public Dwarf {
|
||||
void addBlockByrefAddress(DbgVariable *&DV, DIE *Die, unsigned Attribute,
|
||||
const MachineLocation &Location);
|
||||
|
||||
/// addToContextOwner - Add Die into the list of its context owner's children.
|
||||
void addToContextOwner(DIE *Die, DIDescriptor Context);
|
||||
|
||||
/// addType - Add a new type attribute to the specified entity.
|
||||
void addType(DIE *Entity, DIType Ty);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user