[compiler-rt] 3fa3cb4 - [XRay] Make llvm.xray.typedevent parameter type match __xray_typedevent

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 19 20:28:44 PDT 2023


Author: Fangrui Song
Date: 2023-06-19T20:28:39-07:00
New Revision: 3fa3cb408d8d0f1365b322262e501b6945f7ead9

URL: https://github.com/llvm/llvm-project/commit/3fa3cb408d8d0f1365b322262e501b6945f7ead9
DIFF: https://github.com/llvm/llvm-project/commit/3fa3cb408d8d0f1365b322262e501b6945f7ead9.diff

LOG: [XRay] Make llvm.xray.typedevent parameter type match __xray_typedevent

The Clang built-in function is void __xray_typedevent(size_t, const void *, size_t),
but the LLVM intrinsics has smaller integer types. Since we only allow
64-bit ELF/Mach-O targets, we can change llvm.xray.typedevent to
i64/ptr/i64.

This allows encoding more information and avoids i16 legalization for
many non-X86 targets.

fdrLoggingHandleTypedEvent only supports uint16_t event type.

Added: 
    

Modified: 
    clang/test/CodeGen/xray-always-emit-typedevent.cpp
    clang/test/CodeGen/xray-instrumentation-bundles.cpp
    clang/test/CodeGen/xray-typedevent.cpp
    compiler-rt/include/xray/xray_interface.h
    compiler-rt/lib/xray/xray_fdr_logging.cpp
    compiler-rt/lib/xray/xray_interface.cpp
    compiler-rt/test/xray/TestCases/Posix/typed-event-logging.cpp
    llvm/include/llvm/IR/Intrinsics.td
    llvm/test/CodeGen/X86/xray-custom-log.ll

Removed: 
    


################################################################################
diff  --git a/clang/test/CodeGen/xray-always-emit-typedevent.cpp b/clang/test/CodeGen/xray-always-emit-typedevent.cpp
index 75af669abe28d..745c63f6b3fa5 100644
--- a/clang/test/CodeGen/xray-always-emit-typedevent.cpp
+++ b/clang/test/CodeGen/xray-always-emit-typedevent.cpp
@@ -6,5 +6,5 @@
 [[clang::xray_never_instrument]] void neverInstrument() {
   static constexpr char kPhase[] = "never";
   __xray_typedevent(1, kPhase, 5);
-  // CHECK: call void @llvm.xray.typedevent(i16 {{.*}}, ptr{{.*}}, i32 5)
+  // CHECK: call void @llvm.xray.typedevent(i64 {{.*}}, ptr{{.*}}, i64 5)
 }

diff  --git a/clang/test/CodeGen/xray-instrumentation-bundles.cpp b/clang/test/CodeGen/xray-instrumentation-bundles.cpp
index 83ca42ac6d9e9..45ea6e514e6cc 100644
--- a/clang/test/CodeGen/xray-instrumentation-bundles.cpp
+++ b/clang/test/CodeGen/xray-instrumentation-bundles.cpp
@@ -54,8 +54,8 @@
   __xray_typedevent(1, kPhase, 6);
   // CUSTOM: call void @llvm.xray.customevent(ptr{{.*}}, i32 6)
   // NOCUSTOM-NOT: call void @llvm.xray.customevent(ptr{{.*}}, i32 6)
-  // TYPED: call void @llvm.xray.typedevent(i16 {{.*}}, ptr{{.*}}, i32 6)
-  // NOTYPED-NOT: call void @llvm.xray.typedevent(i16 {{.*}}, ptr{{.*}}, i32 6)
+  // TYPED: call void @llvm.xray.typedevent(i64 {{.*}}, ptr{{.*}}, i64 6)
+  // NOTYPED-NOT: call void @llvm.xray.typedevent(
 }
 
 // FUNCTION: attributes #[[ALWAYSATTR]] = {{.*}} "function-instrument"="xray-always" {{.*}}

diff  --git a/clang/test/CodeGen/xray-typedevent.cpp b/clang/test/CodeGen/xray-typedevent.cpp
index 57597970cd9e8..2ea4f7c75a7f5 100644
--- a/clang/test/CodeGen/xray-typedevent.cpp
+++ b/clang/test/CodeGen/xray-typedevent.cpp
@@ -7,7 +7,7 @@
   auto EventType = 1;
   static constexpr char kPhase[] = "instrument";
   __xray_typedevent(EventType, kPhase, 10);
