]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
cfghooks: Pass data to callback function of make_forwarder_block
authorAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Wed, 15 Apr 2026 20:39:51 +0000 (13:39 -0700)
committerAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Wed, 22 Apr 2026 17:09:50 +0000 (10:09 -0700)
This makes a cleanup that is way overdue and should have been done
years ago. Instead of setting some global/static variables for the
callback function to check here, we pass down the data to the callback
function.  This reduces the number of global variables (which should help
with Parallel GCC project). Plus since mfb_keep_just was exported outside
of cfgloopmanip.cc (it was used in tree-ssa-threadupdate.cc), it reduces
is shared between files.

I found this useful when working on PR 123113 as I needed a new callback
function.

Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

* cfghooks.cc (make_forwarder_block): New data argument,
pass it down to redirect_edge_p.
* cfghooks.h (make_forwarder_block): Add void* argument.
* cfgloop.cc (mfb_reis_set): Remove.
(mfb_redirect_edges_in_set): Add new data argument.
Use it instead of mfb_reis_set.
(form_subloop): Create a local variable instead of
mfb_areis_set. Update call to make_forwarder_block.
(merge_latch_edges): Likewise.
* cfgloopmanip.cc (mfb_kj_edge): Remove.
(mfb_keep_just):  Add new data argument.
Use it instead of mfb_kj_edge.
(create_preheader): Use local variable instead of
mfb_kj_edge. Update call to make_forwarder_block.
* cfgloopmanip.h (mfb_keep_just): Add void* argument.
* tree-cfgcleanup.cc (mfb_keep_latches): Add unused void* arugment.
(cleanup_tree_cfg_noloop): Update call to make_forwarder_block.
* tree-ssa-threadupdate.cc
(fwd_jt_path_registry::thread_through_loop_header): Use local
variable instead of mfb_kj_edge. Update call to make_forwarder_block.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
gcc/cfghooks.cc
gcc/cfghooks.h
gcc/cfgloop.cc
gcc/cfgloopmanip.cc
gcc/cfgloopmanip.h
gcc/tree-cfgcleanup.cc
gcc/tree-ssa-threadupdate.cc

index 063639fe1c9a519cf47894b37c9a7b84c16b3614..6415d0fdec25aa4a3d321bc1708a94775a541cdf 100644 (file)
@@ -923,10 +923,11 @@ merge_blocks (basic_block a, basic_block b)
 
 /* Split BB into entry part and the rest (the rest is the newly created block).
    Redirect those edges for that REDIRECT_EDGE_P returns true to the entry
-   part.  Returns the edge connecting the entry part to the rest.  */
+   part.  Returns the edge connecting the entry part to the rest.
+   DATA gets passed on to REDIRECT_EDGE_P.  */
 
 edge
