This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Eliminate definitively *_stmt_changes


On Fri, May 15, 2009 at 11:42 AM, Bonzini <bonzini@gnu.org> wrote:
> While *_stmt_changes are now almost nops, it is possible to
> eliminate them completely just by changing pop_stmt_changes
> to become update_stmt.
>
> The patch is not totally trivial because I took the occasion
> to change a few related VECs from gimple_p to gimple.

This is ok if bootstrapped/tested.

Thanks,
Richard.

> Paolo
>
> 2009-05-15 ?Paolo Bonzini ?<bonzini@gnu.org>
>
> ? ? ? ?* tree-ssa-operands.h (push_stmt_changes, pop_stmt_changes,
> ? ? ? ?discard_stmt_changes): Delete.
> ? ? ? ?* tree-ssa-operands.c (scb_stack): Delete.
> ? ? ? ?(init_ssa_operands): Do not initialize it.
> ? ? ? ?(fini_ssa_operands): Do not free it.
> ? ? ? ?(push_stmt_changes, pop_stmt_changes, discard_stmt_changes): Delete.
>
> ? ? ? ?* tree-cfg.c (replace_uses_by): Replace pop_stmt_changes with
> ? ? ? ?update_stmt, remove the others. ?Fix comments.
> ? ? ? ?* tree-dfa.c (optimize_stack_restore): Likewise.
> ? ? ? ?* tree-ssa-forwprop.c (forward_propagate_addr_expr): Likewise.
> ? ? ? ?* tree-ssa-loop-ivopts.c (rewrite_use): Likewise.
> ? ? ? ?* tree-ssa-dce.c (eliminate_unnecessary_stmts): Likewise.
> ? ? ? ?* tree-ssa-ccp.c (optimize_stack_restore, execute_fold_all_builtins):
> ? ? ? ?Likewise.
> ? ? ? ?* tree-ssa-propagate.c (substitute_and_fold): Likewise.
> ? ? ? ?* tree-ssa-dom.c (propagate_rhs_into_lhs): Likewise.
> ? ? ? ?(dom_opt_finalize_block): Likewise, adjusting access to stmts_to_rescan.
> ? ? ? ?(optimize_stmt): Likewise, adjusting access to stmts_to_rescan.
> ? ? ? ?(stmts_to_rescan): Change item type to gimple.
> ? ? ? ?(tree_ssa_dominator_optimize): Change type of stmts_to_rescan.
>
> Index: gcc/tree-ssa-operands.c
> ===================================================================
> --- gcc/tree-ssa-operands.c ? ? (branch kill-push-pop-stmt-changes)
> +++ gcc/tree-ssa-operands.c ? ? (working copy)
> @@ -147,12 +147,6 @@ static void get_expr_operands (gimple, t
> ?/* Number of functions with initialized ssa_operands. ?*/
> ?static int n_initialized = 0;
>
> -/* Stack of statements to change. ?Every call to
> - ? push_stmt_changes pushes the stmt onto the stack. ?Calls to
> - ? pop_stmt_changes pop a stmt off of the stack and compute the set
> - ? of changes for the popped statement. ?*/
> -static VEC(gimple_p,heap) *scb_stack;
> -
> ?/* Return the DECL_UID of the base variable of T. ?*/
>
> ?static inline unsigned
> @@ -231,7 +225,6 @@ init_ssa_operands (void)
> ? ? ? build_vuse = NULL_TREE;
> ? ? ? build_vdef = NULL_TREE;
> ? ? ? bitmap_obstack_initialize (&operands_bitmap_obstack);
> - ? ? ?scb_stack = VEC_alloc (gimple_p, heap, 20);
> ? ? }
>
> ? gcc_assert (gimple_ssa_operands (cfun)->operand_memory == NULL);
> @@ -257,11 +250,6 @@ fini_ssa_operands (void)
> ? ? ? VEC_free (tree, heap, build_uses);
> ? ? ? build_vdef = NULL_TREE;
> ? ? ? build_vuse = NULL_TREE;
> -
> - ? ? ?/* The change buffer stack had better be empty. ?*/
> - ? ? ?gcc_assert (VEC_length (gimple_p, scb_stack) == 0);
> - ? ? ?VEC_free (gimple_p, heap, scb_stack);
> - ? ? ?scb_stack = NULL;
> ? ? }
>
> ? gimple_ssa_operands (cfun)->free_defs = NULL;
> @@ -1332,62 +1320,6 @@ debug_immediate_uses_for (tree var)
> ?}
>
>
> -/* Push *STMT_P on the SCB_STACK. ?This function is deprecated, do not
> - ? introduce new uses of it. ?*/
> -
> -void
> -push_stmt_changes (gimple *stmt_p)
> -{
> - ?gimple stmt = *stmt_p;
> -
> - ?/* It makes no sense to keep track of PHI nodes. ?*/
> - ?if (gimple_code (stmt) == GIMPLE_PHI)
> - ? ?return;
> -
> - ?VEC_safe_push (gimple_p, heap, scb_stack, stmt_p);
> -}
> -
> -/* Pop the top stmt from SCB_STACK and act on the differences between
> - ? what was recorded by push_stmt_changes and the current state of
> - ? the statement. ?This function is deprecated, do not introduce
> - ? new uses of it. ?*/
> -
> -void
> -pop_stmt_changes (gimple *stmt_p)
> -{
> - ?gimple *stmt2_p, stmt = *stmt_p;
> -
> - ?/* It makes no sense to keep track of PHI nodes. ?*/
> - ?if (gimple_code (stmt) == GIMPLE_PHI)
> - ? ?return;
> -
> - ?stmt2_p = VEC_pop (gimple_p, scb_stack);
> - ?gcc_assert (stmt_p == stmt2_p);
> -
> - ?/* Force an operand re-scan on the statement and mark any newly
> - ? ? exposed variables. ?This also will mark the virtual operand
> - ? ? for renaming if necessary. ?*/
> - ?update_stmt (stmt);
> -}
> -
> -/* Discard the topmost stmt from SCB_STACK. ?This is useful
> - ? when the caller realized that it did not actually modified the
> - ? statement. ?It avoids the expensive operand re-scan.
> - ? This function is deprecated, do not introduce new uses of it. ?*/
> -
> -void
> -discard_stmt_changes (gimple *stmt_p)
> -{
> - ?gimple *stmt2_p, stmt = *stmt_p;
> -
> - ?/* It makes no sense to keep track of PHI nodes. ?*/
> - ?if (gimple_code (stmt) == GIMPLE_PHI)
> - ? ?return;
> -
> - ?stmt2_p = VEC_pop (gimple_p, scb_stack);
> - ?gcc_assert (stmt_p == stmt2_p);
> -}
> -
> ?/* Unlink STMTs virtual definition from the IL by propagating its use. ?*/
>
> ?void
> Index: gcc/tree-ssa-operands.h
> ===================================================================
> --- gcc/tree-ssa-operands.h ? ? (branch kill-push-pop-stmt-changes)
> +++ gcc/tree-ssa-operands.h ? ? (working copy)
> @@ -114,10 +114,6 @@ extern void debug_decl_set (bitmap);
>
> ?extern bool ssa_operands_active (void);
>
> -extern void push_stmt_changes (gimple *);
> -extern void pop_stmt_changes (gimple *);
> -extern void discard_stmt_changes (gimple *);
> -
> ?extern void unlink_stmt_vdef (gimple);
>
> ?enum ssa_op_iter_type {
> Index: gcc/tree-cfg.c
> ===================================================================
> --- gcc/tree-cfg.c ? ? ?(branch kill-push-pop-stmt-changes)
> +++ gcc/tree-cfg.c ? ? ?(working copy)
> @@ -1289,9 +1289,6 @@ replace_uses_by (tree name, tree val)
>
> ? FOR_EACH_IMM_USE_STMT (stmt, imm_iter, name)
> ? ? {
> - ? ? ?if (gimple_code (stmt) != GIMPLE_PHI)
> - ? ? ? push_stmt_changes (&stmt);
> -
> ? ? ? FOR_EACH_IMM_USE_ON_STMT (use, imm_iter)
> ? ? ? ? {
> ? ? ? ? ?replace_exp (use, val);
> @@ -1318,7 +1315,7 @@ replace_uses_by (tree name, tree val)
> ? ? ? ? ?if (cfgcleanup_altered_bbs)
> ? ? ? ? ? ?bitmap_set_bit (cfgcleanup_altered_bbs, gimple_bb (stmt)->index);
>
> - ? ? ? ? /* FIXME. ?This should go in pop_stmt_changes. ?*/
> + ? ? ? ? /* FIXME. ?This should go in update_stmt. ?*/
> ? ? ? ? ?for (i = 0; i < gimple_num_ops (stmt); i++)
> ? ? ? ? ? ?{
> ? ? ? ? ? ? ?tree op = gimple_op (stmt, i);
> @@ -1330,8 +1327,7 @@ replace_uses_by (tree name, tree val)
> ? ? ? ? ? ?}
>
> ? ? ? ? ?maybe_clean_or_replace_eh_stmt (stmt, stmt);
> -
> - ? ? ? ? pop_stmt_changes (&stmt);
> + ? ? ? ? update_stmt (stmt);
> ? ? ? ?}
> ? ? }
>
> Index: gcc/tree-dfa.c
> ===================================================================
> --- gcc/tree-dfa.c ? ? ?(branch kill-push-pop-stmt-changes)
> +++ gcc/tree-dfa.c ? ? ?(working copy)
> @@ -651,11 +651,7 @@ get_virtual_var (tree var)
> ? return var;
> ?}
>
> -/* Mark all the naked symbols in STMT for SSA renaming.
> -
> - ? NOTE: This function should only be used for brand new statements.
> - ? If the caller is modifying an existing statement, it should use the
> - ? combination push_stmt_changes/pop_stmt_changes. ?*/
> +/* Mark all the naked symbols in STMT for SSA renaming. ?*/
>
> ?void
> ?mark_symbols_for_renaming (gimple stmt)
> Index: gcc/tree-ssa-ccp.c
> ===================================================================
> --- gcc/tree-ssa-ccp.c ?(branch kill-push-pop-stmt-changes)
> +++ gcc/tree-ssa-ccp.c ?(working copy)
> @@ -3023,14 +3023,9 @@ optimize_stack_restore (gimple_stmt_iter
> ? ? return NULL_TREE;
>
> ? stack_save_gsi = gsi_for_stmt (stack_save);
> - ?push_stmt_changes (gsi_stmt_ptr (&stack_save_gsi));
> ? rhs = build_int_cst (TREE_TYPE (gimple_call_arg (call, 0)), 0);
> ? if (!update_call_from_tree (&stack_save_gsi, rhs))
> - ? ?{
> - ? ? ?discard_stmt_changes (gsi_stmt_ptr (&stack_save_gsi));
> - ? ? ?return NULL_TREE;
> - ? ?}
> - ?pop_stmt_changes (gsi_stmt_ptr (&stack_save_gsi));
> + ? ?return NULL_TREE;
>
> ? /* No effect, so the statement will be deleted. ?*/
> ? return integer_zero_node;
> @@ -3252,8 +3247,6 @@ execute_fold_all_builtins (void)
> ? ? ? ? ? ?}
>
> ? ? ? ? ? old_stmt = stmt;
> - ? ? ? ? push_stmt_changes (gsi_stmt_ptr (&i));
> -
> ? ? ? ? ? if (!update_call_from_tree (&i, result))
> ? ? ? ? ? ?{
> ? ? ? ? ? ? ?gimplify_and_update_call_from_tree (&i, result);
> @@ -3261,7 +3254,7 @@ execute_fold_all_builtins (void)
> ? ? ? ? ? ?}
>
> ? ? ? ? ?stmt = gsi_stmt (i);
> - ? ? ? ? pop_stmt_changes (gsi_stmt_ptr (&i));
> + ? ? ? ? update_stmt (stmt);
>
> ? ? ? ? ?if (maybe_clean_or_replace_eh_stmt (old_stmt, stmt)
> ? ? ? ? ? ? ?&& gimple_purge_dead_eh_edges (bb))
> Index: gcc/tree-ssa-dce.c
> ===================================================================
> --- gcc/tree-ssa-dce.c ?(branch kill-push-pop-stmt-changes)
> +++ gcc/tree-ssa-dce.c ?(working copy)
> @@ -984,10 +984,9 @@ eliminate_unnecessary_stmts (void)
> ? ? ? ? ? ? ? ? ? ? ? ? ?fprintf (dump_file, "\n");
> ? ? ? ? ? ? ? ? ? ? ? ?}
>
> - ? ? ? ? ? ? ? ? ? ? push_stmt_changes (gsi_stmt_ptr (&gsi));
> ? ? ? ? ? ? ? ? ? ? ?gimple_call_set_lhs (stmt, NULL_TREE);
> ? ? ? ? ? ? ? ? ? ? ?maybe_clean_or_replace_eh_stmt (stmt, stmt);
> - ? ? ? ? ? ? ? ? ? ? pop_stmt_changes (gsi_stmt_ptr (&gsi));
> + ? ? ? ? ? ? ? ? ? ? update_stmt (stmt);
> ? ? ? ? ? ? ? ? ? ? ?release_ssa_name (name);
> ? ? ? ? ? ? ? ? ? ?}
> ? ? ? ? ? ? ? ? ?notice_special_calls (stmt);
> Index: gcc/tree-ssa-forwprop.c
> ===================================================================
> --- gcc/tree-ssa-forwprop.c ? ? (branch kill-push-pop-stmt-changes)
> +++ gcc/tree-ssa-forwprop.c ? ? (working copy)
> @@ -939,19 +939,17 @@ forward_propagate_addr_expr (tree name,
>
> ? ? ? {
> ? ? ? ?gimple_stmt_iterator gsi = gsi_for_stmt (use_stmt);
> - ? ? ? push_stmt_changes (&use_stmt);
> ? ? ? ?result = forward_propagate_addr_expr_1 (name, rhs, &gsi,
> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?single_use_p);
> ? ? ? ?/* If the use has moved to a different statement adjust
> - ? ? ? ? ?the update machinery. ?*/
> + ? ? ? ? ?the update machinery for the old statement too. ?*/
> ? ? ? ?if (use_stmt != gsi_stmt (gsi))
> ? ? ? ? ?{
> - ? ? ? ? ? pop_stmt_changes (&use_stmt);
> - ? ? ? ? ? use_stmt = gsi_stmt (gsi);
> ? ? ? ? ? ?update_stmt (use_stmt);
> + ? ? ? ? ? use_stmt = gsi_stmt (gsi);
> ? ? ? ? ?}
> - ? ? ? else
> - ? ? ? ? pop_stmt_changes (&use_stmt);
> +
> + ? ? ? update_stmt (use_stmt);
> ? ? ? }
> ? ? ? all &= result;
>
> Index: gcc/tree-ssa-loop-ivopts.c
> ===================================================================
> --- gcc/tree-ssa-loop-ivopts.c ?(branch kill-push-pop-stmt-changes)
> +++ gcc/tree-ssa-loop-ivopts.c ?(working copy)
> @@ -5304,8 +5304,6 @@ rewrite_use_compare (struct ivopts_data
> ?static void
> ?rewrite_use (struct ivopts_data *data, struct iv_use *use, struct iv_cand *cand)
> ?{
> - ?push_stmt_changes (&use->stmt);
> -
> ? switch (use->type)
> ? ? {
> ? ? ? case USE_NONLINEAR_EXPR:
> @@ -5323,8 +5321,8 @@ rewrite_use (struct ivopts_data *data, s
> ? ? ? default:
> ? ? ? ?gcc_unreachable ();
> ? ? }
> -
> - ?pop_stmt_changes (&use->stmt);
> +
> + ?update_stmt (use->stmt);
> ?}
>
> ?/* Rewrite the uses using the selected induction variables. ?*/
> Index: gcc/tree-ssa-propagate.c
> ===================================================================
> --- gcc/tree-ssa-propagate.c ? ?(branch kill-push-pop-stmt-changes)
> +++ gcc/tree-ssa-propagate.c ? ?(working copy)
> @@ -1109,9 +1109,6 @@ substitute_and_fold (prop_value_t *prop_
> ? ? ? ? ? ? ?continue;
> ? ? ? ? ? ?}
>
> - ? ? ? ? /* Record the state of the statement before replacements. ?*/
> - ? ? ? ? push_stmt_changes (gsi_stmt_ptr (&i));
> -
> ? ? ? ? ?/* Replace the statement with its folded version and mark it
> ? ? ? ? ? ? folded. ?*/
> ? ? ? ? ?did_replace = false;
> @@ -1172,14 +1169,9 @@ substitute_and_fold (prop_value_t *prop_
> ? ? ? ? ? ? ? }
>
> ? ? ? ? ? ? ?/* Determine what needs to be done to update the SSA form. ?*/
> - ? ? ? ? ? ? pop_stmt_changes (gsi_stmt_ptr (&i));
> + ? ? ? ? ? ? update_stmt (stmt);
> ? ? ? ? ? ? ?something_changed = true;
> ? ? ? ? ? ?}
> - ? ? ? ? else
> - ? ? ? ? ? {
> - ? ? ? ? ? ? /* The statement was not modified, discard the change buffer. ?*/
> - ? ? ? ? ? ? discard_stmt_changes (gsi_stmt_ptr (&i));
> - ? ? ? ? ? }
>
> ? ? ? ? ?if (dump_file && (dump_flags & TDF_DETAILS))
> ? ? ? ? ? ?{
> Index: gcc/tree-ssa-dom.c
> ===================================================================
> --- gcc/tree-ssa-dom.c ?(branch kill-push-pop-stmt-changes)
> +++ gcc/tree-ssa-dom.c ?(working copy)
> @@ -134,7 +134,7 @@ static VEC(expr_hash_elt_t,heap) *avail_
> ? ?expressions are removed from AVAIL_EXPRS. ?Else we may change the
> ? ?hash code for an expression and be unable to find/remove it from
> ? ?AVAIL_EXPRS. ?*/
> -static VEC(gimple_p,heap) *stmts_to_rescan;
> +static VEC(gimple,heap) *stmts_to_rescan;
>
> ?/* Structure for entries in the expression hash table. ?*/
>
> @@ -626,7 +626,7 @@ tree_ssa_dominator_optimize (void)
> ? avail_exprs = htab_create (1024, real_avail_expr_hash, avail_expr_eq, free_expr_hash_elt);
> ? avail_exprs_stack = VEC_alloc (expr_hash_elt_t, heap, 20);
> ? const_and_copies_stack = VEC_alloc (tree, heap, 20);
> - ?stmts_to_rescan = VEC_alloc (gimple_p, heap, 20);
> + ?stmts_to_rescan = VEC_alloc (gimple, heap, 20);
> ? need_eh_cleanup = BITMAP_ALLOC (NULL);
>
> ? /* Setup callbacks for the generic dominator tree walker. ?*/
> @@ -742,7 +742,7 @@ tree_ssa_dominator_optimize (void)
>
> ? VEC_free (expr_hash_elt_t, heap, avail_exprs_stack);
> ? VEC_free (tree, heap, const_and_copies_stack);
> - ?VEC_free (gimple_p, heap, stmts_to_rescan);
> + ?VEC_free (gimple, heap, stmts_to_rescan);
>
> ? /* Free the value-handle array. ?*/
> ? threadedge_finalize_values ();
> @@ -1047,17 +1047,16 @@ dom_opt_finalize_block (struct dom_walk_
>
> ? /* If we queued any statements to rescan in this block, then
> ? ? ?go ahead and rescan them now. ?*/
> - ?while (VEC_length (gimple_p, stmts_to_rescan) > 0)
> + ?while (VEC_length (gimple, stmts_to_rescan) > 0)
> ? ? {
> - ? ? ?gimple *stmt_p = VEC_last (gimple_p, stmts_to_rescan);
> - ? ? ?gimple stmt = *stmt_p;
> + ? ? ?gimple stmt = VEC_last (gimple, stmts_to_rescan);
> ? ? ? basic_block stmt_bb = gimple_bb (stmt);
>
> ? ? ? if (stmt_bb != bb)
> ? ? ? ?break;
>
> - ? ? ?VEC_pop (gimple_p, stmts_to_rescan);
> - ? ? ?pop_stmt_changes (stmt_p);
> + ? ? ?VEC_pop (gimple, stmts_to_rescan);
> + ? ? ?update_stmt (stmt);
> ? ? }
> ?}
>
> @@ -2130,7 +2129,6 @@ optimize_stmt (struct dom_walk_data *wal
>
> ? update_stmt_if_modified (stmt);
> ? opt_stats.num_stmts++;
> - ?push_stmt_changes (gsi_stmt_ptr (&si));
>
> ? if (dump_file && (dump_flags & TDF_DETAILS))
> ? ? {
> @@ -2253,21 +2251,12 @@ optimize_stmt (struct dom_walk_data *wal
> ? ? ? ?}
> ? ? }
>
> + ?/* Queue the statement to be re-scanned after all the
> + ? ? AVAIL_EXPRS have been processed. ?The change buffer stack for
> + ? ? all the pushed statements will be processed when this queue
> + ? ? is emptied. ?*/
> ? if (may_have_exposed_new_symbols)
> - ? ?{
> - ? ? ?/* Queue the statement to be re-scanned after all the
> - ? ? ? ?AVAIL_EXPRS have been processed. ?The change buffer stack for
> - ? ? ? ?all the pushed statements will be processed when this queue
> - ? ? ? ?is emptied. ?*/
> - ? ? ?VEC_safe_push (gimple_p, heap, stmts_to_rescan, gsi_stmt_ptr (&si));
> - ? ?}
> - ?else
> - ? ?{
> - ? ? ?/* Otherwise, just discard the recently pushed change buffer. ?If
> - ? ? ? ?not, the STMTS_TO_RESCAN queue will get out of synch with the
> - ? ? ? ?change buffer stack. ?*/
> - ? ? ?discard_stmt_changes (gsi_stmt_ptr (&si));
> - ? ?}
> + ? ?VEC_safe_push (gimple, heap, stmts_to_rescan, gsi_stmt (si));
> ?}
>
> ?/* Search for an existing instance of STMT in the AVAIL_EXPRS table.
> @@ -2565,8 +2554,6 @@ propagate_rhs_into_lhs (gimple stmt, tre
> ? ? ? ? ? ? ?print_gimple_stmt (dump_file, use_stmt, 0, dump_flags);
> ? ? ? ? ? ?}
>
> - ? ? ? ? push_stmt_changes (&use_stmt);
> -
> ? ? ? ? ?/* Propagate the RHS into this use of the LHS. ?*/
> ? ? ? ? ?FOR_EACH_IMM_USE_ON_STMT (use_p, iter)
> ? ? ? ? ? ?propagate_value (use_p, rhs);
> @@ -2601,7 +2588,6 @@ propagate_rhs_into_lhs (gimple stmt, tre
> ? ? ? ? ? ? ? ? ?bitmap_set_bit (interesting_names, SSA_NAME_VERSION (result));
> ? ? ? ? ? ? ? ?}
>
> - ? ? ? ? ? ? discard_stmt_changes (&use_stmt);
> ? ? ? ? ? ? ?continue;
> ? ? ? ? ? ?}
>
> @@ -2618,9 +2604,8 @@ propagate_rhs_into_lhs (gimple stmt, tre
> ? ? ? ? ?fold_stmt_inplace (use_stmt);
>
> ? ? ? ? ?/* Sometimes propagation can expose new operands to the
> - ? ? ? ? ? ?renamer. ?Note this will call update_stmt at the
> - ? ? ? ? ? ?appropriate time. ?*/
> - ? ? ? ? pop_stmt_changes (&use_stmt);
> + ? ? ? ? ? ?renamer. ?*/
> + ? ? ? ? update_stmt (use_stmt);
>
> ? ? ? ? ?/* Dump details. ?*/
> ? ? ? ? ?if (dump_file && (dump_flags & TDF_DETAILS))
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]