-  // CHECK: call void @llvm.xray.typedevent(i16 {{.*}}, ptr{{.*}}, i32 10)
+  // CHECK: call void @llvm.xray.typedevent(i64 {{.*}}, ptr{{.*}}, i64 10)
 }
 
 // CHECK-LABEL: @_Z15neverInstrumentv
@@ -15,7 +15,7 @@
   auto EventType = 2;
   static constexpr char kPhase[] = "never";
   __xray_typedevent(EventType, kPhase, 5);
-  // CHECK-NOT: call void @llvm.xray.typedevent(i16 {{.*}}, ptr{{.*}}, i32 5)
+  // CHECK-NOT: call void @llvm.xray.typedevent(i64 {{.*}}, ptr{{.*}}, i64 5)
 }
 
 // CHECK-LABEL: @_Z21conditionalInstrumenti
@@ -29,6 +29,6 @@
   else
     __xray_typedevent(UntrueEventType, kUntrue, 6);
 
-  // CHECK: call void @llvm.xray.typedevent(i16 {{.*}}, ptr{{.*}}, i32 4)
-  // CHECK: call void @llvm.xray.typedevent(i16 {{.*}}, ptr{{.*}}, i32 6)
+  // CHECK: call void @llvm.xray.typedevent(i64 {{.*}}, ptr{{.*}}, i64 4)
+  // CHECK: call void @llvm.xray.typedevent(i64 {{.*}}, ptr{{.*}}, i64 6)
 }

diff  --git a/compiler-rt/include/xray/xray_interface.h b/compiler-rt/include/xray/xray_interface.h
index 410515d2373af..727431c04e4f7 100644
--- a/compiler-rt/include/xray/xray_interface.h
+++ b/compiler-rt/include/xray/xray_interface.h
@@ -76,8 +76,9 @@ extern int __xray_remove_customevent_handler();
 
 /// Set a handler for xray typed event logging. The first parameter is a type
 /// identifier, the second is a payload, and the third is the payload size.
-extern int __xray_set_typedevent_handler(void (*entry)(uint16_t, const void *,
-                                                       std::size_t));
+/// NOTE: fdrLoggingHandleTypedEvent only supports uint16_t event type.
+extern int __xray_set_typedevent_handler(void (*entry)(size_t, const void *,
+                                                       size_t));
 
 /// Removes the currently set typed event handler.
 /// Returns 1 on success, 0 on error.

diff  --git a/compiler-rt/lib/xray/xray_fdr_logging.cpp b/compiler-rt/lib/xray/xray_fdr_logging.cpp
index 799814f437f92..6056f8134553b 100644
--- a/compiler-rt/lib/xray/xray_fdr_logging.cpp
+++ b/compiler-rt/lib/xray/xray_fdr_logging.cpp
@@ -580,9 +580,9 @@ void fdrLoggingHandleCustomEvent(void *Event,
   TLD.Controller->customEvent(TSC, CPU, Event, ReducedEventSize);
 }
 
