[PATCH] D157613: [Clang][ExtendLifetimes][3/4] Add -fextend-lifetimes flag to Clang to extend the lifetime of local variables

Stephen Tozer via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 10 06:49:20 PDT 2023


StephenTozer created this revision.
StephenTozer added reviewers: dblaikie, aprantl, echristo.
StephenTozer added a project: debug-info.
Herald added a reviewer: aaron.ballman.
Herald added a project: All.
StephenTozer requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

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 this patch, in order to simplify review.

---

This particular patch implements the clang side of the `-fextend-lifetimes` and `-fextend-this-ptr` flags, including adding the command line flags, applying the `disable-post-ra` attribute to functions having lifetimes extended (see the first patch in this sequence), and the emission of `llvm.fake.use` intrinsics for variables at the end of their scopes. The main bulk of the patch concerns emitting fake.use intrinsics, which are treated as noop cleanups since they should be emitted at all points where the variable falls out of scope.

In our (Sony's) own internal measurements (presented at EuroLLVM2023 <https://llvm.org/devmtg/2023-05/slides/Lightning-Talks/04-Tozer-UsingAutomatedTestsToTuneOgSlides.pdf>), using this flag at `-O1` gave a 2.4% performance cost for a 22.1% increase in step and variable availability compared to just `-O1`. From these results, it appears that using this flag gives an efficient increase in debuggability of programs for its performance cost, and should be very useful for development builds.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157613

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGCleanup.cpp
  clang/lib/CodeGen/CGCleanup.h
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/EHScopeStack.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/extend-liveness1.c
  clang/test/CodeGen/extend-liveness2.cpp
  clang/test/CodeGen/fake-use-determinism.c
  clang/test/CodeGen/fake-use-lambda.cpp
  clang/test/CodeGen/fake-use-landingpad.c
  clang/test/CodeGen/fake-use-noreturn.c
  clang/test/CodeGen/fake-use-return-line.c
  clang/test/CodeGen/fake-use-sanitizer.cpp
  clang/test/CodeGen/fake-use-scalar.c
  clang/test/CodeGen/fake-use-small-aggs.c
  clang/test/CodeGen/fake-use-while.c
  clang/test/CodeGen/fake-use.cpp
  clang/test/CodeGen/no-fake-use-O0.cpp
  clang/test/CodeGen/suppress-post-ra.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157613.549014.patch
Type: text/x-patch
Size: 29187 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230810/460c611a/attachment-0001.bin>


More information about the cfe-commits mailing list