[lto] tree.c (build_function_type_list): Don't allocate a temporary vector.
Kazu Hirata
kazu@codesourcery.com
Wed Aug 9 03:15:00 GMT 2006
Hi,
Attached is a patch to reduce memory usage in
build_function_type_list.
build_function_type_list builds a parameter type list based on
parameters given in "...".
Without this patch, build_function_type_list temporarily allocates a
vector on heap to store all parameters given in "...". This patch
eliminates the temporary storage by iterating the variable argument
list twice -- once to figure out the length and once to populate the
parameter type list.
Tested on x86_64-pc-linux-gnu. Committed to the LTO branch.
Kazu Hirata
2006-08-09 Kazu Hirata <kazu@codesourcery.com>
* tree.c (build_function_type_list): Don't allocate a
temporary vector.
Index: tree.c
===================================================================
*** tree.c (revision 116006)
--- tree.c (working copy)
*************** build_function_type (tree value_type, tr
*** 5277,5300 ****
tree
build_function_type_list (tree return_type, ...)
{
! tree t, args;
! VEC(tree,heap) *v = NULL;
va_list p;
va_start (p, return_type);
-
for (t = va_arg (p, tree); t != NULL_TREE; t = va_arg (p, tree))
! VEC_safe_push (tree, heap, v, t);
!
! VEC_safe_push (tree, heap, v, void_type_node);
!
! args = vec_heap2parm_types (v);
! VEC_free (tree, heap, v);
! args = build_function_type (return_type, args);
va_end (p);
! return args;
}
/* Build a METHOD_TYPE for a member of BASETYPE. The RETTYPE (a TYPE)
--- 5277,5303 ----
tree
build_function_type_list (tree return_type, ...)
{
! tree t, parm_types;
va_list p;
+ int len = 0;
+ int i;
+ /* Determine the length of the parameter list. */
va_start (p, return_type);
for (t = va_arg (p, tree); t != NULL_TREE; t = va_arg (p, tree))
! len++;
! va_end (p);
! /* We add one because we are going to append void_type_node. */
! parm_types = alloc_parm_types (len + 1);
+ va_start (p, return_type);
+ for (i = 0; i < len; i++)
+ *(nth_parm_type_ptr (parm_types, i)) = va_arg (p, tree);
+ *(nth_parm_type_ptr (parm_types, i)) = void_type_node;
va_end (p);
!
! return build_function_type (return_type, parm_types);
}
/* Build a METHOD_TYPE for a member of BASETYPE. The RETTYPE (a TYPE)
More information about the Gcc-patches
mailing list