This is an archive of the discontinued LLVM Phabricator instance.

[XRay][AArch64] Suppport __xray_customevent/__xray_typedevent
ClosedPublic

Authored by MaskRay on Jun 19 2023, 11:27 PM.

Details

Summary

__xray_customevent and __xray_typedevent are built-in functions in Clang.
With -fxray-instrument, they are lowered to intrinsics llvm.xray.customevent and
llvm.xray.typedevent, respectively. These intrinsics are then lowered to
TargetOpcode::{PATCHABLE_EVENT_CALL,PATCHABLE_TYPED_EVENT_CALL}. The target is
responsible for generating a code sequence that calls either
__xray_CustomEvent (with 2 arguments) or __xray_TypedEvent (with 3
arguments).

Before patching, the code sequence is prefixed by a branch instruction that
skips the rest of the code sequence. After patching
(compiler-rt/lib/xray/xray_AArch64.cpp), the branch instruction becomes a NOP
and the function call will take effects.

This patch implements the lowering process for
{PATCHABLE_EVENT_CALL,PATCHABLE_TYPED_EVENT_CALL} and implements the runtime.

// Lowering of PATCHABLE_EVENT_CALL
.Lxray_sled_N:
  b  #24
  stp x0, x1, [sp, #-16]!
  x0 = reg of op0
  x1 = reg of op1
  bl __xray_CustomEvent
  ldrp x0, x1, [sp], #16

As a result, two updated tests in compiler-rt/test/xray/TestCases/Posix/ now
pass on AArch64.

Diff Detail

Event Timeline

MaskRay created this revision.Jun 19 2023, 11:27 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 19 2023, 11:27 PM
MaskRay requested review of this revision.Jun 19 2023, 11:27 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJun 19 2023, 11:27 PM
Herald added subscribers: llvm-commits, Restricted Project. · View Herald Transcript

I'm not familiar with xray, ideally someone that knows that better will be able to spot anything I've missed. On the AArch64 instruction side it looks good. Maybe better to use a mov rather than an add if the addend is always zero. If we can't find anyone familiar with xray to review I'm happy to approve as I think this looks like an improvement, and is not at risk of breaking anything.

compiler-rt/lib/xray/xray_AArch64.cpp
123–127

For the AArch64 specific file I think it would be better to say
B . + 24 => nop
nop => B . + 24
As B is the AArch64 instruction that matches 0x14......

Is it worth mentioning why 24 and 36 in this file (2 or 3 parameters). This is mentioned in AArch64AsmPrinter.cpp but that is separate from compiler-rt.

llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
343

IIUC these two instructions are add x0, <rn>, #0 and add x1, <rn>, #0 if the addend is always 0 then while this will work it isn't idiomatic. Would a mov instruction work? I think this may be an alias of the register form with one of the sources the zero register Xzr.

374

Similar comment about whether MOV could be used here?

MaskRay updated this revision to Diff 533454.Jun 21 2023, 7:31 PM
MaskRay marked 3 inline comments as done.

Appreciate the comments. updates.
(Yes, there is currently a lack of review resources on XRay...)

MaskRay updated this revision to Diff 533455.Jun 21 2023, 7:36 PM

better comments

MaskRay updated this revision to Diff 533456.Jun 21 2023, 7:37 PM

fix a typo

MaskRay added inline comments.Jun 21 2023, 9:40 PM
llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
343

Yes, mov will work. I'll change...

peter.smith accepted this revision.Jun 22 2023, 2:20 AM

Thanks for update. I've approved as I can't see anything wrong and this doesn't alter any existing target. Could be worth waiting a day to see if anyone objects.

This revision is now accepted and ready to land.Jun 22 2023, 2:20 AM
This revision was landed with ongoing or failed builds.Jun 23 2023, 9:24 AM
This revision was automatically updated to reflect the committed changes.