This is an archive of the discontinued LLVM Phabricator instance.

Support for an intrinsic "fake.use" (and corresponding operand) representing a use of an operand to aid debugging
Needs ReviewPublic

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

Details

Reviewers
None
Summary

The patch presents the implementation of the "FAKE USE" concept I presented in my lightning talk "Debugging of optimized code: Extending the lifetime of local variables" at the October 2017 LLVM developers' 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.

There is a review for the corresponding clang patch, which implements the -fextend-lifetime and -fextend-this-ptr options. These options make clang generate fake uses of local variables. I will add the URL here as soon as I have posted it.

Regarding the implementation, it is a relatively straightforward addition of the intrinsic and machine opcode. Some optimizations had to be suppressed for FAKE_USE operands because they would have affected debuggability. Note also that fake uses are not cloned during inlining, which does reduce their utility somewhat, but doing so led to a larger than acceptable performance degradation. There are probably ways to improve on this.

Diff Detail

Event Timeline

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

The clang portion has been posted in https://reviews.llvm.org/D41044.

efriedma added inline comments.
include/llvm/IR/Intrinsics.td
831

Does this support more than one argument?

lib/Transforms/Utils/CloneFunction.cpp
339

This is an interesting heuristic...

Putting the code here isn't great; IIRC some code outside the inliner uses this codepath.

wolfgangp added inline comments.Dec 11 2017, 5:41 PM
include/llvm/IR/Intrinsics.td
831

Theoretically yes, but it wouldn't work at the moment (SelectionDAG would have to translate it into several FAKE_USE machine ops). Could be an improvement, but the code in the FE would have to be a little better about collecting several locals at the same lexical level.

lib/Transforms/Utils/CloneFunction.cpp
339

Short inline member functions suffer when you can no longer optimize '*this', because 'this' is fake-used. Resulted in a fairly large performance degradation.

Thanks for pointing this out. I'll check for other places cloning is used. One place I'm aware of is generating thunks for virtual varargs methods.

syrajendra removed a subscriber: syrajendra.
syrajendra added a subscriber: syrajendra.

Rebased on r347573 with some test cases and bugfixes.