public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Early "SSA" prerequesite - make SSA def stmt update cheaper
@ 2016-01-21 13:57 Richard Biener
  2016-04-19 12:14 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Richard Biener @ 2016-01-21 13:57 UTC (permalink / raw)
  To: gcc-patches


This makes the SSA def stmt update during inlining cheaper by adjusting
it after remapping a SSA def instead of via an extra walk over all stmt
defs (which incidentially is not possible with FOR_EACH_SSA_* during
"early SSA" as we don't have SSA operands there).

I've tested this independently of the
[RFC] Delayed folding, match-and-simplify and early GIMPLE
patch.

This exposes that the walk_gimple_* stuff is somewhat awkward and
needs some refactoring (can't re-construct wi->gsi as gsi_for_stmt
only works for stmts in a BB and thus when we have a CFG).  Need to
think about sth (simplest is require a gsi for walk_gimple_op, like
we do for walk_gimple_stmt).

Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.

Queued for GCC 7.

Richard.

2016-01-21  Richard Biener  <rguenther@suse.de>

	* gimple-walk.h (struct walk_stmt_info): Add stmt member.
	* gimple-walk.c (walk_gimple_op): Initialize it.
	(walk_gimple_asm): Set wi->is_lhs before each callback invocation.
	* tree-inline.c (remap_gimple_op_r): Set SSA_NAME_DEF_STMT when
	remapping SSA names of defs.
	(copy_bb): Remove walk over all SSA defs and SSA_NAME_DEF_STMT
	adjustment.

Index: gcc/gimple-walk.c
===================================================================
*** gcc/gimple-walk.c	(revision 232670)
--- gcc/gimple-walk.c	(working copy)
*************** walk_gimple_asm (gasm *stmt, walk_tree_f
*** 100,108 ****
    noutputs = gimple_asm_noutputs (stmt);
    oconstraints = (const char **) alloca ((noutputs) * sizeof (const char *));
  
-   if (wi)
-     wi->is_lhs = true;
- 
    for (i = 0; i < noutputs; i++)
      {
        op = gimple_asm_output_op (stmt, i);
--- 100,105 ----
*************** walk_gimple_asm (gasm *stmt, walk_tree_f
*** 114,119 ****
--- 111,118 ----
  				       &allows_reg, &is_inout))
  	    wi->val_only = (allows_reg || !allows_mem);
  	}
+       if (wi)
+ 	wi->is_lhs = true;
        ret = walk_tree (&TREE_VALUE (op), callback_op, wi, NULL);
        if (ret)
  	return ret;
*************** walk_gimple_op (gimple *stmt, walk_tree_
*** 182,187 ****
--- 181,189 ----
    unsigned i;
    tree ret = NULL_TREE;
  
+   if (wi)
+     wi->stmt = stmt;
+ 
    switch (gimple_code (stmt))
      {
      case GIMPLE_ASSIGN:
Index: gcc/gimple-walk.h
===================================================================
*** gcc/gimple-walk.h	(revision 232670)
--- gcc/gimple-walk.h	(working copy)
*************** struct walk_stmt_info
*** 28,33 ****
--- 28,34 ----
  {
    /* Points to the current statement being walked.  */
    gimple_stmt_iterator gsi;
+   gimple *stmt;
  
    /* Additional data that the callback functions may want to carry
       through the recursion.  */
Index: gcc/tree-inline.c
===================================================================
*** gcc/tree-inline.c	(revision 232670)
--- gcc/tree-inline.c	(working copy)
*************** remap_gimple_op_r (tree *tp, int *walk_s
*** 862,871 ****
--- 862,877 ----
    copy_body_data *id = (copy_body_data *) wi_p->info;
    tree fn = id->src_fn;
  
+   /* For recursive invocations this is no longer the LHS itself.  */
+   bool is_lhs = wi_p->is_lhs;
+   wi_p->is_lhs = false;
+ 
    if (TREE_CODE (*tp) == SSA_NAME)
      {
        *tp = remap_ssa_name (*tp, id);
        *walk_subtrees = 0;
+       if (is_lhs)
+ 	SSA_NAME_DEF_STMT (*tp) = wi_p->stmt;
        return NULL;
      }
    else if (auto_var_in_fn_p (*tp, fn))
*************** copy_bb (copy_body_data *id, basic_block
*** 2089,2104 ****
  	  maybe_duplicate_eh_stmt_fn (cfun, stmt, id->src_cfun, orig_stmt,
  				      id->eh_map, id->eh_lp_nr);
  
- 	  if (gimple_in_ssa_p (cfun) && !is_gimple_debug (stmt))
- 	    {
- 	      ssa_op_iter i;
- 	      tree def;
- 
- 	      FOR_EACH_SSA_TREE_OPERAND (def, stmt, i, SSA_OP_DEF)
- 		if (TREE_CODE (def) == SSA_NAME)
- 		  SSA_NAME_DEF_STMT (def) = stmt;
- 	    }
- 
  	  gsi_next (&copy_gsi);
  	}
        while (!gsi_end_p (copy_gsi));
--- 2095,2100 ----

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Early "SSA" prerequesite - make SSA def stmt update cheaper
  2016-01-21 13:57 [PATCH] Early "SSA" prerequesite - make SSA def stmt update cheaper Richard Biener
@ 2016-04-19 12:14 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2016-04-19 12:14 UTC (permalink / raw)
  To: GCC Patches

On Thu, Jan 21, 2016 at 2:57 PM, Richard Biener <rguenther@suse.de> wrote:
>
> This makes the SSA def stmt update during inlining cheaper by adjusting
> it after remapping a SSA def instead of via an extra walk over all stmt
> defs (which incidentially is not possible with FOR_EACH_SSA_* during
> "early SSA" as we don't have SSA operands there).
>
> I've tested this independently of the
> [RFC] Delayed folding, match-and-simplify and early GIMPLE
> patch.
>
> This exposes that the walk_gimple_* stuff is somewhat awkward and
> needs some refactoring (can't re-construct wi->gsi as gsi_for_stmt
> only works for stmts in a BB and thus when we have a CFG).  Need to
> think about sth (simplest is require a gsi for walk_gimple_op, like
> we do for walk_gimple_stmt).
>
> Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.
>
> Queued for GCC 7.

Re-bootstrapped and tested on x86_64-unknown-linux-gnu, applied
to trunk as r235190.

Richard.

> Richard.
>
> 2016-01-21  Richard Biener  <rguenther@suse.de>
>
>         * gimple-walk.h (struct walk_stmt_info): Add stmt member.
>         * gimple-walk.c (walk_gimple_op): Initialize it.
>         (walk_gimple_asm): Set wi->is_lhs before each callback invocation.
>         * tree-inline.c (remap_gimple_op_r): Set SSA_NAME_DEF_STMT when
>         remapping SSA names of defs.
>         (copy_bb): Remove walk over all SSA defs and SSA_NAME_DEF_STMT
>         adjustment.
>
> Index: gcc/gimple-walk.c
> ===================================================================
> *** gcc/gimple-walk.c   (revision 232670)
> --- gcc/gimple-walk.c   (working copy)
> *************** walk_gimple_asm (gasm *stmt, walk_tree_f
> *** 100,108 ****
>     noutputs = gimple_asm_noutputs (stmt);
>     oconstraints = (const char **) alloca ((noutputs) * sizeof (const char *));
>
> -   if (wi)
> -     wi->is_lhs = true;
> -
>     for (i = 0; i < noutputs; i++)
>       {
>         op = gimple_asm_output_op (stmt, i);
> --- 100,105 ----
> *************** walk_gimple_asm (gasm *stmt, walk_tree_f
> *** 114,119 ****
> --- 111,118 ----
>                                        &allows_reg, &is_inout))
>             wi->val_only = (allows_reg || !allows_mem);
>         }
> +       if (wi)
> +       wi->is_lhs = true;
>         ret = walk_tree (&TREE_VALUE (op), callback_op, wi, NULL);
>         if (ret)
>         return ret;
> *************** walk_gimple_op (gimple *stmt, walk_tree_
> *** 182,187 ****
> --- 181,189 ----
>     unsigned i;
>     tree ret = NULL_TREE;
>
> +   if (wi)
> +     wi->stmt = stmt;
> +
>     switch (gimple_code (stmt))
>       {
>       case GIMPLE_ASSIGN:
> Index: gcc/gimple-walk.h
> ===================================================================
> *** gcc/gimple-walk.h   (revision 232670)
> --- gcc/gimple-walk.h   (working copy)
> *************** struct walk_stmt_info
> *** 28,33 ****
> --- 28,34 ----
>   {
>     /* Points to the current statement being walked.  */
>     gimple_stmt_iterator gsi;
> +   gimple *stmt;
>
>     /* Additional data that the callback functions may want to carry
>        through the recursion.  */
> Index: gcc/tree-inline.c
> ===================================================================
> *** gcc/tree-inline.c   (revision 232670)
> --- gcc/tree-inline.c   (working copy)
> *************** remap_gimple_op_r (tree *tp, int *walk_s
> *** 862,871 ****
> --- 862,877 ----
>     copy_body_data *id = (copy_body_data *) wi_p->info;
>     tree fn = id->src_fn;
>
> +   /* For recursive invocations this is no longer the LHS itself.  */
> +   bool is_lhs = wi_p->is_lhs;
> +   wi_p->is_lhs = false;
> +
>     if (TREE_CODE (*tp) == SSA_NAME)
>       {
>         *tp = remap_ssa_name (*tp, id);
>         *walk_subtrees = 0;
> +       if (is_lhs)
> +       SSA_NAME_DEF_STMT (*tp) = wi_p->stmt;
>         return NULL;
>       }
>     else if (auto_var_in_fn_p (*tp, fn))
> *************** copy_bb (copy_body_data *id, basic_block
> *** 2089,2104 ****
>           maybe_duplicate_eh_stmt_fn (cfun, stmt, id->src_cfun, orig_stmt,
>                                       id->eh_map, id->eh_lp_nr);
>
> -         if (gimple_in_ssa_p (cfun) && !is_gimple_debug (stmt))
> -           {
> -             ssa_op_iter i;
> -             tree def;
> -
> -             FOR_EACH_SSA_TREE_OPERAND (def, stmt, i, SSA_OP_DEF)
> -               if (TREE_CODE (def) == SSA_NAME)
> -                 SSA_NAME_DEF_STMT (def) = stmt;
> -           }
> -
>           gsi_next (&copy_gsi);
>         }
>         while (!gsi_end_p (copy_gsi));
> --- 2095,2100 ----

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-04-19 12:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-21 13:57 [PATCH] Early "SSA" prerequesite - make SSA def stmt update cheaper Richard Biener
2016-04-19 12:14 ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).