This is an archive of the discontinued LLVM Phabricator instance.

[DwarfCompileUnit] Set parent DIE right after creating a local entity

Authored by krisb on Nov 22 2021, 12:45 AM.



No functional changes intended.

Before this patch DwarfCompileUnit::createScopeChildrenDIE() and
DwarfCompileUnit::createAndAddScopeChildrenDIE() used to emit child subtrees
and then when all the children get created, attach them to a parent scope DIE.
However, when a DIE doesn't have a parent, all the requests for its unit DIE

Currently, it is not a big issue since it isn't usually needed to know unit DIE
for a local (function-scoped) entity. But once we introduce lexical blocks as
a valid scope for global variables (static locals) and type DIEs, any requests
for a unit DIE need to be guarded against local scope due to the potential
absence of the DIE's parent.

To avoid the aforementioned issue, this patch refactors a few DwarfCompileUnit
methods to support the idea of attaching a DIE to its parent as close to the
creation of this DIE as possible.

Diff Detail

Event Timeline

krisb created this revision.Nov 22 2021, 12:45 AM
krisb requested review of this revision.Nov 22 2021, 12:45 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 22 2021, 12:45 AM
krisb updated this revision to Diff 388809.Nov 22 2021, 12:52 AM

Remove unused 'Children' vector.

ellis accepted this revision.Nov 22 2021, 10:17 AM



A better name would be createInlinedScopeDIE(), but constructInlinedScopeDIE() already exists. Should we merge these two functions together? Or maybe we can rename the second to createInlinedSubprogramDIE().

This revision is now accepted and ready to land.Nov 22 2021, 10:17 AM
krisb updated this revision to Diff 388995.Nov 22 2021, 12:32 PM
krisb marked 2 inline comments as done.

Applied comments.


Mmm, I'm not sure it needs renaming. The message in the assert looks a bit confusing, but this function still handles both inlined subprograms and all sorts of lexical block scopes.