Author: Ian Levesque Date: 2020-01-17T13:32:24-08:00 New Revision: 1d62be244108547558c6d42ddcf2e4a7f3c6dd03
URL: https://github.com/llvm/llvm-project/commit/1d62be244108547558c6d42ddcf2e4a7f3c6dd03 DIFF: https://github.com/llvm/llvm-project/commit/1d62be244108547558c6d42ddcf2e4a7f3c6dd03.diff LOG: [clang][xray] Add -fxray-ignore-loops option XRay allows tuning by minimum function size, but also always instruments functions with loops in them. If the minimum function size is set to a large value the loop instrumention ends up causing most functions to be instrumented anyway. This adds a new flag, -fxray-ignore-loops, to disable the loop detection logic. Differential Revision: https://reviews.llvm.org/D72873 Added: clang/test/CodeGen/xray-ignore-loops.cpp Modified: clang/include/clang/Basic/CodeGenOptions.def clang/include/clang/Driver/Options.td clang/lib/CodeGen/CodeGenFunction.cpp clang/lib/Frontend/CompilerInvocation.cpp Removed: ################################################################################ diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def index 50fc1836282f..9f4f83635673 100644 --- a/clang/include/clang/Basic/CodeGenOptions.def +++ b/clang/include/clang/Basic/CodeGenOptions.def @@ -106,6 +106,10 @@ CODEGENOPT(XRayAlwaysEmitCustomEvents , 1, 0) ///< Set when -fxray-always-emit-typedevents is enabled. CODEGENOPT(XRayAlwaysEmitTypedEvents , 1, 0) +///< Set when -fxray-ignore-loops is enabled. +CODEGENOPT(XRayIgnoreLoops , 1, 0) + + ///< Set the minimum number of instructions in a function to determine selective ///< XRay instrumentation. VALUE_CODEGENOPT(XRayInstructionThreshold , 32, 200) diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index abfa767afea8..ad829efe43da 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1292,6 +1292,13 @@ def fxray_always_emit_typedevents : Flag<["-"], "fxray-always-emit-typedevents"> def fnoxray_always_emit_typedevents : Flag<["-"], "fno-xray-always-emit-typedevents">, Group<f_Group>, Flags<[CC1Option]>; +def fxray_ignore_loops : Flag<["-"], "fxray-ignore-loops">, Group<f_Group>, + Flags<[CC1Option]>, + HelpText<"Don't instrument functions with loops unless they also meet the minimum function size">; +def fno_xray_ignore_loops : Flag<["-"], "fno-xray-ignore-loops">, Group<f_Group>, + Flags<[CC1Option]>; + + def fxray_link_deps : Flag<["-"], "fxray-link-deps">, Group<f_Group>, Flags<[CC1Option]>, HelpText<"Tells clang to add the link dependencies for XRay.">; diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 2bf94f697e01..75f5c0e545d1 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -818,6 +818,9 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, Fn->addFnAttr( "xray-instruction-threshold", llvm::itostr(CGM.getCodeGenOpts().XRayInstructionThreshold)); + if (CGM.getCodeGenOpts().XRayIgnoreLoops) { + Fn->addFnAttr("xray-ignore-loops"); + } } if (const auto *Attr = D->getAttr<PatchableFunctionEntryAttr>()) { diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index e1e59565083b..3671e084b1ca 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -1091,6 +1091,8 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, Args.hasArg(OPT_fxray_always_emit_typedevents); Opts.XRayInstructionThreshold = getLastArgIntValue(Args, OPT_fxray_instruction_threshold_EQ, 200, Diags); + Opts.XRayIgnoreLoops = + Args.hasArg(OPT_fxray_ignore_loops, OPT_fno_xray_ignore_loops, false); auto XRayInstrBundles = Args.getAllArgValues(OPT_fxray_instrumentation_bundle); diff --git a/clang/test/CodeGen/xray-ignore-loops.cpp b/clang/test/CodeGen/xray-ignore-loops.cpp new file mode 100644 index 000000000000..17ea2afbeece --- /dev/null +++ b/clang/test/CodeGen/xray-ignore-loops.cpp @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -fxray-instrument -fxray-ignore-loops -x c++ -std=c++11 -emit-llvm -o - %s -triple x86_64-unknown-linux-gnu | FileCheck %s + +int foo() { + return 1; +} + +// CHECK: define i32 @_Z3foov() #[[ATTRS:[0-9]+]] { +// CHECK-DAG: attributes #[[ATTRS]] = {{.*}} "xray-ignore-loops" {{.*}} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits