]> gcc.gnu.org Git - gcc.git/commitdiff
Make graph dumping work for fn != cfun
authorRichard Biener <rguenther@suse.de>
Fri, 28 Jan 2022 09:28:39 +0000 (10:28 +0100)
committerRichard Biener <rguenther@suse.de>
Fri, 28 Jan 2022 10:28:09 +0000 (11:28 +0100)
The following makes dumping of a function as graph work as intended
when specifying a function other than cfun.  Unfortunately the loop
and the dominance APIs are not set up to work for other functions
than cfun so you won't get any fancy loop dumps but the non-loop
dump works up to reaching mark_dfs_back_edges which I trivially made
function aware and adjusted current callers with a wrapper.

With all this, doing dot-fn id->src_cfun from the debugger when
debugging inlining works.  Previously you got a strange mix of
the src and dest functions visualized ;)

2022-01-28  Richard Biener  <rguenther@suse.de>

* cfganal.h (mark_dfs_back_edges): Provide API with struct
function argument.
* cfganal.cc (mark_dfs_back_edges): Take a struct function
to work on, add a wrapper passing cfun.
* graph.cc (draw_cfg_nodes_no_loops): Replace stray cfun
uses with fun which is already passed.
(draw_cfg_edges): Likewise.
(draw_cfg_nodes_for_loop): Do not use draw_cfg_nodes_for_loop
for fun != cfun.

gcc/cfganal.cc
gcc/cfganal.h
gcc/graph.cc

index e570d27768b4c77ec60b264e48dba3a86f9e9310..79c627a1716a008ab4205aaf3380c0ba744a8a43 100644 (file)
@@ -58,7 +58,7 @@ private:
    and heavily borrowed from pre_and_rev_post_order_compute.  */
 
 bool
