Make function assembly more independent.
authorMichael Ploujnikov <michael.ploujnikov@oracle.com>
Fri, 30 Nov 2018 22:20:43 +0000 (22:20 +0000)
committerMichael Ploujnikov <plouj@gcc.gnu.org>
Fri, 30 Nov 2018 22:20:43 +0000 (22:20 +0000)
This is achieved by having clone_function_name assign unique clone
numbers for each function independently.

gcc:

* cgraphclones.c: Replaced clone_fn_id_num with clone_fn_ids;
hash map.
(clone_function_name_numbered): Use clone_fn_ids.

gcc/testsuite:

* gcc.dg/independent-cloneids-1.c: New test.

From-SVN: r266691

gcc/ChangeLog
gcc/cgraphclones.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/independent-cloneids-1.c [new file with mode: 0644]

index 29e42c000d52f4d147bc4ac07ecd9b33d7ae3bfe..e47e2b17cb8be17b376b17b55e226696386c0a64 100644 (file)
@@ -1,3 +1,13 @@
+2018-11-30  Michael Ploujnikov  <michael.ploujnikov@oracle.com>
+       Make function assembly more independent.
+
+       This is achieved by having clone_function_name assign unique clone
+       numbers for each function independently.
+
+       * cgraphclones.c: Replaced clone_fn_id_num with clone_fn_ids;
+       hash map.
+       (clone_function_name_numbered): Use clone_fn_ids.
+
 2018-11-30  Vladimir Makarov  <vmakarov@redhat.com>
 
        PR rtl-optimization/88179
index 0fbc7a919bde3be70010e35fc2fee13ebcd8456a..a45722f1fc72f4e6973b26dd8f18714f8a1b6124 100644 (file)
@@ -517,7 +517,7 @@ cgraph_node::create_clone (tree new_decl, profile_count prof_count,
   return new_node;
 }
 
-static GTY(()) unsigned int clone_fn_id_num;
+static GTY(()) hash_map<const char *, unsigned> *clone_fn_ids;
 
 /* 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
@@ -529,7 +529,13 @@ static GTY(()) unsigned int clone_fn_id_num;
 tree
 clone_function_name_numbered (const char *name, const char *suffix)
 {
-  return clone_function_name (name, suffix, clone_fn_id_num++);
+  /* Initialize the function->counter mapping the first time it's
+     needed.  */
+  if (!clone_fn_ids)
+    clone_fn_ids = hash_map<const char *, unsigned int>::create_ggc (64);
+  unsigned int &suffix_counter = clone_fn_ids->get_or_insert (
+                                  IDENTIFIER_POINTER (get_identifier (name)));
+  return clone_function_name (name, suffix, suffix_counter++);
 }
 
 /* Return a new assembler name for a clone of DECL.  Apart from string
index 9ec4164919cad6727a4963dd22a9fbb147896c4d..1c6a9561378c02223cd23b16701495e0e46278a9 100644 (file)
@@ -1,3 +1,7 @@
+2018-11-30  Michael Ploujnikov  <michael.ploujnikov@oracle.com>
+
+       * gcc.dg/independent-cloneids-1.c: New test.
+
 2018-11-30  Jakub Jelinek  <jakub@redhat.com>
 
        PR debug/85550
diff --git a/gcc/testsuite/gcc.dg/independent-cloneids-1.c b/gcc/testsuite/gcc.dg/independent-cloneids-1.c
new file mode 100644 (file)
index 0000000..3203895
--- /dev/null
@@ -0,0 +1,38 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -fipa-cp -fipa-cp-clone"  } */
+
+extern int printf (const char *, ...);
+
+static int __attribute__ ((noinline))
+foo (int arg)
+{
+  return 7 * arg;
+}
+
+static int __attribute__ ((noinline))
+bar (int arg)
+{
+  return arg * arg;
+}
+
+int
+baz (int arg)
+{
+  printf("%d\n", bar (3));
+  printf("%d\n", bar (4));
+  printf("%d\n", foo (5));
+  printf("%d\n", foo (6));
+  /* adding or removing the following call should not affect foo
+     function's clone numbering */
+  printf("%d\n", bar (7));
+  return foo (8);
+}
+
+/* { dg-final { scan-assembler-times {(?n)\m_*bar[.$_]constprop[.$_]0:} 1 } } */
+/* { dg-final { scan-assembler-times {(?n)\m_*bar[.$_]constprop[.$_]1:} 1 } } */
+/* { dg-final { scan-assembler-times {(?n)\m_*bar[.$_]constprop[.$_]2:} 1 } } */
+/* { dg-final { scan-assembler-times {(?n)\m_*foo[.$_]constprop[.$_]0:} 1 } } */
+/* { dg-final { scan-assembler-times {(?n)\m_*foo[.$_]constprop[.$_]1:} 1 } } */
+/* { dg-final { scan-assembler-times {(?n)\m_*foo[.$_]constprop[.$_]2:} 1 } } */
+/* { dg-final { scan-assembler-not {(?n)\m_*foo[.$_]constprop[.$_]3:} } } */
+/* { dg-final { scan-assembler-not {(?n)\m_*foo[.$_]constprop[.$_]4:} } } */