Remove unused variables from REFERENCED_VARS list
Jan Hubicka
jh@suse.cz
Fri Jan 12 00:38:00 GMT 2007
Hi,
this patch makes remove_unused_locals to prunt not only unexpanded_var_list but
also referenced_vars that are a lot more commonly traversed. For temporaries
this also makes them available for ggc memory. On tramp3d after early
optimization about 70% of local variables can be reclaimed to GGC this way
reducing peak memory usage from 720 to 630MB.
:ADDPATCH tree-optimization:
Bootstrapped/regtested i686-linux, OK?
Honza
* tree-dfa.c (remove_referenced_var): New function.
* tree-ssa-live.c (remove_unused_locals): Walk referenced vars and
prune referenced vars list too.
* tree-flow.h (remove_referenced_var): Declare.
Index: tree-dfa.c
===================================================================
*** tree-dfa.c (revision 120681)
--- tree-dfa.c (working copy)
*************** add_referenced_var (tree var)
*** 752,757 ****
--- 752,780 ----
}
}
+ /* Remove VAR from the list. */
+
+ void
+ remove_referenced_var (tree var)
+ {
+ var_ann_t v_ann;
+ struct int_tree_map in;
+ void **loc;
+ unsigned int uid = DECL_UID (var);
+
+ clear_call_clobbered (var);
+ v_ann = get_var_ann (var);
+ ggc_free (v_ann);
+ var->base.ann = NULL;
+ gcc_assert (DECL_P (var));
+ in.uid = uid;
+ in.to = var;
+ loc = htab_find_slot_with_hash (gimple_referenced_vars (cfun), &in, uid,
+ NO_INSERT);
+ ggc_free (*loc);
+ htab_clear_slot (gimple_referenced_vars (cfun), loc);
+ }
+
/* Return the virtual variable associated to the non-scalar variable VAR. */
Index: tree-ssa-live.c
===================================================================
*** tree-ssa-live.c (revision 120681)
--- tree-ssa-live.c (working copy)
*************** remove_unused_locals (void)
*** 449,463 ****
{
basic_block bb;
tree t, *cell;
/* Assume all locals are unused. */
! for (t = cfun->unexpanded_var_list; t; t = TREE_CHAIN (t))
! {
! tree var = TREE_VALUE (t);
! if (TREE_CODE (var) != FUNCTION_DECL
! && var_ann (var))
! var_ann (var)->used = false;
! }
/* Walk the CFG marking all referenced symbols. */
FOR_EACH_BB (bb)
--- 449,460 ----
{
basic_block bb;
tree t, *cell;
+ referenced_var_iterator rvi;
+ var_ann_t ann;
/* Assume all locals are unused. */
! FOR_EACH_REFERENCED_VAR (t, rvi)
! var_ann (t)->used = false;
/* Walk the CFG marking all referenced symbols. */
FOR_EACH_BB (bb)
*************** remove_unused_locals (void)
*** 493,503 ****
for (cell = &cfun->unexpanded_var_list; *cell; )
{
tree var = TREE_VALUE (*cell);
- var_ann_t ann;
if (TREE_CODE (var) != FUNCTION_DECL
&& (!(ann = var_ann (var))
|| !ann->used))
{
*cell = TREE_CHAIN (*cell);
continue;
--- 490,499 ----
for (cell = &cfun->unexpanded_var_list; *cell; )
{
tree var = TREE_VALUE (*cell);
if (TREE_CODE (var) != FUNCTION_DECL
&& (!(ann = var_ann (var))
|| !ann->used))
{
*cell = TREE_CHAIN (*cell);
continue;
*************** remove_unused_locals (void)
*** 505,510 ****
--- 501,519 ----
cell = &TREE_CHAIN (*cell);
}
+
+ /* Remove unused variables from REFERENCED_VARs. As an special exception
+ keep the variables that are believed to be aliased. Those can't be
+ easilly removed from the alias sets and and operand caches.
+ They will be removed shortly after next may_alias pass is performed. */
+ FOR_EACH_REFERENCED_VAR (t, rvi)
+ if (!is_global_var (t)
+ && !MTAG_P (t)
+ && TREE_CODE (t) != PARM_DECL
+ && TREE_CODE (t) != RESULT_DECL
+ && !(ann = var_ann (t))->used
+ && !ann->is_aliased && !is_call_clobbered (t) && !ann->symbol_mem_tag)
+ remove_referenced_var (t);
}
Index: tree-flow.h
===================================================================
*** tree-flow.h (revision 120681)
--- tree-flow.h (working copy)
*************** extern void dump_subvars_for (FILE *, tr
*** 698,703 ****
--- 698,704 ----
extern void debug_subvars_for (tree);
extern tree get_virtual_var (tree);
extern void add_referenced_var (tree);
+ extern void remove_referenced_var (tree);
extern void mark_symbols_for_renaming (tree);
extern void find_new_referenced_vars (tree *);
More information about the Gcc-patches
mailing list