This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Take 2: Avoid dumping unused variables.


On Wed, 4 Jan 2006, Diego Novillo wrote:

> On Wednesday 04 January 2006 09:42, Richard Guenther wrote:
> 
> > And here is the patch currently in bootstrapping and regtesting.  Ok
> > for mainline if it succeeds and I didn't happen to miss some var-dumps
> > scanning?
> >
> Sure.  Thanks.

Hmhm, of course it didn't test succesfully.  I fixed it by ignoring
FUNCTION_DECLs (var_ann otherwise asserts) and moving 
TODO_remove_unused_locals to todo_flags_finish in pass_del_ssa.  Other
than that, gcc.dg/tree-ssa/20031106-6.c needs SRA disabled to test
what it is supposed to test.

Bootstrapped and regtested on x86_64-unknown-linux-gnu.  Will apply
to mainline in 24 hours as approved if you don't object.

Richard.


2006-01-04  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.

Index: tree-into-ssa.c
===================================================================
*** tree-into-ssa.c	(revision 109322)
--- tree-into-ssa.c	(working copy)
*************** struct tree_opt_pass pass_build_ssa = 
*** 1791,1797 ****
    PROP_ssa,				/* properties_provided */
    0,					/* properties_destroyed */
    0,					/* todo_flags_start */
!   TODO_dump_func | TODO_verify_ssa,	/* todo_flags_finish */
    0					/* letter */
  };
  
--- 1791,1799 ----
    PROP_ssa,				/* properties_provided */
    0,					/* properties_destroyed */
    0,					/* todo_flags_start */
!   TODO_dump_func
!     | TODO_verify_ssa
!     | TODO_remove_unused_locals,	/* todo_flags_finish */
    0					/* letter */
  };
  
Index: tree-pass.h
===================================================================
*** tree-pass.h	(revision 109322)
--- tree-pass.h	(working copy)
*************** struct dump_file_info
*** 200,205 ****
--- 200,210 ----
     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		\
*************** extern struct tree_opt_pass pass_forwpro
*** 267,273 ****
  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;
--- 272,277 ----
Index: testsuite/gcc.dg/tree-ssa/loop-11.c
===================================================================
*** testsuite/gcc.dg/tree-ssa/loop-11.c	(revision 109322)
--- testsuite/gcc.dg/tree-ssa/loop-11.c	(working copy)
***************
*** 2,8 ****
     see PR 22442.  */
  
  /* { dg-do compile } */
! /* { dg-options "-O1 -fdump-tree-vars" } */
  
  void bar (unsigned);
  
--- 2,8 ----
     see PR 22442.  */
  
  /* { dg-do compile } */
! /* { dg-options "-O1 -fdump-tree-optimized" } */
  
  void bar (unsigned);
  
*************** void foo (void)
*** 18,28 ****
  
  /* Final value of a gets replaced.  */
  
! /* { dg-final { scan-tree-dump-times "\\(16\\)" 1 "vars" } } */
  
  /* And the empty loop is removed.  */
  
! /* { dg-final { scan-tree-dump-times "if " 0 "vars" } } */
  
! /* { dg-final { cleanup-tree-dump "vars" } } */
  
--- 18,28 ----
  
  /* Final value of a gets replaced.  */
  
! /* { dg-final { scan-tree-dump-times "\\(16\\)" 1 "optimized" } } */
  
  /* And the empty loop is removed.  */
  
! /* { dg-final { scan-tree-dump-times "if " 0 "optimized" } } */
  
! /* { dg-final { cleanup-tree-dump "optimized" } } */
  
Index: testsuite/gcc.dg/tree-ssa/loop-8.c
===================================================================
*** testsuite/gcc.dg/tree-ssa/loop-8.c	(revision 109322)
--- testsuite/gcc.dg/tree-ssa/loop-8.c	(working copy)
***************
*** 1,7 ****
  /* A test for strength reduction of ivs with nonconstant step.  */
  
  /* { dg-do compile } */
! /* { dg-options "-O1 -fdump-tree-vars" } */
  
  int bar (void);
  
--- 1,7 ----
  /* A test for strength reduction of ivs with nonconstant step.  */
  
  /* { dg-do compile } */
! /* { dg-options "-O1 -fdump-tree-optimized" } */
  
  int bar (void);
  
*************** void xxx (void)
*** 19,25 ****
     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 { cleanup-tree-dump "vars" } } */
--- 19,25 ----
     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 "optimized" } } */
