This is an archive of the discontinued LLVM Phabricator instance.

[DebugInfo] Add localDecls field to DISubprogram and DILexicalBlock (1/5)
AbandonedPublic

Authored by krisb on May 16 2022, 7:55 AM.

Details

Summary

localDecls is intended to track static locals, function- (or lexical-block-) local types (plus typedefs, enums and unions) and imported entities.
Main motivation for adding new field for DISubprogram and DILexicalBlock is to implement more accurate handling for function-local declarations (types, imports and static locals) and support lexical block scopes for them (see D125693).

Thus static locals, function-local enums and imported entities are no longer go to compile unit's 'globals', 'enums' and 'imports'.
But if '-debug-info-kind' is specified as 'unused-types', function-local type-like entities will be referenced by CUs 'retainedTypes'.

This patch just adds localDecls field, corresponding clang/backend changes are in next patches.

Diff Detail

Event Timeline

krisb created this revision.May 16 2022, 7:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 16 2022, 7:55 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
krisb requested review of this revision.May 16 2022, 7:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 16 2022, 7:55 AM
ormris removed a subscriber: ormris.May 16 2022, 11:08 AM
krisb edited the summary of this revision. (Show Details)May 23 2022, 3:15 AM
krisb updated this revision to Diff 431320.May 23 2022, 3:35 AM

Fix comment.

krisb retitled this revision from [DebugInfo][WIP] Add localDecls field to DISubprogram and DILexicalBlock (1/5) to [DebugInfo] Add localDecls field to DISubprogram and DILexicalBlock (1/5).Jun 13 2022, 2:30 AM

Do you need to add any special handling to CloneFunction.cpp or will it work correctly?

krisb added a comment.Jun 14 2022, 2:45 AM

Do you need to add any special handling to CloneFunction.cpp or will it work correctly?

It will work correctly.
D125693 has a test case that checks that a function with 2 local 'global' variables gets properly cloned.

There is a corner case, though. It doesn't directly relate to this patch, but still needs to be mentioned. If to clone a function with other functions inlined into it within the same module, DISubprograms of the inlined functions will not be cloned. But DILexicalBlocks in scopes of such inlined functions will be duplicated which may cause problems later in AsmPrinter. D127102 proposes to skip cloning DILexicalBlocks if their parent DISubprogram was not cloned.

krisb abandoned this revision.Jul 25 2022, 12:44 AM

Tracking function-local entities per-scope is good from optimization point (we may remove DILexicalBlock if there are no instruction left in it), but it makes handling abstract trees in AsmPrinter difficult.
We want to create an abstract scope if it is a parent scope for any of tracked nodes (this is true for local variables/labels as well as for other local entities). Since there are no easy ways to find which DILexicalBlocks belong to a particular subprogram, I'm not sure this approach is profitable.

So, I give up on this and switch the implementation to per-subprogram field. See D125693 for details.