/* Predictive commoning.
Copyright (C) 2005, 2007, 2008, 2009 Free Software Foundation, Inc.
-
+
This file is part of GCC.
-
+
GCC is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3, or (at your option) any
later version.
-
+
GCC is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
-
+
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
and if needed, we could also take register pressure into account.
Let us demonstrate what is done on an example:
-
+
for (i = 0; i < 100; i++)
{
a[i+2] = a[i] + a[i+1];
making the further transformations simpler. Also, the shorter chains
need the same number of registers, but may require lower unrolling
factor in order to get rid of the copies on the loop latch.
-
+
In our example, we get the following chains (the chain for c is invalid).
a[i]{read,+0}, a[i+1]{read,-1}, a[i+2]{write,-2}
with the smallest positive distance to the read. Then, we remove
the references that are not used in any of these chains, discard the
empty groups, and propagate all the links so that they point to the
- single root reference of the chain (adjusting their distance
+ single root reference of the chain (adjusting their distance
appropriately). Some extra care needs to be taken for references with
step 0. In our example (the numbers indicate the distance of the
reuse),
times. The stores to RN (R0) in the copies of the loop body are
periodically replaced with R0, R1, ... (R1, R2, ...), so that they can
be coalesced and the copies can be eliminated.
-
+
TODO -- copy propagation and other optimizations may change the live
ranges of the temporary registers and prevent them from being coalesced;
this may increase the register pressure.
references. */
#define MAX_DISTANCE (target_avail_regs < 16 ? 4 : 8)
-
+
/* Data references (or phi nodes that carry data reference values across
loop iterations). */
struct component *comp_list = NULL, *comp;
dref dataref;
basic_block last_always_executed = last_always_executed_block (loop);
-
+
for (i = 0; VEC_iterate (data_reference_p, datarefs, i, dr); i++)
{
if (!DR_REF (dr))
&& (ia == bad || ib == bad
|| !determine_offset (dra, drb, &dummy_off)))
continue;
-
+
merge_comps (comp_father, comp_size, ia, ib);
}
/* Returns true if the component COMP satisfies the conditions
described in 2) at the beginning of this file. LOOP is the current
loop. */
-
+
static bool
suitable_component_p (struct loop *loop, struct component *comp)
{
return true;
}
-
+
/* Check the conditions on references inside each of components COMPS,
and remove the unsuitable components from the list. The new list
of components is returned. The conditions are described in 2) at
unsigned i;
dref a;
chain_p chain = NULL;
+ double_int last_ofs = double_int_zero;
/* Invariants are handled specially. */
if (comp->comp_step == RS_INVARIANT)
for (i = 0; VEC_iterate (dref, comp->refs, i, a); i++)
{
- if (!chain || !DR_IS_READ (a->ref))
+ if (!chain || !DR_IS_READ (a->ref)
+ || double_int_ucmp (uhwi_to_double_int (MAX_DISTANCE),
+ double_int_add (a->offset,
+ double_int_neg (last_ofs))) <= 0)
{
if (nontrivial_chain_p (chain))
- VEC_safe_push (chain_p, heap, *chains, chain);
+ {
+ add_looparound_copies (loop, chain);
+ VEC_safe_push (chain_p, heap, *chains, chain);
+ }
else
release_chain (chain);
chain = make_rooted_chain (a);
+ last_ofs = a->offset;
continue;
}
gsi_insert_before (&bsi, new_stmt, GSI_NEW_STMT);
return;
}
-
+
/* Since the reference is of gimple_reg type, it should only
appear as lhs or rhs of modify statement. */
gcc_assert (is_gimple_assign (stmt));
if (in_lhs)
{
/* We have statement
-
+
OLD = VAL
If OLD is a memory reference, then VAL is gimple_val, and we transform
OLD = VAL
NEW = VAL
- Otherwise, we are replacing a combination chain,
+ Otherwise, we are replacing a combination chain,
VAL is the expression that performs the combination, and OLD is an
SSA name. In this case, we transform the assignment to
else if (!INDIRECT_REF_P (ref))
return unshare_expr (ref);
- if (TREE_CODE (ref) == INDIRECT_REF)
+ if (INDIRECT_REF_P (ref))
{
- ret = build1 (INDIRECT_REF, TREE_TYPE (ref), NULL_TREE);
+ /* Take care for INDIRECT_REF and MISALIGNED_INDIRECT_REF at
+ the same time. */
+ ret = copy_node (ref);
idx = TREE_OPERAND (ref, 0);
idx_p = &TREE_OPERAND (ret, 0);
}
}
if (reuse_first)
VEC_quick_push (tree, chain->vars, VEC_index (tree, chain->vars, 0));
-
+
for (i = 0; VEC_iterate (tree, chain->vars, i, var); i++)
VEC_replace (tree, chain->vars, i, make_ssa_name (var, NULL));
VEC_quick_push (tree, *vars, var);
if (written)
VEC_quick_push (tree, *vars, VEC_index (tree, *vars, 0));
-
+
for (i = 0; VEC_iterate (tree, *vars, i, var); i++)
VEC_replace (tree, *vars, i, make_ssa_name (var, NULL));
var = VEC_index (tree, *vars, 0);
-
+
init = force_gimple_operand (init, &stmts, written, NULL_TREE);
if (stmts)
gsi_insert_seq_on_edge_immediate (entry, stmts);
for (i = 0; VEC_iterate (dref, chain->refs, i, a); i++)
if (!DR_IS_READ (a->ref))
n_writes++;
-
+
/* If there are no reads in the loop, there is nothing to do. */
if (n_writes == VEC_length (dref, chain->refs))
return;
else
ridx = 1;
}
-
+
replace_ref_with (a->stmt, VEC_index (tree, vars, ridx),
!is_read, !is_read);
}
while (1)
{
gimple_stmt_iterator bsi;
-
+
bsi = gsi_for_stmt (stmt);
name = gimple_assign_lhs (stmt);
else
execute_pred_commoning_chain (loop, chain, tmp_vars);
}
-
+
update_ssa (TODO_update_ssa_only_virtuals);
}
{
gimple stmt, phi;
imm_use_iterator iter;
- edge e;
SSA_NAME_VAR (name) = var;
if (!phi)
return;
- if (gimple_bb (phi) == loop->header)
- e = loop_latch_edge (loop);
- else
- e = single_pred_edge (gimple_bb (stmt));
-
name = PHI_RESULT (phi);
SSA_NAME_VAR (name) = var;
}
/* Insert the new statement combining NAME1 and NAME2 before S1, and
combine it with the rhs of S1. */
var = create_tmp_var (type, "predreastmp");
+ if (TREE_CODE (type) == COMPLEX_TYPE
+ || TREE_CODE (type) == VECTOR_TYPE)
+ DECL_GIMPLE_REG_P (var) = 1;
add_referenced_var (var);
new_name = make_ssa_name (var, NULL);
new_stmt = gimple_build_assign_with_ops (code, new_name, name1, name2);
var = create_tmp_var (type, "predreastmp");
+ if (TREE_CODE (type) == COMPLEX_TYPE
+ || TREE_CODE (type) == VECTOR_TYPE)
+ DECL_GIMPLE_REG_P (var) = 1;
add_referenced_var (var);
tmp_name = make_ssa_name (var, NULL);
tree rslt_type = NULL_TREE;
if (ch1 == ch2)
- return false;
+ return NULL;
if (ch1->length != ch2->length)
return NULL;
init = ref_at_iteration (loop, DR_REF (dr), (int) i - n);
if (!init)
return false;
-
+
if (!chain->all_always_accessed && tree_could_trap_p (init))
return false;
dta.chains = chains;
dta.tmp_vars = tmp_vars;
-
+
update_ssa (TODO_update_ssa_only_virtuals);
/* Cfg manipulations performed in tree_transform_and_unroll_loop before