[cfe-dev] Design discussion re: DW_TAG_call_site support in clang

Vedant Kumar via cfe-dev cfe-dev at lists.llvm.org
Tue May 19 15:12:43 PDT 2020


(This is a resend; I apologize if you received an earlier mail not posted to the list from a different address)

Hi,

In a recent review (https://reviews.llvm.org/D79967 <https://reviews.llvm.org/D79967>), David Blaikie suggested that we have a broader design discussion about how support for DW_TAG_call_site is supported in clang, so I’ll kick off the discussion.

Some topics to discuss:

1) Under LTO, if we emit a declaration DISubprogram for a function in one TU, and another TU defines the function with __attribute__((nodebug)), would the declaration DISubprogram get attached to the definition?

My own thoughts on this: firstly, as posed in D79967 <https://reviews.llvm.org/D79967>, I think David was asking about the case where the declaration subprogram does not have an attached unit. I’m not sure why it wouldn’t, though, so I’d appreciate some clarification on that. Second, as far as I know, there isn’t a mechanism for attaching a declaration subprogram to a Function which doesn’t have debug info.

2) Should declaration subprograms emitted in support of DW_TAG_call_site be kept in the CU’s retainedTypes field?

David pointed out that these declarations a) persist through optimization and b) don't get deduplicated against the definitions, which means there’s potential to bloat debug info. As an alternative, we might attach a declaration subprogram to the corresponding Function (which we do already), but leave it out of the CU’s retainedTypes field.

My own thoughts: as I understand it, if a function ends up dead (all call sites to it are optimized out), we won’t emit a DW_TAG_call_site that references the function, and so we won't emit unnecessary declaration subprograms. This is demonstrated in the LTO case in llvm/test/DebugInfo/X86/lto-cross-cu-call-origin-ref.ll (added in https://reviews.llvm.org/D70350 <https://reviews.llvm.org/D70350>), where the declaration subprograms for func_from_b, noinline_func_in_a, and always_inline_helper_in_a_that_calls_foo are elided. The same test demonstrates that llvm can emit cross-CU references to definition subprograms within DW_TAG_call_site. However, all of this just pertains to the final DWARF. There may still be some cost (in terms of metadata) to preserving a declaration subprogram throughout optimization when all references to the declaration are removed. Before changing the representation, it’d be helpful to measure how much it costs (either in terms of compile-time, or metadata size) to keep unreferenced declaration subprograms around (say, on a stage2 clang build).

As for why declaration subprograms are inserted into a CU’s retainedTypes field in the first place: I don’t think this was intentionally changed just for DW_TAG_call_site support. Adrian (cc’d) changed EmitFunctionDecl to retain declaration subprograms in r266445, and the new code path which calls into EmitFunctionDecl adopted the same behavior. (Hopefully that clears up some of the history, that’s not to say that it’s not worth revisiting.)

best,
vedant
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20200519/93981354/attachment.html>


More information about the cfe-dev mailing list