Skip to content

Commit 3fa3cb4

Browse files
committed
[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.
1 parent a132f5e commit 3fa3cb4

File tree

9 files changed

+27
-25
lines changed

9 files changed

+27
-25
lines changed

clang/test/CodeGen/xray-always-emit-typedevent.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
[[clang::xray_never_instrument]] void neverInstrument() {
77
static constexpr char kPhase[] = "never";
88
__xray_typedevent(1, kPhase, 5);
9-
// CHECK: call void @llvm.xray.typedevent(i16 {{.*}}, ptr{{.*}}, i32 5)
9+
// CHECK: call void @llvm.xray.typedevent(i64 {{.*}}, ptr{{.*}}, i64 5)
1010
}

clang/test/CodeGen/xray-instrumentation-bundles.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@
5454
__xray_typedevent(1, kPhase, 6);
5555
// CUSTOM: call void @llvm.xray.customevent(ptr{{.*}}, i32 6)
5656
// NOCUSTOM-NOT: call void @llvm.xray.customevent(ptr{{.*}}, i32 6)
57-
// TYPED: call void @llvm.xray.typedevent(i16 {{.*}}, ptr{{.*}}, i32 6)
58-
// NOTYPED-NOT: call void @llvm.xray.typedevent(i16 {{.*}}, ptr{{.*}}, i32 6)
57+
// TYPED: call void @llvm.xray.typedevent(i64 {{.*}}, ptr{{.*}}, i64 6)
58+
// NOTYPED-NOT: call void @llvm.xray.typedevent(
5959
}
6060

6161
// FUNCTION: attributes #[[ALWAYSATTR]] = {{.*}} "function-instrument"="xray-always" {{.*}}

clang/test/CodeGen/xray-typedevent.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
auto EventType = 1;
88
static constexpr char kPhase[] = "instrument";
99
__xray_typedevent(EventType, kPhase, 10);
10-
// CHECK: call void @llvm.xray.typedevent(i16 {{.*}}, ptr{{.*}}, i32 10)
10+
// CHECK: call void @llvm.xray.typedevent(i64 {{.*}}, ptr{{.*}}, i64 10)
1111
}
1212

1313
// CHECK-LABEL: @_Z15neverInstrumentv
1414
[[clang::xray_never_instrument]] void neverInstrument() {
1515
auto EventType = 2;
1616
static constexpr char kPhase[] = "never";
1717
__xray_typedevent(EventType, kPhase, 5);
18-
// CHECK-NOT: call void @llvm.xray.typedevent(i16 {{.*}}, ptr{{.*}}, i32 5)
18+
// CHECK-NOT: call void @llvm.xray.typedevent(i64 {{.*}}, ptr{{.*}}, i64 5)
1919
}
2020

2121
// CHECK-LABEL: @_Z21conditionalInstrumenti
@@ -29,6 +29,6 @@
2929
else
3030
__xray_typedevent(UntrueEventType, kUntrue, 6);
3131

32-
// CHECK: call void @llvm.xray.typedevent(i16 {{.*}}, ptr{{.*}}, i32 4)
33-
// CHECK: call void @llvm.xray.typedevent(i16 {{.*}}, ptr{{.*}}, i32 6)
32+
// CHECK: call void @llvm.xray.typedevent(i64 {{.*}}, ptr{{.*}}, i64 4)
33+
// CHECK: call void @llvm.xray.typedevent(i64 {{.*}}, ptr{{.*}}, i64 6)
3434
}

compiler-rt/include/xray/xray_interface.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ extern int __xray_remove_customevent_handler();
7676

7777
/// Set a handler for xray typed event logging. The first parameter is a type
7878
/// identifier, the second is a payload, and the third is the payload size.
79-
extern int __xray_set_typedevent_handler(void (*entry)(uint16_t, const void *,
80-
std::size_t));
79+
/// NOTE: fdrLoggingHandleTypedEvent only supports uint16_t event type.
80+
extern int __xray_set_typedevent_handler(void (*entry)(size_t, const void *,
81+
size_t));
8182

8283
/// Removes the currently set typed event handler.
8384
/// Returns 1 on success, 0 on error.

compiler-rt/lib/xray/xray_fdr_logging.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -580,9 +580,9 @@ void fdrLoggingHandleCustomEvent(void *Event,
580580
TLD.Controller->customEvent(TSC, CPU, Event, ReducedEventSize);
581581
}
582582

