tree-pass.h (TODO_remove_unused_locals): Define.

2006-01-05  Richard Guenther  <rguenther@suse.de>
	    Diego Novillo  <dnovillo@redhat.com>

	* tree-pass.h (TODO_remove_unused_locals): Define.
	* gimple-low.c (expand_var_p, remove_useless_vars,
	pass_remove_useless_vars): Remove.  Update all users.
	* tree-ssa-live.c (mark_all_vars_used_1): Handle SSA names.
	(remove_unused_locals): New function.
	* tree-flow.h (remove_unused_locals): Declare.
	* passes.c (execute_todo): Call remove_unused_locals if
	TODO_remove_unused_locals is set.
	* tree-into-ssa.c (pass_build_ssa): Add TODO_remove_unused_locals.
	* tree-ssa-dce.c (pass_dce): Likewise.
	* tree-outof-ssa.c (pass_del_ssa): Likewise.

	* gcc.dg/tree-ssa/loop-11.c: Deal with removed vars pass.
	* gcc.dg/tree-ssa/loop-8.c: Likewise.
	* gcc.dg/tree-ssa/loop-1.c: Likewise.
	* gcc.dg/tree-ssa/pr23294.c: Likewise.
	* gcc.dg/tree-ssa/pr21985.c: Likewise.
	* gcc.dg/tree-ssa/loop-14.c: Likewise.
	* gcc.dg/tree-ssa/loop-2.c: Likewise.
	* gcc.dg/tree-ssa/loop-3.c: Likewise.
	* gcc.dg/tree-ssa/loop-4.c: Likewise.
	* gcc.dg/tree-ssa/pr21171.c: Likewise.
	* gcc.dg/tree-ssa/loop-5.c: Likewise.
	* gcc.dg/tree-ssa/loop-10.c: Likewise.
	* gcc.dg/tree-ssa/loop-6.c: Likewise.
	* treelang/compile/extravar.tree: Likewise.
	* g++.dg/tree-ssa/ssa-cast-1.C: Likewise.
	* g++.dg/tree-ssa/pointer-reference-alias.C: Likewise.
	* g++.dg/tree-ssa/ssa-sra-1.C: Likewise.
	* g++.dg/tree-ssa/ssa-sra-2.C: Likewise.
	* gcc.dg/tree-ssa/20031106-6.c: Disable SRA.

Co-Authored-By: Diego Novillo <dnovillo@redhat.com>

From-SVN: r109379
This commit is contained in:
Richard Guenther 2006-01-05 13:53:54 +00:00 committed by Richard Biener
parent db55bccb01
commit 3f519b3517
29 changed files with 204 additions and 160 deletions

View File

@ -1,3 +1,18 @@
2006-01-05 Richard Guenther <rguenther@suse.de>
Diego Novillo <dnovillo@redhat.com>
* tree-pass.h (TODO_remove_unused_locals): Define.
* gimple-low.c (expand_var_p, remove_useless_vars,
pass_remove_useless_vars): Remove. Update all users.
* tree-ssa-live.c (mark_all_vars_used_1): Handle SSA names.
(remove_unused_locals): New function.
* tree-flow.h (remove_unused_locals): Declare.
* passes.c (execute_todo): Call remove_unused_locals if
TODO_remove_unused_locals is set.
* tree-into-ssa.c (pass_build_ssa): Add TODO_remove_unused_locals.
* tree-ssa-dce.c (pass_dce): Likewise.
* tree-outof-ssa.c (pass_del_ssa): Likewise.
2006-01-05 Richard Guenther <rguenther@suse.de>
* tree-flow.h (struct fieldoff): Decompose field to

View File

