This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [tree-ssa] Do alias analysis after SSA. Improvements to PR8361.
- From: Diego Novillo <dnovillo at redhat dot com>
- To: Jeff Law <law at redhat dot com>
- Cc: "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 08 Jan 2004 13:44:20 -0500
- Subject: Re: [tree-ssa] Do alias analysis after SSA. Improvements to PR8361.
- Organization: Red Hat Canada
- References: <200401081812.i08ICS9s007537@speedy.slc.redhat.com>
On Thu, 2004-01-08 at 13:12, law@redhat.com wrote:
> OK. I'll be interested in the use-def chain walker -- I do at little
> of that in the dominator optimizer, so a relatively generic framework
> for walking the chains would probably be useful.
>
I was going to include it in yesterday's patch, but since I still
haven't finished the client I wasn't sure if I was going to add more
features to it. Another client for this is the builtin folder in
tree-ssa-ccp.c.
This is just the obvious implementation of the walker. Feel free to
use/modify this version. I haven't tested too extensively, but it seems
to work fine on the parts-of-gcc collection of .i/.ii files.
Diego.
Index: tree-flow.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-flow.h,v
retrieving revision 1.1.4.179
diff -d -c -p -r1.1.4.179 tree-flow.h
*** tree-flow.h 7 Jan 2004 23:44:15 -0000 1.1.4.179
--- tree-flow.h 8 Jan 2004 02:03:34 -0000
*************** extern void remove_useless_vars (void);
*** 485,490 ****
--- 485,494 ----
extern void record_vars (tree);
extern bool block_may_fallthru (tree block);
+ /* Call-back function for walk_use_def_chains(). At each reaching
+ definition, a function with this prototype is called. */
+ typedef void (*walk_use_def_chains_fn) (tree, tree, void *);
+
/* In tree-ssa.c */
extern void init_tree_ssa (void);
extern void rewrite_into_ssa (tree, bitmap, enum tree_dump_index);
*************** extern bool tree_ssa_useless_type_conver
*** 504,509 ****
--- 508,514 ----
extern bool tree_ssa_useless_type_conversion_1 (tree, tree);
extern void verify_ssa (void);
extern void delete_tree_ssa (void);
+ extern void walk_use_def_chains (tree, walk_use_def_chains_fn, void *);
extern unsigned int highest_ssa_version;
extern void kill_redundant_phi_nodes (void);
Index: tree-ssa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa.c,v
retrieving revision 1.1.4.182
diff -d -c -p -r1.1.4.182 tree-ssa.c
*** tree-ssa.c 7 Jan 2004 23:44:15 -0000 1.1.4.182
--- tree-ssa.c 8 Jan 2004 02:03:34 -0000
*************** tree_ssa_useless_type_conversion (tree e
*** 3577,3582 ****
--- 3577,3640 ----
return false;
}
+
+ /* Internal helper for walk_use_def_chains. */
+
+ static void
+ walk_use_def_chains_1 (tree var, tree def_stmt, walk_use_def_chains_fn fn,
+ void *data, bitmap visited)
+ {
+ if (bitmap_bit_p (visited, SSA_NAME_VERSION (var)))
+ return;
+
+ bitmap_set_bit (visited, SSA_NAME_VERSION (var));
+ if (TREE_CODE (def_stmt) == PHI_NODE)
+ {
+ int i;
+
+ for (i = 0; i < PHI_NUM_ARGS (def_stmt); i++)
+ {
+ tree arg = PHI_ARG_DEF (def_stmt, i);
+ if (TREE_CODE (arg) == SSA_NAME)
+ walk_use_def_chains_1 (arg, SSA_NAME_DEF_STMT (arg), fn, data,
+ visited);
+ else
+ (*fn) (arg, def_stmt, data);
+ }
+ }
+ else
+ (*fn) (var, def_stmt, data);
+ }
+
+
+
+ /* Walk use-def chains starting at the SSA variable VAR. Call function FN
+ with argument DATA at each reaching definition found. */
+
+ void
+ walk_use_def_chains (tree var, walk_use_def_chains_fn fn, void *data)
+ {
+ tree def_stmt;
+
+ #if defined ENABLE_CHECKING
+ if (TREE_CODE (var) != SSA_NAME)
+ abort ();
+ #endif
+
+ def_stmt = SSA_NAME_DEF_STMT (var);
+
+ /* We only need to recurse if the reaching definition comes from a PHI
+ node. */
+ if (TREE_CODE (def_stmt) != PHI_NODE)
+ (*fn) (var, def_stmt, data);
+ else
+ {
+ bitmap visited = BITMAP_XMALLOC ();
+ walk_use_def_chains_1 (var, def_stmt, fn, data, visited);
+ BITMAP_XFREE (visited);
+ }
+ }
+
/* Replaces immediate uses of VAR by REPL. */
static void