From patchwork Wed Sep 5 19:28:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Indu Bhagat X-Patchwork-Id: 966637 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-485264-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="A0DJQmy/"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.b="oZ7wNyq/"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 425DKY0Y0cz9sB5 for ; Thu, 6 Sep 2018 05:29:18 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=m37EfcCKCJZm423A4OnEUMs0a8thdrk2PYmT5lu4P0campFFQz PfMrFF8euSCZMzWCB+FjAJIevKgH+LaXHBtzPLFih+SbGLfU320qS8OgT6ms6Mur 3zFJ9cR6o6SqcwpJ0l5Ui+0F/TWvWLbFCkm1Bkko2EVzwgwafpgXUvmOk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=Nm9yRO+UH9iMXDCKsvGbaEydED8=; b=A0DJQmy/0/XbwqBSBpYR G8Vu7/grbxme/l0rdZzSBpR6bfUYmKQcoxFJseS8O7qMxT1XviM007wEg8ZLXygb CDwjlldGhtsHRwgdZ/nnRDaAgEL4ErtLk90fpWR3+OpBB33o873MAZga1L0+44Tq 6gktKnJ4m5na0HbOiDPsMUo= Received: (qmail 44163 invoked by alias); 5 Sep 2018 19:29:10 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 44137 invoked by uid 89); 5 Sep 2018 19:29:10 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_NUMSUBJECT, KAM_SHORT, SPF_HELO_PASS, SUBJ_ALL_CAPS autolearn=ham version=3.3.2 spammy= X-HELO: userp2130.oracle.com Received: from userp2130.oracle.com (HELO userp2130.oracle.com) (156.151.31.86) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 05 Sep 2018 19:29:07 +0000 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w85JT6kW105312 for ; Wed, 5 Sep 2018 19:29:06 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=to : from : subject : message-id : date : mime-version : content-type; s=corp-2018-07-02; bh=3jX8UePfbuVtTOXkMKZaEPecMZ/w7272WClD+Blprnw=; b=oZ7wNyq/sAjqUMrTG0oaB12LAhHqsKjjPUdsgbhUaQaXyMw5Iq4MqXFyl94gRG5DZTQ0 StEYecCtmEdsPPTBlzxk1TFOVqPawpUok2jf9yZh6vre4xr/SvRmczbsGgcWay8EAzMP 7zp/ANkCNNTCeVMrijuVBr9ETj5HW2/cBc3WwQEwaXZkQ3mob0aXcr/VdLmTNzx1MVWZ ai0ULKPj6De47jCc7KR7d28+6mFhCjmeVgKKKFs/EgYV+6FTFttqF+wmWoATWQt9YzOU CRti1l5U6e/n8Ulx6/vWq46maJRUOWk/VbtpOdIs7yng+Wvkc57cd1G7ZR5OaL9xjZ4X Vw== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2130.oracle.com with ESMTP id 2m7j6tp2xf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 05 Sep 2018 19:29:05 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w85JT2cm005434 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 5 Sep 2018 19:29:02 GMT Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w85JT1Ks016637 for ; Wed, 5 Sep 2018 19:29:01 GMT Received: from [10.159.225.123] (/10.159.225.123) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 05 Sep 2018 19:29:00 +0000 To: gcc-patches@gcc.gnu.org From: Indu Bhagat Subject: [PATCH] PR86957 Message-ID: Date: Wed, 5 Sep 2018 12:28:59 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 Patch for PR 86957 " gcc should warn about missing profiles for a compilation unit or a new function with -fprofile-use". https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86957 The patch adds -Wmissing-profile warning flag to alert user about cases when there is no profile data for a compilation unit or a function when using -fprofile-use. The flag is on by default when -fprofile-use is specified and generates errors by default (like -Wcoverage-mismatch). The attachment pr86957-missing-profile-diagnostic shows the behavior of GCC with the patch. Thanks Indu ------------------------------------------------------ gcc/ChangeLog: 2018-09-05 "Indu Bhagat" <"indu.bhagat@oracle.com"> * common.opt: New warning option -Wmissing-profile. * coverage.c (get_coverage_counts): Add warning for missing .gcda file. * doc/invoke.texi: Document -Wmissing-profile. * profile.c (get_exec_counts): Add warning for missing feedback profile for a function. * toplev.c (process_options): -Wmissing-profile warning as error. [Testcase 1] Missing profile data file with -fprofile-use. The sort.c file contains two functions main() and stop() gcc -c sort.c -fprofile-use -O1 -fprofile-dir=/data2/user/gcc-temp/fdo/profdata/ sort.c: In function ‘main’: sort.c:29:1: error: ‘/data2/user/gcc-temp/fdo/profdata//#data2#user#gcc-temp#fdo#sort.gcda’ profile count data file not found, regenerating profiles may help [-Werror=missing-profile] 29 | } | ^ sort.c:29:1: error: profile for function ‘main’ not found in profile data, regenerating profiles may help [-Werror=missing-profile] sort.c: In function ‘stop’: sort.c:29:1: error: profile for function ‘stop’ not found in profile data, regenerating profiles may help [-Werror=missing-profile] cc1: some warnings being treated as errors make: *** [sort.o] Error 1 [Testcase 2] bubble_sort.c has a non-empty function bubble_sort() for which profile data exists. Now at profile-use phase, a user adds empty function before1() before an existing lone function bubble_sort() and empty function after1() after the lone existing function bubble_sort() gcc -c bubble_sort.c -fprofile-use -O1 -fprofile-dir=/data2/user/gcc-temp/fdo/profdata/ bubble_sort.c: In function ‘after1’: bubble_sort.c:19:1: error: profile for function ‘after1’ not found in profile data, regenerating profiles may help [-Werror=missing-profile] 19 | void after1() { } | ^~~~ bubble_sort.c: In function ‘bubble_sort’: bubble_sort.c:19:1: error: source locations for function ‘bubble_sort’ have changed, the profile data may be out of date [-Werror=coverage-mismatch] bubble_sort.c: In function ‘before1’: bubble_sort.c:19:1: error: profile for function ‘before1’ not found in profile data, regenerating profiles may help [-Werror=missing-profile] cc1: some warnings being treated as errors make: *** [bubble_sort.o] Error 1 [Testcase 3] Use -Wno-error=missing-profile to treat them as warnings, not errors gcc -c bubble_sort.c -fprofile-use -O1 -Wno-error=missing-profile -fprofile-dir=/data2/user/gcc-temp/fdo/profdata/ bubble_sort.c: In function ‘after1’: bubble_sort.c:19:1: warning: profile for function ‘after1’ not found in profile data, regenerating profiles may help [-Wmissing-profile] 19 | void after1() { } | ^~~~ bubble_sort.c: In function ‘bubble_sort’: bubble_sort.c:19:1: error: source locations for function ‘bubble_sort’ have changed, the profile data may be out of date [-Werror=coverage-mismatch] bubble_sort.c: In function ‘before1’: bubble_sort.c:19:1: warning: profile for function ‘before1’ not found in profile data, regenerating profiles may help [-Wmissing-profile] cc1: some warnings being treated as errors make: *** [bubble_sort.o] Error 1 diff --git a/gcc/common.opt b/gcc/common.opt index ebc3ef4..d93ddca 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 bae6f5c..df031df 100644 --- a/gcc/coverage.c +++ b/gcc/coverage.c @@ -341,16 +341,24 @@ get_coverage_counts (unsigned counter, unsigned expected, { 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," + " regenerating profiles may help", + 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; } diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index ca92028..e62bcae 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -314,7 +314,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 @@ -4816,6 +4816,25 @@ 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. +If a new function or a new file is added to the user code between compiling +with @option{-fprofile-gen} and with @option{-fprofile-use} without +regenerating the profiles, 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. By default, this warning is enabled and is +treated as an error. @option{-Wno-missing-profile} can be used to disable the +warning or @option{-Wno-error=missing-profile} can be used to disable the +error. Disabling the error for this warning can result in poorly optimized +code and is useful only in the cases when non-existent profile data is +justified. Completely disabling the warning is not recommended. + @item -Wmultistatement-macros @opindex Wmultistatement-macros @opindex Wno-multistatement-macros @@ -9899,8 +9918,10 @@ 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 an error message if +the feedback profiles do not exist. The latter error can be turned into a +warning by using @option{-Wno-error=missing-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/profile.c b/gcc/profile.c index cb51e0d..40f9763 100644 --- a/gcc/profile.c +++ b/gcc/profile.c @@ -286,7 +286,13 @@ get_exec_counts (unsigned cfg_checksum, unsigned lineno_checksum) counts = get_coverage_counts (GCOV_COUNTER_ARCS, num_edges, cfg_checksum, lineno_checksum, &profile_info); if (!counts) - return NULL; + { + warning (OPT_Wmissing_profile, + "profile for function %qE not found in profile data," + " regenerating profiles may help", + DECL_ASSEMBLER_NAME (current_function_decl)); + return NULL; + } get_working_sets (); diff --git a/gcc/toplev.c b/gcc/toplev.c index 9fb83d4..5891554 100644 --- a/gcc/toplev.c +++ b/gcc/toplev.c @@ -1782,14 +1782,24 @@ process_options (void) || !targetm.have_prologue () || !targetm.have_epilogue ()) flag_ipa_ra = 0; - /* Enable -Werror=coverage-mismatch when -Werror and -Wno-error - have not been set. */ - if (!global_options_set.x_warnings_are_errors - && warn_coverage_mismatch - && (global_dc->classify_diagnostic[OPT_Wcoverage_mismatch] == - DK_UNSPECIFIED)) - diagnostic_classify_diagnostic (global_dc, OPT_Wcoverage_mismatch, - DK_ERROR, UNKNOWN_LOCATION); + if (!global_options_set.x_warnings_are_errors) + { + /* Enable -Werror=coverage-mismatch when -Werror and -Wno-error + have not been set. */ + if (warn_coverage_mismatch + && (global_dc->classify_diagnostic[OPT_Wcoverage_mismatch] == + DK_UNSPECIFIED)) + diagnostic_classify_diagnostic (global_dc, OPT_Wcoverage_mismatch, + DK_ERROR, UNKNOWN_LOCATION); + + /* Enable -Werror=missing-profile when -Werror and -Wno-error + have not been set. */ + if (warn_missing_profile + && (global_dc->classify_diagnostic[OPT_Wmissing_profile] == + DK_UNSPECIFIED)) + diagnostic_classify_diagnostic (global_dc, OPT_Wmissing_profile, + DK_ERROR, UNKNOWN_LOCATION); + } /* Save the current optimization options. */ optimization_default_node = build_optimization_node (&global_options);