-mark_dfs_back_edges (void)
+mark_dfs_back_edges (struct function *fun)
 {
   int *pre;
   int *post;
@@ -67,20 +67,20 @@ mark_dfs_back_edges (void)
   bool found = false;
 
   /* Allocate the preorder and postorder number arrays.  */
-  pre = XCNEWVEC (int, last_basic_block_for_fn (cfun));
-  post = XCNEWVEC (int, last_basic_block_for_fn (cfun));
+  pre = XCNEWVEC (int, last_basic_block_for_fn (fun));
+  post = XCNEWVEC (int, last_basic_block_for_fn (fun));
 
   /* Allocate stack for back-tracking up CFG.  */
-  auto_vec<edge_iterator, 20> stack (n_basic_blocks_for_fn (cfun) + 1);
+  auto_vec<edge_iterator, 20> stack (n_basic_blocks_for_fn (fun) + 1);
 
   /* Allocate bitmap to track nodes that have been visited.  */
-  auto_sbitmap visited (last_basic_block_for_fn (cfun));
+  auto_sbitmap visited (last_basic_block_for_fn (fun));
 
   /* None of the nodes in the CFG have been visited yet.  */
   bitmap_clear (visited);
 
   /* Push the first edge on to the stack.  */
-  stack.quick_push (ei_start (ENTRY_BLOCK_PTR_FOR_FN (cfun)->succs));
+  stack.quick_push (ei_start (ENTRY_BLOCK_PTR_FOR_FN (fun)->succs));
 
   while (!stack.is_empty ())
     {
@@ -94,8 +94,8 @@ mark_dfs_back_edges (void)
       ei_edge (ei)->flags &= ~EDGE_DFS_BACK;
 
       /* Check if the edge destination has been visited yet.  */
-      if (dest != EXIT_BLOCK_PTR_FOR_FN (cfun) && ! bitmap_bit_p (visited,
-                                                                 dest->index))
+      if (dest != EXIT_BLOCK_PTR_FOR_FN (fun) && ! bitmap_bit_p (visited,
+                                                                dest->index))
        {
          /* Mark that we have visited the destination.  */
          bitmap_set_bit (visited, dest->index);
@@ -112,14 +112,14 @@ mark_dfs_back_edges (void)
        }
       else
        {
-         if (dest != EXIT_BLOCK_PTR_FOR_FN (cfun)
-             && src != ENTRY_BLOCK_PTR_FOR_FN (cfun)
+         if (dest != EXIT_BLOCK_PTR_FOR_FN (fun)
+             && src != ENTRY_BLOCK_PTR_FOR_FN (fun)
              && pre[src->index] >= pre[dest->index]
              && post[dest->index] == 0)
            ei_edge (ei)->flags |= EDGE_DFS_BACK, found = true;
 
          if (ei_one_before_end_p (ei)
-             && src != ENTRY_BLOCK_PTR_FOR_FN (cfun))
+             && src != ENTRY_BLOCK_PTR_FOR_FN (fun))
            post[src->index] = postnum++;
 
          if (!ei_one_before_end_p (ei))
@@ -135,6 +135,12 @@ mark_dfs_back_edges (void)
   return found;
 }
 
+bool
+mark_dfs_back_edges (void)
+{
+  return mark_dfs_back_edges (cfun);
+}
+
 /* Find unreachable blocks.  An unreachable block will have 0 in
    the reachable bit in block->flags.  A nonzero value indicates the
    block is reachable.  */
index 386cfbf211fb7cdcb14eee3b61a906b31e585f0a..ac637de2b5aa6f84403707425ad042f9de76c095 100644 (file)
@@ -49,6 +49,7 @@ private:
   bitmap_obstack m_bitmaps;
 };
 
+extern bool mark_dfs_back_edges (struct function *);
 extern bool mark_dfs_back_edges (void);
 extern void find_unreachable_blocks (void);
 extern void verify_no_unreachable_blocks (void);
index 9990c8eccfdf3475f789c1938c66ac13ca8b5815..bc29862fcad231d5162d3af84d9ffe2227b02dee 100644 (file)
@@ -169,14 +169,14 @@ draw_cfg_nodes_no_loops (pretty_printer *pp, struct function *fun)
   int *rpo = XNEWVEC (int, n_basic_blocks_for_fn (fun));
   int i, n;
 
-  auto_sbitmap visited (last_basic_block_for_fn (cfun));
+  auto_sbitmap visited (last_basic_block_for_fn (fun));
   bitmap_clear (visited);
 
   n = pre_and_rev_post_order_compute_fn (fun, NULL, rpo, true);
   for (i = n_basic_blocks_for_fn (fun) - n;
        i < n_basic_blocks_for_fn (fun); i++)
     {
-      basic_block bb = BASIC_BLOCK_FOR_FN (cfun, rpo[i]);
+      basic_block bb = BASIC_BLOCK_FOR_FN (fun, rpo[i]);
       draw_cfg_node (pp, fun->funcdef_no, bb);
       bitmap_set_bit (visited, bb->index);
     }
@@ -248,7 +248,8 @@ draw_cfg_nodes_for_loop (pretty_printer *pp, int funcdef_no,
 static void
 draw_cfg_nodes (pretty_printer *pp, struct function *fun)
 {
-  if (loops_for_fn (fun))
+  /* ???  The loop and dominance APIs are dependent on fun == cfun.  */
+  if (fun == cfun && loops_for_fn (fun))
     draw_cfg_nodes_for_loop (pp, fun->funcdef_no, get_loop (fun, 0));
   else
     draw_cfg_nodes_no_loops (pp, fun);
@@ -267,7 +268,7 @@ draw_cfg_edges (pretty_printer *pp, struct function *fun)
   edge e;
   edge_iterator ei;
   unsigned int idx = 0;
-  FOR_EACH_BB_FN (bb, cfun)
+  FOR_EACH_BB_FN (bb, fun)
     FOR_EACH_EDGE (e, ei, bb->succs)
       {
        if (e->flags & EDGE_DFS_BACK)
@@ -275,13 +276,13 @@ draw_cfg_edges (pretty_printer *pp, struct function *fun)
        idx++;
       }
 
-  mark_dfs_back_edges ();
-  FOR_ALL_BB_FN (bb, cfun)
+  mark_dfs_back_edges (fun);
+  FOR_ALL_BB_FN (bb, fun)
     draw_cfg_node_succ_edges (pp, fun->funcdef_no, bb);
 
   /* Restore EDGE_DFS_BACK flag from dfs_back.  */
   idx = 0;
-  FOR_EACH_BB_FN (bb, cfun)
+  FOR_EACH_BB_FN (bb, fun)
     FOR_EACH_EDGE (e, ei, bb->succs)
       {
        if (bitmap_bit_p (dfs_back, idx))
This page took 0.071363 seconds and 5 git commands to generate.