Index: include/llvm/CodeGen/AsmPrinter.h =================================================================== --- include/llvm/CodeGen/AsmPrinter.h +++ include/llvm/CodeGen/AsmPrinter.h @@ -222,6 +222,7 @@ 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: lib/CodeGen/AsmPrinter/AsmPrinter.cpp =================================================================== --- lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -2756,8 +2756,11 @@ 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 }); } Index: test/CodeGen/X86/xray-log-args.ll =================================================================== --- /dev/null +++ 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 14 +; CHECK: .quad .Lxray_sled_1 +; CHECK: .quad callee +; CHECK: .byte 1 +; CHECK: .byte 1 +; CHECK: .zero 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 14 +; CHECK: .quad .Lxray_sled_3 +; CHECK: .quad caller +; CHECK: .byte 2 +; CHECK: .byte 1 +; CHECK: .zero 14