! /* { dg-final { scan-tree-dump-times "\[^0-9\] \\* step" 0 "optimized" } } */
  
! /* { dg-final { cleanup-tree-dump "optimized" } } */
Index: testsuite/gcc.dg/tree-ssa/loop-1.c
===================================================================
*** testsuite/gcc.dg/tree-ssa/loop-1.c	(revision 109322)
--- testsuite/gcc.dg/tree-ssa/loop-1.c	(working copy)
***************
*** 1,15 ****
  /* { dg-do compile } */
! /* { dg-options "-O1 -ftree-loop-ivcanon -funroll-loops -fdump-tree-ivcanon-details -fdump-tree-cunroll-details -fdump-tree-vars" } */
  
  /* 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-*-* } } */
  
  /* 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* } } */
  
  void xxx(void)
  {
--- 1,15 ----
  /* { dg-do compile } */
! /* { 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-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-optimized -static" { target *-*-darwin* } } */
  
  void xxx(void)
  {
*************** void xxx(void)
*** 25,32 ****
  /* { 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" } } */
  
  /* 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
--- 25,32 ----
  /* { 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 "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
Index: testsuite/gcc.dg/tree-ssa/pr23294.c
===================================================================
*** testsuite/gcc.dg/tree-ssa/pr23294.c	(revision 109322)
--- testsuite/gcc.dg/tree-ssa/pr23294.c	(working copy)
***************
*** 1,5 ****
  /* { dg-do compile } */
! /* { dg-options "-O -fdump-tree-vars" } */
  
  int f1(int a)
  {
--- 1,5 ----
  /* { dg-do compile } */
! /* { dg-options "-O -fdump-tree-optimized" } */
  
  int f1(int a)
  {
*************** int f6(int a, int b)
*** 31,38 ****
    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" } } */
--- 31,38 ----
    return 6*a - 2*b;
  }
  
! /* { 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" } } */
Index: testsuite/gcc.dg/tree-ssa/pr21985.c
===================================================================
*** testsuite/gcc.dg/tree-ssa/pr21985.c	(revision 109322)
--- testsuite/gcc.dg/tree-ssa/pr21985.c	(working copy)
***************
*** 1,5 ****
  /* { dg-do compile } */
! /* { dg-options "-O1 -fdump-tree-vars" } */
  
  struct
  {
--- 1,5 ----
  /* { dg-do compile } */
! /* { dg-options "-O1 -fdump-tree-optimized" } */
  
  struct
  {
*************** main (void)
*** 30,34 ****
  
  /* 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" } } */
--- 30,34 ----
  
  /* Two of the calls to foo should be folded to just foo(constant).  */
  
! /* { dg-final { scan-tree-dump-times "foo \\(\[0-9\]*\\)" 2 "optimized" } } */
! /* { dg-final { cleanup-tree-dump "optimized" } } */
Index: testsuite/gcc.dg/tree-ssa/loop-14.c
===================================================================
*** testsuite/gcc.dg/tree-ssa/loop-14.c	(revision 109322)
--- testsuite/gcc.dg/tree-ssa/loop-14.c	(working copy)
***************
*** 1,6 ****
  /* A test for final value replacement.  */
  
! /* { dg-options "-O2 -fdump-tree-vars" } */
  
  int foo(void);
  
--- 1,6 ----
  /* A test for final value replacement.  */
  
! /* { dg-options "-O2 -fdump-tree-optimized" } */
  
  int foo(void);
  
*************** int bla(void)
*** 15,19 ****
    return j;
  }
  
! /* { dg-final { scan-tree-dump-times "\\+ 100" 1 "vars" } } */
! /* { dg-final { cleanup-tree-dump "vars" } } */
--- 15,19 ----
    return j;
  }
  
! /* { dg-final { scan-tree-dump-times "\\+ 100" 1 "optimized" } } */
! /* { dg-final { cleanup-tree-dump "optimized" } } */
Index: testsuite/gcc.dg/tree-ssa/loop-2.c
===================================================================
*** testsuite/gcc.dg/tree-ssa/loop-2.c	(revision 109322)
--- testsuite/gcc.dg/tree-ssa/loop-2.c	(working copy)
***************
*** 1,7 ****
  /* A test for strength reduction and induction variable elimination.  */
  
  /* { dg-do compile } */
! /* { dg-options "-O1 -fdump-tree-vars" } */
  
  /* Size of this structure should be sufficiently weird so that no memory
     addressing mode applies.  */
--- 1,7 ----
  /* A test for strength reduction and induction variable elimination.  */
  
  /* { dg-do compile } */
! /* { dg-options "-O1 -fdump-tree-optimized" } */
  
  /* Size of this structure should be sufficiently weird so that no memory
     addressing mode applies.  */
*************** void xxx(void)
*** 24,43 ****
  /* 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" } } */
  
  /* 17 * iter should be strength reduced.  */
  
! /* { dg-final { scan-tree-dump-times " \\* 17" 0 "vars" } } */
! /* { dg-final { scan-tree-dump-times " \\+ 17" 1 "vars" } } */
  
  /* 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 { cleanup-tree-dump "vars" } } */
--- 24,43 ----
  /* 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 "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 "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 "optimized" } } */
! /* { dg-final { scan-tree-dump-times "99" 0 "optimized" } } */
! /* { dg-final { scan-tree-dump-times "100" 0 "optimized" } } */
  
! /* { dg-final { cleanup-tree-dump "optimized" } } */
Index: testsuite/gcc.dg/tree-ssa/loop-3.c
===================================================================
*** testsuite/gcc.dg/tree-ssa/loop-3.c	(revision 109322)
--- testsuite/gcc.dg/tree-ssa/loop-3.c	(working copy)
***************
*** 3,9 ****
     assume something about memory addressing modes.  */
  
  /* { dg-do compile { target i?86-*-* x86_64-*-* } } */
! /* { dg-options "-O1 -fdump-tree-vars" } */
  
  int arr_base[100];
  
--- 3,9 ----
     assume something about memory addressing modes.  */
  
  /* { dg-do compile { target i?86-*-* x86_64-*-* } } */
! /* { dg-options "-O1 -fdump-tree-optimized" } */
  
  int arr_base[100];
  
*************** void xxx(void)
*** 20,30 ****
  /* 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" } } */
  
  /* And original induction variable should be preserved.  */
  
! /* { dg-final { scan-tree-dump-times "int iter" 1 "vars" } } */
  
! /* { dg-final { cleanup-tree-dump "vars" } } */
--- 20,30 ----
  /* 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 "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 "optimized" } } */
  
! /* { dg-final { cleanup-tree-dump "optimized" } } */
Index: testsuite/gcc.dg/tree-ssa/loop-4.c
===================================================================
*** testsuite/gcc.dg/tree-ssa/loop-4.c	(revision 109322)
--- testsuite/gcc.dg/tree-ssa/loop-4.c	(working copy)
***************
*** 1,7 ****
  /* A test for strength reduction and induction variable elimination.  */
  
  /* { dg-do compile } */
! /* { dg-options "-O1 -fdump-tree-vars" } */
  
  /* Size of this structure should be sufficiently weird so that no memory
     addressing mode applies.  */
--- 1,7 ----
  /* A test for strength reduction and induction variable elimination.  */
  
  /* { dg-do compile } */
! /* { dg-options "-O1 -fdump-tree-optimized" } */
  
  /* Size of this structure should be sufficiently weird so that no memory
     addressing mode applies.  */
*************** void xxx(void)
*** 34,45 ****
  
     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" } } */
  
  /* And the original induction variable should be eliminated.  */
  
! /* { dg-final { scan-tree-dump-times "iter" 0 "vars" } } */
  
! /* { dg-final { cleanup-tree-dump "vars" } } */
--- 34,45 ----
  
     In any case, we should not have any multiplication.  */
  
! /* { 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 "optimized" } } */
  
! /* { dg-final { cleanup-tree-dump "optimized" } } */
Index: testsuite/gcc.dg/tree-ssa/pr21171.c
===================================================================
*** testsuite/gcc.dg/tree-ssa/pr21171.c	(revision 109322)
--- testsuite/gcc.dg/tree-ssa/pr21171.c	(working copy)
***************
*** 1,6 ****
  /* PR 21171.  Ivopts should not rewrite references to volatile memory.  */
  /* { dg-do compile } */
! /* { dg-options "-O1 -fdump-tree-vars" } */
  
  typedef	unsigned int u_int32_t;
  typedef	unsigned char u_int8_t;
--- 1,6 ----
  /* PR 21171.  Ivopts should not rewrite references to volatile memory.  */
  /* { dg-do compile } */
! /* { dg-options "-O1 -fdump-tree-optimized" } */
  
  typedef	unsigned int u_int32_t;
  typedef	unsigned char u_int8_t;
*************** int main()
*** 25,29 ****
    return 0;
  }
  
! /* { dg-final { scan-tree-dump-times "SVR" 1 "vars"} } */
! /* { dg-final { cleanup-tree-dump "vars" } } */
--- 25,29 ----
    return 0;
  }
  
! /* { dg-final { scan-tree-dump-times "SVR" 1 "optimized"} } */
! /* { dg-final { cleanup-tree-dump "optimized" } } */
Index: testsuite/gcc.dg/tree-ssa/loop-5.c
===================================================================
*** testsuite/gcc.dg/tree-ssa/loop-5.c	(revision 109322)
--- testsuite/gcc.dg/tree-ssa/loop-5.c	(working copy)
***************
*** 1,7 ****
  /* A test for induction variable merging.  */
  
  /* { dg-do compile } */
! /* { dg-options "-O1 -fdump-tree-vars" } */
  
  void foo(long);
  
--- 1,7 ----
  /* A test for induction variable merging.  */
  
  /* { dg-do compile } */
! /* { dg-options "-O1 -fdump-tree-optimized" } */
  
  void foo(long);
  
*************** void xxx(void)
*** 18,28 ****
  
  /* Only iter variable should remain.  */
  
! /* { dg-final { scan-tree-dump-times "int iter" 1 "vars" } } */
! /* { dg-final { scan-tree-dump-times "jter" 0 "vars" } } */
  
  /* And the use of jter should be replaced by iter + 2 */
  
! /* { dg-final { scan-tree-dump-times " \\+ 2" 1 "vars" } } */
  
! /* { dg-final { cleanup-tree-dump "vars" } } */
--- 18,28 ----
  
  /* Only iter variable should remain.  */
  
! /* { 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 "optimized" } } */
  
! /* { dg-final { cleanup-tree-dump "optimized" } } */
Index: testsuite/gcc.dg/tree-ssa/loop-10.c
===================================================================
*** testsuite/gcc.dg/tree-ssa/loop-10.c	(revision 109322)
--- testsuite/gcc.dg/tree-ssa/loop-10.c	(working copy)
***************
*** 1,5 ****
  /* { dg-do compile } */
! /* { dg-options "-O1 -fdump-tree-vars" } */
  
  int bar (void);
  
--- 1,5 ----
  /* { dg-do compile } */
! /* { dg-options "-O1 -fdump-tree-optimized" } */
  
  int bar (void);
  
*************** void foo (void)
*** 26,32 ****
      ;
  }
  
