[PATCH] D37091: Expose -mllvm -accurate-sample-profile to clang.
danielcdh created this revision. Herald added a subscriber: sanjoy. With accurate sample profile, we can do more aggressive size optimization. For some size-critical application, this can reduce the text size by 20% https://reviews.llvm.org/D37091 Files: include/clang/Driver/Options.td lib/Driver/ToolChains/Clang.cpp Index: lib/Driver/ToolChains/Clang.cpp === --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -2340,6 +2340,12 @@ true)) CmdArgs.push_back("-fno-jump-tables"); + if (Args.hasFlag(options::OPT_faccurate_sample_profile, + options::OPT_fno_accurate_sample_profile, false)) { +CmdArgs.push_back("-mllvm"); +CmdArgs.push_back("-accurate-sample-profile"); + } + if (!Args.hasFlag(options::OPT_fpreserve_as_comments, options::OPT_fno_preserve_as_comments, true)) CmdArgs.push_back("-fno-preserve-as-comments"); Index: include/clang/Driver/Options.td === --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -587,6 +587,14 @@ def fPIE : Flag<["-"], "fPIE">, Group; def fno_PIE : Flag<["-"], "fno-PIE">, Group; def faccess_control : Flag<["-"], "faccess-control">, Group; +def faccurate_sample_profile : Flag<["-"], "faccurate-sample-profile">, + Group, Flags<[DriverOption]>, + HelpText<"If sample profile is accurate, we will mark all un-sampled " + "callsite as cold. Otherwise, treat un-sampled callsites as if " + "we have no profile">; +def fno_accurate_sample_profile : Flag<["-"], "fno-accurate-sample-profile">, + Group, Flags<[DriverOption]>; + def fallow_unsupported : Flag<["-"], "fallow-unsupported">, Group; def fapple_kext : Flag<["-"], "fapple-kext">, Group, Flags<[CC1Option]>, HelpText<"Use Apple's kernel extensions ABI">; @@ -643,6 +651,10 @@ Alias; def fauto_profile_EQ : Joined<["-"], "fauto-profile=">, Alias; +def fauto_profile_accurate : Flag<["-"], "fauto-profile-accurate">, +Group, Alias; +def fno_auto_profile_accurate : Flag<["-"], "fno-auto-profile-accurate">, +Group, Alias; def fdebug_info_for_profiling : Flag<["-"], "fdebug-info-for-profiling">, Group, Flags<[CC1Option]>, HelpText<"Emit extra debug info to make sample profile more accurate.">; Index: lib/Driver/ToolChains/Clang.cpp === --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -2340,6 +2340,12 @@ true)) CmdArgs.push_back("-fno-jump-tables"); + if (Args.hasFlag(options::OPT_faccurate_sample_profile, + options::OPT_fno_accurate_sample_profile, false)) { +CmdArgs.push_back("-mllvm"); +CmdArgs.push_back("-accurate-sample-profile"); + } + if (!Args.hasFlag(options::OPT_fpreserve_as_comments, options::OPT_fno_preserve_as_comments, true)) CmdArgs.push_back("-fno-preserve-as-comments"); Index: include/clang/Driver/Options.td === --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -587,6 +587,14 @@ def fPIE : Flag<["-"], "fPIE">, Group; def fno_PIE : Flag<["-"], "fno-PIE">, Group; def faccess_control : Flag<["-"], "faccess-control">, Group; +def faccurate_sample_profile : Flag<["-"], "faccurate-sample-profile">, + Group, Flags<[DriverOption]>, + HelpText<"If sample profile is accurate, we will mark all un-sampled " + "callsite as cold. Otherwise, treat un-sampled callsites as if " + "we have no profile">; +def fno_accurate_sample_profile : Flag<["-"], "fno-accurate-sample-profile">, + Group, Flags<[DriverOption]>; + def fallow_unsupported : Flag<["-"], "fallow-unsupported">, Group; def fapple_kext : Flag<["-"], "fapple-kext">, Group, Flags<[CC1Option]>, HelpText<"Use Apple's kernel extensions ABI">; @@ -643,6 +651,10 @@ Alias; def fauto_profile_EQ : Joined<["-"], "fauto-profile=">, Alias; +def fauto_profile_accurate : Flag<["-"], "fauto-profile-accurate">, +Group, Alias; +def fno_auto_profile_accurate : Flag<["-"], "fno-auto-profile-accurate">, +Group, Alias; def fdebug_info_for_profiling : Flag<["-"], "fdebug-info-for-profiling">, Group, Flags<[CC1Option]>, HelpText<"Emit extra debug info to make sample profile more accurate.">; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D37091: Expose -mllvm -accurate-sample-profile to clang.
danielcdh updated this revision to Diff 112496. danielcdh added a comment. add document and test https://reviews.llvm.org/D37091 Files: docs/ClangCommandLineReference.rst include/clang/Driver/Options.td lib/Driver/ToolChains/Clang.cpp test/Driver/clang_f_opts.c Index: test/Driver/clang_f_opts.c === --- test/Driver/clang_f_opts.c +++ test/Driver/clang_f_opts.c @@ -53,6 +53,9 @@ // CHECK-REROLL-LOOPS: "-freroll-loops" // CHECK-NO-REROLL-LOOPS-NOT: "-freroll-loops" +// RUN: %clang -### -S -faccurate-sample-profile %s 2>&1 | FileCheck -check-prefix=CHECK-ACCURATE-SAMPLE-PROFILE %s +// CHECK-ACCURATE-SAMPLE-PROFILE: "-accurate-sample-profile" + // RUN: %clang -### -S -fprofile-sample-use=%S/Inputs/file.prof %s 2>&1 | FileCheck -check-prefix=CHECK-SAMPLE-PROFILE %s // CHECK-SAMPLE-PROFILE: "-fprofile-sample-use={{.*}}/file.prof" Index: lib/Driver/ToolChains/Clang.cpp === --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -2340,6 +2340,12 @@ true)) CmdArgs.push_back("-fno-jump-tables"); + if (Args.hasFlag(options::OPT_faccurate_sample_profile, + options::OPT_fno_accurate_sample_profile, false)) { +CmdArgs.push_back("-mllvm"); +CmdArgs.push_back("-accurate-sample-profile"); + } + if (!Args.hasFlag(options::OPT_fpreserve_as_comments, options::OPT_fno_preserve_as_comments, true)) CmdArgs.push_back("-fno-preserve-as-comments"); Index: include/clang/Driver/Options.td === --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -587,6 +587,14 @@ def fPIE : Flag<["-"], "fPIE">, Group; def fno_PIE : Flag<["-"], "fno-PIE">, Group; def faccess_control : Flag<["-"], "faccess-control">, Group; +def faccurate_sample_profile : Flag<["-"], "faccurate-sample-profile">, + Group, Flags<[DriverOption]>, + HelpText<"If sample profile is accurate, we will mark all un-sampled " + "callsite as cold. Otherwise, treat un-sampled callsites as if " + "we have no profile">; +def fno_accurate_sample_profile : Flag<["-"], "fno-accurate-sample-profile">, + Group, Flags<[DriverOption]>; + def fallow_unsupported : Flag<["-"], "fallow-unsupported">, Group; def fapple_kext : Flag<["-"], "fapple-kext">, Group, Flags<[CC1Option]>, HelpText<"Use Apple's kernel extensions ABI">; @@ -643,6 +651,10 @@ Alias; def fauto_profile_EQ : Joined<["-"], "fauto-profile=">, Alias; +def fauto_profile_accurate : Flag<["-"], "fauto-profile-accurate">, +Group, Alias; +def fno_auto_profile_accurate : Flag<["-"], "fno-auto-profile-accurate">, +Group, Alias; def fdebug_info_for_profiling : Flag<["-"], "fdebug-info-for-profiling">, Group, Flags<[CC1Option]>, HelpText<"Emit extra debug info to make sample profile more accurate.">; Index: docs/ClangCommandLineReference.rst === --- docs/ClangCommandLineReference.rst +++ docs/ClangCommandLineReference.rst @@ -170,6 +170,11 @@ .. option:: -exported\_symbols\_list +.. option:: -faccurate-sample-profile, -fno-accurate-sample-profile +.. program:: clang + +If sample profile is accurate, we will mark all un-sampled callsite as cold. Otherwise, treat un-sampled callsites as if we have no profile + .. option:: -faligned-new= .. option:: -fcuda-approx-transcendentals, -fno-cuda-approx-transcendentals Index: test/Driver/clang_f_opts.c === --- test/Driver/clang_f_opts.c +++ test/Driver/clang_f_opts.c @@ -53,6 +53,9 @@ // CHECK-REROLL-LOOPS: "-freroll-loops" // CHECK-NO-REROLL-LOOPS-NOT: "-freroll-loops" +// RUN: %clang -### -S -faccurate-sample-profile %s 2>&1 | FileCheck -check-prefix=CHECK-ACCURATE-SAMPLE-PROFILE %s +// CHECK-ACCURATE-SAMPLE-PROFILE: "-accurate-sample-profile" + // RUN: %clang -### -S -fprofile-sample-use=%S/Inputs/file.prof %s 2>&1 | FileCheck -check-prefix=CHECK-SAMPLE-PROFILE %s // CHECK-SAMPLE-PROFILE: "-fprofile-sample-use={{.*}}/file.prof" Index: lib/Driver/ToolChains/Clang.cpp === --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -2340,6 +2340,12 @@ true)) CmdArgs.push_back("-fno-jump-tables"); + if (Args.hasFlag(options::OPT_faccurate_sample_profile, + options::OPT_fno_accurate_sample_profile, false)) { +CmdArgs.push_back("-mllvm"); +CmdArgs.push_back("-accurate-sample-profile"); + } + if (!Args.hasFlag(options::OPT_fpreserve_as_comments, options::OPT_fno_preserve_as_comments, true)) CmdArgs.push_back("-fno-preserve-as-comments"); Index: include/clang/Driver/Options.td =
[PATCH] D37091: Expose -mllvm -accurate-sample-profile to clang.
danielcdh updated this revision to Diff 112574. danielcdh marked 2 inline comments as done. danielcdh added a comment. updated the patch to put it into function attribute so that it works with ThinLTO https://reviews.llvm.org/D37091 Files: docs/ClangCommandLineReference.rst include/clang/Driver/Options.td include/clang/Frontend/CodeGenOptions.def lib/CodeGen/CodeGenFunction.cpp lib/Driver/ToolChains/Clang.cpp lib/Frontend/CompilerInvocation.cpp test/Driver/clang_f_opts.c Index: test/Driver/clang_f_opts.c === --- test/Driver/clang_f_opts.c +++ test/Driver/clang_f_opts.c @@ -53,6 +53,9 @@ // CHECK-REROLL-LOOPS: "-freroll-loops" // CHECK-NO-REROLL-LOOPS-NOT: "-freroll-loops" +// RUN: %clang -### -S -faccurate-sample-profile %s 2>&1 | FileCheck -check-prefix=CHECK-ACCURATE-SAMPLE-PROFILE %s +// CHECK-ACCURATE-SAMPLE-PROFILE: "-faccurate-sample-profile" + // RUN: %clang -### -S -fprofile-sample-use=%S/Inputs/file.prof %s 2>&1 | FileCheck -check-prefix=CHECK-SAMPLE-PROFILE %s // CHECK-SAMPLE-PROFILE: "-fprofile-sample-use={{.*}}/file.prof" Index: lib/Frontend/CompilerInvocation.cpp === --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -652,6 +652,8 @@ Opts.NoUseJumpTables = Args.hasArg(OPT_fno_jump_tables); + Opts.AccurateSampleProfile = Args.hasArg(OPT_faccurate_sample_profile); + Opts.PrepareForLTO = Args.hasArg(OPT_flto, OPT_flto_EQ); Opts.EmitSummaryIndex = false; if (Arg *A = Args.getLastArg(OPT_flto_EQ)) { Index: lib/Driver/ToolChains/Clang.cpp === --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -2340,6 +2340,10 @@ true)) CmdArgs.push_back("-fno-jump-tables"); + if (Args.hasFlag(options::OPT_faccurate_sample_profile, + options::OPT_fno_accurate_sample_profile, false)) +CmdArgs.push_back("-faccurate-sample-profile"); + if (!Args.hasFlag(options::OPT_fpreserve_as_comments, options::OPT_fno_preserve_as_comments, true)) CmdArgs.push_back("-fno-preserve-as-comments"); Index: lib/CodeGen/CodeGenFunction.cpp === --- lib/CodeGen/CodeGenFunction.cpp +++ lib/CodeGen/CodeGenFunction.cpp @@ -837,6 +837,10 @@ Fn->addFnAttr("no-jump-tables", llvm::toStringRef(CGM.getCodeGenOpts().NoUseJumpTables)); + // Add accurate-sample-profile value. + if (CGM.getCodeGenOpts().AccurateSampleProfile) +Fn->addFnAttr("accurate-sample-profile"); + if (getLangOpts().OpenCL) { // Add metadata for a kernel function. if (const FunctionDecl *FD = dyn_cast_or_null(D)) Index: include/clang/Frontend/CodeGenOptions.def === --- include/clang/Frontend/CodeGenOptions.def +++ include/clang/Frontend/CodeGenOptions.def @@ -183,6 +183,7 @@ CODEGENOPT(UnwindTables , 1, 0) ///< Emit unwind tables. CODEGENOPT(VectorizeLoop , 1, 0) ///< Run loop vectorizer. CODEGENOPT(VectorizeSLP , 1, 0) ///< Run SLP vectorizer. +CODEGENOPT(AccurateSampleProfile, 1, 0) ///< Sample profile is accurate. /// Attempt to use register sized accesses to bit-fields in structures, when /// possible. Index: include/clang/Driver/Options.td === --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -587,6 +587,14 @@ def fPIE : Flag<["-"], "fPIE">, Group; def fno_PIE : Flag<["-"], "fno-PIE">, Group; def faccess_control : Flag<["-"], "faccess-control">, Group; +def faccurate_sample_profile : Flag<["-"], "faccurate-sample-profile">, + Group, Flags<[DriverOption, CC1Option]>, + HelpText<"If sample profile is accurate, we will mark all un-sampled " + "callsite as cold. Otherwise, treat callsites without profile " + "samples as if we have no profile">; +def fno_accurate_sample_profile : Flag<["-"], "fno-accurate-sample-profile">, + Group, Flags<[DriverOption]>; + def fallow_unsupported : Flag<["-"], "fallow-unsupported">, Group; def fapple_kext : Flag<["-"], "fapple-kext">, Group, Flags<[CC1Option]>, HelpText<"Use Apple's kernel extensions ABI">; @@ -643,6 +651,10 @@ Alias; def fauto_profile_EQ : Joined<["-"], "fauto-profile=">, Alias; +def fauto_profile_accurate : Flag<["-"], "fauto-profile-accurate">, +Group, Alias; +def fno_auto_profile_accurate : Flag<["-"], "fno-auto-profile-accurate">, +Group, Alias; def fdebug_info_for_profiling : Flag<["-"], "fdebug-info-for-profiling">, Group, Flags<[CC1Option]>, HelpText<"Emit extra debug info to make sample profile more accurate.">; Index: docs/ClangCommandLineReference.rst === --
[PATCH] D37091: Expose -mllvm -accurate-sample-profile to clang.
danielcdh updated this revision to Diff 112597. danielcdh marked 3 inline comments as done. danielcdh added a comment. update https://reviews.llvm.org/D37091 Files: include/clang/Driver/Options.td include/clang/Frontend/CodeGenOptions.def lib/CodeGen/CodeGenFunction.cpp lib/Driver/ToolChains/Clang.cpp lib/Frontend/CompilerInvocation.cpp test/Driver/clang_f_opts.c Index: test/Driver/clang_f_opts.c === --- test/Driver/clang_f_opts.c +++ test/Driver/clang_f_opts.c @@ -53,6 +53,9 @@ // CHECK-REROLL-LOOPS: "-freroll-loops" // CHECK-NO-REROLL-LOOPS-NOT: "-freroll-loops" +// RUN: %clang -### -S -fprofile-sample-accurate %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-SAMPLE-ACCURATE %s +// CHECK-PROFILE-SAMPLE-ACCURATE: "-fprofile-sample-accurate" + // RUN: %clang -### -S -fprofile-sample-use=%S/Inputs/file.prof %s 2>&1 | FileCheck -check-prefix=CHECK-SAMPLE-PROFILE %s // CHECK-SAMPLE-PROFILE: "-fprofile-sample-use={{.*}}/file.prof" Index: lib/Frontend/CompilerInvocation.cpp === --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -652,6 +652,8 @@ Opts.NoUseJumpTables = Args.hasArg(OPT_fno_jump_tables); + Opts.ProfileSampleAccurate = Args.hasArg(OPT_fprofile_sample_accurate); + Opts.PrepareForLTO = Args.hasArg(OPT_flto, OPT_flto_EQ); Opts.EmitSummaryIndex = false; if (Arg *A = Args.getLastArg(OPT_flto_EQ)) { Index: lib/Driver/ToolChains/Clang.cpp === --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -2340,6 +2340,10 @@ true)) CmdArgs.push_back("-fno-jump-tables"); + if (Args.hasFlag(options::OPT_fprofile_sample_accurate, + options::OPT_fno_profile_sample_accurate, false)) +CmdArgs.push_back("-fprofile-sample-accurate"); + if (!Args.hasFlag(options::OPT_fpreserve_as_comments, options::OPT_fno_preserve_as_comments, true)) CmdArgs.push_back("-fno-preserve-as-comments"); Index: lib/CodeGen/CodeGenFunction.cpp === --- lib/CodeGen/CodeGenFunction.cpp +++ lib/CodeGen/CodeGenFunction.cpp @@ -837,6 +837,10 @@ Fn->addFnAttr("no-jump-tables", llvm::toStringRef(CGM.getCodeGenOpts().NoUseJumpTables)); + // Add profile-sample-accurate value. + if (CGM.getCodeGenOpts().ProfileSampleAccurate) +Fn->addFnAttr("profile-sample-accurate"); + if (getLangOpts().OpenCL) { // Add metadata for a kernel function. if (const FunctionDecl *FD = dyn_cast_or_null(D)) Index: include/clang/Frontend/CodeGenOptions.def === --- include/clang/Frontend/CodeGenOptions.def +++ include/clang/Frontend/CodeGenOptions.def @@ -183,6 +183,7 @@ CODEGENOPT(UnwindTables , 1, 0) ///< Emit unwind tables. CODEGENOPT(VectorizeLoop , 1, 0) ///< Run loop vectorizer. CODEGENOPT(VectorizeSLP , 1, 0) ///< Run SLP vectorizer. +CODEGENOPT(ProfileSampleAccurate, 1, 0) ///< Sample profile is accurate. /// Attempt to use register sized accesses to bit-fields in structures, when /// possible. Index: include/clang/Driver/Options.td === --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -637,12 +637,25 @@ def fprofile_sample_use_EQ : Joined<["-"], "fprofile-sample-use=">, Group, Flags<[DriverOption, CC1Option]>, HelpText<"Enable sample-based profile guided optimizations">; +def fprofile_sample_accurate : Flag<["-"], "fprofile-sample-accurate">, +Group, Flags<[DriverOption, CC1Option]>, +HelpText<"Specifies that the sample profile is accurate">, +DocBrief<[{Specifies that the sample profile is accurate. If the sample + profile is accurate, callsites without profile samples are marked + as cold. Otherwise, treat callsites without profile samples as if + we have no profile}]>; +def fno_profile_sample_accurate : Flag<["-"], "fno-profile-sample-accurate">, + Group, Flags<[DriverOption]>; def fauto_profile : Flag<["-"], "fauto-profile">, Group, Alias; def fno_auto_profile : Flag<["-"], "fno-auto-profile">, Group, Alias; def fauto_profile_EQ : Joined<["-"], "fauto-profile=">, Alias; +def fauto_profile_accurate : Flag<["-"], "fauto-profile-accurate">, +Group, Alias; +def fno_auto_profile_accurate : Flag<["-"], "fno-auto-profile-accurate">, +Group, Alias; def fdebug_info_for_profiling : Flag<["-"], "fdebug-info-for-profiling">, Group, Flags<[CC1Option]>, HelpText<"Emit extra debug info to make sample profile more accurate.">; Index: test/Driver/clang_f_opts.c === --- test/Drive
[PATCH] D37091: Expose -mllvm -accurate-sample-profile to clang.
danielcdh updated this revision to Diff 112601. danielcdh added a comment. Herald added subscribers: eraman, mehdi_amini. Add an end-to-end test. https://reviews.llvm.org/D37091 Files: include/clang/Driver/Options.td include/clang/Frontend/CodeGenOptions.def lib/CodeGen/CodeGenFunction.cpp lib/Driver/ToolChains/Clang.cpp lib/Frontend/CompilerInvocation.cpp test/CodeGen/thinlto-profile-sample-accurate.c test/Driver/clang_f_opts.c Index: test/Driver/clang_f_opts.c === --- test/Driver/clang_f_opts.c +++ test/Driver/clang_f_opts.c @@ -53,6 +53,9 @@ // CHECK-REROLL-LOOPS: "-freroll-loops" // CHECK-NO-REROLL-LOOPS-NOT: "-freroll-loops" +// RUN: %clang -### -S -fprofile-sample-accurate %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-SAMPLE-ACCURATE %s +// CHECK-PROFILE-SAMPLE-ACCURATE: "-fprofile-sample-accurate" + // RUN: %clang -### -S -fprofile-sample-use=%S/Inputs/file.prof %s 2>&1 | FileCheck -check-prefix=CHECK-SAMPLE-PROFILE %s // CHECK-SAMPLE-PROFILE: "-fprofile-sample-use={{.*}}/file.prof" Index: test/CodeGen/thinlto-profile-sample-accurate.c === --- /dev/null +++ test/CodeGen/thinlto-profile-sample-accurate.c @@ -0,0 +1,9 @@ +// Test to ensure -emit-llvm profile-sample-accurate is honored in ThinLTO. +// RUN: %clang -O2 %s -flto=thin -fprofile-sample-accurate -c -o %t.o +// RUN: llvm-lto -thinlto -o %t %t.o +// RUN: %clang_cc1 -O2 -x ir %t.o -fthinlto-index=%t.thinlto.bc -emit-llvm -o - | FileCheck %s + +// CHECK: define void @foo() +// CHECK: attributes {{.*}} "profile-sample-accurate" +void foo() { +} Index: lib/Frontend/CompilerInvocation.cpp === --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -652,6 +652,8 @@ Opts.NoUseJumpTables = Args.hasArg(OPT_fno_jump_tables); + Opts.ProfileSampleAccurate = Args.hasArg(OPT_fprofile_sample_accurate); + Opts.PrepareForLTO = Args.hasArg(OPT_flto, OPT_flto_EQ); Opts.EmitSummaryIndex = false; if (Arg *A = Args.getLastArg(OPT_flto_EQ)) { Index: lib/Driver/ToolChains/Clang.cpp === --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -2340,6 +2340,10 @@ true)) CmdArgs.push_back("-fno-jump-tables"); + if (Args.hasFlag(options::OPT_fprofile_sample_accurate, + options::OPT_fno_profile_sample_accurate, false)) +CmdArgs.push_back("-fprofile-sample-accurate"); + if (!Args.hasFlag(options::OPT_fpreserve_as_comments, options::OPT_fno_preserve_as_comments, true)) CmdArgs.push_back("-fno-preserve-as-comments"); Index: lib/CodeGen/CodeGenFunction.cpp === --- lib/CodeGen/CodeGenFunction.cpp +++ lib/CodeGen/CodeGenFunction.cpp @@ -837,6 +837,10 @@ Fn->addFnAttr("no-jump-tables", llvm::toStringRef(CGM.getCodeGenOpts().NoUseJumpTables)); + // Add profile-sample-accurate value. + if (CGM.getCodeGenOpts().ProfileSampleAccurate) +Fn->addFnAttr("profile-sample-accurate"); + if (getLangOpts().OpenCL) { // Add metadata for a kernel function. if (const FunctionDecl *FD = dyn_cast_or_null(D)) Index: include/clang/Frontend/CodeGenOptions.def === --- include/clang/Frontend/CodeGenOptions.def +++ include/clang/Frontend/CodeGenOptions.def @@ -183,6 +183,7 @@ CODEGENOPT(UnwindTables , 1, 0) ///< Emit unwind tables. CODEGENOPT(VectorizeLoop , 1, 0) ///< Run loop vectorizer. CODEGENOPT(VectorizeSLP , 1, 0) ///< Run SLP vectorizer. +CODEGENOPT(ProfileSampleAccurate, 1, 0) ///< Sample profile is accurate. /// Attempt to use register sized accesses to bit-fields in structures, when /// possible. Index: include/clang/Driver/Options.td === --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -637,12 +637,25 @@ def fprofile_sample_use_EQ : Joined<["-"], "fprofile-sample-use=">, Group, Flags<[DriverOption, CC1Option]>, HelpText<"Enable sample-based profile guided optimizations">; +def fprofile_sample_accurate : Flag<["-"], "fprofile-sample-accurate">, +Group, Flags<[DriverOption, CC1Option]>, +HelpText<"Specifies that the sample profile is accurate">, +DocBrief<[{Specifies that the sample profile is accurate. If the sample + profile is accurate, callsites without profile samples are marked + as cold. Otherwise, treat callsites without profile samples as if + we have no profile}]>; +def fno_profile_sample_accurate : Flag<["-"], "fno-profile-sample-accurate">, + Group, Flags<[DriverOption]>; def fauto_profile : Flag<["-"], "fauto-profile"
[PATCH] D37091: Expose -mllvm -accurate-sample-profile to clang.
danielcdh updated this revision to Diff 112604. danielcdh marked an inline comment as done. danielcdh added a comment. update https://reviews.llvm.org/D37091 Files: include/clang/Driver/Options.td include/clang/Frontend/CodeGenOptions.def lib/CodeGen/CodeGenFunction.cpp lib/Driver/ToolChains/Clang.cpp lib/Frontend/CompilerInvocation.cpp test/CodeGen/profile-sample-accurate.c test/Driver/clang_f_opts.c test/Integration/thinlto_profile_sample_accurate.c Index: test/Integration/thinlto_profile_sample_accurate.c === --- /dev/null +++ test/Integration/thinlto_profile_sample_accurate.c @@ -0,0 +1,9 @@ +// Test to ensure -emit-llvm profile-sample-accurate is honored in ThinLTO. +// RUN: %clang -O2 %s -flto=thin -fprofile-sample-accurate -c -o %t.o +// RUN: llvm-lto -thinlto -o %t %t.o +// RUN: %clang_cc1 -O2 -x ir %t.o -fthinlto-index=%t.thinlto.bc -emit-llvm -o - | FileCheck %s + +// CHECK: define void @foo() +// CHECK: attributes {{.*}} "profile-sample-accurate" +void foo() { +} Index: test/Driver/clang_f_opts.c === --- test/Driver/clang_f_opts.c +++ test/Driver/clang_f_opts.c @@ -53,6 +53,9 @@ // CHECK-REROLL-LOOPS: "-freroll-loops" // CHECK-NO-REROLL-LOOPS-NOT: "-freroll-loops" +// RUN: %clang -### -S -fprofile-sample-accurate %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-SAMPLE-ACCURATE %s +// CHECK-PROFILE-SAMPLE-ACCURATE: "-fprofile-sample-accurate" + // RUN: %clang -### -S -fprofile-sample-use=%S/Inputs/file.prof %s 2>&1 | FileCheck -check-prefix=CHECK-SAMPLE-PROFILE %s // CHECK-SAMPLE-PROFILE: "-fprofile-sample-use={{.*}}/file.prof" Index: test/CodeGen/profile-sample-accurate.c === --- /dev/null +++ test/CodeGen/profile-sample-accurate.c @@ -0,0 +1,7 @@ +// Test to ensure -emit-llvm profile-sample-accurate is honored by clang. +// RUN: %clang -S -emit-llvm %s -fprofile-sample-accurate -o - | FileCheck %s + +// CHECK: define void @foo() +// CHECK: attributes {{.*}} "profile-sample-accurate" +void foo() { +} Index: lib/Frontend/CompilerInvocation.cpp === --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -652,6 +652,8 @@ Opts.NoUseJumpTables = Args.hasArg(OPT_fno_jump_tables); + Opts.ProfileSampleAccurate = Args.hasArg(OPT_fprofile_sample_accurate); + Opts.PrepareForLTO = Args.hasArg(OPT_flto, OPT_flto_EQ); Opts.EmitSummaryIndex = false; if (Arg *A = Args.getLastArg(OPT_flto_EQ)) { Index: lib/Driver/ToolChains/Clang.cpp === --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -2340,6 +2340,10 @@ true)) CmdArgs.push_back("-fno-jump-tables"); + if (Args.hasFlag(options::OPT_fprofile_sample_accurate, + options::OPT_fno_profile_sample_accurate, false)) +CmdArgs.push_back("-fprofile-sample-accurate"); + if (!Args.hasFlag(options::OPT_fpreserve_as_comments, options::OPT_fno_preserve_as_comments, true)) CmdArgs.push_back("-fno-preserve-as-comments"); Index: lib/CodeGen/CodeGenFunction.cpp === --- lib/CodeGen/CodeGenFunction.cpp +++ lib/CodeGen/CodeGenFunction.cpp @@ -837,6 +837,10 @@ Fn->addFnAttr("no-jump-tables", llvm::toStringRef(CGM.getCodeGenOpts().NoUseJumpTables)); + // Add profile-sample-accurate value. + if (CGM.getCodeGenOpts().ProfileSampleAccurate) +Fn->addFnAttr("profile-sample-accurate"); + if (getLangOpts().OpenCL) { // Add metadata for a kernel function. if (const FunctionDecl *FD = dyn_cast_or_null(D)) Index: include/clang/Frontend/CodeGenOptions.def === --- include/clang/Frontend/CodeGenOptions.def +++ include/clang/Frontend/CodeGenOptions.def @@ -183,6 +183,7 @@ CODEGENOPT(UnwindTables , 1, 0) ///< Emit unwind tables. CODEGENOPT(VectorizeLoop , 1, 0) ///< Run loop vectorizer. CODEGENOPT(VectorizeSLP , 1, 0) ///< Run SLP vectorizer. +CODEGENOPT(ProfileSampleAccurate, 1, 0) ///< Sample profile is accurate. /// Attempt to use register sized accesses to bit-fields in structures, when /// possible. Index: include/clang/Driver/Options.td === --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -637,12 +637,25 @@ def fprofile_sample_use_EQ : Joined<["-"], "fprofile-sample-use=">, Group, Flags<[DriverOption, CC1Option]>, HelpText<"Enable sample-based profile guided optimizations">; +def fprofile_sample_accurate : Flag<["-"], "fprofile-sample-accurate">, +Group, Flags<[DriverOption, CC1Option]>, +HelpText<"Specifies t
[PATCH] D39923: [ThinLTO] Handle -fdebug-pass-manager for backend invocations via clang
danielcdh accepted this revision. danielcdh added a comment. This revision is now accepted and ready to land. Thanks for the fix. https://reviews.llvm.org/D39923 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D27744: Create SampleProfileLoader pass in llvm instead of clang
danielcdh reopened this revision. danielcdh added a comment. This revision is now accepted and ready to land. was reverted due to bot breaking https://reviews.llvm.org/D27744 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D25435: Add -femit-accurate-debug-info to emit more debug info for sample pgo profile collection
danielcdh updated this revision to Diff 81609. danielcdh added a comment. update option name https://reviews.llvm.org/D25435 Files: include/clang/Driver/Options.td include/clang/Frontend/CodeGenOptions.def lib/CodeGen/BackendUtil.cpp lib/CodeGen/CGDebugInfo.cpp lib/Driver/Tools.cpp lib/Frontend/CompilerInvocation.cpp test/Driver/clang_f_opts.c Index: test/Driver/clang_f_opts.c === --- test/Driver/clang_f_opts.c +++ test/Driver/clang_f_opts.c @@ -469,3 +469,8 @@ // CHECK-WCHAR2: -fshort-wchar // CHECK-WCHAR2-NOT: -fno-short-wchar // DELIMITERS: {{^ *"}} + +// RUN: %clang -### -S -fno-debug-info-for-profiling -fdebug-info-for-profiling %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-DEBUG %s +// RUN: %clang -### -S -fdebug-info-for-profiling -fno-debug-info-for-profiling %s 2>&1 | FileCheck -check-prefix=CHECK-NO-PROFILE-DEBUG %s +// CHECK-PROFILE-DEBUG: -fdebug-info-for-profiling +// CHECK-NO-PROFILE-DEBUG-NOT: -fdebug-info-for-profiling Index: lib/Frontend/CompilerInvocation.cpp === --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -538,6 +538,8 @@ Opts.DisableIntegratedAS = Args.hasArg(OPT_fno_integrated_as); Opts.Autolink = !Args.hasArg(OPT_fno_autolink); Opts.SampleProfileFile = Args.getLastArgValue(OPT_fprofile_sample_use_EQ); + Opts.DebugInfoForProfiling = Args.hasFlag( + OPT_fdebug_info_for_profiling, OPT_fno_debug_info_for_profiling, false); setPGOInstrumentor(Opts, Args, Diags); Opts.InstrProfileOutput = Index: lib/Driver/Tools.cpp === --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -5565,6 +5565,10 @@ A->render(Args, CmdArgs); } + if (Args.hasFlag(options::OPT_fdebug_info_for_profiling, + options::OPT_fno_debug_info_for_profiling, false)) +CmdArgs.push_back("-fdebug-info-for-profiling"); + // -fbuiltin is default unless -mkernel is used. bool UseBuiltins = Args.hasFlag(options::OPT_fbuiltin, options::OPT_fno_builtin, Index: lib/CodeGen/CGDebugInfo.cpp === --- lib/CodeGen/CGDebugInfo.cpp +++ lib/CodeGen/CGDebugInfo.cpp @@ -2741,9 +2741,10 @@ } // No need to replicate the linkage name if it isn't different from the // subprogram name, no need to have it at all unless coverage is enabled or - // debug is set to more than just line tables. + // debug is set to more than just line tables or extra debug info is needed. if (LinkageName == Name || (!CGM.getCodeGenOpts().EmitGcovArcs && !CGM.getCodeGenOpts().EmitGcovNotes && + !CGM.getCodeGenOpts().DebugInfoForProfiling && DebugKind <= codegenoptions::DebugLineTablesOnly)) LinkageName = StringRef(); Index: lib/CodeGen/BackendUtil.cpp === --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -575,6 +575,7 @@ Options.DisableIntegratedAS = CodeGenOpts.DisableIntegratedAS; Options.CompressDebugSections = CodeGenOpts.CompressDebugSections; Options.RelaxELFRelocations = CodeGenOpts.RelaxELFRelocations; + Options.DebugInfoForProfiling = CodeGenOpts.DebugInfoForProfiling; // Set EABI version. Options.EABIVersion = llvm::StringSwitch(TargetOpts.EABIVersion) Index: include/clang/Frontend/CodeGenOptions.def === --- include/clang/Frontend/CodeGenOptions.def +++ include/clang/Frontend/CodeGenOptions.def @@ -255,6 +255,9 @@ /// Whether copy relocations support is available when building as PIE. CODEGENOPT(PIECopyRelocations, 1, 0) +/// Whether emit extra debug info for sample pgo profile collection. +CODEGENOPT(DebugInfoForProfiling, 1, 0) + #undef CODEGENOPT #undef ENUM_CODEGENOPT #undef VALUE_CODEGENOPT Index: include/clang/Driver/Options.td === --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -514,6 +514,12 @@ HelpText<"Enable sample-based profile guided optimizations">; def fauto_profile_EQ : Joined<["-"], "fauto-profile=">, Alias; +def fdebug_info_for_profiling : Flag<["-"], "fdebug-info-for-profiling">, Group, +Flags<[CC1Option]>, +HelpText<"Emit extra debug info to make sample profile more accurate.">; +def fno_debug_info_for_profiling : Flag<["-"], "fno-debug-info-for-profiling">, Group, +Flags<[DriverOption]>, +HelpText<"Do not emit extra debug info for sample profiler.">; def fprofile_instr_generate : Flag<["-"], "fprofile-instr-generate">, Group, Flags<[CoreOption]>, HelpText<"Generate instrumented code to collect execution counts into default.profraw file (overriden by '=
[PATCH] D27832: Add -plugin-opt=sample-profile for thinLTO build.
danielcdh created this revision. danielcdh added reviewers: tejohnson, mehdi_amini, davidxl. danielcdh added a subscriber: cfe-commits. ThinLTO needs to pass down the sample profile file path to linker. https://reviews.llvm.org/D27832 Files: lib/Driver/Tools.cpp Index: lib/Driver/Tools.cpp === --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -2206,6 +2206,14 @@ UseSeparateSections)) { CmdArgs.push_back("-plugin-opt=-data-sections"); } + + if (Arg *A = Args.getLastArg(options::OPT_fprofile_sample_use_EQ)) { +StringRef fname = A->getValue(); +if (!llvm::sys::fs::exists(fname)) + D.Diag(diag::err_drv_no_such_file) << fname; +else + CmdArgs.push_back(Args.MakeArgString(Twine("-plugin-opt=sample-profile=") + fname)); + } } /// This is a helper function for validating the optional refinement step Index: lib/Driver/Tools.cpp === --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -2206,6 +2206,14 @@ UseSeparateSections)) { CmdArgs.push_back("-plugin-opt=-data-sections"); } + + if (Arg *A = Args.getLastArg(options::OPT_fprofile_sample_use_EQ)) { +StringRef fname = A->getValue(); +if (!llvm::sys::fs::exists(fname)) + D.Diag(diag::err_drv_no_such_file) << fname; +else + CmdArgs.push_back(Args.MakeArgString(Twine("-plugin-opt=sample-profile=") + fname)); + } } /// This is a helper function for validating the optional refinement step ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D27832: Add -plugin-opt=sample-profile for thinLTO build.
danielcdh updated this revision to Diff 81759. danielcdh added a comment. add a test. https://reviews.llvm.org/D27832 Files: lib/Driver/Tools.cpp test/Driver/gold-lto-samplepgo.c Index: test/Driver/gold-lto-samplepgo.c === --- /dev/null +++ test/Driver/gold-lto-samplepgo.c @@ -0,0 +1,7 @@ +// RUN: touch %t.o +// +// RUN: %clang -target x86_64-unknown-linux -### %t.o -flto 2>&1 \ +// RUN: -Wl,-plugin-opt=foo -O3 \ +// RUN: -fprofile-sample-use=%s \ +// RUN: | FileCheck %s +// CHECK: -plugin-opt=sample-profile= Index: lib/Driver/Tools.cpp === --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -2206,6 +2206,15 @@ UseSeparateSections)) { CmdArgs.push_back("-plugin-opt=-data-sections"); } + + if (Arg *A = Args.getLastArg(options::OPT_fprofile_sample_use_EQ)) { +StringRef fname = A->getValue(); +if (!llvm::sys::fs::exists(fname)) + D.Diag(diag::err_drv_no_such_file) << fname; +else + CmdArgs.push_back( + Args.MakeArgString(Twine("-plugin-opt=sample-profile=") + fname)); + } } /// This is a helper function for validating the optional refinement step Index: test/Driver/gold-lto-samplepgo.c === --- /dev/null +++ test/Driver/gold-lto-samplepgo.c @@ -0,0 +1,7 @@ +// RUN: touch %t.o +// +// RUN: %clang -target x86_64-unknown-linux -### %t.o -flto 2>&1 \ +// RUN: -Wl,-plugin-opt=foo -O3 \ +// RUN: -fprofile-sample-use=%s \ +// RUN: | FileCheck %s +// CHECK: -plugin-opt=sample-profile= Index: lib/Driver/Tools.cpp === --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -2206,6 +2206,15 @@ UseSeparateSections)) { CmdArgs.push_back("-plugin-opt=-data-sections"); } + + if (Arg *A = Args.getLastArg(options::OPT_fprofile_sample_use_EQ)) { +StringRef fname = A->getValue(); +if (!llvm::sys::fs::exists(fname)) + D.Diag(diag::err_drv_no_such_file) << fname; +else + CmdArgs.push_back( + Args.MakeArgString(Twine("-plugin-opt=sample-profile=") + fname)); + } } /// This is a helper function for validating the optional refinement step ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D25435: Add -femit-accurate-debug-info to emit more debug info for sample pgo profile collection
danielcdh added a comment. ping... Thanks, Dehao https://reviews.llvm.org/D25435 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D27832: Add -plugin-opt=sample-profile for thinLTO build.
danielcdh updated this revision to Diff 82975. danielcdh added a comment. fix function name https://reviews.llvm.org/D27832 Files: lib/Driver/Tools.cpp test/Driver/gold-lto-samplepgo.c Index: test/Driver/gold-lto-samplepgo.c === --- /dev/null +++ test/Driver/gold-lto-samplepgo.c @@ -0,0 +1,7 @@ +// RUN: touch %t.o +// +// RUN: %clang -target x86_64-unknown-linux -### %t.o -flto 2>&1 \ +// RUN: -Wl,-plugin-opt=foo -O3 \ +// RUN: -fprofile-sample-use=%s \ +// RUN: | FileCheck %s +// CHECK: -plugin-opt=sample-profile= Index: lib/Driver/Tools.cpp === --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -2235,6 +2235,15 @@ UseSeparateSections)) { CmdArgs.push_back("-plugin-opt=-data-sections"); } + + if (Arg *A = Args.getLastArg(options::OPT_fprofile_sample_use_EQ)) { +StringRef FName = A->getValue(); +if (!llvm::sys::fs::exists(FName)) + D.Diag(diag::err_drv_no_such_file) << FName; +else + CmdArgs.push_back( + Args.MakeArgString(Twine("-plugin-opt=sample-profile=") + FName)); + } } /// This is a helper function for validating the optional refinement step Index: test/Driver/gold-lto-samplepgo.c === --- /dev/null +++ test/Driver/gold-lto-samplepgo.c @@ -0,0 +1,7 @@ +// RUN: touch %t.o +// +// RUN: %clang -target x86_64-unknown-linux -### %t.o -flto 2>&1 \ +// RUN: -Wl,-plugin-opt=foo -O3 \ +// RUN: -fprofile-sample-use=%s \ +// RUN: | FileCheck %s +// CHECK: -plugin-opt=sample-profile= Index: lib/Driver/Tools.cpp === --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -2235,6 +2235,15 @@ UseSeparateSections)) { CmdArgs.push_back("-plugin-opt=-data-sections"); } + + if (Arg *A = Args.getLastArg(options::OPT_fprofile_sample_use_EQ)) { +StringRef FName = A->getValue(); +if (!llvm::sys::fs::exists(FName)) + D.Diag(diag::err_drv_no_such_file) << FName; +else + CmdArgs.push_back( + Args.MakeArgString(Twine("-plugin-opt=sample-profile=") + FName)); + } } /// This is a helper function for validating the optional refinement step ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D25435: Add -fdebug-info-for-profiling to emit more debug info for sample pgo profile collection
danielcdh added a comment. Thanks David for the reivew. Could you also help take a look at https://reviews.llvm.org/D25434, as it depends on the TargetOptions.h change in that patch. Thanks, Dehao https://reviews.llvm.org/D25435 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D28588: Pass -fprofile-sample-use to lto backends.
danielcdh created this revision. danielcdh added reviewers: tejohnson, mehdi_amini. danielcdh added a subscriber: cfe-commits. LTO backend will not invoke SampleProfileLoader pass even if -fprofile-sample-use is specified. This patch passes the flag down so that pass manager can add the SampleProfileLoader pass correctly. https://reviews.llvm.org/D28588 Files: lib/CodeGen/BackendUtil.cpp test/CodeGen/thinlto_backend.ll Index: test/CodeGen/thinlto_backend.ll === --- test/CodeGen/thinlto_backend.ll +++ test/CodeGen/thinlto_backend.ll @@ -8,6 +8,10 @@ ; RUN: not %clang_cc1 -O2 -o %t1.o -x c %s -c -fthinlto-index=%t.thinlto.bc 2>&1 | FileCheck %s -check-prefix=CHECK-WARNING ; CHECK-WARNING: error: invalid argument '-fthinlto-index={{.*}}' only allowed with '-x ir' +; Ensure sample profile pass are passed to backend +; RUN: %clang -O2 -o %t4.o -x ir %t1.o -c -fthinlto-index=%t.thinlto.bc -fprofile-sample-use=%S/Inputs/pgo-sample.prof -mllvm -debug-pass=Structure 2>&1 | FileCheck %s -check-prefix=CHECK-SAMPLEPGO +; CHECK-SAMPLEPGO: Sample profile pass + ; Ensure we get expected error for missing index file ; RUN: %clang -O2 -o %t4.o -x ir %t1.o -c -fthinlto-index=bad.thinlto.bc 2>&1 | FileCheck %s -check-prefix=CHECK-ERROR1 ; CHECK-ERROR1: Error loading index file 'bad.thinlto.bc' Index: lib/CodeGen/BackendUtil.cpp === --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -862,7 +862,8 @@ } static void runThinLTOBackend(ModuleSummaryIndex *CombinedIndex, Module *M, - std::unique_ptr OS) { + std::unique_ptr OS, + std::string SampleProfile) { StringMap> ModuleToDefinedGVSummaries; CombinedIndex->collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries); @@ -930,6 +931,7 @@ return llvm::make_unique(std::move(OS)); }; lto::Config Conf; + Conf.SampleProfile = SampleProfile; if (Error E = thinBackend( Conf, 0, AddStream, *M, *CombinedIndex, ImportList, ModuleToDefinedGVSummaries[M->getModuleIdentifier()], ModuleMap)) { @@ -965,7 +967,8 @@ // of an error). bool DoThinLTOBackend = CombinedIndex != nullptr; if (DoThinLTOBackend) { - runThinLTOBackend(CombinedIndex.get(), M, std::move(OS)); + runThinLTOBackend(CombinedIndex.get(), M, std::move(OS), +CGOpts.SampleProfileFile); return; } } Index: test/CodeGen/thinlto_backend.ll === --- test/CodeGen/thinlto_backend.ll +++ test/CodeGen/thinlto_backend.ll @@ -8,6 +8,10 @@ ; RUN: not %clang_cc1 -O2 -o %t1.o -x c %s -c -fthinlto-index=%t.thinlto.bc 2>&1 | FileCheck %s -check-prefix=CHECK-WARNING ; CHECK-WARNING: error: invalid argument '-fthinlto-index={{.*}}' only allowed with '-x ir' +; Ensure sample profile pass are passed to backend +; RUN: %clang -O2 -o %t4.o -x ir %t1.o -c -fthinlto-index=%t.thinlto.bc -fprofile-sample-use=%S/Inputs/pgo-sample.prof -mllvm -debug-pass=Structure 2>&1 | FileCheck %s -check-prefix=CHECK-SAMPLEPGO +; CHECK-SAMPLEPGO: Sample profile pass + ; Ensure we get expected error for missing index file ; RUN: %clang -O2 -o %t4.o -x ir %t1.o -c -fthinlto-index=bad.thinlto.bc 2>&1 | FileCheck %s -check-prefix=CHECK-ERROR1 ; CHECK-ERROR1: Error loading index file 'bad.thinlto.bc' Index: lib/CodeGen/BackendUtil.cpp === --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -862,7 +862,8 @@ } static void runThinLTOBackend(ModuleSummaryIndex *CombinedIndex, Module *M, - std::unique_ptr OS) { + std::unique_ptr OS, + std::string SampleProfile) { StringMap> ModuleToDefinedGVSummaries; CombinedIndex->collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries); @@ -930,6 +931,7 @@ return llvm::make_unique(std::move(OS)); }; lto::Config Conf; + Conf.SampleProfile = SampleProfile; if (Error E = thinBackend( Conf, 0, AddStream, *M, *CombinedIndex, ImportList, ModuleToDefinedGVSummaries[M->getModuleIdentifier()], ModuleMap)) { @@ -965,7 +967,8 @@ // of an error). bool DoThinLTOBackend = CombinedIndex != nullptr; if (DoThinLTOBackend) { - runThinLTOBackend(CombinedIndex.get(), M, std::move(OS)); + runThinLTOBackend(CombinedIndex.get(), M, std::move(OS), +CGOpts.SampleProfileFile); return; } } ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D31202: Clang change: Do not inline hot callsites for samplepgo in thinlto compile phase.
danielcdh created this revision. Herald added subscribers: Prazek, mehdi_amini. Because SamplePGO passes will be invoked twice in ThinLTO build: once at compile phase, the other at backend. We want to make sure the IR at the 2nd phase matches the hot part in pro file, thus we do not want to inline hot callsites in the first phase. https://reviews.llvm.org/D31202 Files: lib/CodeGen/BackendUtil.cpp test/CodeGen/Inputs/pgo-sample-thinlto-summary.prof test/CodeGen/pgo-sample-thinlto-summary.c Index: test/CodeGen/pgo-sample-thinlto-summary.c === --- /dev/null +++ test/CodeGen/pgo-sample-thinlto-summary.c @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=INLINE +// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -flto=thin -o - 2>&1 | FileCheck %s -check-prefix=NOINLINE +// Checks if hot call is inlined by normal compile, but not inlined by +// thinlto compile. + +int baz(int); +int g; + +void foo(int n) { + for (int i = 0; i < n; i++) +g += baz(i); +} + +// INLINE-NOT: call{{.*}}foo +// NOINLINE: call{{.*}}foo +void bar(int n) { + for (int i = 0; i < n; i++) +foo(i); +} Index: test/CodeGen/Inputs/pgo-sample-thinlto-summary.prof === --- /dev/null +++ test/CodeGen/Inputs/pgo-sample-thinlto-summary.prof @@ -0,0 +1,2 @@ +bar:100:100 + 2: 2000 foo:2000 Index: lib/CodeGen/BackendUtil.cpp === --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -318,8 +318,13 @@ !CodeGenOpts.DisableLifetimeMarkers); PMBuilder.Inliner = createAlwaysInlinerLegacyPass(InsertLifetimeIntrinsics); } else { +// We do not want to inline hot callsites for SamplePGO module-summary build +// because profile annotation will happen again in ThinLTO backend, and we +// want the IR of the hot path to match the profile. PMBuilder.Inliner = createFunctionInliningPass( -CodeGenOpts.OptimizationLevel, CodeGenOpts.OptimizeSize); +CodeGenOpts.OptimizationLevel, CodeGenOpts.OptimizeSize, +(!CodeGenOpts.SampleProfileFile.empty() && + CodeGenOpts.EmitSummaryIndex)); } PMBuilder.OptLevel = CodeGenOpts.OptimizationLevel; Index: test/CodeGen/pgo-sample-thinlto-summary.c === --- /dev/null +++ test/CodeGen/pgo-sample-thinlto-summary.c @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=INLINE +// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -flto=thin -o - 2>&1 | FileCheck %s -check-prefix=NOINLINE +// Checks if hot call is inlined by normal compile, but not inlined by +// thinlto compile. + +int baz(int); +int g; + +void foo(int n) { + for (int i = 0; i < n; i++) +g += baz(i); +} + +// INLINE-NOT: call{{.*}}foo +// NOINLINE: call{{.*}}foo +void bar(int n) { + for (int i = 0; i < n; i++) +foo(i); +} Index: test/CodeGen/Inputs/pgo-sample-thinlto-summary.prof === --- /dev/null +++ test/CodeGen/Inputs/pgo-sample-thinlto-summary.prof @@ -0,0 +1,2 @@ +bar:100:100 + 2: 2000 foo:2000 Index: lib/CodeGen/BackendUtil.cpp === --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -318,8 +318,13 @@ !CodeGenOpts.DisableLifetimeMarkers); PMBuilder.Inliner = createAlwaysInlinerLegacyPass(InsertLifetimeIntrinsics); } else { +// We do not want to inline hot callsites for SamplePGO module-summary build +// because profile annotation will happen again in ThinLTO backend, and we +// want the IR of the hot path to match the profile. PMBuilder.Inliner = createFunctionInliningPass( -CodeGenOpts.OptimizationLevel, CodeGenOpts.OptimizeSize); +CodeGenOpts.OptimizationLevel, CodeGenOpts.OptimizeSize, +(!CodeGenOpts.SampleProfileFile.empty() && + CodeGenOpts.EmitSummaryIndex)); } PMBuilder.OptLevel = CodeGenOpts.OptimizationLevel; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D31213: Add support for -fno-auto-profile and -fno-profile-sample-use
danielcdh created this revision. We need to be able to disable samplepgo for specific files by supporting -fno-auto-profile and -fno-profile-sample-use https://reviews.llvm.org/D31213 Files: include/clang/Driver/Options.td lib/Driver/ToolChains/Clang.cpp lib/Driver/ToolChains/CommonArgs.cpp lib/Driver/ToolChains/CommonArgs.h test/Driver/clang_f_opts.c Index: test/Driver/clang_f_opts.c === --- test/Driver/clang_f_opts.c +++ test/Driver/clang_f_opts.c @@ -59,6 +59,11 @@ // RUN: %clang -### -S -fauto-profile=%S/Inputs/file.prof %s 2>&1 | FileCheck -check-prefix=CHECK-AUTO-PROFILE %s // CHECK-AUTO-PROFILE: "-fprofile-sample-use={{.*}}/file.prof" +// RUN: %clang -### -S -fauto-profile=%S/Inputs/file.prof -fno-profile-sample-use %s 2>&1 | FileCheck -check-prefix=CHECK-NO-AUTO-PROFILE %s +// CHECK-NO-AUTO-PROFILE-NOT: "-fprofile-sample-use={{.*}}/file.prof" + +// RUN: %clang -### -S -fauto-profile=%S/Inputs/file.prof -fno-profile-sample-use -fauto-profile %s 2>&1 | FileCheck -check-prefix=CHECK-AUTO-PROFILE %s + // RUN: %clang -### -S -fprofile-arcs %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-ARCS %s // RUN: %clang -### -S -fno-profile-arcs -fprofile-arcs %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-ARCS %s // RUN: %clang -### -S -fno-profile-arcs %s 2>&1 | FileCheck -check-prefix=CHECK-NO-PROFILE-ARCS %s Index: lib/Driver/ToolChains/CommonArgs.h === --- lib/Driver/ToolChains/CommonArgs.h +++ lib/Driver/ToolChains/CommonArgs.h @@ -63,6 +63,7 @@ const llvm::opt::ArgList &Args); llvm::opt::Arg *getLastProfileUseArg(const llvm::opt::ArgList &Args); +llvm::opt::Arg *getLastProfileSampleUseArg(const llvm::opt::ArgList &Args); bool isObjCAutoRefCount(const llvm::opt::ArgList &Args); Index: lib/Driver/ToolChains/CommonArgs.cpp === --- lib/Driver/ToolChains/CommonArgs.cpp +++ lib/Driver/ToolChains/CommonArgs.cpp @@ -407,7 +407,7 @@ CmdArgs.push_back("-plugin-opt=-data-sections"); } - if (Arg *A = Args.getLastArg(options::OPT_fprofile_sample_use_EQ)) { + if (Arg *A = getLastProfileSampleUseArg(Args)) { StringRef FName = A->getValue(); if (!llvm::sys::fs::exists(FName)) D.Diag(diag::err_drv_no_such_file) << FName; @@ -673,6 +673,22 @@ return ProfileUseArg; } +Arg *tools::getLastProfileSampleUseArg(const ArgList &Args) { + auto *ProfileSampleUseArg = Args.getLastArg( + options::OPT_fprofile_sample_use, options::OPT_fprofile_sample_use_EQ, + options::OPT_fauto_profile, options::OPT_fauto_profile_EQ, + options::OPT_fno_profile_sample_use, options::OPT_fno_auto_profile); + + if (ProfileSampleUseArg && + (ProfileSampleUseArg->getOption().matches( + options::OPT_fno_profile_sample_use) || + ProfileSampleUseArg->getOption().matches(options::OPT_fno_auto_profile))) +return nullptr; + + return Args.getLastArg(options::OPT_fprofile_sample_use_EQ, + options::OPT_fauto_profile_EQ); +} + /// Parses the various -fpic/-fPIC/-fpie/-fPIE arguments. Then, /// smooshes them together with platform defaults, to decide whether /// this compile should be using PIC mode or not. Returns a tuple of Index: lib/Driver/ToolChains/Clang.cpp === --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -3431,7 +3431,7 @@ // Forward -f options with positive and negative forms; we translate // these by hand. - if (Arg *A = Args.getLastArg(options::OPT_fprofile_sample_use_EQ)) { + if (Arg *A = getLastProfileSampleUseArg(Args)) { StringRef fname = A->getValue(); if (!llvm::sys::fs::exists(fname)) D.Diag(diag::err_drv_no_such_file) << fname; Index: include/clang/Driver/Options.td === --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -613,9 +613,17 @@ Flags<[DriverOption, CC1Option]>, HelpText<"Disable GNU style inline asm">; +def fprofile_sample_use : Flag<["-"], "fprofile-sample-use">, Group, +Flags<[CoreOption]>; +def fno_profile_sample_use : Flag<["-"], "fno-profile-sample-use">, Group, +Flags<[CoreOption]>; def fprofile_sample_use_EQ : Joined<["-"], "fprofile-sample-use=">, Group, Flags<[DriverOption, CC1Option]>, HelpText<"Enable sample-based profile guided optimizations">; +def fauto_profile : Flag<["-"], "fauto-profile">, Group, +Alias; +def fno_auto_profile : Flag<["-"], "fno-auto-profile">, Group, +Alias; def fauto_profile_EQ : Joined<["-"], "fauto-profile=">, Alias; def fdebug_info_for_profiling : Flag<["-"], "fdebug-info-for-profiling">, Group, Index: test/Driver/clang_f_opts.c === --
[PATCH] D31213: Add support for -fno-auto-profile and -fno-profile-sample-use
danielcdh updated this revision to Diff 92554. danielcdh added a comment. add more test https://reviews.llvm.org/D31213 Files: include/clang/Driver/Options.td lib/Driver/ToolChains/Clang.cpp lib/Driver/ToolChains/CommonArgs.cpp lib/Driver/ToolChains/CommonArgs.h test/Driver/clang_f_opts.c Index: test/Driver/clang_f_opts.c === --- test/Driver/clang_f_opts.c +++ test/Driver/clang_f_opts.c @@ -59,6 +59,13 @@ // RUN: %clang -### -S -fauto-profile=%S/Inputs/file.prof %s 2>&1 | FileCheck -check-prefix=CHECK-AUTO-PROFILE %s // CHECK-AUTO-PROFILE: "-fprofile-sample-use={{.*}}/file.prof" +// RUN: %clang -### -S -fauto-profile=%S/Inputs/file.prof -fno-profile-sample-use %s 2>&1 | FileCheck -check-prefix=CHECK-NO-AUTO-PROFILE %s +// RUN: %clang -### -S -fauto-profile=%S/Inputs/file.prof -fno-auto-profile %s 2>&1 | FileCheck -check-prefix=CHECK-NO-AUTO-PROFILE %s +// CHECK-NO-AUTO-PROFILE-NOT: "-fprofile-sample-use={{.*}}/file.prof" + +// RUN: %clang -### -S -fauto-profile=%S/Inputs/file.prof -fno-profile-sample-use -fauto-profile %s 2>&1 | FileCheck -check-prefix=CHECK-AUTO-PROFILE %s +// RUN: %clang -### -S -fauto-profile=%S/Inputs/file.prof -fno-auto-profile -fprofile-sample-use %s 2>&1 | FileCheck -check-prefix=CHECK-AUTO-PROFILE %s + // RUN: %clang -### -S -fprofile-arcs %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-ARCS %s // RUN: %clang -### -S -fno-profile-arcs -fprofile-arcs %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-ARCS %s // RUN: %clang -### -S -fno-profile-arcs %s 2>&1 | FileCheck -check-prefix=CHECK-NO-PROFILE-ARCS %s Index: lib/Driver/ToolChains/CommonArgs.h === --- lib/Driver/ToolChains/CommonArgs.h +++ lib/Driver/ToolChains/CommonArgs.h @@ -63,6 +63,7 @@ const llvm::opt::ArgList &Args); llvm::opt::Arg *getLastProfileUseArg(const llvm::opt::ArgList &Args); +llvm::opt::Arg *getLastProfileSampleUseArg(const llvm::opt::ArgList &Args); bool isObjCAutoRefCount(const llvm::opt::ArgList &Args); Index: lib/Driver/ToolChains/CommonArgs.cpp === --- lib/Driver/ToolChains/CommonArgs.cpp +++ lib/Driver/ToolChains/CommonArgs.cpp @@ -407,7 +407,7 @@ CmdArgs.push_back("-plugin-opt=-data-sections"); } - if (Arg *A = Args.getLastArg(options::OPT_fprofile_sample_use_EQ)) { + if (Arg *A = getLastProfileSampleUseArg(Args)) { StringRef FName = A->getValue(); if (!llvm::sys::fs::exists(FName)) D.Diag(diag::err_drv_no_such_file) << FName; @@ -673,6 +673,22 @@ return ProfileUseArg; } +Arg *tools::getLastProfileSampleUseArg(const ArgList &Args) { + auto *ProfileSampleUseArg = Args.getLastArg( + options::OPT_fprofile_sample_use, options::OPT_fprofile_sample_use_EQ, + options::OPT_fauto_profile, options::OPT_fauto_profile_EQ, + options::OPT_fno_profile_sample_use, options::OPT_fno_auto_profile); + + if (ProfileSampleUseArg && + (ProfileSampleUseArg->getOption().matches( + options::OPT_fno_profile_sample_use) || + ProfileSampleUseArg->getOption().matches(options::OPT_fno_auto_profile))) +return nullptr; + + return Args.getLastArg(options::OPT_fprofile_sample_use_EQ, + options::OPT_fauto_profile_EQ); +} + /// Parses the various -fpic/-fPIC/-fpie/-fPIE arguments. Then, /// smooshes them together with platform defaults, to decide whether /// this compile should be using PIC mode or not. Returns a tuple of Index: lib/Driver/ToolChains/Clang.cpp === --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -3431,7 +3431,7 @@ // Forward -f options with positive and negative forms; we translate // these by hand. - if (Arg *A = Args.getLastArg(options::OPT_fprofile_sample_use_EQ)) { + if (Arg *A = getLastProfileSampleUseArg(Args)) { StringRef fname = A->getValue(); if (!llvm::sys::fs::exists(fname)) D.Diag(diag::err_drv_no_such_file) << fname; Index: include/clang/Driver/Options.td === --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -613,9 +613,17 @@ Flags<[DriverOption, CC1Option]>, HelpText<"Disable GNU style inline asm">; +def fprofile_sample_use : Flag<["-"], "fprofile-sample-use">, Group, +Flags<[CoreOption]>; +def fno_profile_sample_use : Flag<["-"], "fno-profile-sample-use">, Group, +Flags<[CoreOption]>; def fprofile_sample_use_EQ : Joined<["-"], "fprofile-sample-use=">, Group, Flags<[DriverOption, CC1Option]>, HelpText<"Enable sample-based profile guided optimizations">; +def fauto_profile : Flag<["-"], "fauto-profile">, Group, +Alias; +def fno_auto_profile : Flag<["-"], "fno-auto-profile">, Group, +Alias; def fauto_profile_EQ : Joined<["-"], "fauto
[PATCH] D31219: Update the SamplePGO test to verify that unroll/icp is not invoked in thinlto compile phase.
danielcdh created this revision. Herald added a subscriber: Prazek. This is the test added for https://reviews.llvm.org/D31217 https://reviews.llvm.org/D31219 Files: test/CodeGen/Inputs/pgo-sample-thinlto-summary.prof test/CodeGen/pgo-sample-thinlto-summary.c Index: test/CodeGen/pgo-sample-thinlto-summary.c === --- test/CodeGen/pgo-sample-thinlto-summary.c +++ test/CodeGen/pgo-sample-thinlto-summary.c @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=INLINE -// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -flto=thin -o - 2>&1 | FileCheck %s -check-prefix=NOINLINE +// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=O2 +// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -flto=thin -o - 2>&1 | FileCheck %s -check-prefix=THINLTO // Checks if hot call is inlined by normal compile, but not inlined by // thinlto compile. @@ -11,9 +11,30 @@ g += baz(i); } -// INLINE-NOT: call{{.*}}foo -// NOINLINE: call{{.*}}foo +// O2-LABEL: define void @bar +// THINLTO-LABEL: define void @bar +// O2-NOT: call{{.*}}foo +// THINLTO: call{{.*}}foo void bar(int n) { for (int i = 0; i < n; i++) foo(i); } + +// O2-LABEL: define void @unroll +// THINLTO-LABEL: define void @unroll +// O2: call{{.*}}baz +// O2: call{{.*}}baz +// THINLTO: call{{.*}}baz +// THINLTO-NOT: call{{.*}}baz +void unroll() { + for (int i = 0; i < 2; i++) +baz(i); +} + +// O2-LABEL: define void @icp +// THINLTO-LABEL: define void @icp +// O2: if.true.direct_targ +// ThinLTO-NOT: if.true.direct_targ +void icp(void (*p)()) { + p(); +} Index: test/CodeGen/Inputs/pgo-sample-thinlto-summary.prof === --- test/CodeGen/Inputs/pgo-sample-thinlto-summary.prof +++ test/CodeGen/Inputs/pgo-sample-thinlto-summary.prof @@ -1,2 +1,4 @@ bar:100:100 2: 2000 foo:2000 +icp:100:100 + 1: 1000 unroll:1000 Index: test/CodeGen/pgo-sample-thinlto-summary.c === --- test/CodeGen/pgo-sample-thinlto-summary.c +++ test/CodeGen/pgo-sample-thinlto-summary.c @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=INLINE -// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -flto=thin -o - 2>&1 | FileCheck %s -check-prefix=NOINLINE +// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=O2 +// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -flto=thin -o - 2>&1 | FileCheck %s -check-prefix=THINLTO // Checks if hot call is inlined by normal compile, but not inlined by // thinlto compile. @@ -11,9 +11,30 @@ g += baz(i); } -// INLINE-NOT: call{{.*}}foo -// NOINLINE: call{{.*}}foo +// O2-LABEL: define void @bar +// THINLTO-LABEL: define void @bar +// O2-NOT: call{{.*}}foo +// THINLTO: call{{.*}}foo void bar(int n) { for (int i = 0; i < n; i++) foo(i); } + +// O2-LABEL: define void @unroll +// THINLTO-LABEL: define void @unroll +// O2: call{{.*}}baz +// O2: call{{.*}}baz +// THINLTO: call{{.*}}baz +// THINLTO-NOT: call{{.*}}baz +void unroll() { + for (int i = 0; i < 2; i++) +baz(i); +} + +// O2-LABEL: define void @icp +// THINLTO-LABEL: define void @icp +// O2: if.true.direct_targ +// ThinLTO-NOT: if.true.direct_targ +void icp(void (*p)()) { + p(); +} Index: test/CodeGen/Inputs/pgo-sample-thinlto-summary.prof === --- test/CodeGen/Inputs/pgo-sample-thinlto-summary.prof +++ test/CodeGen/Inputs/pgo-sample-thinlto-summary.prof @@ -1,2 +1,4 @@ bar:100:100 2: 2000 foo:2000 +icp:100:100 + 1: 1000 unroll:1000 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D28588: Pass -fprofile-sample-use to lto backends.
danielcdh reopened this revision. danielcdh added a comment. This revision is now accepted and ready to land. The breaks some buildbots thus I reverted the patch: http://lab.llvm.org:8011/builders/clang-x86-windows-msvc2015/builds/1889 http://lab.llvm.org:8080/green/job/clang-stage1-cmake-RA-incremental_check/32242/ Unfortunately I could not reproduce the error locally. Any quick insights why this test change would break? Thanks, Dehao https://reviews.llvm.org/D28588 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D28588: Pass -fprofile-sample-use to lto backends.
danielcdh added a comment. Thanks for the prompt response. But looks like several other tests also has "-mllvm -debug-pass=Structure" in their tests: tools/clang/test/CodeGen/pgo-instrumentation.c test/CodeGen/Generic/llc-start-stop.ll I just verified that if I cmake with -DCMAKE_BUILD_TYPE=Release, it still passes locally. Thanks, Dehao https://reviews.llvm.org/D28588 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D28588: Pass -fprofile-sample-use to lto backends.
danielcdh updated this revision to Diff 84193. danielcdh added a comment. Updates the unittests to clang_cc1 to see if it fixes the buildbot failure. https://reviews.llvm.org/D28588 Files: lib/CodeGen/BackendUtil.cpp test/CodeGen/thinlto_backend.ll Index: test/CodeGen/thinlto_backend.ll === --- test/CodeGen/thinlto_backend.ll +++ test/CodeGen/thinlto_backend.ll @@ -8,6 +8,10 @@ ; RUN: not %clang_cc1 -O2 -o %t1.o -x c %s -c -fthinlto-index=%t.thinlto.bc 2>&1 | FileCheck %s -check-prefix=CHECK-WARNING ; CHECK-WARNING: error: invalid argument '-fthinlto-index={{.*}}' only allowed with '-x ir' +; Ensure sample profile pass are passed to backend +; RUN: %clang_cc1 -emit-obj -O2 -o %t5.o -x ir %t1.o -fthinlto-index=%t.thinlto.bc -fprofile-sample-use=%S/Inputs/pgo-sample.prof -mllvm -debug-pass=Structure 2>&1 | FileCheck %s -check-prefix=CHECK-SAMPLEPGO +; CHECK-SAMPLEPGO: Sample profile pass + ; Ensure we get expected error for missing index file ; RUN: %clang -O2 -o %t4.o -x ir %t1.o -c -fthinlto-index=bad.thinlto.bc 2>&1 | FileCheck %s -check-prefix=CHECK-ERROR1 ; CHECK-ERROR1: Error loading index file 'bad.thinlto.bc' Index: lib/CodeGen/BackendUtil.cpp === --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -862,7 +862,8 @@ } static void runThinLTOBackend(ModuleSummaryIndex *CombinedIndex, Module *M, - std::unique_ptr OS) { + std::unique_ptr OS, + std::string SampleProfile) { StringMap> ModuleToDefinedGVSummaries; CombinedIndex->collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries); @@ -930,6 +931,7 @@ return llvm::make_unique(std::move(OS)); }; lto::Config Conf; + Conf.SampleProfile = SampleProfile; if (Error E = thinBackend( Conf, 0, AddStream, *M, *CombinedIndex, ImportList, ModuleToDefinedGVSummaries[M->getModuleIdentifier()], ModuleMap)) { @@ -965,7 +967,8 @@ // of an error). bool DoThinLTOBackend = CombinedIndex != nullptr; if (DoThinLTOBackend) { - runThinLTOBackend(CombinedIndex.get(), M, std::move(OS)); + runThinLTOBackend(CombinedIndex.get(), M, std::move(OS), +CGOpts.SampleProfileFile); return; } } Index: test/CodeGen/thinlto_backend.ll === --- test/CodeGen/thinlto_backend.ll +++ test/CodeGen/thinlto_backend.ll @@ -8,6 +8,10 @@ ; RUN: not %clang_cc1 -O2 -o %t1.o -x c %s -c -fthinlto-index=%t.thinlto.bc 2>&1 | FileCheck %s -check-prefix=CHECK-WARNING ; CHECK-WARNING: error: invalid argument '-fthinlto-index={{.*}}' only allowed with '-x ir' +; Ensure sample profile pass are passed to backend +; RUN: %clang_cc1 -emit-obj -O2 -o %t5.o -x ir %t1.o -fthinlto-index=%t.thinlto.bc -fprofile-sample-use=%S/Inputs/pgo-sample.prof -mllvm -debug-pass=Structure 2>&1 | FileCheck %s -check-prefix=CHECK-SAMPLEPGO +; CHECK-SAMPLEPGO: Sample profile pass + ; Ensure we get expected error for missing index file ; RUN: %clang -O2 -o %t4.o -x ir %t1.o -c -fthinlto-index=bad.thinlto.bc 2>&1 | FileCheck %s -check-prefix=CHECK-ERROR1 ; CHECK-ERROR1: Error loading index file 'bad.thinlto.bc' Index: lib/CodeGen/BackendUtil.cpp === --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -862,7 +862,8 @@ } static void runThinLTOBackend(ModuleSummaryIndex *CombinedIndex, Module *M, - std::unique_ptr OS) { + std::unique_ptr OS, + std::string SampleProfile) { StringMap> ModuleToDefinedGVSummaries; CombinedIndex->collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries); @@ -930,6 +931,7 @@ return llvm::make_unique(std::move(OS)); }; lto::Config Conf; + Conf.SampleProfile = SampleProfile; if (Error E = thinBackend( Conf, 0, AddStream, *M, *CombinedIndex, ImportList, ModuleToDefinedGVSummaries[M->getModuleIdentifier()], ModuleMap)) { @@ -965,7 +967,8 @@ // of an error). bool DoThinLTOBackend = CombinedIndex != nullptr; if (DoThinLTOBackend) { - runThinLTOBackend(CombinedIndex.get(), M, std::move(OS)); + runThinLTOBackend(CombinedIndex.get(), M, std::move(OS), +CGOpts.SampleProfileFile); return; } } ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D28588: Pass -fprofile-sample-use to lto backends.
danielcdh added a comment. Looks like this is still breaking these buildbots: http://lab.llvm.org:8011/builders/clang-ppc64be-linux/builds/3216/steps/ninja%20check%201/logs/FAIL%3A%20Clang%3A%3Athinlto_backend.ll I reverted the test change for now, and am thinking of how to reproduce/fix the problem... https://reviews.llvm.org/D28588 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D29205: Change debug-info-for-profiling from a TargetOption to a function attribute.
danielcdh created this revision. Herald added a subscriber: mehdi_amini. cfe change for https://reviews.llvm.org/D29203 https://reviews.llvm.org/D29205 Files: lib/CodeGen/BackendUtil.cpp lib/CodeGen/CodeGenFunction.cpp Index: lib/CodeGen/CodeGenFunction.cpp === --- lib/CodeGen/CodeGenFunction.cpp +++ lib/CodeGen/CodeGenFunction.cpp @@ -793,6 +793,10 @@ Fn->addFnAttr("no-jump-tables", llvm::toStringRef(CGM.getCodeGenOpts().NoUseJumpTables)); + // Add debug-info-for-profiling value. + Fn->addFnAttr("debug-info-for-profiling", +llvm::toStringRef(CGM.getCodeGenOpts().DebugInfoForProfiling)); + if (getLangOpts().OpenCL) { // Add metadata for a kernel function. if (const FunctionDecl *FD = dyn_cast_or_null(D)) Index: lib/CodeGen/BackendUtil.cpp === --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -573,7 +573,6 @@ Options.DisableIntegratedAS = CodeGenOpts.DisableIntegratedAS; Options.CompressDebugSections = CodeGenOpts.CompressDebugSections; Options.RelaxELFRelocations = CodeGenOpts.RelaxELFRelocations; - Options.DebugInfoForProfiling = CodeGenOpts.DebugInfoForProfiling; // Set EABI version. Options.EABIVersion = llvm::StringSwitch(TargetOpts.EABIVersion) Index: lib/CodeGen/CodeGenFunction.cpp === --- lib/CodeGen/CodeGenFunction.cpp +++ lib/CodeGen/CodeGenFunction.cpp @@ -793,6 +793,10 @@ Fn->addFnAttr("no-jump-tables", llvm::toStringRef(CGM.getCodeGenOpts().NoUseJumpTables)); + // Add debug-info-for-profiling value. + Fn->addFnAttr("debug-info-for-profiling", +llvm::toStringRef(CGM.getCodeGenOpts().DebugInfoForProfiling)); + if (getLangOpts().OpenCL) { // Add metadata for a kernel function. if (const FunctionDecl *FD = dyn_cast_or_null(D)) Index: lib/CodeGen/BackendUtil.cpp === --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -573,7 +573,6 @@ Options.DisableIntegratedAS = CodeGenOpts.DisableIntegratedAS; Options.CompressDebugSections = CodeGenOpts.CompressDebugSections; Options.RelaxELFRelocations = CodeGenOpts.RelaxELFRelocations; - Options.DebugInfoForProfiling = CodeGenOpts.DebugInfoForProfiling; // Set EABI version. Options.EABIVersion = llvm::StringSwitch(TargetOpts.EABIVersion) ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D29205: Change debug-info-for-profiling from a TargetOption to a function attribute.
danielcdh updated this revision to Diff 86058. danielcdh added a comment. change to use module flag. https://reviews.llvm.org/D29205 Files: lib/CodeGen/BackendUtil.cpp lib/CodeGen/CodeGenModule.cpp Index: lib/CodeGen/CodeGenModule.cpp === --- lib/CodeGen/CodeGenModule.cpp +++ lib/CodeGen/CodeGenModule.cpp @@ -448,6 +448,8 @@ // (and warn about it, too). getModule().addModuleFlag(llvm::Module::Warning, "Debug Info Version", llvm::DEBUG_METADATA_VERSION); + if (CodeGenOpts.DebugInfoForProfiling) +getModule().addModuleFlag(llvm::Module::Warning, "DebugInfoForProfiling", 1); // We need to record the widths of enums and wchar_t, so that we can generate // the correct build attributes in the ARM backend. Index: lib/CodeGen/BackendUtil.cpp === --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -573,7 +573,6 @@ Options.DisableIntegratedAS = CodeGenOpts.DisableIntegratedAS; Options.CompressDebugSections = CodeGenOpts.CompressDebugSections; Options.RelaxELFRelocations = CodeGenOpts.RelaxELFRelocations; - Options.DebugInfoForProfiling = CodeGenOpts.DebugInfoForProfiling; // Set EABI version. Options.EABIVersion = llvm::StringSwitch(TargetOpts.EABIVersion) Index: lib/CodeGen/CodeGenModule.cpp === --- lib/CodeGen/CodeGenModule.cpp +++ lib/CodeGen/CodeGenModule.cpp @@ -448,6 +448,8 @@ // (and warn about it, too). getModule().addModuleFlag(llvm::Module::Warning, "Debug Info Version", llvm::DEBUG_METADATA_VERSION); + if (CodeGenOpts.DebugInfoForProfiling) +getModule().addModuleFlag(llvm::Module::Warning, "DebugInfoForProfiling", 1); // We need to record the widths of enums and wchar_t, so that we can generate // the correct build attributes in the ARM backend. Index: lib/CodeGen/BackendUtil.cpp === --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -573,7 +573,6 @@ Options.DisableIntegratedAS = CodeGenOpts.DisableIntegratedAS; Options.CompressDebugSections = CodeGenOpts.CompressDebugSections; Options.RelaxELFRelocations = CodeGenOpts.RelaxELFRelocations; - Options.DebugInfoForProfiling = CodeGenOpts.DebugInfoForProfiling; // Set EABI version. Options.EABIVersion = llvm::StringSwitch(TargetOpts.EABIVersion) ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D29205: Change debug-info-for-profiling from a TargetOption to a function attribute.
danielcdh added inline comments. Comment at: lib/CodeGen/CodeGenModule.cpp:452 + if (CodeGenOpts.DebugInfoForProfiling) +getModule().addModuleFlag(llvm::Module::Warning, "DebugInfoForProfiling", 1); mehdi_amini wrote: > Why should we warn on mismatch? In theory, we expect this to be the same across all modules. Otherwise when we use this binary for profiling, we may get inaccurate profiles. https://reviews.llvm.org/D29205 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D29205: Change debug-info-for-profiling from a TargetOption to a function attribute.
danielcdh updated this revision to Diff 86292. danielcdh added a comment. update https://reviews.llvm.org/D29205 Files: lib/CodeGen/BackendUtil.cpp lib/CodeGen/CGDebugInfo.cpp Index: lib/CodeGen/CGDebugInfo.cpp === --- lib/CodeGen/CGDebugInfo.cpp +++ lib/CodeGen/CGDebugInfo.cpp @@ -509,7 +509,8 @@ Checksum), Producer, LO.Optimize, CGM.getCodeGenOpts().DwarfDebugFlags, RuntimeVers, CGM.getCodeGenOpts().SplitDwarfFile, EmissionKind, 0 /* DWOid */, - CGM.getCodeGenOpts().SplitDwarfInlining); + CGM.getCodeGenOpts().SplitDwarfInlining, + CGM.getCodeGenOpts().DebugInfoForProfiling); } llvm::DIType *CGDebugInfo::CreateType(const BuiltinType *BT) { Index: lib/CodeGen/BackendUtil.cpp === --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -573,7 +573,6 @@ Options.DisableIntegratedAS = CodeGenOpts.DisableIntegratedAS; Options.CompressDebugSections = CodeGenOpts.CompressDebugSections; Options.RelaxELFRelocations = CodeGenOpts.RelaxELFRelocations; - Options.DebugInfoForProfiling = CodeGenOpts.DebugInfoForProfiling; // Set EABI version. Options.EABIVersion = llvm::StringSwitch(TargetOpts.EABIVersion) Index: lib/CodeGen/CGDebugInfo.cpp === --- lib/CodeGen/CGDebugInfo.cpp +++ lib/CodeGen/CGDebugInfo.cpp @@ -509,7 +509,8 @@ Checksum), Producer, LO.Optimize, CGM.getCodeGenOpts().DwarfDebugFlags, RuntimeVers, CGM.getCodeGenOpts().SplitDwarfFile, EmissionKind, 0 /* DWOid */, - CGM.getCodeGenOpts().SplitDwarfInlining); + CGM.getCodeGenOpts().SplitDwarfInlining, + CGM.getCodeGenOpts().DebugInfoForProfiling); } llvm::DIType *CGDebugInfo::CreateType(const BuiltinType *BT) { Index: lib/CodeGen/BackendUtil.cpp === --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -573,7 +573,6 @@ Options.DisableIntegratedAS = CodeGenOpts.DisableIntegratedAS; Options.CompressDebugSections = CodeGenOpts.CompressDebugSections; Options.RelaxELFRelocations = CodeGenOpts.RelaxELFRelocations; - Options.DebugInfoForProfiling = CodeGenOpts.DebugInfoForProfiling; // Set EABI version. Options.EABIVersion = llvm::StringSwitch(TargetOpts.EABIVersion) ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D34663: Update test for enabling ICP for AutoFDO.
danielcdh updated this revision to Diff 104199. danielcdh added a comment. update comments https://reviews.llvm.org/D34663 Files: test/CodeGen/pgo-sample-thinlto-summary.c Index: test/CodeGen/pgo-sample-thinlto-summary.c === --- test/CodeGen/pgo-sample-thinlto-summary.c +++ test/CodeGen/pgo-sample-thinlto-summary.c @@ -32,10 +32,10 @@ baz(i); } -// Check that icp is not invoked (both -O2 and ThinLTO). +// Check that icp is not invoked for ThinLTO, but invoked for -O2. // O2-LABEL: define void @icp // THINLTO-LABEL: define void @icp -// O2-NOT: if.true.direct_targ +// O2: if.true.direct_targ // ThinLTO-NOT: if.true.direct_targ void icp(void (*p)()) { p(); Index: test/CodeGen/pgo-sample-thinlto-summary.c === --- test/CodeGen/pgo-sample-thinlto-summary.c +++ test/CodeGen/pgo-sample-thinlto-summary.c @@ -32,10 +32,10 @@ baz(i); } -// Check that icp is not invoked (both -O2 and ThinLTO). +// Check that icp is not invoked for ThinLTO, but invoked for -O2. // O2-LABEL: define void @icp // THINLTO-LABEL: define void @icp -// O2-NOT: if.true.direct_targ +// O2: if.true.direct_targ // ThinLTO-NOT: if.true.direct_targ void icp(void (*p)()) { p(); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D34663: Update test for enabling ICP for AutoFDO.
danielcdh added inline comments. Comment at: test/CodeGen/pgo-sample-thinlto-summary.c:39 +// O2: if.true.direct_targ // ThinLTO-NOT: if.true.direct_targ void icp(void (*p)()) { davidxl wrote: > Is the thinLTO behavior here expected? Yes, it's expected, icp is turned off for the samplepgo thinlto summary phase (details in https://reviews.llvm.org/D31217) https://reviews.llvm.org/D34663 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D34721: [PM] Add support for sample PGO in the new pass manager (clang-side)
danielcdh created this revision. Herald added subscribers: eraman, mehdi_amini, sanjoy. This implements the clang bits of https://reviews.llvm.org/D34720, and add corresponding test to verify if it worked. https://reviews.llvm.org/D34721 Files: lib/CodeGen/BackendUtil.cpp test/CodeGen/pgo-sample-thinlto-summary.c Index: test/CodeGen/pgo-sample-thinlto-summary.c === --- test/CodeGen/pgo-sample-thinlto-summary.c +++ test/CodeGen/pgo-sample-thinlto-summary.c @@ -1,5 +1,7 @@ // RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=SAMPLEPGO // RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -flto=thin -o - 2>&1 | FileCheck %s -check-prefix=THINLTO +// RUN: %clang_cc1 -O2 -fexperimental-new-pass-manager -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=SAMPLEPGO +// RUN: %clang_cc1 -O2 -fexperimental-new-pass-manager -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -flto=thin -o - 2>&1 | FileCheck %s -check-prefix=THINLTO // Checks if hot call is inlined by normal compile, but not inlined by // thinlto compile. Index: lib/CodeGen/BackendUtil.cpp === --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -856,11 +856,15 @@ if (CodeGenOpts.hasProfileIRUse()) PGOOpt.ProfileUseFile = CodeGenOpts.ProfileInstrumentUsePath; + if (!CodeGenOpts.SampleProfileFile.empty()) +PGOOpt.SampleProfileFile = CodeGenOpts.SampleProfileFile; + // Only pass a PGO options struct if -fprofile-generate or // -fprofile-use were passed on the cmdline. PassBuilder PB(TM.get(), (PGOOpt.RunProfileGen || - !PGOOpt.ProfileUseFile.empty()) ? + !PGOOpt.ProfileUseFile.empty() || + !PGOOpt.SampleProfileFile.empty()) ? Optional(PGOOpt) : None); LoopAnalysisManager LAM; Index: test/CodeGen/pgo-sample-thinlto-summary.c === --- test/CodeGen/pgo-sample-thinlto-summary.c +++ test/CodeGen/pgo-sample-thinlto-summary.c @@ -1,5 +1,7 @@ // RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=SAMPLEPGO // RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -flto=thin -o - 2>&1 | FileCheck %s -check-prefix=THINLTO +// RUN: %clang_cc1 -O2 -fexperimental-new-pass-manager -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=SAMPLEPGO +// RUN: %clang_cc1 -O2 -fexperimental-new-pass-manager -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -flto=thin -o - 2>&1 | FileCheck %s -check-prefix=THINLTO // Checks if hot call is inlined by normal compile, but not inlined by // thinlto compile. Index: lib/CodeGen/BackendUtil.cpp === --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -856,11 +856,15 @@ if (CodeGenOpts.hasProfileIRUse()) PGOOpt.ProfileUseFile = CodeGenOpts.ProfileInstrumentUsePath; + if (!CodeGenOpts.SampleProfileFile.empty()) +PGOOpt.SampleProfileFile = CodeGenOpts.SampleProfileFile; + // Only pass a PGO options struct if -fprofile-generate or // -fprofile-use were passed on the cmdline. PassBuilder PB(TM.get(), (PGOOpt.RunProfileGen || - !PGOOpt.ProfileUseFile.empty()) ? + !PGOOpt.ProfileUseFile.empty() || + !PGOOpt.SampleProfileFile.empty()) ? Optional(PGOOpt) : None); LoopAnalysisManager LAM; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D34721: [PM] Add support for sample PGO in the new pass manager (clang-side)
danielcdh added inline comments. Comment at: test/CodeGen/pgo-sample-thinlto-summary.c:4 +// RUN: %clang_cc1 -O2 -fexperimental-new-pass-manager -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=SAMPLEPGO +// RUN: %clang_cc1 -O2 -fexperimental-new-pass-manager -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -flto=thin -o - 2>&1 | FileCheck %s -check-prefix=THINLTO // Checks if hot call is inlined by normal compile, but not inlined by This test will currently fail because PrepareForLLVM has not been passed down so that we do not know if it's in the thinlto compile phase. Related discussion: http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20170626/464868.html This patch needs to commit after that issue is fixed. https://reviews.llvm.org/D34721 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D34725: Add sample PGO integration test to cover profile annotation and inlining.
danielcdh created this revision. Herald added a subscriber: sanjoy. The patch makes the integration test cover major sample PGO components. https://reviews.llvm.org/D34725 Files: test/CodeGen/Inputs/pgo-sample.prof test/CodeGen/pgo-sample.c Index: test/CodeGen/pgo-sample.c === --- test/CodeGen/pgo-sample.c +++ test/CodeGen/pgo-sample.c @@ -1,6 +1,31 @@ // Test if PGO sample use passes are invoked. // -// Ensure Pass PGOInstrumentationGenPass is invoked. -// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample.prof %s -mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s +// Ensure Pass SampleProfileLoader is invoked. +// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample.prof %s -mllvm -debug-pass=Structure -mllvm -inline-threshold=0 -emit-llvm -o - 2>&1 | FileCheck %s // CHECK: Remove unused exception handling info // CHECK: Sample profile pass + +void baz(); + +// CHECK-LABEL: @callee( +void callee(int t) { + for (int i = 0; i < t; i++) +baz(); +} + +// CHECK-LABEL: @bar( +// cold call to callee should not be inlined. +// CHECK: call void @callee +void bar(int x) { + if (x < 100) +callee(x); +} + +// CHECK-LABEL: @foo( +// bar should be early-inlined because it is hot inline instance in profile. +// callee should be inlined because it is hot callsite in the inline instance +// of foo:bar. +// CHECK-NOT: call void @callee +void foo(int x) { + bar(x); +} Index: test/CodeGen/Inputs/pgo-sample.prof === --- test/CodeGen/Inputs/pgo-sample.prof +++ test/CodeGen/Inputs/pgo-sample.prof @@ -1,2 +1,7 @@ -bar:100:100 - 1: 2000 +bar:1000:1000 + 1: 1000 + 2: 0 +foo:1000:1000 + 1:bar:1000 + 1: 1000 + 2: 1000 Index: test/CodeGen/pgo-sample.c === --- test/CodeGen/pgo-sample.c +++ test/CodeGen/pgo-sample.c @@ -1,6 +1,31 @@ // Test if PGO sample use passes are invoked. // -// Ensure Pass PGOInstrumentationGenPass is invoked. -// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample.prof %s -mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s +// Ensure Pass SampleProfileLoader is invoked. +// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample.prof %s -mllvm -debug-pass=Structure -mllvm -inline-threshold=0 -emit-llvm -o - 2>&1 | FileCheck %s // CHECK: Remove unused exception handling info // CHECK: Sample profile pass + +void baz(); + +// CHECK-LABEL: @callee( +void callee(int t) { + for (int i = 0; i < t; i++) +baz(); +} + +// CHECK-LABEL: @bar( +// cold call to callee should not be inlined. +// CHECK: call void @callee +void bar(int x) { + if (x < 100) +callee(x); +} + +// CHECK-LABEL: @foo( +// bar should be early-inlined because it is hot inline instance in profile. +// callee should be inlined because it is hot callsite in the inline instance +// of foo:bar. +// CHECK-NOT: call void @callee +void foo(int x) { + bar(x); +} Index: test/CodeGen/Inputs/pgo-sample.prof === --- test/CodeGen/Inputs/pgo-sample.prof +++ test/CodeGen/Inputs/pgo-sample.prof @@ -1,2 +1,7 @@ -bar:100:100 - 1: 2000 +bar:1000:1000 + 1: 1000 + 2: 0 +foo:1000:1000 + 1:bar:1000 + 1: 1000 + 2: 1000 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D34896: Enable the new PM + SamlePGO + ThinLTO testing.
danielcdh created this revision. Herald added subscribers: eraman, inglorion, mehdi_amini, sanjoy. This patch should be enabled after https://reviews.llvm.org/D34895 https://reviews.llvm.org/D34896 Files: test/CodeGen/pgo-sample-thinlto-summary.c Index: test/CodeGen/pgo-sample-thinlto-summary.c === --- test/CodeGen/pgo-sample-thinlto-summary.c +++ test/CodeGen/pgo-sample-thinlto-summary.c @@ -1,9 +1,7 @@ // RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=SAMPLEPGO // RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -flto=thin -o - 2>&1 | FileCheck %s -check-prefix=THINLTO // RUN: %clang_cc1 -O2 -fexperimental-new-pass-manager -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=SAMPLEPGO -// FIXME: Run the following command once LTOPreLinkDefaultPipeline is -//customized. -// %clang_cc1 -O2 -fexperimental-new-pass-manager -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -flto=thin -o - 2>&1 | FileCheck %s -check-prefix=THINLTO +// RUN: %clang_cc1 -O2 -fexperimental-new-pass-manager -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -flto=thin -o - 2>&1 | FileCheck %s -check-prefix=THINLTO // Checks if hot call is inlined by normal compile, but not inlined by // thinlto compile. Index: test/CodeGen/pgo-sample-thinlto-summary.c === --- test/CodeGen/pgo-sample-thinlto-summary.c +++ test/CodeGen/pgo-sample-thinlto-summary.c @@ -1,9 +1,7 @@ // RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=SAMPLEPGO // RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -flto=thin -o - 2>&1 | FileCheck %s -check-prefix=THINLTO // RUN: %clang_cc1 -O2 -fexperimental-new-pass-manager -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=SAMPLEPGO -// FIXME: Run the following command once LTOPreLinkDefaultPipeline is -//customized. -// %clang_cc1 -O2 -fexperimental-new-pass-manager -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -flto=thin -o - 2>&1 | FileCheck %s -check-prefix=THINLTO +// RUN: %clang_cc1 -O2 -fexperimental-new-pass-manager -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -flto=thin -o - 2>&1 | FileCheck %s -check-prefix=THINLTO // Checks if hot call is inlined by normal compile, but not inlined by // thinlto compile. ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D34725: Add sample PGO integration test to cover profile annotation and inlining.
danielcdh added inline comments. Comment at: test/CodeGen/pgo-sample.c:28 +// of foo:bar. +// CHECK-NOT: call void @callee +void foo(int x) { davidxl wrote: > SHould this be 'CHECK-NOT: call' as bar is also inlined? There is still call to baz. Explicitly added CHECK-NOT call bar. https://reviews.llvm.org/D34725 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D34725: Add sample PGO integration test to cover profile annotation and inlining.
danielcdh updated this revision to Diff 105705. danielcdh marked an inline comment as done. danielcdh added a comment. Integrate David's comment and add new PM test. https://reviews.llvm.org/D34725 Files: test/CodeGen/Inputs/pgo-sample.prof test/CodeGen/pgo-sample.c Index: test/CodeGen/pgo-sample.c === --- test/CodeGen/pgo-sample.c +++ test/CodeGen/pgo-sample.c @@ -1,6 +1,34 @@ // Test if PGO sample use passes are invoked. // -// Ensure Pass PGOInstrumentationGenPass is invoked. -// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample.prof %s -mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s -// CHECK: Remove unused exception handling info -// CHECK: Sample profile pass +// Ensure Pass SampleProfileLoader is invoked. +// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample.prof %s -mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=STRUCTURE +// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample.prof %s -mllvm -debug-pass=Structure -mllvm -inline-threshold=0 -emit-llvm -o - 2>&1 | FileCheck %s +// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample.prof %s -mllvm -debug-pass=Structure -mllvm -inline-threshold=0 -emit-llvm -fexperimental-new-pass-manager -o - 2>&1 | FileCheck %s +// STRUCTURE: Remove unused exception handling info +// STRUCTURE: Sample profile pass + +void baz(); + +// CHECK-LABEL: @callee( +void callee(int t) { + for (int i = 0; i < t; i++) +baz(); +} + +// CHECK-LABEL: @bar( +// cold call to callee should not be inlined. +// CHECK: call void @callee +void bar(int x) { + if (x < 100) +callee(x); +} + +// CHECK-LABEL: @foo( +// bar should be early-inlined because it is hot inline instance in profile. +// callee should be inlined because it is hot callsite in the inline instance +// of foo:bar. +// CHECK-NOT: call void @callee +// CHECK-NOT: call void @bar +void foo(int x) { + bar(x); +} Index: test/CodeGen/Inputs/pgo-sample.prof === --- test/CodeGen/Inputs/pgo-sample.prof +++ test/CodeGen/Inputs/pgo-sample.prof @@ -1,2 +1,7 @@ -bar:100:100 - 1: 2000 +bar:1000:1000 + 1: 1000 + 2: 0 +foo:1000:1000 + 1:bar:1000 + 1: 1000 + 2: 1000 Index: test/CodeGen/pgo-sample.c === --- test/CodeGen/pgo-sample.c +++ test/CodeGen/pgo-sample.c @@ -1,6 +1,34 @@ // Test if PGO sample use passes are invoked. // -// Ensure Pass PGOInstrumentationGenPass is invoked. -// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample.prof %s -mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s -// CHECK: Remove unused exception handling info -// CHECK: Sample profile pass +// Ensure Pass SampleProfileLoader is invoked. +// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample.prof %s -mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=STRUCTURE +// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample.prof %s -mllvm -debug-pass=Structure -mllvm -inline-threshold=0 -emit-llvm -o - 2>&1 | FileCheck %s +// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample.prof %s -mllvm -debug-pass=Structure -mllvm -inline-threshold=0 -emit-llvm -fexperimental-new-pass-manager -o - 2>&1 | FileCheck %s +// STRUCTURE: Remove unused exception handling info +// STRUCTURE: Sample profile pass + +void baz(); + +// CHECK-LABEL: @callee( +void callee(int t) { + for (int i = 0; i < t; i++) +baz(); +} + +// CHECK-LABEL: @bar( +// cold call to callee should not be inlined. +// CHECK: call void @callee +void bar(int x) { + if (x < 100) +callee(x); +} + +// CHECK-LABEL: @foo( +// bar should be early-inlined because it is hot inline instance in profile. +// callee should be inlined because it is hot callsite in the inline instance +// of foo:bar. +// CHECK-NOT: call void @callee +// CHECK-NOT: call void @bar +void foo(int x) { + bar(x); +} Index: test/CodeGen/Inputs/pgo-sample.prof === --- test/CodeGen/Inputs/pgo-sample.prof +++ test/CodeGen/Inputs/pgo-sample.prof @@ -1,2 +1,7 @@ -bar:100:100 - 1: 2000 +bar:1000:1000 + 1: 1000 + 2: 0 +foo:1000:1000 + 1:bar:1000 + 1: 1000 + 2: 1000 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D35153: Use DenseMap instead std::map for GVSummaryMapTy
danielcdh created this revision. Herald added a subscriber: sanjoy. Frontend change for https://reviews.llvm.org/D35148 https://reviews.llvm.org/D35153 Files: lib/CodeGen/BackendUtil.cpp Index: lib/CodeGen/BackendUtil.cpp === --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -998,7 +998,7 @@ std::unique_ptr OS, std::string SampleProfile, BackendAction Action) { - StringMap> + StringMap> ModuleToDefinedGVSummaries; CombinedIndex->collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries); Index: lib/CodeGen/BackendUtil.cpp === --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -998,7 +998,7 @@ std::unique_ptr OS, std::string SampleProfile, BackendAction Action) { - StringMap> + StringMap> ModuleToDefinedGVSummaries; CombinedIndex->collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D34725: Add sample PGO integration test to cover profile annotation and inlining.
danielcdh reopened this revision. danielcdh added a comment. This revision is now accepted and ready to land. the patch was reverted as it breaks on certain platforms (e.g. http://lab.llvm.org:8011/builders/clang-hexagon-elf/builds/10088/steps/ninja%20check%201/logs/FAIL%3A%20Clang%3A%3Apgo-sample.c) https://reviews.llvm.org/D34725 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D35746: Make new PM honor -fdebug-info-for-profiling (clang side)
danielcdh created this revision. Herald added a subscriber: sanjoy. The new PM needs to invoke add-discriminator pass when building with -fdebug-info-for-profiling. https://reviews.llvm.org/D35746 Files: lib/CodeGen/BackendUtil.cpp Index: lib/CodeGen/BackendUtil.cpp === --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -861,7 +861,9 @@ (PGOOpt.RunProfileGen || !PGOOpt.ProfileUseFile.empty() || !PGOOpt.SampleProfileFile.empty()) ? -Optional(PGOOpt) : None); +Optional(PGOOpt) : None, +(CodeGenOpts.DebugInfoForProfiling || + !CodeGenOpts.SampleProfileFile.empty())); LoopAnalysisManager LAM; FunctionAnalysisManager FAM; Index: lib/CodeGen/BackendUtil.cpp === --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -861,7 +861,9 @@ (PGOOpt.RunProfileGen || !PGOOpt.ProfileUseFile.empty() || !PGOOpt.SampleProfileFile.empty()) ? -Optional(PGOOpt) : None); +Optional(PGOOpt) : None, +(CodeGenOpts.DebugInfoForProfiling || + !CodeGenOpts.SampleProfileFile.empty())); LoopAnalysisManager LAM; FunctionAnalysisManager FAM; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D35746: Make new PM honor -fdebug-info-for-profiling (clang side)
danielcdh updated this revision to Diff 108174. danielcdh added a comment. update https://reviews.llvm.org/D35746 Files: lib/CodeGen/BackendUtil.cpp Index: lib/CodeGen/BackendUtil.cpp === --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -855,10 +855,13 @@ if (!CodeGenOpts.SampleProfileFile.empty()) PGOOpt.SampleProfileFile = CodeGenOpts.SampleProfileFile; + if (CodeGenOpts.DebugInfoForProfiling) +PGOOpt.SampleProfileGen = true; + // Only pass a PGO options struct if -fprofile-generate or // -fprofile-use were passed on the cmdline. PassBuilder PB(TM.get(), -(PGOOpt.RunProfileGen || +(PGOOpt.RunProfileGen || PGOOpt.SampleProfileGen || !PGOOpt.ProfileUseFile.empty() || !PGOOpt.SampleProfileFile.empty()) ? Optional(PGOOpt) : None); Index: lib/CodeGen/BackendUtil.cpp === --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -855,10 +855,13 @@ if (!CodeGenOpts.SampleProfileFile.empty()) PGOOpt.SampleProfileFile = CodeGenOpts.SampleProfileFile; + if (CodeGenOpts.DebugInfoForProfiling) +PGOOpt.SampleProfileGen = true; + // Only pass a PGO options struct if -fprofile-generate or // -fprofile-use were passed on the cmdline. PassBuilder PB(TM.get(), -(PGOOpt.RunProfileGen || +(PGOOpt.RunProfileGen || PGOOpt.SampleProfileGen || !PGOOpt.ProfileUseFile.empty() || !PGOOpt.SampleProfileFile.empty()) ? Optional(PGOOpt) : None); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D35746: Make new PM honor -fdebug-info-for-profiling (clang side)
danielcdh updated this revision to Diff 108316. danielcdh marked an inline comment as done. danielcdh added a comment. update https://reviews.llvm.org/D35746 Files: lib/CodeGen/BackendUtil.cpp Index: lib/CodeGen/BackendUtil.cpp === --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -840,28 +840,29 @@ return; TheModule->setDataLayout(TM->createDataLayout()); - PGOOptions PGOOpt; + Optional PGOOpt; - // -fprofile-generate. - PGOOpt.RunProfileGen = CodeGenOpts.hasProfileIRInstr(); - if (PGOOpt.RunProfileGen) -PGOOpt.ProfileGenFile = CodeGenOpts.InstrProfileOutput.empty() ? - DefaultProfileGenName : CodeGenOpts.InstrProfileOutput; - - // -fprofile-use. - if (CodeGenOpts.hasProfileIRUse()) -PGOOpt.ProfileUseFile = CodeGenOpts.ProfileInstrumentUsePath; - - if (!CodeGenOpts.SampleProfileFile.empty()) -PGOOpt.SampleProfileFile = CodeGenOpts.SampleProfileFile; + if (CodeGenOpts.hasProfileIRInstr()) +// -fprofile-generate. +PGOOpt = PGOOptions(CodeGenOpts.InstrProfileOutput.empty() +? DefaultProfileGenName +: CodeGenOpts.InstrProfileOutput, +"", "", true, CodeGenOpts.DebugInfoForProfiling); + else if (CodeGenOpts.hasProfileIRUse()) +// -fprofile-use. +PGOOpt = PGOOptions("", CodeGenOpts.ProfileInstrumentUsePath, "", false, +CodeGenOpts.DebugInfoForProfiling); + else if (!CodeGenOpts.SampleProfileFile.empty()) +// -fprofile-sample-use +PGOOpt = PGOOptions("", "", CodeGenOpts.SampleProfileFile, false, +CodeGenOpts.DebugInfoForProfiling); + else if (CodeGenOpts.DebugInfoForProfiling) +// -fdebug-info-for-profiling +PGOOpt = PGOOptions("", "", "", false, true); + else +PGOOpt = None; - // Only pass a PGO options struct if -fprofile-generate or - // -fprofile-use were passed on the cmdline. - PassBuilder PB(TM.get(), -(PGOOpt.RunProfileGen || - !PGOOpt.ProfileUseFile.empty() || - !PGOOpt.SampleProfileFile.empty()) ? -Optional(PGOOpt) : None); + PassBuilder PB(TM.get(), PGOOpt); LoopAnalysisManager LAM; FunctionAnalysisManager FAM; Index: lib/CodeGen/BackendUtil.cpp === --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -840,28 +840,29 @@ return; TheModule->setDataLayout(TM->createDataLayout()); - PGOOptions PGOOpt; + Optional PGOOpt; - // -fprofile-generate. - PGOOpt.RunProfileGen = CodeGenOpts.hasProfileIRInstr(); - if (PGOOpt.RunProfileGen) -PGOOpt.ProfileGenFile = CodeGenOpts.InstrProfileOutput.empty() ? - DefaultProfileGenName : CodeGenOpts.InstrProfileOutput; - - // -fprofile-use. - if (CodeGenOpts.hasProfileIRUse()) -PGOOpt.ProfileUseFile = CodeGenOpts.ProfileInstrumentUsePath; - - if (!CodeGenOpts.SampleProfileFile.empty()) -PGOOpt.SampleProfileFile = CodeGenOpts.SampleProfileFile; + if (CodeGenOpts.hasProfileIRInstr()) +// -fprofile-generate. +PGOOpt = PGOOptions(CodeGenOpts.InstrProfileOutput.empty() +? DefaultProfileGenName +: CodeGenOpts.InstrProfileOutput, +"", "", true, CodeGenOpts.DebugInfoForProfiling); + else if (CodeGenOpts.hasProfileIRUse()) +// -fprofile-use. +PGOOpt = PGOOptions("", CodeGenOpts.ProfileInstrumentUsePath, "", false, +CodeGenOpts.DebugInfoForProfiling); + else if (!CodeGenOpts.SampleProfileFile.empty()) +// -fprofile-sample-use +PGOOpt = PGOOptions("", "", CodeGenOpts.SampleProfileFile, false, +CodeGenOpts.DebugInfoForProfiling); + else if (CodeGenOpts.DebugInfoForProfiling) +// -fdebug-info-for-profiling +PGOOpt = PGOOptions("", "", "", false, true); + else +PGOOpt = None; - // Only pass a PGO options struct if -fprofile-generate or - // -fprofile-use were passed on the cmdline. - PassBuilder PB(TM.get(), -(PGOOpt.RunProfileGen || - !PGOOpt.ProfileUseFile.empty() || - !PGOOpt.SampleProfileFile.empty()) ? -Optional(PGOOpt) : None); + PassBuilder PB(TM.get(), PGOOpt); LoopAnalysisManager LAM; FunctionAnalysisManager FAM; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D35746: Make new PM honor -fdebug-info-for-profiling (clang side)
danielcdh marked 2 inline comments as done. danielcdh added inline comments. Comment at: lib/CodeGen/BackendUtil.cpp:847-859 if (PGOOpt.RunProfileGen) PGOOpt.ProfileGenFile = CodeGenOpts.InstrProfileOutput.empty() ? DefaultProfileGenName : CodeGenOpts.InstrProfileOutput; // -fprofile-use. if (CodeGenOpts.hasProfileIRUse()) PGOOpt.ProfileUseFile = CodeGenOpts.ProfileInstrumentUsePath; chandlerc wrote: > At least some of these seem mutually exclusive, so show that with `else if`? > > I wonder, are all of these mutually exclusive? -fprofile-generate, -fprofile-use and -fprofile-sample-use are mutually exclusive. https://reviews.llvm.org/D35746 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D35746: Make new PM honor -fdebug-info-for-profiling (clang side)
danielcdh marked an inline comment as done. danielcdh added a comment. Thanks for the review! In https://reviews.llvm.org/D35746#822498, @chandlerc wrote: > LGTM with a tiny tweak below. > > Would be good to add a test that this flag is being honored, either in this > patch or in a follow-up. I'll add the test in a follow-up patch. Could you help suggest how to add a test for this? Shall I just invoke "clang -cc1 -fexperimental-new-pass-manager" and check if discriminator is generated? That seems an integration test. https://reviews.llvm.org/D35746 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D30220: Only enable AddDiscriminator pass when -fdebug-info-for-profiling is true
danielcdh created this revision. AddDiscriminator pass is only useful for sample pgo. This patch restricts AddDiscriminator to -fdebug-info-for-profiling so that it does not introduce unecessary debug size increases for non-sample-pgo builds. https://reviews.llvm.org/D30220 Files: lib/CodeGen/BackendUtil.cpp lib/Frontend/CompilerInvocation.cpp test/CodeGenObjC/arc-linetable-autorelease.m Index: test/CodeGenObjC/arc-linetable-autorelease.m === --- test/CodeGenObjC/arc-linetable-autorelease.m +++ test/CodeGenObjC/arc-linetable-autorelease.m @@ -30,11 +30,10 @@ // CHECK: define {{.*}}_createBezierPathWithWidth // CHECK: load {{.*}} %path, align {{.*}}, !dbg ![[RET:[0-9]+]] // CHECK: call void @objc_storeStrong{{.*}} !dbg ![[ARC:[0-9]+]] - // CHECK: call {{.*}} @objc_autoreleaseReturnValue{{.*}} !dbg ![[ARC1:[0-9]+]] + // CHECK: call {{.*}} @objc_autoreleaseReturnValue{{.*}} !dbg ![[ARC]] // CHECK: ret {{.*}} !dbg ![[ARC]] // CHECK: ![[RET]] = !DILocation(line: [[@LINE+1]], scope: !{{.*}}) return path; - // CHECK: ![[ARC]] = !DILocation(line: [[@LINE+2]], scope: !{{.*}}) - // CHECK: ![[ARC1]] = !DILocation(line: [[@LINE+1]], scope: !{{.*}}) + // CHECK: ![[ARC]] = !DILocation(line: [[@LINE+1]], scope: !{{.*}}) } @end Index: lib/Frontend/CompilerInvocation.cpp === --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -545,8 +545,9 @@ Opts.DisableIntegratedAS = Args.hasArg(OPT_fno_integrated_as); Opts.Autolink = !Args.hasArg(OPT_fno_autolink); Opts.SampleProfileFile = Args.getLastArgValue(OPT_fprofile_sample_use_EQ); - Opts.DebugInfoForProfiling = Args.hasFlag( - OPT_fdebug_info_for_profiling, OPT_fno_debug_info_for_profiling, false); + Opts.DebugInfoForProfiling = Args.hasFlag(OPT_fdebug_info_for_profiling, +OPT_fno_debug_info_for_profiling, +!Opts.SampleProfileFile.empty()); setPGOInstrumentor(Opts, Args, Diags); Opts.InstrProfileOutput = Index: lib/CodeGen/BackendUtil.cpp === --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -339,8 +339,9 @@ if (TM) TM->adjustPassManager(PMBuilder); - PMBuilder.addExtension(PassManagerBuilder::EP_EarlyAsPossible, - addAddDiscriminatorsPass); + if (CodeGenOpts.DebugInfoForProfiling) +PMBuilder.addExtension(PassManagerBuilder::EP_EarlyAsPossible, + addAddDiscriminatorsPass); // In ObjC ARC mode, add the main ARC optimization passes. if (LangOpts.ObjCAutoRefCount) { Index: test/CodeGenObjC/arc-linetable-autorelease.m === --- test/CodeGenObjC/arc-linetable-autorelease.m +++ test/CodeGenObjC/arc-linetable-autorelease.m @@ -30,11 +30,10 @@ // CHECK: define {{.*}}_createBezierPathWithWidth // CHECK: load {{.*}} %path, align {{.*}}, !dbg ![[RET:[0-9]+]] // CHECK: call void @objc_storeStrong{{.*}} !dbg ![[ARC:[0-9]+]] - // CHECK: call {{.*}} @objc_autoreleaseReturnValue{{.*}} !dbg ![[ARC1:[0-9]+]] + // CHECK: call {{.*}} @objc_autoreleaseReturnValue{{.*}} !dbg ![[ARC]] // CHECK: ret {{.*}} !dbg ![[ARC]] // CHECK: ![[RET]] = !DILocation(line: [[@LINE+1]], scope: !{{.*}}) return path; - // CHECK: ![[ARC]] = !DILocation(line: [[@LINE+2]], scope: !{{.*}}) - // CHECK: ![[ARC1]] = !DILocation(line: [[@LINE+1]], scope: !{{.*}}) + // CHECK: ![[ARC]] = !DILocation(line: [[@LINE+1]], scope: !{{.*}}) } @end Index: lib/Frontend/CompilerInvocation.cpp === --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -545,8 +545,9 @@ Opts.DisableIntegratedAS = Args.hasArg(OPT_fno_integrated_as); Opts.Autolink = !Args.hasArg(OPT_fno_autolink); Opts.SampleProfileFile = Args.getLastArgValue(OPT_fprofile_sample_use_EQ); - Opts.DebugInfoForProfiling = Args.hasFlag( - OPT_fdebug_info_for_profiling, OPT_fno_debug_info_for_profiling, false); + Opts.DebugInfoForProfiling = Args.hasFlag(OPT_fdebug_info_for_profiling, +OPT_fno_debug_info_for_profiling, +!Opts.SampleProfileFile.empty()); setPGOInstrumentor(Opts, Args, Diags); Opts.InstrProfileOutput = Index: lib/CodeGen/BackendUtil.cpp === --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -339,8 +339,9 @@ if (TM) TM->adjustPassManager(PMBuilder); - PMBuilder.addExtension(PassManagerBuilder::EP_EarlyAsPossible, - addAddDiscriminatorsPass); + if (CodeGenOpts.DebugInfoForProfiling) +PMBuilder.addExtension(Pa
[PATCH] D30220: Only enable AddDiscriminator pass when -fdebug-info-for-profiling is true
danielcdh updated this revision to Diff 89258. danielcdh added a comment. update https://reviews.llvm.org/D30220 Files: lib/CodeGen/BackendUtil.cpp test/CodeGenObjC/arc-linetable-autorelease.m Index: test/CodeGenObjC/arc-linetable-autorelease.m === --- test/CodeGenObjC/arc-linetable-autorelease.m +++ test/CodeGenObjC/arc-linetable-autorelease.m @@ -30,11 +30,10 @@ // CHECK: define {{.*}}_createBezierPathWithWidth // CHECK: load {{.*}} %path, align {{.*}}, !dbg ![[RET:[0-9]+]] // CHECK: call void @objc_storeStrong{{.*}} !dbg ![[ARC:[0-9]+]] - // CHECK: call {{.*}} @objc_autoreleaseReturnValue{{.*}} !dbg ![[ARC1:[0-9]+]] + // CHECK: call {{.*}} @objc_autoreleaseReturnValue{{.*}} !dbg ![[ARC]] // CHECK: ret {{.*}} !dbg ![[ARC]] // CHECK: ![[RET]] = !DILocation(line: [[@LINE+1]], scope: !{{.*}}) return path; - // CHECK: ![[ARC]] = !DILocation(line: [[@LINE+2]], scope: !{{.*}}) - // CHECK: ![[ARC1]] = !DILocation(line: [[@LINE+1]], scope: !{{.*}}) + // CHECK: ![[ARC]] = !DILocation(line: [[@LINE+1]], scope: !{{.*}}) } @end Index: lib/CodeGen/BackendUtil.cpp === --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -339,8 +339,10 @@ if (TM) TM->adjustPassManager(PMBuilder); - PMBuilder.addExtension(PassManagerBuilder::EP_EarlyAsPossible, - addAddDiscriminatorsPass); + if (CodeGenOpts.DebugInfoForProfiling || + !CodeGenOpts.SampleProfileFile.empty()) +PMBuilder.addExtension(PassManagerBuilder::EP_EarlyAsPossible, + addAddDiscriminatorsPass); // In ObjC ARC mode, add the main ARC optimization passes. if (LangOpts.ObjCAutoRefCount) { Index: test/CodeGenObjC/arc-linetable-autorelease.m === --- test/CodeGenObjC/arc-linetable-autorelease.m +++ test/CodeGenObjC/arc-linetable-autorelease.m @@ -30,11 +30,10 @@ // CHECK: define {{.*}}_createBezierPathWithWidth // CHECK: load {{.*}} %path, align {{.*}}, !dbg ![[RET:[0-9]+]] // CHECK: call void @objc_storeStrong{{.*}} !dbg ![[ARC:[0-9]+]] - // CHECK: call {{.*}} @objc_autoreleaseReturnValue{{.*}} !dbg ![[ARC1:[0-9]+]] + // CHECK: call {{.*}} @objc_autoreleaseReturnValue{{.*}} !dbg ![[ARC]] // CHECK: ret {{.*}} !dbg ![[ARC]] // CHECK: ![[RET]] = !DILocation(line: [[@LINE+1]], scope: !{{.*}}) return path; - // CHECK: ![[ARC]] = !DILocation(line: [[@LINE+2]], scope: !{{.*}}) - // CHECK: ![[ARC1]] = !DILocation(line: [[@LINE+1]], scope: !{{.*}}) + // CHECK: ![[ARC]] = !DILocation(line: [[@LINE+1]], scope: !{{.*}}) } @end Index: lib/CodeGen/BackendUtil.cpp === --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -339,8 +339,10 @@ if (TM) TM->adjustPassManager(PMBuilder); - PMBuilder.addExtension(PassManagerBuilder::EP_EarlyAsPossible, - addAddDiscriminatorsPass); + if (CodeGenOpts.DebugInfoForProfiling || + !CodeGenOpts.SampleProfileFile.empty()) +PMBuilder.addExtension(PassManagerBuilder::EP_EarlyAsPossible, + addAddDiscriminatorsPass); // In ObjC ARC mode, add the main ARC optimization passes. if (LangOpts.ObjCAutoRefCount) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D30220: Only enable AddDiscriminator pass when -fdebug-info-for-profiling is true
danielcdh added a comment. You are right, only discriminator is needed, the encoding and emission part should be orthogonal. Patch updated. https://reviews.llvm.org/D30220 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D25435: Add -femit-accurate-debug-info to emit more debug info for sample pgo profile collection
danielcdh updated this revision to Diff 79629. danielcdh marked an inline comment as done. danielcdh added a comment. Change the flag to -fprof-debug, which is more concise. The flag name is still open for discussion. https://reviews.llvm.org/D25435 Files: include/clang/Driver/Options.td include/clang/Frontend/CodeGenOptions.def lib/CodeGen/CGDebugInfo.cpp lib/Driver/Tools.cpp lib/Frontend/CompilerInvocation.cpp test/Driver/clang_f_opts.c Index: test/Driver/clang_f_opts.c === --- test/Driver/clang_f_opts.c +++ test/Driver/clang_f_opts.c @@ -469,3 +469,8 @@ // CHECK-WCHAR2: -fshort-wchar // CHECK-WCHAR2-NOT: -fno-short-wchar // DELIMITERS: {{^ *"}} + +// RUN: %clang -### -S -fno-prof-debug -fprof-debug %s 2>&1 | FileCheck -check-prefix=CHECK-PROF-DEBUG %s +// RUN: %clang -### -S -fprof-debug -fno-prof-debug %s 2>&1 | FileCheck -check-prefix=CHECK-NO-PROF-DEBUG %s +// CHECK-PROF-DEBUG: -fprof-debug +// CHECK-NO-PROF-DEBUG-NOT: -fprof-debug Index: lib/Frontend/CompilerInvocation.cpp === --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -538,6 +538,7 @@ Opts.DisableIntegratedAS = Args.hasArg(OPT_fno_integrated_as); Opts.Autolink = !Args.hasArg(OPT_fno_autolink); Opts.SampleProfileFile = Args.getLastArgValue(OPT_fprofile_sample_use_EQ); + Opts.ProfDebug = Args.hasFlag(OPT_fprof_debug, OPT_fno_prof_debug, false); setPGOInstrumentor(Opts, Args, Diags); Opts.InstrProfileOutput = Index: lib/Driver/Tools.cpp === --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -5508,6 +5508,10 @@ A->render(Args, CmdArgs); } + if (Args.hasFlag(options::OPT_fprof_debug, + options::OPT_fno_prof_debug, false)) +CmdArgs.push_back("-fprof-debug"); + // -fbuiltin is default unless -mkernel is used. bool UseBuiltins = Args.hasFlag(options::OPT_fbuiltin, options::OPT_fno_builtin, Index: lib/CodeGen/CGDebugInfo.cpp === --- lib/CodeGen/CGDebugInfo.cpp +++ lib/CodeGen/CGDebugInfo.cpp @@ -2739,9 +2739,10 @@ } // No need to replicate the linkage name if it isn't different from the // subprogram name, no need to have it at all unless coverage is enabled or - // debug is set to more than just line tables. + // debug is set to more than just line tables or extra debug info is needed. if (LinkageName == Name || (!CGM.getCodeGenOpts().EmitGcovArcs && !CGM.getCodeGenOpts().EmitGcovNotes && + !CGM.getCodeGenOpts().ProfDebug && DebugKind <= codegenoptions::DebugLineTablesOnly)) LinkageName = StringRef(); Index: include/clang/Frontend/CodeGenOptions.def === --- include/clang/Frontend/CodeGenOptions.def +++ include/clang/Frontend/CodeGenOptions.def @@ -256,6 +256,9 @@ /// Whether copy relocations support is available when building as PIE. CODEGENOPT(PIECopyRelocations, 1, 0) +/// Whether emit extra debug info for sample pgo profile collection. +CODEGENOPT(ProfDebug, 1, 0) + #undef CODEGENOPT #undef ENUM_CODEGENOPT #undef VALUE_CODEGENOPT Index: include/clang/Driver/Options.td === --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -509,6 +509,12 @@ HelpText<"Enable sample-based profile guided optimizations">; def fauto_profile_EQ : Joined<["-"], "fauto-profile=">, Alias; +def fprof_debug : Flag<["-"], "fprof-debug">, Group, +Flags<[CC1Option]>, +HelpText<"Emit extra debug info to make sample profile more accurate.">; +def fno_prof_debug : Flag<["-"], "fno-prof-debug">, Group, +Flags<[DriverOption]>, +HelpText<"Do not emit extra debug info for sample profiler.">; def fprofile_instr_generate : Flag<["-"], "fprofile-instr-generate">, Group, Flags<[DriverOption]>, HelpText<"Generate instrumented code to collect execution counts into default.profraw file (overriden by '=' form of option or LLVM_PROFILE_FILE env var)">; Index: test/Driver/clang_f_opts.c === --- test/Driver/clang_f_opts.c +++ test/Driver/clang_f_opts.c @@ -469,3 +469,8 @@ // CHECK-WCHAR2: -fshort-wchar // CHECK-WCHAR2-NOT: -fno-short-wchar // DELIMITERS: {{^ *"}} + +// RUN: %clang -### -S -fno-prof-debug -fprof-debug %s 2>&1 | FileCheck -check-prefix=CHECK-PROF-DEBUG %s +// RUN: %clang -### -S -fprof-debug -fno-prof-debug %s 2>&1 | FileCheck -check-prefix=CHECK-NO-PROF-DEBUG %s +// CHECK-PROF-DEBUG: -fprof-debug +// CHECK-NO-PROF-DEBUG-NOT: -fprof-debug Index: lib/Frontend/CompilerInvocation.cpp =
[PATCH] D25435: Add -femit-accurate-debug-info to emit more debug info for sample pgo profile collection
danielcdh updated this revision to Diff 79770. danielcdh added a comment. change the flag name to -fprofile-debug https://reviews.llvm.org/D25435 Files: include/clang/Driver/Options.td include/clang/Frontend/CodeGenOptions.def lib/CodeGen/BackendUtil.cpp lib/CodeGen/CGDebugInfo.cpp lib/Driver/Tools.cpp lib/Frontend/CompilerInvocation.cpp test/Driver/clang_f_opts.c Index: test/Driver/clang_f_opts.c === --- test/Driver/clang_f_opts.c +++ test/Driver/clang_f_opts.c @@ -469,3 +469,8 @@ // CHECK-WCHAR2: -fshort-wchar // CHECK-WCHAR2-NOT: -fno-short-wchar // DELIMITERS: {{^ *"}} + +// RUN: %clang -### -S -fno-profile-debug -fprofile-debug %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-DEBUG %s +// RUN: %clang -### -S -fprofile-debug -fno-profile-debug %s 2>&1 | FileCheck -check-prefix=CHECK-NO-PROFILE-DEBUG %s +// CHECK-PROFILE-DEBUG: -fprofile-debug +// CHECK-NO-PROFILE-DEBUG-NOT: -fprofile-debug Index: lib/Frontend/CompilerInvocation.cpp === --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -538,6 +538,8 @@ Opts.DisableIntegratedAS = Args.hasArg(OPT_fno_integrated_as); Opts.Autolink = !Args.hasArg(OPT_fno_autolink); Opts.SampleProfileFile = Args.getLastArgValue(OPT_fprofile_sample_use_EQ); + Opts.ProfileDebug = Args.hasFlag(OPT_fprofile_debug, +OPT_fno_profile_debug, false); setPGOInstrumentor(Opts, Args, Diags); Opts.InstrProfileOutput = Index: lib/Driver/Tools.cpp === --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -5508,6 +5508,10 @@ A->render(Args, CmdArgs); } + if (Args.hasFlag(options::OPT_fprofile_debug, + options::OPT_fno_profile_debug, false)) +CmdArgs.push_back("-fprofile-debug"); + // -fbuiltin is default unless -mkernel is used. bool UseBuiltins = Args.hasFlag(options::OPT_fbuiltin, options::OPT_fno_builtin, Index: lib/CodeGen/CGDebugInfo.cpp === --- lib/CodeGen/CGDebugInfo.cpp +++ lib/CodeGen/CGDebugInfo.cpp @@ -2739,9 +2739,10 @@ } // No need to replicate the linkage name if it isn't different from the // subprogram name, no need to have it at all unless coverage is enabled or - // debug is set to more than just line tables. + // debug is set to more than just line tables or extra debug info is needed. if (LinkageName == Name || (!CGM.getCodeGenOpts().EmitGcovArcs && !CGM.getCodeGenOpts().EmitGcovNotes && + !CGM.getCodeGenOpts().ProfileDebug && DebugKind <= codegenoptions::DebugLineTablesOnly)) LinkageName = StringRef(); Index: lib/CodeGen/BackendUtil.cpp === --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -576,6 +576,7 @@ Options.DisableIntegratedAS = CodeGenOpts.DisableIntegratedAS; Options.CompressDebugSections = CodeGenOpts.CompressDebugSections; Options.RelaxELFRelocations = CodeGenOpts.RelaxELFRelocations; + Options.ProfileDebug = CodeGenOpts.ProfileDebug; // Set EABI version. Options.EABIVersion = llvm::StringSwitch(TargetOpts.EABIVersion) Index: include/clang/Frontend/CodeGenOptions.def === --- include/clang/Frontend/CodeGenOptions.def +++ include/clang/Frontend/CodeGenOptions.def @@ -256,6 +256,9 @@ /// Whether copy relocations support is available when building as PIE. CODEGENOPT(PIECopyRelocations, 1, 0) +/// Whether emit extra debug info for sample pgo profile collection. +CODEGENOPT(ProfileDebug, 1, 0) + #undef CODEGENOPT #undef ENUM_CODEGENOPT #undef VALUE_CODEGENOPT Index: include/clang/Driver/Options.td === --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -509,6 +509,12 @@ HelpText<"Enable sample-based profile guided optimizations">; def fauto_profile_EQ : Joined<["-"], "fauto-profile=">, Alias; +def fprofile_debug : Flag<["-"], "fprofile-debug">, Group, +Flags<[CC1Option]>, +HelpText<"Emit extra debug info to make sample profile more accurate.">; +def fno_profile_debug : Flag<["-"], "fno-profile-debug">, Group, +Flags<[DriverOption]>, +HelpText<"Do not emit extra debug info for sample profiler.">; def fprofile_instr_generate : Flag<["-"], "fprofile-instr-generate">, Group, Flags<[DriverOption]>, HelpText<"Generate instrumented code to collect execution counts into default.profraw file (overriden by '=' form of option or LLVM_PROFILE_FILE env var)">; Index: test/Driver/clang_f_opts.c === --- test/Dr
[PATCH] D25435: Add -femit-accurate-debug-info to emit more debug info for sample pgo profile collection
danielcdh added a comment. ping https://reviews.llvm.org/D25435 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D25435: Add -femit-accurate-debug-info to emit more debug info for sample pgo profile collection
danielcdh added inline comments. Comment at: lib/CodeGen/CGDebugInfo.cpp:2743-2745 if (LinkageName == Name || (!CGM.getCodeGenOpts().EmitGcovArcs && !CGM.getCodeGenOpts().EmitGcovNotes && + !CGM.getCodeGenOpts().ProfileDebug && echristo wrote: > Should we be encapsulating all of these for profile debug info? I.e. I think > coverage analysis is going to want the same things. Do you mean that -fcoverage also implies -fprofile-debug? I think the reason we introduce -fprofile-debug is that it has different requirments for debug info than coverage/sanitizer. E.g. we want to emit discriminator for -fprofile-debug, but not coverage/sanitizer. https://reviews.llvm.org/D25435 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D25435: Add -femit-accurate-debug-info to emit more debug info for sample pgo profile collection
danielcdh added inline comments. Comment at: lib/CodeGen/CGDebugInfo.cpp:2743-2745 if (LinkageName == Name || (!CGM.getCodeGenOpts().EmitGcovArcs && !CGM.getCodeGenOpts().EmitGcovNotes && + !CGM.getCodeGenOpts().ProfileDebug && echristo wrote: > danielcdh wrote: > > echristo wrote: > > > Should we be encapsulating all of these for profile debug info? I.e. I > > > think coverage analysis is going to want the same things. > > Do you mean that -fcoverage also implies -fprofile-debug? > > > > I think the reason we introduce -fprofile-debug is that it has different > > requirments for debug info than coverage/sanitizer. E.g. we want to emit > > discriminator for -fprofile-debug, but not coverage/sanitizer. > So, what are the differences here? I imagine that profile debugging will want > accurate source information. Perhaps we should hash this out in the thread > that dblaikie has started on llvm-dev. The discussion about introducing this flag is in the thread of http://lists.llvm.org/pipermail/llvm-dev/2016-November/107645.html Basically -fprofile-debug not only requires accurate source information, it also requires: >> 1. emit linkage name in all subprograms >> 2. emit discriminator with dup-factor copy-factor encoded >> 3. use-unknown-locations=true The above 3 items are not required by -fcoverage. That's why we introduce -fprofile-debug to record these extra debug info. https://reviews.llvm.org/D25435 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D25435: Add -femit-accurate-debug-info to emit more debug info for sample pgo profile collection
danielcdh added a comment. In https://reviews.llvm.org/D25435#619169, @hfinkel wrote: > In https://reviews.llvm.org/D25435#609320, @danielcdh wrote: > > > change the flag name to -fprofile-debug > > > I don't really like this name because it sounds like it might be enabling > some kind of debugging of the profiling. How about > -fdebug-info-for-profiling. Another options is to make it a mode for -g such > as -gprofiling. Thanks for the comment. I'm OK with -fdebug-info-for-profiling. If no one objects, I'll update the patch tomorrow morning. About -gprofiling, as discussed in http://lists.llvm.org/pipermail/llvm-dev/2016-November/107454.html, this should be a -f option instead of -g option. https://reviews.llvm.org/D25435 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D27744: Create SampleProfileLoader pass in llvm instead of clang
danielcdh created this revision. danielcdh added reviewers: dnovillo, tejohnson, davidxl. danielcdh added a subscriber: cfe-commits. Herald added a subscriber: mehdi_amini. We used to create SampleProfileLoader pass in clang. This makes LTO/ThinLTO unable to add this pass in the linker plugin. This patch moves the SampleProfileLoader pass creation from clang to llvm pass manager builder. https://reviews.llvm.org/D27744 Files: lib/CodeGen/BackendUtil.cpp Index: lib/CodeGen/BackendUtil.cpp === --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -464,10 +464,8 @@ if (CodeGenOpts.hasProfileIRUse()) PMBuilder.PGOInstrUse = CodeGenOpts.ProfileInstrumentUsePath; - if (!CodeGenOpts.SampleProfileFile.empty()) { -MPM.add(createPruneEHPass()); -MPM.add(createSampleProfileLoaderPass(CodeGenOpts.SampleProfileFile)); - } + if (!CodeGenOpts.SampleProfileFile.empty()) +PMBuilder.PGOSampleUse = CodeGenOpts.SampleProfileFile; PMBuilder.populateFunctionPassManager(FPM); PMBuilder.populateModulePassManager(MPM); Index: lib/CodeGen/BackendUtil.cpp === --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -464,10 +464,8 @@ if (CodeGenOpts.hasProfileIRUse()) PMBuilder.PGOInstrUse = CodeGenOpts.ProfileInstrumentUsePath; - if (!CodeGenOpts.SampleProfileFile.empty()) { -MPM.add(createPruneEHPass()); -MPM.add(createSampleProfileLoaderPass(CodeGenOpts.SampleProfileFile)); - } + if (!CodeGenOpts.SampleProfileFile.empty()) +PMBuilder.PGOSampleUse = CodeGenOpts.SampleProfileFile; PMBuilder.populateFunctionPassManager(FPM); PMBuilder.populateModulePassManager(MPM); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits