[PATCH] D37091: Expose -mllvm -accurate-sample-profile to clang.

Dehao Chen via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 23 19:52:44 PDT 2017


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<f_Group>;
 def fno_PIE : Flag<["-"], "fno-PIE">, Group<f_Group>;
 def faccess_control : Flag<["-"], "faccess-control">, Group<f_Group>;
+def faccurate_sample_profile : Flag<["-"], "faccurate-sample-profile">,
+  Group<f_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<f_Group>, Flags<[DriverOption]>;
+
 def fallow_unsupported : Flag<["-"], "fallow-unsupported">, Group<f_Group>;
 def fapple_kext : Flag<["-"], "fapple-kext">, Group<f_Group>, Flags<[CC1Option]>,
   HelpText<"Use Apple's kernel extensions ABI">;
@@ -643,6 +651,10 @@
     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<faccurate_sample_profile>;
+def fno_auto_profile_accurate : Flag<["-"], "fno-auto-profile-accurate">,
+    Group<f_Group>, Alias<fno_accurate_sample_profile>;
 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.">;
Index: docs/ClangCommandLineReference.rst
===================================================================
--- docs/ClangCommandLineReference.rst
+++ docs/ClangCommandLineReference.rst
@@ -170,6 +170,11 @@
 
 .. option:: -exported\_symbols\_list <arg>
 
+.. 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=<arg>
 
 .. option:: -fcuda-approx-transcendentals, -fno-cuda-approx-transcendentals


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37091.112496.patch
Type: text/x-patch
Size: 3533 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170824/c5dd9c0e/attachment.bin>


More information about the cfe-commits mailing list