Avoid unnecessarily numbering cloned symbols.
authorMichael Ploujnikov <michael.ploujnikov@oracle.com>
Tue, 30 Oct 2018 11:39:29 +0000 (11:39 +0000)
committerMartin Liska <marxin@gcc.gnu.org>
Tue, 30 Oct 2018 11:39:29 +0000 (11:39 +0000)
2018-10-30  Michael Ploujnikov  <michael.ploujnikov@oracle.com>

* cgraph.h (clone_function_name_1): Replaced by new
  clone_function_name_numbered that takes name as string; for
  privatize_symbol_name_1 use only.
  (clone_function_name): Renamed to
  clone_function_name_numbered to be explicit about numbering.
  (clone_function_name): New two-argument function that does
  not number its output.
  (clone_function_name): New three-argument function that
  takes a number to append to its output.
* cgraphclones.c (duplicate_thunk_for_node):
  (clone_function_name_1): Renamed.
  (clone_function_name_numbered): Two new functions.
  (clone_function_name): Improved documentation.
  (cgraph_node::create_virtual_clone): Use clone_function_name_numbered.
* config/rs6000/rs6000.c (make_resolver_func): Ditto.
* final.c (final_scan_insn_1): Use the new clone_function_name
  without numbering.
* multiple_target.c (create_dispatcher_calls): Ditto.
  (create_target_clone): Ditto.
* omp-expand.c (grid_expand_target_grid_body): Ditto.
* omp-low.c (create_omp_child_function_name): Ditto.
* omp-simd-clone.c (simd_clone_create): Ditto.
* symtab.c (simd_symtab_node::noninterposable_alias): Use the
  new clone_function_name without numbering.
2018-10-30  Michael Ploujnikov  <michael.ploujnikov@oracle.com>

* lto-partition.c (privatize_symbol_name_1): Use
  clone_function_name_numbered.
2018-10-30  Michael Ploujnikov  <michael.ploujnikov@oracle.com>

* gcc.dg/tree-prof/cold_partition_label.c: Update for cold
  section names without numbers.
* gcc.dg/tree-prof/section-attr-1.c: Ditto.
* gcc.dg/tree-prof/section-attr-2.c: Ditto.
* gcc.dg/tree-prof/section-attr-3.c: Ditto.

From-SVN: r265621

15 files changed:
gcc/ChangeLog
gcc/cgraph.h
gcc/cgraphclones.c
gcc/config/rs6000/rs6000.c
gcc/lto/ChangeLog
gcc/lto/lto-partition.c
gcc/multiple_target.c
gcc/omp-expand.c
gcc/omp-low.c
gcc/omp-simd-clone.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-prof/cold_partition_label.c
gcc/testsuite/gcc.dg/tree-prof/section-attr-1.c
gcc/testsuite/gcc.dg/tree-prof/section-attr-2.c
gcc/testsuite/gcc.dg/tree-prof/section-attr-3.c

index c07d3ad96680558156a2492cff82ce38ae725979..1dcec6ae5c03573aad94aeafb30dbe8a34402068 100644 (file)
@@ -1,3 +1,30 @@
+2018-10-30  Michael Ploujnikov  <michael.ploujnikov@oracle.com>
+
+       * cgraph.h (clone_function_name_1): Replaced by new
+         clone_function_name_numbered that takes name as string; for
+         privatize_symbol_name_1 use only.
+         (clone_function_name): Renamed to
+         clone_function_name_numbered to be explicit about numbering.
+         (clone_function_name): New two-argument function that does
+         not number its output.
+         (clone_function_name): New three-argument function that
+         takes a number to append to its output.
+       * cgraphclones.c (duplicate_thunk_for_node):
+         (clone_function_name_1): Renamed.
+         (clone_function_name_numbered): Two new functions.
+         (clone_function_name): Improved documentation.
+         (cgraph_node::create_virtual_clone): Use clone_function_name_numbered.
+       * config/rs6000/rs6000.c (make_resolver_func): Ditto.
+       * final.c (final_scan_insn_1): Use the new clone_function_name
+         without numbering.
+       * multiple_target.c (create_dispatcher_calls): Ditto.
+         (create_target_clone): Ditto.
+       * omp-expand.c (grid_expand_target_grid_body): Ditto.
+       * omp-low.c (create_omp_child_function_name): Ditto.
+       * omp-simd-clone.c (simd_clone_create): Ditto.
+       * symtab.c (simd_symtab_node::noninterposable_alias): Use the
+         new clone_function_name without numbering.
+
 2018-10-30  Richard Earnshaw  <rearnsha@arm.com>
 
        * alloc-pool.h (base_pool_allocator <TBlockAllocator>::initialize):
