[llvm] r296998 - [XRay] Allow logging the first argument of a function call.

Dean Michael Berris via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 5 22:48:57 PST 2017


Author: dberris
Date: Mon Mar  6 00:48:56 2017
New Revision: 296998

URL: http://llvm.org/viewvc/llvm-project?rev=296998&view=rev
Log:
[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

Added:
    llvm/trunk/test/CodeGen/X86/xray-log-args.ll
Modified:
    llvm/trunk/include/llvm/CodeGen/AsmPrinter.h
    llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Modified: llvm/trunk/include/llvm/CodeGen/AsmPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/AsmPrinter.h?rev=296998&r1=296997&r2=296998&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/AsmPrinter.h (original)
+++ llvm/trunk/include/llvm/CodeGen/AsmPrinter.h Mon Mar  6 00:48:56 2017
@@ -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

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=296998&r1=296997&r2=296998&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Mon Mar  6 00:48:56 2017
@@ -2756,8 +2756,11 @@ void AsmPrinter::recordSled(MCSymbol *Sl
   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 });
 }

Added: llvm/trunk/test/CodeGen/X86/xray-log-args.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/xray-log-args.ll?rev=296998&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/xray-log-args.ll (added)
+++ llvm/trunk/test/CodeGen/X86/xray-log-args.ll Mon Mar  6 00:48:56 2017
@@ -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




More information about the llvm-commits mailing list