@ -55,7 +55,6 @@ static void lower_stmt (tree_stmt_iterator *, struct lower_data *);
static void lower_bind_expr (tree_stmt_iterator *, struct lower_data *);
static void lower_cond_expr (tree_stmt_iterator *, struct lower_data *);
static void lower_return_expr (tree_stmt_iterator *, struct lower_data *);
static bool expand_var_p (tree);
/* Lowers the body of current_function_decl. */
@ -533,82 +532,6 @@ record_vars (tree vars)
}
}
/* Check whether to expand a variable VAR. */
static bool
expand_var_p (tree var)
{
struct var_ann_d *ann;
if (TREE_CODE (var) != VAR_DECL)
return true;
/* Leave statics and externals alone. */
if (TREE_STATIC (var) || DECL_EXTERNAL (var))
return true;
/* Remove all unused local variables. */
ann = var_ann (var);
if (!ann || !ann->used)
return false;
return true;
}
/* Throw away variables that are unused. */
static void
remove_useless_vars (void)
{
tree var, *cell;
FILE *df = NULL;
if (dump_file && (dump_flags & TDF_DETAILS))
{
df = dump_file;
fputs ("Discarding as unused:\n", df);
}
for (cell = &cfun->unexpanded_var_list; *cell; )
{
var = TREE_VALUE (*cell);
if (!expand_var_p (var))
{
if (df)
{
fputs (" ", df);
print_generic_expr (df, var, dump_flags);
fputc ('\n', df);
}
*cell = TREE_CHAIN (*cell);
continue;
}
cell = &TREE_CHAIN (*cell);
}
if (df)
fputc ('\n', df);
}
struct tree_opt_pass pass_remove_useless_vars =
{
"vars", /* name */
NULL, /* gate */
remove_useless_vars, /* execute */
NULL, /* sub */
NULL, /* next */
0, /* static_pass_number */
0, /* tv_id */
0, /* properties_required */
0, /* properties_provided */
0, /* properties_destroyed */
0, /* todo_flags_start */
TODO_dump_func, /* todo_flags_finish */
0 /* letter */
};
/* Mark BLOCK used if it has a used variable in it, then recurse over its
subblocks. */

View File

