This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: A support function for loop infrastructure change
Hello.
> > This function is used several times in new loop infrastructure (and also
> > in new loop optimizer) in cfg branch. Bootstrapped on i686 (both mainline
> > and branch).
> >
> > Zdenek Dvorak
> >
> > Changelog:
> >
> > * basic-block.h (dfs_enumerate_from): Declare.
> > * cfganal.c (dfs_enumerate_from): New.
> These may sound like nits, but can you please try to use more descriptive
> variable names.
>
> rslt -> result_list
> rslt_max -> max_blocks (?)
> st->stack
> tv->num_blocks_found
>
> What is "data" used for?
Satisfied?
Zdenek Dvorak
Changelog:
* basic-block.h (dfs_enumerate_from): Declare.
* cfganal.c (dfs_enumerate_from): New.
Index: basic-block.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/basic-block.h,v
retrieving revision 1.137
diff -c -3 -p -r1.137 basic-block.h
*** basic-block.h 2002/03/07 15:37:59 1.137
--- basic-block.h 2002/03/11 09:08:09
*************** extern void alloc_aux_for_edges PARAMS
*** 663,668 ****
--- 663,672 ----
extern void clear_aux_for_edges PARAMS ((void));
extern void free_aux_for_edges PARAMS ((void));
+ extern int dfs_enumerate_from PARAMS ((basic_block, int,
+ bool (*)(basic_block, void *),
+ basic_block *, int, void *));
+
/* This function is always defined so it can be called from the
debugger, and it is declared extern so we don't get warnings about
it being unused. */
Index: cfganal.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cfganal.c,v
retrieving revision 1.16
diff -c -3 -p -r1.16 cfganal.c
*** cfganal.c 2002/03/06 10:17:13 1.16
--- cfganal.c 2002/03/11 09:08:09
*************** flow_dfs_compute_reverse_finish (data)
*** 1178,1180 ****
--- 1178,1240 ----
free (data->stack);
sbitmap_free (data->visited_blocks);
}
+
+ /* Performs dfs search from BB over vertices satisfying PREDICATE;
+ if REVERSE, go against direction of edges. Returns number of blocks
+ found and their list in RESULT. RESULT can contain at most RSLT_MAX items.
+ DATA is passed to PREDICATE. */
+ int
+ dfs_enumerate_from (bb, reverse, predicate, result, rslt_max, data)
+ basic_block bb;
+ int reverse;
+ bool (*predicate) (basic_block, void *);
+ basic_block *result;
+ int rslt_max;
+ void *data;
+ {
+ basic_block *stack, lbb;
+ int sp = 0, bbs_found = 0;
+ sbitmap visited;
+
+ visited = sbitmap_alloc (n_basic_blocks - (INVALID_BLOCK + 1));
+ sbitmap_zero (visited);
+
+ stack = xcalloc (rslt_max, sizeof (basic_block));
+ result[bbs_found++] = stack[sp++] = bb;
+ SET_BIT (visited, bb->index - (INVALID_BLOCK + 1));
+
+ while (sp)
+ {
+ edge e;
+ lbb = stack[--sp];
+ if (reverse)
+ {
+ for (e = lbb->pred; e; e = e->pred_next)
+ if (!TEST_BIT(visited, e->src->index - (INVALID_BLOCK + 1))
+ && predicate (e->src, data))
+ {
+ if (bbs_found == rslt_max)
+ abort ();
+ result[bbs_found++] = stack[sp++] = e->src;
+ SET_BIT (visited, e->src->index - (INVALID_BLOCK + 1));
+ }
+ }
+ else
+ {
+ for (e = lbb->succ; e; e = e->succ_next)
+ if (!TEST_BIT(visited, e->dest->index - (INVALID_BLOCK + 1))
+ && predicate (e->dest, data))
+ {
+ if (bbs_found == rslt_max)
+ abort ();
+ result[bbs_found++] = stack[sp++] = e->dest;
+ SET_BIT (visited, e->dest->index - (INVALID_BLOCK + 1));
+ }
+ }
+ }
+
+ free (stack);
+ sbitmap_free (visited);
+
+ return bbs_found;
+ }