From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29554 invoked by alias); 24 Jul 2017 19:02:32 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 28457 invoked by uid 89); 24 Jul 2017 19:02:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-14.4 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_ASCII_DIVIDERS,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-wm0-f49.google.com Received: from mail-wm0-f49.google.com (HELO mail-wm0-f49.google.com) (74.125.82.49) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 24 Jul 2017 19:02:29 +0000 Received: by mail-wm0-f49.google.com with SMTP id m85so25142537wma.1 for ; Mon, 24 Jul 2017 12:02:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=HQQZDhKXh2DKa5iZg57fk//HAhCQm5Dm+kVXsFtAaBE=; b=ONxrllXlsnAlwX0GyR7zoRGWGQqTJFBCRWns4YLfu725dFLb8FDJZS29ew7K0hGJpd AbOzE+3qlWEDJTt0MPgxYtXSWbPdKGT5/oFWF11RNAeHvq1PsOBcZafqIwqw46wyAmiY br7w8xM6ZnGjiXC9hLpZCnv7d7xPT6jEma1TZ3A6tnK9mF/a4wPpPF0F7zH/NoPN8/Lt 6hJDgzsrsJ+LDh9hIbBeb3ZNz8tZatZefbE3/ToP+4s2rbjInfCG/cLgNIG+E0UxomZO wnlp1YTX1KxcEo/M7xl0nNBXiXLORROD9EBAMJwEZM+oDuAvd4mwkI/32zibBp6NR4ox MQYQ== X-Gm-Message-State: AIVw113yB8llRbigJxWbM7rPFJwcipdAYnDYPkM8TMeV1piEx7N6j6f+ 6bSJn6rqrLAqzkD+LHS6rPyO58VwHP4G X-Received: by 10.80.195.93 with SMTP id q29mr5096178edb.144.1500922947661; Mon, 24 Jul 2017 12:02:27 -0700 (PDT) MIME-Version: 1.0 Received: by 10.80.216.67 with HTTP; Mon, 24 Jul 2017 12:02:07 -0700 (PDT) In-Reply-To: <20170724185633.GA43541@kam.mff.cuni.cz> References: <20170724185633.GA43541@kam.mff.cuni.cz> From: Eric Gallager Date: Mon, 24 Jul 2017 19:02:00 -0000 Message-ID: Subject: Re: Add -Wsuggest-attribute=cold To: Jan Hubicka Cc: gcc-patches Content-Type: text/plain; charset="UTF-8" X-IsSubscribed: yes X-SW-Source: 2017-07/txt/msg01446.txt.bz2 On Mon, Jul 24, 2017 at 2:56 PM, Jan Hubicka wrote: > Hi, > this patch adds -Wsuggest-attribute=cold because we can now statically detect > cold functions atuomatically. > > Bootstrapped/regtested x86_64-linux. Plan to commit it tomorrow if there are no > complains. > > Honza > > * invoke.texi (Wsuggest-attribute=cold): Document. > * common.opt (Wsuggest-attribute=cold): New > * ipa-pure-const.c (warn_function_cold): New function. > * predict.c (compute_function_frequency): Use it. > * predict.h (warn_function_cold): Declare. > > * gcc.dg/cold-1.c: New testcase. Would it be possible to also do -Wsuggest-attribute=hot for symmetry's sake? Just wondering. > Index: common.opt > =================================================================== > --- common.opt (revision 250470) > +++ common.opt (working copy) > @@ -708,6 +708,10 @@ Wstrict-overflow= > Common Joined RejectNegative UInteger Var(warn_strict_overflow) Warning > Warn about optimizations that assume that signed overflow is undefined. > > +Wsuggest-attribute=cold > +Common Var(warn_suggest_attribute_cold) Warning > +Warn about functions which might be candidates for __attribute__((cold)). > + > Wsuggest-attribute=const > Common Var(warn_suggest_attribute_const) Warning > Warn about functions which might be candidates for __attribute__((const)). > Index: doc/invoke.texi > =================================================================== > --- doc/invoke.texi (revision 250470) > +++ doc/invoke.texi (working copy) > @@ -5172,7 +5172,7 @@ whether to issue a warning. Similarly t > setting of the option may result in warnings for benign code. > @end table > > -@item -Wsuggest-attribute=@r{[}pure@r{|}const@r{|}noreturn@r{|}format@r{]} > +@item -Wsuggest-attribute=@r{[}pure@r{|}const@r{|}noreturn@r{|}format@r{|}cold@r{]} > @opindex Wsuggest-attribute= > @opindex Wno-suggest-attribute= > Warn for cases where adding an attribute may be beneficial. The > @@ -5224,6 +5224,15 @@ might be appropriate for any function th > @code{vprintf} or @code{vscanf}, but this might not always be the > case, and some functions for which @code{format} attributes are > appropriate may not be detected. > + > +@item -Wsuggest-attribute=cold > +@opindex Wsuggest-attribute=cold > +@opindex Wno-suggest-attribute=cold > + > +Warn about functions that might be candidates for @code{cold} attribute. This > +is based on static detection and generally will only warn about functions which > +always leads to a call to another @code{cold} function such as wrappers of > +C++ @code{throw} or fatal error reporting functions leading to @code{abort}. > @end table > > @item -Wsuggest-final-types > Index: ipa-pure-const.c > =================================================================== > --- ipa-pure-const.c (revision 250470) > +++ ipa-pure-const.c (working copy) > @@ -232,6 +233,21 @@ warn_function_noreturn (tree decl) > true, warned_about, "noreturn"); > } > > +void > +warn_function_cold (tree decl) > +{ > + tree original_decl = decl; > + > + cgraph_node *node = cgraph_node::get (decl); > + if (node->instrumentation_clone) > + decl = node->instrumented_version->decl; > + > + static hash_set *warned_about; > + warned_about > + = suggest_attribute (OPT_Wsuggest_attribute_cold, original_decl, > + true, warned_about, "cold"); > +} > + > /* Return true if we have a function state for NODE. */ > > static inline bool > Index: predict.c > =================================================================== > --- predict.c (revision 250470) > +++ predict.c (working copy) > @@ -3611,7 +3611,10 @@ compute_function_frequency (void) > if (ENTRY_BLOCK_PTR_FOR_FN (cfun)->count == profile_count::zero () > || lookup_attribute ("cold", DECL_ATTRIBUTES (current_function_decl)) > != NULL) > - node->frequency = NODE_FREQUENCY_UNLIKELY_EXECUTED; > + { > + node->frequency = NODE_FREQUENCY_UNLIKELY_EXECUTED; > + warn_function_cold (current_function_decl); > + } > else if (lookup_attribute ("hot", DECL_ATTRIBUTES (current_function_decl)) > != NULL) > node->frequency = NODE_FREQUENCY_HOT; > @@ -3630,7 +3633,10 @@ compute_function_frequency (void) > Ipa-profile pass will drop functions only called from unlikely > functions to unlikely and that is most of what we care about. */ > if (!cfun->after_inlining) > - node->frequency = NODE_FREQUENCY_UNLIKELY_EXECUTED; > + { > + node->frequency = NODE_FREQUENCY_UNLIKELY_EXECUTED; > + warn_function_cold (current_function_decl); > + } > FOR_EACH_BB_FN (bb, cfun) > { > if (maybe_hot_bb_p (cfun, bb)) > Index: predict.h > =================================================================== > --- predict.h (revision 250470) > +++ predict.h (working copy) > @@ -102,4 +102,7 @@ extern void propagate_unlikely_bbs_forwa > > extern void add_reg_br_prob_note (rtx_insn *, profile_probability); > > +/* In ipa-pure-const.c */ > +extern void warn_function_cold (tree); > + > #endif /* GCC_PREDICT_H */ > Index: testsuite/gcc.dg/cold-1.c > =================================================================== > --- testsuite/gcc.dg/cold-1.c (revision 0) > +++ testsuite/gcc.dg/cold-1.c (working copy) > @@ -0,0 +1,21 @@ > +/* { dg-do compile { target nonpic } } */ > +/* { dg-options "-O2 -Wsuggest-attribute=cold" } */ > + > +extern void do_something_interesting_and_never_return (); > + > +int > +foo1(int a) > +{ /* { dg-warning "cold" "detect cold candidate" { target *-*-* } "8" } */ > + if (a) > + abort (); > + else > + abort (); > +} > + > +int > +foo2(int a) > +{ > + if (a) > + do_something_interesting_and_never_return (); > + abort (); > +}