]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Introduce append_ctor_to_tree_vector
authorJakub Jelinek <jakub@redhat.com>
Wed, 22 Jan 2025 08:22:56 +0000 (09:22 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 22 Jan 2025 08:22:56 +0000 (09:22 +0100)
On Mon, Jan 20, 2025 at 05:14:33PM -0500, Jason Merrill wrote:
> > --- gcc/cp/call.cc.jj       2025-01-15 18:24:36.135503866 +0100
> > +++ gcc/cp/call.cc  2025-01-17 14:42:38.201643385 +0100
> > @@ -4258,11 +4258,30 @@ add_list_candidates (tree fns, tree firs
> >     /* Expand the CONSTRUCTOR into a new argument vec.  */
>
> Maybe we could factor out a function called something like
> append_ctor_to_tree_vector from the common code between this and
> make_tree_vector_from_ctor?
>
> But this is OK as is if you don't want to pursue that.

I had the previous patch already tested and wanted to avoid delaying
the large initializer speedup re-reversion any further, so I've committed
the patch as is.

Here is an incremental patch to factor that out.

2025-01-22  Jakub Jelinek  <jakub@redhat.com>

gcc/c-family/
* c-common.h (append_ctor_to_tree_vector): Declare.
* c-common.cc (append_ctor_to_tree_vector): New function.
(make_tree_vector_from_ctor): Use it.
gcc/cp/
* call.cc (add_list_candidates): Use append_ctor_to_tree_vector.

gcc/c-family/c-common.cc
gcc/c-family/c-common.h
gcc/cp/call.cc

index 91d90725152a6d83a3164cdd8589390d20a85b54..c193eb2c463a27a6bb0ed23bf9877d9ebed0d51b 100644 (file)
@@ -9010,33 +9010,42 @@ make_tree_vector_from_list (tree list)
   return ret;
 }
 
-/* Get a new tree vector of the values of a CONSTRUCTOR.  */
+/* Append to a tree vector V the values of a CONSTRUCTOR CTOR
+   and return the new possibly reallocated vector.  */
 
 vec<tree, va_gc> *
-make_tree_vector_from_ctor (tree ctor)
+append_ctor_to_tree_vector (vec<tree, va_gc> *v, tree ctor)
 {
-  vec<tree,va_gc> *ret = make_tree_vector ();
-  unsigned nelts = CONSTRUCTOR_NELTS (ctor);
-  vec_safe_reserve (ret, CONSTRUCTOR_NELTS (ctor));
+  unsigned nelts = vec_safe_length (v) + CONSTRUCTOR_NELTS (ctor);
+  vec_safe_reserve (v, CONSTRUCTOR_NELTS (ctor));
   for (unsigned i = 0; i < CONSTRUCTOR_NELTS (ctor); ++i)
     if (TREE_CODE (CONSTRUCTOR_ELT (ctor, i)->value) == RAW_DATA_CST)
       {
        tree raw_data = CONSTRUCTOR_ELT (ctor, i)->value;
        nelts += RAW_DATA_LENGTH (raw_data) - 1;
-       vec_safe_reserve (ret, nelts - ret->length ());
+       vec_safe_reserve (v, nelts - v->length ());
        if (TYPE_PRECISION (TREE_TYPE (raw_data)) > CHAR_BIT
            || TYPE_UNSIGNED (TREE_TYPE (raw_data)))
          for (unsigned j = 0; j < (unsigned) RAW_DATA_LENGTH (raw_data); ++j)
-           ret->quick_push (build_int_cst (TREE_TYPE (raw_data),
-                                           RAW_DATA_UCHAR_ELT (raw_data, j)));
+           v->quick_push (build_int_cst (TREE_TYPE (raw_data),
+                                         RAW_DATA_UCHAR_ELT (raw_data, j)));
        else
          for (unsigned j = 0; j < (unsigned) RAW_DATA_LENGTH (raw_data); ++j)
-           ret->quick_push (build_int_cst (TREE_TYPE (raw_data),
-                                           RAW_DATA_SCHAR_ELT (raw_data, j)));
+           v->quick_push (build_int_cst (TREE_TYPE (raw_data),
+                                         RAW_DATA_SCHAR_ELT (raw_data, j)));
       }
     else
-      ret->quick_push (CONSTRUCTOR_ELT (ctor, i)->value);
-  return ret;
+      v->quick_push (CONSTRUCTOR_ELT (ctor, i)->value);
+  return v;
+}
+
+/* Get a new tree vector of the values of a CONSTRUCTOR.  */
+
+vec<tree, va_gc> *
+make_tree_vector_from_ctor (tree ctor)
+{
+  vec<tree,va_gc> *ret = make_tree_vector ();
+  return append_ctor_to_tree_vector (ret, ctor);
 }
 
 /* Get a new tree vector which is a copy of an existing one.  */
index 94b1d2d2b496778833487a1e3534ce85a7f8bc7c..c5eb11d85fd5a9183d80fd1819239f438f39278f 100644 (file)
@@ -1190,6 +1190,8 @@ extern vec<tree, va_gc> *make_tree_vector (void);
 extern void release_tree_vector (vec<tree, va_gc> *);
 extern vec<tree, va_gc> *make_tree_vector_single (tree);
 extern vec<tree, va_gc> *make_tree_vector_from_list (tree);
+extern vec<tree, va_gc> *append_ctor_to_tree_vector (vec<tree, va_gc> *,
+                                                    tree);
 extern vec<tree, va_gc> *make_tree_vector_from_ctor (tree);
 extern vec<tree, va_gc> *make_tree_vector_copy (const vec<tree, va_gc> *);
 
index 80015dfe9da66f9a125eebfadb2b7882875ab125..469af83ccbfdfd124e3fbdde482598be6e936f76 100644 (file)
@@ -4258,30 +4258,10 @@ add_list_candidates (tree fns, tree first_arg,
 
   /* Expand the CONSTRUCTOR into a new argument vec.  */
   vec<tree, va_gc> *new_args;
-  unsigned nelts = nart + CONSTRUCTOR_NELTS (init_list);
-  vec_alloc (new_args, nelts);
+  vec_alloc (new_args, nart + CONSTRUCTOR_NELTS (init_list));
   for (unsigned i = 0; i < nart; ++i)
     new_args->quick_push ((*args)[i]);
-  for (unsigned i = 0; i < CONSTRUCTOR_NELTS (init_list); ++i)
-    if (TREE_CODE (CONSTRUCTOR_ELT (init_list, i)->value) == RAW_DATA_CST)
-      {
-       tree raw_data = CONSTRUCTOR_ELT (init_list, i)->value;
-       nelts += RAW_DATA_LENGTH (raw_data) - 1;
-       vec_safe_reserve (new_args, nelts - new_args->length ());
-       if (TYPE_PRECISION (TREE_TYPE (raw_data)) > CHAR_BIT
-           || TYPE_UNSIGNED (TREE_TYPE (raw_data)))
-         for (unsigned j = 0; j < (unsigned) RAW_DATA_LENGTH (raw_data); ++j)
-           new_args->quick_push (build_int_cst (TREE_TYPE (raw_data),
-                                                RAW_DATA_UCHAR_ELT (raw_data,
-                                                                    j)));
-       else
-         for (unsigned j = 0; j < (unsigned) RAW_DATA_LENGTH (raw_data); ++j)
-           new_args->quick_push (build_int_cst (TREE_TYPE (raw_data),
-                                                RAW_DATA_SCHAR_ELT (raw_data,
-                                                                    j)));
-      }
-    else
-      new_args->quick_push (CONSTRUCTOR_ELT (init_list, i)->value);
+  new_args = append_ctor_to_tree_vector (new_args, init_list);
 
   /* We aren't looking for list-ctors anymore.  */
   flags &= ~LOOKUP_LIST_ONLY;