[PATCH] D28674: [XRay][Arm32] Reduce the portion of the stub and implement more staging for tail calls - in compiler-rt

Serge Rogatch via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 13 05:28:42 PST 2017


rSerge created this revision.
rSerge added reviewers: dberris, rengolin.
rSerge added subscribers: iid_iunknown, llvm-commits.
Herald added a subscriber: aemerson.

This patch provides more staging for tail calls in XRay Arm32 . When the logging part of XRay is ready for tail calls, its support in the core part of XRay Arm32 may be as easy as changing the number passed to the handler from 1 to 2.
Coupled patch:

- https://reviews.llvm.org/D28673


https://reviews.llvm.org/D28674

Files:
  lib/xray/xray_arm.cc
  lib/xray/xray_trampoline_arm.S
  test/xray/lit.cfg


Index: test/xray/lit.cfg
===================================================================
--- test/xray/lit.cfg
+++ test/xray/lit.cfg
@@ -30,7 +30,9 @@
 # Default test suffixes.
 config.suffixes = ['.c', '.cc', '.cpp']
 
-if config.host_os not in ['Linux'] or config.host_arch.find('64') == -1:
+if config.host_os not in ['Linux']:
+  config.unsupported = True
+elif config.host_arch.find('64') == -1 and config.host_arch.find('arm') == -1:
   config.unsupported = True
 
 # Allow tests to use REQUIRES=stable-runtime.  For use when you cannot use XFAIL
Index: lib/xray/xray_trampoline_arm.S
===================================================================
--- lib/xray/xray_trampoline_arm.S
+++ lib/xray/xray_trampoline_arm.S
@@ -3,6 +3,7 @@
     .fpu vfpv2
     .code 32
     .global _ZN6__xray19XRayPatchedFunctionE
+
     @ Word-aligned function entry point
     .p2align 2
     @ Let C/C++ see the symbol
@@ -63,3 +64,35 @@
     @ Restore the floating-point return value of the instrumented function
     VPOP {d0}
     POP {r1-r3,pc}
+
+    @ Word-aligned function entry point
+    .p2align 2
+    @ Let C/C++ see the symbol
+    .global __xray_FunctionTailExit
+    @ It preserves all registers except r0, r12(ip), r14(lr) and r15(pc)
+    @ Assume that "q" part of the floating-point registers is not used
+    @   for passing parameters to C/C++ functions.
+    .type __xray_FunctionTailExit, %function
+    @ In C++ it is void extern "C" __xray_FunctionTailExit(uint32_t FuncId)
+    @   with FuncId passed in r0 register.
+__xray_FunctionTailExit:
+    PUSH {r1-r3,lr}
+    @ Save floating-point parameters of the instrumented function
+    VPUSH {d0-d7}
+    MOVW r1,#:lower16:_ZN6__xray19XRayPatchedFunctionE
+    MOVT r1,#:upper16:_ZN6__xray19XRayPatchedFunctionE
+    LDR r2, [r1]
+    @ Handler address is nullptr if handler is not set
+    CMP r2, #0
+    BEQ FunctionTailExit_restore
+    @ Function ID is already in r0 (the first parameter).
+    @ r1=2 means that we are tracing a tail exit event
+    @ But before the logging part of XRay is ready, we pretend that here a
+    @   normal function exit happens, so we give the handler code 1
+    MOV r1, #1
+    @ Call the handler with 2 parameters in r0 and r1
+    BLX r2
+FunctionTailExit_restore:
+    @ Restore floating-point parameters of the instrumented function
+    VPOP {d0-d7}
+    POP {r1-r3,pc}
Index: lib/xray/xray_arm.cc
===================================================================
--- lib/xray/xray_arm.cc
+++ lib/xray/xray_arm.cc
@@ -148,9 +148,7 @@
 
 bool patchFunctionTailExit(const bool Enable, const uint32_t FuncId,
                            const XRaySledEntry &Sled) XRAY_NEVER_INSTRUMENT {
-  // FIXME: In the future we'd need to distinguish between non-tail exits and
-  // tail exits for better information preservation.
-  return patchSled(Enable, FuncId, Sled, __xray_FunctionExit);
+  return patchSled(Enable, FuncId, Sled, __xray_FunctionTailExit);
 }
 
 } // namespace __xray


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28674.84287.patch
Type: text/x-patch
Size: 3058 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170113/fd9bc96c/attachment.bin>


More information about the llvm-commits mailing list