From 42af6513589dbaf28b98a2d30d92cdd6a4884cc0 Mon Sep 17 00:00:00 2001 From: Dean Michael Berris Date: Tue, 9 May 2017 00:45:40 +0000 Subject: [XRay] Add __xray_customeevent(...) as a clang-supported builtin Summary: We define the `__xray_customeevent` builtin that gets translated to IR calls to the correct intrinsic. The default implementation of this is a no-op function. The codegen side of this follows the following logic: - When `-fxray-instrument` is not provided in the driver, we elide all calls to `__xray_customevent`. - When `-fxray-instrument` is enabled and a function is marked as "never instrumented", we elide all calls to `__xray_customevent` in that function; if either marked as "always instrumented" or subject to threshold-based instrumentation, we emit a call to the `llvm.xray.customevent` intrinsic from LLVM for each `__xray_customevent` occurrence in the function. This change depends on D27503 (to land in LLVM first). Reviewers: echristo, rsmith Subscribers: mehdi_amini, pelikan, lrl, cfe-commits Differential Revision: https://reviews.llvm.org/D30018 llvm-svn: 302492 --- clang/test/CodeGen/xray-customevent.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 clang/test/CodeGen/xray-customevent.cpp (limited to 'clang/test/CodeGen/xray-customevent.cpp') diff --git a/clang/test/CodeGen/xray-customevent.cpp b/clang/test/CodeGen/xray-customevent.cpp new file mode 100644 index 00000000000..359d92df938 --- /dev/null +++ b/clang/test/CodeGen/xray-customevent.cpp @@ -0,0 +1,28 @@ +// RUN: %clang_cc1 -fxray-instrument -x c++ -std=c++11 -triple x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s + +// CHECK-LABEL: @_Z16alwaysInstrumentv +[[clang::xray_always_instrument]] void alwaysInstrument() { + static constexpr char kPhase[] = "instrument"; + __xray_customevent(kPhase, 10); + // CHECK: call void @llvm.xray.customevent(i8*{{.*}}, i32 10) +} + +// CHECK-LABEL: @_Z15neverInstrumentv +[[clang::xray_never_instrument]] void neverInstrument() { + static constexpr char kPhase[] = "never"; + __xray_customevent(kPhase, 5); + // CHECK-NOT: call void @llvm.xray.customevent(i8*{{.*}}, i32 5) +} + +// CHECK-LABEL: @_Z21conditionalInstrumenti +[[clang::xray_always_instrument]] void conditionalInstrument(int v) { + static constexpr char kTrue[] = "true"; + static constexpr char kUntrue[] = "untrue"; + if (v % 2) + __xray_customevent(kTrue, 4); + else + __xray_customevent(kUntrue, 6); + + // CHECK: call void @llvm.xray.customevent(i8*{{.*}}, i32 4) + // CHECK: call void @llvm.xray.customevent(i8*{{.*}}, i32 6) +} -- cgit v1.2.3