@ -586,7 +586,6 @@ init_optimization_passes (void)
NEXT_PASS (pass_uncprop);
NEXT_PASS (pass_del_ssa);
NEXT_PASS (pass_nrv);
NEXT_PASS (pass_remove_useless_vars);
NEXT_PASS (pass_mark_used_blocks);
NEXT_PASS (pass_cleanup_cfg_post_optimizing);
*p = NULL;
@ -702,7 +701,6 @@ init_optimization_passes (void)
}
static unsigned int last_verified;
static void
execute_todo (struct tree_opt_pass *pass, unsigned int flags, bool use_required)
{
@ -738,6 +736,9 @@ execute_todo (struct tree_opt_pass *pass, unsigned int flags, bool use_required)
update_ssa (update_flags);
}
if (flags & TODO_remove_unused_locals)
remove_unused_locals ();
if ((flags & TODO_dump_func)
&& dump_file && current_function_decl)
{

View File

@ -1,3 +1,26 @@
2006-01-05 Richard Guenther <rguenther@suse.de>
Diego Novillo <dnovillo@redhat.com>
* gcc.dg/tree-ssa/loop-11.c: Deal with removed vars pass.
* gcc.dg/tree-ssa/loop-8.c: Likewise.
* gcc.dg/tree-ssa/loop-1.c: Likewise.
* gcc.dg/tree-ssa/pr23294.c: Likewise.
* gcc.dg/tree-ssa/pr21985.c: Likewise.
* gcc.dg/tree-ssa/loop-14.c: Likewise.
* gcc.dg/tree-ssa/loop-2.c: Likewise.
* gcc.dg/tree-ssa/loop-3.c: Likewise.
* gcc.dg/tree-ssa/loop-4.c: Likewise.
* gcc.dg/tree-ssa/pr21171.c: Likewise.
* gcc.dg/tree-ssa/loop-5.c: Likewise.
* gcc.dg/tree-ssa/loop-10.c: Likewise.
* gcc.dg/tree-ssa/loop-6.c: Likewise.
* treelang/compile/extravar.tree: Likewise.
* g++.dg/tree-ssa/ssa-cast-1.C: Likewise.
* g++.dg/tree-ssa/pointer-reference-alias.C: Likewise.
* g++.dg/tree-ssa/ssa-sra-1.C: Likewise.
* g++.dg/tree-ssa/ssa-sra-2.C: Likewise.
* gcc.dg/tree-ssa/20031106-6.c: Disable SRA.
2006-01-05 Hans-Peter Nilsson <hp@bitrange.com>
* g++.dg/abi/thunk3.C, g++.dg/abi/thunk4.C: Revert unnecessary fix

View File

@ -1,5 +1,5 @@
/* { dg-do compile } */
/* { dg-options "-O1 -fdump-tree-vars" } */
/* { dg-options "-O1 -fdump-tree-optimized" } */
int f(int *a)
{
@ -9,5 +9,5 @@ int f(int *a)
}
/* There should be only one dereferencing of a. */
/* { dg-final { scan-tree-dump-times "\\*a" 1 "vars" } } */
/* { dg-final { cleanup-tree-dump "vars" } } */
/* { dg-final { scan-tree-dump-times "\\*a" 1 "optimized" } } */
/* { dg-final { cleanup-tree-dump "optimized" } } */

View File

@ -1,5 +1,5 @@
/* { dg-do compile } */
/* { dg-options "-O1 -fdump-tree-vars" } */
/* { dg-options "-O1 -fdump-tree-optimized" } */
int &f(int *a)
{
@ -8,5 +8,5 @@ int &f(int *a)
/* There should be no cast as pointer and references are
considered the same type. */
/* { dg-final { scan-tree-dump-times "\\(int &\\)" 0 "vars"} } */
/* { dg-final { cleanup-tree-dump "vars" } } */
/* { dg-final { scan-tree-dump-times "\\(int &\\)" 0 "optimized"} } */
/* { dg-final { cleanup-tree-dump "optimized" } } */

View File

@ -1,5 +1,5 @@
/* { dg-do compile } */
/* { dg-options "-O1 -fdump-tree-vars-details" } */
/* { dg-options "-O1 -fdump-tree-optimized" } */
void link_error();
@ -57,5 +57,5 @@ void temp()
/* We should have removed the casts from pointers to references and caused SRA to happen. */
/* { dg-final { scan-tree-dump-times "link_error" 0 "vars"} } */
/* { dg-final { cleanup-tree-dump "vars" } } */
/* { dg-final { scan-tree-dump-times "link_error" 0 "optimized"} } */
/* { dg-final { cleanup-tree-dump "optimized" } } */

View File

@ -1,5 +1,5 @@
/* { dg-do compile } */
/* { dg-options "-O1 -fdump-tree-vars-details" } */
/* { dg-options "-O1 -fdump-tree-optimized" } */
void link_error();
@ -48,5 +48,5 @@ void test()
}
/* We should have removed the casts from pointers to references and caused SRA to happen. */
/* { dg-final { scan-tree-dump-times "link_error" 0 "vars"} } */
/* { dg-final { cleanup-tree-dump "vars" } } */
/* { dg-final { scan-tree-dump-times "link_error" 0 "optimized"} } */
/* { dg-final { cleanup-tree-dump "optimized" } } */

View File

@ -1,5 +1,5 @@
/* { dg-do compile } */
/* { dg-options "-O1 -fdump-tree-optimized" } */
/* { dg-options "-O1 -fno-tree-sra -fdump-tree-optimized" } */
extern void link_error (void);

View File

@ -1,15 +1,15 @@
/* { dg-do compile } */
/* { dg-options "-O1 -ftree-loop-ivcanon -funroll-loops -fdump-tree-ivcanon-details -fdump-tree-cunroll-details -fdump-tree-vars" } */
/* { dg-options "-O1 -ftree-loop-ivcanon -funroll-loops -fdump-tree-ivcanon-details -fdump-tree-cunroll-details -fdump-tree-optimized" } */
/* On 31-bit S/390 the function address will be stored (once) in the literal pool,
so scan-assembler-times "foo" will return 1 even if the loop is fully unrolled.
-msmall-exec avoids this by enabling a call instruction with immediate operand. */
/* { dg-options "-O1 -ftree-loop-ivcanon -funroll-loops -fdump-tree-ivcanon-details -fdump-tree-cunroll-details -fdump-tree-vars -msmall-exec" { target s390-*-* } } */
/* { dg-options "-O1 -ftree-loop-ivcanon -funroll-loops -fdump-tree-ivcanon-details -fdump-tree-cunroll-details -fdump-tree-optimized -msmall-exec" { target s390-*-* } } */
/* On Darwin, we call extern functions via a stub in PIC mode which is default and
the stub is named after the function. To avoid this we use -static to go out
of PIC mode. */
/* { dg-options "-O1 -ftree-loop-ivcanon -funroll-loops -fdump-tree-ivcanon-details -fdump-tree-cunroll-details -fdump-tree-vars -static" { target *-*-darwin* } } */
/* { dg-options "-O1 -ftree-loop-ivcanon -funroll-loops -fdump-tree-ivcanon-details -fdump-tree-cunroll-details -fdump-tree-optimized -static" { target *-*-darwin* } } */
void xxx(void)
{
@ -25,8 +25,8 @@ void xxx(void)
/* { dg-final { cleanup-tree-dump "ivcanon" } } */
/* { dg-final { scan-tree-dump-times "Unrolled loop 1 completely" 1 "cunroll"} } */
/* { dg-final { cleanup-tree-dump "cunroll" } } */
/* { dg-final { scan-tree-dump-times "foo" 5 "vars"} } */
/* { dg-final { cleanup-tree-dump "vars" } } */
/* { dg-final { scan-tree-dump-times "foo" 5 "optimized"} } */
/* { dg-final { cleanup-tree-dump "optimized" } } */
/* Because hppa and ia64 targets include an external declaration for foo as
well as the calls we need to look for something more specific then just

View File

@ -1,5 +1,5 @@
/* { dg-do compile } */
/* { dg-options "-O1 -fdump-tree-vars" } */
/* { dg-options "-O1 -fdump-tree-optimized" } */
int bar (void);
@ -26,7 +26,7 @@ void foo (void)
;
}
/* { dg-final { scan-tree-dump-times "if " 3 "vars" } } */
/* { dg-final { scan-tree-dump-times "bar " 2 "vars" } } */
/* { dg-final { scan-tree-dump-times "if " 3 "optimized" } } */
/* { dg-final { scan-tree-dump-times "bar " 2 "optimized" } } */
/* { dg-final { cleanup-tree-dump "vars" } } */
/* { dg-final { cleanup-tree-dump "optimized" } } */

View File

@ -2,7 +2,7 @@
see PR 22442. */
/* { dg-do compile } */
/* { dg-options "-O1 -fdump-tree-vars" } */
/* { dg-options "-O1 -fdump-tree-optimized" } */
void bar (unsigned);
@ -18,11 +18,11 @@ void foo (void)
/* Final value of a gets replaced. */
/* { dg-final { scan-tree-dump-times "\\(16\\)" 1 "vars" } } */
/* { dg-final { scan-tree-dump-times "\\(16\\)" 1 "optimized" } } */
/* And the empty loop is removed. */
/* { dg-final { scan-tree-dump-times "if " 0 "vars" } } */
/* { dg-final { scan-tree-dump-times "if " 0 "optimized" } } */
/* { dg-final { cleanup-tree-dump "vars" } } */
/* { dg-final { cleanup-tree-dump "optimized" } } */

View File

@ -1,6 +1,6 @@
/* A test for final value replacement. */
/* { dg-options "-O2 -fdump-tree-vars" } */
/* { dg-options "-O2 -fdump-tree-optimized" } */
int foo(void);
@ -15,5 +15,5 @@ int bla(void)
return j;
}
/* { dg-final { scan-tree-dump-times "\\+ 100" 1 "vars" } } */
/* { dg-final { cleanup-tree-dump "vars" } } */
/* { dg-final { scan-tree-dump-times "\\+ 100" 1 "optimized" } } */
/* { dg-final { cleanup-tree-dump "optimized" } } */

