Commit 08dab97a by Razya Ladelsky Committed by Razya Ladelsky

ssa-loop-manip.c: Include langhooks.h.

2009-07-30  Razya Ladelsky <razya@il.ibm.com>

        * ssa-loop-manip.c: Include langhooks.h.
        (rewrite_phi_with_iv): New.
        (rewrite_all_phi_nodes_with_iv): New.
        (canonicalize_loop_ivs): Move here from tree-parloops.c.
        Remove reduction_list argument. Use rewrite_all_phi_nodes_with_iv.
        * tree-parloops.c (loop_parallel_p): Move out all conditions
        except dependency check.
        (canonicalize_loop_ivs): Move to tree-ssa-loop-manip.c.
        (gen_parallel_loop): Call canonicalize_loop_ivs without
        reduction_list argument.
        (build_new_reduction): New.
        (gather_scalar_reductions): New.
        (try_get_loop_niter): New.
        (try_create_reduction_list): New.
        (parallleize_loops): Change the parallel conditions check.
        * tree-flow.h (canonicalize_loop_ivs): Remove one argument.
        * Makefile.in (tree-ssa-loop-manip.o): Add langhooks.h dependency.

From-SVN: r150250
parent 88c2fd3d
2009-07-30 Razya Ladelsky <razya@il.ibm.com>
* ssa-loop-manip.c: Include langhooks.h.
(rewrite_phi_with_iv): New.
(rewrite_all_phi_nodes_with_iv): New.
(canonicalize_loop_ivs): Move here from tree-parloops.c.
Remove reduction_list argument. Use rewrite_all_phi_nodes_with_iv.
* tree-parloops.c (loop_parallel_p): Move out all conditions
except dependency check.
(canonicalize_loop_ivs): Move to tree-ssa-loop-manip.c.
(gen_parallel_loop): Call canonicalize_loop_ivs without
reduction_list argument.
(build_new_reduction): New.
(gather_scalar_reductions): New.
(try_get_loop_niter): New.
(try_create_reduction_list): New.
(parallleize_loops): Change the parallel conditions check.
* tree-flow.h (canonicalize_loop_ivs): Remove one argument.
* Makefile.in (tree-ssa-loop-manip.o): Add langhooks.h dependency.
2009-07-30 Dave Korn <dave.korn.cygwin@gmail.com>
* opt-functions.awk (opt_args): Allow argument to be enclosed in
......
......@@ -2356,7 +2356,7 @@ tree-ssa-loop-manip.o : tree-ssa-loop-manip.c $(TREE_FLOW_H) $(CONFIG_H) \
$(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) $(RTL_H) $(TM_P_H) hard-reg-set.h \
$(BASIC_BLOCK_H) output.h $(DIAGNOSTIC_H) $(TREE_FLOW_H) $(TREE_DUMP_H) \
$(TIMEVAR_H) $(CFGLOOP_H) $(TREE_PASS_H) $(CFGLAYOUT_H) \
$(SCEV_H) $(PARAMS_H) $(TREE_INLINE_H)
$(SCEV_H) $(PARAMS_H) $(TREE_INLINE_H) langhooks.h
tree-ssa-loop-im.o : tree-ssa-loop-im.c $(TREE_FLOW_H) $(CONFIG_H) \
$(SYSTEM_H) $(RTL_H) $(TREE_H) $(TM_P_H) $(CFGLOOP_H) domwalk.h \
$(PARAMS_H) output.h $(DIAGNOSTIC_H) $(TIMEVAR_H) $(TM_H) coretypes.h \
......
......@@ -746,7 +746,7 @@ unsigned int tree_unroll_loops_completely (bool, bool);
unsigned int tree_ssa_prefetch_arrays (void);
void tree_ssa_iv_optimize (void);
unsigned tree_predictive_commoning (void);
tree canonicalize_loop_ivs (struct loop *, htab_t, tree *);
tree canonicalize_loop_ivs (struct loop *, tree *);
bool parallelize_loops (void);
bool loop_only_exit_p (const struct loop *, const_edge);
......
......@@ -37,6 +37,7 @@ along with GCC; see the file COPYING3. If not see
#include "tree-scalar-evolution.h"
#include "params.h"
#include "tree-inline.h"
#include "langhooks.h"
/* Creates an induction variable with value BASE + STEP * iteration in LOOP.
It is expected that neither BASE nor STEP are shared with other expressions
......@@ -1100,3 +1101,132 @@ tree_unroll_loop (struct loop *loop, unsigned factor,
tree_transform_and_unroll_loop (loop, factor, exit, desc,
NULL, NULL);
}
/* Rewrite the phi node at position PSI in function of the main
induction variable MAIN_IV and insert the generated code at GSI. */
static void
rewrite_phi_with_iv (loop_p loop,
gimple_stmt_iterator *psi,
gimple_stmt_iterator *gsi,
tree main_iv)
{
affine_iv iv;
gimple stmt, phi = gsi_stmt (*psi);
tree atype, mtype, val, res = PHI_RESULT (phi);
if (!is_gimple_reg (res) || res == main_iv)
{
gsi_next (psi);
return;
}
if (!simple_iv (loop, loop, res, &iv, true))
{
gsi_next (psi);
return;
}
remove_phi_node (psi, false);
atype = TREE_TYPE (res);
mtype = POINTER_TYPE_P (atype) ? sizetype : atype;
val = fold_build2 (MULT_EXPR, mtype, unshare_expr (iv.step),
fold_convert (mtype, main_iv));
val = fold_build2 (POINTER_TYPE_P (atype)
? POINTER_PLUS_EXPR : PLUS_EXPR,
atype, unshare_expr (iv.base), val);
val = force_gimple_operand_gsi (gsi, val, false, NULL_TREE, true,
GSI_SAME_STMT);
stmt = gimple_build_assign (res, val);
gsi_insert_before (gsi, stmt, GSI_SAME_STMT);
SSA_NAME_DEF_STMT (res) = stmt;
}
/* Rewrite all the phi nodes of LOOP in function of the main induction
variable MAIN_IV. */
static void
rewrite_all_phi_nodes_with_iv (loop_p loop, tree main_iv)
{
unsigned i;
basic_block *bbs = get_loop_body_in_dom_order (loop);
gimple_stmt_iterator psi;
for (i = 0; i < loop->num_nodes; i++)
{
basic_block bb = bbs[i];
gimple_stmt_iterator gsi = gsi_after_labels (bb);
if (bb->loop_father != loop)
continue;
for (psi = gsi_start_phis (bb); !gsi_end_p (psi); )
rewrite_phi_with_iv (loop, &psi, &gsi, main_iv);
}
free (bbs);
}
/* Bases all the induction variables in LOOP on a single induction
variable (unsigned with base 0 and step 1), whose final value is
compared with *NIT. When the IV type precision has to be larger
than *NIT type precision, *NIT is converted to the larger type, the
conversion code is inserted before the loop, and *NIT is updated to
the new definition. The induction variable is incremented in the
loop latch. Return the induction variable that was created. */
tree
canonicalize_loop_ivs (struct loop *loop, tree *nit)
{
unsigned precision = TYPE_PRECISION (TREE_TYPE (*nit));
unsigned original_precision = precision;
tree type, var_before;
gimple_stmt_iterator gsi, psi;
gimple stmt;
edge exit = single_dom_exit (loop);
gimple_seq stmts;
for (psi = gsi_start_phis (loop->header);
!gsi_end_p (psi); gsi_next (&psi))
{
gimple phi = gsi_stmt (psi);
tree res = PHI_RESULT (phi);
if (is_gimple_reg (res) && TYPE_PRECISION (TREE_TYPE (res)) > precision)
precision = TYPE_PRECISION (TREE_TYPE (res));
}
type = lang_hooks.types.type_for_size (precision, 1);
if (original_precision != precision)
{
*nit = fold_convert (type, *nit);
*nit = force_gimple_operand (*nit, &stmts, true, NULL_TREE);
if (stmts)
gsi_insert_seq_on_edge_immediate (loop_preheader_edge (loop), stmts);
}
gsi = gsi_last_bb (loop->latch);
create_iv (build_int_cst_type (type, 0), build_int_cst (type, 1), NULL_TREE,
loop, &gsi, true, &var_before, NULL);
rewrite_all_phi_nodes_with_iv (loop, var_before);
stmt = last_stmt (exit->src);
/* Make the loop exit if the control condition is not satisfied. */
if (exit->flags & EDGE_TRUE_VALUE)
{
edge te, fe;
extract_true_false_edges_from_block (exit->src, &te, &fe);
te->flags = EDGE_FALSE_VALUE;
fe->flags = EDGE_TRUE_VALUE;
}
gimple_cond_set_code (stmt, LT_EXPR);
gimple_cond_set_lhs (stmt, var_before);
gimple_cond_set_rhs (stmt, *nit);
update_stmt (stmt);
return var_before;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment