r311707 - Expose -mllvm -accurate-sample-profile to clang.
Dehao Chen via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 24 14:37:33 PDT 2017
Author: dehao
Date: Thu Aug 24 14:37:33 2017
New Revision: 311707
URL: http://llvm.org/viewvc/llvm-project?rev=311707&view=rev
Log:
Expose -mllvm -accurate-sample-profile to clang.
Summary: With accurate sample profile, we can do more aggressive size optimization. For some size-critical application, this can reduce the text size by 20%
Reviewers: davidxl, rsmith
Reviewed By: davidxl, rsmith
Subscribers: mehdi_amini, eraman, sanjoy, cfe-commits
Differential Revision: https://reviews.llvm.org/D37091
Added:
cfe/trunk/test/CodeGen/profile-sample-accurate.c
cfe/trunk/test/Integration/thinlto_profile_sample_accurate.c
Modified:
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Frontend/CodeGenOptions.def
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/test/Driver/clang_f_opts.c
Modified: cfe/trunk/include/clang/Driver/Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=311707&r1=311706&r2=311707&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Thu Aug 24 14:37:33 2017
@@ -637,12 +637,25 @@ def fno_profile_sample_use : Flag<["-"],
def fprofile_sample_use_EQ : Joined<["-"], "fprofile-sample-use=">,
Group<f_Group>, Flags<[DriverOption, CC1Option]>,
HelpText<"Enable sample-based profile guided optimizations">;
+def fprofile_sample_accurate : Flag<["-"], "fprofile-sample-accurate">,
+ Group<f_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<f_Group>, Flags<[DriverOption]>;
def fauto_profile : Flag<["-"], "fauto-profile">, Group<f_Group>,
Alias<fprofile_sample_use>;
def fno_auto_profile : Flag<["-"], "fno-auto-profile">, Group<f_Group>,
Alias<fno_profile_sample_use>;
def fauto_profile_EQ : Joined<["-"], "fauto-profile=">,
Alias<fprofile_sample_use_EQ>;
+def fauto_profile_accurate : Flag<["-"], "fauto-profile-accurate">,
+ Group<f_Group>, Alias<fprofile_sample_accurate>;
+def fno_auto_profile_accurate : Flag<["-"], "fno-auto-profile-accurate">,
+ Group<f_Group>, Alias<fno_profile_sample_accurate>;
def fdebug_info_for_profiling : Flag<["-"], "fdebug-info-for-profiling">, Group<f_Group>,
Flags<[CC1Option]>,
HelpText<"Emit extra debug info to make sample profile more accurate.">;
Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.def?rev=311707&r1=311706&r2=311707&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.def (original)
+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.def Thu Aug 24 14:37:33 2017
@@ -183,6 +183,7 @@ CODEGENOPT(UnsafeFPMath , 1, 0) ///
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.
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=311707&r1=311706&r2=311707&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Thu Aug 24 14:37:33 2017
@@ -838,6 +838,10 @@ void CodeGenFunction::StartFunction(Glob
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<FunctionDecl>(D))
Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=311707&r1=311706&r2=311707&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Thu Aug 24 14:37:33 2017
@@ -2340,6 +2340,10 @@ void Clang::ConstructJob(Compilation &C,
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");
Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=311707&r1=311706&r2=311707&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Thu Aug 24 14:37:33 2017
@@ -652,6 +652,8 @@ static bool ParseCodeGenArgs(CodeGenOpti
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)) {
Added: cfe/trunk/test/CodeGen/profile-sample-accurate.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/profile-sample-accurate.c?rev=311707&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/profile-sample-accurate.c (added)
+++ cfe/trunk/test/CodeGen/profile-sample-accurate.c Thu Aug 24 14:37:33 2017
@@ -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() {
+}
Modified: cfe/trunk/test/Driver/clang_f_opts.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/clang_f_opts.c?rev=311707&r1=311706&r2=311707&view=diff
==============================================================================
--- cfe/trunk/test/Driver/clang_f_opts.c (original)
+++ cfe/trunk/test/Driver/clang_f_opts.c Thu Aug 24 14:37:33 2017
@@ -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"
Added: cfe/trunk/test/Integration/thinlto_profile_sample_accurate.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Integration/thinlto_profile_sample_accurate.c?rev=311707&view=auto
==============================================================================
--- cfe/trunk/test/Integration/thinlto_profile_sample_accurate.c (added)
+++ cfe/trunk/test/Integration/thinlto_profile_sample_accurate.c Thu Aug 24 14:37:33 2017
@@ -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() {
+}
More information about the cfe-commits
mailing list