[clang] 7db7a35 - Fix uninitialized XRayArg
Author: Ian Levesque Date: 2020-09-25T00:20:36-04:00 New Revision: 7db7a355453887906d12ffb67df8fbaa5e9e873d URL: https://github.com/llvm/llvm-project/commit/7db7a355453887906d12ffb67df8fbaa5e9e873d DIFF: https://github.com/llvm/llvm-project/commit/7db7a355453887906d12ffb67df8fbaa5e9e873d.diff LOG: Fix uninitialized XRayArg Added: Modified: clang/include/clang/Driver/XRayArgs.h Removed: diff --git a/clang/include/clang/Driver/XRayArgs.h b/clang/include/clang/Driver/XRayArgs.h index 4c18fecd2763..6ed99a127669 100644 --- a/clang/include/clang/Driver/XRayArgs.h +++ b/clang/include/clang/Driver/XRayArgs.h @@ -33,7 +33,7 @@ class XRayArgs { bool XRayIgnoreLoops = false; bool XRayFunctionIndex; int XRayFunctionGroups = 1; - int XRaySelectedFunctionGroup; + int XRaySelectedFunctionGroup = 0; public: /// Parses the XRay arguments from an argument list. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 6f7fbdd - [xray] Function coverage groups
Author: Ian Levesque Date: 2020-09-24T22:09:53-04:00 New Revision: 6f7fbdd2857fc8a7280afbb26fd4e1a6450069e4 URL: https://github.com/llvm/llvm-project/commit/6f7fbdd2857fc8a7280afbb26fd4e1a6450069e4 DIFF: https://github.com/llvm/llvm-project/commit/6f7fbdd2857fc8a7280afbb26fd4e1a6450069e4.diff LOG: [xray] Function coverage groups Add the ability to selectively instrument a subset of functions by dividing the functions into N logical groups and then selecting a group to cover. By selecting different groups over time you could cover the entire application incrementally with lower overhead than instrumenting the entire application at once. Differential Revision: https://reviews.llvm.org/D87953 Added: clang/test/CodeGen/xray-function-groups.cpp Modified: clang/include/clang/Basic/CodeGenOptions.def clang/include/clang/Driver/Options.td clang/include/clang/Driver/XRayArgs.h clang/lib/CodeGen/CodeGenFunction.cpp clang/lib/Driver/XRayArgs.cpp clang/lib/Frontend/CompilerInvocation.cpp llvm/docs/XRay.rst Removed: diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def index b5da2a9cde1a..a259218b29c6 100644 --- a/clang/include/clang/Basic/CodeGenOptions.def +++ b/clang/include/clang/Basic/CodeGenOptions.def @@ -120,6 +120,12 @@ CODEGENOPT(XRayOmitFunctionIndex , 1, 0) ///< XRay instrumentation. VALUE_CODEGENOPT(XRayInstructionThreshold , 32, 200) +///< Only instrument 1 in N functions, by dividing functions into N total groups and +///< instrumenting only the specified group at a time. Group numbers start at 0 +///< and end at N-1. +VALUE_CODEGENOPT(XRayTotalFunctionGroups, 32, 1) +VALUE_CODEGENOPT(XRaySelectedFunctionGroup, 32, 0) + VALUE_CODEGENOPT(PatchableFunctionEntryCount , 32, 0) ///< Number of NOPs at function entry VALUE_CODEGENOPT(PatchableFunctionEntryOffset , 32, 0) diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index d7c2496b8a5d..a1f3d7a4316f 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1339,6 +1339,17 @@ def fxray_instrumentation_bundle : Group, Flags<[CC1Option]>, HelpText<"Select which XRay instrumentation points to emit. Options: all, none, function-entry, function-exit, function, custom. Default is 'all'. 'function' includes both 'function-entry' and 'function-exit'.">; +def fxray_function_groups : + Joined<["-"], "fxray-function-groups=">, + Group, Flags<[CC1Option]>, + HelpText<"Only instrument 1 of N groups">; + +def fxray_selected_function_group : + Joined<["-"], "fxray-selected-function-group=">, + Group, Flags<[CC1Option]>, + HelpText<"When using -fxray-function-groups, select which group of functions to instrument. Valid range is 0 to fxray-function-groups - 1">; + + def ffine_grained_bitfield_accesses : Flag<["-"], "ffine-grained-bitfield-accesses">, Group, Flags<[CC1Option]>, HelpText<"Use separate accesses for consecutive bitfield runs with legal widths and alignments.">; diff --git a/clang/include/clang/Driver/XRayArgs.h b/clang/include/clang/Driver/XRayArgs.h index 2f055e5c6d7d..4c18fecd2763 100644 --- a/clang/include/clang/Driver/XRayArgs.h +++ b/clang/include/clang/Driver/XRayArgs.h @@ -32,6 +32,8 @@ class XRayArgs { bool XRayRT = true; bool XRayIgnoreLoops = false; bool XRayFunctionIndex; + int XRayFunctionGroups = 1; + int XRaySelectedFunctionGroup; public: /// Parses the XRay arguments from an argument list. diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 016c7105b52d..47ef5c830723 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -32,6 +32,7 @@ #include "clang/Basic/TargetInfo.h" #include "clang/CodeGen/CGFunctionInfo.h" #include "clang/Frontend/FrontendDiagnostic.h" +#include "llvm/ADT/ArrayRef.h" #include "llvm/Frontend/OpenMP/OMPIRBuilder.h" #include "llvm/IR/DataLayout.h" #include "llvm/IR/Dominators.h" @@ -40,6 +41,7 @@ #include "llvm/IR/Intrinsics.h" #include "llvm/IR/MDBuilder.h" #include "llvm/IR/Operator.h" +#include "llvm/Support/CRC.h" #include "llvm/Transforms/Utils/PromoteMemToReg.h" using namespace clang; using namespace CodeGen; @@ -772,13 +774,16 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, SanOpts.Mask &= ~SanitizerKind::Null; // Apply xray attributes to the function (as a string, for now) + bool AlwaysXRayAttr = false; if (const auto *XRayAttr = D ? D->getAttr() : nullptr) { if (CGM.getCodeGenOpts().XRayInstrumentationBundle.has( XRayInstrKind::FunctionEntry) || CGM.getCodeGenOpts().XRayInstrumentationBundle.has( XRayInstrKind::FunctionExit)) { - if (XRayAttr->alwaysXRayInstrument() && ShouldXRayInstrumentFunction()) +
[clang] 7c7c8e0 - [xray] Option to omit the function index
Author: Ian Levesque Date: 2020-06-17T13:49:01-04:00 New Revision: 7c7c8e0da4e0c400e7e06c4c6658372ea0b487ea URL: https://github.com/llvm/llvm-project/commit/7c7c8e0da4e0c400e7e06c4c6658372ea0b487ea DIFF: https://github.com/llvm/llvm-project/commit/7c7c8e0da4e0c400e7e06c4c6658372ea0b487ea.diff LOG: [xray] Option to omit the function index Summary: Add a flag to omit the xray_fn_idx to cut size overhead and relocations roughly in half at the cost of reduced performance for single function patching. Minor additions to compiler-rt support per-function patching without the index. Reviewers: dberris, MaskRay, johnislarry Subscribers: hiraditya, arphaman, cfe-commits, #sanitizers, llvm-commits Tags: #clang, #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D81995 Added: clang/test/Driver/XRay/xray-function-index-flags.cpp llvm/test/CodeGen/AArch64/xray-omit-function-index.ll Modified: clang/include/clang/Basic/CodeGenOptions.def clang/include/clang/Driver/Options.td clang/include/clang/Driver/XRayArgs.h clang/lib/CodeGen/BackendUtil.cpp clang/lib/Driver/XRayArgs.cpp clang/lib/Frontend/CompilerInvocation.cpp compiler-rt/lib/xray/xray_init.cpp compiler-rt/lib/xray/xray_interface.cpp compiler-rt/test/xray/TestCases/Posix/coverage-sample.cpp compiler-rt/test/xray/TestCases/Posix/func-id-utils.cpp compiler-rt/test/xray/TestCases/Posix/patching-unpatching.cpp llvm/include/llvm/CodeGen/CommandFlags.h llvm/include/llvm/Target/TargetOptions.h llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp llvm/lib/CodeGen/CommandFlags.cpp Removed: diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def index 89a67235b966..d465e00d4c70 100644 --- a/clang/include/clang/Basic/CodeGenOptions.def +++ b/clang/include/clang/Basic/CodeGenOptions.def @@ -110,6 +110,9 @@ CODEGENOPT(XRayAlwaysEmitTypedEvents , 1, 0) ///< Set when -fxray-ignore-loops is enabled. CODEGENOPT(XRayIgnoreLoops , 1, 0) +///< Set with -fno-xray-function-index to omit the index section. +CODEGENOPT(XRayOmitFunctionIndex , 1, 0) + ///< Set the minimum number of instructions in a function to determine selective ///< XRay instrumentation. diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index d8de2a5ae475..9ea0016d057b 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1281,6 +1281,12 @@ defm xray_always_emit_typedevents : OptInFFlag<"xray-always-emit-typedevents", defm xray_ignore_loops : OptInFFlag<"xray-ignore-loops", "Don't instrument functions with loops unless they also meet the minimum function size">; +def fxray_function_index : Flag<["-"], "fxray-function-index">, + Group, Flags<[CC1Option]>; +def fno_xray_function_index : Flag<["-"], "fno-xray-function-index">, + Group, Flags<[CC1Option]>, + HelpText<"Omit the xray index section to reduce binary size at the expense of single-function patching performance">; + def fxray_link_deps : Flag<["-"], "fxray-link-deps">, Group, Flags<[CC1Option]>, HelpText<"Tells clang to add the link dependencies for XRay.">; diff --git a/clang/include/clang/Driver/XRayArgs.h b/clang/include/clang/Driver/XRayArgs.h index 96098bf629cd..22ab5fd2d207 100644 --- a/clang/include/clang/Driver/XRayArgs.h +++ b/clang/include/clang/Driver/XRayArgs.h @@ -31,6 +31,7 @@ class XRayArgs { bool XRayAlwaysEmitTypedEvents = false; bool XRayRT = true; bool XRayIgnoreLoops = false; + bool XRayOmitFunctionIndex = false; public: /// Parses the XRay arguments from an argument list. diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index ebf74dbbe1f5..603f1c9adf54 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -516,6 +516,7 @@ static void initTargetOptions(DiagnosticsEngine , Options.EmitAddrsig = CodeGenOpts.Addrsig; Options.ForceDwarfFrameSection = CodeGenOpts.ForceDwarfFrameSection; Options.EmitCallSiteInfo = CodeGenOpts.EmitCallSiteInfo; + Options.XRayOmitFunctionIndex = CodeGenOpts.XRayOmitFunctionIndex; Options.MCOptions.SplitDwarfFile = CodeGenOpts.SplitDwarfFile; Options.MCOptions.MCRelaxAll = CodeGenOpts.RelaxAll; diff --git a/clang/lib/Driver/XRayArgs.cpp b/clang/lib/Driver/XRayArgs.cpp index f233267b4984..44a5d0d18291 100644 --- a/clang/lib/Driver/XRayArgs.cpp +++ b/clang/lib/Driver/XRayArgs.cpp @@ -105,6 +105,10 @@ XRayArgs::XRayArgs(const ToolChain , const ArgList ) { options::OPT_fno_xray_ignore_loops, false)) XRayIgnoreLoops = true; + if (!Args.hasFlag(options::OPT_fxray_function_index, +options::OPT_fno_xray_function_index, true)) +XRayOmitFunctionIndex = true; + auto Bundles =
[clang] bb3111c - [clang][xray] Add xray attributes to functions without decls too
Author: Ian Levesque Date: 2020-04-01T00:02:39-04:00 New Revision: bb3111cbaf7b181bcda94415456a69b2a6b767ad URL: https://github.com/llvm/llvm-project/commit/bb3111cbaf7b181bcda94415456a69b2a6b767ad DIFF: https://github.com/llvm/llvm-project/commit/bb3111cbaf7b181bcda94415456a69b2a6b767ad.diff LOG: [clang][xray] Add xray attributes to functions without decls too Summary: This allows instrumenting things like global initializers Reviewers: dberris, MaskRay, smeenai Subscribers: cfe-commits, johnislarry Tags: #clang Differential Revision: https://reviews.llvm.org/D77191 Added: clang/test/CodeGen/xray-global-init.cpp Modified: clang/lib/CodeGen/CodeGenFunction.cpp Removed: diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 3393b1b3c5fb..618c9a046321 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -810,55 +810,54 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, FD->getBody()->getStmtClass() == Stmt::CoroutineBodyStmtClass) SanOpts.Mask &= ~SanitizerKind::Null; - if (D) { -// Apply xray attributes to the function (as a string, for now) -if (const auto *XRayAttr = D->getAttr()) { - if (CGM.getCodeGenOpts().XRayInstrumentationBundle.has( - XRayInstrKind::FunctionEntry) || - CGM.getCodeGenOpts().XRayInstrumentationBundle.has( - XRayInstrKind::FunctionExit)) { -if (XRayAttr->alwaysXRayInstrument() && ShouldXRayInstrumentFunction()) - Fn->addFnAttr("function-instrument", "xray-always"); -if (XRayAttr->neverXRayInstrument()) - Fn->addFnAttr("function-instrument", "xray-never"); -if (const auto *LogArgs = D->getAttr()) - if (ShouldXRayInstrumentFunction()) -Fn->addFnAttr("xray-log-args", - llvm::utostr(LogArgs->getArgumentCount())); - } -} else { - if (ShouldXRayInstrumentFunction() && !CGM.imbueXRayAttrs(Fn, Loc)) -Fn->addFnAttr( -"xray-instruction-threshold", -llvm::itostr(CGM.getCodeGenOpts().XRayInstructionThreshold)); + // Apply xray attributes to the function (as a string, for now) + if (const auto *XRayAttr = D ? D->getAttr() : nullptr) { +if (CGM.getCodeGenOpts().XRayInstrumentationBundle.has( +XRayInstrKind::FunctionEntry) || +CGM.getCodeGenOpts().XRayInstrumentationBundle.has( +XRayInstrKind::FunctionExit)) { + if (XRayAttr->alwaysXRayInstrument() && ShouldXRayInstrumentFunction()) +Fn->addFnAttr("function-instrument", "xray-always"); + if (XRayAttr->neverXRayInstrument()) +Fn->addFnAttr("function-instrument", "xray-never"); + if (const auto *LogArgs = D->getAttr()) +if (ShouldXRayInstrumentFunction()) + Fn->addFnAttr("xray-log-args", +llvm::utostr(LogArgs->getArgumentCount())); } + } else { +if (ShouldXRayInstrumentFunction() && !CGM.imbueXRayAttrs(Fn, Loc)) + Fn->addFnAttr( + "xray-instruction-threshold", + llvm::itostr(CGM.getCodeGenOpts().XRayInstructionThreshold)); + } -if (ShouldXRayInstrumentFunction()) { - if (CGM.getCodeGenOpts().XRayIgnoreLoops) -Fn->addFnAttr("xray-ignore-loops"); + if (ShouldXRayInstrumentFunction()) { +if (CGM.getCodeGenOpts().XRayIgnoreLoops) + Fn->addFnAttr("xray-ignore-loops"); - if (!CGM.getCodeGenOpts().XRayInstrumentationBundle.has( - XRayInstrKind::FunctionExit)) -Fn->addFnAttr("xray-skip-exit"); +if (!CGM.getCodeGenOpts().XRayInstrumentationBundle.has( +XRayInstrKind::FunctionExit)) + Fn->addFnAttr("xray-skip-exit"); - if (!CGM.getCodeGenOpts().XRayInstrumentationBundle.has( - XRayInstrKind::FunctionEntry)) -Fn->addFnAttr("xray-skip-entry"); -} +if (!CGM.getCodeGenOpts().XRayInstrumentationBundle.has( +XRayInstrKind::FunctionEntry)) + Fn->addFnAttr("xray-skip-entry"); + } -unsigned Count, Offset; -if (const auto *Attr = D->getAttr()) { - Count = Attr->getCount(); - Offset = Attr->getOffset(); -} else { - Count = CGM.getCodeGenOpts().PatchableFunctionEntryCount; - Offset = CGM.getCodeGenOpts().PatchableFunctionEntryOffset; -} -if (Count && Offset <= Count) { - Fn->addFnAttr("patchable-function-entry", std::to_string(Count - Offset)); - if (Offset) -Fn->addFnAttr("patchable-function-prefix", std::to_string(Offset)); -} + unsigned Count, Offset; + if (const auto *Attr = + D ? D->getAttr() : nullptr) { +Count = Attr->getCount(); +Offset = Attr->getOffset(); + } else { +Count = CGM.getCodeGenOpts().PatchableFunctionEntryCount; +Offset =