[llvm-dev] RFC: New function attribute "patchable-prologue"="<kind>"
Sanjoy Das via llvm-dev
llvm-dev at lists.llvm.org
Thu Apr 7 16:35:02 PDT 2016
Hi Eric,
Eric Christopher wrote:
> Two things:
>
> a) I'm not against this
Great!
> b) So, what's your use case? I've got something I'm idly working on with
> someone else where we want patchable targets in both prologue and
> epilogue (and some other places...), and am thinking of how to make this
> someone generic enough to build off of there.
We plan to use this to be able to divert control flow from an LLVM
compiled function to "somewhere else" where the "somewhere else" is
usually a differently optimized version of the same function. One
reason to do this is when some speculative optimization we did to the
old version becomes unprofitable, but still remains correct[0]. The
threads executing in that old version are still fine to continue
executing there, but threads that just called into the old version
should instead execute this new version that does not have the same
problematic speculative optimization. To do this we overwrite the
prologue of the old function with a jump to a runtime stub which in
turn figures out what the newly compiled function is and branches to
it.
[0] A real world example: say we turned a null check followed by a
load into just a load, with a fallback in the SIGSEGV handler; and now
we've realized that the value we're null checking this way *is*
sometimes null. Taking a SIGSEGV every time the value is null is
correct, but bad for performance so we compile a new "healed" copy of
the same function that does not fall back to the SIGSEGV handler for
that particular null check (but explicitly tests it instead).
-- Sanjoy
More information about the llvm-dev
mailing list