diff options
Diffstat (limited to 'clang')
-rw-r--r-- | clang/include/clang/Driver/Options.td | 13 | ||||
-rw-r--r-- | clang/include/clang/Frontend/CodeGenOptions.def | 1 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenFunction.cpp | 4 | ||||
-rw-r--r-- | clang/lib/Driver/ToolChains/Clang.cpp | 4 | ||||
-rw-r--r-- | clang/lib/Frontend/CompilerInvocation.cpp | 2 | ||||
-rw-r--r-- | clang/test/CodeGen/profile-sample-accurate.c | 7 | ||||
-rw-r--r-- | clang/test/Driver/clang_f_opts.c | 3 | ||||
-rw-r--r-- | clang/test/Integration/thinlto_profile_sample_accurate.c | 9 |
8 files changed, 43 insertions, 0 deletions
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 6f40bb03e35..2c58e27363c 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -637,12 +637,25 @@ def fno_profile_sample_use : Flag<["-"], "fno-profile-sample-use">, Group<f_Grou 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.">; diff --git a/clang/include/clang/Frontend/CodeGenOptions.def b/clang/include/clang/Frontend/CodeGenOptions.def index 6a866fe5072..c9040e7e401 100644 --- a/clang/include/clang/Frontend/CodeGenOptions.def +++ b/clang/include/clang/Frontend/CodeGenOptions.def @@ -183,6 +183,7 @@ CODEGENOPT(UnsafeFPMath , 1, 0) ///< Allow unsafe floating point optzns. 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. diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 17295ae2be8..a9a1a53be20 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -838,6 +838,10 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, 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)) diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 35dcf206abb..fa768b70c53 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -2340,6 +2340,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, 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"); diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 24a08e84dc4..aea3af98285 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -652,6 +652,8 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, 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)) { diff --git a/clang/test/CodeGen/profile-sample-accurate.c b/clang/test/CodeGen/profile-sample-accurate.c new file mode 100644 index 00000000000..cf628d55cf5 --- /dev/null +++ b/clang/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() { +} diff --git a/clang/test/Driver/clang_f_opts.c b/clang/test/Driver/clang_f_opts.c index c17cec6eba9..bb058a00cdf 100644 --- a/clang/test/Driver/clang_f_opts.c +++ b/clang/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" diff --git a/clang/test/Integration/thinlto_profile_sample_accurate.c b/clang/test/Integration/thinlto_profile_sample_accurate.c new file mode 100644 index 00000000000..d7966c215cb --- /dev/null +++ b/clang/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() { +} |