Patchwork PATCH [trunk] gengtype should generate ggc_alloc macros in plugin mode on for plugin files

login
register
mail settings
Submitter Basile Starynkevitch
Date April 11, 2011, 1:35 a.m.
Message ID <20110411033552.75423cd2.basile@starynkevitch.net>
Download mbox | patch
Permalink /patch/90546/
State New
Headers show

Comments

Basile Starynkevitch - April 11, 2011, 1:35 a.m.
On Fri, 8 Apr 2011 19:55:51 +0200
Basile Starynkevitch <basile@starynkevitch.net> wrote:

> Committed revision 172203 (on trunk).
> 
> Actually, the above committed patch is better than nothing, but not
> perfect. It happens to generate ggc_alloc macros for things which are
> not defined in the plugin (however, this is not a big deal in practice,
> since it generates some macros in common with those inside
> gtype-desc.h).
> 
> I have no clear idea on how to improve it. We could for instance write
> the ggc_alloc macros only for struct & typedefs defined in the plugin
> files. We then would need a way to know if a file is a plugin file or
> not.  What do you think?

The attached file improves the situation, by flagging input files and
generating ggc_alloc macros only relevant to plugin files.
########## gcc/ChangeLog entry #####
2011-04-11  Basile Starynkevitch  <basile@starynkevitch.net>

        * gengtype.h (struct input_file_st): Add inpisplugin field.
	(type_fileloc): New function.
	* gengtype.c
	(write_typed_struct_alloc_def): Add gcc_assert.
	(write_typed_alloc_defns): Ditto. Don't output for plugin files.
	(write_typed_alloc_defns): Don't output for plugin files.
	(input_file_by_name): Clear inpisplugin field.
	(main): Set inpisplugin field for plugin files.
########

Comments are welcome. Ok for trunk with what changes?

Regards.
Laurynas Biveinis - April 15, 2011, 3:38 a.m.
2011/4/11 Basile Starynkevitch <basile@starynkevitch.net>:
> On Fri, 8 Apr 2011 19:55:51 +0200
> Basile Starynkevitch <basile@starynkevitch.net> wrote:
>
>> Committed revision 172203 (on trunk).
>>
>> Actually, the above committed patch is better than nothing, but not
>> perfect. It happens to generate ggc_alloc macros for things which are
>> not defined in the plugin (however, this is not a big deal in practice,
>> since it generates some macros in common with those inside
>> gtype-desc.h).
>>
>> I have no clear idea on how to improve it. We could for instance write
>> the ggc_alloc macros only for struct & typedefs defined in the plugin
>> files. We then would need a way to know if a file is a plugin file or
>> not.  What do you think?
>
> The attached file improves the situation, by flagging input files and
> generating ggc_alloc macros only relevant to plugin files.

What about include files in plugins? Are these marked as input files?
Basile Starynkevitch - April 15, 2011, 5:41 a.m.
On Fri, 15 Apr 2011 06:38:46 +0300
Laurynas Biveinis <laurynas.biveinis@gmail.com> wrote:

> 2011/4/11 Basile Starynkevitch <basile@starynkevitch.net>:
> >
> > The attached file improves the situation, by flagging input files and
> > generating ggc_alloc macros only relevant to plugin files.
> 
> What about include files in plugins? Are these marked as input files?

The plugin input files are those passed on the command line.

You can pass gengtype -P gt-plugin.h yourplugin.h plugin1.c plugin2.c

Regards
Laurynas Biveinis - April 19, 2011, 3:42 a.m.
On 04/11/2011 04:35 AM, Basile Starynkevitch wrote:
> 2011-04-11  Basile Starynkevitch  <basile@starynkevitch.net>
>
>         * gengtype.h (struct input_file_st): Add inpisplugin field.
> 	(type_fileloc): New function.
> 	* gengtype.c
> 	(write_typed_struct_alloc_def): Add gcc_assert.
> 	(write_typed_alloc_defns): Ditto. Don't output for plugin files.
> 	(write_typed_alloc_defns): Don't output for plugin files.
> 	(input_file_by_name): Clear inpisplugin field.
> 	(main): Set inpisplugin field for plugin files.

Did you test this patch that it bootstraps and that a GTY-using plugin
gets the right set of definitions in the output?

> @@ -4814,6 +4830,7 @@ input_file_by_name (const char* name)
>    f = XCNEWVAR (input_file, sizeof (input_file)+namlen+2);
>    f->inpbitmap = 0;
>    f->inpoutf = NULL;
> +  f->inpisplugin = 0;

= false;

> @@ -304,6 +305,7 @@ struct type {
>    } u;
>  };
>
> +
>  /* The one and only TYPE_STRING.  */
>  extern struct type string_type;
>

Please drop this.

OK with these changes and confirmation that the patch was tested.

Thanks,
Laurynas
Basile Starynkevitch - April 19, 2011, 9:46 a.m.
On Tue, 19 Apr 2011 06:42:58 +0300
Laurynas Biveinis <laurynas.biveinis@gmail.com> wrote:
> 
> Did you test this patch that it bootstraps and that a GTY-using plugin
> gets the right set of definitions in the output?

