diff options
author | spop <spop@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-08-11 20:29:43 +0000 |
---|---|---|
committer | spop <spop@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-08-11 20:29:43 +0000 |
commit | 5d21c24acbd3137fd519cc514627436f3bb8f6b2 (patch) | |
tree | 66fd9b46b2d3dfc6610aa0c8ce686f2899d5608f /gcc/graphite-sese-to-poly.c | |
parent | a865acd77108b14c971bd39ec85d0c19ad271b37 (diff) | |
download | gcc-5d21c24acbd3137fd519cc514627436f3bb8f6b2.tar.gz |
Propagate constant values or parametric expressions outside the scop region.
2010-07-22 Sebastian Pop <sebastian.pop@amd.com>
* graphite-sese-to-poly.c (propagate_expr_outside_region): New.
(rewrite_close_phi_out_of_ssa): Propagate constant values or
parametric expressions outside the scop region.
(rewrite_cross_bb_scalar_deps): Same.
* sese.c (rename_uses): Use NULL_TREE instead of NULL for trees.
* gcc.dg/graphite/run-id-5.c: New.
* gcc.dg/graphite/run-id-6.c: New.
* gfortran.dg/graphite/id-21.f: New.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@163157 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/graphite-sese-to-poly.c')
-rw-r--r-- | gcc/graphite-sese-to-poly.c | 85 |
1 files changed, 75 insertions, 10 deletions
diff --git a/gcc/graphite-sese-to-poly.c b/gcc/graphite-sese-to-poly.c index 084dd31cf52..574a25b2213 100644 --- a/gcc/graphite-sese-to-poly.c +++ b/gcc/graphite-sese-to-poly.c @@ -2182,6 +2182,45 @@ scalar_close_phi_node_p (gimple phi) return (gimple_phi_num_args (phi) == 1); } +/* For a definition DEF in REGION, propagates the expression EXPR in + all the uses of DEF outside REGION. */ + +static void +propagate_expr_outside_region (tree def, tree expr, sese region) +{ + imm_use_iterator imm_iter; + gimple use_stmt; + gimple_seq stmts; + bool replaced_once = false; + + gcc_assert (TREE_CODE (def) == SSA_NAME + && bb_in_sese_p (gimple_bb (SSA_NAME_DEF_STMT (def)), region)); + + expr = force_gimple_operand (unshare_expr (expr), &stmts, true, + NULL_TREE); + + FOR_EACH_IMM_USE_STMT (use_stmt, imm_iter, def) + if (!is_gimple_debug (use_stmt) + && !bb_in_sese_p (gimple_bb (use_stmt), region)) + { + ssa_op_iter iter; + use_operand_p use_p; + + FOR_EACH_PHI_OR_STMT_USE (use_p, use_stmt, iter, SSA_OP_ALL_USES) + if (operand_equal_p (def, USE_FROM_PTR (use_p), 0) + && (replaced_once = true)) + replace_exp (use_p, expr); + + update_stmt (use_stmt); + } + + if (replaced_once) + { + gsi_insert_seq_on_edge (SESE_ENTRY (region), stmts); + gsi_commit_edge_inserts (); + } +} + /* Rewrite out of SSA the reduction phi node at PSI by creating a zero dimension array for it. */ @@ -2201,20 +2240,36 @@ rewrite_close_phi_out_of_ssa (gimple_stmt_iterator *psi, sese region) before Graphite: see canonicalize_loop_closed_ssa_form. */ gcc_assert (gimple_phi_num_args (phi) == 1); - /* If res is scev analyzable, it is safe to ignore the close phi - node: it will be code generated in the out of Graphite pass. */ - if (scev_analyzable_p (res, region)) - { - gsi_next (psi); - return; - } - /* The phi node can be a non close phi node, when its argument is invariant, or when it is defined in the same loop as the phi node. */ if (is_gimple_min_invariant (arg) || SSA_NAME_IS_DEFAULT_DEF (arg) || gimple_bb (SSA_NAME_DEF_STMT (arg))->loop_father == bb->loop_father) stmt = gimple_build_assign (res, arg); + + /* If res is scev analyzable and is not a scalar value, it is safe + to ignore the close phi node: it will be code generated in the + out of Graphite pass. */ + else if (scev_analyzable_p (res, region)) + { + loop_p loop = loop_containing_stmt (SSA_NAME_DEF_STMT (res)); + tree scev; + + if (!loop_in_sese_p (loop, region)) + { + loop = loop_containing_stmt (SSA_NAME_DEF_STMT (arg)); + scev = scalar_evolution_in_region (region, loop, arg); + scev = compute_overall_effect_of_inner_loop (loop, scev); + } + else + scev = scalar_evolution_in_region (region, loop, res); + + if (tree_does_not_contain_chrecs (scev)) + propagate_expr_outside_region (res, scev, region); + + gsi_next (psi); + return; + } else { tree zero_dim_array = create_zero_dim_array (var, "Close_Phi"); @@ -2428,10 +2483,20 @@ rewrite_cross_bb_scalar_deps (sese region, gimple_stmt_iterator *gsi) return; } - if (!is_gimple_reg (def) - || scev_analyzable_p (def, region)) + if (!is_gimple_reg (def)) return; + if (scev_analyzable_p (def, region)) + { + loop_p loop = loop_containing_stmt (SSA_NAME_DEF_STMT (def)); + tree scev = scalar_evolution_in_region (region, loop, def); + + if (tree_does_not_contain_chrecs (scev)) + propagate_expr_outside_region (def, scev, region); + + return; + } + def_bb = gimple_bb (stmt); FOR_EACH_IMM_USE_STMT (use_stmt, imm_iter, def) |