[PATCH] Introduce build_debug_expr_decl

Richard Biener rguenther@suse.de
Tue Nov 9 07:39:07 GMT 2021


On Mon, 8 Nov 2021, Martin Jambor wrote:

> Hi,
> 
> this patch introduces a helper function build_debug_expr_decl to build
> DEBUG_EXPR_DECL tree nodes in the most common way and replaces with a
> call of this function all code pieces which build such a DECL itself
> and sets its mode to the TYPE_MODE of its type.
> 
> There still remain 11 instances of open-coded creation of a
> DEBUG_EXPR_DECL which set the mode of the DECL to something else.  It
> would probably be a good idea to figure out that has any effect and if
> not, convert them to calls of build_debug_expr_decl too.  But this
> patch deliberately does not introduce any functional changes.
> 
> Bootstrapped and tested on x86_64-linux, OK for trunk?

OK (the const_tree suggestion is a good one).

For the remaining cases I'd simply use

decl = build_debug_expr_decl (type);
SET_DECL_MODE (decl) = ...;

and thus override the mode afterwards, maybe adding a comment to
check whether that's necessary.  As said, the only case where it
might matter is when we create a debug decl replacement for a FIELD_DECL,
so maybe for those SRA things we create for DWARF "piece" info?

Richard.

> Thanks,
> 
> Martin
> 
> 
> gcc/ChangeLog:
> 
> 2021-11-08  Martin Jambor  <mjambor@suse.cz>
> 
> 	* tree.h (build_debug_expr_decl): Declare.
> 	* tree.c (build_debug_expr_decl): New function.
> 	* cfgexpand.c (avoid_deep_ter_for_debug): Use build_debug_expr_decl
> 	instead of building a DEBUG_EXPR_DECL.
> 	* ipa-param-manipulation.c
> 	(ipa_param_body_adjustments::prepare_debug_expressions): Likewise.
> 	* omp-simd-clone.c (ipa_simd_modify_stmt_ops): Likewise.
> 	* tree-ssa-ccp.c (optimize_atomic_bit_test_and): Likewise.
> 	* tree-ssa-phiopt.c (spaceship_replacement): Likewise.
> 	* tree-ssa-reassoc.c (make_new_ssa_for_def): Likewise.
> ---
>  gcc/cfgexpand.c              |  5 +----
>  gcc/ipa-param-manipulation.c |  5 +----
>  gcc/omp-simd-clone.c         |  5 +----
>  gcc/tree-ssa-ccp.c           |  5 +----
>  gcc/tree-ssa-phiopt.c        | 10 ++--------
>  gcc/tree-ssa-reassoc.c       |  5 +----
>  gcc/tree.c                   | 12 ++++++++++++
>  gcc/tree.h                   |  1 +
>  8 files changed, 20 insertions(+), 28 deletions(-)
> 
> diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c
> index 01d0cdc548a..55ff75bd78e 100644
> --- a/gcc/cfgexpand.c
> +++ b/gcc/cfgexpand.c
> @@ -4341,11 +4341,8 @@ avoid_deep_ter_for_debug (gimple *stmt, int depth)
>  	  tree &vexpr = deep_ter_debug_map->get_or_insert (use);
>  	  if (vexpr != NULL)
>  	    continue;
> -	  vexpr = make_node (DEBUG_EXPR_DECL);
> +	  vexpr = build_debug_expr_decl (TREE_TYPE (use));
>  	  gimple *def_temp = gimple_build_debug_bind (vexpr, use, g);
> -	  DECL_ARTIFICIAL (vexpr) = 1;
> -	  TREE_TYPE (vexpr) = TREE_TYPE (use);
> -	  SET_DECL_MODE (vexpr, TYPE_MODE (TREE_TYPE (use)));
>  	  gimple_stmt_iterator gsi = gsi_for_stmt (g);
>  	  gsi_insert_after (&gsi, def_temp, GSI_NEW_STMT);
>  	  avoid_deep_ter_for_debug (def_temp, 0);
> diff --git a/gcc/ipa-param-manipulation.c b/gcc/ipa-param-manipulation.c
> index 4610fc4ac03..ae3149718ca 100644
> --- a/gcc/ipa-param-manipulation.c
> +++ b/gcc/ipa-param-manipulation.c
> @@ -1200,10 +1200,7 @@ ipa_param_body_adjustments::prepare_debug_expressions (tree dead_ssa)
>  	= unshare_expr_without_location (gimple_assign_rhs_to_tree (def));
>        remap_with_debug_expressions (&val);
>  
> -      tree vexpr = make_node (DEBUG_EXPR_DECL);
> -      DECL_ARTIFICIAL (vexpr) = 1;
> -      TREE_TYPE (vexpr) = TREE_TYPE (val);
> -      SET_DECL_MODE (vexpr, TYPE_MODE (TREE_TYPE (val)));
> +      tree vexpr = build_debug_expr_decl (TREE_TYPE (val));
>        m_dead_stmt_debug_equiv.put (def, val);
>        m_dead_ssa_debug_equiv.put (dead_ssa, vexpr);
>        return true;
> diff --git a/gcc/omp-simd-clone.c b/gcc/omp-simd-clone.c
> index b772b7ff520..4d43a86669a 100644
> --- a/gcc/omp-simd-clone.c
> +++ b/gcc/omp-simd-clone.c
> @@ -910,11 +910,8 @@ ipa_simd_modify_stmt_ops (tree *tp, int *walk_subtrees, void *data)
>        gimple *stmt;
>        if (is_gimple_debug (info->stmt))
>  	{
> -	  tree vexpr = make_node (DEBUG_EXPR_DECL);
> +	  tree vexpr = build_debug_expr_decl (TREE_TYPE (repl));
>  	  stmt = gimple_build_debug_source_bind (vexpr, repl, NULL);
> -	  DECL_ARTIFICIAL (vexpr) = 1;
> -	  TREE_TYPE (vexpr) = TREE_TYPE (repl);
> -	  SET_DECL_MODE (vexpr, TYPE_MODE (TREE_TYPE (repl)));
>  	  repl = vexpr;
>  	}
>        else
> diff --git a/gcc/tree-ssa-ccp.c b/gcc/tree-ssa-ccp.c
> index 70ce6a4d5b8..60ae5e6601f 100644
> --- a/gcc/tree-ssa-ccp.c
> +++ b/gcc/tree-ssa-ccp.c
> @@ -3452,10 +3452,7 @@ optimize_atomic_bit_test_and (gimple_stmt_iterator *gsip,
>        tree temp = NULL_TREE;
>        if (!throws || after || single_pred_p (e->dest))
>  	{
> -	  temp = make_node (DEBUG_EXPR_DECL);
> -	  DECL_ARTIFICIAL (temp) = 1;
> -	  TREE_TYPE (temp) = TREE_TYPE (lhs);
> -	  SET_DECL_MODE (temp, TYPE_MODE (TREE_TYPE (lhs)));
> +	  temp = build_debug_expr_decl (TREE_TYPE (lhs));
>  	  tree t = build2 (LSHIFT_EXPR, TREE_TYPE (lhs), new_lhs, bit);
>  	  g = gimple_build_debug_bind (temp, t, g);
>  	  if (throws && !after)
> diff --git a/gcc/tree-ssa-phiopt.c b/gcc/tree-ssa-phiopt.c
> index 0e339c46afa..173ac835ca6 100644
> --- a/gcc/tree-ssa-phiopt.c
> +++ b/gcc/tree-ssa-phiopt.c
> @@ -2429,19 +2429,13 @@ spaceship_replacement (basic_block cond_bb, basic_block middle_bb,
>  	     all floating point numbers should be comparable.  */
>  	  gimple_stmt_iterator gsi = gsi_after_labels (gimple_bb (phi));
>  	  tree type = TREE_TYPE (phires);
> -	  tree temp1 = make_node (DEBUG_EXPR_DECL);
> -	  DECL_ARTIFICIAL (temp1) = 1;
> -	  TREE_TYPE (temp1) = type;
> -	  SET_DECL_MODE (temp1, TYPE_MODE (type));
> +	  tree temp1 = build_debug_expr_decl (type);
>  	  tree t = build2 (one_cmp, boolean_type_node, lhs1, rhs2);
>  	  t = build3 (COND_EXPR, type, t, build_one_cst (type),
>  		      build_int_cst (type, -1));
>  	  gimple *g = gimple_build_debug_bind (temp1, t, phi);
>  	  gsi_insert_before (&gsi, g, GSI_SAME_STMT);
> -	  tree temp2 = make_node (DEBUG_EXPR_DECL);
> -	  DECL_ARTIFICIAL (temp2) = 1;
> -	  TREE_TYPE (temp2) = type;
> -	  SET_DECL_MODE (temp2, TYPE_MODE (type));
> +	  tree temp2 = build_debug_expr_decl (type);
>  	  t = build2 (EQ_EXPR, boolean_type_node, lhs1, rhs2);
>  	  t = build3 (COND_EXPR, type, t, build_zero_cst (type), temp1);
>  	  g = gimple_build_debug_bind (temp2, t, phi);
> diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c
> index db9fb4e1cac..6a555e7c553 100644
> --- a/gcc/tree-ssa-reassoc.c
> +++ b/gcc/tree-ssa-reassoc.c
> @@ -1259,15 +1259,12 @@ make_new_ssa_for_def (gimple *stmt, enum tree_code opcode, tree op)
>  	{
>  	  if (new_debug_lhs == NULL_TREE)
>  	    {
> -	      new_debug_lhs = make_node (DEBUG_EXPR_DECL);
> +	      new_debug_lhs = build_debug_expr_decl (TREE_TYPE (lhs));
>  	      gdebug *def_temp
>  		= gimple_build_debug_bind (new_debug_lhs,
>  					   build2 (opcode, TREE_TYPE (lhs),
>  						   new_lhs, op),
>  					   stmt);
> -	      DECL_ARTIFICIAL (new_debug_lhs) = 1;
> -	      TREE_TYPE (new_debug_lhs) = TREE_TYPE (lhs);
> -	      SET_DECL_MODE (new_debug_lhs, TYPE_MODE (TREE_TYPE (lhs)));
>  	      gimple_set_uid (def_temp, gimple_uid (stmt));
>  	      gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
>  	      gsi_insert_after (&gsi, def_temp, GSI_SAME_STMT);
> diff --git a/gcc/tree.c b/gcc/tree.c
> index 7bfd64160f4..845228a055b 100644
> --- a/gcc/tree.c
> +++ b/gcc/tree.c
> @@ -5280,6 +5280,18 @@ build_decl (location_t loc, enum tree_code code, tree name,
>    return t;
>  }
>  
> +/* Create and return a DEBUG_EXPR_DECL node of the given TYPE.  */
> +
> +tree
> +build_debug_expr_decl (tree type)
> +{
> +  tree vexpr = make_node (DEBUG_EXPR_DECL);
> +  DECL_ARTIFICIAL (vexpr) = 1;
> +  TREE_TYPE (vexpr) = type;
> +  SET_DECL_MODE (vexpr, TYPE_MODE (type));
> +  return vexpr;
> +}
> +
>  /* Builds and returns function declaration with NAME and TYPE.  */
>  
>  tree
> diff --git a/gcc/tree.h b/gcc/tree.h
> index 7542d97ce12..f62c00bc870 100644
> --- a/gcc/tree.h
> +++ b/gcc/tree.h
> @@ -4567,6 +4567,7 @@ extern tree build_tree_list (tree, tree CXX_MEM_STAT_INFO);
>  extern tree build_tree_list_vec (const vec<tree, va_gc> * CXX_MEM_STAT_INFO);
>  extern tree build_decl (location_t, enum tree_code,
>  			tree, tree CXX_MEM_STAT_INFO);
> +extern tree build_debug_expr_decl (tree type);
>  extern tree build_fn_decl (const char *, tree);
>  extern tree build_translation_unit_decl (tree);
>  extern tree build_block (tree, tree, tree, tree);
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg,
Germany; GF: Ivo Totev; HRB 36809 (AG Nuernberg)


More information about the Gcc-patches mailing list