This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] avoid chainon when building record types in Fortran FE
- From: Mikael Morin <mikael dot morin at sfr dot fr>
- To: Nathan Froyd <froydnj at codesourcery dot com>
- Cc: gcc-patches at gcc dot gnu dot org, fortran at gcc dot gnu dot org
- Date: Fri, 02 Jul 2010 17:22:02 +0200
- Subject: Re: [PATCH] avoid chainon when building record types in Fortran FE
- References: <20100702134406.GC17877@codesourcery.com>
Le 02.07.2010 15:44, Nathan Froyd a écrit :
The Fortran FE builds up the fields for RECORD_TYPEs with repeated use
of chainon:
list = chainon (list, decl);
list = chainon (list, decl);
...
which does more work than it needs to. This patch addresses that by
adding a parameter to gfc_add_field_to_struct that points to the end
(last TREE_CHAIN field, really) of the field list being built. It also
makes gfc_add_field_to_struct be used in a few more places, though with
a bit of complexity, as we have to be careful to not add alignment
information where it wasn't present before.
Tested on x86_64-unknown-linux-gnu. OK to commit?
[...]
@@ -1853,26 +1841,44 @@ gfc_finish_type (tree type)
}
/* Add a field of given NAME and TYPE to the context of a UNION_TYPE
- or RECORD_TYPE pointed to by STYPE. The new field is chained
- to the fieldlist pointed to by FIELDLIST.
+ or RECORD_TYPE pointed to by CONTEXT. The new field is chained
+ to the fieldlist pointed to by FIELDLIST through *CHAIN.
Returns a pointer to the new field. */
+static tree
+gfc_add_field_to_struct_1 (tree *fieldlist, tree context,
+ tree name, tree type, tree **chain)
+{
+ tree decl = build_decl (input_location, FIELD_DECL, name, type);
+
+ DECL_CONTEXT (decl) = context;
+ TREE_CHAIN (decl) = NULL_TREE;
+ if (*fieldlist == NULL_TREE)
+ *fieldlist = decl;
It seems you can remove fieldlist from the the parameters and use
TYPE_FIELDS(context) instead here.
OK with that change.
Actually, OK even without it.
Mikael
+ if (chain != NULL)
+ {
+ if (*chain != NULL)
+ **chain = decl;
+ *chain =&TREE_CHAIN (decl);
+ }
+
+ return decl;
+}
+
+/* Like `gfc_add_field_to_struct_1', but adds alignment
+ information. */
+
tree
gfc_add_field_to_struct (tree *fieldlist, tree context,
- tree name, tree type)
+ tree name, tree type, tree **chain)
{
- tree decl;
+ tree decl = gfc_add_field_to_struct_1 (fieldlist, context,
+ name, type, chain);
- decl = build_decl (input_location,
- FIELD_DECL, name, type);
-
- DECL_CONTEXT (decl) = context;
DECL_INITIAL (decl) = 0;
DECL_ALIGN (decl) = 0;
DECL_USER_ALIGN (decl) = 0;
- TREE_CHAIN (decl) = NULL_TREE;
- *fieldlist = chainon (*fieldlist, decl);
return decl;
}
[...]