[llvm-dev] extending liveness of 'this' pointer via FAKE_USE opcode

Joseph Tremoulet via llvm-dev llvm-dev at lists.llvm.org
Mon Sep 21 18:32:09 PDT 2015


We faced a similar issue in LLILC, where our runtime requires us to report certain GC pointers as live (and have their values preserved) throughout certain methods.  We considered some sort of fake_use construct, but we need these things to be live even in code that doesn't reach return (e.g. paths that end in a noreturn call and `unreachable`), and weren't keen on adding them to all such paths (and making sure optimizations can't expose new such paths as they discover that code is unreachable), nor did we put much thought into how that might interfere with tailcall generation/modeling.  So, at least for now, we're calling the @llvm.localescape intrinsic on these addresses in the function entry block, with the expectation that doing so will make them appear live wherever we need them to be (which specifically is GC safe-points, which for us all involve calls to external code).
Your situation sounds different both in that you want this for debugging whereas we need it for correctness (so maybe the paths that lead to unreachable or infinite loops aren't as interesting for you) and in that you may care about extending liveness past the last call (unlike we who just need to cover the GC safe-points), but FYI that's what we've done in a somewhat similar situation.
We'd be happy to have something to use that's explicitly for lifetime extension, so long as it covers the paths which don't reach return.

Thanks
-Joseph

From: llvm-dev [mailto:llvm-dev-bounces at lists.llvm.org] On Behalf Of Pieb, Wolfgang via llvm-dev
Sent: Monday, September 21, 2015 2:17 PM
To: llvm-dev at lists.llvm.org
Subject: [llvm-dev] extending liveness of 'this' pointer via FAKE_USE opcode

Hello!

At Sony we've seen some serious customer interest in having the 'this' pointer visible throughout an entire function during
debugging. However, optimizations may eliminate it after its last use, so we've been looking for a way to artificially extend its
liverange to the end of the function.

So far, the most compelling way we can think of, and one we have used successfully in the past in at least one other compiler,
is to create a 'fake use' of the 'this' pointer at the end of the function, compelling the rest of the compiler to not optimize it away.

At the moment there doesn't seem to be a good way to create such a fake use in LLVM (please enlighten us if you know of one), so we are
proposing to introduce a new intrinsic (e.g. llvm.fake_use), which would take a single value argument, representing a use of that value.
The intrinsic would be lowered to a new invariant TargetOpcode (e.g. FAKE_USE), which serves the same purpose at the MI level.
Code emission would simply ignore the new opcode.

Frontends could use the intrinsic to extend liveranges of variables as desired. As a first use case, clang would accept a new option
(e.g. -fkeep-this-ptr) which would cause a fake use of 'this' to be inserted at the end of a function, making it available for inspection
throughout the entire function body.

One important note is that since such an option would affect code generation, it cannot be automatically enabled by -g. However, should there be
eventually support for a -Og mode (optimize for debugging), that mode could enable it.

Any comments or alternative ideas are appreciated.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150922/e767c836/attachment.html>


More information about the llvm-dev mailing list