Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit d90c50e

Browse files
committed
Add -fdebug-info-for-profiling to emit more debug info for sample pgo profile collection
Summary: SamplePGO uses profile with debug info to collect profile. Unlike the traditional debugging purpose, sample pgo needs more accurate debug info to represent the profile. We add -femit-accurate-debug-info for this purpose. It can be combined with all debugging modes (-g, -gmlt, etc). It makes sure that the following pieces of info is always emitted: * start line of all subprograms * linkage name of all subprograms * standalone subprograms (functions that has neither inlined nor been inlined) The impact on speccpu2006 binary size (size increase comparing with -g0 binary, also includes data for -g binary, which does not change with this patch): -gmlt(orig) -gmlt(patched) -g 433.milc 4.68% 5.40% 19.73% 444.namd 8.45% 8.93% 45.99% 447.dealII 97.43% 115.21% 374.89% 450.soplex 27.75% 31.88% 126.04% 453.povray 21.81% 26.16% 92.03% 470.lbm 0.60% 0.67% 1.96% 482.sphinx3 5.77% 6.47% 26.17% 400.perlbench 17.81% 19.43% 73.08% 401.bzip2 3.73% 3.92% 12.18% 403.gcc 31.75% 34.48% 122.75% 429.mcf 0.78% 0.88% 3.89% 445.gobmk 6.08% 7.92% 42.27% 456.hmmer 10.36% 11.25% 35.23% 458.sjeng 5.08% 5.42% 14.36% 462.libquantum 1.71% 1.96% 6.36% 464.h264ref 15.61% 16.56% 43.92% 471.omnetpp 11.93% 15.84% 60.09% 473.astar 3.11% 3.69% 14.18% 483.xalancbmk 56.29% 81.63% 353.22% geomean 15.60% 18.30% 57.81% Debug info size change for -gmlt binary with this patch: 433.milc 13.46% 444.namd 5.35% 447.dealII 18.21% 450.soplex 14.68% 453.povray 19.65% 470.lbm 6.03% 482.sphinx3 11.21% 400.perlbench 8.91% 401.bzip2 4.41% 403.gcc 8.56% 429.mcf 8.24% 445.gobmk 29.47% 456.hmmer 8.19% 458.sjeng 6.05% 462.libquantum 11.23% 464.h264ref 5.93% 471.omnetpp 31.89% 473.astar 16.20% 483.xalancbmk 44.62% geomean 16.83% Reviewers: davidxl, andreadb, rob.lougher, dblaikie, echristo Reviewed By: dblaikie, echristo Subscribers: hfinkel, rob.lougher, andreadb, gbedwell, cfe-commits, probinson, llvm-commits, mehdi_amini Differential Revision: https://reviews.llvm.org/D25435 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@292458 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 4e25126 commit d90c50e

File tree

7 files changed

+23
-1
lines changed

7 files changed

+23
-1
lines changed

include/clang/Driver/Options.td

+6
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,12 @@ def fprofile_sample_use_EQ : Joined<["-"], "fprofile-sample-use=">,
516516
HelpText<"Enable sample-based profile guided optimizations">;
517517
def fauto_profile_EQ : Joined<["-"], "fauto-profile=">,
518518
Alias<fprofile_sample_use_EQ>;
519+
def fdebug_info_for_profiling : Flag<["-"], "fdebug-info-for-profiling">, Group<f_Group>,
520+
Flags<[CC1Option]>,
521+
HelpText<"Emit extra debug info to make sample profile more accurate.">;
522+
def fno_debug_info_for_profiling : Flag<["-"], "fno-debug-info-for-profiling">, Group<f_Group>,
523+
Flags<[DriverOption]>,
524+
HelpText<"Do not emit extra debug info for sample profiler.">;
519525
def fprofile_instr_generate : Flag<["-"], "fprofile-instr-generate">,
520526
Group<f_Group>, Flags<[CoreOption]>,
521527
HelpText<"Generate instrumented code to collect execution counts into default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env var)">;

include/clang/Frontend/CodeGenOptions.def

+3
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,9 @@ CODEGENOPT(PIECopyRelocations, 1, 0)
258258
/// paths that reach the end of a function without executing a required return.
259259
CODEGENOPT(StrictReturn, 1, 1)
260260