index 71c54537b932d4aef4f226303e90a9edeb700a55..c13d79850fa86e45b40e85b5b32d0854cfbbb2f1 100644 (file)
@@ -2382,8 +2382,11 @@ tree thunk_adjust (gimple_stmt_iterator *, tree, bool, HOST_WIDE_INT, tree,
                   HOST_WIDE_INT);
 /* In cgraphclones.c  */
 
-tree clone_function_name_1 (const char *, const char *);
-tree clone_function_name (tree decl, const char *);
+tree clone_function_name_numbered (const char *name, const char *suffix);
+tree clone_function_name_numbered (tree decl, const char *suffix);
+tree clone_function_name (const char *name, const char *suffix,
+                         unsigned long number);
+tree clone_function_name (tree decl, const char *suffix);
 
 void tree_function_versioning (tree, tree, vec<ipa_replace_map *, va_gc> *,
                               bool, bitmap, bool, bitmap, basic_block);
index 189cb31a5dc8a7243c7bd5bcc616df841040fd4a..e17959c0ca61bd5c85840df1f03b0e2873c8de1d 100644 (file)
@@ -317,7 +317,8 @@ duplicate_thunk_for_node (cgraph_node *thunk, cgraph_node *node)
   gcc_checking_assert (!DECL_RESULT (new_decl));
   gcc_checking_assert (!DECL_RTL_SET_P (new_decl));
 
-  DECL_NAME (new_decl) = clone_function_name (thunk->decl, "artificial_thunk");
+  DECL_NAME (new_decl) = clone_function_name_numbered (thunk->decl,
+                                                      "artificial_thunk");
   SET_DECL_ASSEMBLER_NAME (new_decl, DECL_NAME (new_decl));
 
   new_thunk = cgraph_node::create (new_decl);