! /* { dg-final { scan-tree-dump-times "if " 3 "vars" } } */
! /* { dg-final { scan-tree-dump-times "bar " 2 "vars" } } */
  
! /* { dg-final { cleanup-tree-dump "vars" } } */
--- 26,32 ----
      ;
  }
  
! /* { dg-final { scan-tree-dump-times "if " 3 "optimized" } } */
! /* { dg-final { scan-tree-dump-times "bar " 2 "optimized" } } */
  
! /* { dg-final { cleanup-tree-dump "optimized" } } */
Index: testsuite/gcc.dg/tree-ssa/loop-6.c
===================================================================
*** testsuite/gcc.dg/tree-ssa/loop-6.c	(revision 109322)
--- testsuite/gcc.dg/tree-ssa/loop-6.c	(working copy)
***************
*** 1,5 ****
  /* { dg-do compile } */
! /* { dg-options "-O1 -funswitch-loops -fdump-tree-unswitch-details -fdump-tree-vars" } */
  
  int ch;
  int a[100];
--- 1,5 ----
  /* { dg-do compile } */
! /* { dg-options "-O1 -funswitch-loops -fdump-tree-unswitch-details -fdump-tree-optimized" } */
  
  int ch;
  int a[100];
*************** void xxx(void)
*** 24,28 ****
  
  /* 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" } } */
