diff options
author | Jason Merrill <jason@redhat.com> | 2018-11-16 16:49:42 -0500 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2018-11-16 16:49:42 -0500 |
commit | 2674fa47de9ecfee5b04f753582fb23041029f40 (patch) | |
tree | 1c43236aab7e94c52420d2456ea29ce3079f0857 /gcc/gimplify.c | |
parent | a0a57b074f79dbe5e01745da9cfbd08a52fa8cfd (diff) | |
download | gcc-2674fa47de9ecfee5b04f753582fb23041029f40.zip gcc-2674fa47de9ecfee5b04f753582fb23041029f40.tar.gz gcc-2674fa47de9ecfee5b04f753582fb23041029f40.tar.bz2 |
Implement P0479R5, [[likely]] and [[unlikely]].
[[likely]] and [[unlikely]] are equivalent to the GNU hot/cold attributes,
except that they can be applied to arbitrary statements as well as labels;
this is most likely to be useful for marking if/else branches as likely or
unlikely. Conveniently, PREDICT_EXPR fits the bill nicely as a
representation.
I also had to fix marking case labels as hot/cold, which didn't work before.
Which then required me to force __attribute ((fallthrough)) to apply to the
statement rather than the label.
gcc/
* gimplify.c (gimplify_case_label_expr): Handle hot/cold attributes.
gcc/c-family/
* c-lex.c (c_common_has_attribute): Handle likely/unlikely.
* c-attribs.c (attr_cold_hot_exclusions): Make public.
gcc/cp/
* tree.c (handle_likeliness_attribute): New.
(std_attribute_table): Add likely/unlikely.
* cp-gimplify.c (lookup_hotness_attribute, remove_hotness_attribute)
(process_stmt_hotness_attribute, first_stmt): New.
(genericize_if_stmt): Check for duplicate predictions.
* parser.c (cp_parser_statement): Call
process_stmt_hotness_attribute.
(cp_parser_label_for_labeled_statement): Apply attributes to case.
* decl.c (finish_case_label): Give label in template type void.
* pt.c (tsubst_expr) [CASE_LABEL_EXPR]: Copy attributes.
[PREDICT_EXPR]: Handle.
From-SVN: r266223
Diffstat (limited to 'gcc/gimplify.c')
-rw-r--r-- | gcc/gimplify.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/gcc/gimplify.c b/gcc/gimplify.c index 87082ad..40fbaa2 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -2511,11 +2511,19 @@ gimplify_case_label_expr (tree *expr_p, gimple_seq *pre_p) if (ctxp->case_labels.exists ()) break; - label_stmt = gimple_build_label (CASE_LABEL (*expr_p)); + tree label = CASE_LABEL (*expr_p); + label_stmt = gimple_build_label (label); gimple_set_location (label_stmt, EXPR_LOCATION (*expr_p)); ctxp->case_labels.safe_push (*expr_p); gimplify_seq_add_stmt (pre_p, label_stmt); + if (lookup_attribute ("cold", DECL_ATTRIBUTES (label))) + gimple_seq_add_stmt (pre_p, gimple_build_predict (PRED_COLD_LABEL, + NOT_TAKEN)); + else if (lookup_attribute ("hot", DECL_ATTRIBUTES (label))) + gimple_seq_add_stmt (pre_p, gimple_build_predict (PRED_HOT_LABEL, + TAKEN)); + return GS_ALL_DONE; } |