This is an archive of the discontinued LLVM Phabricator instance.

Implementation of -fextend-lifetimes and -fextend-this-ptr to aid with debugging of optimized code
Needs ReviewPublic

Authored by wolfgangp on Dec 8 2017, 5:27 PM.
This revision needs review, but there are no reviewers specified.

Details

Reviewers
None
Summary

The patch implements the clang support for generating artificial uses of local variables and parameters to aid with debugging of optimized code. I presented this concept in my lightning talk "Debugging of optimized code: Extending the lifetime of local variables" at the October 2017 LLVM conference.

Since the concept is not universally supported, the purpose of this review is to make the patch available to interested parties and perhaps to restart the discussion.

This patch requires the patch posted in https://reviews.llvm.org/D41043 (the llvm portion).

The implementation generates calls to the llvm intrinsic fake.use in similar fashion as end of lifetime markers.

Diff Detail

Event Timeline

wolfgangp created this revision.Dec 8 2017, 5:27 PM

A quick note on usage: Compile your source with "clang -O2 -g -c -fextend-lifetimes foo.cpp" to see the effects (or use -fextend-this-ptr if you just want to extend the lifetime of 'this').

This might be something we want to turn on automatically for -Og.

vsk added a subscriber: vsk.

Thanks for your patches @wolfgangp! I agree with Eli that we should evaluate enabling this automatically with -Og. I'll test this out on a few internal projects and report back.

I should note we've had at least one request to make this specifiable per-function, which would mean defining an attribute to control the emission of the fake-use intrinsics. Doing the feature that way would be consistent with 'optnone'.

vsk added a comment.Dec 20 2017, 3:08 PM

I have some results from the development build of our kernel ('-O2 -g -flto'). According to dwarfdump -statistics, when compiled with -fextend-lifetimes, the percentage of covered scope bytes increases from 62% to 69%. The number of inlined scopes decreases by 4%, and (I think relatedly) the size of the binary increases by 14%. There is a small increase in the number of unique source variables (under 1%). I'd be happy to report back on any other suggested quantitative measures.

My qualitative feedback based on spot-checking a few frames is that -fextend-lifetimes noticeably improves the overall debugging experience. More argument values and local variables tend to be available. I'm not sure how best to put a number to this.

davide added a subscriber: davide.Dec 21 2017, 6:56 AM

Rebased on r347577 with some test cases.