--- 24,28 ----
  
  /* In effect there should be exactly three conditional jumps in the final program.  */
  
! /* { dg-final { scan-tree-dump-times "else" 3 "optimized" } } */
! /* { dg-final { cleanup-tree-dump "optimized" } } */
Index: testsuite/treelang/compile/extravar.tree
===================================================================
*** testsuite/treelang/compile/extravar.tree	(revision 109322)
--- testsuite/treelang/compile/extravar.tree	(working copy)
***************
*** 1,5 ****
  // { dg-do compile }
! // { dg-options "-fdump-tree-vars -O1 -Wunused-variable" }
  external_definition int bar (int aaa, int ddd);
  
  static int foo = -3;  // { dg-warning "defined but not used" }
--- 1,5 ----
  // { dg-do compile }
! // { 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" }
*************** bar
*** 10,14 ****
  
  	return aaa + ddd + +3;
  }
! // { dg-final { scan-tree-dump-not "ccc" "vars" } }
! // { dg-final { cleanup-tree-dump "vars" } }
--- 10,14 ----
  
  	return aaa + ddd + +3;
  }
! // { dg-final { scan-tree-dump-not "ccc" "optimized" } }
! // { dg-final { cleanup-tree-dump "optimized" } }
Index: testsuite/g++.dg/tree-ssa/ssa-cast-1.C
===================================================================
*** testsuite/g++.dg/tree-ssa/ssa-cast-1.C	(revision 109322)
--- testsuite/g++.dg/tree-ssa/ssa-cast-1.C	(working copy)
***************
*** 1,5 ****
  /* { dg-do compile } */
