This is an archive of the discontinued LLVM Phabricator instance.

[Clang][ExtendLifetimes][4/4] Add extend_lifetimes pragma to Clang to selectively disable -fextend-lifetimes for functions
Needs ReviewPublic

Authored by StephenTozer on Aug 10 2023, 6:50 AM.



This patch is part of a set of patches that add an -fextend-lifetimes flag to clang, which extends the lifetimes of local variables and parameters for improved debuggability. In addition to that flag, the patch series adds a new function attribute to disable the post-RA scheduler (which is applied by -fextend-lifetimes), a pragma to selectively disable -fextend-lifetimes, and an -fextend-this-ptr flag which functions as -fextend-lifetimes for this pointers only. All changes and tests in these patches were written by @wolfgangp, though I will be managing these reviews and addressing any comments raised. Discussion on the approach of this patch series as a whole should be directed to the 3rd patch, D157613, in order to simplify review.

This particular patch adds a new pragma, pragma clang extend_lifetimes disable/enable that can be used to toggle -fextend-lifetimes for subsequent functions:

It may be useful for developers to keep certain functions (e.g. very hot function that do not need debugging) from having their variable lifetimes extended (which will hurt performance). The way to do this is to add #pragma clang extend_lifetimes disable prior to those functions, and #pragma clang extend_lifetimes enable afterwards. This is helpful during developer builds where the intention is to repeatedly edit-compile-debug, but the developer likely does not want #pragma clang extend_lifetimes enable to be extending variable lifetimes during Release builds. Therefore these pragmas will only have an effect when -fextend-lifetimes is passed.

Diff Detail