View File

@ -1,7 +1,7 @@
/* A test for strength reduction and induction variable elimination. */
/* { dg-do compile } */
/* { dg-options "-O1 -fdump-tree-vars" } */
/* { dg-options "-O1 -fdump-tree-optimized" } */
/* Size of this structure should be sufficiently weird so that no memory
addressing mode applies. */
@ -24,20 +24,20 @@ void xxx(void)
/* Access to arr_base[iter].y should be strength reduced, i.e., there should
be no multiplication. */
/* { dg-final { scan-tree-dump-times " \\* \[^\\n\\r\]*=" 0 "vars" } } */
/* { dg-final { scan-tree-dump-times "\[^\\n\\r\]*= \\* " 0 "vars" } } */
/* { dg-final { scan-tree-dump-times "MEM" 1 "vars" } } */
/* { dg-final { scan-tree-dump-times " \\* \[^\\n\\r\]*=" 0 "optimized" } } */
/* { dg-final { scan-tree-dump-times "\[^\\n\\r\]*= \\* " 0 "optimized" } } */
/* { dg-final { scan-tree-dump-times "MEM" 1 "optimized" } } */
/* 17 * iter should be strength reduced. */
/* { dg-final { scan-tree-dump-times " \\* 17" 0 "vars" } } */
/* { dg-final { scan-tree-dump-times " \\+ 17" 1 "vars" } } */
/* { dg-final { scan-tree-dump-times " \\* 17" 0 "optimized" } } */
/* { dg-final { scan-tree-dump-times " \\+ 17" 1 "optimized" } } */
/* The induction variable comparison with 99 should be eliminated
and replaced by comparison of one of the newly created ivs. */
/* { dg-final { scan-tree-dump-times "iter" 0 "vars" } } */
/* { dg-final { scan-tree-dump-times "99" 0 "vars" } } */
/* { dg-final { scan-tree-dump-times "100" 0 "vars" } } */
/* { dg-final { scan-tree-dump-times "iter" 0 "optimized" } } */
/* { dg-final { scan-tree-dump-times "99" 0 "optimized" } } */
/* { dg-final { scan-tree-dump-times "100" 0 "optimized" } } */
/* { dg-final { cleanup-tree-dump "vars" } } */
/* { dg-final { cleanup-tree-dump "optimized" } } */