583-
void fdrLoggingHandleTypedEvent(
584-
uint16_t EventType, const void *Event,
585-
std::size_t EventSize) noexcept XRAY_NEVER_INSTRUMENT {
583+
void fdrLoggingHandleTypedEvent(size_t EventType, const void *Event,
584+
size_t EventSize) noexcept
585+
XRAY_NEVER_INSTRUMENT {
586586
auto TC = getTimestamp();
587587
auto &TSC = TC.TSC;
588588
auto &CPU = TC.CPU;
@@ -607,7 +607,8 @@ void fdrLoggingHandleTypedEvent(
607607
return;
608608

609609
int32_t ReducedEventSize = static_cast<int32_t>(EventSize);
610-
TLD.Controller->typedEvent(TSC, CPU, EventType, Event, ReducedEventSize);
610+
TLD.Controller->typedEvent(TSC, CPU, static_cast<uint16_t>(EventType), Event,
611+
ReducedEventSize);
611612
}
612613

613614
XRayLogInitStatus fdrLoggingInit(size_t, size_t, void *Options,

compiler-rt/lib/xray/xray_interface.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,8 @@ int __xray_set_customevent_handler(void (*entry)(void *, size_t))
426426
return 0;
427427
}
428428

429-
int __xray_set_typedevent_handler(void (*entry)(
430-
uint16_t, const void *, size_t)) XRAY_NEVER_INSTRUMENT {
429+
int __xray_set_typedevent_handler(void (*entry)(size_t, const void *,
430+
size_t)) XRAY_NEVER_INSTRUMENT {
431431
if (atomic_load(&XRayInitialized,
432432
memory_order_acquire)) {
433433
atomic_store(&__xray::XRayPatchedTypedEvent,

compiler-rt/test/xray/TestCases/Posix/typed-event-logging.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
printf("after calling the custom logging...\n");
1515
}
1616

17-
static void myprinter(uint16_t type, const void *ptr, size_t size) {
17+
static void myprinter(size_t type, const void *ptr, size_t size) {
1818
assert(type == 42);
1919
printf("%.*s\n", static_cast<int>(size), static_cast<const char*>(ptr));
2020
}

llvm/include/llvm/IR/Intrinsics.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2258,7 +2258,7 @@ def int_xray_customevent : Intrinsic<[], [llvm_ptr_ty, llvm_i32_ty],
22582258
ReadOnly<ArgIndex<0>>]>;
22592259
// Typed event logging for x-ray.
22602260
// Takes a numeric type tag, a pointer to a string and the length of the string.
2261-
def int_xray_typedevent : Intrinsic<[], [llvm_i16_ty, llvm_ptr_ty, llvm_i32_ty],
2261+
def int_xray_typedevent : Intrinsic<[], [llvm_i64_ty, llvm_ptr_ty, llvm_i64_ty],
22622262
[IntrWriteMem, NoCapture<ArgIndex<1>>,
22632263
ReadOnly<ArgIndex<1>>]>;
22642264
//===----------------------------------------------------------------------===//

llvm/test/CodeGen/X86/xray-custom-log.ll

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ define i32 @customevent() nounwind "function-instrument"="xray-always" !dbg !1 {
3737

3838
define i32 @typedevent() nounwind "function-instrument"="xray-always" !dbg !2 {
3939
%eventptr = alloca i8
40-
%eventsize = alloca i32
41-
%eventtype = alloca i16
42-
store i16 6, ptr %eventtype
43-
%type = load i16, ptr %eventtype
44-
store i32 3, ptr %eventsize
45-
%val = load i32, ptr %eventsize
46-
call void @llvm.xray.typedevent(i16 %type, ptr %eventptr, i32 %val), !dbg !9
40+
%eventsize = alloca i64
41+
%eventtype = alloca i64
42+
store i64 6, ptr %eventtype
43+
%type = load i64, ptr %eventtype
44+
store i64 3, ptr %eventsize
45+
%val = load i64, ptr %eventsize
46+
call void @llvm.xray.typedevent(i64 %type, ptr %eventptr, i64 %val), !dbg !9
4747
; CHECK-LABEL: Lxray_typed_event_sled_0:
4848
; CHECK: .byte 0xeb, 0x14
4949
; CHECK-NEXT: pushq %rdi
@@ -76,7 +76,7 @@ define i32 @typedevent() nounwind "function-instrument"="xray-always" !dbg !2 {
7676
; CHECK: .quad {{.*}}xray_typed_event_sled_0
7777

7878
declare void @llvm.xray.customevent(ptr, i32)
79-
declare void @llvm.xray.typedevent(i16, ptr, i32)
79+
declare void @llvm.xray.typedevent(i64, ptr, i64)
8080

8181
;; Construct call site entries for PATCHABLE_EVENT_CALL.
8282
; DBG: DW_TAG_subprogram

0 commit comments

Comments
 (0)