LCOV - code coverage report
Current view: top level - gcc - ipa-free-lang-data.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 95.8 % 526 504
Test Date: 2024-03-23 14:05:01 Functions: 95.8 % 24 23
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* Pass to free or clear language-specific data structures from
       2                 :             :    the IL before they reach the middle end.
       3                 :             : 
       4                 :             :    Copyright (C) 1987-2024 Free Software Foundation, Inc.
       5                 :             : 
       6                 :             :    This file is part of GCC.
       7                 :             : 
       8                 :             :    GCC is free software; you can redistribute it and/or modify it under
       9                 :             :    the terms of the GNU General Public License as published by the Free
      10                 :             :    Software Foundation; either version 3, or (at your option) any later
      11                 :             :    version.
      12                 :             : 
      13                 :             :    GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      14                 :             :    WARRANTY; without even the implied warranty of MERCHANTABILITY or
      15                 :             :    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      16                 :             :    for more details.
      17                 :             : 
      18                 :             :    You should have received a copy of the GNU General Public License
      19                 :             :    along with GCC; see the file COPYING3.  If not see
      20                 :             :    <http://www.gnu.org/licenses/>.  */
      21                 :             : 
      22                 :             : /* This file contains the low level primitives for operating on tree nodes,
      23                 :             :    including allocation, list operations, interning of identifiers,
      24                 :             :    construction of data type nodes and statement nodes,
      25                 :             :    and construction of type conversion nodes.  It also contains
      26                 :             :    tables index by tree code that describe how to take apart
      27                 :             :    nodes of that code.
      28                 :             : 
      29                 :             :    It is intended to be language-independent but can occasionally
      30                 :             :    calls language-dependent routines.  */
      31                 :             : 
      32                 :             : #include "config.h"
      33                 :             : #include "system.h"
      34                 :             : #include "coretypes.h"
      35                 :             : #include "backend.h"
      36                 :             : #include "target.h"
      37                 :             : #include "tree.h"
      38                 :             : #include "gimple.h"
      39                 :             : #include "tree-pass.h"
      40                 :             : #include "ssa.h"
      41                 :             : #include "cgraph.h"
      42                 :             : #include "diagnostic.h"
      43                 :             : #include "alias.h"
      44                 :             : #include "attribs.h"
      45                 :             : #include "langhooks.h"
      46                 :             : #include "gimple-iterator.h"
      47                 :             : #include "langhooks-def.h"
      48                 :             : #include "tree-diagnostic.h"
      49                 :             : #include "except.h"
      50                 :             : #include "ipa-utils.h"
      51                 :             : 
      52                 :             : namespace {
      53                 :             : 
      54                 :             : /* Data used when collecting DECLs and TYPEs for language data removal.  */
      55                 :             : 
      56                 :             : class free_lang_data_d
      57                 :             : {
      58                 :             : public:
      59                 :      230024 :   free_lang_data_d () : decls (100), types (100) {}
      60                 :             : 
      61                 :             :   /* Worklist to avoid excessive recursion.  */
      62                 :             :   auto_vec<tree> worklist;
      63                 :             : 
      64                 :             :   /* Set of traversed objects.  Used to avoid duplicate visits.  */
      65                 :             :   hash_set<tree> pset;
      66                 :             : 
      67                 :             :   /* Array of symbols to process with free_lang_data_in_decl.  */
      68                 :             :   auto_vec<tree> decls;
      69                 :             : 
      70                 :             :   /* Array of types to process with free_lang_data_in_type.  */
      71                 :             :   auto_vec<tree> types;
      72                 :             : };
      73                 :             : 
      74                 :             : 
      75                 :             : /* Add type or decl T to one of the list of tree nodes that need their
      76                 :             :    language data removed.  The lists are held inside FLD.  */
      77                 :             : 
      78                 :             : static void
      79                 :    12801984 : add_tree_to_fld_list (tree t, class free_lang_data_d *fld)
      80                 :             : {
      81                 :    12801984 :   if (DECL_P (t))
      82                 :     9174137 :     fld->decls.safe_push (t);
      83                 :     3627847 :   else if (TYPE_P (t))
      84                 :     3627847 :     fld->types.safe_push (t);
      85                 :             :   else
      86                 :           0 :     gcc_unreachable ();
      87                 :    12801984 : }
      88                 :             : 
      89                 :             : /* Push tree node T into FLD->WORKLIST.  */
      90                 :             : 
      91                 :             : static inline void
      92                 :   149553534 : fld_worklist_push (tree t, class free_lang_data_d *fld)
      93                 :             : {
      94                 :   221699042 :   if (t && !is_lang_specific (t) && !fld->pset.contains (t))
      95                 :    33589179 :     fld->worklist.safe_push ((t));
      96                 :   149553534 : }
      97                 :             : 
      98                 :             : 
      99                 :             : 
     100                 :             : /* Return simplified TYPE_NAME of TYPE.  */
     101                 :             : 
     102                 :             : static tree
     103                 :     4377733 : fld_simplified_type_name (tree type)
     104                 :             : {
     105                 :     4377733 :   if (!TYPE_NAME (type) || TREE_CODE (TYPE_NAME (type)) != TYPE_DECL)
     106                 :     3879360 :     return TYPE_NAME (type);
     107                 :             :   /* Drop TYPE_DECLs in TYPE_NAME in favor of the identifier in the
     108                 :             :      TYPE_DECL if the type doesn't have linkage.
     109                 :             :      this must match fld_  */
     110                 :      498373 :   if (type != TYPE_MAIN_VARIANT (type)
     111                 :      498373 :       || (!DECL_ASSEMBLER_NAME_SET_P (TYPE_NAME (type))
     112                 :      236202 :           && (TREE_CODE (type) != RECORD_TYPE
     113                 :       25681 :               || !TYPE_BINFO (type)
     114                 :           0 :               || !BINFO_VTABLE (TYPE_BINFO (type)))))
     115                 :      442253 :     return DECL_NAME (TYPE_NAME (type));
     116                 :       56120 :   return TYPE_NAME (type);
     117                 :             : }
     118                 :             : 
     119                 :             : /* Do same comparsion as check_qualified_type skipping lang part of type
     120                 :             :    and be more permissive about type names: we only care that names are
     121                 :             :    same (for diagnostics) and that ODR names are the same.
     122                 :             :    If INNER_TYPE is non-NULL, be sure that TREE_TYPE match it.  */
     123                 :             : 
     124                 :             : static bool
     125                 :      453628 : fld_type_variant_equal_p (tree t, tree v, tree inner_type)
     126                 :             : {
     127                 :      453628 :   if (TYPE_QUALS (t) != TYPE_QUALS (v)
     128                 :             :       /* We want to match incomplete variants with complete types.
     129                 :             :          In this case we need to ignore alignment.   */
     130                 :      359016 :       || ((!RECORD_OR_UNION_TYPE_P (t) || COMPLETE_TYPE_P (v))
     131                 :      256346 :           && (TYPE_ALIGN (t) != TYPE_ALIGN (v)
     132                 :      256334 :               || TYPE_USER_ALIGN (t) != TYPE_USER_ALIGN (v)))
     133                 :      359004 :       || fld_simplified_type_name (t) != fld_simplified_type_name (v)
     134                 :      315171 :       || !attribute_list_equal (TYPE_ATTRIBUTES (t),
     135                 :      315171 :                                 TYPE_ATTRIBUTES (v))
     136                 :      768799 :       || (inner_type && TREE_TYPE (v) != inner_type))
     137                 :      138457 :     return false;
     138                 :             : 
     139                 :             :   return true;
     140                 :             : }
     141                 :             : 
     142                 :             : /* Find variant of FIRST that match T and create new one if necessary.
     143                 :             :    Set TREE_TYPE to INNER_TYPE if non-NULL.  */
     144                 :             : 
     145                 :             : static tree
     146                 :      315171 : fld_type_variant (tree first, tree t, class free_lang_data_d *fld,
     147                 :             :                   tree inner_type = NULL)
     148                 :             : {
     149                 :      315171 :   if (first == TYPE_MAIN_VARIANT (t))
     150                 :             :     return t;
     151                 :      453628 :   for (tree v = first; v; v = TYPE_NEXT_VARIANT (v))
     152                 :      414434 :     if (fld_type_variant_equal_p (t, v, inner_type))
     153                 :      275977 :       return v;
     154                 :       39194 :   tree v = build_variant_type_copy (first);
     155                 :       39194 :   TYPE_READONLY (v) = TYPE_READONLY (t);
     156                 :       39194 :   TYPE_VOLATILE (v) = TYPE_VOLATILE (t);
     157                 :       39194 :   TYPE_ATOMIC (v) = TYPE_ATOMIC (t);
     158                 :       39194 :   TYPE_RESTRICT (v) = TYPE_RESTRICT (t);
     159                 :       39194 :   TYPE_ADDR_SPACE (v) = TYPE_ADDR_SPACE (t);
     160                 :       39194 :   TYPE_NAME (v) = TYPE_NAME (t);
     161                 :       39194 :   TYPE_ATTRIBUTES (v) = TYPE_ATTRIBUTES (t);
     162                 :       39194 :   TYPE_CANONICAL (v) = TYPE_CANONICAL (t);
     163                 :             :   /* Variants of incomplete types should have alignment
     164                 :             :      set to BITS_PER_UNIT.  Do not copy the actual alignment.  */
     165                 :       39194 :   if (!RECORD_OR_UNION_TYPE_P (v) || COMPLETE_TYPE_P (v))
     166                 :             :     {
     167                 :       18349 :       SET_TYPE_ALIGN (v, TYPE_ALIGN (t));
     168                 :       18349 :       TYPE_USER_ALIGN (v) = TYPE_USER_ALIGN (t);
     169                 :             :     }
     170                 :       39194 :   if (inner_type)
     171                 :          18 :     TREE_TYPE (v) = inner_type;
     172                 :       39194 :   gcc_checking_assert (fld_type_variant_equal_p (t,v, inner_type));
     173                 :       39194 :   if (!fld->pset.add (v))
     174                 :       39194 :     add_tree_to_fld_list (v, fld);
     175                 :             :   return v;
     176                 :             : }
     177                 :             : 
     178                 :             : /* Map complete types to incomplete types.  */
     179                 :             : 
     180                 :             : static hash_map<tree, tree> *fld_incomplete_types;
     181                 :             : 
     182                 :             : /* Map types to simplified types.  */
     183                 :             : 
     184                 :             : static hash_map<tree, tree> *fld_simplified_types;
     185                 :             : 
     186                 :             : /* Produce variant of T whose TREE_TYPE is T2. If it is main variant,
     187                 :             :    use MAP to prevent duplicates.  */
     188                 :             : 
     189                 :             : static tree
     190                 :        2815 : fld_process_array_type (tree t, tree t2, hash_map<tree, tree> *map,
     191                 :             :                         class free_lang_data_d *fld)
     192                 :             : {
     193                 :        2815 :   if (TREE_TYPE (t) == t2)
     194                 :             :     return t;
     195                 :             : 
     196                 :         146 :   if (TYPE_MAIN_VARIANT (t) != t)
     197                 :             :     {
     198                 :          18 :       return fld_type_variant
     199                 :          18 :         (fld_process_array_type (TYPE_MAIN_VARIANT (t),
     200                 :          18 :                                  TYPE_MAIN_VARIANT (t2), map, fld),
     201                 :          18 :          t, fld, t2);
     202                 :             :     }
     203                 :             : 
     204                 :         128 :   bool existed;
     205                 :         128 :   tree &array
     206                 :         128 :     = map->get_or_insert (t, &existed);
     207                 :         128 :   if (!existed)
     208                 :             :     {
     209                 :          30 :       array
     210                 :          30 :         = build_array_type_1 (t2, TYPE_DOMAIN (t), TYPE_TYPELESS_STORAGE (t),
     211                 :             :                               false, false);
     212                 :          30 :       TYPE_CANONICAL (array) = TYPE_CANONICAL (t);
     213                 :          30 :       if (!fld->pset.add (array))
     214                 :          30 :         add_tree_to_fld_list (array, fld);
     215                 :             :     }
     216                 :         128 :   return array;
     217                 :             : }
     218                 :             : 
     219                 :             : /* Return CTX after removal of contexts that are not relevant  */
     220                 :             : 
     221                 :             : static tree
     222                 :     8912121 : fld_decl_context (tree ctx)
     223                 :             : {
     224                 :             :   /* Variably modified types are needed for tree_is_indexable to decide
     225                 :             :      whether the type needs to go to local or global section.
     226                 :             :      This code is semi-broken but for now it is easiest to keep contexts
     227                 :             :      as expected.  */
     228                 :     7571648 :   if (ctx && TYPE_P (ctx)
     229                 :     8977043 :       && !variably_modified_type_p (ctx, NULL_TREE))
     230                 :             :     {
     231                 :      137024 :       while (ctx && TYPE_P (ctx))
     232                 :       72102 :         ctx = TYPE_CONTEXT (ctx);
     233                 :             :     }
     234                 :     8912121 :   return ctx;
     235                 :             : }
     236                 :             : 
     237                 :             : /* For T being aggregate type try to turn it into a incomplete variant.
     238                 :             :    Return T if no simplification is possible.  */
     239                 :             : 
     240                 :             : static tree
     241                 :     5420143 : fld_incomplete_type_of (tree t, class free_lang_data_d *fld)
     242                 :             : {
     243                 :     5420143 :   if (!t)
     244                 :             :     return NULL;
     245                 :     5420143 :   if (POINTER_TYPE_P (t))
     246                 :             :     {
     247                 :     2708665 :       tree t2 = fld_incomplete_type_of (TREE_TYPE (t), fld);
     248                 :     2708665 :       if (t2 != TREE_TYPE (t))
     249                 :             :         {
     250                 :      250366 :           tree first;
     251                 :      250366 :           if (TREE_CODE (t) == POINTER_TYPE)
     252                 :      226669 :             first = build_pointer_type_for_mode (t2, TYPE_MODE (t),
     253                 :      226669 :                                                  TYPE_REF_CAN_ALIAS_ALL (t));
     254                 :             :           else
     255                 :       23697 :             first = build_reference_type_for_mode (t2, TYPE_MODE (t),
     256                 :       23697 :                                                    TYPE_REF_CAN_ALIAS_ALL (t));
     257                 :      250366 :           gcc_assert (TYPE_CANONICAL (t2) != t2
     258                 :             :                       && TYPE_CANONICAL (t2) == TYPE_CANONICAL (TREE_TYPE (t)));
     259                 :      250366 :           if (!fld->pset.add (first))
     260                 :       53826 :             add_tree_to_fld_list (first, fld);
     261                 :      250366 :           return fld_type_variant (first, t, fld);
     262                 :             :         }
     263                 :             :       return t;
     264                 :             :     }
     265                 :     2711478 :   if (TREE_CODE (t) == ARRAY_TYPE)
     266                 :        2797 :     return fld_process_array_type (t,
     267                 :        2797 :                                    fld_incomplete_type_of (TREE_TYPE (t), fld),
     268                 :        2797 :                                    fld_incomplete_types, fld);
     269                 :     2708681 :   if ((!RECORD_OR_UNION_TYPE_P (t) && TREE_CODE (t) != ENUMERAL_TYPE)
     270                 :     2708681 :       || !COMPLETE_TYPE_P (t))
     271                 :             :     return t;
     272                 :      313536 :   if (TYPE_MAIN_VARIANT (t) == t)
     273                 :             :     {
     274                 :      248749 :       bool existed;
     275                 :      248749 :       tree &copy
     276                 :      248749 :         = fld_incomplete_types->get_or_insert (t, &existed);
     277                 :             : 
     278                 :      248749 :       if (!existed)
     279                 :             :         {
     280                 :       31753 :           copy = build_distinct_type_copy (t);
     281                 :             : 
     282                 :             :           /* It is possible that type was not seen by free_lang_data yet.  */
     283                 :       31753 :           if (!fld->pset.add (copy))
     284                 :       31753 :             add_tree_to_fld_list (copy, fld);
     285                 :       31753 :           TYPE_SIZE (copy) = NULL;
     286                 :       31753 :           TYPE_USER_ALIGN (copy) = 0;
     287                 :       31753 :           TYPE_SIZE_UNIT (copy) = NULL;
     288                 :       31753 :           TYPE_CANONICAL (copy) = TYPE_CANONICAL (t);
     289                 :       31753 :           TREE_ADDRESSABLE (copy) = 0;
     290                 :       31753 :           if (AGGREGATE_TYPE_P (t))
     291                 :             :             {
     292                 :       31685 :               SET_TYPE_MODE (copy, VOIDmode);
     293                 :       31685 :               SET_TYPE_ALIGN (copy, BITS_PER_UNIT);
     294                 :       31685 :               TYPE_TYPELESS_STORAGE (copy) = 0;
     295                 :       31685 :               TYPE_FIELDS (copy) = NULL;
     296                 :       31685 :               TYPE_BINFO (copy) = NULL;
     297                 :       31685 :               TYPE_FINAL_P (copy) = 0;
     298                 :       31685 :               TYPE_EMPTY_P (copy) = 0;
     299                 :             :             }
     300                 :             :           else
     301                 :             :             {
     302                 :          68 :               TYPE_VALUES (copy) = NULL;
     303                 :          68 :               ENUM_IS_OPAQUE (copy) = 0;
     304                 :          68 :               ENUM_IS_SCOPED (copy) = 0;
     305                 :             :             }
     306                 :             : 
     307                 :             :           /* Build copy of TYPE_DECL in TYPE_NAME if necessary.
     308                 :             :              This is needed for ODR violation warnings to come out right (we
     309                 :             :              want duplicate TYPE_DECLs whenever the type is duplicated because
     310                 :             :              of ODR violation.  Because lang data in the TYPE_DECL may not
     311                 :             :              have been freed yet, rebuild it from scratch and copy relevant
     312                 :             :              fields.  */
     313                 :       31753 :           TYPE_NAME (copy) = fld_simplified_type_name (copy);
     314                 :       31753 :           tree name = TYPE_NAME (copy);
     315                 :             : 
     316                 :       31753 :           if (name && TREE_CODE (name) == TYPE_DECL)
     317                 :             :             {
     318                 :        8542 :               gcc_checking_assert (TREE_TYPE (name) == t);
     319                 :        8542 :               tree name2 = build_decl (DECL_SOURCE_LOCATION (name), TYPE_DECL,
     320                 :        8542 :                                        DECL_NAME (name), copy);
     321                 :        8542 :               if (DECL_ASSEMBLER_NAME_SET_P (name))
     322                 :        8542 :                 SET_DECL_ASSEMBLER_NAME (name2, DECL_ASSEMBLER_NAME (name));
     323                 :        8542 :               SET_DECL_ALIGN (name2, 0);
     324                 :        8542 :               DECL_CONTEXT (name2) = fld_decl_context
     325                 :        8542 :                 (DECL_CONTEXT (name));
     326                 :        8542 :               TYPE_NAME (copy) = name2;
     327                 :             :             }
     328                 :             :         }
     329                 :      248749 :       return copy;
     330                 :             :     }
     331                 :       64787 :   return (fld_type_variant
     332                 :       64787 :           (fld_incomplete_type_of (TYPE_MAIN_VARIANT (t), fld), t, fld));
     333                 :             : }
     334                 :             : 
     335                 :             : /* Simplify type T for scenarios where we do not need complete pointer
     336                 :             :    types.  */
     337                 :             : 
     338                 :             : static tree
     339                 :    16642507 : fld_simplified_type (tree t, class free_lang_data_d *fld)
     340                 :             : {
     341                 :    16642507 :   if (!t)
     342                 :             :     return t;
     343                 :    16642507 :   if (POINTER_TYPE_P (t))
     344                 :     2643894 :     return fld_incomplete_type_of (t, fld);
     345                 :             :   /* FIXME: This triggers verification error, see PR88140.  */
     346                 :             : #if 0
     347                 :             :   if (TREE_CODE (t) == ARRAY_TYPE)
     348                 :             :     return fld_process_array_type (t, fld_simplified_type (TREE_TYPE (t), fld),
     349                 :             :                                    fld_simplified_types, fld);
     350                 :             : #endif
     351                 :             :   return t;
     352                 :             : }
     353                 :             : 
     354                 :             : /* Reset the expression *EXPR_P, a size or position.
     355                 :             : 
     356                 :             :    ??? We could reset all non-constant sizes or positions.  But it's cheap
     357                 :             :    enough to not do so and refrain from adding workarounds to dwarf2out.cc.
     358                 :             : 
     359                 :             :    We need to reset self-referential sizes or positions because they cannot
     360                 :             :    be gimplified and thus can contain a CALL_EXPR after the gimplification
     361                 :             :    is finished, which will run afoul of LTO streaming.  And they need to be
     362                 :             :    reset to something essentially dummy but not constant, so as to preserve
     363                 :             :    the properties of the object they are attached to.  */
     364                 :             : 
     365                 :             : static inline void
     366                 :    26493519 : free_lang_data_in_one_sizepos (tree *expr_p)
     367                 :             : {
     368                 :    26493519 :   tree expr = *expr_p;
     369                 :    26493519 :   if (CONTAINS_PLACEHOLDER_P (expr))
     370                 :           0 :     *expr_p = build0 (PLACEHOLDER_EXPR, TREE_TYPE (expr));
     371                 :    26493519 : }
     372                 :             : 
     373                 :             : 
     374                 :             : /* Reset all the fields in a binfo node BINFO.  We only keep
     375                 :             :    BINFO_VTABLE, which is used by gimple_fold_obj_type_ref.  */
     376                 :             : 
     377                 :             : static void
     378                 :       54691 : free_lang_data_in_binfo (tree binfo)
     379                 :             : {
     380                 :       54691 :   unsigned i;
     381                 :       54691 :   tree t;
     382                 :             : 
     383                 :       54691 :   gcc_assert (TREE_CODE (binfo) == TREE_BINFO);
     384                 :             : 
     385                 :       54691 :   BINFO_VIRTUALS (binfo) = NULL_TREE;
     386                 :       54691 :   BINFO_BASE_ACCESSES (binfo) = NULL;
     387                 :       54691 :   BINFO_INHERITANCE_CHAIN (binfo) = NULL_TREE;
     388                 :       54691 :   BINFO_SUBVTT_INDEX (binfo) = NULL_TREE;
     389                 :       54691 :   BINFO_VPTR_FIELD (binfo) = NULL_TREE;
     390                 :       54691 :   TREE_PUBLIC (binfo) = 0;
     391                 :             : 
     392                 :       78596 :   FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (binfo), i, t)
     393                 :       23905 :     free_lang_data_in_binfo (t);
     394                 :       54691 : }
     395                 :             : 
     396                 :             : 
     397                 :             : /* Reset all language specific information still present in TYPE.  */
     398                 :             : 
     399                 :             : static void
     400                 :     3627972 : free_lang_data_in_type (tree type, class free_lang_data_d *fld)
     401                 :             : {
     402                 :     3627972 :   gcc_assert (TYPE_P (type));
     403                 :             : 
     404                 :             :   /* Give the FE a chance to remove its own data first.  */
     405                 :     3627972 :   lang_hooks.free_lang_data (type);
     406                 :             : 
     407                 :     3627972 :   TREE_LANG_FLAG_0 (type) = 0;
     408                 :     3627972 :   TREE_LANG_FLAG_1 (type) = 0;
     409                 :     3627972 :   TREE_LANG_FLAG_2 (type) = 0;
     410                 :     3627972 :   TREE_LANG_FLAG_3 (type) = 0;
     411                 :     3627972 :   TREE_LANG_FLAG_4 (type) = 0;
     412                 :     3627972 :   TREE_LANG_FLAG_5 (type) = 0;
     413                 :     3627972 :   TREE_LANG_FLAG_6 (type) = 0;
     414                 :             : 
     415                 :     3627972 :   TYPE_NEEDS_CONSTRUCTING (type) = 0;
     416                 :             : 
     417                 :             :   /* Purge non-marked variants from the variants chain, so that they
     418                 :             :      don't reappear in the IL after free_lang_data.  */
     419                 :     3627972 :   while (TYPE_NEXT_VARIANT (type)
     420                 :     4136030 :          && !fld->pset.contains (TYPE_NEXT_VARIANT (type)))
     421                 :             :     {
     422                 :      508058 :       tree t = TYPE_NEXT_VARIANT (type);
     423                 :      508058 :       TYPE_NEXT_VARIANT (type) = TYPE_NEXT_VARIANT (t);
     424                 :             :       /* Turn the removed types into distinct types.  */
     425                 :      508058 :       TYPE_MAIN_VARIANT (t) = t;
     426                 :      508058 :       TYPE_NEXT_VARIANT (t) = NULL_TREE;
     427                 :             :     }
     428                 :             : 
     429                 :     3627972 :   if (TREE_CODE (type) == FUNCTION_TYPE)
     430                 :             :     {
     431                 :     2240138 :       TREE_TYPE (type) = fld_simplified_type (TREE_TYPE (type), fld);
     432                 :             :       /* Remove the const and volatile qualifiers from arguments.  The
     433                 :             :          C++ front end removes them, but the C front end does not,
     434                 :             :          leading to false ODR violation errors when merging two
     435                 :             :          instances of the same function signature compiled by
     436                 :             :          different front ends.  */
     437                 :     9276254 :       for (tree p = TYPE_ARG_TYPES (type); p; p = TREE_CHAIN (p))
     438                 :             :         {
     439                 :     7036116 :           TREE_VALUE (p) = fld_simplified_type (TREE_VALUE (p), fld);
     440                 :     7036116 :           tree arg_type = TREE_VALUE (p);
     441                 :             : 
     442                 :     7036116 :           if (TYPE_READONLY (arg_type) || TYPE_VOLATILE (arg_type))
     443                 :             :             {
     444                 :        6364 :               int quals = TYPE_QUALS (arg_type)
     445                 :             :                 & ~TYPE_QUAL_CONST
     446                 :        6364 :                 & ~TYPE_QUAL_VOLATILE;
     447                 :        6364 :               TREE_VALUE (p) = build_qualified_type (arg_type, quals);
     448                 :        6364 :               if (!fld->pset.add (TREE_VALUE (p)))
     449                 :         125 :                 free_lang_data_in_type (TREE_VALUE (p), fld);
     450                 :             :             }
     451                 :             :           /* C++ FE uses TREE_PURPOSE to store initial values.  */
     452                 :     7036116 :           TREE_PURPOSE (p) = NULL;
     453                 :             :         }
     454                 :             :     }
     455                 :             :   else if (TREE_CODE (type) == METHOD_TYPE)
     456                 :             :     {
     457                 :       59515 :       TREE_TYPE (type) = fld_simplified_type (TREE_TYPE (type), fld);
     458                 :      234802 :       for (tree p = TYPE_ARG_TYPES (type); p; p = TREE_CHAIN (p))
     459                 :             :         {
     460                 :             :           /* C++ FE uses TREE_PURPOSE to store initial values.  */
     461                 :      175287 :           TREE_VALUE (p) = fld_simplified_type (TREE_VALUE (p), fld);
     462                 :      175287 :           TREE_PURPOSE (p) = NULL;
     463                 :             :         }
     464                 :             :     }
     465                 :             :   else if (RECORD_OR_UNION_TYPE_P (type))
     466                 :             :     {
     467                 :             :       /* Remove members that are not FIELD_DECLs from the field list
     468                 :             :          of an aggregate.  These occur in C++.  */
     469                 :      855005 :       for (tree *prev = &TYPE_FIELDS (type), member; (member = *prev);)
     470                 :      676453 :         if (TREE_CODE (member) == FIELD_DECL)
     471                 :      345024 :           prev = &DECL_CHAIN (member);
     472                 :             :         else
     473                 :      331429 :           *prev = DECL_CHAIN (member);
     474                 :             : 
     475                 :      178552 :       TYPE_VFIELD (type) = NULL_TREE;
     476                 :             : 
     477                 :      178552 :       if (TYPE_BINFO (type))
     478                 :             :         {
     479                 :       30786 :           free_lang_data_in_binfo (TYPE_BINFO (type));
     480                 :             :           /* We need to preserve link to bases and virtual table for all
     481                 :             :              polymorphic types to make devirtualization machinery working.  */
     482                 :       30786 :           if (!BINFO_VTABLE (TYPE_BINFO (type)))
     483                 :       26763 :             TYPE_BINFO (type) = NULL;
     484                 :             :         }
     485                 :             :     }
     486                 :             :   else if (INTEGRAL_TYPE_P (type)
     487                 :             :            || SCALAR_FLOAT_TYPE_P (type)
     488                 :             :            || FIXED_POINT_TYPE_P (type))
     489                 :             :     {
     490                 :      318676 :       if (TREE_CODE (type) == ENUMERAL_TYPE)
     491                 :             :         {
     492                 :        3325 :           ENUM_IS_OPAQUE (type) = 0;
     493                 :        3325 :           ENUM_IS_SCOPED (type) = 0;
     494                 :             :           /* Type values are used only for C++ ODR checking.  Drop them
     495                 :             :              for all type variants and non-ODR types.
     496                 :             :              For ODR types the data is freed in free_odr_warning_data.  */
     497                 :        3325 :           if (!TYPE_VALUES (type))
     498                 :             :             ;
     499                 :        1090 :           else if (TYPE_MAIN_VARIANT (type) != type
     500                 :         739 :                    || !type_with_linkage_p (type)
     501                 :        1451 :                    || type_in_anonymous_namespace_p (type))
     502                 :         758 :             TYPE_VALUES (type) = NULL;
     503                 :             :           else
     504                 :         332 :             register_odr_enum (type);
     505                 :             :         }
     506                 :      318676 :       free_lang_data_in_one_sizepos (&TYPE_MIN_VALUE (type));
     507                 :      318676 :       free_lang_data_in_one_sizepos (&TYPE_MAX_VALUE (type));
     508                 :             :     }
     509                 :             : 
     510                 :     3627972 :   TYPE_LANG_SLOT_1 (type) = NULL_TREE;
     511                 :             : 
     512                 :     3627972 :   free_lang_data_in_one_sizepos (&TYPE_SIZE (type));
     513                 :     3627972 :   free_lang_data_in_one_sizepos (&TYPE_SIZE_UNIT (type));
     514                 :             : 
     515                 :     3627972 :   if (TYPE_CONTEXT (type)
     516                 :     3627972 :       && TREE_CODE (TYPE_CONTEXT (type)) == BLOCK)
     517                 :             :     {
     518                 :           0 :       tree ctx = TYPE_CONTEXT (type);
     519                 :           0 :       do
     520                 :             :         {
     521                 :           0 :           ctx = BLOCK_SUPERCONTEXT (ctx);
     522                 :             :         }
     523                 :           0 :       while (ctx && TREE_CODE (ctx) == BLOCK);
     524                 :           0 :       TYPE_CONTEXT (type) = ctx;
     525                 :             :     }
     526                 :             : 
     527                 :     3627972 :   TYPE_STUB_DECL (type) = NULL;
     528                 :     3627972 :   TYPE_NAME (type) = fld_simplified_type_name (type);
     529                 :     3627972 : }
     530                 :             : 
     531                 :             : /* Reset all language specific information still present in symbol
     532                 :             :    DECL.  */
     533                 :             : 
     534                 :             : static void
     535                 :     9174137 : free_lang_data_in_decl (tree decl, class free_lang_data_d *fld)
     536                 :             : {
     537                 :     9174137 :   gcc_assert (DECL_P (decl));
     538                 :             : 
     539                 :             :   /* Give the FE a chance to remove its own data first.  */
     540                 :     9174137 :   lang_hooks.free_lang_data (decl);
     541                 :             : 
     542                 :     9174137 :   TREE_LANG_FLAG_0 (decl) = 0;
     543                 :     9174137 :   TREE_LANG_FLAG_1 (decl) = 0;
     544                 :     9174137 :   TREE_LANG_FLAG_2 (decl) = 0;
     545                 :     9174137 :   TREE_LANG_FLAG_3 (decl) = 0;
     546                 :     9174137 :   TREE_LANG_FLAG_4 (decl) = 0;
     547                 :     9174137 :   TREE_LANG_FLAG_5 (decl) = 0;
     548                 :     9174137 :   TREE_LANG_FLAG_6 (decl) = 0;
     549                 :             : 
     550                 :     9174137 :   free_lang_data_in_one_sizepos (&DECL_SIZE (decl));
     551                 :     9174137 :   free_lang_data_in_one_sizepos (&DECL_SIZE_UNIT (decl));
     552                 :     9174137 :   if (TREE_CODE (decl) == FIELD_DECL)
     553                 :             :     {
     554                 :      251949 :       DECL_FCONTEXT (decl) = NULL;
     555                 :      251949 :       free_lang_data_in_one_sizepos (&DECL_FIELD_OFFSET (decl));
     556                 :      251949 :       if (TREE_CODE (DECL_CONTEXT (decl)) == QUAL_UNION_TYPE)
     557                 :           0 :         DECL_QUALIFIER (decl) = NULL_TREE;
     558                 :             :     }
     559                 :             : 
     560                 :     9174137 :   if (TREE_CODE (decl) == FUNCTION_DECL)
     561                 :             :     {
     562                 :     6879502 :       struct cgraph_node *node;
     563                 :             :       /* Frontends do not set TREE_ADDRESSABLE on public variables even though
     564                 :             :          the address may be taken in other unit, so this flag has no practical
     565                 :             :          use for middle-end.
     566                 :             : 
     567                 :             :          It would make more sense if frontends set TREE_ADDRESSABLE to 0 only
     568                 :             :          for public objects that indeed cannot be adressed, but it is not
     569                 :             :          the case.  Set the flag to true so we do not get merge failures for
     570                 :             :          i.e. virtual tables between units that take address of it and
     571                 :             :          units that don't.  */
     572                 :     6879502 :       if (TREE_PUBLIC (decl))
     573                 :     6867102 :         TREE_ADDRESSABLE (decl) = true;
     574                 :     6879502 :       TREE_TYPE (decl) = fld_simplified_type (TREE_TYPE (decl), fld);
     575                 :     6879502 :       if (!(node = cgraph_node::get (decl))
     576                 :     6879502 :           || (!node->definition && !node->clones))
     577                 :             :         {
     578                 :     6758179 :           if (node && !node->declare_variant_alt)
     579                 :      234710 :             node->release_body ();
     580                 :             :           else
     581                 :             :             {
     582                 :     6523469 :               release_function_body (decl);
     583                 :     6523469 :               DECL_ARGUMENTS (decl) = NULL;
     584                 :     6523469 :               DECL_RESULT (decl) = NULL;
     585                 :     6523469 :               DECL_INITIAL (decl) = error_mark_node;
     586                 :             :             }
     587                 :             :         }
     588                 :     6879502 :       if (gimple_has_body_p (decl) || (node && node->thunk))
     589                 :             :         {
     590                 :      115291 :           tree t;
     591                 :             : 
     592                 :             :           /* If DECL has a gimple body, then the context for its
     593                 :             :              arguments must be DECL.  Otherwise, it doesn't really
     594                 :             :              matter, as we will not be emitting any code for DECL.  In
     595                 :             :              general, there may be other instances of DECL created by
     596                 :             :              the front end and since PARM_DECLs are generally shared,
     597                 :             :              their DECL_CONTEXT changes as the replicas of DECL are
     598                 :             :              created.  The only time where DECL_CONTEXT is important
     599                 :             :              is for the FUNCTION_DECLs that have a gimple body (since
     600                 :             :              the PARM_DECL will be used in the function's body).  */
     601                 :      449271 :           for (t = DECL_ARGUMENTS (decl); t; t = TREE_CHAIN (t))
     602                 :      333980 :             DECL_CONTEXT (t) = decl;
     603                 :      115291 :           if (!DECL_FUNCTION_SPECIFIC_TARGET (decl))
     604                 :      115228 :             DECL_FUNCTION_SPECIFIC_TARGET (decl)
     605                 :      115228 :               = target_option_default_node;
     606                 :      115291 :           if (!DECL_FUNCTION_SPECIFIC_OPTIMIZATION (decl))
     607                 :      111568 :             DECL_FUNCTION_SPECIFIC_OPTIMIZATION (decl)
     608                 :      111568 :               = optimization_default_node;
     609                 :             :         }
     610                 :             : 
     611                 :             :       /* DECL_SAVED_TREE holds the GENERIC representation for DECL.
     612                 :             :          At this point, it is not needed anymore.  */
     613                 :     6879502 :       DECL_SAVED_TREE (decl) = NULL_TREE;
     614                 :             : 
     615                 :             :       /* Clear the abstract origin if it refers to a method.
     616                 :             :          Otherwise dwarf2out.cc will ICE as we splice functions out of
     617                 :             :          TYPE_FIELDS and thus the origin will not be output
     618                 :             :          correctly.  */
     619                 :     6879502 :       if (DECL_ABSTRACT_ORIGIN (decl)
     620                 :       24569 :           && DECL_CONTEXT (DECL_ABSTRACT_ORIGIN (decl))
     621                 :     6904071 :           && RECORD_OR_UNION_TYPE_P
     622                 :             :           (DECL_CONTEXT (DECL_ABSTRACT_ORIGIN (decl))))
     623                 :       13009 :         DECL_ABSTRACT_ORIGIN (decl) = NULL_TREE;
     624                 :             : 
     625                 :     6879502 :       DECL_VINDEX (decl) = NULL_TREE;
     626                 :             :     }
     627                 :             :   else if (VAR_P (decl))
     628                 :             :     {
     629                 :             :       /* See comment above why we set the flag for functions.  */
     630                 :      801305 :       if (TREE_PUBLIC (decl))
     631                 :      240148 :         TREE_ADDRESSABLE (decl) = true;
     632                 :      801305 :       if ((DECL_EXTERNAL (decl)
     633                 :        7488 :            && (!TREE_STATIC (decl) || !TREE_READONLY (decl)))
     634                 :      805500 :           || (decl_function_context (decl) && !TREE_STATIC (decl)))
     635                 :      537496 :         DECL_INITIAL (decl) = NULL_TREE;
     636                 :             :     }
     637                 :             :   else if (TREE_CODE (decl) == TYPE_DECL)
     638                 :             :     {
     639                 :      371516 :       DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
     640                 :      371516 :       DECL_VISIBILITY_SPECIFIED (decl) = 0;
     641                 :      371516 :       TREE_PUBLIC (decl) = 0;
     642                 :      371516 :       TREE_PRIVATE (decl) = 0;
     643                 :      371516 :       DECL_ARTIFICIAL (decl) = 0;
     644                 :      371516 :       TYPE_DECL_SUPPRESS_DEBUG (decl) = 0;
     645                 :      371516 :       DECL_INITIAL (decl) = NULL_TREE;
     646                 :      371516 :       DECL_ORIGINAL_TYPE (decl) = NULL_TREE;
     647                 :      371516 :       DECL_MODE (decl) = VOIDmode;
     648                 :      371516 :       SET_DECL_ALIGN (decl, 0);
     649                 :             :       /* TREE_TYPE is cleared at WPA time in free_odr_warning_data.  */
     650                 :             :     }
     651                 :             :   else if (TREE_CODE (decl) == FIELD_DECL)
     652                 :             :     {
     653                 :      251949 :       TREE_TYPE (decl) = fld_simplified_type (TREE_TYPE (decl), fld);
     654                 :      251949 :       DECL_INITIAL (decl) = NULL_TREE;
     655                 :             :     }
     656                 :             :   else if (TREE_CODE (decl) == TRANSLATION_UNIT_DECL
     657                 :       22488 :            && DECL_INITIAL (decl)
     658                 :       19209 :            && TREE_CODE (DECL_INITIAL (decl)) == BLOCK)
     659                 :             :     {
     660                 :             :       /* Strip builtins from the translation-unit BLOCK.  We still have targets
     661                 :             :          without builtin_decl_explicit support and also builtins are shared
     662                 :             :          nodes and thus we can't use TREE_CHAIN in multiple lists.  */
     663                 :       19209 :       tree *nextp = &BLOCK_VARS (DECL_INITIAL (decl));
     664                 :       19209 :       while (*nextp)
     665                 :             :         {
     666                 :           0 :           tree var = *nextp;
     667                 :           0 :           if (TREE_CODE (var) == FUNCTION_DECL
     668                 :           0 :               && fndecl_built_in_p (var))
     669                 :           0 :             *nextp = TREE_CHAIN (var);
     670                 :             :           else
     671                 :           0 :             nextp = &TREE_CHAIN (var);
     672                 :             :         }
     673                 :             :     }
     674                 :             :   /* We need to keep field decls associated with their trees. Otherwise tree
     675                 :             :      merging may merge some fields and keep others disjoint which in turn will
     676                 :             :      not do well with TREE_CHAIN pointers linking them.
     677                 :             : 
     678                 :             :      Also do not drop containing types for virtual methods and tables because
     679                 :             :      these are needed by devirtualization.
     680                 :             :      C++ destructors are special because C++ frontends sometimes produces
     681                 :             :      virtual destructor as an alias of non-virtual destructor.  In
     682                 :             :      devirutalization code we always walk through aliases and we need
     683                 :             :      context to be preserved too.  See PR89335  */
     684                 :     9174137 :   if (TREE_CODE (decl) != FIELD_DECL
     685                 :     9174137 :       && ((TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != FUNCTION_DECL)
     686                 :     7680807 :           || (!DECL_VIRTUAL_P (decl)
     687                 :     7669387 :               && (TREE_CODE (decl) != FUNCTION_DECL
     688                 :     6874450 :                   || !DECL_CXX_DESTRUCTOR_P (decl)))))
     689                 :     8903579 :     DECL_CONTEXT (decl) = fld_decl_context (DECL_CONTEXT (decl));
     690                 :     9174137 : }
     691                 :             : 
     692                 :             : 
     693                 :             : /* Operand callback helper for free_lang_data_in_node.  *TP is the
     694                 :             :    subtree operand being considered.  */
     695                 :             : 
     696                 :             : static tree
     697                 :    44743564 : find_decls_types_r (tree *tp, int *ws, void *data)
     698                 :             : {
     699                 :    44743564 :   tree t = *tp;
     700                 :    44743564 :   class free_lang_data_d *fld = (class free_lang_data_d *) data;
     701                 :             : 
     702                 :    44743564 :   if (TREE_CODE (t) == TREE_LIST)
     703                 :             :     return NULL_TREE;
     704                 :             : 
     705                 :             :   /* Language specific nodes will be removed, so there is no need
     706                 :             :      to gather anything under them.  */
     707                 :    25727259 :   if (is_lang_specific (t))
     708                 :             :     {
     709                 :           9 :       *ws = 0;
     710                 :           9 :       return NULL_TREE;
     711                 :             :     }
     712                 :             : 
     713                 :    25727250 :   if (DECL_P (t))
     714                 :             :     {
     715                 :             :       /* Note that walk_tree does not traverse every possible field in
     716                 :             :          decls, so we have to do our own traversals here.  */
     717                 :     9174137 :       add_tree_to_fld_list (t, fld);
     718                 :             : 
     719                 :     9174137 :       fld_worklist_push (DECL_NAME (t), fld);
     720                 :     9174137 :       fld_worklist_push (DECL_CONTEXT (t), fld);
     721                 :     9174137 :       fld_worklist_push (DECL_SIZE (t), fld);
     722                 :     9174137 :       fld_worklist_push (DECL_SIZE_UNIT (t), fld);
     723                 :             : 
     724                 :             :       /* We are going to remove everything under DECL_INITIAL for
     725                 :             :          TYPE_DECLs.  No point walking them.  */
     726                 :     9174137 :       if (TREE_CODE (t) != TYPE_DECL)
     727                 :     8802621 :         fld_worklist_push (DECL_INITIAL (t), fld);
     728                 :             : 
     729                 :     9174137 :       fld_worklist_push (DECL_ATTRIBUTES (t), fld);
     730                 :     9174137 :       fld_worklist_push (DECL_ABSTRACT_ORIGIN (t), fld);
     731                 :             : 
     732                 :     9174137 :       if (TREE_CODE (t) == FUNCTION_DECL)
     733                 :             :         {
     734                 :     6879502 :           fld_worklist_push (DECL_ARGUMENTS (t), fld);
     735                 :     6879502 :           fld_worklist_push (DECL_RESULT (t), fld);
     736                 :             :         }
     737                 :     2294635 :       else if (TREE_CODE (t) == FIELD_DECL)
     738                 :             :         {
     739                 :      251949 :           fld_worklist_push (DECL_FIELD_OFFSET (t), fld);
     740                 :      251949 :           fld_worklist_push (DECL_BIT_FIELD_TYPE (t), fld);
     741                 :      251949 :           fld_worklist_push (DECL_FIELD_BIT_OFFSET (t), fld);
     742                 :      251949 :           fld_worklist_push (DECL_FCONTEXT (t), fld);
     743                 :             :         }
     744                 :             : 
     745                 :     9174137 :       if ((VAR_P (t) || TREE_CODE (t) == PARM_DECL)
     746                 :     9174137 :           && DECL_HAS_VALUE_EXPR_P (t))
     747                 :        4067 :         fld_worklist_push (DECL_VALUE_EXPR (t), fld);
     748                 :             : 
     749                 :     9174137 :       if (TREE_CODE (t) != FIELD_DECL
     750                 :     9174137 :           && TREE_CODE (t) != TYPE_DECL)
     751                 :     8550672 :         fld_worklist_push (TREE_CHAIN (t), fld);
     752                 :     9174137 :       *ws = 0;
     753                 :             :     }
     754                 :    16553113 :   else if (TYPE_P (t))
     755                 :             :     {
     756                 :             :       /* Note that walk_tree does not traverse every possible field in
     757                 :             :          types, so we have to do our own traversals here.  */
     758                 :     3503044 :       add_tree_to_fld_list (t, fld);
     759                 :             : 
     760                 :     3503044 :       if (!RECORD_OR_UNION_TYPE_P (t))
     761                 :     3377024 :         fld_worklist_push (TYPE_CACHED_VALUES (t), fld);
     762                 :     3503044 :       fld_worklist_push (TYPE_SIZE (t), fld);
     763                 :     3503044 :       fld_worklist_push (TYPE_SIZE_UNIT (t), fld);
     764                 :     3503044 :       fld_worklist_push (TYPE_ATTRIBUTES (t), fld);
     765                 :     3503044 :       fld_worklist_push (TYPE_POINTER_TO (t), fld);
     766                 :     3503044 :       fld_worklist_push (TYPE_REFERENCE_TO (t), fld);
     767                 :     3503044 :       fld_worklist_push (TYPE_NAME (t), fld);
     768                 :             :       /* While we do not stream TYPE_POINTER_TO and TYPE_REFERENCE_TO
     769                 :             :          lists, we may look types up in these lists and use them while
     770                 :             :          optimizing the function body.  Thus we need to free lang data
     771                 :             :          in them.  */
     772                 :     3503044 :       if (TREE_CODE (t) == POINTER_TYPE)
     773                 :      590765 :         fld_worklist_push (TYPE_NEXT_PTR_TO (t), fld);
     774                 :     3503044 :       if (TREE_CODE (t) == REFERENCE_TYPE)
     775                 :       40486 :         fld_worklist_push (TYPE_NEXT_REF_TO (t), fld);
     776                 :     3503044 :       if (!POINTER_TYPE_P (t))
     777                 :     2871793 :         fld_worklist_push (TYPE_MIN_VALUE_RAW (t), fld);
     778                 :             :       /* TYPE_MAX_VALUE_RAW is TYPE_BINFO for record types.  */
     779                 :     3503044 :       if (!RECORD_OR_UNION_TYPE_P (t))
     780                 :     3377024 :         fld_worklist_push (TYPE_MAX_VALUE_RAW (t), fld);
     781                 :     3503044 :       fld_worklist_push (TYPE_MAIN_VARIANT (t), fld);
     782                 :             :       /* Do not walk TYPE_NEXT_VARIANT.  We do not stream it and thus
     783                 :             :          do not and want not to reach unused variants this way.  */
     784                 :     3503044 :       if (TYPE_CONTEXT (t))
     785                 :             :         {
     786                 :       31846 :           tree ctx = TYPE_CONTEXT (t);
     787                 :             :           /* We adjust BLOCK TYPE_CONTEXTs to the innermost non-BLOCK one.
     788                 :             :              So push that instead.  */
     789                 :       31846 :           while (ctx && TREE_CODE (ctx) == BLOCK)
     790                 :           0 :             ctx = BLOCK_SUPERCONTEXT (ctx);
     791                 :       31846 :           fld_worklist_push (ctx, fld);
     792                 :             :         }
     793                 :     3503044 :       fld_worklist_push (TYPE_CANONICAL (t), fld);
     794                 :             : 
     795                 :     3503044 :       if (RECORD_OR_UNION_TYPE_P (t) && TYPE_BINFO (t))
     796                 :             :         {
     797                 :             :           unsigned i;
     798                 :             :           tree tem;
     799                 :       40242 :           FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (TYPE_BINFO (t)), i, tem)
     800                 :        9456 :             fld_worklist_push (TREE_TYPE (tem), fld);
     801                 :       30786 :           fld_worklist_push (BINFO_TYPE (TYPE_BINFO (t)), fld);
     802                 :       30786 :           fld_worklist_push (BINFO_VTABLE (TYPE_BINFO (t)), fld);
     803                 :             :         }
     804                 :     3503044 :       if (RECORD_OR_UNION_TYPE_P (t))
     805                 :             :         {
     806                 :      126020 :           tree tem;
     807                 :             :           /* Push all TYPE_FIELDS - there can be interleaving interesting
     808                 :             :              and non-interesting things.  */
     809                 :      126020 :           tem = TYPE_FIELDS (t);
     810                 :     1033372 :           while (tem)
     811                 :             :             {
     812                 :      907352 :               if (TREE_CODE (tem) == FIELD_DECL)
     813                 :      345020 :                 fld_worklist_push (tem, fld);
     814                 :      907352 :               tem = TREE_CHAIN (tem);
     815                 :             :             }
     816                 :             :         }
     817                 :     3503044 :       if (FUNC_OR_METHOD_TYPE_P (t))
     818                 :     2299653 :         fld_worklist_push (TYPE_METHOD_BASETYPE (t), fld);
     819                 :             : 
     820                 :     3503044 :       fld_worklist_push (TYPE_STUB_DECL (t), fld);
     821                 :     3503044 :       *ws = 0;
     822                 :             :     }
     823                 :    13050069 :   else if (TREE_CODE (t) == BLOCK)
     824                 :             :     {
     825                 :      946261 :       for (tree *tem = &BLOCK_VARS (t); *tem; )
     826                 :             :         {
     827                 :      758004 :           if (TREE_CODE (*tem) != LABEL_DECL
     828                 :      758004 :               && (TREE_CODE (*tem) != VAR_DECL
     829                 :      366094 :                   || !auto_var_in_fn_p (*tem, DECL_CONTEXT (*tem))))
     830                 :             :             {
     831                 :      410282 :               gcc_assert (TREE_CODE (*tem) != RESULT_DECL
     832                 :             :                           && TREE_CODE (*tem) != PARM_DECL);
     833                 :      410282 :               *tem = TREE_CHAIN (*tem);
     834                 :             :             }
     835                 :             :           else
     836                 :             :             {
     837                 :      347722 :               fld_worklist_push (*tem, fld);
     838                 :      347722 :               tem = &TREE_CHAIN (*tem);
     839                 :             :             }
     840                 :             :         }
     841                 :      229827 :       for (tree tem = BLOCK_SUBBLOCKS (t); tem; tem = BLOCK_CHAIN (tem))
     842                 :       41570 :         fld_worklist_push (tem, fld);
     843                 :      188257 :       fld_worklist_push (BLOCK_ABSTRACT_ORIGIN (t), fld);
     844                 :             :     }
     845                 :             : 
     846                 :    25727250 :   if (TREE_CODE (t) != IDENTIFIER_NODE
     847                 :    17463225 :       && CODE_CONTAINS_STRUCT (TREE_CODE (t), TS_TYPED))
     848                 :    17274968 :     fld_worklist_push (TREE_TYPE (t), fld);
     849                 :             : 
     850                 :             :   return NULL_TREE;
     851                 :             : }
     852                 :             : 
     853                 :             : 
     854                 :             : /* Find decls and types in T.  */
     855                 :             : 
     856                 :             : static void
     857                 :     7977619 : find_decls_types (tree t, class free_lang_data_d *fld)
     858                 :             : {
     859                 :    75155977 :   while (1)
     860                 :             :     {
     861                 :    41566798 :       if (!fld->pset.contains (t))
     862                 :    33023830 :         walk_tree (&t, find_decls_types_r, fld, &fld->pset);
     863                 :    41566798 :       if (fld->worklist.is_empty ())
     864                 :             :         break;
     865                 :    33589179 :       t = fld->worklist.pop ();
     866                 :             :     }
     867                 :     7977619 : }
     868                 :             : 
     869                 :             : /* Translate all the types in LIST with the corresponding runtime
     870                 :             :    types.  */
     871                 :             : 
     872                 :             : static tree
     873                 :         764 : get_eh_types_for_runtime (tree list)
     874                 :             : {
     875                 :         764 :   tree head, prev;
     876                 :             : 
     877                 :         764 :   if (list == NULL_TREE)
     878                 :             :     return NULL_TREE;
     879                 :             : 
     880                 :         146 :   head = build_tree_list (0, lookup_type_for_runtime (TREE_VALUE (list)));
     881                 :         146 :   prev = head;
     882                 :         146 :   list = TREE_CHAIN (list);
     883                 :         146 :   while (list)
     884                 :             :     {
     885                 :           0 :       tree n = build_tree_list (0, lookup_type_for_runtime (TREE_VALUE (list)));
     886                 :           0 :       TREE_CHAIN (prev) = n;
     887                 :           0 :       prev = TREE_CHAIN (prev);
     888                 :           0 :       list = TREE_CHAIN (list);
     889                 :             :     }
     890                 :             : 
     891                 :             :   return head;
     892                 :             : }
     893                 :             : 
     894                 :             : 
     895                 :             : /* Find decls and types referenced in EH region R and store them in
     896                 :             :    FLD->DECLS and FLD->TYPES.  */
     897                 :             : 
     898                 :             : static void
     899                 :       34419 : find_decls_types_in_eh_region (eh_region r, class free_lang_data_d *fld)
     900                 :             : {
     901                 :       34419 :   switch (r->type)
     902                 :             :     {
     903                 :             :     case ERT_CLEANUP:
     904                 :             :       break;
     905                 :             : 
     906                 :         804 :     case ERT_TRY:
     907                 :         804 :       {
     908                 :         804 :         eh_catch c;
     909                 :             : 
     910                 :             :         /* The types referenced in each catch must first be changed to the
     911                 :             :            EH types used at runtime.  This removes references to FE types
     912                 :             :            in the region.  */
     913                 :        1409 :         for (c = r->u.eh_try.first_catch; c ; c = c->next_catch)
     914                 :             :           {
     915                 :         605 :             c->type_list = get_eh_types_for_runtime (c->type_list);
     916                 :         605 :             walk_tree (&c->type_list, find_decls_types_r, fld, &fld->pset);
     917                 :             :           }
     918                 :             :       }
     919                 :             :       break;
     920                 :             : 
     921                 :         159 :     case ERT_ALLOWED_EXCEPTIONS:
     922                 :         159 :       r->u.allowed.type_list
     923                 :         159 :         = get_eh_types_for_runtime (r->u.allowed.type_list);
     924                 :         159 :       walk_tree (&r->u.allowed.type_list, find_decls_types_r, fld, &fld->pset);
     925                 :         159 :       break;
     926                 :             : 
     927                 :       12574 :     case ERT_MUST_NOT_THROW:
     928                 :       12574 :       walk_tree (&r->u.must_not_throw.failure_decl,
     929                 :             :                  find_decls_types_r, fld, &fld->pset);
     930                 :       12574 :       break;
     931                 :             :     }
     932                 :       34419 : }
     933                 :             : 
     934                 :             : 
     935                 :             : /* Find decls and types referenced in cgraph node N and store them in
     936                 :             :    FLD->DECLS and FLD->TYPES.  Unlike pass_referenced_vars, this will
     937                 :             :    look for *every* kind of DECL and TYPE node reachable from N,
     938                 :             :    including those embedded inside types and decls (i.e,, TYPE_DECLs,
     939                 :             :    NAMESPACE_DECLs, etc).  */
     940                 :             : 
     941                 :             : static void
     942                 :      356034 : find_decls_types_in_node (struct cgraph_node *n, class free_lang_data_d *fld)
     943                 :             : {
     944                 :      356034 :   basic_block bb;
     945                 :      356034 :   struct function *fn;
     946                 :      356034 :   unsigned ix;
     947                 :      356034 :   tree t;
     948                 :             : 
     949                 :      356034 :   find_decls_types (n->decl, fld);
     950                 :             : 
     951                 :      356034 :   if (!gimple_has_body_p (n->decl))
     952                 :      356034 :     return;
     953                 :             : 
     954                 :      115121 :   gcc_assert (current_function_decl == NULL_TREE && cfun == NULL);
     955                 :             : 
     956                 :      115121 :   fn = DECL_STRUCT_FUNCTION (n->decl);
     957                 :             : 
     958                 :             :   /* Traverse locals. */
     959                 :      763362 :   FOR_EACH_LOCAL_DECL (fn, ix, t)
     960                 :      554485 :     find_decls_types (t, fld);
     961                 :             : 
     962                 :             :   /* Traverse EH regions in FN.  */
     963                 :      115121 :   {
     964                 :      115121 :     eh_region r;
     965                 :      149540 :     FOR_ALL_EH_REGION_FN (r, fn)
     966                 :       34419 :       find_decls_types_in_eh_region (r, fld);
     967                 :             :   }
     968                 :             : 
     969                 :             :   /* Traverse every statement in FN.  */
     970                 :      834658 :   FOR_EACH_BB_FN (bb, fn)
     971                 :             :     {
     972                 :      719537 :       gphi_iterator psi;
     973                 :      719537 :       gimple_stmt_iterator si;
     974                 :      719537 :       unsigned i;
     975                 :             : 
     976                 :      719569 :       for (psi = gsi_start_phis (bb); !gsi_end_p (psi); gsi_next (&psi))
     977                 :             :         {
     978                 :          32 :           gphi *phi = psi.phi ();
     979                 :             : 
     980                 :          96 :           for (i = 0; i < gimple_phi_num_args (phi); i++)
     981                 :             :             {
     982                 :          64 :               tree *arg_p = gimple_phi_arg_def_ptr (phi, i);
     983                 :          64 :               find_decls_types (*arg_p, fld);
     984                 :             :             }
     985                 :             :         }
     986                 :             : 
     987                 :     3613222 :       for (si = gsi_start_bb (bb); !gsi_end_p (si); gsi_next (&si))
     988                 :             :         {
     989                 :     2174148 :           gimple *stmt = gsi_stmt (si);
     990                 :             : 
     991                 :     2174148 :           if (is_gimple_call (stmt))
     992                 :      505285 :             find_decls_types (gimple_call_fntype (stmt), fld);
     993                 :             : 
     994                 :     8461811 :           for (i = 0; i < gimple_num_ops (stmt); i++)
     995                 :             :             {
     996                 :     6287663 :               tree arg = gimple_op (stmt, i);
     997                 :     6287663 :               find_decls_types (arg, fld);
     998                 :             :               /* find_decls_types doesn't walk TREE_PURPOSE of TREE_LISTs,
     999                 :             :                  which we need for asm stmts.  */
    1000                 :     6287663 :               if (arg
    1001                 :     4706089 :                   && TREE_CODE (arg) == TREE_LIST
    1002                 :       16837 :                   && TREE_PURPOSE (arg)
    1003                 :     6303283 :                   && gimple_code (stmt) == GIMPLE_ASM)
    1004                 :       15620 :                 find_decls_types (TREE_PURPOSE (arg), fld);
    1005                 :             :             }
    1006                 :             :         }
    1007                 :             :     }
    1008                 :             : }
    1009                 :             : 
    1010                 :             : 
    1011                 :             : /* Find decls and types referenced in varpool node N and store them in
    1012                 :             :    FLD->DECLS and FLD->TYPES.  Unlike pass_referenced_vars, this will
    1013                 :             :    look for *every* kind of DECL and TYPE node reachable from N,
    1014                 :             :    including those embedded inside types and decls (i.e,, TYPE_DECLs,
    1015                 :             :    NAMESPACE_DECLs, etc).  */
    1016                 :             : 
    1017                 :             : static void
    1018                 :      258468 : find_decls_types_in_var (varpool_node *v, class free_lang_data_d *fld)
    1019                 :             : {
    1020                 :           0 :   find_decls_types (v->decl, fld);
    1021                 :           0 : }
    1022                 :             : 
    1023                 :             : /* Free language specific information for every operand and expression
    1024                 :             :    in every node of the call graph.  This process operates in three stages:
    1025                 :             : 
    1026                 :             :    1- Every callgraph node and varpool node is traversed looking for
    1027                 :             :    decls and types embedded in them.  This is a more exhaustive
    1028                 :             :    search than that done by find_referenced_vars, because it will
    1029                 :             :    also collect individual fields, decls embedded in types, etc.
    1030                 :             : 
    1031                 :             :    2- All the decls found are sent to free_lang_data_in_decl.
    1032                 :             : 
    1033                 :             :    3- All the types found are sent to free_lang_data_in_type.
    1034                 :             : 
    1035                 :             :    The ordering between decls and types is important because
    1036                 :             :    free_lang_data_in_decl sets assembler names, which includes
    1037                 :             :    mangling.  So types cannot be freed up until assembler names have
    1038                 :             :    been set up.  */
    1039                 :             : 
    1040                 :             : static void
    1041                 :       23616 : free_lang_data_in_cgraph (class free_lang_data_d *fld)
    1042                 :             : {
    1043                 :       23616 :   struct cgraph_node *n;
    1044                 :       23616 :   varpool_node *v;
    1045                 :       23616 :   tree t;
    1046                 :       23616 :   unsigned i;
    1047                 :       23616 :   alias_pair *p;
    1048                 :             : 
    1049                 :             :   /* Find decls and types in the body of every function in the callgraph.  */
    1050                 :      759300 :   FOR_EACH_FUNCTION (n)
    1051                 :      356034 :     find_decls_types_in_node (n, fld);
    1052                 :             : 
    1053                 :       23616 :   FOR_EACH_VEC_SAFE_ELT (alias_pairs, i, p)
    1054                 :           0 :     find_decls_types (p->decl, fld);
    1055                 :             : 
    1056                 :             :   /* Find decls and types in every varpool symbol.  */
    1057                 :      305700 :   FOR_EACH_VARIABLE (v)
    1058                 :      258468 :     find_decls_types_in_var (v, fld);
    1059                 :             : 
    1060                 :             :   /* Set the assembler name on every decl found.  We need to do this
    1061                 :             :      now because free_lang_data_in_decl will invalidate data needed
    1062                 :             :      for mangling.  This breaks mangling on interdependent decls.  */
    1063                 :     9197753 :   FOR_EACH_VEC_ELT (fld->decls, i, t)
    1064                 :     9174137 :     assign_assembler_name_if_needed (t);
    1065                 :             : 
    1066                 :             :   /* Traverse every decl found freeing its language data.  */
    1067                 :     9197753 :   FOR_EACH_VEC_ELT (fld->decls, i, t)
    1068                 :     9174137 :     free_lang_data_in_decl (t, fld);
    1069                 :             : 
    1070                 :             :   /* Traverse every type found freeing its language data.  */
    1071                 :     3651463 :   FOR_EACH_VEC_ELT (fld->types, i, t)
    1072                 :     3627847 :     free_lang_data_in_type (t, fld);
    1073                 :       23616 : }
    1074                 :             : 
    1075                 :             : 
    1076                 :             : /* Free resources that are used by FE but are not needed once they are done. */
    1077                 :             : 
    1078                 :             : static unsigned
    1079                 :      230024 : free_lang_data (void)
    1080                 :             : {
    1081                 :      230024 :   unsigned i;
    1082                 :      230024 :   class free_lang_data_d fld;
    1083                 :             : 
    1084                 :             :   /* If we are the LTO frontend we have freed lang-specific data already.  */
    1085                 :      230024 :   if (in_lto_p
    1086                 :      230024 :       || (!flag_generate_lto && !flag_generate_offload))
    1087                 :             :     {
    1088                 :             :       /* Rebuild type inheritance graph even when not doing LTO to get
    1089                 :             :          consistent profile data.  */
    1090                 :      206408 :       rebuild_type_inheritance_graph ();
    1091                 :      206408 :       return 0;
    1092                 :             :     }
    1093                 :             : 
    1094                 :       23616 :   fld_incomplete_types = new hash_map<tree, tree>;
    1095                 :       23616 :   fld_simplified_types = new hash_map<tree, tree>;
    1096                 :             : 
    1097                 :             :   /* Provide a dummy TRANSLATION_UNIT_DECL if the FE failed to provide one.  */
    1098                 :       23616 :   if (vec_safe_is_empty (all_translation_units))
    1099                 :         901 :     build_translation_unit_decl (NULL_TREE);
    1100                 :             : 
    1101                 :             :   /* Allocate and assign alias sets to the standard integer types
    1102                 :             :      while the slots are still in the way the frontends generated them.  */
    1103                 :      472320 :   for (i = 0; i < itk_none; ++i)
    1104                 :      448704 :     if (integer_types[i])
    1105                 :      307008 :       TYPE_ALIAS_SET (integer_types[i]) = get_alias_set (integer_types[i]);
    1106                 :             : 
    1107                 :             :   /* Traverse the IL resetting language specific information for
    1108                 :             :      operands, expressions, etc.  */
    1109                 :       23616 :   free_lang_data_in_cgraph (&fld);
    1110                 :             : 
    1111                 :             :   /* Create gimple variants for common types.  */
    1112                 :      165312 :   for (unsigned i = 0; i < ARRAY_SIZE (builtin_structptr_types); ++i)
    1113                 :      141696 :     builtin_structptr_types[i].node = builtin_structptr_types[i].base;
    1114                 :             : 
    1115                 :             :   /* Reset some langhooks.  Do not reset types_compatible_p, it may
    1116                 :             :      still be used indirectly via the get_alias_set langhook.  */
    1117                 :       23616 :   lang_hooks.dwarf_name = lhd_dwarf_name;
    1118                 :       23616 :   lang_hooks.decl_printable_name = gimple_decl_printable_name;
    1119                 :       23616 :   lang_hooks.gimplify_expr = lhd_gimplify_expr;
    1120                 :       23616 :   lang_hooks.overwrite_decl_assembler_name = lhd_overwrite_decl_assembler_name;
    1121                 :       23616 :   lang_hooks.print_xnode = lhd_print_tree_nothing;
    1122                 :       23616 :   lang_hooks.print_decl = lhd_print_tree_nothing;
    1123                 :       23616 :   lang_hooks.print_type = lhd_print_tree_nothing;
    1124                 :       23616 :   lang_hooks.print_identifier = lhd_print_tree_nothing;
    1125                 :             : 
    1126                 :       23616 :   lang_hooks.tree_inlining.var_mod_type_p = hook_bool_tree_tree_false;
    1127                 :             : 
    1128                 :       23616 :   if (flag_checking)
    1129                 :             :     {
    1130                 :             :       int i;
    1131                 :             :       tree t;
    1132                 :             : 
    1133                 :     3651329 :       FOR_EACH_VEC_ELT (fld.types, i, t)
    1134                 :     3627720 :         verify_type (t);
    1135                 :             :     }
    1136                 :             : 
    1137                 :             :   /* We do not want the default decl_assembler_name implementation,
    1138                 :             :      rather if we have fixed everything we want a wrapper around it
    1139                 :             :      asserting that all non-local symbols already got their assembler
    1140                 :             :      name and only produce assembler names for local symbols.  Or rather
    1141                 :             :      make sure we never call decl_assembler_name on local symbols and
    1142                 :             :      devise a separate, middle-end private scheme for it.  */
    1143                 :             : 
    1144                 :             :   /* Reset diagnostic machinery.  */
    1145                 :       23616 :   tree_diagnostics_defaults (global_dc);
    1146                 :             : 
    1147                 :       23616 :   rebuild_type_inheritance_graph ();
    1148                 :             : 
    1149                 :       47232 :   delete fld_incomplete_types;
    1150                 :       47232 :   delete fld_simplified_types;
    1151                 :             : 
    1152                 :             :   return 0;
    1153                 :      230024 : }
    1154                 :             : 
    1155                 :             : const pass_data pass_data_ipa_free_lang_data =
    1156                 :             :   {
    1157                 :             :    SIMPLE_IPA_PASS, /* type */
    1158                 :             :    "*free_lang_data", /* name */
    1159                 :             :    OPTGROUP_NONE, /* optinfo_flags */
    1160                 :             :    TV_IPA_FREE_LANG_DATA, /* tv_id */
    1161                 :             :    0, /* properties_required */
    1162                 :             :    0, /* properties_provided */
    1163                 :             :    0, /* properties_destroyed */
    1164                 :             :    0, /* todo_flags_start */
    1165                 :             :    0, /* todo_flags_finish */
    1166                 :             :   };
    1167                 :             : 
    1168                 :             : class pass_ipa_free_lang_data : public simple_ipa_opt_pass
    1169                 :             : {
    1170                 :             : public:
    1171                 :      285617 :   pass_ipa_free_lang_data (gcc::context *ctxt)
    1172                 :      571234 :     : simple_ipa_opt_pass (pass_data_ipa_free_lang_data, ctxt)
    1173                 :             :   {}
    1174                 :             : 
    1175                 :             :   /* opt_pass methods: */
    1176                 :      230024 :   unsigned int execute (function *) final override { return free_lang_data (); }
    1177                 :             : 
    1178                 :             : }; // class pass_ipa_free_lang_data
    1179                 :             : 
    1180                 :             : } // anon namespace
    1181                 :             : 
    1182                 :             : simple_ipa_opt_pass *
    1183                 :      285617 : make_pass_ipa_free_lang_data (gcc::context *ctxt)
    1184                 :             : {
    1185                 :      285617 :   return new pass_ipa_free_lang_data (ctxt);
    1186                 :             : }
        

Generated by: LCOV version 2.0-1

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.