View File

@ -3,7 +3,7 @@
assume something about memory addressing modes. */
/* { dg-do compile { target i?86-*-* x86_64-*-* } } */
/* { dg-options "-O1 -fdump-tree-vars" } */
/* { dg-options "-O1 -fdump-tree-optimized" } */
int arr_base[100];
@ -20,11 +20,11 @@ void xxx(void)
/* Access to arr_base[iter].y should not be strength reduced, since
we have a memory mode including multiplication by 4. */
/* { dg-final { scan-tree-dump-times "MEM" 1 "vars" } } */
/* { dg-final { scan-tree-dump-times "step:" 1 "vars" } } */
/* { dg-final { scan-tree-dump-times "MEM" 1 "optimized" } } */
/* { dg-final { scan-tree-dump-times "step:" 1 "optimized" } } */
/* And original induction variable should be preserved. */
/* { dg-final { scan-tree-dump-times "int iter" 1 "vars" } } */
/* { dg-final { scan-tree-dump-times "int iter" 1 "optimized" } } */
/* { dg-final { cleanup-tree-dump "vars" } } */
/* { dg-final { cleanup-tree-dump "optimized" } } */

View File

@ -1,7 +1,7 @@
/* A test for strength reduction and induction variable elimination. */
/* { dg-do compile } */
/* { dg-options "-O1 -fdump-tree-vars" } */
/* { dg-options "-O1 -fdump-tree-optimized" } */
/* Size of this structure should be sufficiently weird so that no memory
addressing mode applies. */
@ -34,12 +34,12 @@ void xxx(void)
In any case, we should not have any multiplication. */
/* { dg-final { scan-tree-dump-times " \\* \[^\\n\\r\]*=" 0 "vars" } } */
/* { dg-final { scan-tree-dump-times "\[^\\n\\r\]*= \\* " 0 "vars" } } */
/* { dg-final { scan-tree-dump-times "MEM" 1 "vars" } } */
/* { dg-final { scan-tree-dump-times " \\* \[^\\n\\r\]*=" 0 "optimized" } } */
/* { dg-final { scan-tree-dump-times "\[^\\n\\r\]*= \\* " 0 "optimized" } } */
/* { dg-final { scan-tree-dump-times "MEM" 1 "optimized" } } */
/* And the original induction variable should be eliminated. */
/* { dg-final { scan-tree-dump-times "iter" 0 "vars" } } */
/* { dg-final { scan-tree-dump-times "iter" 0 "optimized" } } */
/* { dg-final { cleanup-tree-dump "vars" } } */
/* { dg-final { cleanup-tree-dump "optimized" } } */

