#include "coretypes.h"
#include "tm.h"
#include "tree.h"
-#include "diagnostic.h"
#include "tree-pretty-print.h"
#include "gimple-pretty-print.h"
#include "bitmap.h"
bitmap partition_in_use; /* Partitions with kill entries. */
bitmap new_replaceable_dependencies; /* Holding place for pending dep's. */
int *num_in_part; /* # of ssa_names in a partition. */
+ int *call_cnt; /* Call count at definition. */
} *temp_expr_table_p;
/* Used to indicate a dependency on VDEFs. */
if (p != NO_PARTITION)
t->num_in_part[p]++;
}
+ t->call_cnt = XCNEWVEC (int, num_ssa_names + 1);
return t;
}
free (t->kill_list);
free (t->partition_dependencies);
free (t->num_in_part);
+ free (t->call_cnt);
if (t->replaceable_expressions)
ret = t->replaceable_expressions;
/* Create an expression entry for a replaceable expression. */
static void
-process_replaceable (temp_expr_table_p tab, gimple stmt)
+process_replaceable (temp_expr_table_p tab, gimple stmt, int call_cnt)
{
tree var, def, basevar;
int version;
make_dependent_on_partition (tab, version, VIRTUAL_PARTITION (tab));
add_to_partition_kill_list (tab, VIRTUAL_PARTITION (tab), version);
}
+
+ tab->call_cnt[version] = call_cnt;
}
{
gimple_stmt_iterator bsi;
gimple stmt;
- tree def, use;
+ tree def, use, fndecl;
int partition;
var_map map = tab->map;
ssa_op_iter iter;
bool stmt_replaceable;
+ int cur_call_cnt = 0;
for (bsi = gsi_start_bb (bb); !gsi_end_p (bsi); gsi_next (&bsi))
{
}
}
- /* Mark expression as replaceable unless stmt is volatile or the
+ /* If the stmt does a memory store and the replacement
+ is a load aliasing it avoid creating overlapping
+ assignments which we cannot expand correctly. */
+ if (gimple_vdef (stmt)
+ && gimple_assign_single_p (stmt))
+ {
+ gimple def_stmt = SSA_NAME_DEF_STMT (use);
+ while (is_gimple_assign (def_stmt)
+ && gimple_assign_rhs_code (def_stmt) == SSA_NAME)
+ def_stmt
+ = SSA_NAME_DEF_STMT (gimple_assign_rhs1 (def_stmt));
+ if (gimple_vuse (def_stmt)
+ && gimple_assign_single_p (def_stmt)
+ && refs_may_alias_p (gimple_assign_lhs (stmt),
+ gimple_assign_rhs1 (def_stmt)))
+ same_root_var = true;
+ }
+
+ /* Mark expression as replaceable unless stmt is volatile, or the
def variable has the same root variable as something in the
- substitution list. */
- if (gimple_has_volatile_ops (stmt) || same_root_var)
+ substitution list, or the def and use span a call such that
+ we'll expand lifetimes across a call. */
+ if (gimple_has_volatile_ops (stmt) || same_root_var ||
+ tab->call_cnt[ver] != cur_call_cnt)
finished_with_expr (tab, ver, true);
else
mark_replaceable (tab, use, stmt_replaceable);
kill_expr (tab, partition);
}
+ /* Increment counter if this is a non BUILT_IN call. We allow
+ replacement over BUILT_IN calls since many will expand to inline
+ insns instead of a true call. */
+ if (is_gimple_call (stmt)
+ && !((fndecl = gimple_call_fndecl (stmt))
+ && DECL_BUILT_IN (fndecl)))
+ cur_call_cnt++;
+
/* Now see if we are creating a new expression or not. */
if (stmt_replaceable)
- process_replaceable (tab, stmt);
+ process_replaceable (tab, stmt, cur_call_cnt);
/* Free any unused dependency lists. */
bitmap_clear (tab->new_replaceable_dependencies);
exclusively to debug TER. F is the place to send debug info and T is the
table being debugged. */
-void
+DEBUG_FUNCTION void
debug_ter (FILE *f, temp_expr_table_p t)
{
unsigned x, y;
for (x = 1; x < num_ssa_names; x++)
if (t->expr_decl_uids[x])
{
- print_generic_expr (stderr, ssa_name (x), TDF_SLIM);
+ print_generic_expr (f, ssa_name (x), TDF_SLIM);
fprintf (f, " dep-parts : ");
if (t->partition_dependencies[x]
&& !bitmap_empty_p (t->partition_dependencies[x]))
EXECUTE_IF_SET_IN_BITMAP (t->partition_dependencies[x], 0, y, bi)
fprintf (f, "P%d ",y);
}
- fprintf (stderr, " basedecls: ");
+ fprintf (f, " basedecls: ");
EXECUTE_IF_SET_IN_BITMAP (t->expr_decl_uids[x], 0, y, bi)
fprintf (f, "%d ",y);
- fprintf (stderr, "\n");
+ fprintf (f, " call_cnt : %d",t->call_cnt[x]);
+ fprintf (f, "\n");
}
bitmap_print (f, t->partition_in_use, "Partitions in use ",