From: Dean Michael Berris Date: Mon, 6 Mar 2017 06:48:56 +0000 (+0000) Subject: [XRay] Allow logging the first argument of a function call. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8c95619c81a645d9305741485f21fa2a908152b5;p=llvm [XRay] Allow logging the first argument of a function call. Summary: Functions with the "xray-log-args" attribute will have a special XRay sled kind emitted, for compiler-rt to copy any call arguments to your logging handler. For practical and performance reasons, only the first argument is supported, and only up to 64 bits. Reviewers: dberris Reviewed By: dberris Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D29702 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296998 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/CodeGen/AsmPrinter.h b/include/llvm/CodeGen/AsmPrinter.h index 1fc68d061a4..babb1ca1771 100644 --- a/include/llvm/CodeGen/AsmPrinter.h +++ b/include/llvm/CodeGen/AsmPrinter.h @@ -222,6 +222,7 @@ public: FUNCTION_ENTER = 0, FUNCTION_EXIT = 1, TAIL_CALL = 2, + LOG_ARGS_ENTER = 3, }; // The table will contain these structs that point to the sled, the function diff --git a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index b8a8a999c42..7099065a638 100644 --- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -2756,8 +2756,11 @@ void AsmPrinter::recordSled(MCSymbol *Sled, const MachineInstr &MI, SledKind Kind) { auto Fn = MI.getParent()->getParent()->getFunction(); auto Attr = Fn->getFnAttribute("function-instrument"); + bool LogArgs = Fn->hasFnAttribute("xray-log-args"); bool AlwaysInstrument = Attr.isStringAttribute() && Attr.getValueAsString() == "xray-always"; + if (Kind == SledKind::FUNCTION_ENTER && LogArgs) + Kind = SledKind::LOG_ARGS_ENTER; Sleds.emplace_back( XRayFunctionEntry{ Sled, CurrentFnSym, Kind, AlwaysInstrument, Fn }); } diff --git a/test/CodeGen/X86/xray-log-args.ll b/test/CodeGen/X86/xray-log-args.ll new file mode 100644 index 00000000000..a551868ffb4 --- /dev/null +++ b/test/CodeGen/X86/xray-log-args.ll @@ -0,0 +1,35 @@ +; When logging arguments is specified, emit the entry sled accordingly. + +; RUN: llc -filetype=asm -o - -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s +; RUN: llc -filetype=asm -o - -mtriple=x86_64-darwin-unknown < %s | FileCheck %s + +define i32 @callee(i32 %arg) nounwind noinline uwtable "function-instrument"="xray-always" "xray-log-args"="1" { + ret i32 %arg +} +; CHECK-LABEL: Lxray_synthetic_0: +; CHECK: .quad {{\.?}}Lxray_sled_0 +; CHECK: .quad {{_?}}callee +; CHECK: .byte 3 +; CHECK: .byte 1 +; CHECK: .{{(zero|space)}} 14 +; CHECK: .quad {{\.?}}Lxray_sled_1 +; CHECK: .quad {{_?}}callee +; CHECK: .byte 1 +; CHECK: .byte 1 +; CHECK: .{{(zero|space)}} 14 + +define i32 @caller(i32 %arg) nounwind noinline uwtable "function-instrument"="xray-always" "xray-log-args"="1" { + %retval = tail call i32 @callee(i32 %arg) + ret i32 %retval +} +; CHECK-LABEL: Lxray_synthetic_1: +; CHECK: .quad {{\.?}}Lxray_sled_2 +; CHECK: .quad {{_?}}caller +; CHECK: .byte 3 +; CHECK: .byte 1 +; CHECK: .{{(zero|space)}} 14 +; CHECK: .quad {{\.?}}Lxray_sled_3 +; CHECK: .quad {{_?}}caller +; CHECK: .byte 2 +; CHECK: .byte 1 +; CHECK: .{{(zero|space)}} 14