View File

@ -1,7 +1,7 @@
/* A test for induction variable merging. */
/* { dg-do compile } */
/* { dg-options "-O1 -fdump-tree-vars" } */
/* { dg-options "-O1 -fdump-tree-optimized" } */
void foo(long);
@ -18,11 +18,11 @@ void xxx(void)
/* Only iter variable should remain. */
/* { dg-final { scan-tree-dump-times "int iter" 1 "vars" } } */
/* { dg-final { scan-tree-dump-times "jter" 0 "vars" } } */
/* { dg-final { scan-tree-dump-times "int iter" 1 "optimized" } } */
/* { dg-final { scan-tree-dump-times "jter" 0 "optimized" } } */
/* And the use of jter should be replaced by iter + 2 */
/* { dg-final { scan-tree-dump-times " \\+ 2" 1 "vars" } } */
/* { dg-final { scan-tree-dump-times " \\+ 2" 1 "optimized" } } */
/* { dg-final { cleanup-tree-dump "vars" } } */
/* { dg-final { cleanup-tree-dump "optimized" } } */

View File

@ -1,5 +1,5 @@
/* { dg-do compile } */
/* { dg-options "-O1 -funswitch-loops -fdump-tree-unswitch-details -fdump-tree-vars" } */
/* { dg-options "-O1 -funswitch-loops -fdump-tree-unswitch-details -fdump-tree-optimized" } */
int ch;
int a[100];
@ -24,5 +24,5 @@ void xxx(void)
/* In effect there should be exactly three conditional jumps in the final program. */
/* { dg-final { scan-tree-dump-times "else" 3 "vars" } } */
/* { dg-final { cleanup-tree-dump "vars" } } */
/* { dg-final { scan-tree-dump-times "else" 3 "optimized" } } */
/* { dg-final { cleanup-tree-dump "optimized" } } */

View File

@ -1,7 +1,7 @@
/* A test for strength reduction of ivs with nonconstant step. */
/* { dg-do compile } */
/* { dg-options "-O1 -fdump-tree-vars" } */
/* { dg-options "-O1 -fdump-tree-optimized" } */
int bar (void);
@ -19,7 +19,7 @@ void xxx (void)
the step, we need to calculate step * sizeof (int), thus we need to be
a bit careful about which multiplications we disallow. */
/* { dg-final { scan-tree-dump-times "step \\* \[^0-9\]" 0 "vars" } } */
/* { dg-final { scan-tree-dump-times "\[^0-9\] \\* step" 0 "vars" } } */
/* { dg-final { scan-tree-dump-times "step \\* \[^0-9\]" 0 "optimized" } } */
/* { dg-final { scan-tree-dump-times "\[^0-9\] \\* step" 0 "optimized" } } */
/* { dg-final { cleanup-tree-dump "vars" } } */
/* { dg-final { cleanup-tree-dump "optimized" } } */

View File

