Just found this in one of my dev trees and think it's suitable at
this stage as a general speedup.

gimple_block involves querying an on-the-side map in libcpp
since it is encoded in the location_t location.  This means
caching is beneficial.  It's also pointless to copy
gimple_block once you've copied gimple_location.

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

Richard.

2019-03-26  Richard Biener  <rguent...@suse.de>

        * tree-inline.c (remap_gimple_stmt): Cache gimple_block.
        (copy_debug_stmt): Likewise.
        (expand_call_inline): Likewise.
        (copy_bb): Avoid redundant lookup & set of gimple_block.
        * gimple-low.c (lower_gimple_return): Likewise.
        (lower_builtin_setjmp): Likewise.

Index: gcc/tree-inline.c
===================================================================
--- gcc/tree-inline.c   (revision 269937)
+++ gcc/tree-inline.c   (working copy)
@@ -1776,10 +1776,10 @@ remap_gimple_stmt (gimple *stmt, copy_bo
     }
 
   /* If STMT has a block defined, map it to the newly constructed block.  */
-  if (gimple_block (copy))
+  if (tree block = gimple_block (copy))
     {
       tree *n;
-      n = id->decl_map->get (gimple_block (copy));
+      n = id->decl_map->get (block);
       gcc_assert (n);
       gimple_set_block (copy, *n);
     }
@@ -1951,8 +1951,8 @@ copy_bb (copy_body_data *id, basic_block
                 GF_CALL_VA_ARG_PACK.  */
              gimple_call_copy_flags (new_call, call_stmt);
              gimple_call_set_va_arg_pack (new_call, false);
+             /* location includes block.  */
              gimple_set_location (new_call, gimple_location (stmt));
-             gimple_set_block (new_call, gimple_block (stmt));
              gimple_call_set_lhs (new_call, gimple_call_lhs (call_stmt));
 
              gsi_replace (&copy_gsi, new_call, false);
@@ -2891,9 +2891,9 @@ copy_debug_stmt (gdebug *stmt, copy_body
   tree t, *n;
   struct walk_stmt_info wi;
 
-  if (gimple_block (stmt))
+  if (tree block = gimple_block (stmt))
     {
-      n = id->decl_map->get (gimple_block (stmt));
+      n = id->decl_map->get (block);
       gimple_set_block (stmt, n ? *n : id->block);
     }
 
@@ -4589,7 +4589,7 @@ expand_call_inline (basic_block bb, gimp
      artificial decls inserted by the compiler itself.  We need to
      either link the inlined blocks into the caller block tree or
      not refer to them in any way to not break GC for locations.  */
-  if (gimple_block (stmt))
+  if (tree block = gimple_block (stmt))
     {
       /* We do want to assign a not UNKNOWN_LOCATION BLOCK_SOURCE_LOCATION
          to make inlined_function_outer_scope_p return true on this BLOCK.  */
@@ -4601,7 +4601,7 @@ expand_call_inline (basic_block bb, gimp
       id->block = make_node (BLOCK);
       BLOCK_ABSTRACT_ORIGIN (id->block) = DECL_ORIGIN (fn);
       BLOCK_SOURCE_LOCATION (id->block) = loc;
-      prepend_lexical_block (gimple_block (stmt), id->block);
+      prepend_lexical_block (block, id->block);
     }
 
   /* Local declarations will be replaced by their equivalents in this map.  */
Index: gcc/gimple-low.c
===================================================================
--- gcc/gimple-low.c    (revision 269939)
+++ gcc/gimple-low.c    (working copy)
@@ -723,8 +723,8 @@ lower_gimple_return (gimple_stmt_iterato
   if (!optimize && gimple_has_location (stmt))
     DECL_ARTIFICIAL (tmp_rs.label) = 0;
   t = gimple_build_goto (tmp_rs.label);
+  /* location includes block.  */
   gimple_set_location (t, gimple_location (stmt));
-  gimple_set_block (t, gimple_block (stmt));
   gsi_insert_before (gsi, t, GSI_SAME_STMT);
   gsi_remove (gsi, false);
 }
@@ -806,8 +806,8 @@ lower_builtin_setjmp (gimple_stmt_iterat
   arg = build_addr (next_label);
   t = builtin_decl_implicit (BUILT_IN_SETJMP_SETUP);
   g = gimple_build_call (t, 2, gimple_call_arg (stmt, 0), arg);
+  /* location includes block.  */
   gimple_set_location (g, loc);
-  gimple_set_block (g, gimple_block (stmt));
   gsi_insert_before (gsi, g, GSI_SAME_STMT);
 
   /* Build 'DEST = 0' and insert.  */
@@ -815,7 +815,6 @@ lower_builtin_setjmp (gimple_stmt_iterat
     {
       g = gimple_build_assign (dest, build_zero_cst (TREE_TYPE (dest)));
       gimple_set_location (g, loc);
-      gimple_set_block (g, gimple_block (stmt));
       gsi_insert_before (gsi, g, GSI_SAME_STMT);
     }
 
@@ -832,7 +831,6 @@ lower_builtin_setjmp (gimple_stmt_iterat
   t = builtin_decl_implicit (BUILT_IN_SETJMP_RECEIVER);
   g = gimple_build_call (t, 1, arg);
   gimple_set_location (g, loc);
-  gimple_set_block (g, gimple_block (stmt));
   gsi_insert_before (gsi, g, GSI_SAME_STMT);
 
   /* Build 'DEST = 1' and insert.  */
@@ -841,7 +839,6 @@ lower_builtin_setjmp (gimple_stmt_iterat
       g = gimple_build_assign (dest, fold_convert_loc (loc, TREE_TYPE (dest),
                                                       integer_one_node));
       gimple_set_location (g, loc);
-      gimple_set_block (g, gimple_block (stmt));
       gsi_insert_before (gsi, g, GSI_SAME_STMT);
     }
 

Reply via email to