This is an archive of the discontinued LLVM Phabricator instance.

[XRay] Detect and emit sleds for sibling/tail calls
ClosedPublic

Authored by dberris on Aug 29 2016, 3:23 AM.

Details

Summary

This change promotes the 'isTailCall(...)' member function to
TargetInstrInfo as a query interface for determining on a per-target
basis whether a given MachineInstr is a tail call instruction. We build
upon this in the XRay instrumentation pass to emit special sleds for
tail call optimisations, where we emit the correct kind of sled.

The tail call sleds look like a mix between the function entry and
function exit sleds. Form-wise, the sled comes before the "jmp"
instruction that implements the tail call similar to how we do it for
the function entry sled. Functionally, because we know this is a tail
call, it behaves much like an exit sled -- i.e. at runtime we may use
the exit trampolines instead of a different kind of trampoline.

A follow-up change to recognise these sleds will be done in compiler-rt,
so that we can start intercepting these initially as exits, but also
have the option to have different log entries to more accurately reflect
that this is actually a tail call.

Diff Detail

Repository
rL LLVM

Event Timeline

dberris updated this revision to Diff 69550.Aug 29 2016, 3:23 AM
dberris retitled this revision from to [XRay] Detect and emit sleds for sibling/tail calls.
dberris updated this object.
dberris added reviewers: echristo, rSerge, majnemer.
dberris added a subscriber: llvm-commits.
echristo edited edge metadata.Aug 31 2016, 5:39 PM

Probably want to split out just the NFC of making isTailCall a function on TII.

Probably want to split out just the NFC of making isTailCall a function on TII.

Good idea! Let me do that first, then rebase again. :)

dberris updated this revision to Diff 69936.Aug 31 2016, 6:13 PM
dberris edited edge metadata.

Rebase

echristo accepted this revision.Aug 31 2016, 6:34 PM
echristo edited edge metadata.

LGTM.

-eric

This revision is now accepted and ready to land.Aug 31 2016, 6:34 PM
This revision was automatically updated to reflect the committed changes.
rSerge added inline comments.Sep 22 2016, 2:12 PM
llvm/trunk/lib/Target/X86/X86MCInstLower.cpp
1126

Why all the hassle with passing the original tail call instruction and its operands in the arguments of the patchable tail call instruction, instead of just prepending the original tail call instruction with the sled code?

rSerge added inline comments.Oct 12 2016, 11:08 AM
llvm/trunk/test/CodeGen/X86/xray-tail-call-sled.ll
12

Isn't it missing setting EAX to 0? The function in the disassembly seems to just return;, rather than return 0; as, I guess, ret i32 0 requires.

rSerge added inline comments.Oct 12 2016, 12:00 PM
llvm/trunk/test/CodeGen/X86/xray-tail-call-sled.ll
18–20

Perhaps I missed some patches. Where are these generated? And also .quad .Lxray_synthetic_0 2 lines above.

dberris added inline comments.Oct 13 2016, 2:35 AM
llvm/trunk/test/CodeGen/X86/xray-tail-call-sled.ll
12

Nope, this is in a test -- the set to eax 0 happens before the return. We're only looking for the return instruction sled here.

18–20

This was introduced in D23398. The discussion of why is there.