@ -1,6 +1,6 @@
/* PR 21171. Ivopts should not rewrite references to volatile memory. */
/* { dg-do compile } */
/* { dg-options "-O1 -fdump-tree-vars" } */
/* { dg-options "-O1 -fdump-tree-optimized" } */
typedef unsigned int u_int32_t;
typedef unsigned char u_int8_t;
@ -25,5 +25,5 @@ int main()
return 0;
}
/* { dg-final { scan-tree-dump-times "SVR" 1 "vars"} } */
/* { dg-final { cleanup-tree-dump "vars" } } */
/* { dg-final { scan-tree-dump-times "SVR" 1 "optimized"} } */
/* { dg-final { cleanup-tree-dump "optimized" } } */

View File

@ -1,5 +1,5 @@
/* { dg-do compile } */
/* { dg-options "-O1 -fdump-tree-vars" } */
/* { dg-options "-O1 -fdump-tree-optimized" } */
struct
{
@ -30,5 +30,5 @@ main (void)
/* Two of the calls to foo should be folded to just foo(constant). */
/* { dg-final { scan-tree-dump-times "foo \\(\[0-9\]*\\)" 2 "vars" } } */
/* { dg-final { cleanup-tree-dump "vars" } } */
/* { dg-final { scan-tree-dump-times "foo \\(\[0-9\]*\\)" 2 "optimized" } } */
/* { dg-final { cleanup-tree-dump "optimized" } } */

View File

@ -1,5 +1,5 @@
/* { dg-do compile } */
/* { dg-options "-O -fdump-tree-vars" } */
/* { dg-options "-O -fdump-tree-optimized" } */
int f1(int a)
{
@ -31,8 +31,8 @@ int f6(int a, int b)
return 6*a - 2*b;
}
/* { dg-final { scan-tree-dump-times "a \\\* 5" 3 "vars" } } */
/* { dg-final { scan-tree-dump "\\\(b \\\* 3 \\\+ a\\\) \\\* 2" "vars" } } */
/* { dg-final { scan-tree-dump "\\\(a - b \\\* 3\\\) \\\* 2" "vars" } } */
/* { dg-final { scan-tree-dump "\\\(a \\\* 3 - b\\\) \\\* 2" "vars" } } */
/* { dg-final { cleanup-tree-dump "vars" } } */
/* { dg-final { scan-tree-dump-times "a \\\* 5" 3 "optimized" } } */
/* { dg-final { scan-tree-dump "\\\(b \\\* 3 \\\+ a\\\) \\\* 2" "optimized" } } */
/* { dg-final { scan-tree-dump "\\\(a - b \\\* 3\\\) \\\* 2" "optimized" } } */
/* { dg-final { scan-tree-dump "\\\(a \\\* 3 - b\\\) \\\* 2" "optimized" } } */
/* { dg-final { cleanup-tree-dump "optimized" } } */

View File

@ -1,5 +1,5 @@
// { dg-do compile }
// { dg-options "-fdump-tree-vars -O1 -Wunused-variable" }
// { dg-options "-fdump-tree-optimized -O1 -Wunused-variable" }
external_definition int bar (int aaa, int ddd);
static int foo = -3; // { dg-warning "defined but not used" }
@ -10,5 +10,5 @@ bar
return aaa + ddd + +3;
}
// { dg-final { scan-tree-dump-not "ccc" "vars" } }
// { dg-final { cleanup-tree-dump "vars" } }
// { dg-final { scan-tree-dump-not "ccc" "optimized" } }
// { dg-final { cleanup-tree-dump "optimized" } }

View File

@ -815,6 +815,9 @@ tree force_gimple_operand_bsi (block_stmt_iterator *, tree, bool, tree);
/* In tree-ssa-structalias.c */
bool find_what_p_points_to (tree);
/* In tree-ssa-live.c */
extern void remove_unused_locals (void);
/* In tree-ssa-address.c */
/* Affine combination of trees. We keep track of at most MAX_AFF_ELTS elements

View File

@ -1791,7 +1791,9 @@ struct tree_opt_pass pass_build_ssa =
PROP_ssa, /* properties_provided */
0, /* properties_destroyed */
0, /* todo_flags_start */
TODO_dump_func | TODO_verify_ssa, /* todo_flags_finish */
TODO_dump_func
| TODO_verify_ssa
| TODO_remove_unused_locals, /* todo_flags_finish */
0 /* letter */
};