@@ -514,11 +515,41 @@ cgraph_node::create_clone (tree new_decl, profile_count prof_count,
 
 static GTY(()) unsigned int clone_fn_id_num;
 
-/* Return a new assembler name for a clone with SUFFIX of a decl named
-   NAME.  */
+/* Return a new assembler name for a clone of decl named NAME.  Apart
+   from the string SUFFIX, the new name will end with a unique (for
+   each NAME) unspecified number.  If clone numbering is not needed
+   then the two argument clone_function_name should be used instead.
+   Should not be called directly except for by
+   lto-partition.c:privatize_symbol_name_1.  */
 
 tree
-clone_function_name_1 (const char *name, const char *suffix)
+clone_function_name_numbered (const char *name, const char *suffix)
+{
+  return clone_function_name (name, suffix, clone_fn_id_num++);
+}
+
+/* Return a new assembler name for a clone of DECL.  Apart from string
+   SUFFIX, the new name will end with a unique (for each DECL
+   assembler name) unspecified number.  If clone numbering is not
+   needed then the two argument clone_function_name should be used
+   instead.  */
+
+tree
+clone_function_name_numbered (tree decl, const char *suffix)
+{
+  tree name = DECL_ASSEMBLER_NAME (decl);
+  return clone_function_name_numbered (IDENTIFIER_POINTER (name),
+                                      suffix);
+}
+
+/* Return a new assembler name for a clone of decl named NAME.  Apart
+   from the string SUFFIX, the new name will end with the specified
+   NUMBER.  If clone numbering is not needed then the two argument
+   clone_function_name should be used instead.  */
+
+tree
+clone_function_name (const char *name, const char *suffix,
+                    unsigned long number)
 {
   size_t len = strlen (name);
   char *tmp_name, *prefix;
@@ -527,17 +558,34 @@ clone_function_name_1 (const char *name, const char *suffix)
   memcpy (prefix, name, len);
   strcpy (prefix + len + 1, suffix);
   prefix[len] = symbol_table::symbol_suffix_separator ();
-  ASM_FORMAT_PRIVATE_NAME (tmp_name, prefix, clone_fn_id_num++);
+  ASM_FORMAT_PRIVATE_NAME (tmp_name, prefix, number);
   return get_identifier (tmp_name);
 }
 
-/* Return a new assembler name for a clone of DECL with SUFFIX.  */
+/* Return a new assembler name ending with the string SUFFIX for a
+   clone of DECL.  */
 
 tree
 clone_function_name (tree decl, const char *suffix)
 {
-  tree name = DECL_ASSEMBLER_NAME (decl);
-  return clone_function_name_1 (IDENTIFIER_POINTER (name), suffix);
+  tree identifier = DECL_ASSEMBLER_NAME (decl);
+  /* For consistency this needs to behave the same way as
+     ASM_FORMAT_PRIVATE_NAME does, but without the final number
+     suffix.  */
+  char *separator = XALLOCAVEC (char, 2);
+  separator[0] = symbol_table::symbol_suffix_separator ();
+  separator[1] = 0;
+#if defined (NO_DOT_IN_LABEL) && defined (NO_DOLLAR_IN_LABEL)
+  const char *prefix = "__";
+#else
+  const char *prefix = "";
+#endif
+  char *result = ACONCAT ((prefix,
+                          IDENTIFIER_POINTER (identifier),
+                          separator,
+                          suffix,
+                          (char*)0));
+  return get_identifier (result);
 }
 
 
@@ -585,7 +633,8 @@ cgraph_node::create_virtual_clone (vec<cgraph_edge *> redirect_callers,
   strcpy (name + len + 1, suffix);
   name[len] = '.';
   DECL_NAME (new_decl) = get_identifier (name);
-  SET_DECL_ASSEMBLER_NAME (new_decl, clone_function_name (old_decl, suffix));
+  SET_DECL_ASSEMBLER_NAME (new_decl, clone_function_name_numbered (old_decl,
+                                                                  suffix));
   SET_DECL_RTL (new_decl, NULL);
 
   new_node = create_clone (new_decl, count, false,
@@ -964,7 +1013,7 @@ cgraph_node::create_version_clone_with_body
       = build_function_decl_skip_args (old_decl, args_to_skip, skip_return);
 
   /* Generate a new name for the new version. */
-  DECL_NAME (new_decl) = clone_function_name (old_decl, suffix);
+  DECL_NAME (new_decl) = clone_function_name_numbered (old_decl, suffix);
   SET_DECL_ASSEMBLER_NAME (new_decl, DECL_NAME (new_decl));
   SET_DECL_RTL (new_decl, NULL);
 
index a9d038829b798ab5842a6fe0d59babc8e34b35b6..4f113cb025e08191768fec5baa58a649cacdc0f2 100644 (file)
@@ -36997,7 +36997,7 @@ make_resolver_func (const tree default_decl,
 {
   /* Make the resolver function static.  The resolver function returns
      void *.  */
-  tree decl_name = clone_function_name (default_decl, "resolver");
+  tree decl_name = clone_function_name_numbered (default_decl, "resolver");
   const char *resolver_name = IDENTIFIER_POINTER (decl_name);
   tree type = build_function_type_list (ptr_type_node, NULL_TREE);
   tree decl = build_fn_decl (resolver_name, type);
index a5d1ff2a0241d748d2ea4dfdea7d0f2fd4419e64..a31b7de889903b27f8f7940a140527864f340210 100644 (file)
@@ -1,3 +1,8 @@
+2018-10-30  Michael Ploujnikov  <michael.ploujnikov@oracle.com>
+
+       * lto-partition.c (privatize_symbol_name_1): Use
+         clone_function_name_numbered.
+
 2018-10-26  Jan Hubicka  <jh@suse.cz>
 
        * lto/lto-symtab.c (lto_symtab_merge_decls_2): Fix extra space.
index c7a5710f776c09f852a014fb5d51d595acd6d74e..24e7c238597986ccf469446d0b7c8f816976059d 100644 (file)
@@ -964,8 +964,8 @@ privatize_symbol_name_1 (symtab_node *node, tree decl)
 
   name = maybe_rewrite_identifier (name);
   symtab->change_decl_assembler_name (decl,
-                                     clone_function_name_1 (name,
-                                                            "lto_priv"));
+                                     clone_function_name_numbered (
+                                         name, "lto_priv"));
 
   if (node->lto_file_data)
     lto_record_renamed_decl (node->lto_file_data, name,
index 2d892f201c5d06eda2c7b12f380bc0151d63e7e8..5225e46bf04fce6fd372a71393daaa4c2d0ffb21 100644 (file)
@@ -162,8 +162,8 @@ create_dispatcher_calls (struct cgraph_node *node)
     }
 
   symtab->change_decl_assembler_name (node->decl,
-                                     clone_function_name (node->decl,
-                                                          "default"));
+                                     clone_function_name_numbered (
+                                         node->decl, "default"));
 
   /* FIXME: copy of cgraph_node::make_local that should be cleaned up
            in next stage1.  */
@@ -312,8 +312,8 @@ create_target_clone (cgraph_node *node, bool definition, char *name)
       new_node = cgraph_node::get_create (new_decl);
       /* Generate a new name for the new version.  */
       symtab->change_decl_assembler_name (new_node->decl,
-                                         clone_function_name (node->decl,
-                                                              name));
+                                         clone_function_name_numbered (
+                                             node->decl, name));
     }
   return new_node;
 }