I checked both (using MELT as the plugin to test it). 
I very slightly & trivially improved the patch by updating the copyright year of gengtype.h and by 
replacing in the patch of write_typed_struct_alloc_def
+      gcc_assert (s->kind == TYPE_STRUCT || s->kind == TYPE_UNION
+		  || s->kind == TYPE_LANG_STRUCT);
with the more readable & shorter equivalent
       gcc_assert (UNION_OR_STRUCT_P (s));



> OK with these changes and confirmation that the patch was tested.

Committed revision 172705.

Thanks

Patch

Index: gcc/gengtype.c
===================================================================
--- gcc/gengtype.c	(revision 172252)
+++ gcc/gengtype.c	(working copy)
@@ -4235,6 +4235,7 @@  write_typed_struct_alloc_def (outf_p f,
 			      enum alloc_quantity quantity,
 			      enum alloc_zone zone)
 {
+  gcc_assert (UNION_OR_STRUCT_P(s));
   write_typed_alloc_def (f, variable_size_p (s), get_type_specifier (s),
                          s->u.s.tag, allocator_type, quantity, zone);
 }
@@ -4269,6 +4270,13 @@  write_typed_alloc_defns (outf_p f,
     {
       if (!USED_BY_TYPED_GC_P (s))
 	continue;
+      gcc_assert (s->kind == TYPE_STRUCT || s->kind == TYPE_UNION
+		  || s->kind == TYPE_LANG_STRUCT);
+      /* In plugin mode onput output ggc_alloc macro definitions
+	 relevant to plugin input files.  */
+      if (nb_plugin_files > 0 
+	  && ((s->u.s.line.file == NULL) || !s->u.s.line.file->inpisplugin))
+	continue;
       write_typed_struct_alloc_def (f, s, "", single, any_zone);
       write_typed_struct_alloc_def (f, s, "cleared_", single, any_zone);
       write_typed_struct_alloc_def (f, s, "vec_", vector, any_zone);
@@ -4287,6 +4295,14 @@  write_typed_alloc_defns (outf_p f,
       s = p->type;
       if (!USED_BY_TYPED_GC_P (s) || (strcmp (p->name, s->u.s.tag) == 0))
 	continue;
+      /* In plugin mode onput output ggc_alloc macro definitions
+	 relevant to plugin input files.  */
+      if (nb_plugin_files > 0) 
+	{
+	  struct fileloc* filoc = type_fileloc(s);
+	  if (!filoc || !filoc->file->inpisplugin)
+	    continue;
+	};
       write_typed_typedef_alloc_def (f, p, "", single, any_zone);
       write_typed_typedef_alloc_def (f, p, "cleared_", single, any_zone);
       write_typed_typedef_alloc_def (f, p, "vec_", vector, any_zone);
@@ -4814,6 +4830,7 @@  input_file_by_name (const char* name)
   f = XCNEWVAR (input_file, sizeof (input_file)+namlen+2);
   f->inpbitmap = 0;
   f->inpoutf = NULL;
+  f->inpisplugin = 0;
   strcpy (f->inpname, name);
   slot = htab_find_slot (input_file_htab, f, INSERT);
   gcc_assert (slot != NULL);
@@ -4945,8 +4962,11 @@  main (int argc, char **argv)
 
       /* Parse our plugin files and augment the state.  */
       for (ix = 0; ix < nb_plugin_files; ix++)
-	parse_file (get_input_file_name (plugin_files[ix]));
-
+	{
+	  input_file* pluginput = plugin_files [ix];
+	  pluginput->inpisplugin = true;
+	  parse_file (get_input_file_name (pluginput));
+	}
       if (hit_error)
 	return 1;
 
Index: gcc/gengtype.h
===================================================================
--- gcc/gengtype.h	(revision 172252)
+++ gcc/gengtype.h	(working copy)
@@ -33,6 +33,7 @@  struct input_file_st
   struct outf* inpoutf;  /* Cached corresponding output file, computed
                             in get_output_file_with_visibility.  */
   lang_bitmap inpbitmap; /* The set of languages using this file.  */
+  bool inpisplugin;      /* Flag set for plugin input files.  */
   char inpname[1];       /* A variable-length array, ended by a null
                             char.  */
 };
@@ -304,6 +305,7 @@  struct type {
   } u;
 };
 
+
 /* The one and only TYPE_STRING.  */
 extern struct type string_type;
 
@@ -328,6 +330,19 @@  extern struct type scalar_char;
 
 
 
+/* Give the file location of a type, if any. */
+static inline struct fileloc* 
+type_fileloc (type_p t)
+{
+  if (!t) 
+    return NULL;
+  if (UNION_OR_STRUCT_P(t))
+    return &t->u.s.line;
+  if  (t->kind == TYPE_PARAM_STRUCT)
+    return &t->u.param_struct.line;
+  return NULL;
+}
+
 /* Structure representing an output file.  */
 struct outf
 {