View File

@ -2556,6 +2556,8 @@ struct tree_opt_pass pass_del_ssa =
PROP_ssa, /* properties_destroyed */
TODO_verify_ssa | TODO_verify_flow
| TODO_verify_stmts, /* todo_flags_start */
TODO_dump_func | TODO_ggc_collect, /* todo_flags_finish */
TODO_dump_func
| TODO_ggc_collect
| TODO_remove_unused_locals, /* todo_flags_finish */
0 /* letter */
};

View File

@ -200,6 +200,11 @@ struct dump_file_info
renaming are processed. */
#define TODO_update_ssa_only_virtuals (1 << 10)
/* Some passes leave unused local variables that can be removed from
cfun->unexpanded_var_list. This reduces the size of dump files and
the memory footprint for VAR_DECLs. */
#define TODO_remove_unused_locals (1 << 11)
#define TODO_update_ssa_any \
(TODO_update_ssa \
| TODO_update_ssa_no_phi \
@ -267,7 +272,6 @@ extern struct tree_opt_pass pass_forwprop;
extern struct tree_opt_pass pass_redundant_phi;
extern struct tree_opt_pass pass_dse;
extern struct tree_opt_pass pass_nrv;
extern struct tree_opt_pass pass_remove_useless_vars;
extern struct tree_opt_pass pass_mark_used_blocks;
extern struct tree_opt_pass pass_rename_ssa_copies;
extern struct tree_opt_pass pass_expand;

View File

@ -979,7 +979,8 @@ struct tree_opt_pass pass_dce =
| TODO_update_ssa
| TODO_cleanup_cfg
| TODO_ggc_collect
| TODO_verify_ssa, /* todo_flags_finish */
| TODO_verify_ssa
| TODO_remove_unused_locals, /* todo_flags_finish */
0 /* letter */
};

View File

@ -296,6 +296,9 @@ mark_all_vars_used_1 (tree *tp, int *walk_subtrees,
{
tree t = *tp;
if (TREE_CODE (t) == SSA_NAME)
t = SSA_NAME_VAR (t);
/* Ignore TREE_ORIGINAL for TARGET_MEM_REFS, as well as other
fields that do not contain vars. */
if (TREE_CODE (t) == TARGET_MEM_REF)
@ -327,6 +330,72 @@ mark_all_vars_used (tree *expr_p)
walk_tree (expr_p, mark_all_vars_used_1, NULL, NULL);
}
/* Remove local variables that are not referenced in the IL. */
void
remove_unused_locals (void)
{
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)
{
block_stmt_iterator bsi;
tree phi, def;
/* Walk the statements. */
for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
mark_all_vars_used (bsi_stmt_ptr (bsi));
for (phi = phi_nodes (bb); phi; phi = PHI_CHAIN (phi))
{
use_operand_p arg_p;
ssa_op_iter i;
/* No point processing globals. */
if (is_global_var (SSA_NAME_VAR (PHI_RESULT (phi))))
continue;
def = PHI_RESULT (phi);
mark_all_vars_used (&def);
FOR_EACH_PHI_ARG (arg_p, phi, i, SSA_OP_ALL_USES)
{
tree arg = USE_FROM_PTR (arg_p);
mark_all_vars_used (&arg);
}
}
}
/* Remove unmarked vars and clear used flag. */
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;
}
cell = &TREE_CHAIN (*cell);
}
}
/* This function looks through the program and uses FLAGS to determine what
SSA versioned variables are given entries in a new partition table. This
new partition map is returned. */
@ -362,6 +431,7 @@ create_ssa_var_map (int flags)
FOR_EACH_BB (bb)
{
tree phi, arg;
for (phi = phi_nodes (bb); phi; phi = PHI_CHAIN (phi))
{
int i;