Introduce filtering for edge_predictions.
authorMartin Liska <mliska@suse.cz>
Thu, 9 Jun 2016 11:26:32 +0000 (13:26 +0200)
committerMartin Liska <marxin@gcc.gnu.org>
Thu, 9 Jun 2016 11:26:32 +0000 (11:26 +0000)
* 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
gcc/predict.c

index ee271d44ab869b72be599aee3f7b837e94eb0e66..3484047c15c496d636666c6c6f8849842cbfc11d 100644 (file)
@@ -1,3 +1,10 @@
+2016-06-09  Martin Liska  <mliska@suse.cz>
+
+       * 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  <stefan.bruens@rwth-aachen.de>
 
        * doc/invoke.texi (ARM Options): Use lexicographical ordering.
index 837c2f3274ffa6baf2caa7679c53942dfc4a3bd2..f00428fb8ae8fd33a808556129eb78dad2f67486 100644 (file)
@@ -609,16 +609,16 @@ gimple_predict_edge (edge e, enum br_predictor predictor, int probability)
     }
 }
 
-/* Remove all predictions on given basic block that are attached
-   to edge E.  */
+/* Filter edge predictions PREDS by a function FILTER.  DATA are passed
+   to the filter function.  */
+
 void
-remove_predictions_associated_with_edge (edge e)
+filter_predictions (edge_prediction **preds,
+                   bool (*filter) (edge_prediction *, void *), void *data)
 {
   if (!bb_predictions)
     return;
 
-  edge_prediction **preds = bb_predictions->get (e->src);
-
   if (preds)
     {
       struct edge_prediction **prediction = preds;
@@ -626,18 +626,39 @@ remove_predictions_associated_with_edge (edge e)
 
       while (*prediction)
        {
-         if ((*prediction)->ep_edge == e)
+         if ((*filter) (*prediction, data))
+           prediction = &((*prediction)->ep_next);
+         else
            {
              next = (*prediction)->ep_next;
              free (*prediction);
              *prediction = next;
            }
-         else
-           prediction = &((*prediction)->ep_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
+remove_predictions_associated_with_edge (edge e)
+{
+  if (!bb_predictions)
+    return;
+
+  edge_prediction **preds = bb_predictions->get (e->src);
+  filter_predictions (preds, equal_edge_p, e);
+}
+
 /* Clears the list of predictions stored for BB.  */
 
 static void