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]

Re: [PATCH] gc-improv merge (2/n): make gengtype output typed allocators


On Thu, May 6, 2010 at 2:07 PM, Laurynas Biveinis
<laurynas.biveinis@gmail.com> wrote:
> This contains the gengtype changes:
> 1) To accept a new GTY option "variable_size" for types where knowing
> the type is not enough to know the number of bytes that needto be
> allocated
> 2) To output all kinds of typed allocators.
>
> The sample output for a simple type, from gtype-desc.h:
>
> #define ggc_alloc_string_descriptor() ((struct string_descriptor
> *)(ggc_internal_alloc_stat (sizeof (struct string_descriptor)
> MEM_STAT_INFO)))
> #define ggc_alloc_cleared_string_descriptor() ((struct
> string_descriptor *)(ggc_internal_cleared_alloc_stat (sizeof (struct
> string_descriptor) MEM_STAT_INFO)))
> #define ggc_alloc_vec_string_descriptor(n) ((struct string_descriptor
> *)(ggc_internal_vec_alloc_stat (sizeof (struct string_descriptor), n
> MEM_STAT_INFO)))
> #define ggc_alloc_cleared_vec_string_descriptor(n) ((struct
> string_descriptor *)(ggc_internal_cleared_vec_alloc_stat (sizeof
> (struct string_descriptor), n MEM_STAT_INFO)))
> #define ggc_alloc_zone_string_descriptor(z) ((struct string_descriptor
> *)(ggc_internal_zone_alloc_stat (z, sizeof (struct string_descriptor)
> MEM_STAT_INFO)))
> #define ggc_alloc_zone_cleared_string_descriptor(z) ((struct
> string_descriptor *)(ggc_internal_zone_cleared_alloc_stat (z, sizeof
> (struct string_descriptor) MEM_STAT_INFO)))
> #define ggc_alloc_zone_vec_string_descriptor(n, z) ((struct
> string_descriptor *)(ggc_internal_zone_vec_alloc_stat (z, sizeof
> (struct string_descriptor), n MEM_STAT_INFO)))
> #define ggc_alloc_zone_cleared_vec_string_descriptor(n, z) ((struct
> string_descriptor *)(ggc_internal_zone_cleared_vec_alloc_stat (z,
> sizeof (struct string_descriptor), n MEM_STAT_INFO)))
>
> This output shows the following types of allocators:
> 1) ggc_alloc_foo () - simple allocator
> 2) ggc_alloc_cleared_foo () - additionally clears the allocated memory
> 3) ggc_alloc_vec_foo (n) - allocates array for n instances of foo
> 4) ggc_alloc_cleared_vec_foo (n) - additionally clears the allocated memory
> 5) ggc_alloc_zone_foo (z) - allocates in the specified zone
> 6) to 8) - correspond to 2) to 5) with zone allocation.
>
> The types that are annotated with variable_size GTY annotation receive
> allocators that take an extra size parameter.
>
> The types that are to be referenced from hash tables or splay trees
> additionally get callback allocators:
> gtype-desc.h:
> extern void * ggc_alloc_splay_tree_scalar_scalar_splay_tree_node_s
> (int, void *);
> gtype-desc.c:
> void * ggc_alloc_splay_tree_scalar_scalar_splay_tree_node_s (int sz, void * nl)
> {
> ?return ggc_splay_alloc (gt_e_II17splay_tree_node_s, sz, nl);
> }
>
> with automatically-generated names that try to include the names of
> types in question but be more readable than the other gengtype
> automatically-generated names such as
> gt_pch_p_P16var_loc_list_def4htab. The reason for this is that these
> callbacks will have to be specified manually:
>
> superset_entry->children
> ? ? ? ?= splay_tree_new_ggc (splay_tree_compare_ints,
> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?ggc_alloc_splay_tree_scalar_scalar_splay_tree_s,
>
> ggc_alloc_splay_tree_scalar_scalar_splay_tree_node_s);
>
> Such names as ggc_alloc_splay_tree_scalar_scalar_splay_tree_node_s
> will not win beauty contests, but I don't have a better idea how to
> name callbacks automatically.
>
> The implementations of these generated macros and functions depend on
> the other patches in the merge.
>
> Tested on x86_64/linux and many others.

+  bool third_arg = (zone == specific_zone) && (variable_size
+                                              || (quantity == vector));

please use an extra pair of () and align the && vertically instead.

+/*  Writes a typed GC allocator for type S that is suitable as a callback for
+    the splay tree implementation in libiberty.  */

too many leading spaces.

That we need to specialize splay-tree so much is a bit ugly,
but I guess we have to live with that for now.

Ok with the above changes.

Thanks,
Richard.

> 2010-05-06 ?Laurynas Biveinis ?<laurynas.biveinis@gmail.com>
>
> ? ? ? ?* gentype.c: Update copyright year.
> ? ? ? ?(walk_type): Accept variable_size GTY option.
> ? ? ? ?(USED_BY_TYPED_GC_P): New macro.
> ? ? ? ?(write_enum_defn): Use USED_BY_TYPED_GC_P. ?Do not output
> ? ? ? ?whitespace at the end of strings.
> ? ? ? ?(get_type_specifier, variable_size_p): New functions.
> ? ? ? ?(alloc_quantity, alloc_zone): New enums.
> ? ? ? ?(write_typed_alloc_def): New function.
> ? ? ? ?(write_typed_struct_alloc_def): Likewise.
> ? ? ? ?(write_typed_typed_typedef_alloc_def): Likewise.
> ? ? ? ?(write_typed_alloc_defns): Likewise.
> ? ? ? ?(output_typename, write_splay_tree_allocator_def): Likewise.
> ? ? ? ?(write_splay_tree_allocators): Likewise.
> ? ? ? ?(main): Call write_typed_alloc_defns and
> ? ? ? ?write_splay_tree_allocators.
>
> --
> Laurynas
>


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