-void fdrLoggingHandleTypedEvent(
-    uint16_t EventType, const void *Event,
-    std::size_t EventSize) noexcept XRAY_NEVER_INSTRUMENT {
+void fdrLoggingHandleTypedEvent(size_t EventType, const void *Event,
+                                size_t EventSize) noexcept
+    XRAY_NEVER_INSTRUMENT {
   auto TC = getTimestamp();
   auto &TSC = TC.TSC;
   auto &CPU = TC.CPU;
@@ -607,7 +607,8 @@ void fdrLoggingHandleTypedEvent(
     return;
 
   int32_t ReducedEventSize = static_cast<int32_t>(EventSize);
-  TLD.Controller->typedEvent(TSC, CPU, EventType, Event, ReducedEventSize);
+  TLD.Controller->typedEvent(TSC, CPU, static_cast<uint16_t>(EventType), Event,
+                             ReducedEventSize);
 }
 
 XRayLogInitStatus fdrLoggingInit(size_t, size_t, void *Options,

diff  --git a/compiler-rt/lib/xray/xray_interface.cpp b/compiler-rt/lib/xray/xray_interface.cpp
index 73e67618c9d5f..af9f11e166ac5 100644
--- a/compiler-rt/lib/xray/xray_interface.cpp
+++ b/compiler-rt/lib/xray/xray_interface.cpp
@@ -426,8 +426,8 @@ int __xray_set_customevent_handler(void (*entry)(void *, size_t))
   return 0;
 }
 
-int __xray_set_typedevent_handler(void (*entry)(
-    uint16_t, const void *, size_t)) XRAY_NEVER_INSTRUMENT {
+int __xray_set_typedevent_handler(void (*entry)(size_t, const void *,
+                                                size_t)) XRAY_NEVER_INSTRUMENT {
   if (atomic_load(&XRayInitialized,
                                memory_order_acquire)) {
     atomic_store(&__xray::XRayPatchedTypedEvent,

diff  --git a/compiler-rt/test/xray/TestCases/Posix/typed-event-logging.cpp b/compiler-rt/test/xray/TestCases/Posix/typed-event-logging.cpp
index 20c99557acc48..103b11cfb0971 100644
--- a/compiler-rt/test/xray/TestCases/Posix/typed-event-logging.cpp
+++ b/compiler-rt/test/xray/TestCases/Posix/typed-event-logging.cpp
@@ -14,7 +14,7 @@
   printf("after calling the custom logging...\n");
 }
 
-static void myprinter(uint16_t type, const void *ptr, size_t size) {
+static void myprinter(size_t type, const void *ptr, size_t size) {
   assert(type == 42);
   printf("%.*s\n", static_cast<int>(size), static_cast<const char*>(ptr));
 }

diff  --git a/llvm/include/llvm/IR/Intrinsics.td b/llvm/include/llvm/IR/Intrinsics.td
index 97bfb8f22fda5..fbb2fa9a65646 100644
--- a/llvm/include/llvm/IR/Intrinsics.td
+++ b/llvm/include/llvm/IR/Intrinsics.td
@@ -2258,7 +2258,7 @@ def int_xray_customevent : Intrinsic<[], [llvm_ptr_ty, llvm_i32_ty],
                                       ReadOnly<ArgIndex<0>>]>;
 // Typed event logging for x-ray.
 // Takes a numeric type tag, a pointer to a string and the length of the string.
-def int_xray_typedevent : Intrinsic<[], [llvm_i16_ty, llvm_ptr_ty, llvm_i32_ty],
+def int_xray_typedevent : Intrinsic<[], [llvm_i64_ty, llvm_ptr_ty, llvm_i64_ty],
                                         [IntrWriteMem, NoCapture<ArgIndex<1>>,
                                          ReadOnly<ArgIndex<1>>]>;
 //===----------------------------------------------------------------------===//

diff  --git a/llvm/test/CodeGen/X86/xray-custom-log.ll b/llvm/test/CodeGen/X86/xray-custom-log.ll
index 28699e9bb4bcd..ea0d14b9cc7a2 100644
--- a/llvm/test/CodeGen/X86/xray-custom-log.ll
+++ b/llvm/test/CodeGen/X86/xray-custom-log.ll
@@ -37,13 +37,13 @@ define i32 @customevent() nounwind "function-instrument"="xray-always" !dbg !1 {
 
 define i32 @typedevent() nounwind "function-instrument"="xray-always" !dbg !2 {
     %eventptr = alloca i8
-    %eventsize = alloca i32
-    %eventtype = alloca i16
-    store i16 6, ptr %eventtype
-    %type = load i16, ptr %eventtype
-    store i32 3, ptr %eventsize
-    %val = load i32, ptr %eventsize
-    call void @llvm.xray.typedevent(i16 %type, ptr %eventptr, i32 %val), !dbg !9
+    %eventsize = alloca i64
+    %eventtype = alloca i64
+    store i64 6, ptr %eventtype
+    %type = load i64, ptr %eventtype
+    store i64 3, ptr %eventsize
+    %val = load i64, ptr %eventsize
+    call void @llvm.xray.typedevent(i64 %type, ptr %eventptr, i64 %val), !dbg !9
     ; CHECK-LABEL: Lxray_typed_event_sled_0:
     ; CHECK:       .byte 0xeb, 0x14
     ; CHECK-NEXT:  pushq %rdi
@@ -76,7 +76,7 @@ define i32 @typedevent() nounwind "function-instrument"="xray-always" !dbg !2 {
 ; CHECK:       .quad {{.*}}xray_typed_event_sled_0
 
 declare void @llvm.xray.customevent(ptr, i32)
-declare void @llvm.xray.typedevent(i16, ptr, i32)
+declare void @llvm.xray.typedevent(i64, ptr, i64)
 
 ;; Construct call site entries for PATCHABLE_EVENT_CALL.
 ; DBG:     DW_TAG_subprogram


        


More information about the llvm-commits mailing list