diff options
author | Jan Hubicka <hubicka@ucw.cz> | 2017-10-07 18:48:34 +0200 |
---|---|---|
committer | Jan Hubicka <hubicka@gcc.gnu.org> | 2017-10-07 16:48:34 +0000 |
commit | 12b9f3ac928e1ed7e3aa92cab42beb6317b27981 (patch) | |
tree | 52d0be8478f0b04ec8cab8d8483d08112708c62e | |
parent | 59e2f25ee754cc258b55fac759afd6d47d8879d8 (diff) | |
download | gcc-12b9f3ac928e1ed7e3aa92cab42beb6317b27981.zip gcc-12b9f3ac928e1ed7e3aa92cab42beb6317b27981.tar.gz gcc-12b9f3ac928e1ed7e3aa92cab42beb6317b27981.tar.bz2 |
invoke.texi (Wsuggest-attribute=cold): Document.
* 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.
From-SVN: r253513
-rw-r--r-- | gcc/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/common.opt | 4 | ||||
-rw-r--r-- | gcc/doc/invoke.texi | 11 | ||||
-rw-r--r-- | gcc/ipa-pure-const.c | 19 | ||||
-rw-r--r-- | gcc/predict.c | 10 | ||||
-rw-r--r-- | gcc/predict.h | 3 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/cold-1.c | 21 |
8 files changed, 76 insertions, 4 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e8e18d8..5eea631 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2017-10-07 Jan Hubicka <hubicka@ucw.cz> + + * 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. + 2017-10-06 Jan Hubicka <hubicka@ucw.cz> * tree-switch-conversion.c (do_jump_if_equal, emit_cmp_and_jump_insns): diff --git a/gcc/common.opt b/gcc/common.opt index dfde6ad..ce8194b 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -721,6 +721,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)). diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 84cc43a..9ad1fb3 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -5201,7 +5201,7 @@ whether to issue a warning. Similarly to @option{-Wstringop-overflow=3} this 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 @@ -5253,6 +5253,15 @@ might be appropriate for any function that calls a function like @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 diff --git a/gcc/ipa-pure-const.c b/gcc/ipa-pure-const.c index dac8f0d..9154235 100644 --- a/gcc/ipa-pure-const.c +++ b/gcc/ipa-pure-const.c @@ -156,7 +156,8 @@ private: static bool function_always_visible_to_compiler_p (tree decl) { - return (!TREE_PUBLIC (decl) || DECL_DECLARED_INLINE_P (decl)); + return (!TREE_PUBLIC (decl) || DECL_DECLARED_INLINE_P (decl) + || DECL_COMDAT (decl)); } /* Emit suggestion about attribute ATTRIB_NAME for DECL. KNOWN_FINITE @@ -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<tree> *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 @@ -1788,6 +1804,7 @@ pass_local_pure_const::execute (function *fun) node = cgraph_node::get (current_function_decl); skip = skip_function_for_local_pure_const (node); + if (!warn_suggest_attribute_const && !warn_suggest_attribute_pure && skip) diff --git a/gcc/predict.c b/gcc/predict.c index 80c2c19..e534502 100644 --- a/gcc/predict.c +++ b/gcc/predict.c @@ -3613,7 +3613,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; @@ -3632,7 +3635,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)) diff --git a/gcc/predict.h b/gcc/predict.h index 9b8b140..1b73ae2 100644 --- a/gcc/predict.h +++ b/gcc/predict.h @@ -102,4 +102,7 @@ extern void propagate_unlikely_bbs_forward (void); 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 */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index aaf2e60..f764028 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2017-10-07 Jan Hubicka <hubicka@ucw.cz> + + * gcc.dg/cold-1.c: New testcase. + 2017-10-07 Paolo Carlini <paolo.carlini@oracle.com> PR c++/80805 diff --git a/gcc/testsuite/gcc.dg/cold-1.c b/gcc/testsuite/gcc.dg/cold-1.c new file mode 100644 index 0000000..8ea88dd --- /dev/null +++ b/gcc/testsuite/gcc.dg/cold-1.c @@ -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 (); +} |