]> granicus.if.org Git - llvm/commitdiff
[XRay] Allow logging the first argument of a function call.
authorDean Michael Berris <dberris@google.com>
Mon, 6 Mar 2017 06:48:56 +0000 (06:48 +0000)
committerDean Michael Berris <dberris@google.com>
Mon, 6 Mar 2017 06:48:56 +0000 (06:48 +0000)
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

include/llvm/CodeGen/AsmPrinter.h
lib/CodeGen/AsmPrinter/AsmPrinter.cpp
test/CodeGen/X86/xray-log-args.ll [new file with mode: 0644]

index 1fc68d061a4954dddc6813bb0ffe631833dc9fe2..babb1ca1771259d97f9147ab77082b0bc88e98bb 100644 (file)
@@ -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
index b8a8a999c4290816d091da7aef4c14e6c3e23846..7099065a638da0fe197186f12ae58d59d22e38ae 100644 (file)
@@ -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 (file)
index 0000000..a551868
--- /dev/null
@@ -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