! /* { dg-options "-O1 -fdump-tree-vars" } */
  
  int &f(int *a)
  {
--- 1,5 ----
  /* { dg-do compile } */
! /* { dg-options "-O1 -fdump-tree-optimized" } */
  
  int &f(int *a)
  {
*************** int &f(int *a)
*** 8,12 ****
  
  /* 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" } } */
--- 8,12 ----
  
  /* There should be no cast as pointer and references are
     considered the same type. */
! /* { dg-final { scan-tree-dump-times "\\(int &\\)" 0 "optimized"} } */
! /* { dg-final { cleanup-tree-dump "optimized" } } */
Index: testsuite/g++.dg/tree-ssa/pointer-reference-alias.C
===================================================================
*** testsuite/g++.dg/tree-ssa/pointer-reference-alias.C	(revision 109322)
--- testsuite/g++.dg/tree-ssa/pointer-reference-alias.C	(working copy)
***************
*** 1,5 ****
  /* { dg-do compile } */
! /* { dg-options "-O1 -fdump-tree-vars" } */
  
  int f(int *a)
  {
--- 1,5 ----
  /* { dg-do compile } */
! /* { dg-options "-O1 -fdump-tree-optimized" } */
  
  int f(int *a)
  {
*************** int f(int *a)
*** 9,13 ****
  }
  
  /* There should be only one dereferencing of a. */
! /* { dg-final { scan-tree-dump-times "\\*a" 1 "vars" } } */
! /* { dg-final { cleanup-tree-dump "vars" } } */
--- 9,13 ----
  }
  
  /* There should be only one dereferencing of a. */
! /* { dg-final { scan-tree-dump-times "\\*a" 1 "optimized" } } */
! /* { dg-final { cleanup-tree-dump "optimized" } } */
Index: testsuite/g++.dg/tree-ssa/ssa-sra-1.C
===================================================================
*** testsuite/g++.dg/tree-ssa/ssa-sra-1.C	(revision 109322)
--- testsuite/g++.dg/tree-ssa/ssa-sra-1.C	(working copy)
***************
*** 1,5 ****
  /* { dg-do compile } */
! /* { dg-options "-O1 -fdump-tree-vars-details" } */
  
  void link_error();
  
--- 1,5 ----
  /* { dg-do compile } */
! /* { dg-options "-O1 -fdump-tree-optimized" } */
  
  void link_error();
  
*************** void temp()
*** 57,61 ****
  
  /* 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" } } */
--- 57,61 ----
  
  /* We should have removed the casts from pointers to references and caused SRA to happen.  */
  
! /* { dg-final { scan-tree-dump-times "link_error" 0 "optimized"} } */
! /* { dg-final { cleanup-tree-dump "optimized" } } */
Index: testsuite/g++.dg/tree-ssa/ssa-sra-2.C
===================================================================
*** testsuite/g++.dg/tree-ssa/ssa-sra-2.C	(revision 109322)
--- testsuite/g++.dg/tree-ssa/ssa-sra-2.C	(working copy)
***************
*** 1,5 ****
  /* { dg-do compile } */
! /* { dg-options "-O1 -fdump-tree-vars-details" } */
  
  void link_error();
  
--- 1,5 ----
  /* { dg-do compile } */
! /* { dg-options "-O1 -fdump-tree-optimized" } */
  
  void link_error();
  
*************** void test()
*** 48,52 ****
  }
  
  /* 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" } } */
--- 48,52 ----
  }
  
  /* We should have removed the casts from pointers to references and caused SRA to happen.  */