261+
/// Whether emit extra debug info for sample pgo profile collection.
262+
CODEGENOPT(DebugInfoForProfiling, 1, 0)
263+
261264
#undef CODEGENOPT
262265
#undef ENUM_CODEGENOPT
263266
#undef VALUE_CODEGENOPT

lib/CodeGen/BackendUtil.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@ void EmitAssemblyHelper::CreateTargetMachine(bool MustCreateTM) {
573573
Options.DisableIntegratedAS = CodeGenOpts.DisableIntegratedAS;
574574
Options.CompressDebugSections = CodeGenOpts.CompressDebugSections;
575575
Options.RelaxELFRelocations = CodeGenOpts.RelaxELFRelocations;
576+
Options.DebugInfoForProfiling = CodeGenOpts.DebugInfoForProfiling;
576577

577578
// Set EABI version.
578579
Options.EABIVersion = llvm::StringSwitch<llvm::EABI>(TargetOpts.EABIVersion)

lib/CodeGen/CGDebugInfo.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -2774,9 +2774,10 @@ void CGDebugInfo::collectFunctionDeclProps(GlobalDecl GD, llvm::DIFile *Unit,
27742774
}
27752775
// No need to replicate the linkage name if it isn't different from the
27762776
// subprogram name, no need to have it at all unless coverage is enabled or
2777-
// debug is set to more than just line tables.
2777+
// debug is set to more than just line tables or extra debug info is needed.
27782778
if (LinkageName == Name || (!CGM.getCodeGenOpts().EmitGcovArcs &&
27792779
!CGM.getCodeGenOpts().EmitGcovNotes &&
2780+
!CGM.getCodeGenOpts().DebugInfoForProfiling &&
27802781
DebugKind <= codegenoptions::DebugLineTablesOnly))
27812782
LinkageName = StringRef();
27822783

lib/Driver/Tools.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -5615,6 +5615,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
56155615
A->render(Args, CmdArgs);
56165616
}
56175617

5618+
if (Args.hasFlag(options::OPT_fdebug_info_for_profiling,
5619+
options::OPT_fno_debug_info_for_profiling, false))
5620+
CmdArgs.push_back("-fdebug-info-for-profiling");
5621+
56185622
// -fbuiltin is default unless -mkernel is used.
56195623
bool UseBuiltins =
56205624
Args.hasFlag(options::OPT_fbuiltin, options::OPT_fno_builtin,

lib/Frontend/CompilerInvocation.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,8 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
544544
Opts.DisableIntegratedAS = Args.hasArg(OPT_fno_integrated_as);
545545
Opts.Autolink = !Args.hasArg(OPT_fno_autolink);
546546
Opts.SampleProfileFile = Args.getLastArgValue(OPT_fprofile_sample_use_EQ);
547+
Opts.DebugInfoForProfiling = Args.hasFlag(
548+
OPT_fdebug_info_for_profiling, OPT_fno_debug_info_for_profiling, false);
547549

548550
setPGOInstrumentor(Opts, Args, Diags);
549551
Opts.InstrProfileOutput =

test/Driver/clang_f_opts.c

+5
Original file line numberDiff line numberDiff line change
@@ -482,3 +482,8 @@
482482
// RUN: %clang -### -S -fno-strict-return %s 2>&1 | FileCheck -check-prefix=CHECK-NO-STRICT-RETURN %s
483483
// CHECK-STRICT-RETURN-NOT: "-fno-strict-return"
484484
// CHECK-NO-STRICT-RETURN: "-fno-strict-return"
485+
486+
// RUN: %clang -### -S -fno-debug-info-for-profiling -fdebug-info-for-profiling %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-DEBUG %s
487+
// RUN: %clang -### -S -fdebug-info-for-profiling -fno-debug-info-for-profiling %s 2>&1 | FileCheck -check-prefix=CHECK-NO-PROFILE-DEBUG %s
488+
// CHECK-PROFILE-DEBUG: -fdebug-info-for-profiling
489+
// CHECK-NO-PROFILE-DEBUG-NOT: -fdebug-info-for-profiling

0 commit comments

Comments
 (0)