From 734217d0879c246a139d4c55ecd65837b2fa6077 Mon Sep 17 00:00:00 2001 From: Bin Cheng Date: Tue, 5 Dec 2017 10:00:06 +0000 Subject: [PATCH] cleanup-1 --- gcc/gimple-loop-interchange.cc | 49 +++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 29 deletions(-) diff --git a/gcc/gimple-loop-interchange.cc b/gcc/gimple-loop-interchange.cc index 1f46509..8c396ab 100644 --- a/gcc/gimple-loop-interchange.cc +++ b/gcc/gimple-loop-interchange.cc @@ -100,10 +100,11 @@ typedef struct induction { /* IV itself. */ tree var; - /* Initializer. */ - tree init; - /* IV's base and step part of SCEV. */ - tree base; + /* IV's initializing value, which is the init arg of the IV PHI node. */ + tree init_val; + /* IV's initializing expr, which is (the expanded result of) init_val. */ + tree init_expr; + /* IV's step. */ tree step; }* induction_p; @@ -161,7 +162,7 @@ dump_induction (struct loop *loop, induction_p iv) fprintf (dump_file, " Induction: "); print_generic_expr (dump_file, iv->var, TDF_SLIM); fprintf (dump_file, " = {"); - print_generic_expr (dump_file, iv->base, TDF_SLIM); + print_generic_expr (dump_file, iv->init_expr, TDF_SLIM); fprintf (dump_file, ", "); print_generic_expr (dump_file, iv->step, TDF_SLIM); fprintf (dump_file, "}_%d\n", loop->num); @@ -742,8 +743,8 @@ loop_cand::analyze_induction_var (tree var, tree chrec) { struct induction *iv = XCNEW (struct induction); iv->var = var; - iv->init = init; - iv->base = chrec; + iv->init_val = init; + iv->init_expr = chrec; iv->step = build_int_cst (TREE_TYPE (chrec), 0); m_inductions.safe_push (iv); return true; @@ -757,8 +758,8 @@ loop_cand::analyze_induction_var (tree var, tree chrec) struct induction *iv = XCNEW (struct induction); iv->var = var; - iv->init = init; - iv->base = CHREC_LEFT (chrec); + iv->init_val = init; + iv->init_expr = CHREC_LEFT (chrec); iv->step = CHREC_RIGHT (chrec); if (dump_file && (dump_flags & TDF_DETAILS)) @@ -938,14 +939,14 @@ loop_cand::undo_simple_reduction (reduction_p re, bitmap dce_seeds) /* Find all stmts on which expression "MEM_REF[idx]" depends. */ find_deps_in_bb_for_stmt (&stmts, gimple_bb (re->consumer), re->consumer); /* Because we generate new stmt loading from the MEM_REF to TMP. */ - tree tmp = copy_ssa_name (re->var); + tree cond, tmp = copy_ssa_name (re->var); stmt = gimple_build_assign (tmp, re->init_ref); gimple_seq_add_stmt (&stmts, stmt); /* Init new_var to MEM_REF or CONST depending on if it is the first iteration. */ induction_p iv = m_inductions[0]; - tree cond = fold_build2 (NE_EXPR, boolean_type_node, iv->var, iv->init); + cond = fold_build2 (NE_EXPR, boolean_type_node, iv->var, iv->init_val); new_var = copy_ssa_name (re->var); stmt = gimple_build_assign (new_var, COND_EXPR, cond, tmp, re->init); gimple_seq_add_stmt (&stmts, stmt); @@ -1007,7 +1008,6 @@ public: private: void update_data_info (unsigned, unsigned, vec, vec); bool valid_data_dependences (unsigned, unsigned, vec); - bool can_interchange_loops (loop_cand &, loop_cand &); void interchange_loops (loop_cand &, loop_cand &); void map_inductions_to_loop (loop_cand &, loop_cand &); void move_code_to_inner_loop (struct loop *, struct loop *, basic_block *); @@ -1099,21 +1099,6 @@ tree_loop_interchange::valid_data_dependences (unsigned i_idx, unsigned o_idx, return true; } -/* Return true if ILOOP and OLOOP can be interchanged in terms of code - transformation. */ - -bool -tree_loop_interchange::can_interchange_loops (loop_cand &iloop, - loop_cand &oloop) -{ - return (iloop.analyze_carried_vars (NULL) - && iloop.analyze_lcssa_phis () - && oloop.analyze_carried_vars (&iloop) - && oloop.analyze_lcssa_phis () - && iloop.can_interchange_p (NULL) - && oloop.can_interchange_p (&iloop)); -} - /* Interchange two loops specified by ILOOP and OLOOP. */ void @@ -1227,7 +1212,8 @@ tree_loop_interchange::map_inductions_to_loop (loop_cand &src, loop_cand &tgt) { /* Map the IV by creating the same one in target loop. */ tree var_before, var_after; - tree base = unshare_expr (iv->base), step = unshare_expr (iv->step); + tree base = unshare_expr (iv->init_expr); + tree step = unshare_expr (iv->step); create_iv (base, step, SSA_NAME_VAR (iv->var), tgt.m_loop, &incr_pos, false, &var_before, &var_after); bitmap_set_bit (m_dce_seeds, SSA_NAME_VERSION (var_before)); @@ -1622,7 +1608,12 @@ tree_loop_interchange::interchange (vec datarefs, loop_cand oloop (m_loop_nest[o_idx], m_loop_nest[o_idx]); /* Check if we can do transformation for loop interchange. */ - if (!can_interchange_loops (iloop, oloop)) + if (!iloop.analyze_carried_vars (NULL) + || !iloop.analyze_lcssa_phis () + || !oloop.analyze_carried_vars (&iloop) + || !oloop.analyze_lcssa_phis () + || !iloop.can_interchange_p (NULL) + || !oloop.can_interchange_p (&iloop)) break; /* Check profitability for loop interchange. */ -- 1.9.1