/* Rewrite a program in Normal form into SSA.
- Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009
+ Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010
Free Software Foundation, Inc.
Contributed by Diego Novillo <dnovillo@redhat.com>
#include "tm.h"
#include "tree.h"
#include "flags.h"
-#include "rtl.h"
#include "tm_p.h"
#include "langhooks.h"
-#include "hard-reg-set.h"
#include "basic-block.h"
#include "output.h"
-#include "expr.h"
#include "function.h"
-#include "diagnostic.h"
+#include "tree-pretty-print.h"
+#include "gimple-pretty-print.h"
#include "bitmap.h"
#include "tree-flow.h"
#include "gimple.h"
#include "tree-inline.h"
-#include "varray.h"
#include "timevar.h"
#include "hashtab.h"
#include "tree-dump.h"
#include "tree-pass.h"
#include "cfgloop.h"
#include "domwalk.h"
-#include "ggc.h"
#include "params.h"
#include "vecprim.h"
mark_block_for_update (basic_block bb)
{
gcc_assert (blocks_to_update != NULL);
- if (bitmap_bit_p (blocks_to_update, bb->index))
+ if (!bitmap_set_bit (blocks_to_update, bb->index))
return;
- bitmap_set_bit (blocks_to_update, bb->index);
initialize_flags_in_bb (bb);
}
/* Return true if symbol SYM is marked for renaming. */
-static inline bool
+bool
symbol_marked_for_renaming (tree sym)
{
return bitmap_bit_p (SYMS_TO_RENAME (cfun), DECL_UID (sym));
}
/* If the phi node is already live, there is nothing to do. */
- if (bitmap_bit_p (live_phis, p))
+ if (!bitmap_set_bit (live_phis, p))
continue;
- /* Mark the phi as live, and add the new uses to the worklist. */
- bitmap_set_bit (live_phis, p);
+ /* Add the new uses to the worklist. */
def_bb = BASIC_BLOCK (p);
FOR_EACH_EDGE (e, ei, def_bb->preds)
{
the flowgraph. */
static void
-insert_phi_nodes (bitmap *dfs)
+insert_phi_nodes (bitmap_head *dfs)
{
referenced_var_iterator rvi;
+ bitmap_iterator bi;
tree var;
+ bitmap vars;
+ unsigned uid;
timevar_push (TV_TREE_INSERT_PHI_NODES);
+ /* Do two stages to avoid code generation differences for UID
+ differences but no UID ordering differences. */
+
+ vars = BITMAP_ALLOC (NULL);
FOR_EACH_REFERENCED_VAR (var, rvi)
{
struct def_blocks_d *def_map;
- bitmap idf;
def_map = find_def_blocks_for (var);
if (def_map == NULL)
continue;
if (get_phi_state (var) != NEED_PHI_STATE_NO)
- {
- idf = compute_idf (def_map->def_blocks, dfs);
- insert_phi_nodes_for (var, idf, false);
- BITMAP_FREE (idf);
- }
+ bitmap_set_bit (vars, DECL_UID (var));
}
+ EXECUTE_IF_SET_IN_BITMAP (vars, 0, uid, bi)
+ {
+ tree var = referenced_var (uid);
+ struct def_blocks_d *def_map;
+ bitmap idf;
+
+ def_map = find_def_blocks_for (var);
+ idf = compute_idf (def_map->def_blocks, dfs);
+ insert_phi_nodes_for (var, idf, false);
+ BITMAP_FREE (idf);
+ }
+
+ BITMAP_FREE (vars);
+
timevar_pop (TV_TREE_INSERT_PHI_NODES);
}
EXECUTE_IF_SET_IN_BITMAP (set, 0, i, bi)
{
- print_generic_expr (file, referenced_var (i), 0);
+ tree var = referenced_var_lookup (i);
+ if (var)
+ print_generic_expr (file, var, 0);
+ else
+ fprintf (file, "D.%u", i);
fprintf (file, " ");
}
/* Dump bitmap SET (assumed to contain VAR_DECLs) to FILE. */
-void
+DEBUG_FUNCTION void
debug_decl_set (bitmap set)
{
dump_decl_set (stderr, set);
dumped. New levels are created when the dominator tree traversal
used for renaming enters a new sub-tree. */
-void
+DEBUG_FUNCTION void
debug_defs_stack (int n)
{
dump_defs_stack (stderr, n);
/* Dump the current reaching definition of every symbol to stderr. */
-void
+DEBUG_FUNCTION void
debug_currdefs (void)
{
dump_currdefs (stderr);
/* Dump SSA information to stderr. */
-void
+DEBUG_FUNCTION void
debug_tree_ssa (void)
{
dump_tree_ssa (stderr);
/* Dump SSA statistics on stderr. */
-void
+DEBUG_FUNCTION void
debug_tree_ssa_stats (void)
{
dump_tree_ssa_stats (stderr);
/* Dump the DEF_BLOCKS hash table on stderr. */
-void
+DEBUG_FUNCTION void
debug_def_blocks (void)
{
dump_def_blocks (stderr);
if (tracked_var)
{
gimple note = gimple_build_debug_bind (tracked_var, def, stmt);
- gsi_insert_after (&gsi, note, GSI_SAME_STMT);
+ /* If stmt ends the bb, insert the debug stmt on the single
+ non-EH edge from the stmt. */
+ if (gsi_one_before_end_p (gsi) && stmt_ends_bb_p (stmt))
+ {
+ basic_block bb = gsi_bb (gsi);
+ edge_iterator ei;
+ edge e, ef = NULL;
+ FOR_EACH_EDGE (e, ei, bb->succs)
+ if (!(e->flags & EDGE_EH))
+ {
+ gcc_assert (!ef);
+ ef = e;
+ }
+ gcc_assert (ef
+ && single_pred_p (ef->dest)
+ && !phi_nodes (ef->dest)
+ && ef->dest != EXIT_BLOCK_PTR);
+ gsi_insert_on_edge_immediate (ef, note);
+ }
+ else
+ gsi_insert_after (&gsi, note, GSI_SAME_STMT);
}
}
continue;
phis = VEC_index (gimple_vec, phis_to_rewrite, e->dest->index);
- for (i = 0; VEC_iterate (gimple, phis, i, phi); i++)
+ FOR_EACH_VEC_ELT (gimple, phis, i, phi)
{
tree arg, lhs_sym, reaching_def = NULL;
use_operand_p arg_p;
static unsigned int
rewrite_into_ssa (void)
{
- bitmap *dfs;
+ bitmap_head *dfs;
basic_block bb;
timevar_push (TV_TREE_SSA_OTHER);
sbitmap_zero (interesting_blocks);
/* Initialize dominance frontier. */
- dfs = XNEWVEC (bitmap, last_basic_block);
+ dfs = XNEWVEC (bitmap_head, last_basic_block);
FOR_EACH_BB (bb)
- dfs[bb->index] = BITMAP_ALLOC (NULL);
+ bitmap_initialize (&dfs[bb->index], &bitmap_default_obstack);
/* 1- Compute dominance frontiers. */
calculate_dominance_info (CDI_DOMINATORS);
/* Free allocated memory. */
FOR_EACH_BB (bb)
- BITMAP_FREE (dfs[bb->index]);
+ bitmap_clear (&dfs[bb->index]);
free (dfs);
sbitmap_free (interesting_blocks);
/* Dump all the names replaced by NAME to stderr. */
-void
+DEBUG_FUNCTION void
debug_names_replaced_by (tree name)
{
dump_names_replaced_by (stderr, name);
/* Dump SSA update information to stderr. */
-void
+DEBUG_FUNCTION void
debug_update_ssa (void)
{
dump_update_ssa (stderr);
names is not pruned. PHI nodes are inserted at every IDF block. */
static void
-insert_updated_phi_nodes_for (tree var, bitmap *dfs, bitmap blocks,
+insert_updated_phi_nodes_for (tree var, bitmap_head *dfs, bitmap blocks,
unsigned update_flags)
{
basic_block entry;
and for symbols in SYMS_TO_RENAME. */
if (insert_phi_p)
{
- bitmap *dfs;
+ bitmap_head *dfs;
/* If the caller requested PHI nodes to be added, compute
dominance frontiers. */
- dfs = XNEWVEC (bitmap, last_basic_block);
+ dfs = XNEWVEC (bitmap_head, last_basic_block);
FOR_EACH_BB (bb)
- dfs[bb->index] = BITMAP_ALLOC (NULL);
+ bitmap_initialize (&dfs[bb->index], &bitmap_default_obstack);
compute_dominance_frontiers (dfs);
if (sbitmap_first_set_bit (old_ssa_names) >= 0)
update_flags);
FOR_EACH_BB (bb)
- BITMAP_FREE (dfs[bb->index]);
+ bitmap_clear (&dfs[bb->index]);
free (dfs);
/* Insertion of PHI nodes may have added blocks to the region.