]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Introduce build_debug_expr_decl
authorMartin Jambor <mjambor@suse.cz>
Tue, 9 Nov 2021 16:54:23 +0000 (17:54 +0100)
committerMartin Jambor <mjambor@suse.cz>
Tue, 9 Nov 2021 16:54:28 +0000 (17:54 +0100)
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.

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
gcc/ipa-param-manipulation.c
gcc/omp-simd-clone.c
gcc/tree-ssa-ccp.c
gcc/tree-ssa-phiopt.c
gcc/tree-ssa-reassoc.c
gcc/tree.c
gcc/tree.h

index 01d0cdc548aabf04ea108e855489ea1241f8953e..55ff75bd78e369c783e0f04fa6322e837d9f2940 100644 (file)
@@ -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);
index 4610fc4ac030f0fcd9eb47221491f4743de034f6..ae3149718ca2e92cad3398beca201bd1a3370ab4 100644 (file)
@@ -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;
index b772b7ff52004c3fb93c76c051bfc9fe9ef33f0b..4d43a86669a8c4b237b1f1b200090cb99e834022 100644 (file)
@@ -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
index 70ce6a4d5b8d1e88e3983ea52aab2944807893c1..60ae5e6601f2c9717c18c2a3d20649b42e00b474 100644 (file)
@@ -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)
index 0e339c46afa29fa97f90d9bc4394370cd9b4b396..173ac835ca62ba92931e4970b51bcfc5ee35d296 100644 (file)
@@ -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);
index db9fb4e1cac8e7428cf6f2e6dcdf3044d9c3f07c..6a555e7c553b6f6ee9567d67d93473930a7b18e8 100644 (file)
@@ -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);
index 7bfd64160f4e4bf8aae5c704fa30b80d80edb13f..845228a055b2cfac0c9ca8c0cda1b9df4b0095c6 100644 (file)
@@ -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
index 7542d97ce12154cf08b023a2b31a0756c5709aa9..f62c00bc8707029db52e2f3fe529948755235d3d 100644 (file)
@@ -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);