Refactor constructImportedEntityDIE(DwarfUnit, DIImportedEntity) to return a DIE rather than inserting it into a specified context.

First of many steps to improve lexical scope construction (to omit
trivial lexical scopes - those without any direct variables). To that
end it's easier not to create imported entities directly into the
lexical scope node, but to build them, then add them if necessary.

llvm-svn: 216838
This commit is contained in:
David Blaikie 2014-08-31 05:32:06 +00:00
parent 1b88632886
commit e0e8a3baa0
2 changed files with 16 additions and 11 deletions

View File

@ -688,22 +688,23 @@ void DwarfDebug::constructImportedEntityDIE(DwarfCompileUnit &TheCU,
DIImportedEntity Module(N); DIImportedEntity Module(N);
assert(Module.Verify()); assert(Module.Verify());
if (DIE *D = TheCU.getOrCreateContextDIE(Module.getContext())) if (DIE *D = TheCU.getOrCreateContextDIE(Module.getContext()))
constructImportedEntityDIE(TheCU, Module, *D); D->addChild(constructImportedEntityDIE(TheCU, Module));
} }
void DwarfDebug::constructImportedEntityDIE(DwarfCompileUnit &TheCU, void DwarfDebug::constructImportedEntityDIE(DwarfCompileUnit &TheCU,
const MDNode *N, DIE &Context) { const MDNode *N, DIE &Context) {
DIImportedEntity Module(N); DIImportedEntity Module(N);
assert(Module.Verify()); assert(Module.Verify());
return constructImportedEntityDIE(TheCU, Module, Context); Context.addChild(constructImportedEntityDIE(TheCU, Module));
} }
void DwarfDebug::constructImportedEntityDIE(DwarfCompileUnit &TheCU, std::unique_ptr<DIE>
const DIImportedEntity &Module, DwarfDebug::constructImportedEntityDIE(DwarfCompileUnit &TheCU,
DIE &Context) { const DIImportedEntity &Module) {
assert(Module.Verify() && assert(Module.Verify() &&
"Use one of the MDNode * overloads to handle invalid metadata"); "Use one of the MDNode * overloads to handle invalid metadata");
DIE &IMDie = TheCU.createAndAddDIE(Module.getTag(), Context, Module); std::unique_ptr<DIE> IMDie = make_unique<DIE>((dwarf::Tag)Module.getTag());
TheCU.insertDIE(Module, IMDie.get());
DIE *EntityDie; DIE *EntityDie;
DIDescriptor Entity = resolve(Module.getEntity()); DIDescriptor Entity = resolve(Module.getEntity());
if (Entity.isNameSpace()) if (Entity.isNameSpace())
@ -714,13 +715,16 @@ void DwarfDebug::constructImportedEntityDIE(DwarfCompileUnit &TheCU,
EntityDie = TheCU.getOrCreateTypeDIE(DIType(Entity)); EntityDie = TheCU.getOrCreateTypeDIE(DIType(Entity));
else else
EntityDie = TheCU.getDIE(Entity); EntityDie = TheCU.getDIE(Entity);
TheCU.addSourceLine(IMDie, Module.getLineNumber(), assert(EntityDie);
TheCU.addSourceLine(*IMDie, Module.getLineNumber(),
Module.getContext().getFilename(), Module.getContext().getFilename(),
Module.getContext().getDirectory()); Module.getContext().getDirectory());
TheCU.addDIEEntry(IMDie, dwarf::DW_AT_import, *EntityDie); TheCU.addDIEEntry(*IMDie, dwarf::DW_AT_import, *EntityDie);
StringRef Name = Module.getName(); StringRef Name = Module.getName();
if (!Name.empty()) if (!Name.empty())
TheCU.addString(IMDie, dwarf::DW_AT_name, Name); TheCU.addString(*IMDie, dwarf::DW_AT_name, Name);
return IMDie;
} }
// Emit all Dwarf sections that should come prior to the content. Create // Emit all Dwarf sections that should come prior to the content. Create

View File

@ -515,8 +515,9 @@ class DwarfDebug : public AsmPrinterHandler {
DIE &Context); DIE &Context);
/// \brief Construct import_module DIE. /// \brief Construct import_module DIE.
void constructImportedEntityDIE(DwarfCompileUnit &TheCU, std::unique_ptr<DIE>
const DIImportedEntity &Module, DIE &Context); constructImportedEntityDIE(DwarfCompileUnit &TheCU,
const DIImportedEntity &Module);
/// \brief Register a source line with debug info. Returns the unique /// \brief Register a source line with debug info. Returns the unique
/// label that was emitted and which provides correspondence to the /// label that was emitted and which provides correspondence to the