public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Indu Bhagat <indu.bhagat@oracle.com>
To: "Martin Liška" <mliska@suse.cz>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] PR86957
Date: Fri, 21 Sep 2018 23:23:00 -0000	[thread overview]
Message-ID: <e29237f1-eff5-42a7-3b35-ed892868a789@oracle.com> (raw)
In-Reply-To: <20180917105249.GA49438@kam.mff.cuni.cz>

[-- Attachment #1: Type: text/plain, Size: 1085 bytes --]

Attached is the refreshed patch for trunk.

After commit 264462 (Remove arc profile histogram in non-LTO mode.), the API
of get_coverage_counts was changed a bit. So the main difference between the
current version of my patch from the previous one is that :

Now I use
+      if (counter == GCOV_COUNTER_ARCS)
+       warning_at (DECL_SOURCE_LOCATION (current_function_decl),
+                   OPT_Wmissing_profile,
+                   "profile for function %qD not found in profile data",
+                   current_function_decl);

instead of
+      if (summary)
+       warning_at (DECL_SOURCE_LOCATION (current_function_decl),
+                   OPT_Wmissing_profile,
+                   "profile for function %qD not found in profile data",
+                   current_function_decl);

to warn about missing profile of a function only once (get_coverage_counts is
called from two diff flows : getting exec counts for arc counter and computing
histogram for other other counters)

I am not sure of any better way to avoid superfluous warnings per function.

Is the patch OK ?


[-- Attachment #2: pr86957-ver3.patch --]
[-- Type: text/x-patch, Size: 6336 bytes --]

diff --git a/gcc/common.opt b/gcc/common.opt
index ef6a630..53aac19 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -811,6 +811,10 @@ Wcoverage-mismatch
 Common Var(warn_coverage_mismatch) Init(1) Warning
 Warn in case profiles in -fprofile-use do not match.
 
+Wmissing-profile
+Common Var(warn_missing_profile) Init(1) Warning
+Warn in case profiles in -fprofile-use do not exist.
+
 Wvector-operation-performance
 Common Var(warn_vector_operation_performance) Warning
 Warn when a vector operation is compiled outside the SIMD.
diff --git a/gcc/coverage.c b/gcc/coverage.c
index 26cce2b..4b6df8a 100644
--- a/gcc/coverage.c
+++ b/gcc/coverage.c
@@ -304,16 +304,23 @@ get_coverage_counts (unsigned counter, unsigned cfg_checksum,
     {
       static int warned = 0;
 
-      if (!warned++ && dump_enabled_p ())
+      if (!warned++)
 	{
-	  dump_user_location_t loc
-	    = dump_user_location_t::from_location_t (input_location);
-	  dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, loc,
+	  warning (OPT_Wmissing_profile,
+		   "%qs profile count data file not found",
+		   da_file_name);
+	  if (dump_enabled_p ())
+	    {
+	      dump_user_location_t loc
+		= dump_user_location_t::from_location_t (input_location);
+	      dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, loc,
+			       "file %s not found\n",
+			       da_file_name);
+	      dump_printf (MSG_OPTIMIZED_LOCATIONS,
 			   (flag_guess_branch_prob
-			    ? "file %s not found, execution counts estimated\n"
-			    : "file %s not found, execution counts assumed to "
-			    "be zero\n"),
-			   da_file_name);
+			    ? "execution counts estimated\n"
+			    : "execution counts assumed to be zero\n"));
+	    }
 	}
       return NULL;
     }
