return unr_insns;
}
-/* Tries to unroll LOOP completely, i.e. NITER times. LOOPS is the
- loop tree. UL determines which loops we are allowed to unroll.
+/* Tries to unroll LOOP completely, i.e. NITER times.
+ UL determines which loops we are allowed to unroll.
EXIT is the exit of the loop that should be eliminated. */
static bool
-try_unroll_loop_completely (struct loops *loops ATTRIBUTE_UNUSED,
- struct loop *loop,
+try_unroll_loop_completely (struct loop *loop,
edge exit, tree niter,
enum unroll_level ul)
{
RESET_BIT (wont_exit, 0);
if (!tree_duplicate_loop_to_header_edge (loop, loop_preheader_edge (loop),
- loops, n_unroll, wont_exit,
+ n_unroll, wont_exit,
exit, edges_to_remove,
&n_to_remove,
DLTHE_FLAG_UPDATE_FREQ
return true;
}
-/* Adds a canonical induction variable to LOOP if suitable. LOOPS is the loops
- tree. CREATE_IV is true if we may create a new iv. UL determines
+/* Adds a canonical induction variable to LOOP if suitable.
+ CREATE_IV is true if we may create a new iv. UL determines
which loops we are allowed to completely unroll. If TRY_EVAL is true, we try
to determine the number of iterations of a loop by direct evaluation.
Returns true if cfg is changed. */
static bool
-canonicalize_loop_induction_variables (struct loops *loops, struct loop *loop,
+canonicalize_loop_induction_variables (struct loop *loop,
bool create_iv, enum unroll_level ul,
bool try_eval)
{
edge exit = NULL;
tree niter;
- niter = number_of_iterations_in_loop (loop);
+ niter = number_of_latch_executions (loop);
if (TREE_CODE (niter) == INTEGER_CST)
{
- exit = loop->single_exit;
+ exit = single_exit (loop);
if (!just_once_each_iteration_p (loop, exit->src))
return false;
-
- /* The result of number_of_iterations_in_loop is by one higher than
- we expect (i.e. it returns number of executions of the exit
- condition, not of the loop latch edge). */
- niter = fold_build2 (MINUS_EXPR, TREE_TYPE (niter), niter,
- build_int_cst (TREE_TYPE (niter), 1));
}
else
{
/* If the loop has more than one exit, try checking all of them
for # of iterations determinable through scev. */
- if (!loop->single_exit)
+ if (!single_exit (loop))
niter = find_loop_niter (loop, &exit);
/* Finally if everything else fails, try brute force evaluation. */
fprintf (dump_file, " times.\n");
}
- if (try_unroll_loop_completely (loops, loop, exit, niter, ul))
+ if (try_unroll_loop_completely (loop, exit, niter, ul))
return true;
if (create_iv)
}
/* The main entry point of the pass. Adds canonical induction variables
- to the suitable LOOPS. */
+ to the suitable loops. */
-void
-canonicalize_induction_variables (struct loops *loops)
+unsigned int
+canonicalize_induction_variables (void)
{
- unsigned i;
+ loop_iterator li;
struct loop *loop;
bool changed = false;
- for (i = 1; i < loops->num; i++)
+ FOR_EACH_LOOP (li, loop, 0)
{
- loop = loops->parray[i];
-
- if (loop)
- changed |= canonicalize_loop_induction_variables (loops, loop,
- true, UL_SINGLE_ITER,
- true);
+ changed |= canonicalize_loop_induction_variables (loop,
+ true, UL_SINGLE_ITER,
+ true);
}
/* Clean up the information about numbers of iterations, since brute force
scev_reset ();
if (changed)
- cleanup_tree_cfg_loop ();
+ return TODO_cleanup_cfg;
+ return 0;
}
/* Unroll LOOPS completely if they iterate just few times. Unless
MAY_INCREASE_SIZE is true, perform the unrolling only if the
size of the code does not increase. */
-void
-tree_unroll_loops_completely (struct loops *loops, bool may_increase_size)
+unsigned int
+tree_unroll_loops_completely (bool may_increase_size)
{
- unsigned i;
+ loop_iterator li;
struct loop *loop;
bool changed = false;
enum unroll_level ul;
- for (i = 1; i < loops->num; i++)
+ FOR_EACH_LOOP (li, loop, 0)
{
- loop = loops->parray[i];
-
- if (!loop)
- continue;
-
if (may_increase_size && maybe_hot_bb_p (loop->header))
ul = UL_ALL;
else
ul = UL_NO_GROWTH;
- changed |= canonicalize_loop_induction_variables (loops, loop,
+ changed |= canonicalize_loop_induction_variables (loop,
false, ul,
!flag_tree_loop_ivcanon);
}
scev_reset ();
if (changed)
- cleanup_tree_cfg_loop ();
+ return TODO_cleanup_cfg;
+ return 0;
}
/* Checks whether LOOP is empty. */
switch (TREE_CODE (stmt))
{
case RETURN_EXPR:
- case MODIFY_EXPR:
+ case GIMPLE_MODIFY_STMT:
stmt = get_call_expr_in (stmt);
if (!stmt)
break;
return true;
}
-/* Remove the empty LOOPS. */
+/* Remove the empty loops. */
-void
-remove_empty_loops (struct loops *loops)
+unsigned int
+remove_empty_loops (void)
{
bool changed = false;
struct loop *loop;
- for (loop = loops->tree_root->inner; loop; loop = loop->next)
+ for (loop = current_loops->tree_root->inner; loop; loop = loop->next)
try_remove_empty_loop (loop, &changed);
if (changed)
{
scev_reset ();
- cleanup_tree_cfg_loop ();
+ return TODO_cleanup_cfg;
}
+ return 0;
}