LCOV - code coverage report
Current view: top level - gcc - tree-nested.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 88.1 % 1981 1745
Test Date: 2024-03-23 14:05:01 Functions: 95.2 % 62 59
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* Nested function decomposition for GIMPLE.
       2                 :             :    Copyright (C) 2004-2024 Free Software Foundation, Inc.
       3                 :             : 
       4                 :             :    This file is part of GCC.
       5                 :             : 
       6                 :             :    GCC is free software; you can redistribute it and/or modify
       7                 :             :    it under the terms of the GNU General Public License as published by
       8                 :             :    the Free Software Foundation; either version 3, or (at your option)
       9                 :             :    any later version.
      10                 :             : 
      11                 :             :    GCC is distributed in the hope that it will be useful,
      12                 :             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      13                 :             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14                 :             :    GNU General Public License for more details.
      15                 :             : 
      16                 :             :    You should have received a copy of the GNU General Public License
      17                 :             :    along with GCC; see the file COPYING3.  If not see
      18                 :             :    <http://www.gnu.org/licenses/>.  */
      19                 :             : 
      20                 :             : #include "config.h"
      21                 :             : #include "system.h"
      22                 :             : #include "coretypes.h"
      23                 :             : #include "backend.h"
      24                 :             : #include "target.h"
      25                 :             : #include "rtl.h"
      26                 :             : #include "tree.h"
      27                 :             : #include "gimple.h"
      28                 :             : #include "memmodel.h"
      29                 :             : #include "tm_p.h"
      30                 :             : #include "stringpool.h"
      31                 :             : #include "cgraph.h"
      32                 :             : #include "fold-const.h"
      33                 :             : #include "stor-layout.h"
      34                 :             : #include "dumpfile.h"
      35                 :             : #include "tree-inline.h"
      36                 :             : #include "gimplify.h"
      37                 :             : #include "gimple-iterator.h"
      38                 :             : #include "gimple-walk.h"
      39                 :             : #include "tree-cfg.h"
      40                 :             : #include "explow.h"
      41                 :             : #include "langhooks.h"
      42                 :             : #include "gimple-low.h"
      43                 :             : #include "gomp-constants.h"
      44                 :             : #include "diagnostic.h"
      45                 :             : #include "alloc-pool.h"
      46                 :             : #include "tree-nested.h"
      47                 :             : #include "symbol-summary.h"
      48                 :             : #include "symtab-thunks.h"
      49                 :             : 
      50                 :             : /* Summary of nested functions.  */
      51                 :             : static function_summary <nested_function_info *>
      52                 :             :    *nested_function_sum = NULL;
      53                 :             : 
      54                 :             : /* Return nested_function_info, if available.  */
      55                 :             : nested_function_info *
      56                 :   125918627 : nested_function_info::get (cgraph_node *node)
      57                 :             : {
      58                 :   125918627 :   if (!nested_function_sum)
      59                 :             :     return NULL;
      60                 :      509832 :   return nested_function_sum->get (node);
      61                 :             : }
      62                 :             : 
      63                 :             : /* Return nested_function_info possibly creating new one.  */
      64                 :             : nested_function_info *
      65                 :       38286 : nested_function_info::get_create (cgraph_node *node)
      66                 :             : {
      67                 :       38286 :   if (!nested_function_sum)
      68                 :             :     {
      69                 :       16084 :       nested_function_sum = new function_summary <nested_function_info *>
      70                 :        8042 :                                    (symtab);
      71                 :        8042 :       nested_function_sum->disable_insertion_hook ();
      72                 :             :     }
      73                 :       38286 :   return nested_function_sum->get_create (node);
      74                 :             : }
      75                 :             : 
      76                 :             : /* cgraph_node is no longer nested function; update cgraph accordingly.  */
      77                 :             : void
      78                 :       18892 : unnest_function (cgraph_node *node)
      79                 :             : {
      80                 :       18892 :   nested_function_info *info = nested_function_info::get (node);
      81                 :       18892 :   cgraph_node **node2 = &nested_function_info::get
      82                 :       18892 :                 (nested_function_origin (node))->nested;
      83                 :             : 
      84                 :       18892 :   gcc_checking_assert (info->origin);
      85                 :       65937 :   while (*node2 != node)
      86                 :       47045 :     node2 = &nested_function_info::get (*node2)->next_nested;
      87                 :       18892 :   *node2 = info->next_nested;
      88                 :       18892 :   info->next_nested = NULL;
      89                 :       18892 :   info->origin = NULL;
      90                 :       18892 :   nested_function_sum->remove (node);
      91                 :       18892 : }
      92                 :             : 
      93                 :             : /* Destructor: unlink function from nested function lists.  */
      94                 :       27697 : nested_function_info::~nested_function_info ()
      95                 :             : {
      96                 :       27697 :   cgraph_node *next;
      97                 :       27801 :   for (cgraph_node *n = nested; n; n = next)
      98                 :             :     {
      99                 :         104 :       nested_function_info *info = nested_function_info::get (n);
     100                 :         104 :       next = info->next_nested;
     101                 :         104 :       info->origin = NULL;
     102                 :         104 :       info->next_nested = NULL;
     103                 :             :     }
     104                 :       27697 :   nested = NULL;
     105                 :       27697 :   if (origin)
     106                 :             :     {
     107                 :         147 :       cgraph_node **node2
     108                 :         147 :              = &nested_function_info::get (origin)->nested;
     109                 :             : 
     110                 :         147 :       nested_function_info *info;
     111                 :         147 :       while ((info = nested_function_info::get (*node2)) != this && info)
     112                 :           0 :         node2 = &info->next_nested;
     113                 :         147 :       *node2 = next_nested;
     114                 :             :     }
     115                 :       27697 : }
     116                 :             : 
     117                 :             : /* Free nested function info summaries.  */
     118                 :             : void
     119                 :      513371 : nested_function_info::release ()
     120                 :             : {
     121                 :      513371 :   if (nested_function_sum)
     122                 :        8038 :     delete (nested_function_sum);
     123                 :      513371 :   nested_function_sum = NULL;
     124                 :      513371 : }
     125                 :             : 
     126                 :             : /* If NODE is nested function, record it.  */
     127                 :             : void
     128                 :    85330419 : maybe_record_nested_function (cgraph_node *node)
     129                 :             : {
     130                 :             :   /* All nested functions gets lowered during the construction of symtab.  */
     131                 :    85330419 :   if (symtab->state > CONSTRUCTION)
     132                 :             :     return;
     133                 :    85221000 :   if (DECL_CONTEXT (node->decl)
     134                 :    85221000 :       && TREE_CODE (DECL_CONTEXT (node->decl)) == FUNCTION_DECL)
     135                 :             :     {
     136                 :       19143 :       cgraph_node *origin = cgraph_node::get_create (DECL_CONTEXT (node->decl));
     137                 :       19143 :       nested_function_info *info = nested_function_info::get_create (node);
     138                 :       19143 :       nested_function_info *origin_info
     139                 :       19143 :                  = nested_function_info::get_create (origin);
     140                 :             : 
     141                 :       19143 :       info->origin = origin;
     142                 :       19143 :       info->next_nested = origin_info->nested;
     143                 :       19143 :       origin_info->nested = node;
     144                 :             :     }
     145                 :             : }
     146                 :             : 
     147                 :             : /* The object of this pass is to lower the representation of a set of nested
     148                 :             :    functions in order to expose all of the gory details of the various
     149                 :             :    nonlocal references.  We want to do this sooner rather than later, in
     150                 :             :    order to give us more freedom in emitting all of the functions in question.
     151                 :             : 
     152                 :             :    Back in olden times, when gcc was young, we developed an insanely
     153                 :             :    complicated scheme whereby variables which were referenced nonlocally
     154                 :             :    were forced to live in the stack of the declaring function, and then
     155                 :             :    the nested functions magically discovered where these variables were
     156                 :             :    placed.  In order for this scheme to function properly, it required
     157                 :             :    that the outer function be partially expanded, then we switch to
     158                 :             :    compiling the inner function, and once done with those we switch back
     159                 :             :    to compiling the outer function.  Such delicate ordering requirements
     160                 :             :    makes it difficult to do whole translation unit optimizations
     161                 :             :    involving such functions.
     162                 :             : 
     163                 :             :    The implementation here is much more direct.  Everything that can be
     164                 :             :    referenced by an inner function is a member of an explicitly created
     165                 :             :    structure herein called the "nonlocal frame struct".  The incoming
     166                 :             :    static chain for a nested function is a pointer to this struct in
     167                 :             :    the parent.  In this way, we settle on known offsets from a known
     168                 :             :    base, and so are decoupled from the logic that places objects in the
     169                 :             :    function's stack frame.  More importantly, we don't have to wait for
     170                 :             :    that to happen -- since the compilation of the inner function is no
     171                 :             :    longer tied to a real stack frame, the nonlocal frame struct can be
     172                 :             :    allocated anywhere.  Which means that the outer function is now
     173                 :             :    inlinable.
     174                 :             : 
     175                 :             :    Theory of operation here is very simple.  Iterate over all the
     176                 :             :    statements in all the functions (depth first) several times,
     177                 :             :    allocating structures and fields on demand.  In general we want to
     178                 :             :    examine inner functions first, so that we can avoid making changes
     179                 :             :    to outer functions which are unnecessary.
     180                 :             : 
     181                 :             :    The order of the passes matters a bit, in that later passes will be
     182                 :             :    skipped if it is discovered that the functions don't actually interact
     183                 :             :    at all.  That is, they're nested in the lexical sense but could have
     184                 :             :    been written as independent functions without change.  */
     185                 :             : 
     186                 :             : 
     187                 :             : struct nesting_info
     188                 :             : {
     189                 :             :   struct nesting_info *outer;
     190                 :             :   struct nesting_info *inner;
     191                 :             :   struct nesting_info *next;
     192                 :             : 
     193                 :             :   hash_map<tree, tree> *field_map;
     194                 :             :   hash_map<tree, tree> *var_map;
     195                 :             :   hash_set<tree *> *mem_refs;
     196                 :             :   bitmap suppress_expansion;
     197                 :             : 
     198                 :             :   tree context;
     199                 :             :   tree new_local_var_chain;
     200                 :             :   tree debug_var_chain;
     201                 :             :   tree frame_type;
     202                 :             :   tree frame_decl;
     203                 :             :   tree chain_field;
     204                 :             :   tree chain_decl;
     205                 :             :   tree nl_goto_field;
     206                 :             : 
     207                 :             :   bool thunk_p;
     208                 :             :   bool any_parm_remapped;
     209                 :             :   bool any_tramp_created;
     210                 :             :   bool any_descr_created;
     211                 :             :   char static_chain_added;
     212                 :             : };
     213                 :             : 
     214                 :             : 
     215                 :             : /* Iterate over the nesting tree, starting with ROOT, depth first.  */
     216                 :             : 
     217                 :             : static inline struct nesting_info *
     218                 :       76317 : iter_nestinfo_start (struct nesting_info *root)
     219                 :             : {
     220                 :      301534 :   while (root->inner)
     221                 :             :     root = root->inner;
     222                 :             :   return root;
     223                 :             : }
     224                 :             : 
     225                 :             : static inline struct nesting_info *
     226                 :      301534 : iter_nestinfo_next (struct nesting_info *node)
     227                 :             : {
     228                 :      301534 :   if (node->next)
     229                 :             :     return iter_nestinfo_start (node->next);
     230                 :      187997 :   return node->outer;
     231                 :             : }
     232                 :             : 
     233                 :             : #define FOR_EACH_NEST_INFO(I, ROOT) \
     234                 :             :   for ((I) = iter_nestinfo_start (ROOT); (I); (I) = iter_nestinfo_next (I))
     235                 :             : 
     236                 :             : /* Obstack used for the bitmaps in the struct above.  */
     237                 :             : static struct bitmap_obstack nesting_info_bitmap_obstack;
     238                 :             : 
     239                 :             : 
     240                 :             : /* We're working in so many different function contexts simultaneously,
     241                 :             :    that create_tmp_var is dangerous.  Prevent mishap.  */
     242                 :             : #define create_tmp_var cant_use_create_tmp_var_here_dummy
     243                 :             : 
     244                 :             : /* Like create_tmp_var, except record the variable for registration at
     245                 :             :    the given nesting level.  */
     246                 :             : 
     247                 :             : static tree
     248                 :       17659 : create_tmp_var_for (struct nesting_info *info, tree type, const char *prefix)
     249                 :             : {
     250                 :       17659 :   tree tmp_var;
     251                 :             : 
     252                 :             :   /* If the type is of variable size or a type which must be created by the
     253                 :             :      frontend, something is wrong.  Note that we explicitly allow
     254                 :             :      incomplete types here, since we create them ourselves here.  */
     255                 :       17659 :   gcc_assert (!TREE_ADDRESSABLE (type));
     256                 :       17659 :   gcc_assert (!TYPE_SIZE_UNIT (type)
     257                 :             :               || TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST);
     258                 :             : 
     259                 :       17659 :   tmp_var = create_tmp_var_raw (type, prefix);
     260                 :       17659 :   DECL_CONTEXT (tmp_var) = info->context;
     261                 :       17659 :   DECL_CHAIN (tmp_var) = info->new_local_var_chain;
     262                 :       17659 :   DECL_SEEN_IN_BIND_EXPR_P (tmp_var) = 1;
     263                 :             : 
     264                 :       17659 :   info->new_local_var_chain = tmp_var;
     265                 :             : 
     266                 :       17659 :   return tmp_var;
     267                 :             : }
     268                 :             : 
     269                 :             : /* Like build_simple_mem_ref, but set TREE_THIS_NOTRAP on the result.  */
     270                 :             : 
     271                 :             : static tree
     272                 :       18618 : build_simple_mem_ref_notrap (tree ptr)
     273                 :             : {
     274                 :       18618 :   tree t = build_simple_mem_ref (ptr);
     275                 :       18618 :   TREE_THIS_NOTRAP (t) = 1;
     276                 :       18618 :   return t;
     277                 :             : }
     278                 :             : 
     279                 :             : /* Take the address of EXP to be used within function CONTEXT.
     280                 :             :    Mark it for addressability as necessary.  */
     281                 :             : 
     282                 :             : tree
     283                 :       35497 : build_addr (tree exp)
     284                 :             : {
     285                 :       35497 :   mark_addressable (exp);
     286                 :       35497 :   return build_fold_addr_expr (exp);
     287                 :             : }
     288                 :             : 
     289                 :             : /* Insert FIELD into TYPE, sorted by alignment requirements.  */
     290                 :             : 
     291                 :             : void
     292                 :      169735 : insert_field_into_struct (tree type, tree field)
     293                 :             : {
     294                 :      169735 :   tree *p;
     295                 :             : 
     296                 :      169735 :   DECL_CONTEXT (field) = type;
     297                 :             : 
     298                 :      208850 :   for (p = &TYPE_FIELDS (type); *p ; p = &DECL_CHAIN (*p))
     299                 :      149996 :     if (DECL_ALIGN (field) >= DECL_ALIGN (*p))
     300                 :             :       break;
     301                 :             : 
     302                 :      169735 :   DECL_CHAIN (field) = *p;
     303                 :      169735 :   *p = field;
     304                 :             : 
     305                 :             :   /* Set correct alignment for frame struct type.  */
     306                 :      169735 :   if (TYPE_ALIGN (type) < DECL_ALIGN (field))
     307                 :       56746 :     SET_TYPE_ALIGN (type, DECL_ALIGN (field));
     308                 :      169735 : }
     309                 :             : 
     310                 :             : /* Build or return the RECORD_TYPE that describes the frame state that is
     311                 :             :    shared between INFO->CONTEXT and its nested functions.  This record will
     312                 :             :    not be complete until finalize_nesting_tree; up until that point we'll
     313                 :             :    be adding fields as necessary.
     314                 :             : 
     315                 :             :    We also build the DECL that represents this frame in the function.  */
     316                 :             : 
     317                 :             : static tree
     318                 :       31585 : get_frame_type (struct nesting_info *info)
     319                 :             : {
     320                 :       31585 :   tree type = info->frame_type;
     321                 :       31585 :   if (!type)
     322                 :             :     {
     323                 :        3196 :       char *name;
     324                 :             : 
     325                 :        3196 :       type = make_node (RECORD_TYPE);
     326                 :             : 
     327                 :        9588 :       name = concat ("FRAME.",
     328                 :        3196 :                      IDENTIFIER_POINTER (DECL_NAME (info->context)),
     329                 :             :                      NULL);
     330                 :        3196 :       TYPE_NAME (type) = get_identifier (name);
     331                 :        3196 :       free (name);
     332                 :             : 
     333                 :        3196 :       info->frame_type = type;
     334                 :             : 
     335                 :             :       /* Do not put info->frame_decl on info->new_local_var_chain,
     336                 :             :          so that we can declare it in the lexical blocks, which
     337                 :             :          makes sure virtual regs that end up appearing in its RTL
     338                 :             :          expression get substituted in instantiate_virtual_regs.  */
     339                 :        3196 :       info->frame_decl = create_tmp_var_raw (type, "FRAME");
     340                 :        3196 :       DECL_CONTEXT (info->frame_decl) = info->context;
     341                 :        3196 :       DECL_NONLOCAL_FRAME (info->frame_decl) = 1;
     342                 :        3196 :       DECL_SEEN_IN_BIND_EXPR_P (info->frame_decl) = 1;
     343                 :             : 
     344                 :             :       /* ??? Always make it addressable for now, since it is meant to
     345                 :             :          be pointed to by the static chain pointer.  This pessimizes
     346                 :             :          when it turns out that no static chains are needed because
     347                 :             :          the nested functions referencing non-local variables are not
     348                 :             :          reachable, but the true pessimization is to create the non-
     349                 :             :          local frame structure in the first place.  */
     350                 :        3196 :       TREE_ADDRESSABLE (info->frame_decl) = 1;
     351                 :             :     }
     352                 :             : 
     353                 :       31585 :   return type;
     354                 :             : }
     355                 :             : 
     356                 :             : /* Return true if DECL should be referenced by pointer in the non-local frame
     357                 :             :    structure.  */
     358                 :             : 
     359                 :             : static bool
     360                 :     2990094 : use_pointer_in_frame (tree decl)
     361                 :             : {
     362                 :     2990094 :   if (TREE_CODE (decl) == PARM_DECL)
     363                 :             :     {
     364                 :             :       /* It's illegal to copy TREE_ADDRESSABLE, impossible to copy variable-
     365                 :             :          sized DECLs, and inefficient to copy large aggregates.  Don't bother
     366                 :             :          moving anything but scalar parameters.  */
     367                 :      151485 :       return AGGREGATE_TYPE_P (TREE_TYPE (decl));
     368                 :             :     }
     369                 :             :   else
     370                 :             :     {
     371                 :             :       /* Variable-sized DECLs can only come from OMP clauses at this point
     372                 :             :          since the gimplifier has already turned the regular variables into
     373                 :             :          pointers.  Do the same as the gimplifier.  */
     374                 :     2838609 :       return !DECL_SIZE (decl) || TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST;
     375                 :             :     }
     376                 :             : }
     377                 :             : 
     378                 :             : /* Given DECL, a non-locally accessed variable, find or create a field
     379                 :             :    in the non-local frame structure for the given nesting context.  */
     380                 :             : 
     381                 :             : static tree
     382                 :     2986846 : lookup_field_for_decl (struct nesting_info *info, tree decl,
     383                 :             :                        enum insert_option insert)
     384                 :             : {
     385                 :     2986846 :   gcc_checking_assert (decl_function_context (decl) == info->context);
     386                 :             : 
     387                 :     2986846 :   if (insert == NO_INSERT)
     388                 :             :     {
     389                 :     2968945 :       tree *slot = info->field_map->get (decl);
     390                 :     2968945 :       return slot ? *slot : NULL_TREE;
     391                 :             :     }
     392                 :             : 
     393                 :       17901 :   tree *slot = &info->field_map->get_or_insert (decl);
     394                 :       17901 :   if (!*slot)
     395                 :             :     {
     396                 :        3140 :       tree type = get_frame_type (info);
     397                 :        3140 :       tree field = make_node (FIELD_DECL);
     398                 :        3140 :       DECL_NAME (field) = DECL_NAME (decl);
     399                 :             : 
     400                 :        3140 :       if (use_pointer_in_frame (decl))
     401                 :             :         {
     402                 :          27 :           TREE_TYPE (field) = build_pointer_type (TREE_TYPE (decl));
     403                 :          27 :           SET_DECL_ALIGN (field, TYPE_ALIGN (TREE_TYPE (field)));
     404                 :          27 :           DECL_NONADDRESSABLE_P (field) = 1;
     405                 :             :         }
     406                 :             :       else
     407                 :             :         {
     408                 :        3113 :           TREE_TYPE (field) = TREE_TYPE (decl);
     409                 :        3113 :           DECL_SOURCE_LOCATION (field) = DECL_SOURCE_LOCATION (decl);
     410                 :        3113 :           SET_DECL_ALIGN (field, DECL_ALIGN (decl));
     411                 :        3113 :           DECL_USER_ALIGN (field) = DECL_USER_ALIGN (decl);
     412                 :        3113 :           DECL_IGNORED_P (field) = DECL_IGNORED_P (decl);
     413                 :        3113 :           DECL_NONADDRESSABLE_P (field) = !TREE_ADDRESSABLE (decl);
     414                 :        3113 :           TREE_THIS_VOLATILE (field) = TREE_THIS_VOLATILE (decl);
     415                 :        3113 :           copy_warning (field, decl);
     416                 :             : 
     417                 :             :           /* Declare the transformation and adjust the original DECL.  For a
     418                 :             :              variable or for a parameter when not optimizing, we make it point
     419                 :             :              to the field in the frame directly.  For a parameter, we don't do
     420                 :             :              it when optimizing because the variable tracking pass will already
     421                 :             :              do the job,  */
     422                 :        3113 :           if (VAR_P (decl) || !optimize)
     423                 :             :             {
     424                 :        2929 :               tree x
     425                 :        2929 :                 = build3 (COMPONENT_REF, TREE_TYPE (field), info->frame_decl,
     426                 :             :                           field, NULL_TREE);
     427                 :             : 
     428                 :             :               /* If the next declaration is a PARM_DECL pointing to the DECL,
     429                 :             :                  we need to adjust its VALUE_EXPR directly, since chains of
     430                 :             :                  VALUE_EXPRs run afoul of garbage collection.  This occurs
     431                 :             :                  in Ada for Out parameters that aren't copied in.  */
     432                 :        2929 :               tree next = DECL_CHAIN (decl);
     433                 :        2929 :               if (next
     434                 :        2445 :                   && TREE_CODE (next) == PARM_DECL
     435                 :           9 :                   && DECL_HAS_VALUE_EXPR_P (next)
     436                 :        2933 :                   && DECL_VALUE_EXPR (next) == decl)
     437                 :           0 :                 SET_DECL_VALUE_EXPR (next, x);
     438                 :             : 
     439                 :        2929 :               SET_DECL_VALUE_EXPR (decl, x);
     440                 :        2929 :               DECL_HAS_VALUE_EXPR_P (decl) = 1;
     441                 :             :             }
     442                 :             :         }
     443                 :             : 
     444                 :        3140 :       insert_field_into_struct (type, field);
     445                 :        3140 :       *slot = field;
     446                 :             : 
     447                 :        3140 :       if (TREE_CODE (decl) == PARM_DECL)
     448                 :         249 :         info->any_parm_remapped = true;
     449                 :             :     }
     450                 :             : 
     451                 :       17901 :   return *slot;
     452                 :             : }
     453                 :             : 
     454                 :             : /* Build or return the variable that holds the static chain within
     455                 :             :    INFO->CONTEXT.  This variable may only be used within INFO->CONTEXT.  */
     456                 :             : 
     457                 :             : static tree
     458                 :       23608 : get_chain_decl (struct nesting_info *info)
     459                 :             : {
     460                 :       23608 :   tree decl = info->chain_decl;
     461                 :             : 
     462                 :       23608 :   if (!decl)
     463                 :             :     {
     464                 :        5744 :       tree type;
     465                 :             : 
     466                 :        5744 :       type = get_frame_type (info->outer);
     467                 :        5744 :       type = build_pointer_type (type);
     468                 :             : 
     469                 :             :       /* Note that this variable is *not* entered into any BIND_EXPR;
     470                 :             :          the construction of this variable is handled specially in
     471                 :             :          expand_function_start and initialize_inlined_parameters.
     472                 :             :          Note also that it's represented as a parameter.  This is more
     473                 :             :          close to the truth, since the initial value does come from
     474                 :             :          the caller.  */
     475                 :        5744 :       decl = build_decl (DECL_SOURCE_LOCATION (info->context),
     476                 :             :                          PARM_DECL, create_tmp_var_name ("CHAIN"), type);
     477                 :        5744 :       DECL_ARTIFICIAL (decl) = 1;
     478                 :        5744 :       DECL_IGNORED_P (decl) = 1;
     479                 :        5744 :       TREE_USED (decl) = 1;
     480                 :        5744 :       DECL_CONTEXT (decl) = info->context;
     481                 :        5744 :       DECL_ARG_TYPE (decl) = type;
     482                 :             : 
     483                 :             :       /* Tell tree-inline.cc that we never write to this variable, so
     484                 :             :          it can copy-prop the replacement value immediately.  */
     485                 :        5744 :       TREE_READONLY (decl) = 1;
     486                 :             : 
     487                 :        5744 :       info->chain_decl = decl;
     488                 :             : 
     489                 :        5744 :       if (dump_file
     490                 :           0 :           && (dump_flags & TDF_DETAILS)
     491                 :        5744 :           && !DECL_STATIC_CHAIN (info->context))
     492                 :           0 :         fprintf (dump_file, "Setting static-chain for %s\n",
     493                 :           0 :                  lang_hooks.decl_printable_name (info->context, 2));
     494                 :             : 
     495                 :        5744 :       DECL_STATIC_CHAIN (info->context) = 1;
     496                 :             :     }
     497                 :       23608 :   return decl;
     498                 :             : }
     499                 :             : 
     500                 :             : /* Build or return the field within the non-local frame state that holds
     501                 :             :    the static chain for INFO->CONTEXT.  This is the way to walk back up
     502                 :             :    multiple nesting levels.  */
     503                 :             : 
     504                 :             : static tree
     505                 :         146 : get_chain_field (struct nesting_info *info)
     506                 :             : {
     507                 :         146 :   tree field = info->chain_field;
     508                 :             : 
     509                 :         146 :   if (!field)
     510                 :             :     {
     511                 :          77 :       tree type = build_pointer_type (get_frame_type (info->outer));
     512                 :             : 
     513                 :          77 :       field = make_node (FIELD_DECL);
     514                 :          77 :       DECL_NAME (field) = get_identifier ("__chain");
     515                 :          77 :       TREE_TYPE (field) = type;
     516                 :          77 :       SET_DECL_ALIGN (field, TYPE_ALIGN (type));
     517                 :          77 :       DECL_NONADDRESSABLE_P (field) = 1;
     518                 :             : 
     519                 :          77 :       insert_field_into_struct (get_frame_type (info), field);
     520                 :             : 
     521                 :          77 :       info->chain_field = field;
     522                 :             : 
     523                 :          77 :       if (dump_file
     524                 :           0 :           && (dump_flags & TDF_DETAILS)
     525                 :          77 :           && !DECL_STATIC_CHAIN (info->context))
     526                 :           0 :         fprintf (dump_file, "Setting static-chain for %s\n",
     527                 :           0 :                  lang_hooks.decl_printable_name (info->context, 2));
     528                 :             : 
     529                 :          77 :       DECL_STATIC_CHAIN (info->context) = 1;
     530                 :             :     }
     531                 :         146 :   return field;
     532                 :             : }
     533                 :             : 
     534                 :             : /* Initialize a new temporary with the GIMPLE_CALL STMT.  */
     535                 :             : 
     536                 :             : static tree
     537                 :        1297 : init_tmp_var_with_call (struct nesting_info *info, gimple_stmt_iterator *gsi,
     538                 :             :                         gcall *call)
     539                 :             : {
     540                 :        1297 :   tree t;
     541                 :             : 
     542                 :        1297 :   t = create_tmp_var_for (info, gimple_call_return_type (call), NULL);
     543                 :        1297 :   gimple_call_set_lhs (call, t);
     544                 :        1297 :   if (! gsi_end_p (*gsi))
     545                 :         278 :     gimple_set_location (call, gimple_location (gsi_stmt (*gsi)));
     546                 :        1297 :   gsi_insert_before (gsi, call, GSI_SAME_STMT);
     547                 :             : 
     548                 :        1297 :   return t;
     549                 :             : }
     550                 :             : 
     551                 :             : 
     552                 :             : /* Copy EXP into a temporary.  Allocate the temporary in the context of
     553                 :             :    INFO and insert the initialization statement before GSI.  */
     554                 :             : 
     555                 :             : static tree
     556                 :       12019 : init_tmp_var (struct nesting_info *info, tree exp, gimple_stmt_iterator *gsi)
     557                 :             : {
     558                 :       12019 :   tree t;
     559                 :       12019 :   gimple *stmt;
     560                 :             : 
     561                 :       12019 :   t = create_tmp_var_for (info, TREE_TYPE (exp), NULL);
     562                 :       12019 :   stmt = gimple_build_assign (t, exp);
     563                 :       12019 :   if (! gsi_end_p (*gsi))
     564                 :       12001 :     gimple_set_location (stmt, gimple_location (gsi_stmt (*gsi)));
     565                 :       12019 :   gsi_insert_before_without_update (gsi, stmt, GSI_SAME_STMT);
     566                 :             : 
     567                 :       12019 :   return t;
     568                 :             : }
     569                 :             : 
     570                 :             : 
     571                 :             : /* Similarly, but only do so to force EXP to satisfy is_gimple_val.  */
     572                 :             : 
     573                 :             : static tree
     574                 :        3642 : gsi_gimplify_val (struct nesting_info *info, tree exp,
     575                 :             :                   gimple_stmt_iterator *gsi)
     576                 :             : {
     577                 :        3642 :   if (is_gimple_val (exp))
     578                 :             :     return exp;
     579                 :             :   else
     580                 :         548 :     return init_tmp_var (info, exp, gsi);
     581                 :             : }
     582                 :             : 
     583                 :             : /* Similarly, but copy from the temporary and insert the statement
     584                 :             :    after the iterator.  */
     585                 :             : 
     586                 :             : static tree
     587                 :        4343 : save_tmp_var (struct nesting_info *info, tree exp, gimple_stmt_iterator *gsi)
     588                 :             : {
     589                 :        4343 :   tree t;
     590                 :        4343 :   gimple *stmt;
     591                 :             : 
     592                 :        4343 :   t = create_tmp_var_for (info, TREE_TYPE (exp), NULL);
     593                 :        4343 :   stmt = gimple_build_assign (exp, t);
     594                 :        4343 :   if (! gsi_end_p (*gsi))
     595                 :        4343 :     gimple_set_location (stmt, gimple_location (gsi_stmt (*gsi)));
     596                 :        4343 :   gsi_insert_after_without_update (gsi, stmt, GSI_SAME_STMT);
     597                 :             : 
     598                 :        4343 :   return t;
     599                 :             : }
     600                 :             : 
     601                 :             : /* Build or return the type used to represent a nested function trampoline.  */
     602                 :             : 
     603                 :             : static GTY(()) tree trampoline_type;
     604                 :             : 
     605                 :             : static tree
     606                 :         261 : get_trampoline_type (struct nesting_info *info)
     607                 :             : {
     608                 :         261 :   unsigned align, size;
     609                 :         261 :   tree t;
     610                 :             : 
     611                 :         261 :   if (trampoline_type)
     612                 :             :     return trampoline_type;
     613                 :             : 
     614                 :             :   /* When trampolines are created off-stack then the only thing we need in the
     615                 :             :      local frame is a single pointer.  */
     616                 :         229 :   if (flag_trampoline_impl == TRAMPOLINE_IMPL_HEAP)
     617                 :             :     {
     618                 :           1 :       trampoline_type = build_pointer_type (void_type_node);
     619                 :           1 :       return trampoline_type;
     620                 :             :     }
     621                 :             : 
     622                 :         228 :   align = TRAMPOLINE_ALIGNMENT;
     623                 :         228 :   size = TRAMPOLINE_SIZE;
     624                 :             : 
     625                 :             :   /* If we won't be able to guarantee alignment simply via TYPE_ALIGN,
     626                 :             :      then allocate extra space so that we can do dynamic alignment.  */
     627                 :         228 :   if (align > STACK_BOUNDARY)
     628                 :             :     {
     629                 :           0 :       size += ((align/BITS_PER_UNIT) - 1) & -(STACK_BOUNDARY/BITS_PER_UNIT);
     630                 :           0 :       align = STACK_BOUNDARY;
     631                 :             :     }
     632                 :             : 
     633                 :         228 :   t = build_index_type (size_int (size - 1));
     634                 :         228 :   t = build_array_type (char_type_node, t);
     635                 :         228 :   t = build_decl (DECL_SOURCE_LOCATION (info->context),
     636                 :             :                   FIELD_DECL, get_identifier ("__data"), t);
     637                 :         228 :   SET_DECL_ALIGN (t, align);
     638                 :         228 :   DECL_USER_ALIGN (t) = 1;
     639                 :             : 
     640                 :         228 :   trampoline_type = make_node (RECORD_TYPE);
     641                 :         228 :   TYPE_NAME (trampoline_type) = get_identifier ("__builtin_trampoline");
     642                 :         228 :   TYPE_FIELDS (trampoline_type) = t;
     643                 :         228 :   layout_type (trampoline_type);
     644                 :         228 :   DECL_CONTEXT (t) = trampoline_type;
     645                 :             : 
     646                 :         228 :   return trampoline_type;
     647                 :             : }
     648                 :             : 
     649                 :             : /* Build or return the type used to represent a nested function descriptor.  */
     650                 :             : 
     651                 :             : static GTY(()) tree descriptor_type;
     652                 :             : 
     653                 :             : static tree
     654                 :           0 : get_descriptor_type (struct nesting_info *info)
     655                 :             : {
     656                 :             :   /* The base alignment is that of a function.  */
     657                 :           0 :   const unsigned align = FUNCTION_ALIGNMENT (FUNCTION_BOUNDARY);
     658                 :           0 :   tree t;
     659                 :             : 
     660                 :           0 :   if (descriptor_type)
     661                 :             :     return descriptor_type;
     662                 :             : 
     663                 :           0 :   t = build_index_type (integer_one_node);
     664                 :           0 :   t = build_array_type (ptr_type_node, t);
     665                 :           0 :   t = build_decl (DECL_SOURCE_LOCATION (info->context),
     666                 :             :                   FIELD_DECL, get_identifier ("__data"), t);
     667                 :           0 :   SET_DECL_ALIGN (t, MAX (TYPE_ALIGN (ptr_type_node), align));
     668                 :           0 :   DECL_USER_ALIGN (t) = 1;
     669                 :             : 
     670                 :           0 :   descriptor_type = make_node (RECORD_TYPE);
     671                 :           0 :   TYPE_NAME (descriptor_type) = get_identifier ("__builtin_descriptor");
     672                 :           0 :   TYPE_FIELDS (descriptor_type) = t;
     673                 :           0 :   layout_type (descriptor_type);
     674                 :           0 :   DECL_CONTEXT (t) = descriptor_type;
     675                 :             : 
     676                 :           0 :   return descriptor_type;
     677                 :             : }
     678                 :             : 
     679                 :             : /* Given DECL, a nested function, find or create an element in the
     680                 :             :    var map for this function.  */
     681                 :             : 
     682                 :             : static tree
     683                 :         616 : lookup_element_for_decl (struct nesting_info *info, tree decl,
     684                 :             :                          enum insert_option insert)
     685                 :             : {
     686                 :         616 :   if (insert == NO_INSERT)
     687                 :             :     {
     688                 :         335 :       tree *slot = info->var_map->get (decl);
     689                 :         335 :       return slot ? *slot : NULL_TREE;
     690                 :             :     }
     691                 :             : 
     692                 :         281 :   tree *slot = &info->var_map->get_or_insert (decl);
     693                 :         281 :   if (!*slot)
     694                 :         261 :     *slot = build_tree_list (NULL_TREE, NULL_TREE);
     695                 :             : 
     696                 :         281 :   return (tree) *slot;
     697                 :             : }
     698                 :             : 
     699                 :             : /* Given DECL, a nested function, create a field in the non-local
     700                 :             :    frame structure for this function.  */
     701                 :             : 
     702                 :             : static tree
     703                 :         261 : create_field_for_decl (struct nesting_info *info, tree decl, tree type)
     704                 :             : {
     705                 :         261 :   tree field = make_node (FIELD_DECL);
     706                 :         261 :   DECL_NAME (field) = DECL_NAME (decl);
     707                 :         261 :   TREE_TYPE (field) = type;
     708                 :         261 :   TREE_ADDRESSABLE (field) = 1;
     709                 :         261 :   insert_field_into_struct (get_frame_type (info), field);
     710                 :         261 :   return field;
     711                 :             : }
     712                 :             : 
     713                 :             : /* Given DECL, a nested function, find or create a field in the non-local
     714                 :             :    frame structure for a trampoline for this function.  */
     715                 :             : 
     716                 :             : static tree
     717                 :         616 : lookup_tramp_for_decl (struct nesting_info *info, tree decl,
     718                 :             :                        enum insert_option insert)
     719                 :             : {
     720                 :         616 :   tree elt, field;
     721                 :             : 
     722                 :         616 :   elt = lookup_element_for_decl (info, decl, insert);
     723                 :         616 :   if (!elt)
     724                 :             :     return NULL_TREE;
     725                 :             : 
     726                 :         542 :   field = TREE_PURPOSE (elt);
     727                 :             : 
     728                 :         542 :   if (!field && insert == INSERT)
     729                 :             :     {
     730                 :         261 :       field = create_field_for_decl (info, decl, get_trampoline_type (info));
     731                 :         261 :       TREE_PURPOSE (elt) = field;
     732                 :         261 :       info->any_tramp_created = true;
     733                 :             :     }
     734                 :             : 
     735                 :             :   return field;
     736                 :             : }
     737                 :             : 
     738                 :             : /* Given DECL, a nested function, find or create a field in the non-local
     739                 :             :    frame structure for a descriptor for this function.  */
     740                 :             : 
     741                 :             : static tree
     742                 :           0 : lookup_descr_for_decl (struct nesting_info *info, tree decl,
     743                 :             :                        enum insert_option insert)
     744                 :             : {
     745                 :           0 :   tree elt, field;
     746                 :             : 
     747                 :           0 :   elt = lookup_element_for_decl (info, decl, insert);
     748                 :           0 :   if (!elt)
     749                 :             :     return NULL_TREE;
     750                 :             : 
     751                 :           0 :   field = TREE_VALUE (elt);
     752                 :             : 
     753                 :           0 :   if (!field && insert == INSERT)
     754                 :             :     {
     755                 :           0 :       field = create_field_for_decl (info, decl, get_descriptor_type (info));
     756                 :           0 :       TREE_VALUE (elt) = field;
     757                 :           0 :       info->any_descr_created = true;
     758                 :             :     }
     759                 :             : 
     760                 :             :   return field;
     761                 :             : }
     762                 :             : 
     763                 :             : /* Build or return the field within the non-local frame state that holds
     764                 :             :    the non-local goto "jmp_buf".  The buffer itself is maintained by the
     765                 :             :    rtl middle-end as dynamic stack space is allocated.  */
     766                 :             : 
     767                 :             : static tree
     768                 :         519 : get_nl_goto_field (struct nesting_info *info)
     769                 :             : {
     770                 :         519 :   tree field = info->nl_goto_field;
     771                 :         519 :   if (!field)
     772                 :             :     {
     773                 :         373 :       unsigned size;
     774                 :         373 :       tree type;
     775                 :             : 
     776                 :             :       /* For __builtin_nonlocal_goto, we need N words.  The first is the
     777                 :             :          frame pointer, the rest is for the target's stack pointer save
     778                 :             :          area.  The number of words is controlled by STACK_SAVEAREA_MODE;
     779                 :             :          not the best interface, but it'll do for now.  */
     780                 :         373 :       if (Pmode == ptr_mode)
     781                 :         373 :         type = ptr_type_node;
     782                 :             :       else
     783                 :           0 :         type = lang_hooks.types.type_for_mode (Pmode, 1);
     784                 :             : 
     785                 :         373 :       scalar_int_mode mode
     786                 :         373 :         = as_a <scalar_int_mode> (STACK_SAVEAREA_MODE (SAVE_NONLOCAL));
     787                 :         373 :       size = GET_MODE_SIZE (mode);
     788                 :         373 :       size = size / GET_MODE_SIZE (Pmode);
     789                 :         373 :       size = size + 1;
     790                 :             : 
     791                 :         373 :       type = build_array_type
     792                 :         373 :         (type, build_index_type (size_int (size)));
     793                 :             : 
     794                 :         373 :       field = make_node (FIELD_DECL);
     795                 :         373 :       DECL_NAME (field) = get_identifier ("__nl_goto_buf");
     796                 :         373 :       TREE_TYPE (field) = type;
     797                 :         373 :       SET_DECL_ALIGN (field, TYPE_ALIGN (type));
     798                 :         373 :       TREE_ADDRESSABLE (field) = 1;
     799                 :             : 
     800                 :         373 :       insert_field_into_struct (get_frame_type (info), field);
     801                 :             : 
     802                 :         373 :       info->nl_goto_field = field;
     803                 :             :     }
     804                 :             : 
     805                 :         519 :   return field;
     806                 :             : }
     807                 :             : 
     808                 :             : /* Invoke CALLBACK on all statements of GIMPLE sequence *PSEQ.  */
     809                 :             : 
     810                 :             : static void
     811                 :      189148 : walk_body (walk_stmt_fn callback_stmt, walk_tree_fn callback_op,
     812                 :             :            struct nesting_info *info, gimple_seq *pseq)
     813                 :             : {
     814                 :      189148 :   struct walk_stmt_info wi;
     815                 :             : 
     816                 :      189148 :   memset (&wi, 0, sizeof (wi));
     817                 :      189148 :   wi.info = info;
     818                 :      189148 :   wi.val_only = true;
     819                 :      189148 :   walk_gimple_seq_mod (pseq, callback_stmt, callback_op, &wi);
     820                 :      189148 : }
     821                 :             : 
     822                 :             : 
     823                 :             : /* Invoke CALLBACK_STMT/CALLBACK_OP on all statements of INFO->CONTEXT.  */
     824                 :             : 
     825                 :             : static inline void
     826                 :      164704 : walk_function (walk_stmt_fn callback_stmt, walk_tree_fn callback_op,
     827                 :             :                struct nesting_info *info)
     828                 :             : {
     829                 :      164704 :   gimple_seq body = gimple_body (info->context);
     830                 :      164704 :   walk_body (callback_stmt, callback_op, info, &body);
     831                 :      164704 :   gimple_set_body (info->context, body);
     832                 :      164704 : }
     833                 :             : 
     834                 :             : /* Invoke CALLBACK on a GIMPLE_OMP_FOR's init, cond, incr and pre-body.  */
     835                 :             : 
     836                 :             : static void
     837                 :        2952 : walk_gimple_omp_for (gomp_for *for_stmt,
     838                 :             :                      walk_stmt_fn callback_stmt, walk_tree_fn callback_op,
     839                 :             :                      struct nesting_info *info)
     840                 :             : {
     841                 :        2952 :   struct walk_stmt_info wi;
     842                 :        2952 :   gimple_seq seq;
     843                 :        2952 :   tree t;
     844                 :        2952 :   size_t i;
     845                 :             : 
     846                 :        2952 :   walk_body (callback_stmt, callback_op, info, gimple_omp_for_pre_body_ptr (for_stmt));
     847                 :             : 
     848                 :        2952 :   seq = NULL;
     849                 :        2952 :   memset (&wi, 0, sizeof (wi));
     850                 :        2952 :   wi.info = info;
     851                 :        2952 :   wi.gsi = gsi_last (seq);
     852                 :             : 
     853                 :        6774 :   for (i = 0; i < gimple_omp_for_collapse (for_stmt); i++)
     854                 :             :     {
     855                 :        3822 :       wi.val_only = false;
     856                 :        3822 :       walk_tree (gimple_omp_for_index_ptr (for_stmt, i), callback_op,
     857                 :             :                  &wi, NULL);
     858                 :        3822 :       wi.val_only = true;
     859                 :        3822 :       wi.is_lhs = false;
     860                 :        3822 :       walk_tree (gimple_omp_for_initial_ptr (for_stmt, i), callback_op,
     861                 :             :                  &wi, NULL);
     862                 :             : 
     863                 :        3822 :       wi.val_only = true;
     864                 :        3822 :       wi.is_lhs = false;
     865                 :        3822 :       walk_tree (gimple_omp_for_final_ptr (for_stmt, i), callback_op,
     866                 :             :                  &wi, NULL);
     867                 :             : 
     868                 :        3822 :       t = gimple_omp_for_incr (for_stmt, i);
     869                 :        3822 :       gcc_assert (BINARY_CLASS_P (t));
     870                 :        3822 :       wi.val_only = false;
     871                 :        3822 :       walk_tree (&TREE_OPERAND (t, 0), callback_op, &wi, NULL);
     872                 :        3822 :       wi.val_only = true;
     873                 :        3822 :       wi.is_lhs = false;
     874                 :        3822 :       walk_tree (&TREE_OPERAND (t, 1), callback_op, &wi, NULL);
     875                 :             :     }
     876                 :             : 
     877                 :        2952 :   seq = gsi_seq (wi.gsi);
     878                 :        2952 :   if (!gimple_seq_empty_p (seq))
     879                 :             :     {
     880                 :           9 :       gimple_seq pre_body = gimple_omp_for_pre_body (for_stmt);
     881                 :           9 :       annotate_all_with_location (seq, gimple_location (for_stmt));
     882                 :           9 :       gimple_seq_add_seq (&pre_body, seq);
     883                 :           9 :       gimple_omp_for_set_pre_body (for_stmt, pre_body);
     884                 :             :     }
     885                 :        2952 : }
     886                 :             : 
     887                 :             : /* Similarly for ROOT and all functions nested underneath, depth first.  */
     888                 :             : 
     889                 :             : static void
     890                 :       33896 : walk_all_functions (walk_stmt_fn callback_stmt, walk_tree_fn callback_op,
     891                 :             :                     struct nesting_info *root)
     892                 :             : {
     893                 :       33896 :   struct nesting_info *n;
     894                 :      286720 :   FOR_EACH_NEST_INFO (n, root)
     895                 :      109464 :     walk_function (callback_stmt, callback_op, n);
     896                 :       33896 : }
     897                 :             : 
     898                 :             : 
     899                 :             : /* We have to check for a fairly pathological case.  The operands of function
     900                 :             :    nested function are to be interpreted in the context of the enclosing
     901                 :             :    function.  So if any are variably-sized, they will get remapped when the
     902                 :             :    enclosing function is inlined.  But that remapping would also have to be
     903                 :             :    done in the types of the PARM_DECLs of the nested function, meaning the
     904                 :             :    argument types of that function will disagree with the arguments in the
     905                 :             :    calls to that function.  So we'd either have to make a copy of the nested
     906                 :             :    function corresponding to each time the enclosing function was inlined or
     907                 :             :    add a VIEW_CONVERT_EXPR to each such operand for each call to the nested
     908                 :             :    function.  The former is not practical.  The latter would still require
     909                 :             :    detecting this case to know when to add the conversions.  So, for now at
     910                 :             :    least, we don't inline such an enclosing function.
     911                 :             : 
     912                 :             :    We have to do that check recursively, so here return indicating whether
     913                 :             :    FNDECL has such a nested function.  ORIG_FN is the function we were
     914                 :             :    trying to inline to use for checking whether any argument is variably
     915                 :             :    modified by anything in it.
     916                 :             : 
     917                 :             :    It would be better to do this in tree-inline.cc so that we could give
     918                 :             :    the appropriate warning for why a function can't be inlined, but that's
     919                 :             :    too late since the nesting structure has already been flattened and
     920                 :             :    adding a flag just to record this fact seems a waste of a flag.  */
     921                 :             : 
     922                 :             : static bool
     923                 :       45605 : check_for_nested_with_variably_modified (tree fndecl, tree orig_fndecl)
     924                 :             : {
     925                 :       45605 :   struct cgraph_node *cgn = cgraph_node::get (fndecl);
     926                 :       45605 :   tree arg;
     927                 :             : 
     928                 :      127688 :   for (cgn = first_nested_function (cgn); cgn;
     929                 :       18239 :        cgn = next_nested_function (cgn))
     930                 :             :     {
     931                 :       48990 :       for (arg = DECL_ARGUMENTS (cgn->decl); arg; arg = DECL_CHAIN (arg))
     932                 :       30751 :         if (variably_modified_type_p (TREE_TYPE (arg), orig_fndecl))
     933                 :             :           return true;
     934                 :             : 
     935                 :       18239 :       if (check_for_nested_with_variably_modified (cgn->decl,
     936                 :             :                                                    orig_fndecl))
     937                 :             :         return true;
     938                 :             :     }
     939                 :             : 
     940                 :             :   return false;
     941                 :             : }
     942                 :             : 
     943                 :             : /* Construct our local datastructure describing the function nesting
     944                 :             :    tree rooted by CGN.  */
     945                 :             : 
     946                 :             : static struct nesting_info *
     947                 :       27366 : create_nesting_tree (struct cgraph_node *cgn)
     948                 :             : {
     949                 :       27366 :   struct nesting_info *info = XCNEW (struct nesting_info);
     950                 :       27366 :   info->field_map = new hash_map<tree, tree>;
     951                 :       27366 :   info->var_map = new hash_map<tree, tree>;
     952                 :       27366 :   info->mem_refs = new hash_set<tree *>;
     953                 :       27366 :   info->suppress_expansion = BITMAP_ALLOC (&nesting_info_bitmap_obstack);
     954                 :       27366 :   info->context = cgn->decl;
     955                 :       27366 :   info->thunk_p = cgn->thunk;
     956                 :             : 
     957                 :       73624 :   for (cgn = first_nested_function (cgn); cgn;
     958                 :       18892 :        cgn = next_nested_function (cgn))
     959                 :             :     {
     960                 :       18892 :       struct nesting_info *sub = create_nesting_tree (cgn);
     961                 :       18892 :       sub->outer = info;
     962                 :       18892 :       sub->next = info->inner;
     963                 :       18892 :       info->inner = sub;
     964                 :             :     }
     965                 :             : 
     966                 :             :   /* See discussion at check_for_nested_with_variably_modified for a
     967                 :             :      discussion of why this has to be here.  */
     968                 :       27366 :   if (check_for_nested_with_variably_modified (info->context, info->context))
     969                 :         314 :     DECL_UNINLINABLE (info->context) = true;
     970                 :             : 
     971                 :       27366 :   return info;
     972                 :             : }
     973                 :             : 
     974                 :             : /* Return an expression computing the static chain for TARGET_CONTEXT
     975                 :             :    from INFO->CONTEXT.  Insert any necessary computations before TSI.  */
     976                 :             : 
     977                 :             : static tree
     978                 :       14697 : get_static_chain (struct nesting_info *info, tree target_context,
     979                 :             :                   gimple_stmt_iterator *gsi)
     980                 :             : {
     981                 :       14697 :   struct nesting_info *i;
     982                 :       14697 :   tree x;
     983                 :             : 
     984                 :       14697 :   if (info->context == target_context)
     985                 :             :     {
     986                 :       12979 :       x = build_addr (info->frame_decl);
     987                 :       12979 :       info->static_chain_added |= 1;
     988                 :             :     }
     989                 :             :   else
     990                 :             :     {
     991                 :        1718 :       x = get_chain_decl (info);
     992                 :        1718 :       info->static_chain_added |= 2;
     993                 :             : 
     994                 :        1758 :       for (i = info->outer; i->context != target_context; i = i->outer)
     995                 :             :         {
     996                 :          40 :           tree field = get_chain_field (i);
     997                 :             : 
     998                 :          40 :           x = build_simple_mem_ref_notrap (x);
     999                 :          40 :           x = build3 (COMPONENT_REF, TREE_TYPE (field), x, field, NULL_TREE);
    1000                 :          40 :           x = init_tmp_var (info, x, gsi);
    1001                 :             :         }
    1002                 :             :     }
    1003                 :             : 
    1004                 :       14697 :   return x;
    1005                 :             : }
    1006                 :             : 
    1007                 :             : 
    1008                 :             : /* Return an expression referencing FIELD from TARGET_CONTEXT's non-local
    1009                 :             :    frame as seen from INFO->CONTEXT.  Insert any necessary computations
    1010                 :             :    before GSI.  */
    1011                 :             : 
    1012                 :             : static tree
    1013                 :       38148 : get_frame_field (struct nesting_info *info, tree target_context,
    1014                 :             :                  tree field, gimple_stmt_iterator *gsi)
    1015                 :             : {
    1016                 :       38148 :   struct nesting_info *i;
    1017                 :       38148 :   tree x;
    1018                 :             : 
    1019                 :       38148 :   if (info->context == target_context)
    1020                 :             :     {
    1021                 :             :       /* Make sure frame_decl gets created.  */
    1022                 :       20341 :       (void) get_frame_type (info);
    1023                 :       20341 :       x = info->frame_decl;
    1024                 :       20341 :       info->static_chain_added |= 1;
    1025                 :             :     }
    1026                 :             :   else
    1027                 :             :     {
    1028                 :       17807 :       x = get_chain_decl (info);
    1029                 :       17807 :       info->static_chain_added |= 2;
    1030                 :             : 
    1031                 :       17913 :       for (i = info->outer; i->context != target_context; i = i->outer)
    1032                 :             :         {
    1033                 :         106 :           tree field = get_chain_field (i);
    1034                 :             : 
    1035                 :         106 :           x = build_simple_mem_ref_notrap (x);
    1036                 :         106 :           x = build3 (COMPONENT_REF, TREE_TYPE (field), x, field, NULL_TREE);
    1037                 :         106 :           x = init_tmp_var (info, x, gsi);
    1038                 :             :         }
    1039                 :             : 
    1040                 :       17807 :       x = build_simple_mem_ref_notrap (x);
    1041                 :             :     }
    1042                 :             : 
    1043                 :       38148 :   x = build3 (COMPONENT_REF, TREE_TYPE (field), x, field, NULL_TREE);
    1044                 :       38148 :   TREE_THIS_VOLATILE (x) = TREE_THIS_VOLATILE (field);
    1045                 :       38148 :   return x;
    1046                 :             : }
    1047                 :             : 
    1048                 :             : static void note_nonlocal_vla_type (struct nesting_info *info, tree type);
    1049                 :             : 
    1050                 :             : /* A subroutine of convert_nonlocal_reference_op.  Create a local variable
    1051                 :             :    in the nested function with DECL_VALUE_EXPR set to reference the true
    1052                 :             :    variable in the parent function.  This is used both for debug info
    1053                 :             :    and in OMP lowering.  */
    1054                 :             : 
    1055                 :             : static tree
    1056                 :        3578 : get_nonlocal_debug_decl (struct nesting_info *info, tree decl)
    1057                 :             : {
    1058                 :        3578 :   tree target_context;
    1059                 :        3578 :   struct nesting_info *i;
    1060                 :        3578 :   tree x, field, new_decl;
    1061                 :             : 
    1062                 :        3578 :   tree *slot = &info->var_map->get_or_insert (decl);
    1063                 :             : 
    1064                 :        3578 :   if (*slot)
    1065                 :             :     return *slot;
    1066                 :             : 
    1067                 :         638 :   target_context = decl_function_context (decl);
    1068                 :             : 
    1069                 :             :   /* A copy of the code in get_frame_field, but without the temporaries.  */
    1070                 :         638 :   if (info->context == target_context)
    1071                 :             :     {
    1072                 :             :       /* Make sure frame_decl gets created.  */
    1073                 :           0 :       (void) get_frame_type (info);
    1074                 :           0 :       x = info->frame_decl;
    1075                 :           0 :       i = info;
    1076                 :           0 :       info->static_chain_added |= 1;
    1077                 :             :     }
    1078                 :             :   else
    1079                 :             :     {
    1080                 :         638 :       x = get_chain_decl (info);
    1081                 :         638 :       info->static_chain_added |= 2;
    1082                 :         638 :       for (i = info->outer; i->context != target_context; i = i->outer)
    1083                 :             :         {
    1084                 :           0 :           field = get_chain_field (i);
    1085                 :           0 :           x = build_simple_mem_ref_notrap (x);
    1086                 :           0 :           x = build3 (COMPONENT_REF, TREE_TYPE (field), x, field, NULL_TREE);
    1087                 :             :         }
    1088                 :         638 :       x = build_simple_mem_ref_notrap (x);
    1089                 :             :     }
    1090                 :             : 
    1091                 :         638 :   field = lookup_field_for_decl (i, decl, INSERT);
    1092                 :         638 :   x = build3 (COMPONENT_REF, TREE_TYPE (field), x, field, NULL_TREE);
    1093                 :         638 :   if (use_pointer_in_frame (decl))
    1094                 :           6 :     x = build_simple_mem_ref_notrap (x);
    1095                 :             : 
    1096                 :             :   /* ??? We should be remapping types as well, surely.  */
    1097                 :         638 :   new_decl = build_decl (DECL_SOURCE_LOCATION (decl),
    1098                 :         638 :                          VAR_DECL, DECL_NAME (decl), TREE_TYPE (decl));
    1099                 :         638 :   DECL_CONTEXT (new_decl) = info->context;
    1100                 :         638 :   DECL_ARTIFICIAL (new_decl) = DECL_ARTIFICIAL (decl);
    1101                 :         638 :   DECL_IGNORED_P (new_decl) = DECL_IGNORED_P (decl);
    1102                 :         638 :   TREE_THIS_VOLATILE (new_decl) = TREE_THIS_VOLATILE (decl);
    1103                 :         638 :   TREE_SIDE_EFFECTS (new_decl) = TREE_SIDE_EFFECTS (decl);
    1104                 :         638 :   TREE_READONLY (new_decl) = TREE_READONLY (decl);
    1105                 :         638 :   TREE_ADDRESSABLE (new_decl) = TREE_ADDRESSABLE (decl);
    1106                 :         638 :   DECL_SEEN_IN_BIND_EXPR_P (new_decl) = 1;
    1107                 :         638 :   if ((TREE_CODE (decl) == PARM_DECL
    1108                 :             :        || TREE_CODE (decl) == RESULT_DECL
    1109                 :             :        || VAR_P (decl))
    1110                 :         632 :       && DECL_BY_REFERENCE (decl))
    1111                 :           7 :     DECL_BY_REFERENCE (new_decl) = 1;
    1112                 :             : 
    1113                 :         638 :   SET_DECL_VALUE_EXPR (new_decl, x);
    1114                 :         638 :   DECL_HAS_VALUE_EXPR_P (new_decl) = 1;
    1115                 :             : 
    1116                 :         638 :   *slot = new_decl;
    1117                 :         638 :   DECL_CHAIN (new_decl) = info->debug_var_chain;
    1118                 :         638 :   info->debug_var_chain = new_decl;
    1119                 :             : 
    1120                 :         638 :   if (!optimize
    1121                 :         119 :       && info->context != target_context
    1122                 :         757 :       && variably_modified_type_p (TREE_TYPE (decl), NULL))
    1123                 :           1 :     note_nonlocal_vla_type (info, TREE_TYPE (decl));
    1124                 :             : 
    1125                 :             :   return new_decl;
    1126                 :             : }
    1127                 :             : 
    1128                 :             : 
    1129                 :             : /* Callback for walk_gimple_stmt, rewrite all references to VAR
    1130                 :             :    and PARM_DECLs that belong to outer functions.
    1131                 :             : 
    1132                 :             :    The rewrite will involve some number of structure accesses back up
    1133                 :             :    the static chain.  E.g. for a variable FOO up one nesting level it'll
    1134                 :             :    be CHAIN->FOO.  For two levels it'll be CHAIN->__chain->FOO.  Further
    1135                 :             :    indirections apply to decls for which use_pointer_in_frame is true.  */
    1136                 :             : 
    1137                 :             : static tree
    1138                 :    11242429 : convert_nonlocal_reference_op (tree *tp, int *walk_subtrees, void *data)
    1139                 :             : {
    1140                 :    11242429 :   struct walk_stmt_info *wi = (struct walk_stmt_info *) data;
    1141                 :    11242429 :   struct nesting_info *const info = (struct nesting_info *) wi->info;
    1142                 :    11242429 :   tree t = *tp;
    1143                 :             : 
    1144                 :    11242429 :   *walk_subtrees = 0;
    1145                 :    11242429 :   switch (TREE_CODE (t))
    1146                 :             :     {
    1147                 :     2841782 :     case VAR_DECL:
    1148                 :             :       /* Non-automatic variables are never processed.  */
    1149                 :     2841782 :       if (TREE_STATIC (t) || DECL_EXTERNAL (t))
    1150                 :             :         break;
    1151                 :             :       /* FALLTHRU */
    1152                 :             : 
    1153                 :     2839839 :     case PARM_DECL:
    1154                 :     2839839 :       {
    1155                 :     2839839 :         tree x, target_context = decl_function_context (t);
    1156                 :             : 
    1157                 :     2839839 :         if (info->context == target_context)
    1158                 :             :           break;
    1159                 :             : 
    1160                 :       19670 :         wi->changed = true;
    1161                 :             : 
    1162                 :       19670 :         if (bitmap_bit_p (info->suppress_expansion, DECL_UID (t)))
    1163                 :        2407 :           x = get_nonlocal_debug_decl (info, t);
    1164                 :             :         else
    1165                 :             :           {
    1166                 :             :             struct nesting_info *i = info;
    1167                 :       34632 :             while (i && i->context != target_context)
    1168                 :       17369 :               i = i->outer;
    1169                 :             :             /* If none of the outer contexts is the target context, this means
    1170                 :             :                that the VAR or PARM_DECL is referenced in a wrong context.  */
    1171                 :       17263 :             if (!i)
    1172                 :           0 :               internal_error ("%s from %s referenced in %s",
    1173                 :           0 :                               IDENTIFIER_POINTER (DECL_NAME (t)),
    1174                 :           0 :                               IDENTIFIER_POINTER (DECL_NAME (target_context)),
    1175                 :           0 :                               IDENTIFIER_POINTER (DECL_NAME (info->context)));
    1176                 :             : 
    1177                 :       17263 :             x = lookup_field_for_decl (i, t, INSERT);
    1178                 :       17263 :             x = get_frame_field (info, target_context, x, &wi->gsi);
    1179                 :       17263 :             if (use_pointer_in_frame (t))
    1180                 :             :               {
    1181                 :          21 :                 x = init_tmp_var (info, x, &wi->gsi);
    1182                 :          21 :                 x = build_simple_mem_ref_notrap (x);
    1183                 :             :               }
    1184                 :             :           }
    1185                 :             : 
    1186                 :       19670 :         if (wi->val_only)
    1187                 :             :           {
    1188                 :        7584 :             if (wi->is_lhs)
    1189                 :        1843 :               x = save_tmp_var (info, x, &wi->gsi);
    1190                 :             :             else
    1191                 :        5741 :               x = init_tmp_var (info, x, &wi->gsi);
    1192                 :             :           }
    1193                 :             : 
    1194                 :       19670 :         *tp = x;
    1195                 :             :       }
    1196                 :       19670 :       break;
    1197                 :             : 
    1198                 :     1198893 :     case LABEL_DECL:
    1199                 :             :       /* We're taking the address of a label from a parent function, but
    1200                 :             :          this is not itself a non-local goto.  Mark the label such that it
    1201                 :             :          will not be deleted, much as we would with a label address in
    1202                 :             :          static storage.  */
    1203                 :     1198893 :       if (decl_function_context (t) != info->context)
    1204                 :          79 :         FORCED_LABEL (t) = 1;
    1205                 :             :       break;
    1206                 :             : 
    1207                 :      566352 :     case ADDR_EXPR:
    1208                 :      566352 :       {
    1209                 :      566352 :         bool save_val_only = wi->val_only;
    1210                 :             : 
    1211                 :      566352 :         wi->val_only = false;
    1212                 :      566352 :         wi->is_lhs = false;
    1213                 :      566352 :         wi->changed = false;
    1214                 :      566352 :         walk_tree (&TREE_OPERAND (t, 0), convert_nonlocal_reference_op, wi, 0);
    1215                 :      566352 :         wi->val_only = true;
    1216                 :             : 
    1217                 :      566352 :         if (wi->changed)
    1218                 :             :           {
    1219                 :        2565 :             tree save_context;
    1220                 :             : 
    1221                 :             :             /* If we changed anything, we might no longer be directly
    1222                 :             :                referencing a decl.  */
    1223                 :        2565 :             save_context = current_function_decl;
    1224                 :        2565 :             current_function_decl = info->context;
    1225                 :        2565 :             recompute_tree_invariant_for_addr_expr (t);
    1226                 :             : 
    1227                 :             :             /* If the callback converted the address argument in a context
    1228                 :             :                where we only accept variables (and min_invariant, presumably),
    1229                 :             :                then compute the address into a temporary.  */
    1230                 :        2565 :             if (save_val_only)
    1231                 :           0 :               *tp = gsi_gimplify_val ((struct nesting_info *) wi->info,
    1232                 :             :                                       t, &wi->gsi);
    1233                 :        2565 :             current_function_decl = save_context;
    1234                 :             :           }
    1235                 :             :       }
    1236                 :             :       break;
    1237                 :             : 
    1238                 :     1283032 :     case REALPART_EXPR:
    1239                 :     1283032 :     case IMAGPART_EXPR:
    1240                 :     1283032 :     case COMPONENT_REF:
    1241                 :     1283032 :     case ARRAY_REF:
    1242                 :     1283032 :     case ARRAY_RANGE_REF:
    1243                 :     1283032 :     case BIT_FIELD_REF:
    1244                 :             :       /* Go down this entire nest and just look at the final prefix and
    1245                 :             :          anything that describes the references.  Otherwise, we lose track
    1246                 :             :          of whether a NOP_EXPR or VIEW_CONVERT_EXPR needs a simple value.  */
    1247                 :     1283032 :       wi->val_only = true;
    1248                 :     1283032 :       wi->is_lhs = false;
    1249                 :     3694725 :       for (; handled_component_p (t); tp = &TREE_OPERAND (t, 0), t = *tp)
    1250                 :             :         {
    1251                 :     2411693 :           if (TREE_CODE (t) == COMPONENT_REF)
    1252                 :     1830742 :             walk_tree (&TREE_OPERAND (t, 2), convert_nonlocal_reference_op, wi,
    1253                 :             :                        NULL);
    1254                 :      580951 :           else if (TREE_CODE (t) == ARRAY_REF
    1255                 :      580951 :                    || TREE_CODE (t) == ARRAY_RANGE_REF)
    1256                 :             :             {
    1257                 :      580354 :               walk_tree (&TREE_OPERAND (t, 1), convert_nonlocal_reference_op,
    1258                 :             :                          wi, NULL);
    1259                 :      580354 :               walk_tree (&TREE_OPERAND (t, 2), convert_nonlocal_reference_op,
    1260                 :             :                          wi, NULL);
    1261                 :      580354 :               walk_tree (&TREE_OPERAND (t, 3), convert_nonlocal_reference_op,
    1262                 :             :                          wi, NULL);
    1263                 :             :             }
    1264                 :             :         }
    1265                 :     1283032 :       wi->val_only = false;
    1266                 :     1283032 :       walk_tree (tp, convert_nonlocal_reference_op, wi, NULL);
    1267                 :     1283032 :       break;
    1268                 :             : 
    1269                 :         778 :     case VIEW_CONVERT_EXPR:
    1270                 :             :       /* Just request to look at the subtrees, leaving val_only and lhs
    1271                 :             :          untouched.  This might actually be for !val_only + lhs, in which
    1272                 :             :          case we don't want to force a replacement by a temporary.  */
    1273                 :         778 :       *walk_subtrees = 1;
    1274                 :         778 :       break;
    1275                 :             : 
    1276                 :     5219740 :     default:
    1277                 :     5219740 :       if (!IS_TYPE_OR_DECL_P (t))
    1278                 :             :         {
    1279                 :     4922682 :           *walk_subtrees = 1;
    1280                 :     4922682 :           wi->val_only = true;
    1281                 :     4922682 :           wi->is_lhs = false;
    1282                 :             :         }
    1283                 :             :       break;
    1284                 :             :     }
    1285                 :             : 
    1286                 :    11242429 :   return NULL_TREE;
    1287                 :             : }
    1288                 :             : 
    1289                 :             : static tree convert_nonlocal_reference_stmt (gimple_stmt_iterator *, bool *,
    1290                 :             :                                              struct walk_stmt_info *);
    1291                 :             : 
    1292                 :             : /* Helper for convert_nonlocal_references, rewrite all references to VAR
    1293                 :             :    and PARM_DECLs that belong to outer functions.  */
    1294                 :             : 
    1295                 :             : static bool
    1296                 :        4813 : convert_nonlocal_omp_clauses (tree *pclauses, struct walk_stmt_info *wi)
    1297                 :             : {
    1298                 :        4813 :   struct nesting_info *const info = (struct nesting_info *) wi->info;
    1299                 :        4813 :   bool need_chain = false, need_stmts = false;
    1300                 :        4813 :   tree clause, decl, *pdecl;
    1301                 :        4813 :   int dummy;
    1302                 :        4813 :   bitmap new_suppress;
    1303                 :             : 
    1304                 :        4813 :   new_suppress = BITMAP_GGC_ALLOC ();
    1305                 :        4813 :   bitmap_copy (new_suppress, info->suppress_expansion);
    1306                 :             : 
    1307                 :       28655 :   for (clause = *pclauses; clause ; clause = OMP_CLAUSE_CHAIN (clause))
    1308                 :             :     {
    1309                 :       23842 :       pdecl = NULL;
    1310                 :       23842 :       switch (OMP_CLAUSE_CODE (clause))
    1311                 :             :         {
    1312                 :         657 :         case OMP_CLAUSE_REDUCTION:
    1313                 :         657 :         case OMP_CLAUSE_IN_REDUCTION:
    1314                 :         657 :         case OMP_CLAUSE_TASK_REDUCTION:
    1315                 :         657 :           if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (clause))
    1316                 :          37 :             need_stmts = true;
    1317                 :         657 :           if (TREE_CODE (OMP_CLAUSE_DECL (clause)) == MEM_REF)
    1318                 :             :             {
    1319                 :           6 :               pdecl = &TREE_OPERAND (OMP_CLAUSE_DECL (clause), 0);
    1320                 :           6 :               if (TREE_CODE (*pdecl) == POINTER_PLUS_EXPR)
    1321                 :           0 :                 pdecl = &TREE_OPERAND (*pdecl, 0);
    1322                 :           6 :               if (INDIRECT_REF_P (*pdecl)
    1323                 :           6 :                   || TREE_CODE (*pdecl) == ADDR_EXPR)
    1324                 :           4 :                 pdecl = &TREE_OPERAND (*pdecl, 0);
    1325                 :             :             }
    1326                 :         657 :           goto do_decl_clause;
    1327                 :             : 
    1328                 :        1152 :         case OMP_CLAUSE_LASTPRIVATE:
    1329                 :        1152 :           if (OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (clause))
    1330                 :         250 :             need_stmts = true;
    1331                 :        1152 :           goto do_decl_clause;
    1332                 :             : 
    1333                 :         391 :         case OMP_CLAUSE_LINEAR:
    1334                 :         391 :           if (OMP_CLAUSE_LINEAR_GIMPLE_SEQ (clause))
    1335                 :          74 :             need_stmts = true;
    1336                 :         391 :           wi->val_only = true;
    1337                 :         391 :           wi->is_lhs = false;
    1338                 :         391 :           convert_nonlocal_reference_op (&OMP_CLAUSE_LINEAR_STEP (clause),
    1339                 :             :                                          &dummy, wi);
    1340                 :         391 :           goto do_decl_clause;
    1341                 :             : 
    1342                 :        5572 :         case OMP_CLAUSE_PRIVATE:
    1343                 :        5572 :         case OMP_CLAUSE_FIRSTPRIVATE:
    1344                 :        5572 :         case OMP_CLAUSE_COPYPRIVATE:
    1345                 :        5572 :         case OMP_CLAUSE_SHARED:
    1346                 :        5572 :         case OMP_CLAUSE_ENTER:
    1347                 :        5572 :         case OMP_CLAUSE_LINK:
    1348                 :        5572 :         case OMP_CLAUSE_USE_DEVICE_PTR:
    1349                 :        5572 :         case OMP_CLAUSE_USE_DEVICE_ADDR:
    1350                 :        5572 :         case OMP_CLAUSE_HAS_DEVICE_ADDR:
    1351                 :        5572 :         case OMP_CLAUSE_IS_DEVICE_PTR:
    1352                 :        5572 :         case OMP_CLAUSE_DETACH:
    1353                 :        5572 :         do_decl_clause:
    1354                 :        2200 :           if (pdecl == NULL)
    1355                 :       16370 :             pdecl = &OMP_CLAUSE_DECL (clause);
    1356                 :       16376 :           decl = *pdecl;
    1357                 :       16376 :           if (VAR_P (decl)
    1358                 :       16376 :               && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
    1359                 :             :             break;
    1360                 :       15957 :           if (decl_function_context (decl) != info->context)
    1361                 :             :             {
    1362                 :        1157 :               if (OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_SHARED)
    1363                 :         356 :                 OMP_CLAUSE_SHARED_READONLY (clause) = 0;
    1364                 :        1157 :               bitmap_set_bit (new_suppress, DECL_UID (decl));
    1365                 :        1157 :               *pdecl = get_nonlocal_debug_decl (info, decl);
    1366                 :        1157 :               if (OMP_CLAUSE_CODE (clause) != OMP_CLAUSE_PRIVATE)
    1367                 :       23842 :                 need_chain = true;
    1368                 :             :             }
    1369                 :             :           break;
    1370                 :             : 
    1371                 :         165 :         case OMP_CLAUSE_SCHEDULE:
    1372                 :         165 :           if (OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clause) == NULL)
    1373                 :             :             break;
    1374                 :             :           /* FALLTHRU */
    1375                 :        2464 :         case OMP_CLAUSE_FINAL:
    1376                 :        2464 :         case OMP_CLAUSE_IF:
    1377                 :        2464 :         case OMP_CLAUSE_SELF:
    1378                 :        2464 :         case OMP_CLAUSE_NUM_THREADS:
    1379                 :        2464 :         case OMP_CLAUSE_DEPEND:
    1380                 :        2464 :         case OMP_CLAUSE_DOACROSS:
    1381                 :        2464 :         case OMP_CLAUSE_DEVICE:
    1382                 :        2464 :         case OMP_CLAUSE_NUM_TEAMS:
    1383                 :        2464 :         case OMP_CLAUSE_THREAD_LIMIT:
    1384                 :        2464 :         case OMP_CLAUSE_SAFELEN:
    1385                 :        2464 :         case OMP_CLAUSE_SIMDLEN:
    1386                 :        2464 :         case OMP_CLAUSE_PRIORITY:
    1387                 :        2464 :         case OMP_CLAUSE_GRAINSIZE:
    1388                 :        2464 :         case OMP_CLAUSE_NUM_TASKS:
    1389                 :        2464 :         case OMP_CLAUSE_HINT:
    1390                 :        2464 :         case OMP_CLAUSE_FILTER:
    1391                 :        2464 :         case OMP_CLAUSE_NUM_GANGS:
    1392                 :        2464 :         case OMP_CLAUSE_NUM_WORKERS:
    1393                 :        2464 :         case OMP_CLAUSE_VECTOR_LENGTH:
    1394                 :        2464 :         case OMP_CLAUSE_GANG:
    1395                 :        2464 :         case OMP_CLAUSE_WORKER:
    1396                 :        2464 :         case OMP_CLAUSE_VECTOR:
    1397                 :        2464 :         case OMP_CLAUSE_ASYNC:
    1398                 :        2464 :         case OMP_CLAUSE_WAIT:
    1399                 :             :           /* Several OpenACC clauses have optional arguments.  Check if they
    1400                 :             :              are present.  */
    1401                 :        2464 :           if (OMP_CLAUSE_OPERAND (clause, 0))
    1402                 :             :             {
    1403                 :        2208 :               wi->val_only = true;
    1404                 :        2208 :               wi->is_lhs = false;
    1405                 :        2208 :               convert_nonlocal_reference_op (&OMP_CLAUSE_OPERAND (clause, 0),
    1406                 :             :                                              &dummy, wi);
    1407                 :             :             }
    1408                 :             : 
    1409                 :             :           /* The gang clause accepts two arguments.  */
    1410                 :        2464 :           if (OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_GANG
    1411                 :        2464 :               && OMP_CLAUSE_GANG_STATIC_EXPR (clause))
    1412                 :             :             {
    1413                 :          28 :                 wi->val_only = true;
    1414                 :          28 :                 wi->is_lhs = false;
    1415                 :          28 :                 convert_nonlocal_reference_op
    1416                 :          28 :                   (&OMP_CLAUSE_GANG_STATIC_EXPR (clause), &dummy, wi);
    1417                 :             :             }
    1418                 :             :           break;
    1419                 :             : 
    1420                 :           7 :         case OMP_CLAUSE_DIST_SCHEDULE:
    1421                 :           7 :           if (OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (clause) != NULL)
    1422                 :             :             {
    1423                 :           7 :               wi->val_only = true;
    1424                 :           7 :               wi->is_lhs = false;
    1425                 :           7 :               convert_nonlocal_reference_op (&OMP_CLAUSE_OPERAND (clause, 0),
    1426                 :             :                                              &dummy, wi);
    1427                 :             :             }
    1428                 :             :           break;
    1429                 :             : 
    1430                 :        7233 :         case OMP_CLAUSE_MAP:
    1431                 :        7233 :         case OMP_CLAUSE_TO:
    1432                 :        7233 :         case OMP_CLAUSE_FROM:
    1433                 :        7233 :           if (OMP_CLAUSE_SIZE (clause))
    1434                 :             :             {
    1435                 :        7233 :               wi->val_only = true;
    1436                 :        7233 :               wi->is_lhs = false;
    1437                 :        7233 :               convert_nonlocal_reference_op (&OMP_CLAUSE_SIZE (clause),
    1438                 :             :                                              &dummy, wi);
    1439                 :             :             }
    1440                 :        7233 :           if (DECL_P (OMP_CLAUSE_DECL (clause)))
    1441                 :        3372 :             goto do_decl_clause;
    1442                 :        3861 :           wi->val_only = true;
    1443                 :        3861 :           wi->is_lhs = false;
    1444                 :        3861 :           walk_tree (&OMP_CLAUSE_DECL (clause), convert_nonlocal_reference_op,
    1445                 :             :                      wi, NULL);
    1446                 :        3861 :           break;
    1447                 :             : 
    1448                 :           6 :         case OMP_CLAUSE_ALIGNED:
    1449                 :           6 :           if (OMP_CLAUSE_ALIGNED_ALIGNMENT (clause))
    1450                 :             :             {
    1451                 :           6 :               wi->val_only = true;
    1452                 :           6 :               wi->is_lhs = false;
    1453                 :           6 :               convert_nonlocal_reference_op
    1454                 :           6 :                 (&OMP_CLAUSE_ALIGNED_ALIGNMENT (clause), &dummy, wi);
    1455                 :             :             }
    1456                 :             :           /* FALLTHRU */
    1457                 :           6 :         case OMP_CLAUSE_NONTEMPORAL:
    1458                 :           0 :         do_decl_clause_no_supp:
    1459                 :             :           /* Like do_decl_clause, but don't add any suppression.  */
    1460                 :           6 :           decl = OMP_CLAUSE_DECL (clause);
    1461                 :           6 :           if (VAR_P (decl)
    1462                 :           6 :               && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
    1463                 :             :             break;
    1464                 :           6 :           if (decl_function_context (decl) != info->context)
    1465                 :             :             {
    1466                 :           6 :               OMP_CLAUSE_DECL (clause) = get_nonlocal_debug_decl (info, decl);
    1467                 :           6 :               need_chain = true;
    1468                 :             :             }
    1469                 :             :           break;
    1470                 :             : 
    1471                 :           0 :         case OMP_CLAUSE_ALLOCATE:
    1472                 :           0 :           if (OMP_CLAUSE_ALLOCATE_ALLOCATOR (clause))
    1473                 :             :             {
    1474                 :           0 :               wi->val_only = true;
    1475                 :           0 :               wi->is_lhs = false;
    1476                 :           0 :               convert_nonlocal_reference_op
    1477                 :           0 :                 (&OMP_CLAUSE_ALLOCATE_ALLOCATOR (clause), &dummy, wi);
    1478                 :             :             }
    1479                 :           0 :           goto do_decl_clause_no_supp;
    1480                 :             : 
    1481                 :             :         case OMP_CLAUSE_NOWAIT:
    1482                 :             :         case OMP_CLAUSE_ORDERED:
    1483                 :             :         case OMP_CLAUSE_DEFAULT:
    1484                 :             :         case OMP_CLAUSE_COPYIN:
    1485                 :             :         case OMP_CLAUSE_COLLAPSE:
    1486                 :             :         case OMP_CLAUSE_TILE:
    1487                 :             :         case OMP_CLAUSE_UNTIED:
    1488                 :             :         case OMP_CLAUSE_MERGEABLE:
    1489                 :             :         case OMP_CLAUSE_PROC_BIND:
    1490                 :             :         case OMP_CLAUSE_NOGROUP:
    1491                 :             :         case OMP_CLAUSE_THREADS:
    1492                 :             :         case OMP_CLAUSE_SIMD:
    1493                 :             :         case OMP_CLAUSE_DEFAULTMAP:
    1494                 :             :         case OMP_CLAUSE_ORDER:
    1495                 :             :         case OMP_CLAUSE_SEQ:
    1496                 :             :         case OMP_CLAUSE_INDEPENDENT:
    1497                 :             :         case OMP_CLAUSE_AUTO:
    1498                 :             :         case OMP_CLAUSE_IF_PRESENT:
    1499                 :             :         case OMP_CLAUSE_FINALIZE:
    1500                 :             :         case OMP_CLAUSE_BIND:
    1501                 :             :         case OMP_CLAUSE__CONDTEMP_:
    1502                 :             :         case OMP_CLAUSE__SCANTEMP_:
    1503                 :             :           break;
    1504                 :             : 
    1505                 :             :           /* The following clause belongs to the OpenACC cache directive, which
    1506                 :             :              is discarded during gimplification.  */
    1507                 :           0 :         case OMP_CLAUSE__CACHE_:
    1508                 :             :           /* The following clauses are only allowed in the OpenMP declare simd
    1509                 :             :              directive, so not seen here.  */
    1510                 :           0 :         case OMP_CLAUSE_UNIFORM:
    1511                 :           0 :         case OMP_CLAUSE_INBRANCH:
    1512                 :           0 :         case OMP_CLAUSE_NOTINBRANCH:
    1513                 :             :           /* The following clauses are only allowed on OpenMP cancel and
    1514                 :             :              cancellation point directives, which at this point have already
    1515                 :             :              been lowered into a function call.  */
    1516                 :           0 :         case OMP_CLAUSE_FOR:
    1517                 :           0 :         case OMP_CLAUSE_PARALLEL:
    1518                 :           0 :         case OMP_CLAUSE_SECTIONS:
    1519                 :           0 :         case OMP_CLAUSE_TASKGROUP:
    1520                 :             :           /* The following clauses are only added during OMP lowering; nested
    1521                 :             :              function decomposition happens before that.  */
    1522                 :           0 :         case OMP_CLAUSE__LOOPTEMP_:
    1523                 :           0 :         case OMP_CLAUSE__REDUCTEMP_:
    1524                 :           0 :         case OMP_CLAUSE__SIMDUID_:
    1525                 :           0 :         case OMP_CLAUSE__SIMT_:
    1526                 :             :           /* The following clauses are only allowed on OpenACC 'routine'
    1527                 :             :              directives, not seen here.  */
    1528                 :           0 :         case OMP_CLAUSE_NOHOST:
    1529                 :             :           /* Anything else.  */
    1530                 :           0 :         default:
    1531                 :           0 :           gcc_unreachable ();
    1532                 :             :         }
    1533                 :             :     }
    1534                 :             : 
    1535                 :        4813 :   info->suppress_expansion = new_suppress;
    1536                 :             : 
    1537                 :        4813 :   if (need_stmts)
    1538                 :        1540 :     for (clause = *pclauses; clause ; clause = OMP_CLAUSE_CHAIN (clause))
    1539                 :        1255 :       switch (OMP_CLAUSE_CODE (clause))
    1540                 :             :         {
    1541                 :         103 :         case OMP_CLAUSE_REDUCTION:
    1542                 :         103 :         case OMP_CLAUSE_IN_REDUCTION:
    1543                 :         103 :         case OMP_CLAUSE_TASK_REDUCTION:
    1544                 :         103 :           if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (clause))
    1545                 :             :             {
    1546                 :          37 :               tree old_context
    1547                 :          37 :                 = DECL_CONTEXT (OMP_CLAUSE_REDUCTION_PLACEHOLDER (clause));
    1548                 :          37 :               DECL_CONTEXT (OMP_CLAUSE_REDUCTION_PLACEHOLDER (clause))
    1549                 :          37 :                 = info->context;
    1550                 :          37 :               if (OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (clause))
    1551                 :           0 :                 DECL_CONTEXT (OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (clause))
    1552                 :           0 :                   = info->context;
    1553                 :          37 :               tree save_local_var_chain = info->new_local_var_chain;
    1554                 :          37 :               info->new_local_var_chain = NULL;
    1555                 :          37 :               gimple_seq *seq = &OMP_CLAUSE_REDUCTION_GIMPLE_INIT (clause);
    1556                 :          37 :               walk_body (convert_nonlocal_reference_stmt,
    1557                 :             :                          convert_nonlocal_reference_op, info, seq);
    1558                 :          37 :               if (info->new_local_var_chain)
    1559                 :           1 :                 declare_vars (info->new_local_var_chain,
    1560                 :             :                               gimple_seq_first_stmt (*seq), false);
    1561                 :          37 :               info->new_local_var_chain = NULL;
    1562                 :          37 :               seq = &OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (clause);
    1563                 :          37 :               walk_body (convert_nonlocal_reference_stmt,
    1564                 :             :                          convert_nonlocal_reference_op, info, seq);
    1565                 :          37 :               if (info->new_local_var_chain)
    1566                 :           1 :                 declare_vars (info->new_local_var_chain,
    1567                 :             :                               gimple_seq_first_stmt (*seq), false);
    1568                 :          37 :               info->new_local_var_chain = save_local_var_chain;
    1569                 :          37 :               DECL_CONTEXT (OMP_CLAUSE_REDUCTION_PLACEHOLDER (clause))
    1570                 :          37 :                 = old_context;
    1571                 :          37 :               if (OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (clause))
    1572                 :           0 :                 DECL_CONTEXT (OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (clause))
    1573                 :           0 :                   = old_context;
    1574                 :             :             }
    1575                 :             :           break;
    1576                 :             : 
    1577                 :         625 :         case OMP_CLAUSE_LASTPRIVATE:
    1578                 :         625 :         case OMP_CLAUSE_LINEAR:
    1579                 :         625 :           {
    1580                 :         625 :             tree save_local_var_chain = info->new_local_var_chain;
    1581                 :         625 :             info->new_local_var_chain = NULL;
    1582                 :         625 :             gimple_seq *seq;
    1583                 :         625 :             if (OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_LASTPRIVATE)
    1584                 :         410 :               seq = &OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (clause);
    1585                 :             :             else
    1586                 :         215 :               seq = &OMP_CLAUSE_LINEAR_GIMPLE_SEQ (clause);
    1587                 :         625 :             walk_body (convert_nonlocal_reference_stmt,
    1588                 :             :                        convert_nonlocal_reference_op, info, seq);
    1589                 :         625 :             if (info->new_local_var_chain)
    1590                 :             :               {
    1591                 :           8 :                 gimple *g = gimple_seq_first_stmt (*seq);
    1592                 :           8 :                 if (gimple_code (g) != GIMPLE_BIND)
    1593                 :             :                   {
    1594                 :           2 :                     g = gimple_build_bind (NULL_TREE, *seq, NULL_TREE);
    1595                 :           2 :                     *seq = NULL;
    1596                 :           2 :                     gimple_seq_add_stmt_without_update (seq, g);
    1597                 :             :                   }
    1598                 :           8 :                 declare_vars (info->new_local_var_chain,
    1599                 :             :                               gimple_seq_first_stmt (*seq), false);
    1600                 :             :               }
    1601                 :         625 :             info->new_local_var_chain = save_local_var_chain;
    1602                 :             :           }
    1603                 :         625 :           break;
    1604                 :             : 
    1605                 :             :         default:
    1606                 :             :           break;
    1607                 :             :         }
    1608                 :             : 
    1609                 :        4813 :   return need_chain;
    1610                 :             : }
    1611                 :             : 
    1612                 :             : /* Create nonlocal debug decls for nonlocal VLA array bounds.  */
    1613                 :             : 
    1614                 :             : static void
    1615                 :           2 : note_nonlocal_vla_type (struct nesting_info *info, tree type)
    1616                 :             : {
    1617                 :           3 :   while (POINTER_TYPE_P (type) && !TYPE_NAME (type))
    1618                 :           1 :     type = TREE_TYPE (type);
    1619                 :             : 
    1620                 :           2 :   if (TYPE_NAME (type)
    1621                 :           2 :       && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
    1622                 :           4 :       && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
    1623                 :           1 :     type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
    1624                 :             : 
    1625                 :           2 :   while (POINTER_TYPE_P (type)
    1626                 :             :          || VECTOR_TYPE_P (type)
    1627                 :             :          || TREE_CODE (type) == FUNCTION_TYPE
    1628                 :           2 :          || TREE_CODE (type) == METHOD_TYPE)
    1629                 :           0 :     type = TREE_TYPE (type);
    1630                 :             : 
    1631                 :           2 :   if (TREE_CODE (type) == ARRAY_TYPE)
    1632                 :             :     {
    1633                 :           1 :       tree domain, t;
    1634                 :             : 
    1635                 :           1 :       note_nonlocal_vla_type (info, TREE_TYPE (type));
    1636                 :           1 :       domain = TYPE_DOMAIN (type);
    1637                 :           1 :       if (domain)
    1638                 :             :         {
    1639                 :           1 :           t = TYPE_MIN_VALUE (domain);
    1640                 :           1 :           if (t && (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
    1641                 :           1 :               && decl_function_context (t) != info->context)
    1642                 :           0 :             get_nonlocal_debug_decl (info, t);
    1643                 :           1 :           t = TYPE_MAX_VALUE (domain);
    1644                 :           1 :           if (t && (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
    1645                 :           2 :               && decl_function_context (t) != info->context)
    1646                 :           1 :             get_nonlocal_debug_decl (info, t);
    1647                 :             :         }
    1648                 :             :     }
    1649                 :           2 : }
    1650                 :             : 
    1651                 :             : /* Callback for walk_gimple_stmt.  Rewrite all references to VAR and
    1652                 :             :    PARM_DECLs that belong to outer functions.  This handles statements
    1653                 :             :    that are not handled via the standard recursion done in
    1654                 :             :    walk_gimple_stmt.  STMT is the statement to examine, DATA is as in
    1655                 :             :    convert_nonlocal_reference_op.  Set *HANDLED_OPS_P to true if all the
    1656                 :             :    operands of STMT have been handled by this function.  */
    1657                 :             : 
    1658                 :             : static tree
    1659                 :     4110521 : convert_nonlocal_reference_stmt (gimple_stmt_iterator *gsi, bool *handled_ops_p,
    1660                 :             :                                  struct walk_stmt_info *wi)
    1661                 :             : {
    1662                 :     4110521 :   struct nesting_info *info = (struct nesting_info *) wi->info;
    1663                 :     4110521 :   tree save_local_var_chain;
    1664                 :     4110521 :   bitmap save_suppress;
    1665                 :     4110521 :   gimple *stmt = gsi_stmt (*gsi);
    1666                 :             : 
    1667                 :     4110521 :   switch (gimple_code (stmt))
    1668                 :             :     {
    1669                 :      151172 :     case GIMPLE_GOTO:
    1670                 :             :       /* Don't walk non-local gotos for now.  */
    1671                 :      151172 :       if (TREE_CODE (gimple_goto_dest (stmt)) != LABEL_DECL)
    1672                 :             :         {
    1673                 :          75 :           wi->val_only = true;
    1674                 :          75 :           wi->is_lhs = false;
    1675                 :          75 :           *handled_ops_p = false;
    1676                 :          75 :           return NULL_TREE;
    1677                 :             :         }
    1678                 :             :       break;
    1679                 :             : 
    1680                 :          38 :     case GIMPLE_OMP_TEAMS:
    1681                 :          38 :       if (!gimple_omp_teams_host (as_a <gomp_teams *> (stmt)))
    1682                 :             :         {
    1683                 :          26 :           save_suppress = info->suppress_expansion;
    1684                 :          26 :           convert_nonlocal_omp_clauses (gimple_omp_teams_clauses_ptr (stmt),
    1685                 :             :                                         wi);
    1686                 :          26 :           walk_body (convert_nonlocal_reference_stmt,
    1687                 :             :                      convert_nonlocal_reference_op, info,
    1688                 :             :                      gimple_omp_body_ptr (stmt));
    1689                 :          26 :           info->suppress_expansion = save_suppress;
    1690                 :          26 :           break;
    1691                 :             :         }
    1692                 :             :       /* FALLTHRU */
    1693                 :             : 
    1694                 :        1302 :     case GIMPLE_OMP_PARALLEL:
    1695                 :        1302 :     case GIMPLE_OMP_TASK:
    1696                 :        1302 :       save_suppress = info->suppress_expansion;
    1697                 :        1302 :       if (convert_nonlocal_omp_clauses (gimple_omp_taskreg_clauses_ptr (stmt),
    1698                 :             :                                         wi))
    1699                 :             :         {
    1700                 :         152 :           tree c, decl;
    1701                 :         152 :           decl = get_chain_decl (info);
    1702                 :         152 :           c = build_omp_clause (gimple_location (stmt),
    1703                 :             :                                 OMP_CLAUSE_FIRSTPRIVATE);
    1704                 :         152 :           OMP_CLAUSE_DECL (c) = decl;
    1705                 :         152 :           OMP_CLAUSE_CHAIN (c) = gimple_omp_taskreg_clauses (stmt);
    1706                 :         152 :           gimple_omp_taskreg_set_clauses (stmt, c);
    1707                 :             :         }
    1708                 :             : 
    1709                 :        1302 :       save_local_var_chain = info->new_local_var_chain;
    1710                 :        1302 :       info->new_local_var_chain = NULL;
    1711                 :             : 
    1712                 :        1302 :       walk_body (convert_nonlocal_reference_stmt, convert_nonlocal_reference_op,
    1713                 :             :                  info, gimple_omp_body_ptr (stmt));
    1714                 :             : 
    1715                 :        1302 :       if (info->new_local_var_chain)
    1716                 :         110 :         declare_vars (info->new_local_var_chain,
    1717                 :             :                       gimple_seq_first_stmt (gimple_omp_body (stmt)),
    1718                 :             :                       false);
    1719                 :        1302 :       info->new_local_var_chain = save_local_var_chain;
    1720                 :        1302 :       info->suppress_expansion = save_suppress;
    1721                 :        1302 :       break;
    1722                 :             : 
    1723                 :        1476 :     case GIMPLE_OMP_FOR:
    1724                 :        1476 :       save_suppress = info->suppress_expansion;
    1725                 :        1476 :       convert_nonlocal_omp_clauses (gimple_omp_for_clauses_ptr (stmt), wi);
    1726                 :        1476 :       walk_gimple_omp_for (as_a <gomp_for *> (stmt),
    1727                 :             :                            convert_nonlocal_reference_stmt,
    1728                 :             :                            convert_nonlocal_reference_op, info);
    1729                 :        1476 :       walk_body (convert_nonlocal_reference_stmt,
    1730                 :             :                  convert_nonlocal_reference_op, info, gimple_omp_body_ptr (stmt));
    1731                 :        1476 :       info->suppress_expansion = save_suppress;
    1732                 :        1476 :       break;
    1733                 :             : 
    1734                 :          42 :     case GIMPLE_OMP_SECTIONS:
    1735                 :          42 :       save_suppress = info->suppress_expansion;
    1736                 :          42 :       convert_nonlocal_omp_clauses (gimple_omp_sections_clauses_ptr (stmt), wi);
    1737                 :          42 :       walk_body (convert_nonlocal_reference_stmt, convert_nonlocal_reference_op,
    1738                 :             :                  info, gimple_omp_body_ptr (stmt));
    1739                 :          42 :       info->suppress_expansion = save_suppress;
    1740                 :          42 :       break;
    1741                 :             : 
    1742                 :         185 :     case GIMPLE_OMP_SINGLE:
    1743                 :         185 :       save_suppress = info->suppress_expansion;
    1744                 :         185 :       convert_nonlocal_omp_clauses (gimple_omp_single_clauses_ptr (stmt), wi);
    1745                 :         185 :       walk_body (convert_nonlocal_reference_stmt, convert_nonlocal_reference_op,
    1746                 :             :                  info, gimple_omp_body_ptr (stmt));
    1747                 :         185 :       info->suppress_expansion = save_suppress;
    1748                 :         185 :       break;
    1749                 :             : 
    1750                 :           0 :     case GIMPLE_OMP_SCOPE:
    1751                 :           0 :       save_suppress = info->suppress_expansion;
    1752                 :           0 :       convert_nonlocal_omp_clauses (gimple_omp_scope_clauses_ptr (stmt), wi);
    1753                 :           0 :       walk_body (convert_nonlocal_reference_stmt, convert_nonlocal_reference_op,
    1754                 :             :                  info, gimple_omp_body_ptr (stmt));
    1755                 :           0 :       info->suppress_expansion = save_suppress;
    1756                 :           0 :       break;
    1757                 :             : 
    1758                 :          38 :     case GIMPLE_OMP_TASKGROUP:
    1759                 :          38 :       save_suppress = info->suppress_expansion;
    1760                 :          38 :       convert_nonlocal_omp_clauses (gimple_omp_taskgroup_clauses_ptr (stmt), wi);
    1761                 :          38 :       walk_body (convert_nonlocal_reference_stmt, convert_nonlocal_reference_op,
    1762                 :             :                  info, gimple_omp_body_ptr (stmt));
    1763                 :          38 :       info->suppress_expansion = save_suppress;
    1764                 :          38 :       break;
    1765                 :             : 
    1766                 :        1744 :     case GIMPLE_OMP_TARGET:
    1767                 :        1744 :       if (!is_gimple_omp_offloaded (stmt))
    1768                 :             :         {
    1769                 :         646 :           save_suppress = info->suppress_expansion;
    1770                 :         646 :           convert_nonlocal_omp_clauses (gimple_omp_target_clauses_ptr (stmt),
    1771                 :             :                                         wi);
    1772                 :         646 :           info->suppress_expansion = save_suppress;
    1773                 :         646 :           walk_body (convert_nonlocal_reference_stmt,
    1774                 :             :                      convert_nonlocal_reference_op, info,
    1775                 :             :                      gimple_omp_body_ptr (stmt));
    1776                 :         646 :           break;
    1777                 :             :         }
    1778                 :        1098 :       save_suppress = info->suppress_expansion;
    1779                 :        1098 :       if (convert_nonlocal_omp_clauses (gimple_omp_target_clauses_ptr (stmt),
    1780                 :             :                                         wi))
    1781                 :             :         {
    1782                 :          55 :           tree c, decl;
    1783                 :          55 :           decl = get_chain_decl (info);
    1784                 :          55 :           c = build_omp_clause (gimple_location (stmt), OMP_CLAUSE_MAP);
    1785                 :          55 :           OMP_CLAUSE_DECL (c) = decl;
    1786                 :          55 :           OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TO);
    1787                 :          55 :           OMP_CLAUSE_SIZE (c) = DECL_SIZE_UNIT (decl);
    1788                 :          55 :           OMP_CLAUSE_CHAIN (c) = gimple_omp_target_clauses (stmt);
    1789                 :          55 :           gimple_omp_target_set_clauses (as_a <gomp_target *> (stmt), c);
    1790                 :             :         }
    1791                 :             : 
    1792                 :        1098 :       save_local_var_chain = info->new_local_var_chain;
    1793                 :        1098 :       info->new_local_var_chain = NULL;
    1794                 :             : 
    1795                 :        1098 :       walk_body (convert_nonlocal_reference_stmt, convert_nonlocal_reference_op,
    1796                 :             :                  info, gimple_omp_body_ptr (stmt));
    1797                 :             : 
    1798                 :        1098 :       if (info->new_local_var_chain)
    1799                 :         216 :         declare_vars (info->new_local_var_chain,
    1800                 :             :                       gimple_seq_first_stmt (gimple_omp_body (stmt)),
    1801                 :             :                       false);
    1802                 :        1098 :       info->new_local_var_chain = save_local_var_chain;
    1803                 :        1098 :       info->suppress_expansion = save_suppress;
    1804                 :        1098 :       break;
    1805                 :             : 
    1806                 :         552 :     case GIMPLE_OMP_SECTION:
    1807                 :         552 :     case GIMPLE_OMP_STRUCTURED_BLOCK:
    1808                 :         552 :     case GIMPLE_OMP_MASTER:
    1809                 :         552 :     case GIMPLE_OMP_MASKED:
    1810                 :         552 :     case GIMPLE_OMP_ORDERED:
    1811                 :         552 :     case GIMPLE_OMP_SCAN:
    1812                 :         552 :       walk_body (convert_nonlocal_reference_stmt, convert_nonlocal_reference_op,
    1813                 :             :                  info, gimple_omp_body_ptr (stmt));
    1814                 :         552 :       break;
    1815                 :             : 
    1816                 :      191858 :     case GIMPLE_BIND:
    1817                 :      191858 :       {
    1818                 :      191858 :       gbind *bind_stmt = as_a <gbind *> (stmt);
    1819                 :             : 
    1820                 :      856505 :       for (tree var = gimple_bind_vars (bind_stmt); var; var = DECL_CHAIN (var))
    1821                 :      664647 :         if (TREE_CODE (var) == NAMELIST_DECL)
    1822                 :             :           {
    1823                 :             :             /* Adjust decls mentioned in NAMELIST_DECL.  */
    1824                 :         131 :             tree decls = NAMELIST_DECL_ASSOCIATED_DECL (var);
    1825                 :         131 :             tree decl;
    1826                 :         131 :             unsigned int i;
    1827                 :             : 
    1828                 :      665324 :             FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (decls), i, decl)
    1829                 :             :               {
    1830                 :         771 :                 if (VAR_P (decl)
    1831                 :         677 :                     && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
    1832                 :          94 :                   continue;
    1833                 :         583 :                 if (decl_function_context (decl) != info->context)
    1834                 :           7 :                   CONSTRUCTOR_ELT (decls, i)->value
    1835                 :          14 :                     = get_nonlocal_debug_decl (info, decl);
    1836                 :             :               }
    1837                 :             :           }
    1838                 :             : 
    1839                 :      191858 :       *handled_ops_p = false;
    1840                 :      191858 :       return NULL_TREE;
    1841                 :             :       }
    1842                 :      243611 :     case GIMPLE_COND:
    1843                 :      243611 :       wi->val_only = true;
    1844                 :      243611 :       wi->is_lhs = false;
    1845                 :      243611 :       *handled_ops_p = false;
    1846                 :      243611 :       return NULL_TREE;
    1847                 :             : 
    1848                 :     2463158 :     case GIMPLE_ASSIGN:
    1849                 :     2463158 :       if (gimple_clobber_p (stmt))
    1850                 :             :         {
    1851                 :       99519 :           tree lhs = gimple_assign_lhs (stmt);
    1852                 :       99519 :           if (DECL_P (lhs)
    1853                 :       99485 :               && !(TREE_STATIC (lhs) || DECL_EXTERNAL (lhs))
    1854                 :      198935 :               && decl_function_context (lhs) != info->context)
    1855                 :             :             {
    1856                 :          11 :               gsi_replace (gsi, gimple_build_nop (), true);
    1857                 :          11 :               break;
    1858                 :             :             }
    1859                 :             :         }
    1860                 :     2463147 :       *handled_ops_p = false;
    1861                 :     2463147 :       return NULL_TREE;
    1862                 :             : 
    1863                 :     1055357 :     default:
    1864                 :             :       /* For every other statement that we are not interested in
    1865                 :             :          handling here, let the walker traverse the operands.  */
    1866                 :     1055357 :       *handled_ops_p = false;
    1867                 :     1055357 :       return NULL_TREE;
    1868                 :             :     }
    1869                 :             : 
    1870                 :             :   /* We have handled all of STMT operands, no need to traverse the operands.  */
    1871                 :      156473 :   *handled_ops_p = true;
    1872                 :      156473 :   return NULL_TREE;
    1873                 :             : }
    1874                 :             : 
    1875                 :             : 
    1876                 :             : /* A subroutine of convert_local_reference.  Create a local variable
    1877                 :             :    in the parent function with DECL_VALUE_EXPR set to reference the
    1878                 :             :    field in FRAME.  This is used both for debug info and in OMP
    1879                 :             :    lowering.  */
    1880                 :             : 
    1881                 :             : static tree
    1882                 :         205 : get_local_debug_decl (struct nesting_info *info, tree decl, tree field)
    1883                 :             : {
    1884                 :         205 :   tree x, new_decl;
    1885                 :             : 
    1886                 :         205 :   tree *slot = &info->var_map->get_or_insert (decl);
    1887                 :         205 :   if (*slot)
    1888                 :             :     return *slot;
    1889                 :             : 
    1890                 :             :   /* Make sure frame_decl gets created.  */
    1891                 :          63 :   (void) get_frame_type (info);
    1892                 :          63 :   x = info->frame_decl;
    1893                 :          63 :   x = build3 (COMPONENT_REF, TREE_TYPE (field), x, field, NULL_TREE);
    1894                 :             : 
    1895                 :          63 :   new_decl = build_decl (DECL_SOURCE_LOCATION (decl),
    1896                 :          63 :                          VAR_DECL, DECL_NAME (decl), TREE_TYPE (decl));
    1897                 :          63 :   DECL_CONTEXT (new_decl) = info->context;
    1898                 :          63 :   DECL_ARTIFICIAL (new_decl) = DECL_ARTIFICIAL (decl);
    1899                 :          63 :   DECL_IGNORED_P (new_decl) = DECL_IGNORED_P (decl);
    1900                 :          63 :   TREE_THIS_VOLATILE (new_decl) = TREE_THIS_VOLATILE (decl);
    1901                 :          63 :   TREE_SIDE_EFFECTS (new_decl) = TREE_SIDE_EFFECTS (decl);
    1902                 :          63 :   TREE_READONLY (new_decl) = TREE_READONLY (decl);
    1903                 :          63 :   TREE_ADDRESSABLE (new_decl) = TREE_ADDRESSABLE (decl);
    1904                 :          63 :   DECL_SEEN_IN_BIND_EXPR_P (new_decl) = 1;
    1905                 :          63 :   if ((TREE_CODE (decl) == PARM_DECL
    1906                 :             :        || TREE_CODE (decl) == RESULT_DECL
    1907                 :             :        || VAR_P (decl))
    1908                 :          63 :       && DECL_BY_REFERENCE (decl))
    1909                 :           0 :     DECL_BY_REFERENCE (new_decl) = 1;
    1910                 :             : 
    1911                 :          63 :   SET_DECL_VALUE_EXPR (new_decl, x);
    1912                 :          63 :   DECL_HAS_VALUE_EXPR_P (new_decl) = 1;
    1913                 :          63 :   *slot = new_decl;
    1914                 :             : 
    1915                 :          63 :   DECL_CHAIN (new_decl) = info->debug_var_chain;
    1916                 :          63 :   info->debug_var_chain = new_decl;
    1917                 :             : 
    1918                 :             :   /* Do not emit debug info twice.  */
    1919                 :          63 :   DECL_IGNORED_P (decl) = 1;
    1920                 :             : 
    1921                 :          63 :   return new_decl;
    1922                 :             : }
    1923                 :             : 
    1924                 :             : 
    1925                 :             : /* Called via walk_function+walk_gimple_stmt, rewrite all references to VAR
    1926                 :             :    and PARM_DECLs that were referenced by inner nested functions.
    1927                 :             :    The rewrite will be a structure reference to the local frame variable.  */
    1928                 :             : 
    1929                 :             : static bool convert_local_omp_clauses (tree *, struct walk_stmt_info *);
    1930                 :             : 
    1931                 :             : static tree
    1932                 :    11157365 : convert_local_reference_op (tree *tp, int *walk_subtrees, void *data)
    1933                 :             : {
    1934                 :    11157365 :   struct walk_stmt_info *wi = (struct walk_stmt_info *) data;
    1935                 :    11157365 :   struct nesting_info *const info = (struct nesting_info *) wi->info;
    1936                 :    11157365 :   tree t = *tp, field, x;
    1937                 :    11157365 :   bool save_val_only;
    1938                 :             : 
    1939                 :    11157365 :   *walk_subtrees = 0;
    1940                 :    11157365 :   switch (TREE_CODE (t))
    1941                 :             :     {
    1942                 :     2841703 :     case VAR_DECL:
    1943                 :             :       /* Non-automatic variables are never processed.  */
    1944                 :     2841703 :       if (TREE_STATIC (t) || DECL_EXTERNAL (t))
    1945                 :             :         break;
    1946                 :             :       /* FALLTHRU */
    1947                 :             : 
    1948                 :     2855058 :     case PARM_DECL:
    1949                 :     2855058 :       if (t != info->frame_decl && decl_function_context (t) == info->context)
    1950                 :             :         {
    1951                 :             :           /* If we copied a pointer to the frame, then the original decl
    1952                 :             :              is used unchanged in the parent function.  */
    1953                 :     2852579 :           if (use_pointer_in_frame (t))
    1954                 :             :             break;
    1955                 :             : 
    1956                 :             :           /* No need to transform anything if no child references the
    1957                 :             :              variable.  */
    1958                 :     2852465 :           field = lookup_field_for_decl (info, t, NO_INSERT);
    1959                 :     2852465 :           if (!field)
    1960                 :             :             break;
    1961                 :       19832 :           wi->changed = true;
    1962                 :             : 
    1963                 :       19832 :           if (bitmap_bit_p (info->suppress_expansion, DECL_UID (t)))
    1964                 :         120 :             x = get_local_debug_decl (info, t, field);
    1965                 :             :           else
    1966                 :       19712 :             x = get_frame_field (info, info->context, field, &wi->gsi);
    1967                 :             : 
    1968                 :       19832 :           if (wi->val_only)
    1969                 :             :             {
    1970                 :        7745 :               if (wi->is_lhs)
    1971                 :        2500 :                 x = save_tmp_var (info, x, &wi->gsi);
    1972                 :             :               else
    1973                 :        5245 :                 x = init_tmp_var (info, x, &wi->gsi);
    1974                 :             :             }
    1975                 :             : 
    1976                 :       19832 :           *tp = x;
    1977                 :             :         }
    1978                 :             :       break;
    1979                 :             : 
    1980                 :      566352 :     case ADDR_EXPR:
    1981                 :      566352 :       save_val_only = wi->val_only;
    1982                 :      566352 :       wi->val_only = false;
    1983                 :      566352 :       wi->is_lhs = false;
    1984                 :      566352 :       wi->changed = false;
    1985                 :      566352 :       walk_tree (&TREE_OPERAND (t, 0), convert_local_reference_op, wi, NULL);
    1986                 :      566352 :       wi->val_only = save_val_only;
    1987                 :             : 
    1988                 :             :       /* If we converted anything ... */
    1989                 :      566352 :       if (wi->changed)
    1990                 :             :         {
    1991                 :        3391 :           tree save_context;
    1992                 :             : 
    1993                 :             :           /* Then the frame decl is now addressable.  */
    1994                 :        3391 :           TREE_ADDRESSABLE (info->frame_decl) = 1;
    1995                 :             : 
    1996                 :        3391 :           save_context = current_function_decl;
    1997                 :        3391 :           current_function_decl = info->context;
    1998                 :        3391 :           recompute_tree_invariant_for_addr_expr (t);
    1999                 :             : 
    2000                 :             :           /* If we are in a context where we only accept values, then
    2001                 :             :              compute the address into a temporary.  */
    2002                 :        3391 :           if (save_val_only)
    2003                 :        2842 :             *tp = gsi_gimplify_val ((struct nesting_info *) wi->info,
    2004                 :             :                                     t, &wi->gsi);
    2005                 :        3391 :           current_function_decl = save_context;
    2006                 :             :         }
    2007                 :             :       break;
    2008                 :             : 
    2009                 :     1293370 :     case REALPART_EXPR:
    2010                 :     1293370 :     case IMAGPART_EXPR:
    2011                 :     1293370 :     case COMPONENT_REF:
    2012                 :     1293370 :     case ARRAY_REF:
    2013                 :     1293370 :     case ARRAY_RANGE_REF:
    2014                 :     1293370 :     case BIT_FIELD_REF:
    2015                 :             :       /* Go down this entire nest and just look at the final prefix and
    2016                 :             :          anything that describes the references.  Otherwise, we lose track
    2017                 :             :          of whether a NOP_EXPR or VIEW_CONVERT_EXPR needs a simple value.  */
    2018                 :     1293370 :       save_val_only = wi->val_only;
    2019                 :     1293370 :       wi->val_only = true;
    2020                 :     1293370 :       wi->is_lhs = false;
    2021                 :     3723295 :       for (; handled_component_p (t); tp = &TREE_OPERAND (t, 0), t = *tp)
    2022                 :             :         {
    2023                 :     2429925 :           if (TREE_CODE (t) == COMPONENT_REF)
    2024                 :     1848974 :             walk_tree (&TREE_OPERAND (t, 2), convert_local_reference_op, wi,
    2025                 :             :                        NULL);
    2026                 :      580951 :           else if (TREE_CODE (t) == ARRAY_REF
    2027                 :      580951 :                    || TREE_CODE (t) == ARRAY_RANGE_REF)
    2028                 :             :             {
    2029                 :      580354 :               walk_tree (&TREE_OPERAND (t, 1), convert_local_reference_op, wi,
    2030                 :             :                          NULL);
    2031                 :      580354 :               walk_tree (&TREE_OPERAND (t, 2), convert_local_reference_op, wi,
    2032                 :             :                          NULL);
    2033                 :      580354 :               walk_tree (&TREE_OPERAND (t, 3), convert_local_reference_op, wi,
    2034                 :             :                          NULL);
    2035                 :             :             }
    2036                 :             :         }
    2037                 :     1293370 :       wi->val_only = false;
    2038                 :     1293370 :       walk_tree (tp, convert_local_reference_op, wi, NULL);
    2039                 :     1293370 :       wi->val_only = save_val_only;
    2040                 :     1293370 :       break;
    2041                 :             : 
    2042                 :      291764 :     case MEM_REF:
    2043                 :      291764 :       save_val_only = wi->val_only;
    2044                 :      291764 :       wi->val_only = true;
    2045                 :      291764 :       wi->is_lhs = false;
    2046                 :      291764 :       walk_tree (&TREE_OPERAND (t, 0), convert_local_reference_op,
    2047                 :             :                  wi, NULL);
    2048                 :             :       /* We need to re-fold the MEM_REF as component references as
    2049                 :             :          part of a ADDR_EXPR address are not allowed.  But we cannot
    2050                 :             :          fold here, as the chain record type is not yet finalized.  */
    2051                 :      291764 :       if (TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR
    2052                 :      291764 :           && !DECL_P (TREE_OPERAND (TREE_OPERAND (t, 0), 0)))
    2053                 :           0 :         info->mem_refs->add (tp);
    2054                 :      291764 :       wi->val_only = save_val_only;
    2055                 :      291764 :       break;
    2056                 :             : 
    2057                 :         778 :     case VIEW_CONVERT_EXPR:
    2058                 :             :       /* Just request to look at the subtrees, leaving val_only and lhs
    2059                 :             :          untouched.  This might actually be for !val_only + lhs, in which
    2060                 :             :          case we don't want to force a replacement by a temporary.  */
    2061                 :         778 :       *walk_subtrees = 1;
    2062                 :         778 :       break;
    2063                 :             : 
    2064                 :     6016248 :     default:
    2065                 :     6016248 :       if (!IS_TYPE_OR_DECL_P (t))
    2066                 :             :         {
    2067                 :     4369200 :           *walk_subtrees = 1;
    2068                 :     4369200 :           wi->val_only = true;
    2069                 :     4369200 :           wi->is_lhs = false;
    2070                 :             :         }
    2071                 :             :       break;
    2072                 :             :     }
    2073                 :             : 
    2074                 :    11157365 :   return NULL_TREE;
    2075                 :             : }
    2076                 :             : 
    2077                 :             : static tree convert_local_reference_stmt (gimple_stmt_iterator *, bool *,
    2078                 :             :                                           struct walk_stmt_info *);
    2079                 :             : 
    2080                 :             : /* Helper for convert_local_reference.  Convert all the references in
    2081                 :             :    the chain of clauses at *PCLAUSES.  WI is as in convert_local_reference.  */
    2082                 :             : 
    2083                 :             : static bool
    2084                 :        4813 : convert_local_omp_clauses (tree *pclauses, struct walk_stmt_info *wi)
    2085                 :             : {
    2086                 :        4813 :   struct nesting_info *const info = (struct nesting_info *) wi->info;
    2087                 :        4813 :   bool need_frame = false, need_stmts = false;
    2088                 :        4813 :   tree clause, decl, *pdecl;
    2089                 :        4813 :   int dummy;
    2090                 :        4813 :   bitmap new_suppress;
    2091                 :             : 
    2092                 :        4813 :   new_suppress = BITMAP_GGC_ALLOC ();
    2093                 :        4813 :   bitmap_copy (new_suppress, info->suppress_expansion);
    2094                 :             : 
    2095                 :       28862 :   for (clause = *pclauses; clause ; clause = OMP_CLAUSE_CHAIN (clause))
    2096                 :             :     {
    2097                 :       24049 :       pdecl = NULL;
    2098                 :       24049 :       switch (OMP_CLAUSE_CODE (clause))
    2099                 :             :         {
    2100                 :         657 :         case OMP_CLAUSE_REDUCTION:
    2101                 :         657 :         case OMP_CLAUSE_IN_REDUCTION:
    2102                 :         657 :         case OMP_CLAUSE_TASK_REDUCTION:
    2103                 :         657 :           if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (clause))
    2104                 :          37 :             need_stmts = true;
    2105                 :         657 :           if (TREE_CODE (OMP_CLAUSE_DECL (clause)) == MEM_REF)
    2106                 :             :             {
    2107                 :           6 :               pdecl = &TREE_OPERAND (OMP_CLAUSE_DECL (clause), 0);
    2108                 :           6 :               if (TREE_CODE (*pdecl) == POINTER_PLUS_EXPR)
    2109                 :           0 :                 pdecl = &TREE_OPERAND (*pdecl, 0);
    2110                 :           6 :               if (INDIRECT_REF_P (*pdecl)
    2111                 :           6 :                   || TREE_CODE (*pdecl) == ADDR_EXPR)
    2112                 :           4 :                 pdecl = &TREE_OPERAND (*pdecl, 0);
    2113                 :             :             }
    2114                 :         657 :           goto do_decl_clause;
    2115                 :             : 
    2116                 :        1152 :         case OMP_CLAUSE_LASTPRIVATE:
    2117                 :        1152 :           if (OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (clause))
    2118                 :         250 :             need_stmts = true;
    2119                 :        1152 :           goto do_decl_clause;
    2120                 :             : 
    2121                 :         391 :         case OMP_CLAUSE_LINEAR:
    2122                 :         391 :           if (OMP_CLAUSE_LINEAR_GIMPLE_SEQ (clause))
    2123                 :          74 :             need_stmts = true;
    2124                 :         391 :           wi->val_only = true;
    2125                 :         391 :           wi->is_lhs = false;
    2126                 :         391 :           convert_local_reference_op (&OMP_CLAUSE_LINEAR_STEP (clause), &dummy,
    2127                 :             :                                       wi);
    2128                 :         391 :           goto do_decl_clause;
    2129                 :             : 
    2130                 :        5627 :         case OMP_CLAUSE_PRIVATE:
    2131                 :        5627 :         case OMP_CLAUSE_FIRSTPRIVATE:
    2132                 :        5627 :         case OMP_CLAUSE_COPYPRIVATE:
    2133                 :        5627 :         case OMP_CLAUSE_SHARED:
    2134                 :        5627 :         case OMP_CLAUSE_ENTER:
    2135                 :        5627 :         case OMP_CLAUSE_LINK:
    2136                 :        5627 :         case OMP_CLAUSE_USE_DEVICE_PTR:
    2137                 :        5627 :         case OMP_CLAUSE_USE_DEVICE_ADDR:
    2138                 :        5627 :         case OMP_CLAUSE_HAS_DEVICE_ADDR:
    2139                 :        5627 :         case OMP_CLAUSE_IS_DEVICE_PTR:
    2140                 :        5627 :         case OMP_CLAUSE_DETACH:
    2141                 :        5627 :         do_decl_clause:
    2142                 :        2200 :           if (pdecl == NULL)
    2143                 :       16577 :             pdecl = &OMP_CLAUSE_DECL (clause);
    2144                 :       16583 :           decl = *pdecl;
    2145                 :       16583 :           if (VAR_P (decl)
    2146                 :       16583 :               && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
    2147                 :             :             break;
    2148                 :       16164 :           if (decl_function_context (decl) == info->context
    2149                 :       16164 :               && !use_pointer_in_frame (decl))
    2150                 :             :             {
    2151                 :       16038 :               tree field = lookup_field_for_decl (info, decl, NO_INSERT);
    2152                 :       16038 :               if (field)
    2153                 :             :                 {
    2154                 :          83 :                   if (OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_SHARED)
    2155                 :          36 :                     OMP_CLAUSE_SHARED_READONLY (clause) = 0;
    2156                 :          83 :                   bitmap_set_bit (new_suppress, DECL_UID (decl));
    2157                 :          83 :                   *pdecl = get_local_debug_decl (info, decl, field);
    2158                 :          83 :                   need_frame = true;
    2159                 :             :                 }
    2160                 :             :             }
    2161                 :             :           break;
    2162                 :             : 
    2163                 :         165 :         case OMP_CLAUSE_SCHEDULE:
    2164                 :         165 :           if (OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clause) == NULL)
    2165                 :             :             break;
    2166                 :             :           /* FALLTHRU */
    2167                 :        2464 :         case OMP_CLAUSE_FINAL:
    2168                 :        2464 :         case OMP_CLAUSE_IF:
    2169                 :        2464 :         case OMP_CLAUSE_SELF:
    2170                 :        2464 :         case OMP_CLAUSE_NUM_THREADS:
    2171                 :        2464 :         case OMP_CLAUSE_DEPEND:
    2172                 :        2464 :         case OMP_CLAUSE_DOACROSS:
    2173                 :        2464 :         case OMP_CLAUSE_DEVICE:
    2174                 :        2464 :         case OMP_CLAUSE_NUM_TEAMS:
    2175                 :        2464 :         case OMP_CLAUSE_THREAD_LIMIT:
    2176                 :        2464 :         case OMP_CLAUSE_SAFELEN:
    2177                 :        2464 :         case OMP_CLAUSE_SIMDLEN:
    2178                 :        2464 :         case OMP_CLAUSE_PRIORITY:
    2179                 :        2464 :         case OMP_CLAUSE_GRAINSIZE:
    2180                 :        2464 :         case OMP_CLAUSE_NUM_TASKS:
    2181                 :        2464 :         case OMP_CLAUSE_HINT:
    2182                 :        2464 :         case OMP_CLAUSE_FILTER:
    2183                 :        2464 :         case OMP_CLAUSE_NUM_GANGS:
    2184                 :        2464 :         case OMP_CLAUSE_NUM_WORKERS:
    2185                 :        2464 :         case OMP_CLAUSE_VECTOR_LENGTH:
    2186                 :        2464 :         case OMP_CLAUSE_GANG:
    2187                 :        2464 :         case OMP_CLAUSE_WORKER:
    2188                 :        2464 :         case OMP_CLAUSE_VECTOR:
    2189                 :        2464 :         case OMP_CLAUSE_ASYNC:
    2190                 :        2464 :         case OMP_CLAUSE_WAIT:
    2191                 :             :           /* Several OpenACC clauses have optional arguments.  Check if they
    2192                 :             :              are present.  */
    2193                 :        2464 :           if (OMP_CLAUSE_OPERAND (clause, 0))
    2194                 :             :             {
    2195                 :        2208 :               wi->val_only = true;
    2196                 :        2208 :               wi->is_lhs = false;
    2197                 :        2208 :               convert_local_reference_op (&OMP_CLAUSE_OPERAND (clause, 0),
    2198                 :             :                                           &dummy, wi);
    2199                 :             :             }
    2200                 :             : 
    2201                 :             :           /* The gang clause accepts two arguments.  */
    2202                 :        2464 :           if (OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_GANG
    2203                 :        2464 :               && OMP_CLAUSE_GANG_STATIC_EXPR (clause))
    2204                 :             :             {
    2205                 :          28 :                 wi->val_only = true;
    2206                 :          28 :                 wi->is_lhs = false;
    2207                 :          28 :                 convert_nonlocal_reference_op
    2208                 :          28 :                   (&OMP_CLAUSE_GANG_STATIC_EXPR (clause), &dummy, wi);
    2209                 :             :             }
    2210                 :             :           break;
    2211                 :             : 
    2212                 :           7 :         case OMP_CLAUSE_DIST_SCHEDULE:
    2213                 :           7 :           if (OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (clause) != NULL)
    2214                 :             :             {
    2215                 :           7 :               wi->val_only = true;
    2216                 :           7 :               wi->is_lhs = false;
    2217                 :           7 :               convert_local_reference_op (&OMP_CLAUSE_OPERAND (clause, 0),
    2218                 :             :                                           &dummy, wi);
    2219                 :             :             }
    2220                 :             :           break;
    2221                 :             : 
    2222                 :        7288 :         case OMP_CLAUSE_MAP:
    2223                 :        7288 :         case OMP_CLAUSE_TO:
    2224                 :        7288 :         case OMP_CLAUSE_FROM:
    2225                 :        7288 :           if (OMP_CLAUSE_SIZE (clause))
    2226                 :             :             {
    2227                 :        7288 :               wi->val_only = true;
    2228                 :        7288 :               wi->is_lhs = false;
    2229                 :        7288 :               convert_local_reference_op (&OMP_CLAUSE_SIZE (clause),
    2230                 :             :                                           &dummy, wi);
    2231                 :             :             }
    2232                 :        7288 :           if (DECL_P (OMP_CLAUSE_DECL (clause)))
    2233                 :        3427 :             goto do_decl_clause;
    2234                 :        3861 :           wi->val_only = true;
    2235                 :        3861 :           wi->is_lhs = false;
    2236                 :        3861 :           walk_tree (&OMP_CLAUSE_DECL (clause), convert_local_reference_op,
    2237                 :             :                      wi, NULL);
    2238                 :        3861 :           break;
    2239                 :             : 
    2240                 :           6 :         case OMP_CLAUSE_ALIGNED:
    2241                 :           6 :           if (OMP_CLAUSE_ALIGNED_ALIGNMENT (clause))
    2242                 :             :             {
    2243                 :           6 :               wi->val_only = true;
    2244                 :           6 :               wi->is_lhs = false;
    2245                 :           6 :               convert_local_reference_op
    2246                 :           6 :                 (&OMP_CLAUSE_ALIGNED_ALIGNMENT (clause), &dummy, wi);
    2247                 :             :             }
    2248                 :             :           /* FALLTHRU */
    2249                 :           6 :         case OMP_CLAUSE_NONTEMPORAL:
    2250                 :           0 :         do_decl_clause_no_supp:
    2251                 :             :           /* Like do_decl_clause, but don't add any suppression.  */
    2252                 :           6 :           decl = OMP_CLAUSE_DECL (clause);
    2253                 :           6 :           if (VAR_P (decl)
    2254                 :           6 :               && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
    2255                 :             :             break;
    2256                 :           6 :           if (decl_function_context (decl) == info->context
    2257                 :           6 :               && !use_pointer_in_frame (decl))
    2258                 :             :             {
    2259                 :           6 :               tree field = lookup_field_for_decl (info, decl, NO_INSERT);
    2260                 :           6 :               if (field)
    2261                 :             :                 {
    2262                 :           0 :                   OMP_CLAUSE_DECL (clause)
    2263                 :           0 :                     = get_local_debug_decl (info, decl, field);
    2264                 :           0 :                   need_frame = true;
    2265                 :             :                 }
    2266                 :             :             }
    2267                 :             :           break;
    2268                 :             : 
    2269                 :           0 :         case OMP_CLAUSE_ALLOCATE:
    2270                 :           0 :           if (OMP_CLAUSE_ALLOCATE_ALLOCATOR (clause))
    2271                 :             :             {
    2272                 :           0 :               wi->val_only = true;
    2273                 :           0 :               wi->is_lhs = false;
    2274                 :           0 :               convert_local_reference_op
    2275                 :           0 :                 (&OMP_CLAUSE_ALLOCATE_ALLOCATOR (clause), &dummy, wi);
    2276                 :             :             }
    2277                 :           0 :           goto do_decl_clause_no_supp;
    2278                 :             : 
    2279                 :             :         case OMP_CLAUSE_NOWAIT:
    2280                 :             :         case OMP_CLAUSE_ORDERED:
    2281                 :             :         case OMP_CLAUSE_DEFAULT:
    2282                 :             :         case OMP_CLAUSE_COPYIN:
    2283                 :             :         case OMP_CLAUSE_COLLAPSE:
    2284                 :             :         case OMP_CLAUSE_TILE:
    2285                 :             :         case OMP_CLAUSE_UNTIED:
    2286                 :             :         case OMP_CLAUSE_MERGEABLE:
    2287                 :             :         case OMP_CLAUSE_PROC_BIND:
    2288                 :             :         case OMP_CLAUSE_NOGROUP:
    2289                 :             :         case OMP_CLAUSE_THREADS:
    2290                 :             :         case OMP_CLAUSE_SIMD:
    2291                 :             :         case OMP_CLAUSE_DEFAULTMAP:
    2292                 :             :         case OMP_CLAUSE_ORDER:
    2293                 :             :         case OMP_CLAUSE_SEQ:
    2294                 :             :         case OMP_CLAUSE_INDEPENDENT:
    2295                 :             :         case OMP_CLAUSE_AUTO:
    2296                 :             :         case OMP_CLAUSE_IF_PRESENT:
    2297                 :             :         case OMP_CLAUSE_FINALIZE:
    2298                 :             :         case OMP_CLAUSE_BIND:
    2299                 :             :         case OMP_CLAUSE__CONDTEMP_:
    2300                 :             :         case OMP_CLAUSE__SCANTEMP_:
    2301                 :             :           break;
    2302                 :             : 
    2303                 :             :           /* The following clause belongs to the OpenACC cache directive, which
    2304                 :             :              is discarded during gimplification.  */
    2305                 :           0 :         case OMP_CLAUSE__CACHE_:
    2306                 :             :           /* The following clauses are only allowed in the OpenMP declare simd
    2307                 :             :              directive, so not seen here.  */
    2308                 :           0 :         case OMP_CLAUSE_UNIFORM:
    2309                 :           0 :         case OMP_CLAUSE_INBRANCH:
    2310                 :           0 :         case OMP_CLAUSE_NOTINBRANCH:
    2311                 :             :           /* The following clauses are only allowed on OpenMP cancel and
    2312                 :             :              cancellation point directives, which at this point have already
    2313                 :             :              been lowered into a function call.  */
    2314                 :           0 :         case OMP_CLAUSE_FOR:
    2315                 :           0 :         case OMP_CLAUSE_PARALLEL:
    2316                 :           0 :         case OMP_CLAUSE_SECTIONS:
    2317                 :           0 :         case OMP_CLAUSE_TASKGROUP:
    2318                 :             :           /* The following clauses are only added during OMP lowering; nested
    2319                 :             :              function decomposition happens before that.  */
    2320                 :           0 :         case OMP_CLAUSE__LOOPTEMP_:
    2321                 :           0 :         case OMP_CLAUSE__REDUCTEMP_:
    2322                 :           0 :         case OMP_CLAUSE__SIMDUID_:
    2323                 :           0 :         case OMP_CLAUSE__SIMT_:
    2324                 :             :           /* The following clauses are only allowed on OpenACC 'routine'
    2325                 :             :              directives, not seen here.  */
    2326                 :           0 :         case OMP_CLAUSE_NOHOST:
    2327                 :             :           /* Anything else.  */
    2328                 :           0 :         default:
    2329                 :           0 :           gcc_unreachable ();
    2330                 :             :         }
    2331                 :             :     }
    2332                 :             : 
    2333                 :        4813 :   info->suppress_expansion = new_suppress;
    2334                 :             : 
    2335                 :        4813 :   if (need_stmts)
    2336                 :        1547 :     for (clause = *pclauses; clause ; clause = OMP_CLAUSE_CHAIN (clause))
    2337                 :        1262 :       switch (OMP_CLAUSE_CODE (clause))
    2338                 :             :         {
    2339                 :         103 :         case OMP_CLAUSE_REDUCTION:
    2340                 :         103 :         case OMP_CLAUSE_IN_REDUCTION:
    2341                 :         103 :         case OMP_CLAUSE_TASK_REDUCTION:
    2342                 :         103 :           if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (clause))
    2343                 :             :             {
    2344                 :          37 :               tree old_context
    2345                 :          37 :                 = DECL_CONTEXT (OMP_CLAUSE_REDUCTION_PLACEHOLDER (clause));
    2346                 :          37 :               DECL_CONTEXT (OMP_CLAUSE_REDUCTION_PLACEHOLDER (clause))
    2347                 :          37 :                 = info->context;
    2348                 :          37 :               if (OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (clause))
    2349                 :           0 :                 DECL_CONTEXT (OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (clause))
    2350                 :           0 :                   = info->context;
    2351                 :          37 :               walk_body (convert_local_reference_stmt,
    2352                 :             :                          convert_local_reference_op, info,
    2353                 :          37 :                          &OMP_CLAUSE_REDUCTION_GIMPLE_INIT (clause));
    2354                 :          37 :               walk_body (convert_local_reference_stmt,
    2355                 :             :                          convert_local_reference_op, info,
    2356                 :          37 :                          &OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (clause));
    2357                 :          37 :               DECL_CONTEXT (OMP_CLAUSE_REDUCTION_PLACEHOLDER (clause))
    2358                 :          37 :                 = old_context;
    2359                 :          37 :               if (OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (clause))
    2360                 :           0 :                 DECL_CONTEXT (OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (clause))
    2361                 :           0 :                   = old_context;
    2362                 :             :             }
    2363                 :             :           break;
    2364                 :             : 
    2365                 :         410 :         case OMP_CLAUSE_LASTPRIVATE:
    2366                 :         410 :           walk_body (convert_local_reference_stmt,
    2367                 :             :                      convert_local_reference_op, info,
    2368                 :         410 :                      &OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (clause));
    2369                 :         410 :           break;
    2370                 :             : 
    2371                 :         215 :         case OMP_CLAUSE_LINEAR:
    2372                 :         215 :           walk_body (convert_local_reference_stmt,
    2373                 :             :                      convert_local_reference_op, info,
    2374                 :         215 :                      &OMP_CLAUSE_LINEAR_GIMPLE_SEQ (clause));
    2375                 :         215 :           break;
    2376                 :             : 
    2377                 :             :         default:
    2378                 :             :           break;
    2379                 :             :         }
    2380                 :             : 
    2381                 :        4813 :   return need_frame;
    2382                 :             : }
    2383                 :             : 
    2384                 :             : 
    2385                 :             : /* Called via walk_function+walk_gimple_stmt, rewrite all references to VAR
    2386                 :             :    and PARM_DECLs that were referenced by inner nested functions.
    2387                 :             :    The rewrite will be a structure reference to the local frame variable.  */
    2388                 :             : 
    2389                 :             : static tree
    2390                 :     4118891 : convert_local_reference_stmt (gimple_stmt_iterator *gsi, bool *handled_ops_p,
    2391                 :             :                               struct walk_stmt_info *wi)
    2392                 :             : {
    2393                 :     4118891 :   struct nesting_info *info = (struct nesting_info *) wi->info;
    2394                 :     4118891 :   tree save_local_var_chain;
    2395                 :     4118891 :   bitmap save_suppress;
    2396                 :     4118891 :   char save_static_chain_added;
    2397                 :     4118891 :   bool frame_decl_added;
    2398                 :     4118891 :   gimple *stmt = gsi_stmt (*gsi);
    2399                 :             : 
    2400                 :     4118891 :   switch (gimple_code (stmt))
    2401                 :             :     {
    2402                 :          38 :     case GIMPLE_OMP_TEAMS:
    2403                 :          38 :       if (!gimple_omp_teams_host (as_a <gomp_teams *> (stmt)))
    2404                 :             :         {
    2405                 :          26 :           save_suppress = info->suppress_expansion;
    2406                 :          26 :           convert_local_omp_clauses (gimple_omp_teams_clauses_ptr (stmt), wi);
    2407                 :          26 :           walk_body (convert_local_reference_stmt, convert_local_reference_op,
    2408                 :             :                      info, gimple_omp_body_ptr (stmt));
    2409                 :          26 :           info->suppress_expansion = save_suppress;
    2410                 :          26 :           break;
    2411                 :             :         }
    2412                 :             :       /* FALLTHRU */
    2413                 :             : 
    2414                 :        1302 :     case GIMPLE_OMP_PARALLEL:
    2415                 :        1302 :     case GIMPLE_OMP_TASK:
    2416                 :        1302 :       save_suppress = info->suppress_expansion;
    2417                 :        1302 :       frame_decl_added = false;
    2418                 :        1302 :       if (convert_local_omp_clauses (gimple_omp_taskreg_clauses_ptr (stmt),
    2419                 :             :                                      wi))
    2420                 :             :         {
    2421                 :          39 :           tree c = build_omp_clause (gimple_location (stmt),
    2422                 :             :                                      OMP_CLAUSE_SHARED);
    2423                 :          39 :           (void) get_frame_type (info);
    2424                 :          39 :           OMP_CLAUSE_DECL (c) = info->frame_decl;
    2425                 :          39 :           OMP_CLAUSE_CHAIN (c) = gimple_omp_taskreg_clauses (stmt);
    2426                 :          39 :           gimple_omp_taskreg_set_clauses (stmt, c);
    2427                 :          39 :           info->static_chain_added |= 4;
    2428                 :          39 :           frame_decl_added = true;
    2429                 :             :         }
    2430                 :             : 
    2431                 :        1302 :       save_local_var_chain = info->new_local_var_chain;
    2432                 :        1302 :       save_static_chain_added = info->static_chain_added;
    2433                 :        1302 :       info->new_local_var_chain = NULL;
    2434                 :        1302 :       info->static_chain_added = 0;
    2435                 :             : 
    2436                 :        1302 :       walk_body (convert_local_reference_stmt, convert_local_reference_op, info,
    2437                 :             :                  gimple_omp_body_ptr (stmt));
    2438                 :             : 
    2439                 :        1302 :       if ((info->static_chain_added & 4) != 0 && !frame_decl_added)
    2440                 :             :         {
    2441                 :           1 :           tree c = build_omp_clause (gimple_location (stmt),
    2442                 :             :                                      OMP_CLAUSE_SHARED);
    2443                 :           1 :           (void) get_frame_type (info);
    2444                 :           1 :           OMP_CLAUSE_DECL (c) = info->frame_decl;
    2445                 :           1 :           OMP_CLAUSE_CHAIN (c) = gimple_omp_taskreg_clauses (stmt);
    2446                 :           1 :           info->static_chain_added |= 4;
    2447                 :           1 :           gimple_omp_taskreg_set_clauses (stmt, c);
    2448                 :             :         }
    2449                 :        1302 :       if (info->new_local_var_chain)
    2450                 :          18 :         declare_vars (info->new_local_var_chain,
    2451                 :             :                       gimple_seq_first_stmt (gimple_omp_body (stmt)), false);
    2452                 :        1302 :       info->new_local_var_chain = save_local_var_chain;
    2453                 :        1302 :       info->suppress_expansion = save_suppress;
    2454                 :        1302 :       info->static_chain_added |= save_static_chain_added;
    2455                 :        1302 :       break;
    2456                 :             : 
    2457                 :        1476 :     case GIMPLE_OMP_FOR:
    2458                 :        1476 :       save_suppress = info->suppress_expansion;
    2459                 :        1476 :       convert_local_omp_clauses (gimple_omp_for_clauses_ptr (stmt), wi);
    2460                 :        1476 :       walk_gimple_omp_for (as_a <gomp_for *> (stmt),
    2461                 :             :                            convert_local_reference_stmt,
    2462                 :             :                            convert_local_reference_op, info);
    2463                 :        1476 :       walk_body (convert_local_reference_stmt, convert_local_reference_op,
    2464                 :             :                  info, gimple_omp_body_ptr (stmt));
    2465                 :        1476 :       info->suppress_expansion = save_suppress;
    2466                 :        1476 :       break;
    2467                 :             : 
    2468                 :          42 :     case GIMPLE_OMP_SECTIONS:
    2469                 :          42 :       save_suppress = info->suppress_expansion;
    2470                 :          42 :       convert_local_omp_clauses (gimple_omp_sections_clauses_ptr (stmt), wi);
    2471                 :          42 :       walk_body (convert_local_reference_stmt, convert_local_reference_op,
    2472                 :             :                  info, gimple_omp_body_ptr (stmt));
    2473                 :          42 :       info->suppress_expansion = save_suppress;
    2474                 :          42 :       break;
    2475                 :             : 
    2476                 :         185 :     case GIMPLE_OMP_SINGLE:
    2477                 :         185 :       save_suppress = info->suppress_expansion;
    2478                 :         185 :       convert_local_omp_clauses (gimple_omp_single_clauses_ptr (stmt), wi);
    2479                 :         185 :       walk_body (convert_local_reference_stmt, convert_local_reference_op,
    2480                 :             :                  info, gimple_omp_body_ptr (stmt));
    2481                 :         185 :       info->suppress_expansion = save_suppress;
    2482                 :         185 :       break;
    2483                 :             : 
    2484                 :           0 :     case GIMPLE_OMP_SCOPE:
    2485                 :           0 :       save_suppress = info->suppress_expansion;
    2486                 :           0 :       convert_local_omp_clauses (gimple_omp_scope_clauses_ptr (stmt), wi);
    2487                 :           0 :       walk_body (convert_local_reference_stmt, convert_local_reference_op,
    2488                 :             :                  info, gimple_omp_body_ptr (stmt));
    2489                 :           0 :       info->suppress_expansion = save_suppress;
    2490                 :           0 :       break;
    2491                 :             : 
    2492                 :          38 :     case GIMPLE_OMP_TASKGROUP:
    2493                 :          38 :       save_suppress = info->suppress_expansion;
    2494                 :          38 :       convert_local_omp_clauses (gimple_omp_taskgroup_clauses_ptr (stmt), wi);
    2495                 :          38 :       walk_body (convert_local_reference_stmt, convert_local_reference_op,
    2496                 :             :                  info, gimple_omp_body_ptr (stmt));
    2497                 :          38 :       info->suppress_expansion = save_suppress;
    2498                 :          38 :       break;
    2499                 :             : 
    2500                 :        1744 :     case GIMPLE_OMP_TARGET:
    2501                 :        1744 :       if (!is_gimple_omp_offloaded (stmt))
    2502                 :             :         {
    2503                 :         646 :           save_suppress = info->suppress_expansion;
    2504                 :         646 :           convert_local_omp_clauses (gimple_omp_target_clauses_ptr (stmt), wi);
    2505                 :         646 :           info->suppress_expansion = save_suppress;
    2506                 :         646 :           walk_body (convert_local_reference_stmt, convert_local_reference_op,
    2507                 :             :                      info, gimple_omp_body_ptr (stmt));
    2508                 :         646 :           break;
    2509                 :             :         }
    2510                 :        1098 :       save_suppress = info->suppress_expansion;
    2511                 :        1098 :       frame_decl_added = false;
    2512                 :        1098 :       if (convert_local_omp_clauses (gimple_omp_target_clauses_ptr (stmt), wi))
    2513                 :             :         {
    2514                 :           0 :           tree c = build_omp_clause (gimple_location (stmt), OMP_CLAUSE_MAP);
    2515                 :           0 :           (void) get_frame_type (info);
    2516                 :           0 :           OMP_CLAUSE_DECL (c) = info->frame_decl;
    2517                 :           0 :           OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TOFROM);
    2518                 :           0 :           OMP_CLAUSE_SIZE (c) = DECL_SIZE_UNIT (info->frame_decl);
    2519                 :           0 :           OMP_CLAUSE_CHAIN (c) = gimple_omp_target_clauses (stmt);
    2520                 :           0 :           gimple_omp_target_set_clauses (as_a <gomp_target *> (stmt), c);
    2521                 :           0 :           info->static_chain_added |= 4;
    2522                 :           0 :           frame_decl_added = true;
    2523                 :             :         }
    2524                 :             : 
    2525                 :        1098 :       save_local_var_chain = info->new_local_var_chain;
    2526                 :        1098 :       save_static_chain_added = info->static_chain_added;
    2527                 :        1098 :       info->new_local_var_chain = NULL;
    2528                 :        1098 :       info->static_chain_added = 0;
    2529                 :             : 
    2530                 :        1098 :       walk_body (convert_local_reference_stmt, convert_local_reference_op, info,
    2531                 :             :                  gimple_omp_body_ptr (stmt));
    2532                 :             : 
    2533                 :        1098 :       if ((info->static_chain_added & 4) != 0 && !frame_decl_added)
    2534                 :             :         {
    2535                 :           0 :           tree c = build_omp_clause (gimple_location (stmt), OMP_CLAUSE_MAP);
    2536                 :           0 :           (void) get_frame_type (info);
    2537                 :           0 :           OMP_CLAUSE_DECL (c) = info->frame_decl;
    2538                 :           0 :           OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TOFROM);
    2539                 :           0 :           OMP_CLAUSE_SIZE (c) = DECL_SIZE_UNIT (info->frame_decl);
    2540                 :           0 :           OMP_CLAUSE_CHAIN (c) = gimple_omp_target_clauses (stmt);
    2541                 :           0 :           gimple_omp_target_set_clauses (as_a <gomp_target *> (stmt), c);
    2542                 :           0 :           info->static_chain_added |= 4;
    2543                 :             :         }
    2544                 :             : 
    2545                 :        1098 :       if (info->new_local_var_chain)
    2546                 :           1 :         declare_vars (info->new_local_var_chain,
    2547                 :             :                       gimple_seq_first_stmt (gimple_omp_body (stmt)), false);
    2548                 :        1098 :       info->new_local_var_chain = save_local_var_chain;
    2549                 :        1098 :       info->suppress_expansion = save_suppress;
    2550                 :        1098 :       info->static_chain_added |= save_static_chain_added;
    2551                 :        1098 :       break;
    2552                 :             : 
    2553                 :         552 :     case GIMPLE_OMP_SECTION:
    2554                 :         552 :     case GIMPLE_OMP_STRUCTURED_BLOCK:
    2555                 :         552 :     case GIMPLE_OMP_MASTER:
    2556                 :         552 :     case GIMPLE_OMP_MASKED:
    2557                 :         552 :     case GIMPLE_OMP_ORDERED:
    2558                 :         552 :     case GIMPLE_OMP_SCAN:
    2559                 :         552 :       walk_body (convert_local_reference_stmt, convert_local_reference_op,
    2560                 :             :                  info, gimple_omp_body_ptr (stmt));
    2561                 :         552 :       break;
    2562                 :             : 
    2563                 :      243611 :     case GIMPLE_COND:
    2564                 :      243611 :       wi->val_only = true;
    2565                 :      243611 :       wi->is_lhs = false;
    2566                 :      243611 :       *handled_ops_p = false;
    2567                 :      243611 :       return NULL_TREE;
    2568                 :             : 
    2569                 :     2471515 :     case GIMPLE_ASSIGN:
    2570                 :     2471515 :       if (gimple_clobber_p (stmt))
    2571                 :             :         {
    2572                 :       99508 :           tree lhs = gimple_assign_lhs (stmt);
    2573                 :       99508 :           if (DECL_P (lhs)
    2574                 :       99474 :               && decl_function_context (lhs) == info->context
    2575                 :       99472 :               && !use_pointer_in_frame (lhs)
    2576                 :      198980 :               && lookup_field_for_decl (info, lhs, NO_INSERT))
    2577                 :             :             {
    2578                 :        1509 :               gsi_replace (gsi, gimple_build_nop (), true);
    2579                 :        1509 :               break;
    2580                 :             :             }
    2581                 :             :         }
    2582                 :     2470006 :       *handled_ops_p = false;
    2583                 :     2470006 :       return NULL_TREE;
    2584                 :             : 
    2585                 :      191860 :     case GIMPLE_BIND:
    2586                 :      191860 :       for (tree var = gimple_bind_vars (as_a <gbind *> (stmt));
    2587                 :      857753 :            var;
    2588                 :      665893 :            var = DECL_CHAIN (var))
    2589                 :      665893 :         if (TREE_CODE (var) == NAMELIST_DECL)
    2590                 :             :           {
    2591                 :             :             /* Adjust decls mentioned in NAMELIST_DECL.  */
    2592                 :         131 :             tree decls = NAMELIST_DECL_ASSOCIATED_DECL (var);
    2593                 :         131 :             tree decl;
    2594                 :         131 :             unsigned int i;
    2595                 :             : 
    2596                 :      666570 :             FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (decls), i, decl)
    2597                 :             :               {
    2598                 :         771 :                 if (VAR_P (decl)
    2599                 :         677 :                     && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
    2600                 :          94 :                   continue;
    2601                 :         583 :                 if (decl_function_context (decl) == info->context
    2602                 :         583 :                     && !use_pointer_in_frame (decl))
    2603                 :             :                   {
    2604                 :         583 :                     tree field = lookup_field_for_decl (info, decl, NO_INSERT);
    2605                 :         583 :                     if (field)
    2606                 :             :                       {
    2607                 :           2 :                         CONSTRUCTOR_ELT (decls, i)->value
    2608                 :           4 :                           = get_local_debug_decl (info, decl, field);
    2609                 :             :                       }
    2610                 :             :                   }
    2611                 :             :               }
    2612                 :             :           }
    2613                 :             : 
    2614                 :      191860 :       *handled_ops_p = false;
    2615                 :      191860 :       return NULL_TREE;
    2616                 :             : 
    2617                 :     1206540 :     default:
    2618                 :             :       /* For every other statement that we are not interested in
    2619                 :             :          handling here, let the walker traverse the operands.  */
    2620                 :     1206540 :       *handled_ops_p = false;
    2621                 :     1206540 :       return NULL_TREE;
    2622                 :             :     }
    2623                 :             : 
    2624                 :             :   /* Indicate that we have handled all the operands ourselves.  */
    2625                 :        6874 :   *handled_ops_p = true;
    2626                 :        6874 :   return NULL_TREE;
    2627                 :             : }
    2628                 :             : 
    2629                 :             : 
    2630                 :             : /* Called via walk_function+walk_gimple_stmt, rewrite all GIMPLE_GOTOs
    2631                 :             :    that reference labels from outer functions.  The rewrite will be a
    2632                 :             :    call to __builtin_nonlocal_goto.  */
    2633                 :             : 
    2634                 :             : static tree
    2635                 :     4121361 : convert_nl_goto_reference (gimple_stmt_iterator *gsi, bool *handled_ops_p,
    2636                 :             :                            struct walk_stmt_info *wi)
    2637                 :             : {
    2638                 :     4121361 :   struct nesting_info *const info = (struct nesting_info *) wi->info, *i;
    2639                 :     4121361 :   tree label, new_label, target_context, x, field;
    2640                 :     4121361 :   gcall *call;
    2641                 :     4121361 :   gimple *stmt = gsi_stmt (*gsi);
    2642                 :             : 
    2643                 :     4121361 :   if (gimple_code (stmt) != GIMPLE_GOTO)
    2644                 :             :     {
    2645                 :     3970287 :       *handled_ops_p = false;
    2646                 :     3970287 :       return NULL_TREE;
    2647                 :             :     }
    2648                 :             : 
    2649                 :      151074 :   label = gimple_goto_dest (stmt);
    2650                 :      151074 :   if (TREE_CODE (label) != LABEL_DECL)
    2651                 :             :     {
    2652                 :          75 :       *handled_ops_p = false;
    2653                 :          75 :       return NULL_TREE;
    2654                 :             :     }
    2655                 :             : 
    2656                 :      150999 :   target_context = decl_function_context (label);
    2657                 :      150999 :   if (target_context == info->context)
    2658                 :             :     {
    2659                 :      150480 :       *handled_ops_p = false;
    2660                 :      150480 :       return NULL_TREE;
    2661                 :             :     }
    2662                 :             : 
    2663                 :         519 :   for (i = info->outer; target_context != i->context; i = i->outer)
    2664                 :           0 :     continue;
    2665                 :             : 
    2666                 :             :   /* The original user label may also be use for a normal goto, therefore
    2667                 :             :      we must create a new label that will actually receive the abnormal
    2668                 :             :      control transfer.  This new label will be marked LABEL_NONLOCAL; this
    2669                 :             :      mark will trigger proper behavior in the cfg, as well as cause the
    2670                 :             :      (hairy target-specific) non-local goto receiver code to be generated
    2671                 :             :      when we expand rtl.  Enter this association into var_map so that we
    2672                 :             :      can insert the new label into the IL during a second pass.  */
    2673                 :         519 :   tree *slot = &i->var_map->get_or_insert (label);
    2674                 :         519 :   if (*slot == NULL)
    2675                 :             :     {
    2676                 :         476 :       new_label = create_artificial_label (UNKNOWN_LOCATION);
    2677                 :         476 :       DECL_NONLOCAL (new_label) = 1;
    2678                 :         476 :       *slot = new_label;
    2679                 :             :     }
    2680                 :             :   else
    2681                 :             :     new_label = *slot;
    2682                 :             : 
    2683                 :             :   /* Build: __builtin_nl_goto(new_label, &chain->nl_goto_field).  */
    2684                 :         519 :   field = get_nl_goto_field (i);
    2685                 :         519 :   x = get_frame_field (info, target_context, field, gsi);
    2686                 :         519 :   x = build_addr (x);
    2687                 :         519 :   x = gsi_gimplify_val (info, x, gsi);
    2688                 :        1038 :   call = gimple_build_call (builtin_decl_implicit (BUILT_IN_NONLOCAL_GOTO),
    2689                 :             :                             2, build_addr (new_label), x);
    2690                 :         519 :   gsi_replace (gsi, call, false);
    2691                 :             : 
    2692                 :             :   /* We have handled all of STMT's operands, no need to keep going.  */
    2693                 :         519 :   *handled_ops_p = true;
    2694                 :         519 :   return NULL_TREE;
    2695                 :           0 : }
    2696                 :             : 
    2697                 :             : 
    2698                 :             : /* Called via walk_function+walk_tree, rewrite all GIMPLE_LABELs whose labels
    2699                 :             :    are referenced via nonlocal goto from a nested function.  The rewrite
    2700                 :             :    will involve installing a newly generated DECL_NONLOCAL label, and
    2701                 :             :    (potentially) a branch around the rtl gunk that is assumed to be
    2702                 :             :    attached to such a label.  */
    2703                 :             : 
    2704                 :             : static tree
    2705                 :     4121880 : convert_nl_goto_receiver (gimple_stmt_iterator *gsi, bool *handled_ops_p,
    2706                 :             :                           struct walk_stmt_info *wi)
    2707                 :             : {
    2708                 :     4121880 :   struct nesting_info *const info = (struct nesting_info *) wi->info;
    2709                 :     4121880 :   tree label, new_label;
    2710                 :     4121880 :   gimple_stmt_iterator tmp_gsi;
    2711                 :     4121880 :   glabel *stmt = dyn_cast <glabel *> (gsi_stmt (*gsi));
    2712                 :             : 
    2713                 :     4121880 :   if (!stmt)
    2714                 :             :     {
    2715                 :     3414453 :       *handled_ops_p = false;
    2716                 :     3414453 :       return NULL_TREE;
    2717                 :             :     }
    2718                 :             : 
    2719                 :      707427 :   label = gimple_label_label (stmt);
    2720                 :             : 
    2721                 :      707427 :   tree *slot = info->var_map->get (label);
    2722                 :      707427 :   if (!slot)
    2723                 :             :     {
    2724                 :      706951 :       *handled_ops_p = false;
    2725                 :      706951 :       return NULL_TREE;
    2726                 :             :     }
    2727                 :             : 
    2728                 :             :   /* If there's any possibility that the previous statement falls through,
    2729                 :             :      then we must branch around the new non-local label.  */
    2730                 :         476 :   tmp_gsi = wi->gsi;
    2731                 :         476 :   gsi_prev (&tmp_gsi);
    2732                 :         476 :   if (gsi_end_p (tmp_gsi) || gimple_stmt_may_fallthru (gsi_stmt (tmp_gsi)))
    2733                 :             :     {
    2734                 :         265 :       gimple *stmt = gimple_build_goto (label);
    2735                 :         265 :       gsi_insert_before (gsi, stmt, GSI_SAME_STMT);
    2736                 :             :     }
    2737                 :             : 
    2738                 :         476 :   new_label = (tree) *slot;
    2739                 :         476 :   stmt = gimple_build_label (new_label);
    2740                 :         476 :   gsi_insert_before (gsi, stmt, GSI_SAME_STMT);
    2741                 :             : 
    2742                 :         476 :   *handled_ops_p = true;
    2743                 :         476 :   return NULL_TREE;
    2744                 :             : }
    2745                 :             : 
    2746                 :             : 
    2747                 :             : /* Called via walk_function+walk_stmt, rewrite all references to addresses
    2748                 :             :    of nested functions that require the use of trampolines.  The rewrite
    2749                 :             :    will involve a reference a trampoline generated for the occasion.  */
    2750                 :             : 
    2751                 :             : static tree
    2752                 :    13341296 : convert_tramp_reference_op (tree *tp, int *walk_subtrees, void *data)
    2753                 :             : {
    2754                 :    13341296 :   struct walk_stmt_info *wi = (struct walk_stmt_info *) data;
    2755                 :    13341296 :   struct nesting_info *const info = (struct nesting_info *) wi->info, *i;
    2756                 :    13341296 :   tree t = *tp, decl, target_context, x, builtin;
    2757                 :    13341296 :   bool descr;
    2758                 :    13341296 :   gcall *call;
    2759                 :             : 
    2760                 :    13341296 :   *walk_subtrees = 0;
    2761                 :    13341296 :   switch (TREE_CODE (t))
    2762                 :             :     {
    2763                 :      317222 :     case ADDR_EXPR:
    2764                 :             :       /* Build
    2765                 :             :            T.1 = &CHAIN->tramp;
    2766                 :             :            T.2 = __builtin_adjust_trampoline (T.1);
    2767                 :             :            T.3 = (func_type)T.2;
    2768                 :             :       */
    2769                 :             : 
    2770                 :      317222 :       decl = TREE_OPERAND (t, 0);
    2771                 :      317222 :       if (TREE_CODE (decl) != FUNCTION_DECL)
    2772                 :             :         break;
    2773                 :             : 
    2774                 :             :       /* Only need to process nested functions.  */
    2775                 :         855 :       target_context = decl_function_context (decl);
    2776                 :         855 :       if (!target_context)
    2777                 :             :         break;
    2778                 :             : 
    2779                 :             :       /* If the nested function doesn't use a static chain, then
    2780                 :             :          it doesn't need a trampoline.  */
    2781                 :         603 :       if (!DECL_STATIC_CHAIN (decl))
    2782                 :             :         break;
    2783                 :             : 
    2784                 :             :       /* If we don't want a trampoline, then don't build one.  */
    2785                 :         281 :       if (TREE_NO_TRAMPOLINE (t))
    2786                 :             :         break;
    2787                 :             : 
    2788                 :             :       /* Lookup the immediate parent of the callee, as that's where
    2789                 :             :          we need to insert the trampoline.  */
    2790                 :         306 :       for (i = info; i->context != target_context; i = i->outer)
    2791                 :          25 :         continue;
    2792                 :             : 
    2793                 :             :       /* Decide whether to generate a descriptor or a trampoline. */
    2794                 :         281 :       descr = FUNC_ADDR_BY_DESCRIPTOR (t) && !flag_trampolines;
    2795                 :             : 
    2796                 :         281 :       if (descr)
    2797                 :           0 :         x = lookup_descr_for_decl (i, decl, INSERT);
    2798                 :             :       else
    2799                 :         281 :         x = lookup_tramp_for_decl (i, decl, INSERT);
    2800                 :             : 
    2801                 :             :       /* Compute the address of the field holding the trampoline.  */
    2802                 :         281 :       x = get_frame_field (info, target_context, x, &wi->gsi);
    2803                 :             : 
    2804                 :             :       /* APB: We don't need to do the adjustment calls when using off-stack
    2805                 :             :          trampolines, any such adjustment will be done when the off-stack
    2806                 :             :          trampoline is created.  */
    2807                 :         281 :       if (!descr && flag_trampoline_impl == TRAMPOLINE_IMPL_HEAP)
    2808                 :           3 :         x = gsi_gimplify_val (info, x, &wi->gsi);
    2809                 :             :       else
    2810                 :             :         {
    2811                 :         278 :           x = build_addr (x);
    2812                 :             : 
    2813                 :         278 :           x = gsi_gimplify_val (info, x, &wi->gsi);
    2814                 :             : 
    2815                 :             :           /* Do machine-specific ugliness.  Normally this will involve
    2816                 :             :              computing extra alignment, but it can really be anything.  */
    2817                 :         278 :           if (descr)
    2818                 :           0 :             builtin = builtin_decl_implicit (BUILT_IN_ADJUST_DESCRIPTOR);
    2819                 :             :           else
    2820                 :         278 :             builtin = builtin_decl_implicit (BUILT_IN_ADJUST_TRAMPOLINE);
    2821                 :         278 :           call = gimple_build_call (builtin, 1, x);
    2822                 :         278 :           x = init_tmp_var_with_call (info, &wi->gsi, call);
    2823                 :             :         }
    2824                 :             : 
    2825                 :             :       /* Cast back to the proper function type.  */
    2826                 :         281 :       x = build1 (NOP_EXPR, TREE_TYPE (t), x);
    2827                 :         281 :       x = init_tmp_var (info, x, &wi->gsi);
    2828                 :             : 
    2829                 :         281 :       *tp = x;
    2830                 :         281 :       break;
    2831                 :             : 
    2832                 :    13024074 :     default:
    2833                 :    13024074 :       if (!IS_TYPE_OR_DECL_P (t))
    2834                 :     6961780 :         *walk_subtrees = 1;
    2835                 :             :       break;
    2836                 :             :     }
    2837                 :             : 
    2838                 :    13341296 :   return NULL_TREE;
    2839                 :             : }
    2840                 :             : 
    2841                 :             : 
    2842                 :             : /* Called via walk_function+walk_gimple_stmt, rewrite all references
    2843                 :             :    to addresses of nested functions that require the use of
    2844                 :             :    trampolines.  The rewrite will involve a reference a trampoline
    2845                 :             :    generated for the occasion.  */
    2846                 :             : 
    2847                 :             : static tree
    2848                 :     4146014 : convert_tramp_reference_stmt (gimple_stmt_iterator *gsi, bool *handled_ops_p,
    2849                 :             :                               struct walk_stmt_info *wi)
    2850                 :             : {
    2851                 :     4146014 :   struct nesting_info *info = (struct nesting_info *) wi->info;
    2852                 :     4146014 :   gimple *stmt = gsi_stmt (*gsi);
    2853                 :             : 
    2854                 :     4146014 :   switch (gimple_code (stmt))
    2855                 :             :     {
    2856                 :      277581 :     case GIMPLE_CALL:
    2857                 :      277581 :       {
    2858                 :             :         /* Only walk call arguments, lest we generate trampolines for
    2859                 :             :            direct calls.  */
    2860                 :      277581 :         unsigned long i, nargs = gimple_call_num_args (stmt);
    2861                 :      953237 :         for (i = 0; i < nargs; i++)
    2862                 :      675656 :           walk_tree (gimple_call_arg_ptr (stmt, i), convert_tramp_reference_op,
    2863                 :             :                      wi, NULL);
    2864                 :             :         break;
    2865                 :             :       }
    2866                 :             : 
    2867                 :          38 :     case GIMPLE_OMP_TEAMS:
    2868                 :          38 :       if (!gimple_omp_teams_host (as_a <gomp_teams *> (stmt)))
    2869                 :             :         {
    2870                 :          26 :           *handled_ops_p = false;
    2871                 :          26 :           return NULL_TREE;
    2872                 :             :         }
    2873                 :          12 :       goto do_parallel;
    2874                 :             : 
    2875                 :        1744 :     case GIMPLE_OMP_TARGET:
    2876                 :        1744 :       if (!is_gimple_omp_offloaded (stmt))
    2877                 :             :         {
    2878                 :         646 :           *handled_ops_p = false;
    2879                 :         646 :           return NULL_TREE;
    2880                 :             :         }
    2881                 :             :       /* FALLTHRU */
    2882                 :        2416 :     case GIMPLE_OMP_PARALLEL:
    2883                 :        2416 :     case GIMPLE_OMP_TASK:
    2884                 :        1098 :     do_parallel:
    2885                 :        2416 :       {
    2886                 :        2416 :         tree save_local_var_chain = info->new_local_var_chain;
    2887                 :        2416 :         walk_gimple_op (stmt, convert_tramp_reference_op, wi);
    2888                 :        2416 :         info->new_local_var_chain = NULL;
    2889                 :        2416 :         char save_static_chain_added = info->static_chain_added;
    2890                 :        2416 :         info->static_chain_added = 0;
    2891                 :        2416 :         walk_body (convert_tramp_reference_stmt, convert_tramp_reference_op,
    2892                 :             :                    info, gimple_omp_body_ptr (stmt));
    2893                 :        2416 :         if (info->new_local_var_chain)
    2894                 :           6 :           declare_vars (info->new_local_var_chain,
    2895                 :             :                         gimple_seq_first_stmt (gimple_omp_body (stmt)),
    2896                 :             :                         false);
    2897                 :        7248 :         for (int i = 0; i < 2; i++)
    2898                 :             :           {
    2899                 :        4832 :             tree c, decl;
    2900                 :        4832 :             if ((info->static_chain_added & (1 << i)) == 0)
    2901                 :        4826 :               continue;
    2902                 :           6 :             decl = i ? get_chain_decl (info) : info->frame_decl;
    2903                 :             :             /* Don't add CHAIN.* or FRAME.* twice.  */
    2904                 :           6 :             for (c = gimple_omp_taskreg_clauses (stmt);
    2905                 :           6 :                  c;
    2906                 :           0 :                  c = OMP_CLAUSE_CHAIN (c))
    2907                 :           1 :               if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
    2908                 :           1 :                    || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED)
    2909                 :           2 :                   && OMP_CLAUSE_DECL (c) == decl)
    2910                 :             :                 break;
    2911                 :           6 :             if (c == NULL && gimple_code (stmt) != GIMPLE_OMP_TARGET)
    2912                 :             :               {
    2913                 :           8 :                 c = build_omp_clause (gimple_location (stmt),
    2914                 :             :                                       i ? OMP_CLAUSE_FIRSTPRIVATE
    2915                 :             :                                       : OMP_CLAUSE_SHARED);
    2916                 :           5 :                 OMP_CLAUSE_DECL (c) = decl;
    2917                 :           5 :                 OMP_CLAUSE_CHAIN (c) = gimple_omp_taskreg_clauses (stmt);
    2918                 :           5 :                 gimple_omp_taskreg_set_clauses (stmt, c);
    2919                 :             :               }
    2920                 :           1 :             else if (c == NULL)
    2921                 :             :               {
    2922                 :           0 :                 c = build_omp_clause (gimple_location (stmt),
    2923                 :             :                                       OMP_CLAUSE_MAP);
    2924                 :           0 :                 OMP_CLAUSE_DECL (c) = decl;
    2925                 :           0 :                 OMP_CLAUSE_SET_MAP_KIND (c,
    2926                 :             :                                          i ? GOMP_MAP_TO : GOMP_MAP_TOFROM);
    2927                 :           0 :                 OMP_CLAUSE_SIZE (c) = DECL_SIZE_UNIT (decl);
    2928                 :           0 :                 OMP_CLAUSE_CHAIN (c) = gimple_omp_target_clauses (stmt);
    2929                 :           0 :                 gimple_omp_target_set_clauses (as_a <gomp_target *> (stmt),
    2930                 :             :                                                c);
    2931                 :             :               }
    2932                 :             :           }
    2933                 :        2416 :         info->new_local_var_chain = save_local_var_chain;
    2934                 :        2416 :         info->static_chain_added |= save_static_chain_added;
    2935                 :             :       }
    2936                 :        2416 :       break;
    2937                 :             : 
    2938                 :     3865345 :     default:
    2939                 :     3865345 :       *handled_ops_p = false;
    2940                 :     3865345 :       return NULL_TREE;
    2941                 :             :     }
    2942                 :             : 
    2943                 :      279997 :   *handled_ops_p = true;
    2944                 :      279997 :   return NULL_TREE;
    2945                 :             : }
    2946                 :             : 
    2947                 :             : 
    2948                 :             : 
    2949                 :             : /* Called via walk_function+walk_gimple_stmt, rewrite all GIMPLE_CALLs
    2950                 :             :    that reference nested functions to make sure that the static chain
    2951                 :             :    is set up properly for the call.  */
    2952                 :             : 
    2953                 :             : static tree
    2954                 :     4146602 : convert_gimple_call (gimple_stmt_iterator *gsi, bool *handled_ops_p,
    2955                 :             :                      struct walk_stmt_info *wi)
    2956                 :             : {
    2957                 :     4146602 :   struct nesting_info *const info = (struct nesting_info *) wi->info;
    2958                 :     4146602 :   tree decl, target_context;
    2959                 :     4146602 :   char save_static_chain_added;
    2960                 :     4146602 :   int i;
    2961                 :     4146602 :   gimple *stmt = gsi_stmt (*gsi);
    2962                 :             : 
    2963                 :     4146602 :   switch (gimple_code (stmt))
    2964                 :             :     {
    2965                 :      277859 :     case GIMPLE_CALL:
    2966                 :      277859 :       if (gimple_call_chain (stmt))
    2967                 :             :         break;
    2968                 :      277666 :       decl = gimple_call_fndecl (stmt);
    2969                 :      277666 :       if (!decl)
    2970                 :             :         break;
    2971                 :      252918 :       target_context = decl_function_context (decl);
    2972                 :      298723 :       if (target_context && DECL_STATIC_CHAIN (decl))
    2973                 :             :         {
    2974                 :             :           struct nesting_info *i = info;
    2975                 :       16455 :           while (i && i->context != target_context)
    2976                 :        1758 :             i = i->outer;
    2977                 :             :           /* If none of the outer contexts is the target context, this means
    2978                 :             :              that the function is called in a wrong context.  */
    2979                 :       14697 :           if (!i)
    2980                 :           0 :             internal_error ("%s from %s called in %s",
    2981                 :           0 :                             IDENTIFIER_POINTER (DECL_NAME (decl)),
    2982                 :           0 :                             IDENTIFIER_POINTER (DECL_NAME (target_context)),
    2983                 :           0 :                             IDENTIFIER_POINTER (DECL_NAME (info->context)));
    2984                 :             : 
    2985                 :       14697 :           gimple_call_set_chain (as_a <gcall *> (stmt),
    2986                 :             :                                  get_static_chain (info, target_context,
    2987                 :             :                                                    &wi->gsi));
    2988                 :       27676 :           info->static_chain_added |= (1 << (info->context != target_context));
    2989                 :             :         }
    2990                 :             :       break;
    2991                 :             : 
    2992                 :          38 :     case GIMPLE_OMP_TEAMS:
    2993                 :          38 :       if (!gimple_omp_teams_host (as_a <gomp_teams *> (stmt)))
    2994                 :             :         {
    2995                 :          26 :           walk_body (convert_gimple_call, NULL, info,
    2996                 :             :                      gimple_omp_body_ptr (stmt));
    2997                 :          26 :           break;
    2998                 :             :         }
    2999                 :             :       /* FALLTHRU */
    3000                 :             : 
    3001                 :        1318 :     case GIMPLE_OMP_PARALLEL:
    3002                 :        1318 :     case GIMPLE_OMP_TASK:
    3003                 :        1318 :       save_static_chain_added = info->static_chain_added;
    3004                 :        1318 :       info->static_chain_added = 0;
    3005                 :        1318 :       walk_body (convert_gimple_call, NULL, info, gimple_omp_body_ptr (stmt));
    3006                 :        3954 :       for (i = 0; i < 2; i++)
    3007                 :             :         {
    3008                 :        2636 :           tree c, decl;
    3009                 :        2636 :           if ((info->static_chain_added & (1 << i)) == 0)
    3010                 :        2568 :             continue;
    3011                 :          68 :           decl = i ? get_chain_decl (info) : info->frame_decl;
    3012                 :             :           /* Don't add CHAIN.* or FRAME.* twice.  */
    3013                 :          68 :           for (c = gimple_omp_taskreg_clauses (stmt);
    3014                 :         736 :                c;
    3015                 :         668 :                c = OMP_CLAUSE_CHAIN (c))
    3016                 :         670 :             if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
    3017                 :         258 :                  || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED)
    3018                 :         724 :                 && OMP_CLAUSE_DECL (c) == decl)
    3019                 :             :               break;
    3020                 :          68 :           if (c == NULL)
    3021                 :             :             {
    3022                 :         110 :               c = build_omp_clause (gimple_location (stmt),
    3023                 :             :                                     i ? OMP_CLAUSE_FIRSTPRIVATE
    3024                 :             :                                     : OMP_CLAUSE_SHARED);
    3025                 :          66 :               OMP_CLAUSE_DECL (c) = decl;
    3026                 :          66 :               OMP_CLAUSE_CHAIN (c) = gimple_omp_taskreg_clauses (stmt);
    3027                 :          66 :               gimple_omp_taskreg_set_clauses (stmt, c);
    3028                 :             :             }
    3029                 :             :         }
    3030                 :        1318 :       info->static_chain_added |= save_static_chain_added;
    3031                 :        1318 :       break;
    3032                 :             : 
    3033                 :        1744 :     case GIMPLE_OMP_TARGET:
    3034                 :        1744 :       if (!is_gimple_omp_offloaded (stmt))
    3035                 :             :         {
    3036                 :         646 :           walk_body (convert_gimple_call, NULL, info, gimple_omp_body_ptr (stmt));
    3037                 :         646 :           break;
    3038                 :             :         }
    3039                 :        1098 :       save_static_chain_added = info->static_chain_added;
    3040                 :        1098 :       info->static_chain_added = 0;
    3041                 :        1098 :       walk_body (convert_gimple_call, NULL, info, gimple_omp_body_ptr (stmt));
    3042                 :        3294 :       for (i = 0; i < 2; i++)
    3043                 :             :         {
    3044                 :        2196 :           tree c, decl;
    3045                 :        2196 :           if ((info->static_chain_added & (1 << i)) == 0)
    3046                 :        2178 :             continue;
    3047                 :          18 :           decl = i ? get_chain_decl (info) : info->frame_decl;
    3048                 :             :           /* Don't add CHAIN.* or FRAME.* twice.  */
    3049                 :          18 :           for (c = gimple_omp_target_clauses (stmt);
    3050                 :         134 :                c;
    3051                 :         116 :                c = OMP_CLAUSE_CHAIN (c))
    3052                 :         116 :             if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
    3053                 :         116 :                 && OMP_CLAUSE_DECL (c) == decl)
    3054                 :             :               break;
    3055                 :          18 :           if (c == NULL)
    3056                 :             :             {
    3057                 :          18 :               c = build_omp_clause (gimple_location (stmt), OMP_CLAUSE_MAP);
    3058                 :          18 :               OMP_CLAUSE_DECL (c) = decl;
    3059                 :          28 :               OMP_CLAUSE_SET_MAP_KIND (c, i ? GOMP_MAP_TO : GOMP_MAP_TOFROM);
    3060                 :          18 :               OMP_CLAUSE_SIZE (c) = DECL_SIZE_UNIT (decl);
    3061                 :          18 :               OMP_CLAUSE_CHAIN (c) = gimple_omp_target_clauses (stmt);
    3062                 :          18 :               gimple_omp_target_set_clauses (as_a <gomp_target *> (stmt),
    3063                 :             :                                              c);
    3064                 :             :             }
    3065                 :             :         }
    3066                 :        1098 :       info->static_chain_added |= save_static_chain_added;
    3067                 :        1098 :       break;
    3068                 :             : 
    3069                 :        1481 :     case GIMPLE_OMP_FOR:
    3070                 :        1481 :       walk_body (convert_gimple_call, NULL, info,
    3071                 :             :                  gimple_omp_for_pre_body_ptr (stmt));
    3072                 :             :       /* FALLTHRU */
    3073                 :        2379 :     case GIMPLE_OMP_SECTIONS:
    3074                 :        2379 :     case GIMPLE_OMP_SECTION:
    3075                 :        2379 :     case GIMPLE_OMP_STRUCTURED_BLOCK:
    3076                 :        2379 :     case GIMPLE_OMP_SINGLE:
    3077                 :        2379 :     case GIMPLE_OMP_SCOPE:
    3078                 :        2379 :     case GIMPLE_OMP_MASTER:
    3079                 :        2379 :     case GIMPLE_OMP_MASKED:
    3080                 :        2379 :     case GIMPLE_OMP_TASKGROUP:
    3081                 :        2379 :     case GIMPLE_OMP_ORDERED:
    3082                 :        2379 :     case GIMPLE_OMP_SCAN:
    3083                 :        2379 :     case GIMPLE_OMP_CRITICAL:
    3084                 :        2379 :       walk_body (convert_gimple_call, NULL, info, gimple_omp_body_ptr (stmt));
    3085                 :        2379 :       break;
    3086                 :             : 
    3087                 :     3863276 :     default:
    3088                 :             :       /* Keep looking for other operands.  */
    3089                 :     3863276 :       *handled_ops_p = false;
    3090                 :     3863276 :       return NULL_TREE;
    3091                 :             :     }
    3092                 :             : 
    3093                 :      283326 :   *handled_ops_p = true;
    3094                 :      283326 :   return NULL_TREE;
    3095                 :             : }
    3096                 :             : 
    3097                 :             : /* Walk the nesting tree starting with ROOT.  Convert all trampolines and
    3098                 :             :    call expressions.  At the same time, determine if a nested function
    3099                 :             :    actually uses its static chain; if not, remember that.  */
    3100                 :             : 
    3101                 :             : static void
    3102                 :        8474 : convert_all_function_calls (struct nesting_info *root)
    3103                 :             : {
    3104                 :        8474 :   unsigned int chain_count = 0, old_chain_count, iter_count;
    3105                 :        8474 :   struct nesting_info *n;
    3106                 :             : 
    3107                 :             :   /* First, optimistically clear static_chain for all decls that haven't
    3108                 :             :      used the static chain already for variable access.  But always create
    3109                 :             :      it if not optimizing.  This makes it possible to reconstruct the static
    3110                 :             :      nesting tree at run time and thus to resolve up-level references from
    3111                 :             :      within the debugger.  */
    3112                 :       71680 :   FOR_EACH_NEST_INFO (n, root)
    3113                 :             :     {
    3114                 :       27366 :       if (n->thunk_p)
    3115                 :           0 :         continue;
    3116                 :       27366 :       tree decl = n->context;
    3117                 :       27366 :       if (!optimize)
    3118                 :             :         {
    3119                 :        4551 :           if (n->inner)
    3120                 :        1469 :             (void) get_frame_type (n);
    3121                 :        4551 :           if (n->outer)
    3122                 :        3128 :             (void) get_chain_decl (n);
    3123                 :             :         }
    3124                 :       22815 :       else if (!n->outer || (!n->chain_decl && !n->chain_field))
    3125                 :             :         {
    3126                 :       20255 :           DECL_STATIC_CHAIN (decl) = 0;
    3127                 :       20255 :           if (dump_file && (dump_flags & TDF_DETAILS))
    3128                 :           0 :             fprintf (dump_file, "Guessing no static-chain for %s\n",
    3129                 :           0 :                      lang_hooks.decl_printable_name (decl, 2));
    3130                 :             :         }
    3131                 :             :       else
    3132                 :        2560 :         DECL_STATIC_CHAIN (decl) = 1;
    3133                 :       27366 :       chain_count += DECL_STATIC_CHAIN (decl);
    3134                 :             :     }
    3135                 :             : 
    3136                 :       63206 :   FOR_EACH_NEST_INFO (n, root)
    3137                 :       27366 :     if (n->thunk_p)
    3138                 :             :       {
    3139                 :           0 :         tree decl = n->context;
    3140                 :           0 :         tree alias = thunk_info::get (cgraph_node::get (decl))->alias;
    3141                 :           0 :         DECL_STATIC_CHAIN (decl) = DECL_STATIC_CHAIN (alias);
    3142                 :             :       }
    3143                 :             : 
    3144                 :             :   /* Walk the functions and perform transformations.  Note that these
    3145                 :             :      transformations can induce new uses of the static chain, which in turn
    3146                 :             :      require re-examining all users of the decl.  */
    3147                 :             :   /* ??? It would make sense to try to use the call graph to speed this up,
    3148                 :             :      but the call graph hasn't really been built yet.  Even if it did, we
    3149                 :             :      would still need to iterate in this loop since address-of references
    3150                 :             :      wouldn't show up in the callgraph anyway.  */
    3151                 :             :   iter_count = 0;
    3152                 :        8525 :   do
    3153                 :             :     {
    3154                 :        8525 :       old_chain_count = chain_count;
    3155                 :        8525 :       chain_count = 0;
    3156                 :        8525 :       iter_count++;
    3157                 :             : 
    3158                 :        8525 :       if (dump_file && (dump_flags & TDF_DETAILS))
    3159                 :           0 :         fputc ('\n', dump_file);
    3160                 :             : 
    3161                 :       72290 :       FOR_EACH_NEST_INFO (n, root)
    3162                 :             :         {
    3163                 :       27620 :           if (n->thunk_p)
    3164                 :           0 :             continue;
    3165                 :       27620 :           tree decl = n->context;
    3166                 :       27620 :           walk_function (convert_tramp_reference_stmt,
    3167                 :             :                          convert_tramp_reference_op, n);
    3168                 :       27620 :           walk_function (convert_gimple_call, NULL, n);
    3169                 :       27620 :           chain_count += DECL_STATIC_CHAIN (decl);
    3170                 :             :         }
    3171                 :             : 
    3172                 :       63765 :       FOR_EACH_NEST_INFO (n, root)
    3173                 :       27620 :         if (n->thunk_p)
    3174                 :             :           {
    3175                 :           0 :             tree decl = n->context;
    3176                 :           0 :             tree alias = thunk_info::get (cgraph_node::get (decl))->alias;
    3177                 :           0 :             DECL_STATIC_CHAIN (decl) = DECL_STATIC_CHAIN (alias);
    3178                 :             :           }
    3179                 :             :     }
    3180                 :        8525 :   while (chain_count != old_chain_count);
    3181                 :             : 
    3182                 :        8474 :   if (dump_file && (dump_flags & TDF_DETAILS))
    3183                 :           0 :     fprintf (dump_file, "convert_all_function_calls iterations: %u\n\n",
    3184                 :             :              iter_count);
    3185                 :        8474 : }
    3186                 :             : 
    3187                 :             : struct nesting_copy_body_data
    3188                 :             : {
    3189                 :             :   copy_body_data cb;
    3190                 :             :   struct nesting_info *root;
    3191                 :             : };
    3192                 :             : 
    3193                 :             : /* A helper subroutine for debug_var_chain type remapping.  */
    3194                 :             : 
    3195                 :             : static tree
    3196                 :          30 : nesting_copy_decl (tree decl, copy_body_data *id)
    3197                 :             : {
    3198                 :          30 :   struct nesting_copy_body_data *nid = (struct nesting_copy_body_data *) id;
    3199                 :          30 :   tree *slot = nid->root->var_map->get (decl);
    3200                 :             : 
    3201                 :          30 :   if (slot)
    3202                 :           6 :     return (tree) *slot;
    3203                 :             : 
    3204                 :          24 :   if (TREE_CODE (decl) == TYPE_DECL && DECL_ORIGINAL_TYPE (decl))
    3205                 :             :     {
    3206                 :           6 :       tree new_decl = copy_decl_no_change (decl, id);
    3207                 :          12 :       DECL_ORIGINAL_TYPE (new_decl)
    3208                 :           6 :         = remap_type (DECL_ORIGINAL_TYPE (decl), id);
    3209                 :           6 :       return new_decl;
    3210                 :             :     }
    3211                 :             : 
    3212                 :          18 :   if (VAR_P (decl)
    3213                 :             :       || TREE_CODE (decl) == PARM_DECL
    3214                 :             :       || TREE_CODE (decl) == RESULT_DECL)
    3215                 :             :     return decl;
    3216                 :             : 
    3217                 :           0 :   return copy_decl_no_change (decl, id);
    3218                 :             : }
    3219                 :             : 
    3220                 :             : /* A helper function for remap_vla_decls.  See if *TP contains
    3221                 :             :    some remapped variables.  */
    3222                 :             : 
    3223                 :             : static tree
    3224                 :          36 : contains_remapped_vars (tree *tp, int *walk_subtrees, void *data)
    3225                 :             : {
    3226                 :          36 :   struct nesting_info *root = (struct nesting_info *) data;
    3227                 :          36 :   tree t = *tp;
    3228                 :             : 
    3229                 :          36 :   if (DECL_P (t))
    3230                 :             :     {
    3231                 :           0 :       *walk_subtrees = 0;
    3232                 :           0 :       tree *slot = root->var_map->get (t);
    3233                 :             : 
    3234                 :           0 :       if (slot)
    3235                 :           0 :         return *slot;
    3236                 :             :     }
    3237                 :             :   return NULL;
    3238                 :             : }
    3239                 :             : 
    3240                 :             : /* Remap VLA decls in BLOCK and subblocks if remapped variables are
    3241                 :             :    involved.  */
    3242                 :             : 
    3243                 :             : static void
    3244                 :        2698 : remap_vla_decls (tree block, struct nesting_info *root)
    3245                 :             : {
    3246                 :        2698 :   tree var, subblock, val, type;
    3247                 :        2698 :   struct nesting_copy_body_data id;
    3248                 :             : 
    3249                 :        5050 :   for (subblock = BLOCK_SUBBLOCKS (block);
    3250                 :        5050 :        subblock;
    3251                 :        2352 :        subblock = BLOCK_CHAIN (subblock))
    3252                 :        2352 :     remap_vla_decls (subblock, root);
    3253                 :             : 
    3254                 :        8623 :   for (var = BLOCK_VARS (block); var; var = DECL_CHAIN (var))
    3255                 :        5925 :     if (VAR_P (var) && DECL_HAS_VALUE_EXPR_P (var))
    3256                 :             :       {
    3257                 :          87 :         val = DECL_VALUE_EXPR (var);
    3258                 :          87 :         type = TREE_TYPE (var);
    3259                 :             : 
    3260                 :          99 :         if (! (INDIRECT_REF_P (val)
    3261                 :          12 :               && VAR_P (TREE_OPERAND (val, 0))
    3262                 :          12 :               && variably_modified_type_p (type, NULL)))
    3263                 :          75 :           continue;
    3264                 :             : 
    3265                 :          12 :         if (root->var_map->get (TREE_OPERAND (val, 0))
    3266                 :          12 :             || walk_tree (&type, contains_remapped_vars, root, NULL))
    3267                 :             :           break;
    3268                 :             :       }
    3269                 :             : 
    3270                 :        2698 :   if (var == NULL_TREE)
    3271                 :        2698 :     return;
    3272                 :             : 
    3273                 :           0 :   memset (&id, 0, sizeof (id));
    3274                 :           0 :   id.cb.copy_decl = nesting_copy_decl;
    3275                 :           0 :   id.cb.decl_map = new hash_map<tree, tree>;
    3276                 :           0 :   id.root = root;
    3277                 :             : 
    3278                 :           0 :   for (; var; var = DECL_CHAIN (var))
    3279                 :           0 :     if (VAR_P (var) && DECL_HAS_VALUE_EXPR_P (var))
    3280                 :             :       {
    3281                 :           0 :         struct nesting_info *i;
    3282                 :           0 :         tree newt, context;
    3283                 :             : 
    3284                 :           0 :         val = DECL_VALUE_EXPR (var);
    3285                 :           0 :         type = TREE_TYPE (var);
    3286                 :             : 
    3287                 :           0 :         if (! (INDIRECT_REF_P (val)
    3288                 :           0 :               && VAR_P (TREE_OPERAND (val, 0))
    3289                 :           0 :               && variably_modified_type_p (type, NULL)))
    3290                 :           0 :           continue;
    3291                 :             : 
    3292                 :           0 :         tree *slot = root->var_map->get (TREE_OPERAND (val, 0));
    3293                 :           0 :         if (!slot && !walk_tree (&type, contains_remapped_vars, root, NULL))
    3294                 :           0 :           continue;
    3295                 :             : 
    3296                 :           0 :         context = decl_function_context (var);
    3297                 :           0 :         for (i = root; i; i = i->outer)
    3298                 :           0 :           if (i->context == context)
    3299                 :             :             break;
    3300                 :             : 
    3301                 :           0 :         if (i == NULL)
    3302                 :           0 :           continue;
    3303                 :             : 
    3304                 :             :         /* Fully expand value expressions.  This avoids having debug variables
    3305                 :             :            only referenced from them and that can be swept during GC.  */
    3306                 :           0 :         if (slot)
    3307                 :             :           {
    3308                 :           0 :             tree t = (tree) *slot;
    3309                 :           0 :             gcc_assert (DECL_P (t) && DECL_HAS_VALUE_EXPR_P (t));
    3310                 :           0 :             val = build1 (INDIRECT_REF, TREE_TYPE (val), DECL_VALUE_EXPR (t));
    3311                 :             :           }
    3312                 :             : 
    3313                 :           0 :         id.cb.src_fn = i->context;
    3314                 :           0 :         id.cb.dst_fn = i->context;
    3315                 :           0 :         id.cb.src_cfun = DECL_STRUCT_FUNCTION (root->context);
    3316                 :             : 
    3317                 :           0 :         TREE_TYPE (var) = newt = remap_type (type, &id.cb);
    3318                 :           0 :         while (POINTER_TYPE_P (newt) && !TYPE_NAME (newt))
    3319                 :             :           {
    3320                 :           0 :             newt = TREE_TYPE (newt);
    3321                 :           0 :             type = TREE_TYPE (type);
    3322                 :             :           }
    3323                 :           0 :         if (TYPE_NAME (newt)
    3324                 :           0 :             && TREE_CODE (TYPE_NAME (newt)) == TYPE_DECL
    3325                 :           0 :             && DECL_ORIGINAL_TYPE (TYPE_NAME (newt))
    3326                 :           0 :             && newt != type
    3327                 :           0 :             && TYPE_NAME (newt) == TYPE_NAME (type))
    3328                 :           0 :           TYPE_NAME (newt) = remap_decl (TYPE_NAME (newt), &id.cb);
    3329                 :             : 
    3330                 :           0 :         walk_tree (&val, copy_tree_body_r, &id.cb, NULL);
    3331                 :           0 :         if (val != DECL_VALUE_EXPR (var))
    3332                 :           0 :           SET_DECL_VALUE_EXPR (var, val);
    3333                 :             :       }
    3334                 :             : 
    3335                 :           0 :   delete id.cb.decl_map;
    3336                 :             : }
    3337                 :             : 
    3338                 :             : /* Fixup VLA decls in BLOCK and subblocks if remapped variables are
    3339                 :             :    involved.  */
    3340                 :             : 
    3341                 :             : static void
    3342                 :      189800 : fixup_vla_decls (tree block)
    3343                 :             : {
    3344                 :      758416 :   for (tree var = BLOCK_VARS (block); var; var = DECL_CHAIN (var))
    3345                 :      568616 :     if (VAR_P (var) && DECL_HAS_VALUE_EXPR_P (var))
    3346                 :             :       {
    3347                 :        3626 :         tree val = DECL_VALUE_EXPR (var);
    3348                 :             : 
    3349                 :        3626 :         if (! (INDIRECT_REF_P (val)
    3350                 :         332 :               && VAR_P (TREE_OPERAND (val, 0))
    3351                 :         330 :               && DECL_HAS_VALUE_EXPR_P (TREE_OPERAND (val, 0))))
    3352                 :        3593 :           continue;
    3353                 :             : 
    3354                 :             :         /* Fully expand value expressions.  This avoids having debug variables
    3355                 :             :            only referenced from them and that can be swept during GC.  */
    3356                 :          33 :         val = build1 (INDIRECT_REF, TREE_TYPE (val),
    3357                 :          33 :                       DECL_VALUE_EXPR (TREE_OPERAND (val, 0)));
    3358                 :          33 :         SET_DECL_VALUE_EXPR (var, val);
    3359                 :             :       }
    3360                 :             : 
    3361                 :      352580 :   for (tree sub = BLOCK_SUBBLOCKS (block); sub; sub = BLOCK_CHAIN (sub))
    3362                 :      162780 :     fixup_vla_decls (sub);
    3363                 :      189800 : }
    3364                 :             : 
    3365                 :             : /* Fold the MEM_REF *E.  */
    3366                 :             : bool
    3367                 :           0 : fold_mem_refs (tree *const &e, void *data ATTRIBUTE_UNUSED)
    3368                 :             : {
    3369                 :           0 :   tree *ref_p = CONST_CAST2 (tree *, const tree *, (const tree *)e);
    3370                 :           0 :   *ref_p = fold (*ref_p);
    3371                 :           0 :   return true;
    3372                 :             : }
    3373                 :             : 
    3374                 :             : /* Given DECL, a nested function, build an initialization call for FIELD,
    3375                 :             :    the trampoline or descriptor for DECL, using FUNC as the function.  */
    3376                 :             : 
    3377                 :             : static gcall *
    3378                 :         260 : build_init_call_stmt (struct nesting_info *info, tree decl, tree field,
    3379                 :             :                       tree func)
    3380                 :             : {
    3381                 :         260 :   tree arg1, arg2, arg3, x;
    3382                 :             : 
    3383                 :         260 :   gcc_assert (DECL_STATIC_CHAIN (decl));
    3384                 :         260 :   arg3 = build_addr (info->frame_decl);
    3385                 :             : 
    3386                 :         260 :   arg2 = build_addr (decl);
    3387                 :             : 
    3388                 :         260 :   x = build3 (COMPONENT_REF, TREE_TYPE (field),
    3389                 :             :               info->frame_decl, field, NULL_TREE);
    3390                 :         260 :   arg1 = build_addr (x);
    3391                 :             : 
    3392                 :         260 :   return gimple_build_call (func, 3, arg1, arg2, arg3);
    3393                 :             : }
    3394                 :             : 
    3395                 :             : /* Do "everything else" to clean up or complete state collected by the various
    3396                 :             :    walking passes -- create a field to hold the frame base address, lay out the
    3397                 :             :    types and decls, generate code to initialize the frame decl, store critical
    3398                 :             :    expressions in the struct function for rtl to find.  */
    3399                 :             : 
    3400                 :             : static void
    3401                 :       27366 : finalize_nesting_tree_1 (struct nesting_info *root)
    3402                 :             : {
    3403                 :       27366 :   gimple_seq cleanup_list = NULL;
    3404                 :       27366 :   gimple_seq stmt_list = NULL;
    3405                 :       27366 :   gimple *stmt;
    3406                 :       27366 :   tree context = root->context;
    3407                 :       27366 :   struct function *sf;
    3408                 :             : 
    3409                 :       27366 :   if (root->thunk_p)
    3410                 :           0 :     return;
    3411                 :             : 
    3412                 :             :   /* If we created a non-local frame type or decl, we need to lay them
    3413                 :             :      out at this time.  */
    3414                 :       27366 :   if (root->frame_type)
    3415                 :             :     {
    3416                 :             :       /* Debugging information needs to compute the frame base address of the
    3417                 :             :          parent frame out of the static chain from the nested frame.
    3418                 :             : 
    3419                 :             :          The static chain is the address of the FRAME record, so one could
    3420                 :             :          imagine it would be possible to compute the frame base address just
    3421                 :             :          adding a constant offset to this address.  Unfortunately, this is not
    3422                 :             :          possible: if the FRAME object has alignment constraints that are
    3423                 :             :          stronger than the stack, then the offset between the frame base and
    3424                 :             :          the FRAME object will be dynamic.
    3425                 :             : 
    3426                 :             :          What we do instead is to append a field to the FRAME object that holds
    3427                 :             :          the frame base address: then debug info just has to fetch this
    3428                 :             :          field.  */
    3429                 :             : 
    3430                 :             :       /* Debugging information will refer to the CFA as the frame base
    3431                 :             :          address: we will do the same here.  */
    3432                 :        3196 :       const tree frame_addr_fndecl
    3433                 :        3196 :         = builtin_decl_explicit (BUILT_IN_DWARF_CFA);
    3434                 :             : 
    3435                 :             :       /* Create a field in the FRAME record to hold the frame base address for
    3436                 :             :          this stack frame.  Since it will be used only by the debugger, put it
    3437                 :             :          at the end of the record in order not to shift all other offsets.  */
    3438                 :        3196 :       tree fb_decl = make_node (FIELD_DECL);
    3439                 :             : 
    3440                 :        3196 :       DECL_NAME (fb_decl) = get_identifier ("FRAME_BASE.PARENT");
    3441                 :        3196 :       TREE_TYPE (fb_decl) = ptr_type_node;
    3442                 :        3196 :       TREE_ADDRESSABLE (fb_decl) = 1;
    3443                 :        3196 :       DECL_CONTEXT (fb_decl) = root->frame_type;
    3444                 :        3196 :       TYPE_FIELDS (root->frame_type) = chainon (TYPE_FIELDS (root->frame_type),
    3445                 :             :                                                 fb_decl);
    3446                 :             : 
    3447                 :             :       /* In some cases the frame type will trigger the -Wpadded warning.
    3448                 :             :          This is not helpful; suppress it. */
    3449                 :        3196 :       int save_warn_padded = warn_padded;
    3450                 :        3196 :       warn_padded = 0;
    3451                 :        3196 :       layout_type (root->frame_type);
    3452                 :        3196 :       warn_padded = save_warn_padded;
    3453                 :        3196 :       layout_decl (root->frame_decl, 0);
    3454                 :             : 
    3455                 :             :       /* Initialize the frame base address field.  If the builtin we need is
    3456                 :             :          not available, set it to NULL so that debugging information does not
    3457                 :             :          reference junk.  */
    3458                 :        3196 :       tree fb_ref = build3 (COMPONENT_REF, TREE_TYPE (fb_decl),
    3459                 :             :                             root->frame_decl, fb_decl, NULL_TREE);
    3460                 :        3196 :       tree fb_tmp;
    3461                 :             : 
    3462                 :        3196 :       if (frame_addr_fndecl != NULL_TREE)
    3463                 :             :         {
    3464                 :        1019 :           gcall *fb_gimple = gimple_build_call (frame_addr_fndecl, 1,
    3465                 :             :                                                 integer_zero_node);
    3466                 :        1019 :           gimple_stmt_iterator gsi = gsi_last (stmt_list);
    3467                 :             : 
    3468                 :        1019 :           fb_tmp = init_tmp_var_with_call (root, &gsi, fb_gimple);
    3469                 :             :         }
    3470                 :             :       else
    3471                 :        2177 :         fb_tmp = build_int_cst (TREE_TYPE (fb_ref), 0);
    3472                 :        3196 :       gimple_seq_add_stmt (&stmt_list,
    3473                 :        3196 :                            gimple_build_assign (fb_ref, fb_tmp));
    3474                 :             : 
    3475                 :        3196 :       declare_vars (root->frame_decl,
    3476                 :             :                     gimple_seq_first_stmt (gimple_body (context)), true);
    3477                 :             :     }
    3478                 :             : 
    3479                 :             :   /* If any parameters were referenced non-locally, then we need to insert
    3480                 :             :      a copy or a pointer.  */
    3481                 :       27366 :   if (root->any_parm_remapped)
    3482                 :             :     {
    3483                 :         210 :       tree p;
    3484                 :         591 :       for (p = DECL_ARGUMENTS (context); p ; p = DECL_CHAIN (p))
    3485                 :             :         {
    3486                 :         381 :           tree field, x, y;
    3487                 :             : 
    3488                 :         381 :           field = lookup_field_for_decl (root, p, NO_INSERT);
    3489                 :         381 :           if (!field)
    3490                 :         132 :             continue;
    3491                 :             : 
    3492                 :         249 :           if (use_pointer_in_frame (p))
    3493                 :          21 :             x = build_addr (p);
    3494                 :             :           else
    3495                 :             :             x = p;
    3496                 :             : 
    3497                 :             :           /* If the assignment is from a non-register the stmt is
    3498                 :             :              not valid gimple.  Make it so by using a temporary instead.  */
    3499                 :         249 :           if (!is_gimple_reg (x)
    3500                 :         249 :               && is_gimple_reg_type (TREE_TYPE (x)))
    3501                 :             :             {
    3502                 :          37 :               gimple_stmt_iterator gsi = gsi_last (stmt_list);
    3503                 :          37 :               x = init_tmp_var (root, x, &gsi);
    3504                 :             :             }
    3505                 :             : 
    3506                 :         249 :           y = build3 (COMPONENT_REF, TREE_TYPE (field),
    3507                 :             :                       root->frame_decl, field, NULL_TREE);
    3508                 :         249 :           stmt = gimple_build_assign (y, x);
    3509                 :         249 :           gimple_seq_add_stmt (&stmt_list, stmt);
    3510                 :             :         }
    3511                 :             :     }
    3512                 :             : 
    3513                 :             :   /* If a chain_field was created, then it needs to be initialized
    3514                 :             :      from chain_decl.  */
    3515                 :       27366 :   if (root->chain_field)
    3516                 :             :     {
    3517                 :          77 :       tree x = build3 (COMPONENT_REF, TREE_TYPE (root->chain_field),
    3518                 :             :                        root->frame_decl, root->chain_field, NULL_TREE);
    3519                 :          77 :       stmt = gimple_build_assign (x, get_chain_decl (root));
    3520                 :          77 :       gimple_seq_add_stmt (&stmt_list, stmt);
    3521                 :             :     }
    3522                 :             : 
    3523                 :             :   /* If trampolines were created, then we need to initialize them.  */
    3524                 :       27366 :   if (root->any_tramp_created)
    3525                 :             :     {
    3526                 :         233 :       struct nesting_info *i;
    3527                 :         568 :       for (i = root->inner; i ; i = i->next)
    3528                 :             :         {
    3529                 :         335 :           tree field, x;
    3530                 :             : 
    3531                 :         335 :           field = lookup_tramp_for_decl (root, i->context, NO_INSERT);
    3532                 :         335 :           if (!field)
    3533                 :          74 :             continue;
    3534                 :             : 
    3535                 :         261 :           if (flag_trampoline_impl == TRAMPOLINE_IMPL_HEAP)
    3536                 :             :             {
    3537                 :             :               /* We pass a whole bunch of arguments to the builtin function that
    3538                 :             :                  creates the off-stack trampoline, these are
    3539                 :             :                  1. The nested function chain value (that must be passed to the
    3540                 :             :                  nested function so it can find the function arguments).
    3541                 :             :                  2. A pointer to the nested function implementation,
    3542                 :             :                  3. The address in the local stack frame where we should write
    3543                 :             :                  the address of the trampoline.
    3544                 :             : 
    3545                 :             :                  When this code was originally written I just kind of threw
    3546                 :             :                  everything at the builtin, figuring I'd work out what was
    3547                 :             :                  actually needed later, I think, the stack pointer could
    3548                 :             :                  certainly be dropped, arguments #2 and #4 are based off the
    3549                 :             :                  stack pointer anyway, so #1 doesn't seem to add much value.  */
    3550                 :           1 :               tree arg1, arg2, arg3;
    3551                 :             : 
    3552                 :           1 :               gcc_assert (DECL_STATIC_CHAIN (i->context));
    3553                 :           1 :               arg1 = build_addr (root->frame_decl);
    3554                 :           1 :               arg2 = build_addr (i->context);
    3555                 :             : 
    3556                 :           1 :               x = build3 (COMPONENT_REF, TREE_TYPE (field),
    3557                 :             :                           root->frame_decl, field, NULL_TREE);
    3558                 :           1 :               arg3 = build_addr (x);
    3559                 :             : 
    3560                 :           1 :               x = builtin_decl_explicit (BUILT_IN_GCC_NESTED_PTR_CREATED);
    3561                 :           1 :               stmt = gimple_build_call (x, 3, arg1, arg2, arg3);
    3562                 :           1 :               gimple_seq_add_stmt (&stmt_list, stmt);
    3563                 :             : 
    3564                 :             :               /* This call to delete the nested function trampoline is added to
    3565                 :             :                  the cleanup list, and called when we exit the current scope.  */
    3566                 :           1 :               x = builtin_decl_explicit (BUILT_IN_GCC_NESTED_PTR_DELETED);
    3567                 :           1 :               stmt = gimple_build_call (x, 0);
    3568                 :           1 :               gimple_seq_add_stmt (&cleanup_list, stmt);
    3569                 :             :             }
    3570                 :             :           else
    3571                 :             :             {
    3572                 :             :               /* Original code to initialise the on stack trampoline.  */
    3573                 :         260 :               x = builtin_decl_implicit (BUILT_IN_INIT_TRAMPOLINE);
    3574                 :         260 :               stmt = build_init_call_stmt (root, i->context, field, x);
    3575                 :         260 :               gimple_seq_add_stmt (&stmt_list, stmt);
    3576                 :             :             }
    3577                 :             :         }
    3578                 :             :     }
    3579                 :             : 
    3580                 :             :   /* If descriptors were created, then we need to initialize them.  */
    3581                 :       27366 :   if (root->any_descr_created)
    3582                 :             :     {
    3583                 :           0 :       struct nesting_info *i;
    3584                 :           0 :       for (i = root->inner; i ; i = i->next)
    3585                 :             :         {
    3586                 :           0 :           tree field, x;
    3587                 :             : 
    3588                 :           0 :           field = lookup_descr_for_decl (root, i->context, NO_INSERT);
    3589                 :           0 :           if (!field)
    3590                 :           0 :             continue;
    3591                 :             : 
    3592                 :           0 :           x = builtin_decl_implicit (BUILT_IN_INIT_DESCRIPTOR);
    3593                 :           0 :           stmt = build_init_call_stmt (root, i->context, field, x);
    3594                 :           0 :           gimple_seq_add_stmt (&stmt_list, stmt);
    3595                 :             :         }
    3596                 :             :     }
    3597                 :             : 
    3598                 :             :   /* If we created initialization statements, insert them.  */
    3599                 :       27366 :   if (stmt_list)
    3600                 :             :     {
    3601                 :        3196 :       if (flag_trampoline_impl == TRAMPOLINE_IMPL_HEAP)
    3602                 :             :         {
    3603                 :             :           /* Handle off-stack trampolines.  */
    3604                 :           1 :           gbind *bind;
    3605                 :           1 :           annotate_all_with_location (stmt_list, DECL_SOURCE_LOCATION (context));
    3606                 :           1 :           annotate_all_with_location (cleanup_list, DECL_SOURCE_LOCATION (context));
    3607                 :           1 :           bind = gimple_seq_first_stmt_as_a_bind (gimple_body (context));
    3608                 :           1 :           gimple_seq_add_seq (&stmt_list, gimple_bind_body (bind));
    3609                 :             : 
    3610                 :           1 :           gimple_seq xxx_list = NULL;
    3611                 :             : 
    3612                 :           1 :           if (cleanup_list != NULL)
    3613                 :             :             {
    3614                 :             :               /* Maybe we shouldn't be creating this try/finally if -fno-exceptions is
    3615                 :             :                  in use.  If this is the case, then maybe we should, instead, be
    3616                 :             :                  inserting the cleanup code onto every path out of this function?  Not
    3617                 :             :                  yet figured out how we would do this.  */
    3618                 :           1 :               gtry *t = gimple_build_try (stmt_list, cleanup_list, GIMPLE_TRY_FINALLY);
    3619                 :           1 :               gimple_seq_add_stmt (&xxx_list, t);
    3620                 :             :             }
    3621                 :             :           else
    3622                 :           0 :             xxx_list = stmt_list;
    3623                 :             : 
    3624                 :           1 :           gimple_bind_set_body (bind, xxx_list);
    3625                 :             :         }
    3626                 :             :       else
    3627                 :             :         {
    3628                 :             :           /* The traditional, on stack trampolines.  */
    3629                 :        3195 :           gbind *bind;
    3630                 :        3195 :           annotate_all_with_location (stmt_list, DECL_SOURCE_LOCATION (context));
    3631                 :        3195 :           bind = gimple_seq_first_stmt_as_a_bind (gimple_body (context));
    3632                 :        3195 :           gimple_seq_add_seq (&stmt_list, gimple_bind_body (bind));
    3633                 :        3195 :           gimple_bind_set_body (bind, stmt_list);
    3634                 :             :         }
    3635                 :             :     }
    3636                 :             : 
    3637                 :             :   /* If a chain_decl was created, then it needs to be registered with
    3638                 :             :      struct function so that it gets initialized from the static chain
    3639                 :             :      register at the beginning of the function.  */
    3640                 :       27366 :   sf = DECL_STRUCT_FUNCTION (root->context);
    3641                 :       27366 :   sf->static_chain_decl = root->chain_decl;
    3642                 :             : 
    3643                 :             :   /* Similarly for the non-local goto save area.  */
    3644                 :       27366 :   if (root->nl_goto_field)
    3645                 :             :     {
    3646                 :         373 :       sf->nonlocal_goto_save_area
    3647                 :         373 :         = get_frame_field (root, context, root->nl_goto_field, NULL);
    3648                 :         373 :       sf->has_nonlocal_label = 1;
    3649                 :             :     }
    3650                 :             : 
    3651                 :             :   /* Make sure all new local variables get inserted into the
    3652                 :             :      proper BIND_EXPR.  */
    3653                 :       27366 :   if (root->new_local_var_chain)
    3654                 :        3300 :     declare_vars (root->new_local_var_chain,
    3655                 :             :                   gimple_seq_first_stmt (gimple_body (root->context)),
    3656                 :             :                   false);
    3657                 :             : 
    3658                 :       27366 :   if (root->debug_var_chain)
    3659                 :             :     {
    3660                 :         346 :       tree debug_var;
    3661                 :         346 :       gbind *scope;
    3662                 :             : 
    3663                 :         346 :       remap_vla_decls (DECL_INITIAL (root->context), root);
    3664                 :             : 
    3665                 :        1017 :       for (debug_var = root->debug_var_chain; debug_var;
    3666                 :         671 :            debug_var = DECL_CHAIN (debug_var))
    3667                 :         677 :         if (variably_modified_type_p (TREE_TYPE (debug_var), NULL))
    3668                 :             :           break;
    3669                 :             : 
    3670                 :             :       /* If there are any debug decls with variable length types,
    3671                 :             :          remap those types using other debug_var_chain variables.  */
    3672                 :         346 :       if (debug_var)
    3673                 :             :         {
    3674                 :           6 :           struct nesting_copy_body_data id;
    3675                 :             : 
    3676                 :           6 :           memset (&id, 0, sizeof (id));
    3677                 :           6 :           id.cb.copy_decl = nesting_copy_decl;
    3678                 :           6 :           id.cb.decl_map = new hash_map<tree, tree>;
    3679                 :           6 :           id.root = root;
    3680                 :             : 
    3681                 :          36 :           for (; debug_var; debug_var = DECL_CHAIN (debug_var))
    3682                 :          30 :             if (variably_modified_type_p (TREE_TYPE (debug_var), NULL))
    3683                 :             :               {
    3684                 :           6 :                 tree type = TREE_TYPE (debug_var);
    3685                 :           6 :                 tree newt, t = type;
    3686                 :           6 :                 struct nesting_info *i;
    3687                 :             : 
    3688                 :          12 :                 for (i = root; i; i = i->outer)
    3689                 :          12 :                   if (variably_modified_type_p (type, i->context))
    3690                 :             :                     break;
    3691                 :             : 
    3692                 :           6 :                 if (i == NULL)
    3693                 :           0 :                   continue;
    3694                 :             : 
    3695                 :           6 :                 id.cb.src_fn = i->context;
    3696                 :           6 :                 id.cb.dst_fn = i->context;
    3697                 :           6 :                 id.cb.src_cfun = DECL_STRUCT_FUNCTION (root->context);
    3698                 :             : 
    3699                 :           6 :                 TREE_TYPE (debug_var) = newt = remap_type (type, &id.cb);
    3700                 :          12 :                 while (POINTER_TYPE_P (newt) && !TYPE_NAME (newt))
    3701                 :             :                   {
    3702                 :           6 :                     newt = TREE_TYPE (newt);
    3703                 :           6 :                     t = TREE_TYPE (t);
    3704                 :             :                   }
    3705                 :           6 :                 if (TYPE_NAME (newt)
    3706                 :           6 :                     && TREE_CODE (TYPE_NAME (newt)) == TYPE_DECL
    3707                 :           6 :                     && DECL_ORIGINAL_TYPE (TYPE_NAME (newt))
    3708                 :           6 :                     && newt != t
    3709                 :          12 :                     && TYPE_NAME (newt) == TYPE_NAME (t))
    3710                 :           6 :                   TYPE_NAME (newt) = remap_decl (TYPE_NAME (newt), &id.cb);
    3711                 :             :               }
    3712                 :             : 
    3713                 :          12 :           delete id.cb.decl_map;
    3714                 :             :         }
    3715                 :             : 
    3716                 :         346 :       scope = gimple_seq_first_stmt_as_a_bind (gimple_body (root->context));
    3717                 :         346 :       if (gimple_bind_block (scope))
    3718                 :         344 :         declare_vars (root->debug_var_chain, scope, true);
    3719                 :             :       else
    3720                 :           2 :         BLOCK_VARS (DECL_INITIAL (root->context))
    3721                 :           4 :           = chainon (BLOCK_VARS (DECL_INITIAL (root->context)),
    3722                 :             :                      root->debug_var_chain);
    3723                 :             :     }
    3724                 :             :   else
    3725                 :       27020 :     fixup_vla_decls (DECL_INITIAL (root->context));
    3726                 :             : 
    3727                 :             :   /* Fold the rewritten MEM_REF trees.  */
    3728                 :       27366 :   root->mem_refs->traverse<void *, fold_mem_refs> (NULL);
    3729                 :             : 
    3730                 :             :   /* Dump the translated tree function.  */
    3731                 :       27366 :   if (dump_file)
    3732                 :             :     {
    3733                 :           0 :       fputs ("\n\n", dump_file);
    3734                 :           0 :       dump_function_to_file (root->context, dump_file, dump_flags);
    3735                 :             :     }
    3736                 :             : }
    3737                 :             : 
    3738                 :             : static void
    3739                 :        8474 : finalize_nesting_tree (struct nesting_info *root)
    3740                 :             : {
    3741                 :        8474 :   struct nesting_info *n;
    3742                 :       71680 :   FOR_EACH_NEST_INFO (n, root)
    3743                 :       27366 :     finalize_nesting_tree_1 (n);
    3744                 :        8474 : }
    3745                 :             : 
    3746                 :             : /* Unnest the nodes and pass them to cgraph.  */
    3747                 :             : 
    3748                 :             : static void
    3749                 :       27366 : unnest_nesting_tree_1 (struct nesting_info *root)
    3750                 :             : {
    3751                 :       27366 :   struct cgraph_node *node = cgraph_node::get (root->context);
    3752                 :             : 
    3753                 :             :   /* For nested functions update the cgraph to reflect unnesting.
    3754                 :             :      We also delay finalizing of these functions up to this point.  */
    3755                 :       27366 :   if (nested_function_info::get (node)->origin)
    3756                 :             :     {
    3757                 :       18892 :        unnest_function (node);
    3758                 :       18892 :        if (!root->thunk_p)
    3759                 :       18892 :          cgraph_node::finalize_function (root->context, true);
    3760                 :             :     }
    3761                 :       27366 : }
    3762                 :             : 
    3763                 :             : static void
    3764                 :        8474 : unnest_nesting_tree (struct nesting_info *root)
    3765                 :             : {
    3766                 :        8474 :   struct nesting_info *n;
    3767                 :       71680 :   FOR_EACH_NEST_INFO (n, root)
    3768                 :       27366 :     unnest_nesting_tree_1 (n);
    3769                 :        8474 : }
    3770                 :             : 
    3771                 :             : /* Free the data structures allocated during this pass.  */
    3772                 :             : 
    3773                 :             : static void
    3774                 :        8474 : free_nesting_tree (struct nesting_info *root)
    3775                 :             : {
    3776                 :        8474 :   struct nesting_info *node, *next;
    3777                 :             : 
    3778                 :        8474 :   node = iter_nestinfo_start (root);
    3779                 :       27366 :   do
    3780                 :             :     {
    3781                 :       27366 :       next = iter_nestinfo_next (node);
    3782                 :       54732 :       delete node->var_map;
    3783                 :       54732 :       delete node->field_map;
    3784                 :       54732 :       delete node->mem_refs;
    3785                 :       27366 :       free (node);
    3786                 :       27366 :       node = next;
    3787                 :             :     }
    3788                 :       27366 :   while (node);
    3789                 :        8474 : }
    3790                 :             : 
    3791                 :             : /* Gimplify a function and all its nested functions.  */
    3792                 :             : static void
    3793                 :       27366 : gimplify_all_functions (struct cgraph_node *root)
    3794                 :             : {
    3795                 :       27366 :   struct cgraph_node *iter;
    3796                 :       27366 :   if (!gimple_body (root->decl))
    3797                 :       18892 :     gimplify_function_tree (root->decl);
    3798                 :       92516 :   for (iter = first_nested_function (root); iter;
    3799                 :       18892 :        iter = next_nested_function (iter))
    3800                 :       18892 :     if (!iter->thunk)
    3801                 :       18892 :       gimplify_all_functions (iter);
    3802                 :       27366 : }
    3803                 :             : 
    3804                 :             : /* Main entry point for this pass.  Process FNDECL and all of its nested
    3805                 :             :    subroutines and turn them into something less tightly bound.  */
    3806                 :             : 
    3807                 :             : void
    3808                 :        8474 : lower_nested_functions (tree fndecl)
    3809                 :             : {
    3810                 :        8474 :   struct cgraph_node *cgn;
    3811                 :        8474 :   struct nesting_info *root;
    3812                 :             : 
    3813                 :             :   /* If there are no nested functions, there's nothing to do.  */
    3814                 :        8474 :   cgn = cgraph_node::get (fndecl);
    3815                 :       16948 :   if (!first_nested_function (cgn))
    3816                 :             :     return;
    3817                 :             : 
    3818                 :        8474 :   gimplify_all_functions (cgn);
    3819                 :             : 
    3820                 :        8474 :   set_dump_file (dump_begin (TDI_nested, &dump_flags));
    3821                 :        8474 :   if (dump_file)
    3822                 :           0 :     fprintf (dump_file, "\n;; Function %s\n\n",
    3823                 :           0 :              lang_hooks.decl_printable_name (fndecl, 2));
    3824                 :             : 
    3825                 :        8474 :   bitmap_obstack_initialize (&nesting_info_bitmap_obstack);
    3826                 :        8474 :   root = create_nesting_tree (cgn);
    3827                 :             : 
    3828                 :        8474 :   walk_all_functions (convert_nonlocal_reference_stmt,
    3829                 :             :                       convert_nonlocal_reference_op,
    3830                 :             :                       root);
    3831                 :        8474 :   walk_all_functions (convert_local_reference_stmt,
    3832                 :             :                       convert_local_reference_op,
    3833                 :             :                       root);
    3834                 :        8474 :   walk_all_functions (convert_nl_goto_reference, NULL, root);
    3835                 :        8474 :   walk_all_functions (convert_nl_goto_receiver, NULL, root);
    3836                 :             : 
    3837                 :        8474 :   convert_all_function_calls (root);
    3838                 :        8474 :   finalize_nesting_tree (root);
    3839                 :        8474 :   unnest_nesting_tree (root);
    3840                 :             : 
    3841                 :        8474 :   free_nesting_tree (root);
    3842                 :        8474 :   bitmap_obstack_release (&nesting_info_bitmap_obstack);
    3843                 :             : 
    3844                 :        8474 :   if (dump_file)
    3845                 :             :     {
    3846                 :           0 :       dump_end (TDI_nested, dump_file);
    3847                 :           0 :       set_dump_file (NULL);
    3848                 :             :     }
    3849                 :             : }
    3850                 :             : 
    3851                 :             : #include "gt-tree-nested.h"
        

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.