On Fri, Oct 26, 2018 at 9:12 AM Jan Hubicka <hubi...@ucw.cz> wrote: > > Hi, > this patch frees TYPE_DECL and alignment from TYPE_DECL and also preserves > only those TYPE_DECL pointers that are actually used to build ODR type tree. > > It reduces number of TYPE_DECLs streamed from WPA to ltrans to about 20% > and is important for the patch turning types to incomplete types. Without > this change the TREE_TYPE of TYPE_DECL would still point back to complete type > and duplicating TYPE_DECLs as well is somewhat laborious.
So the following is the really important hunk, correct? > @@ -5174,7 +5174,7 @@ free_lang_data_in_type (tree type) > > /* Drop TYPE_DECLs in TYPE_NAME in favor of the identifier in the > TYPE_DECL if the type doesn't have linkage. */ > - if (! type_with_linkage_p (type)) > + if (type != TYPE_MAIN_VARIANT (type) || ! type_with_linkage_p (type)) > { > TYPE_NAME (type) = TYPE_IDENTIFIER (type); > TYPE_STUB_DECL (type) = NULL; Can you explain why you "free" alignment of TYPE_DECLs? It's just some bits... does the FE somehow re-use those for sth else? I wouldn't have expected those to be set to anything meaningful. I'm not too comfortable with setting TREE_TYPE of a TYPE_DECL to NULL. Can we instead use void_type_node? The tree-inline.c hunk should probably test whether DECL_ORIGINAL_TYPE is non-null instead. Richard. > Bootstrapped/regtested x86_64-linux, OK? > > Honza > > * tree-inline.c (remap_decl): Be ready that TREE_TYPE of TYPE_DECL > may be NULL. > * tree-pretty-print.c (dump_generic_node): Likewise. > * tree.c (free_lang_data_in_type): Free more type decls. > (free_lang_data_in_decl): Free type and alignment of TYPE_DECL. > Index: tree-inline.c > =================================================================== > --- tree-inline.c (revision 265492) > +++ tree-inline.c (working copy) > @@ -382,7 +382,7 @@ remap_decl (tree decl, copy_body_data *i > /* Preserve the invariant that DECL_ORIGINAL_TYPE != TREE_TYPE, > which is enforced in gen_typedef_die when DECL_ABSTRACT_ORIGIN > is not set on the TYPE_DECL, for example in LTO mode. */ > - if (DECL_ORIGINAL_TYPE (t) == TREE_TYPE (t)) > + if (TREE_TYPE (t) && DECL_ORIGINAL_TYPE (t) == TREE_TYPE (t)) > { > tree x = build_variant_type_copy (TREE_TYPE (t)); > TYPE_STUB_DECL (x) = TYPE_STUB_DECL (TREE_TYPE (t)); > Index: tree-pretty-print.c > =================================================================== > --- tree-pretty-print.c (revision 265492) > +++ tree-pretty-print.c (working copy) > @@ -1896,7 +1896,7 @@ dump_generic_node (pretty_printer *pp, t > } > if (DECL_NAME (node)) > dump_decl_name (pp, node, flags); > - else if (TYPE_NAME (TREE_TYPE (node)) != node) > + else if (TREE_TYPE (node) && TYPE_NAME (TREE_TYPE (node)) != node) > { > pp_string (pp, (TREE_CODE (TREE_TYPE (node)) == UNION_TYPE > ? "union" : "struct ")); > Index: tree.c > =================================================================== > --- tree.c (revision 265492) > +++ tree.c (working copy) > @@ -5174,7 +5174,7 @@ free_lang_data_in_type (tree type) > > /* Drop TYPE_DECLs in TYPE_NAME in favor of the identifier in the > TYPE_DECL if the type doesn't have linkage. */ > - if (! type_with_linkage_p (type)) > + if (type != TYPE_MAIN_VARIANT (type) || ! type_with_linkage_p (type)) > { > TYPE_NAME (type) = TYPE_IDENTIFIER (type); > TYPE_STUB_DECL (type) = NULL; > @@ -5354,6 +5354,8 @@ free_lang_data_in_decl (tree decl) > DECL_VISIBILITY_SPECIFIED (decl) = 0; > DECL_INITIAL (decl) = NULL_TREE; > DECL_ORIGINAL_TYPE (decl) = NULL_TREE; > + TREE_TYPE (decl) = NULL_TREE; > + SET_DECL_ALIGN (decl, 0); > } > else if (TREE_CODE (decl) == FIELD_DECL) > DECL_INITIAL (decl) = NULL_TREE;