* tree-cfg.c (tree_duplicate_bb): Mark duplicated definitions.
* tree-flow.h (rewrite_ssa_into_ssa): Declaration changed.
* tree-into-ssa.c (rewrite_ssa_into_ssa): Use new interface to
manipulate the duplicated ssa names.
* tree-ssanames.c (ssa_names_to_rewrite): New variable.
(marked_for_rewrite_p, any_marked_for_rewrite_p, mark_for_rewrite,
unmark_all_for_rewrite, marked_ssa_names, release_ssa_name_force):
New functions.
(release_ssa_name): Do not release ssa names that may have multiple
definitions.
* tree.h (release_ssa_name_force, mark_for_rewrite,
unmark_all_for_rewrite, marked_for_rewrite_p, any_marked_for_rewrite_p,
marked_ssa_names): Declare.
* tree-ssa-loop-ch.c (mark_defs_for_rewrite): Remove.
(duplicate_blocks): Remove call to mark_defs_for_rewrite.
Update call to rewrite_ssa_into_ssa.
Co-Authored-By: Jeff Law <law@redhat.com>
From-SVN: r85572
+2004-08-04 Zdenek Dvorak <rakdver@atrey.karlin.mff.cuni.cz>
+ Jeff Law <law@redhat.com>
+
+ * tree-cfg.c (tree_duplicate_bb): Mark duplicated definitions.
+ * tree-flow.h (rewrite_ssa_into_ssa): Declaration changed.
+ * tree-into-ssa.c (rewrite_ssa_into_ssa): Use new interface to
+ manipulate the duplicated ssa names.
+ * tree-ssanames.c (ssa_names_to_rewrite): New variable.
+ (marked_for_rewrite_p, any_marked_for_rewrite_p, mark_for_rewrite,
+ unmark_all_for_rewrite, marked_ssa_names, release_ssa_name_force):
+ New functions.
+ (release_ssa_name): Do not release ssa names that may have multiple
+ definitions.
+ * tree.h (release_ssa_name_force, mark_for_rewrite,
+ unmark_all_for_rewrite, marked_for_rewrite_p, any_marked_for_rewrite_p,
+ marked_ssa_names): Declare.
+ * tree-ssa-loop-ch.c (mark_defs_for_rewrite): Remove.
+ (duplicate_blocks): Remove call to mark_defs_for_rewrite.
+ Update call to rewrite_ssa_into_ssa.
+
2004-08-04 Mark Mitchell <mark@codesourcery.com>
* defaults.h (TARGET_DECLSPEC): New macro.
{
basic_block new_bb;
block_stmt_iterator bsi, bsi_tgt;
+ tree phi;
+ def_optype defs;
+ v_may_def_optype v_may_defs;
+ v_must_def_optype v_must_defs;
+ unsigned j;
new_bb = create_empty_bb (EXIT_BLOCK_PTR->prev_bb);
+
+ for (phi = phi_nodes (bb); phi; phi = TREE_CHAIN (phi))
+ {
+ mark_for_rewrite (PHI_RESULT (phi));
+ }
+
bsi_tgt = bsi_start (new_bb);
for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
{
if (TREE_CODE (stmt) == LABEL_EXPR)
continue;
+ /* Record the definitions. */
+ get_stmt_operands (stmt);
+
+ defs = STMT_DEF_OPS (stmt);
+ for (j = 0; j < NUM_DEFS (defs); j++)
+ mark_for_rewrite (DEF_OP (defs, j));
+
+ v_may_defs = STMT_V_MAY_DEF_OPS (stmt);
+ for (j = 0; j < NUM_V_MAY_DEFS (v_may_defs); j++)
+ mark_for_rewrite (V_MAY_DEF_RESULT (v_may_defs, j));
+
+ v_must_defs = STMT_V_MUST_DEF_OPS (stmt);
+ for (j = 0; j < NUM_V_MUST_DEFS (v_must_defs); j++)
+ mark_for_rewrite (V_MUST_DEF_OP (v_must_defs, j));
+
copy = unshare_expr (stmt);
/* Copy also the virtual operands. */
/* In tree-into-ssa.c */
extern void rewrite_into_ssa (bool);
-extern void rewrite_ssa_into_ssa (bitmap);
+extern void rewrite_ssa_into_ssa (void);
void compute_global_livein (bitmap, bitmap);
tree duplicate_ssa_name (tree, tree);
timevar_pop (TV_TREE_SSA_OTHER);
}
-/* The ssa names in NAMES_TO_RENAME may have more than one definition;
+/* The marked ssa names may have more than one definition;
add phi nodes and rewrite them to fix this. */
void
-rewrite_ssa_into_ssa (bitmap names_to_rename)
+rewrite_ssa_into_ssa (void)
{
bitmap *dfs;
basic_block bb;
unsigned i;
sbitmap snames_to_rename;
tree name;
+ bitmap to_rename;
- if (bitmap_first_set_bit (names_to_rename) < 0)
+ if (!any_marked_for_rewrite_p ())
return;
+ to_rename = marked_ssa_names ();
timevar_push (TV_TREE_SSA_OTHER);
snames_to_rename = sbitmap_alloc (num_ssa_names);
sbitmap_zero (snames_to_rename);
- EXECUTE_IF_SET_IN_BITMAP (names_to_rename, 0, i,
+ EXECUTE_IF_SET_IN_BITMAP (to_rename, 0, i,
SET_BIT (snames_to_rename, i));
mark_def_sites_global_data.kills = sbitmap_alloc (num_ssa_names);
set_current_def (ssa_name (i), NULL_TREE);
/* Insert PHI nodes at dominance frontiers of definition blocks. */
- insert_phi_nodes (dfs, names_to_rename);
+ insert_phi_nodes (dfs, to_rename);
/* Rewrite all the basic blocks in the program. */
timevar_push (TV_TREE_SSA_REWRITE_BLOCKS);
/* Finalize the dominator walker. */
fini_walk_dominator_tree (&walk_data);
- EXECUTE_IF_SET_IN_BITMAP (names_to_rename, 0, i,
- release_ssa_name (ssa_name (i)));
+ unmark_all_for_rewrite ();
+
+ EXECUTE_IF_SET_IN_BITMAP (to_rename, 0, i, release_ssa_name (ssa_name (i)));
sbitmap_free (snames_to_rename);
SSA_NAME_AUX (name) = NULL;
}
+ BITMAP_XFREE (to_rename);
timevar_pop (TV_TREE_SSA_OTHER);
}
return true;
}
-/* Marks variables defined in basic block BB for rewriting. */
-
-static void
-mark_defs_for_rewrite (basic_block bb)
-{
- tree stmt, var;
- block_stmt_iterator bsi;
- stmt_ann_t ann;
- def_optype defs;
- v_may_def_optype v_may_defs;
- v_must_def_optype v_must_defs;
- unsigned i;
-
- for (stmt = phi_nodes (bb); stmt; stmt = TREE_CHAIN (stmt))
- {
- var = PHI_RESULT (stmt);
- bitmap_set_bit (vars_to_rename, SSA_NAME_VERSION (var));
- }
-
- for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
- {
- stmt = bsi_stmt (bsi);
- get_stmt_operands (stmt);
- ann = stmt_ann (stmt);
-
- defs = DEF_OPS (ann);
- for (i = 0; i < NUM_DEFS (defs); i++)
- {
- var = DEF_OP (defs, i);
- bitmap_set_bit (vars_to_rename, SSA_NAME_VERSION (var));
- }
-
- v_may_defs = V_MAY_DEF_OPS (ann);
- for (i = 0; i < NUM_V_MAY_DEFS (v_may_defs); i++)
- {
- var = V_MAY_DEF_RESULT (v_may_defs, i);
- bitmap_set_bit (vars_to_rename, SSA_NAME_VERSION (var));
- }
-
- v_must_defs = V_MUST_DEF_OPS (ann);
- for (i = 0; i < NUM_V_MUST_DEFS (v_must_defs); i++)
- {
- var = V_MUST_DEF_OP (v_must_defs, i);
- bitmap_set_bit (vars_to_rename, SSA_NAME_VERSION (var));
- }
- }
-}
-
/* Duplicates destinations of edges in BBS_TO_DUPLICATE. */
static void
up-to-date. */
free_dominance_info (CDI_DOMINATORS);
- for (i = 0; i < VARRAY_ACTIVE_SIZE (bbs_to_duplicate); i++)
- {
- preheader_edge = VARRAY_GENERIC_PTR_NOGC (bbs_to_duplicate, i);
- header = preheader_edge->dest;
-
- /* It is sufficient to rewrite the definitions, since the uses of
- the operands defined outside of the duplicated basic block are
- still valid (every basic block that dominates the original block
- also dominates the duplicate). */
- mark_defs_for_rewrite (header);
- }
-
for (i = 0; i < VARRAY_ACTIVE_SIZE (bbs_to_duplicate); i++)
{
preheader_edge = VARRAY_GENERIC_PTR_NOGC (bbs_to_duplicate, i);
calculate_dominance_info (CDI_DOMINATORS);
- rewrite_ssa_into_ssa (vars_to_rename);
- bitmap_clear (vars_to_rename);
+ rewrite_ssa_into_ssa ();
}
/* Checks whether LOOP is a do-while style loop. */
/* Array of all SSA_NAMEs used in the function. */
varray_type ssa_names;
-
+
+/* Bitmap of ssa names marked for rewriting. */
+bitmap ssa_names_to_rewrite;
+
/* Free list of SSA_NAMEs. This list is wiped at the end of each function
after we leave SSA form. */
static GTY (()) tree free_ssanames;
unsigned int ssa_name_nodes_created;
#endif
+/* Returns true if ssa name VAR is marked for rewrite. */
+
+bool
+marked_for_rewrite_p (tree var)
+{
+ if (ssa_names_to_rewrite
+ && bitmap_bit_p (ssa_names_to_rewrite, SSA_NAME_VERSION (var)))
+ return true;
+
+ return false;
+}
+
+/* Returns true if any ssa name is marked for rewrite. */
+
+bool
+any_marked_for_rewrite_p (void)
+{
+ if (!ssa_names_to_rewrite)
+ return false;
+
+ return bitmap_first_set_bit (ssa_names_to_rewrite) != -1;
+}
+
+/* Mark ssa name VAR for rewriting. */
+
+void
+mark_for_rewrite (tree var)
+{
+ if (!ssa_names_to_rewrite)
+ ssa_names_to_rewrite = BITMAP_XMALLOC ();
+
+ bitmap_set_bit (ssa_names_to_rewrite, SSA_NAME_VERSION (var));
+}
+
+/* Unmark all ssa names marked for rewrite. */
+
+void
+unmark_all_for_rewrite (void)
+{
+ if (!ssa_names_to_rewrite)
+ return;
+
+ bitmap_clear (ssa_names_to_rewrite);
+}
+
+/* Return the bitmap of ssa names to rewrite. Copy the bitmap,
+ so that the optimizers cannot access internals directly */
+
+bitmap
+marked_ssa_names (void)
+{
+ bitmap ret = BITMAP_XMALLOC ();
+ if (ssa_names_to_rewrite)
+ bitmap_copy (ret, ssa_names_to_rewrite);
+
+ return ret;
+}
+
/* Initialize management of SSA_NAMEs. */
void
if (var == var_ann (SSA_NAME_VAR (var))->default_def)
return;
+ /* If the ssa name is marked for rewriting, it may have multiple definitions,
+ but we may happen to remove just one of them. So do not remove the
+ ssa name now. */
+ if (marked_for_rewrite_p (var))
+ return;
+
/* release_ssa_name can be called multiple times on a single SSA_NAME.
However, it should only end up on our free list one time. We
keep a status bit in the SSA_NAME node itself to indicate it has
extern void ssanames_print_statistics (void);
#endif
+extern void mark_for_rewrite (tree);
+extern void unmark_all_for_rewrite (void);
+extern bool marked_for_rewrite_p (tree);
+extern bool any_marked_for_rewrite_p (void);
+extern struct bitmap_head_def *marked_ssa_names (void);
+
+
/* Return the (unique) IDENTIFIER_NODE node for a given name.
The name is supplied as a char *. */