aboutsummaryrefslogtreecommitdiff
path: root/gcc/predict.c
diff options
context:
space:
mode:
authorRichard Henderson <rth@redhat.com>2012-07-26 21:31:40 +0000
committerRichard Henderson <rth@redhat.com>2012-07-26 21:31:40 +0000
commit18caa61031cfa2386f3dab277d8152d70ab2d8f6 (patch)
tree20c51469f397cdea4c543dc55b62a9a1b3ce14d1 /gcc/predict.c
parent3f1e89dfad969d073fb8c4ed04ec75acfa74e89f (diff)
Hot/cold attributes for labels.
gcc/ * doc/extend.texi (attribute): Document hot/cold for labels. * predict.c (tree_estimate_probability_bb): Handle hot/cold attributes on user labels. * predict.def (PRED_HOT_LABEL, PRED_COLD_LABEL): New. gcc/c-family/ * c-common.c (handle_hot_attribute): Allow labels. (handle_cold_attribute): Likewise. gcc/testsuite/ * gcc.dg/attr-hotcold-1.c: New. * gcc.dg/tree-ssa/attr-hotcold-2.c: New. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@189898 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/predict.c')
-rw-r--r--gcc/predict.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/gcc/predict.c b/gcc/predict.c
index b690bdc2519..b8acdbaeb6e 100644
--- a/gcc/predict.c
+++ b/gcc/predict.c
@@ -2059,6 +2059,29 @@ tree_estimate_probability_bb (basic_block bb)
FOR_EACH_EDGE (e, ei, bb->succs)
{
+ /* Predict edges to user labels with attributes. */
+ if (e->dest != EXIT_BLOCK_PTR)
+ {
+ gimple_stmt_iterator gi;
+ for (gi = gsi_start_bb (e->dest); !gsi_end_p (gi); gsi_next (&gi))
+ {
+ gimple stmt = gsi_stmt (gi);
+ tree decl;
+
+ if (gimple_code (stmt) != GIMPLE_LABEL)
+ break;
+ decl = gimple_label_label (stmt);
+ if (DECL_ARTIFICIAL (decl))
+ continue;
+
+ /* Finally, we have a user-defined label. */
+ if (lookup_attribute ("cold", DECL_ATTRIBUTES (decl)))
+ predict_edge_def (e, PRED_COLD_LABEL, NOT_TAKEN);
+ else if (lookup_attribute ("hot", DECL_ATTRIBUTES (decl)))
+ predict_edge_def (e, PRED_HOT_LABEL, TAKEN);
+ }
+ }
+
/* Predict early returns to be probable, as we've already taken
care for error returns and other cases are often used for
fast paths through function.