[PATCH] D34082: [Frontend 'Show hotness' can be used with a sampling profile

Brian Gesiak via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Jun 10 10:35:37 PDT 2017


modocache created this revision.

Prior to this change, using `-fdiagnostics-show-hotness` with a sampling
profile specified via `-fprofile-sample-use=` would result in the Clang
frontend emitting a warning: "argument '-fdiagnostics-show-hotness' requires
profile-guided optimization information". Of course, a sampling profile
*is* profile-guided optimization information, so the warning is misleading.
Furthermore, despite the warning, hotness was displayed based on the data in
the sampling profile.

Prevent the warning from being emitted when a sampling profile is used, and
add a test that verifies this.


https://reviews.llvm.org/D34082

Files:
  lib/Frontend/CompilerInvocation.cpp
  test/Frontend/Inputs/optimization-remark-with-hotness-sample.proftext
  test/Frontend/optimization-remark-with-hotness.c


Index: test/Frontend/optimization-remark-with-hotness.c
===================================================================
--- test/Frontend/optimization-remark-with-hotness.c
+++ test/Frontend/optimization-remark-with-hotness.c
@@ -1,6 +1,11 @@
+// Generate instrumentation and sampling profile data.
 // RUN: llvm-profdata merge \
-// RUN:     %S/Inputs/optimization-remark-with-hotness.proftext   \
+// RUN:     %S/Inputs/optimization-remark-with-hotness.proftext \
 // RUN:     -o %t.profdata
+// RUN: llvm-profdata merge -sample \
+// RUN:     %S/Inputs/optimization-remark-with-hotness-sample.proftext \
+// RUN:     -o %t-sample.profdata
+//
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \
 // RUN:     optimization-remark-with-hotness.c %s -emit-llvm-only \
 // RUN:     -fprofile-instrument-use-path=%t.profdata -Rpass=inline \
@@ -22,6 +27,11 @@
 // RUN:     -check-prefix=HOTNESS_OFF %s
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \
 // RUN:     optimization-remark-with-hotness.c %s -emit-llvm-only \
+// RUN:     -fprofile-sample-use=%t-sample.profdata -Rpass=inline \
+// RUN:     -Rpass-analysis=inline -fdiagnostics-show-hotness  2>&1 | FileCheck \
+// RUN:     -check-prefix=PGO_ENABLED %s
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \
+// RUN:     optimization-remark-with-hotness.c %s -emit-llvm-only \
 // RUN:     -Rpass=inline -Rpass-analysis=inline -fdiagnostics-show-hotness  2>&1 \
 // RUN:     | FileCheck -check-prefix=NO_PGO %s
 
@@ -33,6 +43,7 @@
 void bar(int x) {
   // HOTNESS_OFF: foo inlined into bar
   // HOTNESS_OFF-NOT: hotness:
+  // PGO_ENABLED-NOT: '-fdiagnostics-show-hotness' requires profile-guided optimization information
   // NO_PGO: '-fdiagnostics-show-hotness' requires profile-guided optimization information
   // expected-remark at +2 {{foo should always be inlined (cost=always) (hotness: 30)}}
   // expected-remark at +1 {{foo inlined into bar (hotness: 30)}}
Index: test/Frontend/Inputs/optimization-remark-with-hotness-sample.proftext
===================================================================
--- /dev/null
+++ test/Frontend/Inputs/optimization-remark-with-hotness-sample.proftext
@@ -0,0 +1,6 @@
+bar:15:0
+  1: foo:15
+    1: 15
+main:100:0
+  1: 100
+
Index: lib/Frontend/CompilerInvocation.cpp
===================================================================
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -884,14 +884,18 @@
 
   Opts.DiagnosticsWithHotness =
       Args.hasArg(options::OPT_fdiagnostics_show_hotness);
+  bool UsingSampleProfile = !Opts.SampleProfileFile.empty();
+
   if (Opts.DiagnosticsWithHotness &&
-      Opts.getProfileUse() == CodeGenOptions::ProfileNone)
+      Opts.getProfileUse() == CodeGenOptions::ProfileNone &&
+      !UsingSampleProfile) {
     Diags.Report(diag::warn_drv_fdiagnostics_show_hotness_requires_pgo);
+  }
 
   // If the user requested to use a sample profile for PGO, then the
   // backend will need to track source location information so the profile
   // can be incorporated into the IR.
-  if (!Opts.SampleProfileFile.empty())
+  if (UsingSampleProfile)
     NeedLocTracking = true;
 
   // If the user requested a flag that requires source locations available in


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34082.102121.patch
Type: text/x-patch
Size: 3293 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170610/6443dd0a/attachment.bin>


More information about the cfe-commits mailing list