This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[C++ PATCH] clone_function_decl breakup


This patch, from the modules branch, breaks out function cloning from the method vector updating. We have a new function, build_clones, which does the building, returning a count of the number of clones (2 or 3). clone_function_decl separately adds them to the method vector, if they should be added. I suppose this could have used FOR_EVERY_CLONE, but I went with the counting scheme.

On the module branch, build_clones is not static and has a few more parameters, but that's a different patch.

installing on trunk.

nathan
--
Nathan Sidwell
2019-10-15  Nathan Sidwell  <nathan@acm.org>

	* class.c (build_clones): Break out of clone_function_decl.  Just
	build the clones.
	(clone_function_decl): Call build_clones, then maybe add them to
	the method vector.

Index: class.c
===================================================================
--- class.c	(revision 276992)
+++ class.c	(working copy)
@@ -4700,17 +4700,11 @@ build_clone (tree fn, tree name)
 }
 
-/* Produce declarations for all appropriate clones of FN.  If
-   UPDATE_METHODS is true, the clones are added to the
-   CLASSTYPE_MEMBER_VEC.  */
+/* Build the clones of FN, return the number of clones built.  These
+   will be inserted onto DECL_CHAIN of FN.  */
 
-void
-clone_function_decl (tree fn, bool update_methods)
+unsigned
+build_clones (tree fn)
 {
-  tree clone;
-
-  /* Avoid inappropriate cloning.  */
-  if (DECL_CHAIN (fn)
-      && DECL_CLONED_FUNCTION_P (DECL_CHAIN (fn)))
-    return;
+  unsigned count = 0;
 
   if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (fn))
@@ -4718,10 +4712,7 @@ clone_function_decl (tree fn, bool updat
       /* For each constructor, we need two variants: an in-charge version
 	 and a not-in-charge version.  */
-      clone = build_clone (fn, complete_ctor_identifier);
-      if (update_methods)
-	add_method (DECL_CONTEXT (clone), clone, false);
-      clone = build_clone (fn, base_ctor_identifier);
-      if (update_methods)
-	add_method (DECL_CONTEXT (clone), clone, false);
+      build_clone (fn, complete_ctor_identifier);
+      build_clone (fn, base_ctor_identifier);
+      count += 2;
     }
   else
@@ -4740,18 +4731,38 @@ clone_function_decl (tree fn, bool updat
       if (DECL_VIRTUAL_P (fn))
 	{
-	  clone = build_clone (fn, deleting_dtor_identifier);
-	  if (update_methods)
-	    add_method (DECL_CONTEXT (clone), clone, false);
+	  build_clone (fn, deleting_dtor_identifier);
+	  count++;
 	}
-      clone = build_clone (fn, complete_dtor_identifier);
-      if (update_methods)
-	add_method (DECL_CONTEXT (clone), clone, false);
-      clone = build_clone (fn, base_dtor_identifier);
-      if (update_methods)
-	add_method (DECL_CONTEXT (clone), clone, false);
+      build_clone (fn, complete_dtor_identifier);
+      build_clone (fn, base_dtor_identifier);
+      count += 2;
     }
 
+  return count;
+}
+
+/* Produce declarations for all appropriate clones of FN.  If
+   UPDATE_METHODS is true, the clones are added to the
+   CLASSTYPE_MEMBER_VEC.  */
+
+void
+clone_function_decl (tree fn, bool update_methods)
+{
+  /* Avoid inappropriate cloning.  */
+  if (DECL_CHAIN (fn)
+      && DECL_CLONED_FUNCTION_P (DECL_CHAIN (fn)))
+    return;
+
+  unsigned count = build_clones (fn);
+
   /* Note that this is an abstract function that is never emitted.  */
   DECL_ABSTRACT_P (fn) = true;
+
+  if (update_methods)
+    for (tree clone = fn; count--;)
+      {
+	clone = DECL_CHAIN (clone);
+	add_method (DECL_CONTEXT (clone), clone, false);
+      }
 }
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]