index e8abde413dbb73e99c7ab2d5a2d50ee7b20272db..1185a26619ae46a46167b226423867af846618d9 100644 (file)
@@ -7625,7 +7625,8 @@ grid_expand_target_grid_body (struct omp_region *target)
     expand_omp (gpukernel->inner);
 
   tree kern_fndecl = copy_node (orig_child_fndecl);
-  DECL_NAME (kern_fndecl) = clone_function_name (kern_fndecl, "kernel");
+  DECL_NAME (kern_fndecl) = clone_function_name_numbered (kern_fndecl,
+                                                         "kernel");
   SET_DECL_ASSEMBLER_NAME (kern_fndecl, DECL_NAME (kern_fndecl));
   tree tgtblock = gimple_block (tgt_stmt);
   tree fniniblock = make_node (BLOCK);
index bbcbc121baeb9a3a9d0240e2a0d1cb4530d181eb..b06ddb385767283c64da3cb290dea1b0fe51b1fe 100644 (file)
@@ -1531,8 +1531,8 @@ scan_sharing_clauses (tree clauses, omp_context *ctx)
 static tree
 create_omp_child_function_name (bool task_copy)
 {
-  return clone_function_name (current_function_decl,
-                             task_copy ? "_omp_cpyfn" : "_omp_fn");
+  return clone_function_name_numbered (current_function_decl,
+                                      task_copy ? "_omp_cpyfn" : "_omp_fn");
 }
 
 /* Return true if CTX may belong to offloaded code: either if current function
index b15adf0bada40e2f083668cf3d2390852b15d238..7bafe39b1778c6e7c1af2507f258ac8dec1c614c 100644 (file)
@@ -444,7 +444,8 @@ simd_clone_create (struct cgraph_node *old_node)
     {
       tree old_decl = old_node->decl;
       tree new_decl = copy_node (old_node->decl);
-      DECL_NAME (new_decl) = clone_function_name (old_decl, "simdclone");
+      DECL_NAME (new_decl) = clone_function_name_numbered (old_decl,
+                                                          "simdclone");
       SET_DECL_ASSEMBLER_NAME (new_decl, DECL_NAME (new_decl));
       SET_DECL_RTL (new_decl, NULL);
       DECL_STATIC_CONSTRUCTOR (new_decl) = 0;
index 4fe555cd624fc7af1bd8357b20050a2ac860db04..5463008e6458d30f0c0123381b59fb12d1c86b17 100644 (file)
@@ -1,3 +1,11 @@
+2018-10-30  Michael Ploujnikov  <michael.ploujnikov@oracle.com>
+
+       * gcc.dg/tree-prof/cold_partition_label.c: Update for cold
+         section names without numbers.
+       * gcc.dg/tree-prof/section-attr-1.c: Ditto.
+       * gcc.dg/tree-prof/section-attr-2.c: Ditto.
+       * gcc.dg/tree-prof/section-attr-3.c: Ditto.
+
 2018-10-29  David Malcolm  <dmalcolm@redhat.com>
 
        PR c++/87721
index 52518cf40c38b5c9e4109c0afdaa3d779feba87f..450308d6407e6cb627fdd7c8738754c37ac0432b 100644 (file)
@@ -37,6 +37,6 @@ main (int argc, char *argv[])
   return 0;
 }
 
-/* { dg-final-use { scan-assembler "foo\[._\]+cold\[\._\]+0" { target *-*-linux* *-*-gnu* } } } */
-/* { dg-final-use { scan-assembler "size\[ \ta-zA-Z0-0\]+foo\[._\]+cold\[\._\]+0" { target *-*-linux* *-*-gnu* } } } */
+/* { dg-final-use { scan-assembler "foo\[._\]+cold" { target *-*-linux* *-*-gnu* } } } */
+/* { dg-final-use { scan-assembler "size\[ \ta-zA-Z0-0\]+foo\[._\]+cold" { target *-*-linux* *-*-gnu* } } } */
 /* { dg-final-use { scan-tree-dump-not "Invalid sum" "optimized"} } */
