forked from OSchip/llvm-project
Add -finstrument-function-entry-bare flag
This is an instrumentation flag that's similar to -finstrument-functions, but it only inserts calls on function entry, the calls are inserted post-inlining, and they don't take any arugments. This is intended for users who want to instrument function entry with minimal overhead. (-pg would be another alternative, but forces frame pointer emission and affects link flags, so is probably best left alone to be used for generating gcov data.) Differential revision: https://reviews.llvm.org/D40276 llvm-svn: 318785
This commit is contained in:
parent
d97c0f7855
commit
14e8a5a32d
|
@ -1030,6 +1030,8 @@ def finstrument_functions : Flag<["-"], "finstrument-functions">, Group<f_Group>
|
||||||
HelpText<"Generate calls to instrument function entry and exit">;
|
HelpText<"Generate calls to instrument function entry and exit">;
|
||||||
def finstrument_functions_after_inlining : Flag<["-"], "finstrument-functions-after-inlining">, Group<f_Group>, Flags<[CC1Option]>,
|
def finstrument_functions_after_inlining : Flag<["-"], "finstrument-functions-after-inlining">, Group<f_Group>, Flags<[CC1Option]>,
|
||||||
HelpText<"Like -finstrument-functions, but insert the calls after inlining">;
|
HelpText<"Like -finstrument-functions, but insert the calls after inlining">;
|
||||||
|
def finstrument_function_entry_bare : Flag<["-"], "finstrument-function-entry-bare">, Group<f_Group>, Flags<[CC1Option]>,
|
||||||
|
HelpText<"Instrument function entry only, after inlining, without arguments to the instrumentation call">;
|
||||||
|
|
||||||
def fxray_instrument : Flag<["-"], "fxray-instrument">, Group<f_Group>,
|
def fxray_instrument : Flag<["-"], "fxray-instrument">, Group<f_Group>,
|
||||||
Flags<[CC1Option]>,
|
Flags<[CC1Option]>,
|
||||||
|
|
|
@ -78,6 +78,8 @@ CODEGENOPT(InstrumentFunctions , 1, 0) ///< Set when -finstrument-functions is
|
||||||
///< enabled.
|
///< enabled.
|
||||||
CODEGENOPT(InstrumentFunctionsAfterInlining , 1, 0) ///< Set when
|
CODEGENOPT(InstrumentFunctionsAfterInlining , 1, 0) ///< Set when
|
||||||
///< -finstrument-functions-after-inlining is enabled.
|
///< -finstrument-functions-after-inlining is enabled.
|
||||||
|
CODEGENOPT(InstrumentFunctionEntryBare , 1, 0) ///< Set when
|
||||||
|
///< -finstrument-function-entry-bare is enabled.
|
||||||
|
|
||||||
CODEGENOPT(XRayInstrumentFunctions , 1, 0) ///< Set when -fxray-instrument is
|
CODEGENOPT(XRayInstrumentFunctions , 1, 0) ///< Set when -fxray-instrument is
|
||||||
///< enabled.
|
///< enabled.
|
||||||
|
|
|
@ -355,10 +355,11 @@ void CodeGenFunction::FinishFunction(SourceLocation EndLoc) {
|
||||||
llvm::DebugLoc Loc = EmitReturnBlock();
|
llvm::DebugLoc Loc = EmitReturnBlock();
|
||||||
|
|
||||||
if (ShouldInstrumentFunction()) {
|
if (ShouldInstrumentFunction()) {
|
||||||
CurFn->addFnAttr(!CGM.getCodeGenOpts().InstrumentFunctionsAfterInlining
|
if (CGM.getCodeGenOpts().InstrumentFunctions)
|
||||||
? "instrument-function-exit"
|
CurFn->addFnAttr("instrument-function-exit", "__cyg_profile_func_exit");
|
||||||
: "instrument-function-exit-inlined",
|
if (CGM.getCodeGenOpts().InstrumentFunctionsAfterInlining)
|
||||||
"__cyg_profile_func_exit");
|
CurFn->addFnAttr("instrument-function-exit-inlined",
|
||||||
|
"__cyg_profile_func_exit");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emit debug descriptor for function end.
|
// Emit debug descriptor for function end.
|
||||||
|
@ -443,7 +444,8 @@ void CodeGenFunction::FinishFunction(SourceLocation EndLoc) {
|
||||||
/// instrumented with __cyg_profile_func_* calls
|
/// instrumented with __cyg_profile_func_* calls
|
||||||
bool CodeGenFunction::ShouldInstrumentFunction() {
|
bool CodeGenFunction::ShouldInstrumentFunction() {
|
||||||
if (!CGM.getCodeGenOpts().InstrumentFunctions &&
|
if (!CGM.getCodeGenOpts().InstrumentFunctions &&
|
||||||
!CGM.getCodeGenOpts().InstrumentFunctionsAfterInlining)
|
!CGM.getCodeGenOpts().InstrumentFunctionsAfterInlining &&
|
||||||
|
!CGM.getCodeGenOpts().InstrumentFunctionEntryBare)
|
||||||
return false;
|
return false;
|
||||||
if (!CurFuncDecl || CurFuncDecl->hasAttr<NoInstrumentFunctionAttr>())
|
if (!CurFuncDecl || CurFuncDecl->hasAttr<NoInstrumentFunctionAttr>())
|
||||||
return false;
|
return false;
|
||||||
|
@ -982,10 +984,14 @@ void CodeGenFunction::StartFunction(GlobalDecl GD,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ShouldInstrumentFunction()) {
|
if (ShouldInstrumentFunction()) {
|
||||||
Fn->addFnAttr(!CGM.getCodeGenOpts().InstrumentFunctionsAfterInlining
|
if (CGM.getCodeGenOpts().InstrumentFunctions)
|
||||||
? "instrument-function-entry"
|
CurFn->addFnAttr("instrument-function-entry", "__cyg_profile_func_enter");
|
||||||
: "instrument-function-entry-inlined",
|
if (CGM.getCodeGenOpts().InstrumentFunctionsAfterInlining)
|
||||||
"__cyg_profile_func_enter");
|
CurFn->addFnAttr("instrument-function-entry-inlined",
|
||||||
|
"__cyg_profile_func_enter");
|
||||||
|
if (CGM.getCodeGenOpts().InstrumentFunctionEntryBare)
|
||||||
|
CurFn->addFnAttr("instrument-function-entry-inlined",
|
||||||
|
"__cyg_profile_func_enter_bare");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Since emitting the mcount call here impacts optimizations such as function
|
// Since emitting the mcount call here impacts optimizations such as function
|
||||||
|
|
|
@ -3554,8 +3554,11 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
|
||||||
options::OPT_fno_unique_section_names, true))
|
options::OPT_fno_unique_section_names, true))
|
||||||
CmdArgs.push_back("-fno-unique-section-names");
|
CmdArgs.push_back("-fno-unique-section-names");
|
||||||
|
|
||||||
Args.AddLastArg(CmdArgs, options::OPT_finstrument_functions,
|
if (auto *A = Args.getLastArg(
|
||||||
options::OPT_finstrument_functions_after_inlining);
|
options::OPT_finstrument_functions,
|
||||||
|
options::OPT_finstrument_functions_after_inlining,
|
||||||
|
options::OPT_finstrument_function_entry_bare))
|
||||||
|
A->render(Args, CmdArgs);
|
||||||
|
|
||||||
addPGOAndCoverageFlags(C, D, Output, Args, CmdArgs);
|
addPGOAndCoverageFlags(C, D, Output, Args, CmdArgs);
|
||||||
|
|
||||||
|
|
|
@ -782,6 +782,8 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
|
||||||
Opts.InstrumentFunctions = Args.hasArg(OPT_finstrument_functions);
|
Opts.InstrumentFunctions = Args.hasArg(OPT_finstrument_functions);
|
||||||
Opts.InstrumentFunctionsAfterInlining =
|
Opts.InstrumentFunctionsAfterInlining =
|
||||||
Args.hasArg(OPT_finstrument_functions_after_inlining);
|
Args.hasArg(OPT_finstrument_functions_after_inlining);
|
||||||
|
Opts.InstrumentFunctionEntryBare =
|
||||||
|
Args.hasArg(OPT_finstrument_function_entry_bare);
|
||||||
Opts.XRayInstrumentFunctions = Args.hasArg(OPT_fxray_instrument);
|
Opts.XRayInstrumentFunctions = Args.hasArg(OPT_fxray_instrument);
|
||||||
Opts.XRayInstructionThreshold =
|
Opts.XRayInstructionThreshold =
|
||||||
getLastArgIntValue(Args, OPT_fxray_instruction_threshold_EQ, 200, Diags);
|
getLastArgIntValue(Args, OPT_fxray_instruction_threshold_EQ, 200, Diags);
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
// RUN: %clang_cc1 -S -debug-info-kind=standalone -emit-llvm -o - %s -finstrument-functions -disable-llvm-passes | FileCheck %s
|
// RUN: %clang_cc1 -S -debug-info-kind=standalone -emit-llvm -o - %s -finstrument-functions -disable-llvm-passes | FileCheck %s
|
||||||
|
// RUN: %clang_cc1 -S -debug-info-kind=standalone -emit-llvm -o - %s -finstrument-function-entry-bare -disable-llvm-passes | FileCheck -check-prefix=BARE %s
|
||||||
|
|
||||||
int test1(int x) {
|
int test1(int x) {
|
||||||
// CHECK: @test1(i32 {{.*}}%x) #[[ATTR1:[0-9]+]]
|
// CHECK: @test1(i32 {{.*}}%x) #[[ATTR1:[0-9]+]]
|
||||||
// CHECK: ret
|
// CHECK: ret
|
||||||
|
|
||||||
|
// BARE: @test1(i32 {{.*}}%x) #[[ATTR1:[0-9]+]]
|
||||||
|
// BARE: ret
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,6 +14,9 @@ int test2(int) __attribute__((no_instrument_function));
|
||||||
int test2(int x) {
|
int test2(int x) {
|
||||||
// CHECK: @test2(i32 {{.*}}%x) #[[ATTR2:[0-9]+]]
|
// CHECK: @test2(i32 {{.*}}%x) #[[ATTR2:[0-9]+]]
|
||||||
// CHECK: ret
|
// CHECK: ret
|
||||||
|
|
||||||
|
// BARE: @test2(i32 {{.*}}%x) #[[ATTR2:[0-9]+]]
|
||||||
|
// BARE: ret
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,5 +24,11 @@ int test2(int x) {
|
||||||
// CHECK-SAME: "instrument-function-entry"="__cyg_profile_func_enter"
|
// CHECK-SAME: "instrument-function-entry"="__cyg_profile_func_enter"
|
||||||
// CHECK-SAME: "instrument-function-exit"="__cyg_profile_func_exit"
|
// CHECK-SAME: "instrument-function-exit"="__cyg_profile_func_exit"
|
||||||
|
|
||||||
|
// BARE: attributes #[[ATTR1]] =
|
||||||
|
// BARE-SAME: "instrument-function-entry-inlined"="__cyg_profile_func_enter_bare"
|
||||||
|
|
||||||
// CHECK: attributes #[[ATTR2]] =
|
// CHECK: attributes #[[ATTR2]] =
|
||||||
// CHECK-NOT: "instrument-function-entry"
|
// CHECK-NOT: "instrument-function-entry"
|
||||||
|
|
||||||
|
// BARE: attributes #[[ATTR2]] =
|
||||||
|
// BARE-NOT: "instrument-function-entry"
|
||||||
|
|
Loading…
Reference in New Issue