@@ -327,10 +334,17 @@ get_coverage_counts (unsigned counter, unsigned cfg_checksum,
   elt.ctr = counter;
   entry = counts_hash->find (&elt);
   if (!entry)
-    /* The function was not emitted, or is weak and not chosen in the
-       final executable.  Silently fail, because there's nothing we
-       can do about it.  */
-    return NULL;
+    {
+      if (counter == GCOV_COUNTER_ARCS)
+	warning_at (DECL_SOURCE_LOCATION (current_function_decl),
+		    OPT_Wmissing_profile,
+		    "profile for function %qD not found in profile data",
+		    current_function_decl);
+      /* The function was not emitted, or is weak and not chosen in the
+	 final executable.  Silently fail, because there's nothing we
+	 can do about it.  */
+      return NULL;
+    }
   
   if (entry->cfg_checksum != cfg_checksum)
     {
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index abbd9ec..ed56af3 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -315,7 +315,7 @@ Objective-C and Objective-C++ Dialects}.
 -Wlogical-op  -Wlogical-not-parentheses  -Wlong-long @gol
 -Wmain  -Wmaybe-uninitialized  -Wmemset-elt-size  -Wmemset-transposed-args @gol
 -Wmisleading-indentation  -Wmissing-attributes -Wmissing-braces @gol
--Wmissing-field-initializers  -Wmissing-include-dirs @gol
+-Wmissing-field-initializers  -Wmissing-include-dirs  -Wmissing-profile @gol
 -Wno-multichar  -Wmultistatement-macros  -Wnonnull  -Wnonnull-compare @gol
 -Wnormalized=@r{[}none@r{|}id@r{|}nfc@r{|}nfkc@r{]} @gol
 -Wnull-dereference  -Wodr  -Wno-overflow  -Wopenmp-simd  @gol
@@ -4218,8 +4218,8 @@ Warn about an invalid memory access that is found by Pointer Bounds Checker
 @opindex Wcoverage-mismatch
 Warn if feedback profiles do not match when using the
 @option{-fprofile-use} option.
-If a source file is changed between compiling with @option{-fprofile-gen} and
-with @option{-fprofile-use}, the files with the profile feedback can fail
+If a source file is changed between compiling with @option{-fprofile-generate}
+and with @option{-fprofile-use}, the files with the profile feedback can fail
 to match the source file and GCC cannot use the profile feedback
 information.  By default, this warning is enabled and is treated as an
 error.  @option{-Wno-coverage-mismatch} can be used to disable the
@@ -4823,6 +4823,23 @@ This warning is enabled by @option{-Wall}.
 @opindex Wno-missing-include-dirs
 Warn if a user-supplied include directory does not exist.
 
+@item -Wmissing-profile
+@opindex Wmissing-profile
+@opindex Wno-missing-profile
+Warn if feedback profiles are missing when using the
+@option{-fprofile-use} option.
+This option diagnoses those cases where a new function or a new file is added
+to the user code between compiling with @option{-fprofile-generate} and with
+@option{-fprofile-use}, without regenerating the profiles.  In these cases, the
+profile feedback data files do not contain any profile feedback information for
+the newly added function or file respectively.  Also, in the case when profile
+count data (.gcda) files are wiped out, GCC cannot use any profile feedback
+information.  In all these cases, warnings are issued to inform the user that a
+profile generation step is due.  @option{-Wno-missing-profile} can be used to
+disable the warning.  Ignoring the warning can result in poorly optimized code.
+Completely disabling the warning is not recommended and should be done only
+when non-existent profile data is justified.
+
 @item -Wmultistatement-macros
 @opindex Wmultistatement-macros
 @opindex Wno-multistatement-macros
@@ -9920,8 +9937,9 @@ Before you can use this option, you must first generate profiling information.
 
 By default, GCC emits an error message if the feedback profiles do not
 match the source code.  This error can be turned into a warning by using
-@option{-Wcoverage-mismatch}.  Note this may result in poorly optimized
-code.
+@option{-Wno-error=coverage-mismatch}.  Note this may result in poorly
+optimized code.  Additionally, by default, GCC also emits a warning message if
+the feedback profiles do not exist (See @option{-Wmissing-profile}).
 
 If @var{path} is specified, GCC looks at the @var{path} to find
 the profile feedback data files. See @option{-fprofile-dir}.
diff --git a/gcc/testsuite/gcc.dg/Wmissing-profile.c b/gcc/testsuite/gcc.dg/Wmissing-profile.c
new file mode 100644
index 0000000..6ef1ac1
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wmissing-profile.c
@@ -0,0 +1,5 @@
+/* PR gcov-profile/86957 */
+/* { dg-do compile } */
+/* { dg-options "-fprofile-use" } */
+
+void foo () { } /* { dg-warning "profile count data file not found" } */

  parent reply	other threads:[~2018-09-21 23:20 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-05 19:29 Indu Bhagat
2018-09-11  9:21 ` Martin Liška
2018-09-16  8:28   ` Indu Bhagat
     [not found]   ` <159a29c5-8f8b-4194-dbea-1c9bd414db3a@oracle.com>
2018-09-17 10:10     ` Martin Liška
2018-09-17 11:20       ` Jan Hubicka
2018-09-18 19:41         ` Indu Bhagat
2018-09-21 23:23         ` Indu Bhagat [this message]
2018-09-24 16:46           ` Martin Sebor
2018-09-24 19:16             ` Indu Bhagat
2018-09-26  9:23               ` Martin Liška
2018-09-27 10:02               ` Richard Biener
2018-09-27 10:15                 ` Martin Liška
2018-09-27 13:13                   ` Martin Liška
2018-09-27 14:58                     ` Richard Biener
2018-12-05 11:33                 ` Thomas Schwinge
2018-12-07  1:46                   ` Indu Bhagat
2018-12-10 20:45                     ` Indu Bhagat
2018-12-11  9:14                       ` Thomas Schwinge
2018-12-04 15:33               ` [committed, testsuite] Fix PR88310 Iain Sandoe
2018-09-11  9:23 ` [PATCH] PR86957 Martin Liška

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e29237f1-eff5-42a7-3b35-ed892868a789@oracle.com \
    --to=indu.bhagat@oracle.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=mliska@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).