index 1f99b3128cc8278afbfd901ff2813d828d81a13f..0cbd2de0cb100d0574b078cb8a2b4f0a2ad52301 100644 (file)
@@ -46,5 +46,5 @@ foo (int path)
     }
 }
 
-/* { dg-final-use { scan-assembler "\.section\[\t \]*\.text\.unlikely\[\\n\\r\]+\[\t \]*\.size\[\t \]*foo\.cold\.0" { target *-*-linux* *-*-gnu* } } } */
-/* { dg-final-use { scan-assembler "\.section\[\t \]*__TEXT,__text_cold\.\*\[\\n\\r\]+_foo\.cold\.0" { target *-*-darwin* } } } */
+/* { dg-final-use { scan-assembler "\.section\[\t \]*\.text\.unlikely\[\\n\\r\]+\[\t \]*\.size\[\t \]*foo\.cold" { target *-*-linux* *-*-gnu* } } } */
+/* { dg-final-use { scan-assembler "\.section\[\t \]*__TEXT,__text_cold\*\[\\n\\r\]+_foo\.cold" { target *-*-darwin* } } } */
index 9bdc63a1b0adb0db311b732d58ad50f05f11f4bf..75a4d8a2c9652fe5e3800f70e2fc7a3faa3f3c31 100644 (file)
@@ -45,5 +45,5 @@ foo (int path)
     }
 }
 
-/* { dg-final-use { scan-assembler "\.section\[\t \]*\.text\.unlikely\[\\n\\r\]+\[\t \]*\.size\[\t \]*foo\.cold\.0" { target *-*-linux* *-*-gnu* } } } */
-/* { dg-final-use { scan-assembler "\.section\[\t \]*__TEXT,__text_cold\.\*\[\\n\\r\]+_foo\.cold\.0:" { target *-*-darwin* } } } */
+/* { dg-final-use { scan-assembler "\.section\[\t \]*\.text\.unlikely\[\\n\\r\]+\[\t \]*\.size\[\t \]*foo\.cold" { target *-*-linux* *-*-gnu* } } } */
+/* { dg-final-use { scan-assembler "\.section\[\t \]*__TEXT,__text_cold\*\[\\n\\r\]+_foo\.cold:" { target *-*-darwin* } } } */
index 29eee4587d6e87b76dcea6b58faf29a6b953493d..c243b18b1cff4a992ae156cdd9f9423ff1428551 100644 (file)
@@ -46,5 +46,5 @@ foo (int path)
     }
 }
 
-/* { dg-final-use { scan-assembler "\.section\[\t \]*\.text\.unlikely\[\\n\\r\]+\[\t \]*\.size\[\t \]*foo\.cold\.0" { target *-*-linux* *-*-gnu* } } } */
-/* { dg-final-use { scan-assembler "\.section\[\t \]*__TEXT,__text_cold\.\*\[\\n\\r\]+_foo\.cold\.0:" { target *-*-darwin* } } } */
+/* { dg-final-use { scan-assembler "\.section\[\t \]*\.text\.unlikely\[\\n\\r\]+\[\t \]*\.size\[\t \]*foo\.cold" { target *-*-linux* *-*-gnu* } } } */
+/* { dg-final-use { scan-assembler "\.section\[\t \]*__TEXT,__text_cold\*\[\\n\\r\]+_foo\.cold:" { target *-*-darwin* } } } */