! /* { dg-final { scan-tree-dump-times "link_error" 0 "optimized"} } */
! /* { dg-final { cleanup-tree-dump "optimized" } } */
Index: gimple-low.c
===================================================================
*** gimple-low.c	(revision 109322)
--- gimple-low.c	(working copy)
*************** static void lower_stmt (tree_stmt_iterat
*** 55,61 ****
  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.  */
  
--- 55,60 ----
*************** record_vars (tree vars)
*** 533,614 ****
      }
  }
  
- /* 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.  */
--- 532,537 ----
Index: tree-ssa-dce.c
===================================================================
*** tree-ssa-dce.c	(revision 109322)
--- tree-ssa-dce.c	(working copy)
*************** struct tree_opt_pass pass_dce =
*** 979,985 ****
      | TODO_update_ssa
      | TODO_cleanup_cfg
      | TODO_ggc_collect
!     | TODO_verify_ssa,			/* todo_flags_finish */
    0					/* letter */
  };
  
--- 979,986 ----
      | TODO_update_ssa
      | TODO_cleanup_cfg
      | TODO_ggc_collect
!     | TODO_verify_ssa
!     | TODO_remove_unused_locals,	/* todo_flags_finish */
    0					/* letter */
  };
  
Index: tree-flow.h
===================================================================
*** tree-flow.h	(revision 109322)
--- tree-flow.h	(working copy)
*************** tree force_gimple_operand_bsi (block_stm
*** 815,820 ****
--- 815,823 ----
  /* 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
Index: passes.c
===================================================================
*** passes.c	(revision 109322)
--- passes.c	(working copy)
*************** init_optimization_passes (void)
*** 586,592 ****
    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;
--- 586,591 ----
*************** init_optimization_passes (void)
*** 702,708 ****
  }
  
  static unsigned int last_verified;
- 
  static void
  execute_todo (struct tree_opt_pass *pass, unsigned int flags, bool use_required)
  {
--- 701,706 ----
*************** execute_todo (struct tree_opt_pass *pass
*** 738,743 ****
--- 736,744 ----
        update_ssa (update_flags);
      }
  
+   if (flags & TODO_remove_unused_locals)
+     remove_unused_locals ();
+ 
    if ((flags & TODO_dump_func)
        && dump_file && current_function_decl)
      {
Index: testsuite/gcc.dg/tree-ssa/20031106-6.c
===================================================================
*** testsuite/gcc.dg/tree-ssa/20031106-6.c	(revision 109322)
--- testsuite/gcc.dg/tree-ssa/20031106-6.c	(working copy)
***************
*** 1,5 ****
  /* { dg-do compile } */ 
! /* { dg-options "-O1 -fdump-tree-optimized" } */
  
  extern void link_error (void);
  
--- 1,5 ----
  /* { dg-do compile } */ 
! /* { dg-options "-O1 -fno-tree-sra -fdump-tree-optimized" } */
  
  extern void link_error (void);
  
Index: tree-outof-ssa.c
===================================================================
*** tree-outof-ssa.c	(revision 109322)
--- tree-outof-ssa.c	(working copy)
*************** struct tree_opt_pass pass_del_ssa = 
*** 2556,2561 ****
    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 */
    0					/* letter */
  };
--- 2556,2563 ----
    PROP_ssa,				/* properties_destroyed */
    TODO_verify_ssa | TODO_verify_flow
      | TODO_verify_stmts,		/* todo_flags_start */
!   TODO_dump_func
!   | TODO_ggc_collect
!   | TODO_remove_unused_locals,		/* todo_flags_finish */
    0					/* letter */
  };
Index: tree-ssa-live.c
===================================================================
*** tree-ssa-live.c	(revision 109322)
--- tree-ssa-live.c	(working copy)
*************** mark_all_vars_used_1 (tree *tp, int *wal
*** 296,301 ****
--- 296,304 ----
  {
    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)
*************** mark_all_vars_used (tree *expr_p)
*** 327,332 ****
--- 330,401 ----
    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.  */
*************** create_ssa_var_map (int flags)
*** 362,367 ****
--- 431,437 ----
    FOR_EACH_BB (bb)
      {
        tree phi, arg;
+ 
        for (phi = phi_nodes (bb); phi; phi = PHI_CHAIN (phi))
  	{
  	  int i;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]