From: Zdenek Dvorak Date: Wed, 30 Jun 2004 21:29:00 +0000 (+0200) Subject: common.opt (ftree-loop-optimize): New flag. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c66b6c6689525b38af7cf9ea184fdef3d54d34f4;p=gcc.git common.opt (ftree-loop-optimize): New flag. * common.opt (ftree-loop-optimize): New flag. * tree-flow.h (kill_redundant_phi_nodes): Declare. * tree-optimize.c (init_tree_optimization_passes): Add pass_loop. * tree-pass.h (pass_loop_init, pass_loop_done): Declare. * tree-ssa-loop.c (current_loops): New variable. (tree_loop_optimizer_init, gate_loop, tree_ssa_loop_init, tree_ssa_loop_done): New functions. (pass_loop, pass_loop_init, pass_loop_done): New passes. * tree-ssa.c (kill_redundant_phi_nodes): Export. * doc/invoke.texi (-ftree-loop-optimize): Document. From-SVN: r83933 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 1cf4e55d1bd..8244666a5cb 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,16 @@ +2004-06-30 Zdenek Dvorak + + * common.opt (ftree-loop-optimize): New flag. + * tree-flow.h (kill_redundant_phi_nodes): Declare. + * tree-optimize.c (init_tree_optimization_passes): Add pass_loop. + * tree-pass.h (pass_loop_init, pass_loop_done): Declare. + * tree-ssa-loop.c (current_loops): New variable. + (tree_loop_optimizer_init, gate_loop, tree_ssa_loop_init, + tree_ssa_loop_done): New functions. + (pass_loop, pass_loop_init, pass_loop_done): New passes. + * tree-ssa.c (kill_redundant_phi_nodes): Export. + * doc/invoke.texi (-ftree-loop-optimize): Document. + 2004-06-30 Zdenek Dvorak * tree-ssa-loop-ch.c: New file. diff --git a/gcc/common.opt b/gcc/common.opt index 3cf0ec92ec3..1c75bc25050 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -777,6 +777,10 @@ ftree-fre Common Report Var(flag_tree_fre) Enable Full Redundancy Elimination (FRE) on trees +ftree-loop-optimize +Common Report Var(flag_tree_loop_optimize) Init(1) +Enable loop optimizations on tree level + ftree-points-to= Common Joined RejectNegative diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 510eda967ba..ede70f67a46 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -312,7 +312,7 @@ in the following sections. -fstrength-reduce -fstrict-aliasing -ftracer -fthread-jumps @gol -funroll-all-loops -funroll-loops -fpeel-loops @gol -funswitch-loops -fold-unroll-loops -fold-unroll-all-loops @gol --ftree-pre -ftree-ccp -ftree-dce @gol +-ftree-pre -ftree-ccp -ftree-dce -ftree-loop-optimize @gol -ftree-dominator-opts -ftree-dse -ftree-copyrename @gol -ftree-ch -ftree-sra -ftree-ter -ftree-lrs -ftree-fre @gol --param @var{name}=@var{value} @@ -4400,6 +4400,10 @@ effectivity of code motion optimizations. It also saves one jump. This flag is enabled by default at -O and higher. It is not enabled for -Os, since it usually increases code size. +@item -ftree-loop-optimize +Perform loop optimizations on trees. This flag is enabled by default at -O +and higher. + @item -ftree-sra Perform scalar replacement of aggregates. This pass replaces structure references with scalars to prevent committing structures to memory too diff --git a/gcc/tree-flow.h b/gcc/tree-flow.h index 8d8f58a9eeb..f0bfba4c153 100644 --- a/gcc/tree-flow.h +++ b/gcc/tree-flow.h @@ -573,6 +573,7 @@ extern void verify_ssa (void); extern void delete_tree_ssa (void); extern void register_new_def (tree, varray_type *); extern void walk_use_def_chains (tree, walk_use_def_chains_fn, void *); +extern void kill_redundant_phi_nodes (void); /* In tree-into-ssa.c */ extern void rewrite_into_ssa (bool); diff --git a/gcc/tree-optimize.c b/gcc/tree-optimize.c index 00ddc20827f..be663bb75fd 100644 --- a/gcc/tree-optimize.c +++ b/gcc/tree-optimize.c @@ -319,6 +319,7 @@ init_tree_optimization_passes (void) NEXT_PASS (pass_fold_builtins); NEXT_PASS (pass_split_crit_edges); NEXT_PASS (pass_pre); + NEXT_PASS (pass_loop); NEXT_PASS (DUP_PASS (pass_dominator)); NEXT_PASS (DUP_PASS (pass_redundant_phi)); NEXT_PASS (pass_cd_dce); @@ -333,6 +334,11 @@ init_tree_optimization_passes (void) NEXT_PASS (pass_remove_useless_vars); *p = NULL; + p = &pass_loop.sub; + NEXT_PASS (pass_loop_init); + NEXT_PASS (pass_loop_done); + *p = NULL; + #undef NEXT_PASS #undef DUP_PASS diff --git a/gcc/tree-pass.h b/gcc/tree-pass.h index 18c2197dbbc..276de395bd1 100644 --- a/gcc/tree-pass.h +++ b/gcc/tree-pass.h @@ -106,6 +106,8 @@ extern struct tree_opt_pass pass_sra; extern struct tree_opt_pass pass_tail_recursion; extern struct tree_opt_pass pass_tail_calls; extern struct tree_opt_pass pass_loop; +extern struct tree_opt_pass pass_loop_init; +extern struct tree_opt_pass pass_loop_done; extern struct tree_opt_pass pass_ch; extern struct tree_opt_pass pass_ccp; extern struct tree_opt_pass pass_build_ssa; diff --git a/gcc/tree-ssa-loop.c b/gcc/tree-ssa-loop.c index 4ceb2820b38..885954e5e85 100644 --- a/gcc/tree-ssa-loop.c +++ b/gcc/tree-ssa-loop.c @@ -38,4 +38,106 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include "flags.h" #include "tree-inline.h" +/* The loop tree currently optimized. */ + +struct loops *current_loops; + +/* Initializes the loop structures. DUMP is the file to that the details + about the analysis should be dumped. */ + +static struct loops * +tree_loop_optimizer_init (FILE *dump) +{ + struct loops *loops = loop_optimizer_init (dump); + + if (!loops) + return NULL; + + /* Creation of preheaders may create redundant phi nodes if the loop is + entered by more than one edge, but the initial value of the induction + variable is the same on all of them. */ + kill_redundant_phi_nodes (); + rewrite_into_ssa (false); + bitmap_clear (vars_to_rename); + + return loops; +} + +/* The loop superpass. */ + +static bool +gate_loop (void) +{ + return flag_tree_loop_optimize != 0; +} + +struct tree_opt_pass pass_loop = +{ + "loop", /* name */ + gate_loop, /* gate */ + NULL, /* execute */ + NULL, /* sub */ + NULL, /* next */ + 0, /* static_pass_number */ + TV_TREE_LOOP, /* tv_id */ + PROP_cfg, /* properties_required */ + 0, /* properties_provided */ + 0, /* properties_destroyed */ + TODO_ggc_collect, /* todo_flags_start */ + TODO_dump_func | TODO_verify_ssa | TODO_ggc_collect /* todo_flags_finish */ +}; + +/* Loop optimizer initialization. */ + +static void +tree_ssa_loop_init (void) +{ + current_loops = tree_loop_optimizer_init (dump_file); +} + +struct tree_opt_pass pass_loop_init = +{ + "loopinit", /* name */ + NULL, /* gate */ + tree_ssa_loop_init, /* execute */ + NULL, /* sub */ + NULL, /* next */ + 0, /* static_pass_number */ + 0, /* tv_id */ + PROP_cfg, /* properties_required */ + 0, /* properties_provided */ + 0, /* properties_destroyed */ + 0, /* todo_flags_start */ + 0 /* todo_flags_finish */ +}; + +/* Loop optimizer finalization. */ + +static void +tree_ssa_loop_done (void) +{ + if (!current_loops) + return; + + loop_optimizer_finalize (current_loops, + (dump_flags & TDF_DETAILS ? dump_file : NULL)); + current_loops = NULL; + cleanup_tree_cfg (); +} + +struct tree_opt_pass pass_loop_done = +{ + "loopdone", /* name */ + NULL, /* gate */ + tree_ssa_loop_done, /* execute */ + NULL, /* sub */ + NULL, /* next */ + 0, /* static_pass_number */ + 0, /* tv_id */ + PROP_cfg, /* properties_required */ + 0, /* properties_provided */ + 0, /* properties_destroyed */ + 0, /* todo_flags_start */ + 0 /* todo_flags_finish */ +}; diff --git a/gcc/tree-ssa.c b/gcc/tree-ssa.c index a931d9f7fef..37b83bfeca5 100644 --- a/gcc/tree-ssa.c +++ b/gcc/tree-ssa.c @@ -926,7 +926,7 @@ check_phi_redundancy (tree phi, tree *eq_to) The most important effect of this pass is to remove degenerate PHI nodes created by removing unreachable code. */ -static void +void kill_redundant_phi_nodes (void) { tree *eq_to;