From 28cd6814b5bf87cb65505df85c326f7a1975a60d Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Thu, 9 Jun 2016 13:26:32 +0200 Subject: [PATCH] Introduce filtering for edge_predictions. * predict.c (filter_predictions): New function. (remove_predictions_associated_with_edge): Use the filter function. (equal_edge_p): New function. From-SVN: r237253 --- gcc/ChangeLog | 7 +++++++ gcc/predict.c | 57 +++++++++++++++++++++++++++++++++++---------------- 2 files changed, 46 insertions(+), 18 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index ee271d44ab8..3484047c15c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2016-06-09 Martin Liska + + * predict.c (filter_predictions): New function. + (remove_predictions_associated_with_edge): Use the filter + function. + (equal_edge_p): New function. + 2016-06-09 Stefan Bruens * doc/invoke.texi (ARM Options): Use lexicographical ordering. diff --git a/gcc/predict.c b/gcc/predict.c index 837c2f3274f..f00428fb8ae 100644 --- a/gcc/predict.c +++ b/gcc/predict.c @@ -609,6 +609,44 @@ gimple_predict_edge (edge e, enum br_predictor predictor, int probability) } } +/* Filter edge predictions PREDS by a function FILTER. DATA are passed + to the filter function. */ + +void +filter_predictions (edge_prediction **preds, + bool (*filter) (edge_prediction *, void *), void *data) +{ + if (!bb_predictions) + return; + + if (preds) + { + struct edge_prediction **prediction = preds; + struct edge_prediction *next; + + while (*prediction) + { + if ((*filter) (*prediction, data)) + prediction = &((*prediction)->ep_next); + else + { + next = (*prediction)->ep_next; + free (*prediction); + *prediction = next; + } + } + } +} + +/* Filter function predicate that returns true for a edge predicate P + if its edge is equal to DATA. */ + +bool +equal_edge_p (edge_prediction *p, void *data) +{ + return p->ep_edge == (edge)data; +} + /* Remove all predictions on given basic block that are attached to edge E. */ void @@ -618,24 +656,7 @@ remove_predictions_associated_with_edge (edge e) return; edge_prediction **preds = bb_predictions->get (e->src); - - if (preds) - { - struct edge_prediction **prediction = preds; - struct edge_prediction *next; - - while (*prediction) - { - if ((*prediction)->ep_edge == e) - { - next = (*prediction)->ep_next; - free (*prediction); - *prediction = next; - } - else - prediction = &((*prediction)->ep_next); - } - } + filter_predictions (preds, equal_edge_p, e); } /* Clears the list of predictions stored for BB. */