-make_forwarder_block (basic_block bb, bool (*redirect_edge_p) (edge))
+make_forwarder_block (basic_block bb, bool (*redirect_edge_p) (edge, void*), void *data)
 {
   edge e, fallthru;
   edge_iterator ei;
@@ -947,7 +948,7 @@ make_forwarder_block (basic_block bb, bool (*redirect_edge_p) (edge))
     {
       basic_block e_src;
 
-      if (redirect_edge_p (e))
+      if (redirect_edge_p (e, data))
        {
          dummy->count += e->count ();
          ei_next (&ei);
index 6cc1b66baef5b37cb8ccf957ff361f84d06276a7..bc7956be2a8a3832ebcb43ba7bdba24b712e5205 100644 (file)
@@ -245,7 +245,7 @@ extern basic_block create_basic_block (gimple_seq, basic_block);
 extern basic_block create_empty_bb (basic_block);
 extern bool can_merge_blocks_p (basic_block, basic_block);
 extern void merge_blocks (basic_block, basic_block);
-extern edge make_forwarder_block (basic_block, bool (*)(edge));
+extern edge make_forwarder_block (basic_block, bool (*)(edge, void*), void*);
 extern basic_block force_nonfallthru (edge);
 extern void tidy_fallthru_edge (edge);
 extern void tidy_fallthru_edges (void);
index fc4d635d8b659d8e73221a7689c019b18a9fa97b..70f2996a4165c1d86c542381135cec081f932b55 100644 (file)
@@ -709,13 +709,13 @@ find_subloop_latch_edge (class loop *loop)
 }
 
 /* Callback for make_forwarder_block.  Returns true if the edge E is marked
-   in the set MFB_REIS_SET.  */
+   in the set SET(DATA).  */
 
-static hash_set<edge> *mfb_reis_set;
 static bool
-mfb_redirect_edges_in_set (edge e)
+mfb_redirect_edges_in_set (edge e, void *data)
 {
-  return mfb_reis_set->contains (e);
+  hash_set<edge> *set = (hash_set<edge> *)data;
+  return set->contains (e);
 }
 
 /* Creates a subloop of LOOP with latch edge LATCH.  */
@@ -727,14 +727,14 @@ form_subloop (class loop *loop, edge latch)
   edge e, new_entry;
   class loop *new_loop;
 
-  mfb_reis_set = new hash_set<edge>;
+  hash_set<edge> *reis_set = new hash_set<edge>;
   FOR_EACH_EDGE (e, ei, loop->header->preds)
     {
       if (e != latch)
-       mfb_reis_set->add (e);
+       reis_set->add (e);
     }
-  new_entry = make_forwarder_block (loop->header, mfb_redirect_edges_in_set);
-  delete mfb_reis_set;
+  new_entry = make_forwarder_block (loop->header, mfb_redirect_edges_in_set, reis_set);
+  delete reis_set;
 
   loop->header = new_entry->src;
 
@@ -765,11 +765,11 @@ merge_latch_edges (class loop *loop)
       if (dump_file)
        fprintf (dump_file, "Merged latch edges of loop %d\n", loop->num);
 
-      mfb_reis_set = new hash_set<edge>;
+      hash_set<edge> *reis_set = new hash_set<edge>;
       FOR_EACH_VEC_ELT (latches, i, e)
-       mfb_reis_set->add (e);
-      latch = make_forwarder_block (loop->header, mfb_redirect_edges_in_set);
-      delete mfb_reis_set;
+       reis_set->add (e);
+      latch = make_forwarder_block (loop->header, mfb_redirect_edges_in_set, reis_set);
+      delete reis_set;
 
       loop->header = latch->dest;
       loop->latch = latch->src;
index c953bc95b40f4a0c7811b6b87e71ae29e2a057d9..dd5ae82f73ec3c0a54f1a4d81b0ba1cc4da1dac1 100644 (file)
@@ -1640,14 +1640,14 @@ duplicate_loop_body_to_header_edge (class loop *loop, edge e,
 }
 
 /* A callback for make_forwarder block, to redirect all edges except for
-   MFB_KJ_EDGE to the entry part.  E is the edge for that we should decide
+   OTHER(DATA) to the entry part.  E is the edge for that we should decide
    whether to redirect it.  */
 
-edge mfb_kj_edge;
 bool
-mfb_keep_just (edge e)
+mfb_keep_just (edge e, void *data)
 {
-  return e != mfb_kj_edge;
+  edge other = (edge)data;
+  return e != other;
 }
 
 /* True when a candidate preheader BLOCK has predecessors from LOOP.  */
@@ -1729,15 +1729,16 @@ create_preheader (class loop *loop, int flags)
        return NULL;
     }
 
-  mfb_kj_edge = loop_latch_edge (loop);
-  latch_edge_was_fallthru = (mfb_kj_edge->flags & EDGE_FALLTHRU) != 0;
+  edge latch;
+  latch = loop_latch_edge (loop);
+  latch_edge_was_fallthru = (latch->flags & EDGE_FALLTHRU) != 0;
   if (nentry == 1
       && ((flags & CP_FALLTHRU_PREHEADERS) == 0
          || (single_entry->flags & EDGE_CROSSING) == 0))
     dummy = split_edge (single_entry);
   else
     {
-      edge fallthru = make_forwarder_block (loop->header, mfb_keep_just);
+      edge fallthru = make_forwarder_block (loop->header, mfb_keep_just, latch);
       dummy = fallthru->src;
       loop->header = fallthru->dest;
     }
index 396e6d69e8c4d2ffe0d894c19024d02246a063ed..106cc7d005af259f08d69ba3c92a6d18fd64f9ef 100644 (file)
@@ -38,8 +38,6 @@ enum
                                                      discriminators to
                                                      distinguish loop
                                                      iterations.  */
-extern edge mfb_kj_edge;
-
 extern bool remove_path (edge, bool * = NULL, bitmap = NULL);
 extern void place_new_loop (struct function *, class loop *);
 extern void add_loop (class loop *, class loop *);
@@ -62,7 +60,7 @@ extern bool can_duplicate_loop_p (const class loop *loop);
 extern bool
 duplicate_loop_body_to_header_edge (class loop *, edge, unsigned, sbitmap, edge,
                                    vec<edge> *, int);
-extern bool mfb_keep_just (edge);
+extern bool mfb_keep_just (edge, void *);
 basic_block create_preheader (class loop *, int);
 extern void create_preheaders (int);
 extern void force_single_succ_latches (void);
index ab3c8c308935a40301117031b6fb8b9a42c27e19..234b45a219fc923fffa67f8fe6d78ce499f5844e 100644 (file)
@@ -1103,8 +1103,11 @@ cleanup_control_flow_pre ()
   return retval;
 }
 
+/* Callback function for make_forwarder_block which returns
+   true when E is not a latch.  */
+
 static bool
-mfb_keep_latches (edge e)
+mfb_keep_latches (edge e, void*)
 {
   return !((dom_info_available_p (CDI_DOMINATORS)
            && dominated_by_p (CDI_DOMINATORS, e->src, e->dest))
@@ -1164,7 +1167,7 @@ cleanup_tree_cfg_noloop (unsigned ssa_update_flags)
               create a forwarder.  */
            if (found_latch && ! any_abnormal && n > 1)
              {
-               edge fallthru = make_forwarder_block (bb, mfb_keep_latches);
+               edge fallthru = make_forwarder_block (bb, mfb_keep_latches, NULL);
                loop->header = fallthru->dest;
                if (! loops_state_satisfies_p (LOOPS_NEED_FIXUP))
                  {
index 0e437b145514a6b9210573a81f79ba325f253a60..db3520b42fc95d9c7bcf18f940f3d94c8ff4ee7d 100644 (file)
@@ -1867,9 +1867,10 @@ fwd_jt_path_registry::thread_through_loop_header (class loop *loop,
      must have only a single successor, but the original header had at
      least two successors.  */
   loop->latch = NULL;
-  mfb_kj_edge = single_succ_edge (new_preheader);
-  loop->header = mfb_kj_edge->dest;
-  latch = make_forwarder_block (tgt_bb, mfb_keep_just);
+  edge keep_edge;
+  keep_edge = single_succ_edge (new_preheader);
+  loop->header = keep_edge->dest;
+  latch = make_forwarder_block (tgt_bb, mfb_keep_just, keep_edge);
   loop->header = latch->dest;
   loop->latch = latch->src;
   return true;