LCOV - code coverage report
Current view: top level - gcc - gimplify.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 94.3 % 10149 9571
Test Date: 2025-03-15 13:07:15 Functions: 96.0 % 226 217
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* Tree lowering pass.  This pass converts the GENERIC functions-as-trees
       2                 :             :    tree representation into the GIMPLE form.
       3                 :             :    Copyright (C) 2002-2025 Free Software Foundation, Inc.
       4                 :             :    Major work done by Sebastian Pop <s.pop@laposte.net>,
       5                 :             :    Diego Novillo <dnovillo@redhat.com> and Jason Merrill <jason@redhat.com>.
       6                 :             : 
       7                 :             : This file is part of GCC.
       8                 :             : 
       9                 :             : GCC is free software; you can redistribute it and/or modify it under
      10                 :             : the terms of the GNU General Public License as published by the Free
      11                 :             : Software Foundation; either version 3, or (at your option) any later
      12                 :             : version.
      13                 :             : 
      14                 :             : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      15                 :             : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      16                 :             : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      17                 :             : for more details.
      18                 :             : 
      19                 :             : You should have received a copy of the GNU General Public License
      20                 :             : along with GCC; see the file COPYING3.  If not see
      21                 :             : <http://www.gnu.org/licenses/>.  */
      22                 :             : 
      23                 :             : #include "config.h"
      24                 :             : #include "system.h"
      25                 :             : #include "coretypes.h"
      26                 :             : #include "backend.h"
      27                 :             : #include "target.h"
      28                 :             : #include "rtl.h"
      29                 :             : #include "tree.h"
      30                 :             : #include "memmodel.h"
      31                 :             : #include "tm_p.h"
      32                 :             : #include "gimple.h"
      33                 :             : #include "gimple-predict.h"
      34                 :             : #include "tree-pass.h"                /* FIXME: only for PROP_gimple_any */
      35                 :             : #include "ssa.h"
      36                 :             : #include "cgraph.h"
      37                 :             : #include "tree-pretty-print.h"
      38                 :             : #include "diagnostic-core.h"
      39                 :             : #include "diagnostic.h"               /* For errorcount.  */
      40                 :             : #include "alias.h"
      41                 :             : #include "fold-const.h"
      42                 :             : #include "calls.h"
      43                 :             : #include "varasm.h"
      44                 :             : #include "stmt.h"
      45                 :             : #include "expr.h"
      46                 :             : #include "gimple-iterator.h"
      47                 :             : #include "gimple-fold.h"
      48                 :             : #include "tree-eh.h"
      49                 :             : #include "gimplify.h"
      50                 :             : #include "stor-layout.h"
      51                 :             : #include "print-tree.h"
      52                 :             : #include "tree-iterator.h"
      53                 :             : #include "tree-inline.h"
      54                 :             : #include "langhooks.h"
      55                 :             : #include "tree-cfg.h"
      56                 :             : #include "tree-ssa.h"
      57                 :             : #include "tree-hash-traits.h"
      58                 :             : #include "omp-general.h"
      59                 :             : #include "omp-low.h"
      60                 :             : #include "gimple-low.h"
      61                 :             : #include "gomp-constants.h"
      62                 :             : #include "splay-tree.h"
      63                 :             : #include "gimple-walk.h"
      64                 :             : #include "langhooks-def.h"    /* FIXME: for lhd_set_decl_assembler_name */
      65                 :             : #include "builtins.h"
      66                 :             : #include "stringpool.h"
      67                 :             : #include "attribs.h"
      68                 :             : #include "asan.h"
      69                 :             : #include "dbgcnt.h"
      70                 :             : #include "omp-offload.h"
      71                 :             : #include "context.h"
      72                 :             : #include "tree-nested.h"
      73                 :             : #include "gcc-urlifier.h"
      74                 :             : 
      75                 :             : /* Identifier for a basic condition, mapping it to other basic conditions of
      76                 :             :    its Boolean expression.  Basic conditions given the same uid (in the same
      77                 :             :    function) are parts of the same ANDIF/ORIF expression.  Used for condition
      78                 :             :    coverage.  */
      79                 :             : static unsigned nextconduid = 1;
      80                 :             : 
      81                 :             : /* Annotated gconds so that basic conditions in the same expression map to
      82                 :             :    the same uid.  This is used for condition coverage.  */
      83                 :             : static hash_map <tree, unsigned> *cond_uids;
      84                 :             : 
      85                 :             : /* Get a fresh identifier for a new condition expression.  This is used for
      86                 :             :    condition coverage.  */
      87                 :             : static unsigned
      88                 :     5509051 : next_cond_uid ()
      89                 :             : {
      90                 :     5509051 :   return nextconduid++;
      91                 :             : }
      92                 :             : 
      93                 :             : /* Reset the condition uid to the value it should have when compiling a new
      94                 :             :    function.  0 is already the default/untouched value, so start at non-zero.
      95                 :             :    A valid and set id should always be > 0.  This is used for condition
      96                 :             :    coverage.  */
      97                 :             : static void
      98                 :     2711611 : reset_cond_uid ()
      99                 :             : {
     100                 :     2711611 :   nextconduid = 1;
     101                 :           0 : }
     102                 :             : 
     103                 :             : /* Associate the condition STMT with the discriminator UID.  STMTs that are
     104                 :             :    broken down with ANDIF/ORIF from the same Boolean expression should be given
     105                 :             :    the same UID; 'if (a && b && c) { if (d || e) ... } ...' should yield the
     106                 :             :    { a: 1, b: 1, c: 1, d: 2, e: 2 } when gimplification is done.  This is used
     107                 :             :    for condition coverage.  */
     108                 :             : static void
     109                 :     1167367 : tree_associate_condition_with_expr (tree stmt, unsigned uid)
     110                 :             : {
     111                 :     1167367 :   if (!condition_coverage_flag)
     112                 :             :     return;
     113                 :             : 
     114                 :         527 :   if (!cond_uids)
     115                 :          65 :     cond_uids = new hash_map <tree, unsigned> ();
     116                 :             : 
     117                 :         527 :   cond_uids->put (stmt, uid);
     118                 :             : }
     119                 :             : 
     120                 :             : /* Hash set of poisoned variables in a bind expr.  */
     121                 :             : static hash_set<tree> *asan_poisoned_variables = NULL;
     122                 :             : 
     123                 :             : /* Hash set of already-resolved calls to OpenMP "declare variant"
     124                 :             :    functions.  A call can resolve to the original function and
     125                 :             :    we don't want to repeat the resolution multiple times.  */
     126                 :             : static hash_set<tree> *omp_resolved_variant_calls = NULL;
     127                 :             : 
     128                 :             : enum gimplify_omp_var_data
     129                 :             : {
     130                 :             :   GOVD_SEEN = 0x000001,
     131                 :             :   GOVD_EXPLICIT = 0x000002,
     132                 :             :   GOVD_SHARED = 0x000004,
     133                 :             :   GOVD_PRIVATE = 0x000008,
     134                 :             :   GOVD_FIRSTPRIVATE = 0x000010,
     135                 :             :   GOVD_LASTPRIVATE = 0x000020,
     136                 :             :   GOVD_REDUCTION = 0x000040,
     137                 :             :   GOVD_LOCAL = 0x00080,
     138                 :             :   GOVD_MAP = 0x000100,
     139                 :             :   GOVD_DEBUG_PRIVATE = 0x000200,
     140                 :             :   GOVD_PRIVATE_OUTER_REF = 0x000400,
     141                 :             :   GOVD_LINEAR = 0x000800,
     142                 :             :   GOVD_ALIGNED = 0x001000,
     143                 :             : 
     144                 :             :   /* Flag for GOVD_MAP: don't copy back.  */
     145                 :             :   GOVD_MAP_TO_ONLY = 0x002000,
     146                 :             : 
     147                 :             :   /* Flag for GOVD_LINEAR or GOVD_LASTPRIVATE: no outer reference.  */
     148                 :             :   GOVD_LINEAR_LASTPRIVATE_NO_OUTER = 0x004000,
     149                 :             : 
     150                 :             :   GOVD_MAP_0LEN_ARRAY = 0x008000,
     151                 :             : 
     152                 :             :   /* Flag for GOVD_MAP, if it is always, to or always, tofrom mapping.  */
     153                 :             :   GOVD_MAP_ALWAYS_TO = 0x010000,
     154                 :             : 
     155                 :             :   /* Flag for shared vars that are or might be stored to in the region.  */
     156                 :             :   GOVD_WRITTEN = 0x020000,
     157                 :             : 
     158                 :             :   /* Flag for GOVD_MAP, if it is a forced mapping.  */
     159                 :             :   GOVD_MAP_FORCE = 0x040000,
     160                 :             : 
     161                 :             :   /* Flag for GOVD_MAP: must be present already.  */
     162                 :             :   GOVD_MAP_FORCE_PRESENT = 0x080000,
     163                 :             : 
     164                 :             :   /* Flag for GOVD_MAP: only allocate.  */
     165                 :             :   GOVD_MAP_ALLOC_ONLY = 0x100000,
     166                 :             : 
     167                 :             :   /* Flag for GOVD_MAP: only copy back.  */
     168                 :             :   GOVD_MAP_FROM_ONLY = 0x200000,
     169                 :             : 
     170                 :             :   GOVD_NONTEMPORAL = 0x400000,
     171                 :             : 
     172                 :             :   /* Flag for GOVD_LASTPRIVATE: conditional modifier.  */
     173                 :             :   GOVD_LASTPRIVATE_CONDITIONAL = 0x800000,
     174                 :             : 
     175                 :             :   GOVD_CONDTEMP = 0x1000000,
     176                 :             : 
     177                 :             :   /* Flag for GOVD_REDUCTION: inscan seen in {in,ex}clusive clause.  */
     178                 :             :   GOVD_REDUCTION_INSCAN = 0x2000000,
     179                 :             : 
     180                 :             :   /* Flag for GOVD_FIRSTPRIVATE: OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT.  */
     181                 :             :   GOVD_FIRSTPRIVATE_IMPLICIT = 0x4000000,
     182                 :             : 
     183                 :             :   GOVD_DATA_SHARE_CLASS = (GOVD_SHARED | GOVD_PRIVATE | GOVD_FIRSTPRIVATE
     184                 :             :                            | GOVD_LASTPRIVATE | GOVD_REDUCTION | GOVD_LINEAR
     185                 :             :                            | GOVD_LOCAL)
     186                 :             : };
     187                 :             : 
     188                 :             : 
     189                 :             : enum omp_region_type
     190                 :             : {
     191                 :             :   ORT_WORKSHARE = 0x00,
     192                 :             :   ORT_TASKGROUP = 0x01,
     193                 :             :   ORT_DISPATCH  = 0x02,
     194                 :             :   ORT_SIMD      = 0x04,
     195                 :             : 
     196                 :             :   ORT_PARALLEL  = 0x08,
     197                 :             :   ORT_COMBINED_PARALLEL = ORT_PARALLEL | 1,
     198                 :             : 
     199                 :             :   ORT_TASK      = 0x10,
     200                 :             :   ORT_UNTIED_TASK = ORT_TASK | 1,
     201                 :             :   ORT_TASKLOOP  = ORT_TASK | 2,
     202                 :             :   ORT_UNTIED_TASKLOOP = ORT_UNTIED_TASK | 2,
     203                 :             : 
     204                 :             :   ORT_TEAMS     = 0x20,
     205                 :             :   ORT_COMBINED_TEAMS = ORT_TEAMS | 1,
     206                 :             :   ORT_HOST_TEAMS = ORT_TEAMS | 2,
     207                 :             :   ORT_COMBINED_HOST_TEAMS = ORT_COMBINED_TEAMS | 2,
     208                 :             : 
     209                 :             :   /* Data region.  */
     210                 :             :   ORT_TARGET_DATA = 0x40,
     211                 :             : 
     212                 :             :   /* Data region with offloading.  */
     213                 :             :   ORT_TARGET    = 0x80,
     214                 :             :   ORT_COMBINED_TARGET = ORT_TARGET | 1,
     215                 :             :   ORT_IMPLICIT_TARGET = ORT_TARGET | 2,
     216                 :             : 
     217                 :             :   /* OpenACC variants.  */
     218                 :             :   ORT_ACC       = 0x100,  /* A generic OpenACC region.  */
     219                 :             :   ORT_ACC_DATA  = ORT_ACC | ORT_TARGET_DATA, /* Data construct.  */
     220                 :             :   ORT_ACC_PARALLEL = ORT_ACC | ORT_TARGET,  /* Parallel construct */
     221                 :             :   ORT_ACC_KERNELS  = ORT_ACC | ORT_TARGET | 2,  /* Kernels construct.  */
     222                 :             :   ORT_ACC_SERIAL   = ORT_ACC | ORT_TARGET | 4,  /* Serial construct.  */
     223                 :             :   ORT_ACC_HOST_DATA = ORT_ACC | ORT_TARGET_DATA | 2,  /* Host data.  */
     224                 :             : 
     225                 :             :   /* Dummy OpenMP region, used to disable expansion of
     226                 :             :      DECL_VALUE_EXPRs in taskloop pre body.  */
     227                 :             :   ORT_NONE      = 0x200
     228                 :             : };
     229                 :             : 
     230                 :             : /* Gimplify hashtable helper.  */
     231                 :             : 
     232                 :             : struct gimplify_hasher : free_ptr_hash <elt_t>
     233                 :             : {
     234                 :             :   static inline hashval_t hash (const elt_t *);
     235                 :             :   static inline bool equal (const elt_t *, const elt_t *);
     236                 :             : };
     237                 :             : 
     238                 :             : struct gimplify_ctx
     239                 :             : {
     240                 :             :   struct gimplify_ctx *prev_context;
     241                 :             : 
     242                 :             :   vec<gbind *> bind_expr_stack;
     243                 :             :   tree temps;
     244                 :             :   gimple_seq conditional_cleanups;
     245                 :             :   tree exit_label;
     246                 :             :   tree return_temp;
     247                 :             : 
     248                 :             :   vec<tree> case_labels;
     249                 :             :   hash_set<tree> *live_switch_vars;
     250                 :             :   /* The formal temporary table.  Should this be persistent?  */
     251                 :             :   hash_table<gimplify_hasher> *temp_htab;
     252                 :             : 
     253                 :             :   int conditions;
     254                 :             :   unsigned into_ssa : 1;
     255                 :             :   unsigned allow_rhs_cond_expr : 1;
     256                 :             :   unsigned in_cleanup_point_expr : 1;
     257                 :             :   unsigned keep_stack : 1;
     258                 :             :   unsigned save_stack : 1;
     259                 :             :   unsigned in_switch_expr : 1;
     260                 :             :   unsigned in_handler_expr : 1;
     261                 :             : };
     262                 :             : 
     263                 :             : enum gimplify_defaultmap_kind
     264                 :             : {
     265                 :             :   GDMK_SCALAR,
     266                 :             :   GDMK_SCALAR_TARGET, /* w/ Fortran's target attr, implicit mapping, only.  */
     267                 :             :   GDMK_AGGREGATE,
     268                 :             :   GDMK_ALLOCATABLE,
     269                 :             :   GDMK_POINTER
     270                 :             : };
     271                 :             : 
     272                 :             : struct gimplify_omp_ctx
     273                 :             : {
     274                 :             :   struct gimplify_omp_ctx *outer_context;
     275                 :             :   splay_tree variables;
     276                 :             :   hash_set<tree> *privatized_types;
     277                 :             :   tree clauses;
     278                 :             :   /* Iteration variables in an OMP_FOR.  */
     279                 :             :   vec<tree> loop_iter_var;
     280                 :             :   location_t location;
     281                 :             :   enum omp_clause_default_kind default_kind;
     282                 :             :   enum omp_region_type region_type;
     283                 :             :   enum tree_code code;
     284                 :             :   bool combined_loop;
     285                 :             :   bool distribute;
     286                 :             :   bool target_firstprivatize_array_bases;
     287                 :             :   bool add_safelen1;
     288                 :             :   bool order_concurrent;
     289                 :             :   bool has_depend;
     290                 :             :   bool in_for_exprs;
     291                 :             :   bool in_call_args;
     292                 :             :   int defaultmap[5];
     293                 :             : };
     294                 :             : 
     295                 :             : static struct gimplify_ctx *gimplify_ctxp;
     296                 :             : static struct gimplify_omp_ctx *gimplify_omp_ctxp;
     297                 :             : static bool in_omp_construct;
     298                 :             : 
     299                 :             : /* Forward declaration.  */
     300                 :             : static enum gimplify_status gimplify_compound_expr (tree *, gimple_seq *, bool);
     301                 :             : static hash_map<tree, tree> *oacc_declare_returns;
     302                 :             : static enum gimplify_status gimplify_expr (tree *, gimple_seq *, gimple_seq *,
     303                 :             :                                            bool (*) (tree), fallback_t, bool);
     304                 :             : static void prepare_gimple_addressable (tree *, gimple_seq *);
     305                 :             : 
     306                 :             : /* Shorter alias name for the above function for use in gimplify.cc
     307                 :             :    only.  */
     308                 :             : 
     309                 :             : static inline void
     310                 :    88368975 : gimplify_seq_add_stmt (gimple_seq *seq_p, gimple *gs)
     311                 :             : {
     312                 :    88368975 :   gimple_seq_add_stmt_without_update (seq_p, gs);
     313                 :     6122449 : }
     314                 :             : 
     315                 :             : /* Append sequence SRC to the end of sequence *DST_P.  If *DST_P is
     316                 :             :    NULL, a new sequence is allocated.   This function is
     317                 :             :    similar to gimple_seq_add_seq, but does not scan the operands.
     318                 :             :    During gimplification, we need to manipulate statement sequences
     319                 :             :    before the def/use vectors have been constructed.  */
     320                 :             : 
     321                 :             : static void
     322                 :     8916250 : gimplify_seq_add_seq (gimple_seq *dst_p, gimple_seq src)
     323                 :             : {
     324                 :     8916250 :   gimple_stmt_iterator si;
     325                 :             : 
     326                 :     8916250 :   if (src == NULL)
     327                 :     3826853 :     return;
     328                 :             : 
     329                 :     5089397 :   si = gsi_last (*dst_p);
     330                 :     5089397 :   gsi_insert_seq_after_without_update (&si, src, GSI_NEW_STMT);
     331                 :             : }
     332                 :             : 
     333                 :             : 
     334                 :             : /* Pointer to a list of allocated gimplify_ctx structs to be used for pushing
     335                 :             :    and popping gimplify contexts.  */
     336                 :             : 
     337                 :             : static struct gimplify_ctx *ctx_pool = NULL;
     338                 :             : 
     339                 :             : /* Return a gimplify context struct from the pool.  */
     340                 :             : 
     341                 :             : static inline struct gimplify_ctx *
     342                 :     8343965 : ctx_alloc (void)
     343                 :             : {
     344                 :     8343965 :   struct gimplify_ctx * c = ctx_pool;
     345                 :             : 
     346                 :     8343965 :   if (c)
     347                 :     8082993 :     ctx_pool = c->prev_context;
     348                 :             :   else
     349                 :      260972 :     c = XNEW (struct gimplify_ctx);
     350                 :             : 
     351                 :     8343965 :   memset (c, '\0', sizeof (*c));
     352                 :     8343965 :   return c;
     353                 :             : }
     354                 :             : 
     355                 :             : /* Put gimplify context C back into the pool.  */
     356                 :             : 
     357                 :             : static inline void
     358                 :     8343961 : ctx_free (struct gimplify_ctx *c)
     359                 :             : {
     360                 :     8343961 :   c->prev_context = ctx_pool;
     361                 :     8343961 :   ctx_pool = c;
     362                 :             : }
     363                 :             : 
     364                 :             : /* Free allocated ctx stack memory.  */
     365                 :             : 
     366                 :             : void
     367                 :      227030 : free_gimplify_stack (void)
     368                 :             : {
     369                 :      227030 :   struct gimplify_ctx *c;
     370                 :             : 
     371                 :      457426 :   while ((c = ctx_pool))
     372                 :             :     {
     373                 :      230396 :       ctx_pool = c->prev_context;
     374                 :      230396 :       free (c);
     375                 :             :     }
     376                 :      227030 : }
     377                 :             : 
     378                 :             : 
     379                 :             : /* Set up a context for the gimplifier.  */
     380                 :             : 
     381                 :             : void
     382                 :     8343965 : push_gimplify_context (bool in_ssa, bool rhs_cond_ok)
     383                 :             : {
     384                 :     8343965 :   struct gimplify_ctx *c = ctx_alloc ();
     385                 :             : 
     386                 :     8343965 :   c->prev_context = gimplify_ctxp;
     387                 :     8343965 :   gimplify_ctxp = c;
     388                 :     8343965 :   gimplify_ctxp->into_ssa = in_ssa;
     389                 :     8343965 :   gimplify_ctxp->allow_rhs_cond_expr = rhs_cond_ok;
     390                 :     8343965 : }
     391                 :             : 
     392                 :             : /* Tear down a context for the gimplifier.  If BODY is non-null, then
     393                 :             :    put the temporaries into the outer BIND_EXPR.  Otherwise, put them
     394                 :             :    in the local_decls.
     395                 :             : 
     396                 :             :    BODY is not a sequence, but the first tuple in a sequence.  */
     397                 :             : 
     398                 :             : void
     399                 :     8343961 : pop_gimplify_context (gimple *body)
     400                 :             : {
     401                 :     8343961 :   struct gimplify_ctx *c = gimplify_ctxp;
     402                 :             : 
     403                 :     8343961 :   gcc_assert (c
     404                 :             :               && (!c->bind_expr_stack.exists ()
     405                 :             :                   || c->bind_expr_stack.is_empty ()));
     406                 :     8343961 :   c->bind_expr_stack.release ();
     407                 :     8343961 :   gimplify_ctxp = c->prev_context;
     408                 :             : 
     409                 :     8343961 :   if (body)
     410                 :     2834418 :     declare_vars (c->temps, body, false);
     411                 :             :   else
     412                 :     5509543 :     record_vars (c->temps);
     413                 :             : 
     414                 :     8343961 :   delete c->temp_htab;
     415                 :     8343961 :   c->temp_htab = NULL;
     416                 :     8343961 :   ctx_free (c);
     417                 :     8343961 : }
     418                 :             : 
     419                 :             : /* Push a GIMPLE_BIND tuple onto the stack of bindings.  */
     420                 :             : 
     421                 :             : static void
     422                 :     5750961 : gimple_push_bind_expr (gbind *bind_stmt)
     423                 :             : {
     424                 :     5750961 :   gimplify_ctxp->bind_expr_stack.reserve (8);
     425                 :     5750961 :   gimplify_ctxp->bind_expr_stack.safe_push (bind_stmt);
     426                 :     5750961 : }
     427                 :             : 
     428                 :             : /* Pop the first element off the stack of bindings.  */
     429                 :             : 
     430                 :             : static void
     431                 :     5750961 : gimple_pop_bind_expr (void)
     432                 :             : {
     433                 :           0 :   gimplify_ctxp->bind_expr_stack.pop ();
     434                 :           0 : }
     435                 :             : 
     436                 :             : /* Return the first element of the stack of bindings.  */
     437                 :             : 
     438                 :             : gbind *
     439                 :           0 : gimple_current_bind_expr (void)
     440                 :             : {
     441                 :           0 :   return gimplify_ctxp->bind_expr_stack.last ();
     442                 :             : }
     443                 :             : 
     444                 :             : /* Return the stack of bindings created during gimplification.  */
     445                 :             : 
     446                 :             : vec<gbind *>
     447                 :         331 : gimple_bind_expr_stack (void)
     448                 :             : {
     449                 :         331 :   return gimplify_ctxp->bind_expr_stack;
     450                 :             : }
     451                 :             : 
     452                 :             : /* Return true iff there is a COND_EXPR between us and the innermost
     453                 :             :    CLEANUP_POINT_EXPR.  This info is used by gimple_push_cleanup.  */
     454                 :             : 
     455                 :             : static bool
     456                 :     2580388 : gimple_conditional_context (void)
     457                 :             : {
     458                 :     2580388 :   return gimplify_ctxp->conditions > 0;
     459                 :             : }
     460                 :             : 
     461                 :             : /* Note that we've entered a COND_EXPR.  */
     462                 :             : 
     463                 :             : static void
     464                 :     5509486 : gimple_push_condition (void)
     465                 :             : {
     466                 :             : #ifdef ENABLE_GIMPLE_CHECKING
     467                 :     5509486 :   if (gimplify_ctxp->conditions == 0)
     468                 :     3609350 :     gcc_assert (gimple_seq_empty_p (gimplify_ctxp->conditional_cleanups));
     469                 :             : #endif
     470                 :     5509486 :   ++(gimplify_ctxp->conditions);
     471                 :     5509486 : }
     472                 :             : 
     473                 :             : /* Note that we've left a COND_EXPR.  If we're back at unconditional scope
     474                 :             :    now, add any conditional cleanups we've seen to the prequeue.  */
     475                 :             : 
     476                 :             : static void
     477                 :     5509486 : gimple_pop_condition (gimple_seq *pre_p)
     478                 :             : {
     479                 :     5509486 :   int conds = --(gimplify_ctxp->conditions);
     480                 :             : 
     481                 :     5509486 :   gcc_assert (conds >= 0);
     482                 :     5509486 :   if (conds == 0)
     483                 :             :     {
     484                 :     3609350 :       gimplify_seq_add_seq (pre_p, gimplify_ctxp->conditional_cleanups);
     485                 :     3609350 :       gimplify_ctxp->conditional_cleanups = NULL;
     486                 :             :     }
     487                 :     5509486 : }
     488                 :             : 
     489                 :             : /* A stable comparison routine for use with splay trees and DECLs.  */
     490                 :             : 
     491                 :             : static int
     492                 :    17278228 : splay_tree_compare_decl_uid (splay_tree_key xa, splay_tree_key xb)
     493                 :             : {
     494                 :    17278228 :   tree a = (tree) xa;
     495                 :    17278228 :   tree b = (tree) xb;
     496                 :             : 
     497                 :    17278228 :   return DECL_UID (a) - DECL_UID (b);
     498                 :             : }
     499                 :             : 
     500                 :             : /* Create a new omp construct that deals with variable remapping.  */
     501                 :             : 
     502                 :             : static struct gimplify_omp_ctx *
     503                 :      131286 : new_omp_context (enum omp_region_type region_type)
     504                 :             : {
     505                 :      131286 :   struct gimplify_omp_ctx *c;
     506                 :             : 
     507                 :      131286 :   c = XCNEW (struct gimplify_omp_ctx);
     508                 :      131286 :   c->outer_context = gimplify_omp_ctxp;
     509                 :      131286 :   c->variables = splay_tree_new (splay_tree_compare_decl_uid, 0, 0);
     510                 :      131286 :   c->privatized_types = new hash_set<tree>;
     511                 :      131286 :   c->location = input_location;
     512                 :      131286 :   c->region_type = region_type;
     513                 :      131286 :   if ((region_type & ORT_TASK) == 0)
     514                 :      125681 :     c->default_kind = OMP_CLAUSE_DEFAULT_SHARED;
     515                 :             :   else
     516                 :        5605 :     c->default_kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
     517                 :      131286 :   c->defaultmap[GDMK_SCALAR] = GOVD_MAP;
     518                 :      131286 :   c->defaultmap[GDMK_SCALAR_TARGET] = GOVD_MAP;
     519                 :      131286 :   c->defaultmap[GDMK_AGGREGATE] = GOVD_MAP;
     520                 :      131286 :   c->defaultmap[GDMK_ALLOCATABLE] = GOVD_MAP;
     521                 :      131286 :   c->defaultmap[GDMK_POINTER] = GOVD_MAP;
     522                 :             : 
     523                 :      131286 :   return c;
     524                 :             : }
     525                 :             : 
     526                 :             : /* Destroy an omp construct that deals with variable remapping.  */
     527                 :             : 
     528                 :             : static void
     529                 :      131286 : delete_omp_context (struct gimplify_omp_ctx *c)
     530                 :             : {
     531                 :      131286 :   splay_tree_delete (c->variables);
     532                 :      262572 :   delete c->privatized_types;
     533                 :      131286 :   c->loop_iter_var.release ();
     534                 :      131286 :   XDELETE (c);
     535                 :      131286 : }
     536                 :             : 
     537                 :             : static void omp_add_variable (struct gimplify_omp_ctx *, tree, unsigned int);
     538                 :             : static bool omp_notice_variable (struct gimplify_omp_ctx *, tree, bool);
     539                 :             : 
     540                 :             : /* Both gimplify the statement T and append it to *SEQ_P.  This function
     541                 :             :    behaves exactly as gimplify_stmt, but you don't have to pass T as a
     542                 :             :    reference.  */
     543                 :             : 
     544                 :             : void
     545                 :    36479724 : gimplify_and_add (tree t, gimple_seq *seq_p)
     546                 :             : {
     547                 :    36479724 :   gimplify_stmt (&t, seq_p);
     548                 :    36479724 : }
     549                 :             : 
     550                 :             : /* Gimplify statement T into sequence *SEQ_P, and return the first
     551                 :             :    tuple in the sequence of generated tuples for this statement.
     552                 :             :    Return NULL if gimplifying T produced no tuples.  */
     553                 :             : 
     554                 :             : static gimple *
     555                 :      103926 : gimplify_and_return_first (tree t, gimple_seq *seq_p)
     556                 :             : {
     557                 :      103926 :   gimple_stmt_iterator last = gsi_last (*seq_p);
     558                 :             : 
     559                 :      103926 :   gimplify_and_add (t, seq_p);
     560                 :             : 
     561                 :      103926 :   if (!gsi_end_p (last))
     562                 :             :     {
     563                 :        4863 :       gsi_next (&last);
     564                 :        4863 :       return gsi_stmt (last);
     565                 :             :     }
     566                 :             :   else
     567                 :       99063 :     return gimple_seq_first_stmt (*seq_p);
     568                 :             : }
     569                 :             : 
     570                 :             : /* Returns true iff T is a valid RHS for an assignment to an un-renamed
     571                 :             :    LHS, or for a call argument.  */
     572                 :             : 
     573                 :             : static bool
     574                 :      234456 : is_gimple_mem_rhs (tree t)
     575                 :             : {
     576                 :             :   /* If we're dealing with a renamable type, either source or dest must be
     577                 :             :      a renamed variable.  */
     578                 :      234456 :   if (is_gimple_reg_type (TREE_TYPE (t)))
     579                 :      231136 :     return is_gimple_val (t);
     580                 :             :   else
     581                 :        3320 :     return is_gimple_val (t) || is_gimple_lvalue (t);
     582                 :             : }
     583                 :             : 
     584                 :             : /* Return true if T is a CALL_EXPR or an expression that can be
     585                 :             :    assigned to a temporary.  Note that this predicate should only be
     586                 :             :    used during gimplification.  See the rationale for this in
     587                 :             :    gimplify_modify_expr.  */
     588                 :             : 
     589                 :             : static bool
     590                 :    93737496 : is_gimple_reg_rhs_or_call (tree t)
     591                 :             : {
     592                 :    68753581 :   return (get_gimple_rhs_class (TREE_CODE (t)) != GIMPLE_INVALID_RHS
     593                 :    93737496 :           || TREE_CODE (t) == CALL_EXPR);
     594                 :             : }
     595                 :             : 
     596                 :             : /* Return true if T is a valid memory RHS or a CALL_EXPR.  Note that
     597                 :             :    this predicate should only be used during gimplification.  See the
     598                 :             :    rationale for this in gimplify_modify_expr.  */
     599                 :             : 
     600                 :             : static bool
     601                 :    13545533 : is_gimple_mem_rhs_or_call (tree t)
     602                 :             : {
     603                 :             :   /* If we're dealing with a renamable type, either source or dest must be
     604                 :             :      a renamed variable.  */
     605                 :    13545533 :   if (is_gimple_reg_type (TREE_TYPE (t)))
     606                 :    10469111 :     return is_gimple_val (t);
     607                 :             :   else
     608                 :     3076422 :     return (is_gimple_val (t)
     609                 :     1526959 :             || is_gimple_lvalue (t)
     610                 :     1028988 :             || (TREE_CODE (t) == CONSTRUCTOR && CONSTRUCTOR_NELTS (t) == 0)
     611                 :     4104952 :             || TREE_CODE (t) == CALL_EXPR);
     612                 :             : }
     613                 :             : 
     614                 :             : /* Create a temporary with a name derived from VAL.  Subroutine of
     615                 :             :    lookup_tmp_var; nobody else should call this function.  */
     616                 :             : 
     617                 :             : static inline tree
     618                 :     2062903 : create_tmp_from_val (tree val)
     619                 :             : {
     620                 :             :   /* Drop all qualifiers and address-space information from the value type.  */
     621                 :     2062903 :   tree type = TYPE_MAIN_VARIANT (TREE_TYPE (val));
     622                 :     2062903 :   tree var = create_tmp_var (type, get_name (val));
     623                 :     2062903 :   return var;
     624                 :             : }
     625                 :             : 
     626                 :             : /* Create a temporary to hold the value of VAL.  If IS_FORMAL, try to reuse
     627                 :             :    an existing expression temporary.  If NOT_GIMPLE_REG, mark it as such.  */
     628                 :             : 
     629                 :             : static tree
     630                 :     2275909 : lookup_tmp_var (tree val, bool is_formal, bool not_gimple_reg)
     631                 :             : {
     632                 :     2275909 :   tree ret;
     633                 :             : 
     634                 :             :   /* We cannot mark a formal temporary with DECL_NOT_GIMPLE_REG_P.  */
     635                 :     2275909 :   gcc_assert (!is_formal || !not_gimple_reg);
     636                 :             : 
     637                 :             :   /* If not optimizing, never really reuse a temporary.  local-alloc
     638                 :             :      won't allocate any variable that is used in more than one basic
     639                 :             :      block, which means it will go into memory, causing much extra
     640                 :             :      work in reload and final and poorer code generation, outweighing
     641                 :             :      the extra memory allocation here.  */
     642                 :     2275909 :   if (!optimize || !is_formal || TREE_SIDE_EFFECTS (val))
     643                 :             :     {
     644                 :     1054580 :       ret = create_tmp_from_val (val);
     645                 :     1054580 :       DECL_NOT_GIMPLE_REG_P (ret) = not_gimple_reg;
     646                 :             :     }
     647                 :             :   else
     648                 :             :     {
     649                 :     1221329 :       elt_t elt, *elt_p;
     650                 :     1221329 :       elt_t **slot;
     651                 :             : 
     652                 :     1221329 :       elt.val = val;
     653                 :     1221329 :       if (!gimplify_ctxp->temp_htab)
     654                 :      374772 :         gimplify_ctxp->temp_htab = new hash_table<gimplify_hasher> (1000);
     655                 :     1221329 :       slot = gimplify_ctxp->temp_htab->find_slot (&elt, INSERT);
     656                 :     1221329 :       if (*slot == NULL)
     657                 :             :         {
     658                 :     1008323 :           elt_p = XNEW (elt_t);
     659                 :     1008323 :           elt_p->val = val;
     660                 :     1008323 :           elt_p->temp = ret = create_tmp_from_val (val);
     661                 :     1008323 :           *slot = elt_p;
     662                 :             :         }
     663                 :             :       else
     664                 :             :         {
     665                 :      213006 :           elt_p = *slot;
     666                 :      213006 :           ret = elt_p->temp;
     667                 :             :         }
     668                 :             :     }
     669                 :             : 
     670                 :     2275909 :   return ret;
     671                 :             : }
     672                 :             : 
     673                 :             : /* Helper for get_formal_tmp_var and get_initialized_tmp_var.  */
     674                 :             : 
     675                 :             : static tree
     676                 :    25501605 : internal_get_tmp_var (tree val, gimple_seq *pre_p, gimple_seq *post_p,
     677                 :             :                       bool is_formal, bool allow_ssa, bool not_gimple_reg)
     678                 :             : {
     679                 :    25501605 :   tree t, mod;
     680                 :             : 
     681                 :             :   /* Notice that we explicitly allow VAL to be a CALL_EXPR so that we
     682                 :             :      can create an INIT_EXPR and convert it into a GIMPLE_CALL below.  */
     683                 :    25501605 :   gimplify_expr (&val, pre_p, post_p, is_gimple_reg_rhs_or_call,
     684                 :             :                  fb_rvalue);
     685                 :             : 
     686                 :    25501605 :   if (allow_ssa
     687                 :    25253362 :       && gimplify_ctxp->into_ssa
     688                 :    49371378 :       && is_gimple_reg_type (TREE_TYPE (val)))
     689                 :             :     {
     690                 :    23225697 :       t = make_ssa_name (TYPE_MAIN_VARIANT (TREE_TYPE (val)));
     691                 :    23225697 :       if (! gimple_in_ssa_p (cfun))
     692                 :             :         {
     693                 :    20103425 :           const char *name = get_name (val);
     694                 :    20103425 :           if (name)
     695                 :     6645180 :             SET_SSA_NAME_VAR_OR_IDENTIFIER (t, create_tmp_var_name (name));
     696                 :             :         }
     697                 :             :     }
     698                 :             :   else
     699                 :     2275908 :     t = lookup_tmp_var (val, is_formal, not_gimple_reg);
     700                 :             : 
     701                 :    25501605 :   mod = build2 (INIT_EXPR, TREE_TYPE (t), t, unshare_expr (val));
     702                 :             : 
     703                 :    25501605 :   SET_EXPR_LOCATION (mod, EXPR_LOC_OR_LOC (val, input_location));
     704                 :             : 
     705                 :             :   /* gimplify_modify_expr might want to reduce this further.  */
     706                 :    25501605 :   gimplify_and_add (mod, pre_p);
     707                 :    25501605 :   ggc_free (mod);
     708                 :             : 
     709                 :             :   /* If we failed to gimplify VAL then we can end up with the temporary
     710                 :             :      SSA name not having a definition.  In this case return a decl.  */
     711                 :    25501605 :   if (TREE_CODE (t) == SSA_NAME && ! SSA_NAME_DEF_STMT (t))
     712                 :           1 :     return lookup_tmp_var (val, is_formal, not_gimple_reg);
     713                 :             : 
     714                 :             :   return t;
     715                 :             : }
     716                 :             : 
     717                 :             : /* Return a formal temporary variable initialized with VAL.  PRE_P is as
     718                 :             :    in gimplify_expr.  Only use this function if:
     719                 :             : 
     720                 :             :    1) The value of the unfactored expression represented by VAL will not
     721                 :             :       change between the initialization and use of the temporary, and
     722                 :             :    2) The temporary will not be otherwise modified.
     723                 :             : 
     724                 :             :    For instance, #1 means that this is inappropriate for SAVE_EXPR temps,
     725                 :             :    and #2 means it is inappropriate for && temps.
     726                 :             : 
     727                 :             :    For other cases, use get_initialized_tmp_var instead.  */
     728                 :             : 
     729                 :             : tree
     730                 :    25022505 : get_formal_tmp_var (tree val, gimple_seq *pre_p)
     731                 :             : {
     732                 :    25022505 :   return internal_get_tmp_var (val, pre_p, NULL, true, true, false);
     733                 :             : }
     734                 :             : 
     735                 :             : /* Return a temporary variable initialized with VAL.  PRE_P and POST_P
     736                 :             :    are as in gimplify_expr.  */
     737                 :             : 
     738                 :             : tree
     739                 :      467106 : get_initialized_tmp_var (tree val, gimple_seq *pre_p,
     740                 :             :                          gimple_seq *post_p /* = NULL */,
     741                 :             :                          bool allow_ssa /* = true */)
     742                 :             : {
     743                 :      467106 :   return internal_get_tmp_var (val, pre_p, post_p, false, allow_ssa, false);
     744                 :             : }
     745                 :             : 
     746                 :             : /* Declare all the variables in VARS in SCOPE.  If DEBUG_INFO is true,
     747                 :             :    generate debug info for them; otherwise don't.  */
     748                 :             : 
     749                 :             : void
     750                 :     2842088 : declare_vars (tree vars, gimple *gs, bool debug_info)
     751                 :             : {
     752                 :     2842088 :   tree last = vars;
     753                 :     2842088 :   if (last)
     754                 :             :     {
     755                 :     1775099 :       tree temps, block;
     756                 :             : 
     757                 :     1775099 :       gbind *scope = as_a <gbind *> (gs);
     758                 :             : 
     759                 :     1775099 :       temps = nreverse (last);
     760                 :             : 
     761                 :     1775099 :       block = gimple_bind_block (scope);
     762                 :     1775099 :       gcc_assert (!block || TREE_CODE (block) == BLOCK);
     763                 :     1775099 :       if (!block || !debug_info)
     764                 :             :         {
     765                 :     1771553 :           DECL_CHAIN (last) = gimple_bind_vars (scope);
     766                 :     1771553 :           gimple_bind_set_vars (scope, temps);
     767                 :             :         }
     768                 :             :       else
     769                 :             :         {
     770                 :             :           /* We need to attach the nodes both to the BIND_EXPR and to its
     771                 :             :              associated BLOCK for debugging purposes.  The key point here
     772                 :             :              is that the BLOCK_VARS of the BIND_EXPR_BLOCK of a BIND_EXPR
     773                 :             :              is a subchain of the BIND_EXPR_VARS of the BIND_EXPR.  */
     774                 :        3546 :           if (BLOCK_VARS (block))
     775                 :        3353 :             BLOCK_VARS (block) = chainon (BLOCK_VARS (block), temps);
     776                 :             :           else
     777                 :             :             {
     778                 :         193 :               gimple_bind_set_vars (scope,
     779                 :             :                                     chainon (gimple_bind_vars (scope), temps));
     780                 :         193 :               BLOCK_VARS (block) = temps;
     781                 :             :             }
     782                 :             :         }
     783                 :             :     }
     784                 :     2842088 : }
     785                 :             : 
     786                 :             : /* For VAR a VAR_DECL of variable size, try to find a constant upper bound
     787                 :             :    for the size and adjust DECL_SIZE/DECL_SIZE_UNIT accordingly.  Abort if
     788                 :             :    no such upper bound can be obtained.  */
     789                 :             : 
     790                 :             : static void
     791                 :           0 : force_constant_size (tree var)
     792                 :             : {
     793                 :             :   /* The only attempt we make is by querying the maximum size of objects
     794                 :             :      of the variable's type.  */
     795                 :             : 
     796                 :           0 :   HOST_WIDE_INT max_size;
     797                 :             : 
     798                 :           0 :   gcc_assert (VAR_P (var));
     799                 :             : 
     800                 :           0 :   max_size = max_int_size_in_bytes (TREE_TYPE (var));
     801                 :             : 
     802                 :           0 :   gcc_assert (max_size >= 0);
     803                 :             : 
     804                 :           0 :   DECL_SIZE_UNIT (var)
     805                 :           0 :     = build_int_cst (TREE_TYPE (DECL_SIZE_UNIT (var)), max_size);
     806                 :           0 :   DECL_SIZE (var)
     807                 :           0 :     = build_int_cst (TREE_TYPE (DECL_SIZE (var)), max_size * BITS_PER_UNIT);
     808                 :           0 : }
     809                 :             : 
     810                 :             : /* Push the temporary variable TMP into the current binding.  */
     811                 :             : 
     812                 :             : void
     813                 :       22271 : gimple_add_tmp_var_fn (struct function *fn, tree tmp)
     814                 :             : {
     815                 :       22271 :   gcc_assert (!DECL_CHAIN (tmp) && !DECL_SEEN_IN_BIND_EXPR_P (tmp));
     816                 :             : 
     817                 :             :   /* Later processing assumes that the object size is constant, which might
     818                 :             :      not be true at this point.  Force the use of a constant upper bound in
     819                 :             :      this case.  */
     820                 :       22271 :   if (!tree_fits_poly_uint64_p (DECL_SIZE_UNIT (tmp)))
     821                 :           0 :     force_constant_size (tmp);
     822                 :             : 
     823                 :       22271 :   DECL_CONTEXT (tmp) = fn->decl;
     824                 :       22271 :   DECL_SEEN_IN_BIND_EXPR_P (tmp) = 1;
     825                 :             : 
     826                 :       22271 :   record_vars_into (tmp, fn->decl);
     827                 :       22271 : }
     828                 :             : 
     829                 :             : /* Push the temporary variable TMP into the current binding.  */
     830                 :             : 
     831                 :             : void
     832                 :    16077506 : gimple_add_tmp_var (tree tmp)
     833                 :             : {
     834                 :    16077506 :   gcc_assert (!DECL_CHAIN (tmp) && !DECL_SEEN_IN_BIND_EXPR_P (tmp));
     835                 :             : 
     836                 :             :   /* Later processing assumes that the object size is constant, which might
     837                 :             :      not be true at this point.  Force the use of a constant upper bound in
     838                 :             :      this case.  */
     839                 :    16077506 :   if (!tree_fits_poly_uint64_p (DECL_SIZE_UNIT (tmp)))
     840                 :           0 :     force_constant_size (tmp);
     841                 :             : 
     842                 :    16077506 :   DECL_CONTEXT (tmp) = current_function_decl;
     843                 :    16077506 :   DECL_SEEN_IN_BIND_EXPR_P (tmp) = 1;
     844                 :             : 
     845                 :    16077506 :   if (gimplify_ctxp)
     846                 :             :     {
     847                 :     5291223 :       DECL_CHAIN (tmp) = gimplify_ctxp->temps;
     848                 :     5291223 :       gimplify_ctxp->temps = tmp;
     849                 :             : 
     850                 :             :       /* Mark temporaries local within the nearest enclosing parallel.  */
     851                 :     5291223 :       if (gimplify_omp_ctxp)
     852                 :             :         {
     853                 :             :           struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp;
     854                 :      532988 :           int flag = GOVD_LOCAL | GOVD_SEEN;
     855                 :             :           while (ctx
     856                 :      532988 :                  && (ctx->region_type == ORT_WORKSHARE
     857                 :             :                      || ctx->region_type == ORT_TASKGROUP
     858                 :      385709 :                      || ctx->region_type == ORT_SIMD
     859                 :      335502 :                      || ctx->region_type == ORT_ACC))
     860                 :             :             {
     861                 :      204450 :               if (ctx->region_type == ORT_SIMD
     862                 :             :                   && TREE_ADDRESSABLE (tmp)
     863                 :       50207 :                   && !TREE_STATIC (tmp))
     864                 :             :                 {
     865                 :          96 :                   if (TREE_CODE (DECL_SIZE_UNIT (tmp)) != INTEGER_CST)
     866                 :           0 :                     ctx->add_safelen1 = true;
     867                 :          96 :                   else if (ctx->in_for_exprs)
     868                 :             :                     flag = GOVD_PRIVATE;
     869                 :             :                   else
     870                 :             :                     flag = GOVD_PRIVATE | GOVD_SEEN;
     871                 :             :                   break;
     872                 :             :                 }
     873                 :      204354 :               ctx = ctx->outer_context;
     874                 :             :             }
     875                 :      328538 :           if (ctx)
     876                 :      301524 :             omp_add_variable (ctx, tmp, flag);
     877                 :             :         }
     878                 :             :     }
     879                 :    10786283 :   else if (cfun)
     880                 :    10786283 :     record_vars (tmp);
     881                 :             :   else
     882                 :             :     {
     883                 :           0 :       gimple_seq body_seq;
     884                 :             : 
     885                 :             :       /* This case is for nested functions.  We need to expose the locals
     886                 :             :          they create.  */
     887                 :           0 :       body_seq = gimple_body (current_function_decl);
     888                 :           0 :       declare_vars (tmp, gimple_seq_first_stmt (body_seq), false);
     889                 :             :     }
     890                 :    16077506 : }
     891                 :             : 
     892                 :             : 
     893                 :             : 
     894                 :             : /* This page contains routines to unshare tree nodes, i.e. to duplicate tree
     895                 :             :    nodes that are referenced more than once in GENERIC functions.  This is
     896                 :             :    necessary because gimplification (translation into GIMPLE) is performed
     897                 :             :    by modifying tree nodes in-place, so gimplication of a shared node in a
     898                 :             :    first context could generate an invalid GIMPLE form in a second context.
     899                 :             : 
     900                 :             :    This is achieved with a simple mark/copy/unmark algorithm that walks the
     901                 :             :    GENERIC representation top-down, marks nodes with TREE_VISITED the first
     902                 :             :    time it encounters them, duplicates them if they already have TREE_VISITED
     903                 :             :    set, and finally removes the TREE_VISITED marks it has set.
     904                 :             : 
     905                 :             :    The algorithm works only at the function level, i.e. it generates a GENERIC
     906                 :             :    representation of a function with no nodes shared within the function when
     907                 :             :    passed a GENERIC function (except for nodes that are allowed to be shared).
     908                 :             : 
     909                 :             :    At the global level, it is also necessary to unshare tree nodes that are
     910                 :             :    referenced in more than one function, for the same aforementioned reason.
     911                 :             :    This requires some cooperation from the front-end.  There are 2 strategies:
     912                 :             : 
     913                 :             :      1. Manual unsharing.  The front-end needs to call unshare_expr on every
     914                 :             :         expression that might end up being shared across functions.
     915                 :             : 
     916                 :             :      2. Deep unsharing.  This is an extension of regular unsharing.  Instead
     917                 :             :         of calling unshare_expr on expressions that might be shared across
     918                 :             :         functions, the front-end pre-marks them with TREE_VISITED.  This will
     919                 :             :         ensure that they are unshared on the first reference within functions
     920                 :             :         when the regular unsharing algorithm runs.  The counterpart is that
     921                 :             :         this algorithm must look deeper than for manual unsharing, which is
     922                 :             :         specified by LANG_HOOKS_DEEP_UNSHARING.
     923                 :             : 
     924                 :             :   If there are only few specific cases of node sharing across functions, it is
     925                 :             :   probably easier for a front-end to unshare the expressions manually.  On the
     926                 :             :   contrary, if the expressions generated at the global level are as widespread
     927                 :             :   as expressions generated within functions, deep unsharing is very likely the
     928                 :             :   way to go.  */
     929                 :             : 
     930                 :             : /* Similar to copy_tree_r but do not copy SAVE_EXPR or TARGET_EXPR nodes.
     931                 :             :    These nodes model computations that must be done once.  If we were to
     932                 :             :    unshare something like SAVE_EXPR(i++), the gimplification process would
     933                 :             :    create wrong code.  However, if DATA is non-null, it must hold a pointer
     934                 :             :    set that is used to unshare the subtrees of these nodes.  */
     935                 :             : 
     936                 :             : static tree
     937                 :  2030474801 : mostly_copy_tree_r (tree *tp, int *walk_subtrees, void *data)
     938                 :             : {
     939                 :  2030474801 :   tree t = *tp;
     940                 :  2030474801 :   enum tree_code code = TREE_CODE (t);
     941                 :             : 
     942                 :             :   /* Do not copy SAVE_EXPR, TARGET_EXPR or BIND_EXPR nodes themselves, but
     943                 :             :      copy their subtrees if we can make sure to do it only once.  */
     944                 :  2030474801 :   if (code == SAVE_EXPR || code == TARGET_EXPR || code == BIND_EXPR)
     945                 :             :     {
     946                 :     7863591 :       if (data && !((hash_set<tree> *)data)->add (t))
     947                 :             :         ;
     948                 :             :       else
     949                 :     7863591 :         *walk_subtrees = 0;
     950                 :             :     }
     951                 :             : 
     952                 :             :   /* Stop at types, decls, constants like copy_tree_r.  */
     953                 :  2022611210 :   else if (TREE_CODE_CLASS (code) == tcc_type
     954                 :             :            || TREE_CODE_CLASS (code) == tcc_declaration
     955                 :  2022611210 :            || TREE_CODE_CLASS (code) == tcc_constant)
     956                 :  1228388478 :     *walk_subtrees = 0;
     957                 :             : 
     958                 :             :   /* Cope with the statement expression extension.  */
     959                 :   794222732 :   else if (code == STATEMENT_LIST)
     960                 :             :     ;
     961                 :             : 
     962                 :             :   /* Leave the bulk of the work to copy_tree_r itself.  */
     963                 :             :   else
     964                 :   794173102 :     copy_tree_r (tp, walk_subtrees, NULL);
     965                 :             : 
     966                 :  2030474801 :   return NULL_TREE;
     967                 :             : }
     968                 :             : 
     969                 :             : /* Callback for walk_tree to unshare most of the shared trees rooted at *TP.
     970                 :             :    If *TP has been visited already, then *TP is deeply copied by calling
     971                 :             :    mostly_copy_tree_r.  DATA is passed to mostly_copy_tree_r unmodified.  */
     972                 :             : 
     973                 :             : static tree
     974                 :   266477916 : copy_if_shared_r (tree *tp, int *walk_subtrees, void *data)
     975                 :             : {
     976                 :   266477916 :   tree t = *tp;
     977                 :   266477916 :   enum tree_code code = TREE_CODE (t);
     978                 :             : 
     979                 :             :   /* Skip types, decls, and constants.  But we do want to look at their
     980                 :             :      types and the bounds of types.  Mark them as visited so we properly
     981                 :             :      unmark their subtrees on the unmark pass.  If we've already seen them,
     982                 :             :      don't look down further.  */
     983                 :   266477916 :   if (TREE_CODE_CLASS (code) == tcc_type
     984                 :             :       || TREE_CODE_CLASS (code) == tcc_declaration
     985                 :   266477916 :       || TREE_CODE_CLASS (code) == tcc_constant)
     986                 :             :     {
     987                 :   126142619 :       if (TREE_VISITED (t))
     988                 :    77935677 :         *walk_subtrees = 0;
     989                 :             :       else
     990                 :    48206942 :         TREE_VISITED (t) = 1;
     991                 :             :     }
     992                 :             : 
     993                 :             :   /* If this node has been visited already, unshare it and don't look
     994                 :             :      any deeper.  */
     995                 :   140335297 :   else if (TREE_VISITED (t))
     996                 :             :     {
     997                 :     1520659 :       walk_tree (tp, mostly_copy_tree_r, data, NULL);
     998                 :     1520659 :       *walk_subtrees = 0;
     999                 :             :     }
    1000                 :             : 
    1001                 :             :   /* Otherwise, mark the node as visited and keep looking.  */
    1002                 :             :   else
    1003                 :   138814638 :     TREE_VISITED (t) = 1;
    1004                 :             : 
    1005                 :   266477916 :   return NULL_TREE;
    1006                 :             : }
    1007                 :             : 
    1008                 :             : /* Unshare most of the shared trees rooted at *TP.  DATA is passed to the
    1009                 :             :    copy_if_shared_r callback unmodified.  */
    1010                 :             : 
    1011                 :             : void
    1012                 :     8210067 : copy_if_shared (tree *tp, void *data)
    1013                 :             : {
    1014                 :     8210067 :   walk_tree (tp, copy_if_shared_r, data, NULL);
    1015                 :     8210067 : }
    1016                 :             : 
    1017                 :             : /* Unshare all the trees in the body of FNDECL, as well as in the bodies of
    1018                 :             :    any nested functions.  */
    1019                 :             : 
    1020                 :             : static void
    1021                 :     2736689 : unshare_body (tree fndecl)
    1022                 :             : {
    1023                 :     2736689 :   struct cgraph_node *cgn = cgraph_node::get (fndecl);
    1024                 :             :   /* If the language requires deep unsharing, we need a pointer set to make
    1025                 :             :      sure we don't repeatedly unshare subtrees of unshareable nodes.  */
    1026                 :     2736689 :   hash_set<tree> *visited
    1027                 :     2736689 :     = lang_hooks.deep_unsharing ? new hash_set<tree> : NULL;
    1028                 :             : 
    1029                 :     2736689 :   copy_if_shared (&DECL_SAVED_TREE (fndecl), visited);
    1030                 :     2736689 :   copy_if_shared (&DECL_SIZE (DECL_RESULT (fndecl)), visited);
    1031                 :     2736689 :   copy_if_shared (&DECL_SIZE_UNIT (DECL_RESULT (fndecl)), visited);
    1032                 :             : 
    1033                 :     2739955 :   delete visited;
    1034                 :             : 
    1035                 :     2736689 :   if (cgn)
    1036                 :     5515876 :     for (cgn = first_nested_function (cgn); cgn;
    1037                 :       24560 :          cgn = next_nested_function (cgn))
    1038                 :       24560 :       unshare_body (cgn->decl);
    1039                 :     2736689 : }
    1040                 :             : 
    1041                 :             : /* Callback for walk_tree to unmark the visited trees rooted at *TP.
    1042                 :             :    Subtrees are walked until the first unvisited node is encountered.  */
    1043                 :             : 
    1044                 :             : static tree
    1045                 :   266477490 : unmark_visited_r (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED)
    1046                 :             : {
    1047                 :   266477490 :   tree t = *tp;
    1048                 :             : 
    1049                 :             :   /* If this node has been visited, unmark it and keep looking.  */
    1050                 :   266477490 :   if (TREE_VISITED (t))
    1051                 :   187025874 :     TREE_VISITED (t) = 0;
    1052                 :             : 
    1053                 :             :   /* Otherwise, don't look any deeper.  */
    1054                 :             :   else
    1055                 :    79451616 :     *walk_subtrees = 0;
    1056                 :             : 
    1057                 :   266477490 :   return NULL_TREE;
    1058                 :             : }
    1059                 :             : 
    1060                 :             : /* Unmark the visited trees rooted at *TP.  */
    1061                 :             : 
    1062                 :             : static inline void
    1063                 :     8210067 : unmark_visited (tree *tp)
    1064                 :             : {
    1065                 :     8210067 :   walk_tree (tp, unmark_visited_r, NULL, NULL);
    1066                 :     8210067 : }
    1067                 :             : 
    1068                 :             : /* Likewise, but mark all trees as not visited.  */
    1069                 :             : 
    1070                 :             : static void
    1071                 :     2736689 : unvisit_body (tree fndecl)
    1072                 :             : {
    1073                 :     2736689 :   struct cgraph_node *cgn = cgraph_node::get (fndecl);
    1074                 :             : 
    1075                 :     2736689 :   unmark_visited (&DECL_SAVED_TREE (fndecl));
    1076                 :     2736689 :   unmark_visited (&DECL_SIZE (DECL_RESULT (fndecl)));
    1077                 :     2736689 :   unmark_visited (&DECL_SIZE_UNIT (DECL_RESULT (fndecl)));
    1078                 :             : 
    1079                 :     2736689 :   if (cgn)
    1080                 :     2757938 :     for (cgn = first_nested_function (cgn);
    1081                 :     2757938 :          cgn; cgn = next_nested_function (cgn))
    1082                 :       24560 :       unvisit_body (cgn->decl);
    1083                 :     2736689 : }
    1084                 :             : 
    1085                 :             : /* Unconditionally make an unshared copy of EXPR.  This is used when using
    1086                 :             :    stored expressions which span multiple functions, such as BINFO_VTABLE,
    1087                 :             :    as the normal unsharing process can't tell that they're shared.  */
    1088                 :             : 
    1089                 :             : tree
    1090                 :  1101421902 : unshare_expr (tree expr)
    1091                 :             : {
    1092                 :  1101421902 :   walk_tree (&expr, mostly_copy_tree_r, NULL, NULL);
    1093                 :  1101421902 :   return expr;
    1094                 :             : }
    1095                 :             : 
    1096                 :             : /* Worker for unshare_expr_without_location.  */
    1097                 :             : 
    1098                 :             : static tree
    1099                 :     7361903 : prune_expr_location (tree *tp, int *walk_subtrees, void *)
    1100                 :             : {
    1101                 :     7361903 :   if (EXPR_P (*tp))
    1102                 :     3338299 :     SET_EXPR_LOCATION (*tp, UNKNOWN_LOCATION);
    1103                 :             :   else
    1104                 :     4023604 :     *walk_subtrees = 0;
    1105                 :     7361903 :   return NULL_TREE;
    1106                 :             : }
    1107                 :             : 
    1108                 :             : /* Similar to unshare_expr but also prune all expression locations
    1109                 :             :    from EXPR.  */
    1110                 :             : 
    1111                 :             : tree
    1112                 :    19357486 : unshare_expr_without_location (tree expr)
    1113                 :             : {
    1114                 :    19357486 :   walk_tree (&expr, mostly_copy_tree_r, NULL, NULL);
    1115                 :    19357486 :   if (EXPR_P (expr))
    1116                 :     2448586 :     walk_tree (&expr, prune_expr_location, NULL, NULL);
    1117                 :    19357486 :   return expr;
    1118                 :             : }
    1119                 :             : 
    1120                 :             : /* Return the EXPR_LOCATION of EXPR, if it (maybe recursively) has
    1121                 :             :    one, OR_ELSE otherwise.  The location of a STATEMENT_LISTs
    1122                 :             :    comprising at least one DEBUG_BEGIN_STMT followed by exactly one
    1123                 :             :    EXPR is the location of the EXPR.  */
    1124                 :             : 
    1125                 :             : static location_t
    1126                 :     1120357 : rexpr_location (tree expr, location_t or_else = UNKNOWN_LOCATION)
    1127                 :             : {
    1128                 :     1120357 :   if (!expr)
    1129                 :             :     return or_else;
    1130                 :             : 
    1131                 :     1120357 :   if (EXPR_HAS_LOCATION (expr))
    1132                 :      777885 :     return EXPR_LOCATION (expr);
    1133                 :             : 
    1134                 :      342472 :   if (TREE_CODE (expr) != STATEMENT_LIST)
    1135                 :             :     return or_else;
    1136                 :             : 
    1137                 :           0 :   tree_stmt_iterator i = tsi_start (expr);
    1138                 :             : 
    1139                 :           0 :   bool found = false;
    1140                 :           0 :   while (!tsi_end_p (i) && TREE_CODE (tsi_stmt (i)) == DEBUG_BEGIN_STMT)
    1141                 :             :     {
    1142                 :           0 :       found = true;
    1143                 :           0 :       tsi_next (&i);
    1144                 :             :     }
    1145                 :             : 
    1146                 :           0 :   if (!found || !tsi_one_before_end_p (i))
    1147                 :           0 :     return or_else;
    1148                 :             : 
    1149                 :           0 :   return rexpr_location (tsi_stmt (i), or_else);
    1150                 :             : }
    1151                 :             : 
    1152                 :             : /* Return TRUE iff EXPR (maybe recursively) has a location; see
    1153                 :             :    rexpr_location for the potential recursion.  */
    1154                 :             : 
    1155                 :             : static inline bool
    1156                 :      485525 : rexpr_has_location (tree expr)
    1157                 :             : {
    1158                 :      298293 :   return rexpr_location (expr) != UNKNOWN_LOCATION;
    1159                 :             : }
    1160                 :             : 
    1161                 :             : 
    1162                 :             : /* WRAPPER is a code such as BIND_EXPR or CLEANUP_POINT_EXPR which can both
    1163                 :             :    contain statements and have a value.  Assign its value to a temporary
    1164                 :             :    and give it void_type_node.  Return the temporary, or NULL_TREE if
    1165                 :             :    WRAPPER was already void.  */
    1166                 :             : 
    1167                 :             : tree
    1168                 :    19827569 : voidify_wrapper_expr (tree wrapper, tree temp)
    1169                 :             : {
    1170                 :    19827569 :   tree type = TREE_TYPE (wrapper);
    1171                 :    19827569 :   if (type && !VOID_TYPE_P (type))
    1172                 :             :     {
    1173                 :             :       tree *p;
    1174                 :             : 
    1175                 :             :       /* Set p to point to the body of the wrapper.  Loop until we find
    1176                 :             :          something that isn't a wrapper.  */
    1177                 :      779496 :       for (p = &wrapper; p && *p; )
    1178                 :             :         {
    1179                 :      779496 :           switch (TREE_CODE (*p))
    1180                 :             :             {
    1181                 :        3057 :             case BIND_EXPR:
    1182                 :        3057 :               TREE_SIDE_EFFECTS (*p) = 1;
    1183                 :        3057 :               TREE_TYPE (*p) = void_type_node;
    1184                 :             :               /* For a BIND_EXPR, the body is operand 1.  */
    1185                 :        3057 :               p = &BIND_EXPR_BODY (*p);
    1186                 :        3057 :               break;
    1187                 :             : 
    1188                 :      363856 :             case CLEANUP_POINT_EXPR:
    1189                 :      363856 :             case TRY_FINALLY_EXPR:
    1190                 :      363856 :             case TRY_CATCH_EXPR:
    1191                 :      363856 :               TREE_SIDE_EFFECTS (*p) = 1;
    1192                 :      363856 :               TREE_TYPE (*p) = void_type_node;
    1193                 :      363856 :               p = &TREE_OPERAND (*p, 0);
    1194                 :      363856 :               break;
    1195                 :             : 
    1196                 :       18186 :             case STATEMENT_LIST:
    1197                 :       18186 :               {
    1198                 :       18186 :                 tree_stmt_iterator i = tsi_last (*p);
    1199                 :       18186 :                 TREE_SIDE_EFFECTS (*p) = 1;
    1200                 :       18186 :                 TREE_TYPE (*p) = void_type_node;
    1201                 :       18186 :                 p = tsi_end_p (i) ? NULL : tsi_stmt_ptr (i);
    1202                 :             :               }
    1203                 :       18186 :               break;
    1204                 :             : 
    1205                 :             :             case COMPOUND_EXPR:
    1206                 :             :               /* Advance to the last statement.  Set all container types to
    1207                 :             :                  void.  */
    1208                 :       48138 :               for (; TREE_CODE (*p) == COMPOUND_EXPR; p = &TREE_OPERAND (*p, 1))
    1209                 :             :                 {
    1210                 :       24072 :                   TREE_SIDE_EFFECTS (*p) = 1;
    1211                 :       24072 :                   TREE_TYPE (*p) = void_type_node;
    1212                 :             :                 }
    1213                 :             :               break;
    1214                 :             : 
    1215                 :          76 :             case TRANSACTION_EXPR:
    1216                 :          76 :               TREE_SIDE_EFFECTS (*p) = 1;
    1217                 :          76 :               TREE_TYPE (*p) = void_type_node;
    1218                 :          76 :               p = &TRANSACTION_EXPR_BODY (*p);
    1219                 :          76 :               break;
    1220                 :             : 
    1221                 :      370255 :             default:
    1222                 :             :               /* Assume that any tree upon which voidify_wrapper_expr is
    1223                 :             :                  directly called is a wrapper, and that its body is op0.  */
    1224                 :      370255 :               if (p == &wrapper)
    1225                 :             :                 {
    1226                 :          33 :                   TREE_SIDE_EFFECTS (*p) = 1;
    1227                 :          33 :                   TREE_TYPE (*p) = void_type_node;
    1228                 :          33 :                   p = &TREE_OPERAND (*p, 0);
    1229                 :          33 :                   break;
    1230                 :             :                 }
    1231                 :      370222 :               goto out;
    1232                 :             :             }
    1233                 :             :         }
    1234                 :             : 
    1235                 :           0 :     out:
    1236                 :      370222 :       if (p == NULL || IS_EMPTY_STMT (*p))
    1237                 :             :         temp = NULL_TREE;
    1238                 :      370222 :       else if (temp)
    1239                 :             :         {
    1240                 :             :           /* The wrapper is on the RHS of an assignment that we're pushing
    1241                 :             :              down.  */
    1242                 :        1649 :           gcc_assert (TREE_CODE (temp) == INIT_EXPR
    1243                 :             :                       || TREE_CODE (temp) == MODIFY_EXPR);
    1244                 :        1649 :           TREE_OPERAND (temp, 1) = *p;
    1245                 :        1649 :           *p = temp;
    1246                 :             :         }
    1247                 :             :       else
    1248                 :             :         {
    1249                 :      368573 :           temp = create_tmp_var (type, "retval");
    1250                 :      368573 :           *p = build2 (INIT_EXPR, type, temp, *p);
    1251                 :             :         }
    1252                 :             : 
    1253                 :      370222 :       return temp;
    1254                 :             :     }
    1255                 :             : 
    1256                 :             :   return NULL_TREE;
    1257                 :             : }
    1258                 :             : 
    1259                 :             : /* Prepare calls to builtins to SAVE and RESTORE the stack as well as
    1260                 :             :    a temporary through which they communicate.  */
    1261                 :             : 
    1262                 :             : static void
    1263                 :        7763 : build_stack_save_restore (gcall **save, gcall **restore)
    1264                 :             : {
    1265                 :        7763 :   tree tmp_var;
    1266                 :             : 
    1267                 :       15526 :   *save = gimple_build_call (builtin_decl_implicit (BUILT_IN_STACK_SAVE), 0);
    1268                 :        7763 :   tmp_var = create_tmp_var (ptr_type_node, "saved_stack");
    1269                 :        7763 :   gimple_call_set_lhs (*save, tmp_var);
    1270                 :             : 
    1271                 :        7763 :   *restore
    1272                 :        7763 :     = gimple_build_call (builtin_decl_implicit (BUILT_IN_STACK_RESTORE),
    1273                 :             :                          1, tmp_var);
    1274                 :        7763 : }
    1275                 :             : 
    1276                 :             : /* Generate IFN_ASAN_MARK call that poisons shadow of a for DECL variable.  */
    1277                 :             : 
    1278                 :             : static tree
    1279                 :         437 : build_asan_poison_call_expr (tree decl)
    1280                 :             : {
    1281                 :             :   /* Do not poison variables that have size equal to zero.  */
    1282                 :         437 :   tree unit_size = DECL_SIZE_UNIT (decl);
    1283                 :         437 :   if (zerop (unit_size))
    1284                 :             :     return NULL_TREE;
    1285                 :             : 
    1286                 :         437 :   tree base = build_fold_addr_expr (decl);
    1287                 :             : 
    1288                 :         437 :   return build_call_expr_internal_loc (UNKNOWN_LOCATION, IFN_ASAN_MARK,
    1289                 :             :                                        void_type_node, 3,
    1290                 :         437 :                                        build_int_cst (integer_type_node,
    1291                 :         437 :                                                       ASAN_MARK_POISON),
    1292                 :             :                                        base, unit_size);
    1293                 :             : }
    1294                 :             : 
    1295                 :             : /* Generate IFN_ASAN_MARK call that would poison or unpoison, depending
    1296                 :             :    on POISON flag, shadow memory of a DECL variable.  The call will be
    1297                 :             :    put on location identified by IT iterator, where BEFORE flag drives
    1298                 :             :    position where the stmt will be put.  */
    1299                 :             : 
    1300                 :             : static void
    1301                 :        4153 : asan_poison_variable (tree decl, bool poison, gimple_stmt_iterator *it,
    1302                 :             :                       bool before)
    1303                 :             : {
    1304                 :        4153 :   tree unit_size = DECL_SIZE_UNIT (decl);
    1305                 :        4153 :   tree base = build_fold_addr_expr (decl);
    1306                 :             : 
    1307                 :             :   /* Do not poison variables that have size equal to zero.  */
    1308                 :        4153 :   if (zerop (unit_size))
    1309                 :        4153 :     return;
    1310                 :             : 
    1311                 :             :   /* It's necessary to have all stack variables aligned to ASAN granularity
    1312                 :             :      bytes.  */
    1313                 :        4139 :   gcc_assert (!hwasan_sanitize_p () || hwasan_sanitize_stack_p ());
    1314                 :        4139 :   unsigned shadow_granularity
    1315                 :        4139 :     = hwasan_sanitize_p () ? HWASAN_TAG_GRANULE_SIZE : ASAN_SHADOW_GRANULARITY;
    1316                 :        4139 :   if (DECL_ALIGN_UNIT (decl) <= shadow_granularity)
    1317                 :        3937 :     SET_DECL_ALIGN (decl, BITS_PER_UNIT * shadow_granularity);
    1318                 :             : 
    1319                 :        4139 :   HOST_WIDE_INT flags = poison ? ASAN_MARK_POISON : ASAN_MARK_UNPOISON;
    1320                 :             : 
    1321                 :        4139 :   gimple *g
    1322                 :        4139 :     = gimple_build_call_internal (IFN_ASAN_MARK, 3,
    1323                 :        4139 :                                   build_int_cst (integer_type_node, flags),
    1324                 :             :                                   base, unit_size);
    1325                 :             : 
    1326                 :        4139 :   if (before)
    1327                 :        2113 :     gsi_insert_before (it, g, GSI_NEW_STMT);
    1328                 :             :   else
    1329                 :        2026 :     gsi_insert_after (it, g, GSI_NEW_STMT);
    1330                 :             : }
    1331                 :             : 
    1332                 :             : /* Generate IFN_ASAN_MARK internal call that depending on POISON flag
    1333                 :             :    either poisons or unpoisons a DECL.  Created statement is appended
    1334                 :             :    to SEQ_P gimple sequence.  */
    1335                 :             : 
    1336                 :             : static void
    1337                 :        3716 : asan_poison_variable (tree decl, bool poison, gimple_seq *seq_p)
    1338                 :             : {
    1339                 :        3716 :   gimple_stmt_iterator it = gsi_last (*seq_p);
    1340                 :        3716 :   bool before = false;
    1341                 :             : 
    1342                 :        3716 :   if (gsi_end_p (it))
    1343                 :        1897 :     before = true;
    1344                 :             : 
    1345                 :        3716 :   asan_poison_variable (decl, poison, &it, before);
    1346                 :        3716 : }
    1347                 :             : 
    1348                 :             : /* Sort pair of VAR_DECLs A and B by DECL_UID.  */
    1349                 :             : 
    1350                 :             : static int
    1351                 :         135 : sort_by_decl_uid (const void *a, const void *b)
    1352                 :             : {
    1353                 :         135 :   const tree *t1 = (const tree *)a;
    1354                 :         135 :   const tree *t2 = (const tree *)b;
    1355                 :             : 
    1356                 :         135 :   int uid1 = DECL_UID (*t1);
    1357                 :         135 :   int uid2 = DECL_UID (*t2);
    1358                 :             : 
    1359                 :         135 :   if (uid1 < uid2)
    1360                 :             :     return -1;
    1361                 :          56 :   else if (uid1 > uid2)
    1362                 :             :     return 1;
    1363                 :             :   else
    1364                 :           0 :     return 0;
    1365                 :             : }
    1366                 :             : 
    1367                 :             : /* Generate IFN_ASAN_MARK internal call for all VARIABLES
    1368                 :             :    depending on POISON flag.  Created statement is appended
    1369                 :             :    to SEQ_P gimple sequence.  */
    1370                 :             : 
    1371                 :             : static void
    1372                 :     1047327 : asan_poison_variables (hash_set<tree> *variables, bool poison, gimple_seq *seq_p)
    1373                 :             : {
    1374                 :     1047327 :   unsigned c = variables->elements ();
    1375                 :     1047327 :   if (c == 0)
    1376                 :     1047144 :     return;
    1377                 :             : 
    1378                 :         183 :   auto_vec<tree> sorted_variables (c);
    1379                 :             : 
    1380                 :         183 :   for (hash_set<tree>::iterator it = variables->begin ();
    1381                 :         591 :        it != variables->end (); ++it)
    1382                 :         204 :     sorted_variables.safe_push (*it);
    1383                 :             : 
    1384                 :         183 :   sorted_variables.qsort (sort_by_decl_uid);
    1385                 :             : 
    1386                 :             :   unsigned i;
    1387                 :             :   tree var;
    1388                 :         570 :   FOR_EACH_VEC_ELT (sorted_variables, i, var)
    1389                 :             :     {
    1390                 :         204 :       asan_poison_variable (var, poison, seq_p);
    1391                 :             : 
    1392                 :             :       /* Add use_after_scope_memory attribute for the variable in order
    1393                 :             :          to prevent re-written into SSA.  */
    1394                 :         204 :       if (!lookup_attribute (ASAN_USE_AFTER_SCOPE_ATTRIBUTE,
    1395                 :         204 :                              DECL_ATTRIBUTES (var)))
    1396                 :          90 :         DECL_ATTRIBUTES (var)
    1397                 :         180 :           = tree_cons (get_identifier (ASAN_USE_AFTER_SCOPE_ATTRIBUTE),
    1398                 :             :                        integer_one_node,
    1399                 :          90 :                        DECL_ATTRIBUTES (var));
    1400                 :             :     }
    1401                 :         183 : }
    1402                 :             : 
    1403                 :             : /* Gimplify a BIND_EXPR.  Just voidify and recurse.  */
    1404                 :             : 
    1405                 :             : static enum gimplify_status
    1406                 :     5750961 : gimplify_bind_expr (tree *expr_p, gimple_seq *pre_p)
    1407                 :             : {
    1408                 :     5750961 :   tree bind_expr = *expr_p;
    1409                 :     5750961 :   bool old_keep_stack = gimplify_ctxp->keep_stack;
    1410                 :     5750961 :   bool old_save_stack = gimplify_ctxp->save_stack;
    1411                 :     5750961 :   tree t;
    1412                 :     5750961 :   gbind *bind_stmt;
    1413                 :     5750961 :   gimple_seq body, cleanup;
    1414                 :     5750961 :   gcall *stack_save;
    1415                 :     5750961 :   location_t start_locus = 0, end_locus = 0;
    1416                 :     5750961 :   tree ret_clauses = NULL;
    1417                 :             : 
    1418                 :     5750961 :   tree temp = voidify_wrapper_expr (bind_expr, NULL);
    1419                 :             : 
    1420                 :             :   /* Mark variables seen in this bind expr.  */
    1421                 :    12114048 :   for (t = BIND_EXPR_VARS (bind_expr); t ; t = DECL_CHAIN (t))
    1422                 :             :     {
    1423                 :     6363087 :       if (VAR_P (t))
    1424                 :             :         {
    1425                 :     5782741 :           struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp;
    1426                 :     5782741 :           tree attr;
    1427                 :             : 
    1428                 :     5782741 :           if (flag_openmp
    1429                 :      223426 :               && !is_global_var (t)
    1430                 :      216107 :               && !TREE_STATIC (t)
    1431                 :      216107 :               && DECL_CONTEXT (t) == current_function_decl
    1432                 :      216107 :               && TREE_USED (t)
    1433                 :     5997456 :               && (attr = lookup_attribute ("omp allocate", DECL_ATTRIBUTES (t)))
    1434                 :             :                  != NULL_TREE)
    1435                 :             :             {
    1436                 :          74 :               gcc_assert (!DECL_HAS_VALUE_EXPR_P (t));
    1437                 :          74 :               tree alloc = TREE_PURPOSE (TREE_VALUE (attr));
    1438                 :          74 :               tree align = TREE_VALUE (TREE_VALUE (attr));
    1439                 :             :               /* Allocate directives that appear in a target region must specify
    1440                 :             :                  an allocator clause unless a requires directive with the
    1441                 :             :                  dynamic_allocators clause is present in the same compilation
    1442                 :             :                  unit.  */
    1443                 :          74 :               bool missing_dyn_alloc = false;
    1444                 :          74 :               if (alloc == NULL_TREE
    1445                 :          48 :                   && ((omp_requires_mask & OMP_REQUIRES_DYNAMIC_ALLOCATORS)
    1446                 :             :                       == 0))
    1447                 :             :                 {
    1448                 :             :                   /* This comes too early for omp_discover_declare_target...,
    1449                 :             :                      but should at least catch the most common cases.  */
    1450                 :          42 :                   missing_dyn_alloc
    1451                 :          42 :                     = cgraph_node::get (current_function_decl)->offloadable;
    1452                 :          42 :                   for (struct gimplify_omp_ctx *ctx2 = ctx;
    1453                 :          48 :                        ctx2 && !missing_dyn_alloc; ctx2 = ctx2->outer_context)
    1454                 :           6 :                     if (ctx2->code == OMP_TARGET)
    1455                 :           2 :                       missing_dyn_alloc = true;
    1456                 :             :                 }
    1457                 :          42 :               if (missing_dyn_alloc)
    1458                 :           4 :                 error_at (DECL_SOURCE_LOCATION (t),
    1459                 :             :                           "%<allocate%> directive for %qD inside a target "
    1460                 :             :                           "region must specify an %<allocator%> clause", t);
    1461                 :             :               /* Skip for omp_default_mem_alloc (= 1),
    1462                 :             :                  unless align is present.  For C/C++, there should be always a
    1463                 :             :                  statement list following if TREE_USED, except for, e.g., using
    1464                 :             :                  this decl in a static_assert; in that case, only a single
    1465                 :             :                  DECL_EXPR remains, which can be skipped here.  */
    1466                 :          70 :               else if (!errorcount
    1467                 :          55 :                        && (align != NULL_TREE
    1468                 :          55 :                            || alloc == NULL_TREE
    1469                 :          10 :                            || !integer_onep (alloc))
    1470                 :         123 :                        && (lang_GNU_Fortran ()
    1471                 :          25 :                            || (TREE_CODE (BIND_EXPR_BODY (bind_expr))
    1472                 :             :                                != DECL_EXPR)))
    1473                 :             :                 {
    1474                 :             :                   /* Fortran might already use a pointer type internally;
    1475                 :             :                      use that pointer except for type(C_ptr) and type(C_funptr);
    1476                 :             :                      note that normal proc pointers are rejected.  */
    1477                 :          53 :                   tree type = TREE_TYPE (t);
    1478                 :          53 :                   tree tmp, v;
    1479                 :          53 :                   if (lang_GNU_Fortran ()
    1480                 :          28 :                       && POINTER_TYPE_P (type)
    1481                 :           8 :                       && TREE_TYPE (type) != void_type_node
    1482                 :          59 :                       && TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE)
    1483                 :             :                     {
    1484                 :           6 :                       type = TREE_TYPE (type);
    1485                 :           6 :                       v = t;
    1486                 :             :                     }
    1487                 :             :                   else
    1488                 :             :                     {
    1489                 :          47 :                       tmp = build_pointer_type (type);
    1490                 :          47 :                       v = create_tmp_var (tmp, get_name (t));
    1491                 :          47 :                       DECL_IGNORED_P (v) = 0;
    1492                 :          47 :                       DECL_ATTRIBUTES (v)
    1493                 :          94 :                         = tree_cons (get_identifier ("omp allocate var"),
    1494                 :             :                                      build_tree_list (NULL_TREE, t),
    1495                 :             :                                      remove_attribute ("omp allocate",
    1496                 :          47 :                                                        DECL_ATTRIBUTES (t)));
    1497                 :          47 :                       tmp = build_fold_indirect_ref (v);
    1498                 :          47 :                       TREE_THIS_NOTRAP (tmp) = 1;
    1499                 :          47 :                       SET_DECL_VALUE_EXPR (t, tmp);
    1500                 :          47 :                       DECL_HAS_VALUE_EXPR_P (t) = 1;
    1501                 :             :                     }
    1502                 :          53 :                   tree sz = TYPE_SIZE_UNIT (type);
    1503                 :             :                   /* The size to use in Fortran might not match TYPE_SIZE_UNIT;
    1504                 :             :                      hence, for some decls, a size variable is saved in the
    1505                 :             :                      attributes; use it, if available.  */
    1506                 :          53 :                   if (TREE_CHAIN (TREE_VALUE (attr))
    1507                 :          28 :                       && TREE_CHAIN (TREE_CHAIN (TREE_VALUE (attr)))
    1508                 :          59 :                       && TREE_PURPOSE (
    1509                 :             :                            TREE_CHAIN (TREE_CHAIN (TREE_VALUE (attr)))))
    1510                 :             :                     {
    1511                 :           6 :                       sz = TREE_CHAIN (TREE_CHAIN (TREE_VALUE (attr)));
    1512                 :           6 :                       sz = TREE_PURPOSE (sz);
    1513                 :             :                     }
    1514                 :          53 :                   if (alloc == NULL_TREE)
    1515                 :          36 :                     alloc = build_zero_cst (ptr_type_node);
    1516                 :          53 :                   if (align == NULL_TREE)
    1517                 :          42 :                     align = build_int_cst (size_type_node, DECL_ALIGN_UNIT (t));
    1518                 :             :                   else
    1519                 :          11 :                     align = build_int_cst (size_type_node,
    1520                 :          11 :                                            MAX (tree_to_uhwi (align),
    1521                 :             :                                                 DECL_ALIGN_UNIT (t)));
    1522                 :          53 :                   location_t loc = DECL_SOURCE_LOCATION (t);
    1523                 :          53 :                   tmp = builtin_decl_explicit (BUILT_IN_GOMP_ALLOC);
    1524                 :          53 :                   tmp = build_call_expr_loc (loc, tmp, 3, align, sz, alloc);
    1525                 :          53 :                   tmp = fold_build2_loc (loc, MODIFY_EXPR, TREE_TYPE (v), v,
    1526                 :          53 :                                          fold_convert (TREE_TYPE (v), tmp));
    1527                 :          53 :                   gcc_assert (BIND_EXPR_BODY (bind_expr) != NULL_TREE);
    1528                 :             :                   /* Ensure that either TREE_CHAIN (TREE_VALUE (attr) is set
    1529                 :             :                      and GOMP_FREE added here or that DECL_HAS_VALUE_EXPR_P (t)
    1530                 :             :                      is set, using in a condition much further below.  */
    1531                 :          59 :                   gcc_assert (DECL_HAS_VALUE_EXPR_P (t)
    1532                 :             :                               || TREE_CHAIN (TREE_VALUE (attr)));
    1533                 :          53 :                   if (TREE_CHAIN (TREE_VALUE (attr)))
    1534                 :             :                     {
    1535                 :             :                       /* Fortran is special as it does not have properly nest
    1536                 :             :                          declarations in blocks.  And as there is no
    1537                 :             :                          initializer, there is also no expression to look for.
    1538                 :             :                          Hence, the FE makes the statement list of the
    1539                 :             :                          try-finally block available. We can put the GOMP_alloc
    1540                 :             :                          at the top, unless an allocator or size expression
    1541                 :             :                          requires to put it afterward; note that the size is
    1542                 :             :                          always later in generated code; for strings, no
    1543                 :             :                          size expr but still an expr might be available.
    1544                 :             :                          As LTO does not handle a statement list, 'sl' has
    1545                 :             :                          to be removed; done so by removing the attribute.  */
    1546                 :          56 :                       DECL_ATTRIBUTES (t)
    1547                 :          28 :                         = remove_attribute ("omp allocate",
    1548                 :          28 :                                             DECL_ATTRIBUTES (t));
    1549                 :          28 :                       tree sl = TREE_PURPOSE (TREE_CHAIN (TREE_VALUE (attr)));
    1550                 :          28 :                       tree_stmt_iterator e = tsi_start (sl);
    1551                 :          28 :                       tree needle = NULL_TREE;
    1552                 :          28 :                       if (TREE_CHAIN (TREE_CHAIN (TREE_VALUE (attr))))
    1553                 :             :                         {
    1554                 :           6 :                           needle = TREE_CHAIN (TREE_CHAIN (TREE_VALUE (attr)));
    1555                 :           6 :                           needle = (TREE_VALUE (needle) ? TREE_VALUE (needle)
    1556                 :             :                                                         : sz);
    1557                 :             :                         }
    1558                 :          22 :                       else if (TREE_CHAIN (TREE_CHAIN (TREE_VALUE (attr))))
    1559                 :             :                         needle = sz;
    1560                 :          22 :                       else if (DECL_P (alloc) && DECL_ARTIFICIAL (alloc))
    1561                 :             :                         needle = alloc;
    1562                 :             : 
    1563                 :          10 :                       if (needle != NULL_TREE)
    1564                 :             :                         {
    1565                 :          49 :                           while (!tsi_end_p (e))
    1566                 :             :                             {
    1567                 :          49 :                               if (*e == needle
    1568                 :          49 :                                   || (TREE_CODE (*e) == MODIFY_EXPR
    1569                 :          49 :                                       && TREE_OPERAND (*e, 0) == needle))
    1570                 :             :                                 break;
    1571                 :          39 :                               ++e;
    1572                 :             :                             }
    1573                 :          10 :                           gcc_assert (!tsi_end_p (e));
    1574                 :             :                         }
    1575                 :          28 :                       tsi_link_after (&e, tmp, TSI_SAME_STMT);
    1576                 :             : 
    1577                 :             :                       /* As the cleanup is in BIND_EXPR_BODY, GOMP_free is added
    1578                 :             :                          here; for C/C++ it will be added in the 'cleanup'
    1579                 :             :                          section after gimplification. But Fortran already has
    1580                 :             :                          a try-finally block.  */
    1581                 :          28 :                       sl = TREE_VALUE (TREE_CHAIN (TREE_VALUE (attr)));
    1582                 :          28 :                       e = tsi_last (sl);
    1583                 :          28 :                       tmp = builtin_decl_explicit (BUILT_IN_GOMP_FREE);
    1584                 :          28 :                       tmp = build_call_expr_loc (EXPR_LOCATION (*e), tmp, 2, v,
    1585                 :             :                                                  build_zero_cst (ptr_type_node));
    1586                 :          28 :                       tsi_link_after (&e, tmp, TSI_SAME_STMT);
    1587                 :          28 :                       tmp = build_clobber (TREE_TYPE (v), CLOBBER_STORAGE_END);
    1588                 :          28 :                       tmp = fold_build2_loc (loc, MODIFY_EXPR, TREE_TYPE (v), v,
    1589                 :          28 :                                              fold_convert (TREE_TYPE (v), tmp));
    1590                 :          28 :                       ++e;
    1591                 :          28 :                       tsi_link_after (&e, tmp, TSI_SAME_STMT);
    1592                 :             :                     }
    1593                 :             :                   else
    1594                 :             :                     {
    1595                 :          25 :                       gcc_assert (TREE_CODE (BIND_EXPR_BODY (bind_expr))
    1596                 :             :                                   == STATEMENT_LIST);
    1597                 :          25 :                       tree_stmt_iterator e;
    1598                 :          25 :                       e = tsi_start (BIND_EXPR_BODY (bind_expr));
    1599                 :         113 :                       while (!tsi_end_p (e))
    1600                 :             :                         {
    1601                 :          88 :                           if ((TREE_CODE (*e) == DECL_EXPR
    1602                 :          58 :                                && TREE_OPERAND (*e, 0) == t)
    1603                 :         121 :                               || (TREE_CODE (*e) == CLEANUP_POINT_EXPR
    1604                 :           0 :                                   && (TREE_CODE (TREE_OPERAND (*e, 0))
    1605                 :             :                                       == DECL_EXPR)
    1606                 :           0 :                                   && (TREE_OPERAND (TREE_OPERAND (*e, 0), 0)
    1607                 :             :                                       == t)))
    1608                 :             :                             break;
    1609                 :          63 :                           ++e;
    1610                 :             :                         }
    1611                 :          25 :                       gcc_assert (!tsi_end_p (e));
    1612                 :          25 :                       tsi_link_before (&e, tmp, TSI_SAME_STMT);
    1613                 :             :                    }
    1614                 :             :                 }
    1615                 :             :             }
    1616                 :             : 
    1617                 :             :           /* Mark variable as local.  */
    1618                 :     5782741 :           if (ctx && ctx->region_type != ORT_NONE && !DECL_EXTERNAL (t))
    1619                 :             :             {
    1620                 :       89661 :               if (! DECL_SEEN_IN_BIND_EXPR_P (t)
    1621                 :       89661 :                   || splay_tree_lookup (ctx->variables,
    1622                 :             :                                         (splay_tree_key) t) == NULL)
    1623                 :             :                 {
    1624                 :       89661 :                   int flag = GOVD_LOCAL;
    1625                 :       89661 :                   if (ctx->region_type == ORT_SIMD
    1626                 :             :                       && TREE_ADDRESSABLE (t)
    1627                 :        4360 :                       && !TREE_STATIC (t))
    1628                 :             :                     {
    1629                 :          69 :                       if (TREE_CODE (DECL_SIZE_UNIT (t)) != INTEGER_CST)
    1630                 :           2 :                         ctx->add_safelen1 = true;
    1631                 :             :                       else
    1632                 :             :                         flag = GOVD_PRIVATE;
    1633                 :             :                     }
    1634                 :       89661 :                   omp_add_variable (ctx, t, flag | GOVD_SEEN);
    1635                 :             :                 }
    1636                 :             :               /* Static locals inside of target construct or offloaded
    1637                 :             :                  routines need to be "omp declare target".  */
    1638                 :       89661 :               if (TREE_STATIC (t))
    1639                 :         995 :                 for (; ctx; ctx = ctx->outer_context)
    1640                 :         841 :                   if ((ctx->region_type & ORT_TARGET) != 0)
    1641                 :             :                     {
    1642                 :         630 :                       if (!lookup_attribute ("omp declare target",
    1643                 :         630 :                                              DECL_ATTRIBUTES (t)))
    1644                 :             :                         {
    1645                 :         618 :                           tree id = get_identifier ("omp declare target");
    1646                 :        1236 :                           DECL_ATTRIBUTES (t)
    1647                 :         618 :                             = tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (t));
    1648                 :         618 :                           varpool_node *node = varpool_node::get (t);
    1649                 :         618 :                           if (node)
    1650                 :             :                             {
    1651                 :          30 :                               node->offloadable = 1;
    1652                 :          30 :                               if (ENABLE_OFFLOADING && !DECL_EXTERNAL (t))
    1653                 :             :                                 {
    1654                 :             :                                   g->have_offload = true;
    1655                 :             :                                   if (!in_lto_p)
    1656                 :             :                                     vec_safe_push (offload_vars, t);
    1657                 :             :                                 }
    1658                 :             :                             }
    1659                 :             :                         }
    1660                 :             :                       break;
    1661                 :             :                     }
    1662                 :             :             }
    1663                 :             : 
    1664                 :     5782741 :           DECL_SEEN_IN_BIND_EXPR_P (t) = 1;
    1665                 :             : 
    1666                 :     5782741 :           if (DECL_HARD_REGISTER (t) && !is_global_var (t) && cfun)
    1667                 :        1076 :             cfun->has_local_explicit_reg_vars = true;
    1668                 :             :         }
    1669                 :             :     }
    1670                 :             : 
    1671                 :    11501922 :   bind_stmt = gimple_build_bind (BIND_EXPR_VARS (bind_expr), NULL,
    1672                 :     5750961 :                                  BIND_EXPR_BLOCK (bind_expr));
    1673                 :     5750961 :   gimple_push_bind_expr (bind_stmt);
    1674                 :             : 
    1675                 :     5750961 :   gimplify_ctxp->keep_stack = false;
    1676                 :     5750961 :   gimplify_ctxp->save_stack = false;
    1677                 :             : 
    1678                 :             :   /* Gimplify the body into the GIMPLE_BIND tuple's body.  */
    1679                 :     5750961 :   body = NULL;
    1680                 :     5750961 :   gimplify_stmt (&BIND_EXPR_BODY (bind_expr), &body);
    1681                 :     5750961 :   gimple_bind_set_body (bind_stmt, body);
    1682                 :             : 
    1683                 :             :   /* Source location wise, the cleanup code (stack_restore and clobbers)
    1684                 :             :      belongs to the end of the block, so propagate what we have.  The
    1685                 :             :      stack_save operation belongs to the beginning of block, which we can
    1686                 :             :      infer from the bind_expr directly if the block has no explicit
    1687                 :             :      assignment.  */
    1688                 :     5750961 :   if (BIND_EXPR_BLOCK (bind_expr))
    1689                 :             :     {
    1690                 :     5622398 :       end_locus = BLOCK_SOURCE_END_LOCATION (BIND_EXPR_BLOCK (bind_expr));
    1691                 :     5622398 :       start_locus = BLOCK_SOURCE_LOCATION (BIND_EXPR_BLOCK (bind_expr));
    1692                 :             :     }
    1693                 :     5622398 :   if (start_locus == 0)
    1694                 :     5750961 :     start_locus = EXPR_LOCATION (bind_expr);
    1695                 :             : 
    1696                 :     5750961 :   cleanup = NULL;
    1697                 :     5750961 :   stack_save = NULL;
    1698                 :             : 
    1699                 :             :   /* Add clobbers for all variables that go out of scope.  */
    1700                 :    12114048 :   for (t = BIND_EXPR_VARS (bind_expr); t ; t = DECL_CHAIN (t))
    1701                 :             :     {
    1702                 :     6363087 :       if (VAR_P (t)
    1703                 :     5782741 :           && !is_global_var (t)
    1704                 :    11940237 :           && DECL_CONTEXT (t) == current_function_decl)
    1705                 :             :         {
    1706                 :     5577150 :           if (flag_openmp
    1707                 :      216103 :               && DECL_HAS_VALUE_EXPR_P (t)
    1708                 :         939 :               && TREE_USED (t)
    1709                 :     5578079 :               && lookup_attribute ("omp allocate", DECL_ATTRIBUTES (t)))
    1710                 :             :             {
    1711                 :             :               /* For Fortran, TREE_CHAIN (TREE_VALUE (attr)) is set, which
    1712                 :             :                  causes that the GOMP_free call is already added above;
    1713                 :             :                  and "omp allocate" is removed from DECL_ATTRIBUTES.  */
    1714                 :          25 :               tree v = TREE_OPERAND (DECL_VALUE_EXPR (t), 0);
    1715                 :          25 :               tree tmp = builtin_decl_explicit (BUILT_IN_GOMP_FREE);
    1716                 :          25 :               tmp = build_call_expr_loc (end_locus, tmp, 2, v,
    1717                 :             :                                          build_zero_cst (ptr_type_node));
    1718                 :          25 :               gimplify_and_add (tmp, &cleanup);
    1719                 :          25 :               gimple *clobber_stmt;
    1720                 :          25 :               tmp = build_clobber (TREE_TYPE (v), CLOBBER_STORAGE_END);
    1721                 :          25 :               clobber_stmt = gimple_build_assign (v, tmp);
    1722                 :          25 :               gimple_set_location (clobber_stmt, end_locus);
    1723                 :          25 :               gimplify_seq_add_stmt (&cleanup, clobber_stmt);
    1724                 :             :             }
    1725                 :     5577150 :           if (!DECL_HARD_REGISTER (t)
    1726                 :     5576074 :               && !TREE_THIS_VOLATILE (t)
    1727                 :     5537155 :               && !DECL_HAS_VALUE_EXPR_P (t)
    1728                 :             :               /* Only care for variables that have to be in memory.  Others
    1729                 :             :                  will be rewritten into SSA names, hence moved to the
    1730                 :             :                  top-level.  */
    1731                 :     5454856 :               && !is_gimple_reg (t)
    1732                 :     6745939 :               && flag_stack_reuse != SR_NONE)
    1733                 :             :             {
    1734                 :     1166187 :               tree clobber = build_clobber (TREE_TYPE (t), CLOBBER_STORAGE_END);
    1735                 :     1166187 :               gimple *clobber_stmt;
    1736                 :     1166187 :               clobber_stmt = gimple_build_assign (t, clobber);
    1737                 :     1166187 :               gimple_set_location (clobber_stmt, end_locus);
    1738                 :     1166187 :               gimplify_seq_add_stmt (&cleanup, clobber_stmt);
    1739                 :             :             }
    1740                 :             : 
    1741                 :     5577150 :           if (flag_openacc && oacc_declare_returns != NULL)
    1742                 :             :             {
    1743                 :         207 :               tree key = t;
    1744                 :         207 :               if (DECL_HAS_VALUE_EXPR_P (key))
    1745                 :             :                 {
    1746                 :           8 :                   key = DECL_VALUE_EXPR (key);
    1747                 :           8 :                   if (INDIRECT_REF_P (key))
    1748                 :           8 :                     key = TREE_OPERAND (key, 0);
    1749                 :             :                 }
    1750                 :         207 :               tree *c = oacc_declare_returns->get (key);
    1751                 :         207 :               if (c != NULL)
    1752                 :             :                 {
    1753                 :         116 :                   if (ret_clauses)
    1754                 :          64 :                     OMP_CLAUSE_CHAIN (*c) = ret_clauses;
    1755                 :             : 
    1756                 :         116 :                   ret_clauses = unshare_expr (*c);
    1757                 :             : 
    1758                 :         116 :                   oacc_declare_returns->remove (key);
    1759                 :             : 
    1760                 :         116 :                   if (oacc_declare_returns->is_empty ())
    1761                 :             :                     {
    1762                 :          40 :                       delete oacc_declare_returns;
    1763                 :          40 :                       oacc_declare_returns = NULL;
    1764                 :             :                     }
    1765                 :             :                 }
    1766                 :             :             }
    1767                 :             :         }
    1768                 :             : 
    1769                 :     6363087 :       if (asan_poisoned_variables != NULL
    1770                 :     6363087 :           && asan_poisoned_variables->contains (t))
    1771                 :             :         {
    1772                 :        1756 :           asan_poisoned_variables->remove (t);
    1773                 :        1756 :           asan_poison_variable (t, true, &cleanup);
    1774                 :             :         }
    1775                 :             : 
    1776                 :     6363087 :       if (gimplify_ctxp->live_switch_vars != NULL
    1777                 :     6363087 :           && gimplify_ctxp->live_switch_vars->contains (t))
    1778                 :          55 :         gimplify_ctxp->live_switch_vars->remove (t);
    1779                 :             :     }
    1780                 :             : 
    1781                 :             :   /* If the code both contains VLAs and calls alloca, then we cannot reclaim
    1782                 :             :      the stack space allocated to the VLAs.  */
    1783                 :     5750961 :   if (gimplify_ctxp->save_stack && !gimplify_ctxp->keep_stack)
    1784                 :             :     {
    1785                 :        7763 :       gcall *stack_restore;
    1786                 :             : 
    1787                 :             :       /* Save stack on entry and restore it on exit.  Add a try_finally
    1788                 :             :          block to achieve this.  */
    1789                 :        7763 :       build_stack_save_restore (&stack_save, &stack_restore);
    1790                 :             : 
    1791                 :        7763 :       gimple_set_location (stack_save, start_locus);
    1792                 :        7763 :       gimple_set_location (stack_restore, end_locus);
    1793                 :             : 
    1794                 :        7763 :       gimplify_seq_add_stmt (&cleanup, stack_restore);
    1795                 :             :     }
    1796                 :             : 
    1797                 :     5750961 :   if (ret_clauses)
    1798                 :             :     {
    1799                 :          52 :       gomp_target *stmt;
    1800                 :          52 :       gimple_stmt_iterator si = gsi_start (cleanup);
    1801                 :             : 
    1802                 :          52 :       stmt = gimple_build_omp_target (NULL, GF_OMP_TARGET_KIND_OACC_DECLARE,
    1803                 :             :                                       ret_clauses);
    1804                 :          52 :       gsi_insert_seq_before_without_update (&si, stmt, GSI_NEW_STMT);
    1805                 :             :     }
    1806                 :             : 
    1807                 :     5750961 :   if (cleanup)
    1808                 :             :     {
    1809                 :      715418 :       gtry *gs;
    1810                 :      715418 :       gimple_seq new_body;
    1811                 :             : 
    1812                 :      715418 :       new_body = NULL;
    1813                 :      715418 :       gs = gimple_build_try (gimple_bind_body (bind_stmt), cleanup,
    1814                 :             :                              GIMPLE_TRY_FINALLY);
    1815                 :             : 
    1816                 :      715418 :       if (stack_save)
    1817                 :        7763 :         gimplify_seq_add_stmt (&new_body, stack_save);
    1818                 :      715418 :       gimplify_seq_add_stmt (&new_body, gs);
    1819                 :      715418 :       gimple_bind_set_body (bind_stmt, new_body);
    1820                 :             :     }
    1821                 :             : 
    1822                 :             :   /* keep_stack propagates all the way up to the outermost BIND_EXPR.  */
    1823                 :     5750961 :   if (!gimplify_ctxp->keep_stack)
    1824                 :     5735880 :     gimplify_ctxp->keep_stack = old_keep_stack;
    1825                 :     5750961 :   gimplify_ctxp->save_stack = old_save_stack;
    1826                 :             : 
    1827                 :     5750961 :   gimple_pop_bind_expr ();
    1828                 :             : 
    1829                 :     5750961 :   gimplify_seq_add_stmt (pre_p, bind_stmt);
    1830                 :             : 
    1831                 :     5750961 :   if (temp)
    1832                 :             :     {
    1833                 :        1709 :       *expr_p = temp;
    1834                 :        1709 :       return GS_OK;
    1835                 :             :     }
    1836                 :             : 
    1837                 :     5749252 :   *expr_p = NULL_TREE;
    1838                 :     5749252 :   return GS_ALL_DONE;
    1839                 :             : }
    1840                 :             : 
    1841                 :             : /* Maybe add early return predict statement to PRE_P sequence.  */
    1842                 :             : 
    1843                 :             : static void
    1844                 :     2070234 : maybe_add_early_return_predict_stmt (gimple_seq *pre_p)
    1845                 :             : {
    1846                 :             :   /* If we are not in a conditional context, add PREDICT statement.  */
    1847                 :     2070234 :   if (gimple_conditional_context ())
    1848                 :             :     {
    1849                 :      423584 :       gimple *predict = gimple_build_predict (PRED_TREE_EARLY_RETURN,
    1850                 :             :                                               NOT_TAKEN);
    1851                 :      423584 :       gimplify_seq_add_stmt (pre_p, predict);
    1852                 :             :     }
    1853                 :     2070234 : }
    1854                 :             : 
    1855                 :             : /* Gimplify a RETURN_EXPR.  If the expression to be returned is not a
    1856                 :             :    GIMPLE value, it is assigned to a new temporary and the statement is
    1857                 :             :    re-written to return the temporary.
    1858                 :             : 
    1859                 :             :    PRE_P points to the sequence where side effects that must happen before
    1860                 :             :    STMT should be stored.  */
    1861                 :             : 
    1862                 :             : static enum gimplify_status
    1863                 :     2070234 : gimplify_return_expr (tree stmt, gimple_seq *pre_p)
    1864                 :             : {
    1865                 :     2070234 :   greturn *ret;
    1866                 :     2070234 :   tree ret_expr = TREE_OPERAND (stmt, 0);
    1867                 :     2070234 :   tree result_decl, result;
    1868                 :             : 
    1869                 :     2070234 :   if (ret_expr == error_mark_node)
    1870                 :             :     return GS_ERROR;
    1871                 :             : 
    1872                 :     2070234 :   if (!ret_expr
    1873                 :     1991457 :       || TREE_CODE (ret_expr) == RESULT_DECL)
    1874                 :             :     {
    1875                 :       91859 :       maybe_add_early_return_predict_stmt (pre_p);
    1876                 :       91859 :       greturn *ret = gimple_build_return (ret_expr);
    1877                 :       91859 :       copy_warning (ret, stmt);
    1878                 :       91859 :       gimplify_seq_add_stmt (pre_p, ret);
    1879                 :       91859 :       return GS_ALL_DONE;
    1880                 :             :     }
    1881                 :             : 
    1882                 :     1978375 :   if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (current_function_decl))))
    1883                 :             :     result_decl = NULL_TREE;
    1884                 :     1978112 :   else if (TREE_CODE (ret_expr) == COMPOUND_EXPR)
    1885                 :             :     {
    1886                 :             :       /* Used in C++ for handling EH cleanup of the return value if a local
    1887                 :             :          cleanup throws.  Assume the front-end knows what it's doing.  */
    1888                 :        4618 :       result_decl = DECL_RESULT (current_function_decl);
    1889                 :             :       /* But crash if we end up trying to modify ret_expr below.  */
    1890                 :        4618 :       ret_expr = NULL_TREE;
    1891                 :             :     }
    1892                 :             :   else
    1893                 :             :     {
    1894                 :     1973494 :       result_decl = TREE_OPERAND (ret_expr, 0);
    1895                 :             : 
    1896                 :             :       /* See through a return by reference.  */
    1897                 :     1973494 :       if (INDIRECT_REF_P (result_decl))
    1898                 :       35138 :         result_decl = TREE_OPERAND (result_decl, 0);
    1899                 :             : 
    1900                 :     1973494 :       gcc_assert ((TREE_CODE (ret_expr) == MODIFY_EXPR
    1901                 :             :                    || TREE_CODE (ret_expr) == INIT_EXPR)
    1902                 :             :                   && TREE_CODE (result_decl) == RESULT_DECL);
    1903                 :             :     }
    1904                 :             : 
    1905                 :             :   /* If aggregate_value_p is true, then we can return the bare RESULT_DECL.
    1906                 :             :      Recall that aggregate_value_p is FALSE for any aggregate type that is
    1907                 :             :      returned in registers.  If we're returning values in registers, then
    1908                 :             :      we don't want to extend the lifetime of the RESULT_DECL, particularly
    1909                 :             :      across another call.  In addition, for those aggregates for which
    1910                 :             :      hard_function_value generates a PARALLEL, we'll die during normal
    1911                 :             :      expansion of structure assignments; there's special code in expand_return
    1912                 :             :      to handle this case that does not exist in expand_expr.  */
    1913                 :        4618 :   if (!result_decl)
    1914                 :             :     result = NULL_TREE;
    1915                 :     1978112 :   else if (aggregate_value_p (result_decl, TREE_TYPE (current_function_decl)))
    1916                 :             :     {
    1917                 :      162669 :       if (!poly_int_tree_p (DECL_SIZE (result_decl)))
    1918                 :             :         {
    1919                 :          43 :           if (!TYPE_SIZES_GIMPLIFIED (TREE_TYPE (result_decl)))
    1920                 :           0 :             gimplify_type_sizes (TREE_TYPE (result_decl), pre_p);
    1921                 :             :           /* Note that we don't use gimplify_vla_decl because the RESULT_DECL
    1922                 :             :              should be effectively allocated by the caller, i.e. all calls to
    1923                 :             :              this function must be subject to the Return Slot Optimization.  */
    1924                 :          43 :           gimplify_one_sizepos (&DECL_SIZE (result_decl), pre_p);
    1925                 :          43 :           gimplify_one_sizepos (&DECL_SIZE_UNIT (result_decl), pre_p);
    1926                 :             :         }
    1927                 :             :       result = result_decl;
    1928                 :             :     }
    1929                 :     1815443 :   else if (gimplify_ctxp->return_temp)
    1930                 :             :     result = gimplify_ctxp->return_temp;
    1931                 :             :   else
    1932                 :             :     {
    1933                 :     1352808 :       result = create_tmp_reg (TREE_TYPE (result_decl));
    1934                 :             : 
    1935                 :             :       /* ??? With complex control flow (usually involving abnormal edges),
    1936                 :             :          we can wind up warning about an uninitialized value for this.  Due
    1937                 :             :          to how this variable is constructed and initialized, this is never
    1938                 :             :          true.  Give up and never warn.  */
    1939                 :     1352808 :       suppress_warning (result, OPT_Wuninitialized);
    1940                 :             : 
    1941                 :     1352808 :       gimplify_ctxp->return_temp = result;
    1942                 :             :     }
    1943                 :             : 
    1944                 :             :   /* Smash the lhs of the MODIFY_EXPR to the temporary we plan to use.
    1945                 :             :      Then gimplify the whole thing.  */
    1946                 :     1978375 :   if (result != result_decl)
    1947                 :     1815443 :     TREE_OPERAND (ret_expr, 0) = result;
    1948                 :             : 
    1949                 :     1978375 :   gimplify_and_add (TREE_OPERAND (stmt, 0), pre_p);
    1950                 :             : 
    1951                 :     1978375 :   maybe_add_early_return_predict_stmt (pre_p);
    1952                 :     1978375 :   ret = gimple_build_return (result);
    1953                 :     1978375 :   copy_warning (ret, stmt);
    1954                 :     1978375 :   gimplify_seq_add_stmt (pre_p, ret);
    1955                 :             : 
    1956                 :     1978375 :   return GS_ALL_DONE;
    1957                 :             : }
    1958                 :             : 
    1959                 :             : /* Gimplify a variable-length array DECL.  */
    1960                 :             : 
    1961                 :             : static void
    1962                 :        8834 : gimplify_vla_decl (tree decl, gimple_seq *seq_p)
    1963                 :             : {
    1964                 :             :   /* This is a variable-sized decl.  Simplify its size and mark it
    1965                 :             :      for deferred expansion.  */
    1966                 :        8834 :   tree t, addr, ptr_type;
    1967                 :             : 
    1968                 :        8834 :   gimplify_one_sizepos (&DECL_SIZE (decl), seq_p);
    1969                 :        8834 :   gimplify_one_sizepos (&DECL_SIZE_UNIT (decl), seq_p);
    1970                 :             : 
    1971                 :             :   /* Don't mess with a DECL_VALUE_EXPR set by the front-end.  */
    1972                 :        8834 :   if (DECL_HAS_VALUE_EXPR_P (decl))
    1973                 :             :     return;
    1974                 :             : 
    1975                 :             :   /* All occurrences of this decl in final gimplified code will be
    1976                 :             :      replaced by indirection.  Setting DECL_VALUE_EXPR does two
    1977                 :             :      things: First, it lets the rest of the gimplifier know what
    1978                 :             :      replacement to use.  Second, it lets the debug info know
    1979                 :             :      where to find the value.  */
    1980                 :        8829 :   ptr_type = build_pointer_type (TREE_TYPE (decl));
    1981                 :        8829 :   addr = create_tmp_var (ptr_type, get_name (decl));
    1982                 :        8829 :   DECL_IGNORED_P (addr) = 0;
    1983                 :        8829 :   t = build_fold_indirect_ref (addr);
    1984                 :        8829 :   TREE_THIS_NOTRAP (t) = 1;
    1985                 :        8829 :   SET_DECL_VALUE_EXPR (decl, t);
    1986                 :        8829 :   DECL_HAS_VALUE_EXPR_P (decl) = 1;
    1987                 :             : 
    1988                 :        8829 :   t = build_alloca_call_expr (DECL_SIZE_UNIT (decl), DECL_ALIGN (decl),
    1989                 :        8829 :                               max_int_size_in_bytes (TREE_TYPE (decl)));
    1990                 :             :   /* The call has been built for a variable-sized object.  */
    1991                 :        8829 :   CALL_ALLOCA_FOR_VAR_P (t) = 1;
    1992                 :        8829 :   t = fold_convert (ptr_type, t);
    1993                 :        8829 :   t = build2 (MODIFY_EXPR, TREE_TYPE (addr), addr, t);
    1994                 :             : 
    1995                 :        8829 :   gimplify_and_add (t, seq_p);
    1996                 :             : 
    1997                 :             :   /* Record the dynamic allocation associated with DECL if requested.  */
    1998                 :        8829 :   if (flag_callgraph_info & CALLGRAPH_INFO_DYNAMIC_ALLOC)
    1999                 :           0 :     record_dynamic_alloc (decl);
    2000                 :             : }
    2001                 :             : 
    2002                 :             : /* A helper function to be called via walk_tree.  Mark all labels under *TP
    2003                 :             :    as being forced.  To be called for DECL_INITIAL of static variables.  */
    2004                 :             : 
    2005                 :             : static tree
    2006                 :      823689 : force_labels_r (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED)
    2007                 :             : {
    2008                 :      823689 :   if (TYPE_P (*tp))
    2009                 :           0 :     *walk_subtrees = 0;
    2010                 :      823689 :   if (TREE_CODE (*tp) == LABEL_DECL)
    2011                 :             :     {
    2012                 :         921 :       FORCED_LABEL (*tp) = 1;
    2013                 :         921 :       cfun->has_forced_label_in_static = 1;
    2014                 :             :     }
    2015                 :             : 
    2016                 :      823689 :   return NULL_TREE;
    2017                 :             : }
    2018                 :             : 
    2019                 :             : /* Generate an initialization to automatic variable DECL based on INIT_TYPE.
    2020                 :             :    Build a call to internal const function DEFERRED_INIT:
    2021                 :             :    1st argument: SIZE of the DECL;
    2022                 :             :    2nd argument: INIT_TYPE;
    2023                 :             :    3rd argument: NAME of the DECL;
    2024                 :             : 
    2025                 :             :    as LHS = DEFERRED_INIT (SIZE of the DECL, INIT_TYPE, NAME of the DECL).  */
    2026                 :             : 
    2027                 :             : static void
    2028                 :         588 : gimple_add_init_for_auto_var (tree decl,
    2029                 :             :                               enum auto_init_type init_type,
    2030                 :             :                               gimple_seq *seq_p)
    2031                 :             : {
    2032                 :         588 :   gcc_assert (auto_var_p (decl));
    2033                 :         588 :   gcc_assert (init_type > AUTO_INIT_UNINITIALIZED);
    2034                 :             : 
    2035                 :         588 :   const location_t loc = DECL_SOURCE_LOCATION (decl);
    2036                 :         588 :   tree decl_size = TYPE_SIZE_UNIT (TREE_TYPE (decl));
    2037                 :         588 :   tree init_type_node = build_int_cst (integer_type_node, (int) init_type);
    2038                 :         588 :   tree decl_name;
    2039                 :             : 
    2040                 :         588 :   if (DECL_NAME (decl))
    2041                 :         585 :     decl_name = build_string_literal (DECL_NAME (decl));
    2042                 :             :   else
    2043                 :             :     {
    2044                 :           3 :       char decl_name_anonymous[3 + (HOST_BITS_PER_INT + 2) / 3];
    2045                 :           3 :       sprintf (decl_name_anonymous, "D.%u", DECL_UID (decl));
    2046                 :           3 :       decl_name = build_string_literal (decl_name_anonymous);
    2047                 :             :     }
    2048                 :             : 
    2049                 :         588 :   tree call = build_call_expr_internal_loc (loc, IFN_DEFERRED_INIT,
    2050                 :         588 :                                             TREE_TYPE (decl), 3,
    2051                 :             :                                             decl_size, init_type_node,
    2052                 :             :                                             decl_name);
    2053                 :             : 
    2054                 :         588 :   gimplify_assign (decl, call, seq_p);
    2055                 :         588 : }
    2056                 :             : 
    2057                 :             : /* Generate padding initialization for automatic variable DECL.
    2058                 :             :    C guarantees that brace-init with fewer initializers than members
    2059                 :             :    aggregate will initialize the rest of the aggregate as-if it were
    2060                 :             :    static initialization.  In turn static initialization guarantees
    2061                 :             :    that padding is initialized to zero. So, we always initialize paddings
    2062                 :             :    to zeroes regardless INIT_TYPE.
    2063                 :             :    To do the padding initialization, we insert a call to
    2064                 :             :    __builtin_clear_padding (&decl, 0, for_auto_init = true).
    2065                 :             :    Note, we add an additional dummy argument for __builtin_clear_padding,
    2066                 :             :    'for_auto_init' to distinguish whether this call is for automatic
    2067                 :             :    variable initialization or not.
    2068                 :             :    */
    2069                 :             : static void
    2070                 :         109 : gimple_add_padding_init_for_auto_var (tree decl, bool is_vla,
    2071                 :             :                                       gimple_seq *seq_p)
    2072                 :             : {
    2073                 :         109 :   tree addr_of_decl = NULL_TREE;
    2074                 :         109 :   tree fn = builtin_decl_explicit (BUILT_IN_CLEAR_PADDING);
    2075                 :             : 
    2076                 :         109 :   if (is_vla)
    2077                 :             :     {
    2078                 :             :       /* The temporary address variable for this vla should be
    2079                 :             :          created in gimplify_vla_decl.  */
    2080                 :           0 :       gcc_assert (DECL_HAS_VALUE_EXPR_P (decl));
    2081                 :           0 :       gcc_assert (INDIRECT_REF_P (DECL_VALUE_EXPR (decl)));
    2082                 :           0 :       addr_of_decl = TREE_OPERAND (DECL_VALUE_EXPR (decl), 0);
    2083                 :             :     }
    2084                 :             :   else
    2085                 :             :     {
    2086                 :         109 :       mark_addressable (decl);
    2087                 :         109 :       addr_of_decl = build_fold_addr_expr (decl);
    2088                 :             :     }
    2089                 :             : 
    2090                 :         109 :   gimple *call = gimple_build_call (fn, 2, addr_of_decl,
    2091                 :         109 :                                     build_one_cst (TREE_TYPE (addr_of_decl)));
    2092                 :         109 :   gimplify_seq_add_stmt (seq_p, call);
    2093                 :         109 : }
    2094                 :             : 
    2095                 :             : /* Return true if the DECL need to be automaticly initialized by the
    2096                 :             :    compiler.  */
    2097                 :             : static bool
    2098                 :     3270535 : is_var_need_auto_init (tree decl)
    2099                 :             : {
    2100                 :     3270535 :   if (auto_var_p (decl)
    2101                 :     3182453 :       && (TREE_CODE (decl) != VAR_DECL
    2102                 :     3180998 :           || !DECL_HARD_REGISTER (decl))
    2103                 :     3181755 :       && (flag_auto_var_init > AUTO_INIT_UNINITIALIZED)
    2104                 :         641 :       && (!lookup_attribute ("uninitialized", DECL_ATTRIBUTES (decl)))
    2105                 :         633 :       && !OPAQUE_TYPE_P (TREE_TYPE (decl))
    2106                 :     3271168 :       && !is_empty_type (TREE_TYPE (decl)))
    2107                 :             :     return true;
    2108                 :             :   return false;
    2109                 :             : }
    2110                 :             : 
    2111                 :             : /* Gimplify a DECL_EXPR node *STMT_P by making any necessary allocation
    2112                 :             :    and initialization explicit.  */
    2113                 :             : 
    2114                 :             : static enum gimplify_status
    2115                 :     6310062 : gimplify_decl_expr (tree *stmt_p, gimple_seq *seq_p)
    2116                 :             : {
    2117                 :     6310062 :   tree stmt = *stmt_p;
    2118                 :     6310062 :   tree decl = DECL_EXPR_DECL (stmt);
    2119                 :             : 
    2120                 :     6310062 :   *stmt_p = NULL_TREE;
    2121                 :             : 
    2122                 :     6310062 :   if (TREE_TYPE (decl) == error_mark_node)
    2123                 :             :     return GS_ERROR;
    2124                 :             : 
    2125                 :     6309997 :   if ((TREE_CODE (decl) == TYPE_DECL
    2126                 :     6268197 :        || VAR_P (decl))
    2127                 :    12575241 :       && !TYPE_SIZES_GIMPLIFIED (TREE_TYPE (decl)))
    2128                 :             :     {
    2129                 :      661904 :       gimplify_type_sizes (TREE_TYPE (decl), seq_p);
    2130                 :      661904 :       if (TREE_CODE (TREE_TYPE (decl)) == REFERENCE_TYPE)
    2131                 :       19937 :         gimplify_type_sizes (TREE_TYPE (TREE_TYPE (decl)), seq_p);
    2132                 :             :     }
    2133                 :             : 
    2134                 :             :   /* ??? DECL_ORIGINAL_TYPE is streamed for LTO so it needs to be gimplified
    2135                 :             :      in case its size expressions contain problematic nodes like CALL_EXPR.  */
    2136                 :     6309997 :   if (TREE_CODE (decl) == TYPE_DECL
    2137                 :       41800 :       && DECL_ORIGINAL_TYPE (decl)
    2138                 :     6315304 :       && !TYPE_SIZES_GIMPLIFIED (DECL_ORIGINAL_TYPE (decl)))
    2139                 :             :     {
    2140                 :           0 :       gimplify_type_sizes (DECL_ORIGINAL_TYPE (decl), seq_p);
    2141                 :           0 :       if (TREE_CODE (DECL_ORIGINAL_TYPE (decl)) == REFERENCE_TYPE)
    2142                 :           0 :         gimplify_type_sizes (TREE_TYPE (DECL_ORIGINAL_TYPE (decl)), seq_p);
    2143                 :             :     }
    2144                 :             : 
    2145                 :     6309997 :   if (VAR_P (decl) && !DECL_EXTERNAL (decl))
    2146                 :             :     {
    2147                 :     6265244 :       tree init = DECL_INITIAL (decl);
    2148                 :     6265244 :       bool is_vla = false;
    2149                 :             :       /* Check whether a decl has FE created VALUE_EXPR here BEFORE
    2150                 :             :          gimplify_vla_decl creates VALUE_EXPR for a vla decl.
    2151                 :             :          If the decl has VALUE_EXPR that was created by FE (usually
    2152                 :             :          C++FE), it's a proxy varaible, and FE already initialized
    2153                 :             :          the VALUE_EXPR of it, we should not initialize it anymore.  */
    2154                 :     6265244 :       bool decl_had_value_expr_p = DECL_HAS_VALUE_EXPR_P (decl);
    2155                 :             : 
    2156                 :     6265244 :       poly_uint64 size;
    2157                 :     6265244 :       if (!poly_int_tree_p (DECL_SIZE_UNIT (decl), &size)
    2158                 :     6265244 :           || (!TREE_STATIC (decl)
    2159                 :     6145960 :               && flag_stack_check == GENERIC_STACK_CHECK
    2160                 :         228 :               && maybe_gt (size,
    2161                 :             :                            (unsigned HOST_WIDE_INT) STACK_CHECK_MAX_VAR_SIZE)))
    2162                 :             :         {
    2163                 :        8711 :           gimplify_vla_decl (decl, seq_p);
    2164                 :        8711 :           is_vla = true;
    2165                 :             :         }
    2166                 :             : 
    2167                 :     6265244 :       if (asan_poisoned_variables
    2168                 :        4377 :           && !is_vla
    2169                 :             :           && TREE_ADDRESSABLE (decl)
    2170                 :        4191 :           && !TREE_STATIC (decl)
    2171                 :        1806 :           && !DECL_HAS_VALUE_EXPR_P (decl)
    2172                 :        1764 :           && DECL_ALIGN (decl) <= MAX_SUPPORTED_STACK_ALIGNMENT
    2173                 :        1764 :           && dbg_cnt (asan_use_after_scope)
    2174                 :        1764 :           && !gimplify_omp_ctxp
    2175                 :             :           /* GNAT introduces temporaries to hold return values of calls in
    2176                 :             :              initializers of variables defined in other units, so the
    2177                 :             :              declaration of the variable is discarded completely.  We do not
    2178                 :             :              want to issue poison calls for such dropped variables.  */
    2179                 :     6267000 :           && (DECL_SEEN_IN_BIND_EXPR_P (decl)
    2180                 :           0 :               || (DECL_ARTIFICIAL (decl) && DECL_NAME (decl) == NULL_TREE)))
    2181                 :             :         {
    2182                 :        1756 :           asan_poisoned_variables->add (decl);
    2183                 :        1756 :           asan_poison_variable (decl, false, seq_p);
    2184                 :        1756 :           if (!DECL_ARTIFICIAL (decl) && gimplify_ctxp->live_switch_vars)
    2185                 :          55 :             gimplify_ctxp->live_switch_vars->add (decl);
    2186                 :             :         }
    2187                 :             : 
    2188                 :             :       /* Some front ends do not explicitly declare all anonymous
    2189                 :             :          artificial variables.  We compensate here by declaring the
    2190                 :             :          variables, though it would be better if the front ends would
    2191                 :             :          explicitly declare them.  */
    2192                 :     6265244 :       if (!DECL_SEEN_IN_BIND_EXPR_P (decl)
    2193                 :     6265244 :           && DECL_ARTIFICIAL (decl) && DECL_NAME (decl) == NULL_TREE)
    2194                 :       16078 :         gimple_add_tmp_var (decl);
    2195                 :             : 
    2196                 :     6265244 :       if (init && init != error_mark_node)
    2197                 :             :         {
    2198                 :     3626608 :           if (!TREE_STATIC (decl))
    2199                 :             :             {
    2200                 :     3598080 :               DECL_INITIAL (decl) = NULL_TREE;
    2201                 :     3598080 :               init = build2 (INIT_EXPR, void_type_node, decl, init);
    2202                 :     3598080 :               gimplify_and_add (init, seq_p);
    2203                 :     3598080 :               ggc_free (init);
    2204                 :             :               /* Clear TREE_READONLY if we really have an initialization.  */
    2205                 :     3598080 :               if (!DECL_INITIAL (decl)
    2206                 :     3598080 :                   && !omp_privatize_by_reference (decl))
    2207                 :     3582764 :                 TREE_READONLY (decl) = 0;
    2208                 :             :             }
    2209                 :             :           else
    2210                 :             :             /* We must still examine initializers for static variables
    2211                 :             :                as they may contain a label address.  */
    2212                 :       28528 :             walk_tree (&init, force_labels_r, NULL, NULL);
    2213                 :             :         }
    2214                 :             :       /* When there is no explicit initializer, if the user requested,
    2215                 :             :          We should insert an artifical initializer for this automatic
    2216                 :             :          variable.  */
    2217                 :     2638636 :       else if (is_var_need_auto_init (decl)
    2218                 :     2638636 :                && !decl_had_value_expr_p)
    2219                 :             :         {
    2220                 :         588 :           gimple_add_init_for_auto_var (decl,
    2221                 :             :                                         flag_auto_var_init,
    2222                 :             :                                         seq_p);
    2223                 :             :           /* The expanding of a call to the above .DEFERRED_INIT will apply
    2224                 :             :              block initialization to the whole space covered by this variable.
    2225                 :             :              As a result, all the paddings will be initialized to zeroes
    2226                 :             :              for zero initialization and 0xFE byte-repeatable patterns for
    2227                 :             :              pattern initialization.
    2228                 :             :              In order to make the paddings as zeroes for pattern init, We
    2229                 :             :              should add a call to __builtin_clear_padding to clear the
    2230                 :             :              paddings to zero in compatiple with CLANG.
    2231                 :             :              We cannot insert this call if the variable is a gimple register
    2232                 :             :              since __builtin_clear_padding will take the address of the
    2233                 :             :              variable.  As a result, if a long double/_Complex long double
    2234                 :             :              variable will spilled into stack later, its padding is 0XFE.  */
    2235                 :         588 :           if (flag_auto_var_init == AUTO_INIT_PATTERN
    2236                 :         180 :               && !is_gimple_reg (decl)
    2237                 :         682 :               && clear_padding_type_may_have_padding_p (TREE_TYPE (decl)))
    2238                 :          71 :             gimple_add_padding_init_for_auto_var (decl, is_vla, seq_p);
    2239                 :             :         }
    2240                 :             :     }
    2241                 :             : 
    2242                 :             :   return GS_ALL_DONE;
    2243                 :             : }
    2244                 :             : 
    2245                 :             : /* Gimplify a LOOP_EXPR.  Normally this just involves gimplifying the body
    2246                 :             :    and replacing the LOOP_EXPR with goto, but if the loop contains an
    2247                 :             :    EXIT_EXPR, we need to append a label for it to jump to.  */
    2248                 :             : 
    2249                 :             : static enum gimplify_status
    2250                 :      184102 : gimplify_loop_expr (tree *expr_p, gimple_seq *pre_p)
    2251                 :             : {
    2252                 :      184102 :   tree saved_label = gimplify_ctxp->exit_label;
    2253                 :      184102 :   tree start_label = create_artificial_label (UNKNOWN_LOCATION);
    2254                 :             : 
    2255                 :      184102 :   gimplify_seq_add_stmt (pre_p, gimple_build_label (start_label));
    2256                 :             : 
    2257                 :      184102 :   gimplify_ctxp->exit_label = NULL_TREE;
    2258                 :             : 
    2259                 :      184102 :   gimplify_and_add (LOOP_EXPR_BODY (*expr_p), pre_p);
    2260                 :             : 
    2261                 :      184102 :   gimplify_seq_add_stmt (pre_p, gimple_build_goto (start_label));
    2262                 :             : 
    2263                 :      184102 :   if (gimplify_ctxp->exit_label)
    2264                 :        5878 :     gimplify_seq_add_stmt (pre_p,
    2265                 :        2939 :                            gimple_build_label (gimplify_ctxp->exit_label));
    2266                 :             : 
    2267                 :      184102 :   gimplify_ctxp->exit_label = saved_label;
    2268                 :             : 
    2269                 :      184102 :   *expr_p = NULL;
    2270                 :      184102 :   return GS_ALL_DONE;
    2271                 :             : }
    2272                 :             : 
    2273                 :             : /* Gimplify a statement list onto a sequence.  These may be created either
    2274                 :             :    by an enlightened front-end, or by shortcut_cond_expr.  */
    2275                 :             : 
    2276                 :             : static enum gimplify_status
    2277                 :     8480390 : gimplify_statement_list (tree *expr_p, gimple_seq *pre_p)
    2278                 :             : {
    2279                 :     8480390 :   tree temp = voidify_wrapper_expr (*expr_p, NULL);
    2280                 :             : 
    2281                 :     8480390 :   tree_stmt_iterator i = tsi_start (*expr_p);
    2282                 :             : 
    2283                 :    53919032 :   while (!tsi_end_p (i))
    2284                 :             :     {
    2285                 :    36958252 :       gimplify_stmt (tsi_stmt_ptr (i), pre_p);
    2286                 :    36958252 :       tsi_delink (&i);
    2287                 :             :     }
    2288                 :             : 
    2289                 :     8480390 :   if (temp)
    2290                 :             :     {
    2291                 :       15141 :       *expr_p = temp;
    2292                 :       15141 :       return GS_OK;
    2293                 :             :     }
    2294                 :             : 
    2295                 :             :   return GS_ALL_DONE;
    2296                 :             : }
    2297                 :             : 
    2298                 :             : 
    2299                 :             : /* Emit warning for the unreachable statment STMT if needed.
    2300                 :             :    Return the gimple itself when the warning is emitted, otherwise
    2301                 :             :    return NULL.  */
    2302                 :             : static gimple *
    2303                 :         188 : emit_warn_switch_unreachable (gimple *stmt)
    2304                 :             : {
    2305                 :         188 :   if (gimple_code (stmt) == GIMPLE_GOTO
    2306                 :          45 :       && TREE_CODE (gimple_goto_dest (stmt)) == LABEL_DECL
    2307                 :         233 :       && DECL_ARTIFICIAL (gimple_goto_dest (stmt)))
    2308                 :             :   /* Don't warn for compiler-generated gotos.  These occur
    2309                 :             :      in Duff's devices, for example.  */
    2310                 :             :     return NULL;
    2311                 :         143 :   else if ((flag_auto_var_init > AUTO_INIT_UNINITIALIZED)
    2312                 :         143 :            && ((gimple_call_internal_p (stmt, IFN_DEFERRED_INIT))
    2313                 :           6 :                 || (gimple_call_builtin_p (stmt, BUILT_IN_CLEAR_PADDING)
    2314                 :           2 :                     && (bool) TREE_INT_CST_LOW (gimple_call_arg (stmt, 1)))
    2315                 :           4 :                 || (is_gimple_assign (stmt)
    2316                 :           4 :                     && gimple_assign_single_p (stmt)
    2317                 :           4 :                     && (TREE_CODE (gimple_assign_rhs1 (stmt)) == SSA_NAME)
    2318                 :           4 :                     && gimple_call_internal_p (
    2319                 :           4 :                          SSA_NAME_DEF_STMT (gimple_assign_rhs1 (stmt)),
    2320                 :             :                          IFN_DEFERRED_INIT))))
    2321                 :             :   /* Don't warn for compiler-generated initializations for
    2322                 :             :      -ftrivial-auto-var-init.
    2323                 :             :      There are 3 cases:
    2324                 :             :         case 1: a call to .DEFERRED_INIT;
    2325                 :             :         case 2: a call to __builtin_clear_padding with the 2nd argument is
    2326                 :             :                 present and non-zero;
    2327                 :             :         case 3: a gimple assign store right after the call to .DEFERRED_INIT
    2328                 :             :                 that has the LHS of .DEFERRED_INIT as the RHS as following:
    2329                 :             :                   _1 = .DEFERRED_INIT (4, 2, &"i1"[0]);
    2330                 :             :                   i1 = _1.  */
    2331                 :          12 :     return NULL;
    2332                 :             :   else
    2333                 :         131 :     warning_at (gimple_location (stmt), OPT_Wswitch_unreachable,
    2334                 :             :                 "statement will never be executed");
    2335                 :         131 :   return stmt;
    2336                 :             : }
    2337                 :             : 
    2338                 :             : /* Callback for walk_gimple_seq.  */
    2339                 :             : 
    2340                 :             : static tree
    2341                 :       48084 : warn_switch_unreachable_and_auto_init_r (gimple_stmt_iterator *gsi_p,
    2342                 :             :                                          bool *handled_ops_p,
    2343                 :             :                                          struct walk_stmt_info *wi)
    2344                 :             : {
    2345                 :       48084 :   gimple *stmt = gsi_stmt (*gsi_p);
    2346                 :       48084 :   bool unreachable_issued = wi->info != NULL;
    2347                 :             : 
    2348                 :       48084 :   *handled_ops_p = true;
    2349                 :       48084 :   switch (gimple_code (stmt))
    2350                 :             :     {
    2351                 :         133 :     case GIMPLE_TRY:
    2352                 :             :       /* A compiler-generated cleanup or a user-written try block.
    2353                 :             :          If it's empty, don't dive into it--that would result in
    2354                 :             :          worse location info.  */
    2355                 :         133 :       if (gimple_try_eval (stmt) == NULL)
    2356                 :             :         {
    2357                 :           3 :           if (warn_switch_unreachable && !unreachable_issued)
    2358                 :           3 :             wi->info = emit_warn_switch_unreachable (stmt);
    2359                 :             : 
    2360                 :             :           /* Stop when auto var init warning is not on.  */
    2361                 :           3 :           if (!warn_trivial_auto_var_init)
    2362                 :           3 :             return integer_zero_node;
    2363                 :             :         }
    2364                 :             :       /* Fall through.  */
    2365                 :        2397 :     case GIMPLE_BIND:
    2366                 :        2397 :     case GIMPLE_CATCH:
    2367                 :        2397 :     case GIMPLE_EH_FILTER:
    2368                 :        2397 :     case GIMPLE_TRANSACTION:
    2369                 :             :       /* Walk the sub-statements.  */
    2370                 :        2397 :       *handled_ops_p = false;
    2371                 :        2397 :       break;
    2372                 :             : 
    2373                 :             :     case GIMPLE_DEBUG:
    2374                 :             :       /* Ignore these.  We may generate them before declarations that
    2375                 :             :          are never executed.  If there's something to warn about,
    2376                 :             :          there will be non-debug stmts too, and we'll catch those.  */
    2377                 :             :       break;
    2378                 :             : 
    2379                 :       44671 :     case GIMPLE_LABEL:
    2380                 :             :       /* Stop till the first Label.  */
    2381                 :       44671 :       return integer_zero_node;
    2382                 :          46 :     case GIMPLE_CALL:
    2383                 :          46 :       if (gimple_call_internal_p (stmt, IFN_ASAN_MARK))
    2384                 :             :         {
    2385                 :           8 :           *handled_ops_p = false;
    2386                 :           8 :           break;
    2387                 :             :         }
    2388                 :          38 :       if (warn_trivial_auto_var_init
    2389                 :          14 :           && flag_auto_var_init > AUTO_INIT_UNINITIALIZED
    2390                 :          52 :           && gimple_call_internal_p (stmt, IFN_DEFERRED_INIT))
    2391                 :             :         {
    2392                 :             :           /* Get the variable name from the 3rd argument of call.  */
    2393                 :          12 :           tree var_name = gimple_call_arg (stmt, 2);
    2394                 :          12 :           var_name = TREE_OPERAND (TREE_OPERAND (var_name, 0), 0);
    2395                 :          12 :           const char *var_name_str = TREE_STRING_POINTER (var_name);
    2396                 :             : 
    2397                 :          12 :           warning_at (gimple_location (stmt), OPT_Wtrivial_auto_var_init,
    2398                 :             :                       "%qs cannot be initialized with"
    2399                 :             :                       "%<-ftrivial-auto-var_init%>",
    2400                 :             :                       var_name_str);
    2401                 :          12 :           break;
    2402                 :             :        }
    2403                 :             : 
    2404                 :             :       /* Fall through.  */
    2405                 :         185 :     default:
    2406                 :             :       /* check the first "real" statement (not a decl/lexical scope/...), issue
    2407                 :             :          warning if needed.  */
    2408                 :         185 :       if (warn_switch_unreachable && !unreachable_issued)
    2409                 :         185 :         wi->info = emit_warn_switch_unreachable (stmt);
    2410                 :             :       /* Stop when auto var init warning is not on.  */
    2411                 :         185 :       if (!warn_trivial_auto_var_init)
    2412                 :         179 :         return integer_zero_node;
    2413                 :             :       break;
    2414                 :             :     }
    2415                 :             :   return NULL_TREE;
    2416                 :             : }
    2417                 :             : 
    2418                 :             : 
    2419                 :             : /* Possibly warn about unreachable statements between switch's controlling
    2420                 :             :    expression and the first case.  Also warn about -ftrivial-auto-var-init
    2421                 :             :    cannot initialize the auto variable under such situation.
    2422                 :             :    SEQ is the body of a switch expression.  */
    2423                 :             : 
    2424                 :             : static void
    2425                 :       48637 : maybe_warn_switch_unreachable_and_auto_init (gimple_seq seq)
    2426                 :             : {
    2427                 :          60 :   if ((!warn_switch_unreachable && !warn_trivial_auto_var_init)
    2428                 :             :       /* This warning doesn't play well with Fortran when optimizations
    2429                 :             :          are on.  */
    2430                 :       48577 :       || lang_GNU_Fortran ()
    2431                 :       93648 :       || seq == NULL)
    2432                 :        3781 :     return;
    2433                 :             : 
    2434                 :       44856 :   struct walk_stmt_info wi;
    2435                 :             : 
    2436                 :       44856 :   memset (&wi, 0, sizeof (wi));
    2437                 :       44856 :   walk_gimple_seq (seq, warn_switch_unreachable_and_auto_init_r, NULL, &wi);
    2438                 :             : }
    2439                 :             : 
    2440                 :             : 
    2441                 :             : /* A label entry that pairs label and a location.  */
    2442                 :             : struct label_entry
    2443                 :             : {
    2444                 :             :   tree label;
    2445                 :             :   location_t loc;
    2446                 :             : };
    2447                 :             : 
    2448                 :             : /* Find LABEL in vector of label entries VEC.  */
    2449                 :             : 
    2450                 :             : static struct label_entry *
    2451                 :       11743 : find_label_entry (const auto_vec<struct label_entry> *vec, tree label)
    2452                 :             : {
    2453                 :       11743 :   unsigned int i;
    2454                 :       11743 :   struct label_entry *l;
    2455                 :             : 
    2456                 :       22492 :   FOR_EACH_VEC_ELT (*vec, i, l)
    2457                 :       19215 :     if (l->label == label)
    2458                 :             :       return l;
    2459                 :             :   return NULL;
    2460                 :             : }
    2461                 :             : 
    2462                 :             : /* Return true if LABEL, a LABEL_DECL, represents a case label
    2463                 :             :    in a vector of labels CASES.  */
    2464                 :             : 
    2465                 :             : static bool
    2466                 :       15160 : case_label_p (const vec<tree> *cases, tree label)
    2467                 :             : {
    2468                 :       15160 :   unsigned int i;
    2469                 :       15160 :   tree l;
    2470                 :             : 
    2471                 :      154830 :   FOR_EACH_VEC_ELT (*cases, i, l)
    2472                 :      154504 :     if (CASE_LABEL (l) == label)
    2473                 :             :       return true;
    2474                 :             :   return false;
    2475                 :             : }
    2476                 :             : 
    2477                 :             : /* Find the last nondebug statement in a scope STMT.  */
    2478                 :             : 
    2479                 :             : static gimple *
    2480                 :        2056 : last_stmt_in_scope (gimple *stmt)
    2481                 :             : {
    2482                 :        3850 :   if (!stmt)
    2483                 :             :     return NULL;
    2484                 :             : 
    2485                 :        3839 :   switch (gimple_code (stmt))
    2486                 :             :     {
    2487                 :        1324 :     case GIMPLE_BIND:
    2488                 :        1324 :       {
    2489                 :        1324 :         gbind *bind = as_a <gbind *> (stmt);
    2490                 :        1324 :         stmt = gimple_seq_last_nondebug_stmt (gimple_bind_body (bind));
    2491                 :        1324 :         return last_stmt_in_scope (stmt);
    2492                 :             :       }
    2493                 :             : 
    2494                 :         633 :     case GIMPLE_TRY:
    2495                 :         633 :       {
    2496                 :         633 :         gtry *try_stmt = as_a <gtry *> (stmt);
    2497                 :         633 :         stmt = gimple_seq_last_nondebug_stmt (gimple_try_eval (try_stmt));
    2498                 :         633 :         gimple *last_eval = last_stmt_in_scope (stmt);
    2499                 :         633 :         if (gimple_stmt_may_fallthru (last_eval)
    2500                 :         489 :             && (last_eval == NULL
    2501                 :         486 :                 || !gimple_call_internal_p (last_eval, IFN_FALLTHROUGH))
    2502                 :        1115 :             && gimple_try_kind (try_stmt) == GIMPLE_TRY_FINALLY)
    2503                 :             :           {
    2504                 :         470 :             stmt = gimple_seq_last_nondebug_stmt (gimple_try_cleanup (try_stmt));
    2505                 :         470 :             return last_stmt_in_scope (stmt);
    2506                 :             :           }
    2507                 :             :         else
    2508                 :             :           return last_eval;
    2509                 :             :       }
    2510                 :             : 
    2511                 :           0 :     case GIMPLE_DEBUG:
    2512                 :           0 :       gcc_unreachable ();
    2513                 :             : 
    2514                 :             :     default:
    2515                 :             :       return stmt;
    2516                 :             :     }
    2517                 :             : }
    2518                 :             : 
    2519                 :             : /* Collect labels that may fall through into LABELS and return the statement
    2520                 :             :    preceding another case label, or a user-defined label.  Store a location
    2521                 :             :    useful to give warnings at *PREVLOC (usually the location of the returned
    2522                 :             :    statement or of its surrounding scope).  */
    2523                 :             : 
    2524                 :             : static gimple *
    2525                 :       19547 : collect_fallthrough_labels (gimple_stmt_iterator *gsi_p,
    2526                 :             :                             auto_vec <struct label_entry> *labels,
    2527                 :             :                             location_t *prevloc)
    2528                 :             : {
    2529                 :       19547 :   gimple *prev = NULL;
    2530                 :             : 
    2531                 :       19547 :   *prevloc = UNKNOWN_LOCATION;
    2532                 :       95914 :   do
    2533                 :             :     {
    2534                 :       95914 :       if (gimple_code (gsi_stmt (*gsi_p)) == GIMPLE_BIND)
    2535                 :             :         {
    2536                 :             :           /* Recognize the special GIMPLE_BIND added by gimplify_switch_expr,
    2537                 :             :              which starts on a GIMPLE_SWITCH and ends with a break label.
    2538                 :             :              Handle that as a single statement that can fall through.  */
    2539                 :        1385 :           gbind *bind = as_a <gbind *> (gsi_stmt (*gsi_p));
    2540                 :        1385 :           gimple *first = gimple_seq_first_stmt (gimple_bind_body (bind));
    2541                 :        1385 :           gimple *last = gimple_seq_last_stmt (gimple_bind_body (bind));
    2542                 :        1377 :           if (last
    2543                 :        1377 :               && gimple_code (first) == GIMPLE_SWITCH
    2544                 :        1479 :               && gimple_code (last) == GIMPLE_LABEL)
    2545                 :             :             {
    2546                 :         102 :               tree label = gimple_label_label (as_a <glabel *> (last));
    2547                 :         102 :               if (SWITCH_BREAK_LABEL_P (label))
    2548                 :             :                 {
    2549                 :         102 :                   prev = bind;
    2550                 :         102 :                   gsi_next (gsi_p);
    2551                 :         102 :                   continue;
    2552                 :             :                 }
    2553                 :             :             }
    2554                 :             :         }
    2555                 :       95812 :       if (gimple_code (gsi_stmt (*gsi_p)) == GIMPLE_BIND
    2556                 :       95812 :           || gimple_code (gsi_stmt (*gsi_p)) == GIMPLE_TRY)
    2557                 :             :         {
    2558                 :             :           /* Nested scope.  Only look at the last statement of
    2559                 :             :              the innermost scope.  */
    2560                 :        1423 :           location_t bind_loc = gimple_location (gsi_stmt (*gsi_p));
    2561                 :        1423 :           gimple *last = last_stmt_in_scope (gsi_stmt (*gsi_p));
    2562                 :        1423 :           if (last)
    2563                 :             :             {
    2564                 :        1415 :               prev = last;
    2565                 :             :               /* It might be a label without a location.  Use the
    2566                 :             :                  location of the scope then.  */
    2567                 :        1415 :               if (!gimple_has_location (prev))
    2568                 :         616 :                 *prevloc = bind_loc;
    2569                 :             :             }
    2570                 :        1423 :           gsi_next (gsi_p);
    2571                 :        1423 :           continue;
    2572                 :        1423 :         }
    2573                 :             : 
    2574                 :             :       /* Ifs are tricky.  */
    2575                 :       94389 :       if (gimple_code (gsi_stmt (*gsi_p)) == GIMPLE_COND)
    2576                 :             :         {
    2577                 :        6945 :           gcond *cond_stmt = as_a <gcond *> (gsi_stmt (*gsi_p));
    2578                 :        6945 :           tree false_lab = gimple_cond_false_label (cond_stmt);
    2579                 :        6945 :           location_t if_loc = gimple_location (cond_stmt);
    2580                 :             : 
    2581                 :             :           /* If we have e.g.
    2582                 :             :                if (i > 1) goto <D.2259>; else goto D;
    2583                 :             :              we can't do much with the else-branch.  */
    2584                 :        6945 :           if (!DECL_ARTIFICIAL (false_lab))
    2585                 :             :             break;
    2586                 :             : 
    2587                 :             :           /* Go on until the false label, then one step back.  */
    2588                 :       52964 :           for (; !gsi_end_p (*gsi_p); gsi_next (gsi_p))
    2589                 :             :             {
    2590                 :       52964 :               gimple *stmt = gsi_stmt (*gsi_p);
    2591                 :       52964 :               if (gimple_code (stmt) == GIMPLE_LABEL
    2592                 :       52964 :                   && gimple_label_label (as_a <glabel *> (stmt)) == false_lab)
    2593                 :             :                 break;
    2594                 :             :             }
    2595                 :             : 
    2596                 :             :           /* Not found?  Oops.  */
    2597                 :        6945 :           if (gsi_end_p (*gsi_p))
    2598                 :             :             break;
    2599                 :             : 
    2600                 :             :           /* A dead label can't fall through.  */
    2601                 :        6945 :           if (!UNUSED_LABEL_P (false_lab))
    2602                 :             :             {
    2603                 :        6898 :               struct label_entry l = { false_lab, if_loc };
    2604                 :        6898 :               labels->safe_push (l);
    2605                 :             :             }
    2606                 :             : 
    2607                 :             :           /* Go to the last statement of the then branch.  */
    2608                 :        6945 :           gsi_prev (gsi_p);
    2609                 :             : 
    2610                 :             :           /* if (i != 0) goto <D.1759>; else goto <D.1760>;
    2611                 :             :              <D.1759>:
    2612                 :             :              <stmt>;
    2613                 :             :              goto <D.1761>;
    2614                 :             :              <D.1760>:
    2615                 :             :            */
    2616                 :        6945 :           if (gimple_code (gsi_stmt (*gsi_p)) == GIMPLE_GOTO
    2617                 :        6945 :               && !gimple_has_location (gsi_stmt (*gsi_p)))
    2618                 :             :             {
    2619                 :             :               /* Look at the statement before, it might be
    2620                 :             :                  attribute fallthrough, in which case don't warn.  */
    2621                 :        1427 :               gsi_prev (gsi_p);
    2622                 :        1427 :               bool fallthru_before_dest
    2623                 :        1427 :                 = gimple_call_internal_p (gsi_stmt (*gsi_p), IFN_FALLTHROUGH);
    2624                 :        1427 :               gsi_next (gsi_p);
    2625                 :        1427 :               tree goto_dest = gimple_goto_dest (gsi_stmt (*gsi_p));
    2626                 :        1427 :               if (!fallthru_before_dest)
    2627                 :             :                 {
    2628                 :        1370 :                   struct label_entry l = { goto_dest, if_loc };
    2629                 :        1370 :                   labels->safe_push (l);
    2630                 :             :                 }
    2631                 :             :             }
    2632                 :             :           /* This case is about
    2633                 :             :               if (1 != 0) goto <D.2022>; else goto <D.2023>;
    2634                 :             :               <D.2022>:
    2635                 :             :               n = n + 1; // #1
    2636                 :             :               <D.2023>:  // #2
    2637                 :             :               <D.1988>:  // #3
    2638                 :             :              where #2 is UNUSED_LABEL_P and we want to warn about #1 falling
    2639                 :             :              through to #3.  So set PREV to #1.  */
    2640                 :        5518 :           else if (UNUSED_LABEL_P (false_lab))
    2641                 :          47 :             prev = gsi_stmt (*gsi_p);
    2642                 :             : 
    2643                 :             :           /* And move back.  */
    2644                 :        6945 :           gsi_next (gsi_p);
    2645                 :             :         }
    2646                 :             : 
    2647                 :             :       /* Remember the last statement.  Skip labels that are of no interest
    2648                 :             :          to us.  */
    2649                 :       94389 :       if (gimple_code (gsi_stmt (*gsi_p)) == GIMPLE_LABEL)
    2650                 :             :         {
    2651                 :       11525 :           tree label = gimple_label_label (as_a <glabel *> (gsi_stmt (*gsi_p)));
    2652                 :       11525 :           if (find_label_entry (labels, label))
    2653                 :       70142 :             prev = gsi_stmt (*gsi_p);
    2654                 :             :         }
    2655                 :       82864 :       else if (gimple_call_internal_p (gsi_stmt (*gsi_p), IFN_ASAN_MARK))
    2656                 :             :         ;
    2657                 :       82864 :       else if (gimple_code (gsi_stmt (*gsi_p)) == GIMPLE_PREDICT)
    2658                 :             :         ;
    2659                 :       81700 :       else if (!is_gimple_debug (gsi_stmt (*gsi_p)))
    2660                 :       70142 :         prev = gsi_stmt (*gsi_p);
    2661                 :       94389 :       gsi_next (gsi_p);
    2662                 :             :     }
    2663                 :       95914 :   while (!gsi_end_p (*gsi_p)
    2664                 :             :          /* Stop if we find a case or a user-defined label.  */
    2665                 :      191828 :          && (gimple_code (gsi_stmt (*gsi_p)) != GIMPLE_LABEL
    2666                 :       20256 :              || !gimple_has_location (gsi_stmt (*gsi_p))));
    2667                 :             : 
    2668                 :       19547 :   if (prev && gimple_has_location (prev))
    2669                 :       19094 :     *prevloc = gimple_location (prev);
    2670                 :       19547 :   return prev;
    2671                 :             : }
    2672                 :             : 
    2673                 :             : /* Return true if the switch fallthough warning should occur.  LABEL is
    2674                 :             :    the label statement that we're falling through to.  */
    2675                 :             : 
    2676                 :             : static bool
    2677                 :       15669 : should_warn_for_implicit_fallthrough (gimple_stmt_iterator *gsi_p, tree label)
    2678                 :             : {
    2679                 :       15669 :   gimple_stmt_iterator gsi = *gsi_p;
    2680                 :             : 
    2681                 :             :   /* Don't warn if the label is marked with a "falls through" comment.  */
    2682                 :       15669 :   if (FALLTHROUGH_LABEL_P (label))
    2683                 :             :     return false;
    2684                 :             : 
    2685                 :             :   /* Don't warn for non-case labels followed by a statement:
    2686                 :             :        case 0:
    2687                 :             :          foo ();
    2688                 :             :        label:
    2689                 :             :          bar ();
    2690                 :             :      as these are likely intentional.  */
    2691                 :       14905 :   if (!case_label_p (&gimplify_ctxp->case_labels, label))
    2692                 :             :     {
    2693                 :             :       tree l;
    2694                 :         326 :       while (!gsi_end_p (gsi)
    2695                 :         318 :              && gimple_code (gsi_stmt (gsi)) == GIMPLE_LABEL
    2696                 :         255 :              && (l = gimple_label_label (as_a <glabel *> (gsi_stmt (gsi))))
    2697                 :         581 :              && !case_label_p (&gimplify_ctxp->case_labels, l))
    2698                 :         169 :         gsi_next_nondebug (&gsi);
    2699                 :         157 :       if (gsi_end_p (gsi) || gimple_code (gsi_stmt (gsi)) != GIMPLE_LABEL)
    2700                 :          71 :         return false;
    2701                 :             :     }
    2702                 :             : 
    2703                 :             :   /* Don't warn for terminated branches, i.e. when the subsequent case labels
    2704                 :             :      immediately breaks.  */
    2705                 :       14834 :   gsi = *gsi_p;
    2706                 :             : 
    2707                 :             :   /* Skip all immediately following labels.  */
    2708                 :       33107 :   while (!gsi_end_p (gsi)
    2709                 :       33107 :          && (gimple_code (gsi_stmt (gsi)) == GIMPLE_LABEL
    2710                 :       14971 :              || gimple_code (gsi_stmt (gsi)) == GIMPLE_PREDICT))
    2711                 :       18273 :     gsi_next_nondebug (&gsi);
    2712                 :             : 
    2713                 :             :   /* { ... something; default:; } */
    2714                 :       14834 :   if (gsi_end_p (gsi)
    2715                 :             :       /* { ... something; default: break; } or
    2716                 :             :          { ... something; default: goto L; } */
    2717                 :       14770 :       || gimple_code (gsi_stmt (gsi)) == GIMPLE_GOTO
    2718                 :             :       /* { ... something; default: return; } */
    2719                 :       28521 :       || gimple_code (gsi_stmt (gsi)) == GIMPLE_RETURN)
    2720                 :        1174 :     return false;
    2721                 :             : 
    2722                 :             :   return true;
    2723                 :             : }
    2724                 :             : 
    2725                 :             : /* Callback for walk_gimple_seq.  */
    2726                 :             : 
    2727                 :             : static tree
    2728                 :       20401 : warn_implicit_fallthrough_r (gimple_stmt_iterator *gsi_p, bool *handled_ops_p,
    2729                 :             :                              struct walk_stmt_info *)
    2730                 :             : {
    2731                 :       20401 :   gimple *stmt = gsi_stmt (*gsi_p);
    2732                 :             : 
    2733                 :       20401 :   *handled_ops_p = true;
    2734                 :       20401 :   switch (gimple_code (stmt))
    2735                 :             :     {
    2736                 :         222 :     case GIMPLE_TRY:
    2737                 :         222 :     case GIMPLE_BIND:
    2738                 :         222 :     case GIMPLE_CATCH:
    2739                 :         222 :     case GIMPLE_EH_FILTER:
    2740                 :         222 :     case GIMPLE_TRANSACTION:
    2741                 :             :       /* Walk the sub-statements.  */
    2742                 :         222 :       *handled_ops_p = false;
    2743                 :         222 :       break;
    2744                 :             : 
    2745                 :             :     /* Find a sequence of form:
    2746                 :             : 
    2747                 :             :        GIMPLE_LABEL
    2748                 :             :        [...]
    2749                 :             :        <may fallthru stmt>
    2750                 :             :        GIMPLE_LABEL
    2751                 :             : 
    2752                 :             :        and possibly warn.  */
    2753                 :             :     case GIMPLE_LABEL:
    2754                 :             :       {
    2755                 :             :         /* Found a label.  Skip all immediately following labels.  */
    2756                 :       45997 :         while (!gsi_end_p (*gsi_p)
    2757                 :       45997 :                && gimple_code (gsi_stmt (*gsi_p)) == GIMPLE_LABEL)
    2758                 :       26263 :           gsi_next_nondebug (gsi_p);
    2759                 :             : 
    2760                 :             :         /* There might be no more statements.  */
    2761                 :       19734 :         if (gsi_end_p (*gsi_p))
    2762                 :        4058 :           return integer_zero_node;
    2763                 :             : 
    2764                 :             :         /* Vector of labels that fall through.  */
    2765                 :       19547 :         auto_vec <struct label_entry> labels;
    2766                 :       19547 :         location_t prevloc;
    2767                 :       19547 :         gimple *prev = collect_fallthrough_labels (gsi_p, &labels, &prevloc);
    2768                 :             : 
    2769                 :             :         /* There might be no more statements.  */
    2770                 :       19547 :         if (gsi_end_p (*gsi_p))
    2771                 :        3871 :           return integer_zero_node;
    2772                 :             : 
    2773                 :       15676 :         gimple *next = gsi_stmt (*gsi_p);
    2774                 :       15676 :         tree label;
    2775                 :             :         /* If what follows is a label, then we may have a fallthrough.  */
    2776                 :       15676 :         if (gimple_code (next) == GIMPLE_LABEL
    2777                 :       15676 :             && gimple_has_location (next)
    2778                 :       15676 :             && (label = gimple_label_label (as_a <glabel *> (next)))
    2779                 :       31352 :             && prev != NULL)
    2780                 :             :           {
    2781                 :       15669 :             struct label_entry *l;
    2782                 :       15669 :             bool warned_p = false;
    2783                 :       15669 :             auto_diagnostic_group d;
    2784                 :       15669 :             if (!should_warn_for_implicit_fallthrough (gsi_p, label))
    2785                 :             :               /* Quiet.  */;
    2786                 :       13660 :             else if (gimple_code (prev) == GIMPLE_LABEL
    2787                 :         218 :                      && (label = gimple_label_label (as_a <glabel *> (prev)))
    2788                 :       13878 :                      && (l = find_label_entry (&labels, label)))
    2789                 :         198 :               warned_p = warning_at (l->loc, OPT_Wimplicit_fallthrough_,
    2790                 :             :                                      "this statement may fall through");
    2791                 :       13462 :             else if (!gimple_call_internal_p (prev, IFN_FALLTHROUGH)
    2792                 :             :                      /* Try to be clever and don't warn when the statement
    2793                 :             :                         can't actually fall through.  */
    2794                 :       13065 :                      && gimple_stmt_may_fallthru (prev)
    2795                 :       13755 :                      && prevloc != UNKNOWN_LOCATION)
    2796                 :         293 :               warned_p = warning_at (prevloc,
    2797                 :             :                                      OPT_Wimplicit_fallthrough_,
    2798                 :             :                                      "this statement may fall through");
    2799                 :         491 :             if (warned_p)
    2800                 :         491 :               inform (gimple_location (next), "here");
    2801                 :             : 
    2802                 :             :             /* Mark this label as processed so as to prevent multiple
    2803                 :             :                warnings in nested switches.  */
    2804                 :       15669 :             FALLTHROUGH_LABEL_P (label) = true;
    2805                 :             : 
    2806                 :             :             /* So that next warn_implicit_fallthrough_r will start looking for
    2807                 :             :                a new sequence starting with this label.  */
    2808                 :       15669 :             gsi_prev (gsi_p);
    2809                 :       15669 :           }
    2810                 :        3871 :       }
    2811                 :       15676 :       break;
    2812                 :             :    default:
    2813                 :             :       break;
    2814                 :             :     }
    2815                 :             :   return NULL_TREE;
    2816                 :             : }
    2817                 :             : 
    2818                 :             : /* Warn when a switch case falls through.  */
    2819                 :             : 
    2820                 :             : static void
    2821                 :       48637 : maybe_warn_implicit_fallthrough (gimple_seq seq)
    2822                 :             : {
    2823                 :       48637 :   if (!warn_implicit_fallthrough)
    2824                 :       44675 :     return;
    2825                 :             : 
    2826                 :             :   /* This warning is meant for C/C++/ObjC/ObjC++ only.  */
    2827                 :        3962 :   if (!(lang_GNU_C ()
    2828                 :        1059 :         || lang_GNU_CXX ()
    2829                 :           0 :         || lang_GNU_OBJC ()))
    2830                 :             :     return;
    2831                 :             : 
    2832                 :        3962 :   struct walk_stmt_info wi;
    2833                 :        3962 :   memset (&wi, 0, sizeof (wi));
    2834                 :        3962 :   walk_gimple_seq (seq, warn_implicit_fallthrough_r, NULL, &wi);
    2835                 :             : }
    2836                 :             : 
    2837                 :             : /* Callback for walk_gimple_seq.  */
    2838                 :             : 
    2839                 :             : static tree
    2840                 :     3283237 : expand_FALLTHROUGH_r (gimple_stmt_iterator *gsi_p, bool *handled_ops_p,
    2841                 :             :                       struct walk_stmt_info *wi)
    2842                 :             : {
    2843                 :     3283237 :   gimple *stmt = gsi_stmt (*gsi_p);
    2844                 :             : 
    2845                 :     3283237 :   *handled_ops_p = true;
    2846                 :     3283237 :   switch (gimple_code (stmt))
    2847                 :             :     {
    2848                 :      152628 :     case GIMPLE_TRY:
    2849                 :      152628 :     case GIMPLE_BIND:
    2850                 :      152628 :     case GIMPLE_CATCH:
    2851                 :      152628 :     case GIMPLE_EH_FILTER:
    2852                 :      152628 :     case GIMPLE_TRANSACTION:
    2853                 :             :       /* Walk the sub-statements.  */
    2854                 :      152628 :       *handled_ops_p = false;
    2855                 :      152628 :       break;
    2856                 :      264350 :     case GIMPLE_CALL:
    2857                 :      264350 :       static_cast<location_t *>(wi->info)[0] = UNKNOWN_LOCATION;
    2858                 :      264350 :       if (gimple_call_internal_p (stmt, IFN_FALLTHROUGH))
    2859                 :             :         {
    2860                 :        3868 :           location_t loc = gimple_location (stmt);
    2861                 :        3868 :           gsi_remove (gsi_p, true);
    2862                 :        3868 :           wi->removed_stmt = true;
    2863                 :             : 
    2864                 :             :           /* nothrow flag is added by genericize_c_loop to mark fallthrough
    2865                 :             :              statement at the end of some loop's body.  Those should be
    2866                 :             :              always diagnosed, either because they indeed don't precede
    2867                 :             :              a case label or default label, or because the next statement
    2868                 :             :              is not within the same iteration statement.  */
    2869                 :        3868 :           if ((stmt->subcode & GF_CALL_NOTHROW) != 0)
    2870                 :             :             {
    2871                 :          12 :               pedwarn (loc, 0, "attribute %<fallthrough%> not preceding "
    2872                 :             :                                "a case label or default label");
    2873                 :          12 :               break;
    2874                 :             :             }
    2875                 :             : 
    2876                 :        3856 :           if (gsi_end_p (*gsi_p))
    2877                 :             :             {
    2878                 :          32 :               static_cast<location_t *>(wi->info)[0] = BUILTINS_LOCATION;
    2879                 :          32 :               static_cast<location_t *>(wi->info)[1] = loc;
    2880                 :          32 :               break;
    2881                 :             :             }
    2882                 :             : 
    2883                 :        3824 :           bool found = false;
    2884                 :             : 
    2885                 :        3824 :           gimple_stmt_iterator gsi2 = *gsi_p;
    2886                 :        3824 :           stmt = gsi_stmt (gsi2);
    2887                 :        3824 :           if (gimple_code (stmt) == GIMPLE_GOTO && !gimple_has_location (stmt))
    2888                 :             :             {
    2889                 :             :               /* Go on until the artificial label.  */
    2890                 :          57 :               tree goto_dest = gimple_goto_dest (stmt);
    2891                 :         414 :               for (; !gsi_end_p (gsi2); gsi_next (&gsi2))
    2892                 :             :                 {
    2893                 :         357 :                   if (gimple_code (gsi_stmt (gsi2)) == GIMPLE_LABEL
    2894                 :         357 :                       && gimple_label_label (as_a <glabel *> (gsi_stmt (gsi2)))
    2895                 :             :                            == goto_dest)
    2896                 :             :                     break;
    2897                 :             :                 }
    2898                 :             : 
    2899                 :             :               /* Not found?  Stop.  */
    2900                 :          57 :               if (gsi_end_p (gsi2))
    2901                 :             :                 break;
    2902                 :             : 
    2903                 :             :               /* Look one past it.  */
    2904                 :          57 :               gsi_next (&gsi2);
    2905                 :             :             }
    2906                 :             : 
    2907                 :             :           /* We're looking for a case label or default label here.  */
    2908                 :        3914 :           while (!gsi_end_p (gsi2))
    2909                 :             :             {
    2910                 :        3914 :               stmt = gsi_stmt (gsi2);
    2911                 :        3914 :               if (gimple_code (stmt) == GIMPLE_LABEL)
    2912                 :             :                 {
    2913                 :        3871 :                   tree label = gimple_label_label (as_a <glabel *> (stmt));
    2914                 :        3871 :                   if (gimple_has_location (stmt) && DECL_ARTIFICIAL (label))
    2915                 :             :                     {
    2916                 :             :                       found = true;
    2917                 :             :                       break;
    2918                 :             :                     }
    2919                 :             :                 }
    2920                 :          43 :               else if (gimple_call_internal_p (stmt, IFN_ASAN_MARK))
    2921                 :             :                 ;
    2922                 :          43 :               else if (!is_gimple_debug (stmt))
    2923                 :             :                 /* Anything else is not expected.  */
    2924                 :             :                 break;
    2925                 :          90 :               gsi_next (&gsi2);
    2926                 :             :             }
    2927                 :        3824 :           if (!found)
    2928                 :          23 :             pedwarn (loc, 0, "attribute %<fallthrough%> not preceding "
    2929                 :             :                      "a case label or default label");
    2930                 :             :         }
    2931                 :             :       break;
    2932                 :     2866259 :     default:
    2933                 :     2866259 :       static_cast<location_t *>(wi->info)[0] = UNKNOWN_LOCATION;
    2934                 :     2866259 :       break;
    2935                 :             :     }
    2936                 :     3283237 :   return NULL_TREE;
    2937                 :             : }
    2938                 :             : 
    2939                 :             : /* Expand all FALLTHROUGH () calls in SEQ.  */
    2940                 :             : 
    2941                 :             : static void
    2942                 :       47313 : expand_FALLTHROUGH (gimple_seq *seq_p)
    2943                 :             : {
    2944                 :       47313 :   auto_urlify_attributes sentinel;
    2945                 :             : 
    2946                 :       47313 :   struct walk_stmt_info wi;
    2947                 :       47313 :   location_t loc[2];
    2948                 :       47313 :   memset (&wi, 0, sizeof (wi));
    2949                 :       47313 :   loc[0] = UNKNOWN_LOCATION;
    2950                 :       47313 :   loc[1] = UNKNOWN_LOCATION;
    2951                 :       47313 :   wi.info = (void *) &loc[0];
    2952                 :       47313 :   walk_gimple_seq_mod (seq_p, expand_FALLTHROUGH_r, NULL, &wi);
    2953                 :       47313 :   if (loc[0] != UNKNOWN_LOCATION)
    2954                 :             :     /* We've found [[fallthrough]]; at the end of a switch, which the C++
    2955                 :             :        standard says is ill-formed; see [dcl.attr.fallthrough].  */
    2956                 :           8 :     pedwarn (loc[1], 0, "attribute %<fallthrough%> not preceding "
    2957                 :             :              "a case label or default label");
    2958                 :       47313 : }
    2959                 :             : 
    2960                 :             : 
    2961                 :             : /* Gimplify a SWITCH_EXPR, and collect the vector of labels it can
    2962                 :             :    branch to.  */
    2963                 :             : 
    2964                 :             : static enum gimplify_status
    2965                 :       48637 : gimplify_switch_expr (tree *expr_p, gimple_seq *pre_p)
    2966                 :             : {
    2967                 :       48637 :   tree switch_expr = *expr_p;
    2968                 :       48637 :   gimple_seq switch_body_seq = NULL;
    2969                 :       48637 :   enum gimplify_status ret;
    2970                 :       48637 :   tree index_type = TREE_TYPE (switch_expr);
    2971                 :       48637 :   if (index_type == NULL_TREE)
    2972                 :       11312 :     index_type = TREE_TYPE (SWITCH_COND (switch_expr));
    2973                 :             : 
    2974                 :       48637 :   ret = gimplify_expr (&SWITCH_COND (switch_expr), pre_p, NULL, is_gimple_val,
    2975                 :             :                        fb_rvalue);
    2976                 :       48637 :   if (ret == GS_ERROR || ret == GS_UNHANDLED)
    2977                 :             :     return ret;
    2978                 :             : 
    2979                 :       48637 :   if (SWITCH_BODY (switch_expr))
    2980                 :             :     {
    2981                 :       48637 :       vec<tree> labels;
    2982                 :       48637 :       vec<tree> saved_labels;
    2983                 :       48637 :       hash_set<tree> *saved_live_switch_vars = NULL;
    2984                 :       48637 :       tree default_case = NULL_TREE;
    2985                 :       48637 :       gswitch *switch_stmt;
    2986                 :             : 
    2987                 :             :       /* Save old labels, get new ones from body, then restore the old
    2988                 :             :          labels.  Save all the things from the switch body to append after.  */
    2989                 :       48637 :       saved_labels = gimplify_ctxp->case_labels;
    2990                 :       48637 :       gimplify_ctxp->case_labels.create (8);
    2991                 :             : 
    2992                 :             :       /* Do not create live_switch_vars if SWITCH_BODY is not a BIND_EXPR.  */
    2993                 :       48637 :       saved_live_switch_vars = gimplify_ctxp->live_switch_vars;
    2994                 :       48637 :       tree_code body_type = TREE_CODE (SWITCH_BODY (switch_expr));
    2995                 :       48637 :       if (body_type == BIND_EXPR || body_type == STATEMENT_LIST)
    2996                 :       48369 :         gimplify_ctxp->live_switch_vars = new hash_set<tree> (4);
    2997                 :             :       else
    2998                 :         268 :         gimplify_ctxp->live_switch_vars = NULL;
    2999                 :             : 
    3000                 :       48637 :       bool old_in_switch_expr = gimplify_ctxp->in_switch_expr;
    3001                 :       48637 :       gimplify_ctxp->in_switch_expr = true;
    3002                 :             : 
    3003                 :       48637 :       gimplify_stmt (&SWITCH_BODY (switch_expr), &switch_body_seq);
    3004                 :             : 
    3005                 :       48637 :       gimplify_ctxp->in_switch_expr = old_in_switch_expr;
    3006                 :       48637 :       maybe_warn_switch_unreachable_and_auto_init (switch_body_seq);
    3007                 :       48637 :       maybe_warn_implicit_fallthrough (switch_body_seq);
    3008                 :             :       /* Only do this for the outermost GIMPLE_SWITCH.  */
    3009                 :       48637 :       if (!gimplify_ctxp->in_switch_expr)
    3010                 :       47313 :         expand_FALLTHROUGH (&switch_body_seq);
    3011                 :             : 
    3012                 :       48637 :       labels = gimplify_ctxp->case_labels;
    3013                 :       48637 :       gimplify_ctxp->case_labels = saved_labels;
    3014                 :             : 
    3015                 :       48637 :       if (gimplify_ctxp->live_switch_vars)
    3016                 :             :         {
    3017                 :       48369 :           gcc_assert (gimplify_ctxp->live_switch_vars->is_empty ());
    3018                 :       48369 :           delete gimplify_ctxp->live_switch_vars;
    3019                 :             :         }
    3020                 :       48637 :       gimplify_ctxp->live_switch_vars = saved_live_switch_vars;
    3021                 :             : 
    3022                 :       48637 :       preprocess_case_label_vec_for_gimple (labels, index_type,
    3023                 :             :                                             &default_case);
    3024                 :             : 
    3025                 :       48637 :       bool add_bind = false;
    3026                 :       48637 :       if (!default_case)
    3027                 :             :         {
    3028                 :       14342 :           glabel *new_default;
    3029                 :             : 
    3030                 :       14342 :           default_case
    3031                 :       14342 :             = build_case_label (NULL_TREE, NULL_TREE,
    3032                 :             :                                 create_artificial_label (UNKNOWN_LOCATION));
    3033                 :       14342 :           if (old_in_switch_expr)
    3034                 :             :             {
    3035                 :         766 :               SWITCH_BREAK_LABEL_P (CASE_LABEL (default_case)) = 1;
    3036                 :         766 :               add_bind = true;
    3037                 :             :             }
    3038                 :       14342 :           new_default = gimple_build_label (CASE_LABEL (default_case));
    3039                 :       14342 :           gimplify_seq_add_stmt (&switch_body_seq, new_default);
    3040                 :             :         }
    3041                 :       34295 :       else if (old_in_switch_expr)
    3042                 :             :         {
    3043                 :         558 :           gimple *last = gimple_seq_last_stmt (switch_body_seq);
    3044                 :         558 :           if (last && gimple_code (last) == GIMPLE_LABEL)
    3045                 :             :             {
    3046                 :         301 :               tree label = gimple_label_label (as_a <glabel *> (last));
    3047                 :         301 :               if (SWITCH_BREAK_LABEL_P (label))
    3048                 :       48637 :                 add_bind = true;
    3049                 :             :             }
    3050                 :             :         }
    3051                 :             : 
    3052                 :       48637 :       switch_stmt = gimple_build_switch (SWITCH_COND (switch_expr),
    3053                 :             :                                          default_case, labels);
    3054                 :       48637 :       gimple_set_location (switch_stmt, EXPR_LOCATION (switch_expr));
    3055                 :             :       /* For the benefit of -Wimplicit-fallthrough, if switch_body_seq
    3056                 :             :          ends with a GIMPLE_LABEL holding SWITCH_BREAK_LABEL_P LABEL_DECL,
    3057                 :             :          wrap the GIMPLE_SWITCH up to that GIMPLE_LABEL into a GIMPLE_BIND,
    3058                 :             :          so that we can easily find the start and end of the switch
    3059                 :             :          statement.  */
    3060                 :       48637 :       if (add_bind)
    3061                 :             :         {
    3062                 :        1066 :           gimple_seq bind_body = NULL;
    3063                 :        1066 :           gimplify_seq_add_stmt (&bind_body, switch_stmt);
    3064                 :        1066 :           gimple_seq_add_seq (&bind_body, switch_body_seq);
    3065                 :        1066 :           gbind *bind = gimple_build_bind (NULL_TREE, bind_body, NULL_TREE);
    3066                 :        1066 :           gimple_set_location (bind, EXPR_LOCATION (switch_expr));
    3067                 :        1066 :           gimplify_seq_add_stmt (pre_p, bind);
    3068                 :             :         }
    3069                 :             :       else
    3070                 :             :         {
    3071                 :       47571 :           gimplify_seq_add_stmt (pre_p, switch_stmt);
    3072                 :       47571 :           gimplify_seq_add_seq (pre_p, switch_body_seq);
    3073                 :             :         }
    3074                 :       48637 :       labels.release ();
    3075                 :             :     }
    3076                 :             :   else
    3077                 :           0 :     gcc_unreachable ();
    3078                 :             : 
    3079                 :       48637 :   return GS_ALL_DONE;
    3080                 :             : }
    3081                 :             : 
    3082                 :             : /* Gimplify the LABEL_EXPR pointed to by EXPR_P.  */
    3083                 :             : 
    3084                 :             : static enum gimplify_status
    3085                 :     2407302 : gimplify_label_expr (tree *expr_p, gimple_seq *pre_p)
    3086                 :             : {
    3087                 :     2407302 :   gcc_assert (decl_function_context (LABEL_EXPR_LABEL (*expr_p))
    3088                 :             :               == current_function_decl);
    3089                 :             : 
    3090                 :     2407302 :   tree label = LABEL_EXPR_LABEL (*expr_p);
    3091                 :     2407302 :   glabel *label_stmt = gimple_build_label (label);
    3092                 :     2407302 :   gimple_set_location (label_stmt, EXPR_LOCATION (*expr_p));
    3093                 :     2407302 :   gimplify_seq_add_stmt (pre_p, label_stmt);
    3094                 :             : 
    3095                 :     2407302 :   if (lookup_attribute ("cold", DECL_ATTRIBUTES (label)))
    3096                 :          21 :     gimple_seq_add_stmt (pre_p, gimple_build_predict (PRED_COLD_LABEL,
    3097                 :             :                                                       NOT_TAKEN));
    3098                 :     2407281 :   else if (lookup_attribute ("hot", DECL_ATTRIBUTES (label)))
    3099                 :           9 :     gimple_seq_add_stmt (pre_p, gimple_build_predict (PRED_HOT_LABEL,
    3100                 :             :                                                       TAKEN));
    3101                 :             : 
    3102                 :     2407302 :   return GS_ALL_DONE;
    3103                 :             : }
    3104                 :             : 
    3105                 :             : /* Gimplify the CASE_LABEL_EXPR pointed to by EXPR_P.  */
    3106                 :             : 
    3107                 :             : static enum gimplify_status
    3108                 :     1047343 : gimplify_case_label_expr (tree *expr_p, gimple_seq *pre_p)
    3109                 :             : {
    3110                 :     1047343 :   struct gimplify_ctx *ctxp;
    3111                 :     1047343 :   glabel *label_stmt;
    3112                 :             : 
    3113                 :             :   /* Invalid programs can play Duff's Device type games with, for example,
    3114                 :             :      #pragma omp parallel.  At least in the C front end, we don't
    3115                 :             :      detect such invalid branches until after gimplification, in the
    3116                 :             :      diagnose_omp_blocks pass.  */
    3117                 :     1047353 :   for (ctxp = gimplify_ctxp; ; ctxp = ctxp->prev_context)
    3118                 :     1047353 :     if (ctxp->case_labels.exists ())
    3119                 :             :       break;
    3120                 :             : 
    3121                 :     1047343 :   tree label = CASE_LABEL (*expr_p);
    3122                 :     1047343 :   label_stmt = gimple_build_label (label);
    3123                 :     1047343 :   gimple_set_location (label_stmt, EXPR_LOCATION (*expr_p));
    3124                 :     1047343 :   ctxp->case_labels.safe_push (*expr_p);
    3125                 :     1047343 :   gimplify_seq_add_stmt (pre_p, label_stmt);
    3126                 :             : 
    3127                 :     1047343 :   if (lookup_attribute ("cold", DECL_ATTRIBUTES (label)))
    3128                 :          16 :     gimple_seq_add_stmt (pre_p, gimple_build_predict (PRED_COLD_LABEL,
    3129                 :             :                                                       NOT_TAKEN));
    3130                 :     1047327 :   else if (lookup_attribute ("hot", DECL_ATTRIBUTES (label)))
    3131                 :          20 :     gimple_seq_add_stmt (pre_p, gimple_build_predict (PRED_HOT_LABEL,
    3132                 :             :                                                       TAKEN));
    3133                 :             : 
    3134                 :     1047343 :   return GS_ALL_DONE;
    3135                 :             : }
    3136                 :             : 
    3137                 :             : /* Build a GOTO to the LABEL_DECL pointed to by LABEL_P, building it first
    3138                 :             :    if necessary.  */
    3139                 :             : 
    3140                 :             : tree
    3141                 :     1718652 : build_and_jump (tree *label_p)
    3142                 :             : {
    3143                 :     1718652 :   if (label_p == NULL)
    3144                 :             :     /* If there's nowhere to jump, just fall through.  */
    3145                 :             :     return NULL_TREE;
    3146                 :             : 
    3147                 :     1169524 :   if (*label_p == NULL_TREE)
    3148                 :             :     {
    3149                 :      669492 :       tree label = create_artificial_label (UNKNOWN_LOCATION);
    3150                 :      669492 :       *label_p = label;
    3151                 :             :     }
    3152                 :             : 
    3153                 :     1169524 :   return build1 (GOTO_EXPR, void_type_node, *label_p);
    3154                 :             : }
    3155                 :             : 
    3156                 :             : /* Gimplify an EXIT_EXPR by converting to a GOTO_EXPR inside a COND_EXPR.
    3157                 :             :    This also involves building a label to jump to and communicating it to
    3158                 :             :    gimplify_loop_expr through gimplify_ctxp->exit_label.  */
    3159                 :             : 
    3160                 :             : static enum gimplify_status
    3161                 :        2939 : gimplify_exit_expr (tree *expr_p)
    3162                 :             : {
    3163                 :        2939 :   tree cond = TREE_OPERAND (*expr_p, 0);
    3164                 :        2939 :   tree expr;
    3165                 :             : 
    3166                 :        2939 :   expr = build_and_jump (&gimplify_ctxp->exit_label);
    3167                 :        2939 :   expr = build3 (COND_EXPR, void_type_node, cond, expr, NULL_TREE);
    3168                 :        2939 :   *expr_p = expr;
    3169                 :             : 
    3170                 :        2939 :   return GS_OK;
    3171                 :             : }
    3172                 :             : 
    3173                 :             : /* *EXPR_P is a COMPONENT_REF being used as an rvalue.  If its type is
    3174                 :             :    different from its canonical type, wrap the whole thing inside a
    3175                 :             :    NOP_EXPR and force the type of the COMPONENT_REF to be the canonical
    3176                 :             :    type.
    3177                 :             : 
    3178                 :             :    The canonical type of a COMPONENT_REF is the type of the field being
    3179                 :             :    referenced--unless the field is a bit-field which can be read directly
    3180                 :             :    in a smaller mode, in which case the canonical type is the
    3181                 :             :    sign-appropriate type corresponding to that mode.  */
    3182                 :             : 
    3183                 :             : static void
    3184                 :    17684310 : canonicalize_component_ref (tree *expr_p)
    3185                 :             : {
    3186                 :    17684310 :   tree expr = *expr_p;
    3187                 :    17684310 :   tree type;
    3188                 :             : 
    3189                 :    17684310 :   gcc_assert (TREE_CODE (expr) == COMPONENT_REF);
    3190                 :             : 
    3191                 :    17684310 :   if (INTEGRAL_TYPE_P (TREE_TYPE (expr)))
    3192                 :     7216050 :     type = TREE_TYPE (get_unwidened (expr, NULL_TREE));
    3193                 :             :   else
    3194                 :    10468260 :     type = TREE_TYPE (TREE_OPERAND (expr, 1));
    3195                 :             : 
    3196                 :             :   /* One could argue that all the stuff below is not necessary for
    3197                 :             :      the non-bitfield case and declare it a FE error if type
    3198                 :             :      adjustment would be needed.  */
    3199                 :    17684310 :   if (TREE_TYPE (expr) != type)
    3200                 :             :     {
    3201                 :             : #ifdef ENABLE_TYPES_CHECKING
    3202                 :      722602 :       tree old_type = TREE_TYPE (expr);
    3203                 :             : #endif
    3204                 :      722602 :       int type_quals;
    3205                 :             : 
    3206                 :             :       /* We need to preserve qualifiers and propagate them from
    3207                 :             :          operand 0.  */
    3208                 :      722602 :       type_quals = TYPE_QUALS (type)
    3209                 :      722602 :         | TYPE_QUALS (TREE_TYPE (TREE_OPERAND (expr, 0)));
    3210                 :      722602 :       if (TYPE_QUALS (type) != type_quals)
    3211                 :      722552 :         type = build_qualified_type (TYPE_MAIN_VARIANT (type), type_quals);
    3212                 :             : 
    3213                 :             :       /* Set the type of the COMPONENT_REF to the underlying type.  */
    3214                 :      722602 :       TREE_TYPE (expr) = type;
    3215                 :             : 
    3216                 :             : #ifdef ENABLE_TYPES_CHECKING
    3217                 :             :       /* It is now a FE error, if the conversion from the canonical
    3218                 :             :          type to the original expression type is not useless.  */
    3219                 :      722602 :       gcc_assert (useless_type_conversion_p (old_type, type));
    3220                 :             : #endif
    3221                 :             :     }
    3222                 :    17684310 : }
    3223                 :             : 
    3224                 :             : /* If a NOP conversion is changing a pointer to array of foo to a pointer
    3225                 :             :    to foo, embed that change in the ADDR_EXPR by converting
    3226                 :             :       T array[U];
    3227                 :             :       (T *)&array
    3228                 :             :    ==>
    3229                 :             :       &array[L]
    3230                 :             :    where L is the lower bound.  For simplicity, only do this for constant
    3231                 :             :    lower bound.
    3232                 :             :    The constraint is that the type of &array[L] is trivially convertible
    3233                 :             :    to T *.  */
    3234                 :             : 
    3235                 :             : static void
    3236                 :      492914 : canonicalize_addr_expr (tree *expr_p)
    3237                 :             : {
    3238                 :      492914 :   tree expr = *expr_p;
    3239                 :      492914 :   tree addr_expr = TREE_OPERAND (expr, 0);
    3240                 :      492914 :   tree datype, ddatype, pddatype;
    3241                 :             : 
    3242                 :             :   /* We simplify only conversions from an ADDR_EXPR to a pointer type.  */
    3243                 :      985482 :   if (!POINTER_TYPE_P (TREE_TYPE (expr))
    3244                 :      492914 :       || TREE_CODE (addr_expr) != ADDR_EXPR)
    3245                 :             :     return;
    3246                 :             : 
    3247                 :             :   /* The addr_expr type should be a pointer to an array.  */
    3248                 :         346 :   datype = TREE_TYPE (TREE_TYPE (addr_expr));
    3249                 :         346 :   if (TREE_CODE (datype) != ARRAY_TYPE)
    3250                 :             :     return;
    3251                 :             : 
    3252                 :             :   /* The pointer to element type shall be trivially convertible to
    3253                 :             :      the expression pointer type.  */
    3254                 :          28 :   ddatype = TREE_TYPE (datype);
    3255                 :          28 :   pddatype = build_pointer_type (ddatype);
    3256                 :          28 :   if (!useless_type_conversion_p (TYPE_MAIN_VARIANT (TREE_TYPE (expr)),
    3257                 :             :                                   pddatype))
    3258                 :             :     return;
    3259                 :             : 
    3260                 :             :   /* The lower bound and element sizes must be constant.  */
    3261                 :           0 :   if (!TYPE_SIZE_UNIT (ddatype)
    3262                 :           0 :       || TREE_CODE (TYPE_SIZE_UNIT (ddatype)) != INTEGER_CST
    3263                 :           0 :       || !TYPE_DOMAIN (datype) || !TYPE_MIN_VALUE (TYPE_DOMAIN (datype))
    3264                 :           0 :       || TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (datype))) != INTEGER_CST)
    3265                 :             :     return;
    3266                 :             : 
    3267                 :             :   /* All checks succeeded.  Build a new node to merge the cast.  */
    3268                 :           0 :   *expr_p = build4 (ARRAY_REF, ddatype, TREE_OPERAND (addr_expr, 0),
    3269                 :           0 :                     TYPE_MIN_VALUE (TYPE_DOMAIN (datype)),
    3270                 :             :                     NULL_TREE, NULL_TREE);
    3271                 :           0 :   *expr_p = build1 (ADDR_EXPR, pddatype, *expr_p);
    3272                 :             : 
    3273                 :             :   /* We can have stripped a required restrict qualifier above.  */
    3274                 :           0 :   if (!useless_type_conversion_p (TREE_TYPE (expr), TREE_TYPE (*expr_p)))
    3275                 :           0 :     *expr_p = fold_convert (TREE_TYPE (expr), *expr_p);
    3276                 :             : }
    3277                 :             : 
    3278                 :             : /* *EXPR_P is a NOP_EXPR or CONVERT_EXPR.  Remove it and/or other conversions
    3279                 :             :    underneath as appropriate.  */
    3280                 :             : 
    3281                 :             : static enum gimplify_status
    3282                 :    12675440 : gimplify_conversion (tree *expr_p)
    3283                 :             : {
    3284                 :    12675440 :   location_t loc = EXPR_LOCATION (*expr_p);
    3285                 :    12675440 :   gcc_assert (CONVERT_EXPR_P (*expr_p));
    3286                 :             : 
    3287                 :             :   /* Then strip away all but the outermost conversion.  */
    3288                 :    12675440 :   STRIP_SIGN_NOPS (TREE_OPERAND (*expr_p, 0));
    3289                 :             : 
    3290                 :             :   /* And remove the outermost conversion if it's useless.  */
    3291                 :    12675440 :   if (tree_ssa_useless_type_conversion (*expr_p))
    3292                 :           0 :     *expr_p = TREE_OPERAND (*expr_p, 0);
    3293                 :             : 
    3294                 :             :   /* If we still have a conversion at the toplevel,
    3295                 :             :      then canonicalize some constructs.  */
    3296                 :    12675440 :   if (CONVERT_EXPR_P (*expr_p))
    3297                 :             :     {
    3298                 :    12675440 :       tree sub = TREE_OPERAND (*expr_p, 0);
    3299                 :             : 
    3300                 :             :       /* If a NOP conversion is changing the type of a COMPONENT_REF
    3301                 :             :          expression, then canonicalize its type now in order to expose more
    3302                 :             :          redundant conversions.  */
    3303                 :    12675440 :       if (TREE_CODE (sub) == COMPONENT_REF)
    3304                 :      274200 :         canonicalize_component_ref (&TREE_OPERAND (*expr_p, 0));
    3305                 :             : 
    3306                 :             :       /* If a NOP conversion is changing a pointer to array of foo
    3307                 :             :          to a pointer to foo, embed that change in the ADDR_EXPR.  */
    3308                 :    12401240 :       else if (TREE_CODE (sub) == ADDR_EXPR)
    3309                 :      492914 :         canonicalize_addr_expr (expr_p);
    3310                 :             :     }
    3311                 :             : 
    3312                 :             :   /* If we have a conversion to a non-register type force the
    3313                 :             :      use of a VIEW_CONVERT_EXPR instead.  */
    3314                 :    12675440 :   if (CONVERT_EXPR_P (*expr_p) && !is_gimple_reg_type (TREE_TYPE (*expr_p)))
    3315                 :          90 :     *expr_p = fold_build1_loc (loc, VIEW_CONVERT_EXPR, TREE_TYPE (*expr_p),
    3316                 :          90 :                                TREE_OPERAND (*expr_p, 0));
    3317                 :             : 
    3318                 :             :   /* Canonicalize CONVERT_EXPR to NOP_EXPR.  */
    3319                 :    12675440 :   if (TREE_CODE (*expr_p) == CONVERT_EXPR)
    3320                 :      233447 :     TREE_SET_CODE (*expr_p, NOP_EXPR);
    3321                 :             : 
    3322                 :    12675440 :   return GS_OK;
    3323                 :             : }
    3324                 :             : 
    3325                 :             : /* Gimplify a VAR_DECL or PARM_DECL.  Return GS_OK if we expanded a
    3326                 :             :    DECL_VALUE_EXPR, and it's worth re-examining things.  */
    3327                 :             : 
    3328                 :             : static enum gimplify_status
    3329                 :   120766685 : gimplify_var_or_parm_decl (tree *expr_p)
    3330                 :             : {
    3331                 :   120766685 :   tree decl = *expr_p;
    3332                 :             : 
    3333                 :             :   /* ??? If this is a local variable, and it has not been seen in any
    3334                 :             :      outer BIND_EXPR, then it's probably the result of a duplicate
    3335                 :             :      declaration, for which we've already issued an error.  It would
    3336                 :             :      be really nice if the front end wouldn't leak these at all.
    3337                 :             :      Currently the only known culprit is C++ destructors, as seen
    3338                 :             :      in g++.old-deja/g++.jason/binding.C.
    3339                 :             :      Another possible culpit are size expressions for variably modified
    3340                 :             :      types which are lost in the FE or not gimplified correctly.  */
    3341                 :   120766685 :   if (VAR_P (decl)
    3342                 :    94335688 :       && !DECL_SEEN_IN_BIND_EXPR_P (decl)
    3343                 :    16760815 :       && !TREE_STATIC (decl) && !DECL_EXTERNAL (decl)
    3344                 :   120809208 :       && decl_function_context (decl) == current_function_decl)
    3345                 :             :     {
    3346                 :           0 :       gcc_assert (seen_error ());
    3347                 :             :       return GS_ERROR;
    3348                 :             :     }
    3349                 :             : 
    3350                 :             :   /* When within an OMP context, notice uses of variables.  */
    3351                 :   120766685 :   if (gimplify_omp_ctxp && omp_notice_variable (gimplify_omp_ctxp, decl, true))
    3352                 :             :     return GS_ALL_DONE;
    3353                 :             : 
    3354                 :             :   /* If the decl is an alias for another expression, substitute it now.  */
    3355                 :   120760850 :   if (DECL_HAS_VALUE_EXPR_P (decl))
    3356                 :             :     {
    3357                 :      376220 :       *expr_p = unshare_expr (DECL_VALUE_EXPR (decl));
    3358                 :      376220 :       return GS_OK;
    3359                 :             :     }
    3360                 :             : 
    3361                 :             :   return GS_ALL_DONE;
    3362                 :             : }
    3363                 :             : 
    3364                 :             : /* Recalculate the value of the TREE_SIDE_EFFECTS flag for T.  */
    3365                 :             : 
    3366                 :             : static void
    3367                 :   106114134 : recalculate_side_effects (tree t)
    3368                 :             : {
    3369                 :   106114134 :   enum tree_code code = TREE_CODE (t);
    3370                 :   106114134 :   int len = TREE_OPERAND_LENGTH (t);
    3371                 :   106114134 :   int i;
    3372                 :             : 
    3373                 :   106114134 :   switch (TREE_CODE_CLASS (code))
    3374                 :             :     {
    3375                 :      639106 :     case tcc_expression:
    3376                 :      639106 :       switch (code)
    3377                 :             :         {
    3378                 :             :         case INIT_EXPR:
    3379                 :             :         case MODIFY_EXPR:
    3380                 :             :         case VA_ARG_EXPR:
    3381                 :             :         case PREDECREMENT_EXPR:
    3382                 :             :         case PREINCREMENT_EXPR:
    3383                 :             :         case POSTDECREMENT_EXPR:
    3384                 :             :         case POSTINCREMENT_EXPR:
    3385                 :             :           /* All of these have side-effects, no matter what their
    3386                 :             :              operands are.  */
    3387                 :             :           return;
    3388                 :             : 
    3389                 :             :         default:
    3390                 :             :           break;
    3391                 :             :         }
    3392                 :             :       /* Fall through.  */
    3393                 :             : 
    3394                 :   106114132 :     case tcc_comparison:  /* a comparison expression */
    3395                 :   106114132 :     case tcc_unary:       /* a unary arithmetic expression */
    3396                 :   106114132 :     case tcc_binary:      /* a binary arithmetic expression */
    3397                 :   106114132 :     case tcc_reference:   /* a reference */
    3398                 :   106114132 :     case tcc_vl_exp:        /* a function call */
    3399                 :   106114132 :       TREE_SIDE_EFFECTS (t) = TREE_THIS_VOLATILE (t);
    3400                 :   344518316 :       for (i = 0; i < len; ++i)
    3401                 :             :         {
    3402                 :   238404184 :           tree op = TREE_OPERAND (t, i);
    3403                 :   238404184 :           if (op && TREE_SIDE_EFFECTS (op))
    3404                 :     1229130 :             TREE_SIDE_EFFECTS (t) = 1;
    3405                 :             :         }
    3406                 :             :       break;
    3407                 :             : 
    3408                 :             :     case tcc_constant:
    3409                 :             :       /* No side-effects.  */
    3410                 :             :       return;
    3411                 :             : 
    3412                 :           2 :     default:
    3413                 :           2 :       if (code == SSA_NAME)
    3414                 :             :         /* No side-effects.  */
    3415                 :             :         return;
    3416                 :           0 :       gcc_unreachable ();
    3417                 :             :    }
    3418                 :             : }
    3419                 :             : 
    3420                 :             : /* Gimplify the COMPONENT_REF, ARRAY_REF, REALPART_EXPR or IMAGPART_EXPR
    3421                 :             :    node *EXPR_P.
    3422                 :             : 
    3423                 :             :       compound_lval
    3424                 :             :               : min_lval '[' val ']'
    3425                 :             :               | min_lval '.' ID
    3426                 :             :               | compound_lval '[' val ']'
    3427                 :             :               | compound_lval '.' ID
    3428                 :             : 
    3429                 :             :    This is not part of the original SIMPLE definition, which separates
    3430                 :             :    array and member references, but it seems reasonable to handle them
    3431                 :             :    together.  Also, this way we don't run into problems with union
    3432                 :             :    aliasing; gcc requires that for accesses through a union to alias, the
    3433                 :             :    union reference must be explicit, which was not always the case when we
    3434                 :             :    were splitting up array and member refs.
    3435                 :             : 
    3436                 :             :    PRE_P points to the sequence where side effects that must happen before
    3437                 :             :      *EXPR_P should be stored.
    3438                 :             : 
    3439                 :             :    POST_P points to the sequence where side effects that must happen after
    3440                 :             :      *EXPR_P should be stored.  */
    3441                 :             : 
    3442                 :             : static enum gimplify_status
    3443                 :    28574885 : gimplify_compound_lval (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
    3444                 :             :                         fallback_t fallback)
    3445                 :             : {
    3446                 :    28574885 :   tree *p;
    3447                 :    28574885 :   enum gimplify_status ret = GS_ALL_DONE, tret;
    3448                 :    28574885 :   int i;
    3449                 :    28574885 :   location_t loc = EXPR_LOCATION (*expr_p);
    3450                 :    28574885 :   tree expr = *expr_p;
    3451                 :             : 
    3452                 :             :   /* Create a stack of the subexpressions so later we can walk them in
    3453                 :             :      order from inner to outer.  */
    3454                 :    28574885 :   auto_vec<tree, 10> expr_stack;
    3455                 :             : 
    3456                 :             :   /* We can handle anything that get_inner_reference can deal with.  */
    3457                 :    68709524 :   for (p = expr_p; ; p = &TREE_OPERAND (*p, 0))
    3458                 :             :     {
    3459                 :    40134639 :     restart:
    3460                 :             :       /* Fold INDIRECT_REFs now to turn them into ARRAY_REFs.  */
    3461                 :    68767352 :       if (TREE_CODE (*p) == INDIRECT_REF)
    3462                 :     3696603 :         *p = fold_indirect_ref_loc (loc, *p);
    3463                 :             : 
    3464                 :    68767352 :       if (handled_component_p (*p))
    3465                 :             :         ;
    3466                 :             :       /* Expand DECL_VALUE_EXPR now.  In some cases that may expose
    3467                 :             :          additional COMPONENT_REFs.  */
    3468                 :    12497343 :       else if ((VAR_P (*p) || TREE_CODE (*p) == PARM_DECL)
    3469                 :    30042641 :                && gimplify_var_or_parm_decl (p) == GS_OK)
    3470                 :       57828 :         goto restart;
    3471                 :             :       else
    3472                 :             :         break;
    3473                 :             : 
    3474                 :    40134639 :       expr_stack.safe_push (*p);
    3475                 :             :     }
    3476                 :             : 
    3477                 :    28574885 :   gcc_assert (expr_stack.length ());
    3478                 :             : 
    3479                 :             :   /* Now EXPR_STACK is a stack of pointers to all the refs we've
    3480                 :             :      walked through and P points to the innermost expression.
    3481                 :             : 
    3482                 :             :      Java requires that we elaborated nodes in source order.  That
    3483                 :             :      means we must gimplify the inner expression followed by each of
    3484                 :             :      the indices, in order.  But we can't gimplify the inner
    3485                 :             :      expression until we deal with any variable bounds, sizes, or
    3486                 :             :      positions in order to deal with PLACEHOLDER_EXPRs.
    3487                 :             : 
    3488                 :             :      The base expression may contain a statement expression that
    3489                 :             :      has declarations used in size expressions, so has to be
    3490                 :             :      gimplified before gimplifying the size expressions.
    3491                 :             : 
    3492                 :             :      So we do this in three steps.  First we deal with variable
    3493                 :             :      bounds, sizes, and positions, then we gimplify the base and
    3494                 :             :      ensure it is memory if needed, then we deal with the annotations
    3495                 :             :      for any variables in the components and any indices, from left
    3496                 :             :      to right.  */
    3497                 :             : 
    3498                 :    28574885 :   bool need_non_reg = false;
    3499                 :    68709521 :   for (i = expr_stack.length () - 1; i >= 0; i--)
    3500                 :             :     {
    3501                 :    40134639 :       tree t = expr_stack[i];
    3502                 :             : 
    3503                 :    40134639 :       if (error_operand_p (TREE_OPERAND (t, 0)))
    3504                 :             :         return GS_ERROR;
    3505                 :             : 
    3506                 :    40134636 :       if (TREE_CODE (t) == ARRAY_REF || TREE_CODE (t) == ARRAY_RANGE_REF)
    3507                 :             :         {
    3508                 :             :           /* Deal with the low bound and element type size and put them into
    3509                 :             :              the ARRAY_REF.  If these values are set, they have already been
    3510                 :             :              gimplified.  */
    3511                 :     8456071 :           if (TREE_OPERAND (t, 2) == NULL_TREE)
    3512                 :             :             {
    3513                 :     8406211 :               tree low = unshare_expr (array_ref_low_bound (t));
    3514                 :     8406211 :               if (!is_gimple_min_invariant (low))
    3515                 :             :                 {
    3516                 :           0 :                   TREE_OPERAND (t, 2) = low;
    3517                 :             :                 }
    3518                 :             :             }
    3519                 :             : 
    3520                 :     8456071 :           if (TREE_OPERAND (t, 3) == NULL_TREE)
    3521                 :             :             {
    3522                 :     8439106 :               tree elmt_size = array_ref_element_size (t);
    3523                 :     8439106 :               if (!is_gimple_min_invariant (elmt_size))
    3524                 :             :                 {
    3525                 :        8383 :                   elmt_size = unshare_expr (elmt_size);
    3526                 :        8383 :                   tree elmt_type = TREE_TYPE (TREE_TYPE (TREE_OPERAND (t, 0)));
    3527                 :        8383 :                   tree factor = size_int (TYPE_ALIGN_UNIT (elmt_type));
    3528                 :             : 
    3529                 :             :                   /* Divide the element size by the alignment of the element
    3530                 :             :                      type (above).  */
    3531                 :        8383 :                   elmt_size = size_binop_loc (loc, EXACT_DIV_EXPR,
    3532                 :             :                                               elmt_size, factor);
    3533                 :             : 
    3534                 :        8383 :                   TREE_OPERAND (t, 3) = elmt_size;
    3535                 :             :                 }
    3536                 :             :             }
    3537                 :             :           need_non_reg = true;
    3538                 :             :         }
    3539                 :    31678565 :       else if (TREE_CODE (t) == COMPONENT_REF)
    3540                 :             :         {
    3541                 :             :           /* Set the field offset into T and gimplify it.  */
    3542                 :    30414381 :           if (TREE_OPERAND (t, 2) == NULL_TREE)
    3543                 :             :             {
    3544                 :    30414014 :               tree offset = component_ref_field_offset (t);
    3545                 :    30414014 :               if (!is_gimple_min_invariant (offset))
    3546                 :             :                 {
    3547                 :         281 :                   offset = unshare_expr (offset);
    3548                 :         281 :                   tree field = TREE_OPERAND (t, 1);
    3549                 :         281 :                   tree factor
    3550                 :         281 :                     = size_int (DECL_OFFSET_ALIGN (field) / BITS_PER_UNIT);
    3551                 :             : 
    3552                 :             :                   /* Divide the offset by its alignment.  */
    3553                 :         281 :                   offset = size_binop_loc (loc, EXACT_DIV_EXPR,
    3554                 :             :                                            offset, factor);
    3555                 :             : 
    3556                 :         281 :                   TREE_OPERAND (t, 2) = offset;
    3557                 :             :                 }
    3558                 :             :             }
    3559                 :             :           need_non_reg = true;
    3560                 :             :         }
    3561                 :     1264184 :       else if (!is_gimple_reg_type (TREE_TYPE (t)))
    3562                 :             :         /* When the result of an operation, in particular a VIEW_CONVERT_EXPR
    3563                 :             :            is a non-register type then require the base object to be a
    3564                 :             :            non-register as well.  */
    3565                 :    39139782 :         need_non_reg = true;
    3566                 :             :     }
    3567                 :             : 
    3568                 :             :   /* Step 2 is to gimplify the base expression.  Make sure lvalue is set
    3569                 :             :      so as to match the min_lval predicate.  Failure to do so may result
    3570                 :             :      in the creation of large aggregate temporaries.  */
    3571                 :    28574882 :   tret = gimplify_expr (p, pre_p, post_p, is_gimple_min_lval,
    3572                 :             :                         fallback | fb_lvalue);
    3573                 :    28574882 :   ret = MIN (ret, tret);
    3574                 :    28574882 :   if (ret == GS_ERROR)
    3575                 :             :     return GS_ERROR;
    3576                 :             : 
    3577                 :             :   /* Step 2a: if we have component references we do not support on
    3578                 :             :      registers then make sure the base isn't a register.  Of course
    3579                 :             :      we can only do so if an rvalue is OK.  */
    3580                 :    28574882 :   if (need_non_reg && (fallback & fb_rvalue))
    3581                 :    21352089 :     prepare_gimple_addressable (p, pre_p);
    3582                 :             : 
    3583                 :             : 
    3584                 :             :   /* Step 3: gimplify size expressions and the indices and operands of
    3585                 :             :      ARRAY_REF.  During this loop we also remove any useless conversions.
    3586                 :             :      If we operate on a register also make sure to properly gimplify
    3587                 :             :      to individual operations.  */
    3588                 :             : 
    3589                 :    28574882 :   bool reg_operations = is_gimple_reg (*p);
    3590                 :    68709518 :   for (; expr_stack.length () > 0; )
    3591                 :             :     {
    3592                 :    40134636 :       tree t = expr_stack.pop ();
    3593                 :             : 
    3594                 :    40134636 :       if (TREE_CODE (t) == ARRAY_REF || TREE_CODE (t) == ARRAY_RANGE_REF)
    3595                 :             :         {
    3596                 :     8456071 :           gcc_assert (!reg_operations);
    3597                 :             : 
    3598                 :             :           /* Gimplify the low bound and element type size. */
    3599                 :     8456071 :           tret = gimplify_expr (&TREE_OPERAND (t, 2), pre_p, post_p,
    3600                 :             :                                 is_gimple_reg, fb_rvalue);
    3601                 :     8456071 :           ret = MIN (ret, tret);
    3602                 :             : 
    3603                 :     8456071 :           tret = gimplify_expr (&TREE_OPERAND (t, 3), pre_p, post_p,
    3604                 :             :                                 is_gimple_reg, fb_rvalue);
    3605                 :     8456071 :           ret = MIN (ret, tret);
    3606                 :             : 
    3607                 :             :           /* Gimplify the dimension.  */
    3608                 :     8456071 :           tret = gimplify_expr (&TREE_OPERAND (t, 1), pre_p, post_p,
    3609                 :             :                                 is_gimple_val, fb_rvalue);
    3610                 :     8456071 :           ret = MIN (ret, tret);
    3611                 :             :         }
    3612                 :    31678565 :       else if (TREE_CODE (t) == COMPONENT_REF)
    3613                 :             :         {
    3614                 :    30414381 :           gcc_assert (!reg_operations);
    3615                 :             : 
    3616                 :    30414381 :           tret = gimplify_expr (&TREE_OPERAND (t, 2), pre_p, post_p,
    3617                 :             :                                 is_gimple_reg, fb_rvalue);
    3618                 :    30414381 :           ret = MIN (ret, tret);
    3619                 :             :         }
    3620                 :     1264184 :       else if (reg_operations)
    3621                 :             :         {
    3622                 :      742043 :           tret = gimplify_expr (&TREE_OPERAND (t, 0), pre_p, post_p,
    3623                 :             :                                 is_gimple_val, fb_rvalue);
    3624                 :      742043 :           ret = MIN (ret, tret);
    3625                 :             :         }
    3626                 :             : 
    3627                 :    40134636 :       STRIP_USELESS_TYPE_CONVERSION (TREE_OPERAND (t, 0));
    3628                 :             : 
    3629                 :             :       /* The innermost expression P may have originally had
    3630                 :             :          TREE_SIDE_EFFECTS set which would have caused all the outer
    3631                 :             :          expressions in *EXPR_P leading to P to also have had
    3632                 :             :          TREE_SIDE_EFFECTS set.  */
    3633                 :    40134636 :       recalculate_side_effects (t);
    3634                 :             :     }
    3635                 :             : 
    3636                 :             :   /* If the outermost expression is a COMPONENT_REF, canonicalize its type.  */
    3637                 :    28574882 :   if ((fallback & fb_rvalue) && TREE_CODE (*expr_p) == COMPONENT_REF)
    3638                 :             :     {
    3639                 :    17410110 :       canonicalize_component_ref (expr_p);
    3640                 :             :     }
    3641                 :             : 
    3642                 :    28574882 :   expr_stack.release ();
    3643                 :             : 
    3644                 :    28574882 :   gcc_assert (*expr_p == expr || ret != GS_ALL_DONE);
    3645                 :             : 
    3646                 :             :   return ret;
    3647                 :    28574885 : }
    3648                 :             : 
    3649                 :             : /*  Gimplify the self modifying expression pointed to by EXPR_P
    3650                 :             :     (++, --, +=, -=).
    3651                 :             : 
    3652                 :             :     PRE_P points to the list where side effects that must happen before
    3653                 :             :         *EXPR_P should be stored.
    3654                 :             : 
    3655                 :             :     POST_P points to the list where side effects that must happen after
    3656                 :             :         *EXPR_P should be stored.
    3657                 :             : 
    3658                 :             :     WANT_VALUE is nonzero iff we want to use the value of this expression
    3659                 :             :         in another expression.
    3660                 :             : 
    3661                 :             :     ARITH_TYPE is the type the computation should be performed in.  */
    3662                 :             : 
    3663                 :             : enum gimplify_status
    3664                 :     1118318 : gimplify_self_mod_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
    3665                 :             :                         bool want_value, tree arith_type)
    3666                 :             : {
    3667                 :     1118318 :   enum tree_code code;
    3668                 :     1118318 :   tree lhs, lvalue, rhs, t1;
    3669                 :     1118318 :   gimple_seq post = NULL, *orig_post_p = post_p;
    3670                 :     1118318 :   bool postfix;
    3671                 :     1118318 :   enum tree_code arith_code;
    3672                 :     1118318 :   enum gimplify_status ret;
    3673                 :     1118318 :   location_t loc = EXPR_LOCATION (*expr_p);
    3674                 :             : 
    3675                 :     1118318 :   code = TREE_CODE (*expr_p);
    3676                 :             : 
    3677                 :     1118318 :   gcc_assert (code == POSTINCREMENT_EXPR || code == POSTDECREMENT_EXPR
    3678                 :             :               || code == PREINCREMENT_EXPR || code == PREDECREMENT_EXPR);
    3679                 :             : 
    3680                 :             :   /* Prefix or postfix?  */
    3681                 :     1118318 :   if (code == POSTINCREMENT_EXPR || code == POSTDECREMENT_EXPR)
    3682                 :             :     /* Faster to treat as prefix if result is not used.  */
    3683                 :             :     postfix = want_value;
    3684                 :             :   else
    3685                 :             :     postfix = false;
    3686                 :             : 
    3687                 :             :   /* For postfix, make sure the inner expression's post side effects
    3688                 :             :      are executed after side effects from this expression.  */
    3689                 :      390634 :   if (postfix)
    3690                 :     1118318 :     post_p = &post;
    3691                 :             : 
    3692                 :             :   /* Add or subtract?  */
    3693                 :     1118318 :   if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
    3694                 :             :     arith_code = PLUS_EXPR;
    3695                 :             :   else
    3696                 :       44991 :     arith_code = MINUS_EXPR;
    3697                 :             : 
    3698                 :             :   /* Gimplify the LHS into a GIMPLE lvalue.  */
    3699                 :     1118318 :   lvalue = TREE_OPERAND (*expr_p, 0);
    3700                 :     1118318 :   ret = gimplify_expr (&lvalue, pre_p, post_p, is_gimple_lvalue, fb_lvalue);
    3701                 :     1118318 :   if (ret == GS_ERROR)
    3702                 :             :     return ret;
    3703                 :             : 
    3704                 :             :   /* Extract the operands to the arithmetic operation.  */
    3705                 :     1118317 :   lhs = lvalue;
    3706                 :     1118317 :   rhs = TREE_OPERAND (*expr_p, 1);
    3707                 :             : 
    3708                 :             :   /* For postfix operator, we evaluate the LHS to an rvalue and then use
    3709                 :             :      that as the result value and in the postqueue operation.  */
    3710                 :     1118317 :   if (postfix)
    3711                 :             :     {
    3712                 :      188133 :       ret = gimplify_expr (&lhs, pre_p, post_p, is_gimple_val, fb_rvalue);
    3713                 :      188133 :       if (ret == GS_ERROR)
    3714                 :             :         return ret;
    3715                 :             : 
    3716                 :      188133 :       lhs = get_initialized_tmp_var (lhs, pre_p);
    3717                 :             :     }
    3718                 :             : 
    3719                 :             :   /* For POINTERs increment, use POINTER_PLUS_EXPR.  */
    3720                 :     1118317 :   if (POINTER_TYPE_P (TREE_TYPE (lhs)))
    3721                 :             :     {
    3722                 :      233052 :       rhs = convert_to_ptrofftype_loc (loc, rhs);
    3723                 :      233052 :       if (arith_code == MINUS_EXPR)
    3724                 :        9622 :         rhs = fold_build1_loc (loc, NEGATE_EXPR, TREE_TYPE (rhs), rhs);
    3725                 :      233052 :       t1 = fold_build2 (POINTER_PLUS_EXPR, TREE_TYPE (*expr_p), lhs, rhs);
    3726                 :             :     }
    3727                 :             :   else
    3728                 :      885265 :     t1 = fold_convert (TREE_TYPE (*expr_p),
    3729                 :             :                        fold_build2 (arith_code, arith_type,
    3730                 :             :                                     fold_convert (arith_type, lhs),
    3731                 :             :                                     fold_convert (arith_type, rhs)));
    3732                 :             : 
    3733                 :     1118317 :   if (postfix)
    3734                 :             :     {
    3735                 :      188133 :       gimplify_assign (lvalue, t1, pre_p);
    3736                 :      188133 :       gimplify_seq_add_seq (orig_post_p, post);
    3737                 :      188133 :       *expr_p = lhs;
    3738                 :      188133 :       return GS_ALL_DONE;
    3739                 :             :     }
    3740                 :             :   else
    3741                 :             :     {
    3742                 :      930184 :       *expr_p = build2 (MODIFY_EXPR, TREE_TYPE (lvalue), lvalue, t1);
    3743                 :      930184 :       return GS_OK;
    3744                 :             :     }
    3745                 :             : }
    3746                 :             : 
    3747                 :             : /* If *EXPR_P has a variable sized type, wrap it in a WITH_SIZE_EXPR.  */
    3748                 :             : 
    3749                 :             : static void
    3750                 :    76162424 : maybe_with_size_expr (tree *expr_p)
    3751                 :             : {
    3752                 :    76162424 :   tree expr = *expr_p;
    3753                 :    76162424 :   tree type = TREE_TYPE (expr);
    3754                 :    76162424 :   tree size;
    3755                 :             : 
    3756                 :             :   /* If we've already wrapped this or the type is error_mark_node, we can't do
    3757                 :             :      anything.  */
    3758                 :    76162424 :   if (TREE_CODE (expr) == WITH_SIZE_EXPR
    3759                 :    76162303 :       || type == error_mark_node)
    3760                 :             :     return;
    3761                 :             : 
    3762                 :             :   /* If the size isn't known or is a constant, we have nothing to do.  */
    3763                 :    76162272 :   size = TYPE_SIZE_UNIT (type);
    3764                 :    76162272 :   if (!size || poly_int_tree_p (size))
    3765                 :             :     return;
    3766                 :             : 
    3767                 :             :   /* Otherwise, make a WITH_SIZE_EXPR.  */
    3768                 :        1494 :   size = unshare_expr (size);
    3769                 :        1494 :   size = SUBSTITUTE_PLACEHOLDER_IN_EXPR (size, expr);
    3770                 :        1494 :   *expr_p = build2 (WITH_SIZE_EXPR, type, expr, size);
    3771                 :             : }
    3772                 :             : 
    3773                 :             : /* Helper for gimplify_call_expr.  Gimplify a single argument *ARG_P
    3774                 :             :    Store any side-effects in PRE_P.  CALL_LOCATION is the location of
    3775                 :             :    the CALL_EXPR.  If ALLOW_SSA is set the actual parameter may be
    3776                 :             :    gimplified to an SSA name.  */
    3777                 :             : 
    3778                 :             : enum gimplify_status
    3779                 :    30708708 : gimplify_arg (tree *arg_p, gimple_seq *pre_p, location_t call_location,
    3780                 :             :               bool allow_ssa)
    3781                 :             : {
    3782                 :    30708708 :   bool (*test) (tree);
    3783                 :    30708708 :   fallback_t fb;
    3784                 :             : 
    3785                 :             :   /* In general, we allow lvalues for function arguments to avoid
    3786                 :             :      extra overhead of copying large aggregates out of even larger
    3787                 :             :      aggregates into temporaries only to copy the temporaries to
    3788                 :             :      the argument list.  Make optimizers happy by pulling out to
    3789                 :             :      temporaries those types that fit in registers.  */
    3790                 :    30708708 :   if (is_gimple_reg_type (TREE_TYPE (*arg_p)))
    3791                 :             :     test = is_gimple_val, fb = fb_rvalue;
    3792                 :             :   else
    3793                 :             :     {
    3794                 :     1436637 :       test = is_gimple_lvalue, fb = fb_either;
    3795                 :             :       /* Also strip a TARGET_EXPR that would force an extra copy.  */
    3796                 :     1436637 :       if (TREE_CODE (*arg_p) == TARGET_EXPR)
    3797                 :             :         {
    3798                 :      267512 :           tree init = TARGET_EXPR_INITIAL (*arg_p);
    3799                 :      267512 :           if (init
    3800                 :      267511 :               && !VOID_TYPE_P (TREE_TYPE (init))
    3801                 :             :               /* Currently, due to c++/116015, it is not desirable to
    3802                 :             :                  strip a TARGET_EXPR whose initializer is a {}.  The
    3803                 :             :                  problem is that if we do elide it, we also have to
    3804                 :             :                  replace all the occurrences of the slot temporary in the
    3805                 :             :                  initializer with the temporary created for the argument.
    3806                 :             :                  But we do not have that temporary yet so the replacement
    3807                 :             :                  would be quite awkward and it might be needed to resort
    3808                 :             :                  back to a PLACEHOLDER_EXPR.  Note that stripping the
    3809                 :             :                  TARGET_EXPR wouldn't help anyway, as gimplify_expr would
    3810                 :             :                  just allocate a temporary to store the CONSTRUCTOR into.
    3811                 :             :                  (FIXME PR116375.)
    3812                 :             : 
    3813                 :             :                  See convert_for_arg_passing for the C++ code that marks
    3814                 :             :                  the TARGET_EXPR as eliding or not.  */
    3815                 :      508335 :               && TREE_CODE (init) != CONSTRUCTOR)
    3816                 :      223845 :             *arg_p = init;
    3817                 :             :         }
    3818                 :             :     }
    3819                 :             : 
    3820                 :             :   /* If this is a variable sized type, we must remember the size.  */
    3821                 :    30708708 :   maybe_with_size_expr (arg_p);
    3822                 :             : 
    3823                 :             :   /* FIXME diagnostics: This will mess up gcc.dg/Warray-bounds.c.  */
    3824                 :             :   /* Make sure arguments have the same location as the function call
    3825                 :             :      itself.  */
    3826                 :    30708708 :   protected_set_expr_location (*arg_p, call_location);
    3827                 :             : 
    3828                 :             :   /* There is a sequence point before a function call.  Side effects in
    3829                 :             :      the argument list must occur before the actual call. So, when
    3830                 :             :      gimplifying arguments, force gimplify_expr to use an internal
    3831                 :             :      post queue which is then appended to the end of PRE_P.  */
    3832                 :    30708708 :   return gimplify_expr (arg_p, pre_p, NULL, test, fb, allow_ssa);
    3833                 :             : }
    3834                 :             : 
    3835                 :             : /* Don't fold inside offloading or taskreg regions: it can break code by
    3836                 :             :    adding decl references that weren't in the source.  We'll do it during
    3837                 :             :    omplower pass instead.  */
    3838                 :             : 
    3839                 :             : static bool
    3840                 :    56321481 : maybe_fold_stmt (gimple_stmt_iterator *gsi)
    3841                 :             : {
    3842                 :    56321481 :   struct gimplify_omp_ctx *ctx;
    3843                 :    56846575 :   for (ctx = gimplify_omp_ctxp; ctx; ctx = ctx->outer_context)
    3844                 :     1118201 :     if ((ctx->region_type & (ORT_TARGET | ORT_PARALLEL | ORT_TASK)) != 0)
    3845                 :             :       return false;
    3846                 :      529971 :     else if ((ctx->region_type & ORT_HOST_TEAMS) == ORT_HOST_TEAMS)
    3847                 :             :       return false;
    3848                 :             :   /* Delay folding of builtins until the IL is in consistent state
    3849                 :             :      so the diagnostic machinery can do a better job.  */
    3850                 :    55728374 :   if (gimple_call_builtin_p (gsi_stmt (*gsi)))
    3851                 :             :     return false;
    3852                 :    53500859 :   return fold_stmt (gsi);
    3853                 :             : }
    3854                 :             : 
    3855                 :             : static tree
    3856                 :             : expand_late_variant_directive (vec<struct omp_variant> all_candidates,
    3857                 :             :                                tree construct_context);
    3858                 :             : 
    3859                 :             : 
    3860                 :             : /* Helper function for calls to omp_dynamic_cond: find the current
    3861                 :             :    enclosing block in the gimplification context.  */
    3862                 :             : static tree
    3863                 :         331 : find_supercontext (void)
    3864                 :             : {
    3865                 :         331 :   vec<gbind *>stack = gimple_bind_expr_stack ();
    3866                 :         633 :   for (int i = stack.length () - 1; i >= 0; i++)
    3867                 :             :     {
    3868                 :         302 :       gbind *b = stack[i];
    3869                 :         302 :       if (b->block)
    3870                 :             :         return b->block;
    3871                 :             :     }
    3872                 :             :   return NULL_TREE;
    3873                 :             : }
    3874                 :             : 
    3875                 :             : /* OpenMP: Handle the append_args and adjust_args clauses of
    3876                 :             :    declare_variant for EXPR, which is a CALL_EXPR whose CALL_EXPR_FN
    3877                 :             :    is the variant, within a dispatch construct with clauses DISPATCH_CLAUSES
    3878                 :             :    and location DISPATCH_LOC.
    3879                 :             : 
    3880                 :             :    'append_args' causes interop objects are added after the last regular
    3881                 :             :    (nonhidden, nonvariadic) arguments of the variant function.
    3882                 :             :    'adjust_args' with need_device_{addr,ptr} converts the pointer target of
    3883                 :             :    a pointer from a host to a device address. This uses either the default
    3884                 :             :    device or the passed device number, which then sets the default device
    3885                 :             :    address.  */
    3886                 :             : static tree
    3887                 :         448 : modify_call_for_omp_dispatch (tree expr, tree dispatch_clauses,
    3888                 :             :                               location_t dispatch_loc)
    3889                 :             : {
    3890                 :         448 :   tree fndecl = get_callee_fndecl (expr);
    3891                 :             : 
    3892                 :             :   /* Skip processing if we don't get the expected call form.  */
    3893                 :         448 :   if (!fndecl)
    3894                 :             :     return expr;
    3895                 :             : 
    3896                 :         448 :   int nargs = call_expr_nargs (expr);
    3897                 :         448 :   tree dispatch_device_num = NULL_TREE;
    3898                 :         448 :   tree dispatch_device_num_init = NULL_TREE;
    3899                 :         448 :   tree dispatch_interop = NULL_TREE;
    3900                 :         448 :   tree dispatch_append_args = NULL_TREE;
    3901                 :         448 :   int nfirst_args = 0;
    3902                 :         448 :   tree dispatch_adjust_args_list
    3903                 :         448 :     = lookup_attribute ("omp declare variant variant args",
    3904                 :         448 :                         DECL_ATTRIBUTES (fndecl));
    3905                 :             : 
    3906                 :         448 :   if (dispatch_adjust_args_list)
    3907                 :             :     {
    3908                 :         366 :       dispatch_adjust_args_list = TREE_VALUE (dispatch_adjust_args_list);
    3909                 :         366 :       dispatch_append_args = TREE_CHAIN (dispatch_adjust_args_list);
    3910                 :         366 :       if (TREE_PURPOSE (dispatch_adjust_args_list) == NULL_TREE
    3911                 :         366 :           && TREE_VALUE (dispatch_adjust_args_list) == NULL_TREE)
    3912                 :             :         dispatch_adjust_args_list = NULL_TREE;
    3913                 :             :     }
    3914                 :         366 :   if (dispatch_append_args)
    3915                 :             :     {
    3916                 :         222 :       nfirst_args = tree_to_shwi (TREE_PURPOSE (dispatch_append_args));
    3917                 :         222 :       dispatch_append_args = TREE_VALUE (dispatch_append_args);
    3918                 :             :     }
    3919                 :         448 :   dispatch_device_num = omp_find_clause (dispatch_clauses, OMP_CLAUSE_DEVICE);
    3920                 :         448 :   if (dispatch_device_num)
    3921                 :         273 :     dispatch_device_num = OMP_CLAUSE_DEVICE_ID (dispatch_device_num);
    3922                 :         448 :   dispatch_interop = omp_find_clause (dispatch_clauses, OMP_CLAUSE_INTEROP);
    3923                 :         448 :   int nappend = 0, ninterop = 0;
    3924                 :         815 :   for (tree t = dispatch_append_args; t; t = TREE_CHAIN (t))
    3925                 :         367 :     nappend++;
    3926                 :             : 
    3927                 :             :   /* FIXME: error checking should be taken out of this function and
    3928                 :             :      handled before any attempt at filtering or resolution happens.
    3929                 :             :      Otherwise whether or not diagnostics appear is determined by
    3930                 :             :      GCC internals, how good the front ends are at constant-folding,
    3931                 :             :      the split between early/late resolution, etc instead of the code
    3932                 :             :      as written by the user.  */
    3933                 :         448 :   if (dispatch_interop)
    3934                 :             :     {
    3935                 :         840 :       for (tree t = dispatch_interop; t; t = TREE_CHAIN (t))
    3936                 :         591 :         if (OMP_CLAUSE_CODE (t) == OMP_CLAUSE_INTEROP)
    3937                 :         402 :           ninterop++;
    3938                 :         249 :       if (nappend < ninterop)
    3939                 :             :         {
    3940                 :          48 :           error_at (OMP_CLAUSE_LOCATION (dispatch_interop),
    3941                 :             :                     "number of list items in %<interop%> clause (%d) "
    3942                 :             :                     "exceeds the number of %<append_args%> items (%d) for "
    3943                 :             :                     "%<declare variant%> candidate %qD",
    3944                 :             :                     ninterop, nappend, fndecl);
    3945                 :          96 :           inform (dispatch_append_args
    3946                 :           8 :                   ? EXPR_LOCATION (TREE_PURPOSE (dispatch_append_args))
    3947                 :          40 :                   : DECL_SOURCE_LOCATION (fndecl),
    3948                 :             :                   "%<declare variant%> candidate %qD declared here",
    3949                 :             :                   fndecl);
    3950                 :             :         }
    3951                 :             :     }
    3952                 :         448 :   if (dispatch_interop && !dispatch_device_num)
    3953                 :             :     {
    3954                 :           7 :       gcc_checking_assert (ninterop > 1);
    3955                 :           7 :       error_at (OMP_CLAUSE_LOCATION (dispatch_interop),
    3956                 :             :                 "the %<device%> clause must be present if the %<interop%> "
    3957                 :             :                 "clause has more than one list item");
    3958                 :             :     }
    3959                 :         448 :   if (dispatch_append_args && nappend != ninterop)
    3960                 :             :     {
    3961                 :          41 :       sorry_at (EXPR_LOCATION (TREE_PURPOSE (dispatch_append_args)),
    3962                 :             :                 "%<append_args%> clause not yet supported for %qD, except "
    3963                 :             :                 "when specifying all %d objects in the %<interop%> clause "
    3964                 :             :                 "of the %<dispatch%> directive", fndecl, nappend);
    3965                 :          41 :       inform (dispatch_loc, "required by %<dispatch%> construct");
    3966                 :             :     }
    3967                 :         407 :   else if (dispatch_append_args)
    3968                 :             :     {
    3969                 :         181 :       tree *buffer = XALLOCAVEC (tree, nargs + nappend);
    3970                 :         181 :       tree arg = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
    3971                 :             :       /* Copy the first arguments; insert then the interop objects,
    3972                 :             :          and then copy the rest (nargs - nfirst_args) args.  */
    3973                 :         181 :       int i;
    3974                 :         558 :       for (i = 0; i < nfirst_args; i++)
    3975                 :             :         {
    3976                 :         377 :           arg = TREE_CHAIN (arg);
    3977                 :         377 :           buffer[i] = CALL_EXPR_ARG (expr, i);
    3978                 :             :         }
    3979                 :             :       int j = nappend;
    3980                 :         629 :       for (tree t = dispatch_interop; t; t = TREE_CHAIN (t))
    3981                 :         448 :         if (OMP_CLAUSE_CODE (t) == OMP_CLAUSE_INTEROP)
    3982                 :         303 :           buffer[i + --j] = OMP_CLAUSE_DECL (t);
    3983                 :         181 :       gcc_checking_assert (j == 0);
    3984                 :         484 :       for (j = 0; j < nappend; j++)
    3985                 :             :         {
    3986                 :             :           /* Fortran permits by-reference or by-value for the dummy arg
    3987                 :             :              and by-value, by-reference, ptr by-reference as actual
    3988                 :             :              argument. Handle this.  */
    3989                 :         303 :           tree obj = buffer[i + j];  // interop object
    3990                 :         303 :           tree a2 = TREE_VALUE (arg);  // parameter type
    3991                 :         554 :           if (POINTER_TYPE_P (TREE_TYPE (obj))
    3992                 :         330 :               && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (obj))))
    3993                 :             :             {
    3994                 :          32 :               tree t = TREE_TYPE (TREE_TYPE (obj));
    3995                 :          32 :               gcc_checking_assert (INTEGRAL_TYPE_P (TREE_TYPE (t)));
    3996                 :          32 :               obj = fold_build1 (INDIRECT_REF, t, obj);
    3997                 :             :             }
    3998                 :         538 :           if (POINTER_TYPE_P (TREE_TYPE (obj))
    3999                 :         314 :               && INTEGRAL_TYPE_P (a2))
    4000                 :             :             {
    4001                 :          43 :               tree t = TREE_TYPE (TREE_TYPE (obj));
    4002                 :          43 :               gcc_checking_assert (INTEGRAL_TYPE_P (t));
    4003                 :          43 :               obj = fold_build1 (INDIRECT_REF, t, obj);
    4004                 :             :             }
    4005                 :         320 :           else if (INTEGRAL_TYPE_P (TREE_TYPE (obj))
    4006                 :         284 :                    && POINTER_TYPE_P (a2))
    4007                 :             :             {
    4008                 :          12 :               gcc_checking_assert (INTEGRAL_TYPE_P (TREE_TYPE (a2)));
    4009                 :          12 :               obj = build_fold_addr_expr (obj);
    4010                 :             :             }
    4011                 :         248 :           else if (!INTEGRAL_TYPE_P (a2)
    4012                 :         248 :                    || !INTEGRAL_TYPE_P (TREE_TYPE (obj)))
    4013                 :             :             {
    4014                 :          36 :               tree t = TREE_TYPE (obj);
    4015                 :          36 :               gcc_checking_assert (POINTER_TYPE_P (t)
    4016                 :             :                                    && POINTER_TYPE_P (a2)
    4017                 :             :                                    && INTEGRAL_TYPE_P (TREE_TYPE (t))
    4018                 :             :                                    && INTEGRAL_TYPE_P (TREE_TYPE (a2)));
    4019                 :             :             }
    4020                 :         303 :           buffer[i + j] = obj;
    4021                 :         303 :           arg = TREE_CHAIN (arg);
    4022                 :             :         }
    4023                 :         181 :       i += nappend;
    4024                 :         428 :       for (j = nfirst_args; j < nargs; j++)
    4025                 :         247 :         buffer[i++] = CALL_EXPR_ARG (expr, j);
    4026                 :         181 :       nargs += nappend;
    4027                 :         181 :       tree call = expr;
    4028                 :         362 :       expr = build_call_array_loc (EXPR_LOCATION (expr), TREE_TYPE (call),
    4029                 :         181 :                                    CALL_EXPR_FN (call), nargs, buffer);
    4030                 :             : 
    4031                 :             :       /* Copy all CALL_EXPR flags.  */
    4032                 :         181 :       CALL_EXPR_STATIC_CHAIN (expr) = CALL_EXPR_STATIC_CHAIN (call);
    4033                 :         181 :       CALL_EXPR_TAILCALL (expr) = CALL_EXPR_TAILCALL (call);
    4034                 :         181 :       CALL_EXPR_RETURN_SLOT_OPT (expr)
    4035                 :         181 :         = CALL_EXPR_RETURN_SLOT_OPT (call);
    4036                 :         181 :       CALL_FROM_THUNK_P (expr) = CALL_FROM_THUNK_P (call);
    4037                 :         181 :       SET_EXPR_LOCATION (expr, EXPR_LOCATION (call));
    4038                 :         181 :       CALL_EXPR_VA_ARG_PACK (expr) = CALL_EXPR_VA_ARG_PACK (call);
    4039                 :             :     }
    4040                 :             : 
    4041                 :             :   /* Nothing to do for adjust_args?  */
    4042                 :         448 :   if (!dispatch_adjust_args_list || !TYPE_ARG_TYPES (TREE_TYPE (fndecl)))
    4043                 :             :     return expr;
    4044                 :             : 
    4045                 :         927 :   for (int i = 0; i < nargs; i++)
    4046                 :             :     {
    4047                 :         719 :       tree *arg_p = &CALL_EXPR_ARG (expr, i);
    4048                 :             : 
    4049                 :             :       /* Nothing to do if arg is constant null pointer.  */
    4050                 :         719 :       if (integer_zerop (*arg_p))
    4051                 :           6 :         continue;
    4052                 :             : 
    4053                 :             :       bool need_device_ptr = false;
    4054                 :             :       bool need_device_addr = false;
    4055                 :        2139 :       for (int need_addr = 0; need_addr <= 1; need_addr++)
    4056                 :        2196 :         for (tree arg = (need_addr
    4057                 :        2139 :                          ? TREE_VALUE (dispatch_adjust_args_list)
    4058                 :         713 :                          : TREE_PURPOSE (dispatch_adjust_args_list));
    4059                 :        2196 :              arg != NULL; arg = TREE_CHAIN (arg))
    4060                 :             :           {
    4061                 :        1116 :             if (TREE_VALUE (arg)
    4062                 :        1116 :                 && TREE_CODE (TREE_VALUE (arg)) == INTEGER_CST
    4063                 :        2232 :                 && wi::eq_p (i, wi::to_wide (TREE_VALUE (arg))))
    4064                 :             :               {
    4065                 :         346 :                 if (need_addr)
    4066                 :             :                   need_device_addr = true;
    4067                 :             :                 else
    4068                 :         346 :                   need_device_ptr = true;
    4069                 :             :                 break;
    4070                 :             :               }
    4071                 :             :           }
    4072                 :             : 
    4073                 :         713 :       if (need_device_ptr || need_device_addr)
    4074                 :             :         {
    4075                 :         731 :           bool is_device_ptr = false;
    4076                 :         731 :           bool has_device_addr = false;
    4077                 :             : 
    4078                 :         731 :           for (tree c = dispatch_clauses; c; c = TREE_CHAIN (c))
    4079                 :             :             {
    4080                 :         448 :               if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR
    4081                 :         448 :                   || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR)
    4082                 :             :                 {
    4083                 :         164 :                   tree decl1 = DECL_NAME (OMP_CLAUSE_DECL (c));
    4084                 :         164 :                   tree decl2 = tree_strip_nop_conversions (*arg_p);
    4085                 :         164 :                   if (TREE_CODE (decl2) == ADDR_EXPR)
    4086                 :          19 :                     decl2 = TREE_OPERAND (decl2, 0);
    4087                 :         164 :                   if (VAR_P (decl2) || TREE_CODE (decl2) == PARM_DECL)
    4088                 :             :                     {
    4089                 :         140 :                       decl2 = DECL_NAME (decl2);
    4090                 :         140 :                       if (decl1 == decl2
    4091                 :         203 :                           && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR)
    4092                 :             :                         {
    4093                 :          58 :                           if (need_device_addr)
    4094                 :           0 :                             warning_at (OMP_CLAUSE_LOCATION (c),
    4095                 :             :                                         OPT_Wopenmp,
    4096                 :             :                                         "%<is_device_ptr%> for %qD does"
    4097                 :             :                                         " not imply %<has_device_addr%> "
    4098                 :             :                                         "required for %<need_device_addr%>",
    4099                 :           0 :                                         OMP_CLAUSE_DECL (c));
    4100                 :             :                           is_device_ptr = true;
    4101                 :             :                           break;
    4102                 :             :                         }
    4103                 :          82 :                       else if (decl1 == decl2)
    4104                 :             :                         {
    4105                 :           5 :                           if (need_device_ptr)
    4106                 :          10 :                             warning_at (OMP_CLAUSE_LOCATION (c),
    4107                 :             :                                         OPT_Wopenmp,
    4108                 :             :                                         "%<has_device_addr%> for %qD does"
    4109                 :             :                                         " not imply %<is_device_ptr%> "
    4110                 :             :                                         "required for %<need_device_ptr%>",
    4111                 :           5 :                                         OMP_CLAUSE_DECL (c));
    4112                 :             :                           has_device_addr = true;
    4113                 :             :                           break;
    4114                 :             :                         }
    4115                 :             :                     }
    4116                 :             :                 }
    4117                 :             :             }
    4118                 :             : 
    4119                 :         346 :           if ((need_device_ptr && !is_device_ptr)
    4120                 :          58 :               || (need_device_addr && !has_device_addr))
    4121                 :             :             {
    4122                 :         288 :               if (dispatch_device_num == NULL_TREE)
    4123                 :             :                 {
    4124                 :             :                   // device_num = omp_get_default_device ()
    4125                 :         105 :                   tree fn
    4126                 :         105 :                     = builtin_decl_explicit (BUILT_IN_OMP_GET_DEFAULT_DEVICE);
    4127                 :         105 :                   tree call = build_call_expr (fn, 0);
    4128                 :         105 :                   dispatch_device_num = create_tmp_var_raw (TREE_TYPE (call));
    4129                 :         105 :                   dispatch_device_num_init
    4130                 :         105 :                     = build4 (TARGET_EXPR, TREE_TYPE (call),
    4131                 :             :                               dispatch_device_num, call, NULL_TREE, NULL_TREE);
    4132                 :             :                 }
    4133                 :             : 
    4134                 :             :               // We want to emit the following statement:
    4135                 :             :               //   mapped_arg = omp_get_mapped_ptr (arg,
    4136                 :             :               //                device_num)
    4137                 :             :               // but arg has to be the actual pointer, not a
    4138                 :             :               // reference or a conversion expression.
    4139                 :         288 :               tree actual_ptr
    4140                 :         288 :                 = ((TREE_CODE (*arg_p) == ADDR_EXPR)
    4141                 :         288 :                    ? TREE_OPERAND (*arg_p, 0)
    4142                 :         288 :                    : *arg_p);
    4143                 :         288 :               if (TREE_CODE (actual_ptr) == NOP_EXPR
    4144                 :         288 :                   && (TREE_CODE (TREE_TYPE (TREE_OPERAND (actual_ptr, 0)))
    4145                 :             :                       == REFERENCE_TYPE))
    4146                 :             :                 {
    4147                 :           6 :                   actual_ptr = TREE_OPERAND (actual_ptr, 0);
    4148                 :           6 :                   actual_ptr = build1 (INDIRECT_REF,
    4149                 :           6 :                                        TREE_TYPE (actual_ptr),
    4150                 :             :                                        actual_ptr);
    4151                 :             :                 }
    4152                 :         288 :               tree fn = builtin_decl_explicit (BUILT_IN_OMP_GET_MAPPED_PTR);
    4153                 :         288 :               tree mapped_arg = build_call_expr (fn, 2, actual_ptr,
    4154                 :             :                                                  dispatch_device_num);
    4155                 :             : 
    4156                 :         288 :               if (TREE_CODE (*arg_p) == ADDR_EXPR
    4157                 :         288 :                   || (TREE_CODE (TREE_TYPE (actual_ptr)) == REFERENCE_TYPE))
    4158                 :          47 :                 mapped_arg = build_fold_addr_expr (mapped_arg);
    4159                 :         241 :               else if (TREE_CODE (*arg_p) == NOP_EXPR)
    4160                 :          35 :                 mapped_arg = build1 (NOP_EXPR, TREE_TYPE (*arg_p),
    4161                 :             :                                      mapped_arg);
    4162                 :         288 :               *arg_p = mapped_arg;
    4163                 :             :             }
    4164                 :             :         }
    4165                 :             :     }
    4166                 :         208 :   if (dispatch_device_num_init)
    4167                 :         105 :     expr = build2 (COMPOUND_EXPR, TREE_TYPE (expr),
    4168                 :             :                    dispatch_device_num_init, expr);
    4169                 :             :   return expr;
    4170                 :             : }
    4171                 :             : 
    4172                 :             : /* Helper function for gimplify_call_expr: handle "declare variant"
    4173                 :             :    resolution and expansion of the CALL_EXPR EXPR.  WANT_VALUE is true
    4174                 :             :    if the result value of the call is needed; POINTERIZE is true if it
    4175                 :             :    also needs to be pointerized.  If OMP_DISPATCH_P is true, apply
    4176                 :             :    associated transformations using DISPATCH_CLAUSES and DISPATCH_LOC.
    4177                 :             :    This function may return either the original call or some other
    4178                 :             :    expression such as a conditional to select one of multiple calls.
    4179                 :             : 
    4180                 :             :    FIXME: this function is written to be independent of gimplifier internals
    4181                 :             :    so that it could be moved to omp-general.cc and invoked from the
    4182                 :             :    front ends instead, per PR115076.  */
    4183                 :             : 
    4184                 :             : static tree
    4185                 :        1060 : expand_variant_call_expr (tree expr, bool want_value, bool pointerize,
    4186                 :             :                           bool omp_dispatch_p,
    4187                 :             :                           tree dispatch_clauses, location_t dispatch_loc)
    4188                 :             : {
    4189                 :             :   /* If we've already processed this call, stop now.  This can happen
    4190                 :             :      if the variant call resolves to the original function, or to
    4191                 :             :      a dynamic conditional that includes the default call to the original
    4192                 :             :      function.  */
    4193                 :        1060 :   gcc_assert (omp_resolved_variant_calls != NULL);
    4194                 :        1060 :   if (omp_resolved_variant_calls->contains (expr))
    4195                 :          96 :     return expr;
    4196                 :             : 
    4197                 :         964 :   tree fndecl = get_callee_fndecl (expr);
    4198                 :         964 :   tree fnptrtype = TREE_TYPE (CALL_EXPR_FN (expr));
    4199                 :         964 :   location_t loc = EXPR_LOCATION (expr);
    4200                 :         964 :   tree construct_context = omp_get_construct_context ();
    4201                 :         964 :   vec<struct omp_variant> all_candidates
    4202                 :         964 :     = omp_declare_variant_candidates (fndecl, construct_context);
    4203                 :         964 :   gcc_assert (!all_candidates.is_empty ());
    4204                 :         964 :   vec<struct omp_variant> candidates
    4205                 :         964 :     = omp_get_dynamic_candidates (all_candidates, construct_context);
    4206                 :             : 
    4207                 :             :   /* If the variant call could be resolved now, build a nest of COND_EXPRs
    4208                 :             :      if there are dynamic candidates, and/or a new CALL_EXPR for each
    4209                 :             :      candidate call.  */
    4210                 :         964 :   if (!candidates.is_empty ())
    4211                 :             :     {
    4212                 :         952 :       int n = candidates.length ();
    4213                 :         952 :       tree tail = NULL_TREE;
    4214                 :             : 
    4215                 :        1936 :       for (int i = n - 1; i >= 0; i--)
    4216                 :             :         {
    4217                 :         984 :           if (tail)
    4218                 :          32 :             gcc_assert (candidates[i].dynamic_selector);
    4219                 :             :           else
    4220                 :         952 :             gcc_assert (!candidates[i].dynamic_selector);
    4221                 :         984 :           if (candidates[i].alternative == fndecl)
    4222                 :             :             {
    4223                 :             :               /* We should only get the original function back as the
    4224                 :             :                  default.  */
    4225                 :         194 :               gcc_assert (!tail);
    4226                 :         194 :               omp_resolved_variant_calls->add (expr);
    4227                 :         194 :               tail = expr;
    4228                 :             :             }
    4229                 :             :           else
    4230                 :             :             {
    4231                 :             :               /* For the final static selector, we can re-use the old
    4232                 :             :                  CALL_EXPR and just replace the function, unless it may
    4233                 :             :                  need dispatch argument modification.  Otherwise,
    4234                 :             :                  make a copy of it.  */
    4235                 :         790 :               tree thiscall = (tail || omp_dispatch_p
    4236                 :         790 :                                ? unshare_expr (expr) : expr);
    4237                 :         790 :               CALL_EXPR_FN (thiscall) = build1 (ADDR_EXPR, fnptrtype,
    4238                 :         790 :                                                 candidates[i].alternative);
    4239                 :         790 :               if (omp_dispatch_p)
    4240                 :         448 :                 thiscall = modify_call_for_omp_dispatch (thiscall,
    4241                 :             :                                                          dispatch_clauses,
    4242                 :             :                                                          dispatch_loc);
    4243                 :         790 :               if (!tail)
    4244                 :             :                 tail = thiscall;
    4245                 :             :               else
    4246                 :          64 :                 tail = build3 (COND_EXPR, TREE_TYPE (expr),
    4247                 :          32 :                                omp_dynamic_cond (candidates[i].selector,
    4248                 :             :                                                  find_supercontext ()),
    4249                 :             :                                thiscall, tail);
    4250                 :             :             }
    4251                 :             :         }
    4252                 :             :       return tail;
    4253                 :             :     }
    4254                 :             : 
    4255                 :             :   /* If we couldn't resolve the variant call now, expand it into a loop using
    4256                 :             :      a switch and OMP_NEXT_VARIANT for dispatch.  The ompdevlow pass will
    4257                 :             :      handle OMP_NEXT_VARIANT expansion.  */
    4258                 :             :   else
    4259                 :             :     {
    4260                 :             :       /* If we need a usable return value, we need a temporary
    4261                 :             :          and an assignment in each alternative.  This logic was borrowed
    4262                 :             :          from gimplify_cond_expr.  */
    4263                 :          12 :       tree type = TREE_TYPE (expr);
    4264                 :          12 :       tree tmp = NULL_TREE, result = NULL_TREE;
    4265                 :             : 
    4266                 :          12 :       if (want_value)
    4267                 :             :         {
    4268                 :          12 :           if (pointerize)
    4269                 :             :             {
    4270                 :           0 :               type = build_pointer_type (type);
    4271                 :           0 :               tmp = create_tmp_var (type, "iftmp");
    4272                 :           0 :               result = build_simple_mem_ref_loc (loc, tmp);
    4273                 :             :             }
    4274                 :             :           else
    4275                 :             :             {
    4276                 :          12 :               tmp = create_tmp_var (type, "iftmp");
    4277                 :          12 :               result = tmp;
    4278                 :             :             }
    4279                 :             :         }
    4280                 :             : 
    4281                 :             :       /* Preprocess the all_candidates array so that the alternative field of
    4282                 :             :          each element holds the actual function call expression and possible
    4283                 :             :          assignment, instead of just the decl for the variant function.  */
    4284                 :          60 :       for (unsigned int i = 0; i < all_candidates.length (); i++)
    4285                 :             :         {
    4286                 :          48 :           tree decl = all_candidates[i].alternative;
    4287                 :          48 :           tree thiscall;
    4288                 :             : 
    4289                 :             :           /* We need to turn the decl from the candidate into a function
    4290                 :             :              call and possible assignment, and stuff that in
    4291                 :             :              the directive seq of the gomp_variant.  */
    4292                 :          48 :           if (decl == fndecl)
    4293                 :             :             {
    4294                 :          12 :               thiscall = expr;
    4295                 :          12 :               omp_resolved_variant_calls->add (expr);
    4296                 :             :             }
    4297                 :             :           else
    4298                 :             :             {
    4299                 :          36 :               thiscall = unshare_expr (expr);
    4300                 :          36 :               CALL_EXPR_FN (thiscall) = build1 (ADDR_EXPR, fnptrtype, decl);
    4301                 :          36 :               if (omp_dispatch_p)
    4302                 :           0 :                 thiscall = modify_call_for_omp_dispatch (thiscall,
    4303                 :             :                                                          dispatch_clauses,
    4304                 :             :                                                          dispatch_loc);
    4305                 :             :             }
    4306                 :          48 :           if (pointerize)
    4307                 :           0 :             thiscall = build_fold_addr_expr_loc (loc, thiscall);
    4308                 :          48 :           if (want_value)
    4309                 :          48 :             thiscall = build2 (INIT_EXPR, type, tmp, thiscall);
    4310                 :          48 :           all_candidates[i].alternative = thiscall;
    4311                 :             :         }
    4312                 :             : 
    4313                 :          12 :       cgraph_node::get (cfun->decl)->has_omp_variant_constructs = 1;
    4314                 :          12 :       tree expansion = expand_late_variant_directive (all_candidates,
    4315                 :             :                                                       construct_context);
    4316                 :          12 :       if (result)
    4317                 :          12 :         expansion = build2 (COMPOUND_EXPR, TREE_TYPE (result),
    4318                 :             :                             expansion, result);
    4319                 :          12 :       return expansion;
    4320                 :             :     }
    4321                 :             : }
    4322                 :             : 
    4323                 :             : /* Wrapper around expand_variant_call_expr to interface with gimplifier
    4324                 :             :    state.  EXPR and OMP_DISPATCH_P are as for expand_variant_call_expr,
    4325                 :             :    FALLBACK is used to compute the WANT_VALUE and POINTERIZE arguments.  */
    4326                 :             : static tree
    4327                 :        1060 : gimplify_variant_call_expr (tree expr, fallback_t fallback,
    4328                 :             :                             bool omp_dispatch_p)
    4329                 :             : {
    4330                 :        1060 :   tree type = TREE_TYPE (expr);
    4331                 :        1060 :   bool want_value = (fallback != fb_none && !VOID_TYPE_P (type));
    4332                 :         467 :   bool pointerize = false;
    4333                 :             :   /* If the result value must be an lvalue or the result type must
    4334                 :             :      live in memory, then we have to pointerize it if we need a temporary.  */
    4335                 :         467 :   if (want_value
    4336                 :         467 :       && ((!(fallback & fb_rvalue) && (fallback & fb_lvalue))
    4337                 :         467 :           || TREE_ADDRESSABLE (type)))
    4338                 :           0 :     pointerize = true;
    4339                 :             : 
    4340                 :        1060 :   if (omp_dispatch_p)
    4341                 :         486 :     return expand_variant_call_expr (expr, want_value, pointerize,
    4342                 :             :                                      omp_dispatch_p,
    4343                 :             :                                      gimplify_omp_ctxp->clauses,
    4344                 :         486 :                                      gimplify_omp_ctxp->location);
    4345                 :             :   else
    4346                 :         574 :     return expand_variant_call_expr (expr, want_value, pointerize,
    4347                 :             :                                      omp_dispatch_p,
    4348                 :         574 :                                      NULL_TREE, UNKNOWN_LOCATION);
    4349                 :             : }
    4350                 :             : 
    4351                 :             : 
    4352                 :             : /* Gimplify the CALL_EXPR node *EXPR_P into the GIMPLE sequence PRE_P.
    4353                 :             :    WANT_VALUE is true if the result of the call is desired.  */
    4354                 :             : 
    4355                 :             : static enum gimplify_status
    4356                 :    15613227 : gimplify_call_expr (tree *expr_p, gimple_seq *pre_p, fallback_t fallback)
    4357                 :             : {
    4358                 :    15613227 :   bool want_value = (fallback != fb_none);
    4359                 :    15613227 :   tree fndecl, parms, p, fnptrtype;
    4360                 :    15613227 :   enum gimplify_status ret;
    4361                 :    15613227 :   int i, nargs;
    4362                 :    15613227 :   gcall *call;
    4363                 :    15613227 :   bool builtin_va_start_p = false, omp_dispatch_p = false;
    4364                 :    15613227 :   location_t loc = EXPR_LOCATION (*expr_p);
    4365                 :             : 
    4366                 :    15613227 :   gcc_assert (TREE_CODE (*expr_p) == CALL_EXPR);
    4367                 :             : 
    4368                 :             :   /* For reliable diagnostics during inlining, it is necessary that
    4369                 :             :      every call_expr be annotated with file and line.  */
    4370                 :    15613227 :   if (! EXPR_HAS_LOCATION (*expr_p))
    4371                 :      569765 :     SET_EXPR_LOCATION (*expr_p, input_location);
    4372                 :             : 
    4373                 :             :   /* Gimplify internal functions created in the FEs.  */
    4374                 :    15613227 :   if (CALL_EXPR_FN (*expr_p) == NULL_TREE)
    4375                 :             :     {
    4376                 :      409868 :       enum internal_fn ifn = CALL_EXPR_IFN (*expr_p);
    4377                 :      409868 :       if (ifn == IFN_GOMP_DISPATCH)
    4378                 :             :         {
    4379                 :         851 :           gcc_assert (flag_openmp
    4380                 :             :                       && gimplify_omp_ctxp
    4381                 :             :                       && gimplify_omp_ctxp->code == OMP_DISPATCH);
    4382                 :         851 :           *expr_p = CALL_EXPR_ARG (*expr_p, 0);
    4383                 :         851 :           gcc_assert (TREE_CODE (*expr_p) == CALL_EXPR);
    4384                 :         851 :           if (! EXPR_HAS_LOCATION (*expr_p))
    4385                 :          94 :             SET_EXPR_LOCATION (*expr_p, input_location);
    4386                 :             :           omp_dispatch_p = true;
    4387                 :             :         }
    4388                 :             :       else
    4389                 :             :         {
    4390                 :      409017 :           if (want_value)
    4391                 :             :             return GS_ALL_DONE;
    4392                 :             : 
    4393                 :       19128 :           nargs = call_expr_nargs (*expr_p);
    4394                 :       19128 :           auto_vec<tree> vargs (nargs);
    4395                 :             : 
    4396                 :       19128 :           if (ifn == IFN_ASSUME)
    4397                 :             :             {
    4398                 :         476 :               if (simple_condition_p (CALL_EXPR_ARG (*expr_p, 0)))
    4399                 :             :                 {
    4400                 :             :                   /* If the [[assume (cond)]]; condition is simple
    4401                 :             :                      enough and can be evaluated unconditionally
    4402                 :             :                      without side-effects, expand it as
    4403                 :             :                      if (!cond) __builtin_unreachable ();  */
    4404                 :         274 :                   tree fndecl = builtin_decl_explicit (BUILT_IN_UNREACHABLE);
    4405                 :         274 :                   *expr_p
    4406                 :         548 :                     = build3 (COND_EXPR, void_type_node,
    4407                 :         274 :                               CALL_EXPR_ARG (*expr_p, 0), void_node,
    4408                 :         274 :                               build_call_expr_loc (EXPR_LOCATION (*expr_p),
    4409                 :             :                                                    fndecl, 0));
    4410                 :         274 :                   return GS_OK;
    4411                 :             :                 }
    4412                 :             :               /* If not optimizing, ignore the assumptions.  */
    4413                 :         202 :               if (!optimize || seen_error ())
    4414                 :             :                 {
    4415                 :          94 :                   *expr_p = NULL_TREE;
    4416                 :          94 :                   return GS_ALL_DONE;
    4417                 :             :                 }
    4418                 :             :               /* Temporarily, until gimple lowering, transform
    4419                 :             :                  .ASSUME (cond);
    4420                 :             :                  into:
    4421                 :             :                  [[assume (guard)]]
    4422                 :             :                  {
    4423                 :             :                    guard = cond;
    4424                 :             :                  }
    4425                 :             :                  such that gimple lowering can outline the condition into
    4426                 :             :                  a separate function easily.  */
    4427                 :         108 :               tree guard = create_tmp_var (boolean_type_node);
    4428                 :         108 :               *expr_p = build2 (MODIFY_EXPR, void_type_node, guard,
    4429                 :         108 :                                 gimple_boolify (CALL_EXPR_ARG (*expr_p, 0)));
    4430                 :         108 :               *expr_p = build3 (BIND_EXPR, void_type_node, NULL, *expr_p, NULL);
    4431                 :         108 :               push_gimplify_context ();
    4432                 :         108 :               gimple_seq body = NULL;
    4433                 :         108 :               gimple *g = gimplify_and_return_first (*expr_p, &body);
    4434                 :         108 :               pop_gimplify_context (g);
    4435                 :         108 :               g = gimple_build_assume (guard, body);
    4436                 :         108 :               gimple_set_location (g, loc);
    4437                 :         108 :               gimplify_seq_add_stmt (pre_p, g);
    4438                 :         108 :               *expr_p = NULL_TREE;
    4439                 :         108 :               return GS_ALL_DONE;
    4440                 :             :             }
    4441                 :             : 
    4442                 :       42059 :           for (i = 0; i < nargs; i++)
    4443                 :             :             {
    4444                 :       23407 :               gimplify_arg (&CALL_EXPR_ARG (*expr_p, i), pre_p,
    4445                 :       23407 :                             EXPR_LOCATION (*expr_p));
    4446                 :       23407 :               vargs.quick_push (CALL_EXPR_ARG (*expr_p, i));
    4447                 :             :             }
    4448                 :             : 
    4449                 :       18652 :           gcall *call = gimple_build_call_internal_vec (ifn, vargs);
    4450                 :       18652 :           gimple_call_set_nothrow (call, TREE_NOTHROW (*expr_p));
    4451                 :       18652 :           gimplify_seq_add_stmt (pre_p, call);
    4452                 :       18652 :           return GS_ALL_DONE;
    4453                 :       19128 :         }
    4454                 :             :     }
    4455                 :             : 
    4456                 :             :   /* This may be a call to a builtin function.
    4457                 :             : 
    4458                 :             :      Builtin function calls may be transformed into different
    4459                 :             :      (and more efficient) builtin function calls under certain
    4460                 :             :      circumstances.  Unfortunately, gimplification can muck things
    4461                 :             :      up enough that the builtin expanders are not aware that certain
    4462                 :             :      transformations are still valid.
    4463                 :             : 
    4464                 :             :      So we attempt transformation/gimplification of the call before
    4465                 :             :      we gimplify the CALL_EXPR.  At this time we do not manage to
    4466                 :             :      transform all calls in the same manner as the expanders do, but
    4467                 :             :      we do transform most of them.  */
    4468                 :    15204210 :   fndecl = get_callee_fndecl (*expr_p);
    4469                 :    15204210 :   if (fndecl && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL))
    4470                 :     3754050 :     switch (DECL_FUNCTION_CODE (fndecl))
    4471                 :             :       {
    4472                 :       80692 :       CASE_BUILT_IN_ALLOCA:
    4473                 :             :         /* If the call has been built for a variable-sized object, then we
    4474                 :             :            want to restore the stack level when the enclosing BIND_EXPR is
    4475                 :             :            exited to reclaim the allocated space; otherwise, we precisely
    4476                 :             :            need to do the opposite and preserve the latest stack level.  */
    4477                 :       80692 :         if (CALL_ALLOCA_FOR_VAR_P (*expr_p))
    4478                 :        8829 :           gimplify_ctxp->save_stack = true;
    4479                 :             :         else
    4480                 :       71863 :           gimplify_ctxp->keep_stack = true;
    4481                 :             :         break;
    4482                 :             : 
    4483                 :       20670 :       case BUILT_IN_VA_START:
    4484                 :       20670 :         {
    4485                 :       20670 :           builtin_va_start_p = true;
    4486                 :       20670 :           if (call_expr_nargs (*expr_p) < 2)
    4487                 :             :             {
    4488                 :           1 :               error ("too few arguments to function %<va_start%>");
    4489                 :           1 :               *expr_p = build_empty_stmt (EXPR_LOCATION (*expr_p));
    4490                 :           1 :               return GS_OK;
    4491                 :             :             }
    4492                 :             : 
    4493                 :       20669 :           if (fold_builtin_next_arg (*expr_p, true))
    4494                 :             :             {
    4495                 :           8 :               *expr_p = build_empty_stmt (EXPR_LOCATION (*expr_p));
    4496                 :           8 :               return GS_OK;
    4497                 :             :             }
    4498                 :             :           break;
    4499                 :             :         }
    4500                 :             : 
    4501                 :          30 :       case BUILT_IN_EH_RETURN:
    4502                 :          30 :         cfun->calls_eh_return = true;
    4503                 :          30 :         break;
    4504                 :             : 
    4505                 :        1014 :       case BUILT_IN_CLEAR_PADDING:
    4506                 :        1014 :         if (call_expr_nargs (*expr_p) == 1)
    4507                 :             :           {
    4508                 :             :             /* Remember the original type of the argument in an internal
    4509                 :             :                dummy second argument, as in GIMPLE pointer conversions are
    4510                 :             :                useless.  Also mark this call as not for automatic
    4511                 :             :                initialization in the internal dummy third argument.  */
    4512                 :         507 :             p = CALL_EXPR_ARG (*expr_p, 0);
    4513                 :         507 :             *expr_p
    4514                 :         507 :               = build_call_expr_loc (EXPR_LOCATION (*expr_p), fndecl, 2, p,
    4515                 :         507 :                                      build_zero_cst (TREE_TYPE (p)));
    4516                 :         507 :             return GS_OK;
    4517                 :             :           }
    4518                 :             :         break;
    4519                 :             : 
    4520                 :             :       default:
    4521                 :             :         ;
    4522                 :             :       }
    4523                 :    15203694 :   if (fndecl && fndecl_built_in_p (fndecl))
    4524                 :             :     {
    4525                 :     3989340 :       tree new_tree = fold_call_expr (input_location, *expr_p, !want_value);
    4526                 :     3989340 :       if (new_tree && new_tree != *expr_p)
    4527                 :             :         {
    4528                 :             :           /* There was a transformation of this call which computes the
    4529                 :             :              same value, but in a more efficient way.  Return and try
    4530                 :             :              again.  */
    4531                 :         694 :           *expr_p = new_tree;
    4532                 :         694 :           return GS_OK;
    4533                 :             :         }
    4534                 :             :     }
    4535                 :             : 
    4536                 :             :   /* Remember the original function pointer type.  */
    4537                 :    15203000 :   fnptrtype = TREE_TYPE (CALL_EXPR_FN (*expr_p));
    4538                 :             : 
    4539                 :             :   /* Handle "declare variant" resolution and arglist processing.  */
    4540                 :    15203000 :   if (flag_openmp
    4541                 :      395021 :       && fndecl
    4542                 :      394362 :       && cfun
    4543                 :      394362 :       && (cfun->curr_properties & PROP_gimple_any) == 0
    4544                 :      199786 :       && !omp_has_novariants ()
    4545                 :    15402680 :       && lookup_attribute ("omp declare variant base",
    4546                 :      199680 :                            DECL_ATTRIBUTES (fndecl)))
    4547                 :             :     {
    4548                 :        1060 :       tree orig = *expr_p;
    4549                 :        1060 :       *expr_p = gimplify_variant_call_expr (*expr_p, fallback,
    4550                 :             :                                             omp_dispatch_p);
    4551                 :             : 
    4552                 :             :       /* This may resolve to the same call, or the call expr with just
    4553                 :             :          the function replaced, in which case we should just continue to
    4554                 :             :          gimplify it normally.  Otherwise, if we get something else back,
    4555                 :             :          stop here and re-gimplify the whole replacement expr.  */
    4556                 :        1060 :       if (*expr_p != orig)
    4557                 :             :         return GS_OK;
    4558                 :             :     }
    4559                 :             : 
    4560                 :             :   /* There is a sequence point before the call, so any side effects in
    4561                 :             :      the calling expression must occur before the actual call.  Force
    4562                 :             :      gimplify_expr to use an internal post queue.  */
    4563                 :    15202540 :   ret = gimplify_expr (&CALL_EXPR_FN (*expr_p), pre_p, NULL,
    4564                 :             :                        is_gimple_call_addr, fb_rvalue);
    4565                 :             : 
    4566                 :    15202540 :   if (ret == GS_ERROR)
    4567                 :             :     return GS_ERROR;
    4568                 :             : 
    4569                 :    15202538 :   nargs = call_expr_nargs (*expr_p);
    4570                 :             : 
    4571                 :             :   /* Get argument types for verification.  */
    4572                 :    15202538 :   fndecl = get_callee_fndecl (*expr_p);
    4573                 :    15202538 :   parms = NULL_TREE;
    4574                 :    15202538 :   if (fndecl)
    4575                 :    14985005 :     parms = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
    4576                 :             :   else
    4577                 :      217533 :     parms = TYPE_ARG_TYPES (TREE_TYPE (fnptrtype));
    4578                 :             : 
    4579                 :    30187543 :   if (fndecl && DECL_ARGUMENTS (fndecl))
    4580                 :             :     p = DECL_ARGUMENTS (fndecl);
    4581                 :     7054888 :   else if (parms)
    4582                 :             :     p = parms;
    4583                 :             :   else
    4584                 :             :     p = NULL_TREE;
    4585                 :    40353446 :   for (i = 0; i < nargs && p; i++, p = TREE_CHAIN (p))
    4586                 :             :     ;
    4587                 :             : 
    4588                 :             :   /* If the last argument is __builtin_va_arg_pack () and it is not
    4589                 :             :      passed as a named argument, decrease the number of CALL_EXPR
    4590                 :             :      arguments and set instead the CALL_EXPR_VA_ARG_PACK flag.  */
    4591                 :    15202538 :   if (!p
    4592                 :    15202538 :       && i < nargs
    4593                 :    15202538 :       && TREE_CODE (CALL_EXPR_ARG (*expr_p, nargs - 1)) == CALL_EXPR)
    4594                 :             :     {
    4595                 :        6636 :       tree last_arg = CALL_EXPR_ARG (*expr_p, nargs - 1);
    4596                 :        6636 :       tree last_arg_fndecl = get_callee_fndecl (last_arg);
    4597                 :             : 
    4598                 :        6636 :       if (last_arg_fndecl
    4599                 :        6636 :           && fndecl_built_in_p (last_arg_fndecl, BUILT_IN_VA_ARG_PACK))
    4600                 :             :         {
    4601                 :         130 :           tree call = *expr_p;
    4602                 :             : 
    4603                 :         130 :           --nargs;
    4604                 :         260 :           *expr_p = build_call_array_loc (loc, TREE_TYPE (call),
    4605                 :         130 :                                           CALL_EXPR_FN (call),
    4606                 :         130 :                                           nargs, CALL_EXPR_ARGP (call));
    4607                 :             : 
    4608                 :             :           /* Copy all CALL_EXPR flags, location and block, except
    4609                 :             :              CALL_EXPR_VA_ARG_PACK flag.  */
    4610                 :         130 :           CALL_EXPR_STATIC_CHAIN (*expr_p) = CALL_EXPR_STATIC_CHAIN (call);
    4611                 :         130 :           CALL_EXPR_TAILCALL (*expr_p) = CALL_EXPR_TAILCALL (call);
    4612                 :         130 :           CALL_EXPR_RETURN_SLOT_OPT (*expr_p)
    4613                 :         130 :             = CALL_EXPR_RETURN_SLOT_OPT (call);
    4614                 :         130 :           CALL_FROM_THUNK_P (*expr_p) = CALL_FROM_THUNK_P (call);
    4615                 :         130 :           SET_EXPR_LOCATION (*expr_p, EXPR_LOCATION (call));
    4616                 :             : 
    4617                 :             :           /* Set CALL_EXPR_VA_ARG_PACK.  */
    4618                 :         130 :           CALL_EXPR_VA_ARG_PACK (*expr_p) = 1;
    4619                 :             :         }
    4620                 :             :     }
    4621                 :             : 
    4622                 :             :   /* If the call returns twice then after building the CFG the call
    4623                 :             :      argument computations will no longer dominate the call because
    4624                 :             :      we add an abnormal incoming edge to the call.  So do not use SSA
    4625                 :             :      vars there.  */
    4626                 :    15202538 :   bool returns_twice = call_expr_flags (*expr_p) & ECF_RETURNS_TWICE;
    4627                 :             : 
    4628                 :             : 
    4629                 :             :   /* Gimplify the function arguments.  */
    4630                 :    15202538 :   if (nargs > 0)
    4631                 :             :     {
    4632                 :    13125016 :       for (i = (PUSH_ARGS_REVERSED ? nargs - 1 : 0);
    4633                 :    39622791 :            PUSH_ARGS_REVERSED ? i >= 0 : i < nargs;
    4634                 :    26497775 :            PUSH_ARGS_REVERSED ? i-- : i++)
    4635                 :             :         {
    4636                 :    26497775 :           enum gimplify_status t;
    4637                 :             : 
    4638                 :             :           /* Avoid gimplifying the second argument to va_start, which needs to
    4639                 :             :              be the plain PARM_DECL.  */
    4640                 :    26497775 :           if ((i != 1) || !builtin_va_start_p)
    4641                 :             :             {
    4642                 :    26477114 :               tree *arg_p = &CALL_EXPR_ARG (*expr_p, i);
    4643                 :             : 
    4644                 :    26477114 :               if (gimplify_omp_ctxp && gimplify_omp_ctxp->code == OMP_DISPATCH)
    4645                 :        5225 :                 gimplify_omp_ctxp->in_call_args = true;
    4646                 :    26477114 :               t = gimplify_arg (arg_p, pre_p, EXPR_LOCATION (*expr_p),
    4647                 :    26477114 :                                 !returns_twice);
    4648                 :    26477114 :               if (gimplify_omp_ctxp && gimplify_omp_ctxp->code == OMP_DISPATCH)
    4649                 :        5225 :                 gimplify_omp_ctxp->in_call_args = false;
    4650                 :             : 
    4651                 :    26477114 :               if (t == GS_ERROR)
    4652                 :    26497775 :                 ret = GS_ERROR;
    4653                 :             :             }
    4654                 :             :         }
    4655                 :             :     }
    4656                 :             : 
    4657                 :             :   /* Gimplify the static chain.  */
    4658                 :    15202538 :   if (CALL_EXPR_STATIC_CHAIN (*expr_p))
    4659                 :             :     {
    4660                 :       28852 :       if (fndecl && !DECL_STATIC_CHAIN (fndecl))
    4661                 :           3 :         CALL_EXPR_STATIC_CHAIN (*expr_p) = NULL;
    4662                 :             :       else
    4663                 :             :         {
    4664                 :       28173 :           enum gimplify_status t;
    4665                 :       28173 :           t = gimplify_arg (&CALL_EXPR_STATIC_CHAIN (*expr_p), pre_p,
    4666                 :       28173 :                             EXPR_LOCATION (*expr_p), ! returns_twice);
    4667                 :       28173 :           if (t == GS_ERROR)
    4668                 :    15202538 :             ret = GS_ERROR;
    4669                 :             :         }
    4670                 :             :     }
    4671                 :             : 
    4672                 :             :   /* Verify the function result.  */
    4673                 :    15202538 :   if (want_value && fndecl
    4674                 :    15202538 :       && VOID_TYPE_P (TREE_TYPE (TREE_TYPE (fnptrtype))))
    4675                 :             :     {
    4676                 :           0 :       error_at (loc, "using result of function returning %<void%>");
    4677                 :           0 :       ret = GS_ERROR;
    4678                 :             :     }
    4679                 :             : 
    4680                 :             :   /* Try this again in case gimplification exposed something.  */
    4681                 :    15202538 :   if (ret != GS_ERROR)
    4682                 :             :     {
    4683                 :    15202507 :       tree new_tree = fold_call_expr (input_location, *expr_p, !want_value);
    4684                 :             : 
    4685                 :    15202507 :       if (new_tree && new_tree != *expr_p)
    4686                 :             :         {
    4687                 :             :           /* There was a transformation of this call which computes the
    4688                 :             :              same value, but in a more efficient way.  Return and try
    4689                 :             :              again.  */
    4690                 :       11512 :           *expr_p = new_tree;
    4691                 :       11512 :           return GS_OK;
    4692                 :             :         }
    4693                 :             :     }
    4694                 :             :   else
    4695                 :             :     {
    4696                 :          31 :       *expr_p = error_mark_node;
    4697                 :          31 :       return GS_ERROR;
    4698                 :             :     }
    4699                 :             : 
    4700                 :             :   /* If the function is "const" or "pure", then clear TREE_SIDE_EFFECTS on its
    4701                 :             :      decl.  This allows us to eliminate redundant or useless
    4702                 :             :      calls to "const" functions.  */
    4703                 :    15190995 :   if (TREE_CODE (*expr_p) == CALL_EXPR)
    4704                 :             :     {
    4705                 :    15190995 :       int flags = call_expr_flags (*expr_p);
    4706                 :    15190995 :       if (flags & (ECF_CONST | ECF_PURE)
    4707                 :             :           /* An infinite loop is considered a side effect.  */
    4708                 :     2346431 :           && !(flags & (ECF_LOOPING_CONST_OR_PURE)))
    4709                 :     2000743 :         TREE_SIDE_EFFECTS (*expr_p) = 0;
    4710                 :             :     }
    4711                 :             : 
    4712                 :             :   /* If the value is not needed by the caller, emit a new GIMPLE_CALL
    4713                 :             :      and clear *EXPR_P.  Otherwise, leave *EXPR_P in its gimplified
    4714                 :             :      form and delegate the creation of a GIMPLE_CALL to
    4715                 :             :      gimplify_modify_expr.  This is always possible because when
    4716                 :             :      WANT_VALUE is true, the caller wants the result of this call into
    4717                 :             :      a temporary, which means that we will emit an INIT_EXPR in
    4718                 :             :      internal_get_tmp_var which will then be handled by
    4719                 :             :      gimplify_modify_expr.  */
    4720                 :    15190995 :   if (!want_value)
    4721                 :             :     {
    4722                 :             :       /* The CALL_EXPR in *EXPR_P is already in GIMPLE form, so all we
    4723                 :             :          have to do is replicate it as a GIMPLE_CALL tuple.  */
    4724                 :     5839359 :       gimple_stmt_iterator gsi;
    4725                 :     5839359 :       call = gimple_build_call_from_tree (*expr_p, fnptrtype);
    4726                 :     5839359 :       notice_special_calls (call);
    4727                 :     5839359 :       gimplify_seq_add_stmt (pre_p, call);
    4728                 :     5839359 :       gsi = gsi_last (*pre_p);
    4729                 :     5839359 :       maybe_fold_stmt (&gsi);
    4730                 :     5839359 :       *expr_p = NULL_TREE;
    4731                 :             :     }
    4732                 :             :   else
    4733                 :             :     /* Remember the original function type.  */
    4734                 :     9351636 :     CALL_EXPR_FN (*expr_p) = build1 (NOP_EXPR, fnptrtype,
    4735                 :     9351636 :                                      CALL_EXPR_FN (*expr_p));
    4736                 :             : 
    4737                 :             :   return ret;
    4738                 :             : }
    4739                 :             : 
    4740                 :             : /* Handle shortcut semantics in the predicate operand of a COND_EXPR by
    4741                 :             :    rewriting it into multiple COND_EXPRs, and possibly GOTO_EXPRs.
    4742                 :             : 
    4743                 :             :    TRUE_LABEL_P and FALSE_LABEL_P point to the labels to jump to if the
    4744                 :             :    condition is true or false, respectively.  If null, we should generate
    4745                 :             :    our own to skip over the evaluation of this specific expression.
    4746                 :             : 
    4747                 :             :    LOCUS is the source location of the COND_EXPR.
    4748                 :             : 
    4749                 :             :    The condition_uid is a discriminator tag for condition coverage used to map
    4750                 :             :    conditions to its corresponding full Boolean function.
    4751                 :             : 
    4752                 :             :    This function is the tree equivalent of do_jump.
    4753                 :             : 
    4754                 :             :    shortcut_cond_r should only be called by shortcut_cond_expr.  */
    4755                 :             : 
    4756                 :             : static tree
    4757                 :     1274938 : shortcut_cond_r (tree pred, tree *true_label_p, tree *false_label_p,
    4758                 :             :                  location_t locus, unsigned condition_uid)
    4759                 :             : {
    4760                 :     1274938 :   tree local_label = NULL_TREE;
    4761                 :     1274938 :   tree t, expr = NULL;
    4762                 :             : 
    4763                 :             :   /* OK, it's not a simple case; we need to pull apart the COND_EXPR to
    4764                 :             :      retain the shortcut semantics.  Just insert the gotos here;
    4765                 :             :      shortcut_cond_expr will append the real blocks later.  */
    4766                 :     1274938 :   if (TREE_CODE (pred) == TRUTH_ANDIF_EXPR)
    4767                 :             :     {
    4768                 :      110226 :       location_t new_locus;
    4769                 :             : 
    4770                 :             :       /* Turn if (a && b) into
    4771                 :             : 
    4772                 :             :          if (a); else goto no;
    4773                 :             :          if (b) goto yes; else goto no;
    4774                 :             :          (no:) */
    4775                 :             : 
    4776                 :      110226 :       if (false_label_p == NULL)
    4777                 :        4018 :         false_label_p = &local_label;
    4778                 :             : 
    4779                 :             :       /* Keep the original source location on the first 'if'.  */
    4780                 :      110226 :       t = shortcut_cond_r (TREE_OPERAND (pred, 0), NULL, false_label_p, locus,
    4781                 :             :                            condition_uid);
    4782                 :      110226 :       append_to_statement_list (t, &expr);
    4783                 :             : 
    4784                 :             :       /* Set the source location of the && on the second 'if'.  */
    4785                 :      110226 :       new_locus = rexpr_location (pred, locus);
    4786                 :      110226 :       t = shortcut_cond_r (TREE_OPERAND (pred, 1), true_label_p, false_label_p,
    4787                 :             :                            new_locus, condition_uid);
    4788                 :      110226 :       append_to_statement_list (t, &expr);
    4789                 :             :     }
    4790                 :     1164712 :   else if (TREE_CODE (pred) == TRUTH_ORIF_EXPR)
    4791                 :             :     {
    4792                 :      378275 :       location_t new_locus;
    4793                 :             : 
    4794                 :             :       /* Turn if (a || b) into
    4795                 :             : 
    4796                 :             :          if (a) goto yes;
    4797                 :             :          if (b) goto yes; else goto no;
    4798                 :             :          (yes:) */
    4799                 :             : 
    4800                 :      378275 :       if (true_label_p == NULL)
    4801                 :      228053 :         true_label_p = &local_label;
    4802                 :             : 
    4803                 :             :       /* Keep the original source location on the first 'if'.  */
    4804                 :      378275 :       t = shortcut_cond_r (TREE_OPERAND (pred, 0), true_label_p, NULL, locus,
    4805                 :             :                            condition_uid);
    4806                 :      378275 :       append_to_statement_list (t, &expr);
    4807                 :             : 
    4808                 :             :       /* Set the source location of the || on the second 'if'.  */
    4809                 :      378275 :       new_locus = rexpr_location (pred, locus);
    4810                 :      378275 :       t = shortcut_cond_r (TREE_OPERAND (pred, 1), true_label_p, false_label_p,
    4811                 :             :                            new_locus, condition_uid);
    4812                 :      378275 :       append_to_statement_list (t, &expr);
    4813                 :             :     }
    4814                 :      786437 :   else if (TREE_CODE (pred) == COND_EXPR
    4815                 :         764 :            && !VOID_TYPE_P (TREE_TYPE (TREE_OPERAND (pred, 1)))
    4816                 :      787201 :            && !VOID_TYPE_P (TREE_TYPE (TREE_OPERAND (pred, 2))))
    4817                 :             :     {
    4818                 :         758 :       location_t new_locus;
    4819                 :             : 
    4820                 :             :       /* As long as we're messing with gotos, turn if (a ? b : c) into
    4821                 :             :          if (a)
    4822                 :             :            if (b) goto yes; else goto no;
    4823                 :             :          else
    4824                 :             :            if (c) goto yes; else goto no;
    4825                 :             : 
    4826                 :             :          Don't do this if one of the arms has void type, which can happen
    4827                 :             :          in C++ when the arm is throw.  */
    4828                 :             : 
    4829                 :             :       /* Keep the original source location on the first 'if'.  Set the source
    4830                 :             :          location of the ? on the second 'if'.  */
    4831                 :         758 :       new_locus = rexpr_location (pred, locus);
    4832                 :        1516 :       expr = build3 (COND_EXPR, void_type_node, TREE_OPERAND (pred, 0),
    4833                 :         758 :                      shortcut_cond_r (TREE_OPERAND (pred, 1), true_label_p,
    4834                 :             :                                       false_label_p, locus, condition_uid),
    4835                 :         758 :                      shortcut_cond_r (TREE_OPERAND (pred, 2), true_label_p,
    4836                 :             :                                       false_label_p, new_locus,
    4837                 :             :                                       condition_uid));
    4838                 :         758 :       tree_associate_condition_with_expr (expr, condition_uid);
    4839                 :             :     }
    4840                 :             :   else
    4841                 :             :     {
    4842                 :      785679 :       expr = build3 (COND_EXPR, void_type_node, pred,
    4843                 :             :                      build_and_jump (true_label_p),
    4844                 :             :                      build_and_jump (false_label_p));
    4845                 :      785679 :       SET_EXPR_LOCATION (expr, locus);
    4846                 :      785679 :       tree_associate_condition_with_expr (expr, condition_uid);
    4847                 :             :     }
    4848                 :             : 
    4849                 :     1274938 :   if (local_label)
    4850                 :             :     {
    4851                 :      232071 :       t = build1 (LABEL_EXPR, void_type_node, local_label);
    4852                 :      232071 :       append_to_statement_list (t, &expr);
    4853                 :             :     }
    4854                 :             : 
    4855                 :     1274938 :   return expr;
    4856                 :             : }
    4857                 :             : 
    4858                 :             : /* If EXPR is a GOTO_EXPR, return it.  If it is a STATEMENT_LIST, skip
    4859                 :             :    any of its leading DEBUG_BEGIN_STMTS and recurse on the subsequent
    4860                 :             :    statement, if it is the last one.  Otherwise, return NULL.  */
    4861                 :             : 
    4862                 :             : static tree
    4863                 :    10941846 : find_goto (tree expr)
    4864                 :             : {
    4865                 :    11248753 :   if (!expr)
    4866                 :             :     return NULL_TREE;
    4867                 :             : 
    4868                 :     9353970 :   if (TREE_CODE (expr) == GOTO_EXPR)
    4869                 :             :     return expr;
    4870                 :             : 
    4871                 :     7454897 :   if (TREE_CODE (expr) != STATEMENT_LIST)
    4872                 :             :     return NULL_TREE;
    4873                 :             : 
    4874                 :     1026523 :   tree_stmt_iterator i = tsi_start (expr);
    4875                 :             : 
    4876                 :     1413092 :   while (!tsi_end_p (i) && TREE_CODE (tsi_stmt (i)) == DEBUG_BEGIN_STMT)
    4877                 :      386569 :     tsi_next (&i);
    4878                 :             : 
    4879                 :     9972296 :   if (!tsi_one_before_end_p (i))
    4880                 :             :     return NULL_TREE;
    4881                 :             : 
    4882                 :      306907 :   return find_goto (tsi_stmt (i));
    4883                 :             : }
    4884                 :             : 
    4885                 :             : /* Same as find_goto, except that it returns NULL if the destination
    4886                 :             :    is not a LABEL_DECL.  */
    4887                 :             : 
    4888                 :             : static inline tree
    4889                 :    10941846 : find_goto_label (tree expr)
    4890                 :             : {
    4891                 :    10941846 :   tree dest = find_goto (expr);
    4892                 :    12840919 :   if (dest && TREE_CODE (GOTO_DESTINATION (dest)) == LABEL_DECL)
    4893                 :     1898964 :     return dest;
    4894                 :             :   return NULL_TREE;
    4895                 :             : }
    4896                 :             : 
    4897                 :             : 
    4898                 :             : /* Given a multi-term condition (ANDIF, ORIF), walk the predicate PRED and tag
    4899                 :             :    every basic condition with CONDITION_UID.  Two basic conditions share the
    4900                 :             :    CONDITION_UID discriminator when they belong to the same predicate, which is
    4901                 :             :    used by the condition coverage.  Doing this as an explicit step makes for a
    4902                 :             :    simpler implementation than weaving it into the splitting code as the
    4903                 :             :    splitting code eventually calls the entry point gimplfiy_expr which makes
    4904                 :             :    bookkeeping complicated.  */
    4905                 :             : static void
    4906                 :      544132 : tag_shortcut_cond (tree pred, unsigned condition_uid)
    4907                 :             : {
    4908                 :      579820 :   if (TREE_CODE (pred) == TRUTH_ANDIF_EXPR
    4909                 :      579820 :       || TREE_CODE (pred) == TRUTH_ORIF_EXPR)
    4910                 :             :     {
    4911                 :      536108 :       tree fst = TREE_OPERAND (pred, 0);
    4912                 :      536108 :       tree lst = TREE_OPERAND (pred, 1);
    4913                 :             : 
    4914                 :      536108 :       if (TREE_CODE (fst) == TRUTH_ANDIF_EXPR
    4915                 :      536108 :           || TREE_CODE (fst) == TRUTH_ORIF_EXPR)
    4916                 :      163842 :         tag_shortcut_cond (fst, condition_uid);
    4917                 :      372266 :       else if (TREE_CODE (fst) == COND_EXPR)
    4918                 :         216 :         tree_associate_condition_with_expr (fst, condition_uid);
    4919                 :             : 
    4920                 :      536108 :       if (TREE_CODE (lst) == TRUTH_ANDIF_EXPR
    4921                 :      536108 :           || TREE_CODE (lst) == TRUTH_ORIF_EXPR)
    4922                 :             :         tag_shortcut_cond (lst, condition_uid);
    4923                 :      500420 :       else if (TREE_CODE (lst) == COND_EXPR)
    4924                 :         424 :         tree_associate_condition_with_expr (lst, condition_uid);
    4925                 :             :     }
    4926                 :      544132 : }
    4927                 :             : 
    4928                 :             : /* Given a conditional expression EXPR with short-circuit boolean
    4929                 :             :    predicates using TRUTH_ANDIF_EXPR or TRUTH_ORIF_EXPR, break the
    4930                 :             :    predicate apart into the equivalent sequence of conditionals.  CONDITION_UID
    4931                 :             :    is a the tag/discriminator for this EXPR - all basic conditions in the
    4932                 :             :    expression will be given the same CONDITION_UID.  */
    4933                 :             : static tree
    4934                 :      380290 : shortcut_cond_expr (tree expr, unsigned condition_uid)
    4935                 :             : {
    4936                 :      380290 :   tree pred = TREE_OPERAND (expr, 0);
    4937                 :      380290 :   tree then_ = TREE_OPERAND (expr, 1);
    4938                 :      380290 :   tree else_ = TREE_OPERAND (expr, 2);
    4939                 :      380290 :   tree true_label, false_label, end_label, t;
    4940                 :      380290 :   tree *true_label_p;
    4941                 :      380290 :   tree *false_label_p;
    4942                 :      380290 :   bool emit_end, emit_false, jump_over_else;
    4943                 :      380290 :   bool then_se = then_ && TREE_SIDE_EFFECTS (then_);
    4944                 :      380290 :   bool else_se = else_ && TREE_SIDE_EFFECTS (else_);
    4945                 :             : 
    4946                 :      380290 :   tag_shortcut_cond (pred, condition_uid);
    4947                 :             : 
    4948                 :             :   /* First do simple transformations.  */
    4949                 :      380290 :   if (!else_se)
    4950                 :             :     {
    4951                 :             :       /* If there is no 'else', turn
    4952                 :             :            if (a && b) then c
    4953                 :             :          into
    4954                 :             :            if (a) if (b) then c.  */
    4955                 :      275826 :       while (TREE_CODE (pred) == TRUTH_ANDIF_EXPR)
    4956                 :             :         {
    4957                 :             :           /* Keep the original source location on the first 'if'.  */
    4958                 :       44628 :           location_t locus = EXPR_LOC_OR_LOC (expr, input_location);
    4959                 :       44628 :           TREE_OPERAND (expr, 0) = TREE_OPERAND (pred, 1);
    4960                 :             :           /* Set the source location of the && on the second 'if'.  */
    4961                 :       44628 :           if (rexpr_has_location (pred))
    4962                 :       43620 :             SET_EXPR_LOCATION (expr, rexpr_location (pred));
    4963                 :       44628 :           then_ = shortcut_cond_expr (expr, condition_uid);
    4964                 :       44628 :           then_se = then_ && TREE_SIDE_EFFECTS (then_);
    4965                 :       44628 :           pred = TREE_OPERAND (pred, 0);
    4966                 :       44628 :           expr = build3 (COND_EXPR, void_type_node, pred, then_, NULL_TREE);
    4967                 :       44628 :           SET_EXPR_LOCATION (expr, locus);
    4968                 :             :         }
    4969                 :             :     }
    4970                 :             : 
    4971                 :      380290 :   if (!then_se)
    4972                 :             :     {
    4973                 :             :       /* If there is no 'then', turn
    4974                 :             :            if (a || b); else d
    4975                 :             :          into
    4976                 :             :            if (a); else if (b); else d.  */
    4977                 :       18543 :       while (TREE_CODE (pred) == TRUTH_ORIF_EXPR)
    4978                 :             :         {
    4979                 :             :           /* Keep the original source location on the first 'if'.  */
    4980                 :         679 :           location_t locus = EXPR_LOC_OR_LOC (expr, input_location);
    4981                 :         679 :           TREE_OPERAND (expr, 0) = TREE_OPERAND (pred, 1);
    4982                 :             :           /* Set the source location of the || on the second 'if'.  */
    4983                 :         679 :           if (rexpr_has_location (pred))
    4984                 :         678 :             SET_EXPR_LOCATION (expr, rexpr_location (pred));
    4985                 :         679 :           else_ = shortcut_cond_expr (expr, condition_uid);
    4986                 :         679 :           else_se = else_ && TREE_SIDE_EFFECTS (else_);
    4987                 :         679 :           pred = TREE_OPERAND (pred, 0);
    4988                 :         679 :           expr = build3 (COND_EXPR, void_type_node, pred, NULL_TREE, else_);
    4989                 :         679 :           SET_EXPR_LOCATION (expr, locus);
    4990                 :             :         }
    4991                 :             :     }
    4992                 :             : 
    4993                 :             :   /* The expr tree should also have the expression id set.  */
    4994                 :      380290 :   tree_associate_condition_with_expr (expr, condition_uid);
    4995                 :             : 
    4996                 :             :   /* If we're done, great.  */
    4997                 :      380290 :   if (TREE_CODE (pred) != TRUTH_ANDIF_EXPR
    4998                 :      380290 :       && TREE_CODE (pred) != TRUTH_ORIF_EXPR)
    4999                 :       83870 :     return expr;
    5000                 :             : 
    5001                 :             :   /* Otherwise we need to mess with gotos.  Change
    5002                 :             :        if (a) c; else d;
    5003                 :             :      to
    5004                 :             :        if (a); else goto no;
    5005                 :             :        c; goto end;
    5006                 :             :        no: d; end:
    5007                 :             :      and recursively gimplify the condition.  */
    5008                 :             : 
    5009                 :      296420 :   true_label = false_label = end_label = NULL_TREE;
    5010                 :             : 
    5011                 :             :   /* If our arms just jump somewhere, hijack those labels so we don't
    5012                 :             :      generate jumps to jumps.  */
    5013                 :             : 
    5014                 :      296420 :   if (tree then_goto = find_goto_label (then_))
    5015                 :             :     {
    5016                 :        4410 :       true_label = GOTO_DESTINATION (then_goto);
    5017                 :        4410 :       then_ = NULL;
    5018                 :        4410 :       then_se = false;
    5019                 :             :     }
    5020                 :             : 
    5021                 :      296420 :   if (tree else_goto = find_goto_label (else_))
    5022                 :             :     {
    5023                 :        4023 :       false_label = GOTO_DESTINATION (else_goto);
    5024                 :        4023 :       else_ = NULL;
    5025                 :        4023 :       else_se = false;
    5026                 :             :     }
    5027                 :             : 
    5028                 :             :   /* If we aren't hijacking a label for the 'then' branch, it falls through.  */
    5029                 :      296420 :   if (true_label)
    5030                 :             :     true_label_p = &true_label;
    5031                 :             :   else
    5032                 :      292010 :     true_label_p = NULL;
    5033                 :             : 
    5034                 :             :   /* The 'else' branch also needs a label if it contains interesting code.  */
    5035                 :      296420 :   if (false_label || else_se)
    5036                 :             :     false_label_p = &false_label;
    5037                 :             :   else
    5038                 :             :     false_label_p = NULL;
    5039                 :             : 
    5040                 :             :   /* If there was nothing else in our arms, just forward the label(s).  */
    5041                 :      152126 :   if (!then_se && !else_se)
    5042                 :        8132 :     return shortcut_cond_r (pred, true_label_p, false_label_p,
    5043                 :       12198 :                             EXPR_LOC_OR_LOC (expr, input_location), condition_uid);
    5044                 :             : 
    5045                 :             :   /* If our last subexpression already has a terminal label, reuse it.  */
    5046                 :      292354 :   if (else_se)
    5047                 :      144294 :     t = expr_last (else_);
    5048                 :      148060 :   else if (then_se)
    5049                 :      148060 :     t = expr_last (then_);
    5050                 :             :   else
    5051                 :             :     t = NULL;
    5052                 :      292354 :   if (t && TREE_CODE (t) == LABEL_EXPR)
    5053                 :         922 :     end_label = LABEL_EXPR_LABEL (t);
    5054                 :             : 
    5055                 :             :   /* If we don't care about jumping to the 'else' branch, jump to the end
    5056                 :             :      if the condition is false.  */
    5057                 :      292354 :   if (!false_label_p)
    5058                 :      147817 :     false_label_p = &end_label;
    5059                 :             : 
    5060                 :             :   /* We only want to emit these labels if we aren't hijacking them.  */
    5061                 :      292354 :   emit_end = (end_label == NULL_TREE);
    5062                 :      292354 :   emit_false = (false_label == NULL_TREE);
    5063                 :             : 
    5064                 :             :   /* We only emit the jump over the else clause if we have to--if the
    5065                 :             :      then clause may fall through.  Otherwise we can wind up with a
    5066                 :             :      useless jump and a useless label at the end of gimplified code,
    5067                 :             :      which will cause us to think that this conditional as a whole
    5068                 :             :      falls through even if it doesn't.  If we then inline a function
    5069                 :             :      which ends with such a condition, that can cause us to issue an
    5070                 :             :      inappropriate warning about control reaching the end of a
    5071                 :             :      non-void function.  */
    5072                 :      292354 :   jump_over_else = block_may_fallthru (then_);
    5073                 :             : 
    5074                 :      584077 :   pred = shortcut_cond_r (pred, true_label_p, false_label_p,
    5075                 :      584077 :                           EXPR_LOC_OR_LOC (expr, input_location),
    5076                 :             :                           condition_uid);
    5077                 :             : 
    5078                 :      292354 :   expr = NULL;
    5079                 :      292354 :   append_to_statement_list (pred, &expr);
    5080                 :             : 
    5081                 :      292354 :   append_to_statement_list (then_, &expr);
    5082                 :      292354 :   if (else_se)
    5083                 :             :     {
    5084                 :      144294 :       if (jump_over_else)
    5085                 :             :         {
    5086                 :      141925 :           tree last = expr_last (expr);
    5087                 :      141925 :           t = build_and_jump (&end_label);
    5088                 :      141925 :           if (rexpr_has_location (last))
    5089                 :       29389 :             SET_EXPR_LOCATION (t, rexpr_location (last));
    5090                 :      141925 :           append_to_statement_list (t, &expr);
    5091                 :             :         }
    5092                 :      144294 :       if (emit_false)
    5093                 :             :         {
    5094                 :      144294 :           t = build1 (LABEL_EXPR, void_type_node, false_label);
    5095                 :      144294 :           append_to_statement_list (t, &expr);
    5096                 :             :         }
    5097                 :      144294 :       append_to_statement_list (else_, &expr);
    5098                 :             :     }
    5099                 :      292354 :   if (emit_end && end_label)
    5100                 :             :     {
    5101                 :      288825 :       t = build1 (LABEL_EXPR, void_type_node, end_label);
    5102                 :      288825 :       append_to_statement_list (t, &expr);
    5103                 :             :     }
    5104                 :             : 
    5105                 :      292354 :   return expr;
    5106                 :             : }
    5107                 :             : 
    5108                 :             : /* EXPR is used in a boolean context; make sure it has BOOLEAN_TYPE.  */
    5109                 :             : 
    5110                 :             : tree
    5111                 :    15729547 : gimple_boolify (tree expr)
    5112                 :             : {
    5113                 :    15729547 :   tree type = TREE_TYPE (expr);
    5114                 :    15729547 :   location_t loc = EXPR_LOCATION (expr);
    5115                 :             : 
    5116                 :    15729547 :   if (TREE_CODE (expr) == NE_EXPR
    5117                 :     5508591 :       && TREE_CODE (TREE_OPERAND (expr, 0)) == CALL_EXPR
    5118                 :    16649861 :       && integer_zerop (TREE_OPERAND (expr, 1)))
    5119                 :             :     {
    5120                 :      465432 :       tree call = TREE_OPERAND (expr, 0);
    5121                 :      465432 :       tree fn = get_callee_fndecl (call);
    5122                 :             : 
    5123                 :             :       /* For __builtin_expect ((long) (x), y) recurse into x as well
    5124                 :             :          if x is truth_value_p.  */
    5125                 :      465432 :       if (fn
    5126                 :      464859 :           && fndecl_built_in_p (fn, BUILT_IN_EXPECT)
    5127                 :      587250 :           && call_expr_nargs (call) == 2)
    5128                 :             :         {
    5129                 :      121818 :           tree arg = CALL_EXPR_ARG (call, 0);
    5130                 :      121818 :           if (arg)
    5131                 :             :             {
    5132                 :      121818 :               if (TREE_CODE (arg) == NOP_EXPR
    5133                 :      121818 :                   && TREE_TYPE (arg) == TREE_TYPE (call))
    5134                 :       58810 :                 arg = TREE_OPERAND (arg, 0);
    5135                 :      121818 :               if (truth_value_p (TREE_CODE (arg)))
    5136                 :             :                 {
    5137                 :       99899 :                   arg = gimple_boolify (arg);
    5138                 :       99899 :                   CALL_EXPR_ARG (call, 0)
    5139                 :      199798 :                     = fold_convert_loc (loc, TREE_TYPE (call), arg);
    5140                 :             :                 }
    5141                 :             :             }
    5142                 :             :         }
    5143                 :             :     }
    5144                 :             : 
    5145                 :    15729547 :   switch (TREE_CODE (expr))
    5146                 :             :     {
    5147                 :     1185330 :     case TRUTH_AND_EXPR:
    5148                 :     1185330 :     case TRUTH_OR_EXPR:
    5149                 :     1185330 :     case TRUTH_XOR_EXPR:
    5150                 :     1185330 :     case TRUTH_ANDIF_EXPR:
    5151                 :     1185330 :     case TRUTH_ORIF_EXPR:
    5152                 :             :       /* Also boolify the arguments of truth exprs.  */
    5153                 :     1185330 :       TREE_OPERAND (expr, 1) = gimple_boolify (TREE_OPERAND (expr, 1));
    5154                 :             :       /* FALLTHRU */
    5155                 :             : 
    5156                 :     1595878 :     case TRUTH_NOT_EXPR:
    5157                 :     1595878 :       TREE_OPERAND (expr, 0) = gimple_boolify (TREE_OPERAND (expr, 0));
    5158                 :             : 
    5159                 :             :       /* These expressions always produce boolean results.  */
    5160                 :     1595878 :       if (TREE_CODE (type) != BOOLEAN_TYPE)
    5161                 :      302186 :         TREE_TYPE (expr) = boolean_type_node;
    5162                 :             :       return expr;
    5163                 :             : 
    5164                 :        4688 :     case ANNOTATE_EXPR:
    5165                 :        4688 :       switch ((enum annot_expr_kind) TREE_INT_CST_LOW (TREE_OPERAND (expr, 1)))
    5166                 :             :         {
    5167                 :        4688 :         case annot_expr_ivdep_kind:
    5168                 :        4688 :         case annot_expr_unroll_kind:
    5169                 :        4688 :         case annot_expr_no_vector_kind:
    5170                 :        4688 :         case annot_expr_vector_kind:
    5171                 :        4688 :         case annot_expr_parallel_kind:
    5172                 :        4688 :         case annot_expr_maybe_infinite_kind:
    5173                 :        4688 :           TREE_OPERAND (expr, 0) = gimple_boolify (TREE_OPERAND (expr, 0));
    5174                 :        4688 :           if (TREE_CODE (type) != BOOLEAN_TYPE)
    5175                 :        2872 :             TREE_TYPE (expr) = boolean_type_node;
    5176                 :             :           return expr;
    5177                 :           0 :         default:
    5178                 :           0 :           gcc_unreachable ();
    5179                 :             :         }
    5180                 :             : 
    5181                 :    14128981 :     default:
    5182                 :    14128981 :       if (COMPARISON_CLASS_P (expr))
    5183                 :             :         {
    5184                 :             :           /* These expressions always produce boolean results.  */
    5185                 :    12400455 :           if (TREE_CODE (type) != BOOLEAN_TYPE)
    5186                 :     1545035 :             TREE_TYPE (expr) = boolean_type_node;
    5187                 :    12400455 :           return expr;
    5188                 :             :         }
    5189                 :             :       /* Other expressions that get here must have boolean values, but
    5190                 :             :          might need to be converted to the appropriate mode.  */
    5191                 :     1728526 :       if (TREE_CODE (type) == BOOLEAN_TYPE)
    5192                 :             :         return expr;
    5193                 :      190302 :       return fold_convert_loc (loc, boolean_type_node, expr);
    5194                 :             :     }
    5195                 :             : }
    5196                 :             : 
    5197                 :             : /* Given a conditional expression *EXPR_P without side effects, gimplify
    5198                 :             :    its operands.  New statements are inserted to PRE_P.  */
    5199                 :             : 
    5200                 :             : static enum gimplify_status
    5201                 :       45394 : gimplify_pure_cond_expr (tree *expr_p, gimple_seq *pre_p)
    5202                 :             : {
    5203                 :       45394 :   tree expr = *expr_p, cond;
    5204                 :       45394 :   enum gimplify_status ret, tret;
    5205                 :       45394 :   enum tree_code code;
    5206                 :             : 
    5207                 :       45394 :   cond = gimple_boolify (COND_EXPR_COND (expr));
    5208                 :             : 
    5209                 :             :   /* We need to handle && and || specially, as their gimplification
    5210                 :             :      creates pure cond_expr, thus leading to an infinite cycle otherwise.  */
    5211                 :       45394 :   code = TREE_CODE (cond);
    5212                 :       45394 :   if (code == TRUTH_ANDIF_EXPR)
    5213                 :          32 :     TREE_SET_CODE (cond, TRUTH_AND_EXPR);
    5214                 :       45362 :   else if (code == TRUTH_ORIF_EXPR)
    5215                 :        4574 :     TREE_SET_CODE (cond, TRUTH_OR_EXPR);
    5216                 :       45394 :   ret = gimplify_expr (&cond, pre_p, NULL, is_gimple_val, fb_rvalue);
    5217                 :       45394 :   COND_EXPR_COND (*expr_p) = cond;
    5218                 :             : 
    5219                 :       45394 :   tret = gimplify_expr (&COND_EXPR_THEN (expr), pre_p, NULL,
    5220                 :             :                         is_gimple_val, fb_rvalue);
    5221                 :       45394 :   ret = MIN (ret, tret);
    5222                 :       45394 :   tret = gimplify_expr (&COND_EXPR_ELSE (expr), pre_p, NULL,
    5223                 :             :                         is_gimple_val, fb_rvalue);
    5224                 :             : 
    5225                 :       45394 :   return MIN (ret, tret);
    5226                 :             : }
    5227                 :             : 
    5228                 :             : /* Return true if evaluating EXPR could trap.
    5229                 :             :    EXPR is GENERIC, while tree_could_trap_p can be called
    5230                 :             :    only on GIMPLE.  */
    5231                 :             : 
    5232                 :             : bool
    5233                 :    12301214 : generic_expr_could_trap_p (tree expr)
    5234                 :             : {
    5235                 :    12301214 :   unsigned i, n;
    5236                 :             : 
    5237                 :    12301214 :   if (!expr || is_gimple_val (expr))
    5238                 :     5049473 :     return false;
    5239                 :             : 
    5240                 :     7251741 :   if (!EXPR_P (expr) || tree_could_trap_p (expr))
    5241                 :     2261225 :     return true;
    5242                 :             : 
    5243                 :     4990516 :   n = TREE_OPERAND_LENGTH (expr);
    5244                 :    11236569 :   for (i = 0; i < n; i++)
    5245                 :     8364897 :     if (generic_expr_could_trap_p (TREE_OPERAND (expr, i)))
    5246                 :             :       return true;
    5247                 :             : 
    5248                 :             :   return false;
    5249                 :             : }
    5250                 :             : 
    5251                 :             : /* Associate the condition STMT with the discriminator UID.  STMTs that are
    5252                 :             :    broken down with ANDIF/ORIF from the same Boolean expression should be given
    5253                 :             :    the same UID; 'if (a && b && c) { if (d || e) ... } ...' should yield the
    5254                 :             :    { a: 1, b: 1, c: 1, d: 2, e: 2 } when gimplification is done.  This is used
    5255                 :             :    for condition coverage.  */
    5256                 :             : static void
    5257                 :     5174503 : gimple_associate_condition_with_expr (struct function *fn, gcond *stmt,
    5258                 :             :                                       unsigned uid)
    5259                 :             : {
    5260                 :     5174503 :   if (!condition_coverage_flag)
    5261                 :             :     return;
    5262                 :             : 
    5263                 :         636 :   if (!fn->cond_uids)
    5264                 :         135 :     fn->cond_uids = new hash_map <gcond*, unsigned> ();
    5265                 :             : 
    5266                 :         636 :   fn->cond_uids->put (stmt, uid);
    5267                 :             : }
    5268                 :             : 
    5269                 :             : /*  Convert the conditional expression pointed to by EXPR_P '(p) ? a : b;'
    5270                 :             :     into
    5271                 :             : 
    5272                 :             :     if (p)                      if (p)
    5273                 :             :       t1 = a;                     a;
    5274                 :             :     else                or      else
    5275                 :             :       t1 = b;                     b;
    5276                 :             :     t1;
    5277                 :             : 
    5278                 :             :     The second form is used when *EXPR_P is of type void.
    5279                 :             : 
    5280                 :             :     PRE_P points to the list where side effects that must happen before
    5281                 :             :       *EXPR_P should be stored.  */
    5282                 :             : 
    5283                 :             : static enum gimplify_status
    5284                 :     5910709 : gimplify_cond_expr (tree *expr_p, gimple_seq *pre_p, fallback_t fallback)
    5285                 :             : {
    5286                 :     5910709 :   tree expr = *expr_p;
    5287                 :     5910709 :   tree type = TREE_TYPE (expr);
    5288                 :     5910709 :   location_t loc = EXPR_LOCATION (expr);
    5289                 :     5910709 :   tree tmp, arm1, arm2;
    5290                 :     5910709 :   enum gimplify_status ret;
    5291                 :     5910709 :   tree label_true, label_false, label_cont;
    5292                 :     5910709 :   bool have_then_clause_p, have_else_clause_p;
    5293                 :     5910709 :   gcond *cond_stmt;
    5294                 :     5910709 :   enum tree_code pred_code;
    5295                 :     5910709 :   gimple_seq seq = NULL;
    5296                 :             : 
    5297                 :             :   /* If this COND_EXPR has a value, copy the values into a temporary within
    5298                 :             :      the arms.  */
    5299                 :     5910709 :   if (!VOID_TYPE_P (type))
    5300                 :             :     {
    5301                 :      400463 :       tree then_ = TREE_OPERAND (expr, 1), else_ = TREE_OPERAND (expr, 2);
    5302                 :      400463 :       tree result;
    5303                 :             : 
    5304                 :             :       /* If either an rvalue is ok or we do not require an lvalue, create the
    5305                 :             :          temporary.  But we cannot do that if the type is addressable.  */
    5306                 :      400463 :       if (((fallback & fb_rvalue) || !(fallback & fb_lvalue))
    5307                 :      400456 :           && !TREE_ADDRESSABLE (type))
    5308                 :             :         {
    5309                 :      400456 :           if (gimplify_ctxp->allow_rhs_cond_expr
    5310                 :             :               /* If either branch has side effects or could trap, it can't be
    5311                 :             :                  evaluated unconditionally.  */
    5312                 :       45394 :               && !TREE_SIDE_EFFECTS (then_)
    5313                 :       45394 :               && !generic_expr_could_trap_p (then_)
    5314                 :       45394 :               && !TREE_SIDE_EFFECTS (else_)
    5315                 :      445850 :               && !generic_expr_could_trap_p (else_))
    5316                 :       45394 :             return gimplify_pure_cond_expr (expr_p, pre_p);
    5317                 :             : 
    5318                 :      355062 :           tmp = create_tmp_var (type, "iftmp");
    5319                 :      355062 :           result = tmp;
    5320                 :             :         }
    5321                 :             : 
    5322                 :             :       /* Otherwise, only create and copy references to the values.  */
    5323                 :             :       else
    5324                 :             :         {
    5325                 :           7 :           type = build_pointer_type (type);
    5326                 :             : 
    5327                 :           7 :           if (!VOID_TYPE_P (TREE_TYPE (then_)))
    5328                 :           7 :             then_ = build_fold_addr_expr_loc (loc, then_);
    5329                 :             : 
    5330                 :           7 :           if (!VOID_TYPE_P (TREE_TYPE (else_)))
    5331                 :           7 :             else_ = build_fold_addr_expr_loc (loc, else_);
    5332                 :             : 
    5333                 :           7 :           expr
    5334                 :           7 :             = build3 (COND_EXPR, type, TREE_OPERAND (expr, 0), then_, else_);
    5335                 :             : 
    5336                 :           7 :           tmp = create_tmp_var (type, "iftmp");
    5337                 :           7 :           result = build_simple_mem_ref_loc (loc, tmp);
    5338                 :             :         }
    5339                 :             : 
    5340                 :             :       /* Build the new then clause, `tmp = then_;'.  But don't build the
    5341                 :             :          assignment if the value is void; in C++ it can be if it's a throw.  */
    5342                 :      355069 :       if (!VOID_TYPE_P (TREE_TYPE (then_)))
    5343                 :      276305 :         TREE_OPERAND (expr, 1) = build2 (INIT_EXPR, type, tmp, then_);
    5344                 :             : 
    5345                 :             :       /* Similarly, build the new else clause, `tmp = else_;'.  */
    5346                 :      355069 :       if (!VOID_TYPE_P (TREE_TYPE (else_)))
    5347                 :      347892 :         TREE_OPERAND (expr, 2) = build2 (INIT_EXPR, type, tmp, else_);
    5348                 :             : 
    5349                 :      355069 :       TREE_TYPE (expr) = void_type_node;
    5350                 :      355069 :       recalculate_side_effects (expr);
    5351                 :             : 
    5352                 :             :       /* Move the COND_EXPR to the prequeue.  */
    5353                 :      355069 :       gimplify_stmt (&expr, pre_p);
    5354                 :             : 
    5355                 :      355069 :       *expr_p = result;
    5356                 :      355069 :       return GS_ALL_DONE;
    5357                 :             :     }
    5358                 :             : 
    5359                 :             :   /* Remove any COMPOUND_EXPR so the following cases will be caught.  */
    5360                 :     5525174 :   STRIP_TYPE_NOPS (TREE_OPERAND (expr, 0));
    5361                 :     5510246 :   if (TREE_CODE (TREE_OPERAND (expr, 0)) == COMPOUND_EXPR)
    5362                 :       79809 :     gimplify_compound_expr (&TREE_OPERAND (expr, 0), pre_p, true);
    5363                 :             : 
    5364                 :             :   /* Make sure the condition has BOOLEAN_TYPE.  */
    5365                 :     5510246 :   TREE_OPERAND (expr, 0) = gimple_boolify (TREE_OPERAND (expr, 0));
    5366                 :             : 
    5367                 :             :   /* Break apart && and || conditions.  */
    5368                 :     5510246 :   if (TREE_CODE (TREE_OPERAND (expr, 0)) == TRUTH_ANDIF_EXPR
    5369                 :     5510246 :       || TREE_CODE (TREE_OPERAND (expr, 0)) == TRUTH_ORIF_EXPR)
    5370                 :             :     {
    5371                 :      334983 :       expr = shortcut_cond_expr (expr, next_cond_uid ());
    5372                 :             : 
    5373                 :      334983 :       if (expr != *expr_p)
    5374                 :             :         {
    5375                 :      334983 :           *expr_p = expr;
    5376                 :             : 
    5377                 :             :           /* We can't rely on gimplify_expr to re-gimplify the expanded
    5378                 :             :              form properly, as cleanups might cause the target labels to be
    5379                 :             :              wrapped in a TRY_FINALLY_EXPR.  To prevent that, we need to
    5380                 :             :              set up a conditional context.  */
    5381                 :      334983 :           gimple_push_condition ();
    5382                 :      334983 :           gimplify_stmt (expr_p, &seq);
    5383                 :      334983 :           gimple_pop_condition (pre_p);
    5384                 :      334983 :           gimple_seq_add_seq (pre_p, seq);
    5385                 :             : 
    5386                 :      334983 :           return GS_ALL_DONE;
    5387                 :             :         }
    5388                 :             :     }
    5389                 :             : 
    5390                 :             :   /* Now do the normal gimplification.  */
    5391                 :             : 
    5392                 :             :   /* Gimplify condition.  */
    5393                 :     5175263 :   ret = gimplify_expr (&TREE_OPERAND (expr, 0), pre_p, NULL,
    5394                 :             :                        is_gimple_condexpr_for_cond, fb_rvalue);
    5395                 :     5175263 :   if (ret == GS_ERROR)
    5396                 :             :     return GS_ERROR;
    5397                 :     5174503 :   gcc_assert (TREE_OPERAND (expr, 0) != NULL_TREE);
    5398                 :             : 
    5399                 :     5174503 :   gimple_push_condition ();
    5400                 :             : 
    5401                 :     5174503 :   have_then_clause_p = have_else_clause_p = false;
    5402                 :     5174503 :   label_true = find_goto_label (TREE_OPERAND (expr, 1));
    5403                 :     5174503 :   if (label_true
    5404                 :     1218115 :       && DECL_CONTEXT (GOTO_DESTINATION (label_true)) == current_function_decl
    5405                 :             :       /* For -O0 avoid this optimization if the COND_EXPR and GOTO_EXPR
    5406                 :             :          have different locations, otherwise we end up with incorrect
    5407                 :             :          location information on the branches.  */
    5408                 :     6392618 :       && (optimize
    5409                 :      227087 :           || !EXPR_HAS_LOCATION (expr)
    5410                 :      200426 :           || !rexpr_has_location (label_true)
    5411                 :       71730 :           || EXPR_LOCATION (expr) == rexpr_location (label_true)))
    5412                 :             :     {
    5413                 :     1217238 :       have_then_clause_p = true;
    5414                 :     1217238 :       label_true = GOTO_DESTINATION (label_true);
    5415                 :             :     }
    5416                 :             :   else
    5417                 :     3957265 :     label_true = create_artificial_label (UNKNOWN_LOCATION);
    5418                 :     5174503 :   label_false = find_goto_label (TREE_OPERAND (expr, 2));
    5419                 :     5174503 :   if (label_false
    5420                 :      672416 :       && DECL_CONTEXT (GOTO_DESTINATION (label_false)) == current_function_decl
    5421                 :             :       /* For -O0 avoid this optimization if the COND_EXPR and GOTO_EXPR
    5422                 :             :          have different locations, otherwise we end up with incorrect
    5423                 :             :          location information on the branches.  */
    5424                 :     5846919 :       && (optimize
    5425                 :       98716 :           || !EXPR_HAS_LOCATION (expr)
    5426                 :       97867 :           || !rexpr_has_location (label_false)
    5427                 :         156 :           || EXPR_LOCATION (expr) == rexpr_location (label_false)))
    5428                 :             :     {
    5429                 :      672272 :       have_else_clause_p = true;
    5430                 :      672272 :       label_false = GOTO_DESTINATION (label_false);
    5431                 :             :     }
    5432                 :             :   else
    5433                 :     4502231 :     label_false = create_artificial_label (UNKNOWN_LOCATION);
    5434                 :             : 
    5435                 :     5174503 :   unsigned cond_uid = 0;
    5436                 :     5174503 :   if (cond_uids)
    5437                 :         455 :     if (unsigned *v = cond_uids->get (expr))
    5438                 :         435 :       cond_uid = *v;
    5439                 :         435 :   if (cond_uid == 0)
    5440                 :     5174068 :     cond_uid = next_cond_uid ();
    5441                 :             : 
    5442                 :     5174503 :   gimple_cond_get_ops_from_tree (COND_EXPR_COND (expr), &pred_code, &arm1,
    5443                 :             :                                  &arm2);
    5444                 :     5174503 :   cond_stmt = gimple_build_cond (pred_code, arm1, arm2, label_true,
    5445                 :             :                                  label_false);
    5446                 :     5174503 :   gimple_set_location (cond_stmt, EXPR_LOCATION (expr));
    5447                 :     5174503 :   gimple_associate_condition_with_expr (cfun, cond_stmt, cond_uid);
    5448                 :     5174503 :   copy_warning (cond_stmt, COND_EXPR_COND (expr));
    5449                 :     5174503 :   gimplify_seq_add_stmt (&seq, cond_stmt);
    5450                 :     5174503 :   gimple_stmt_iterator gsi = gsi_last (seq);
    5451                 :     5174503 :   maybe_fold_stmt (&gsi);
    5452                 :             : 
    5453                 :     5174503 :   label_cont = NULL_TREE;
    5454                 :     5174503 :   if (!have_then_clause_p)
    5455                 :             :     {
    5456                 :             :       /* For if (...) {} else { code; } put label_true after
    5457                 :             :          the else block.  */
    5458                 :     3957265 :       if (TREE_OPERAND (expr, 1) == NULL_TREE
    5459                 :      176137 :           && !have_else_clause_p
    5460                 :     3957934 :           && TREE_OPERAND (expr, 2) != NULL_TREE)
    5461                 :             :         {
    5462                 :             :           /* For if (0) {} else { code; } tell -Wimplicit-fallthrough
    5463                 :             :              handling that label_cont == label_true can be only reached
    5464                 :             :              through fallthrough from { code; }.  */
    5465                 :         669 :           if (integer_zerop (COND_EXPR_COND (expr)))
    5466                 :           0 :             UNUSED_LABEL_P (label_true) = 1;
    5467                 :             :           label_cont = label_true;
    5468                 :             :         }
    5469                 :             :       else
    5470                 :             :         {
    5471                 :     3956596 :           bool then_side_effects
    5472                 :     3956596 :             = (TREE_OPERAND (expr, 1)
    5473                 :     3956596 :                && TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1)));
    5474                 :     3956596 :           gimplify_seq_add_stmt (&seq, gimple_build_label (label_true));
    5475                 :     3956596 :           have_then_clause_p = gimplify_stmt (&TREE_OPERAND (expr, 1), &seq);
    5476                 :             :           /* For if (...) { code; } else {} or
    5477                 :             :              if (...) { code; } else goto label; or
    5478                 :             :              if (...) { code; return; } else { ... }
    5479                 :             :              label_cont isn't needed.  */
    5480                 :     3956596 :           if (!have_else_clause_p
    5481                 :     3779973 :               && TREE_OPERAND (expr, 2) != NULL_TREE
    5482                 :     6542615 :               && gimple_seq_may_fallthru (seq))
    5483                 :             :             {
    5484                 :     1754240 :               gimple *g;
    5485                 :     1754240 :               label_cont = create_artificial_label (UNKNOWN_LOCATION);
    5486                 :             : 
    5487                 :             :               /* For if (0) { non-side-effect-code } else { code }
    5488                 :             :                  tell -Wimplicit-fallthrough handling that label_cont can
    5489                 :             :                  be only reached through fallthrough from { code }.  */
    5490                 :     1754240 :               if (integer_zerop (COND_EXPR_COND (expr)))
    5491                 :             :                 {
    5492                 :       59112 :                   UNUSED_LABEL_P (label_true) = 1;
    5493                 :       59112 :                   if (!then_side_effects)
    5494                 :       11297 :                     UNUSED_LABEL_P (label_cont) = 1;
    5495                 :             :                 }
    5496                 :             : 
    5497                 :     1754240 :               g = gimple_build_goto (label_cont);
    5498                 :             : 
    5499                 :             :               /* GIMPLE_COND's are very low level; they have embedded
    5500                 :             :                  gotos.  This particular embedded goto should not be marked
    5501                 :             :                  with the location of the original COND_EXPR, as it would
    5502                 :             :                  correspond to the COND_EXPR's condition, not the ELSE or the
    5503                 :             :                  THEN arms.  To avoid marking it with the wrong location, flag
    5504                 :             :                  it as "no location".  */
    5505                 :     1754240 :               gimple_set_do_not_emit_location (g);
    5506                 :             : 
    5507                 :     1754240 :               gimplify_seq_add_stmt (&seq, g);
    5508                 :             :             }
    5509                 :             :         }
    5510                 :             :     }
    5511                 :     5174503 :   if (!have_else_clause_p)
    5512                 :             :     {
    5513                 :             :       /* For if (1) { code } or if (1) { code } else { non-side-effect-code }
    5514                 :             :          tell -Wimplicit-fallthrough handling that label_false can be only
    5515                 :             :          reached through fallthrough from { code }.  */
    5516                 :     4502231 :       if (integer_nonzerop (COND_EXPR_COND (expr))
    5517                 :     4502231 :           && (TREE_OPERAND (expr, 2) == NULL_TREE
    5518                 :       54966 :               || !TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 2))))
    5519                 :        6395 :         UNUSED_LABEL_P (label_false) = 1;
    5520                 :     4502231 :       gimplify_seq_add_stmt (&seq, gimple_build_label (label_false));
    5521                 :     4502231 :       have_else_clause_p = gimplify_stmt (&TREE_OPERAND (expr, 2), &seq);
    5522                 :             :     }
    5523                 :     5174503 :   if (label_cont)
    5524                 :     1754909 :     gimplify_seq_add_stmt (&seq, gimple_build_label (label_cont));
    5525                 :             : 
    5526                 :     5174503 :   gimple_pop_condition (pre_p);
    5527                 :     5174503 :   gimple_seq_add_seq (pre_p, seq);
    5528                 :             : 
    5529                 :     5174503 :   if (ret == GS_ERROR)
    5530                 :             :     ; /* Do nothing.  */
    5531                 :     5174503 :   else if (have_then_clause_p || have_else_clause_p)
    5532                 :             :     ret = GS_ALL_DONE;
    5533                 :             :   else
    5534                 :             :     {
    5535                 :             :       /* Both arms are empty; replace the COND_EXPR with its predicate.  */
    5536                 :        2748 :       expr = TREE_OPERAND (expr, 0);
    5537                 :        2748 :       gimplify_stmt (&expr, pre_p);
    5538                 :             :     }
    5539                 :             : 
    5540                 :     5174503 :   *expr_p = NULL;
    5541                 :     5174503 :   return ret;
    5542                 :             : }
    5543                 :             : 
    5544                 :             : /* Prepare the node pointed to by EXPR_P, an is_gimple_addressable expression,
    5545                 :             :    to be marked addressable.
    5546                 :             : 
    5547                 :             :    We cannot rely on such an expression being directly markable if a temporary
    5548                 :             :    has been created by the gimplification.  In this case, we create another
    5549                 :             :    temporary and initialize it with a copy, which will become a store after we
    5550                 :             :    mark it addressable.  This can happen if the front-end passed us something
    5551                 :             :    that it could not mark addressable yet, like a Fortran pass-by-reference
    5552                 :             :    parameter (int) floatvar.  */
    5553                 :             : 
    5554                 :             : static void
    5555                 :    51884558 : prepare_gimple_addressable (tree *expr_p, gimple_seq *seq_p)
    5556                 :             : {
    5557                 :    56796890 :   while (handled_component_p (*expr_p))
    5558                 :     4912332 :     expr_p = &TREE_OPERAND (*expr_p, 0);
    5559                 :             : 
    5560                 :             :   /* Do not allow an SSA name as the temporary.  */
    5561                 :    51884558 :   if (is_gimple_reg (*expr_p))
    5562                 :       11994 :     *expr_p = internal_get_tmp_var (*expr_p, seq_p, NULL, false, false, true);
    5563                 :    51884558 : }
    5564                 :             : 
    5565                 :             : /* A subroutine of gimplify_modify_expr.  Replace a MODIFY_EXPR with
    5566                 :             :    a call to __builtin_memcpy.  */
    5567                 :             : 
    5568                 :             : static enum gimplify_status
    5569                 :        1070 : gimplify_modify_expr_to_memcpy (tree *expr_p, tree size, bool want_value,
    5570                 :             :                                 gimple_seq *seq_p)
    5571                 :             : {
    5572                 :        1070 :   tree t, to, to_ptr, from, from_ptr;
    5573                 :        1070 :   gcall *gs;
    5574                 :        1070 :   location_t loc = EXPR_LOCATION (*expr_p);
    5575                 :             : 
    5576                 :        1070 :   to = TREE_OPERAND (*expr_p, 0);
    5577                 :        1070 :   from = TREE_OPERAND (*expr_p, 1);
    5578                 :        1070 :   gcc_assert (ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (TREE_TYPE (to)))
    5579                 :             :               && ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (TREE_TYPE (from))));
    5580                 :             : 
    5581                 :             :   /* Mark the RHS addressable.  Beware that it may not be possible to do so
    5582                 :             :      directly if a temporary has been created by the gimplification.  */
    5583                 :        1070 :   prepare_gimple_addressable (&from, seq_p);
    5584                 :             : 
    5585                 :        1070 :   mark_addressable (from);
    5586                 :        1070 :   from_ptr = build_fold_addr_expr_loc (loc, from);
    5587                 :        1070 :   gimplify_arg (&from_ptr, seq_p, loc);
    5588                 :             : 
    5589                 :        1070 :   mark_addressable (to);
    5590                 :        1070 :   to_ptr = build_fold_addr_expr_loc (loc, to);
    5591                 :        1070 :   gimplify_arg (&to_ptr, seq_p, loc);
    5592                 :             : 
    5593                 :        1070 :   t = builtin_decl_implicit (BUILT_IN_MEMCPY);
    5594                 :             : 
    5595                 :        1070 :   gs = gimple_build_call (t, 3, to_ptr, from_ptr, size);
    5596                 :        1070 :   gimple_call_set_alloca_for_var (gs, true);
    5597                 :             : 
    5598                 :        1070 :   if (want_value)
    5599                 :             :     {
    5600                 :             :       /* tmp = memcpy() */
    5601                 :           8 :       t = create_tmp_var (TREE_TYPE (to_ptr));
    5602                 :           8 :       gimple_call_set_lhs (gs, t);
    5603                 :           8 :       gimplify_seq_add_stmt (seq_p, gs);
    5604                 :             : 
    5605                 :           8 :       *expr_p = build_simple_mem_ref (t);
    5606                 :           8 :       return GS_ALL_DONE;
    5607                 :             :     }
    5608                 :             : 
    5609                 :        1062 :   gimplify_seq_add_stmt (seq_p, gs);
    5610                 :        1062 :   *expr_p = NULL;
    5611                 :        1062 :   return GS_ALL_DONE;
    5612                 :             : }
    5613                 :             : 
    5614                 :             : /* A subroutine of gimplify_modify_expr.  Replace a MODIFY_EXPR with
    5615                 :             :    a call to __builtin_memset.  In this case we know that the RHS is
    5616                 :             :    a CONSTRUCTOR with an empty element list.  */
    5617                 :             : 
    5618                 :             : static enum gimplify_status
    5619                 :          66 : gimplify_modify_expr_to_memset (tree *expr_p, tree size, bool want_value,
    5620                 :             :                                 gimple_seq *seq_p)
    5621                 :             : {
    5622                 :          66 :   tree t, from, to, to_ptr;
    5623                 :          66 :   gcall *gs;
    5624                 :          66 :   location_t loc = EXPR_LOCATION (*expr_p);
    5625                 :             : 
    5626                 :             :   /* Assert our assumptions, to abort instead of producing wrong code
    5627                 :             :      silently if they are not met.  Beware that the RHS CONSTRUCTOR might
    5628                 :             :      not be immediately exposed.  */
    5629                 :          66 :   from = TREE_OPERAND (*expr_p, 1);
    5630                 :          66 :   if (TREE_CODE (from) == WITH_SIZE_EXPR)
    5631                 :          66 :     from = TREE_OPERAND (from, 0);
    5632                 :             : 
    5633                 :          66 :   gcc_assert (TREE_CODE (from) == CONSTRUCTOR
    5634                 :             :               && vec_safe_is_empty (CONSTRUCTOR_ELTS (from)));
    5635                 :             : 
    5636                 :             :   /* Now proceed.  */
    5637                 :          66 :   to = TREE_OPERAND (*expr_p, 0);
    5638                 :          66 :   gcc_assert (ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (TREE_TYPE (to))));
    5639                 :             : 
    5640                 :          66 :   to_ptr = build_fold_addr_expr_loc (loc, to);
    5641                 :          66 :   gimplify_arg (&to_ptr, seq_p, loc);
    5642                 :          66 :   t = builtin_decl_implicit (BUILT_IN_MEMSET);
    5643                 :             : 
    5644                 :          66 :   gs = gimple_build_call (t, 3, to_ptr, integer_zero_node, size);
    5645                 :             : 
    5646                 :          66 :   if (want_value)
    5647                 :             :     {
    5648                 :             :       /* tmp = memset() */
    5649                 :           0 :       t = create_tmp_var (TREE_TYPE (to_ptr));
    5650                 :           0 :       gimple_call_set_lhs (gs, t);
    5651                 :           0 :       gimplify_seq_add_stmt (seq_p, gs);
    5652                 :             : 
    5653                 :           0 :       *expr_p = build1 (INDIRECT_REF, TREE_TYPE (to), t);
    5654                 :           0 :       return GS_ALL_DONE;
    5655                 :             :     }
    5656                 :             : 
    5657                 :          66 :   gimplify_seq_add_stmt (seq_p, gs);
    5658                 :          66 :   *expr_p = NULL;
    5659                 :          66 :   return GS_ALL_DONE;
    5660                 :             : }
    5661                 :             : 
    5662                 :             : /* A subroutine of gimplify_init_ctor_preeval.  Called via walk_tree,
    5663                 :             :    determine, cautiously, if a CONSTRUCTOR overlaps the lhs of an
    5664                 :             :    assignment.  Return non-null if we detect a potential overlap.  */
    5665                 :             : 
    5666                 :             : struct gimplify_init_ctor_preeval_data
    5667                 :             : {
    5668                 :             :   /* The base decl of the lhs object.  May be NULL, in which case we
    5669                 :             :      have to assume the lhs is indirect.  */
    5670                 :             :   tree lhs_base_decl;
    5671                 :             : 
    5672                 :             :   /* The alias set of the lhs object.  */
    5673                 :             :   alias_set_type lhs_alias_set;
    5674                 :             : };
    5675                 :             : 
    5676                 :             : static tree
    5677                 :      114809 : gimplify_init_ctor_preeval_1 (tree *tp, int *walk_subtrees, void *xdata)
    5678                 :             : {
    5679                 :      114809 :   struct gimplify_init_ctor_preeval_data *data
    5680                 :             :     = (struct gimplify_init_ctor_preeval_data *) xdata;
    5681                 :      114809 :   tree t = *tp;
    5682                 :             : 
    5683                 :             :   /* If we find the base object, obviously we have overlap.  */
    5684                 :      114809 :   if (data->lhs_base_decl == t)
    5685                 :             :     return t;
    5686                 :             : 
    5687                 :             :   /* If the constructor component is indirect, determine if we have a
    5688                 :             :      potential overlap with the lhs.  The only bits of information we
    5689                 :             :      have to go on at this point are addressability and alias sets.  */
    5690                 :      114808 :   if ((INDIRECT_REF_P (t)
    5691                 :      114808 :        || TREE_CODE (t) == MEM_REF)
    5692                 :         643 :       && (!data->lhs_base_decl || TREE_ADDRESSABLE (data->lhs_base_decl))
    5693                 :      115320 :       && alias_sets_conflict_p (data->lhs_alias_set, get_alias_set (t)))
    5694                 :             :     return t;
    5695                 :             : 
    5696                 :             :   /* If the constructor component is a call, determine if it can hide a
    5697                 :             :      potential overlap with the lhs through an INDIRECT_REF like above.
    5698                 :             :      ??? Ugh - this is completely broken.  In fact this whole analysis
    5699                 :             :      doesn't look conservative.  */
    5700                 :      114296 :   if (TREE_CODE (t) == CALL_EXPR)
    5701                 :             :     {
    5702                 :           0 :       tree type, fntype = TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (t)));
    5703                 :             : 
    5704                 :           0 :       for (type = TYPE_ARG_TYPES (fntype); type; type = TREE_CHAIN (type))
    5705                 :           0 :         if (POINTER_TYPE_P (TREE_VALUE (type))
    5706                 :           0 :             && (!data->lhs_base_decl || TREE_ADDRESSABLE (data->lhs_base_decl))
    5707                 :           0 :             && alias_sets_conflict_p (data->lhs_alias_set,
    5708                 :             :                                       get_alias_set
    5709                 :           0 :                                         (TREE_TYPE (TREE_VALUE (type)))))
    5710                 :             :           return t;
    5711                 :             :     }
    5712                 :             : 
    5713                 :      114296 :   if (IS_TYPE_OR_DECL_P (t))
    5714                 :       10964 :     *walk_subtrees = 0;
    5715                 :             :   return NULL;
    5716                 :             : }
    5717                 :             : 
    5718                 :             : /* A subroutine of gimplify_init_constructor.  Pre-evaluate EXPR,
    5719                 :             :    force values that overlap with the lhs (as described by *DATA)
    5720                 :             :    into temporaries.  */
    5721                 :             : 
    5722                 :             : static void
    5723                 :      400693 : gimplify_init_ctor_preeval (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
    5724                 :             :                             struct gimplify_init_ctor_preeval_data *data)
    5725                 :             : {
    5726                 :      400693 :   enum gimplify_status one;
    5727                 :             : 
    5728                 :             :   /* If the value is constant, then there's nothing to pre-evaluate.  */
    5729                 :      400693 :   if (TREE_CONSTANT (*expr_p))
    5730                 :             :     {
    5731                 :             :       /* Ensure it does not have side effects, it might contain a reference to
    5732                 :             :          the object we're initializing.  */
    5733                 :      186364 :       gcc_assert (!TREE_SIDE_EFFECTS (*expr_p));
    5734                 :             :       return;
    5735                 :             :     }
    5736                 :             : 
    5737                 :             :   /* If the type has non-trivial constructors, we can't pre-evaluate.  */
    5738                 :      214329 :   if (TREE_ADDRESSABLE (TREE_TYPE (*expr_p)))
    5739                 :             :     return;
    5740                 :             : 
    5741                 :             :   /* Recurse for nested constructors.  */
    5742                 :      214329 :   if (TREE_CODE (*expr_p) == CONSTRUCTOR)
    5743                 :             :     {
    5744                 :       72221 :       unsigned HOST_WIDE_INT ix;
    5745                 :       72221 :       constructor_elt *ce;
    5746                 :       72221 :       vec<constructor_elt, va_gc> *v = CONSTRUCTOR_ELTS (*expr_p);
    5747                 :             : 
    5748                 :      266711 :       FOR_EACH_VEC_SAFE_ELT (v, ix, ce)
    5749                 :      194490 :         gimplify_init_ctor_preeval (&ce->value, pre_p, post_p, data);
    5750                 :             : 
    5751                 :             :       return;
    5752                 :             :     }
    5753                 :             : 
    5754                 :             :   /* If this is a variable sized type, we must remember the size.  */
    5755                 :      142108 :   maybe_with_size_expr (expr_p);
    5756                 :             : 
    5757                 :             :   /* Gimplify the constructor element to something appropriate for the rhs
    5758                 :             :      of a MODIFY_EXPR.  Given that we know the LHS is an aggregate, we know
    5759                 :             :      the gimplifier will consider this a store to memory.  Doing this
    5760                 :             :      gimplification now means that we won't have to deal with complicated
    5761                 :             :      language-specific trees, nor trees like SAVE_EXPR that can induce
    5762                 :             :      exponential search behavior.  */
    5763                 :      142108 :   one = gimplify_expr (expr_p, pre_p, post_p, is_gimple_mem_rhs, fb_rvalue);
    5764                 :      142108 :   if (one == GS_ERROR)
    5765                 :             :     {
    5766                 :           0 :       *expr_p = NULL;
    5767                 :           0 :       return;
    5768                 :             :     }
    5769                 :             : 
    5770                 :             :   /* If we gimplified to a bare decl, we can be sure that it doesn't overlap
    5771                 :             :      with the lhs, since "a = { .x=a }" doesn't make sense.  This will
    5772                 :             :      always be true for all scalars, since is_gimple_mem_rhs insists on a
    5773                 :             :      temporary variable for them.  */
    5774                 :      142108 :   if (DECL_P (*expr_p))
    5775                 :             :     return;
    5776                 :             : 
    5777                 :             :   /* If this is of variable size, we have no choice but to assume it doesn't
    5778                 :             :      overlap since we can't make a temporary for it.  */
    5779                 :      103265 :   if (TREE_CODE (TYPE_SIZE (TREE_TYPE (*expr_p))) != INTEGER_CST)
    5780                 :             :     return;
    5781                 :             : 
    5782                 :             :   /* Otherwise, we must search for overlap ...  */
    5783                 :      103265 :   if (!walk_tree (expr_p, gimplify_init_ctor_preeval_1, data, NULL))
    5784                 :             :     return;
    5785                 :             : 
    5786                 :             :   /* ... and if found, force the value into a temporary.  */
    5787                 :         513 :   *expr_p = get_formal_tmp_var (*expr_p, pre_p);
    5788                 :             : }
    5789                 :             : 
    5790                 :             : /* A subroutine of gimplify_init_ctor_eval.  Create a loop for
    5791                 :             :    a RANGE_EXPR in a CONSTRUCTOR for an array.
    5792                 :             : 
    5793                 :             :       var = lower;
    5794                 :             :     loop_entry:
    5795                 :             :       object[var] = value;
    5796                 :             :       if (var == upper)
    5797                 :             :         goto loop_exit;
    5798                 :             :       var = var + 1;
    5799                 :             :       goto loop_entry;
    5800                 :             :     loop_exit:
    5801                 :             : 
    5802                 :             :    We increment var _after_ the loop exit check because we might otherwise
    5803                 :             :    fail if upper == TYPE_MAX_VALUE (type for upper).
    5804                 :             : 
    5805                 :             :    Note that we never have to deal with SAVE_EXPRs here, because this has
    5806                 :             :    already been taken care of for us, in gimplify_init_ctor_preeval().  */
    5807                 :             : 
    5808                 :             : static void gimplify_init_ctor_eval (tree, vec<constructor_elt, va_gc> *,
    5809                 :             :                                      gimple_seq *, bool);
    5810                 :             : 
    5811                 :             : static void
    5812                 :         375 : gimplify_init_ctor_eval_range (tree object, tree lower, tree upper,
    5813                 :             :                                tree value, tree array_elt_type,
    5814                 :             :                                gimple_seq *pre_p, bool cleared)
    5815                 :             : {
    5816                 :         375 :   tree loop_entry_label, loop_exit_label, fall_thru_label;
    5817                 :         375 :   tree var, var_type, cref, tmp;
    5818                 :             : 
    5819                 :         375 :   loop_entry_label = create_artificial_label (UNKNOWN_LOCATION);
    5820                 :         375 :   loop_exit_label = create_artificial_label (UNKNOWN_LOCATION);
    5821                 :         375 :   fall_thru_label = create_artificial_label (UNKNOWN_LOCATION);
    5822                 :             : 
    5823                 :             :   /* Create and initialize the index variable.  */
    5824                 :         375 :   var_type = TREE_TYPE (upper);
    5825                 :         375 :   var = create_tmp_var (var_type);
    5826                 :         375 :   gimplify_seq_add_stmt (pre_p, gimple_build_assign (var, lower));
    5827                 :             : 
    5828                 :             :   /* Add the loop entry label.  */
    5829                 :         375 :   gimplify_seq_add_stmt (pre_p, gimple_build_label (loop_entry_label));
    5830                 :             : 
    5831                 :             :   /* Build the reference.  */
    5832                 :         375 :   cref = build4 (ARRAY_REF, array_elt_type, unshare_expr (object),
    5833                 :             :                  var, NULL_TREE, NULL_TREE);
    5834                 :             : 
    5835                 :             :   /* If we are a constructor, just call gimplify_init_ctor_eval to do
    5836                 :             :      the store.  Otherwise just assign value to the reference.  */
    5837                 :             : 
    5838                 :         375 :   if (TREE_CODE (value) == CONSTRUCTOR)
    5839                 :             :     /* NB we might have to call ourself recursively through
    5840                 :             :        gimplify_init_ctor_eval if the value is a constructor.  */
    5841                 :          85 :     gimplify_init_ctor_eval (cref, CONSTRUCTOR_ELTS (value),
    5842                 :             :                              pre_p, cleared);
    5843                 :             :   else
    5844                 :             :     {
    5845                 :         290 :       if (gimplify_expr (&value, pre_p, NULL, is_gimple_val, fb_rvalue)
    5846                 :             :           != GS_ERROR)
    5847                 :         290 :         gimplify_seq_add_stmt (pre_p, gimple_build_assign (cref, value));
    5848                 :             :     }
    5849                 :             : 
    5850                 :             :   /* We exit the loop when the index var is equal to the upper bound.  */
    5851                 :         750 :   gimplify_seq_add_stmt (pre_p,
    5852                 :         375 :                          gimple_build_cond (EQ_EXPR, var, upper,
    5853                 :             :                                             loop_exit_label, fall_thru_label));
    5854                 :             : 
    5855                 :         375 :   gimplify_seq_add_stmt (pre_p, gimple_build_label (fall_thru_label));
    5856                 :             : 
    5857                 :             :   /* Otherwise, increment the index var...  */
    5858                 :         375 :   tmp = build2 (PLUS_EXPR, var_type, var,
    5859                 :             :                 fold_convert (var_type, integer_one_node));
    5860                 :         375 :   gimplify_seq_add_stmt (pre_p, gimple_build_assign (var, tmp));
    5861                 :             : 
    5862                 :             :   /* ...and jump back to the loop entry.  */
    5863                 :         375 :   gimplify_seq_add_stmt (pre_p, gimple_build_goto (loop_entry_label));
    5864                 :             : 
    5865                 :             :   /* Add the loop exit label.  */
    5866                 :         375 :   gimplify_seq_add_stmt (pre_p, gimple_build_label (loop_exit_label));
    5867                 :         375 : }
    5868                 :             : 
    5869                 :             : /* A subroutine of gimplify_init_constructor.  Generate individual
    5870                 :             :    MODIFY_EXPRs for a CONSTRUCTOR.  OBJECT is the LHS against which the
    5871                 :             :    assignments should happen.  ELTS is the CONSTRUCTOR_ELTS of the
    5872                 :             :    CONSTRUCTOR.  CLEARED is true if the entire LHS object has been
    5873                 :             :    zeroed first.  */
    5874                 :             : 
    5875                 :             : static void
    5876                 :     1156728 : gimplify_init_ctor_eval (tree object, vec<constructor_elt, va_gc> *elts,
    5877                 :             :                          gimple_seq *pre_p, bool cleared)
    5878                 :             : {
    5879                 :     1156728 :   tree array_elt_type = NULL;
    5880                 :     1156728 :   unsigned HOST_WIDE_INT ix;
    5881                 :     1156728 :   tree purpose, value;
    5882                 :             : 
    5883                 :     1156728 :   if (TREE_CODE (TREE_TYPE (object)) == ARRAY_TYPE)
    5884                 :      132825 :     array_elt_type = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (object)));
    5885                 :             : 
    5886                 :     4266923 :   FOR_EACH_CONSTRUCTOR_ELT (elts, ix, purpose, value)
    5887                 :             :     {
    5888                 :     3110195 :       tree cref;
    5889                 :             : 
    5890                 :             :       /* NULL values are created above for gimplification errors.  */
    5891                 :     3110195 :       if (value == NULL)
    5892                 :      281704 :         continue;
    5893                 :             : 
    5894                 :     3110195 :       if (cleared && initializer_zerop (value))
    5895                 :      281167 :         continue;
    5896                 :             : 
    5897                 :             :       /* ??? Here's to hoping the front end fills in all of the indices,
    5898                 :             :          so we don't have to figure out what's missing ourselves.  */
    5899                 :     2829028 :       gcc_assert (purpose);
    5900                 :             : 
    5901                 :             :       /* Skip zero-sized fields, unless value has side-effects.  This can
    5902                 :             :          happen with calls to functions returning a empty type, which
    5903                 :             :          we shouldn't discard.  As a number of downstream passes don't
    5904                 :             :          expect sets of empty type fields, we rely on the gimplification of
    5905                 :             :          the MODIFY_EXPR we make below to drop the assignment statement.  */
    5906                 :     2829028 :       if (!TREE_SIDE_EFFECTS (value)
    5907                 :     2540598 :           && TREE_CODE (purpose) == FIELD_DECL
    5908                 :     4989256 :           && is_empty_type (TREE_TYPE (purpose)))
    5909                 :         162 :         continue;
    5910                 :             : 
    5911                 :             :       /* If we have a RANGE_EXPR, we have to build a loop to assign the
    5912                 :             :          whole range.  */
    5913                 :     2828866 :       if (TREE_CODE (purpose) == RANGE_EXPR)
    5914                 :             :         {
    5915                 :         385 :           tree lower = TREE_OPERAND (purpose, 0);
    5916                 :         385 :           tree upper = TREE_OPERAND (purpose, 1);
    5917                 :             : 
    5918                 :             :           /* If the lower bound is equal to upper, just treat it as if
    5919                 :             :              upper was the index.  */
    5920                 :         385 :           if (simple_cst_equal (lower, upper))
    5921                 :             :             purpose = upper;
    5922                 :             :           else
    5923                 :             :             {
    5924                 :         375 :               gimplify_init_ctor_eval_range (object, lower, upper, value,
    5925                 :             :                                              array_elt_type, pre_p, cleared);
    5926                 :         375 :               continue;
    5927                 :             :             }
    5928                 :             :         }
    5929                 :             : 
    5930                 :     2828491 :       if (array_elt_type)
    5931                 :             :         {
    5932                 :             :           /* Do not use bitsizetype for ARRAY_REF indices.  */
    5933                 :      468650 :           if (TYPE_DOMAIN (TREE_TYPE (object)))
    5934                 :      468650 :             purpose
    5935                 :      468650 :               = fold_convert (TREE_TYPE (TYPE_DOMAIN (TREE_TYPE (object))),
    5936                 :             :                               purpose);
    5937                 :      468650 :           cref = build4 (ARRAY_REF, array_elt_type, unshare_expr (object),
    5938                 :             :                          purpose, NULL_TREE, NULL_TREE);
    5939                 :             :         }
    5940                 :             :       else
    5941                 :             :         {
    5942                 :     2359841 :           gcc_assert (TREE_CODE (purpose) == FIELD_DECL);
    5943                 :     2359841 :           cref = build3 (COMPONENT_REF, TREE_TYPE (purpose),
    5944                 :             :                          unshare_expr (object), purpose, NULL_TREE);
    5945                 :             :         }
    5946                 :             : 
    5947                 :     2828491 :       if (TREE_CODE (value) == CONSTRUCTOR
    5948                 :     2828491 :           && TREE_CODE (TREE_TYPE (value)) != VECTOR_TYPE)
    5949                 :      254605 :         gimplify_init_ctor_eval (cref, CONSTRUCTOR_ELTS (value),
    5950                 :             :                                  pre_p, cleared);
    5951                 :     2573886 :       else if (TREE_CODE (value) == RAW_DATA_CST)
    5952                 :             :         {
    5953                 :          31 :           if (RAW_DATA_LENGTH (value) <= 32)
    5954                 :             :             {
    5955                 :          13 :               for (unsigned int i = 0; i < (unsigned) RAW_DATA_LENGTH (value);
    5956                 :             :                    ++i)
    5957                 :          12 :                 if (!cleared || RAW_DATA_POINTER (value)[i])
    5958                 :             :                   {
    5959                 :          12 :                     if (i)
    5960                 :             :                       {
    5961                 :          11 :                         tree p
    5962                 :          11 :                           = fold_build2 (PLUS_EXPR, TREE_TYPE (purpose),
    5963                 :             :                                          purpose,
    5964                 :             :                                          build_int_cst (TREE_TYPE (purpose),
    5965                 :             :                                                         i));
    5966                 :          11 :                         cref = build4 (ARRAY_REF, array_elt_type,
    5967                 :             :                                        unshare_expr (object), p, NULL_TREE,
    5968                 :             :                                        NULL_TREE);
    5969                 :             :                       }
    5970                 :          12 :                     tree init
    5971                 :          12 :                       = build2 (INIT_EXPR, TREE_TYPE (cref), cref,
    5972                 :          12 :                                 build_int_cst (TREE_TYPE (value),
    5973                 :          12 :                                                RAW_DATA_UCHAR_ELT (value, i)));
    5974                 :          12 :                     gimplify_and_add (init, pre_p);
    5975                 :          12 :                     ggc_free (init);
    5976                 :             :                   }
    5977                 :             :             }
    5978                 :             :           else
    5979                 :             :             {
    5980                 :          30 :               tree rtype = build_array_type_nelts (TREE_TYPE (value),
    5981                 :          30 :                                                    RAW_DATA_LENGTH (value));
    5982                 :          30 :               tree rctor = build_constructor_single (rtype, bitsize_zero_node,
    5983                 :             :                                                      value);
    5984                 :          30 :               tree addr = build_fold_addr_expr (cref);
    5985                 :          30 :               cref = build2 (MEM_REF, rtype, addr,
    5986                 :          30 :                              build_int_cst (ptr_type_node, 0));
    5987                 :          30 :               rctor = tree_output_constant_def (rctor);
    5988                 :          30 :               if (!useless_type_conversion_p (rtype, TREE_TYPE (rctor)))
    5989                 :           4 :                 rctor = build1 (VIEW_CONVERT_EXPR, rtype, rctor);
    5990                 :          30 :               if (gimplify_expr (&cref, pre_p, NULL, is_gimple_lvalue,
    5991                 :             :                                  fb_lvalue) != GS_ERROR)
    5992                 :          60 :                 gimplify_seq_add_stmt (pre_p,
    5993                 :          30 :                                        gimple_build_assign (cref, rctor));
    5994                 :             :             }
    5995                 :             :         }
    5996                 :             :       else
    5997                 :             :         {
    5998                 :     2573855 :           tree init = build2 (INIT_EXPR, TREE_TYPE (cref), cref, value);
    5999                 :     2573855 :           gimplify_and_add (init, pre_p);
    6000                 :     2573855 :           ggc_free (init);
    6001                 :             :         }
    6002                 :             :     }
    6003                 :     1156728 : }
    6004                 :             : 
    6005                 :             : /* Return the appropriate RHS predicate for this LHS.  */
    6006                 :             : 
    6007                 :             : gimple_predicate
    6008                 :    46285523 : rhs_predicate_for (tree lhs)
    6009                 :             : {
    6010                 :    46285523 :   if (is_gimple_reg (lhs))
    6011                 :             :     return is_gimple_reg_rhs_or_call;
    6012                 :             :   else
    6013                 :    10739384 :     return is_gimple_mem_rhs_or_call;
    6014                 :             : }
    6015                 :             : 
    6016                 :             : /* Return the initial guess for an appropriate RHS predicate for this LHS,
    6017                 :             :    before the LHS has been gimplified.  */
    6018                 :             : 
    6019                 :             : static gimple_predicate
    6020                 :    45311542 : initial_rhs_predicate_for (tree lhs)
    6021                 :             : {
    6022                 :    45311542 :   if (is_gimple_reg_type (TREE_TYPE (lhs)))
    6023                 :             :     return is_gimple_reg_rhs_or_call;
    6024                 :             :   else
    6025                 :     2215128 :     return is_gimple_mem_rhs_or_call;
    6026                 :             : }
    6027                 :             : 
    6028                 :             : /* Gimplify a C99 compound literal expression.  This just means adding
    6029                 :             :    the DECL_EXPR before the current statement and using its anonymous
    6030                 :             :    decl instead.  */
    6031                 :             : 
    6032                 :             : static enum gimplify_status
    6033                 :       36527 : gimplify_compound_literal_expr (tree *expr_p, gimple_seq *pre_p,
    6034                 :             :                                 bool (*gimple_test_f) (tree),
    6035                 :             :                                 fallback_t fallback)
    6036                 :             : {
    6037                 :       36527 :   tree decl_s = COMPOUND_LITERAL_EXPR_DECL_EXPR (*expr_p);
    6038                 :       36527 :   tree decl = DECL_EXPR_DECL (decl_s);
    6039                 :       36527 :   tree init = DECL_INITIAL (decl);
    6040                 :             :   /* Mark the decl as addressable if the compound literal
    6041                 :             :      expression is addressable now, otherwise it is marked too late
    6042                 :             :      after we gimplify the initialization expression.  */
    6043                 :       36527 :   if (TREE_ADDRESSABLE (*expr_p))
    6044                 :         495 :     TREE_ADDRESSABLE (decl) = 1;
    6045                 :             :   /* Otherwise, if we don't need an lvalue and have a literal directly
    6046                 :             :      substitute it.  Check if it matches the gimple predicate, as
    6047                 :             :      otherwise we'd generate a new temporary, and we can as well just
    6048                 :             :      use the decl we already have.  */
    6049                 :       36032 :   else if (!TREE_ADDRESSABLE (decl)
    6050                 :       36032 :            && !TREE_THIS_VOLATILE (decl)
    6051                 :       36027 :            && init
    6052                 :       36020 :            && (fallback & fb_lvalue) == 0
    6053                 :       71950 :            && gimple_test_f (init))
    6054                 :             :     {
    6055                 :       34866 :       *expr_p = init;
    6056                 :       34866 :       return GS_OK;
    6057                 :             :     }
    6058                 :             : 
    6059                 :             :   /* If the decl is not addressable, then it is being used in some
    6060                 :             :      expression or on the right hand side of a statement, and it can
    6061                 :             :      be put into a readonly data section.  */
    6062                 :        1661 :   if (!TREE_ADDRESSABLE (decl) && (fallback & fb_lvalue) == 0)
    6063                 :        1057 :     TREE_READONLY (decl) = 1;
    6064                 :             : 
    6065                 :             :   /* This decl isn't mentioned in the enclosing block, so add it to the
    6066                 :             :      list of temps.  FIXME it seems a bit of a kludge to say that
    6067                 :             :      anonymous artificial vars aren't pushed, but everything else is.  */
    6068                 :        1661 :   if (DECL_NAME (decl) == NULL_TREE && !DECL_SEEN_IN_BIND_EXPR_P (decl))
    6069                 :           2 :     gimple_add_tmp_var (decl);
    6070                 :             : 
    6071                 :        1661 :   gimplify_and_add (decl_s, pre_p);
    6072                 :        1661 :   *expr_p = decl;
    6073                 :        1661 :   return GS_OK;
    6074                 :             : }
    6075                 :             : 
    6076                 :             : /* Optimize embedded COMPOUND_LITERAL_EXPRs within a CONSTRUCTOR,
    6077                 :             :    return a new CONSTRUCTOR if something changed.  */
    6078                 :             : 
    6079                 :             : static tree
    6080                 :     1714438 : optimize_compound_literals_in_ctor (tree orig_ctor)
    6081                 :             : {
    6082                 :     1714438 :   tree ctor = orig_ctor;
    6083                 :     1714438 :   vec<constructor_elt, va_gc> *elts = CONSTRUCTOR_ELTS (ctor);
    6084                 :     1714438 :   unsigned int idx, num = vec_safe_length (elts);
    6085                 :             : 
    6086                 :     5700762 :   for (idx = 0; idx < num; idx++)
    6087                 :             :     {
    6088                 :     3986324 :       tree value = (*elts)[idx].value;
    6089                 :     3986324 :       tree newval = value;
    6090                 :     3986324 :       if (TREE_CODE (value) == CONSTRUCTOR)
    6091                 :      467080 :         newval = optimize_compound_literals_in_ctor (value);
    6092                 :     3519244 :       else if (TREE_CODE (value) == COMPOUND_LITERAL_EXPR)
    6093                 :             :         {
    6094                 :          79 :           tree decl_s = COMPOUND_LITERAL_EXPR_DECL_EXPR (value);
    6095                 :          79 :           tree decl = DECL_EXPR_DECL (decl_s);
    6096                 :          79 :           tree init = DECL_INITIAL (decl);
    6097                 :             : 
    6098                 :          79 :           if (!TREE_ADDRESSABLE (value)
    6099                 :          79 :               && !TREE_ADDRESSABLE (decl)
    6100                 :          79 :               && init
    6101                 :          79 :               && TREE_CODE (init) == CONSTRUCTOR)
    6102                 :          48 :             newval = optimize_compound_literals_in_ctor (init);
    6103                 :             :         }
    6104                 :     3986324 :       if (newval == value)
    6105                 :     3986268 :         continue;
    6106                 :             : 
    6107                 :          56 :       if (ctor == orig_ctor)
    6108                 :             :         {
    6109                 :          45 :           ctor = copy_node (orig_ctor);
    6110                 :          45 :           CONSTRUCTOR_ELTS (ctor) = vec_safe_copy (elts);
    6111                 :          45 :           elts = CONSTRUCTOR_ELTS (ctor);
    6112                 :             :         }
    6113                 :          56 :       (*elts)[idx].value = newval;
    6114                 :             :     }
    6115                 :     1714438 :   return ctor;
    6116                 :             : }
    6117                 :             : 
    6118                 :             : /* A subroutine of gimplify_modify_expr.  Break out elements of a
    6119                 :             :    CONSTRUCTOR used as an initializer into separate MODIFY_EXPRs.
    6120                 :             : 
    6121                 :             :    Note that we still need to clear any elements that don't have explicit
    6122                 :             :    initializers, so if not all elements are initialized we keep the
    6123                 :             :    original MODIFY_EXPR, we just remove all of the constructor elements.
    6124                 :             : 
    6125                 :             :    If NOTIFY_TEMP_CREATION is true, do not gimplify, just return
    6126                 :             :    GS_ERROR if we would have to create a temporary when gimplifying
    6127                 :             :    this constructor.  Otherwise, return GS_OK.
    6128                 :             : 
    6129                 :             :    If NOTIFY_TEMP_CREATION is false, just do the gimplification.  */
    6130                 :             : 
    6131                 :             : static enum gimplify_status
    6132                 :     1247310 : gimplify_init_constructor (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
    6133                 :             :                            bool want_value, bool notify_temp_creation)
    6134                 :             : {
    6135                 :     1247310 :   tree object, ctor, type;
    6136                 :     1247310 :   enum gimplify_status ret;
    6137                 :     1247310 :   vec<constructor_elt, va_gc> *elts;
    6138                 :     1247310 :   bool cleared = false;
    6139                 :     1247310 :   bool is_empty_ctor = false;
    6140                 :     1247310 :   bool is_init_expr = (TREE_CODE (*expr_p) == INIT_EXPR);
    6141                 :             : 
    6142                 :     1247310 :   gcc_assert (TREE_CODE (TREE_OPERAND (*expr_p, 1)) == CONSTRUCTOR);
    6143                 :             : 
    6144                 :     1247310 :   if (!notify_temp_creation)
    6145                 :             :     {
    6146                 :     1240656 :       ret = gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p,
    6147                 :             :                            is_gimple_lvalue, fb_lvalue);
    6148                 :     1240656 :       if (ret == GS_ERROR)
    6149                 :             :         return ret;
    6150                 :             :     }
    6151                 :             : 
    6152                 :     1247310 :   object = TREE_OPERAND (*expr_p, 0);
    6153                 :     3741930 :   ctor = TREE_OPERAND (*expr_p, 1)
    6154                 :     1247310 :     = optimize_compound_literals_in_ctor (TREE_OPERAND (*expr_p, 1));
    6155                 :     1247310 :   type = TREE_TYPE (ctor);
    6156                 :     1247310 :   elts = CONSTRUCTOR_ELTS (ctor);
    6157                 :     1247310 :   ret = GS_ALL_DONE;
    6158                 :             : 
    6159                 :     1247310 :   switch (TREE_CODE (type))
    6160                 :             :     {
    6161                 :     1240812 :     case RECORD_TYPE:
    6162                 :     1240812 :     case UNION_TYPE:
    6163                 :     1240812 :     case QUAL_UNION_TYPE:
    6164                 :     1240812 :     case ARRAY_TYPE:
    6165                 :     1240812 :       {
    6166                 :             :         /* Use readonly data for initializers of this or smaller size
    6167                 :             :            regardless of the num_nonzero_elements / num_unique_nonzero_elements
    6168                 :             :            ratio.  */
    6169                 :     1240812 :         const HOST_WIDE_INT min_unique_size = 64;
    6170                 :             :         /* If num_nonzero_elements / num_unique_nonzero_elements ratio
    6171                 :             :            is smaller than this, use readonly data.  */
    6172                 :     1240812 :         const int unique_nonzero_ratio = 8;
    6173                 :             :         /* True if a single access of the object must be ensured.  This is the
    6174                 :             :            case if the target is volatile, the type is non-addressable and more
    6175                 :             :            than one field need to be assigned.  */
    6176                 :     1240812 :         const bool ensure_single_access
    6177                 :     1240812 :           = TREE_THIS_VOLATILE (object)
    6178                 :         222 :             && !TREE_ADDRESSABLE (type)
    6179                 :     1241000 :             && vec_safe_length (elts) > 1;
    6180                 :     1240812 :         struct gimplify_init_ctor_preeval_data preeval_data;
    6181                 :     1240812 :         HOST_WIDE_INT num_ctor_elements, num_nonzero_elements;
    6182                 :     1240812 :         HOST_WIDE_INT num_unique_nonzero_elements;
    6183                 :     1240812 :         int complete_p;
    6184                 :     1240812 :         bool valid_const_initializer;
    6185                 :             : 
    6186                 :             :         /* Aggregate types must lower constructors to initialization of
    6187                 :             :            individual elements.  The exception is that a CONSTRUCTOR node
    6188                 :             :            with no elements indicates zero-initialization of the whole.  */
    6189                 :     1240812 :         if (vec_safe_is_empty (elts))
    6190                 :             :           {
    6191                 :      314254 :             if (notify_temp_creation)
    6192                 :        8168 :               return GS_OK;
    6193                 :             : 
    6194                 :             :             /* The var will be initialized and so appear on lhs of
    6195                 :             :                assignment, it can't be TREE_READONLY anymore.  */
    6196                 :      314206 :             if (VAR_P (object))
    6197                 :      177441 :               TREE_READONLY (object) = 0;
    6198                 :             : 
    6199                 :             :             is_empty_ctor = true;
    6200                 :      315825 :             break;
    6201                 :             :           }
    6202                 :             : 
    6203                 :             :         /* Fetch information about the constructor to direct later processing.
    6204                 :             :            We might want to make static versions of it in various cases, and
    6205                 :             :            can only do so if it known to be a valid constant initializer.  */
    6206                 :      926558 :         valid_const_initializer
    6207                 :      926558 :           = categorize_ctor_elements (ctor, &num_nonzero_elements,
    6208                 :             :                                       &num_unique_nonzero_elements,
    6209                 :             :                                       &num_ctor_elements, &complete_p);
    6210                 :             : 
    6211                 :             :         /* If a const aggregate variable is being initialized, then it
    6212                 :             :            should never be a lose to promote the variable to be static.  */
    6213                 :      926558 :         if (valid_const_initializer
    6214                 :      556892 :             && num_nonzero_elements > 1
    6215                 :      419598 :             && TREE_READONLY (object)
    6216                 :        3882 :             && VAR_P (object)
    6217                 :        3505 :             && !DECL_REGISTER (object)
    6218                 :        3498 :             && (flag_merge_constants >= 2 || !TREE_ADDRESSABLE (object)
    6219                 :        3303 :                 || DECL_MERGEABLE (object))
    6220                 :             :             /* For ctors that have many repeated nonzero elements
    6221                 :             :                represented through RANGE_EXPRs, prefer initializing
    6222                 :             :                those through runtime loops over copies of large amounts
    6223                 :             :                of data from readonly data section.  */
    6224                 :      926558 :             && (num_unique_nonzero_elements
    6225                 :        1619 :                 > num_nonzero_elements / unique_nonzero_ratio
    6226                 :           0 :                 || ((unsigned HOST_WIDE_INT) int_size_in_bytes (type)
    6227                 :             :                     <= (unsigned HOST_WIDE_INT) min_unique_size)))
    6228                 :             :           {
    6229                 :        1619 :             if (notify_temp_creation)
    6230                 :             :               return GS_ERROR;
    6231                 :             : 
    6232                 :        1619 :             DECL_INITIAL (object) = ctor;
    6233                 :        1619 :             TREE_STATIC (object) = 1;
    6234                 :        1619 :             if (!DECL_NAME (object) || DECL_NAMELESS (object))
    6235                 :        1439 :               DECL_NAME (object) = create_tmp_var_name ("C");
    6236                 :        1619 :             walk_tree (&DECL_INITIAL (object), force_labels_r, NULL, NULL);
    6237                 :             : 
    6238                 :             :             /* ??? C++ doesn't automatically append a .<number> to the
    6239                 :             :                assembler name, and even when it does, it looks at FE private
    6240                 :             :                data structures to figure out what that number should be,
    6241                 :             :                which are not set for this variable.  I suppose this is
    6242                 :             :                important for local statics for inline functions, which aren't
    6243                 :             :                "local" in the object file sense.  So in order to get a unique
    6244                 :             :                TU-local symbol, we must invoke the lhd version now.  */
    6245                 :        1619 :             lhd_set_decl_assembler_name (object);
    6246                 :             : 
    6247                 :        1619 :             *expr_p = NULL_TREE;
    6248                 :        1619 :             break;
    6249                 :             :           }
    6250                 :             : 
    6251                 :             :         /* The var will be initialized and so appear on lhs of
    6252                 :             :            assignment, it can't be TREE_READONLY anymore.  */
    6253                 :      924939 :         if (VAR_P (object) && !notify_temp_creation)
    6254                 :      733739 :           TREE_READONLY (object) = 0;
    6255                 :             : 
    6256                 :             :         /* If there are "lots" of initialized elements, even discounting
    6257                 :             :            those that are not address constants (and thus *must* be
    6258                 :             :            computed at runtime), then partition the constructor into
    6259                 :             :            constant and non-constant parts.  Block copy the constant
    6260                 :             :            parts in, then generate code for the non-constant parts.  */
    6261                 :             :         /* TODO.  There's code in cp/typeck.cc to do this.  */
    6262                 :             : 
    6263                 :      924939 :         if (int_size_in_bytes (TREE_TYPE (ctor)) < 0)
    6264                 :             :           /* store_constructor will ignore the clearing of variable-sized
    6265                 :             :              objects.  Initializers for such objects must explicitly set
    6266                 :             :              every field that needs to be set.  */
    6267                 :             :           cleared = false;
    6268                 :      924922 :         else if (!complete_p)
    6269                 :             :           /* If the constructor isn't complete, clear the whole object
    6270                 :             :              beforehand, unless CONSTRUCTOR_NO_CLEARING is set on it.
    6271                 :             : 
    6272                 :             :              ??? This ought not to be needed.  For any element not present
    6273                 :             :              in the initializer, we should simply set them to zero.  Except
    6274                 :             :              we'd need to *find* the elements that are not present, and that
    6275                 :             :              requires trickery to avoid quadratic compile-time behavior in
    6276                 :             :              large cases or excessive memory use in small cases.  */
    6277                 :      163687 :           cleared = !CONSTRUCTOR_NO_CLEARING (ctor);
    6278                 :      761235 :         else if (num_ctor_elements - num_nonzero_elements
    6279                 :      761235 :                  > CLEAR_RATIO (optimize_function_for_speed_p (cfun))
    6280                 :      761235 :                  && num_nonzero_elements < num_ctor_elements / 4)
    6281                 :             :           /* If there are "lots" of zeros, it's more efficient to clear
    6282                 :             :              the memory and then set the nonzero elements.  */
    6283                 :             :           cleared = true;
    6284                 :      755990 :         else if (ensure_single_access && num_nonzero_elements == 0)
    6285                 :             :           /* If a single access to the target must be ensured and all elements
    6286                 :             :              are zero, then it's optimal to clear whatever their number.  */
    6287                 :             :           cleared = true;
    6288                 :             :         /* If the object is small enough to go in registers, and it's
    6289                 :             :            not required to be constructed in memory, clear it first.
    6290                 :             :            That will avoid wasting cycles preserving any padding bits
    6291                 :             :            that might be there, and if there aren't any, the compiler
    6292                 :             :            is smart enough to optimize the clearing out.  */
    6293                 :      755985 :         else if (complete_p <= 0
    6294                 :       12816 :                  && !TREE_ADDRESSABLE (ctor)
    6295                 :       12802 :                  && !TREE_THIS_VOLATILE (object)
    6296                 :       12799 :                  && (TYPE_MODE (type) != BLKmode || TYPE_NO_FORCE_BLK (type))
    6297                 :      762417 :                  && optimize)
    6298                 :             :           cleared = true;
    6299                 :             :         else
    6300                 :             :           cleared = false;
    6301                 :             : 
    6302                 :             :         /* If there are "lots" of initialized elements, and all of them
    6303                 :             :            are valid address constants, then the entire initializer can
    6304                 :             :            be dropped to memory, and then memcpy'd out.  Don't do this
    6305                 :             :            for sparse arrays, though, as it's more efficient to follow
    6306                 :             :            the standard CONSTRUCTOR behavior of memset followed by
    6307                 :             :            individual element initialization.  Also don't do this for small
    6308                 :             :            all-zero initializers (which aren't big enough to merit
    6309                 :             :            clearing), and don't try to make bitwise copies of
    6310                 :             :            TREE_ADDRESSABLE types.  */
    6311                 :      924939 :         if (valid_const_initializer
    6312                 :      555273 :             && complete_p
    6313                 :      406170 :             && !(cleared || num_nonzero_elements == 0)
    6314                 :      313213 :             && !TREE_ADDRESSABLE (type))
    6315                 :             :           {
    6316                 :      312229 :             HOST_WIDE_INT size = int_size_in_bytes (type);
    6317                 :      312229 :             unsigned int align;
    6318                 :             : 
    6319                 :             :             /* ??? We can still get unbounded array types, at least
    6320                 :             :                from the C++ front end.  This seems wrong, but attempt
    6321                 :             :                to work around it for now.  */
    6322                 :      312229 :             if (size < 0)
    6323                 :             :               {
    6324                 :           8 :                 size = int_size_in_bytes (TREE_TYPE (object));
    6325                 :           8 :                 if (size >= 0)
    6326                 :           0 :                   TREE_TYPE (ctor) = type = TREE_TYPE (object);
    6327                 :             :               }
    6328                 :             : 
    6329                 :             :             /* Find the maximum alignment we can assume for the object.  */
    6330                 :             :             /* ??? Make use of DECL_OFFSET_ALIGN.  */
    6331                 :      312229 :             if (DECL_P (object))
    6332                 :      298928 :               align = DECL_ALIGN (object);
    6333                 :             :             else
    6334                 :       13301 :               align = TYPE_ALIGN (type);
    6335                 :             : 
    6336                 :             :             /* Do a block move either if the size is so small as to make
    6337                 :             :                each individual move a sub-unit move on average, or if it
    6338                 :             :                is so large as to make individual moves inefficient.  */
    6339                 :      312229 :             if (size > 0
    6340                 :      312221 :                 && num_nonzero_elements > 1
    6341                 :             :                 /* For ctors that have many repeated nonzero elements
    6342                 :             :                    represented through RANGE_EXPRs, prefer initializing
    6343                 :             :                    those through runtime loops over copies of large amounts
    6344                 :             :                    of data from readonly data section.  */
    6345                 :      286694 :                 && (num_unique_nonzero_elements
    6346                 :      286694 :                     > num_nonzero_elements / unique_nonzero_ratio
    6347                 :          41 :                     || size <= min_unique_size)
    6348                 :      598882 :                 && (size < num_nonzero_elements
    6349                 :      286575 :                     || !can_move_by_pieces (size, align)))
    6350                 :             :               {
    6351                 :        2726 :                 if (notify_temp_creation)
    6352                 :             :                   return GS_ERROR;
    6353                 :             : 
    6354                 :        1363 :                 walk_tree (&ctor, force_labels_r, NULL, NULL);
    6355                 :        1363 :                 ctor = tree_output_constant_def (ctor);
    6356                 :        1363 :                 if (!useless_type_conversion_p (type, TREE_TYPE (ctor)))
    6357                 :           0 :                   ctor = build1 (VIEW_CONVERT_EXPR, type, ctor);
    6358                 :        1363 :                 TREE_OPERAND (*expr_p, 1) = ctor;
    6359                 :             : 
    6360                 :             :                 /* This is no longer an assignment of a CONSTRUCTOR, but
    6361                 :             :                    we still may have processing to do on the LHS.  So
    6362                 :             :                    pretend we didn't do anything here to let that happen.  */
    6363                 :        1363 :                 return GS_UNHANDLED;
    6364                 :             :               }
    6365                 :             :           }
    6366                 :             : 
    6367                 :             :         /* If a single access to the target must be ensured and there are
    6368                 :             :            nonzero elements or the zero elements are not assigned en masse,
    6369                 :             :            initialize the target from a temporary.  */
    6370                 :      922213 :         if (ensure_single_access && (num_nonzero_elements > 0 || !cleared))
    6371                 :             :           {
    6372                 :         157 :             if (notify_temp_creation)
    6373                 :             :               return GS_ERROR;
    6374                 :             : 
    6375                 :         151 :             tree temp = create_tmp_var (TYPE_MAIN_VARIANT (type));
    6376                 :         151 :             TREE_OPERAND (*expr_p, 0) = temp;
    6377                 :         151 :             *expr_p = build2 (COMPOUND_EXPR, TREE_TYPE (*expr_p),
    6378                 :             :                               *expr_p,
    6379                 :             :                               build2 (MODIFY_EXPR, void_type_node,
    6380                 :             :                                       object, temp));
    6381                 :         151 :             return GS_OK;
    6382                 :             :           }
    6383                 :             : 
    6384                 :      922056 :         if (notify_temp_creation)
    6385                 :             :           return GS_OK;
    6386                 :             : 
    6387                 :             :         /* If there are nonzero elements and if needed, pre-evaluate to capture
    6388                 :             :            elements overlapping with the lhs into temporaries.  We must do this
    6389                 :             :            before clearing to fetch the values before they are zeroed-out.  */
    6390                 :      916819 :         if (num_nonzero_elements > 0 && TREE_CODE (*expr_p) != INIT_EXPR)
    6391                 :             :           {
    6392                 :      206203 :             preeval_data.lhs_base_decl = get_base_address (object);
    6393                 :      206203 :             if (!DECL_P (preeval_data.lhs_base_decl))
    6394                 :       40373 :               preeval_data.lhs_base_decl = NULL;
    6395                 :      206203 :             preeval_data.lhs_alias_set = get_alias_set (object);
    6396                 :             : 
    6397                 :      206203 :             gimplify_init_ctor_preeval (&TREE_OPERAND (*expr_p, 1),
    6398                 :             :                                         pre_p, post_p, &preeval_data);
    6399                 :             :           }
    6400                 :             : 
    6401                 :      916819 :         bool ctor_has_side_effects_p
    6402                 :      916819 :           = TREE_SIDE_EFFECTS (TREE_OPERAND (*expr_p, 1));
    6403                 :             : 
    6404                 :      916819 :         if (cleared)
    6405                 :             :           {
    6406                 :             :             /* Zap the CONSTRUCTOR element list, which simplifies this case.
    6407                 :             :                Note that we still have to gimplify, in order to handle the
    6408                 :             :                case of variable sized types.  Avoid shared tree structures.  */
    6409                 :      174359 :             CONSTRUCTOR_ELTS (ctor) = NULL;
    6410                 :      174359 :             TREE_SIDE_EFFECTS (ctor) = 0;
    6411                 :      174359 :             object = unshare_expr (object);
    6412                 :      174359 :             gimplify_stmt (expr_p, pre_p);
    6413                 :             :           }
    6414                 :             : 
    6415                 :             :         /* If we have not block cleared the object, or if there are nonzero
    6416                 :             :            elements in the constructor, or if the constructor has side effects,
    6417                 :             :            add assignments to the individual scalar fields of the object.  */
    6418                 :      174359 :         if (!cleared
    6419                 :      174359 :             || num_nonzero_elements > 0
    6420                 :       15068 :             || ctor_has_side_effects_p)
    6421                 :      902038 :           gimplify_init_ctor_eval (object, elts, pre_p, cleared);
    6422                 :             : 
    6423                 :      916819 :         *expr_p = NULL_TREE;
    6424                 :             :       }
    6425                 :      916819 :       break;
    6426                 :             : 
    6427                 :           0 :     case COMPLEX_TYPE:
    6428                 :           0 :       {
    6429                 :           0 :         tree r, i;
    6430                 :             : 
    6431                 :           0 :         if (notify_temp_creation)
    6432                 :             :           return GS_OK;
    6433                 :             : 
    6434                 :             :         /* Extract the real and imaginary parts out of the ctor.  */
    6435                 :           0 :         gcc_assert (elts->length () == 2);
    6436                 :           0 :         r = (*elts)[0].value;
    6437                 :           0 :         i = (*elts)[1].value;
    6438                 :           0 :         if (r == NULL || i == NULL)
    6439                 :             :           {
    6440                 :           0 :             tree zero = build_zero_cst (TREE_TYPE (type));
    6441                 :           0 :             if (r == NULL)
    6442                 :           0 :               r = zero;
    6443                 :           0 :             if (i == NULL)
    6444                 :           0 :               i = zero;
    6445                 :             :           }
    6446                 :             : 
    6447                 :             :         /* Complex types have either COMPLEX_CST or COMPLEX_EXPR to
    6448                 :             :            represent creation of a complex value.  */
    6449                 :           0 :         if (TREE_CONSTANT (r) && TREE_CONSTANT (i))
    6450                 :             :           {
    6451                 :           0 :             ctor = build_complex (type, r, i);
    6452                 :           0 :             TREE_OPERAND (*expr_p, 1) = ctor;
    6453                 :             :           }
    6454                 :             :         else
    6455                 :             :           {
    6456                 :           0 :             ctor = build2 (COMPLEX_EXPR, type, r, i);
    6457                 :           0 :             TREE_OPERAND (*expr_p, 1) = ctor;
    6458                 :           0 :             ret = gimplify_expr (&TREE_OPERAND (*expr_p, 1),
    6459                 :             :                                  pre_p,
    6460                 :             :                                  post_p,
    6461                 :           0 :                                  rhs_predicate_for (TREE_OPERAND (*expr_p, 0)),
    6462                 :             :                                  fb_rvalue);
    6463                 :             :           }
    6464                 :             :       }
    6465                 :             :       break;
    6466                 :             : 
    6467                 :        6498 :     case VECTOR_TYPE:
    6468                 :        6498 :       {
    6469                 :        6498 :         unsigned HOST_WIDE_INT ix;
    6470                 :        6498 :         constructor_elt *ce;
    6471                 :             : 
    6472                 :        6498 :         if (notify_temp_creation)
    6473                 :     1247310 :           return GS_OK;
    6474                 :             : 
    6475                 :             :         /* Vector types use CONSTRUCTOR all the way through gimple
    6476                 :             :            compilation as a general initializer.  */
    6477                 :       59961 :         FOR_EACH_VEC_SAFE_ELT (elts, ix, ce)
    6478                 :             :           {
    6479                 :       53463 :             enum gimplify_status tret;
    6480                 :       53463 :             tret = gimplify_expr (&ce->value, pre_p, post_p, is_gimple_val,
    6481                 :             :                                   fb_rvalue);
    6482                 :       53463 :             if (tret == GS_ERROR)
    6483                 :             :               ret = GS_ERROR;
    6484                 :       53462 :             else if (TREE_STATIC (ctor)
    6485                 :       53494 :                      && !initializer_constant_valid_p (ce->value,
    6486                 :          32 :                                                        TREE_TYPE (ce->value)))
    6487                 :          32 :               TREE_STATIC (ctor) = 0;
    6488                 :             :           }
    6489                 :        6498 :         recompute_constructor_flags (ctor);
    6490                 :             : 
    6491                 :             :         /* Go ahead and simplify constant constructors to VECTOR_CST.  */
    6492                 :        6498 :         if (TREE_CONSTANT (ctor))
    6493                 :             :           {
    6494                 :         697 :             bool constant_p = true;
    6495                 :             :             tree value;
    6496                 :             : 
    6497                 :             :             /* Even when ctor is constant, it might contain non-*_CST
    6498                 :             :                elements, such as addresses or trapping values like
    6499                 :             :                1.0/0.0 - 1.0/0.0.  Such expressions don't belong
    6500                 :             :                in VECTOR_CST nodes.  */
    6501                 :         697 :             FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
    6502                 :         478 :               if (!CONSTANT_CLASS_P (value))
    6503                 :             :                 {
    6504                 :             :                   constant_p = false;
    6505                 :             :                   break;
    6506                 :             :                 }
    6507                 :             : 
    6508                 :         219 :             if (constant_p)
    6509                 :             :               {
    6510                 :         219 :                 TREE_OPERAND (*expr_p, 1) = build_vector_from_ctor (type, elts);
    6511                 :         219 :                 break;
    6512                 :             :               }
    6513                 :             :           }
    6514                 :             : 
    6515                 :        6279 :         if (!is_gimple_reg (TREE_OPERAND (*expr_p, 0)))
    6516                 :         895 :           TREE_OPERAND (*expr_p, 1) = get_formal_tmp_var (ctor, pre_p);
    6517                 :             :       }
    6518                 :             :       break;
    6519                 :             : 
    6520                 :           0 :     default:
    6521                 :             :       /* So how did we get a CONSTRUCTOR for a scalar type?  */
    6522                 :           0 :       gcc_unreachable ();
    6523                 :             :     }
    6524                 :             : 
    6525                 :     1239142 :   if (ret == GS_ERROR)
    6526                 :             :     return GS_ERROR;
    6527                 :             :   /* If we have gimplified both sides of the initializer but have
    6528                 :             :      not emitted an assignment, do so now.   */
    6529                 :     1239141 :   if (*expr_p
    6530                 :             :       /* If the type is an empty type, we don't need to emit the
    6531                 :             :          assignment. */
    6532                 :     1239141 :       && !is_empty_type (TREE_TYPE (TREE_OPERAND (*expr_p, 0))))
    6533                 :             :     {
    6534                 :      317436 :       tree lhs = TREE_OPERAND (*expr_p, 0);
    6535                 :      317436 :       tree rhs = TREE_OPERAND (*expr_p, 1);
    6536                 :      317436 :       if (want_value && object == lhs)
    6537                 :          12 :         lhs = unshare_expr (lhs);
    6538                 :      317436 :       gassign *init = gimple_build_assign (lhs, rhs);
    6539                 :      317436 :       gimplify_seq_add_stmt (pre_p, init);
    6540                 :             :     }
    6541                 :     1239141 :   if (want_value)
    6542                 :             :     {
    6543                 :          19 :       *expr_p = object;
    6544                 :          19 :       ret = GS_OK;
    6545                 :             :     }
    6546                 :             :   else
    6547                 :             :     {
    6548                 :     1239122 :       *expr_p = NULL;
    6549                 :     1239122 :       ret = GS_ALL_DONE;
    6550                 :             :     }
    6551                 :             : 
    6552                 :             :   /* If the user requests to initialize automatic variables, we
    6553                 :             :      should initialize paddings inside the variable.  Add a call to
    6554                 :             :      __builtin_clear_pading (&object, 0, for_auto_init = true) to
    6555                 :             :      initialize paddings of object always to zero regardless of
    6556                 :             :      INIT_TYPE.  Note, we will not insert this call if the aggregate
    6557                 :             :      variable has be completely cleared already or it's initialized
    6558                 :             :      with an empty constructor.  We cannot insert this call if the
    6559                 :             :      variable is a gimple register since __builtin_clear_padding will take
    6560                 :             :      the address of the variable.  As a result, if a long double/_Complex long
    6561                 :             :      double variable will be spilled into stack later, its padding cannot
    6562                 :             :      be cleared with __builtin_clear_padding.  We should clear its padding
    6563                 :             :      when it is spilled into memory.  */
    6564                 :     1239141 :   if (is_init_expr
    6565                 :      880677 :       && !is_gimple_reg (object)
    6566                 :      876728 :       && clear_padding_type_may_have_padding_p (type)
    6567                 :      839847 :       && ((AGGREGATE_TYPE_P (type) && !cleared && !is_empty_ctor)
    6568                 :      207948 :           || !AGGREGATE_TYPE_P (type))
    6569                 :     1871040 :       && is_var_need_auto_init (object))
    6570                 :          38 :     gimple_add_padding_init_for_auto_var (object, false, pre_p);
    6571                 :             : 
    6572                 :             :   return ret;
    6573                 :             : }
    6574                 :             : 
    6575                 :             : /* Given a pointer value OP0, return a simplified version of an
    6576                 :             :    indirection through OP0, or NULL_TREE if no simplification is
    6577                 :             :    possible.  This may only be applied to a rhs of an expression.
    6578                 :             :    Note that the resulting type may be different from the type pointed
    6579                 :             :    to in the sense that it is still compatible from the langhooks
    6580                 :             :    point of view. */
    6581                 :             : 
    6582                 :             : static tree
    6583                 :      505472 : gimple_fold_indirect_ref_rhs (tree t)
    6584                 :             : {
    6585                 :           0 :   return gimple_fold_indirect_ref (t);
    6586                 :             : }
    6587                 :             : 
    6588                 :             : /* Subroutine of gimplify_modify_expr to do simplifications of
    6589                 :             :    MODIFY_EXPRs based on the code of the RHS.  We loop for as long as
    6590                 :             :    something changes.  */
    6591                 :             : 
    6592                 :             : static enum gimplify_status
    6593                 :    92537565 : gimplify_modify_expr_rhs (tree *expr_p, tree *from_p, tree *to_p,
    6594                 :             :                           gimple_seq *pre_p, gimple_seq *post_p,
    6595                 :             :                           bool want_value)
    6596                 :             : {
    6597                 :    92537565 :   enum gimplify_status ret = GS_UNHANDLED;
    6598                 :    93135002 :   bool changed;
    6599                 :             : 
    6600                 :    91752707 :   do
    6601                 :             :     {
    6602                 :    93135002 :       changed = false;
    6603                 :    93135002 :       switch (TREE_CODE (*from_p))
    6604                 :             :         {
    6605                 :    11586228 :         case VAR_DECL:
    6606                 :             :           /* If we're assigning from a read-only variable initialized with
    6607                 :             :              a constructor and not volatile, do the direct assignment from
    6608                 :             :              the constructor, but only if the target is not volatile either
    6609                 :             :              since this latter assignment might end up being done on a per
    6610                 :             :              field basis.  However, if the target is volatile and the type
    6611                 :             :              is aggregate and non-addressable, gimplify_init_constructor
    6612                 :             :              knows that it needs to ensure a single access to the target
    6613                 :             :              and it will return GS_OK only in this case.  */
    6614                 :    11586228 :           if (TREE_READONLY (*from_p)
    6615                 :       97098 :               && DECL_INITIAL (*from_p)
    6616                 :       64189 :               && TREE_CODE (DECL_INITIAL (*from_p)) == CONSTRUCTOR
    6617                 :        6654 :               && !TREE_THIS_VOLATILE (*from_p)
    6618                 :    11592882 :               && (!TREE_THIS_VOLATILE (*to_p)
    6619                 :           6 :                   || (AGGREGATE_TYPE_P (TREE_TYPE (*to_p))
    6620                 :           6 :                       && !TREE_ADDRESSABLE (TREE_TYPE (*to_p)))))
    6621                 :             :             {
    6622                 :        6654 :               tree old_from = *from_p;
    6623                 :        6654 :               enum gimplify_status subret;
    6624                 :             : 
    6625                 :             :               /* Move the constructor into the RHS.  */
    6626                 :        6654 :               *from_p = unshare_expr (DECL_INITIAL (*from_p));
    6627                 :             : 
    6628                 :             :               /* Let's see if gimplify_init_constructor will need to put
    6629                 :             :                  it in memory.  */
    6630                 :        6654 :               subret = gimplify_init_constructor (expr_p, NULL, NULL,
    6631                 :             :                                                   false, true);
    6632                 :        6654 :               if (subret == GS_ERROR)
    6633                 :             :                 {
    6634                 :             :                   /* If so, revert the change.  */
    6635                 :        1369 :                   *from_p = old_from;
    6636                 :             :                 }
    6637                 :             :               else
    6638                 :             :                 {
    6639                 :             :                   ret = GS_OK;
    6640                 :             :                   changed = true;
    6641                 :             :                 }
    6642                 :             :             }
    6643                 :             :           break;
    6644                 :      508629 :         case INDIRECT_REF:
    6645                 :      508629 :           if (!TREE_ADDRESSABLE (TREE_TYPE (*from_p)))
    6646                 :             :             /* If we have code like
    6647                 :             : 
    6648                 :             :              *(const A*)(A*)&x
    6649                 :             : 
    6650                 :             :              where the type of "x" is a (possibly cv-qualified variant
    6651                 :             :              of "A"), treat the entire expression as identical to "x".
    6652                 :             :              This kind of code arises in C++ when an object is bound
    6653                 :             :              to a const reference, and if "x" is a TARGET_EXPR we want
    6654                 :             :              to take advantage of the optimization below.  But not if
    6655                 :             :              the type is TREE_ADDRESSABLE; then C++17 says that the
    6656                 :             :              TARGET_EXPR needs to be a temporary.  */
    6657                 :     1010944 :             if (tree t
    6658                 :      505472 :                 = gimple_fold_indirect_ref_rhs (TREE_OPERAND (*from_p, 0)))
    6659                 :             :               {
    6660                 :      121607 :                 bool volatile_p = TREE_THIS_VOLATILE (*from_p);
    6661                 :      121607 :                 if (TREE_THIS_VOLATILE (t) != volatile_p)
    6662                 :             :                   {
    6663                 :           5 :                     if (DECL_P (t))
    6664                 :           0 :                       t = build_simple_mem_ref_loc (EXPR_LOCATION (*from_p),
    6665                 :             :                                                     build_fold_addr_expr (t));
    6666                 :           5 :                     if (REFERENCE_CLASS_P (t))
    6667                 :           5 :                       TREE_THIS_VOLATILE (t) = volatile_p;
    6668                 :             :                   }
    6669                 :      121607 :                 *from_p = t;
    6670                 :      121607 :                 ret = GS_OK;
    6671                 :      121607 :                 changed = true;
    6672                 :             :               }
    6673                 :             :           break;
    6674                 :             : 
    6675                 :      175247 :         case TARGET_EXPR:
    6676                 :      175247 :           {
    6677                 :             :             /* If we are initializing something from a TARGET_EXPR, strip the
    6678                 :             :                TARGET_EXPR and initialize it directly, if possible.  This can't
    6679                 :             :                be done if the initializer is void, since that implies that the
    6680                 :             :                temporary is set in some non-trivial way.
    6681                 :             : 
    6682                 :             :                ??? What about code that pulls out the temp and uses it
    6683                 :             :                elsewhere? I think that such code never uses the TARGET_EXPR as
    6684                 :             :                an initializer.  If I'm wrong, we'll die because the temp won't
    6685                 :             :                have any RTL.  In that case, I guess we'll need to replace
    6686                 :             :                references somehow.  */
    6687                 :      175247 :             tree init = TARGET_EXPR_INITIAL (*from_p);
    6688                 :             : 
    6689                 :      175247 :             if (init
    6690                 :      174531 :                 && (TREE_CODE (*expr_p) != MODIFY_EXPR
    6691                 :       57043 :                     || !TARGET_EXPR_NO_ELIDE (*from_p))
    6692                 :      349488 :                 && !VOID_TYPE_P (TREE_TYPE (init)))
    6693                 :             :               {
    6694                 :      153970 :                 *from_p = init;
    6695                 :      153970 :                 ret = GS_OK;
    6696                 :      153970 :                 changed = true;
    6697                 :             :               }
    6698                 :             :           }
    6699                 :             :           break;
    6700                 :             : 
    6701                 :      316366 :         case COMPOUND_EXPR:
    6702                 :             :           /* Remove any COMPOUND_EXPR in the RHS so the following cases will be
    6703                 :             :              caught.  */
    6704                 :      316366 :           gimplify_compound_expr (from_p, pre_p, true);
    6705                 :      316366 :           ret = GS_OK;
    6706                 :      316366 :           changed = true;
    6707                 :      316366 :           break;
    6708                 :             : 
    6709                 :     1256721 :         case CONSTRUCTOR:
    6710                 :             :           /* If we already made some changes, let the front end have a
    6711                 :             :              crack at this before we break it down.  */
    6712                 :     1256721 :           if (ret != GS_UNHANDLED)
    6713                 :             :             break;
    6714                 :             : 
    6715                 :             :           /* If we're initializing from a CONSTRUCTOR, break this into
    6716                 :             :              individual MODIFY_EXPRs.  */
    6717                 :     1240656 :           ret = gimplify_init_constructor (expr_p, pre_p, post_p, want_value,
    6718                 :             :                                            false);
    6719                 :     1240656 :           return ret;
    6720                 :             : 
    6721                 :      215631 :         case COND_EXPR:
    6722                 :             :           /* If we're assigning to a non-register type, push the assignment
    6723                 :             :              down into the branches.  This is mandatory for ADDRESSABLE types,
    6724                 :             :              since we cannot generate temporaries for such, but it saves a
    6725                 :             :              copy in other cases as well.
    6726                 :             :              Also avoid an extra temporary and copy when assigning to
    6727                 :             :              a register.  */
    6728                 :      215631 :           if (!is_gimple_reg_type (TREE_TYPE (*from_p))
    6729                 :      215631 :               || (is_gimple_reg (*to_p) && !gimplify_ctxp->allow_rhs_cond_expr))
    6730                 :             :             {
    6731                 :             :               /* This code should mirror the code in gimplify_cond_expr. */
    6732                 :      135956 :               enum tree_code code = TREE_CODE (*expr_p);
    6733                 :      135956 :               tree cond = *from_p;
    6734                 :      135956 :               tree result = *to_p;
    6735                 :             : 
    6736                 :      135956 :               ret = gimplify_expr (&result, pre_p, post_p,
    6737                 :             :                                    is_gimple_lvalue, fb_lvalue);
    6738                 :      135956 :               if (ret != GS_ERROR)
    6739                 :      135956 :                 ret = GS_OK;
    6740                 :             : 
    6741                 :             :               /* If we are going to write RESULT more than once, clear
    6742                 :             :                  TREE_READONLY flag, otherwise we might incorrectly promote
    6743                 :             :                  the variable to static const and initialize it at compile
    6744                 :             :                  time in one of the branches.  */
    6745                 :      135956 :               if (VAR_P (result)
    6746                 :      134926 :                   && TREE_TYPE (TREE_OPERAND (cond, 1)) != void_type_node
    6747                 :      261809 :                   && TREE_TYPE (TREE_OPERAND (cond, 2)) != void_type_node)
    6748                 :      125829 :                 TREE_READONLY (result) = 0;
    6749                 :      135956 :               if (TREE_TYPE (TREE_OPERAND (cond, 1)) != void_type_node)
    6750                 :      253494 :                 TREE_OPERAND (cond, 1)
    6751                 :      126747 :                   = build2 (code, void_type_node, result,
    6752                 :      126747 :                             TREE_OPERAND (cond, 1));
    6753                 :      135956 :               if (TREE_TYPE (TREE_OPERAND (cond, 2)) != void_type_node)
    6754                 :      271864 :                 TREE_OPERAND (cond, 2)
    6755                 :      135932 :                   = build2 (code, void_type_node, unshare_expr (result),
    6756                 :      135932 :                             TREE_OPERAND (cond, 2));
    6757                 :             : 
    6758                 :      135956 :               TREE_TYPE (cond) = void_type_node;
    6759                 :      135956 :               recalculate_side_effects (cond);
    6760                 :             : 
    6761                 :      135956 :               if (want_value)
    6762                 :             :                 {
    6763                 :          66 :                   gimplify_and_add (cond, pre_p);
    6764                 :          66 :                   *expr_p = unshare_expr (result);
    6765                 :             :                 }
    6766                 :             :               else
    6767                 :      135890 :                 *expr_p = cond;
    6768                 :      135956 :               return ret;
    6769                 :             :             }
    6770                 :             :           break;
    6771                 :             : 
    6772                 :     8965210 :         case CALL_EXPR:
    6773                 :             :           /* For calls that return in memory, give *to_p as the CALL_EXPR's
    6774                 :             :              return slot so that we don't generate a temporary.  */
    6775                 :     8965210 :           if (!CALL_EXPR_RETURN_SLOT_OPT (*from_p)
    6776                 :     8965210 :               && aggregate_value_p (*from_p, *from_p))
    6777                 :             :             {
    6778                 :      235857 :               bool use_target;
    6779                 :             : 
    6780                 :      235857 :               if (!(rhs_predicate_for (*to_p))(*from_p))
    6781                 :             :                 /* If we need a temporary, *to_p isn't accurate.  */
    6782                 :             :                 use_target = false;
    6783                 :             :               /* It's OK to use the return slot directly unless it's an NRV. */
    6784                 :      235116 :               else if (TREE_CODE (*to_p) == RESULT_DECL
    6785                 :        3106 :                        && DECL_NAME (*to_p) == NULL_TREE
    6786                 :      238088 :                        && needs_to_live_in_memory (*to_p))
    6787                 :             :                 use_target = true;
    6788                 :      232144 :               else if (is_gimple_reg_type (TREE_TYPE (*to_p))
    6789                 :      232144 :                        || (DECL_P (*to_p) && DECL_REGISTER (*to_p)))
    6790                 :             :                 /* Don't force regs into memory.  */
    6791                 :             :                 use_target = false;
    6792                 :      218168 :               else if (TREE_CODE (*expr_p) == INIT_EXPR)
    6793                 :             :                 /* It's OK to use the target directly if it's being
    6794                 :             :                    initialized. */
    6795                 :             :                 use_target = true;
    6796                 :       13042 :               else if (TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (*to_p)))
    6797                 :             :                        != INTEGER_CST)
    6798                 :             :                 /* Always use the target and thus RSO for variable-sized types.
    6799                 :             :                    GIMPLE cannot deal with a variable-sized assignment
    6800                 :             :                    embedded in a call statement.  */
    6801                 :             :                 use_target = true;
    6802                 :       13014 :               else if (TREE_CODE (*to_p) != SSA_NAME
    6803                 :       13014 :                       && (!is_gimple_variable (*to_p)
    6804                 :       10036 :                           || needs_to_live_in_memory (*to_p)))
    6805                 :             :                 /* Don't use the original target if it's already addressable;
    6806                 :             :                    if its address escapes, and the called function uses the
    6807                 :             :                    NRV optimization, a conforming program could see *to_p
    6808                 :             :                    change before the called function returns; see c++/19317.
    6809                 :             :                    When optimizing, the return_slot pass marks more functions
    6810                 :             :                    as safe after we have escape info.  */
    6811                 :             :                 use_target = false;
    6812                 :             :               else
    6813                 :             :                 use_target = true;
    6814                 :             : 
    6815                 :             :               if (use_target)
    6816                 :             :                 {
    6817                 :      210177 :                   CALL_EXPR_RETURN_SLOT_OPT (*from_p) = 1;
    6818                 :      210177 :                   mark_addressable (*to_p);
    6819                 :             :                 }
    6820                 :             :             }
    6821                 :             :           break;
    6822                 :             : 
    6823                 :        1366 :         case WITH_SIZE_EXPR:
    6824                 :             :           /* Likewise for calls that return an aggregate of non-constant size,
    6825                 :             :              since we would not be able to generate a temporary at all.  */
    6826                 :        1366 :           if (TREE_CODE (TREE_OPERAND (*from_p, 0)) == CALL_EXPR)
    6827                 :             :             {
    6828                 :         196 :               *from_p = TREE_OPERAND (*from_p, 0);
    6829                 :             :               /* We don't change ret in this case because the
    6830                 :             :                  WITH_SIZE_EXPR might have been added in
    6831                 :             :                  gimplify_modify_expr, so returning GS_OK would lead to an
    6832                 :             :                  infinite loop.  */
    6833                 :         196 :               changed = true;
    6834                 :             :             }
    6835                 :             :           break;
    6836                 :             : 
    6837                 :             :           /* If we're initializing from a container, push the initialization
    6838                 :             :              inside it.  */
    6839                 :        1649 :         case CLEANUP_POINT_EXPR:
    6840                 :        1649 :         case BIND_EXPR:
    6841                 :        1649 :         case STATEMENT_LIST:
    6842                 :        1649 :           {
    6843                 :        1649 :             tree wrap = *from_p;
    6844                 :        1649 :             tree t;
    6845                 :             : 
    6846                 :        1649 :             ret = gimplify_expr (to_p, pre_p, post_p, is_gimple_min_lval,
    6847                 :             :                                  fb_lvalue);
    6848                 :        1649 :             if (ret != GS_ERROR)
    6849                 :        1649 :               ret = GS_OK;
    6850                 :             : 
    6851                 :        1649 :             t = voidify_wrapper_expr (wrap, *expr_p);
    6852                 :        1649 :             gcc_assert (t == *expr_p);
    6853                 :             : 
    6854                 :        1649 :             if (want_value)
    6855                 :             :               {
    6856                 :           6 :                 gimplify_and_add (wrap, pre_p);
    6857                 :           6 :                 *expr_p = unshare_expr (*to_p);
    6858                 :             :               }
    6859                 :             :             else
    6860                 :        1643 :               *expr_p = wrap;
    6861                 :             :             return GS_OK;
    6862                 :             :           }
    6863                 :             : 
    6864                 :     9255152 :         case NOP_EXPR:
    6865                 :             :           /* Pull out compound literal expressions from a NOP_EXPR.
    6866                 :             :              Those are created in the C FE to drop qualifiers during
    6867                 :             :              lvalue conversion.  */
    6868                 :     9255152 :           if ((TREE_CODE (TREE_OPERAND (*from_p, 0)) == COMPOUND_LITERAL_EXPR)
    6869                 :     9255152 :               && tree_ssa_useless_type_conversion (*from_p))
    6870                 :             :             {
    6871                 :          13 :               *from_p = TREE_OPERAND (*from_p, 0);
    6872                 :          13 :               ret = GS_OK;
    6873                 :          13 :               changed = true;
    6874                 :             :             }
    6875                 :             :           break;
    6876                 :             : 
    6877                 :        4034 :         case COMPOUND_LITERAL_EXPR:
    6878                 :        4034 :           {
    6879                 :        4034 :             tree complit = TREE_OPERAND (*expr_p, 1);
    6880                 :        4034 :             tree decl_s = COMPOUND_LITERAL_EXPR_DECL_EXPR (complit);
    6881                 :        4034 :             tree decl = DECL_EXPR_DECL (decl_s);
    6882                 :        4034 :             tree init = DECL_INITIAL (decl);
    6883                 :             : 
    6884                 :             :             /* struct T x = (struct T) { 0, 1, 2 } can be optimized
    6885                 :             :                into struct T x = { 0, 1, 2 } if the address of the
    6886                 :             :                compound literal has never been taken.  */
    6887                 :        4034 :             if (!TREE_ADDRESSABLE (complit)
    6888                 :        4034 :                 && !TREE_ADDRESSABLE (decl)
    6889                 :        4034 :                 && init)
    6890                 :             :               {
    6891                 :        4034 :                 *expr_p = copy_node (*expr_p);
    6892                 :        4034 :                 TREE_OPERAND (*expr_p, 1) = init;
    6893                 :        4034 :                 return GS_OK;
    6894                 :             :               }
    6895                 :             :           }
    6896                 :             : 
    6897                 :             :         default:
    6898                 :             :           break;
    6899                 :             :         }
    6900                 :             :     }
    6901                 :             :   while (changed);
    6902                 :             : 
    6903                 :             :   return ret;
    6904                 :             : }
    6905                 :             : 
    6906                 :             : 
    6907                 :             : /* Return true if T looks like a valid GIMPLE statement.  */
    6908                 :             : 
    6909                 :             : static bool
    6910                 :    18530960 : is_gimple_stmt (tree t)
    6911                 :             : {
    6912                 :    18530960 :   const enum tree_code code = TREE_CODE (t);
    6913                 :             : 
    6914                 :    18530960 :   switch (code)
    6915                 :             :     {
    6916                 :     1657029 :     case NOP_EXPR:
    6917                 :             :       /* The only valid NOP_EXPR is the empty statement.  */
    6918                 :     1657029 :       return IS_EMPTY_STMT (t);
    6919                 :             : 
    6920                 :           0 :     case BIND_EXPR:
    6921                 :           0 :     case COND_EXPR:
    6922                 :             :       /* These are only valid if they're void.  */
    6923                 :           0 :       return TREE_TYPE (t) == NULL || VOID_TYPE_P (TREE_TYPE (t));
    6924                 :             : 
    6925                 :             :     case SWITCH_EXPR:
    6926                 :             :     case GOTO_EXPR:
    6927                 :             :     case RETURN_EXPR:
    6928                 :             :     case LABEL_EXPR:
    6929                 :             :     case CASE_LABEL_EXPR:
    6930                 :             :     case TRY_CATCH_EXPR:
    6931                 :             :     case TRY_FINALLY_EXPR:
    6932                 :             :     case EH_FILTER_EXPR:
    6933                 :             :     case CATCH_EXPR:
    6934                 :             :     case ASM_EXPR:
    6935                 :             :     case STATEMENT_LIST:
    6936                 :             :     case OACC_PARALLEL:
    6937                 :             :     case OACC_KERNELS:
    6938                 :             :     case OACC_SERIAL:
    6939                 :             :     case OACC_DATA:
    6940                 :             :     case OACC_HOST_DATA:
    6941                 :             :     case OACC_DECLARE:
    6942                 :             :     case OACC_UPDATE:
    6943                 :             :     case OACC_ENTER_DATA:
    6944                 :             :     case OACC_EXIT_DATA:
    6945                 :             :     case OACC_CACHE:
    6946                 :             :     case OMP_PARALLEL:
    6947                 :             :     case OMP_FOR:
    6948                 :             :     case OMP_SIMD:
    6949                 :             :     case OMP_DISTRIBUTE:
    6950                 :             :     case OMP_LOOP:
    6951                 :             :     case OMP_TILE:
    6952                 :             :     case OMP_UNROLL:
    6953                 :             :     case OACC_LOOP:
    6954                 :             :     case OMP_SCAN:
    6955                 :             :     case OMP_SCOPE:
    6956                 :             :     case OMP_DISPATCH:
    6957                 :             :     case OMP_SECTIONS:
    6958                 :             :     case OMP_SECTION:
    6959                 :             :     case OMP_STRUCTURED_BLOCK:
    6960                 :             :     case OMP_SINGLE:
    6961                 :             :     case OMP_MASTER:
    6962                 :             :     case OMP_MASKED:
    6963                 :             :     case OMP_TASKGROUP:
    6964                 :             :     case OMP_ORDERED:
    6965                 :             :     case OMP_CRITICAL:
    6966                 :             :     case OMP_METADIRECTIVE:
    6967                 :             :     case OMP_TASK:
    6968                 :             :     case OMP_TARGET:
    6969                 :             :     case OMP_TARGET_DATA:
    6970                 :             :     case OMP_TARGET_UPDATE:
    6971                 :             :     case OMP_TARGET_ENTER_DATA:
    6972                 :             :     case OMP_TARGET_EXIT_DATA:
    6973                 :             :     case OMP_TASKLOOP:
    6974                 :             :     case OMP_TEAMS:
    6975                 :             :       /* These are always void.  */
    6976                 :             :       return true;
    6977                 :             : 
    6978                 :             :     case CALL_EXPR:
    6979                 :             :     case MODIFY_EXPR:
    6980                 :             :     case PREDICT_EXPR:
    6981                 :             :       /* These are valid regardless of their type.  */
    6982                 :             :       return true;
    6983                 :             : 
    6984                 :             :     default:
    6985                 :             :       return false;
    6986                 :             :     }
    6987                 :             : }
    6988                 :             : 
    6989                 :             : 
    6990                 :             : /* Promote partial stores to COMPLEX variables to total stores.  *EXPR_P is
    6991                 :             :    a MODIFY_EXPR with a lhs of a REAL/IMAGPART_EXPR of a gimple register.
    6992                 :             : 
    6993                 :             :    IMPORTANT NOTE: This promotion is performed by introducing a load of the
    6994                 :             :    other, unmodified part of the complex object just before the total store.
    6995                 :             :    As a consequence, if the object is still uninitialized, an undefined value
    6996                 :             :    will be loaded into a register, which may result in a spurious exception
    6997                 :             :    if the register is floating-point and the value happens to be a signaling
    6998                 :             :    NaN for example.  Then the fully-fledged complex operations lowering pass
    6999                 :             :    followed by a DCE pass are necessary in order to fix things up.  */
    7000                 :             : 
    7001                 :             : static enum gimplify_status
    7002                 :        1960 : gimplify_modify_expr_complex_part (tree *expr_p, gimple_seq *pre_p,
    7003                 :             :                                    bool want_value)
    7004                 :             : {
    7005                 :        1960 :   enum tree_code code, ocode;
    7006                 :        1960 :   tree lhs, rhs, new_rhs, other, realpart, imagpart;
    7007                 :             : 
    7008                 :        1960 :   lhs = TREE_OPERAND (*expr_p, 0);
    7009                 :        1960 :   rhs = TREE_OPERAND (*expr_p, 1);
    7010                 :        1960 :   code = TREE_CODE (lhs);
    7011                 :        1960 :   lhs = TREE_OPERAND (lhs, 0);
    7012                 :             : 
    7013                 :        1960 :   ocode = code == REALPART_EXPR ? IMAGPART_EXPR : REALPART_EXPR;
    7014                 :        1960 :   other = build1 (ocode, TREE_TYPE (rhs), lhs);
    7015                 :        1960 :   suppress_warning (other);
    7016                 :        1960 :   other = get_formal_tmp_var (other, pre_p);
    7017                 :             : 
    7018                 :        1960 :   realpart = code == REALPART_EXPR ? rhs : other;
    7019                 :         966 :   imagpart = code == REALPART_EXPR ? other : rhs;
    7020                 :             : 
    7021                 :        1960 :   if (TREE_CONSTANT (realpart) && TREE_CONSTANT (imagpart))
    7022                 :           0 :     new_rhs = build_complex (TREE_TYPE (lhs), realpart, imagpart);
    7023                 :             :   else
    7024                 :        1960 :     new_rhs = build2 (COMPLEX_EXPR, TREE_TYPE (lhs), realpart, imagpart);
    7025                 :             : 
    7026                 :        1960 :   gimplify_seq_add_stmt (pre_p, gimple_build_assign (lhs, new_rhs));
    7027                 :        1960 :   *expr_p = (want_value) ? rhs : NULL_TREE;
    7028                 :             : 
    7029                 :        1960 :   return GS_ALL_DONE;
    7030                 :             : }
    7031                 :             : 
    7032                 :             : /* Gimplify the MODIFY_EXPR node pointed to by EXPR_P.
    7033                 :             : 
    7034                 :             :       modify_expr
    7035                 :             :               : varname '=' rhs
    7036                 :             :               | '*' ID '=' rhs
    7037                 :             : 
    7038                 :             :     PRE_P points to the list where side effects that must happen before
    7039                 :             :         *EXPR_P should be stored.
    7040                 :             : 
    7041                 :             :     POST_P points to the list where side effects that must happen after
    7042                 :             :         *EXPR_P should be stored.
    7043                 :             : 
    7044                 :             :     WANT_VALUE is nonzero iff we want to use the value of this expression
    7045                 :             :         in another expression.  */
    7046                 :             : 
    7047                 :             : static enum gimplify_status
    7048                 :    47877043 : gimplify_modify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
    7049                 :             :                       bool want_value)
    7050                 :             : {
    7051                 :    47877043 :   tree *from_p = &TREE_OPERAND (*expr_p, 1);
    7052                 :    47877043 :   tree *to_p = &TREE_OPERAND (*expr_p, 0);
    7053                 :    47877043 :   enum gimplify_status ret = GS_UNHANDLED;
    7054                 :    47877043 :   gimple *assign;
    7055                 :    47877043 :   location_t loc = EXPR_LOCATION (*expr_p);
    7056                 :    47877043 :   gimple_stmt_iterator gsi;
    7057                 :             : 
    7058                 :    47877043 :   if (error_operand_p (*from_p) || error_operand_p (*to_p))
    7059                 :             :     return GS_ERROR;
    7060                 :             : 
    7061                 :    47877000 :   gcc_assert (TREE_CODE (*expr_p) == MODIFY_EXPR
    7062                 :             :               || TREE_CODE (*expr_p) == INIT_EXPR);
    7063                 :             : 
    7064                 :             :   /* Trying to simplify a clobber using normal logic doesn't work,
    7065                 :             :      so handle it here.  */
    7066                 :    47877000 :   if (TREE_CLOBBER_P (*from_p))
    7067                 :             :     {
    7068                 :      650878 :       ret = gimplify_expr (to_p, pre_p, post_p, is_gimple_lvalue, fb_lvalue);
    7069                 :      650878 :       if (ret == GS_ERROR)
    7070                 :             :         return ret;
    7071                 :      650878 :       gcc_assert (!want_value);
    7072                 :      650878 :       if (!VAR_P (*to_p) && TREE_CODE (*to_p) != MEM_REF)
    7073                 :             :         {
    7074                 :         231 :           tree addr = get_initialized_tmp_var (build_fold_addr_expr (*to_p),
    7075                 :             :                                                pre_p, post_p);
    7076                 :         231 :           *to_p = build_simple_mem_ref_loc (EXPR_LOCATION (*to_p), addr);
    7077                 :             :         }
    7078                 :      650878 :       gimplify_seq_add_stmt (pre_p, gimple_build_assign (*to_p, *from_p));
    7079                 :      650878 :       *expr_p = NULL;
    7080                 :      650878 :       return GS_ALL_DONE;
    7081                 :             :     }
    7082                 :             : 
    7083                 :             :   /* Convert initialization from an empty variable-size CONSTRUCTOR to
    7084                 :             :      memset.  */
    7085                 :    47226122 :   if (TREE_TYPE (*from_p) != error_mark_node
    7086                 :    47226122 :       && TYPE_SIZE_UNIT (TREE_TYPE (*from_p))
    7087                 :    47226122 :       && !poly_int_tree_p (TYPE_SIZE_UNIT (TREE_TYPE (*from_p)))
    7088                 :        1405 :       && TREE_CODE (*from_p) == CONSTRUCTOR
    7089                 :    47226205 :       && CONSTRUCTOR_NELTS (*from_p) == 0)
    7090                 :             :     {
    7091                 :          66 :       maybe_with_size_expr (from_p);
    7092                 :          66 :       gcc_assert (TREE_CODE (*from_p) == WITH_SIZE_EXPR);
    7093                 :          66 :       return gimplify_modify_expr_to_memset (expr_p,
    7094                 :          66 :                                              TREE_OPERAND (*from_p, 1),
    7095                 :          66 :                                              want_value, pre_p);
    7096                 :             :     }
    7097                 :             : 
    7098                 :             :   /* Insert pointer conversions required by the middle-end that are not
    7099                 :             :      required by the frontend.  This fixes middle-end type checking for
    7100                 :             :      for example gcc.dg/redecl-6.c.  */
    7101                 :    47226056 :   if (POINTER_TYPE_P (TREE_TYPE (*to_p)))
    7102                 :             :     {
    7103                 :    12652851 :       STRIP_USELESS_TYPE_CONVERSION (*from_p);
    7104                 :    12652851 :       if (!useless_type_conversion_p (TREE_TYPE (*to_p), TREE_TYPE (*from_p)))
    7105                 :         267 :         *from_p = fold_convert_loc (loc, TREE_TYPE (*to_p), *from_p);
    7106                 :             :     }
    7107                 :             : 
    7108                 :             :   /* See if any simplifications can be done based on what the RHS is.  */
    7109                 :    47226056 :   ret = gimplify_modify_expr_rhs (expr_p, from_p, to_p, pre_p, post_p,
    7110                 :             :                                   want_value);
    7111                 :    47226056 :   if (ret != GS_UNHANDLED)
    7112                 :             :     return ret;
    7113                 :             : 
    7114                 :             :   /* For empty types only gimplify the left hand side and right hand
    7115                 :             :      side as statements and throw away the assignment.  Do this after
    7116                 :             :      gimplify_modify_expr_rhs so we handle TARGET_EXPRs of addressable
    7117                 :             :      types properly.  */
    7118                 :    45313546 :   if (is_empty_type (TREE_TYPE (*from_p))
    7119                 :       11984 :       && !want_value
    7120                 :             :       /* Don't do this for calls that return addressable types, expand_call
    7121                 :             :          relies on those having a lhs.  */
    7122                 :    45325523 :       && !(TREE_ADDRESSABLE (TREE_TYPE (*from_p))
    7123                 :        9973 :            && TREE_CODE (*from_p) == CALL_EXPR))
    7124                 :             :     {
    7125                 :        2004 :       gimplify_stmt (from_p, pre_p);
    7126                 :        2004 :       gimplify_stmt (to_p, pre_p);
    7127                 :        2004 :       *expr_p = NULL_TREE;
    7128                 :        2004 :       return GS_ALL_DONE;
    7129                 :             :     }
    7130                 :             : 
    7131                 :             :   /* If the value being copied is of variable width, compute the length
    7132                 :             :      of the copy into a WITH_SIZE_EXPR.   Note that we need to do this
    7133                 :             :      before gimplifying any of the operands so that we can resolve any
    7134                 :             :      PLACEHOLDER_EXPRs in the size.  Also note that the RTL expander uses
    7135                 :             :      the size of the expression to be copied, not of the destination, so
    7136                 :             :      that is what we must do here.  */
    7137                 :    45311542 :   maybe_with_size_expr (from_p);
    7138                 :             : 
    7139                 :             :   /* As a special case, we have to temporarily allow for assignments
    7140                 :             :      with a CALL_EXPR on the RHS.  Since in GIMPLE a function call is
    7141                 :             :      a toplevel statement, when gimplifying the GENERIC expression
    7142                 :             :      MODIFY_EXPR <a, CALL_EXPR <foo>>, we cannot create the tuple
    7143                 :             :      GIMPLE_ASSIGN <a, GIMPLE_CALL <foo>>.
    7144                 :             : 
    7145                 :             :      Instead, we need to create the tuple GIMPLE_CALL <a, foo>.  To
    7146                 :             :      prevent gimplify_expr from trying to create a new temporary for
    7147                 :             :      foo's LHS, we tell it that it should only gimplify until it
    7148                 :             :      reaches the CALL_EXPR.  On return from gimplify_expr, the newly
    7149                 :             :      created GIMPLE_CALL <foo> will be the last statement in *PRE_P
    7150                 :             :      and all we need to do here is set 'a' to be its LHS.  */
    7151                 :             : 
    7152                 :             :   /* Gimplify the RHS first for C++17 and bug 71104.  */
    7153                 :    45311542 :   gimple_predicate initial_pred = initial_rhs_predicate_for (*to_p);
    7154                 :    45311542 :   ret = gimplify_expr (from_p, pre_p, post_p, initial_pred, fb_rvalue);
    7155                 :    45311542 :   if (ret == GS_ERROR)
    7156                 :             :     return ret;
    7157                 :             : 
    7158                 :             :   /* Then gimplify the LHS.  */
    7159                 :             :   /* If we gimplified the RHS to a CALL_EXPR and that call may return
    7160                 :             :      twice we have to make sure to gimplify into non-SSA as otherwise
    7161                 :             :      the abnormal edge added later will make those defs not dominate
    7162                 :             :      their uses.
    7163                 :             :      ???  Technically this applies only to the registers used in the
    7164                 :             :      resulting non-register *TO_P.  */
    7165                 :    45311509 :   bool saved_into_ssa = gimplify_ctxp->into_ssa;
    7166                 :    45311509 :   if (saved_into_ssa
    7167                 :    43065303 :       && TREE_CODE (*from_p) == CALL_EXPR
    7168                 :    49872389 :       && call_expr_flags (*from_p) & ECF_RETURNS_TWICE)
    7169                 :        1471 :     gimplify_ctxp->into_ssa = false;
    7170                 :    45311509 :   ret = gimplify_expr (to_p, pre_p, post_p, is_gimple_lvalue, fb_lvalue);
    7171                 :    45311509 :   gimplify_ctxp->into_ssa = saved_into_ssa;
    7172                 :    45311509 :   if (ret == GS_ERROR)
    7173                 :             :     return ret;
    7174                 :             : 
    7175                 :             :   /* Now that the LHS is gimplified, re-gimplify the RHS if our initial
    7176                 :             :      guess for the predicate was wrong.  */
    7177                 :    45311509 :   gimple_predicate final_pred = rhs_predicate_for (*to_p);
    7178                 :    45311509 :   if (final_pred != initial_pred)
    7179                 :             :     {
    7180                 :     7703808 :       ret = gimplify_expr (from_p, pre_p, post_p, final_pred, fb_rvalue);
    7181                 :     7703808 :       if (ret == GS_ERROR)
    7182                 :             :         return ret;
    7183                 :             :     }
    7184                 :             : 
    7185                 :             :   /* In case of va_arg internal fn wrappped in a WITH_SIZE_EXPR, add the type
    7186                 :             :      size as argument to the call.  */
    7187                 :    45311509 :   if (TREE_CODE (*from_p) == WITH_SIZE_EXPR)
    7188                 :             :     {
    7189                 :        1267 :       tree call = TREE_OPERAND (*from_p, 0);
    7190                 :        1267 :       tree vlasize = TREE_OPERAND (*from_p, 1);
    7191                 :             : 
    7192                 :        1267 :       if (TREE_CODE (call) == CALL_EXPR
    7193                 :        1267 :           && CALL_EXPR_IFN (call) == IFN_VA_ARG)
    7194                 :             :         {
    7195                 :          95 :           int nargs = call_expr_nargs (call);
    7196                 :          95 :           tree type = TREE_TYPE (call);
    7197                 :          95 :           tree ap = CALL_EXPR_ARG (call, 0);
    7198                 :          95 :           tree tag = CALL_EXPR_ARG (call, 1);
    7199                 :          95 :           tree aptag = CALL_EXPR_ARG (call, 2);
    7200                 :          95 :           tree newcall = build_call_expr_internal_loc (EXPR_LOCATION (call),
    7201                 :             :                                                        IFN_VA_ARG, type,
    7202                 :             :                                                        nargs + 1, ap, tag,
    7203                 :             :                                                        aptag, vlasize);
    7204                 :          95 :           TREE_OPERAND (*from_p, 0) = newcall;
    7205                 :             :         }
    7206                 :             :     }
    7207                 :             : 
    7208                 :             :   /* Now see if the above changed *from_p to something we handle specially.  */
    7209                 :    45311509 :   ret = gimplify_modify_expr_rhs (expr_p, from_p, to_p, pre_p, post_p,
    7210                 :             :                                   want_value);
    7211                 :    45311509 :   if (ret != GS_UNHANDLED)
    7212                 :             :     return ret;
    7213                 :             : 
    7214                 :             :   /* If we've got a variable sized assignment between two lvalues (i.e. does
    7215                 :             :      not involve a call), then we can make things a bit more straightforward
    7216                 :             :      by converting the assignment to memcpy or memset.  */
    7217                 :    45310649 :   if (TREE_CODE (*from_p) == WITH_SIZE_EXPR)
    7218                 :             :     {
    7219                 :        1071 :       tree from = TREE_OPERAND (*from_p, 0);
    7220                 :        1071 :       tree size = TREE_OPERAND (*from_p, 1);
    7221                 :             : 
    7222                 :        1071 :       if (TREE_CODE (from) == CONSTRUCTOR)
    7223                 :           0 :         return gimplify_modify_expr_to_memset (expr_p, size, want_value, pre_p);
    7224                 :        1071 :       else if (is_gimple_addressable (from)
    7225                 :        1071 :                && ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (TREE_TYPE (*to_p)))
    7226                 :        2141 :                && ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (TREE_TYPE (from))))
    7227                 :             :         {
    7228                 :        1070 :           *from_p = from;
    7229                 :        1070 :           return gimplify_modify_expr_to_memcpy (expr_p, size, want_value,
    7230                 :        1070 :                                                  pre_p);
    7231                 :             :         }
    7232                 :             :     }
    7233                 :             : 
    7234                 :             :   /* Transform partial stores to non-addressable complex variables into
    7235                 :             :      total stores.  This allows us to use real instead of virtual operands
    7236                 :             :      for these variables, which improves optimization.  */
    7237                 :    45309579 :   if ((TREE_CODE (*to_p) == REALPART_EXPR
    7238                 :    45309579 :        || TREE_CODE (*to_p) == IMAGPART_EXPR)
    7239                 :    45309579 :       && is_gimple_reg (TREE_OPERAND (*to_p, 0)))
    7240                 :        1960 :     return gimplify_modify_expr_complex_part (expr_p, pre_p, want_value);
    7241                 :             : 
    7242                 :             :   /* Try to alleviate the effects of the gimplification creating artificial
    7243                 :             :      temporaries (see for example is_gimple_reg_rhs) on the debug info, but
    7244                 :             :      make sure not to create DECL_DEBUG_EXPR links across functions.  */
    7245                 :    45307619 :   if (!gimplify_ctxp->into_ssa
    7246                 :     2245311 :       && VAR_P (*from_p)
    7247                 :      444624 :       && DECL_IGNORED_P (*from_p)
    7248                 :      325088 :       && DECL_P (*to_p)
    7249                 :      119391 :       && !DECL_IGNORED_P (*to_p)
    7250                 :       28890 :       && decl_function_context (*to_p) == current_function_decl
    7251                 :    45331061 :       && decl_function_context (*from_p) == current_function_decl)
    7252                 :             :     {
    7253                 :       23437 :       if (!DECL_NAME (*from_p) && DECL_NAME (*to_p))
    7254                 :       36414 :         DECL_NAME (*from_p)
    7255                 :       18207 :           = create_tmp_var_name (IDENTIFIER_POINTER (DECL_NAME (*to_p)));
    7256                 :       23437 :       DECL_HAS_DEBUG_EXPR_P (*from_p) = 1;
    7257                 :       23437 :       SET_DECL_DEBUG_EXPR (*from_p, *to_p);
    7258                 :             :    }
    7259                 :             : 
    7260                 :    45307619 :   if (want_value && TREE_THIS_VOLATILE (*to_p))
    7261                 :         647 :     *from_p = get_initialized_tmp_var (*from_p, pre_p, post_p);
    7262                 :             : 
    7263                 :    45307619 :   if (TREE_CODE (*from_p) == CALL_EXPR)
    7264                 :             :     {
    7265                 :             :       /* Since the RHS is a CALL_EXPR, we need to create a GIMPLE_CALL
    7266                 :             :          instead of a GIMPLE_ASSIGN.  */
    7267                 :     4279833 :       gcall *call_stmt;
    7268                 :     4279833 :       if (CALL_EXPR_FN (*from_p) == NULL_TREE)
    7269                 :             :         {
    7270                 :             :           /* Gimplify internal functions created in the FEs.  */
    7271                 :      174981 :           int nargs = call_expr_nargs (*from_p), i;
    7272                 :      174981 :           enum internal_fn ifn = CALL_EXPR_IFN (*from_p);
    7273                 :      174981 :           auto_vec<tree> vargs (nargs);
    7274                 :             : 
    7275                 :      895011 :           for (i = 0; i < nargs; i++)
    7276                 :             :             {
    7277                 :      545049 :               gimplify_arg (&CALL_EXPR_ARG (*from_p, i), pre_p,
    7278                 :      545049 :                             EXPR_LOCATION (*from_p));
    7279                 :      545049 :               vargs.quick_push (CALL_EXPR_ARG (*from_p, i));
    7280                 :             :             }
    7281                 :      174981 :           call_stmt = gimple_build_call_internal_vec (ifn, vargs);
    7282                 :      174981 :           gimple_call_set_nothrow (call_stmt, TREE_NOTHROW (*from_p));
    7283                 :      349962 :           gimple_set_location (call_stmt, EXPR_LOCATION (*expr_p));
    7284                 :      174981 :         }
    7285                 :             :       else
    7286                 :             :         {
    7287                 :     4104852 :           tree fnptrtype = TREE_TYPE (CALL_EXPR_FN (*from_p));
    7288                 :     4104852 :           CALL_EXPR_FN (*from_p) = TREE_OPERAND (CALL_EXPR_FN (*from_p), 0);
    7289                 :     4104852 :           STRIP_USELESS_TYPE_CONVERSION (CALL_EXPR_FN (*from_p));
    7290                 :     4104852 :           tree fndecl = get_callee_fndecl (*from_p);
    7291                 :     4104852 :           if (fndecl
    7292                 :     3991454 :               && fndecl_built_in_p (fndecl, BUILT_IN_EXPECT)
    7293                 :     4224659 :               && call_expr_nargs (*from_p) == 3)
    7294                 :       60136 :             call_stmt = gimple_build_call_internal (IFN_BUILTIN_EXPECT, 3,
    7295                 :       60136 :                                                     CALL_EXPR_ARG (*from_p, 0),
    7296                 :       60136 :                                                     CALL_EXPR_ARG (*from_p, 1),
    7297                 :       60136 :                                                     CALL_EXPR_ARG (*from_p, 2));
    7298                 :             :           else
    7299                 :             :             {
    7300                 :     4044716 :               call_stmt = gimple_build_call_from_tree (*from_p, fnptrtype);
    7301                 :             :             }
    7302                 :             :         }
    7303                 :     4279833 :       notice_special_calls (call_stmt);
    7304                 :     4279833 :       if (!gimple_call_noreturn_p (call_stmt) || !should_remove_lhs_p (*to_p))
    7305                 :     4279051 :         gimple_call_set_lhs (call_stmt, *to_p);
    7306                 :         782 :       else if (TREE_CODE (*to_p) == SSA_NAME)
    7307                 :             :         /* The above is somewhat premature, avoid ICEing later for a
    7308                 :             :            SSA name w/o a definition.  We may have uses in the GIMPLE IL.
    7309                 :             :            ???  This doesn't make it a default-def.  */
    7310                 :           8 :         SSA_NAME_DEF_STMT (*to_p) = gimple_build_nop ();
    7311                 :             : 
    7312                 :             :       assign = call_stmt;
    7313                 :             :     }
    7314                 :             :   else
    7315                 :             :     {
    7316                 :    41027786 :       assign = gimple_build_assign (*to_p, *from_p);
    7317                 :    41027786 :       gimple_set_location (assign, EXPR_LOCATION (*expr_p));
    7318                 :    41027786 :       if (COMPARISON_CLASS_P (*from_p))
    7319                 :     1161685 :         copy_warning (assign, *from_p);
    7320                 :             :     }
    7321                 :             : 
    7322                 :    45307619 :   if (gimplify_ctxp->into_ssa && is_gimple_reg (*to_p))
    7323                 :             :     {
    7324                 :             :       /* We should have got an SSA name from the start.  */
    7325                 :    33599986 :       gcc_assert (TREE_CODE (*to_p) == SSA_NAME
    7326                 :             :                   || ! gimple_in_ssa_p (cfun));
    7327                 :             :     }
    7328                 :             : 
    7329                 :    45307619 :   gimplify_seq_add_stmt (pre_p, assign);
    7330                 :    45307619 :   gsi = gsi_last (*pre_p);
    7331                 :    45307619 :   maybe_fold_stmt (&gsi);
    7332                 :             : 
    7333                 :    45307619 :   if (want_value)
    7334                 :             :     {
    7335                 :      597549 :       *expr_p = TREE_THIS_VOLATILE (*to_p) ? *from_p : unshare_expr (*to_p);
    7336                 :      597549 :       return GS_OK;
    7337                 :             :     }
    7338                 :             :   else
    7339                 :    44710070 :     *expr_p = NULL;
    7340                 :             : 
    7341                 :    44710070 :   return GS_ALL_DONE;
    7342                 :             : }
    7343                 :             : 
    7344                 :             : /* Gimplify a comparison between two variable-sized objects.  Do this
    7345                 :             :    with a call to BUILT_IN_MEMCMP.  */
    7346                 :             : 
    7347                 :             : static enum gimplify_status
    7348                 :           0 : gimplify_variable_sized_compare (tree *expr_p)
    7349                 :             : {
    7350                 :           0 :   location_t loc = EXPR_LOCATION (*expr_p);
    7351                 :           0 :   tree op0 = TREE_OPERAND (*expr_p, 0);
    7352                 :           0 :   tree op1 = TREE_OPERAND (*expr_p, 1);
    7353                 :           0 :   tree t, arg, dest, src, expr;
    7354                 :             : 
    7355                 :           0 :   arg = TYPE_SIZE_UNIT (TREE_TYPE (op0));
    7356                 :           0 :   arg = unshare_expr (arg);
    7357                 :           0 :   arg = SUBSTITUTE_PLACEHOLDER_IN_EXPR (arg, op0);
    7358                 :           0 :   src = build_fold_addr_expr_loc (loc, op1);
    7359                 :           0 :   dest = build_fold_addr_expr_loc (loc, op0);
    7360                 :           0 :   t = builtin_decl_implicit (BUILT_IN_MEMCMP);
    7361                 :           0 :   t = build_call_expr_loc (loc, t, 3, dest, src, arg);
    7362                 :             : 
    7363                 :           0 :   expr
    7364                 :           0 :     = build2 (TREE_CODE (*expr_p), TREE_TYPE (*expr_p), t, integer_zero_node);
    7365                 :           0 :   SET_EXPR_LOCATION (expr, loc);
    7366                 :           0 :   *expr_p = expr;
    7367                 :             : 
    7368                 :           0 :   return GS_OK;
    7369                 :             : }
    7370                 :             : 
    7371                 :             : /* Gimplify a comparison between two aggregate objects of integral scalar
    7372                 :             :    mode as a comparison between the bitwise equivalent scalar values.  */
    7373                 :             : 
    7374                 :             : static enum gimplify_status
    7375                 :          14 : gimplify_scalar_mode_aggregate_compare (tree *expr_p)
    7376                 :             : {
    7377                 :          14 :   const location_t loc = EXPR_LOCATION (*expr_p);
    7378                 :          14 :   const enum tree_code code = TREE_CODE (*expr_p);
    7379                 :          14 :   tree op0 = TREE_OPERAND (*expr_p, 0);
    7380                 :          14 :   tree op1 = TREE_OPERAND (*expr_p, 1);
    7381                 :          14 :   tree type = TREE_TYPE (op0);
    7382                 :          14 :   tree scalar_type = lang_hooks.types.type_for_mode (TYPE_MODE (type), 1);
    7383                 :             : 
    7384                 :          14 :   op0 = fold_build1_loc (loc, VIEW_CONVERT_EXPR, scalar_type, op0);
    7385                 :          14 :   op1 = fold_build1_loc (loc, VIEW_CONVERT_EXPR, scalar_type, op1);
    7386                 :             : 
    7387                 :             :   /* We need to perform ordering comparisons in memory order like memcmp and,
    7388                 :             :      therefore, may need to byte-swap operands for little-endian targets.  */
    7389                 :          14 :   if (code != EQ_EXPR && code != NE_EXPR)
    7390                 :             :     {
    7391                 :           0 :       gcc_assert (BYTES_BIG_ENDIAN == WORDS_BIG_ENDIAN);
    7392                 :           0 :       gcc_assert (TREE_CODE (scalar_type) == INTEGER_TYPE);
    7393                 :           0 :       tree fndecl;
    7394                 :             : 
    7395                 :           0 :       if (BYTES_BIG_ENDIAN)
    7396                 :             :         fndecl = NULL_TREE;
    7397                 :             :       else
    7398                 :           0 :         switch (int_size_in_bytes (scalar_type))
    7399                 :             :           {
    7400                 :             :           case 1:
    7401                 :             :             fndecl = NULL_TREE;
    7402                 :             :             break;
    7403                 :           0 :           case 2:
    7404                 :           0 :             fndecl = builtin_decl_implicit (BUILT_IN_BSWAP16);
    7405                 :           0 :             break;
    7406                 :           0 :           case 4:
    7407                 :           0 :             fndecl = builtin_decl_implicit (BUILT_IN_BSWAP32);
    7408                 :           0 :             break;
    7409                 :           0 :           case 8:
    7410                 :           0 :             fndecl = builtin_decl_implicit (BUILT_IN_BSWAP64);
    7411                 :           0 :             break;
    7412                 :           0 :           case 16:
    7413                 :           0 :             fndecl = builtin_decl_implicit (BUILT_IN_BSWAP128);
    7414                 :           0 :             break;
    7415                 :           0 :           default:
    7416                 :           0 :             gcc_unreachable ();
    7417                 :             :           }
    7418                 :             : 
    7419                 :           0 :       if (fndecl)
    7420                 :             :         {
    7421                 :           0 :           op0 = build_call_expr_loc (loc, fndecl, 1, op0);
    7422                 :           0 :           op1 = build_call_expr_loc (loc, fndecl, 1, op1);
    7423                 :             :         }
    7424                 :             :     }
    7425                 :             : 
    7426                 :          14 :   *expr_p = fold_build2_loc (loc, code, TREE_TYPE (*expr_p), op0, op1);
    7427                 :             : 
    7428                 :          14 :   return GS_OK;
    7429                 :             : }
    7430                 :             : 
    7431                 :             : /* Gimplify an expression sequence.  This function gimplifies each
    7432                 :             :    expression and rewrites the original expression with the last
    7433                 :             :    expression of the sequence in GIMPLE form.
    7434                 :             : 
    7435                 :             :    PRE_P points to the list where the side effects for all the
    7436                 :             :        expressions in the sequence will be emitted.
    7437                 :             : 
    7438                 :             :    WANT_VALUE is true when the result of the last COMPOUND_EXPR is used.  */
    7439                 :             : 
    7440                 :             : static enum gimplify_status
    7441                 :      944944 : gimplify_compound_expr (tree *expr_p, gimple_seq *pre_p, bool want_value)
    7442                 :             : {
    7443                 :      944944 :   tree t = *expr_p;
    7444                 :             : 
    7445                 :     1004275 :   do
    7446                 :             :     {
    7447                 :     1004275 :       tree *sub_p = &TREE_OPERAND (t, 0);
    7448                 :             : 
    7449                 :     1004275 :       if (TREE_CODE (*sub_p) == COMPOUND_EXPR)
    7450                 :      180759 :         gimplify_compound_expr (sub_p, pre_p, false);
    7451                 :             :       else
    7452                 :      823516 :         gimplify_stmt (sub_p, pre_p);
    7453                 :             : 
    7454                 :     1004275 :       t = TREE_OPERAND (t, 1);
    7455                 :             :     }
    7456                 :     1004275 :   while (TREE_CODE (t) == COMPOUND_EXPR);
    7457                 :             : 
    7458                 :      944944 :   *expr_p = t;
    7459                 :      944944 :   if (want_value)
    7460                 :             :     return GS_OK;
    7461                 :             :   else
    7462                 :             :     {
    7463                 :      469142 :       gimplify_stmt (expr_p, pre_p);
    7464                 :      469142 :       return GS_ALL_DONE;
    7465                 :             :     }
    7466                 :             : }
    7467                 :             : 
    7468                 :             : /* Gimplify a SAVE_EXPR node.  EXPR_P points to the expression to
    7469                 :             :    gimplify.  After gimplification, EXPR_P will point to a new temporary
    7470                 :             :    that holds the original value of the SAVE_EXPR node.
    7471                 :             : 
    7472                 :             :    PRE_P points to the list where side effects that must happen before
    7473                 :             :    *EXPR_P should be stored.  */
    7474                 :             : 
    7475                 :             : static enum gimplify_status
    7476                 :      407976 : gimplify_save_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p)
    7477                 :             : {
    7478                 :      407976 :   enum gimplify_status ret = GS_ALL_DONE;
    7479                 :      407976 :   tree val;
    7480                 :             : 
    7481                 :      407976 :   gcc_assert (TREE_CODE (*expr_p) == SAVE_EXPR);
    7482                 :      407976 :   val = TREE_OPERAND (*expr_p, 0);
    7483                 :             : 
    7484                 :      407976 :   if (val && TREE_TYPE (val) == error_mark_node)
    7485                 :             :     return GS_ERROR;
    7486                 :             : 
    7487                 :             :   /* If the SAVE_EXPR has not been resolved, then evaluate it once.  */
    7488                 :      407974 :   if (!SAVE_EXPR_RESOLVED_P (*expr_p))
    7489                 :             :     {
    7490                 :             :       /* The operand may be a void-valued expression.  It is
    7491                 :             :          being executed only for its side-effects.  */
    7492                 :      152734 :       if (TREE_TYPE (val) == void_type_node)
    7493                 :             :         {
    7494                 :           0 :           ret = gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p,
    7495                 :             :                                is_gimple_stmt, fb_none);
    7496                 :           0 :           val = NULL;
    7497                 :             :         }
    7498                 :             :       else
    7499                 :             :         /* The temporary may not be an SSA name as later abnormal and EH
    7500                 :             :            control flow may invalidate use/def domination.  When in SSA
    7501                 :             :            form then assume there are no such issues and SAVE_EXPRs only
    7502                 :             :            appear via GENERIC foldings.  */
    7503                 :      305468 :         val = get_initialized_tmp_var (val, pre_p, post_p,
    7504                 :      305468 :                                        gimple_in_ssa_p (cfun));
    7505                 :             : 
    7506                 :      152734 :       TREE_OPERAND (*expr_p, 0) = val;
    7507                 :      152734 :       SAVE_EXPR_RESOLVED_P (*expr_p) = 1;
    7508                 :             :     }
    7509                 :             : 
    7510                 :      407974 :   *expr_p = val;
    7511                 :             : 
    7512                 :      407974 :   return ret;
    7513                 :             : }
    7514                 :             : 
    7515                 :             : /* Rewrite the ADDR_EXPR node pointed to by EXPR_P
    7516                 :             : 
    7517                 :             :       unary_expr
    7518                 :             :               : ...
    7519                 :             :               | '&' varname
    7520                 :             :               ...
    7521                 :             : 
    7522                 :             :     PRE_P points to the list where side effects that must happen before
    7523                 :             :         *EXPR_P should be stored.
    7524                 :             : 
    7525                 :             :     POST_P points to the list where side effects that must happen after
    7526                 :             :         *EXPR_P should be stored.  */
    7527                 :             : 
    7528                 :             : static enum gimplify_status
    7529                 :    30603020 : gimplify_addr_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p)
    7530                 :             : {
    7531                 :    30603020 :   tree expr = *expr_p;
    7532                 :    30603020 :   tree op0 = TREE_OPERAND (expr, 0);
    7533                 :    30603020 :   enum gimplify_status ret;
    7534                 :    30603020 :   location_t loc = EXPR_LOCATION (*expr_p);
    7535                 :             : 
    7536                 :    30603020 :   switch (TREE_CODE (op0))
    7537                 :             :     {
    7538                 :       86754 :     case INDIRECT_REF:
    7539                 :       86754 :     do_indirect_ref:
    7540                 :             :       /* Check if we are dealing with an expression of the form '&*ptr'.
    7541                 :             :          While the front end folds away '&*ptr' into 'ptr', these
    7542                 :             :          expressions may be generated internally by the compiler (e.g.,
    7543                 :             :          builtins like __builtin_va_end).  */
    7544                 :             :       /* Caution: the silent array decomposition semantics we allow for
    7545                 :             :          ADDR_EXPR means we can't always discard the pair.  */
    7546                 :             :       /* Gimplification of the ADDR_EXPR operand may drop
    7547                 :             :          cv-qualification conversions, so make sure we add them if
    7548                 :             :          needed.  */
    7549                 :       86754 :       {
    7550                 :       86754 :         tree op00 = TREE_OPERAND (op0, 0);
    7551                 :       86754 :         tree t_expr = TREE_TYPE (expr);
    7552                 :       86754 :         tree t_op00 = TREE_TYPE (op00);
    7553                 :             : 
    7554                 :       86754 :         if (!useless_type_conversion_p (t_expr, t_op00))
    7555                 :           0 :           op00 = fold_convert_loc (loc, TREE_TYPE (expr), op00);
    7556                 :       86754 :         *expr_p = op00;
    7557                 :       86754 :         ret = GS_OK;
    7558                 :             :       }
    7559                 :       86754 :       break;
    7560                 :             : 
    7561                 :           0 :     case VIEW_CONVERT_EXPR:
    7562                 :             :       /* Take the address of our operand and then convert it to the type of
    7563                 :             :          this ADDR_EXPR.
    7564                 :             : 
    7565                 :             :          ??? The interactions of VIEW_CONVERT_EXPR and aliasing is not at
    7566                 :             :          all clear.  The impact of this transformation is even less clear.  */
    7567                 :             : 
    7568                 :             :       /* If the operand is a useless conversion, look through it.  Doing so
    7569                 :             :          guarantees that the ADDR_EXPR and its operand will remain of the
    7570                 :             :          same type.  */
    7571                 :           0 :       if (tree_ssa_useless_type_conversion (TREE_OPERAND (op0, 0)))
    7572                 :           0 :         op0 = TREE_OPERAND (op0, 0);
    7573                 :             : 
    7574                 :           0 :       *expr_p = fold_convert_loc (loc, TREE_TYPE (expr),
    7575                 :             :                                   build_fold_addr_expr_loc (loc,
    7576                 :           0 :                                                         TREE_OPERAND (op0, 0)));
    7577                 :           0 :       ret = GS_OK;
    7578                 :           0 :       break;
    7579                 :             : 
    7580                 :       47949 :     case MEM_REF:
    7581                 :       47949 :       if (integer_zerop (TREE_OPERAND (op0, 1)))
    7582                 :       30970 :         goto do_indirect_ref;
    7583                 :             : 
    7584                 :             :       /* fall through */
    7585                 :             : 
    7586                 :    30531384 :     default:
    7587                 :             :       /* If we see a call to a declared builtin or see its address
    7588                 :             :          being taken (we can unify those cases here) then we can mark
    7589                 :             :          the builtin for implicit generation by GCC.  */
    7590                 :    30531384 :       if (TREE_CODE (op0) == FUNCTION_DECL
    7591                 :    15307180 :           && fndecl_built_in_p (op0, BUILT_IN_NORMAL)
    7592                 :    34284983 :           && builtin_decl_declared_p (DECL_FUNCTION_CODE (op0)))
    7593                 :     1235318 :         set_builtin_decl_implicit_p (DECL_FUNCTION_CODE (op0), true);
    7594                 :             : 
    7595                 :             :       /* We use fb_either here because the C frontend sometimes takes
    7596                 :             :          the address of a call that returns a struct; see
    7597                 :             :          gcc.dg/c99-array-lval-1.c.  The gimplifier will correctly make
    7598                 :             :          the implied temporary explicit.  */
    7599                 :             : 
    7600                 :             :       /* Make the operand addressable.  */
    7601                 :    30531384 :       ret = gimplify_expr (&TREE_OPERAND (expr, 0), pre_p, post_p,
    7602                 :             :                            is_gimple_addressable, fb_either);
    7603                 :    30531384 :       if (ret == GS_ERROR)
    7604                 :             :         break;
    7605                 :             : 
    7606                 :             :       /* Then mark it.  Beware that it may not be possible to do so directly
    7607                 :             :          if a temporary has been created by the gimplification.  */
    7608                 :    30531382 :       prepare_gimple_addressable (&TREE_OPERAND (expr, 0), pre_p);
    7609                 :             : 
    7610                 :    30531382 :       op0 = TREE_OPERAND (expr, 0);
    7611                 :             : 
    7612                 :             :       /* For various reasons, the gimplification of the expression
    7613                 :             :          may have made a new INDIRECT_REF.  */
    7614                 :    30531382 :       if (INDIRECT_REF_P (op0)
    7615                 :    30531382 :           || (TREE_CODE (op0) == MEM_REF
    7616                 :       32097 :               && integer_zerop (TREE_OPERAND (op0, 1))))
    7617                 :       15118 :         goto do_indirect_ref;
    7618                 :             : 
    7619                 :    30516264 :       mark_addressable (TREE_OPERAND (expr, 0));
    7620                 :             : 
    7621                 :             :       /* The FEs may end up building ADDR_EXPRs early on a decl with
    7622                 :             :          an incomplete type.  Re-build ADDR_EXPRs in canonical form
    7623                 :             :          here.  */
    7624                 :    30516264 :       if (!types_compatible_p (TREE_TYPE (op0), TREE_TYPE (TREE_TYPE (expr))))
    7625                 :      143763 :         *expr_p = build_fold_addr_expr (op0);
    7626                 :             : 
    7627                 :             :       /* Make sure TREE_CONSTANT and TREE_SIDE_EFFECTS are set properly.  */
    7628                 :    30516264 :       if (TREE_CODE (*expr_p) == ADDR_EXPR)
    7629                 :    30516263 :         recompute_tree_invariant_for_addr_expr (*expr_p);
    7630                 :             : 
    7631                 :             :       /* If we re-built the ADDR_EXPR add a conversion to the original type
    7632                 :             :          if required.  */
    7633                 :    30516264 :       if (!useless_type_conversion_p (TREE_TYPE (expr), TREE_TYPE (*expr_p)))
    7634                 :           0 :         *expr_p = fold_convert (TREE_TYPE (expr), *expr_p);
    7635                 :             : 
    7636                 :             :       break;
    7637                 :             :     }
    7638                 :             : 
    7639                 :    30603020 :   return ret;
    7640                 :             : }
    7641                 :             : 
    7642                 :             : /* Gimplify the operands of an ASM_EXPR.  Input operands should be a gimple
    7643                 :             :    value; output operands should be a gimple lvalue.  */
    7644                 :             : 
    7645                 :             : static enum gimplify_status
    7646                 :       94867 : gimplify_asm_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p)
    7647                 :             : {
    7648                 :       94867 :   tree expr;
    7649                 :       94867 :   int noutputs;
    7650                 :       94867 :   const char **oconstraints;
    7651                 :       94867 :   int i;
    7652                 :       94867 :   tree link;
    7653                 :       94867 :   const char *constraint;
    7654                 :       94867 :   bool allows_mem, allows_reg, is_inout;
    7655                 :       94867 :   enum gimplify_status ret, tret;
    7656                 :       94867 :   gasm *stmt;
    7657                 :       94867 :   vec<tree, va_gc> *inputs;
    7658                 :       94867 :   vec<tree, va_gc> *outputs;
    7659                 :       94867 :   vec<tree, va_gc> *clobbers;
    7660                 :       94867 :   vec<tree, va_gc> *labels;
    7661                 :       94867 :   tree link_next;
    7662                 :             : 
    7663                 :       94867 :   expr = *expr_p;
    7664                 :       94867 :   noutputs = list_length (ASM_OUTPUTS (expr));
    7665                 :       94867 :   oconstraints = (const char **) alloca ((noutputs) * sizeof (const char *));
    7666                 :             : 
    7667                 :       94867 :   inputs = NULL;
    7668                 :       94867 :   outputs = NULL;
    7669                 :       94867 :   clobbers = NULL;
    7670                 :       94867 :   labels = NULL;
    7671                 :             : 
    7672                 :       94867 :   ret = GS_ALL_DONE;
    7673                 :       94867 :   link_next = NULL_TREE;
    7674                 :      152182 :   for (i = 0, link = ASM_OUTPUTS (expr); link; ++i, link = link_next)
    7675                 :             :     {
    7676                 :       57327 :       bool ok;
    7677                 :       57327 :       size_t constraint_len;
    7678                 :             : 
    7679                 :       57327 :       link_next = TREE_CHAIN (link);
    7680                 :             : 
    7681                 :      114654 :       oconstraints[i]
    7682                 :       57327 :         = constraint
    7683                 :       57327 :         = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link)));
    7684                 :       57327 :       constraint_len = strlen (constraint);
    7685                 :       57327 :       if (constraint_len == 0)
    7686                 :           6 :         continue;
    7687                 :             : 
    7688                 :       57321 :       ok = parse_output_constraint (&constraint, i, 0, 0,
    7689                 :             :                                     &allows_mem, &allows_reg, &is_inout);
    7690                 :       57321 :       if (!ok)
    7691                 :             :         {
    7692                 :           3 :           ret = GS_ERROR;
    7693                 :           3 :           is_inout = false;
    7694                 :             :         }
    7695                 :             : 
    7696                 :             :       /* If we can't make copies, we can only accept memory.
    7697                 :             :          Similarly for VLAs.  */
    7698                 :       57321 :       tree outtype = TREE_TYPE (TREE_VALUE (link));
    7699                 :       57321 :       if (outtype != error_mark_node
    7700                 :       57321 :           && (TREE_ADDRESSABLE (outtype)
    7701                 :       57291 :               || !COMPLETE_TYPE_P (outtype)
    7702                 :       57266 :               || !tree_fits_poly_uint64_p (TYPE_SIZE_UNIT (outtype))))
    7703                 :             :         {
    7704                 :         246 :           if (allows_mem)
    7705                 :         234 :             allows_reg = 0;
    7706                 :             :           else
    7707                 :             :             {
    7708                 :          12 :               error ("impossible constraint in %<asm%>");
    7709                 :          12 :               error ("non-memory output %d must stay in memory", i);
    7710                 :          12 :               return GS_ERROR;
    7711                 :             :             }
    7712                 :             :         }
    7713                 :             : 
    7714                 :       57309 :       if (!allows_reg && allows_mem)
    7715                 :        1279 :         mark_addressable (TREE_VALUE (link));
    7716                 :             : 
    7717                 :       57309 :       tree orig = TREE_VALUE (link);
    7718                 :      105979 :       tret = gimplify_expr (&TREE_VALUE (link), pre_p, post_p,
    7719                 :             :                             is_inout ? is_gimple_min_lval : is_gimple_lvalue,
    7720                 :             :                             fb_lvalue | fb_mayfail);
    7721                 :       57309 :       if (tret == GS_ERROR)
    7722                 :             :         {
    7723                 :          15 :           if (orig != error_mark_node)
    7724                 :           0 :             error ("invalid lvalue in %<asm%> output %d", i);
    7725                 :             :           ret = tret;
    7726                 :             :         }
    7727                 :             : 
    7728                 :             :       /* If the gimplified operand is a register we do not allow memory.  */
    7729                 :       57309 :       if (allows_reg
    7730                 :       56027 :           && allows_mem
    7731                 :       63027 :           && (is_gimple_reg (TREE_VALUE (link))
    7732                 :         269 :               || (handled_component_p (TREE_VALUE (link))
    7733                 :          36 :                   && is_gimple_reg (TREE_OPERAND (TREE_VALUE (link), 0)))))
    7734                 :        5450 :         allows_mem = 0;
    7735                 :             : 
    7736                 :             :       /* If the constraint does not allow memory make sure we gimplify
    7737                 :             :          it to a register if it is not already but its base is.  This
    7738                 :             :          happens for complex and vector components.  */
    7739                 :       57309 :       if (!allows_mem)
    7740                 :             :         {
    7741                 :       55762 :           tree op = TREE_VALUE (link);
    7742                 :       55762 :           if (! is_gimple_val (op)
    7743                 :       20544 :               && is_gimple_reg_type (TREE_TYPE (op))
    7744                 :       76305 :               && is_gimple_reg (get_base_address (op)))
    7745                 :             :             {
    7746                 :          19 :               tree tem = create_tmp_reg (TREE_TYPE (op));
    7747                 :          19 :               tree ass;
    7748                 :          19 :               if (is_inout)
    7749                 :             :                 {
    7750                 :           7 :                   ass = build2 (MODIFY_EXPR, TREE_TYPE (tem),
    7751                 :             :                                 tem, unshare_expr (op));
    7752                 :           7 :                   gimplify_and_add (ass, pre_p);
    7753                 :             :                 }
    7754                 :          19 :               ass = build2 (MODIFY_EXPR, TREE_TYPE (tem), op, tem);
    7755                 :          19 :               gimplify_and_add (ass, post_p);
    7756                 :             : 
    7757                 :          19 :               TREE_VALUE (link) = tem;
    7758                 :          19 :               tret = GS_OK;
    7759                 :             :             }
    7760                 :             :         }
    7761                 :             : 
    7762                 :       57309 :       vec_safe_push (outputs, link);
    7763                 :       57309 :       TREE_CHAIN (link) = NULL_TREE;
    7764                 :             : 
    7765                 :       57309 :       if (is_inout)
    7766                 :             :         {
    7767                 :             :           /* An input/output operand.  To give the optimizers more
    7768                 :             :              flexibility, split it into separate input and output
    7769                 :             :              operands.  */
    7770                 :        8639 :           tree input;
    7771                 :             :           /* Buffer big enough to format a 32-bit UINT_MAX into.  */
    7772                 :        8639 :           char buf[11];
    7773                 :             : 
    7774                 :             :           /* Turn the in/out constraint into an output constraint.  */
    7775                 :        8639 :           char *p = xstrdup (constraint);
    7776                 :        8639 :           p[0] = '=';
    7777                 :        8639 :           TREE_PURPOSE (link) = unshare_expr (TREE_PURPOSE (link));
    7778                 :        8639 :           TREE_VALUE (TREE_PURPOSE (link)) = build_string (constraint_len, p);
    7779                 :             : 
    7780                 :             :           /* And add a matching input constraint.  */
    7781                 :        8639 :           if (allows_reg)
    7782                 :             :             {
    7783                 :        8140 :               sprintf (buf, "%u", i);
    7784                 :             : 
    7785                 :             :               /* If there are multiple alternatives in the constraint,
    7786                 :             :                  handle each of them individually.  Those that allow register
    7787                 :             :                  will be replaced with operand number, the others will stay
    7788                 :             :                  unchanged.  */
    7789                 :        8140 :               if (strchr (p, ',') != NULL)
    7790                 :             :                 {
    7791                 :         100 :                   size_t len = 0, buflen = strlen (buf);
    7792                 :         100 :                   char *beg, *end, *str, *dst;
    7793                 :             : 
    7794                 :         100 :                   for (beg = p + 1;;)
    7795                 :             :                     {
    7796                 :         200 :                       end = strchr (beg, ',');
    7797                 :         200 :                       if (end == NULL)
    7798                 :         100 :                         end = strchr (beg, '\0');
    7799                 :         200 :                       if ((size_t) (end - beg) < buflen)
    7800                 :          28 :                         len += buflen + 1;
    7801                 :             :                       else
    7802                 :         172 :                         len += end - beg + 1;
    7803                 :         200 :                       if (*end)
    7804                 :         100 :                         beg = end + 1;
    7805                 :             :                       else
    7806                 :             :                         break;
    7807                 :             :                     }
    7808                 :             : 
    7809                 :         100 :                   str = (char *) alloca (len);
    7810                 :         100 :                   for (beg = p + 1, dst = str;;)
    7811                 :             :                     {
    7812                 :         200 :                       const char *tem;
    7813                 :         200 :                       bool mem_p, reg_p, inout_p;
    7814                 :             : 
    7815                 :         200 :                       end = strchr (beg, ',');
    7816                 :         200 :                       if (end)
    7817                 :         100 :                         *end = '\0';
    7818                 :         200 :                       beg[-1] = '=';
    7819                 :         200 :                       tem = beg - 1;
    7820                 :         200 :                       parse_output_constraint (&tem, i, 0, 0,
    7821                 :             :                                                &mem_p, &reg_p, &inout_p);
    7822                 :         200 :                       if (dst != str)
    7823                 :         100 :                         *dst++ = ',';
    7824                 :         200 :                       if (reg_p)
    7825                 :             :                         {
    7826                 :         115 :                           memcpy (dst, buf, buflen);
    7827                 :         115 :                           dst += buflen;
    7828                 :             :                         }
    7829                 :             :                       else
    7830                 :             :                         {
    7831                 :          85 :                           if (end)
    7832                 :           0 :                             len = end - beg;
    7833                 :             :                           else
    7834                 :          85 :                             len = strlen (beg);
    7835                 :          85 :                           memcpy (dst, beg, len);
    7836                 :          85 :                           dst += len;
    7837                 :             :                         }
    7838                 :         200 :                       if (end)
    7839                 :         100 :                         beg = end + 1;
    7840                 :             :                       else
    7841                 :             :                         break;
    7842                 :         100 :                     }
    7843                 :         100 :                   *dst = '\0';
    7844                 :         100 :                   input = build_string (dst - str, str);
    7845                 :             :                 }
    7846                 :             :               else
    7847                 :        8040 :                 input = build_string (strlen (buf), buf);
    7848                 :             :             }
    7849                 :             :           else
    7850                 :         499 :             input = build_string (constraint_len - 1, constraint + 1);
    7851                 :             : 
    7852                 :        8639 :           free (p);
    7853                 :             : 
    7854                 :        8639 :           input = build_tree_list (build_tree_list (NULL_TREE, input),
    7855                 :        8639 :                                    unshare_expr (TREE_VALUE (link)));
    7856                 :        8639 :           ASM_INPUTS (expr) = chainon (ASM_INPUTS (expr), input);
    7857                 :             :         }
    7858                 :             :     }
    7859                 :             : 
    7860                 :       94855 :   link_next = NULL_TREE;
    7861                 :      134168 :   for (link = ASM_INPUTS (expr); link; ++i, link = link_next)
    7862                 :             :     {
    7863                 :       39322 :       link_next = TREE_CHAIN (link);
    7864                 :       39322 :       constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link)));
    7865                 :       39322 :       parse_input_constraint (&constraint, 0, 0, noutputs, 0,
    7866                 :             :                               oconstraints, &allows_mem, &allows_reg);
    7867                 :             : 
    7868                 :             :       /* If we can't make copies, we can only accept memory.  */
    7869                 :       39322 :       tree intype = TREE_TYPE (TREE_VALUE (link));
    7870                 :       39322 :       if (intype != error_mark_node
    7871                 :       39322 :           && (TREE_ADDRESSABLE (intype)
    7872                 :       39259 :               || !COMPLETE_TYPE_P (intype)
    7873                 :       39220 :               || !tree_fits_poly_uint64_p (TYPE_SIZE_UNIT (intype))))
    7874                 :             :         {
    7875                 :         255 :           if (allows_mem)
    7876                 :         246 :             allows_reg = 0;
    7877                 :             :           else
    7878                 :             :             {
    7879                 :           9 :               error ("impossible constraint in %<asm%>");
    7880                 :           9 :               error ("non-memory input %d must stay in memory", i);
    7881                 :           9 :               return GS_ERROR;
    7882                 :             :             }
    7883                 :             :         }
    7884                 :             : 
    7885                 :             :       /* If the operand is a memory input, it should be an lvalue.  */
    7886                 :       39313 :       if (!allows_reg && allows_mem)
    7887                 :             :         {
    7888                 :        1652 :           tree inputv = TREE_VALUE (link);
    7889                 :        1652 :           STRIP_NOPS (inputv);
    7890                 :        1652 :           if (TREE_CODE (inputv) == PREDECREMENT_EXPR
    7891                 :             :               || TREE_CODE (inputv) == PREINCREMENT_EXPR
    7892                 :             :               || TREE_CODE (inputv) == POSTDECREMENT_EXPR
    7893                 :        1652 :               || TREE_CODE (inputv) == POSTINCREMENT_EXPR
    7894                 :        1640 :               || TREE_CODE (inputv) == MODIFY_EXPR
    7895                 :        3290 :               || VOID_TYPE_P (TREE_TYPE (inputv)))
    7896                 :          38 :             TREE_VALUE (link) = error_mark_node;
    7897                 :        1652 :           tret = gimplify_expr (&TREE_VALUE (link), pre_p, post_p,
    7898                 :             :                                 is_gimple_lvalue, fb_lvalue | fb_mayfail);
    7899                 :        1652 :           if (tret != GS_ERROR)
    7900                 :             :             {
    7901                 :             :               /* Unlike output operands, memory inputs are not guaranteed
    7902                 :             :                  to be lvalues by the FE, and while the expressions are
    7903                 :             :                  marked addressable there, if it is e.g. a statement
    7904                 :             :                  expression, temporaries in it might not end up being
    7905                 :             :                  addressable.  They might be already used in the IL and thus
    7906                 :             :                  it is too late to make them addressable now though.  */
    7907                 :        1596 :               tree x = TREE_VALUE (link);
    7908                 :        1737 :               while (handled_component_p (x))
    7909                 :         141 :                 x = TREE_OPERAND (x, 0);
    7910                 :        1596 :               if (TREE_CODE (x) == MEM_REF
    7911                 :        1596 :                   && TREE_CODE (TREE_OPERAND (x, 0)) == ADDR_EXPR)
    7912                 :           0 :                 x = TREE_OPERAND (TREE_OPERAND (x, 0), 0);
    7913                 :        1596 :               if ((VAR_P (x)
    7914                 :             :                    || TREE_CODE (x) == PARM_DECL
    7915                 :             :                    || TREE_CODE (x) == RESULT_DECL)
    7916                 :        1207 :                   && !TREE_ADDRESSABLE (x)
    7917                 :          23 :                   && is_gimple_reg (x))
    7918                 :             :                 {
    7919                 :          17 :                   warning_at (EXPR_LOC_OR_LOC (TREE_VALUE (link),
    7920                 :             :                                                input_location), 0,
    7921                 :             :                               "memory input %d is not directly addressable",
    7922                 :             :                               i);
    7923                 :          17 :                   prepare_gimple_addressable (&TREE_VALUE (link), pre_p);
    7924                 :             :                 }
    7925                 :             :             }
    7926                 :        1652 :           mark_addressable (TREE_VALUE (link));
    7927                 :        1652 :           if (tret == GS_ERROR)
    7928                 :             :             {
    7929                 :          56 :               if (inputv != error_mark_node)
    7930                 :          46 :                 error_at (EXPR_LOC_OR_LOC (TREE_VALUE (link), input_location),
    7931                 :             :                           "memory input %d is not directly addressable", i);
    7932                 :             :               ret = tret;
    7933                 :             :             }
    7934                 :             :         }
    7935                 :             :       else
    7936                 :             :         {
    7937                 :       37661 :           tret = gimplify_expr (&TREE_VALUE (link), pre_p, post_p,
    7938                 :             :                                 is_gimple_asm_val, fb_rvalue);
    7939                 :       37661 :           if (tret == GS_ERROR)
    7940                 :          91 :             ret = tret;
    7941                 :             :         }
    7942                 :             : 
    7943                 :       39313 :       TREE_CHAIN (link) = NULL_TREE;
    7944                 :       39313 :       vec_safe_push (inputs, link);
    7945                 :             :     }
    7946                 :             : 
    7947                 :       94846 :   link_next = NULL_TREE;
    7948                 :      189150 :   for (link = ASM_CLOBBERS (expr); link; ++i, link = link_next)
    7949                 :             :     {
    7950                 :       94304 :       link_next = TREE_CHAIN (link);
    7951                 :       94304 :       TREE_CHAIN (link) = NULL_TREE;
    7952                 :       94304 :       vec_safe_push (clobbers, link);
    7953                 :             :     }
    7954                 :             : 
    7955                 :       94846 :   link_next = NULL_TREE;
    7956                 :       95609 :   for (link = ASM_LABELS (expr); link; ++i, link = link_next)
    7957                 :             :     {
    7958                 :         763 :       link_next = TREE_CHAIN (link);
    7959                 :         763 :       TREE_CHAIN (link) = NULL_TREE;
    7960                 :         763 :       vec_safe_push (labels, link);
    7961                 :             :     }
    7962                 :             : 
    7963                 :             :   /* Do not add ASMs with errors to the gimple IL stream.  */
    7964                 :       94846 :   if (ret != GS_ERROR)
    7965                 :             :     {
    7966                 :       94741 :       stmt = gimple_build_asm_vec (TREE_STRING_POINTER (ASM_STRING (expr)),
    7967                 :             :                                    inputs, outputs, clobbers, labels);
    7968                 :             : 
    7969                 :             :       /* asm is volatile if it was marked by the user as volatile or
    7970                 :             :          there are no outputs or this is an asm goto.  */
    7971                 :      189482 :       gimple_asm_set_volatile (stmt,
    7972                 :       94741 :                                ASM_VOLATILE_P (expr)
    7973                 :        7322 :                                || noutputs == 0
    7974                 :      102057 :                                || labels);
    7975                 :       94741 :       gimple_asm_set_basic (stmt, ASM_BASIC_P (expr));
    7976                 :       94741 :       gimple_asm_set_inline (stmt, ASM_INLINE_P (expr));
    7977                 :             : 
    7978                 :       94741 :       gimplify_seq_add_stmt (pre_p, stmt);
    7979                 :             :     }
    7980                 :             : 
    7981                 :             :   return ret;
    7982                 :             : }
    7983                 :             : 
    7984                 :             : /* Gimplify a CLEANUP_POINT_EXPR.  Currently this works by adding
    7985                 :             :    GIMPLE_WITH_CLEANUP_EXPRs to the prequeue as we encounter cleanups while
    7986                 :             :    gimplifying the body, and converting them to TRY_FINALLY_EXPRs when we
    7987                 :             :    return to this function.
    7988                 :             : 
    7989                 :             :    FIXME should we complexify the prequeue handling instead?  Or use flags
    7990                 :             :    for all the cleanups and let the optimizer tighten them up?  The current
    7991                 :             :    code seems pretty fragile; it will break on a cleanup within any
    7992                 :             :    non-conditional nesting.  But any such nesting would be broken, anyway;
    7993                 :             :    we can't write a TRY_FINALLY_EXPR that starts inside a nesting construct
    7994                 :             :    and continues out of it.  We can do that at the RTL level, though, so
    7995                 :             :    having an optimizer to tighten up try/finally regions would be a Good
    7996                 :             :    Thing.  */
    7997                 :             : 
    7998                 :             : static enum gimplify_status
    7999                 :     5064052 : gimplify_cleanup_point_expr (tree *expr_p, gimple_seq *pre_p)
    8000                 :             : {
    8001                 :     5064052 :   gimple_stmt_iterator iter;
    8002                 :     5064052 :   gimple_seq body_sequence = NULL;
    8003                 :             : 
    8004                 :     5064052 :   tree temp = voidify_wrapper_expr (*expr_p, NULL);
    8005                 :             : 
    8006                 :             :   /* We only care about the number of conditions between the innermost
    8007                 :             :      CLEANUP_POINT_EXPR and the cleanup.  So save and reset the count and
    8008                 :             :      any cleanups collected outside the CLEANUP_POINT_EXPR.  */
    8009                 :     5064052 :   int old_conds = gimplify_ctxp->conditions;
    8010                 :     5064052 :   gimple_seq old_cleanups = gimplify_ctxp->conditional_cleanups;
    8011                 :     5064052 :   bool old_in_cleanup_point_expr = gimplify_ctxp->in_cleanup_point_expr;
    8012                 :     5064052 :   gimplify_ctxp->conditions = 0;
    8013                 :     5064052 :   gimplify_ctxp->conditional_cleanups = NULL;
    8014                 :     5064052 :   gimplify_ctxp->in_cleanup_point_expr = true;
    8015                 :             : 
    8016                 :     5064052 :   gimplify_stmt (&TREE_OPERAND (*expr_p, 0), &body_sequence);
    8017                 :             : 
    8018                 :     5064052 :   gimplify_ctxp->conditions = old_conds;
    8019                 :     5064052 :   gimplify_ctxp->conditional_cleanups = old_cleanups;
    8020                 :     5064052 :   gimplify_ctxp->in_cleanup_point_expr = old_in_cleanup_point_expr;
    8021                 :             : 
    8022                 :    25285151 :   for (iter = gsi_start (body_sequence); !gsi_end_p (iter); )
    8023                 :             :     {
    8024                 :    15191716 :       gimple *wce = gsi_stmt (iter);
    8025                 :             : 
    8026                 :    15191716 :       if (gimple_code (wce) == GIMPLE_WITH_CLEANUP_EXPR)
    8027                 :             :         {
    8028                 :      510154 :           if (gsi_one_before_end_p (iter))
    8029                 :             :             {
    8030                 :             :               /* Note that gsi_insert_seq_before and gsi_remove do not
    8031                 :             :                  scan operands, unlike some other sequence mutators.  */
    8032                 :        3652 :               if (!gimple_wce_cleanup_eh_only (wce))
    8033                 :        3284 :                 gsi_insert_seq_before_without_update (&iter,
    8034                 :             :                                                       gimple_wce_cleanup (wce),
    8035                 :             :                                                       GSI_SAME_STMT);
    8036                 :        3652 :               gsi_remove (&iter, true);
    8037                 :        3652 :               break;
    8038                 :             :             }
    8039                 :             :           else
    8040                 :             :             {
    8041                 :      506502 :               gtry *gtry;
    8042                 :      506502 :               gimple_seq seq;
    8043                 :      506502 :               enum gimple_try_flags kind;
    8044                 :             : 
    8045                 :      506502 :               if (gimple_wce_cleanup_eh_only (wce))
    8046                 :             :                 kind = GIMPLE_TRY_CATCH;
    8047                 :             :               else
    8048                 :      494574 :                 kind = GIMPLE_TRY_FINALLY;
    8049                 :      506502 :               seq = gsi_split_seq_after (iter);
    8050                 :             : 
    8051                 :      506502 :               gtry = gimple_build_try (seq, gimple_wce_cleanup (wce), kind);
    8052                 :             :               /* Do not use gsi_replace here, as it may scan operands.
    8053                 :             :                  We want to do a simple structural modification only.  */
    8054                 :      506502 :               gsi_set_stmt (&iter, gtry);
    8055                 :     1013004 :               iter = gsi_start (gtry->eval);
    8056                 :             :             }
    8057                 :             :         }
    8058                 :             :       else
    8059                 :    14681562 :         gsi_next (&iter);
    8060                 :             :     }
    8061                 :             : 
    8062                 :     5064052 :   gimplify_seq_add_seq (pre_p, body_sequence);
    8063                 :     5064052 :   if (temp)
    8064                 :             :     {
    8065                 :      351614 :       *expr_p = temp;
    8066                 :      351614 :       return GS_OK;
    8067                 :             :     }
    8068                 :             :   else
    8069                 :             :     {
    8070                 :     4712438 :       *expr_p = NULL;
    8071                 :     4712438 :       return GS_ALL_DONE;
    8072                 :             :     }
    8073                 :             : }
    8074                 :             : 
    8075                 :             : /* Insert a cleanup marker for gimplify_cleanup_point_expr.  CLEANUP
    8076                 :             :    is the cleanup action required.  EH_ONLY is true if the cleanup should
    8077                 :             :    only be executed if an exception is thrown, not on normal exit.
    8078                 :             :    If FORCE_UNCOND is true perform the cleanup unconditionally;  this is
    8079                 :             :    only valid for clobbers.  */
    8080                 :             : 
    8081                 :             : static void
    8082                 :      514362 : gimple_push_cleanup (tree var, tree cleanup, bool eh_only, gimple_seq *pre_p,
    8083                 :             :                      bool force_uncond = false)
    8084                 :             : {
    8085                 :      514362 :   gimple *wce;
    8086                 :      514362 :   gimple_seq cleanup_stmts = NULL;
    8087                 :             : 
    8088                 :             :   /* Errors can result in improperly nested cleanups.  Which results in
    8089                 :             :      confusion when trying to resolve the GIMPLE_WITH_CLEANUP_EXPR.  */
    8090                 :      514362 :   if (seen_error ())
    8091                 :        4208 :     return;
    8092                 :             : 
    8093                 :      510154 :   if (gimple_conditional_context ())
    8094                 :             :     {
    8095                 :             :       /* If we're in a conditional context, this is more complex.  We only
    8096                 :             :          want to run the cleanup if we actually ran the initialization that
    8097                 :             :          necessitates it, but we want to run it after the end of the
    8098                 :             :          conditional context.  So we wrap the try/finally around the
    8099                 :             :          condition and use a flag to determine whether or not to actually
    8100                 :             :          run the destructor.  Thus
    8101                 :             : 
    8102                 :             :            test ? f(A()) : 0
    8103                 :             : 
    8104                 :             :          becomes (approximately)
    8105                 :             : 
    8106                 :             :            flag = 0;
    8107                 :             :            try {
    8108                 :             :              if (test) { A::A(temp); flag = 1; val = f(temp); }
    8109                 :             :              else { val = 0; }
    8110                 :             :            } finally {
    8111                 :             :              if (flag) A::~A(temp);
    8112                 :             :            }
    8113                 :             :            val
    8114                 :             :       */
    8115                 :       11270 :       if (force_uncond)
    8116                 :             :         {
    8117                 :       10406 :           gimplify_stmt (&cleanup, &cleanup_stmts);
    8118                 :       10406 :           wce = gimple_build_wce (cleanup_stmts);
    8119                 :       10406 :           gimplify_seq_add_stmt (&gimplify_ctxp->conditional_cleanups, wce);
    8120                 :             :         }
    8121                 :             :       else
    8122                 :             :         {
    8123                 :         864 :           tree flag = create_tmp_var (boolean_type_node, "cleanup");
    8124                 :         864 :           gassign *ffalse = gimple_build_assign (flag, boolean_false_node);
    8125                 :         864 :           gassign *ftrue = gimple_build_assign (flag, boolean_true_node);
    8126                 :             : 
    8127                 :         864 :           cleanup = build3 (COND_EXPR, void_type_node, flag, cleanup, NULL);
    8128                 :         864 :           gimplify_stmt (&cleanup, &cleanup_stmts);
    8129                 :         864 :           wce = gimple_build_wce (cleanup_stmts);
    8130                 :         864 :           gimple_wce_set_cleanup_eh_only (wce, eh_only);
    8131                 :             : 
    8132                 :         864 :           gimplify_seq_add_stmt (&gimplify_ctxp->conditional_cleanups, ffalse);
    8133                 :         864 :           gimplify_seq_add_stmt (&gimplify_ctxp->conditional_cleanups, wce);
    8134                 :         864 :           gimplify_seq_add_stmt (pre_p, ftrue);
    8135                 :             : 
    8136                 :             :           /* Because of this manipulation, and the EH edges that jump
    8137                 :             :              threading cannot redirect, the temporary (VAR) will appear
    8138                 :             :              to be used uninitialized.  Don't warn.  */
    8139                 :         864 :           suppress_warning (var, OPT_Wuninitialized);
    8140                 :             :         }
    8141                 :             :     }
    8142                 :             :   else
    8143                 :             :     {
    8144                 :      498884 :       gimplify_stmt (&cleanup, &cleanup_stmts);
    8145                 :      498884 :       wce = gimple_build_wce (cleanup_stmts);
    8146                 :      498884 :       gimple_wce_set_cleanup_eh_only (wce, eh_only);
    8147                 :      498884 :       gimplify_seq_add_stmt (pre_p, wce);
    8148                 :             :     }
    8149                 :             : }
    8150                 :             : 
    8151                 :             : /* Gimplify a TARGET_EXPR which doesn't appear on the rhs of an INIT_EXPR.  */
    8152                 :             : 
    8153                 :             : static enum gimplify_status
    8154                 :      697665 : gimplify_target_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p)
    8155                 :             : {
    8156                 :      697665 :   tree targ = *expr_p;
    8157                 :      697665 :   tree temp = TARGET_EXPR_SLOT (targ);
    8158                 :      697665 :   tree init = TARGET_EXPR_INITIAL (targ);
    8159                 :      697665 :   enum gimplify_status ret;
    8160                 :             : 
    8161                 :      697665 :   bool unpoison_empty_seq = false;
    8162                 :      697665 :   gimple_stmt_iterator unpoison_it;
    8163                 :             : 
    8164                 :      697665 :   if (init)
    8165                 :             :     {
    8166                 :      661533 :       gimple_seq init_pre_p = NULL;
    8167                 :             : 
    8168                 :             :       /* TARGET_EXPR temps aren't part of the enclosing block, so add it
    8169                 :             :          to the temps list.  Handle also variable length TARGET_EXPRs.  */
    8170                 :      661533 :       if (!poly_int_tree_p (DECL_SIZE (temp)))
    8171                 :             :         {
    8172                 :          42 :           if (!TYPE_SIZES_GIMPLIFIED (TREE_TYPE (temp)))
    8173                 :           1 :             gimplify_type_sizes (TREE_TYPE (temp), &init_pre_p);
    8174                 :             :           /* FIXME: this is correct only when the size of the type does
    8175                 :             :              not depend on expressions evaluated in init.  */
    8176                 :          42 :           gimplify_vla_decl (temp, &init_pre_p);
    8177                 :             :         }
    8178                 :             :       else
    8179                 :             :         {
    8180                 :             :           /* Save location where we need to place unpoisoning.  It's possible
    8181                 :             :              that a variable will be converted to needs_to_live_in_memory.  */
    8182                 :      661491 :           unpoison_it = gsi_last (*pre_p);
    8183                 :      661491 :           unpoison_empty_seq = gsi_end_p (unpoison_it);
    8184                 :             : 
    8185                 :      661491 :           gimple_add_tmp_var (temp);
    8186                 :             :         }
    8187                 :             : 
    8188                 :             :       /* If TARGET_EXPR_INITIAL is void, then the mere evaluation of the
    8189                 :             :          expression is supposed to initialize the slot.  */
    8190                 :      661533 :       if (VOID_TYPE_P (TREE_TYPE (init)))
    8191                 :      280361 :         ret = gimplify_expr (&init, &init_pre_p, post_p, is_gimple_stmt,
    8192                 :             :                              fb_none);
    8193                 :             :       else
    8194                 :             :         {
    8195                 :      381172 :           tree init_expr = build2 (INIT_EXPR, void_type_node, temp, init);
    8196                 :      381172 :           init = init_expr;
    8197                 :      381172 :           ret = gimplify_expr (&init, &init_pre_p, post_p, is_gimple_stmt,
    8198                 :             :                                fb_none);
    8199                 :      381172 :           init = NULL;
    8200                 :      381172 :           ggc_free (init_expr);
    8201                 :             :         }
    8202                 :      661533 :       if (ret == GS_ERROR)
    8203                 :             :         {
    8204                 :             :           /* PR c++/28266 Make sure this is expanded only once. */
    8205                 :          15 :           TARGET_EXPR_INITIAL (targ) = NULL_TREE;
    8206                 :          15 :           return GS_ERROR;
    8207                 :             :         }
    8208                 :             : 
    8209                 :      661518 :       if (init)
    8210                 :           0 :         gimplify_and_add (init, &init_pre_p);
    8211                 :             : 
    8212                 :             :       /* Add a clobber for the temporary going out of scope, like
    8213                 :             :          gimplify_bind_expr.  But only if we did not promote the
    8214                 :             :          temporary to static storage.  */
    8215                 :      661518 :       if (gimplify_ctxp->in_cleanup_point_expr
    8216                 :      514274 :           && !TREE_STATIC (temp)
    8217                 :     1174525 :           && needs_to_live_in_memory (temp))
    8218                 :             :         {
    8219                 :      389672 :           if (flag_stack_reuse == SR_ALL)
    8220                 :             :             {
    8221                 :      389227 :               tree clobber = build_clobber (TREE_TYPE (temp),
    8222                 :             :                                             CLOBBER_STORAGE_END);
    8223                 :      389227 :               clobber = build2 (MODIFY_EXPR, TREE_TYPE (temp), temp, clobber);
    8224                 :      389227 :               gimple_push_cleanup (temp, clobber, false, pre_p, true);
    8225                 :             :             }
    8226                 :      389672 :           if (asan_poisoned_variables
    8227                 :         445 :               && DECL_ALIGN (temp) <= MAX_SUPPORTED_STACK_ALIGNMENT
    8228                 :         445 :               && !TREE_STATIC (temp)
    8229                 :         445 :               && dbg_cnt (asan_use_after_scope)
    8230                 :      390117 :               && !gimplify_omp_ctxp)
    8231                 :             :             {
    8232                 :         437 :               tree asan_cleanup = build_asan_poison_call_expr (temp);
    8233                 :         437 :               if (asan_cleanup)
    8234                 :             :                 {
    8235                 :         437 :                   if (unpoison_empty_seq)
    8236                 :         224 :                     unpoison_it = gsi_start (*pre_p);
    8237                 :             : 
    8238                 :         437 :                   asan_poison_variable (temp, false, &unpoison_it,
    8239                 :             :                                         unpoison_empty_seq);
    8240                 :         437 :                   gimple_push_cleanup (temp, asan_cleanup, false, pre_p);
    8241                 :             :                 }
    8242                 :             :             }
    8243                 :             :         }
    8244                 :             : 
    8245                 :      661518 :       gimple_seq_add_seq (pre_p, init_pre_p);
    8246                 :             : 
    8247                 :             :       /* If needed, push the cleanup for the temp.  */
    8248                 :      661518 :       if (TARGET_EXPR_CLEANUP (targ))
    8249                 :      124698 :         gimple_push_cleanup (temp, TARGET_EXPR_CLEANUP (targ),
    8250                 :      124698 :                              CLEANUP_EH_ONLY (targ), pre_p);
    8251                 :             : 
    8252                 :             :       /* Only expand this once.  */
    8253                 :      661518 :       TREE_OPERAND (targ, 3) = init;
    8254                 :      661518 :       TARGET_EXPR_INITIAL (targ) = NULL_TREE;
    8255                 :             :     }
    8256                 :             :   else
    8257                 :             :     /* We should have expanded this before.  */
    8258                 :       36132 :     gcc_assert (DECL_SEEN_IN_BIND_EXPR_P (temp));
    8259                 :             : 
    8260                 :      697650 :   *expr_p = temp;
    8261                 :      697650 :   return GS_OK;
    8262                 :             : }
    8263                 :             : 
    8264                 :             : /* Gimplification of expression trees.  */
    8265                 :             : 
    8266                 :             : /* Gimplify an expression which appears at statement context.  The
    8267                 :             :    corresponding GIMPLE statements are added to *SEQ_P.  If *SEQ_P is
    8268                 :             :    NULL, a new sequence is allocated.
    8269                 :             : 
    8270                 :             :    Return true if we actually added a statement to the queue.  */
    8271                 :             : 
    8272                 :             : bool
    8273                 :    98147018 : gimplify_stmt (tree *stmt_p, gimple_seq *seq_p)
    8274                 :             : {
    8275                 :    98147018 :   gimple_seq_node last;
    8276                 :             : 
    8277                 :    98147018 :   last = gimple_seq_last (*seq_p);
    8278                 :    98147018 :   gimplify_expr (stmt_p, seq_p, NULL, is_gimple_stmt, fb_none);
    8279                 :    98147018 :   return last != gimple_seq_last (*seq_p);
    8280                 :             : }
    8281                 :             : 
    8282                 :             : /* Add FIRSTPRIVATE entries for DECL in the OpenMP the surrounding parallels
    8283                 :             :    to CTX.  If entries already exist, force them to be some flavor of private.
    8284                 :             :    If there is no enclosing parallel, do nothing.  */
    8285                 :             : 
    8286                 :             : void
    8287                 :      124099 : omp_firstprivatize_variable (struct gimplify_omp_ctx *ctx, tree decl)
    8288                 :             : {
    8289                 :      124099 :   splay_tree_node n;
    8290                 :             : 
    8291                 :      124099 :   if (decl == NULL || !DECL_P (decl) || ctx->region_type == ORT_NONE)
    8292                 :             :     return;
    8293                 :             : 
    8294                 :       36472 :   do
    8295                 :             :     {
    8296                 :       36472 :       n = splay_tree_lookup (ctx->variables, (splay_tree_key)decl);
    8297                 :       36472 :       if (n != NULL)
    8298                 :             :         {
    8299                 :        4269 :           if (n->value & GOVD_SHARED)
    8300                 :         183 :             n->value = GOVD_FIRSTPRIVATE | (n->value & GOVD_SEEN);
    8301                 :        4086 :           else if (n->value & GOVD_MAP)
    8302                 :          55 :             n->value |= GOVD_MAP_TO_ONLY;
    8303                 :             :           else
    8304                 :             :             return;
    8305                 :             :         }
    8306                 :       32203 :       else if ((ctx->region_type & ORT_TARGET) != 0)
    8307                 :             :         {
    8308                 :        6775 :           if (ctx->defaultmap[GDMK_SCALAR] & GOVD_FIRSTPRIVATE)
    8309                 :        4020 :             omp_add_variable (ctx, decl, GOVD_FIRSTPRIVATE);
    8310                 :             :           else
    8311                 :        2755 :             omp_add_variable (ctx, decl, GOVD_MAP | GOVD_MAP_TO_ONLY);
    8312                 :             :         }
    8313                 :       25428 :       else if (ctx->region_type != ORT_WORKSHARE
    8314                 :             :                && ctx->region_type != ORT_TASKGROUP
    8315                 :       23619 :                && ctx->region_type != ORT_SIMD
    8316                 :       22995 :                && ctx->region_type != ORT_ACC
    8317                 :       22885 :                && !(ctx->region_type & ORT_TARGET_DATA))
    8318                 :       14304 :         omp_add_variable (ctx, decl, GOVD_FIRSTPRIVATE);
    8319                 :             : 
    8320                 :       32441 :       ctx = ctx->outer_context;
    8321                 :             :     }
    8322                 :       32441 :   while (ctx);
    8323                 :             : }
    8324                 :             : 
    8325                 :             : /* Similarly for each of the type sizes of TYPE.  */
    8326                 :             : 
    8327                 :             : static void
    8328                 :       40651 : omp_firstprivatize_type_sizes (struct gimplify_omp_ctx *ctx, tree type)
    8329                 :             : {
    8330                 :       40651 :   if (type == NULL || type == error_mark_node)
    8331                 :             :     return;
    8332                 :       40647 :   type = TYPE_MAIN_VARIANT (type);
    8333                 :             : 
    8334                 :       40647 :   if (ctx->privatized_types->add (type))
    8335                 :             :     return;
    8336                 :             : 
    8337                 :       30901 :   switch (TREE_CODE (type))
    8338                 :             :     {
    8339                 :       13073 :     case INTEGER_TYPE:
    8340                 :       13073 :     case ENUMERAL_TYPE:
    8341                 :       13073 :     case BOOLEAN_TYPE:
    8342                 :       13073 :     case REAL_TYPE:
    8343                 :       13073 :     case FIXED_POINT_TYPE:
    8344                 :       13073 :       omp_firstprivatize_variable (ctx, TYPE_MIN_VALUE (type));
    8345                 :       13073 :       omp_firstprivatize_variable (ctx, TYPE_MAX_VALUE (type));
    8346                 :       13073 :       break;
    8347                 :             : 
    8348                 :        5384 :     case ARRAY_TYPE:
    8349                 :        5384 :       omp_firstprivatize_type_sizes (ctx, TREE_TYPE (type));
    8350                 :        5384 :       omp_firstprivatize_type_sizes (ctx, TYPE_DOMAIN (type));
    8351                 :        5384 :       break;
    8352                 :             : 
    8353                 :        2507 :     case RECORD_TYPE:
    8354                 :        2507 :     case UNION_TYPE:
    8355                 :        2507 :     case QUAL_UNION_TYPE:
    8356                 :        2507 :       {
    8357                 :        2507 :         tree field;
    8358                 :       26710 :         for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
    8359                 :       24203 :           if (TREE_CODE (field) == FIELD_DECL)
    8360                 :             :             {
    8361                 :        9004 :               omp_firstprivatize_variable (ctx, DECL_FIELD_OFFSET (field));
    8362                 :        9004 :               omp_firstprivatize_type_sizes (ctx, TREE_TYPE (field));
    8363                 :             :             }
    8364                 :             :       }
    8365                 :             :       break;
    8366                 :             : 
    8367                 :        9289 :     case POINTER_TYPE:
    8368                 :        9289 :     case REFERENCE_TYPE:
    8369                 :        9289 :       omp_firstprivatize_type_sizes (ctx, TREE_TYPE (type));
    8370                 :        9289 :       break;
    8371                 :             : 
    8372                 :             :     default:
    8373                 :             :       break;
    8374                 :             :     }
    8375                 :             : 
    8376                 :       30901 :   omp_firstprivatize_variable (ctx, TYPE_SIZE (type));
    8377                 :       30901 :   omp_firstprivatize_variable (ctx, TYPE_SIZE_UNIT (type));
    8378                 :       30901 :   lang_hooks.types.omp_firstprivatize_type_sizes (ctx, type);
    8379                 :             : }
    8380                 :             : 
    8381                 :             : /* Add an entry for DECL in the OMP context CTX with FLAGS.  */
    8382                 :             : 
    8383                 :             : static void
    8384                 :      669654 : omp_add_variable (struct gimplify_omp_ctx *ctx, tree decl, unsigned int flags)
    8385                 :             : {
    8386                 :      669654 :   splay_tree_node n;
    8387                 :      669654 :   unsigned int nflags;
    8388                 :      669654 :   tree t;
    8389                 :             : 
    8390                 :      669654 :   if (error_operand_p (decl) || ctx->region_type == ORT_NONE)
    8391                 :             :     return;
    8392                 :             : 
    8393                 :             :   /* Never elide decls whose type has TREE_ADDRESSABLE set.  This means
    8394                 :             :      there are constructors involved somewhere.  Exception is a shared clause,
    8395                 :             :      there is nothing privatized in that case.  */
    8396                 :      669509 :   if ((flags & GOVD_SHARED) == 0
    8397                 :      669509 :       && (TREE_ADDRESSABLE (TREE_TYPE (decl))
    8398                 :      610297 :           || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl))))
    8399                 :        3590 :     flags |= GOVD_SEEN;
    8400                 :             : 
    8401                 :      669509 :   n = splay_tree_lookup (ctx->variables, (splay_tree_key)decl);
    8402                 :      669509 :   if (n != NULL && (n->value & GOVD_DATA_SHARE_CLASS) != 0)
    8403                 :             :     {
    8404                 :             :       /* We shouldn't be re-adding the decl with the same data
    8405                 :             :          sharing class.  */
    8406                 :         821 :       gcc_assert ((n->value & GOVD_DATA_SHARE_CLASS & flags) == 0);
    8407                 :         821 :       nflags = n->value | flags;
    8408                 :             :       /* The only combination of data sharing classes we should see is
    8409                 :             :          FIRSTPRIVATE and LASTPRIVATE.  However, OpenACC permits
    8410                 :             :          reduction variables to be used in data sharing clauses.  */
    8411                 :         821 :       gcc_assert ((ctx->region_type & ORT_ACC) != 0
    8412                 :             :                   || ((nflags & GOVD_DATA_SHARE_CLASS)
    8413                 :             :                       == (GOVD_FIRSTPRIVATE | GOVD_LASTPRIVATE))
    8414                 :             :                   || (flags & GOVD_DATA_SHARE_CLASS) == 0);
    8415                 :         821 :       n->value = nflags;
    8416                 :         821 :       return;
    8417                 :             :     }
    8418                 :             : 
    8419                 :             :   /* When adding a variable-sized variable, we have to handle all sorts
    8420                 :             :      of additional bits of data: the pointer replacement variable, and
    8421                 :             :      the parameters of the type.  */
    8422                 :      668688 :   if (DECL_SIZE (decl) && !poly_int_tree_p (DECL_SIZE (decl)))
    8423                 :             :     {
    8424                 :             :       /* Add the pointer replacement variable as PRIVATE if the variable
    8425                 :             :          replacement is private, else FIRSTPRIVATE since we'll need the
    8426                 :             :          address of the original variable either for SHARED, or for the
    8427                 :             :          copy into or out of the context.  */
    8428                 :        1312 :       if (!(flags & GOVD_LOCAL) && ctx->region_type != ORT_TASKGROUP)
    8429                 :             :         {
    8430                 :        1222 :           if (flags & GOVD_MAP)
    8431                 :             :             nflags = GOVD_MAP | GOVD_MAP_TO_ONLY | GOVD_EXPLICIT;
    8432                 :         515 :           else if (flags & GOVD_PRIVATE)
    8433                 :             :             nflags = GOVD_PRIVATE;
    8434                 :         431 :           else if (((ctx->region_type & (ORT_TARGET | ORT_TARGET_DATA)) != 0
    8435                 :          48 :                     && (flags & GOVD_FIRSTPRIVATE))
    8436                 :         423 :                    || (ctx->region_type == ORT_TARGET_DATA
    8437                 :           6 :                        && (flags & GOVD_DATA_SHARE_CLASS) == 0))
    8438                 :             :             nflags = GOVD_PRIVATE | GOVD_EXPLICIT;
    8439                 :             :           else
    8440                 :        1222 :             nflags = GOVD_FIRSTPRIVATE;
    8441                 :        1222 :           nflags |= flags & GOVD_SEEN;
    8442                 :        1222 :           t = DECL_VALUE_EXPR (decl);
    8443                 :        1222 :           gcc_assert (INDIRECT_REF_P (t));
    8444                 :        1222 :           t = TREE_OPERAND (t, 0);
    8445                 :        1222 :           gcc_assert (DECL_P (t));
    8446                 :        1222 :           omp_add_variable (ctx, t, nflags);
    8447                 :             :         }
    8448                 :             : 
    8449                 :             :       /* Add all of the variable and type parameters (which should have
    8450                 :             :          been gimplified to a formal temporary) as FIRSTPRIVATE.  */
    8451                 :        1312 :       omp_firstprivatize_variable (ctx, DECL_SIZE_UNIT (decl));
    8452                 :        1312 :       omp_firstprivatize_variable (ctx, DECL_SIZE (decl));
    8453                 :        1312 :       omp_firstprivatize_type_sizes (ctx, TREE_TYPE (decl));
    8454                 :             : 
    8455                 :             :       /* The variable-sized variable itself is never SHARED, only some form
    8456                 :             :          of PRIVATE.  The sharing would take place via the pointer variable
    8457                 :             :          which we remapped above.  */
    8458                 :        1312 :       if (flags & GOVD_SHARED)
    8459                 :         276 :         flags = GOVD_SHARED | GOVD_DEBUG_PRIVATE
    8460                 :         276 :                 | (flags & (GOVD_SEEN | GOVD_EXPLICIT));
    8461                 :             : 
    8462                 :             :       /* We're going to make use of the TYPE_SIZE_UNIT at least in the
    8463                 :             :          alloca statement we generate for the variable, so make sure it
    8464                 :             :          is available.  This isn't automatically needed for the SHARED
    8465                 :             :          case, since we won't be allocating local storage then.
    8466                 :             :          For local variables TYPE_SIZE_UNIT might not be gimplified yet,
    8467                 :             :          in this case omp_notice_variable will be called later
    8468                 :             :          on when it is gimplified.  */
    8469                 :        1036 :       else if (! (flags & (GOVD_LOCAL | GOVD_MAP))
    8470                 :        1036 :                && DECL_P (TYPE_SIZE_UNIT (TREE_TYPE (decl))))
    8471                 :         267 :         omp_notice_variable (ctx, TYPE_SIZE_UNIT (TREE_TYPE (decl)), true);
    8472                 :             :     }
    8473                 :      667376 :   else if ((flags & (GOVD_MAP | GOVD_LOCAL)) == 0
    8474                 :      667376 :            && omp_privatize_by_reference (decl))
    8475                 :             :     {
    8476                 :       10278 :       omp_firstprivatize_type_sizes (ctx, TREE_TYPE (decl));
    8477                 :             : 
    8478                 :             :       /* Similar to the direct variable sized case above, we'll need the
    8479                 :             :          size of references being privatized.  */
    8480                 :       10278 :       if ((flags & GOVD_SHARED) == 0)
    8481                 :             :         {
    8482                 :        6487 :           t = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl)));
    8483                 :        6487 :           if (t && DECL_P (t))
    8484                 :        1337 :             omp_notice_variable (ctx, t, true);
    8485                 :             :         }
    8486                 :             :     }
    8487                 :             : 
    8488                 :      668688 :   if (n != NULL)
    8489                 :        1791 :     n->value |= flags;
    8490                 :             :   else
    8491                 :      666897 :     splay_tree_insert (ctx->variables, (splay_tree_key)decl, flags);
    8492                 :             : 
    8493                 :             :   /* For reductions clauses in OpenACC loop directives, by default create a
    8494                 :             :      copy clause on the enclosing parallel construct for carrying back the
    8495                 :             :      results.  */
    8496                 :      668688 :   if (ctx->region_type == ORT_ACC && (flags & GOVD_REDUCTION))
    8497                 :             :     {
    8498                 :        4715 :       struct gimplify_omp_ctx *outer_ctx = ctx->outer_context;
    8499                 :        6454 :       while (outer_ctx)
    8500                 :             :         {
    8501                 :        5787 :           n = splay_tree_lookup (outer_ctx->variables, (splay_tree_key)decl);
    8502                 :        5787 :           if (n != NULL)
    8503                 :             :             {
    8504                 :             :               /* Ignore local variables and explicitly declared clauses.  */
    8505                 :        3989 :               if (n->value & (GOVD_LOCAL | GOVD_EXPLICIT))
    8506                 :             :                 break;
    8507                 :         444 :               else if (outer_ctx->region_type == ORT_ACC_KERNELS)
    8508                 :             :                 {
    8509                 :             :                   /* According to the OpenACC spec, such a reduction variable
    8510                 :             :                      should already have a copy map on a kernels construct,
    8511                 :             :                      verify that here.  */
    8512                 :         144 :                   gcc_assert (!(n->value & GOVD_FIRSTPRIVATE)
    8513                 :             :                               && (n->value & GOVD_MAP));
    8514                 :             :                 }
    8515                 :         300 :               else if (outer_ctx->region_type == ORT_ACC_PARALLEL)
    8516                 :             :                 {
    8517                 :             :                   /* Remove firstprivate and make it a copy map.  */
    8518                 :         150 :                   n->value &= ~GOVD_FIRSTPRIVATE;
    8519                 :         150 :                   n->value |= GOVD_MAP;
    8520                 :             :                 }
    8521                 :             :             }
    8522                 :        1798 :           else if (outer_ctx->region_type == ORT_ACC_PARALLEL)
    8523                 :             :             {
    8524                 :         503 :               splay_tree_insert (outer_ctx->variables, (splay_tree_key)decl,
    8525                 :             :                                  GOVD_MAP | GOVD_SEEN);
    8526                 :         503 :               break;
    8527                 :             :             }
    8528                 :        1739 :           outer_ctx = outer_ctx->outer_context;
    8529                 :             :         }
    8530                 :             :     }
    8531                 :             : }
    8532                 :             : 
    8533                 :             : /* Notice a threadprivate variable DECL used in OMP context CTX.
    8534                 :             :    This just prints out diagnostics about threadprivate variable uses
    8535                 :             :    in untied tasks.  If DECL2 is non-NULL, prevent this warning
    8536                 :             :    on that variable.  */
    8537                 :             : 
    8538                 :             : static bool
    8539                 :       14183 : omp_notice_threadprivate_variable (struct gimplify_omp_ctx *ctx, tree decl,
    8540                 :             :                                    tree decl2)
    8541                 :             : {
    8542                 :       14183 :   splay_tree_node n;
    8543                 :       14183 :   struct gimplify_omp_ctx *octx;
    8544                 :             : 
    8545                 :       28798 :   for (octx = ctx; octx; octx = octx->outer_context)
    8546                 :       14615 :     if ((octx->region_type & ORT_TARGET) != 0
    8547                 :       14615 :         || octx->order_concurrent)
    8548                 :             :       {
    8549                 :         112 :         n = splay_tree_lookup (octx->variables, (splay_tree_key)decl);
    8550                 :         112 :         if (n == NULL)
    8551                 :             :           {
    8552                 :          20 :             if (octx->order_concurrent)
    8553                 :             :               {
    8554                 :          20 :                 error ("threadprivate variable %qE used in a region with"
    8555                 :          20 :                        " %<order(concurrent)%> clause", DECL_NAME (decl));
    8556                 :          20 :                 inform (octx->location, "enclosing region");
    8557                 :             :               }
    8558                 :             :             else
    8559                 :             :               {
    8560                 :           0 :                 error ("threadprivate variable %qE used in target region",
    8561                 :           0 :                        DECL_NAME (decl));
    8562                 :           0 :                 inform (octx->location, "enclosing target region");
    8563                 :             :               }
    8564                 :          20 :             splay_tree_insert (octx->variables, (splay_tree_key)decl, 0);
    8565                 :             :           }
    8566                 :         112 :         if (decl2)
    8567                 :           0 :           splay_tree_insert (octx->variables, (splay_tree_key)decl2, 0);
    8568                 :             :       }
    8569                 :             : 
    8570                 :       14183 :   if (ctx->region_type != ORT_UNTIED_TASK)
    8571                 :             :     return false;
    8572                 :          37 :   n = splay_tree_lookup (ctx->variables, (splay_tree_key)decl);
    8573                 :          37 :   if (n == NULL)
    8574                 :             :     {
    8575                 :           6 :       error ("threadprivate variable %qE used in untied task",
    8576                 :           6 :              DECL_NAME (decl));
    8577                 :           6 :       inform (ctx->location, "enclosing task");
    8578                 :           6 :       splay_tree_insert (ctx->variables, (splay_tree_key)decl, 0);
    8579                 :             :     }
    8580                 :          37 :   if (decl2)
    8581                 :           4 :     splay_tree_insert (ctx->variables, (splay_tree_key)decl2, 0);
    8582                 :             :   return false;
    8583                 :             : }
    8584                 :             : 
    8585                 :             : /* Return true if global var DECL is device resident.  */
    8586                 :             : 
    8587                 :             : static bool
    8588                 :         617 : device_resident_p (tree decl)
    8589                 :             : {
    8590                 :         617 :   tree attr = lookup_attribute ("oacc declare target", DECL_ATTRIBUTES (decl));
    8591                 :             : 
    8592                 :         617 :   if (!attr)
    8593                 :             :     return false;
    8594                 :             : 
    8595                 :           0 :   for (tree t = TREE_VALUE (attr); t; t = TREE_PURPOSE (t))
    8596                 :             :     {
    8597                 :           0 :       tree c = TREE_VALUE (t);
    8598                 :           0 :       if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DEVICE_RESIDENT)
    8599                 :             :         return true;
    8600                 :             :     }
    8601                 :             : 
    8602                 :             :   return false;
    8603                 :             : }
    8604                 :             : 
    8605                 :             : /* Return true if DECL has an ACC DECLARE attribute.  */
    8606                 :             : 
    8607                 :             : static bool
    8608                 :        9096 : is_oacc_declared (tree decl)
    8609                 :             : {
    8610                 :        9096 :   tree t = TREE_CODE (decl) == MEM_REF ? TREE_OPERAND (decl, 0) : decl;
    8611                 :        9096 :   tree declared = lookup_attribute ("oacc declare target", DECL_ATTRIBUTES (t));
    8612                 :        9096 :   return declared != NULL_TREE;
    8613                 :             : }
    8614                 :             : 
    8615                 :             : /* Determine outer default flags for DECL mentioned in an OMP region
    8616                 :             :    but not declared in an enclosing clause.
    8617                 :             : 
    8618                 :             :    ??? Some compiler-generated variables (like SAVE_EXPRs) could be
    8619                 :             :    remapped firstprivate instead of shared.  To some extent this is
    8620                 :             :    addressed in omp_firstprivatize_type_sizes, but not
    8621                 :             :    effectively.  */
    8622                 :             : 
    8623                 :             : static unsigned
    8624                 :       47245 : omp_default_clause (struct gimplify_omp_ctx *ctx, tree decl,
    8625                 :             :                     bool in_code, unsigned flags)
    8626                 :             : {
    8627                 :       47245 :   enum omp_clause_default_kind default_kind = ctx->default_kind;
    8628                 :       47245 :   enum omp_clause_default_kind kind;
    8629                 :             : 
    8630                 :       47245 :   kind = lang_hooks.decls.omp_predetermined_sharing (decl);
    8631                 :       47245 :   if (ctx->region_type & ORT_TASK)
    8632                 :             :     {
    8633                 :        3501 :       tree detach_clause = omp_find_clause (ctx->clauses, OMP_CLAUSE_DETACH);
    8634                 :             : 
    8635                 :             :       /* The event-handle specified by a detach clause should always be firstprivate,
    8636                 :             :          regardless of the current default.  */
    8637                 :        3713 :       if (detach_clause && OMP_CLAUSE_DECL (detach_clause) == decl)
    8638                 :             :         kind = OMP_CLAUSE_DEFAULT_FIRSTPRIVATE;
    8639                 :             :     }
    8640                 :       47245 :   if (kind != OMP_CLAUSE_DEFAULT_UNSPECIFIED)
    8641                 :             :     default_kind = kind;
    8642                 :       58951 :   else if (VAR_P (decl) && TREE_STATIC (decl) && DECL_IN_CONSTANT_POOL (decl))
    8643                 :             :     default_kind = OMP_CLAUSE_DEFAULT_SHARED;
    8644                 :             :   /* For C/C++ default({,first}private), variables with static storage duration
    8645                 :             :      declared in a namespace or global scope and referenced in construct
    8646                 :             :      must be explicitly specified, i.e. acts as default(none).  */
    8647                 :       44458 :   else if ((default_kind == OMP_CLAUSE_DEFAULT_PRIVATE
    8648                 :       44458 :             || default_kind == OMP_CLAUSE_DEFAULT_FIRSTPRIVATE)
    8649                 :         360 :            && VAR_P (decl)
    8650                 :         321 :            && is_global_var (decl)
    8651                 :         184 :            && (DECL_FILE_SCOPE_P (decl)
    8652                 :         104 :                || (DECL_CONTEXT (decl)
    8653                 :         104 :                    && TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL))
    8654                 :       44586 :            && !lang_GNU_Fortran ())
    8655                 :             :     default_kind = OMP_CLAUSE_DEFAULT_NONE;
    8656                 :             : 
    8657                 :       47116 :   switch (default_kind)
    8658                 :             :     {
    8659                 :         267 :     case OMP_CLAUSE_DEFAULT_NONE:
    8660                 :         267 :       {
    8661                 :         267 :         const char *rtype;
    8662                 :             : 
    8663                 :         267 :         if (ctx->region_type & ORT_PARALLEL)
    8664                 :             :           rtype = "parallel";
    8665                 :         108 :         else if ((ctx->region_type & ORT_TASKLOOP) == ORT_TASKLOOP)
    8666                 :             :           rtype = "taskloop";
    8667                 :          72 :         else if (ctx->region_type & ORT_TASK)
    8668                 :             :           rtype = "task";
    8669                 :          36 :         else if (ctx->region_type & ORT_TEAMS)
    8670                 :             :           rtype = "teams";
    8671                 :             :         else
    8672                 :           0 :           gcc_unreachable ();
    8673                 :             : 
    8674                 :         267 :         error ("%qE not specified in enclosing %qs",
    8675                 :         267 :                DECL_NAME (lang_hooks.decls.omp_report_decl (decl)), rtype);
    8676                 :         267 :         inform (ctx->location, "enclosing %qs", rtype);
    8677                 :             :       }
    8678                 :             :       /* FALLTHRU */
    8679                 :       44073 :     case OMP_CLAUSE_DEFAULT_SHARED:
    8680                 :       44073 :       flags |= GOVD_SHARED;
    8681                 :       44073 :       break;
    8682                 :         155 :     case OMP_CLAUSE_DEFAULT_PRIVATE:
    8683                 :         155 :       flags |= GOVD_PRIVATE;
    8684                 :         155 :       break;
    8685                 :         266 :     case OMP_CLAUSE_DEFAULT_FIRSTPRIVATE:
    8686                 :         266 :       flags |= GOVD_FIRSTPRIVATE;
    8687                 :         266 :       break;
    8688                 :        2751 :     case OMP_CLAUSE_DEFAULT_UNSPECIFIED:
    8689                 :             :       /* decl will be either GOVD_FIRSTPRIVATE or GOVD_SHARED.  */
    8690                 :        2751 :       gcc_assert ((ctx->region_type & ORT_TASK) != 0);
    8691                 :        2751 :       if (struct gimplify_omp_ctx *octx = ctx->outer_context)
    8692                 :             :         {
    8693                 :        1698 :           omp_notice_variable (octx, decl, in_code);
    8694                 :        2526 :           for (; octx; octx = octx->outer_context)
    8695                 :             :             {
    8696                 :        2470 :               splay_tree_node n2;
    8697                 :             : 
    8698                 :        2470 :               n2 = splay_tree_lookup (octx->variables, (splay_tree_key) decl);
    8699                 :        2470 :               if ((octx->region_type & (ORT_TARGET_DATA | ORT_TARGET)) != 0
    8700                 :           5 :                   && (n2 == NULL || (n2->value & GOVD_DATA_SHARE_CLASS) == 0))
    8701                 :           5 :                 continue;
    8702                 :        2465 :               if (n2 && (n2->value & GOVD_DATA_SHARE_CLASS) != GOVD_SHARED)
    8703                 :             :                 {
    8704                 :         436 :                   flags |= GOVD_FIRSTPRIVATE;
    8705                 :         436 :                   goto found_outer;
    8706                 :             :                 }
    8707                 :        2029 :               if ((octx->region_type & (ORT_PARALLEL | ORT_TEAMS)) != 0)
    8708                 :             :                 {
    8709                 :        1206 :                   flags |= GOVD_SHARED;
    8710                 :        1206 :                   goto found_outer;
    8711                 :             :                 }
    8712                 :             :             }
    8713                 :             :         }
    8714                 :             : 
    8715                 :        1109 :       if (TREE_CODE (decl) == PARM_DECL
    8716                 :        1109 :           || (!is_global_var (decl)
    8717                 :         233 :               && DECL_CONTEXT (decl) == current_function_decl))
    8718                 :         686 :         flags |= GOVD_FIRSTPRIVATE;
    8719                 :             :       else
    8720                 :         423 :         flags |= GOVD_SHARED;
    8721                 :       47245 :     found_outer:
    8722                 :             :       break;
    8723                 :             : 
    8724                 :           0 :     default:
    8725                 :           0 :       gcc_unreachable ();
    8726                 :             :     }
    8727                 :             : 
    8728                 :       47245 :   return flags;
    8729                 :             : }
    8730                 :             : 
    8731                 :             : /* Return string name for types of OpenACC constructs from ORT_* values.  */
    8732                 :             : 
    8733                 :             : static const char *
    8734                 :         570 : oacc_region_type_name (enum omp_region_type region_type)
    8735                 :             : {
    8736                 :         570 :   switch (region_type)
    8737                 :             :     {
    8738                 :             :     case ORT_ACC_DATA:
    8739                 :             :       return "data";
    8740                 :         140 :     case ORT_ACC_PARALLEL:
    8741                 :         140 :       return "parallel";
    8742                 :         140 :     case ORT_ACC_KERNELS:
    8743                 :         140 :       return "kernels";
    8744                 :         140 :     case ORT_ACC_SERIAL:
    8745                 :         140 :       return "serial";
    8746                 :           0 :     default:
    8747                 :           0 :       gcc_unreachable ();
    8748                 :             :     }
    8749                 :             : }
    8750                 :             : 
    8751                 :             : /* Determine outer default flags for DECL mentioned in an OACC region
    8752                 :             :    but not declared in an enclosing clause.  */
    8753                 :             : 
    8754                 :             : static unsigned
    8755                 :        8834 : oacc_default_clause (struct gimplify_omp_ctx *ctx, tree decl, unsigned flags)
    8756                 :             : {
    8757                 :        8834 :   struct gimplify_omp_ctx *ctx_default = ctx;
    8758                 :             :   /* If no 'default' clause appears on this compute construct...  */
    8759                 :        8834 :   if (ctx_default->default_kind == OMP_CLAUSE_DEFAULT_SHARED)
    8760                 :             :     {
    8761                 :             :       /* ..., see if one appears on a lexically containing 'data'
    8762                 :             :          construct.  */
    8763                 :        9618 :       while ((ctx_default = ctx_default->outer_context))
    8764                 :             :         {
    8765                 :        1533 :           if (ctx_default->region_type == ORT_ACC_DATA
    8766                 :        1533 :               && ctx_default->default_kind != OMP_CLAUSE_DEFAULT_SHARED)
    8767                 :             :             break;
    8768                 :             :         }
    8769                 :             :       /* If not, reset.  */
    8770                 :        8261 :       if (!ctx_default)
    8771                 :        8658 :         ctx_default = ctx;
    8772                 :             :     }
    8773                 :             : 
    8774                 :        8834 :   bool on_device = false;
    8775                 :        8834 :   bool is_private = false;
    8776                 :        8834 :   bool declared = is_oacc_declared (decl);
    8777                 :        8834 :   tree type = TREE_TYPE (decl);
    8778                 :             : 
    8779                 :        8834 :   if (omp_privatize_by_reference (decl))
    8780                 :         338 :     type = TREE_TYPE (type);
    8781                 :             : 
    8782                 :             :   /* For Fortran COMMON blocks, only used variables in those blocks are
    8783                 :             :      transfered and remapped.  The block itself will have a private clause to
    8784                 :             :      avoid transfering the data twice.
    8785                 :             :      The hook evaluates to false by default.  For a variable in Fortran's COMMON
    8786                 :             :      or EQUIVALENCE block, returns 'true' (as we have shared=false) - as only
    8787                 :             :      the variables in such a COMMON/EQUIVALENCE block shall be privatized not
    8788                 :             :      the whole block.  For C++ and Fortran, it can also be true under certain
    8789                 :             :      other conditions, if DECL_HAS_VALUE_EXPR.  */
    8790                 :        8834 :   if (RECORD_OR_UNION_TYPE_P (type))
    8791                 :         955 :     is_private = lang_hooks.decls.omp_disregard_value_expr (decl, false);
    8792                 :             : 
    8793                 :        8834 :   if ((ctx->region_type & (ORT_ACC_PARALLEL | ORT_ACC_KERNELS)) != 0
    8794                 :        8834 :       && is_global_var (decl)
    8795                 :         617 :       && device_resident_p (decl)
    8796                 :        8834 :       && !is_private)
    8797                 :             :     {
    8798                 :           0 :       on_device = true;
    8799                 :           0 :       flags |= GOVD_MAP_TO_ONLY;
    8800                 :             :     }
    8801                 :             : 
    8802                 :        8834 :   switch (ctx->region_type)
    8803                 :             :     {
    8804                 :        1491 :     case ORT_ACC_KERNELS:
    8805                 :        1491 :       if (is_private)
    8806                 :           0 :         flags |= GOVD_FIRSTPRIVATE;
    8807                 :        1491 :       else if (AGGREGATE_TYPE_P (type))
    8808                 :             :         {
    8809                 :             :           /* Aggregates default to 'present_or_copy', or 'present'.  */
    8810                 :         429 :           if (ctx_default->default_kind != OMP_CLAUSE_DEFAULT_PRESENT)
    8811                 :         411 :             flags |= GOVD_MAP;
    8812                 :             :           else
    8813                 :          18 :             flags |= GOVD_MAP | GOVD_MAP_FORCE_PRESENT;
    8814                 :             :         }
    8815                 :             :       else
    8816                 :             :         /* Scalars default to 'copy'.  */
    8817                 :        1062 :         flags |= GOVD_MAP | GOVD_MAP_FORCE;
    8818                 :             : 
    8819                 :             :       break;
    8820                 :             : 
    8821                 :        7343 :     case ORT_ACC_PARALLEL:
    8822                 :        7343 :     case ORT_ACC_SERIAL:
    8823                 :        7343 :       if (is_private)
    8824                 :           0 :         flags |= GOVD_FIRSTPRIVATE;
    8825                 :        7343 :       else if (on_device || declared)
    8826                 :          17 :         flags |= GOVD_MAP;
    8827                 :        7326 :       else if (AGGREGATE_TYPE_P (type))
    8828                 :             :         {
    8829                 :             :           /* Aggregates default to 'present_or_copy', or 'present'.  */
    8830                 :        3664 :           if (ctx_default->default_kind != OMP_CLAUSE_DEFAULT_PRESENT)
    8831                 :        3401 :             flags |= GOVD_MAP;
    8832                 :             :           else
    8833                 :         263 :             flags |= GOVD_MAP | GOVD_MAP_FORCE_PRESENT;
    8834                 :             :         }
    8835                 :             :       else
    8836                 :             :         /* Scalars default to 'firstprivate'.  */
    8837                 :        3662 :         flags |= GOVD_FIRSTPRIVATE;
    8838                 :             : 
    8839                 :             :       break;
    8840                 :             : 
    8841                 :           0 :     default:
    8842                 :           0 :       gcc_unreachable ();
    8843                 :             :     }
    8844                 :             : 
    8845                 :        8834 :   if (DECL_ARTIFICIAL (decl))
    8846                 :             :     ; /* We can get compiler-generated decls, and should not complain
    8847                 :             :          about them.  */
    8848                 :        8547 :   else if (ctx_default->default_kind == OMP_CLAUSE_DEFAULT_NONE)
    8849                 :             :     {
    8850                 :         420 :       error ("%qE not specified in enclosing OpenACC %qs construct",
    8851                 :         210 :              DECL_NAME (lang_hooks.decls.omp_report_decl (decl)),
    8852                 :             :              oacc_region_type_name (ctx->region_type));
    8853                 :         210 :       if (ctx_default != ctx)
    8854                 :         150 :         inform (ctx->location, "enclosing OpenACC %qs construct and",
    8855                 :             :                 oacc_region_type_name (ctx->region_type));
    8856                 :         210 :       inform (ctx_default->location,
    8857                 :             :               "enclosing OpenACC %qs construct with %qs clause",
    8858                 :             :               oacc_region_type_name (ctx_default->region_type),
    8859                 :             :               "default(none)");
    8860                 :             :     }
    8861                 :        8337 :   else if (ctx_default->default_kind == OMP_CLAUSE_DEFAULT_PRESENT)
    8862                 :             :     ; /* Handled above.  */
    8863                 :             :   else
    8864                 :        7804 :     gcc_checking_assert (ctx_default->default_kind == OMP_CLAUSE_DEFAULT_SHARED);
    8865                 :             : 
    8866                 :        8834 :   return flags;
    8867                 :             : }
    8868                 :             : 
    8869                 :             : /* Record the fact that DECL was used within the OMP context CTX.
    8870                 :             :    IN_CODE is true when real code uses DECL, and false when we should
    8871                 :             :    merely emit default(none) errors.  Return true if DECL is going to
    8872                 :             :    be remapped and thus DECL shouldn't be gimplified into its
    8873                 :             :    DECL_VALUE_EXPR (if any).  */
    8874                 :             : 
    8875                 :             : static bool
    8876                 :     3671278 : omp_notice_variable (struct gimplify_omp_ctx *ctx, tree decl, bool in_code)
    8877                 :             : {
    8878                 :     3671278 :   splay_tree_node n;
    8879                 :     3671278 :   unsigned flags = in_code ? GOVD_SEEN : 0;
    8880                 :     3671278 :   bool ret = false, shared;
    8881                 :             : 
    8882                 :     3671278 :   if (error_operand_p (decl))
    8883                 :             :     return false;
    8884                 :             : 
    8885                 :     3671278 :   if (DECL_ARTIFICIAL (decl))
    8886                 :             :     {
    8887                 :     2097386 :       tree attr = lookup_attribute ("omp allocate var", DECL_ATTRIBUTES (decl));
    8888                 :     2097386 :       if (attr)
    8889                 :         531 :         decl = TREE_VALUE (TREE_VALUE (attr));
    8890                 :             :     }
    8891                 :             : 
    8892                 :     3671278 :   if (ctx->region_type == ORT_NONE)
    8893                 :         156 :     return lang_hooks.decls.omp_disregard_value_expr (decl, false);
    8894                 :             : 
    8895                 :     3671122 :   if (is_global_var (decl))
    8896                 :             :     {
    8897                 :             :       /* Threadprivate variables are predetermined.  */
    8898                 :      465916 :       if (DECL_THREAD_LOCAL_P (decl))
    8899                 :       13565 :         return omp_notice_threadprivate_variable (ctx, decl, NULL_TREE);
    8900                 :             : 
    8901                 :      452351 :       if (DECL_HAS_VALUE_EXPR_P (decl))
    8902                 :             :         {
    8903                 :        4362 :           if (ctx->region_type & ORT_ACC)
    8904                 :             :             /* For OpenACC, defer expansion of value to avoid transfering
    8905                 :             :                privatized common block data instead of im-/explicitly transfered
    8906                 :             :                variables which are in common blocks.  */
    8907                 :             :             ;
    8908                 :             :           else
    8909                 :             :             {
    8910                 :        2086 :               tree value = get_base_address (DECL_VALUE_EXPR (decl));
    8911                 :             : 
    8912                 :        2086 :               if (value && DECL_P (value) && DECL_THREAD_LOCAL_P (value))
    8913                 :         618 :                 return omp_notice_threadprivate_variable (ctx, decl, value);
    8914                 :             :             }
    8915                 :             :         }
    8916                 :             : 
    8917                 :      451733 :       if (gimplify_omp_ctxp->outer_context == NULL
    8918                 :       79915 :           && VAR_P (decl)
    8919                 :      531648 :           && oacc_get_fn_attrib (current_function_decl))
    8920                 :             :         {
    8921                 :         746 :           location_t loc = DECL_SOURCE_LOCATION (decl);
    8922                 :             : 
    8923                 :         746 :           if (lookup_attribute ("omp declare target link",
    8924                 :         746 :                                 DECL_ATTRIBUTES (decl)))
    8925                 :             :             {
    8926                 :          48 :               error_at (loc,
    8927                 :             :                         "%qE with %<link%> clause used in %<routine%> function",
    8928                 :          24 :                         DECL_NAME (decl));
    8929                 :          24 :               return false;
    8930                 :             :             }
    8931                 :         722 :           else if (!lookup_attribute ("omp declare target",
    8932                 :         722 :                                       DECL_ATTRIBUTES (decl)))
    8933                 :             :             {
    8934                 :         132 :               error_at (loc,
    8935                 :             :                         "%qE requires a %<declare%> directive for use "
    8936                 :          66 :                         "in a %<routine%> function", DECL_NAME (decl));
    8937                 :          66 :               return false;
    8938                 :             :             }
    8939                 :             :         }
    8940                 :             :     }
    8941                 :             : 
    8942                 :     3656849 :   n = splay_tree_lookup (ctx->variables, (splay_tree_key)decl);
    8943                 :     3656849 :   if ((ctx->region_type & ORT_TARGET) != 0)
    8944                 :             :     {
    8945                 :      623063 :       if (n == NULL)
    8946                 :             :         {
    8947                 :       33137 :           unsigned nflags = flags;
    8948                 :       33137 :           if ((ctx->region_type & ORT_ACC) == 0)
    8949                 :             :             {
    8950                 :       22187 :               bool is_declare_target = false;
    8951                 :       22187 :               if (is_global_var (decl)
    8952                 :       22187 :                   && varpool_node::get_create (decl)->offloadable)
    8953                 :             :                 {
    8954                 :        6972 :                   struct gimplify_omp_ctx *octx;
    8955                 :        6972 :                   for (octx = ctx->outer_context;
    8956                 :        6980 :                        octx; octx = octx->outer_context)
    8957                 :             :                     {
    8958                 :           9 :                       n = splay_tree_lookup (octx->variables,
    8959                 :             :                                              (splay_tree_key)decl);
    8960                 :           9 :                       if (n
    8961                 :           9 :                           && (n->value & GOVD_DATA_SHARE_CLASS) != GOVD_SHARED
    8962                 :           9 :                           && (n->value & GOVD_DATA_SHARE_CLASS) != 0)
    8963                 :             :                         break;
    8964                 :             :                     }
    8965                 :        6972 :                   is_declare_target = octx == NULL;
    8966                 :             :                 }
    8967                 :        6972 :               if (!is_declare_target)
    8968                 :             :                 {
    8969                 :       15216 :                   int gdmk;
    8970                 :       15216 :                   enum omp_clause_defaultmap_kind kind;
    8971                 :       15216 :                   if (lang_hooks.decls.omp_allocatable_p (decl))
    8972                 :             :                     gdmk = GDMK_ALLOCATABLE;
    8973                 :       14901 :                   else if (lang_hooks.decls.omp_scalar_target_p (decl))
    8974                 :             :                     gdmk = GDMK_SCALAR_TARGET;
    8975                 :       14826 :                   else if (lang_hooks.decls.omp_scalar_p (decl, false))
    8976                 :             :                     gdmk = GDMK_SCALAR;
    8977                 :        2059 :                   else if (TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE
    8978                 :        2059 :                            || (TREE_CODE (TREE_TYPE (decl)) == REFERENCE_TYPE
    8979                 :         274 :                                && (TREE_CODE (TREE_TYPE (TREE_TYPE (decl)))
    8980                 :             :                                    == POINTER_TYPE)))
    8981                 :             :                     gdmk = GDMK_POINTER;
    8982                 :             :                   else
    8983                 :             :                     gdmk = GDMK_AGGREGATE;
    8984                 :       15216 :                   kind = lang_hooks.decls.omp_predetermined_mapping (decl);
    8985                 :       15216 :                   if (kind != OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED)
    8986                 :             :                     {
    8987                 :         904 :                       if (kind == OMP_CLAUSE_DEFAULTMAP_FIRSTPRIVATE)
    8988                 :         101 :                         nflags |= GOVD_FIRSTPRIVATE;
    8989                 :         803 :                       else if (kind == OMP_CLAUSE_DEFAULTMAP_TO)
    8990                 :         803 :                         nflags |= GOVD_MAP | GOVD_MAP_TO_ONLY;
    8991                 :             :                       else
    8992                 :           0 :                         gcc_unreachable ();
    8993                 :             :                     }
    8994                 :       14312 :                   else if (ctx->defaultmap[gdmk] == 0)
    8995                 :             :                     {
    8996                 :          72 :                       tree d = lang_hooks.decls.omp_report_decl (decl);
    8997                 :          72 :                       error ("%qE not specified in enclosing %<target%>",
    8998                 :          72 :                              DECL_NAME (d));
    8999                 :          72 :                       inform (ctx->location, "enclosing %<target%>");
    9000                 :             :                     }
    9001                 :       14240 :                   else if (ctx->defaultmap[gdmk]
    9002                 :       14240 :                            & (GOVD_MAP_0LEN_ARRAY | GOVD_FIRSTPRIVATE))
    9003                 :        8842 :                     nflags |= ctx->defaultmap[gdmk];
    9004                 :        5398 :                   else if (ctx->defaultmap[gdmk] & GOVD_MAP_FORCE_PRESENT)
    9005                 :             :                     {
    9006                 :          39 :                       gcc_assert (ctx->defaultmap[gdmk] & GOVD_MAP);
    9007                 :          39 :                       nflags |= ctx->defaultmap[gdmk] | GOVD_MAP_ALLOC_ONLY;
    9008                 :             :                     }
    9009                 :             :                   else
    9010                 :             :                     {
    9011                 :        5359 :                       gcc_assert (ctx->defaultmap[gdmk] & GOVD_MAP);
    9012                 :        5359 :                       nflags |= ctx->defaultmap[gdmk] & ~GOVD_MAP;
    9013                 :             :                     }
    9014                 :             :                 }
    9015                 :             :             }
    9016                 :             : 
    9017                 :       33137 :           struct gimplify_omp_ctx *octx = ctx->outer_context;
    9018                 :       33137 :           if ((ctx->region_type & ORT_ACC) && octx)
    9019                 :             :             {
    9020                 :             :               /* Look in outer OpenACC contexts, to see if there's a
    9021                 :             :                  data attribute for this variable.  */
    9022                 :        3535 :               omp_notice_variable (octx, decl, in_code);
    9023                 :             : 
    9024                 :        5306 :               for (; octx; octx = octx->outer_context)
    9025                 :             :                 {
    9026                 :        3883 :                   if (!(octx->region_type & (ORT_TARGET_DATA | ORT_TARGET)))
    9027                 :             :                     break;
    9028                 :        3883 :                   splay_tree_node n2
    9029                 :        3883 :                     = splay_tree_lookup (octx->variables,
    9030                 :             :                                          (splay_tree_key) decl);
    9031                 :        3883 :                   if (n2)
    9032                 :             :                     {
    9033                 :        2112 :                       if (octx->region_type == ORT_ACC_HOST_DATA)
    9034                 :           4 :                         error ("variable %qE declared in enclosing "
    9035                 :           4 :                                "%<host_data%> region", DECL_NAME (decl));
    9036                 :        2112 :                       nflags |= GOVD_MAP;
    9037                 :        2112 :                       if (octx->region_type == ORT_ACC_DATA
    9038                 :        2108 :                           && (n2->value & GOVD_MAP_0LEN_ARRAY))
    9039                 :         288 :                         nflags |= GOVD_MAP_0LEN_ARRAY;
    9040                 :        2112 :                       goto found_outer;
    9041                 :             :                     }
    9042                 :             :                 }
    9043                 :             :             }
    9044                 :             : 
    9045                 :       31025 :           if ((nflags & ~(GOVD_MAP_TO_ONLY | GOVD_MAP_FROM_ONLY
    9046                 :             :                           | GOVD_MAP_ALLOC_ONLY)) == flags)
    9047                 :             :             {
    9048                 :       21240 :               tree type = TREE_TYPE (decl);
    9049                 :             : 
    9050                 :       21240 :               if (gimplify_omp_ctxp->target_firstprivatize_array_bases
    9051                 :       21240 :                   && omp_privatize_by_reference (decl))
    9052                 :          26 :                 type = TREE_TYPE (type);
    9053                 :       21240 :               if (!omp_mappable_type (type))
    9054                 :             :                 {
    9055                 :           8 :                   error ("%qD referenced in target region does not have "
    9056                 :             :                          "a mappable type", decl);
    9057                 :           8 :                   nflags |= GOVD_MAP | GOVD_EXPLICIT;
    9058                 :             :                 }
    9059                 :             :               else
    9060                 :             :                 {
    9061                 :       21232 :                   if ((ctx->region_type & ORT_ACC) != 0)
    9062                 :        8834 :                     nflags = oacc_default_clause (ctx, decl, flags);
    9063                 :             :                   else
    9064                 :       12398 :                     nflags |= GOVD_MAP;
    9065                 :             :                 }
    9066                 :             :             }
    9067                 :        9785 :         found_outer:
    9068                 :       33137 :           omp_add_variable (ctx, decl, nflags);
    9069                 :       33137 :           if (ctx->region_type & ORT_ACC)
    9070                 :             :             /* For OpenACC, as remarked above, defer expansion.  */
    9071                 :             :             shared = false;
    9072                 :             :           else
    9073                 :       22187 :             shared = (nflags & (GOVD_PRIVATE | GOVD_FIRSTPRIVATE)) == 0;
    9074                 :       33137 :           ret = lang_hooks.decls.omp_disregard_value_expr (decl, shared);
    9075                 :             :         }
    9076                 :             :       else
    9077                 :             :         {
    9078                 :      589926 :           if (ctx->region_type & ORT_ACC)
    9079                 :             :             /* For OpenACC, as remarked above, defer expansion.  */
    9080                 :             :             shared = false;
    9081                 :             :           else
    9082                 :      296402 :             shared = ((n->value | flags)
    9083                 :      296402 :                       & (GOVD_PRIVATE | GOVD_FIRSTPRIVATE)) == 0;
    9084                 :      589926 :           ret = lang_hooks.decls.omp_disregard_value_expr (decl, shared);
    9085                 :             :           /* If nothing changed, there's nothing left to do.  */
    9086                 :      589926 :           if ((n->value & flags) == flags)
    9087                 :             :             return ret;
    9088                 :       15146 :           flags |= n->value;
    9089                 :       15146 :           n->value = flags;
    9090                 :             :         }
    9091                 :       48283 :       goto do_outer;
    9092                 :             :     }
    9093                 :             : 
    9094                 :     3033786 :   if (n == NULL)
    9095                 :             :     {
    9096                 :     1178306 :       if (ctx->region_type == ORT_WORKSHARE
    9097                 :             :           || ctx->region_type == ORT_TASKGROUP
    9098                 :      559424 :           || ctx->region_type == ORT_SIMD
    9099                 :      287520 :           || ctx->region_type == ORT_ACC
    9100                 :       91295 :           || (ctx->region_type & ORT_TARGET_DATA) != 0)
    9101                 :     1131061 :         goto do_outer;
    9102                 :             : 
    9103                 :       47245 :       flags = omp_default_clause (ctx, decl, in_code, flags);
    9104                 :             : 
    9105                 :       47245 :       if ((flags & GOVD_PRIVATE)
    9106                 :       47245 :           && lang_hooks.decls.omp_private_outer_ref (decl))
    9107                 :           6 :         flags |= GOVD_PRIVATE_OUTER_REF;
    9108                 :             : 
    9109                 :       47245 :       omp_add_variable (ctx, decl, flags);
    9110                 :             : 
    9111                 :       47245 :       shared = (flags & GOVD_SHARED) != 0;
    9112                 :       47245 :       ret = lang_hooks.decls.omp_disregard_value_expr (decl, shared);
    9113                 :       47245 :       goto do_outer;
    9114                 :             :     }
    9115                 :             : 
    9116                 :             :   /* Don't mark as GOVD_SEEN addressable temporaries seen only in simd
    9117                 :             :      lb, b or incr expressions, those shouldn't be turned into simd arrays.  */
    9118                 :     1855480 :   if (ctx->region_type == ORT_SIMD
    9119                 :      151029 :       && ctx->in_for_exprs
    9120                 :          70 :       && ((n->value & (GOVD_PRIVATE | GOVD_SEEN | GOVD_EXPLICIT))
    9121                 :             :           == GOVD_PRIVATE))
    9122                 :     1855480 :     flags &= ~GOVD_SEEN;
    9123                 :             : 
    9124                 :     1855480 :   if ((n->value & (GOVD_SEEN | GOVD_LOCAL)) == 0
    9125                 :       31814 :       && (flags & (GOVD_SEEN | GOVD_LOCAL)) == GOVD_SEEN
    9126                 :     1887255 :       && DECL_SIZE (decl))
    9127                 :             :     {
    9128                 :       31774 :       if (TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
    9129                 :             :         {
    9130                 :         140 :           splay_tree_node n2;
    9131                 :         140 :           tree t = DECL_VALUE_EXPR (decl);
    9132                 :         140 :           gcc_assert (INDIRECT_REF_P (t));
    9133                 :         140 :           t = TREE_OPERAND (t, 0);
    9134                 :         140 :           gcc_assert (DECL_P (t));
    9135                 :         140 :           n2 = splay_tree_lookup (ctx->variables, (splay_tree_key) t);
    9136                 :         140 :           n2->value |= GOVD_SEEN;
    9137                 :             :         }
    9138                 :       31634 :       else if (omp_privatize_by_reference (decl)
    9139                 :        4205 :                && TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl)))
    9140                 :       35802 :                && (TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl))))
    9141                 :             :                    != INTEGER_CST))
    9142                 :             :         {
    9143                 :        1324 :           splay_tree_node n2;
    9144                 :        1324 :           tree t = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl)));
    9145                 :        1324 :           gcc_assert (DECL_P (t));
    9146                 :        1324 :           n2 = splay_tree_lookup (ctx->variables, (splay_tree_key) t);
    9147                 :        1324 :           if (n2)
    9148                 :         617 :             omp_notice_variable (ctx, t, true);
    9149                 :             :         }
    9150                 :             :     }
    9151                 :             : 
    9152                 :     1855480 :   if (ctx->region_type & ORT_ACC)
    9153                 :             :     /* For OpenACC, as remarked above, defer expansion.  */
    9154                 :             :     shared = false;
    9155                 :             :   else
    9156                 :     1674048 :     shared = ((flags | n->value) & GOVD_SHARED) != 0;
    9157                 :     1855480 :   ret = lang_hooks.decls.omp_disregard_value_expr (decl, shared);
    9158                 :             : 
    9159                 :             :   /* If nothing changed, there's nothing left to do.  */
    9160                 :     1855480 :   if ((n->value & flags) == flags)
    9161                 :             :     return ret;
    9162                 :       31775 :   flags |= n->value;
    9163                 :       31775 :   n->value = flags;
    9164                 :             : 
    9165                 :     1258364 :  do_outer:
    9166                 :             :   /* If the variable is private in the current context, then we don't
    9167                 :             :      need to propagate anything to an outer context.  */
    9168                 :     1258364 :   if ((flags & GOVD_PRIVATE) && !(flags & GOVD_PRIVATE_OUTER_REF))
    9169                 :             :     return ret;
    9170                 :     1248017 :   if ((flags & (GOVD_LINEAR | GOVD_LINEAR_LASTPRIVATE_NO_OUTER))
    9171                 :             :       == (GOVD_LINEAR | GOVD_LINEAR_LASTPRIVATE_NO_OUTER))
    9172                 :             :     return ret;
    9173                 :     1247957 :   if ((flags & (GOVD_FIRSTPRIVATE | GOVD_LASTPRIVATE
    9174                 :             :                 | GOVD_LINEAR_LASTPRIVATE_NO_OUTER))
    9175                 :             :       == (GOVD_LASTPRIVATE | GOVD_LINEAR_LASTPRIVATE_NO_OUTER))
    9176                 :             :     return ret;
    9177                 :     1247957 :   if (ctx->outer_context
    9178                 :     1247957 :       && omp_notice_variable (ctx->outer_context, decl, in_code))
    9179                 :             :     return true;
    9180                 :             :   return ret;
    9181                 :             : }
    9182                 :             : 
    9183                 :             : /* Verify that DECL is private within CTX.  If there's specific information
    9184                 :             :    to the contrary in the innermost scope, generate an error.  */
    9185                 :             : 
    9186                 :             : static bool
    9187                 :       50093 : omp_is_private (struct gimplify_omp_ctx *ctx, tree decl, int simd)
    9188                 :             : {
    9189                 :       95764 :   splay_tree_node n;
    9190                 :             : 
    9191                 :       95764 :   n = splay_tree_lookup (ctx->variables, (splay_tree_key)decl);
    9192                 :       95764 :   if (n != NULL)
    9193                 :             :     {
    9194                 :       17981 :       if (n->value & GOVD_SHARED)
    9195                 :             :         {
    9196                 :         407 :           if (ctx == gimplify_omp_ctxp)
    9197                 :             :             {
    9198                 :           0 :               if (simd)
    9199                 :           0 :                 error ("iteration variable %qE is predetermined linear",
    9200                 :           0 :                        DECL_NAME (decl));
    9201                 :             :               else
    9202                 :           0 :                 error ("iteration variable %qE should be private",
    9203                 :           0 :                        DECL_NAME (decl));
    9204                 :           0 :               n->value = GOVD_PRIVATE;
    9205                 :           0 :               return true;
    9206                 :             :             }
    9207                 :             :           else
    9208                 :             :             return false;
    9209                 :             :         }
    9210                 :       17574 :       else if ((n->value & GOVD_EXPLICIT) != 0
    9211                 :        9719 :                && (ctx == gimplify_omp_ctxp
    9212                 :         331 :                    || (ctx->region_type == ORT_COMBINED_PARALLEL
    9213                 :         211 :                        && gimplify_omp_ctxp->outer_context == ctx)))
    9214                 :             :         {
    9215                 :        9599 :           if ((n->value & GOVD_FIRSTPRIVATE) != 0)
    9216                 :           4 :             error ("iteration variable %qE should not be firstprivate",
    9217                 :           4 :                    DECL_NAME (decl));
    9218                 :        9595 :           else if ((n->value & GOVD_REDUCTION) != 0)
    9219                 :           8 :             error ("iteration variable %qE should not be reduction",
    9220                 :           8 :                    DECL_NAME (decl));
    9221                 :        9587 :           else if (simd != 1 && (n->value & GOVD_LINEAR) != 0)
    9222                 :          58 :             error ("iteration variable %qE should not be linear",
    9223                 :          58 :                    DECL_NAME (decl));
    9224                 :             :         }
    9225                 :       17574 :       return (ctx == gimplify_omp_ctxp
    9226                 :       17574 :               || (ctx->region_type == ORT_COMBINED_PARALLEL
    9227                 :       19439 :                   && gimplify_omp_ctxp->outer_context == ctx));
    9228                 :             :     }
    9229                 :             : 
    9230                 :       77783 :   if (ctx->region_type != ORT_WORKSHARE
    9231                 :             :       && ctx->region_type != ORT_TASKGROUP
    9232                 :       49405 :       && ctx->region_type != ORT_SIMD
    9233                 :       36158 :       && ctx->region_type != ORT_ACC)
    9234                 :             :     return false;
    9235                 :       53822 :   else if (ctx->outer_context)
    9236                 :             :     return omp_is_private (ctx->outer_context, decl, simd);
    9237                 :             :   return false;
    9238                 :             : }
    9239                 :             : 
    9240                 :             : /* Return true if DECL is private within a parallel region
    9241                 :             :    that binds to the current construct's context or in parallel
    9242                 :             :    region's REDUCTION clause.  */
    9243                 :             : 
    9244                 :             : static bool
    9245                 :       11529 : omp_check_private (struct gimplify_omp_ctx *ctx, tree decl, bool copyprivate)
    9246                 :             : {
    9247                 :       11601 :   splay_tree_node n;
    9248                 :             : 
    9249                 :       11601 :   do
    9250                 :             :     {
    9251                 :       11601 :       ctx = ctx->outer_context;
    9252                 :       11601 :       if (ctx == NULL)
    9253                 :             :         {
    9254                 :        2764 :           if (is_global_var (decl))
    9255                 :             :             return false;
    9256                 :             : 
    9257                 :             :           /* References might be private, but might be shared too,
    9258                 :             :              when checking for copyprivate, assume they might be
    9259                 :             :              private, otherwise assume they might be shared.  */
    9260                 :        1290 :           if (copyprivate)
    9261                 :             :             return true;
    9262                 :             : 
    9263                 :        1244 :           if (omp_privatize_by_reference (decl))
    9264                 :             :             return false;
    9265                 :             : 
    9266                 :             :           /* Treat C++ privatized non-static data members outside
    9267                 :             :              of the privatization the same.  */
    9268                 :        1198 :           if (omp_member_access_dummy_var (decl))
    9269                 :             :             return false;
    9270                 :             : 
    9271                 :             :           return true;
    9272                 :             :         }
    9273                 :             : 
    9274                 :        8837 :       n = splay_tree_lookup (ctx->variables, (splay_tree_key) decl);
    9275                 :             : 
    9276                 :        8837 :       if ((ctx->region_type & (ORT_TARGET | ORT_TARGET_DATA)) != 0
    9277                 :        1291 :           && (n == NULL || (n->value & GOVD_DATA_SHARE_CLASS) == 0))
    9278                 :             :         {
    9279                 :         242 :           if ((ctx->region_type & ORT_TARGET_DATA) != 0
    9280                 :         238 :               || n == NULL
    9281                 :         230 :               || (n->value & GOVD_MAP) == 0)
    9282                 :          12 :             continue;
    9283                 :             :           return false;
    9284                 :             :         }
    9285                 :             : 
    9286                 :        7546 :       if (n != NULL)
    9287                 :             :         {
    9288                 :        5346 :           if ((n->value & GOVD_LOCAL) != 0
    9289                 :        5346 :               && omp_member_access_dummy_var (decl))
    9290                 :             :             return false;
    9291                 :        5307 :           return (n->value & GOVD_SHARED) == 0;
    9292                 :             :         }
    9293                 :             : 
    9294                 :        3249 :       if (ctx->region_type == ORT_WORKSHARE
    9295                 :             :           || ctx->region_type == ORT_TASKGROUP
    9296                 :        3193 :           || ctx->region_type == ORT_SIMD
    9297                 :        3189 :           || ctx->region_type == ORT_ACC)
    9298                 :          60 :         continue;
    9299                 :             : 
    9300                 :             :       break;
    9301                 :             :     }
    9302                 :             :   while (1);
    9303                 :             :   return false;
    9304                 :             : }
    9305                 :             : 
    9306                 :             : /* Callback for walk_tree to find a DECL_EXPR for the given DECL.  */
    9307                 :             : 
    9308                 :             : static tree
    9309                 :        3148 : find_decl_expr (tree *tp, int *walk_subtrees, void *data)
    9310                 :             : {
    9311                 :        3148 :   tree t = *tp;
    9312                 :             : 
    9313                 :             :   /* If this node has been visited, unmark it and keep looking.  */
    9314                 :        3148 :   if (TREE_CODE (t) == DECL_EXPR && DECL_EXPR_DECL (t) == (tree) data)
    9315                 :             :     return t;
    9316                 :             : 
    9317                 :        2724 :   if (IS_TYPE_OR_DECL_P (t))
    9318                 :         452 :     *walk_subtrees = 0;
    9319                 :             :   return NULL_TREE;
    9320                 :             : }
    9321                 :             : 
    9322                 :             : 
    9323                 :             : /* Gimplify the affinity clause but effectively ignore it.
    9324                 :             :    Generate:
    9325                 :             :      var = begin;
    9326                 :             :      if ((step > 1) ? var <= end : var > end)
    9327                 :             :        locatator_var_expr;  */
    9328                 :             : 
    9329                 :             : static void
    9330                 :         468 : gimplify_omp_affinity (tree *list_p, gimple_seq *pre_p)
    9331                 :             : {
    9332                 :         468 :   tree last_iter = NULL_TREE;
    9333                 :         468 :   tree last_bind = NULL_TREE;
    9334                 :         468 :   tree label = NULL_TREE;
    9335                 :         468 :   tree *last_body = NULL;
    9336                 :        1203 :   for (tree c = *list_p; c; c = OMP_CLAUSE_CHAIN (c))
    9337                 :         735 :     if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
    9338                 :             :       {
    9339                 :         735 :         tree t = OMP_CLAUSE_DECL (c);
    9340                 :         735 :         if (TREE_CODE (t) == TREE_LIST
    9341                 :         389 :                     && TREE_PURPOSE (t)
    9342                 :        1124 :                     && TREE_CODE (TREE_PURPOSE (t)) == TREE_VEC)
    9343                 :             :           {
    9344                 :         389 :             if (TREE_VALUE (t) == null_pointer_node)
    9345                 :         201 :               continue;
    9346                 :         188 :             if (TREE_PURPOSE (t) != last_iter)
    9347                 :             :               {
    9348                 :         127 :                 if (last_bind)
    9349                 :             :                   {
    9350                 :           9 :                     append_to_statement_list (label, last_body);
    9351                 :           9 :                     gimplify_and_add (last_bind, pre_p);
    9352                 :           9 :                     last_bind = NULL_TREE;
    9353                 :             :                   }
    9354                 :         274 :                 for (tree it = TREE_PURPOSE (t); it; it = TREE_CHAIN (it))
    9355                 :             :                   {
    9356                 :         147 :                     if (gimplify_expr (&TREE_VEC_ELT (it, 1), pre_p, NULL,
    9357                 :             :                                        is_gimple_val, fb_rvalue) == GS_ERROR
    9358                 :         147 :                         || gimplify_expr (&TREE_VEC_ELT (it, 2), pre_p, NULL,
    9359                 :             :                                           is_gimple_val, fb_rvalue) == GS_ERROR
    9360                 :         147 :                         || gimplify_expr (&TREE_VEC_ELT (it, 3), pre_p, NULL,
    9361                 :             :                                           is_gimple_val, fb_rvalue) == GS_ERROR
    9362                 :         294 :                         || (gimplify_expr (&TREE_VEC_ELT (it, 4), pre_p, NULL,
    9363                 :             :                                            is_gimple_val, fb_rvalue)
    9364                 :             :                             == GS_ERROR))
    9365                 :           0 :                       return;
    9366                 :             :                   }
    9367                 :         127 :             last_iter = TREE_PURPOSE (t);
    9368                 :         127 :             tree block = TREE_VEC_ELT (TREE_PURPOSE (t), 5);
    9369                 :         127 :             last_bind = build3 (BIND_EXPR, void_type_node, BLOCK_VARS (block),
    9370                 :             :                                 NULL, block);
    9371                 :         127 :             last_body = &BIND_EXPR_BODY (last_bind);
    9372                 :         127 :             tree cond = NULL_TREE;
    9373                 :         127 :             location_t loc = OMP_CLAUSE_LOCATION (c);
    9374                 :         274 :             for (tree it = TREE_PURPOSE (t); it; it = TREE_CHAIN (it))
    9375                 :             :               {
    9376                 :         147 :                 tree var = TREE_VEC_ELT (it, 0);
    9377                 :         147 :                 tree begin = TREE_VEC_ELT (it, 1);
    9378                 :         147 :                 tree end = TREE_VEC_ELT (it, 2);
    9379                 :         147 :                 tree step = TREE_VEC_ELT (it, 3);
    9380                 :         147 :                 loc = DECL_SOURCE_LOCATION (var);
    9381                 :         147 :                 tree tem = build2_loc (loc, MODIFY_EXPR, void_type_node,
    9382                 :             :                                        var, begin);
    9383                 :         147 :                 append_to_statement_list_force (tem, last_body);
    9384                 :             : 
    9385                 :         147 :                 tree cond1 = fold_build2_loc (loc, GT_EXPR, boolean_type_node,
    9386                 :         147 :                                step, build_zero_cst (TREE_TYPE (step)));
    9387                 :         147 :                 tree cond2 = fold_build2_loc (loc, LE_EXPR, boolean_type_node,
    9388                 :             :                                               var, end);
    9389                 :         147 :                 tree cond3 = fold_build2_loc (loc, GT_EXPR, boolean_type_node,
    9390                 :             :                                               var, end);
    9391                 :         147 :                 cond1 = fold_build3_loc (loc, COND_EXPR, boolean_type_node,
    9392                 :             :                                          cond1, cond2, cond3);
    9393                 :         147 :                 if (cond)
    9394                 :          20 :                   cond = fold_build2_loc (loc, TRUTH_AND_EXPR,
    9395                 :             :                                           boolean_type_node, cond, cond1);
    9396                 :             :                 else
    9397                 :             :                   cond = cond1;
    9398                 :             :               }
    9399                 :         127 :             tree cont_label = create_artificial_label (loc);
    9400                 :         127 :             label = build1 (LABEL_EXPR, void_type_node, cont_label);
    9401                 :         127 :             tree tem = fold_build3_loc (loc, COND_EXPR, void_type_node, cond,
    9402                 :             :                                         void_node,
    9403                 :             :                                         build_and_jump (&cont_label));
    9404                 :         127 :             append_to_statement_list_force (tem, last_body);
    9405                 :             :               }
    9406                 :         188 :             if (TREE_CODE (TREE_VALUE (t)) == COMPOUND_EXPR)
    9407                 :             :               {
    9408                 :           0 :                 append_to_statement_list (TREE_OPERAND (TREE_VALUE (t), 0),
    9409                 :             :                                           last_body);
    9410                 :           0 :                 TREE_VALUE (t) = TREE_OPERAND (TREE_VALUE (t), 1);
    9411                 :             :               }
    9412                 :         188 :             if (error_operand_p (TREE_VALUE (t)))
    9413                 :             :               return;
    9414                 :         188 :             append_to_statement_list_force (TREE_VALUE (t), last_body);
    9415                 :         188 :             TREE_VALUE (t) = null_pointer_node;
    9416                 :             :           }
    9417                 :             :         else
    9418                 :             :           {
    9419                 :         346 :             if (last_bind)
    9420                 :             :               {
    9421                 :           9 :                 append_to_statement_list (label, last_body);
    9422                 :           9 :                 gimplify_and_add (last_bind, pre_p);
    9423                 :           9 :                 last_bind = NULL_TREE;
    9424                 :             :               }
    9425                 :         346 :             if (TREE_CODE (OMP_CLAUSE_DECL (c)) == COMPOUND_EXPR)
    9426                 :             :               {
    9427                 :           0 :                 gimplify_expr (&TREE_OPERAND (OMP_CLAUSE_DECL (c), 0), pre_p,
    9428                 :             :                                NULL, is_gimple_val, fb_rvalue);
    9429                 :           0 :                 OMP_CLAUSE_DECL (c) = TREE_OPERAND (OMP_CLAUSE_DECL (c), 1);
    9430                 :             :               }
    9431                 :         346 :             if (error_operand_p (OMP_CLAUSE_DECL (c)))
    9432                 :             :               return;
    9433                 :         346 :             if (gimplify_expr (&OMP_CLAUSE_DECL (c), pre_p, NULL,
    9434                 :             :                                is_gimple_lvalue, fb_lvalue) == GS_ERROR)
    9435                 :             :               return;
    9436                 :         346 :             gimplify_and_add (OMP_CLAUSE_DECL (c), pre_p);
    9437                 :             :           }
    9438                 :             :       }
    9439                 :         468 :   if (last_bind)
    9440                 :             :     {
    9441                 :         109 :       append_to_statement_list (label, last_body);
    9442                 :         109 :       gimplify_and_add (last_bind, pre_p);
    9443                 :             :     }
    9444                 :             :   return;
    9445                 :             : }
    9446                 :             : 
    9447                 :             : /* If *LIST_P contains any OpenMP depend clauses with iterators,
    9448                 :             :    lower all the depend clauses by populating corresponding depend
    9449                 :             :    array.  Returns 0 if there are no such depend clauses, or
    9450                 :             :    2 if all depend clauses should be removed, 1 otherwise.  */
    9451                 :             : 
    9452                 :             : static int
    9453                 :        1806 : gimplify_omp_depend (tree *list_p, gimple_seq *pre_p)
    9454                 :             : {
    9455                 :        1806 :   tree c;
    9456                 :        1806 :   gimple *g;
    9457                 :        1806 :   size_t n[5] = { 0, 0, 0, 0, 0 };
    9458                 :        1806 :   bool unused[5];
    9459                 :        1806 :   tree counts[5] = { NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE };
    9460                 :        1806 :   tree last_iter = NULL_TREE, last_count = NULL_TREE;
    9461                 :        1806 :   size_t i, j;
    9462                 :        1806 :   location_t first_loc = UNKNOWN_LOCATION;
    9463                 :             : 
    9464                 :        5834 :   for (c = *list_p; c; c = OMP_CLAUSE_CHAIN (c))
    9465                 :        4028 :     if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND)
    9466                 :             :       {
    9467                 :        2108 :         switch (OMP_CLAUSE_DEPEND_KIND (c))
    9468                 :             :           {
    9469                 :             :           case OMP_CLAUSE_DEPEND_IN:
    9470                 :             :             i = 2;
    9471                 :             :             break;
    9472                 :             :           case OMP_CLAUSE_DEPEND_OUT:
    9473                 :             :           case OMP_CLAUSE_DEPEND_INOUT:
    9474                 :             :             i = 0;
    9475                 :             :             break;
    9476                 :             :           case OMP_CLAUSE_DEPEND_MUTEXINOUTSET:
    9477                 :             :             i = 1;
    9478                 :             :             break;
    9479                 :             :           case OMP_CLAUSE_DEPEND_DEPOBJ:
    9480                 :             :             i = 3;
    9481                 :             :             break;
    9482                 :             :           case OMP_CLAUSE_DEPEND_INOUTSET:
    9483                 :             :             i = 4;
    9484                 :             :             break;
    9485                 :           0 :           default:
    9486                 :           0 :             gcc_unreachable ();
    9487                 :             :           }
    9488                 :        2108 :         tree t = OMP_CLAUSE_DECL (c);
    9489                 :        2108 :         if (first_loc == UNKNOWN_LOCATION)
    9490                 :        1806 :           first_loc = OMP_CLAUSE_LOCATION (c);
    9491                 :        2108 :         if (TREE_CODE (t) == TREE_LIST
    9492                 :         297 :             && TREE_PURPOSE (t)
    9493                 :        2405 :             && TREE_CODE (TREE_PURPOSE (t)) == TREE_VEC)
    9494                 :             :           {
    9495                 :         297 :             if (TREE_PURPOSE (t) != last_iter)
    9496                 :             :               {
    9497                 :         250 :                 tree tcnt = size_one_node;
    9498                 :         534 :                 for (tree it = TREE_PURPOSE (t); it; it = TREE_CHAIN (it))
    9499                 :             :                   {
    9500                 :         284 :                     if (gimplify_expr (&TREE_VEC_ELT (it, 1), pre_p, NULL,
    9501                 :             :                                        is_gimple_val, fb_rvalue) == GS_ERROR
    9502                 :         284 :                         || gimplify_expr (&TREE_VEC_ELT (it, 2), pre_p, NULL,
    9503                 :             :                                           is_gimple_val, fb_rvalue) == GS_ERROR
    9504                 :         284 :                         || gimplify_expr (&TREE_VEC_ELT (it, 3), pre_p, NULL,
    9505                 :             :                                           is_gimple_val, fb_rvalue) == GS_ERROR
    9506                 :         568 :                         || (gimplify_expr (&TREE_VEC_ELT (it, 4), pre_p, NULL,
    9507                 :             :                                            is_gimple_val, fb_rvalue)
    9508                 :             :                             == GS_ERROR))
    9509                 :           0 :                       return 2;
    9510                 :         284 :                     tree var = TREE_VEC_ELT (it, 0);
    9511                 :         284 :                     tree begin = TREE_VEC_ELT (it, 1);
    9512                 :         284 :                     tree end = TREE_VEC_ELT (it, 2);
    9513                 :         284 :                     tree step = TREE_VEC_ELT (it, 3);
    9514                 :         284 :                     tree orig_step = TREE_VEC_ELT (it, 4);
    9515                 :         284 :                     tree type = TREE_TYPE (var);
    9516                 :         284 :                     tree stype = TREE_TYPE (step);
    9517                 :         284 :                     location_t loc = DECL_SOURCE_LOCATION (var);
    9518                 :         284 :                     tree endmbegin;
    9519                 :             :                     /* Compute count for this iterator as
    9520                 :             :                        orig_step > 0
    9521                 :             :                        ? (begin < end ? (end - begin + (step - 1)) / step : 0)
    9522                 :             :                        : (begin > end ? (end - begin + (step + 1)) / step : 0)
    9523                 :             :                        and compute product of those for the entire depend
    9524                 :             :                        clause.  */
    9525                 :         284 :                     if (POINTER_TYPE_P (type))
    9526                 :          42 :                       endmbegin = fold_build2_loc (loc, POINTER_DIFF_EXPR,
    9527                 :             :                                                    stype, end, begin);
    9528                 :             :                     else
    9529                 :         242 :                       endmbegin = fold_build2_loc (loc, MINUS_EXPR, type,
    9530                 :             :                                                    end, begin);
    9531                 :         284 :                     tree stepm1 = fold_build2_loc (loc, MINUS_EXPR, stype,
    9532                 :             :                                                    step,
    9533                 :         284 :                                                    build_int_cst (stype, 1));
    9534                 :         284 :                     tree stepp1 = fold_build2_loc (loc, PLUS_EXPR, stype, step,
    9535                 :         284 :                                                    build_int_cst (stype, 1));
    9536                 :         284 :                     tree pos = fold_build2_loc (loc, PLUS_EXPR, stype,
    9537                 :             :                                                 unshare_expr (endmbegin),
    9538                 :             :                                                 stepm1);
    9539                 :         284 :                     pos = fold_build2_loc (loc, TRUNC_DIV_EXPR, stype,
    9540                 :             :                                            pos, step);
    9541                 :         284 :                     tree neg = fold_build2_loc (loc, PLUS_EXPR, stype,
    9542                 :             :                                                 endmbegin, stepp1);
    9543                 :         284 :                     if (TYPE_UNSIGNED (stype))
    9544                 :             :                       {
    9545                 :          31 :                         neg = fold_build1_loc (loc, NEGATE_EXPR, stype, neg);
    9546                 :          31 :                         step = fold_build1_loc (loc, NEGATE_EXPR, stype, step);
    9547                 :             :                       }
    9548                 :         284 :                     neg = fold_build2_loc (loc, TRUNC_DIV_EXPR, stype,
    9549                 :             :                                            neg, step);
    9550                 :         284 :                     step = NULL_TREE;
    9551                 :         284 :                     tree cond = fold_build2_loc (loc, LT_EXPR,
    9552                 :             :                                                  boolean_type_node,
    9553                 :             :                                                  begin, end);
    9554                 :         284 :                     pos = fold_build3_loc (loc, COND_EXPR, stype, cond, pos,
    9555                 :         284 :                                            build_int_cst (stype, 0));
    9556                 :         284 :                     cond = fold_build2_loc (loc, LT_EXPR, boolean_type_node,
    9557                 :             :                                             end, begin);
    9558                 :         284 :                     neg = fold_build3_loc (loc, COND_EXPR, stype, cond, neg,
    9559                 :         284 :                                            build_int_cst (stype, 0));
    9560                 :         284 :                     tree osteptype = TREE_TYPE (orig_step);
    9561                 :         284 :                     cond = fold_build2_loc (loc, GT_EXPR, boolean_type_node,
    9562                 :             :                                             orig_step,
    9563                 :         284 :                                             build_int_cst (osteptype, 0));
    9564                 :         284 :                     tree cnt = fold_build3_loc (loc, COND_EXPR, stype,
    9565                 :         284 :                                                 cond, pos, neg);
    9566                 :         284 :                     cnt = fold_convert_loc (loc, sizetype, cnt);
    9567                 :         284 :                     if (gimplify_expr (&cnt, pre_p, NULL, is_gimple_val,
    9568                 :             :                                        fb_rvalue) == GS_ERROR)
    9569                 :             :                       return 2;
    9570                 :         284 :                     tcnt = size_binop_loc (loc, MULT_EXPR, tcnt, cnt);
    9571                 :             :                   }
    9572                 :         250 :                 if (gimplify_expr (&tcnt, pre_p, NULL, is_gimple_val,
    9573                 :             :                                    fb_rvalue) == GS_ERROR)
    9574                 :             :                   return 2;
    9575                 :         250 :                 last_iter = TREE_PURPOSE (t);
    9576                 :         250 :                 last_count = tcnt;
    9577                 :             :               }
    9578                 :         297 :             if (counts[i] == NULL_TREE)
    9579                 :         243 :               counts[i] = last_count;
    9580                 :             :             else
    9581                 :          54 :               counts[i] = size_binop_loc (OMP_CLAUSE_LOCATION (c),
    9582                 :             :                                           PLUS_EXPR, counts[i], last_count);
    9583                 :             :           }
    9584                 :             :         else
    9585                 :        1811 :           n[i]++;
    9586                 :             :       }
    9587                 :       10049 :   for (i = 0; i < 5; i++)
    9588                 :        8448 :     if (counts[i])
    9589                 :             :       break;
    9590                 :        1806 :   if (i == 5)
    9591                 :             :     return 0;
    9592                 :             : 
    9593                 :         205 :   tree total = size_zero_node;
    9594                 :        1230 :   for (i = 0; i < 5; i++)
    9595                 :             :     {
    9596                 :        1025 :       unused[i] = counts[i] == NULL_TREE && n[i] == 0;
    9597                 :        1025 :       if (counts[i] == NULL_TREE)
    9598                 :         782 :         counts[i] = size_zero_node;
    9599                 :        1025 :       if (n[i])
    9600                 :          44 :         counts[i] = size_binop (PLUS_EXPR, counts[i], size_int (n[i]));
    9601                 :        1025 :       if (gimplify_expr (&counts[i], pre_p, NULL, is_gimple_val,
    9602                 :             :                          fb_rvalue) == GS_ERROR)
    9603                 :             :         return 2;
    9604                 :        1025 :       total = size_binop (PLUS_EXPR, total, counts[i]);
    9605                 :             :     }
    9606                 :             : 
    9607                 :         205 :   if (gimplify_expr (&total, pre_p, NULL, is_gimple_val, fb_rvalue)
    9608                 :             :       == GS_ERROR)
    9609                 :             :     return 2;
    9610                 :         205 :   bool is_old = unused[1] && unused[3] && unused[4];
    9611                 :         205 :   tree totalpx = size_binop (PLUS_EXPR, unshare_expr (total),
    9612                 :             :                              size_int (is_old ? 1 : 4));
    9613                 :         205 :   if (!unused[4])
    9614                 :           3 :     totalpx = size_binop (PLUS_EXPR, totalpx,
    9615                 :             :                           size_binop (MULT_EXPR, counts[4], size_int (2)));
    9616                 :         205 :   tree type = build_array_type (ptr_type_node, build_index_type (totalpx));
    9617                 :         205 :   tree array = create_tmp_var_raw (type);
    9618                 :         205 :   TREE_ADDRESSABLE (array) = 1;
    9619                 :         205 :   if (!poly_int_tree_p (totalpx))
    9620                 :             :     {
    9621                 :          81 :       if (!TYPE_SIZES_GIMPLIFIED (TREE_TYPE (array)))
    9622                 :          81 :         gimplify_type_sizes (TREE_TYPE (array), pre_p);
    9623                 :          81 :       if (gimplify_omp_ctxp)
    9624                 :             :         {
    9625                 :             :           struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp;
    9626                 :             :           while (ctx
    9627                 :          20 :                  && (ctx->region_type == ORT_WORKSHARE
    9628                 :             :                      || ctx->region_type == ORT_TASKGROUP
    9629                 :          20 :                      || ctx->region_type == ORT_SIMD
    9630                 :          20 :                      || ctx->region_type == ORT_ACC))
    9631                 :           0 :             ctx = ctx->outer_context;
    9632                 :          20 :           if (ctx)
    9633                 :          20 :             omp_add_variable (ctx, array, GOVD_LOCAL | GOVD_SEEN);
    9634                 :             :         }
    9635                 :          81 :       gimplify_vla_decl (array, pre_p);
    9636                 :             :     }
    9637                 :             :   else
    9638                 :         124 :     gimple_add_tmp_var (array);
    9639                 :         205 :   tree r = build4 (ARRAY_REF, ptr_type_node, array, size_int (0), NULL_TREE,
    9640                 :             :                    NULL_TREE);
    9641                 :         205 :   tree tem;
    9642                 :         205 :   if (!is_old)
    9643                 :             :     {
    9644                 :          31 :       tem = build2 (MODIFY_EXPR, void_type_node, r,
    9645                 :          31 :                     build_int_cst (ptr_type_node, 0));
    9646                 :          31 :       gimplify_and_add (tem, pre_p);
    9647                 :          31 :       r = build4 (ARRAY_REF, ptr_type_node, array, size_int (1), NULL_TREE,
    9648                 :             :                   NULL_TREE);
    9649                 :             :     }
    9650                 :         205 :   tem = build2 (MODIFY_EXPR, void_type_node, r,
    9651                 :             :                 fold_convert (ptr_type_node, total));
    9652                 :         205 :   gimplify_and_add (tem, pre_p);
    9653                 :         801 :   for (i = 1; i < (is_old ? 2 : 4); i++)
    9654                 :             :     {
    9655                 :         267 :       r = build4 (ARRAY_REF, ptr_type_node, array, size_int (i + !is_old),
    9656                 :             :                   NULL_TREE, NULL_TREE);
    9657                 :         267 :       tem = build2 (MODIFY_EXPR, void_type_node, r, counts[i - 1]);
    9658                 :         267 :       gimplify_and_add (tem, pre_p);
    9659                 :             :     }
    9660                 :             : 
    9661                 :             :   tree cnts[6];
    9662                 :         717 :   for (j = 5; j; j--)
    9663                 :         717 :     if (!unused[j - 1])
    9664                 :             :       break;
    9665                 :        1230 :   for (i = 0; i < 5; i++)
    9666                 :             :     {
    9667                 :        1025 :       if (i && (i >= j || unused[i - 1]))
    9668                 :             :         {
    9669                 :         770 :           cnts[i] = cnts[i - 1];
    9670                 :         770 :           continue;
    9671                 :             :         }
    9672                 :         255 :       cnts[i] = create_tmp_var (sizetype);
    9673                 :         255 :       if (i == 0)
    9674                 :         236 :         g = gimple_build_assign (cnts[i], size_int (is_old ? 2 : 5));
    9675                 :             :       else
    9676                 :             :         {
    9677                 :          50 :           tree t;
    9678                 :          50 :           if (is_old)
    9679                 :          38 :             t = size_binop (PLUS_EXPR, counts[0], size_int (2));
    9680                 :             :           else
    9681                 :          12 :             t = size_binop (PLUS_EXPR, cnts[i - 1], counts[i - 1]);
    9682                 :          50 :           if (gimplify_expr (&t, pre_p, NULL, is_gimple_val, fb_rvalue)
    9683                 :             :               == GS_ERROR)
    9684                 :           0 :             return 2;
    9685                 :          50 :           g = gimple_build_assign (cnts[i], t);
    9686                 :             :         }
    9687                 :         255 :       gimple_seq_add_stmt (pre_p, g);
    9688                 :             :     }
    9689                 :         205 :   if (unused[4])
    9690                 :         202 :     cnts[5] = NULL_TREE;
    9691                 :             :   else
    9692                 :             :     {
    9693                 :           3 :       tree t = size_binop (PLUS_EXPR, total, size_int (5));
    9694                 :           3 :       cnts[5] = create_tmp_var (sizetype);
    9695                 :           3 :       g = gimple_build_assign (cnts[i], t);
    9696                 :           3 :       gimple_seq_add_stmt (pre_p, g);
    9697                 :             :     }
    9698                 :             : 
    9699                 :         205 :   last_iter = NULL_TREE;
    9700                 :         205 :   tree last_bind = NULL_TREE;
    9701                 :         205 :   tree *last_body = NULL;
    9702                 :         563 :   for (c = *list_p; c; c = OMP_CLAUSE_CHAIN (c))
    9703                 :         358 :     if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND)
    9704                 :             :       {
    9705                 :         343 :         switch (OMP_CLAUSE_DEPEND_KIND (c))
    9706                 :             :           {
    9707                 :             :           case OMP_CLAUSE_DEPEND_IN:
    9708                 :             :             i = 2;
    9709                 :             :             break;
    9710                 :             :           case OMP_CLAUSE_DEPEND_OUT:
    9711                 :             :           case OMP_CLAUSE_DEPEND_INOUT:
    9712                 :             :             i = 0;
    9713                 :             :             break;
    9714                 :             :           case OMP_CLAUSE_DEPEND_MUTEXINOUTSET:
    9715                 :             :             i = 1;
    9716                 :             :             break;
    9717                 :             :           case OMP_CLAUSE_DEPEND_DEPOBJ:
    9718                 :             :             i = 3;
    9719                 :             :             break;
    9720                 :             :           case OMP_CLAUSE_DEPEND_INOUTSET:
    9721                 :             :             i = 4;
    9722                 :             :             break;
    9723                 :           0 :           default:
    9724                 :           0 :             gcc_unreachable ();
    9725                 :             :           }
    9726                 :         343 :         tree t = OMP_CLAUSE_DECL (c);
    9727                 :         343 :         if (TREE_CODE (t) == TREE_LIST
    9728                 :         297 :             && TREE_PURPOSE (t)
    9729                 :         640 :             && TREE_CODE (TREE_PURPOSE (t)) == TREE_VEC)
    9730                 :             :           {
    9731                 :         297 :             if (TREE_PURPOSE (t) != last_iter)
    9732                 :             :               {
    9733                 :         250 :                 if (last_bind)
    9734                 :          31 :                   gimplify_and_add (last_bind, pre_p);
    9735                 :         250 :                 tree block = TREE_VEC_ELT (TREE_PURPOSE (t), 5);
    9736                 :         250 :                 last_bind = build3 (BIND_EXPR, void_type_node,
    9737                 :         250 :                                     BLOCK_VARS (block), NULL, block);
    9738                 :         250 :                 TREE_SIDE_EFFECTS (last_bind) = 1;
    9739                 :         250 :                 SET_EXPR_LOCATION (last_bind, OMP_CLAUSE_LOCATION (c));
    9740                 :         250 :                 tree *p = &BIND_EXPR_BODY (last_bind);
    9741                 :         534 :                 for (tree it = TREE_PURPOSE (t); it; it = TREE_CHAIN (it))
    9742                 :             :                   {
    9743                 :         284 :                     tree var = TREE_VEC_ELT (it, 0);
    9744                 :         284 :                     tree begin = TREE_VEC_ELT (it, 1);
    9745                 :         284 :                     tree end = TREE_VEC_ELT (it, 2);
    9746                 :         284 :                     tree step = TREE_VEC_ELT (it, 3);
    9747                 :         284 :                     tree orig_step = TREE_VEC_ELT (it, 4);
    9748                 :         284 :                     tree type = TREE_TYPE (var);
    9749                 :         284 :                     location_t loc = DECL_SOURCE_LOCATION (var);
    9750                 :             :                     /* Emit:
    9751                 :             :                        var = begin;
    9752                 :             :                        goto cond_label;
    9753                 :             :                        beg_label:
    9754                 :             :                        ...
    9755                 :             :                        var = var + step;
    9756                 :             :                        cond_label:
    9757                 :             :                        if (orig_step > 0) {
    9758                 :             :                          if (var < end) goto beg_label;
    9759                 :             :                        } else {
    9760                 :             :                          if (var > end) goto beg_label;
    9761                 :             :                        }
    9762                 :             :                        for each iterator, with inner iterators added to
    9763                 :             :                        the ... above.  */
    9764                 :         284 :                     tree beg_label = create_artificial_label (loc);
    9765                 :         284 :                     tree cond_label = NULL_TREE;
    9766                 :         284 :                     tem = build2_loc (loc, MODIFY_EXPR, void_type_node,
    9767                 :             :                                       var, begin);
    9768                 :         284 :                     append_to_statement_list_force (tem, p);
    9769                 :         284 :                     tem = build_and_jump (&cond_label);
    9770                 :         284 :                     append_to_statement_list_force (tem, p);
    9771                 :         284 :                     tem = build1 (LABEL_EXPR, void_type_node, beg_label);
    9772                 :         284 :                     append_to_statement_list (tem, p);
    9773                 :         284 :                     tree bind = build3 (BIND_EXPR, void_type_node, NULL_TREE,
    9774                 :             :                                         NULL_TREE, NULL_TREE);
    9775                 :         284 :                     TREE_SIDE_EFFECTS (bind) = 1;
    9776                 :         284 :                     SET_EXPR_LOCATION (bind, loc);
    9777                 :         284 :                     append_to_statement_list_force (bind, p);
    9778                 :         284 :                     if (POINTER_TYPE_P (type))
    9779                 :          42 :                       tem = build2_loc (loc, POINTER_PLUS_EXPR, type,
    9780                 :             :                                         var, fold_convert_loc (loc, sizetype,
    9781                 :             :                                                                step));
    9782                 :             :                     else
    9783                 :         242 :                       tem = build2_loc (loc, PLUS_EXPR, type, var, step);
    9784                 :         284 :                     tem = build2_loc (loc, MODIFY_EXPR, void_type_node,
    9785                 :             :                                       var, tem);
    9786                 :         284 :                     append_to_statement_list_force (tem, p);
    9787                 :         284 :                     tem = build1 (LABEL_EXPR, void_type_node, cond_label);
    9788                 :         284 :                     append_to_statement_list (tem, p);
    9789                 :         284 :                     tree cond = fold_build2_loc (loc, LT_EXPR,
    9790                 :             :                                                  boolean_type_node,
    9791                 :             :                                                  var, end);
    9792                 :         284 :                     tree pos
    9793                 :         284 :                       = fold_build3_loc (loc, COND_EXPR, void_type_node,
    9794                 :             :                                          cond, build_and_jump (&beg_label),
    9795                 :             :                                          void_node);
    9796                 :         284 :                     cond = fold_build2_loc (loc, GT_EXPR, boolean_type_node,
    9797                 :             :                                             var, end);
    9798                 :         284 :                     tree neg
    9799                 :         284 :                       = fold_build3_loc (loc, COND_EXPR, void_type_node,
    9800                 :             :                                          cond, build_and_jump (&beg_label),
    9801                 :             :                                          void_node);
    9802                 :         284 :                     tree osteptype = TREE_TYPE (orig_step);
    9803                 :         284 :                     cond = fold_build2_loc (loc, GT_EXPR, boolean_type_node,
    9804                 :             :                                             orig_step,
    9805                 :         284 :                                             build_int_cst (osteptype, 0));
    9806                 :         284 :                     tem = fold_build3_loc (loc, COND_EXPR, void_type_node,
    9807                 :             :                                            cond, pos, neg);
    9808                 :         284 :                     append_to_statement_list_force (tem, p);
    9809                 :         284 :                     p = &BIND_EXPR_BODY (bind);
    9810                 :             :                   }
    9811                 :             :                 last_body = p;
    9812                 :             :               }
    9813                 :         297 :             last_iter = TREE_PURPOSE (t);
    9814                 :         297 :             if (TREE_CODE (TREE_VALUE (t)) == COMPOUND_EXPR)
    9815                 :             :               {
    9816                 :           0 :                 append_to_statement_list (TREE_OPERAND (TREE_VALUE (t),
    9817                 :             :                                           0), last_body);
    9818                 :           0 :                 TREE_VALUE (t) = TREE_OPERAND (TREE_VALUE (t), 1);
    9819                 :             :               }
    9820                 :         297 :             if (error_operand_p (TREE_VALUE (t)))
    9821                 :             :               return 2;
    9822                 :         297 :             if (TREE_VALUE (t) != null_pointer_node)
    9823                 :         291 :               TREE_VALUE (t) = build_fold_addr_expr (TREE_VALUE (t));
    9824                 :         297 :             if (i == 4)
    9825                 :             :               {
    9826                 :           3 :                 r = build4 (ARRAY_REF, ptr_type_node, array, cnts[i],
    9827                 :             :                             NULL_TREE, NULL_TREE);
    9828                 :           3 :                 tree r2 = build4 (ARRAY_REF, ptr_type_node, array, cnts[5],
    9829                 :             :                                   NULL_TREE, NULL_TREE);
    9830                 :           3 :                 r2 = build_fold_addr_expr_with_type (r2, ptr_type_node);
    9831                 :           3 :                 tem = build2_loc (OMP_CLAUSE_LOCATION (c), MODIFY_EXPR,
    9832                 :             :                                   void_type_node, r, r2);
    9833                 :           3 :                 append_to_statement_list_force (tem, last_body);
    9834                 :           3 :                 tem = build2_loc (OMP_CLAUSE_LOCATION (c), MODIFY_EXPR,
    9835                 :             :                                   void_type_node, cnts[i],
    9836                 :           3 :                                   size_binop (PLUS_EXPR, cnts[i],
    9837                 :             :                                               size_int (1)));
    9838                 :           3 :                 append_to_statement_list_force (tem, last_body);
    9839                 :           3 :                 i = 5;
    9840                 :             :               }
    9841                 :         297 :             r = build4 (ARRAY_REF, ptr_type_node, array, cnts[i],
    9842                 :             :                         NULL_TREE, NULL_TREE);
    9843                 :         594 :             tem = build2_loc (OMP_CLAUSE_LOCATION (c), MODIFY_EXPR,
    9844                 :         297 :                               void_type_node, r, TREE_VALUE (t));
    9845                 :         297 :             append_to_statement_list_force (tem, last_body);
    9846                 :         297 :             if (i == 5)
    9847                 :             :               {
    9848                 :           3 :                 r = build4 (ARRAY_REF, ptr_type_node, array,
    9849                 :           3 :                             size_binop (PLUS_EXPR, cnts[i], size_int (1)),
    9850                 :             :                             NULL_TREE, NULL_TREE);
    9851                 :           3 :                 tem = build_int_cst (ptr_type_node, GOMP_DEPEND_INOUTSET);
    9852                 :           3 :                 tem = build2_loc (OMP_CLAUSE_LOCATION (c), MODIFY_EXPR,
    9853                 :             :                                   void_type_node, r, tem);
    9854                 :           3 :                 append_to_statement_list_force (tem, last_body);
    9855                 :             :               }
    9856                 :         297 :             tem = build2_loc (OMP_CLAUSE_LOCATION (c), MODIFY_EXPR,
    9857                 :             :                               void_type_node, cnts[i],
    9858                 :         297 :                               size_binop (PLUS_EXPR, cnts[i],
    9859                 :             :                                           size_int (1 + (i == 5))));
    9860                 :         297 :             append_to_statement_list_force (tem, last_body);
    9861                 :         297 :             TREE_VALUE (t) = null_pointer_node;
    9862                 :             :           }
    9863                 :             :         else
    9864                 :             :           {
    9865                 :          46 :             if (last_bind)
    9866                 :             :               {
    9867                 :          18 :                 gimplify_and_add (last_bind, pre_p);
    9868                 :          18 :                 last_bind = NULL_TREE;
    9869                 :             :               }
    9870                 :          46 :             if (TREE_CODE (OMP_CLAUSE_DECL (c)) == COMPOUND_EXPR)
    9871                 :             :               {
    9872                 :           0 :                 gimplify_expr (&TREE_OPERAND (OMP_CLAUSE_DECL (c), 0), pre_p,
    9873                 :             :                                NULL, is_gimple_val, fb_rvalue);
    9874                 :           0 :                 OMP_CLAUSE_DECL (c) = TREE_OPERAND (OMP_CLAUSE_DECL (c), 1);
    9875                 :             :               }
    9876                 :          46 :             if (error_operand_p (OMP_CLAUSE_DECL (c)))
    9877                 :             :               return 2;
    9878                 :          46 :             if (OMP_CLAUSE_DECL (c) != null_pointer_node)
    9879                 :          46 :               OMP_CLAUSE_DECL (c) = build_fold_addr_expr (OMP_CLAUSE_DECL (c));
    9880                 :          46 :             if (gimplify_expr (&OMP_CLAUSE_DECL (c), pre_p, NULL,
    9881                 :             :                                is_gimple_val, fb_rvalue) == GS_ERROR)
    9882                 :             :               return 2;
    9883                 :          46 :             if (i == 4)
    9884                 :             :               {
    9885                 :           0 :                 r = build4 (ARRAY_REF, ptr_type_node, array, cnts[i],
    9886                 :             :                             NULL_TREE, NULL_TREE);
    9887                 :           0 :                 tree r2 = build4 (ARRAY_REF, ptr_type_node, array, cnts[5],
    9888                 :             :                                   NULL_TREE, NULL_TREE);
    9889                 :           0 :                 r2 = build_fold_addr_expr_with_type (r2, ptr_type_node);
    9890                 :           0 :                 tem = build2 (MODIFY_EXPR, void_type_node, r, r2);
    9891                 :           0 :                 gimplify_and_add (tem, pre_p);
    9892                 :           0 :                 g = gimple_build_assign (cnts[i], size_binop (PLUS_EXPR,
    9893                 :             :                                                               cnts[i],
    9894                 :             :                                                               size_int (1)));
    9895                 :           0 :                 gimple_seq_add_stmt (pre_p, g);
    9896                 :           0 :                 i = 5;
    9897                 :             :               }
    9898                 :          46 :             r = build4 (ARRAY_REF, ptr_type_node, array, cnts[i],
    9899                 :             :                         NULL_TREE, NULL_TREE);
    9900                 :          46 :             tem = build2 (MODIFY_EXPR, void_type_node, r, OMP_CLAUSE_DECL (c));
    9901                 :          46 :             gimplify_and_add (tem, pre_p);
    9902                 :          46 :             if (i == 5)
    9903                 :             :               {
    9904                 :           0 :                 r = build4 (ARRAY_REF, ptr_type_node, array,
    9905                 :           0 :                             size_binop (PLUS_EXPR, cnts[i], size_int (1)),
    9906                 :             :                             NULL_TREE, NULL_TREE);
    9907                 :           0 :                 tem = build_int_cst (ptr_type_node, GOMP_DEPEND_INOUTSET);
    9908                 :           0 :                 tem = build2 (MODIFY_EXPR, void_type_node, r, tem);
    9909                 :           0 :                 append_to_statement_list_force (tem, last_body);
    9910                 :           0 :                 gimplify_and_add (tem, pre_p);
    9911                 :             :               }
    9912                 :          46 :             g = gimple_build_assign (cnts[i],
    9913                 :          46 :                                      size_binop (PLUS_EXPR, cnts[i],
    9914                 :             :                                                  size_int (1 + (i == 5))));
    9915                 :          46 :             gimple_seq_add_stmt (pre_p, g);
    9916                 :             :           }
    9917                 :             :       }
    9918                 :         205 :   if (last_bind)
    9919                 :         201 :     gimplify_and_add (last_bind, pre_p);
    9920                 :         205 :   tree cond = boolean_false_node;
    9921                 :         205 :   if (is_old)
    9922                 :             :     {
    9923                 :         174 :       if (!unused[0])
    9924                 :          88 :         cond = build2_loc (first_loc, NE_EXPR, boolean_type_node, cnts[0],
    9925                 :             :                            size_binop_loc (first_loc, PLUS_EXPR, counts[0],
    9926                 :          88 :                                            size_int (2)));
    9927                 :         174 :       if (!unused[2])
    9928                 :         124 :         cond = build2_loc (first_loc, TRUTH_OR_EXPR, boolean_type_node, cond,
    9929                 :             :                            build2_loc (first_loc, NE_EXPR, boolean_type_node,
    9930                 :             :                                        cnts[2],
    9931                 :             :                                        size_binop_loc (first_loc, PLUS_EXPR,
    9932                 :             :                                                        totalpx,
    9933                 :         124 :                                                        size_int (1))));
    9934                 :             :     }
    9935                 :             :   else
    9936                 :             :     {
    9937                 :          31 :       tree prev = size_int (5);
    9938                 :         186 :       for (i = 0; i < 5; i++)
    9939                 :             :         {
    9940                 :         155 :           if (unused[i])
    9941                 :         112 :             continue;
    9942                 :          43 :           prev = size_binop_loc (first_loc, PLUS_EXPR, counts[i], prev);
    9943                 :          43 :           cond = build2_loc (first_loc, TRUTH_OR_EXPR, boolean_type_node, cond,
    9944                 :             :                              build2_loc (first_loc, NE_EXPR, boolean_type_node,
    9945                 :             :                                          cnts[i], unshare_expr (prev)));
    9946                 :             :         }
    9947                 :             :     }
    9948                 :         205 :   tem = build3_loc (first_loc, COND_EXPR, void_type_node, cond,
    9949                 :             :                     build_call_expr_loc (first_loc,
    9950                 :             :                                          builtin_decl_explicit (BUILT_IN_TRAP),
    9951                 :             :                                          0), void_node);
    9952                 :         205 :   gimplify_and_add (tem, pre_p);
    9953                 :         205 :   c = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE_DEPEND);
    9954                 :         205 :   OMP_CLAUSE_DEPEND_KIND (c) = OMP_CLAUSE_DEPEND_LAST;
    9955                 :         205 :   OMP_CLAUSE_DECL (c) = build_fold_addr_expr (array);
    9956                 :         205 :   OMP_CLAUSE_CHAIN (c) = *list_p;
    9957                 :         205 :   *list_p = c;
    9958                 :         205 :   return 1;
    9959                 :             : }
    9960                 :             : 
    9961                 :             : /* True if mapping node C maps, or unmaps, a (Fortran) array descriptor.  */
    9962                 :             : 
    9963                 :             : static bool
    9964                 :      109427 : omp_map_clause_descriptor_p (tree c)
    9965                 :             : {
    9966                 :      109427 :   if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
    9967                 :             :     return false;
    9968                 :             : 
    9969                 :      109425 :   if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_TO_PSET)
    9970                 :             :     return true;
    9971                 :             : 
    9972                 :       71405 :   if ((OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_RELEASE
    9973                 :       66032 :        || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DELETE)
    9974                 :       71845 :       && OMP_CLAUSE_RELEASE_DESCRIPTOR (c))
    9975                 :        4002 :     return true;
    9976                 :             : 
    9977                 :             :   return false;
    9978                 :             : }
    9979                 :             : 
    9980                 :             : /* For a set of mappings describing an array section pointed to by a struct
    9981                 :             :    (or derived type, etc.) component, create an "alloc" or "release" node to
    9982                 :             :    insert into a list following a GOMP_MAP_STRUCT node.  For some types of
    9983                 :             :    mapping (e.g. Fortran arrays with descriptors), an additional mapping may
    9984                 :             :    be created that is inserted into the list of mapping nodes attached to the
    9985                 :             :    directive being processed -- not part of the sorted list of nodes after
    9986                 :             :    GOMP_MAP_STRUCT.
    9987                 :             : 
    9988                 :             :    CODE is the code of the directive being processed.  GRP_START and GRP_END
    9989                 :             :    are the first and last of two or three nodes representing this array section
    9990                 :             :    mapping (e.g. a data movement node like GOMP_MAP_{TO,FROM}, optionally a
    9991                 :             :    GOMP_MAP_TO_PSET, and finally a GOMP_MAP_ALWAYS_POINTER).  EXTRA_NODE is
    9992                 :             :    filled with the additional node described above, if needed.
    9993                 :             : 
    9994                 :             :    This function does not add the new nodes to any lists itself.  It is the
    9995                 :             :    responsibility of the caller to do that.  */
    9996                 :             : 
    9997                 :             : static tree
    9998                 :        1587 : build_omp_struct_comp_nodes (enum tree_code code, tree grp_start, tree grp_end,
    9999                 :             :                              tree *extra_node)
   10000                 :             : {
   10001                 :        3174 :   enum gomp_map_kind mkind
   10002                 :        1587 :     = (code == OMP_TARGET_EXIT_DATA || code == OACC_EXIT_DATA)
   10003                 :        1587 :       ? GOMP_MAP_RELEASE : GOMP_MAP_ALLOC;
   10004                 :             : 
   10005                 :        1587 :   gcc_assert (grp_start != grp_end);
   10006                 :             : 
   10007                 :        1587 :   tree c2 = build_omp_clause (OMP_CLAUSE_LOCATION (grp_end), OMP_CLAUSE_MAP);
   10008                 :        1587 :   OMP_CLAUSE_SET_MAP_KIND (c2, mkind);
   10009                 :        1587 :   OMP_CLAUSE_DECL (c2) = unshare_expr (OMP_CLAUSE_DECL (grp_end));
   10010                 :        1587 :   OMP_CLAUSE_CHAIN (c2) = NULL_TREE;
   10011                 :        1587 :   tree grp_mid = NULL_TREE;
   10012                 :        1587 :   if (OMP_CLAUSE_CHAIN (grp_start) != grp_end)
   10013                 :         185 :     grp_mid = OMP_CLAUSE_CHAIN (grp_start);
   10014                 :             : 
   10015                 :         185 :   if (grp_mid && omp_map_clause_descriptor_p (grp_mid))
   10016                 :           0 :     OMP_CLAUSE_SIZE (c2) = OMP_CLAUSE_SIZE (grp_mid);
   10017                 :             :   else
   10018                 :        1587 :     OMP_CLAUSE_SIZE (c2) = TYPE_SIZE_UNIT (ptr_type_node);
   10019                 :             : 
   10020                 :        1587 :   if (grp_mid
   10021                 :         185 :       && OMP_CLAUSE_CODE (grp_mid) == OMP_CLAUSE_MAP
   10022                 :        1772 :       && OMP_CLAUSE_MAP_KIND (grp_mid) == GOMP_MAP_ALWAYS_POINTER)
   10023                 :             :     {
   10024                 :           0 :       tree c3
   10025                 :           0 :         = build_omp_clause (OMP_CLAUSE_LOCATION (grp_end), OMP_CLAUSE_MAP);
   10026                 :           0 :       OMP_CLAUSE_SET_MAP_KIND (c3, mkind);
   10027                 :           0 :       OMP_CLAUSE_DECL (c3) = unshare_expr (OMP_CLAUSE_DECL (grp_mid));
   10028                 :           0 :       OMP_CLAUSE_SIZE (c3) = TYPE_SIZE_UNIT (ptr_type_node);
   10029                 :           0 :       OMP_CLAUSE_CHAIN (c3) = NULL_TREE;
   10030                 :             : 
   10031                 :           0 :       *extra_node = c3;
   10032                 :             :     }
   10033                 :             :   else
   10034                 :        1587 :     *extra_node = NULL_TREE;
   10035                 :             : 
   10036                 :        1587 :   return c2;
   10037                 :             : }
   10038                 :             : 
   10039                 :             : /* Strip ARRAY_REFS or an indirect ref off BASE, find the containing object,
   10040                 :             :    and set *BITPOSP and *POFFSETP to the bit offset of the access.
   10041                 :             :    If BASE_REF is non-NULL and the containing object is a reference, set
   10042                 :             :    *BASE_REF to that reference before dereferencing the object.
   10043                 :             :    If BASE_REF is NULL, check that the containing object is a COMPONENT_REF or
   10044                 :             :    has array type, else return NULL.  */
   10045                 :             : 
   10046                 :             : static tree
   10047                 :        6115 : extract_base_bit_offset (tree base, poly_int64 *bitposp,
   10048                 :             :                          poly_offset_int *poffsetp,
   10049                 :             :                          bool *variable_offset)
   10050                 :             : {
   10051                 :        6115 :   tree offset;
   10052                 :        6115 :   poly_int64 bitsize, bitpos;
   10053                 :        6115 :   machine_mode mode;
   10054                 :        6115 :   int unsignedp, reversep, volatilep = 0;
   10055                 :        6115 :   poly_offset_int poffset;
   10056                 :             : 
   10057                 :        6115 :   STRIP_NOPS (base);
   10058                 :             : 
   10059                 :        6115 :   base = get_inner_reference (base, &bitsize, &bitpos, &offset, &mode,
   10060                 :             :                               &unsignedp, &reversep, &volatilep);
   10061                 :             : 
   10062                 :        6115 :   STRIP_NOPS (base);
   10063                 :             : 
   10064                 :        6115 :   if (offset && poly_int_tree_p (offset))
   10065                 :             :     {
   10066                 :           0 :       poffset = wi::to_poly_offset (offset);
   10067                 :           0 :       *variable_offset = false;
   10068                 :             :     }
   10069                 :             :   else
   10070                 :             :     {
   10071                 :        6115 :       poffset = 0;
   10072                 :        6115 :       *variable_offset = (offset != NULL_TREE);
   10073                 :             :     }
   10074                 :             : 
   10075                 :        6115 :   if (maybe_ne (bitpos, 0))
   10076                 :        4697 :     poffset += bits_to_bytes_round_down (bitpos);
   10077                 :             : 
   10078                 :        6115 :   *bitposp = bitpos;
   10079                 :        6115 :   *poffsetp = poffset;
   10080                 :             : 
   10081                 :        6115 :   return base;
   10082                 :             : }
   10083                 :             : 
   10084                 :             : /* Used for topological sorting of mapping groups.  UNVISITED means we haven't
   10085                 :             :    started processing the group yet.  The TEMPORARY mark is used when we first
   10086                 :             :    encounter a group on a depth-first traversal, and the PERMANENT mark is used
   10087                 :             :    when we have processed all the group's children (i.e. all the base pointers
   10088                 :             :    referred to by the group's mapping nodes, recursively).  */
   10089                 :             : 
   10090                 :             : enum omp_tsort_mark {
   10091                 :             :   UNVISITED,
   10092                 :             :   TEMPORARY,
   10093                 :             :   PERMANENT
   10094                 :             : };
   10095                 :             : 
   10096                 :             : /* Hash for trees based on operand_equal_p.  Like tree_operand_hash
   10097                 :             :    but ignores side effects in the equality comparisons.  */
   10098                 :             : 
   10099                 :             : struct tree_operand_hash_no_se : tree_operand_hash
   10100                 :             : {
   10101                 :             :   static inline bool equal (const value_type &,
   10102                 :             :                             const compare_type &);
   10103                 :             : };
   10104                 :             : 
   10105                 :             : inline bool
   10106                 :      329872 : tree_operand_hash_no_se::equal (const value_type &t1,
   10107                 :             :                                 const compare_type &t2)
   10108                 :             : {
   10109                 :      329872 :   return operand_equal_p (t1, t2, OEP_MATCH_SIDE_EFFECTS);
   10110                 :             : }
   10111                 :             : 
   10112                 :             : /* A group of OMP_CLAUSE_MAP nodes that correspond to a single "map"
   10113                 :             :    clause.  */
   10114                 :             : 
   10115                 :             : struct omp_mapping_group {
   10116                 :             :   tree *grp_start;
   10117                 :             :   tree grp_end;
   10118                 :             :   omp_tsort_mark mark;
   10119                 :             :   /* If we've removed the group but need to reindex, mark the group as
   10120                 :             :      deleted.  */
   10121                 :             :   bool deleted;
   10122                 :             :   /* The group points to an already-created "GOMP_MAP_STRUCT
   10123                 :             :      GOMP_MAP_ATTACH_DETACH" pair.  */
   10124                 :             :   bool reprocess_struct;
   10125                 :             :   /* The group should use "zero-length" allocations for pointers that are not
   10126                 :             :      mapped "to" on the same directive.  */
   10127                 :             :   bool fragile;
   10128                 :             :   struct omp_mapping_group *sibling;
   10129                 :             :   struct omp_mapping_group *next;
   10130                 :             : };
   10131                 :             : 
   10132                 :             : DEBUG_FUNCTION void
   10133                 :           0 : debug_mapping_group (omp_mapping_group *grp)
   10134                 :             : {
   10135                 :           0 :   tree tmp = OMP_CLAUSE_CHAIN (grp->grp_end);
   10136                 :           0 :   OMP_CLAUSE_CHAIN (grp->grp_end) = NULL;
   10137                 :           0 :   debug_generic_expr (*grp->grp_start);
   10138                 :           0 :   OMP_CLAUSE_CHAIN (grp->grp_end) = tmp;
   10139                 :           0 : }
   10140                 :             : 
   10141                 :             : /* Return the OpenMP "base pointer" of an expression EXPR, or NULL if there
   10142                 :             :    isn't one.  */
   10143                 :             : 
   10144                 :             : static tree
   10145                 :       30706 : omp_get_base_pointer (tree expr)
   10146                 :             : {
   10147                 :       30706 :   while (TREE_CODE (expr) == ARRAY_REF
   10148                 :       35635 :          || TREE_CODE (expr) == COMPONENT_REF)
   10149                 :        4929 :     expr = TREE_OPERAND (expr, 0);
   10150                 :             : 
   10151                 :       30706 :   if (INDIRECT_REF_P (expr)
   10152                 :       30706 :       || (TREE_CODE (expr) == MEM_REF
   10153                 :           0 :           && integer_zerop (TREE_OPERAND (expr, 1))))
   10154                 :             :     {
   10155                 :        9067 :       expr = TREE_OPERAND (expr, 0);
   10156                 :        9104 :       while (TREE_CODE (expr) == COMPOUND_EXPR)
   10157                 :          37 :         expr = TREE_OPERAND (expr, 1);
   10158                 :        9067 :       if (TREE_CODE (expr) == POINTER_PLUS_EXPR)
   10159                 :         705 :         expr = TREE_OPERAND (expr, 0);
   10160                 :        9067 :       if (TREE_CODE (expr) == SAVE_EXPR)
   10161                 :          31 :         expr = TREE_OPERAND (expr, 0);
   10162                 :        9067 :       STRIP_NOPS (expr);
   10163                 :        9067 :       return expr;
   10164                 :             :     }
   10165                 :             : 
   10166                 :             :   return NULL_TREE;
   10167                 :             : }
   10168                 :             : 
   10169                 :             : /* An attach or detach operation depends directly on the address being
   10170                 :             :    attached/detached.  Return that address, or none if there are no
   10171                 :             :    attachments/detachments.  */
   10172                 :             : 
   10173                 :             : static tree
   10174                 :       13923 : omp_get_attachment (omp_mapping_group *grp)
   10175                 :             : {
   10176                 :       13923 :   tree node = *grp->grp_start;
   10177                 :             : 
   10178                 :       13923 :   switch (OMP_CLAUSE_MAP_KIND (node))
   10179                 :             :     {
   10180                 :       11625 :     case GOMP_MAP_TO:
   10181                 :       11625 :     case GOMP_MAP_FROM:
   10182                 :       11625 :     case GOMP_MAP_TOFROM:
   10183                 :       11625 :     case GOMP_MAP_ALWAYS_FROM:
   10184                 :       11625 :     case GOMP_MAP_ALWAYS_TO:
   10185                 :       11625 :     case GOMP_MAP_ALWAYS_TOFROM:
   10186                 :       11625 :     case GOMP_MAP_FORCE_FROM:
   10187                 :       11625 :     case GOMP_MAP_FORCE_TO:
   10188                 :       11625 :     case GOMP_MAP_FORCE_TOFROM:
   10189                 :       11625 :     case GOMP_MAP_FORCE_PRESENT:
   10190                 :       11625 :     case GOMP_MAP_PRESENT_ALLOC:
   10191                 :       11625 :     case GOMP_MAP_PRESENT_FROM:
   10192                 :       11625 :     case GOMP_MAP_PRESENT_TO:
   10193                 :       11625 :     case GOMP_MAP_PRESENT_TOFROM:
   10194                 :       11625 :     case GOMP_MAP_ALWAYS_PRESENT_FROM:
   10195                 :       11625 :     case GOMP_MAP_ALWAYS_PRESENT_TO:
   10196                 :       11625 :     case GOMP_MAP_ALWAYS_PRESENT_TOFROM:
   10197                 :       11625 :     case GOMP_MAP_ALLOC:
   10198                 :       11625 :     case GOMP_MAP_RELEASE:
   10199                 :       11625 :     case GOMP_MAP_DELETE:
   10200                 :       11625 :     case GOMP_MAP_FORCE_ALLOC:
   10201                 :       11625 :       if (node == grp->grp_end)
   10202                 :             :         return NULL_TREE;
   10203                 :             : 
   10204                 :        5591 :       node = OMP_CLAUSE_CHAIN (node);
   10205                 :        5591 :       if (node && omp_map_clause_descriptor_p (node))
   10206                 :             :         {
   10207                 :         987 :           gcc_assert (node != grp->grp_end);
   10208                 :         987 :           node = OMP_CLAUSE_CHAIN (node);
   10209                 :             :         }
   10210                 :        5591 :       if (node)
   10211                 :        5591 :         switch (OMP_CLAUSE_MAP_KIND (node))
   10212                 :             :           {
   10213                 :             :           case GOMP_MAP_POINTER:
   10214                 :             :           case GOMP_MAP_ALWAYS_POINTER:
   10215                 :             :           case GOMP_MAP_FIRSTPRIVATE_POINTER:
   10216                 :             :           case GOMP_MAP_FIRSTPRIVATE_REFERENCE:
   10217                 :             :           case GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION:
   10218                 :             :             return NULL_TREE;
   10219                 :             : 
   10220                 :        1885 :           case GOMP_MAP_ATTACH_DETACH:
   10221                 :        1885 :           case GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION:
   10222                 :        1885 :           case GOMP_MAP_DETACH:
   10223                 :        1885 :             return OMP_CLAUSE_DECL (node);
   10224                 :             : 
   10225                 :           0 :           default:
   10226                 :           0 :             internal_error ("unexpected mapping node");
   10227                 :             :           }
   10228                 :           0 :       return error_mark_node;
   10229                 :             : 
   10230                 :           0 :     case GOMP_MAP_TO_PSET:
   10231                 :           0 :       gcc_assert (node != grp->grp_end);
   10232                 :           0 :       node = OMP_CLAUSE_CHAIN (node);
   10233                 :           0 :       if (OMP_CLAUSE_MAP_KIND (node) == GOMP_MAP_ATTACH
   10234                 :           0 :           || OMP_CLAUSE_MAP_KIND (node) == GOMP_MAP_DETACH)
   10235                 :           0 :         return OMP_CLAUSE_DECL (node);
   10236                 :             :       else
   10237                 :           0 :         internal_error ("unexpected mapping node");
   10238                 :             :       return error_mark_node;
   10239                 :             : 
   10240                 :         394 :     case GOMP_MAP_ATTACH:
   10241                 :         394 :     case GOMP_MAP_DETACH:
   10242                 :         394 :       node = OMP_CLAUSE_CHAIN (node);
   10243                 :         394 :       if (!node || *grp->grp_start == grp->grp_end)
   10244                 :         394 :         return OMP_CLAUSE_DECL (*grp->grp_start);
   10245                 :           0 :       if (OMP_CLAUSE_MAP_KIND (node) == GOMP_MAP_FIRSTPRIVATE_POINTER
   10246                 :           0 :           || OMP_CLAUSE_MAP_KIND (node) == GOMP_MAP_FIRSTPRIVATE_REFERENCE)
   10247                 :           0 :         return OMP_CLAUSE_DECL (*grp->grp_start);
   10248                 :             :       else
   10249                 :           0 :         internal_error ("unexpected mapping node");
   10250                 :             :       return error_mark_node;
   10251                 :             : 
   10252                 :             :     case GOMP_MAP_STRUCT:
   10253                 :             :     case GOMP_MAP_STRUCT_UNORD:
   10254                 :             :     case GOMP_MAP_FORCE_DEVICEPTR:
   10255                 :             :     case GOMP_MAP_DEVICE_RESIDENT:
   10256                 :             :     case GOMP_MAP_LINK:
   10257                 :             :     case GOMP_MAP_IF_PRESENT:
   10258                 :             :     case GOMP_MAP_FIRSTPRIVATE:
   10259                 :             :     case GOMP_MAP_FIRSTPRIVATE_INT:
   10260                 :             :     case GOMP_MAP_USE_DEVICE_PTR:
   10261                 :             :     case GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION:
   10262                 :             :       return NULL_TREE;
   10263                 :             : 
   10264                 :           0 :     default:
   10265                 :           0 :       internal_error ("unexpected mapping node");
   10266                 :             :     }
   10267                 :             : 
   10268                 :             :   return error_mark_node;
   10269                 :             : }
   10270                 :             : 
   10271                 :             : /* Given a pointer START_P to the start of a group of related (e.g. pointer)
   10272                 :             :    mappings, return the chain pointer to the end of that group in the list.  */
   10273                 :             : 
   10274                 :             : static tree *
   10275                 :      100099 : omp_group_last (tree *start_p)
   10276                 :             : {
   10277                 :      100099 :   tree c = *start_p, nc, *grp_last_p = start_p;
   10278                 :             : 
   10279                 :      100099 :   gcc_assert (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP);
   10280                 :             : 
   10281                 :      100099 :   nc = OMP_CLAUSE_CHAIN (c);
   10282                 :             : 
   10283                 :      175783 :   if (!nc || OMP_CLAUSE_CODE (nc) != OMP_CLAUSE_MAP)
   10284                 :             :     return grp_last_p;
   10285                 :             : 
   10286                 :       63642 :   switch (OMP_CLAUSE_MAP_KIND (c))
   10287                 :             :     {
   10288                 :             :     default:
   10289                 :             :       while (nc
   10290                 :      103603 :              && OMP_CLAUSE_CODE (nc) == OMP_CLAUSE_MAP
   10291                 :      217067 :              && (OMP_CLAUSE_MAP_KIND (nc) == GOMP_MAP_FIRSTPRIVATE_REFERENCE
   10292                 :       96549 :                  || OMP_CLAUSE_MAP_KIND (nc) == GOMP_MAP_FIRSTPRIVATE_POINTER
   10293                 :       86725 :                  || OMP_CLAUSE_MAP_KIND (nc) == GOMP_MAP_ATTACH_DETACH
   10294                 :       76735 :                  || OMP_CLAUSE_MAP_KIND (nc) == GOMP_MAP_POINTER
   10295                 :       51239 :                  || (OMP_CLAUSE_MAP_KIND (nc)
   10296                 :             :                      == GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION)
   10297                 :       51223 :                  || (OMP_CLAUSE_MAP_KIND (nc)
   10298                 :             :                      == GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION)
   10299                 :       50856 :                  || OMP_CLAUSE_MAP_KIND (nc) == GOMP_MAP_DETACH
   10300                 :       50815 :                  || OMP_CLAUSE_MAP_KIND (nc) == GOMP_MAP_ALWAYS_POINTER
   10301                 :       48935 :                  || omp_map_clause_descriptor_p (nc)))
   10302                 :             :         {
   10303                 :       61204 :           tree nc2 = OMP_CLAUSE_CHAIN (nc);
   10304                 :       61204 :           if (OMP_CLAUSE_MAP_KIND (nc) == GOMP_MAP_DETACH)
   10305                 :             :             {
   10306                 :             :               /* In the specific case we're doing "exit data" on an array
   10307                 :             :                  slice of a reference-to-pointer struct component, we will see
   10308                 :             :                  DETACH followed by ATTACH_DETACH here.  We want to treat that
   10309                 :             :                  as a single group. In other cases DETACH might represent a
   10310                 :             :                  stand-alone "detach" clause, so we don't want to consider
   10311                 :             :                  that part of the group.  */
   10312                 :          41 :               if (nc2
   10313                 :          12 :                   && OMP_CLAUSE_CODE (nc2) == OMP_CLAUSE_MAP
   10314                 :          53 :                   && OMP_CLAUSE_MAP_KIND (nc2) == GOMP_MAP_ATTACH_DETACH)
   10315                 :           0 :                 goto consume_two_nodes;
   10316                 :             :               else
   10317                 :             :                 break;
   10318                 :             :             }
   10319                 :       61163 :           if (nc2
   10320                 :       44805 :               && OMP_CLAUSE_CODE (nc2) == OMP_CLAUSE_MAP
   10321                 :       38304 :               && (OMP_CLAUSE_MAP_KIND (nc)
   10322                 :             :                   == GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION)
   10323                 :       61179 :               && OMP_CLAUSE_MAP_KIND (nc2) == GOMP_MAP_ATTACH)
   10324                 :             :             {
   10325                 :          16 :             consume_two_nodes:
   10326                 :          16 :               grp_last_p = &OMP_CLAUSE_CHAIN (nc);
   10327                 :          16 :               c = nc2;
   10328                 :          16 :               nc = OMP_CLAUSE_CHAIN (nc2);
   10329                 :             :             }
   10330                 :             :           else
   10331                 :             :             {
   10332                 :       61147 :               grp_last_p = &OMP_CLAUSE_CHAIN (c);
   10333                 :       61147 :               c = nc;
   10334                 :       61147 :               nc = nc2;
   10335                 :             :             }
   10336                 :             :         }
   10337                 :             :       break;
   10338                 :             : 
   10339                 :         120 :     case GOMP_MAP_ATTACH:
   10340                 :         120 :     case GOMP_MAP_DETACH:
   10341                 :             :       /* This is a weird artifact of how directives are parsed: bare attach or
   10342                 :             :          detach clauses get a subsequent (meaningless) FIRSTPRIVATE_POINTER or
   10343                 :             :          FIRSTPRIVATE_REFERENCE node.  FIXME.  */
   10344                 :         120 :       if (nc
   10345                 :         120 :           && OMP_CLAUSE_CODE (nc) == OMP_CLAUSE_MAP
   10346                 :         120 :           && (OMP_CLAUSE_MAP_KIND (nc) == GOMP_MAP_FIRSTPRIVATE_REFERENCE
   10347                 :         120 :               || OMP_CLAUSE_MAP_KIND (nc) == GOMP_MAP_FIRSTPRIVATE_POINTER))
   10348                 :           0 :         grp_last_p = &OMP_CLAUSE_CHAIN (c);
   10349                 :             :       break;
   10350                 :             : 
   10351                 :          27 :     case GOMP_MAP_TO_PSET:
   10352                 :          27 :       if (OMP_CLAUSE_CODE (nc) == OMP_CLAUSE_MAP
   10353                 :          27 :           && (OMP_CLAUSE_MAP_KIND (nc) == GOMP_MAP_ATTACH
   10354                 :           6 :               || OMP_CLAUSE_MAP_KIND (nc) == GOMP_MAP_DETACH))
   10355                 :          27 :         grp_last_p = &OMP_CLAUSE_CHAIN (c);
   10356                 :             :       break;
   10357                 :             : 
   10358                 :        4693 :     case GOMP_MAP_STRUCT:
   10359                 :        4693 :     case GOMP_MAP_STRUCT_UNORD:
   10360                 :        4693 :       {
   10361                 :        4693 :         unsigned HOST_WIDE_INT num_mappings
   10362                 :        4693 :           = tree_to_uhwi (OMP_CLAUSE_SIZE (c));
   10363                 :        4693 :         if (OMP_CLAUSE_MAP_KIND (nc) == GOMP_MAP_FIRSTPRIVATE_POINTER
   10364                 :        4361 :             || OMP_CLAUSE_MAP_KIND (nc) == GOMP_MAP_FIRSTPRIVATE_REFERENCE
   10365                 :        8576 :             || OMP_CLAUSE_MAP_KIND (nc) == GOMP_MAP_ATTACH_DETACH)
   10366                 :        1109 :           grp_last_p = &OMP_CLAUSE_CHAIN (*grp_last_p);
   10367                 :       11387 :         for (unsigned i = 0; i < num_mappings; i++)
   10368                 :        6694 :           grp_last_p = &OMP_CLAUSE_CHAIN (*grp_last_p);
   10369                 :             :       }
   10370                 :             :       break;
   10371                 :             :     }
   10372                 :             : 
   10373                 :             :   return grp_last_p;
   10374                 :             : }
   10375                 :             : 
   10376                 :             : /* Walk through LIST_P, and return a list of groups of mappings found (e.g.
   10377                 :             :    OMP_CLAUSE_MAP with GOMP_MAP_{TO/FROM/TOFROM} followed by one or two
   10378                 :             :    associated GOMP_MAP_POINTER mappings).  Return a vector of omp_mapping_group
   10379                 :             :    if we have more than one such group, else return NULL.  */
   10380                 :             : 
   10381                 :             : static void
   10382                 :       84123 : omp_gather_mapping_groups_1 (tree *list_p, vec<omp_mapping_group> *groups,
   10383                 :             :                              tree gather_sentinel)
   10384                 :             : {
   10385                 :       84123 :   for (tree *cp = list_p;
   10386                 :      247486 :        *cp && *cp != gather_sentinel;
   10387                 :      163363 :        cp = &OMP_CLAUSE_CHAIN (*cp))
   10388                 :             :     {
   10389                 :      163363 :       if (OMP_CLAUSE_CODE (*cp) != OMP_CLAUSE_MAP)
   10390                 :       92266 :         continue;
   10391                 :             : 
   10392                 :       71097 :       tree *grp_last_p = omp_group_last (cp);
   10393                 :       71097 :       omp_mapping_group grp;
   10394                 :             : 
   10395                 :       71097 :       grp.grp_start = cp;
   10396                 :       71097 :       grp.grp_end = *grp_last_p;
   10397                 :       71097 :       grp.mark = UNVISITED;
   10398                 :       71097 :       grp.sibling = NULL;
   10399                 :       71097 :       grp.deleted = false;
   10400                 :       71097 :       grp.reprocess_struct = false;
   10401                 :       71097 :       grp.fragile = false;
   10402                 :       71097 :       grp.next = NULL;
   10403                 :       71097 :       groups->safe_push (grp);
   10404                 :             : 
   10405                 :       71097 :       cp = grp_last_p;
   10406                 :             :     }
   10407                 :       84123 : }
   10408                 :             : 
   10409                 :             : static vec<omp_mapping_group> *
   10410                 :       83820 : omp_gather_mapping_groups (tree *list_p)
   10411                 :             : {
   10412                 :       83820 :   vec<omp_mapping_group> *groups = new vec<omp_mapping_group> ();
   10413                 :             : 
   10414                 :       83820 :   omp_gather_mapping_groups_1 (list_p, groups, NULL_TREE);
   10415                 :             : 
   10416                 :       83820 :   if (groups->length () > 0)
   10417                 :             :     return groups;
   10418                 :             :   else
   10419                 :             :     {
   10420                 :       43558 :       delete groups;
   10421                 :       43558 :       return NULL;
   10422                 :             :     }
   10423                 :             : }
   10424                 :             : 
   10425                 :             : /* A pointer mapping group GRP may define a block of memory starting at some
   10426                 :             :    base address, and maybe also define a firstprivate pointer or firstprivate
   10427                 :             :    reference that points to that block.  The return value is a node containing
   10428                 :             :    the former, and the *FIRSTPRIVATE pointer is set if we have the latter.
   10429                 :             :    If we define several base pointers, i.e. for a GOMP_MAP_STRUCT mapping,
   10430                 :             :    return the number of consecutive chained nodes in CHAINED.  */
   10431                 :             : 
   10432                 :             : static tree
   10433                 :       71433 : omp_group_base (omp_mapping_group *grp, unsigned int *chained,
   10434                 :             :                 tree *firstprivate)
   10435                 :             : {
   10436                 :       71433 :   tree node = *grp->grp_start;
   10437                 :             : 
   10438                 :       71433 :   *firstprivate = NULL_TREE;
   10439                 :       71433 :   *chained = 1;
   10440                 :             : 
   10441                 :       71433 :   switch (OMP_CLAUSE_MAP_KIND (node))
   10442                 :             :     {
   10443                 :       68024 :     case GOMP_MAP_TO:
   10444                 :       68024 :     case GOMP_MAP_FROM:
   10445                 :       68024 :     case GOMP_MAP_TOFROM:
   10446                 :       68024 :     case GOMP_MAP_ALWAYS_FROM:
   10447                 :       68024 :     case GOMP_MAP_ALWAYS_TO:
   10448                 :       68024 :     case GOMP_MAP_ALWAYS_TOFROM:
   10449                 :       68024 :     case GOMP_MAP_FORCE_FROM:
   10450                 :       68024 :     case GOMP_MAP_FORCE_TO:
   10451                 :       68024 :     case GOMP_MAP_FORCE_TOFROM:
   10452                 :       68024 :     case GOMP_MAP_FORCE_PRESENT:
   10453                 :       68024 :     case GOMP_MAP_PRESENT_ALLOC:
   10454                 :       68024 :     case GOMP_MAP_PRESENT_FROM:
   10455                 :       68024 :     case GOMP_MAP_PRESENT_TO:
   10456                 :       68024 :     case GOMP_MAP_PRESENT_TOFROM:
   10457                 :       68024 :     case GOMP_MAP_ALWAYS_PRESENT_FROM:
   10458                 :       68024 :     case GOMP_MAP_ALWAYS_PRESENT_TO:
   10459                 :       68024 :     case GOMP_MAP_ALWAYS_PRESENT_TOFROM:
   10460                 :       68024 :     case GOMP_MAP_ALLOC:
   10461                 :       68024 :     case GOMP_MAP_RELEASE:
   10462                 :       68024 :     case GOMP_MAP_DELETE:
   10463                 :       68024 :     case GOMP_MAP_FORCE_ALLOC:
   10464                 :       68024 :     case GOMP_MAP_IF_PRESENT:
   10465                 :       68024 :       if (node == grp->grp_end)
   10466                 :             :         return node;
   10467                 :             : 
   10468                 :       31478 :       node = OMP_CLAUSE_CHAIN (node);
   10469                 :       31478 :       if (!node)
   10470                 :           0 :         internal_error ("unexpected mapping node");
   10471                 :       31478 :       if (omp_map_clause_descriptor_p (node))
   10472                 :             :         {
   10473                 :        9549 :           if (node == grp->grp_end)
   10474                 :           0 :             return *grp->grp_start;
   10475                 :        9549 :           node = OMP_CLAUSE_CHAIN (node);
   10476                 :             :         }
   10477                 :       31478 :       switch (OMP_CLAUSE_MAP_KIND (node))
   10478                 :             :         {
   10479                 :       22380 :         case GOMP_MAP_POINTER:
   10480                 :       22380 :         case GOMP_MAP_FIRSTPRIVATE_POINTER:
   10481                 :       22380 :         case GOMP_MAP_FIRSTPRIVATE_REFERENCE:
   10482                 :       22380 :         case GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION:
   10483                 :       22380 :           *firstprivate = OMP_CLAUSE_DECL (node);
   10484                 :       22380 :           return *grp->grp_start;
   10485                 :             : 
   10486                 :        9098 :         case GOMP_MAP_ALWAYS_POINTER:
   10487                 :        9098 :         case GOMP_MAP_ATTACH_DETACH:
   10488                 :        9098 :         case GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION:
   10489                 :        9098 :         case GOMP_MAP_DETACH:
   10490                 :        9098 :           return *grp->grp_start;
   10491                 :             : 
   10492                 :           0 :         default:
   10493                 :           0 :           internal_error ("unexpected mapping node");
   10494                 :             :         }
   10495                 :             :       return error_mark_node;
   10496                 :             : 
   10497                 :          18 :     case GOMP_MAP_TO_PSET:
   10498                 :          18 :       gcc_assert (node != grp->grp_end);
   10499                 :          18 :       node = OMP_CLAUSE_CHAIN (node);
   10500                 :          18 :       if (OMP_CLAUSE_MAP_KIND (node) == GOMP_MAP_ATTACH
   10501                 :          18 :           || OMP_CLAUSE_MAP_KIND (node) == GOMP_MAP_DETACH)
   10502                 :             :         return NULL_TREE;
   10503                 :             :       else
   10504                 :           0 :         internal_error ("unexpected mapping node");
   10505                 :             :       return error_mark_node;
   10506                 :             : 
   10507                 :         898 :     case GOMP_MAP_ATTACH:
   10508                 :         898 :     case GOMP_MAP_DETACH:
   10509                 :         898 :       node = OMP_CLAUSE_CHAIN (node);
   10510                 :         898 :       if (!node || *grp->grp_start == grp->grp_end)
   10511                 :             :         return NULL_TREE;
   10512                 :           0 :       if (OMP_CLAUSE_MAP_KIND (node) == GOMP_MAP_FIRSTPRIVATE_POINTER
   10513                 :           0 :           || OMP_CLAUSE_MAP_KIND (node) == GOMP_MAP_FIRSTPRIVATE_REFERENCE)
   10514                 :             :         {
   10515                 :             :           /* We're mapping the base pointer itself in a bare attach or detach
   10516                 :             :              node.  This is a side effect of how parsing works, and the mapping
   10517                 :             :              will be removed anyway (at least for enter/exit data directives).
   10518                 :             :              We should ignore the mapping here.  FIXME.  */
   10519                 :             :           return NULL_TREE;
   10520                 :             :         }
   10521                 :             :       else
   10522                 :           0 :         internal_error ("unexpected mapping node");
   10523                 :             :       return error_mark_node;
   10524                 :             : 
   10525                 :        2243 :     case GOMP_MAP_STRUCT:
   10526                 :        2243 :     case GOMP_MAP_STRUCT_UNORD:
   10527                 :        2243 :       {
   10528                 :        2243 :         unsigned HOST_WIDE_INT num_mappings
   10529                 :        2243 :           = tree_to_uhwi (OMP_CLAUSE_SIZE (node));
   10530                 :        2243 :         node = OMP_CLAUSE_CHAIN (node);
   10531                 :        2243 :         if (OMP_CLAUSE_MAP_KIND (node) == GOMP_MAP_FIRSTPRIVATE_POINTER
   10532                 :        2243 :             || OMP_CLAUSE_MAP_KIND (node) == GOMP_MAP_FIRSTPRIVATE_REFERENCE)
   10533                 :             :           {
   10534                 :         388 :             *firstprivate = OMP_CLAUSE_DECL (node);
   10535                 :         388 :             node = OMP_CLAUSE_CHAIN (node);
   10536                 :             :           }
   10537                 :        1855 :         else if (OMP_CLAUSE_MAP_KIND (node) == GOMP_MAP_ATTACH_DETACH)
   10538                 :         299 :           node = OMP_CLAUSE_CHAIN (node);
   10539                 :        2243 :         *chained = num_mappings;
   10540                 :        2243 :         return node;
   10541                 :             :       }
   10542                 :             : 
   10543                 :             :     case GOMP_MAP_FORCE_DEVICEPTR:
   10544                 :             :     case GOMP_MAP_DEVICE_RESIDENT:
   10545                 :             :     case GOMP_MAP_LINK:
   10546                 :             :     case GOMP_MAP_FIRSTPRIVATE:
   10547                 :             :     case GOMP_MAP_FIRSTPRIVATE_INT:
   10548                 :             :     case GOMP_MAP_USE_DEVICE_PTR:
   10549                 :             :     case GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION:
   10550                 :             :       return NULL_TREE;
   10551                 :             : 
   10552                 :           0 :     case GOMP_MAP_FIRSTPRIVATE_POINTER:
   10553                 :           0 :     case GOMP_MAP_FIRSTPRIVATE_REFERENCE:
   10554                 :           0 :     case GOMP_MAP_POINTER:
   10555                 :           0 :     case GOMP_MAP_ALWAYS_POINTER:
   10556                 :           0 :     case GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION:
   10557                 :             :       /* These shouldn't appear by themselves.  */
   10558                 :           0 :       if (!seen_error ())
   10559                 :           0 :         internal_error ("unexpected pointer mapping node");
   10560                 :           0 :       return error_mark_node;
   10561                 :             : 
   10562                 :           0 :     default:
   10563                 :           0 :       gcc_unreachable ();
   10564                 :             :     }
   10565                 :             : 
   10566                 :             :   return error_mark_node;
   10567                 :             : }
   10568                 :             : 
   10569                 :             : /* Given a vector of omp_mapping_groups, build a hash table so we can look up
   10570                 :             :    nodes by tree_operand_hash_no_se.  */
   10571                 :             : 
   10572                 :             : static void
   10573                 :       40716 : omp_index_mapping_groups_1 (hash_map<tree_operand_hash_no_se,
   10574                 :             :                                      omp_mapping_group *> *grpmap,
   10575                 :             :                             vec<omp_mapping_group> *groups,
   10576                 :             :                             tree reindex_sentinel)
   10577                 :             : {
   10578                 :       40716 :   omp_mapping_group *grp;
   10579                 :       40716 :   unsigned int i;
   10580                 :       40716 :   bool reindexing = reindex_sentinel != NULL_TREE, above_hwm = false;
   10581                 :             : 
   10582                 :      112557 :   FOR_EACH_VEC_ELT (*groups, i, grp)
   10583                 :             :     {
   10584                 :       71841 :       if (reindexing && *grp->grp_start == reindex_sentinel)
   10585                 :       71841 :         above_hwm = true;
   10586                 :             : 
   10587                 :       71841 :       if (reindexing && !above_hwm)
   10588                 :       49073 :         continue;
   10589                 :             : 
   10590                 :       71572 :       if (grp->reprocess_struct)
   10591                 :         139 :         continue;
   10592                 :             : 
   10593                 :       71433 :       tree fpp;
   10594                 :       71433 :       unsigned int chained;
   10595                 :       71433 :       tree node = omp_group_base (grp, &chained, &fpp);
   10596                 :             : 
   10597                 :       71433 :       if (node == error_mark_node || (!node && !fpp))
   10598                 :        1166 :         continue;
   10599                 :             : 
   10600                 :             :       for (unsigned j = 0;
   10601                 :      141495 :            node && j < chained;
   10602                 :       71228 :            node = OMP_CLAUSE_CHAIN (node), j++)
   10603                 :             :         {
   10604                 :       71228 :           tree decl = OMP_CLAUSE_DECL (node);
   10605                 :             :           /* Sometimes we see zero-offset MEM_REF instead of INDIRECT_REF,
   10606                 :             :              meaning node-hash lookups don't work.  This is a workaround for
   10607                 :             :              that, but ideally we should just create the INDIRECT_REF at
   10608                 :             :              source instead.  FIXME.  */
   10609                 :       71228 :           if (TREE_CODE (decl) == MEM_REF
   10610                 :       71228 :               && integer_zerop (TREE_OPERAND (decl, 1)))
   10611                 :           0 :             decl = build_fold_indirect_ref (TREE_OPERAND (decl, 0));
   10612                 :             : 
   10613                 :       71228 :           omp_mapping_group **prev = grpmap->get (decl);
   10614                 :             : 
   10615                 :       71228 :           if (prev && *prev == grp)
   10616                 :             :             /* Empty.  */;
   10617                 :       71228 :           else if (prev)
   10618                 :             :             {
   10619                 :             :               /* Mapping the same thing twice is normally diagnosed as an error,
   10620                 :             :                  but can happen under some circumstances, e.g. in pr99928-16.c,
   10621                 :             :                  the directive:
   10622                 :             : 
   10623                 :             :                  #pragma omp target simd reduction(+:a[:3]) \
   10624                 :             :                                          map(always, tofrom: a[:6])
   10625                 :             :                  ...
   10626                 :             : 
   10627                 :             :                  will result in two "a[0]" mappings (of different sizes).  */
   10628                 :             : 
   10629                 :         120 :               grp->sibling = (*prev)->sibling;
   10630                 :         120 :               (*prev)->sibling = grp;
   10631                 :             :             }
   10632                 :             :           else
   10633                 :       71108 :             grpmap->put (decl, grp);
   10634                 :             :         }
   10635                 :             : 
   10636                 :       70267 :       if (!fpp)
   10637                 :       47499 :         continue;
   10638                 :             : 
   10639                 :       22768 :       omp_mapping_group **prev = grpmap->get (fpp);
   10640                 :       22768 :       if (prev && *prev != grp)
   10641                 :             :         {
   10642                 :          12 :           grp->sibling = (*prev)->sibling;
   10643                 :          12 :           (*prev)->sibling = grp;
   10644                 :             :         }
   10645                 :             :       else
   10646                 :       22756 :         grpmap->put (fpp, grp);
   10647                 :             :     }
   10648                 :       40716 : }
   10649                 :             : 
   10650                 :             : static hash_map<tree_operand_hash_no_se, omp_mapping_group *> *
   10651                 :       40262 : omp_index_mapping_groups (vec<omp_mapping_group> *groups)
   10652                 :             : {
   10653                 :       40262 :   hash_map<tree_operand_hash_no_se, omp_mapping_group *> *grpmap
   10654                 :       40262 :     = new hash_map<tree_operand_hash_no_se, omp_mapping_group *>;
   10655                 :             : 
   10656                 :       40262 :   omp_index_mapping_groups_1 (grpmap, groups, NULL_TREE);
   10657                 :             : 
   10658                 :       40262 :   return grpmap;
   10659                 :             : }
   10660                 :             : 
   10661                 :             : /* Rebuild group map from partially-processed clause list (during
   10662                 :             :    omp_build_struct_sibling_lists).  We have already processed nodes up until
   10663                 :             :    a high-water mark (HWM).  This is a bit tricky because the list is being
   10664                 :             :    reordered as it is scanned, but we know:
   10665                 :             : 
   10666                 :             :    1. The list after HWM has not been touched yet, so we can reindex it safely.
   10667                 :             : 
   10668                 :             :    2. The list before and including HWM has been altered, but remains
   10669                 :             :       well-formed throughout the sibling-list building operation.
   10670                 :             : 
   10671                 :             :    so, we can do the reindex operation in two parts, on the processed and
   10672                 :             :    then the unprocessed halves of the list.  */
   10673                 :             : 
   10674                 :             : static hash_map<tree_operand_hash_no_se, omp_mapping_group *> *
   10675                 :         303 : omp_reindex_mapping_groups (tree *list_p,
   10676                 :             :                             vec<omp_mapping_group> *groups,
   10677                 :             :                             vec<omp_mapping_group> *processed_groups,
   10678                 :             :                             tree sentinel)
   10679                 :             : {
   10680                 :         303 :   hash_map<tree_operand_hash_no_se, omp_mapping_group *> *grpmap
   10681                 :         303 :     = new hash_map<tree_operand_hash_no_se, omp_mapping_group *>;
   10682                 :             : 
   10683                 :         303 :   processed_groups->truncate (0);
   10684                 :             : 
   10685                 :         303 :   omp_gather_mapping_groups_1 (list_p, processed_groups, sentinel);
   10686                 :         303 :   omp_index_mapping_groups_1 (grpmap, processed_groups, NULL_TREE);
   10687                 :         303 :   if (sentinel)
   10688                 :         151 :     omp_index_mapping_groups_1 (grpmap, groups, sentinel);
   10689                 :             : 
   10690                 :         303 :   return grpmap;
   10691                 :             : }
   10692                 :             : 
   10693                 :             : /* Find the immediately-containing struct for a component ref (etc.)
   10694                 :             :    expression EXPR.  */
   10695                 :             : 
   10696                 :             : static tree
   10697                 :       35017 : omp_containing_struct (tree expr)
   10698                 :             : {
   10699                 :       35017 :   tree expr0 = expr;
   10700                 :             : 
   10701                 :       35017 :   STRIP_NOPS (expr);
   10702                 :             : 
   10703                 :             :   /* Note: don't strip NOPs unless we're also stripping off array refs or a
   10704                 :             :      component ref.  */
   10705                 :       35017 :   if (TREE_CODE (expr) != ARRAY_REF && TREE_CODE (expr) != COMPONENT_REF)
   10706                 :             :     return expr0;
   10707                 :             : 
   10708                 :       17447 :   while (TREE_CODE (expr) == ARRAY_REF)
   10709                 :        2054 :     expr = TREE_OPERAND (expr, 0);
   10710                 :             : 
   10711                 :       15393 :   if (TREE_CODE (expr) == COMPONENT_REF)
   10712                 :       14486 :     expr = TREE_OPERAND (expr, 0);
   10713                 :             : 
   10714                 :             :   return expr;
   10715                 :             : }
   10716                 :             : 
   10717                 :             : /* Return TRUE if DECL describes a component that is part of a whole structure
   10718                 :             :    that is mapped elsewhere in GRPMAP.  *MAPPED_BY_GROUP is set to the group
   10719                 :             :    that maps that structure, if present.  */
   10720                 :             : 
   10721                 :             : static bool
   10722                 :       20541 : omp_mapped_by_containing_struct (hash_map<tree_operand_hash_no_se,
   10723                 :             :                                           omp_mapping_group *> *grpmap,
   10724                 :             :                                  tree decl,
   10725                 :             :                                  omp_mapping_group **mapped_by_group)
   10726                 :             : {
   10727                 :       20541 :   tree wsdecl = NULL_TREE;
   10728                 :             : 
   10729                 :       20541 :   *mapped_by_group = NULL;
   10730                 :             : 
   10731                 :       35017 :   while (true)
   10732                 :             :     {
   10733                 :       35017 :       wsdecl = omp_containing_struct (decl);
   10734                 :       35017 :       if (wsdecl == decl)
   10735                 :             :         break;
   10736                 :       15393 :       omp_mapping_group **wholestruct = grpmap->get (wsdecl);
   10737                 :       15393 :       if (!wholestruct
   10738                 :       14476 :           && TREE_CODE (wsdecl) == MEM_REF
   10739                 :       15393 :           && integer_zerop (TREE_OPERAND (wsdecl, 1)))
   10740                 :             :         {
   10741                 :           0 :           tree deref = TREE_OPERAND (wsdecl, 0);
   10742                 :           0 :           deref = build_fold_indirect_ref (deref);
   10743                 :           0 :           wholestruct = grpmap->get (deref);
   10744                 :             :         }
   10745                 :       15393 :       if (wholestruct)
   10746                 :             :         {
   10747                 :         917 :           *mapped_by_group = *wholestruct;
   10748                 :         917 :           return true;
   10749                 :             :         }
   10750                 :             :       decl = wsdecl;
   10751                 :             :     }
   10752                 :             : 
   10753                 :             :   return false;
   10754                 :             : }
   10755                 :             : 
   10756                 :             : /* Helper function for omp_tsort_mapping_groups.  Returns TRUE on success, or
   10757                 :             :    FALSE on error.  */
   10758                 :             : 
   10759                 :             : static bool
   10760                 :       16748 : omp_tsort_mapping_groups_1 (omp_mapping_group ***outlist,
   10761                 :             :                             vec<omp_mapping_group> *groups,
   10762                 :             :                             hash_map<tree_operand_hash_no_se,
   10763                 :             :                                      omp_mapping_group *> *grpmap,
   10764                 :             :                             omp_mapping_group *grp)
   10765                 :             : {
   10766                 :       16748 :   if (grp->mark == PERMANENT)
   10767                 :             :     return true;
   10768                 :       13923 :   if (grp->mark == TEMPORARY)
   10769                 :             :     {
   10770                 :           0 :       fprintf (stderr, "when processing group:\n");
   10771                 :           0 :       debug_mapping_group (grp);
   10772                 :           0 :       internal_error ("base pointer cycle detected");
   10773                 :             :       return false;
   10774                 :             :     }
   10775                 :       13923 :   grp->mark = TEMPORARY;
   10776                 :             : 
   10777                 :       13923 :   tree attaches_to = omp_get_attachment (grp);
   10778                 :             : 
   10779                 :       13923 :   if (attaches_to)
   10780                 :             :     {
   10781                 :        2279 :       omp_mapping_group **basep = grpmap->get (attaches_to);
   10782                 :             : 
   10783                 :        2279 :       if (basep && *basep != grp)
   10784                 :             :         {
   10785                 :        2592 :           for (omp_mapping_group *w = *basep; w; w = w->sibling)
   10786                 :        1296 :             if (!omp_tsort_mapping_groups_1 (outlist, groups, grpmap, w))
   10787                 :             :               return false;
   10788                 :             :         }
   10789                 :             :     }
   10790                 :             : 
   10791                 :       13923 :   tree decl = OMP_CLAUSE_DECL (*grp->grp_start);
   10792                 :             : 
   10793                 :       19173 :   while (decl)
   10794                 :             :     {
   10795                 :       19173 :       tree base = omp_get_base_pointer (decl);
   10796                 :             : 
   10797                 :       19173 :       if (!base)
   10798                 :             :         break;
   10799                 :             : 
   10800                 :        7557 :       omp_mapping_group **innerp = grpmap->get (base);
   10801                 :        7557 :       omp_mapping_group *wholestruct;
   10802                 :             : 
   10803                 :             :       /* We should treat whole-structure mappings as if all (pointer, in this
   10804                 :             :          case) members are mapped as individual list items.  Check if we have
   10805                 :             :          such a whole-structure mapping, if we don't have an explicit reference
   10806                 :             :          to the pointer member itself.  */
   10807                 :        7557 :       if (!innerp
   10808                 :        3196 :           && TREE_CODE (base) == COMPONENT_REF
   10809                 :        8891 :           && omp_mapped_by_containing_struct (grpmap, base, &wholestruct))
   10810                 :             :         innerp = &wholestruct;
   10811                 :             : 
   10812                 :        7557 :       if (innerp && *innerp != grp)
   10813                 :             :         {
   10814                 :        4614 :           for (omp_mapping_group *w = *innerp; w; w = w->sibling)
   10815                 :        2307 :             if (!omp_tsort_mapping_groups_1 (outlist, groups, grpmap, w))
   10816                 :           0 :               return false;
   10817                 :             :           break;
   10818                 :             :         }
   10819                 :             : 
   10820                 :        5250 :       decl = base;
   10821                 :             :     }
   10822                 :             : 
   10823                 :       13923 :   grp->mark = PERMANENT;
   10824                 :             : 
   10825                 :             :   /* Emit grp to output list.  */
   10826                 :             : 
   10827                 :       13923 :   **outlist = grp;
   10828                 :       13923 :   *outlist = &grp->next;
   10829                 :             : 
   10830                 :       13923 :   return true;
   10831                 :             : }
   10832                 :             : 
   10833                 :             : /* Topologically sort GROUPS, so that OMP 5.0-defined base pointers come
   10834                 :             :    before mappings that use those pointers.  This is an implementation of the
   10835                 :             :    depth-first search algorithm, described e.g. at:
   10836                 :             : 
   10837                 :             :      https://en.wikipedia.org/wiki/Topological_sorting
   10838                 :             : */
   10839                 :             : 
   10840                 :             : static omp_mapping_group *
   10841                 :        7066 : omp_tsort_mapping_groups (vec<omp_mapping_group> *groups,
   10842                 :             :                           hash_map<tree_operand_hash_no_se, omp_mapping_group *>
   10843                 :             :                             *grpmap,
   10844                 :             :                           bool enter_exit_data)
   10845                 :             : {
   10846                 :        7066 :   omp_mapping_group *grp, *outlist = NULL, **cursor;
   10847                 :        7066 :   unsigned int i;
   10848                 :        7066 :   bool saw_runtime_implicit = false;
   10849                 :             : 
   10850                 :        7066 :   cursor = &outlist;
   10851                 :             : 
   10852                 :       20989 :   FOR_EACH_VEC_ELT (*groups, i, grp)
   10853                 :             :     {
   10854                 :       13923 :       if (grp->mark != PERMANENT)
   10855                 :             :         {
   10856                 :       13145 :           if (OMP_CLAUSE_MAP_RUNTIME_IMPLICIT_P (*grp->grp_start))
   10857                 :             :             {
   10858                 :         205 :               saw_runtime_implicit = true;
   10859                 :         205 :               continue;
   10860                 :             :             }
   10861                 :       12940 :           if (!omp_tsort_mapping_groups_1 (&cursor, groups, grpmap, grp))
   10862                 :             :             return NULL;
   10863                 :             :         }
   10864                 :             :     }
   10865                 :             : 
   10866                 :        7066 :   if (!saw_runtime_implicit)
   10867                 :        6935 :     return outlist;
   10868                 :             : 
   10869                 :         536 :   FOR_EACH_VEC_ELT (*groups, i, grp)
   10870                 :             :     {
   10871                 :         405 :       if (grp->mark != PERMANENT
   10872                 :         405 :           && OMP_CLAUSE_MAP_RUNTIME_IMPLICIT_P (*grp->grp_start))
   10873                 :             :         {
   10874                 :             :           /* Clear the flag for enter/exit data because it is currently
   10875                 :             :              meaningless for those operations in libgomp.  */
   10876                 :         205 :           if (enter_exit_data)
   10877                 :          35 :             OMP_CLAUSE_MAP_RUNTIME_IMPLICIT_P (*grp->grp_start) = 0;
   10878                 :             : 
   10879                 :         205 :           if (!omp_tsort_mapping_groups_1 (&cursor, groups, grpmap, grp))
   10880                 :             :             return NULL;
   10881                 :             :         }
   10882                 :             :     }
   10883                 :             : 
   10884                 :         131 :   return outlist;
   10885                 :             : }
   10886                 :             : 
   10887                 :             : /* Split INLIST into three parts:
   10888                 :             : 
   10889                 :             :      - "present" alloc/to/from groups
   10890                 :             :      - other to/from groups
   10891                 :             :      - other alloc/release/delete groups
   10892                 :             : 
   10893                 :             :    These sub-lists are then concatenated together to form the final list.
   10894                 :             :    Each sub-list retains the order of the original list.
   10895                 :             :    Note that ATTACH nodes are later moved to the end of the list in
   10896                 :             :    gimplify_adjust_omp_clauses, for target regions.  */
   10897                 :             : 
   10898                 :             : static omp_mapping_group *
   10899                 :        7066 : omp_segregate_mapping_groups (omp_mapping_group *inlist)
   10900                 :             : {
   10901                 :        7066 :   omp_mapping_group *ard_groups = NULL, *tf_groups = NULL;
   10902                 :        7066 :   omp_mapping_group *p_groups = NULL;
   10903                 :        7066 :   omp_mapping_group **ard_tail = &ard_groups, **tf_tail = &tf_groups;
   10904                 :        7066 :   omp_mapping_group **p_tail = &p_groups;
   10905                 :             : 
   10906                 :       20989 :   for (omp_mapping_group *w = inlist; w;)
   10907                 :             :     {
   10908                 :       13923 :       tree c = *w->grp_start;
   10909                 :       13923 :       omp_mapping_group *next = w->next;
   10910                 :             : 
   10911                 :       13923 :       gcc_assert (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP);
   10912                 :             : 
   10913                 :       13923 :       switch (OMP_CLAUSE_MAP_KIND (c))
   10914                 :             :         {
   10915                 :        1554 :         case GOMP_MAP_ALLOC:
   10916                 :        1554 :         case GOMP_MAP_RELEASE:
   10917                 :        1554 :         case GOMP_MAP_DELETE:
   10918                 :        1554 :           *ard_tail = w;
   10919                 :        1554 :           w->next = NULL;
   10920                 :        1554 :           ard_tail = &w->next;
   10921                 :        1554 :           break;
   10922                 :             : 
   10923                 :             :         /* These map types are all semantically identical, so are moved into a
   10924                 :             :            single group.  They will each be changed into GOMP_MAP_FORCE_PRESENT
   10925                 :             :            in gimplify_adjust_omp_clauses.  */
   10926                 :         123 :         case GOMP_MAP_PRESENT_ALLOC:
   10927                 :         123 :         case GOMP_MAP_PRESENT_FROM:
   10928                 :         123 :         case GOMP_MAP_PRESENT_TO:
   10929                 :         123 :         case GOMP_MAP_PRESENT_TOFROM:
   10930                 :         123 :           *p_tail = w;
   10931                 :         123 :           w->next = NULL;
   10932                 :         123 :           p_tail = &w->next;
   10933                 :         123 :           break;
   10934                 :             : 
   10935                 :       12246 :         default:
   10936                 :       12246 :           *tf_tail = w;
   10937                 :       12246 :           w->next = NULL;
   10938                 :       12246 :           tf_tail = &w->next;
   10939                 :             :         }
   10940                 :             : 
   10941                 :             :       w = next;
   10942                 :             :     }
   10943                 :             : 
   10944                 :             :   /* Now splice the lists together...  */
   10945                 :        7066 :   *tf_tail = ard_groups;
   10946                 :        7066 :   *p_tail = tf_groups;
   10947                 :             : 
   10948                 :        7066 :   return p_groups;
   10949                 :             : }
   10950                 :             : 
   10951                 :             : /* Given a list LIST_P containing groups of mappings given by GROUPS, reorder
   10952                 :             :    those groups based on the output list of omp_tsort_mapping_groups --
   10953                 :             :    singly-linked, threaded through each element's NEXT pointer starting at
   10954                 :             :    HEAD.  Each list element appears exactly once in that linked list.
   10955                 :             : 
   10956                 :             :    Each element of GROUPS may correspond to one or several mapping nodes.
   10957                 :             :    Node groups are kept together, and in the reordered list, the positions of
   10958                 :             :    the original groups are reused for the positions of the reordered list.
   10959                 :             :    Hence if we have e.g.
   10960                 :             : 
   10961                 :             :      {to ptr ptr} firstprivate {tofrom ptr} ...
   10962                 :             :       ^             ^           ^
   10963                 :             :       first group  non-"map"    second group
   10964                 :             : 
   10965                 :             :    and say the second group contains a base pointer for the first so must be
   10966                 :             :    moved before it, the resulting list will contain:
   10967                 :             : 
   10968                 :             :      {tofrom ptr} firstprivate {to ptr ptr} ...
   10969                 :             :       ^ prev. second group      ^ prev. first group
   10970                 :             : */
   10971                 :             : 
   10972                 :             : static tree *
   10973                 :        7066 : omp_reorder_mapping_groups (vec<omp_mapping_group> *groups,
   10974                 :             :                             omp_mapping_group *head,
   10975                 :             :                             tree *list_p)
   10976                 :             : {
   10977                 :        7066 :   omp_mapping_group *grp;
   10978                 :        7066 :   unsigned int i;
   10979                 :        7066 :   unsigned numgroups = groups->length ();
   10980                 :        7066 :   auto_vec<tree> old_heads (numgroups);
   10981                 :        7066 :   auto_vec<tree *> old_headps (numgroups);
   10982                 :        7066 :   auto_vec<tree> new_heads (numgroups);
   10983                 :        7066 :   auto_vec<tree> old_succs (numgroups);
   10984                 :        7066 :   bool map_at_start = (list_p == (*groups)[0].grp_start);
   10985                 :             : 
   10986                 :        7066 :   tree *new_grp_tail = NULL;
   10987                 :             : 
   10988                 :             :   /* Stash the start & end nodes of each mapping group before we start
   10989                 :             :      modifying the list.  */
   10990                 :       20989 :   FOR_EACH_VEC_ELT (*groups, i, grp)
   10991                 :             :     {
   10992                 :       13923 :       old_headps.quick_push (grp->grp_start);
   10993                 :       13923 :       old_heads.quick_push (*grp->grp_start);
   10994                 :       13923 :       old_succs.quick_push (OMP_CLAUSE_CHAIN (grp->grp_end));
   10995                 :             :     }
   10996                 :             : 
   10997                 :             :   /* And similarly, the heads of the groups in the order we want to rearrange
   10998                 :             :      the list to.  */
   10999                 :       20989 :   for (omp_mapping_group *w = head; w; w = w->next)
   11000                 :       13923 :     new_heads.quick_push (*w->grp_start);
   11001                 :             : 
   11002                 :       20989 :   FOR_EACH_VEC_ELT (*groups, i, grp)
   11003                 :             :     {
   11004                 :       13923 :       gcc_assert (head);
   11005                 :             : 
   11006                 :       13923 :       if (new_grp_tail && old_succs[i - 1] == old_heads[i])
   11007                 :             :         {
   11008                 :             :           /* a {b c d} {e f g} h i j   (original)
   11009                 :             :              -->
   11010                 :             :              a {k l m} {e f g} h i j   (inserted new group on last iter)
   11011                 :             :              -->
   11012                 :             :              a {k l m} {n o p} h i j   (this time, chain last group to new one)
   11013                 :             :                       ^new_grp_tail
   11014                 :             :           */
   11015                 :        6235 :           *new_grp_tail = new_heads[i];
   11016                 :             :         }
   11017                 :        7688 :       else if (new_grp_tail)
   11018                 :             :         {
   11019                 :             :           /* a {b c d} e {f g h} i j k   (original)
   11020                 :             :              -->
   11021                 :             :              a {l m n} e {f g h} i j k   (gap after last iter's group)
   11022                 :             :              -->
   11023                 :             :              a {l m n} e {o p q} h i j   (chain last group to old successor)
   11024                 :             :                       ^new_grp_tail
   11025                 :             :            */
   11026                 :         622 :           *new_grp_tail = old_succs[i - 1];
   11027                 :         622 :           *old_headps[i] = new_heads[i];
   11028                 :             :         }
   11029                 :             :       else
   11030                 :             :         {
   11031                 :             :           /* The first inserted group -- point to new group, and leave end
   11032                 :             :              open.
   11033                 :             :              a {b c d} e f
   11034                 :             :              -->
   11035                 :             :              a {g h i...
   11036                 :             :           */
   11037                 :        7066 :           *grp->grp_start = new_heads[i];
   11038                 :             :         }
   11039                 :             : 
   11040                 :       13923 :       new_grp_tail = &OMP_CLAUSE_CHAIN (head->grp_end);
   11041                 :             : 
   11042                 :       13923 :       head = head->next;
   11043                 :             :     }
   11044                 :             : 
   11045                 :        7066 :   if (new_grp_tail)
   11046                 :        7066 :     *new_grp_tail = old_succs[numgroups - 1];
   11047                 :             : 
   11048                 :        7066 :   gcc_assert (!head);
   11049                 :             : 
   11050                 :        9998 :   return map_at_start ? (*groups)[0].grp_start : list_p;
   11051                 :        7066 : }
   11052                 :             : 
   11053                 :             : /* DECL is supposed to have lastprivate semantics in the outer contexts
   11054                 :             :    of combined/composite constructs, starting with OCTX.
   11055                 :             :    Add needed lastprivate, shared or map clause if no data sharing or
   11056                 :             :    mapping clause are present.  IMPLICIT_P is true if it is an implicit
   11057                 :             :    clause (IV on simd), in which case the lastprivate will not be
   11058                 :             :    copied to some constructs.  */
   11059                 :             : 
   11060                 :             : static void
   11061                 :       14648 : omp_lastprivate_for_combined_outer_constructs (struct gimplify_omp_ctx *octx,
   11062                 :             :                                                tree decl, bool implicit_p)
   11063                 :             : {
   11064                 :       14648 :   struct gimplify_omp_ctx *orig_octx = octx;
   11065                 :       26964 :   for (; octx; octx = octx->outer_context)
   11066                 :             :     {
   11067                 :       25894 :       if ((octx->region_type == ORT_COMBINED_PARALLEL
   11068                 :       20862 :            || (octx->region_type & ORT_COMBINED_TEAMS) == ORT_COMBINED_TEAMS)
   11069                 :       25325 :           && splay_tree_lookup (octx->variables,
   11070                 :             :                                 (splay_tree_key) decl) == NULL)
   11071                 :             :         {
   11072                 :        3883 :           omp_add_variable (octx, decl, GOVD_SHARED | GOVD_SEEN);
   11073                 :        3883 :           continue;
   11074                 :             :         }
   11075                 :       18376 :       if ((octx->region_type & ORT_TASK) != 0
   11076                 :         575 :           && octx->combined_loop
   11077                 :       18657 :           && splay_tree_lookup (octx->variables,
   11078                 :             :                                 (splay_tree_key) decl) == NULL)
   11079                 :             :         {
   11080                 :         248 :           omp_add_variable (octx, decl, GOVD_LASTPRIVATE | GOVD_SEEN);
   11081                 :         248 :           continue;
   11082                 :             :         }
   11083                 :       22715 :       if (implicit_p
   11084                 :       13624 :           && octx->region_type == ORT_WORKSHARE
   11085                 :       10404 :           && octx->combined_loop
   11086                 :       10299 :           && splay_tree_lookup (octx->variables,
   11087                 :             :                                 (splay_tree_key) decl) == NULL
   11088                 :       10299 :           && octx->outer_context
   11089                 :        8906 :           && octx->outer_context->region_type == ORT_COMBINED_PARALLEL
   11090                 :       22722 :           && splay_tree_lookup (octx->outer_context->variables,
   11091                 :             :                                 (splay_tree_key) decl) == NULL)
   11092                 :             :         {
   11093                 :        4835 :           octx = octx->outer_context;
   11094                 :        4835 :           omp_add_variable (octx, decl, GOVD_LASTPRIVATE | GOVD_SEEN);
   11095                 :        4835 :           continue;
   11096                 :             :         }
   11097                 :        5567 :       if ((octx->region_type == ORT_WORKSHARE || octx->region_type == ORT_ACC)
   11098                 :        7478 :           && octx->combined_loop
   11099                 :        7291 :           && splay_tree_lookup (octx->variables,
   11100                 :             :                                 (splay_tree_key) decl) == NULL
   11101                 :       19066 :           && !omp_check_private (octx, decl, false))
   11102                 :             :         {
   11103                 :        3350 :           omp_add_variable (octx, decl, GOVD_LASTPRIVATE | GOVD_SEEN);
   11104                 :        3350 :           continue;
   11105                 :             :         }
   11106                 :        9695 :       if (octx->region_type == ORT_COMBINED_TARGET)
   11107                 :             :         {
   11108                 :        2004 :           splay_tree_node n = splay_tree_lookup (octx->variables,
   11109                 :             :                                                  (splay_tree_key) decl);
   11110                 :        2004 :           if (n == NULL)
   11111                 :             :             {
   11112                 :        1982 :               omp_add_variable (octx, decl, GOVD_MAP | GOVD_SEEN);
   11113                 :        1982 :               octx = octx->outer_context;
   11114                 :             :             }
   11115                 :          22 :           else if (!implicit_p
   11116                 :          22 :                    && (n->value & GOVD_FIRSTPRIVATE_IMPLICIT))
   11117                 :             :             {
   11118                 :          12 :               n->value &= ~(GOVD_FIRSTPRIVATE
   11119                 :             :                             | GOVD_FIRSTPRIVATE_IMPLICIT
   11120                 :             :                             | GOVD_EXPLICIT);
   11121                 :          12 :               omp_add_variable (octx, decl, GOVD_MAP | GOVD_SEEN);
   11122                 :          12 :               octx = octx->outer_context;
   11123                 :             :             }
   11124                 :             :         }
   11125                 :             :       break;
   11126                 :             :     }
   11127                 :       14648 :   if (octx && (implicit_p || octx != orig_octx))
   11128                 :        4056 :     omp_notice_variable (octx, decl, true);
   11129                 :       14648 : }
   11130                 :             : 
   11131                 :             : /* We might have indexed several groups for DECL, e.g. a "TO" mapping and also
   11132                 :             :    a "FIRSTPRIVATE" mapping.  Return the one that isn't firstprivate, etc.  */
   11133                 :             : 
   11134                 :             : static omp_mapping_group *
   11135                 :        4896 : omp_get_nonfirstprivate_group (hash_map<tree_operand_hash_no_se,
   11136                 :             :                                         omp_mapping_group *> *grpmap,
   11137                 :             :                                tree decl, bool allow_deleted = false)
   11138                 :             : {
   11139                 :        4896 :   omp_mapping_group **to_group_p = grpmap->get (decl);
   11140                 :             : 
   11141                 :        4896 :   if (!to_group_p)
   11142                 :             :     return NULL;
   11143                 :             : 
   11144                 :        2070 :   omp_mapping_group *to_group = *to_group_p;
   11145                 :             : 
   11146                 :        3204 :   for (; to_group; to_group = to_group->sibling)
   11147                 :             :     {
   11148                 :        2107 :       tree grp_end = to_group->grp_end;
   11149                 :        2107 :       switch (OMP_CLAUSE_MAP_KIND (grp_end))
   11150                 :             :         {
   11151                 :             :         case GOMP_MAP_FIRSTPRIVATE_POINTER:
   11152                 :             :         case GOMP_MAP_FIRSTPRIVATE_REFERENCE:
   11153                 :             :           break;
   11154                 :             : 
   11155                 :         975 :         default:
   11156                 :         975 :           if (allow_deleted || !to_group->deleted)
   11157                 :             :             return to_group;
   11158                 :             :         }
   11159                 :             :     }
   11160                 :             : 
   11161                 :             :   return NULL;
   11162                 :             : }
   11163                 :             : 
   11164                 :             : /* Return TRUE if the directive (whose clauses are described by the hash table
   11165                 :             :    of mapping groups, GRPMAP) maps DECL explicitly.  If TO_SPECIFICALLY is
   11166                 :             :    true, only count TO mappings.  If ALLOW_DELETED is true, ignore the
   11167                 :             :    "deleted" flag for groups.  If CONTAINED_IN_STRUCT is true, also return
   11168                 :             :    TRUE if DECL is mapped as a member of a whole-struct mapping.  */
   11169                 :             : 
   11170                 :             : static bool
   11171                 :        3597 : omp_directive_maps_explicitly (hash_map<tree_operand_hash_no_se,
   11172                 :             :                                         omp_mapping_group *> *grpmap,
   11173                 :             :                                tree decl, omp_mapping_group **base_group,
   11174                 :             :                                bool to_specifically, bool allow_deleted,
   11175                 :             :                                bool contained_in_struct)
   11176                 :             : {
   11177                 :        3597 :   omp_mapping_group *decl_group
   11178                 :        3597 :     = omp_get_nonfirstprivate_group (grpmap, decl, allow_deleted);
   11179                 :             : 
   11180                 :        3597 :   *base_group = NULL;
   11181                 :             : 
   11182                 :        3597 :   if (decl_group)
   11183                 :             :     {
   11184                 :         871 :       tree grp_first = *decl_group->grp_start;
   11185                 :             :       /* We might be called during omp_build_struct_sibling_lists, when
   11186                 :             :          GOMP_MAP_STRUCT might have been inserted at the start of the group.
   11187                 :             :          Skip over that, and also possibly the node after it.  */
   11188                 :         871 :       if (OMP_CLAUSE_MAP_KIND (grp_first) == GOMP_MAP_STRUCT
   11189                 :         871 :           || OMP_CLAUSE_MAP_KIND (grp_first) == GOMP_MAP_STRUCT_UNORD)
   11190                 :             :         {
   11191                 :           6 :           grp_first = OMP_CLAUSE_CHAIN (grp_first);
   11192                 :           6 :           if (OMP_CLAUSE_MAP_KIND (grp_first) == GOMP_MAP_FIRSTPRIVATE_POINTER
   11193                 :           6 :               || (OMP_CLAUSE_MAP_KIND (grp_first)
   11194                 :             :                   == GOMP_MAP_FIRSTPRIVATE_REFERENCE)
   11195                 :          12 :               || OMP_CLAUSE_MAP_KIND (grp_first) == GOMP_MAP_ATTACH_DETACH)
   11196                 :           0 :             grp_first = OMP_CLAUSE_CHAIN (grp_first);
   11197                 :             :         }
   11198                 :         871 :       enum gomp_map_kind first_kind = OMP_CLAUSE_MAP_KIND (grp_first);
   11199                 :         871 :       if (!to_specifically
   11200                 :         495 :           || GOMP_MAP_COPY_TO_P (first_kind)
   11201                 :         307 :           || first_kind == GOMP_MAP_ALLOC)
   11202                 :             :         {
   11203                 :         831 :           *base_group = decl_group;
   11204                 :         831 :           return true;
   11205                 :             :         }
   11206                 :             :     }
   11207                 :             : 
   11208                 :        2766 :   if (contained_in_struct
   11209                 :        2766 :       && omp_mapped_by_containing_struct (grpmap, decl, base_group))
   11210                 :             :     return true;
   11211                 :             : 
   11212                 :             :   return false;
   11213                 :             : }
   11214                 :             : 
   11215                 :             : /* If we have mappings INNER and OUTER, where INNER is a component access and
   11216                 :             :    OUTER is a mapping of the whole containing struct, check that the mappings
   11217                 :             :    are compatible.  We'll be deleting the inner mapping, so we need to make
   11218                 :             :    sure the outer mapping does (at least) the same transfers to/from the device
   11219                 :             :    as the inner mapping.  */
   11220                 :             : 
   11221                 :             : bool
   11222                 :         169 : omp_check_mapping_compatibility (location_t loc,
   11223                 :             :                                  omp_mapping_group *outer,
   11224                 :             :                                  omp_mapping_group *inner)
   11225                 :             : {
   11226                 :         169 :   tree first_outer = *outer->grp_start, first_inner = *inner->grp_start;
   11227                 :             : 
   11228                 :         169 :   gcc_assert (OMP_CLAUSE_CODE (first_outer) == OMP_CLAUSE_MAP);
   11229                 :         169 :   gcc_assert (OMP_CLAUSE_CODE (first_inner) == OMP_CLAUSE_MAP);
   11230                 :             : 
   11231                 :         169 :   enum gomp_map_kind outer_kind = OMP_CLAUSE_MAP_KIND (first_outer);
   11232                 :         169 :   enum gomp_map_kind inner_kind = OMP_CLAUSE_MAP_KIND (first_inner);
   11233                 :             : 
   11234                 :         169 :   if (outer_kind == inner_kind)
   11235                 :             :     return true;
   11236                 :             : 
   11237                 :          67 :   switch (outer_kind)
   11238                 :             :     {
   11239                 :           0 :     case GOMP_MAP_ALWAYS_TO:
   11240                 :           0 :       if (inner_kind == GOMP_MAP_FORCE_PRESENT
   11241                 :           0 :           || inner_kind == GOMP_MAP_ALLOC
   11242                 :           0 :           || inner_kind == GOMP_MAP_TO)
   11243                 :             :         return true;
   11244                 :             :       break;
   11245                 :             : 
   11246                 :           0 :     case GOMP_MAP_ALWAYS_FROM:
   11247                 :           0 :       if (inner_kind == GOMP_MAP_FORCE_PRESENT
   11248                 :           0 :           || inner_kind == GOMP_MAP_RELEASE
   11249                 :             :           || inner_kind == GOMP_MAP_FROM)
   11250                 :             :         return true;
   11251                 :             :       break;
   11252                 :             : 
   11253                 :          10 :     case GOMP_MAP_TO:
   11254                 :          10 :       if (inner_kind == GOMP_MAP_FORCE_PRESENT
   11255                 :          10 :           || inner_kind == GOMP_MAP_ALLOC)
   11256                 :             :         return true;
   11257                 :             :       break;
   11258                 :             : 
   11259                 :           8 :     case GOMP_MAP_FROM:
   11260                 :           8 :       if (inner_kind == GOMP_MAP_RELEASE
   11261                 :           8 :           || inner_kind == GOMP_MAP_FORCE_PRESENT)
   11262                 :             :         return true;
   11263                 :             :       break;
   11264                 :             : 
   11265                 :          29 :     case GOMP_MAP_ALWAYS_TOFROM:
   11266                 :          29 :     case GOMP_MAP_TOFROM:
   11267                 :          29 :       if (inner_kind == GOMP_MAP_FORCE_PRESENT
   11268                 :          29 :           || inner_kind == GOMP_MAP_ALLOC
   11269                 :             :           || inner_kind == GOMP_MAP_TO
   11270                 :          21 :           || inner_kind == GOMP_MAP_FROM
   11271                 :          12 :           || inner_kind == GOMP_MAP_TOFROM)
   11272                 :             :         return true;
   11273                 :             :       break;
   11274                 :             : 
   11275                 :          28 :     default:
   11276                 :          28 :       ;
   11277                 :             :     }
   11278                 :             : 
   11279                 :          84 :   error_at (loc, "data movement for component %qE is not compatible with "
   11280                 :          28 :             "movement for struct %qE", OMP_CLAUSE_DECL (first_inner),
   11281                 :          28 :             OMP_CLAUSE_DECL (first_outer));
   11282                 :             : 
   11283                 :          28 :   return false;
   11284                 :             : }
   11285                 :             : 
   11286                 :             : /* This function handles several cases where clauses on a mapping directive
   11287                 :             :    can interact with each other.
   11288                 :             : 
   11289                 :             :    If we have a FIRSTPRIVATE_POINTER node and we're also mapping the pointer
   11290                 :             :    on the same directive, change the mapping of the first node to
   11291                 :             :    ATTACH_DETACH.  We should have detected that this will happen already in
   11292                 :             :    c-omp.cc:c_omp_adjust_map_clauses and marked the appropriate decl
   11293                 :             :    as addressable.  (If we didn't, bail out.)
   11294                 :             : 
   11295                 :             :    If we have a FIRSTPRIVATE_REFERENCE (for a reference to pointer) and we're
   11296                 :             :    mapping the base pointer also, we may need to change the mapping type to
   11297                 :             :    ATTACH_DETACH and synthesize an alloc node for the reference itself.
   11298                 :             : 
   11299                 :             :    If we have an ATTACH_DETACH node, this is an array section with a pointer
   11300                 :             :    base.  If we're mapping the base on the same directive too, we can drop its
   11301                 :             :    mapping.  However, if we have a reference to pointer, make other appropriate
   11302                 :             :    adjustments to the mapping nodes instead.
   11303                 :             : 
   11304                 :             :    If we have an ATTACH_DETACH node with a Fortran pointer-set (array
   11305                 :             :    descriptor) mapping for a derived-type component, and we're also mapping the
   11306                 :             :    whole of the derived-type variable on another clause, the pointer-set
   11307                 :             :    mapping is removed.
   11308                 :             : 
   11309                 :             :    If we have a component access but we're also mapping the whole of the
   11310                 :             :    containing struct, drop the former access.
   11311                 :             : 
   11312                 :             :    If the expression is a component access, and we're also mapping a base
   11313                 :             :    pointer used in that component access in the same expression, change the
   11314                 :             :    mapping type of the latter to ALLOC (ready for processing by
   11315                 :             :    omp_build_struct_sibling_lists).  */
   11316                 :             : 
   11317                 :             : void
   11318                 :        7066 : omp_resolve_clause_dependencies (enum tree_code code,
   11319                 :             :                                  vec<omp_mapping_group> *groups,
   11320                 :             :                                  hash_map<tree_operand_hash_no_se,
   11321                 :             :                                           omp_mapping_group *> *grpmap)
   11322                 :             : {
   11323                 :        7066 :   int i;
   11324                 :        7066 :   omp_mapping_group *grp;
   11325                 :        7066 :   bool repair_chain = false;
   11326                 :             : 
   11327                 :       20144 :   FOR_EACH_VEC_ELT (*groups, i, grp)
   11328                 :             :     {
   11329                 :       13078 :       tree grp_end = grp->grp_end;
   11330                 :       13078 :       tree decl = OMP_CLAUSE_DECL (grp_end);
   11331                 :             : 
   11332                 :       13078 :       gcc_assert (OMP_CLAUSE_CODE (grp_end) == OMP_CLAUSE_MAP);
   11333                 :             : 
   11334                 :       13078 :       switch (OMP_CLAUSE_MAP_KIND (grp_end))
   11335                 :             :         {
   11336                 :        1026 :         case GOMP_MAP_FIRSTPRIVATE_POINTER:
   11337                 :        1026 :           {
   11338                 :        1026 :             omp_mapping_group *to_group
   11339                 :        1026 :               = omp_get_nonfirstprivate_group (grpmap, decl);
   11340                 :             : 
   11341                 :        1026 :             if (!to_group || to_group == grp)
   11342                 :        1001 :               continue;
   11343                 :             : 
   11344                 :          25 :             tree grp_first = *to_group->grp_start;
   11345                 :          25 :             enum gomp_map_kind first_kind = OMP_CLAUSE_MAP_KIND (grp_first);
   11346                 :             : 
   11347                 :          25 :             if ((GOMP_MAP_COPY_TO_P (first_kind)
   11348                 :           7 :                  || first_kind == GOMP_MAP_ALLOC)
   11349                 :          50 :                 && (OMP_CLAUSE_MAP_KIND (to_group->grp_end)
   11350                 :             :                     != GOMP_MAP_FIRSTPRIVATE_POINTER))
   11351                 :             :               {
   11352                 :          25 :                 gcc_assert (TREE_ADDRESSABLE (OMP_CLAUSE_DECL (grp_end)));
   11353                 :          25 :                 OMP_CLAUSE_SET_MAP_KIND (grp_end, GOMP_MAP_ATTACH_DETACH);
   11354                 :             :               }
   11355                 :             :           }
   11356                 :             :           break;
   11357                 :             : 
   11358                 :         132 :         case GOMP_MAP_FIRSTPRIVATE_REFERENCE:
   11359                 :         132 :           {
   11360                 :         132 :             tree ptr = build_fold_indirect_ref (decl);
   11361                 :             : 
   11362                 :         132 :             omp_mapping_group *to_group
   11363                 :         132 :               = omp_get_nonfirstprivate_group (grpmap, ptr);
   11364                 :             : 
   11365                 :         132 :             if (!to_group || to_group == grp)
   11366                 :         128 :               continue;
   11367                 :             : 
   11368                 :           4 :             tree grp_first = *to_group->grp_start;
   11369                 :           4 :             enum gomp_map_kind first_kind = OMP_CLAUSE_MAP_KIND (grp_first);
   11370                 :             : 
   11371                 :           4 :             if (GOMP_MAP_COPY_TO_P (first_kind)
   11372                 :           4 :                 || first_kind == GOMP_MAP_ALLOC)
   11373                 :             :               {
   11374                 :           4 :                 OMP_CLAUSE_SET_MAP_KIND (grp_end, GOMP_MAP_ATTACH_DETACH);
   11375                 :           4 :                 OMP_CLAUSE_DECL (grp_end) = ptr;
   11376                 :           4 :                 if ((OMP_CLAUSE_CHAIN (*to_group->grp_start)
   11377                 :           4 :                      == to_group->grp_end)
   11378                 :           4 :                     && (OMP_CLAUSE_MAP_KIND (to_group->grp_end)
   11379                 :             :                         == GOMP_MAP_FIRSTPRIVATE_REFERENCE))
   11380                 :             :                   {
   11381                 :           0 :                     gcc_assert (TREE_ADDRESSABLE
   11382                 :             :                                   (OMP_CLAUSE_DECL (to_group->grp_end)));
   11383                 :           0 :                     OMP_CLAUSE_SET_MAP_KIND (to_group->grp_end,
   11384                 :             :                                              GOMP_MAP_ATTACH_DETACH);
   11385                 :             : 
   11386                 :           0 :                     location_t loc = OMP_CLAUSE_LOCATION (to_group->grp_end);
   11387                 :           0 :                     tree alloc
   11388                 :           0 :                       = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11389                 :           0 :                     OMP_CLAUSE_SET_MAP_KIND (alloc, GOMP_MAP_ALLOC);
   11390                 :           0 :                     tree tmp = build_fold_addr_expr (OMP_CLAUSE_DECL
   11391                 :             :                                                       (to_group->grp_end));
   11392                 :           0 :                     tree char_ptr_type = build_pointer_type (char_type_node);
   11393                 :           0 :                     OMP_CLAUSE_DECL (alloc)
   11394                 :           0 :                       = build2 (MEM_REF, char_type_node,
   11395                 :             :                                 tmp,
   11396                 :           0 :                                 build_int_cst (char_ptr_type, 0));
   11397                 :           0 :                     OMP_CLAUSE_SIZE (alloc) = TYPE_SIZE_UNIT (TREE_TYPE (tmp));
   11398                 :             : 
   11399                 :           0 :                     OMP_CLAUSE_CHAIN (alloc)
   11400                 :           0 :                       = OMP_CLAUSE_CHAIN (*to_group->grp_start);
   11401                 :           0 :                     OMP_CLAUSE_CHAIN (*to_group->grp_start) = alloc;
   11402                 :             :                   }
   11403                 :             :               }
   11404                 :             :           }
   11405                 :             :           break;
   11406                 :             : 
   11407                 :             :         case GOMP_MAP_ATTACH_DETACH:
   11408                 :             :         case GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION:
   11409                 :             :           {
   11410                 :        1862 :             tree base_ptr, referenced_ptr_node = NULL_TREE;
   11411                 :             : 
   11412                 :        1862 :             while (TREE_CODE (decl) == ARRAY_REF)
   11413                 :           0 :               decl = TREE_OPERAND (decl, 0);
   11414                 :             : 
   11415                 :        1862 :             if (TREE_CODE (decl) == INDIRECT_REF)
   11416                 :          13 :               decl = TREE_OPERAND (decl, 0);
   11417                 :             : 
   11418                 :             :             /* Only component accesses.  */
   11419                 :        1862 :             if (DECL_P (decl))
   11420                 :         191 :               continue;
   11421                 :             : 
   11422                 :             :             /* We want the pointer itself when checking if the base pointer is
   11423                 :             :                mapped elsewhere in the same directive -- if we have a
   11424                 :             :                reference to the pointer, don't use that.  */
   11425                 :             : 
   11426                 :        1671 :             if (TREE_CODE (TREE_TYPE (decl)) == REFERENCE_TYPE
   11427                 :        1671 :                 && TREE_CODE (TREE_TYPE (TREE_TYPE (decl))) == POINTER_TYPE)
   11428                 :             :               {
   11429                 :         394 :                 referenced_ptr_node = OMP_CLAUSE_CHAIN (*grp->grp_start);
   11430                 :         394 :                 base_ptr = OMP_CLAUSE_DECL (referenced_ptr_node);
   11431                 :             :               }
   11432                 :             :             else
   11433                 :             :               base_ptr = decl;
   11434                 :             : 
   11435                 :        3342 :             gomp_map_kind zlas_kind
   11436                 :        1671 :               = (code == OACC_EXIT_DATA || code == OMP_TARGET_EXIT_DATA)
   11437                 :        1671 :                 ? GOMP_MAP_DETACH : GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION;
   11438                 :             : 
   11439                 :        1671 :             if (TREE_CODE (TREE_TYPE (base_ptr)) == POINTER_TYPE)
   11440                 :             :               {
   11441                 :             :                 /* If we map the base TO, and we're doing an attachment, we can
   11442                 :             :                    skip the TO mapping altogether and create an ALLOC mapping
   11443                 :             :                    instead, since the attachment will overwrite the device
   11444                 :             :                    pointer in that location immediately anyway.  Otherwise,
   11445                 :             :                    change our mapping to
   11446                 :             :                    GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION in case the
   11447                 :             :                    attachment target has not been copied to the device already
   11448                 :             :                    by some earlier directive.  */
   11449                 :             : 
   11450                 :        1247 :                 bool base_mapped_to = false;
   11451                 :             : 
   11452                 :        1247 :                 omp_mapping_group *base_group;
   11453                 :             : 
   11454                 :        1247 :                 if (omp_directive_maps_explicitly (grpmap, base_ptr,
   11455                 :             :                                                    &base_group, false, true,
   11456                 :             :                                                    false))
   11457                 :             :                   {
   11458                 :         376 :                     if (referenced_ptr_node)
   11459                 :             :                       {
   11460                 :         129 :                         base_mapped_to = true;
   11461                 :         129 :                         if ((OMP_CLAUSE_MAP_KIND (base_group->grp_end)
   11462                 :             :                              == GOMP_MAP_ATTACH_DETACH)
   11463                 :         129 :                             && (OMP_CLAUSE_CHAIN (*base_group->grp_start)
   11464                 :             :                                 == base_group->grp_end))
   11465                 :             :                           {
   11466                 :         129 :                             OMP_CLAUSE_CHAIN (*base_group->grp_start)
   11467                 :         129 :                               = OMP_CLAUSE_CHAIN (base_group->grp_end);
   11468                 :         129 :                             base_group->grp_end = *base_group->grp_start;
   11469                 :         129 :                             repair_chain = true;
   11470                 :             :                           }
   11471                 :             :                       }
   11472                 :             :                     else
   11473                 :             :                       {
   11474                 :         247 :                         base_group->deleted = true;
   11475                 :         247 :                         OMP_CLAUSE_ATTACHMENT_MAPPING_ERASED (grp_end) = 1;
   11476                 :             :                       }
   11477                 :             :                   }
   11478                 :             : 
   11479                 :             :                 /* We're dealing with a reference to a pointer, and we are
   11480                 :             :                    attaching both the reference and the pointer.  We know the
   11481                 :             :                    reference itself is on the target, because we are going to
   11482                 :             :                    create an ALLOC node for it in accumulate_sibling_list.  The
   11483                 :             :                    pointer might be on the target already or it might not, but
   11484                 :             :                    if it isn't then it's not an error, so use
   11485                 :             :                    GOMP_MAP_ATTACH_ZLAS for it.  */
   11486                 :        1247 :                 if (!base_mapped_to && referenced_ptr_node)
   11487                 :          56 :                   OMP_CLAUSE_SET_MAP_KIND (referenced_ptr_node, zlas_kind);
   11488                 :             : 
   11489                 :        1247 :                 omp_mapping_group *struct_group;
   11490                 :        1247 :                 tree desc;
   11491                 :        1247 :                 if ((desc = OMP_CLAUSE_CHAIN (*grp->grp_start))
   11492                 :        1247 :                     && omp_map_clause_descriptor_p (desc)
   11493                 :        1806 :                     && omp_mapped_by_containing_struct (grpmap, decl,
   11494                 :             :                                                         &struct_group))
   11495                 :             :                   /* If we have a pointer set but we're mapping (or unmapping)
   11496                 :             :                      the whole of the containing struct, we can remove the
   11497                 :             :                      pointer set mapping.  */
   11498                 :          15 :                   OMP_CLAUSE_CHAIN (*grp->grp_start) = OMP_CLAUSE_CHAIN (desc);
   11499                 :             :               }
   11500                 :         424 :             else if (TREE_CODE (TREE_TYPE (base_ptr)) == REFERENCE_TYPE
   11501                 :         424 :                      && (TREE_CODE (TREE_TYPE (TREE_TYPE (base_ptr)))
   11502                 :             :                          == ARRAY_TYPE)
   11503                 :         562 :                      && OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION
   11504                 :             :                           (*grp->grp_start))
   11505                 :          92 :               OMP_CLAUSE_SET_MAP_KIND (grp->grp_end, zlas_kind);
   11506                 :             :           }
   11507                 :             :           break;
   11508                 :             : 
   11509                 :             :         case GOMP_MAP_ATTACH:
   11510                 :             :           /* Ignore standalone attach here.  */
   11511                 :             :           break;
   11512                 :             : 
   11513                 :       10023 :         default:
   11514                 :       10023 :           {
   11515                 :       10023 :             omp_mapping_group *struct_group;
   11516                 :       10023 :             if (omp_mapped_by_containing_struct (grpmap, decl, &struct_group)
   11517                 :       10023 :                 && *grp->grp_start == grp_end)
   11518                 :             :               {
   11519                 :          91 :                 omp_check_mapping_compatibility (OMP_CLAUSE_LOCATION (grp_end),
   11520                 :             :                                                  struct_group, grp);
   11521                 :             :                 /* Remove the whole of this mapping -- redundant.  */
   11522                 :          91 :                 grp->deleted = true;
   11523                 :             :               }
   11524                 :             : 
   11525                 :             :             tree base = decl;
   11526                 :       11533 :             while ((base = omp_get_base_pointer (base)))
   11527                 :             :               {
   11528                 :        1510 :                 omp_mapping_group *base_group;
   11529                 :             : 
   11530                 :        1510 :                 if (omp_directive_maps_explicitly (grpmap, base, &base_group,
   11531                 :             :                                                    true, true, false))
   11532                 :             :                   {
   11533                 :         309 :                     tree grp_first = *base_group->grp_start;
   11534                 :         309 :                     OMP_CLAUSE_SET_MAP_KIND (grp_first, GOMP_MAP_ALLOC);
   11535                 :             :                   }
   11536                 :             :               }
   11537                 :             :           }
   11538                 :             :         }
   11539                 :             :     }
   11540                 :             : 
   11541                 :        7066 :   if (repair_chain)
   11542                 :             :     {
   11543                 :             :       /* Group start pointers may have become detached from the
   11544                 :             :          OMP_CLAUSE_CHAIN of previous groups if elements were removed from the
   11545                 :             :          end of those groups.  Fix that now.  */
   11546                 :             :       tree *new_next = NULL;
   11547                 :         716 :       FOR_EACH_VEC_ELT (*groups, i, grp)
   11548                 :             :         {
   11549                 :         587 :           if (new_next)
   11550                 :         458 :             grp->grp_start = new_next;
   11551                 :             : 
   11552                 :         587 :           new_next = &OMP_CLAUSE_CHAIN (grp->grp_end);
   11553                 :             :         }
   11554                 :             :     }
   11555                 :        7066 : }
   11556                 :             : 
   11557                 :             : /* Similar to omp_resolve_clause_dependencies, but for OpenACC.  The only
   11558                 :             :    clause dependencies we handle for now are struct element mappings and
   11559                 :             :    whole-struct mappings on the same directive, and duplicate clause
   11560                 :             :    detection.  */
   11561                 :             : 
   11562                 :             : void
   11563                 :        9405 : oacc_resolve_clause_dependencies (vec<omp_mapping_group> *groups,
   11564                 :             :                                   hash_map<tree_operand_hash_no_se,
   11565                 :             :                                            omp_mapping_group *> *grpmap)
   11566                 :             : {
   11567                 :        9405 :   int i;
   11568                 :        9405 :   omp_mapping_group *grp;
   11569                 :        9405 :   hash_set<tree_operand_hash> *seen_components = NULL;
   11570                 :        9405 :   hash_set<tree_operand_hash> *shown_error = NULL;
   11571                 :             : 
   11572                 :       24462 :   FOR_EACH_VEC_ELT (*groups, i, grp)
   11573                 :             :     {
   11574                 :       15057 :       tree grp_end = grp->grp_end;
   11575                 :       15057 :       tree decl = OMP_CLAUSE_DECL (grp_end);
   11576                 :             : 
   11577                 :       15057 :       gcc_assert (OMP_CLAUSE_CODE (grp_end) == OMP_CLAUSE_MAP);
   11578                 :             : 
   11579                 :       15057 :       if (DECL_P (grp_end))
   11580                 :       14535 :         continue;
   11581                 :             : 
   11582                 :       15057 :       tree c = OMP_CLAUSE_DECL (*grp->grp_start);
   11583                 :       16682 :       while (TREE_CODE (c) == ARRAY_REF)
   11584                 :        1625 :         c = TREE_OPERAND (c, 0);
   11585                 :       15057 :       if (TREE_CODE (c) != COMPONENT_REF)
   11586                 :       14535 :         continue;
   11587                 :         522 :       if (!seen_components)
   11588                 :         479 :         seen_components = new hash_set<tree_operand_hash> ();
   11589                 :         522 :       if (!shown_error)
   11590                 :         479 :         shown_error = new hash_set<tree_operand_hash> ();
   11591                 :         522 :       if (seen_components->contains (c)
   11592                 :         522 :           && !shown_error->contains (c))
   11593                 :             :         {
   11594                 :          10 :           error_at (OMP_CLAUSE_LOCATION (grp_end),
   11595                 :             :                     "%qE appears more than once in map clauses",
   11596                 :           5 :                     OMP_CLAUSE_DECL (grp_end));
   11597                 :           5 :           shown_error->add (c);
   11598                 :             :         }
   11599                 :             :       else
   11600                 :         517 :         seen_components->add (c);
   11601                 :             : 
   11602                 :         522 :       omp_mapping_group *struct_group;
   11603                 :         522 :       if (omp_mapped_by_containing_struct (grpmap, decl, &struct_group)
   11604                 :         522 :           && *grp->grp_start == grp_end)
   11605                 :             :         {
   11606                 :          78 :           omp_check_mapping_compatibility (OMP_CLAUSE_LOCATION (grp_end),
   11607                 :             :                                            struct_group, grp);
   11608                 :             :           /* Remove the whole of this mapping -- redundant.  */
   11609                 :          78 :           grp->deleted = true;
   11610                 :             :         }
   11611                 :             :     }
   11612                 :             : 
   11613                 :        9405 :   if (seen_components)
   11614                 :         479 :     delete seen_components;
   11615                 :        9405 :   if (shown_error)
   11616                 :         479 :     delete shown_error;
   11617                 :        9405 : }
   11618                 :             : 
   11619                 :             : /* Link node NEWNODE so it is pointed to by chain INSERT_AT.  NEWNODE's chain
   11620                 :             :    is linked to the previous node pointed to by INSERT_AT.  */
   11621                 :             : 
   11622                 :             : static tree *
   11623                 :        1009 : omp_siblist_insert_node_after (tree newnode, tree *insert_at)
   11624                 :             : {
   11625                 :        1009 :   OMP_CLAUSE_CHAIN (newnode) = *insert_at;
   11626                 :        1009 :   *insert_at = newnode;
   11627                 :        1009 :   return &OMP_CLAUSE_CHAIN (newnode);
   11628                 :             : }
   11629                 :             : 
   11630                 :             : /* Move NODE (which is currently pointed to by the chain OLD_POS) so it is
   11631                 :             :    pointed to by chain MOVE_AFTER instead.  */
   11632                 :             : 
   11633                 :             : static void
   11634                 :         782 : omp_siblist_move_node_after (tree node, tree *old_pos, tree *move_after)
   11635                 :             : {
   11636                 :         782 :   gcc_assert (node == *old_pos);
   11637                 :         782 :   *old_pos = OMP_CLAUSE_CHAIN (node);
   11638                 :         782 :   OMP_CLAUSE_CHAIN (node) = *move_after;
   11639                 :         782 :   *move_after = node;
   11640                 :         782 : }
   11641                 :             : 
   11642                 :             : /* Move nodes from FIRST_PTR (pointed to by previous node's chain) to
   11643                 :             :    LAST_NODE to after MOVE_AFTER chain.  Similar to below function, but no
   11644                 :             :    new nodes are prepended to the list before splicing into the new position.
   11645                 :             :    Return the position we should continue scanning the list at, or NULL to
   11646                 :             :    stay where we were.  */
   11647                 :             : 
   11648                 :             : static tree *
   11649                 :         235 : omp_siblist_move_nodes_after (tree *first_ptr, tree last_node,
   11650                 :             :                               tree *move_after)
   11651                 :             : {
   11652                 :         235 :   if (first_ptr == move_after)
   11653                 :             :     return NULL;
   11654                 :             : 
   11655                 :         224 :   tree tmp = *first_ptr;
   11656                 :         224 :   *first_ptr = OMP_CLAUSE_CHAIN (last_node);
   11657                 :         224 :   OMP_CLAUSE_CHAIN (last_node) = *move_after;
   11658                 :         224 :   *move_after = tmp;
   11659                 :             : 
   11660                 :         224 :   return first_ptr;
   11661                 :             : }
   11662                 :             : 
   11663                 :             : /* Concatenate two lists described by [FIRST_NEW, LAST_NEW_TAIL] and
   11664                 :             :    [FIRST_PTR, LAST_NODE], and insert them in the OMP clause list after chain
   11665                 :             :    pointer MOVE_AFTER.
   11666                 :             : 
   11667                 :             :    The latter list was previously part of the OMP clause list, and the former
   11668                 :             :    (prepended) part is comprised of new nodes.
   11669                 :             : 
   11670                 :             :    We start with a list of nodes starting with a struct mapping node.  We
   11671                 :             :    rearrange the list so that new nodes starting from FIRST_NEW and whose last
   11672                 :             :    node's chain is LAST_NEW_TAIL comes directly after MOVE_AFTER, followed by
   11673                 :             :    the group of mapping nodes we are currently processing (from the chain
   11674                 :             :    FIRST_PTR to LAST_NODE).  The return value is the pointer to the next chain
   11675                 :             :    we should continue processing from, or NULL to stay where we were.
   11676                 :             : 
   11677                 :             :    The transformation (in the case where MOVE_AFTER and FIRST_PTR are
   11678                 :             :    different) is worked through below.  Here we are processing LAST_NODE, and
   11679                 :             :    FIRST_PTR points at the preceding mapping clause:
   11680                 :             : 
   11681                 :             :   #. mapping node               chain
   11682                 :             :   ---------------------------------------------------
   11683                 :             :   A. struct_node                [->B]
   11684                 :             :   B. comp_1                     [->C]
   11685                 :             :   C. comp_2                     [->D (move_after)]
   11686                 :             :   D. map_to_3                   [->E]
   11687                 :             :   E. attach_3                   [->F (first_ptr)]
   11688                 :             :   F. map_to_4                   [->G (continue_at)]
   11689                 :             :   G. attach_4 (last_node)       [->H]
   11690                 :             :   H. ...
   11691                 :             : 
   11692                 :             :      *last_new_tail = *first_ptr;
   11693                 :             : 
   11694                 :             :   I. new_node (first_new)       [->F (last_new_tail)]
   11695                 :             : 
   11696                 :             :      *first_ptr = OMP_CLAUSE_CHAIN (last_node)
   11697                 :             : 
   11698                 :             :   #. mapping node               chain
   11699                 :             :   ----------------------------------------------------
   11700                 :             :   A. struct_node                [->B]
   11701                 :             :   B. comp_1                     [->C]
   11702                 :             :   C. comp_2                     [->D (move_after)]
   11703                 :             :   D. map_to_3                   [->E]
   11704                 :             :   E. attach_3                   [->H (first_ptr)]
   11705                 :             :   F. map_to_4                   [->G (continue_at)]
   11706                 :             :   G. attach_4 (last_node)       [->H]
   11707                 :             :   H. ...
   11708                 :             : 
   11709                 :             :   I. new_node (first_new)       [->F  (last_new_tail)]
   11710                 :             : 
   11711                 :             :      OMP_CLAUSE_CHAIN (last_node) = *move_after;
   11712                 :             : 
   11713                 :             :   #. mapping node               chain
   11714                 :             :   ---------------------------------------------------
   11715                 :             :   A. struct_node                [->B]
   11716                 :             :   B. comp_1                     [->C]
   11717                 :             :   C. comp_2                     [->D (move_after)]
   11718                 :             :   D. map_to_3                   [->E]
   11719                 :             :   E. attach_3                   [->H (continue_at)]
   11720                 :             :   F. map_to_4                   [->G]
   11721                 :             :   G. attach_4 (last_node)       [->D]
   11722                 :             :   H. ...
   11723                 :             : 
   11724                 :             :   I. new_node (first_new)       [->F  (last_new_tail)]
   11725                 :             : 
   11726                 :             :      *move_after = first_new;
   11727                 :             : 
   11728                 :             :   #. mapping node               chain
   11729                 :             :   ---------------------------------------------------
   11730                 :             :   A. struct_node                [->B]
   11731                 :             :   B. comp_1                     [->C]
   11732                 :             :   C. comp_2                     [->I (move_after)]
   11733                 :             :   D. map_to_3                   [->E]
   11734                 :             :   E. attach_3                   [->H (continue_at)]
   11735                 :             :   F. map_to_4                   [->G]
   11736                 :             :   G. attach_4 (last_node)       [->D]
   11737                 :             :   H. ...
   11738                 :             :   I. new_node (first_new)       [->F (last_new_tail)]
   11739                 :             : 
   11740                 :             :   or, in order:
   11741                 :             : 
   11742                 :             :   #. mapping node               chain
   11743                 :             :   ---------------------------------------------------
   11744                 :             :   A. struct_node                [->B]
   11745                 :             :   B. comp_1                     [->C]
   11746                 :             :   C. comp_2                     [->I (move_after)]
   11747                 :             :   I. new_node (first_new)       [->F (last_new_tail)]
   11748                 :             :   F. map_to_4                   [->G]
   11749                 :             :   G. attach_4 (last_node)       [->D]
   11750                 :             :   D. map_to_3                   [->E]
   11751                 :             :   E. attach_3                   [->H (continue_at)]
   11752                 :             :   H. ...
   11753                 :             : */
   11754                 :             : 
   11755                 :             : static tree *
   11756                 :          59 : omp_siblist_move_concat_nodes_after (tree first_new, tree *last_new_tail,
   11757                 :             :                                      tree *first_ptr, tree last_node,
   11758                 :             :                                      tree *move_after)
   11759                 :             : {
   11760                 :          59 :   tree *continue_at = NULL;
   11761                 :          59 :   *last_new_tail = *first_ptr;
   11762                 :          59 :   if (first_ptr == move_after)
   11763                 :          12 :     *move_after = first_new;
   11764                 :             :   else
   11765                 :             :     {
   11766                 :          47 :       *first_ptr = OMP_CLAUSE_CHAIN (last_node);
   11767                 :          47 :       continue_at = first_ptr;
   11768                 :          47 :       OMP_CLAUSE_CHAIN (last_node) = *move_after;
   11769                 :          47 :       *move_after = first_new;
   11770                 :             :     }
   11771                 :          59 :   return continue_at;
   11772                 :             : }
   11773                 :             : 
   11774                 :             : static omp_addr_token *
   11775                 :        9393 : omp_first_chained_access_token (vec<omp_addr_token *> &addr_tokens)
   11776                 :             : {
   11777                 :        9393 :   using namespace omp_addr_tokenizer;
   11778                 :        9393 :   int idx = addr_tokens.length () - 1;
   11779                 :        9393 :   gcc_assert (idx >= 0);
   11780                 :        9393 :   if (addr_tokens[idx]->type != ACCESS_METHOD)
   11781                 :             :     return addr_tokens[idx];
   11782                 :        9410 :   while (idx > 0 && addr_tokens[idx - 1]->type == ACCESS_METHOD)
   11783                 :             :     idx--;
   11784                 :        9393 :   return addr_tokens[idx];
   11785                 :             : }
   11786                 :             : 
   11787                 :             : /* Mapping struct members causes an additional set of nodes to be created,
   11788                 :             :    starting with GOMP_MAP_STRUCT followed by a number of mappings equal to the
   11789                 :             :    number of members being mapped, in order of ascending position (address or
   11790                 :             :    bitwise).
   11791                 :             : 
   11792                 :             :    We scan through the list of mapping clauses, calling this function for each
   11793                 :             :    struct member mapping we find, and build up the list of mappings after the
   11794                 :             :    initial GOMP_MAP_STRUCT node.  For pointer members, these will be
   11795                 :             :    newly-created ALLOC nodes.  For non-pointer members, the existing mapping is
   11796                 :             :    moved into place in the sorted list.
   11797                 :             : 
   11798                 :             :      struct {
   11799                 :             :        int *a;
   11800                 :             :        int *b;
   11801                 :             :        int c;
   11802                 :             :        int *d;
   11803                 :             :      };
   11804                 :             : 
   11805                 :             :      #pragma (acc|omp directive) copy(struct.a[0:n], struct.b[0:n], struct.c,
   11806                 :             :                                       struct.d[0:n])
   11807                 :             : 
   11808                 :             :      GOMP_MAP_STRUCT (4)
   11809                 :             :      [GOMP_MAP_FIRSTPRIVATE_REFERENCE -- for refs to structs]
   11810                 :             :      GOMP_MAP_ALLOC  (struct.a)
   11811                 :             :      GOMP_MAP_ALLOC  (struct.b)
   11812                 :             :      GOMP_MAP_TO     (struct.c)
   11813                 :             :      GOMP_MAP_ALLOC  (struct.d)
   11814                 :             :      ...
   11815                 :             : 
   11816                 :             :    In the case where we are mapping references to pointers, or in Fortran if
   11817                 :             :    we are mapping an array with a descriptor, additional nodes may be created
   11818                 :             :    after the struct node list also.
   11819                 :             : 
   11820                 :             :    The return code is either a pointer to the next node to process (if the
   11821                 :             :    list has been rearranged), else NULL to continue with the next node in the
   11822                 :             :    original list.  */
   11823                 :             : 
   11824                 :             : static tree *
   11825                 :        3764 : omp_accumulate_sibling_list (enum omp_region_type region_type,
   11826                 :             :                              enum tree_code code,
   11827                 :             :                              hash_map<tree_operand_hash, tree>
   11828                 :             :                                *&struct_map_to_clause,
   11829                 :             :                              hash_map<tree_operand_hash_no_se,
   11830                 :             :                                       omp_mapping_group *> *group_map,
   11831                 :             :                              tree *grp_start_p, tree grp_end,
   11832                 :             :                              vec<omp_addr_token *> &addr_tokens, tree **inner,
   11833                 :             :                              bool *fragile_p, bool reprocessing_struct,
   11834                 :             :                              tree **added_tail)
   11835                 :             : {
   11836                 :        3764 :   using namespace omp_addr_tokenizer;
   11837                 :        3764 :   poly_offset_int coffset;
   11838                 :        3764 :   poly_int64 cbitpos;
   11839                 :        3764 :   tree ocd = OMP_CLAUSE_DECL (grp_end);
   11840                 :        3764 :   bool openmp = !(region_type & ORT_ACC);
   11841                 :        3764 :   bool target = (region_type & ORT_TARGET) != 0;
   11842                 :        3764 :   tree *continue_at = NULL;
   11843                 :             : 
   11844                 :        4065 :   while (TREE_CODE (ocd) == ARRAY_REF)
   11845                 :         301 :     ocd = TREE_OPERAND (ocd, 0);
   11846                 :             : 
   11847                 :        3764 :   if (*fragile_p)
   11848                 :             :     {
   11849                 :         141 :       omp_mapping_group *to_group
   11850                 :         141 :         = omp_get_nonfirstprivate_group (group_map, ocd, true);
   11851                 :             : 
   11852                 :         141 :       if (to_group)
   11853                 :             :         return NULL;
   11854                 :             :     }
   11855                 :             : 
   11856                 :        3691 :   omp_addr_token *last_token = omp_first_chained_access_token (addr_tokens);
   11857                 :        3691 :   if (last_token->type == ACCESS_METHOD)
   11858                 :             :     {
   11859                 :        3691 :       switch (last_token->u.access_kind)
   11860                 :             :         {
   11861                 :         735 :         case ACCESS_REF:
   11862                 :         735 :         case ACCESS_REF_TO_POINTER:
   11863                 :         735 :         case ACCESS_REF_TO_POINTER_OFFSET:
   11864                 :         735 :         case ACCESS_INDEXED_REF_TO_ARRAY:
   11865                 :             :           /* We may see either a bare reference or a dereferenced
   11866                 :             :              "convert_from_reference"-like one here.  Handle either way.  */
   11867                 :         735 :           if (TREE_CODE (ocd) == INDIRECT_REF)
   11868                 :          64 :             ocd = TREE_OPERAND (ocd, 0);
   11869                 :         735 :           gcc_assert (TREE_CODE (TREE_TYPE (ocd)) == REFERENCE_TYPE);
   11870                 :             :           break;
   11871                 :             : 
   11872                 :             :         default:
   11873                 :             :           ;
   11874                 :             :         }
   11875                 :             :     }
   11876                 :             : 
   11877                 :        3691 :   bool variable_offset;
   11878                 :        3691 :   tree base
   11879                 :        3691 :     = extract_base_bit_offset (ocd, &cbitpos, &coffset, &variable_offset);
   11880                 :             : 
   11881                 :        3691 :   int base_token;
   11882                 :       18627 :   for (base_token = addr_tokens.length () - 1; base_token >= 0; base_token--)
   11883                 :             :     {
   11884                 :       14936 :       if (addr_tokens[base_token]->type == ARRAY_BASE
   11885                 :       14936 :           || addr_tokens[base_token]->type == STRUCTURE_BASE)
   11886                 :             :         break;
   11887                 :             :     }
   11888                 :             : 
   11889                 :             :   /* The two expressions in the assertion below aren't quite the same: if we
   11890                 :             :      have 'struct_base_decl access_indexed_array' for something like
   11891                 :             :      "myvar[2].x" then base will be "myvar" and addr_tokens[base_token]->expr
   11892                 :             :      will be "myvar[2]" -- the actual base of the structure.
   11893                 :             :      The former interpretation leads to a strange situation where we get
   11894                 :             :        struct(myvar) alloc(myvar[2].ptr1)
   11895                 :             :      That is, the array of structures is kind of treated as one big structure
   11896                 :             :      for the purposes of gathering sibling lists, etc.  */
   11897                 :             :   /* gcc_assert (base == addr_tokens[base_token]->expr);  */
   11898                 :             : 
   11899                 :        3691 :   bool attach_detach = ((OMP_CLAUSE_MAP_KIND (grp_end)
   11900                 :             :                          == GOMP_MAP_ATTACH_DETACH)
   11901                 :        3691 :                         || (OMP_CLAUSE_MAP_KIND (grp_end)
   11902                 :        3691 :                             == GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION));
   11903                 :        3691 :   bool has_descriptor = false;
   11904                 :        3691 :   if (OMP_CLAUSE_CHAIN (*grp_start_p) != grp_end)
   11905                 :             :     {
   11906                 :        2281 :       tree grp_mid = OMP_CLAUSE_CHAIN (*grp_start_p);
   11907                 :        2281 :       if (grp_mid && omp_map_clause_descriptor_p (grp_mid))
   11908                 :             :         has_descriptor = true;
   11909                 :             :     }
   11910                 :             : 
   11911                 :        3691 :   if (!struct_map_to_clause || struct_map_to_clause->get (base) == NULL)
   11912                 :             :     {
   11913                 :        2546 :       enum gomp_map_kind str_kind = GOMP_MAP_STRUCT;
   11914                 :             : 
   11915                 :        2546 :       if (struct_map_to_clause == NULL)
   11916                 :        2149 :         struct_map_to_clause = new hash_map<tree_operand_hash, tree>;
   11917                 :             : 
   11918                 :        2546 :       if (variable_offset)
   11919                 :         108 :         str_kind = GOMP_MAP_STRUCT_UNORD;
   11920                 :             : 
   11921                 :        2546 :       tree l = build_omp_clause (OMP_CLAUSE_LOCATION (grp_end), OMP_CLAUSE_MAP);
   11922                 :             : 
   11923                 :        2546 :       OMP_CLAUSE_SET_MAP_KIND (l, str_kind);
   11924                 :        2546 :       OMP_CLAUSE_DECL (l) = unshare_expr (base);
   11925                 :        2546 :       OMP_CLAUSE_SIZE (l) = size_int (1);
   11926                 :             : 
   11927                 :        2546 :       struct_map_to_clause->put (base, l);
   11928                 :             : 
   11929                 :             :       /* On first iterating through the clause list, we insert the struct node
   11930                 :             :          just before the component access node that triggers the initial
   11931                 :             :          omp_accumulate_sibling_list call for a particular sibling list (and
   11932                 :             :          it then forms the first entry in that list).  When reprocessing
   11933                 :             :          struct bases that are themselves component accesses, we insert the
   11934                 :             :          struct node on an off-side list to avoid inserting the new
   11935                 :             :          GOMP_MAP_STRUCT into the middle of the old one.  */
   11936                 :        2546 :       tree *insert_node_pos = reprocessing_struct ? *added_tail : grp_start_p;
   11937                 :             : 
   11938                 :        2546 :       if (has_descriptor)
   11939                 :             :         {
   11940                 :         463 :           tree desc = OMP_CLAUSE_CHAIN (*grp_start_p);
   11941                 :         463 :           if (code == OMP_TARGET_EXIT_DATA || code == OACC_EXIT_DATA)
   11942                 :          93 :             OMP_CLAUSE_SET_MAP_KIND (desc, GOMP_MAP_RELEASE);
   11943                 :         463 :           tree sc = *insert_node_pos;
   11944                 :         463 :           OMP_CLAUSE_CHAIN (l) = desc;
   11945                 :         463 :           OMP_CLAUSE_CHAIN (*grp_start_p) = OMP_CLAUSE_CHAIN (desc);
   11946                 :         463 :           OMP_CLAUSE_CHAIN (desc) = sc;
   11947                 :         463 :           *insert_node_pos = l;
   11948                 :             :         }
   11949                 :        2083 :       else if (attach_detach)
   11950                 :             :         {
   11951                 :        1285 :           tree extra_node;
   11952                 :        1285 :           tree alloc_node
   11953                 :        1285 :             = build_omp_struct_comp_nodes (code, *grp_start_p, grp_end,
   11954                 :             :                                            &extra_node);
   11955                 :        1285 :           tree *tail;
   11956                 :        1285 :           OMP_CLAUSE_CHAIN (l) = alloc_node;
   11957                 :             : 
   11958                 :        1285 :           if (extra_node)
   11959                 :             :             {
   11960                 :           0 :               OMP_CLAUSE_CHAIN (extra_node) = *insert_node_pos;
   11961                 :           0 :               OMP_CLAUSE_CHAIN (alloc_node) = extra_node;
   11962                 :           0 :               tail = &OMP_CLAUSE_CHAIN (extra_node);
   11963                 :             :             }
   11964                 :             :           else
   11965                 :             :             {
   11966                 :        1285 :               OMP_CLAUSE_CHAIN (alloc_node) = *insert_node_pos;
   11967                 :        1285 :               tail = &OMP_CLAUSE_CHAIN (alloc_node);
   11968                 :             :             }
   11969                 :             : 
   11970                 :             :           /* For OpenMP semantics, we don't want to implicitly allocate
   11971                 :             :              space for the pointer here for non-compute regions (e.g. "enter
   11972                 :             :              data").  A FRAGILE_P node is only being created so that
   11973                 :             :              omp-low.cc is able to rewrite the struct properly.
   11974                 :             :              For references (to pointers), we want to actually allocate the
   11975                 :             :              space for the reference itself in the sorted list following the
   11976                 :             :              struct node.
   11977                 :             :              For pointers, we want to allocate space if we had an explicit
   11978                 :             :              mapping of the attachment point, but not otherwise.  */
   11979                 :        1285 :           if (*fragile_p
   11980                 :        1285 :               || (openmp
   11981                 :             :                   && !target
   11982                 :             :                   && attach_detach
   11983                 :         206 :                   && TREE_CODE (TREE_TYPE (ocd)) == POINTER_TYPE
   11984                 :          60 :                   && !OMP_CLAUSE_ATTACHMENT_MAPPING_ERASED (grp_end)))
   11985                 :             :             {
   11986                 :         105 :               if (!lang_GNU_Fortran ())
   11987                 :             :                /* In Fortran, pointers are dereferenced automatically, but may
   11988                 :             :                   be unassociated.  So we still want to allocate space for the
   11989                 :             :                   pointer (as the base for an attach operation that should be
   11990                 :             :                   present in the same directive's clause list also).  */
   11991                 :          93 :                 OMP_CLAUSE_SIZE (alloc_node) = size_zero_node;
   11992                 :         105 :               OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (alloc_node) = 1;
   11993                 :             :             }
   11994                 :             : 
   11995                 :        1285 :           *insert_node_pos = l;
   11996                 :             : 
   11997                 :        1285 :           if (reprocessing_struct)
   11998                 :             :             {
   11999                 :             :               /* When reprocessing a struct node group used as the base of a
   12000                 :             :                  subcomponent access, if we have a reference-to-pointer base,
   12001                 :             :                  we will see:
   12002                 :             :                    struct(**ptr) attach(*ptr)
   12003                 :             :                  whereas for a non-reprocess-struct group, we see, e.g.:
   12004                 :             :                    tofrom(**ptr) attach(*ptr) attach(ptr)
   12005                 :             :                  and we create the "alloc" for the second "attach", i.e.
   12006                 :             :                  for the reference itself.  When reprocessing a struct group we
   12007                 :             :                  thus change the pointer attachment into a reference attachment
   12008                 :             :                  by stripping the indirection.  (The attachment of the
   12009                 :             :                  referenced pointer must happen elsewhere, either on the same
   12010                 :             :                  directive, or otherwise.)  */
   12011                 :         180 :               tree adecl = OMP_CLAUSE_DECL (alloc_node);
   12012                 :             : 
   12013                 :         180 :               if ((TREE_CODE (adecl) == INDIRECT_REF
   12014                 :         148 :                    || (TREE_CODE (adecl) == MEM_REF
   12015                 :           0 :                        && integer_zerop (TREE_OPERAND (adecl, 1))))
   12016                 :          32 :                   && (TREE_CODE (TREE_TYPE (TREE_OPERAND (adecl, 0)))
   12017                 :             :                       == REFERENCE_TYPE)
   12018                 :         212 :                   && (TREE_CODE (TREE_TYPE (TREE_TYPE
   12019                 :             :                         (TREE_OPERAND (adecl, 0)))) == POINTER_TYPE))
   12020                 :          32 :                 OMP_CLAUSE_DECL (alloc_node) = TREE_OPERAND (adecl, 0);
   12021                 :             : 
   12022                 :         180 :               *added_tail = tail;
   12023                 :             :             }
   12024                 :             :         }
   12025                 :             :       else
   12026                 :             :         {
   12027                 :         798 :           gcc_assert (*grp_start_p == grp_end);
   12028                 :         798 :           if (reprocessing_struct)
   12029                 :             :             {
   12030                 :             :               /* If we don't have an attach/detach node, this is a
   12031                 :             :                  "target data" directive or similar, not an offload region.
   12032                 :             :                  Synthesize an "alloc" node using just the initiating
   12033                 :             :                  GOMP_MAP_STRUCT decl.  */
   12034                 :          64 :               gomp_map_kind k = (code == OMP_TARGET_EXIT_DATA
   12035                 :          32 :                                  || code == OACC_EXIT_DATA)
   12036                 :          32 :                                 ? GOMP_MAP_RELEASE : GOMP_MAP_ALLOC;
   12037                 :          32 :               tree alloc_node
   12038                 :          32 :                 = build_omp_clause (OMP_CLAUSE_LOCATION (grp_end),
   12039                 :             :                                     OMP_CLAUSE_MAP);
   12040                 :          32 :               OMP_CLAUSE_SET_MAP_KIND (alloc_node, k);
   12041                 :          32 :               OMP_CLAUSE_DECL (alloc_node) = unshare_expr (last_token->expr);
   12042                 :          64 :               OMP_CLAUSE_SIZE (alloc_node)
   12043                 :          32 :                 = TYPE_SIZE_UNIT (TREE_TYPE (OMP_CLAUSE_DECL (alloc_node)));
   12044                 :             : 
   12045                 :          32 :               OMP_CLAUSE_CHAIN (alloc_node) = OMP_CLAUSE_CHAIN (l);
   12046                 :          32 :               OMP_CLAUSE_CHAIN (l) = alloc_node;
   12047                 :          32 :               *insert_node_pos = l;
   12048                 :          32 :               *added_tail = &OMP_CLAUSE_CHAIN (alloc_node);
   12049                 :             :             }
   12050                 :             :           else
   12051                 :         766 :             grp_start_p = omp_siblist_insert_node_after (l, insert_node_pos);
   12052                 :             :         }
   12053                 :             : 
   12054                 :        2546 :       unsigned last_access = base_token + 1;
   12055                 :             : 
   12056                 :        2546 :       while (last_access + 1 < addr_tokens.length ()
   12057                 :        2714 :              && addr_tokens[last_access + 1]->type == ACCESS_METHOD)
   12058                 :             :         last_access++;
   12059                 :             : 
   12060                 :        2546 :       if ((region_type & ORT_TARGET)
   12061                 :        2546 :           && addr_tokens[base_token + 1]->type == ACCESS_METHOD)
   12062                 :             :         {
   12063                 :        1527 :           bool base_ref = false;
   12064                 :        1527 :           access_method_kinds access_kind
   12065                 :        1527 :             = addr_tokens[last_access]->u.access_kind;
   12066                 :             : 
   12067                 :        1527 :           switch (access_kind)
   12068                 :             :             {
   12069                 :             :             case ACCESS_DIRECT:
   12070                 :             :             case ACCESS_INDEXED_ARRAY:
   12071                 :         890 :               return NULL;
   12072                 :             : 
   12073                 :         401 :             case ACCESS_REF:
   12074                 :         401 :             case ACCESS_REF_TO_POINTER:
   12075                 :         401 :             case ACCESS_REF_TO_POINTER_OFFSET:
   12076                 :         401 :             case ACCESS_INDEXED_REF_TO_ARRAY:
   12077                 :         401 :               base_ref = true;
   12078                 :         401 :               break;
   12079                 :             : 
   12080                 :         840 :             default:
   12081                 :         840 :               ;
   12082                 :             :             }
   12083                 :         840 :           tree c2 = build_omp_clause (OMP_CLAUSE_LOCATION (grp_end),
   12084                 :             :                                       OMP_CLAUSE_MAP);
   12085                 :         840 :           enum gomp_map_kind mkind;
   12086                 :         840 :           omp_mapping_group *decl_group;
   12087                 :         840 :           tree use_base;
   12088                 :         840 :           switch (access_kind)
   12089                 :             :             {
   12090                 :         439 :             case ACCESS_POINTER:
   12091                 :         439 :             case ACCESS_POINTER_OFFSET:
   12092                 :         439 :               use_base = addr_tokens[last_access]->expr;
   12093                 :         439 :               break;
   12094                 :         198 :             case ACCESS_REF_TO_POINTER:
   12095                 :         198 :             case ACCESS_REF_TO_POINTER_OFFSET:
   12096                 :         198 :               use_base
   12097                 :         198 :                 = build_fold_indirect_ref (addr_tokens[last_access]->expr);
   12098                 :         198 :               break;
   12099                 :         203 :             default:
   12100                 :         203 :               use_base = addr_tokens[base_token]->expr;
   12101                 :             :             }
   12102                 :         840 :           bool mapped_to_p
   12103                 :         840 :             = omp_directive_maps_explicitly (group_map, use_base, &decl_group,
   12104                 :             :                                              true, false, true);
   12105                 :         840 :           if (addr_tokens[base_token]->type == STRUCTURE_BASE
   12106                 :         840 :               && DECL_P (addr_tokens[last_access]->expr)
   12107                 :        1335 :               && !mapped_to_p)
   12108                 :         439 :             mkind = base_ref ? GOMP_MAP_FIRSTPRIVATE_REFERENCE
   12109                 :             :                              : GOMP_MAP_FIRSTPRIVATE_POINTER;
   12110                 :             :           else
   12111                 :             :             mkind = GOMP_MAP_ATTACH_DETACH;
   12112                 :             : 
   12113                 :         840 :           OMP_CLAUSE_SET_MAP_KIND (c2, mkind);
   12114                 :             :           /* If we have a reference to pointer base, we want to attach the
   12115                 :             :              pointer here, not the reference.  The reference attachment happens
   12116                 :             :              elsewhere.  */
   12117                 :         840 :           bool ref_to_ptr
   12118                 :         840 :             = (access_kind == ACCESS_REF_TO_POINTER
   12119                 :         840 :                || access_kind == ACCESS_REF_TO_POINTER_OFFSET);
   12120                 :         840 :           tree sdecl = addr_tokens[last_access]->expr;
   12121                 :         840 :           tree sdecl_ptr = ref_to_ptr ? build_fold_indirect_ref (sdecl)
   12122                 :         840 :                                       : sdecl;
   12123                 :             :           /* For the FIRSTPRIVATE_REFERENCE after the struct node, we
   12124                 :             :              want to use the reference itself for the decl, but we
   12125                 :             :              still want to use the pointer to calculate the bias.  */
   12126                 :         840 :           OMP_CLAUSE_DECL (c2) = (mkind == GOMP_MAP_ATTACH_DETACH)
   12127                 :         840 :                                  ? sdecl_ptr : sdecl;
   12128                 :         840 :           sdecl = sdecl_ptr;
   12129                 :         840 :           tree baddr = build_fold_addr_expr (base);
   12130                 :         840 :           baddr = fold_convert_loc (OMP_CLAUSE_LOCATION (grp_end),
   12131                 :             :                                     ptrdiff_type_node, baddr);
   12132                 :         840 :           tree decladdr = fold_convert_loc (OMP_CLAUSE_LOCATION (grp_end),
   12133                 :             :                                             ptrdiff_type_node, sdecl);
   12134                 :         840 :           OMP_CLAUSE_SIZE (c2)
   12135                 :        1680 :             = fold_build2_loc (OMP_CLAUSE_LOCATION (grp_end), MINUS_EXPR,
   12136                 :             :                                ptrdiff_type_node, baddr, decladdr);
   12137                 :             :           /* Insert after struct node.  */
   12138                 :         840 :           OMP_CLAUSE_CHAIN (c2) = OMP_CLAUSE_CHAIN (l);
   12139                 :         840 :           OMP_CLAUSE_CHAIN (l) = c2;
   12140                 :             : 
   12141                 :         840 :           if (addr_tokens[base_token]->type == STRUCTURE_BASE
   12142                 :         840 :               && (addr_tokens[base_token]->u.structure_base_kind
   12143                 :             :                   == BASE_COMPONENT_EXPR)
   12144                 :         271 :               && mkind == GOMP_MAP_ATTACH_DETACH
   12145                 :        1111 :               && addr_tokens[last_access]->u.access_kind != ACCESS_REF)
   12146                 :             :             {
   12147                 :         203 :               *inner = insert_node_pos;
   12148                 :         203 :               if (openmp)
   12149                 :         151 :                 *fragile_p = true;
   12150                 :         203 :               return NULL;
   12151                 :             :             }
   12152                 :             :         }
   12153                 :             : 
   12154                 :        1656 :       if (addr_tokens[base_token]->type == STRUCTURE_BASE
   12155                 :        1656 :           && (addr_tokens[base_token]->u.structure_base_kind
   12156                 :             :               == BASE_COMPONENT_EXPR)
   12157                 :        1971 :           && addr_tokens[last_access]->u.access_kind == ACCESS_REF)
   12158                 :         100 :         *inner = insert_node_pos;
   12159                 :             : 
   12160                 :        1656 :       return NULL;
   12161                 :             :     }
   12162                 :        1145 :   else if (struct_map_to_clause)
   12163                 :             :     {
   12164                 :        1145 :       tree *osc = struct_map_to_clause->get (base);
   12165                 :        1145 :       tree *sc = NULL, *scp = NULL;
   12166                 :        1145 :       bool unordered = false;
   12167                 :             : 
   12168                 :        1145 :       if (osc && OMP_CLAUSE_MAP_KIND (*osc) == GOMP_MAP_STRUCT_UNORD)
   12169                 :             :         unordered = true;
   12170                 :             : 
   12171                 :        1145 :       unsigned HOST_WIDE_INT i, elems = tree_to_uhwi (OMP_CLAUSE_SIZE (*osc));
   12172                 :        1145 :       sc = &OMP_CLAUSE_CHAIN (*osc);
   12173                 :             :       /* The struct mapping might be immediately followed by a
   12174                 :             :          FIRSTPRIVATE_POINTER,  FIRSTPRIVATE_REFERENCE or an ATTACH_DETACH --
   12175                 :             :          if it's an indirect access or a reference, or if the structure base
   12176                 :             :          is not a decl.  The FIRSTPRIVATE_* nodes are removed in omp-low.cc
   12177                 :             :          after they have been processed there, and ATTACH_DETACH nodes are
   12178                 :             :          recomputed and moved out of the GOMP_MAP_STRUCT construct once
   12179                 :             :          sibling list building is complete.  */
   12180                 :        1145 :       if (OMP_CLAUSE_MAP_KIND (*sc) == GOMP_MAP_FIRSTPRIVATE_POINTER
   12181                 :        1101 :           || OMP_CLAUSE_MAP_KIND (*sc) == GOMP_MAP_FIRSTPRIVATE_REFERENCE
   12182                 :        2201 :           || OMP_CLAUSE_MAP_KIND (*sc) == GOMP_MAP_ATTACH_DETACH)
   12183                 :         188 :         sc = &OMP_CLAUSE_CHAIN (*sc);
   12184                 :        3188 :       for (i = 0; i < elems; i++, sc = &OMP_CLAUSE_CHAIN (*sc))
   12185                 :        2424 :         if (attach_detach && sc == grp_start_p)
   12186                 :             :           break;
   12187                 :        2424 :         else if (TREE_CODE (OMP_CLAUSE_DECL (*sc)) != COMPONENT_REF
   12188                 :         180 :                  && TREE_CODE (OMP_CLAUSE_DECL (*sc)) != INDIRECT_REF
   12189                 :        2604 :                  && TREE_CODE (OMP_CLAUSE_DECL (*sc)) != ARRAY_REF)
   12190                 :             :           break;
   12191                 :             :         else
   12192                 :             :           {
   12193                 :        2424 :             tree sc_decl = OMP_CLAUSE_DECL (*sc);
   12194                 :        2424 :             poly_offset_int offset;
   12195                 :        2424 :             poly_int64 bitpos;
   12196                 :             : 
   12197                 :        2424 :             if (TREE_CODE (sc_decl) == ARRAY_REF)
   12198                 :             :               {
   12199                 :         360 :                 while (TREE_CODE (sc_decl) == ARRAY_REF)
   12200                 :         180 :                   sc_decl = TREE_OPERAND (sc_decl, 0);
   12201                 :         180 :                 if (TREE_CODE (sc_decl) != COMPONENT_REF
   12202                 :         180 :                     || TREE_CODE (TREE_TYPE (sc_decl)) != ARRAY_TYPE)
   12203                 :             :                   break;
   12204                 :             :               }
   12205                 :        2244 :             else if (INDIRECT_REF_P (sc_decl)
   12206                 :           0 :                      && TREE_CODE (TREE_OPERAND (sc_decl, 0)) == COMPONENT_REF
   12207                 :        2244 :                      && (TREE_CODE (TREE_TYPE (TREE_OPERAND (sc_decl, 0)))
   12208                 :             :                          == REFERENCE_TYPE))
   12209                 :           0 :               sc_decl = TREE_OPERAND (sc_decl, 0);
   12210                 :             : 
   12211                 :        2424 :             bool variable_offset2;
   12212                 :        2424 :             tree base2 = extract_base_bit_offset (sc_decl, &bitpos, &offset,
   12213                 :             :                                                   &variable_offset2);
   12214                 :        2424 :             if (!base2 || !operand_equal_p (base2, base, 0))
   12215                 :             :               break;
   12216                 :        2424 :             if (scp)
   12217                 :         216 :               continue;
   12218                 :        2208 :             if (variable_offset2)
   12219                 :             :               {
   12220                 :          48 :                 OMP_CLAUSE_SET_MAP_KIND (*osc, GOMP_MAP_STRUCT_UNORD);
   12221                 :          48 :                 unordered = true;
   12222                 :          48 :                 break;
   12223                 :             :               }
   12224                 :        2160 :             else if ((region_type & ORT_ACC) != 0)
   12225                 :             :               {
   12226                 :             :                 /* For OpenACC, allow (ignore) duplicate struct accesses in
   12227                 :             :                    the middle of a mapping clause, e.g. "mystruct->foo" in:
   12228                 :             :                    copy(mystruct->foo->bar) copy(mystruct->foo->qux).  */
   12229                 :         223 :                 if (reprocessing_struct
   12230                 :           8 :                     && known_eq (coffset, offset)
   12231                 :         223 :                     && known_eq (cbitpos, bitpos))
   12232                 :          21 :                   return NULL;
   12233                 :             :               }
   12234                 :        1937 :             else if (known_eq (coffset, offset)
   12235                 :        1937 :                      && known_eq (cbitpos, bitpos))
   12236                 :             :               {
   12237                 :             :                 /* Having two struct members at the same offset doesn't work,
   12238                 :             :                    so make sure we don't.  (We're allowed to ignore this.
   12239                 :             :                    Should we report the error?)  */
   12240                 :             :                 /*error_at (OMP_CLAUSE_LOCATION (grp_end),
   12241                 :             :                           "duplicate struct member %qE in map clauses",
   12242                 :             :                           OMP_CLAUSE_DECL (grp_end));*/
   12243                 :             :                 return NULL;
   12244                 :             :               }
   12245                 :        2139 :             if (maybe_lt (coffset, offset)
   12246                 :        3719 :                 || (known_eq (coffset, offset)
   12247                 :           2 :                     && maybe_lt (cbitpos, bitpos)))
   12248                 :             :               {
   12249                 :         559 :                 if (attach_detach)
   12250                 :             :                   scp = sc;
   12251                 :             :                 else
   12252                 :             :                   break;
   12253                 :             :               }
   12254                 :             :           }
   12255                 :             : 
   12256                 :             :       /* If this is an unordered struct, just insert the new element at the
   12257                 :             :          end of the list.  */
   12258                 :        1124 :       if (unordered)
   12259                 :             :         {
   12260                 :         102 :           for (; i < elems; i++)
   12261                 :          54 :             sc = &OMP_CLAUSE_CHAIN (*sc);
   12262                 :             :           scp = NULL;
   12263                 :             :         }
   12264                 :             : 
   12265                 :        1124 :       OMP_CLAUSE_SIZE (*osc)
   12266                 :        2248 :         = size_binop (PLUS_EXPR, OMP_CLAUSE_SIZE (*osc), size_one_node);
   12267                 :             : 
   12268                 :        1124 :       if (reprocessing_struct)
   12269                 :             :         {
   12270                 :             :           /* If we're reprocessing a struct node, we don't want to do most of
   12271                 :             :              the list manipulation below.  We only need to handle the (pointer
   12272                 :             :              or reference) attach/detach case.  */
   12273                 :           8 :           tree extra_node, alloc_node;
   12274                 :           8 :           if (has_descriptor)
   12275                 :           0 :             gcc_unreachable ();
   12276                 :           8 :           else if (attach_detach)
   12277                 :           8 :             alloc_node = build_omp_struct_comp_nodes (code, *grp_start_p,
   12278                 :             :                                                       grp_end, &extra_node);
   12279                 :             :           else
   12280                 :             :             {
   12281                 :             :               /* If we don't have an attach/detach node, this is a
   12282                 :             :                  "target data" directive or similar, not an offload region.
   12283                 :             :                  Synthesize an "alloc" node using just the initiating
   12284                 :             :                  GOMP_MAP_STRUCT decl.  */
   12285                 :           0 :               gomp_map_kind k = (code == OMP_TARGET_EXIT_DATA
   12286                 :           0 :                                  || code == OACC_EXIT_DATA)
   12287                 :           0 :                                 ? GOMP_MAP_RELEASE : GOMP_MAP_ALLOC;
   12288                 :           0 :               alloc_node
   12289                 :           0 :                 = build_omp_clause (OMP_CLAUSE_LOCATION (grp_end),
   12290                 :             :                                     OMP_CLAUSE_MAP);
   12291                 :           0 :               OMP_CLAUSE_SET_MAP_KIND (alloc_node, k);
   12292                 :           0 :               OMP_CLAUSE_DECL (alloc_node) = unshare_expr (last_token->expr);
   12293                 :           0 :               OMP_CLAUSE_SIZE (alloc_node)
   12294                 :           0 :                 = TYPE_SIZE_UNIT (TREE_TYPE (OMP_CLAUSE_DECL (alloc_node)));
   12295                 :             :             }
   12296                 :             : 
   12297                 :           8 :           if (scp)
   12298                 :           0 :             omp_siblist_insert_node_after (alloc_node, scp);
   12299                 :             :           else
   12300                 :             :             {
   12301                 :           8 :               tree *new_end = omp_siblist_insert_node_after (alloc_node, sc);
   12302                 :           8 :               if (sc == *added_tail)
   12303                 :           8 :                 *added_tail = new_end;
   12304                 :             :             }
   12305                 :             : 
   12306                 :           8 :           return NULL;
   12307                 :             :         }
   12308                 :             : 
   12309                 :        1116 :       if (has_descriptor)
   12310                 :             :         {
   12311                 :         315 :           tree desc = OMP_CLAUSE_CHAIN (*grp_start_p);
   12312                 :         315 :           if (code == OMP_TARGET_EXIT_DATA
   12313                 :         315 :               || code == OACC_EXIT_DATA)
   12314                 :          19 :             OMP_CLAUSE_SET_MAP_KIND (desc, GOMP_MAP_RELEASE);
   12315                 :         630 :           omp_siblist_move_node_after (desc,
   12316                 :         315 :                                        &OMP_CLAUSE_CHAIN (*grp_start_p),
   12317                 :             :                                        scp ? scp : sc);
   12318                 :             :         }
   12319                 :         801 :       else if (attach_detach)
   12320                 :             :         {
   12321                 :         294 :           tree cl = NULL_TREE, extra_node;
   12322                 :         294 :           tree alloc_node = build_omp_struct_comp_nodes (code, *grp_start_p,
   12323                 :             :                                                          grp_end, &extra_node);
   12324                 :         294 :           tree *tail_chain = NULL;
   12325                 :             : 
   12326                 :         294 :           if (*fragile_p
   12327                 :         294 :               || (openmp
   12328                 :             :                   && !target
   12329                 :             :                   && attach_detach
   12330                 :          56 :                   && TREE_CODE (TREE_TYPE (ocd)) == POINTER_TYPE
   12331                 :          17 :                   && !OMP_CLAUSE_ATTACHMENT_MAPPING_ERASED (grp_end)))
   12332                 :             :             {
   12333                 :           0 :               if (!lang_GNU_Fortran ())
   12334                 :           0 :                 OMP_CLAUSE_SIZE (alloc_node) = size_zero_node;
   12335                 :           0 :               OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (alloc_node) = 1;
   12336                 :             :             }
   12337                 :             : 
   12338                 :             :           /* Here, we have:
   12339                 :             : 
   12340                 :             :              grp_end : the last (or only) node in this group.
   12341                 :             :              grp_start_p : pointer to the first node in a pointer mapping group
   12342                 :             :                            up to and including GRP_END.
   12343                 :             :              sc : pointer to the chain for the end of the struct component
   12344                 :             :                   list.
   12345                 :             :              scp : pointer to the chain for the sorted position at which we
   12346                 :             :                    should insert in the middle of the struct component list
   12347                 :             :                    (else NULL to insert at end).
   12348                 :             :              alloc_node : the "alloc" node for the structure (pointer-type)
   12349                 :             :                           component. We insert at SCP (if present), else SC
   12350                 :             :                           (the end of the struct component list).
   12351                 :             :              extra_node : a newly-synthesized node for an additional indirect
   12352                 :             :                           pointer mapping or a Fortran pointer set, if needed.
   12353                 :             :              cl : first node to prepend before grp_start_p.
   12354                 :             :              tail_chain : pointer to chain of last prepended node.
   12355                 :             : 
   12356                 :             :              The general idea is we move the nodes for this struct mapping
   12357                 :             :              together: the alloc node goes into the sorted list directly after
   12358                 :             :              the struct mapping, and any extra nodes (together with the nodes
   12359                 :             :              mapping arrays pointed to by struct components) get moved after
   12360                 :             :              that list.  When SCP is NULL, we insert the nodes at SC, i.e. at
   12361                 :             :              the end of the struct component mapping list.  It's important that
   12362                 :             :              the alloc_node comes first in that case because it's part of the
   12363                 :             :              sorted component mapping list (but subsequent nodes are not!).  */
   12364                 :             : 
   12365                 :         294 :           if (scp)
   12366                 :         235 :             omp_siblist_insert_node_after (alloc_node, scp);
   12367                 :             : 
   12368                 :             :           /* Make [cl,tail_chain] a list of the alloc node (if we haven't
   12369                 :             :              already inserted it) and the extra_node (if it is present).  The
   12370                 :             :              list can be empty if we added alloc_node above and there is no
   12371                 :             :              extra node.  */
   12372                 :         235 :           if (scp && extra_node)
   12373                 :             :             {
   12374                 :           0 :               cl = extra_node;
   12375                 :           0 :               tail_chain = &OMP_CLAUSE_CHAIN (extra_node);
   12376                 :             :             }
   12377                 :         294 :           else if (extra_node)
   12378                 :             :             {
   12379                 :           0 :               OMP_CLAUSE_CHAIN (alloc_node) = extra_node;
   12380                 :           0 :               cl = alloc_node;
   12381                 :           0 :               tail_chain = &OMP_CLAUSE_CHAIN (extra_node);
   12382                 :             :             }
   12383                 :         294 :           else if (!scp)
   12384                 :             :             {
   12385                 :          59 :               cl = alloc_node;
   12386                 :          59 :               tail_chain = &OMP_CLAUSE_CHAIN (alloc_node);
   12387                 :             :             }
   12388                 :             : 
   12389                 :         294 :           continue_at
   12390                 :         294 :             = cl ? omp_siblist_move_concat_nodes_after (cl, tail_chain,
   12391                 :             :                                                         grp_start_p, grp_end,
   12392                 :             :                                                         sc)
   12393                 :         235 :                  : omp_siblist_move_nodes_after (grp_start_p, grp_end, sc);
   12394                 :             :         }
   12395                 :         507 :       else if (*sc != grp_end)
   12396                 :             :         {
   12397                 :         467 :           gcc_assert (*grp_start_p == grp_end);
   12398                 :             : 
   12399                 :             :           /* We are moving the current node back to a previous struct node:
   12400                 :             :              the node that used to point to the current node will now point to
   12401                 :             :              the next node.  */
   12402                 :         467 :           continue_at = grp_start_p;
   12403                 :             :           /* In the non-pointer case, the mapping clause itself is moved into
   12404                 :             :              the correct position in the struct component list, which in this
   12405                 :             :              case is just SC.  */
   12406                 :         467 :           omp_siblist_move_node_after (*grp_start_p, grp_start_p, sc);
   12407                 :             :         }
   12408                 :             :     }
   12409                 :             :   return continue_at;
   12410                 :             : }
   12411                 :             : 
   12412                 :             : /* Scan through GROUPS, and create sorted structure sibling lists without
   12413                 :             :    gimplifying.  */
   12414                 :             : 
   12415                 :             : static bool
   12416                 :       16471 : omp_build_struct_sibling_lists (enum tree_code code,
   12417                 :             :                                 enum omp_region_type region_type,
   12418                 :             :                                 vec<omp_mapping_group> *groups,
   12419                 :             :                                 hash_map<tree_operand_hash_no_se,
   12420                 :             :                                          omp_mapping_group *> **grpmap,
   12421                 :             :                                 tree *list_p)
   12422                 :             : {
   12423                 :       16471 :   using namespace omp_addr_tokenizer;
   12424                 :       16471 :   unsigned i;
   12425                 :       16471 :   omp_mapping_group *grp;
   12426                 :       16471 :   hash_map<tree_operand_hash, tree> *struct_map_to_clause = NULL;
   12427                 :       16471 :   bool success = true;
   12428                 :       16471 :   tree *new_next = NULL;
   12429                 :       32942 :   tree *tail = &OMP_CLAUSE_CHAIN ((*groups)[groups->length () - 1].grp_end);
   12430                 :       16471 :   tree added_nodes = NULL_TREE;
   12431                 :       16471 :   tree *added_tail = &added_nodes;
   12432                 :       16471 :   auto_vec<omp_mapping_group> pre_hwm_groups;
   12433                 :             : 
   12434                 :       61380 :   FOR_EACH_VEC_ELT (*groups, i, grp)
   12435                 :             :     {
   12436                 :       28438 :       tree c = grp->grp_end;
   12437                 :       28438 :       tree decl = OMP_CLAUSE_DECL (c);
   12438                 :       28438 :       tree grp_end = grp->grp_end;
   12439                 :       28438 :       auto_vec<omp_addr_token *> addr_tokens;
   12440                 :       28438 :       tree sentinel = OMP_CLAUSE_CHAIN (grp_end);
   12441                 :             : 
   12442                 :       28438 :       if (new_next && !grp->reprocess_struct)
   12443                 :         467 :         grp->grp_start = new_next;
   12444                 :             : 
   12445                 :       28438 :       new_next = NULL;
   12446                 :             : 
   12447                 :       28438 :       tree *grp_start_p = grp->grp_start;
   12448                 :             : 
   12449                 :       28438 :       if (DECL_P (decl))
   12450                 :       19597 :         continue;
   12451                 :             : 
   12452                 :             :       /* Skip groups we marked for deletion in
   12453                 :             :          {omp,oacc}_resolve_clause_dependencies.  */
   12454                 :        8841 :       if (grp->deleted)
   12455                 :         387 :         continue;
   12456                 :             : 
   12457                 :        8454 :       if (OMP_CLAUSE_CHAIN (*grp_start_p)
   12458                 :        8454 :           && OMP_CLAUSE_CHAIN (*grp_start_p) != grp_end)
   12459                 :             :         {
   12460                 :             :           /* Don't process an array descriptor that isn't inside a derived type
   12461                 :             :              as a struct (the GOMP_MAP_POINTER following will have the form
   12462                 :             :              "var.data", but such mappings are handled specially).  */
   12463                 :        5240 :           tree grpmid = OMP_CLAUSE_CHAIN (*grp_start_p);
   12464                 :        5240 :           if (omp_map_clause_descriptor_p (grpmid)
   12465                 :        8817 :               && DECL_P (OMP_CLAUSE_DECL (grpmid)))
   12466                 :        2752 :             continue;
   12467                 :             :         }
   12468                 :             : 
   12469                 :             :       tree expr = decl;
   12470                 :             : 
   12471                 :        6701 :       while (TREE_CODE (expr) == ARRAY_REF)
   12472                 :         999 :         expr = TREE_OPERAND (expr, 0);
   12473                 :             : 
   12474                 :        5702 :       if (!omp_parse_expr (addr_tokens, expr))
   12475                 :           0 :         continue;
   12476                 :             : 
   12477                 :        5702 :       omp_addr_token *last_token
   12478                 :        5702 :         = omp_first_chained_access_token (addr_tokens);
   12479                 :             : 
   12480                 :             :       /* A mapping of a reference to a pointer member that doesn't specify an
   12481                 :             :          array section, etc., like this:
   12482                 :             :            *mystruct.ref_to_ptr
   12483                 :             :          should not be processed by the struct sibling-list handling code --
   12484                 :             :          it just transfers the referenced pointer.
   12485                 :             : 
   12486                 :             :          In contrast, the quite similar-looking construct:
   12487                 :             :            *mystruct.ptr
   12488                 :             :          which is equivalent to e.g.
   12489                 :             :            mystruct.ptr[0]
   12490                 :             :          *does* trigger sibling-list processing.
   12491                 :             : 
   12492                 :             :          An exception for the former case is for "fragile" groups where the
   12493                 :             :          reference itself is not handled otherwise; this is subject to special
   12494                 :             :          handling in omp_accumulate_sibling_list also.  */
   12495                 :             : 
   12496                 :        5702 :       if (TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE
   12497                 :        2611 :           && last_token->type == ACCESS_METHOD
   12498                 :        2611 :           && last_token->u.access_kind == ACCESS_REF
   12499                 :        5986 :           && !grp->fragile)
   12500                 :         219 :         continue;
   12501                 :             : 
   12502                 :        5483 :       tree d = decl;
   12503                 :        5483 :       if (TREE_CODE (d) == ARRAY_REF)
   12504                 :             :         {
   12505                 :        1946 :           while (TREE_CODE (d) == ARRAY_REF)
   12506                 :         982 :             d = TREE_OPERAND (d, 0);
   12507                 :         964 :           if (TREE_CODE (d) == COMPONENT_REF
   12508                 :         964 :               && TREE_CODE (TREE_TYPE (d)) == ARRAY_TYPE)
   12509                 :             :             decl = d;
   12510                 :             :         }
   12511                 :        5483 :       if (d == decl
   12512                 :        4822 :           && INDIRECT_REF_P (decl)
   12513                 :         647 :           && TREE_CODE (TREE_OPERAND (decl, 0)) == COMPONENT_REF
   12514                 :         105 :           && (TREE_CODE (TREE_TYPE (TREE_OPERAND (decl, 0)))
   12515                 :             :               == REFERENCE_TYPE)
   12516                 :        5580 :           && (OMP_CLAUSE_MAP_KIND (c)
   12517                 :             :               != GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION))
   12518                 :          97 :         decl = TREE_OPERAND (decl, 0);
   12519                 :             : 
   12520                 :        5483 :       STRIP_NOPS (decl);
   12521                 :             : 
   12522                 :        5483 :       if (TREE_CODE (decl) != COMPONENT_REF)
   12523                 :        1242 :         continue;
   12524                 :             : 
   12525                 :             :       /* If we're mapping the whole struct in another node, skip adding this
   12526                 :             :          node to a sibling list.  */
   12527                 :        4241 :       omp_mapping_group *wholestruct;
   12528                 :        4241 :       if (omp_mapped_by_containing_struct (*grpmap, OMP_CLAUSE_DECL (c),
   12529                 :             :                                            &wholestruct))
   12530                 :         115 :         continue;
   12531                 :             : 
   12532                 :        4126 :       if (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_TO_PSET
   12533                 :        4126 :           && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH
   12534                 :        4022 :           && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_DETACH
   12535                 :             :           && code != OACC_UPDATE
   12536                 :        8081 :           && code != OMP_TARGET_UPDATE)
   12537                 :             :         {
   12538                 :        3764 :           if (error_operand_p (decl))
   12539                 :             :             {
   12540                 :           0 :               success = false;
   12541                 :           0 :               goto error_out;
   12542                 :             :             }
   12543                 :             : 
   12544                 :        3764 :           tree stype = TREE_TYPE (decl);
   12545                 :        3764 :           if (TREE_CODE (stype) == REFERENCE_TYPE)
   12546                 :         768 :             stype = TREE_TYPE (stype);
   12547                 :        3764 :           if (TYPE_SIZE_UNIT (stype) == NULL
   12548                 :        3764 :               || TREE_CODE (TYPE_SIZE_UNIT (stype)) != INTEGER_CST)
   12549                 :             :             {
   12550                 :           0 :               error_at (OMP_CLAUSE_LOCATION (c),
   12551                 :             :                         "mapping field %qE of variable length "
   12552                 :           0 :                         "structure", OMP_CLAUSE_DECL (c));
   12553                 :           0 :               success = false;
   12554                 :           0 :               goto error_out;
   12555                 :             :             }
   12556                 :             : 
   12557                 :        3764 :           tree *inner = NULL;
   12558                 :        3764 :           bool fragile_p = grp->fragile;
   12559                 :             : 
   12560                 :        3764 :           new_next
   12561                 :        7528 :             = omp_accumulate_sibling_list (region_type, code,
   12562                 :             :                                            struct_map_to_clause, *grpmap,
   12563                 :             :                                            grp_start_p, grp_end, addr_tokens,
   12564                 :             :                                            &inner, &fragile_p,
   12565                 :        3764 :                                            grp->reprocess_struct, &added_tail);
   12566                 :             : 
   12567                 :        3764 :           if (inner)
   12568                 :             :             {
   12569                 :         303 :               omp_mapping_group newgrp;
   12570                 :         303 :               newgrp.grp_start = inner;
   12571                 :         303 :               if (OMP_CLAUSE_MAP_KIND (OMP_CLAUSE_CHAIN (*inner))
   12572                 :             :                   == GOMP_MAP_ATTACH_DETACH)
   12573                 :         271 :                 newgrp.grp_end = OMP_CLAUSE_CHAIN (*inner);
   12574                 :             :               else
   12575                 :          32 :                 newgrp.grp_end = *inner;
   12576                 :         303 :               newgrp.mark = UNVISITED;
   12577                 :         303 :               newgrp.sibling = NULL;
   12578                 :         303 :               newgrp.deleted = false;
   12579                 :         303 :               newgrp.reprocess_struct = true;
   12580                 :         303 :               newgrp.fragile = fragile_p;
   12581                 :         303 :               newgrp.next = NULL;
   12582                 :         303 :               groups->safe_push (newgrp);
   12583                 :             : 
   12584                 :             :               /* !!! Growing GROUPS might invalidate the pointers in the group
   12585                 :             :                  map.  Rebuild it here.  This is a bit inefficient, but
   12586                 :             :                  shouldn't happen very often.  */
   12587                 :         606 :               delete (*grpmap);
   12588                 :         303 :               *grpmap
   12589                 :         303 :                 = omp_reindex_mapping_groups (list_p, groups, &pre_hwm_groups,
   12590                 :             :                                               sentinel);
   12591                 :             :             }
   12592                 :             :         }
   12593                 :       28438 :     }
   12594                 :             : 
   12595                 :             :   /* Delete groups marked for deletion above.  At this point the order of the
   12596                 :             :      groups may no longer correspond to the order of the underlying list,
   12597                 :             :      which complicates this a little.  First clear out OMP_CLAUSE_DECL for
   12598                 :             :      deleted nodes...  */
   12599                 :             : 
   12600                 :       44909 :   FOR_EACH_VEC_ELT (*groups, i, grp)
   12601                 :       28438 :     if (grp->deleted)
   12602                 :         387 :       for (tree d = *grp->grp_start;
   12603                 :         774 :            d != OMP_CLAUSE_CHAIN (grp->grp_end);
   12604                 :         387 :            d = OMP_CLAUSE_CHAIN (d))
   12605                 :         387 :         OMP_CLAUSE_DECL (d) = NULL_TREE;
   12606                 :             : 
   12607                 :             :   /* ...then sweep through the list removing the now-empty nodes.  */
   12608                 :             : 
   12609                 :             :   tail = list_p;
   12610                 :       87045 :   while (*tail)
   12611                 :             :     {
   12612                 :       70574 :       if (OMP_CLAUSE_CODE (*tail) == OMP_CLAUSE_MAP
   12613                 :       70574 :           && OMP_CLAUSE_DECL (*tail) == NULL_TREE)
   12614                 :         387 :         *tail = OMP_CLAUSE_CHAIN (*tail);
   12615                 :             :       else
   12616                 :       70187 :         tail = &OMP_CLAUSE_CHAIN (*tail);
   12617                 :             :     }
   12618                 :             : 
   12619                 :             :   /* Tack on the struct nodes added during nested struct reprocessing.  */
   12620                 :       16471 :   if (added_nodes)
   12621                 :             :     {
   12622                 :         192 :       *tail = added_nodes;
   12623                 :         192 :       tail = added_tail;
   12624                 :             :     }
   12625                 :             : 
   12626                 :             :   /* Now we have finished building the struct sibling lists, reprocess
   12627                 :             :      newly-added "attach" nodes: we need the address of the first
   12628                 :             :      mapped element of each struct sibling list for the bias of the attach
   12629                 :             :      operation -- not necessarily the base address of the whole struct.  */
   12630                 :       16471 :   if (struct_map_to_clause)
   12631                 :        4695 :     for (hash_map<tree_operand_hash, tree>::iterator iter
   12632                 :        2149 :            = struct_map_to_clause->begin ();
   12633                 :        6844 :          iter != struct_map_to_clause->end ();
   12634                 :        2546 :          ++iter)
   12635                 :             :       {
   12636                 :        2546 :         tree struct_node = (*iter).second;
   12637                 :        2546 :         gcc_assert (OMP_CLAUSE_CODE (struct_node) == OMP_CLAUSE_MAP);
   12638                 :        2546 :         tree attach = OMP_CLAUSE_CHAIN (struct_node);
   12639                 :             : 
   12640                 :        2546 :         if (OMP_CLAUSE_CODE (attach) != OMP_CLAUSE_MAP
   12641                 :        2546 :             || OMP_CLAUSE_MAP_KIND (attach) != GOMP_MAP_ATTACH_DETACH)
   12642                 :        2145 :           continue;
   12643                 :             : 
   12644                 :         401 :         OMP_CLAUSE_SET_MAP_KIND (attach, GOMP_MAP_ATTACH);
   12645                 :             : 
   12646                 :             :         /* Sanity check: the standalone attach node will not work if we have
   12647                 :             :            an "enter data" operation (because for those, variables need to be
   12648                 :             :            mapped separately and attach nodes must be grouped together with the
   12649                 :             :            base they attach to).  We should only have created the
   12650                 :             :            ATTACH_DETACH node after GOMP_MAP_STRUCT for a target region, so
   12651                 :             :            this should never be true.  */
   12652                 :         401 :         gcc_assert ((region_type & ORT_TARGET) != 0);
   12653                 :             : 
   12654                 :             :         /* This is the first sorted node in the struct sibling list.  Use it
   12655                 :             :            to recalculate the correct bias to use.
   12656                 :             :            (&first_node - attach_decl).
   12657                 :             :            For GOMP_MAP_STRUCT_UNORD, we need e.g. the
   12658                 :             :            min(min(min(first,second),third),fourth) element, because the
   12659                 :             :            elements aren't in any particular order.  */
   12660                 :         401 :         tree lowest_addr;
   12661                 :         401 :         if (OMP_CLAUSE_MAP_KIND (struct_node) == GOMP_MAP_STRUCT_UNORD)
   12662                 :             :           {
   12663                 :           4 :             tree first_node = OMP_CLAUSE_CHAIN (attach);
   12664                 :           4 :             unsigned HOST_WIDE_INT num_mappings
   12665                 :           4 :               = tree_to_uhwi (OMP_CLAUSE_SIZE (struct_node));
   12666                 :           4 :             lowest_addr = OMP_CLAUSE_DECL (first_node);
   12667                 :           4 :             lowest_addr = build_fold_addr_expr (lowest_addr);
   12668                 :           4 :             lowest_addr = fold_convert (pointer_sized_int_node, lowest_addr);
   12669                 :           4 :             tree next_node = OMP_CLAUSE_CHAIN (first_node);
   12670                 :           8 :             while (num_mappings > 1)
   12671                 :             :               {
   12672                 :           4 :                 tree tmp = OMP_CLAUSE_DECL (next_node);
   12673                 :           4 :                 tmp = build_fold_addr_expr (tmp);
   12674                 :           4 :                 tmp = fold_convert (pointer_sized_int_node, tmp);
   12675                 :           4 :                 lowest_addr = fold_build2 (MIN_EXPR, pointer_sized_int_node,
   12676                 :             :                                            lowest_addr, tmp);
   12677                 :           4 :                 next_node = OMP_CLAUSE_CHAIN (next_node);
   12678                 :           4 :                 num_mappings--;
   12679                 :             :               }
   12680                 :           4 :             lowest_addr = fold_convert (ptrdiff_type_node, lowest_addr);
   12681                 :             :           }
   12682                 :             :         else
   12683                 :             :           {
   12684                 :         397 :             tree first_node = OMP_CLAUSE_DECL (OMP_CLAUSE_CHAIN (attach));
   12685                 :         397 :             first_node = build_fold_addr_expr (first_node);
   12686                 :         397 :             lowest_addr = fold_convert (ptrdiff_type_node, first_node);
   12687                 :             :           }
   12688                 :         401 :         tree attach_decl = OMP_CLAUSE_DECL (attach);
   12689                 :         401 :         attach_decl = fold_convert (ptrdiff_type_node, attach_decl);
   12690                 :         401 :         OMP_CLAUSE_SIZE (attach)
   12691                 :         802 :           = fold_build2 (MINUS_EXPR, ptrdiff_type_node, lowest_addr,
   12692                 :             :                          attach_decl);
   12693                 :             : 
   12694                 :             :         /* Remove GOMP_MAP_ATTACH node from after struct node.  */
   12695                 :         401 :         OMP_CLAUSE_CHAIN (struct_node) = OMP_CLAUSE_CHAIN (attach);
   12696                 :             :         /* ...and re-insert it at the end of our clause list.  */
   12697                 :         401 :         *tail = attach;
   12698                 :         401 :         OMP_CLAUSE_CHAIN (attach) = NULL_TREE;
   12699                 :         401 :         tail = &OMP_CLAUSE_CHAIN (attach);
   12700                 :             :       }
   12701                 :             : 
   12702                 :       14322 : error_out:
   12703                 :       16471 :   if (struct_map_to_clause)
   12704                 :        2149 :     delete struct_map_to_clause;
   12705                 :             : 
   12706                 :       16471 :   return success;
   12707                 :       16471 : }
   12708                 :             : 
   12709                 :             : /* Scan the OMP clauses in *LIST_P, installing mappings into a new
   12710                 :             :    and previous omp contexts.  */
   12711                 :             : 
   12712                 :             : static void
   12713                 :      127893 : gimplify_scan_omp_clauses (tree *list_p, gimple_seq *pre_p,
   12714                 :             :                            enum omp_region_type region_type,
   12715                 :             :                            enum tree_code code)
   12716                 :             : {
   12717                 :      127893 :   using namespace omp_addr_tokenizer;
   12718                 :      127893 :   struct gimplify_omp_ctx *ctx, *outer_ctx;
   12719                 :      127893 :   tree c;
   12720                 :      127893 :   tree *orig_list_p = list_p;
   12721                 :      127893 :   int handled_depend_iterators = -1;
   12722                 :      127893 :   int nowait = -1;
   12723                 :             : 
   12724                 :      127893 :   ctx = new_omp_context (region_type);
   12725                 :      127893 :   ctx->code = code;
   12726                 :      127893 :   outer_ctx = ctx->outer_context;
   12727                 :      127893 :   if (code == OMP_TARGET)
   12728                 :             :     {
   12729                 :       11983 :       if (!lang_GNU_Fortran ())
   12730                 :       10117 :         ctx->defaultmap[GDMK_POINTER] = GOVD_MAP | GOVD_MAP_0LEN_ARRAY;
   12731                 :       11983 :       ctx->defaultmap[GDMK_SCALAR] = GOVD_FIRSTPRIVATE;
   12732                 :       23966 :       ctx->defaultmap[GDMK_SCALAR_TARGET] = (lang_GNU_Fortran ()
   12733                 :       11983 :                                              ? GOVD_MAP : GOVD_FIRSTPRIVATE);
   12734                 :             :     }
   12735                 :      127893 :   if (!lang_GNU_Fortran ())
   12736                 :       97595 :     switch (code)
   12737                 :             :       {
   12738                 :       17428 :       case OMP_TARGET:
   12739                 :       17428 :       case OMP_TARGET_DATA:
   12740                 :       17428 :       case OMP_TARGET_ENTER_DATA:
   12741                 :       17428 :       case OMP_TARGET_EXIT_DATA:
   12742                 :       17428 :       case OACC_DECLARE:
   12743                 :       17428 :       case OACC_HOST_DATA:
   12744                 :       17428 :       case OACC_PARALLEL:
   12745                 :       17428 :       case OACC_KERNELS:
   12746                 :       17428 :         ctx->target_firstprivatize_array_bases = true;
   12747                 :             :       default:
   12748                 :             :         break;
   12749                 :             :       }
   12750                 :             : 
   12751                 :      127893 :   vec<omp_mapping_group> *groups = NULL;
   12752                 :      127893 :   hash_map<tree_operand_hash_no_se, omp_mapping_group *> *grpmap = NULL;
   12753                 :      127893 :   unsigned grpnum = 0;
   12754                 :      127893 :   tree *grp_start_p = NULL, grp_end = NULL_TREE;
   12755                 :             : 
   12756                 :      127893 :   if (code == OMP_TARGET
   12757                 :      127893 :       || code == OMP_TARGET_DATA
   12758                 :      127893 :       || code == OMP_TARGET_ENTER_DATA
   12759                 :             :       || code == OMP_TARGET_EXIT_DATA
   12760                 :             :       || code == OACC_DATA
   12761                 :             :       || code == OACC_KERNELS
   12762                 :             :       || code == OACC_PARALLEL
   12763                 :             :       || code == OACC_SERIAL
   12764                 :             :       || code == OACC_ENTER_DATA
   12765                 :             :       || code == OACC_EXIT_DATA
   12766                 :             :       || code == OACC_UPDATE
   12767                 :             :       || code == OACC_DECLARE)
   12768                 :             :     {
   12769                 :       31808 :       groups = omp_gather_mapping_groups (list_p);
   12770                 :             : 
   12771                 :       31808 :       if (groups)
   12772                 :       16725 :         grpmap = omp_index_mapping_groups (groups);
   12773                 :             :     }
   12774                 :             : 
   12775                 :      326920 :   while ((c = *list_p) != NULL)
   12776                 :             :     {
   12777                 :      199027 :       bool remove = false;
   12778                 :      199027 :       bool notice_outer = true;
   12779                 :      199027 :       bool map_descriptor;
   12780                 :      199027 :       const char *check_non_private = NULL;
   12781                 :      199027 :       unsigned int flags;
   12782                 :      199027 :       tree decl;
   12783                 :      199027 :       auto_vec<omp_addr_token *, 10> addr_tokens;
   12784                 :             : 
   12785                 :      233579 :       if (grp_end && c == OMP_CLAUSE_CHAIN (grp_end))
   12786                 :             :         {
   12787                 :             :           grp_start_p = NULL;
   12788                 :             :           grp_end = NULL_TREE;
   12789                 :             :         }
   12790                 :             : 
   12791                 :      199027 :       switch (OMP_CLAUSE_CODE (c))
   12792                 :             :         {
   12793                 :       12189 :         case OMP_CLAUSE_PRIVATE:
   12794                 :       12189 :           flags = GOVD_PRIVATE | GOVD_EXPLICIT;
   12795                 :       12189 :           if (lang_hooks.decls.omp_private_outer_ref (OMP_CLAUSE_DECL (c)))
   12796                 :             :             {
   12797                 :         165 :               flags |= GOVD_PRIVATE_OUTER_REF;
   12798                 :         165 :               OMP_CLAUSE_PRIVATE_OUTER_REF (c) = 1;
   12799                 :             :             }
   12800                 :             :           else
   12801                 :             :             notice_outer = false;
   12802                 :       12189 :           goto do_add;
   12803                 :        5510 :         case OMP_CLAUSE_SHARED:
   12804                 :        5510 :           flags = GOVD_SHARED | GOVD_EXPLICIT;
   12805                 :        5510 :           goto do_add;
   12806                 :        7876 :         case OMP_CLAUSE_FIRSTPRIVATE:
   12807                 :        7876 :           flags = GOVD_FIRSTPRIVATE | GOVD_EXPLICIT;
   12808                 :        7876 :           check_non_private = "firstprivate";
   12809                 :        7876 :           if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c))
   12810                 :             :             {
   12811                 :         380 :               gcc_assert (code == OMP_TARGET);
   12812                 :             :               flags |= GOVD_FIRSTPRIVATE_IMPLICIT;
   12813                 :             :             }
   12814                 :        7876 :           goto do_add;
   12815                 :        7325 :         case OMP_CLAUSE_LASTPRIVATE:
   12816                 :        7325 :           if (OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c))
   12817                 :         496 :             switch (code)
   12818                 :             :               {
   12819                 :          25 :               case OMP_DISTRIBUTE:
   12820                 :          25 :                 error_at (OMP_CLAUSE_LOCATION (c),
   12821                 :             :                           "conditional %<lastprivate%> clause on "
   12822                 :             :                           "%qs construct", "distribute");
   12823                 :          25 :                 OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c) = 0;
   12824                 :          25 :                 break;
   12825                 :          13 :               case OMP_TASKLOOP:
   12826                 :          13 :                 error_at (OMP_CLAUSE_LOCATION (c),
   12827                 :             :                           "conditional %<lastprivate%> clause on "
   12828                 :             :                           "%qs construct", "taskloop");
   12829                 :          13 :                 OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c) = 0;
   12830                 :          13 :                 break;
   12831                 :             :               default:
   12832                 :             :                 break;
   12833                 :             :               }
   12834                 :        7325 :           flags = GOVD_LASTPRIVATE | GOVD_SEEN | GOVD_EXPLICIT;
   12835                 :        7325 :           if (code != OMP_LOOP)
   12836                 :        6974 :             check_non_private = "lastprivate";
   12837                 :        7325 :           decl = OMP_CLAUSE_DECL (c);
   12838                 :        7325 :           if (error_operand_p (decl))
   12839                 :           0 :             goto do_add;
   12840                 :        7325 :           if (OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c)
   12841                 :        7325 :               && !lang_hooks.decls.omp_scalar_p (decl, true))
   12842                 :             :             {
   12843                 :           5 :               error_at (OMP_CLAUSE_LOCATION (c),
   12844                 :             :                         "non-scalar variable %qD in conditional "
   12845                 :             :                         "%<lastprivate%> clause", decl);
   12846                 :           5 :               OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c) = 0;
   12847                 :             :             }
   12848                 :        7325 :           if (OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c))
   12849                 :         453 :             flags |= GOVD_LASTPRIVATE_CONDITIONAL;
   12850                 :        7325 :           omp_lastprivate_for_combined_outer_constructs (outer_ctx, decl,
   12851                 :             :                                                          false);
   12852                 :        7325 :           goto do_add;
   12853                 :       15262 :         case OMP_CLAUSE_REDUCTION:
   12854                 :       15262 :           if (OMP_CLAUSE_REDUCTION_TASK (c))
   12855                 :             :             {
   12856                 :         594 :               if (region_type == ORT_WORKSHARE || code == OMP_SCOPE)
   12857                 :             :                 {
   12858                 :         408 :                   if (nowait == -1)
   12859                 :         293 :                     nowait = omp_find_clause (*list_p,
   12860                 :         293 :                                               OMP_CLAUSE_NOWAIT) != NULL_TREE;
   12861                 :         408 :                   if (nowait
   12862                 :          15 :                       && (outer_ctx == NULL
   12863                 :           0 :                           || outer_ctx->region_type != ORT_COMBINED_PARALLEL))
   12864                 :             :                     {
   12865                 :          15 :                       error_at (OMP_CLAUSE_LOCATION (c),
   12866                 :             :                                 "%<task%> reduction modifier on a construct "
   12867                 :             :                                 "with a %<nowait%> clause");
   12868                 :          15 :                       OMP_CLAUSE_REDUCTION_TASK (c) = 0;
   12869                 :             :                     }
   12870                 :             :                 }
   12871                 :         186 :               else if ((region_type & ORT_PARALLEL) != ORT_PARALLEL)
   12872                 :             :                 {
   12873                 :          40 :                   error_at (OMP_CLAUSE_LOCATION (c),
   12874                 :             :                             "invalid %<task%> reduction modifier on construct "
   12875                 :             :                             "other than %<parallel%>, %qs, %<sections%> or "
   12876                 :          20 :                             "%<scope%>", lang_GNU_Fortran () ? "do" : "for");
   12877                 :          20 :                   OMP_CLAUSE_REDUCTION_TASK (c) = 0;
   12878                 :             :                 }
   12879                 :             :             }
   12880                 :       15262 :           if (OMP_CLAUSE_REDUCTION_INSCAN (c))
   12881                 :         831 :             switch (code)
   12882                 :             :               {
   12883                 :           4 :               case OMP_SECTIONS:
   12884                 :           4 :                 error_at (OMP_CLAUSE_LOCATION (c),
   12885                 :             :                           "%<inscan%> %<reduction%> clause on "
   12886                 :             :                           "%qs construct", "sections");
   12887                 :           4 :                 OMP_CLAUSE_REDUCTION_INSCAN (c) = 0;
   12888                 :           4 :                 break;
   12889                 :           4 :               case OMP_PARALLEL:
   12890                 :           4 :                 error_at (OMP_CLAUSE_LOCATION (c),
   12891                 :             :                           "%<inscan%> %<reduction%> clause on "
   12892                 :             :                           "%qs construct", "parallel");
   12893                 :           4 :                 OMP_CLAUSE_REDUCTION_INSCAN (c) = 0;
   12894                 :           4 :                 break;
   12895                 :           4 :               case OMP_TEAMS:
   12896                 :           4 :                 error_at (OMP_CLAUSE_LOCATION (c),
   12897                 :             :                           "%<inscan%> %<reduction%> clause on "
   12898                 :             :                           "%qs construct", "teams");
   12899                 :           4 :                 OMP_CLAUSE_REDUCTION_INSCAN (c) = 0;
   12900                 :           4 :                 break;
   12901                 :           4 :               case OMP_TASKLOOP:
   12902                 :           4 :                 error_at (OMP_CLAUSE_LOCATION (c),
   12903                 :             :                           "%<inscan%> %<reduction%> clause on "
   12904                 :             :                           "%qs construct", "taskloop");
   12905                 :           4 :                 OMP_CLAUSE_REDUCTION_INSCAN (c) = 0;
   12906                 :           4 :                 break;
   12907                 :           4 :               case OMP_SCOPE:
   12908                 :           4 :                 error_at (OMP_CLAUSE_LOCATION (c),
   12909                 :             :                           "%<inscan%> %<reduction%> clause on "
   12910                 :             :                           "%qs construct", "scope");
   12911                 :           4 :                 OMP_CLAUSE_REDUCTION_INSCAN (c) = 0;
   12912                 :           4 :                 break;
   12913                 :             :               default:
   12914                 :             :                 break;
   12915                 :             :               }
   12916                 :             :           /* FALLTHRU */
   12917                 :       17862 :         case OMP_CLAUSE_IN_REDUCTION:
   12918                 :       17862 :         case OMP_CLAUSE_TASK_REDUCTION:
   12919                 :       17862 :           flags = GOVD_REDUCTION | GOVD_SEEN | GOVD_EXPLICIT;
   12920                 :             :           /* OpenACC permits reductions on private variables.  */
   12921                 :       17862 :           if (!(region_type & ORT_ACC)
   12922                 :             :               /* taskgroup is actually not a worksharing region.  */
   12923                 :       12346 :               && code != OMP_TASKGROUP)
   12924                 :       11816 :             check_non_private = omp_clause_code_name[OMP_CLAUSE_CODE (c)];
   12925                 :       17862 :           decl = OMP_CLAUSE_DECL (c);
   12926                 :       17862 :           if (TREE_CODE (decl) == MEM_REF)
   12927                 :             :             {
   12928                 :        2614 :               tree type = TREE_TYPE (decl);
   12929                 :        2614 :               bool saved_into_ssa = gimplify_ctxp->into_ssa;
   12930                 :        2614 :               gimplify_ctxp->into_ssa = false;
   12931                 :        2614 :               if (gimplify_expr (&TYPE_MAX_VALUE (TYPE_DOMAIN (type)), pre_p,
   12932                 :             :                                  NULL, is_gimple_val, fb_rvalue, false)
   12933                 :             :                   == GS_ERROR)
   12934                 :             :                 {
   12935                 :           0 :                   gimplify_ctxp->into_ssa = saved_into_ssa;
   12936                 :           0 :                   remove = true;
   12937                 :           0 :                   break;
   12938                 :             :                 }
   12939                 :        2614 :               gimplify_ctxp->into_ssa = saved_into_ssa;
   12940                 :        2614 :               tree v = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
   12941                 :        2614 :               if (DECL_P (v))
   12942                 :             :                 {
   12943                 :         571 :                   omp_firstprivatize_variable (ctx, v);
   12944                 :         571 :                   omp_notice_variable (ctx, v, true);
   12945                 :             :                 }
   12946                 :        2614 :               decl = TREE_OPERAND (decl, 0);
   12947                 :        2614 :               if (TREE_CODE (decl) == POINTER_PLUS_EXPR)
   12948                 :             :                 {
   12949                 :         477 :                   gimplify_ctxp->into_ssa = false;
   12950                 :         477 :                   if (gimplify_expr (&TREE_OPERAND (decl, 1), pre_p,
   12951                 :             :                                      NULL, is_gimple_val, fb_rvalue, false)
   12952                 :             :                       == GS_ERROR)
   12953                 :             :                     {
   12954                 :           0 :                       gimplify_ctxp->into_ssa = saved_into_ssa;
   12955                 :           0 :                       remove = true;
   12956                 :           0 :                       break;
   12957                 :             :                     }
   12958                 :         477 :                   gimplify_ctxp->into_ssa = saved_into_ssa;
   12959                 :         477 :                   v = TREE_OPERAND (decl, 1);
   12960                 :         477 :                   if (DECL_P (v))
   12961                 :             :                     {
   12962                 :         477 :                       omp_firstprivatize_variable (ctx, v);
   12963                 :         477 :                       omp_notice_variable (ctx, v, true);
   12964                 :             :                     }
   12965                 :         477 :                   decl = TREE_OPERAND (decl, 0);
   12966                 :             :                 }
   12967                 :        2614 :               if (TREE_CODE (decl) == ADDR_EXPR
   12968                 :        1409 :                   || TREE_CODE (decl) == INDIRECT_REF)
   12969                 :        1375 :                 decl = TREE_OPERAND (decl, 0);
   12970                 :             :             }
   12971                 :       17862 :           goto do_add_decl;
   12972                 :        2678 :         case OMP_CLAUSE_LINEAR:
   12973                 :        2678 :           if (gimplify_expr (&OMP_CLAUSE_LINEAR_STEP (c), pre_p, NULL,
   12974                 :             :                              is_gimple_val, fb_rvalue) == GS_ERROR)
   12975                 :             :             {
   12976                 :             :               remove = true;
   12977                 :             :               break;
   12978                 :             :             }
   12979                 :             :           else
   12980                 :             :             {
   12981                 :        2678 :               if (code == OMP_SIMD
   12982                 :        2678 :                   && !OMP_CLAUSE_LINEAR_NO_COPYIN (c))
   12983                 :             :                 {
   12984                 :        1154 :                   struct gimplify_omp_ctx *octx = outer_ctx;
   12985                 :        1154 :                   if (octx
   12986                 :         741 :                       && octx->region_type == ORT_WORKSHARE
   12987                 :         500 :                       && octx->combined_loop
   12988                 :         500 :                       && !octx->distribute)
   12989                 :             :                     {
   12990                 :         492 :                       if (octx->outer_context
   12991                 :         430 :                           && (octx->outer_context->region_type
   12992                 :             :                               == ORT_COMBINED_PARALLEL))
   12993                 :         393 :                         octx = octx->outer_context->outer_context;
   12994                 :             :                       else
   12995                 :             :                         octx = octx->outer_context;
   12996                 :             :                     }
   12997                 :         905 :                   if (octx
   12998                 :         316 :                       && octx->region_type == ORT_WORKSHARE
   12999                 :          16 :                       && octx->combined_loop
   13000                 :          16 :                       && octx->distribute)
   13001                 :             :                     {
   13002                 :          16 :                       error_at (OMP_CLAUSE_LOCATION (c),
   13003                 :             :                                 "%<linear%> clause for variable other than "
   13004                 :             :                                 "loop iterator specified on construct "
   13005                 :             :                                 "combined with %<distribute%>");
   13006                 :          16 :                       remove = true;
   13007                 :          16 :                       break;
   13008                 :             :                     }
   13009                 :             :                 }
   13010                 :             :               /* For combined #pragma omp parallel for simd, need to put
   13011                 :             :                  lastprivate and perhaps firstprivate too on the
   13012                 :             :                  parallel.  Similarly for #pragma omp for simd.  */
   13013                 :             :               struct gimplify_omp_ctx *octx = outer_ctx;
   13014                 :             :               bool taskloop_seen = false;
   13015                 :             :               decl = NULL_TREE;
   13016                 :        3453 :               do
   13017                 :             :                 {
   13018                 :        3453 :                   if (OMP_CLAUSE_LINEAR_NO_COPYIN (c)
   13019                 :        3453 :                       && OMP_CLAUSE_LINEAR_NO_COPYOUT (c))
   13020                 :             :                     break;
   13021                 :        3393 :                   decl = OMP_CLAUSE_DECL (c);
   13022                 :        3393 :                   if (error_operand_p (decl))
   13023                 :             :                     {
   13024                 :             :                       decl = NULL_TREE;
   13025                 :             :                       break;
   13026                 :             :                     }
   13027                 :        3393 :                   flags = GOVD_SEEN;
   13028                 :        3393 :                   if (!OMP_CLAUSE_LINEAR_NO_COPYIN (c))
   13029                 :        1672 :                     flags |= GOVD_FIRSTPRIVATE;
   13030                 :        3393 :                   if (!OMP_CLAUSE_LINEAR_NO_COPYOUT (c))
   13031                 :        3393 :                     flags |= GOVD_LASTPRIVATE;
   13032                 :        3393 :                   if (octx
   13033                 :        2511 :                       && octx->region_type == ORT_WORKSHARE
   13034                 :        1218 :                       && octx->combined_loop)
   13035                 :             :                     {
   13036                 :        1207 :                       if (octx->outer_context
   13037                 :        1037 :                           && (octx->outer_context->region_type
   13038                 :             :                               == ORT_COMBINED_PARALLEL))
   13039                 :             :                         octx = octx->outer_context;
   13040                 :         476 :                       else if (omp_check_private (octx, decl, false))
   13041                 :             :                         break;
   13042                 :             :                     }
   13043                 :             :                   else if (octx
   13044                 :        1304 :                            && (octx->region_type & ORT_TASK) != 0
   13045                 :         307 :                            && octx->combined_loop)
   13046                 :             :                     taskloop_seen = true;
   13047                 :             :                   else if (octx
   13048                 :        1001 :                            && octx->region_type == ORT_COMBINED_PARALLEL
   13049                 :         301 :                            && ((ctx->region_type == ORT_WORKSHARE
   13050                 :         201 :                                 && octx == outer_ctx)
   13051                 :         100 :                                || taskloop_seen))
   13052                 :             :                     flags = GOVD_SEEN | GOVD_SHARED;
   13053                 :             :                   else if (octx
   13054                 :         700 :                            && ((octx->region_type & ORT_COMBINED_TEAMS)
   13055                 :             :                                == ORT_COMBINED_TEAMS))
   13056                 :             :                     flags = GOVD_SEEN | GOVD_SHARED;
   13057                 :         545 :                   else if (octx
   13058                 :         545 :                            && octx->region_type == ORT_COMBINED_TARGET)
   13059                 :             :                     {
   13060                 :         195 :                       if (flags & GOVD_LASTPRIVATE)
   13061                 :         195 :                         flags = GOVD_SEEN | GOVD_MAP;
   13062                 :             :                     }
   13063                 :             :                   else
   13064                 :             :                     break;
   13065                 :        2071 :                   splay_tree_node on
   13066                 :        2071 :                     = splay_tree_lookup (octx->variables,
   13067                 :             :                                          (splay_tree_key) decl);
   13068                 :        2071 :                   if (on && (on->value & GOVD_DATA_SHARE_CLASS) != 0)
   13069                 :             :                     {
   13070                 :             :                       octx = NULL;
   13071                 :             :                       break;
   13072                 :             :                     }
   13073                 :        2067 :                   omp_add_variable (octx, decl, flags);
   13074                 :        2067 :                   if (octx->outer_context == NULL)
   13075                 :             :                     break;
   13076                 :             :                   octx = octx->outer_context;
   13077                 :             :                 }
   13078                 :             :               while (1);
   13079                 :        2662 :               if (octx
   13080                 :        2662 :                   && decl
   13081                 :        2662 :                   && (!OMP_CLAUSE_LINEAR_NO_COPYIN (c)
   13082                 :         733 :                       || !OMP_CLAUSE_LINEAR_NO_COPYOUT (c)))
   13083                 :        1716 :                 omp_notice_variable (octx, decl, true);
   13084                 :             :             }
   13085                 :        2662 :           flags = GOVD_LINEAR | GOVD_EXPLICIT;
   13086                 :        2662 :           if (OMP_CLAUSE_LINEAR_NO_COPYIN (c)
   13087                 :        2662 :               && OMP_CLAUSE_LINEAR_NO_COPYOUT (c))
   13088                 :             :             {
   13089                 :             :               notice_outer = false;
   13090                 :             :               flags |= GOVD_LINEAR_LASTPRIVATE_NO_OUTER;
   13091                 :             :             }
   13092                 :        2662 :           goto do_add;
   13093                 :             : 
   13094                 :       46855 :         case OMP_CLAUSE_MAP:
   13095                 :       46855 :           if (!grp_start_p)
   13096                 :             :             {
   13097                 :       28397 :               grp_start_p = list_p;
   13098                 :       28397 :               grp_end = (*groups)[grpnum].grp_end;
   13099                 :       28397 :               grpnum++;
   13100                 :             :             }
   13101                 :       46855 :           decl = OMP_CLAUSE_DECL (c);
   13102                 :             : 
   13103                 :       46855 :           if (error_operand_p (decl))
   13104                 :             :             {
   13105                 :             :               remove = true;
   13106                 :             :               break;
   13107                 :             :             }
   13108                 :             : 
   13109                 :       46855 :           if (!omp_parse_expr (addr_tokens, decl))
   13110                 :             :             {
   13111                 :             :               remove = true;
   13112                 :             :               break;
   13113                 :             :             }
   13114                 :             : 
   13115                 :       46855 :           if (remove)
   13116                 :             :             break;
   13117                 :       46855 :           if (DECL_P (decl) && outer_ctx && (region_type & ORT_ACC))
   13118                 :             :             {
   13119                 :             :               struct gimplify_omp_ctx *octx;
   13120                 :        1159 :               for (octx = outer_ctx; octx; octx = octx->outer_context)
   13121                 :             :                 {
   13122                 :        1159 :                   if (octx->region_type != ORT_ACC_HOST_DATA)
   13123                 :             :                     break;
   13124                 :          12 :                   splay_tree_node n2
   13125                 :          12 :                     = splay_tree_lookup (octx->variables,
   13126                 :             :                                          (splay_tree_key) decl);
   13127                 :          12 :                   if (n2)
   13128                 :           4 :                     error_at (OMP_CLAUSE_LOCATION (c), "variable %qE "
   13129                 :             :                               "declared in enclosing %<host_data%> region",
   13130                 :           4 :                               DECL_NAME (decl));
   13131                 :             :                 }
   13132                 :             :             }
   13133                 :             : 
   13134                 :       46855 :           map_descriptor = false;
   13135                 :             : 
   13136                 :             :           /* This condition checks if we're mapping an array descriptor that
   13137                 :             :              isn't inside a derived type -- these have special handling, and
   13138                 :             :              are not handled as structs in omp_build_struct_sibling_lists.
   13139                 :             :              See that function for further details.  */
   13140                 :       46855 :           if (*grp_start_p != grp_end
   13141                 :       31356 :               && OMP_CLAUSE_CHAIN (*grp_start_p)
   13142                 :       78211 :               && OMP_CLAUSE_CHAIN (*grp_start_p) != grp_end)
   13143                 :             :             {
   13144                 :       15296 :               tree grp_mid = OMP_CLAUSE_CHAIN (*grp_start_p);
   13145                 :       15296 :               if (omp_map_clause_descriptor_p (grp_mid)
   13146                 :       28831 :                   && DECL_P (OMP_CLAUSE_DECL (grp_mid)))
   13147                 :             :                 map_descriptor = true;
   13148                 :             :             }
   13149                 :       31559 :           else if (OMP_CLAUSE_CODE (grp_end) == OMP_CLAUSE_MAP
   13150                 :       31559 :                    && (OMP_CLAUSE_MAP_KIND (grp_end) == GOMP_MAP_RELEASE
   13151                 :       30995 :                        || OMP_CLAUSE_MAP_KIND (grp_end) == GOMP_MAP_DELETE)
   13152                 :       32265 :                    && OMP_CLAUSE_RELEASE_DESCRIPTOR (grp_end))
   13153                 :             :             map_descriptor = true;
   13154                 :             : 
   13155                 :             :           /* Adding the decl for a struct access: we haven't created
   13156                 :             :              GOMP_MAP_STRUCT nodes yet, so this statement needs to predict
   13157                 :             :              whether they will be created in gimplify_adjust_omp_clauses.
   13158                 :             :              NOTE: Technically we should probably look through DECL_VALUE_EXPR
   13159                 :             :              here because something that looks like a DECL_P may actually be a
   13160                 :             :              struct access, e.g. variables in a lambda closure
   13161                 :             :              (__closure->__foo) or class members (this->foo). Currently in both
   13162                 :             :              those cases we map the whole of the containing object (directly in
   13163                 :             :              the C++ FE) though, so struct nodes are not created.  */
   13164                 :       46855 :           if (c == grp_end
   13165                 :       28397 :               && addr_tokens[0]->type == STRUCTURE_BASE
   13166                 :        7348 :               && addr_tokens[0]->u.structure_base_kind == BASE_DECL
   13167                 :       54203 :               && !map_descriptor)
   13168                 :             :             {
   13169                 :        4599 :               gcc_assert (addr_tokens[1]->type == ACCESS_METHOD);
   13170                 :             :               /* If we got to this struct via a chain of pointers, maybe we
   13171                 :             :                  want to map it implicitly instead.  */
   13172                 :        4599 :               if (omp_access_chain_p (addr_tokens, 1))
   13173                 :             :                 break;
   13174                 :        4439 :               omp_mapping_group *wholestruct;
   13175                 :        4439 :               if (!(region_type & ORT_ACC)
   13176                 :        7607 :                   && omp_mapped_by_containing_struct (grpmap,
   13177                 :        3168 :                                                       OMP_CLAUSE_DECL (c),
   13178                 :             :                                                       &wholestruct))
   13179                 :             :                 break;
   13180                 :        4268 :               decl = addr_tokens[1]->expr;
   13181                 :        4268 :               if (splay_tree_lookup (ctx->variables, (splay_tree_key) decl))
   13182                 :             :                 break;
   13183                 :             :               /* Standalone attach or detach clauses for a struct element
   13184                 :             :                  should not inhibit implicit mapping of the whole struct.  */
   13185                 :        2657 :               if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
   13186                 :        2657 :                   || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
   13187                 :             :                 break;
   13188                 :        2502 :               flags = GOVD_MAP | GOVD_EXPLICIT;
   13189                 :             : 
   13190                 :        2502 :               gcc_assert (addr_tokens[1]->u.access_kind != ACCESS_DIRECT
   13191                 :             :                           || TREE_ADDRESSABLE (decl));
   13192                 :        2502 :               goto do_add_decl;
   13193                 :             :             }
   13194                 :             : 
   13195                 :       42256 :           if (!DECL_P (decl))
   13196                 :             :             {
   13197                 :       19293 :               tree d = decl, *pd;
   13198                 :       19293 :               if (TREE_CODE (d) == ARRAY_REF)
   13199                 :             :                 {
   13200                 :        4738 :                   while (TREE_CODE (d) == ARRAY_REF)
   13201                 :        2426 :                     d = TREE_OPERAND (d, 0);
   13202                 :        2312 :                   if (TREE_CODE (d) == COMPONENT_REF
   13203                 :        2312 :                       && TREE_CODE (TREE_TYPE (d)) == ARRAY_TYPE)
   13204                 :             :                     decl = d;
   13205                 :             :                 }
   13206                 :       19293 :               pd = &OMP_CLAUSE_DECL (c);
   13207                 :       19293 :               if (d == decl
   13208                 :       17027 :                   && TREE_CODE (decl) == INDIRECT_REF
   13209                 :       12977 :                   && TREE_CODE (TREE_OPERAND (decl, 0)) == COMPONENT_REF
   13210                 :        1011 :                   && (TREE_CODE (TREE_TYPE (TREE_OPERAND (decl, 0)))
   13211                 :             :                       == REFERENCE_TYPE)
   13212                 :       19944 :                   && (OMP_CLAUSE_MAP_KIND (c)
   13213                 :             :                       != GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION))
   13214                 :             :                 {
   13215                 :         647 :                   pd = &TREE_OPERAND (decl, 0);
   13216                 :         647 :                   decl = TREE_OPERAND (decl, 0);
   13217                 :             :                 }
   13218                 :             : 
   13219                 :       19293 :               if (addr_tokens[0]->type == STRUCTURE_BASE
   13220                 :       10061 :                   && addr_tokens[0]->u.structure_base_kind == BASE_DECL
   13221                 :       10061 :                   && addr_tokens[1]->type == ACCESS_METHOD
   13222                 :       10061 :                   && (addr_tokens[1]->u.access_kind == ACCESS_POINTER
   13223                 :        9588 :                       || (addr_tokens[1]->u.access_kind
   13224                 :             :                           == ACCESS_POINTER_OFFSET))
   13225                 :       19842 :                   && GOMP_MAP_ALWAYS_P (OMP_CLAUSE_MAP_KIND (c)))
   13226                 :             :                 {
   13227                 :           0 :                   tree base = addr_tokens[1]->expr;
   13228                 :           0 :                   splay_tree_node n
   13229                 :           0 :                     = splay_tree_lookup (ctx->variables,
   13230                 :             :                                          (splay_tree_key) base);
   13231                 :           0 :                   n->value |= GOVD_SEEN;
   13232                 :             :                 }
   13233                 :             : 
   13234                 :       19293 :               if (code == OMP_TARGET && OMP_CLAUSE_MAP_IN_REDUCTION (c))
   13235                 :             :                 {
   13236                 :             :                   /* Don't gimplify *pd fully at this point, as the base
   13237                 :             :                      will need to be adjusted during omp lowering.  */
   13238                 :          88 :                   auto_vec<tree, 10> expr_stack;
   13239                 :          88 :                   tree *p = pd;
   13240                 :          88 :                   while (handled_component_p (*p)
   13241                 :             :                          || TREE_CODE (*p) == INDIRECT_REF
   13242                 :             :                          || TREE_CODE (*p) == ADDR_EXPR
   13243                 :             :                          || TREE_CODE (*p) == MEM_REF
   13244                 :         224 :                          || TREE_CODE (*p) == NON_LVALUE_EXPR)
   13245                 :             :                     {
   13246                 :         136 :                       expr_stack.safe_push (*p);
   13247                 :         136 :                       p = &TREE_OPERAND (*p, 0);
   13248                 :             :                     }
   13249                 :         312 :                   for (int i = expr_stack.length () - 1; i >= 0; i--)
   13250                 :             :                     {
   13251                 :         136 :                       tree t = expr_stack[i];
   13252                 :         136 :                       if (TREE_CODE (t) == ARRAY_REF
   13253                 :         136 :                           || TREE_CODE (t) == ARRAY_RANGE_REF)
   13254                 :             :                         {
   13255                 :          56 :                           if (TREE_OPERAND (t, 2) == NULL_TREE)
   13256                 :             :                             {
   13257                 :          56 :                               tree low = unshare_expr (array_ref_low_bound (t));
   13258                 :          56 :                               if (!is_gimple_min_invariant (low))
   13259                 :             :                                 {
   13260                 :           0 :                                   TREE_OPERAND (t, 2) = low;
   13261                 :           0 :                                   if (gimplify_expr (&TREE_OPERAND (t, 2),
   13262                 :             :                                                      pre_p, NULL,
   13263                 :             :                                                      is_gimple_reg,
   13264                 :             :                                                      fb_rvalue) == GS_ERROR)
   13265                 :           0 :                                     remove = true;
   13266                 :             :                                 }
   13267                 :             :                             }
   13268                 :           0 :                           else if (gimplify_expr (&TREE_OPERAND (t, 2), pre_p,
   13269                 :             :                                                   NULL, is_gimple_reg,
   13270                 :             :                                                   fb_rvalue) == GS_ERROR)
   13271                 :           0 :                             remove = true;
   13272                 :          56 :                           if (TREE_OPERAND (t, 3) == NULL_TREE)
   13273                 :             :                             {
   13274                 :          56 :                               tree elmt_size = array_ref_element_size (t);
   13275                 :          56 :                               if (!is_gimple_min_invariant (elmt_size))
   13276                 :             :                                 {
   13277                 :           0 :                                   elmt_size = unshare_expr (elmt_size);
   13278                 :           0 :                                   tree elmt_type
   13279                 :           0 :                                     = TREE_TYPE (TREE_TYPE (TREE_OPERAND (t,
   13280                 :             :                                                                           0)));
   13281                 :           0 :                                   tree factor
   13282                 :           0 :                                     = size_int (TYPE_ALIGN_UNIT (elmt_type));
   13283                 :           0 :                                   elmt_size
   13284                 :           0 :                                     = size_binop (EXACT_DIV_EXPR, elmt_size,
   13285                 :             :                                                   factor);
   13286                 :           0 :                                   TREE_OPERAND (t, 3) = elmt_size;
   13287                 :           0 :                                   if (gimplify_expr (&TREE_OPERAND (t, 3),
   13288                 :             :                                                      pre_p, NULL,
   13289                 :             :                                                      is_gimple_reg,
   13290                 :             :                                                      fb_rvalue) == GS_ERROR)
   13291                 :           0 :                                     remove = true;
   13292                 :             :                                 }
   13293                 :             :                             }
   13294                 :           0 :                           else if (gimplify_expr (&TREE_OPERAND (t, 3), pre_p,
   13295                 :             :                                                   NULL, is_gimple_reg,
   13296                 :             :                                                   fb_rvalue) == GS_ERROR)
   13297                 :           0 :                             remove = true;
   13298                 :             :                         }
   13299                 :          80 :                       else if (TREE_CODE (t) == COMPONENT_REF)
   13300                 :             :                         {
   13301                 :           0 :                           if (TREE_OPERAND (t, 2) == NULL_TREE)
   13302                 :             :                             {
   13303                 :           0 :                               tree offset = component_ref_field_offset (t);
   13304                 :           0 :                               if (!is_gimple_min_invariant (offset))
   13305                 :             :                                 {
   13306                 :           0 :                                   offset = unshare_expr (offset);
   13307                 :           0 :                                   tree field = TREE_OPERAND (t, 1);
   13308                 :           0 :                                   tree factor
   13309                 :           0 :                                     = size_int (DECL_OFFSET_ALIGN (field)
   13310                 :             :                                                 / BITS_PER_UNIT);
   13311                 :           0 :                                   offset = size_binop (EXACT_DIV_EXPR, offset,
   13312                 :             :                                                        factor);
   13313                 :           0 :                                   TREE_OPERAND (t, 2) = offset;
   13314                 :           0 :                                   if (gimplify_expr (&TREE_OPERAND (t, 2),
   13315                 :             :                                                      pre_p, NULL,
   13316                 :             :                                                      is_gimple_reg,
   13317                 :             :                                                      fb_rvalue) == GS_ERROR)
   13318                 :           0 :                                     remove = true;
   13319                 :             :                                 }
   13320                 :             :                             }
   13321                 :           0 :                           else if (gimplify_expr (&TREE_OPERAND (t, 2), pre_p,
   13322                 :             :                                                   NULL, is_gimple_reg,
   13323                 :             :                                                   fb_rvalue) == GS_ERROR)
   13324                 :           0 :                             remove = true;
   13325                 :             :                         }
   13326                 :             :                     }
   13327                 :         224 :                   for (; expr_stack.length () > 0; )
   13328                 :             :                     {
   13329                 :         136 :                       tree t = expr_stack.pop ();
   13330                 :             : 
   13331                 :         136 :                       if (TREE_CODE (t) == ARRAY_REF
   13332                 :         136 :                           || TREE_CODE (t) == ARRAY_RANGE_REF)
   13333                 :             :                         {
   13334                 :          56 :                           if (!is_gimple_min_invariant (TREE_OPERAND (t, 1))
   13335                 :          56 :                               && gimplify_expr (&TREE_OPERAND (t, 1), pre_p,
   13336                 :             :                                                 NULL, is_gimple_val,
   13337                 :             :                                                 fb_rvalue) == GS_ERROR)
   13338                 :         144 :                             remove = true;
   13339                 :             :                         }
   13340                 :             :                     }
   13341                 :          88 :                 }
   13342                 :             :               break;
   13343                 :             :             }
   13344                 :             : 
   13345                 :       22963 :           if ((code == OMP_TARGET
   13346                 :             :                || code == OMP_TARGET_DATA
   13347                 :             :                || code == OMP_TARGET_ENTER_DATA
   13348                 :       13965 :                || code == OMP_TARGET_EXIT_DATA)
   13349                 :       23465 :               && OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH_DETACH)
   13350                 :             :             {
   13351                 :             :               /* If we have attach/detach but the decl we have is a pointer to
   13352                 :             :                  pointer, we're probably mapping the "base level" array
   13353                 :             :                  implicitly.  Make sure we don't add the decl as if we mapped
   13354                 :             :                  it explicitly.  That is,
   13355                 :             : 
   13356                 :             :                    int **arr;
   13357                 :             :                    [...]
   13358                 :             :                    #pragma omp target map(arr[a][b:c])
   13359                 :             : 
   13360                 :             :                  should *not* map "arr" explicitly.  That way we get a
   13361                 :             :                  zero-length "alloc" mapping for it, and assuming it's been
   13362                 :             :                  mapped by some previous directive, etc., things work as they
   13363                 :             :                  should.  */
   13364                 :             : 
   13365                 :         178 :               tree basetype = TREE_TYPE (addr_tokens[0]->expr);
   13366                 :             : 
   13367                 :         178 :               if (TREE_CODE (basetype) == REFERENCE_TYPE)
   13368                 :          34 :                 basetype = TREE_TYPE (basetype);
   13369                 :             : 
   13370                 :         178 :               if (code == OMP_TARGET
   13371                 :          42 :                   && addr_tokens[0]->type == ARRAY_BASE
   13372                 :          42 :                   && addr_tokens[0]->u.structure_base_kind == BASE_DECL
   13373                 :          42 :                   && TREE_CODE (basetype) == POINTER_TYPE
   13374                 :         220 :                   && TREE_CODE (TREE_TYPE (basetype)) == POINTER_TYPE)
   13375                 :             :                 break;
   13376                 :             :             }
   13377                 :             : 
   13378                 :       22953 :           flags = GOVD_MAP | GOVD_EXPLICIT;
   13379                 :       22953 :           if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ALWAYS_TO
   13380                 :       22842 :               || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ALWAYS_TOFROM
   13381                 :       22340 :               || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ALWAYS_PRESENT_TO
   13382                 :       45267 :               || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ALWAYS_PRESENT_TOFROM)
   13383                 :             :             flags |= GOVD_MAP_ALWAYS_TO;
   13384                 :             : 
   13385                 :       22953 :           goto do_add;
   13386                 :             : 
   13387                 :         468 :         case OMP_CLAUSE_AFFINITY:
   13388                 :         468 :           gimplify_omp_affinity (list_p, pre_p);
   13389                 :         468 :           remove = true;
   13390                 :         468 :           break;
   13391                 :           8 :         case OMP_CLAUSE_DOACROSS:
   13392                 :           8 :           if (OMP_CLAUSE_DOACROSS_KIND (c) == OMP_CLAUSE_DOACROSS_SINK)
   13393                 :             :             {
   13394                 :           4 :               tree deps = OMP_CLAUSE_DECL (c);
   13395                 :           8 :               while (deps && TREE_CODE (deps) == TREE_LIST)
   13396                 :             :                 {
   13397                 :           4 :                   if (TREE_CODE (TREE_PURPOSE (deps)) == TRUNC_DIV_EXPR
   13398                 :           4 :                       && DECL_P (TREE_OPERAND (TREE_PURPOSE (deps), 1)))
   13399                 :           0 :                     gimplify_expr (&TREE_OPERAND (TREE_PURPOSE (deps), 1),
   13400                 :             :                                    pre_p, NULL, is_gimple_val, fb_rvalue);
   13401                 :           4 :                   deps = TREE_CHAIN (deps);
   13402                 :             :                 }
   13403                 :             :             }
   13404                 :             :           else
   13405                 :           4 :             gcc_assert (OMP_CLAUSE_DOACROSS_KIND (c)
   13406                 :             :                         == OMP_CLAUSE_DOACROSS_SOURCE);
   13407                 :             :           break;
   13408                 :        2108 :         case OMP_CLAUSE_DEPEND:
   13409                 :        2108 :           if (handled_depend_iterators == -1)
   13410                 :        1806 :             handled_depend_iterators = gimplify_omp_depend (list_p, pre_p);
   13411                 :        2108 :           if (handled_depend_iterators)
   13412                 :             :             {
   13413                 :         343 :               if (handled_depend_iterators == 2)
   13414                 :           0 :                 remove = true;
   13415                 :             :               break;
   13416                 :             :             }
   13417                 :        1765 :           if (TREE_CODE (OMP_CLAUSE_DECL (c)) == COMPOUND_EXPR)
   13418                 :             :             {
   13419                 :           0 :               gimplify_expr (&TREE_OPERAND (OMP_CLAUSE_DECL (c), 0), pre_p,
   13420                 :             :                              NULL, is_gimple_val, fb_rvalue);
   13421                 :           0 :               OMP_CLAUSE_DECL (c) = TREE_OPERAND (OMP_CLAUSE_DECL (c), 1);
   13422                 :             :             }
   13423                 :        1765 :           if (error_operand_p (OMP_CLAUSE_DECL (c)))
   13424                 :             :             {
   13425                 :             :               remove = true;
   13426                 :             :               break;
   13427                 :             :             }
   13428                 :        1765 :           if (OMP_CLAUSE_DECL (c) != null_pointer_node)
   13429                 :             :             {
   13430                 :        1734 :               OMP_CLAUSE_DECL (c) = build_fold_addr_expr (OMP_CLAUSE_DECL (c));
   13431                 :        1734 :               if (gimplify_expr (&OMP_CLAUSE_DECL (c), pre_p, NULL,
   13432                 :             :                                  is_gimple_val, fb_rvalue) == GS_ERROR)
   13433                 :             :                 {
   13434                 :             :                   remove = true;
   13435                 :             :                   break;
   13436                 :             :                 }
   13437                 :             :             }
   13438                 :        1765 :           if (code == OMP_TASK)
   13439                 :        1396 :             ctx->has_depend = true;
   13440                 :             :           break;
   13441                 :             : 
   13442                 :        8188 :         case OMP_CLAUSE_TO:
   13443                 :        8188 :         case OMP_CLAUSE_FROM:
   13444                 :        8188 :         case OMP_CLAUSE__CACHE_:
   13445                 :        8188 :           decl = OMP_CLAUSE_DECL (c);
   13446                 :        8188 :           if (error_operand_p (decl))
   13447                 :             :             {
   13448                 :             :               remove = true;
   13449                 :             :               break;
   13450                 :             :             }
   13451                 :        8188 :           if (OMP_CLAUSE_SIZE (c) == NULL_TREE)
   13452                 :        7429 :             OMP_CLAUSE_SIZE (c) = DECL_P (decl) ? DECL_SIZE_UNIT (decl)
   13453                 :         684 :                                   : TYPE_SIZE_UNIT (TREE_TYPE (decl));
   13454                 :        8188 :           if (gimplify_expr (&OMP_CLAUSE_SIZE (c), pre_p,
   13455                 :             :                              NULL, is_gimple_val, fb_rvalue) == GS_ERROR)
   13456                 :             :             {
   13457                 :             :               remove = true;
   13458                 :             :               break;
   13459                 :             :             }
   13460                 :        8188 :           if (!DECL_P (decl))
   13461                 :             :             {
   13462                 :        2007 :               if (gimplify_expr (&OMP_CLAUSE_DECL (c), pre_p,
   13463                 :             :                                  NULL, is_gimple_lvalue, fb_lvalue)
   13464                 :             :                   == GS_ERROR)
   13465                 :             :                 {
   13466                 :           0 :                   remove = true;
   13467                 :             :                   break;
   13468                 :             :                 }
   13469                 :             :               break;
   13470                 :             :             }
   13471                 :        6181 :           goto do_notice;
   13472                 :             : 
   13473                 :        2118 :         case OMP_CLAUSE_USE_DEVICE_PTR:
   13474                 :        2118 :         case OMP_CLAUSE_USE_DEVICE_ADDR:
   13475                 :        2118 :           flags = GOVD_EXPLICIT;
   13476                 :        2118 :           goto do_add;
   13477                 :             : 
   13478                 :         543 :         case OMP_CLAUSE_HAS_DEVICE_ADDR:
   13479                 :         543 :           decl = OMP_CLAUSE_DECL (c);
   13480                 :         543 :           while (TREE_CODE (decl) == INDIRECT_REF
   13481                 :         592 :                  || TREE_CODE (decl) == ARRAY_REF)
   13482                 :          49 :             decl = TREE_OPERAND (decl, 0);
   13483                 :         543 :           flags = GOVD_EXPLICIT;
   13484                 :         543 :           goto do_add_decl;
   13485                 :             : 
   13486                 :         481 :         case OMP_CLAUSE_IS_DEVICE_PTR:
   13487                 :         481 :           flags = GOVD_FIRSTPRIVATE | GOVD_EXPLICIT;
   13488                 :         481 :           goto do_add;
   13489                 :             : 
   13490                 :       61304 :         do_add:
   13491                 :       61304 :           decl = OMP_CLAUSE_DECL (c);
   13492                 :       82211 :         do_add_decl:
   13493                 :       82211 :           if (error_operand_p (decl))
   13494                 :             :             {
   13495                 :             :               remove = true;
   13496                 :             :               break;
   13497                 :             :             }
   13498                 :       82203 :           if (DECL_NAME (decl) == NULL_TREE && (flags & GOVD_SHARED) == 0)
   13499                 :             :             {
   13500                 :        1776 :               tree t = omp_member_access_dummy_var (decl);
   13501                 :        1776 :               if (t)
   13502                 :             :                 {
   13503                 :         662 :                   tree v = DECL_VALUE_EXPR (decl);
   13504                 :         662 :                   DECL_NAME (decl) = DECL_NAME (TREE_OPERAND (v, 1));
   13505                 :         662 :                   if (outer_ctx)
   13506                 :         134 :                     omp_notice_variable (outer_ctx, t, true);
   13507                 :             :                 }
   13508                 :             :             }
   13509                 :       82203 :           if (code == OACC_DATA
   13510                 :        2402 :               && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   13511                 :       84605 :               && OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FIRSTPRIVATE_POINTER)
   13512                 :         308 :             flags |= GOVD_MAP_0LEN_ARRAY;
   13513                 :       82203 :           omp_add_variable (ctx, decl, flags);
   13514                 :       82203 :           if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   13515                 :       66941 :                || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
   13516                 :       64871 :                || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
   13517                 :       84803 :               && OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
   13518                 :             :             {
   13519                 :        4294 :               struct gimplify_omp_ctx *pctx
   13520                 :        2147 :                 = code == OMP_TARGET ? outer_ctx : ctx;
   13521                 :        2147 :               if (pctx)
   13522                 :        2117 :                 omp_add_variable (pctx, OMP_CLAUSE_REDUCTION_PLACEHOLDER (c),
   13523                 :             :                                   GOVD_LOCAL | GOVD_SEEN);
   13524                 :        2117 :               if (pctx
   13525                 :        2117 :                   && OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c)
   13526                 :         632 :                   && walk_tree (&OMP_CLAUSE_REDUCTION_INIT (c),
   13527                 :             :                                 find_decl_expr,
   13528                 :             :                                 OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c),
   13529                 :             :                                 NULL) == NULL_TREE)
   13530                 :         208 :                 omp_add_variable (pctx,
   13531                 :         208 :                                   OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c),
   13532                 :             :                                   GOVD_LOCAL | GOVD_SEEN);
   13533                 :        2147 :               gimplify_omp_ctxp = pctx;
   13534                 :        2147 :               push_gimplify_context ();
   13535                 :             : 
   13536                 :        2147 :               OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c) = NULL;
   13537                 :        2147 :               OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c) = NULL;
   13538                 :             : 
   13539                 :        2147 :               gimplify_and_add (OMP_CLAUSE_REDUCTION_INIT (c),
   13540                 :        2147 :                                 &OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c));
   13541                 :        2147 :               pop_gimplify_context
   13542                 :        2147 :                 (gimple_seq_first_stmt (OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c)));
   13543                 :        2147 :               push_gimplify_context ();
   13544                 :        4294 :               gimplify_and_add (OMP_CLAUSE_REDUCTION_MERGE (c),
   13545                 :        2147 :                                 &OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c));
   13546                 :        2147 :               pop_gimplify_context
   13547                 :        2147 :                 (gimple_seq_first_stmt (OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c)));
   13548                 :        2147 :               OMP_CLAUSE_REDUCTION_INIT (c) = NULL_TREE;
   13549                 :        2147 :               OMP_CLAUSE_REDUCTION_MERGE (c) = NULL_TREE;
   13550                 :             : 
   13551                 :        2147 :               gimplify_omp_ctxp = outer_ctx;
   13552                 :             :             }
   13553                 :       80056 :           else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
   13554                 :       80056 :                    && OMP_CLAUSE_LASTPRIVATE_STMT (c))
   13555                 :             :             {
   13556                 :         303 :               gimplify_omp_ctxp = ctx;
   13557                 :         303 :               push_gimplify_context ();
   13558                 :         303 :               if (TREE_CODE (OMP_CLAUSE_LASTPRIVATE_STMT (c)) != BIND_EXPR)
   13559                 :             :                 {
   13560                 :         303 :                   tree bind = build3 (BIND_EXPR, void_type_node, NULL,
   13561                 :             :                                       NULL, NULL);
   13562                 :         303 :                   TREE_SIDE_EFFECTS (bind) = 1;
   13563                 :         303 :                   BIND_EXPR_BODY (bind) = OMP_CLAUSE_LASTPRIVATE_STMT (c);
   13564                 :         303 :                   OMP_CLAUSE_LASTPRIVATE_STMT (c) = bind;
   13565                 :             :                 }
   13566                 :         606 :               gimplify_and_add (OMP_CLAUSE_LASTPRIVATE_STMT (c),
   13567                 :         303 :                                 &OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (c));
   13568                 :         303 :               pop_gimplify_context
   13569                 :         303 :                 (gimple_seq_first_stmt (OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (c)));
   13570                 :         303 :               OMP_CLAUSE_LASTPRIVATE_STMT (c) = NULL_TREE;
   13571                 :             : 
   13572                 :         303 :               gimplify_omp_ctxp = outer_ctx;
   13573                 :             :             }
   13574                 :       79753 :           else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR
   13575                 :       79753 :                    && OMP_CLAUSE_LINEAR_STMT (c))
   13576                 :             :             {
   13577                 :          60 :               gimplify_omp_ctxp = ctx;
   13578                 :          60 :               push_gimplify_context ();
   13579                 :          60 :               if (TREE_CODE (OMP_CLAUSE_LINEAR_STMT (c)) != BIND_EXPR)
   13580                 :             :                 {
   13581                 :          60 :                   tree bind = build3 (BIND_EXPR, void_type_node, NULL,
   13582                 :             :                                       NULL, NULL);
   13583                 :          60 :                   TREE_SIDE_EFFECTS (bind) = 1;
   13584                 :          60 :                   BIND_EXPR_BODY (bind) = OMP_CLAUSE_LINEAR_STMT (c);
   13585                 :          60 :                   OMP_CLAUSE_LINEAR_STMT (c) = bind;
   13586                 :             :                 }
   13587                 :         120 :               gimplify_and_add (OMP_CLAUSE_LINEAR_STMT (c),
   13588                 :          60 :                                 &OMP_CLAUSE_LINEAR_GIMPLE_SEQ (c));
   13589                 :          60 :               pop_gimplify_context
   13590                 :          60 :                 (gimple_seq_first_stmt (OMP_CLAUSE_LINEAR_GIMPLE_SEQ (c)));
   13591                 :          60 :               OMP_CLAUSE_LINEAR_STMT (c) = NULL_TREE;
   13592                 :             : 
   13593                 :          60 :               gimplify_omp_ctxp = outer_ctx;
   13594                 :             :             }
   13595                 :       82203 :           if (notice_outer)
   13596                 :       70119 :             goto do_notice;
   13597                 :             :           break;
   13598                 :             : 
   13599                 :         906 :         case OMP_CLAUSE_COPYIN:
   13600                 :         906 :         case OMP_CLAUSE_COPYPRIVATE:
   13601                 :         906 :           decl = OMP_CLAUSE_DECL (c);
   13602                 :         906 :           if (error_operand_p (decl))
   13603                 :             :             {
   13604                 :             :               remove = true;
   13605                 :             :               break;
   13606                 :             :             }
   13607                 :         906 :           if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_COPYPRIVATE
   13608                 :             :               && !remove
   13609                 :         906 :               && !omp_check_private (ctx, decl, true))
   13610                 :             :             {
   13611                 :          35 :               remove = true;
   13612                 :          35 :               if (is_global_var (decl))
   13613                 :             :                 {
   13614                 :          30 :                   if (DECL_THREAD_LOCAL_P (decl))
   13615                 :             :                     remove = false;
   13616                 :          10 :                   else if (DECL_HAS_VALUE_EXPR_P (decl))
   13617                 :             :                     {
   13618                 :           2 :                       tree value = get_base_address (DECL_VALUE_EXPR (decl));
   13619                 :             : 
   13620                 :           2 :                       if (value
   13621                 :           2 :                           && DECL_P (value)
   13622                 :           4 :                           && DECL_THREAD_LOCAL_P (value))
   13623                 :             :                         remove = false;
   13624                 :             :                     }
   13625                 :             :                 }
   13626                 :             :               if (remove)
   13627                 :          13 :                 error_at (OMP_CLAUSE_LOCATION (c),
   13628                 :             :                           "copyprivate variable %qE is not threadprivate"
   13629                 :          13 :                           " or private in outer context", DECL_NAME (decl));
   13630                 :             :             }
   13631                 :       77206 :         do_notice:
   13632                 :       77206 :           if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   13633                 :       61944 :                || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
   13634                 :       54068 :                || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE)
   13635                 :       30463 :               && outer_ctx
   13636                 :       17529 :               && ((region_type & ORT_TASKLOOP) == ORT_TASKLOOP
   13637                 :       16202 :                    || (region_type == ORT_WORKSHARE
   13638                 :        3884 :                        && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   13639                 :        1087 :                        && (OMP_CLAUSE_REDUCTION_INSCAN (c)
   13640                 :         912 :                            || code == OMP_LOOP)))
   13641                 :       79139 :               && (outer_ctx->region_type == ORT_COMBINED_PARALLEL
   13642                 :         845 :                   || (code == OMP_LOOP
   13643                 :         138 :                       && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   13644                 :         138 :                       && ((outer_ctx->region_type & ORT_COMBINED_TEAMS)
   13645                 :             :                           == ORT_COMBINED_TEAMS))))
   13646                 :             :             {
   13647                 :        1209 :               splay_tree_node on
   13648                 :        1209 :                 = splay_tree_lookup (outer_ctx->variables,
   13649                 :             :                                      (splay_tree_key)decl);
   13650                 :        1209 :               if (on == NULL || (on->value & GOVD_DATA_SHARE_CLASS) == 0)
   13651                 :             :                 {
   13652                 :         891 :                   if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   13653                 :         705 :                       && TREE_CODE (OMP_CLAUSE_DECL (c)) == MEM_REF
   13654                 :        1003 :                       && (TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE
   13655                 :          56 :                           || (TREE_CODE (TREE_TYPE (decl)) == REFERENCE_TYPE
   13656                 :           0 :                               && (TREE_CODE (TREE_TYPE (TREE_TYPE (decl)))
   13657                 :             :                                   == POINTER_TYPE))))
   13658                 :          56 :                     omp_firstprivatize_variable (outer_ctx, decl);
   13659                 :             :                   else
   13660                 :             :                     {
   13661                 :         835 :                       omp_add_variable (outer_ctx, decl,
   13662                 :             :                                         GOVD_SEEN | GOVD_SHARED);
   13663                 :         835 :                       if (outer_ctx->outer_context)
   13664                 :         235 :                         omp_notice_variable (outer_ctx->outer_context, decl,
   13665                 :             :                                              true);
   13666                 :             :                     }
   13667                 :             :                 }
   13668                 :             :             }
   13669                 :       76606 :           if (outer_ctx)
   13670                 :       29549 :             omp_notice_variable (outer_ctx, decl, true);
   13671                 :       77206 :           if (check_non_private
   13672                 :       26666 :               && (region_type == ORT_WORKSHARE || code == OMP_SCOPE)
   13673                 :        4747 :               && (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
   13674                 :        1641 :                   || decl == OMP_CLAUSE_DECL (c)
   13675                 :         224 :                   || (TREE_CODE (OMP_CLAUSE_DECL (c)) == MEM_REF
   13676                 :         224 :                       && (TREE_CODE (TREE_OPERAND (OMP_CLAUSE_DECL (c), 0))
   13677                 :             :                           == ADDR_EXPR
   13678                 :         113 :                           || (TREE_CODE (TREE_OPERAND (OMP_CLAUSE_DECL (c), 0))
   13679                 :             :                               == POINTER_PLUS_EXPR
   13680                 :          22 :                               && (TREE_CODE (TREE_OPERAND (TREE_OPERAND
   13681                 :             :                                                 (OMP_CLAUSE_DECL (c), 0), 0))
   13682                 :             :                                   == ADDR_EXPR)))))
   13683                 :       81851 :               && omp_check_private (ctx, decl, false))
   13684                 :             :             {
   13685                 :          58 :               error ("%s variable %qE is private in outer context",
   13686                 :          29 :                      check_non_private, DECL_NAME (decl));
   13687                 :          29 :               remove = true;
   13688                 :             :             }
   13689                 :             :           break;
   13690                 :             : 
   13691                 :         190 :         case OMP_CLAUSE_DETACH:
   13692                 :         190 :           flags = GOVD_FIRSTPRIVATE | GOVD_SEEN;
   13693                 :         190 :           goto do_add;
   13694                 :             : 
   13695                 :        4092 :         case OMP_CLAUSE_IF:
   13696                 :        4092 :           if (OMP_CLAUSE_IF_MODIFIER (c) != ERROR_MARK
   13697                 :        4092 :               && OMP_CLAUSE_IF_MODIFIER (c) != code)
   13698                 :             :             {
   13699                 :             :               const char *p[2];
   13700                 :         168 :               for (int i = 0; i < 2; i++)
   13701                 :         112 :                 switch (i ? OMP_CLAUSE_IF_MODIFIER (c) : code)
   13702                 :             :                   {
   13703                 :           8 :                   case VOID_CST: p[i] = "cancel"; break;
   13704                 :          24 :                   case OMP_PARALLEL: p[i] = "parallel"; break;
   13705                 :           4 :                   case OMP_SIMD: p[i] = "simd"; break;
   13706                 :          12 :                   case OMP_TASK: p[i] = "task"; break;
   13707                 :          12 :                   case OMP_TASKLOOP: p[i] = "taskloop"; break;
   13708                 :           8 :                   case OMP_TARGET_DATA: p[i] = "target data"; break;
   13709                 :          12 :                   case OMP_TARGET: p[i] = "target"; break;
   13710                 :          12 :                   case OMP_TARGET_UPDATE: p[i] = "target update"; break;
   13711                 :           8 :                   case OMP_TARGET_ENTER_DATA:
   13712                 :           8 :                     p[i] = "target enter data"; break;
   13713                 :          12 :                   case OMP_TARGET_EXIT_DATA: p[i] = "target exit data"; break;
   13714                 :           0 :                   default: gcc_unreachable ();
   13715                 :             :                   }
   13716                 :          56 :               error_at (OMP_CLAUSE_LOCATION (c),
   13717                 :             :                         "expected %qs %<if%> clause modifier rather than %qs",
   13718                 :             :                         p[0], p[1]);
   13719                 :          56 :               remove = true;
   13720                 :             :             }
   13721                 :             :           /* Fall through.  */
   13722                 :             : 
   13723                 :        4798 :         case OMP_CLAUSE_SELF:
   13724                 :        4798 :         case OMP_CLAUSE_FINAL:
   13725                 :        9596 :           OMP_CLAUSE_OPERAND (c, 0)
   13726                 :        4798 :             = gimple_boolify (OMP_CLAUSE_OPERAND (c, 0));
   13727                 :             :           /* Fall through.  */
   13728                 :             : 
   13729                 :        5718 :         case OMP_CLAUSE_NUM_TEAMS:
   13730                 :        5718 :           if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NUM_TEAMS
   13731                 :         920 :               && OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c)
   13732                 :        5963 :               && !is_gimple_min_invariant (OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c)))
   13733                 :             :             {
   13734                 :         208 :               if (error_operand_p (OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c)))
   13735                 :             :                 {
   13736                 :             :                   remove = true;
   13737                 :             :                   break;
   13738                 :             :                 }
   13739                 :         208 :               OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c)
   13740                 :         416 :                 = get_initialized_tmp_var (OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c),
   13741                 :             :                                            pre_p, NULL, true);
   13742                 :             :             }
   13743                 :             :           /* Fall through.  */
   13744                 :             : 
   13745                 :       21682 :         case OMP_CLAUSE_SCHEDULE:
   13746                 :       21682 :         case OMP_CLAUSE_NUM_THREADS:
   13747                 :       21682 :         case OMP_CLAUSE_THREAD_LIMIT:
   13748                 :       21682 :         case OMP_CLAUSE_DIST_SCHEDULE:
   13749                 :       21682 :         case OMP_CLAUSE_DEVICE:
   13750                 :       21682 :           if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEVICE
   13751                 :       21682 :               && OMP_CLAUSE_DEVICE_ANCESTOR (c))
   13752                 :             :             {
   13753                 :         125 :               if (code != OMP_TARGET)
   13754                 :             :                 {
   13755                 :          20 :                   error_at (OMP_CLAUSE_LOCATION (c),
   13756                 :             :                             "%<device%> clause with %<ancestor%> is only "
   13757                 :             :                             "allowed on %<target%> construct");
   13758                 :          20 :                   remove = true;
   13759                 :          20 :                   break;
   13760                 :             :                 }
   13761                 :             : 
   13762                 :         105 :               tree clauses = *orig_list_p;
   13763                 :         330 :               for (; clauses ; clauses = OMP_CLAUSE_CHAIN (clauses))
   13764                 :         236 :                 if (OMP_CLAUSE_CODE (clauses) != OMP_CLAUSE_DEVICE
   13765                 :             :                     && OMP_CLAUSE_CODE (clauses) != OMP_CLAUSE_FIRSTPRIVATE
   13766                 :             :                     && OMP_CLAUSE_CODE (clauses) != OMP_CLAUSE_PRIVATE
   13767                 :             :                     && OMP_CLAUSE_CODE (clauses) != OMP_CLAUSE_DEFAULTMAP
   13768                 :             :                     && OMP_CLAUSE_CODE (clauses) != OMP_CLAUSE_MAP
   13769                 :             :                    )
   13770                 :             :                   {
   13771                 :          11 :                     error_at (OMP_CLAUSE_LOCATION (c),
   13772                 :             :                               "with %<ancestor%>, only the %<device%>, "
   13773                 :             :                               "%<firstprivate%>, %<private%>, %<defaultmap%>, "
   13774                 :             :                               "and %<map%> clauses may appear on the "
   13775                 :             :                               "construct");
   13776                 :          11 :                     remove = true;
   13777                 :          11 :                     break;
   13778                 :             :                   }
   13779                 :             :             }
   13780                 :       21557 :           else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEVICE
   13781                 :       21557 :                    && code == OMP_DISPATCH)
   13782                 :             :             {
   13783                 :         265 :               bool saved_into_ssa = gimplify_ctxp->into_ssa;
   13784                 :         265 :               gimplify_ctxp->into_ssa = false;
   13785                 :         265 :               if (gimplify_expr (&OMP_CLAUSE_DEVICE_ID (c), pre_p, NULL,
   13786                 :             :                                  is_gimple_val, fb_rvalue)
   13787                 :             :                   == GS_ERROR)
   13788                 :             :                 remove = true;
   13789                 :         265 :               else if (DECL_P (OMP_CLAUSE_DEVICE_ID (c)))
   13790                 :          49 :                 omp_add_variable (ctx, OMP_CLAUSE_DEVICE_ID (c),
   13791                 :             :                                   GOVD_SHARED | GOVD_SEEN);
   13792                 :         265 :               gimplify_ctxp->into_ssa = saved_into_ssa;
   13793                 :         265 :               break;
   13794                 :             :             }
   13795                 :             :           /* Fall through.  */
   13796                 :             : 
   13797                 :       31119 :         case OMP_CLAUSE_PRIORITY:
   13798                 :       31119 :         case OMP_CLAUSE_GRAINSIZE:
   13799                 :       31119 :         case OMP_CLAUSE_NUM_TASKS:
   13800                 :       31119 :         case OMP_CLAUSE_FILTER:
   13801                 :       31119 :         case OMP_CLAUSE_HINT:
   13802                 :       31119 :         case OMP_CLAUSE_ASYNC:
   13803                 :       31119 :         case OMP_CLAUSE_WAIT:
   13804                 :       31119 :         case OMP_CLAUSE_NUM_GANGS:
   13805                 :       31119 :         case OMP_CLAUSE_NUM_WORKERS:
   13806                 :       31119 :         case OMP_CLAUSE_VECTOR_LENGTH:
   13807                 :       31119 :         case OMP_CLAUSE_WORKER:
   13808                 :       31119 :         case OMP_CLAUSE_VECTOR:
   13809                 :       31119 :           if (OMP_CLAUSE_OPERAND (c, 0)
   13810                 :       31119 :               && !is_gimple_min_invariant (OMP_CLAUSE_OPERAND (c, 0)))
   13811                 :             :             {
   13812                 :        7690 :               if (error_operand_p (OMP_CLAUSE_OPERAND (c, 0)))
   13813                 :             :                 {
   13814                 :             :                   remove = true;
   13815                 :             :                   break;
   13816                 :             :                 }
   13817                 :             :               /* All these clauses care about value, not a particular decl,
   13818                 :             :                  so try to force it into a SSA_NAME or fresh temporary.  */
   13819                 :       15366 :               OMP_CLAUSE_OPERAND (c, 0)
   13820                 :        7683 :                 = get_initialized_tmp_var (OMP_CLAUSE_OPERAND (c, 0),
   13821                 :             :                                            pre_p, NULL, true);
   13822                 :             :             }
   13823                 :             :           break;
   13824                 :             : 
   13825                 :        2331 :         case OMP_CLAUSE_GANG:
   13826                 :        2331 :           if (gimplify_expr (&OMP_CLAUSE_OPERAND (c, 0), pre_p, NULL,
   13827                 :             :                              is_gimple_val, fb_rvalue) == GS_ERROR)
   13828                 :           0 :             remove = true;
   13829                 :        2331 :           if (gimplify_expr (&OMP_CLAUSE_OPERAND (c, 1), pre_p, NULL,
   13830                 :             :                              is_gimple_val, fb_rvalue) == GS_ERROR)
   13831                 :           0 :             remove = true;
   13832                 :             :           break;
   13833                 :             : 
   13834                 :             :         case OMP_CLAUSE_NOWAIT:
   13835                 :      197631 :           nowait = 1;
   13836                 :             :           break;
   13837                 :             : 
   13838                 :             :         case OMP_CLAUSE_ORDERED:
   13839                 :             :         case OMP_CLAUSE_UNTIED:
   13840                 :             :         case OMP_CLAUSE_COLLAPSE:
   13841                 :             :         case OMP_CLAUSE_TILE:
   13842                 :             :         case OMP_CLAUSE_AUTO:
   13843                 :             :         case OMP_CLAUSE_SEQ:
   13844                 :             :         case OMP_CLAUSE_INDEPENDENT:
   13845                 :             :         case OMP_CLAUSE_MERGEABLE:
   13846                 :             :         case OMP_CLAUSE_PROC_BIND:
   13847                 :             :         case OMP_CLAUSE_SAFELEN:
   13848                 :             :         case OMP_CLAUSE_SIMDLEN:
   13849                 :             :         case OMP_CLAUSE_NOGROUP:
   13850                 :             :         case OMP_CLAUSE_THREADS:
   13851                 :             :         case OMP_CLAUSE_SIMD:
   13852                 :             :         case OMP_CLAUSE_BIND:
   13853                 :             :         case OMP_CLAUSE_IF_PRESENT:
   13854                 :             :         case OMP_CLAUSE_FINALIZE:
   13855                 :             :         case OMP_CLAUSE_INTEROP:
   13856                 :             :           break;
   13857                 :             : 
   13858                 :        3969 :         case OMP_CLAUSE_ORDER:
   13859                 :        3969 :           ctx->order_concurrent = true;
   13860                 :        3969 :           break;
   13861                 :             : 
   13862                 :         989 :         case OMP_CLAUSE_DEFAULTMAP:
   13863                 :         989 :           enum gimplify_defaultmap_kind gdmkmin, gdmkmax;
   13864                 :         989 :           switch (OMP_CLAUSE_DEFAULTMAP_CATEGORY (c))
   13865                 :             :             {
   13866                 :             :             case OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED:
   13867                 :             :             case OMP_CLAUSE_DEFAULTMAP_CATEGORY_ALL:
   13868                 :             :               gdmkmin = GDMK_SCALAR;
   13869                 :             :               gdmkmax = GDMK_POINTER;
   13870                 :             :               break;
   13871                 :             :             case OMP_CLAUSE_DEFAULTMAP_CATEGORY_SCALAR:
   13872                 :             :               gdmkmin = GDMK_SCALAR;
   13873                 :             :               gdmkmax = GDMK_SCALAR_TARGET;
   13874                 :             :               break;
   13875                 :             :             case OMP_CLAUSE_DEFAULTMAP_CATEGORY_AGGREGATE:
   13876                 :             :               gdmkmin = gdmkmax = GDMK_AGGREGATE;
   13877                 :             :               break;
   13878                 :             :             case OMP_CLAUSE_DEFAULTMAP_CATEGORY_ALLOCATABLE:
   13879                 :             :               gdmkmin = gdmkmax = GDMK_ALLOCATABLE;
   13880                 :             :               break;
   13881                 :             :             case OMP_CLAUSE_DEFAULTMAP_CATEGORY_POINTER:
   13882                 :             :               gdmkmin = gdmkmax = GDMK_POINTER;
   13883                 :             :               break;
   13884                 :           0 :             default:
   13885                 :           0 :               gcc_unreachable ();
   13886                 :             :             }
   13887                 :        4337 :           for (int gdmk = gdmkmin; gdmk <= gdmkmax; gdmk++)
   13888                 :        3348 :             switch (OMP_CLAUSE_DEFAULTMAP_BEHAVIOR (c))
   13889                 :             :               {
   13890                 :          71 :               case OMP_CLAUSE_DEFAULTMAP_ALLOC:
   13891                 :          71 :                 ctx->defaultmap[gdmk] = GOVD_MAP | GOVD_MAP_ALLOC_ONLY;
   13892                 :          71 :                 break;
   13893                 :          56 :               case OMP_CLAUSE_DEFAULTMAP_TO:
   13894                 :          56 :                 ctx->defaultmap[gdmk] = GOVD_MAP | GOVD_MAP_TO_ONLY;
   13895                 :          56 :                 break;
   13896                 :          28 :               case OMP_CLAUSE_DEFAULTMAP_FROM:
   13897                 :          28 :                 ctx->defaultmap[gdmk] = GOVD_MAP | GOVD_MAP_FROM_ONLY;
   13898                 :          28 :                 break;
   13899                 :         671 :               case OMP_CLAUSE_DEFAULTMAP_TOFROM:
   13900                 :         671 :                 ctx->defaultmap[gdmk] = GOVD_MAP;
   13901                 :         671 :                 break;
   13902                 :         375 :               case OMP_CLAUSE_DEFAULTMAP_FIRSTPRIVATE:
   13903                 :         375 :                 ctx->defaultmap[gdmk] = GOVD_FIRSTPRIVATE;
   13904                 :         375 :                 break;
   13905                 :        2049 :               case OMP_CLAUSE_DEFAULTMAP_NONE:
   13906                 :        2049 :                 ctx->defaultmap[gdmk] = 0;
   13907                 :        2049 :                 break;
   13908                 :          40 :               case OMP_CLAUSE_DEFAULTMAP_PRESENT:
   13909                 :          40 :                 ctx->defaultmap[gdmk] = GOVD_MAP | GOVD_MAP_FORCE_PRESENT;
   13910                 :          40 :                 break;
   13911                 :          58 :               case OMP_CLAUSE_DEFAULTMAP_DEFAULT:
   13912                 :          58 :                 switch (gdmk)
   13913                 :             :                   {
   13914                 :          11 :                   case GDMK_SCALAR:
   13915                 :          11 :                     ctx->defaultmap[gdmk] = GOVD_FIRSTPRIVATE;
   13916                 :          11 :                     break;
   13917                 :          11 :                   case GDMK_SCALAR_TARGET:
   13918                 :          11 :                     ctx->defaultmap[gdmk] = (lang_GNU_Fortran ()
   13919                 :          11 :                                              ? GOVD_MAP : GOVD_FIRSTPRIVATE);
   13920                 :          11 :                     break;
   13921                 :          14 :                   case GDMK_AGGREGATE:
   13922                 :          14 :                   case GDMK_ALLOCATABLE:
   13923                 :          14 :                     ctx->defaultmap[gdmk] = GOVD_MAP;
   13924                 :          14 :                     break;
   13925                 :          22 :                   case GDMK_POINTER:
   13926                 :          22 :                     ctx->defaultmap[gdmk] = GOVD_MAP;
   13927                 :          22 :                     if (!lang_GNU_Fortran ())
   13928                 :          14 :                       ctx->defaultmap[gdmk] |= GOVD_MAP_0LEN_ARRAY;
   13929                 :             :                     break;
   13930                 :             :                   default:
   13931                 :             :                     gcc_unreachable ();
   13932                 :             :                   }
   13933                 :             :                 break;
   13934                 :           0 :               default:
   13935                 :           0 :                 gcc_unreachable ();
   13936                 :             :               }
   13937                 :             :           break;
   13938                 :             : 
   13939                 :         824 :         case OMP_CLAUSE_ALIGNED:
   13940                 :         824 :           decl = OMP_CLAUSE_DECL (c);
   13941                 :         824 :           if (error_operand_p (decl))
   13942                 :             :             {
   13943                 :             :               remove = true;
   13944                 :             :               break;
   13945                 :             :             }
   13946                 :         824 :           if (gimplify_expr (&OMP_CLAUSE_ALIGNED_ALIGNMENT (c), pre_p, NULL,
   13947                 :             :                              is_gimple_val, fb_rvalue) == GS_ERROR)
   13948                 :             :             {
   13949                 :             :               remove = true;
   13950                 :             :               break;
   13951                 :             :             }
   13952                 :         824 :           if (!is_global_var (decl)
   13953                 :         824 :               && TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE)
   13954                 :         592 :             omp_add_variable (ctx, decl, GOVD_ALIGNED);
   13955                 :             :           break;
   13956                 :             : 
   13957                 :         489 :         case OMP_CLAUSE_NONTEMPORAL:
   13958                 :         489 :           decl = OMP_CLAUSE_DECL (c);
   13959                 :         489 :           if (error_operand_p (decl))
   13960                 :             :             {
   13961                 :             :               remove = true;
   13962                 :             :               break;
   13963                 :             :             }
   13964                 :         489 :           omp_add_variable (ctx, decl, GOVD_NONTEMPORAL);
   13965                 :         489 :           break;
   13966                 :             : 
   13967                 :        3541 :         case OMP_CLAUSE_ALLOCATE:
   13968                 :        3541 :           decl = OMP_CLAUSE_ALLOCATE_ALLOCATOR (c);
   13969                 :        3541 :           if (decl
   13970                 :        1580 :               && TREE_CODE (decl) == INTEGER_CST
   13971                 :        3570 :               && wi::eq_p (wi::to_widest (decl), GOMP_OMP_PREDEF_ALLOC_THREADS)
   13972                 :        3570 :               && (code == OMP_TARGET || code == OMP_TASK || code == OMP_TASKLOOP))
   13973                 :          35 :             warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
   13974                 :             :                         "allocator with access trait set to %<thread%> "
   13975                 :             :                         "results in undefined behavior for %qs directive",
   13976                 :             :                         code == OMP_TARGET ? "target"
   13977                 :             :                                            : (code == OMP_TASK
   13978                 :          15 :                                               ? "task" : "taskloop"));
   13979                 :        3541 :           decl = OMP_CLAUSE_DECL (c);
   13980                 :        3541 :           if (error_operand_p (decl))
   13981                 :             :             {
   13982                 :             :               remove = true;
   13983                 :             :               break;
   13984                 :             :             }
   13985                 :        3541 :           if (gimplify_expr (&OMP_CLAUSE_ALLOCATE_ALLOCATOR (c), pre_p, NULL,
   13986                 :             :                              is_gimple_val, fb_rvalue) == GS_ERROR)
   13987                 :             :             {
   13988                 :             :               remove = true;
   13989                 :             :               break;
   13990                 :             :             }
   13991                 :        3541 :           else if (OMP_CLAUSE_ALLOCATE_ALLOCATOR (c) == NULL_TREE
   13992                 :        3541 :                    || (TREE_CODE (OMP_CLAUSE_ALLOCATE_ALLOCATOR (c))
   13993                 :             :                        == INTEGER_CST))
   13994                 :             :             ;
   13995                 :         491 :           else if (code == OMP_TASKLOOP
   13996                 :         491 :                    || !DECL_P (OMP_CLAUSE_ALLOCATE_ALLOCATOR (c)))
   13997                 :          66 :             OMP_CLAUSE_ALLOCATE_ALLOCATOR (c)
   13998                 :         132 :               = get_initialized_tmp_var (OMP_CLAUSE_ALLOCATE_ALLOCATOR (c),
   13999                 :             :                                          pre_p, NULL, false);
   14000                 :             :           break;
   14001                 :             : 
   14002                 :        4347 :         case OMP_CLAUSE_DEFAULT:
   14003                 :        4347 :           ctx->default_kind = OMP_CLAUSE_DEFAULT_KIND (c);
   14004                 :        4347 :           break;
   14005                 :             : 
   14006                 :         640 :         case OMP_CLAUSE_INCLUSIVE:
   14007                 :         640 :         case OMP_CLAUSE_EXCLUSIVE:
   14008                 :         640 :           decl = OMP_CLAUSE_DECL (c);
   14009                 :         640 :           {
   14010                 :         640 :             splay_tree_node n = splay_tree_lookup (outer_ctx->variables,
   14011                 :             :                                                    (splay_tree_key) decl);
   14012                 :         640 :             if (n == NULL || (n->value & GOVD_REDUCTION) == 0)
   14013                 :             :               {
   14014                 :           5 :                 error_at (OMP_CLAUSE_LOCATION (c),
   14015                 :             :                           "%qD specified in %qs clause but not in %<inscan%> "
   14016                 :             :                           "%<reduction%> clause on the containing construct",
   14017                 :           5 :                           decl, omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   14018                 :           5 :                 remove = true;
   14019                 :             :               }
   14020                 :             :             else
   14021                 :             :               {
   14022                 :         635 :                 n->value |= GOVD_REDUCTION_INSCAN;
   14023                 :         635 :                 if (outer_ctx->region_type == ORT_SIMD
   14024                 :         520 :                     && outer_ctx->outer_context
   14025                 :         107 :                     && outer_ctx->outer_context->region_type == ORT_WORKSHARE)
   14026                 :             :                   {
   14027                 :         107 :                     n = splay_tree_lookup (outer_ctx->outer_context->variables,
   14028                 :             :                                            (splay_tree_key) decl);
   14029                 :         107 :                     if (n && (n->value & GOVD_REDUCTION) != 0)
   14030                 :         107 :                       n->value |= GOVD_REDUCTION_INSCAN;
   14031                 :             :                   }
   14032                 :             :               }
   14033                 :             :           }
   14034                 :             :           break;
   14035                 :             : 
   14036                 :          97 :         case OMP_CLAUSE_NOVARIANTS:
   14037                 :          97 :           OMP_CLAUSE_NOVARIANTS_EXPR (c)
   14038                 :         194 :             = gimple_boolify (OMP_CLAUSE_NOVARIANTS_EXPR (c));
   14039                 :          97 :           break;
   14040                 :         112 :         case OMP_CLAUSE_NOCONTEXT:
   14041                 :         112 :           OMP_CLAUSE_NOCONTEXT_EXPR (c)
   14042                 :         224 :             = gimple_boolify (OMP_CLAUSE_NOCONTEXT_EXPR (c));
   14043                 :         112 :           break;
   14044                 :           0 :         case OMP_CLAUSE_NOHOST:
   14045                 :           0 :         default:
   14046                 :           0 :           gcc_unreachable ();
   14047                 :             :         }
   14048                 :             : 
   14049                 :        1396 :       if (code == OACC_DATA
   14050                 :        5126 :           && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   14051                 :      202445 :           && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FIRSTPRIVATE_POINTER
   14052                 :        4506 :               || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FIRSTPRIVATE_REFERENCE))
   14053                 :             :         remove = true;
   14054                 :      198719 :       if (remove)
   14055                 :         941 :         *list_p = OMP_CLAUSE_CHAIN (c);
   14056                 :             :       else
   14057                 :      198086 :         list_p = &OMP_CLAUSE_CHAIN (c);
   14058                 :      199027 :     }
   14059                 :             : 
   14060                 :      127893 :   if (groups)
   14061                 :             :     {
   14062                 :       33450 :       delete grpmap;
   14063                 :       16725 :       delete groups;
   14064                 :             :     }
   14065                 :             : 
   14066                 :      127893 :   ctx->clauses = *orig_list_p;
   14067                 :      127893 :   gimplify_omp_ctxp = ctx;
   14068                 :      127893 : }
   14069                 :             : 
   14070                 :             : /* Return true if DECL is a candidate for shared to firstprivate
   14071                 :             :    optimization.  We only consider non-addressable scalars, not
   14072                 :             :    too big, and not references.  */
   14073                 :             : 
   14074                 :             : static bool
   14075                 :      403315 : omp_shared_to_firstprivate_optimizable_decl_p (tree decl)
   14076                 :             : {
   14077                 :      403315 :   if (TREE_ADDRESSABLE (decl))
   14078                 :             :     return false;
   14079                 :      354974 :   tree type = TREE_TYPE (decl);
   14080                 :      354974 :   if (!is_gimple_reg_type (type)
   14081                 :      330476 :       || TREE_CODE (type) == REFERENCE_TYPE
   14082                 :      679903 :       || TREE_ADDRESSABLE (type))
   14083                 :             :     return false;
   14084                 :             :   /* Don't optimize too large decls, as each thread/task will have
   14085                 :             :      its own.  */
   14086                 :      324929 :   HOST_WIDE_INT len = int_size_in_bytes (type);
   14087                 :      324929 :   if (len == -1 || len > 4 * POINTER_SIZE / BITS_PER_UNIT)
   14088                 :             :     return false;
   14089                 :      324912 :   if (omp_privatize_by_reference (decl))
   14090                 :             :     return false;
   14091                 :             :   return true;
   14092                 :             : }
   14093                 :             : 
   14094                 :             : /* Helper function of omp_find_stores_op and gimplify_adjust_omp_clauses*.
   14095                 :             :    For omp_shared_to_firstprivate_optimizable_decl_p decl mark it as
   14096                 :             :    GOVD_WRITTEN in outer contexts.  */
   14097                 :             : 
   14098                 :             : static void
   14099                 :      302077 : omp_mark_stores (struct gimplify_omp_ctx *ctx, tree decl)
   14100                 :             : {
   14101                 :      463850 :   for (; ctx; ctx = ctx->outer_context)
   14102                 :             :     {
   14103                 :      446874 :       splay_tree_node n = splay_tree_lookup (ctx->variables,
   14104                 :             :                                              (splay_tree_key) decl);
   14105                 :      446874 :       if (n == NULL)
   14106                 :      158197 :         continue;
   14107                 :      288677 :       else if (n->value & GOVD_SHARED)
   14108                 :             :         {
   14109                 :        9098 :           n->value |= GOVD_WRITTEN;
   14110                 :        9098 :           return;
   14111                 :             :         }
   14112                 :      279579 :       else if (n->value & GOVD_DATA_SHARE_CLASS)
   14113                 :             :         return;
   14114                 :             :     }
   14115                 :             : }
   14116                 :             : 
   14117                 :             : /* Helper callback for walk_gimple_seq to discover possible stores
   14118                 :             :    to omp_shared_to_firstprivate_optimizable_decl_p decls and set
   14119                 :             :    GOVD_WRITTEN if they are GOVD_SHARED in some outer context
   14120                 :             :    for those.  */
   14121                 :             : 
   14122                 :             : static tree
   14123                 :     1122466 : omp_find_stores_op (tree *tp, int *walk_subtrees, void *data)
   14124                 :             : {
   14125                 :     1122466 :   struct walk_stmt_info *wi = (struct walk_stmt_info *) data;
   14126                 :             : 
   14127                 :     1122466 :   *walk_subtrees = 0;
   14128                 :     1122466 :   if (!wi->is_lhs)
   14129                 :             :     return NULL_TREE;
   14130                 :             : 
   14131                 :      320475 :   tree op = *tp;
   14132                 :      398657 :   do
   14133                 :             :     {
   14134                 :      398657 :       if (handled_component_p (op))
   14135                 :       78182 :         op = TREE_OPERAND (op, 0);
   14136                 :      320475 :       else if ((TREE_CODE (op) == MEM_REF || TREE_CODE (op) == TARGET_MEM_REF)
   14137                 :      320475 :                && TREE_CODE (TREE_OPERAND (op, 0)) == ADDR_EXPR)
   14138                 :           0 :         op = TREE_OPERAND (TREE_OPERAND (op, 0), 0);
   14139                 :             :       else
   14140                 :             :         break;
   14141                 :             :     }
   14142                 :             :   while (1);
   14143                 :      320475 :   if (!DECL_P (op) || !omp_shared_to_firstprivate_optimizable_decl_p (op))
   14144                 :       58691 :     return NULL_TREE;
   14145                 :             : 
   14146                 :      261784 :   omp_mark_stores (gimplify_omp_ctxp, op);
   14147                 :      261784 :   return NULL_TREE;
   14148                 :             : }
   14149                 :             : 
   14150                 :             : /* Helper callback for walk_gimple_seq to discover possible stores
   14151                 :             :    to omp_shared_to_firstprivate_optimizable_decl_p decls and set
   14152                 :             :    GOVD_WRITTEN if they are GOVD_SHARED in some outer context
   14153                 :             :    for those.  */
   14154                 :             : 
   14155                 :             : static tree
   14156                 :      623997 : omp_find_stores_stmt (gimple_stmt_iterator *gsi_p,
   14157                 :             :                       bool *handled_ops_p,
   14158                 :             :                       struct walk_stmt_info *wi)
   14159                 :             : {
   14160                 :      623997 :   gimple *stmt = gsi_stmt (*gsi_p);
   14161                 :      623997 :   switch (gimple_code (stmt))
   14162                 :             :     {
   14163                 :             :     /* Don't recurse on OpenMP constructs for which
   14164                 :             :        gimplify_adjust_omp_clauses already handled the bodies,
   14165                 :             :        except handle gimple_omp_for_pre_body.  */
   14166                 :       26679 :     case GIMPLE_OMP_FOR:
   14167                 :       26679 :       *handled_ops_p = true;
   14168                 :       26679 :       if (gimple_omp_for_pre_body (stmt))
   14169                 :        1384 :         walk_gimple_seq (gimple_omp_for_pre_body (stmt),
   14170                 :             :                          omp_find_stores_stmt, omp_find_stores_op, wi);
   14171                 :             :       break;
   14172                 :        8556 :     case GIMPLE_OMP_PARALLEL:
   14173                 :        8556 :     case GIMPLE_OMP_TASK:
   14174                 :        8556 :     case GIMPLE_OMP_SECTIONS:
   14175                 :        8556 :     case GIMPLE_OMP_SINGLE:
   14176                 :        8556 :     case GIMPLE_OMP_SCOPE:
   14177                 :        8556 :     case GIMPLE_OMP_TARGET:
   14178                 :        8556 :     case GIMPLE_OMP_TEAMS:
   14179                 :        8556 :     case GIMPLE_OMP_CRITICAL:
   14180                 :        8556 :       *handled_ops_p = true;
   14181                 :        8556 :       break;
   14182                 :             :     default:
   14183                 :             :       break;
   14184                 :             :     }
   14185                 :      623997 :   return NULL_TREE;
   14186                 :             : }
   14187                 :             : 
   14188                 :             : struct gimplify_adjust_omp_clauses_data
   14189                 :             : {
   14190                 :             :   tree *list_p;
   14191                 :             :   gimple_seq *pre_p;
   14192                 :             : };
   14193                 :             : 
   14194                 :             : /* For all variables that were not actually used within the context,
   14195                 :             :    remove PRIVATE, SHARED, and FIRSTPRIVATE clauses.  */
   14196                 :             : 
   14197                 :             : static int
   14198                 :      652698 : gimplify_adjust_omp_clauses_1 (splay_tree_node n, void *data)
   14199                 :             : {
   14200                 :      652698 :   tree *list_p = ((struct gimplify_adjust_omp_clauses_data *) data)->list_p;
   14201                 :      652698 :   gimple_seq *pre_p
   14202                 :             :     = ((struct gimplify_adjust_omp_clauses_data *) data)->pre_p;
   14203                 :      652698 :   tree decl = (tree) n->key;
   14204                 :      652698 :   unsigned flags = n->value;
   14205                 :      652698 :   enum omp_clause_code code;
   14206                 :      652698 :   tree clause;
   14207                 :      652698 :   bool private_debug;
   14208                 :             : 
   14209                 :      652698 :   if (gimplify_omp_ctxp->region_type == ORT_COMBINED_PARALLEL
   14210                 :      132468 :       && (flags & GOVD_LASTPRIVATE_CONDITIONAL) != 0)
   14211                 :             :     flags = GOVD_SHARED | GOVD_SEEN | GOVD_WRITTEN;
   14212                 :      652573 :   if (flags & (GOVD_EXPLICIT | GOVD_LOCAL))
   14213                 :             :     return 0;
   14214                 :      177233 :   if ((flags & GOVD_SEEN) == 0)
   14215                 :             :     return 0;
   14216                 :      156469 :   if (flags & GOVD_DEBUG_PRIVATE)
   14217                 :             :     {
   14218                 :         256 :       gcc_assert ((flags & GOVD_DATA_SHARE_CLASS) == GOVD_SHARED);
   14219                 :             :       private_debug = true;
   14220                 :             :     }
   14221                 :      156213 :   else if (flags & GOVD_MAP)
   14222                 :             :     private_debug = false;
   14223                 :             :   else
   14224                 :      138462 :     private_debug
   14225                 :      138462 :       = lang_hooks.decls.omp_private_debug_clause (decl,
   14226                 :      138462 :                                                    !!(flags & GOVD_SHARED));
   14227                 :      138462 :   if (private_debug)
   14228                 :             :     code = OMP_CLAUSE_PRIVATE;
   14229                 :      156091 :   else if (flags & GOVD_MAP)
   14230                 :             :     {
   14231                 :       17751 :       code = OMP_CLAUSE_MAP;
   14232                 :       17751 :       if ((gimplify_omp_ctxp->region_type & ORT_ACC) == 0
   14233                 :       17751 :           && TYPE_ATOMIC (strip_array_types (TREE_TYPE (decl))))
   14234                 :             :         {
   14235                 :           2 :           error ("%<_Atomic%> %qD in implicit %<map%> clause", decl);
   14236                 :           2 :           return 0;
   14237                 :             :         }
   14238                 :       17749 :       if (VAR_P (decl)
   14239                 :       15822 :           && DECL_IN_CONSTANT_POOL (decl)
   14240                 :       17750 :           && !lookup_attribute ("omp declare target",
   14241                 :           1 :                                 DECL_ATTRIBUTES (decl)))
   14242                 :             :         {
   14243                 :           1 :           tree id = get_identifier ("omp declare target");
   14244                 :           2 :           DECL_ATTRIBUTES (decl)
   14245                 :           1 :             = tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (decl));
   14246                 :           1 :           varpool_node *node = varpool_node::get (decl);
   14247                 :           1 :           if (node)
   14248                 :             :             {
   14249                 :           1 :               node->offloadable = 1;
   14250                 :           1 :               if (ENABLE_OFFLOADING)
   14251                 :             :                 g->have_offload = true;
   14252                 :             :             }
   14253                 :             :         }
   14254                 :             :     }
   14255                 :      138340 :   else if (flags & GOVD_SHARED)
   14256                 :             :     {
   14257                 :       49005 :       if (is_global_var (decl))
   14258                 :             :         {
   14259                 :       16156 :           struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp->outer_context;
   14260                 :       25336 :           while (ctx != NULL)
   14261                 :             :             {
   14262                 :       17593 :               splay_tree_node on
   14263                 :       17593 :                 = splay_tree_lookup (ctx->variables, (splay_tree_key) decl);
   14264                 :       17593 :               if (on && (on->value & (GOVD_FIRSTPRIVATE | GOVD_LASTPRIVATE
   14265                 :             :                                       | GOVD_PRIVATE | GOVD_REDUCTION
   14266                 :             :                                       | GOVD_LINEAR | GOVD_MAP)) != 0)
   14267                 :             :                 break;
   14268                 :        9180 :               ctx = ctx->outer_context;
   14269                 :             :             }
   14270                 :       16156 :           if (ctx == NULL)
   14271                 :             :             return 0;
   14272                 :             :         }
   14273                 :       41262 :       code = OMP_CLAUSE_SHARED;
   14274                 :             :       /* Don't optimize shared into firstprivate for read-only vars
   14275                 :             :          on tasks with depend clause, we shouldn't try to copy them
   14276                 :             :          until the dependencies are satisfied.  */
   14277                 :       41262 :       if (gimplify_omp_ctxp->has_depend)
   14278                 :         350 :         flags |= GOVD_WRITTEN;
   14279                 :             :     }
   14280                 :       89335 :   else if (flags & GOVD_PRIVATE)
   14281                 :             :     code = OMP_CLAUSE_PRIVATE;
   14282                 :       30966 :   else if (flags & GOVD_FIRSTPRIVATE)
   14283                 :             :     {
   14284                 :       21566 :       code = OMP_CLAUSE_FIRSTPRIVATE;
   14285                 :       21566 :       if ((gimplify_omp_ctxp->region_type & ORT_TARGET)
   14286                 :       21566 :           && (gimplify_omp_ctxp->region_type & ORT_ACC) == 0
   14287                 :       21566 :           && TYPE_ATOMIC (strip_array_types (TREE_TYPE (decl))))
   14288                 :             :         {
   14289                 :           1 :           error ("%<_Atomic%> %qD in implicit %<firstprivate%> clause on "
   14290                 :             :                  "%<target%> construct", decl);
   14291                 :           1 :           return 0;
   14292                 :             :         }
   14293                 :             :     }
   14294                 :        9400 :   else if (flags & GOVD_LASTPRIVATE)
   14295                 :             :     code = OMP_CLAUSE_LASTPRIVATE;
   14296                 :         241 :   else if (flags & (GOVD_ALIGNED | GOVD_NONTEMPORAL))
   14297                 :             :     return 0;
   14298                 :         118 :   else if (flags & GOVD_CONDTEMP)
   14299                 :             :     {
   14300                 :         118 :       code = OMP_CLAUSE__CONDTEMP_;
   14301                 :         118 :       gimple_add_tmp_var (decl);
   14302                 :             :     }
   14303                 :             :   else
   14304                 :           0 :     gcc_unreachable ();
   14305                 :             : 
   14306                 :      139441 :   if (((flags & GOVD_LASTPRIVATE)
   14307                 :      138751 :        || (code == OMP_CLAUSE_SHARED && (flags & GOVD_WRITTEN)))
   14308                 :      154651 :       && omp_shared_to_firstprivate_optimizable_decl_p (decl))
   14309                 :       15196 :     omp_mark_stores (gimplify_omp_ctxp->outer_context, decl);
   14310                 :             : 
   14311                 :      148600 :   tree chain = *list_p;
   14312                 :      148600 :   clause = build_omp_clause (input_location, code);
   14313                 :      148600 :   OMP_CLAUSE_DECL (clause) = decl;
   14314                 :      148600 :   OMP_CLAUSE_CHAIN (clause) = chain;
   14315                 :      148600 :   if (private_debug)
   14316                 :         378 :     OMP_CLAUSE_PRIVATE_DEBUG (clause) = 1;
   14317                 :      148222 :   else if (code == OMP_CLAUSE_PRIVATE && (flags & GOVD_PRIVATE_OUTER_REF))
   14318                 :           6 :     OMP_CLAUSE_PRIVATE_OUTER_REF (clause) = 1;
   14319                 :      148216 :   else if (code == OMP_CLAUSE_SHARED
   14320                 :       41262 :            && (flags & GOVD_WRITTEN) == 0
   14321                 :      183427 :            && omp_shared_to_firstprivate_optimizable_decl_p (decl))
   14322                 :       20990 :     OMP_CLAUSE_SHARED_READONLY (clause) = 1;
   14323                 :      127226 :   else if (code == OMP_CLAUSE_FIRSTPRIVATE && (flags & GOVD_EXPLICIT) == 0)
   14324                 :       21565 :     OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (clause) = 1;
   14325                 :      105661 :   else if (code == OMP_CLAUSE_MAP && (flags & GOVD_MAP_0LEN_ARRAY) != 0)
   14326                 :             :     {
   14327                 :         637 :       tree nc = build_omp_clause (input_location, OMP_CLAUSE_MAP);
   14328                 :         637 :       OMP_CLAUSE_DECL (nc) = decl;
   14329                 :         637 :       if (TREE_CODE (TREE_TYPE (decl)) == REFERENCE_TYPE
   14330                 :         637 :           && TREE_CODE (TREE_TYPE (TREE_TYPE (decl))) == POINTER_TYPE)
   14331                 :          15 :         OMP_CLAUSE_DECL (clause)
   14332                 :          30 :           = build_fold_indirect_ref_loc (input_location, decl);
   14333                 :         637 :       OMP_CLAUSE_DECL (clause)
   14334                 :        1274 :         = build2 (MEM_REF, char_type_node, OMP_CLAUSE_DECL (clause),
   14335                 :         637 :                   build_int_cst (build_pointer_type (char_type_node), 0));
   14336                 :         637 :       OMP_CLAUSE_SIZE (clause) = size_zero_node;
   14337                 :         637 :       OMP_CLAUSE_SIZE (nc) = size_zero_node;
   14338                 :         637 :       OMP_CLAUSE_SET_MAP_KIND (clause, GOMP_MAP_ALLOC);
   14339                 :         637 :       OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (clause) = 1;
   14340                 :         637 :       tree dtype = TREE_TYPE (decl);
   14341                 :         637 :       if (TREE_CODE (dtype) == REFERENCE_TYPE)
   14342                 :          15 :         dtype = TREE_TYPE (dtype);
   14343                 :             :       /* FIRSTPRIVATE_POINTER doesn't work well if we have a
   14344                 :             :          multiply-indirected pointer.  If we have a reference to a pointer to
   14345                 :             :          a pointer, it's possible that this should really be
   14346                 :             :          GOMP_MAP_FIRSTPRIVATE_REFERENCE -- but that also doesn't work at the
   14347                 :             :          moment, so stick with this.  (See PR113279 and testcases
   14348                 :             :          baseptrs-{4,6}.C:ref2ptrptr_offset_decl_member_slice).  */
   14349                 :         637 :       if (TREE_CODE (dtype) == POINTER_TYPE
   14350                 :         637 :           && TREE_CODE (TREE_TYPE (dtype)) == POINTER_TYPE)
   14351                 :          19 :         OMP_CLAUSE_SET_MAP_KIND (nc, GOMP_MAP_POINTER);
   14352                 :             :       else
   14353                 :         618 :         OMP_CLAUSE_SET_MAP_KIND (nc, GOMP_MAP_FIRSTPRIVATE_POINTER);
   14354                 :         637 :       OMP_CLAUSE_CHAIN (nc) = chain;
   14355                 :         637 :       OMP_CLAUSE_CHAIN (clause) = nc;
   14356                 :         637 :       struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp;
   14357                 :         637 :       gimplify_omp_ctxp = ctx->outer_context;
   14358                 :         637 :       gimplify_expr (&TREE_OPERAND (OMP_CLAUSE_DECL (clause), 0),
   14359                 :             :                      pre_p, NULL, is_gimple_val, fb_rvalue);
   14360                 :         637 :       gimplify_omp_ctxp = ctx;
   14361                 :         637 :     }
   14362                 :       17112 :   else if (code == OMP_CLAUSE_MAP)
   14363                 :             :     {
   14364                 :       17112 :       int kind;
   14365                 :             :       /* Not all combinations of these GOVD_MAP flags are actually valid.  */
   14366                 :       17112 :       switch (flags & (GOVD_MAP_TO_ONLY
   14367                 :             :                        | GOVD_MAP_FORCE
   14368                 :             :                        | GOVD_MAP_FORCE_PRESENT
   14369                 :             :                        | GOVD_MAP_ALLOC_ONLY
   14370                 :             :                        | GOVD_MAP_FROM_ONLY))
   14371                 :             :         {
   14372                 :             :         case 0:
   14373                 :             :           kind = GOMP_MAP_TOFROM;
   14374                 :             :           break;
   14375                 :        1062 :         case GOVD_MAP_FORCE:
   14376                 :        1062 :           kind = GOMP_MAP_TOFROM | GOMP_MAP_FLAG_FORCE;
   14377                 :        1062 :           break;
   14378                 :         817 :         case GOVD_MAP_TO_ONLY:
   14379                 :         817 :           kind = GOMP_MAP_TO;
   14380                 :         817 :           break;
   14381                 :          16 :         case GOVD_MAP_FROM_ONLY:
   14382                 :          16 :           kind = GOMP_MAP_FROM;
   14383                 :          16 :           break;
   14384                 :          37 :         case GOVD_MAP_ALLOC_ONLY:
   14385                 :          37 :           kind = GOMP_MAP_ALLOC;
   14386                 :          37 :           break;
   14387                 :           0 :         case GOVD_MAP_TO_ONLY | GOVD_MAP_FORCE:
   14388                 :           0 :           kind = GOMP_MAP_TO | GOMP_MAP_FLAG_FORCE;
   14389                 :           0 :           break;
   14390                 :             :         case GOVD_MAP_FORCE_PRESENT:
   14391                 :         320 :           kind = GOMP_MAP_FORCE_PRESENT;
   14392                 :             :           break;
   14393                 :             :         case GOVD_MAP_FORCE_PRESENT | GOVD_MAP_ALLOC_ONLY:
   14394                 :         320 :           kind = GOMP_MAP_FORCE_PRESENT;
   14395                 :             :           break;
   14396                 :           0 :         default:
   14397                 :           0 :           gcc_unreachable ();
   14398                 :             :         }
   14399                 :       17112 :       OMP_CLAUSE_SET_MAP_KIND (clause, kind);
   14400                 :             :       /* Setting of the implicit flag for the runtime is currently disabled for
   14401                 :             :          OpenACC.  */
   14402                 :       17112 :       if ((gimplify_omp_ctxp->region_type & ORT_ACC) == 0)
   14403                 :        9580 :         OMP_CLAUSE_MAP_RUNTIME_IMPLICIT_P (clause) = 1;
   14404                 :       17112 :       if (DECL_SIZE (decl)
   14405                 :       17112 :           && TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
   14406                 :             :         {
   14407                 :         535 :           tree decl2 = DECL_VALUE_EXPR (decl);
   14408                 :         535 :           gcc_assert (INDIRECT_REF_P (decl2));
   14409                 :         535 :           decl2 = TREE_OPERAND (decl2, 0);
   14410                 :         535 :           gcc_assert (DECL_P (decl2));
   14411                 :         535 :           tree mem = build_simple_mem_ref (decl2);
   14412                 :         535 :           OMP_CLAUSE_DECL (clause) = mem;
   14413                 :         535 :           OMP_CLAUSE_SIZE (clause) = TYPE_SIZE_UNIT (TREE_TYPE (decl));
   14414                 :         535 :           if (gimplify_omp_ctxp->outer_context)
   14415                 :             :             {
   14416                 :         446 :               struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp->outer_context;
   14417                 :         446 :               omp_notice_variable (ctx, decl2, true);
   14418                 :         446 :               omp_notice_variable (ctx, OMP_CLAUSE_SIZE (clause), true);
   14419                 :             :             }
   14420                 :         535 :           tree nc = build_omp_clause (OMP_CLAUSE_LOCATION (clause),
   14421                 :             :                                       OMP_CLAUSE_MAP);
   14422                 :         535 :           OMP_CLAUSE_DECL (nc) = decl;
   14423                 :         535 :           OMP_CLAUSE_SIZE (nc) = size_zero_node;
   14424                 :         535 :           if (gimplify_omp_ctxp->target_firstprivatize_array_bases)
   14425                 :         535 :             OMP_CLAUSE_SET_MAP_KIND (nc, GOMP_MAP_FIRSTPRIVATE_POINTER);
   14426                 :             :           else
   14427                 :           0 :             OMP_CLAUSE_SET_MAP_KIND (nc, GOMP_MAP_POINTER);
   14428                 :         535 :           OMP_CLAUSE_CHAIN (nc) = OMP_CLAUSE_CHAIN (clause);
   14429                 :         535 :           OMP_CLAUSE_CHAIN (clause) = nc;
   14430                 :             :         }
   14431                 :       16577 :       else if (gimplify_omp_ctxp->target_firstprivatize_array_bases
   14432                 :       16577 :                && omp_privatize_by_reference (decl))
   14433                 :             :         {
   14434                 :          28 :           OMP_CLAUSE_DECL (clause) = build_simple_mem_ref (decl);
   14435                 :          28 :           OMP_CLAUSE_SIZE (clause)
   14436                 :          56 :             = unshare_expr (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl))));
   14437                 :          28 :           struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp;
   14438                 :          28 :           gimplify_omp_ctxp = ctx->outer_context;
   14439                 :          28 :           gimplify_expr (&OMP_CLAUSE_SIZE (clause),
   14440                 :             :                          pre_p, NULL, is_gimple_val, fb_rvalue);
   14441                 :          28 :           gimplify_omp_ctxp = ctx;
   14442                 :          28 :           tree nc = build_omp_clause (OMP_CLAUSE_LOCATION (clause),
   14443                 :             :                                       OMP_CLAUSE_MAP);
   14444                 :          28 :           OMP_CLAUSE_DECL (nc) = decl;
   14445                 :          28 :           OMP_CLAUSE_SIZE (nc) = size_zero_node;
   14446                 :          28 :           OMP_CLAUSE_SET_MAP_KIND (nc, GOMP_MAP_FIRSTPRIVATE_REFERENCE);
   14447                 :          28 :           OMP_CLAUSE_CHAIN (nc) = OMP_CLAUSE_CHAIN (clause);
   14448                 :          28 :           OMP_CLAUSE_CHAIN (clause) = nc;
   14449                 :             :         }
   14450                 :             :       else
   14451                 :       16549 :         OMP_CLAUSE_SIZE (clause) = DECL_SIZE_UNIT (decl);
   14452                 :             :     }
   14453                 :      148600 :   if (code == OMP_CLAUSE_FIRSTPRIVATE && (flags & GOVD_LASTPRIVATE) != 0)
   14454                 :             :     {
   14455                 :         690 :       tree nc = build_omp_clause (input_location, OMP_CLAUSE_LASTPRIVATE);
   14456                 :         690 :       OMP_CLAUSE_DECL (nc) = decl;
   14457                 :         690 :       OMP_CLAUSE_LASTPRIVATE_FIRSTPRIVATE (nc) = 1;
   14458                 :         690 :       OMP_CLAUSE_CHAIN (nc) = chain;
   14459                 :         690 :       OMP_CLAUSE_CHAIN (clause) = nc;
   14460                 :         690 :       struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp;
   14461                 :         690 :       gimplify_omp_ctxp = ctx->outer_context;
   14462                 :         690 :       lang_hooks.decls.omp_finish_clause (nc, pre_p,
   14463                 :         690 :                                           (ctx->region_type & ORT_ACC) != 0);
   14464                 :         690 :       gimplify_omp_ctxp = ctx;
   14465                 :             :     }
   14466                 :      148600 :   *list_p = clause;
   14467                 :      148600 :   struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp;
   14468                 :      148600 :   gimplify_omp_ctxp = ctx->outer_context;
   14469                 :             :   /* Don't call omp_finish_clause on implicitly added OMP_CLAUSE_PRIVATE
   14470                 :             :      in simd.  Those are only added for the local vars inside of simd body
   14471                 :             :      and they don't need to be e.g. default constructible.  */
   14472                 :      148600 :   if (code != OMP_CLAUSE_PRIVATE || ctx->region_type != ORT_SIMD)
   14473                 :      140582 :     lang_hooks.decls.omp_finish_clause (clause, pre_p,
   14474                 :      140582 :                                         (ctx->region_type & ORT_ACC) != 0);
   14475                 :      148600 :   if (gimplify_omp_ctxp)
   14476                 :      183771 :     for (; clause != chain; clause = OMP_CLAUSE_CHAIN (clause))
   14477                 :       93298 :       if (OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_MAP
   14478                 :       93298 :           && DECL_P (OMP_CLAUSE_SIZE (clause)))
   14479                 :        1241 :         omp_notice_variable (gimplify_omp_ctxp, OMP_CLAUSE_SIZE (clause),
   14480                 :             :                              true);
   14481                 :      148600 :   gimplify_omp_ctxp = ctx;
   14482                 :      148600 :   return 0;
   14483                 :             : }
   14484                 :             : 
   14485                 :             : static void
   14486                 :      127074 : gimplify_adjust_omp_clauses (gimple_seq *pre_p, gimple_seq body, tree *list_p,
   14487                 :             :                              enum tree_code code)
   14488                 :             : {
   14489                 :      127074 :   struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp;
   14490                 :      127074 :   tree *orig_list_p = list_p;
   14491                 :      127074 :   tree c, decl;
   14492                 :      127074 :   bool has_inscan_reductions = false;
   14493                 :             : 
   14494                 :      127074 :   if (body)
   14495                 :             :     {
   14496                 :             :       struct gimplify_omp_ctx *octx;
   14497                 :      221886 :       for (octx = ctx; octx; octx = octx->outer_context)
   14498                 :      172135 :         if ((octx->region_type & (ORT_PARALLEL | ORT_TASK | ORT_TEAMS)) != 0)
   14499                 :             :           break;
   14500                 :      110048 :       if (octx)
   14501                 :             :         {
   14502                 :       60297 :           struct walk_stmt_info wi;
   14503                 :       60297 :           memset (&wi, 0, sizeof (wi));
   14504                 :       60297 :           walk_gimple_seq (body, omp_find_stores_stmt,
   14505                 :             :                            omp_find_stores_op, &wi);
   14506                 :             :         }
   14507                 :             :     }
   14508                 :             : 
   14509                 :      127074 :   if (ctx->add_safelen1)
   14510                 :             :     {
   14511                 :             :       /* If there are VLAs in the body of simd loop, prevent
   14512                 :             :          vectorization.  */
   14513                 :           2 :       gcc_assert (ctx->region_type == ORT_SIMD);
   14514                 :           2 :       c = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE_SAFELEN);
   14515                 :           2 :       OMP_CLAUSE_SAFELEN_EXPR (c) = integer_one_node;
   14516                 :           2 :       OMP_CLAUSE_CHAIN (c) = *list_p;
   14517                 :           2 :       *list_p = c;
   14518                 :           2 :       list_p = &OMP_CLAUSE_CHAIN (c);
   14519                 :             :     }
   14520                 :             : 
   14521                 :      127074 :   if (ctx->region_type == ORT_WORKSHARE
   14522                 :       39086 :       && ctx->outer_context
   14523                 :       27849 :       && ctx->outer_context->region_type == ORT_COMBINED_PARALLEL)
   14524                 :             :     {
   14525                 :       24926 :       for (c = ctx->outer_context->clauses; c; c = OMP_CLAUSE_CHAIN (c))
   14526                 :       12585 :         if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
   14527                 :       12585 :             && OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c))
   14528                 :             :           {
   14529                 :         125 :             decl = OMP_CLAUSE_DECL (c);
   14530                 :         125 :             splay_tree_node n
   14531                 :         125 :               = splay_tree_lookup (ctx->outer_context->variables,
   14532                 :             :                                    (splay_tree_key) decl);
   14533                 :         125 :             gcc_checking_assert (!splay_tree_lookup (ctx->variables,
   14534                 :             :                                                      (splay_tree_key) decl));
   14535                 :         125 :             omp_add_variable (ctx, decl, n->value);
   14536                 :         125 :             tree c2 = copy_node (c);
   14537                 :         125 :             OMP_CLAUSE_CHAIN (c2) = *list_p;
   14538                 :         125 :             *list_p = c2;
   14539                 :         125 :             if ((n->value & GOVD_FIRSTPRIVATE) == 0)
   14540                 :         103 :               continue;
   14541                 :          22 :             c2 = build_omp_clause (OMP_CLAUSE_LOCATION (c),
   14542                 :             :                                    OMP_CLAUSE_FIRSTPRIVATE);
   14543                 :          22 :             OMP_CLAUSE_DECL (c2) = decl;
   14544                 :          22 :             OMP_CLAUSE_CHAIN (c2) = *list_p;
   14545                 :          22 :             *list_p = c2;
   14546                 :             :           }
   14547                 :             :     }
   14548                 :             : 
   14549                 :      127074 :   if (code == OMP_TARGET
   14550                 :      127074 :       || code == OMP_TARGET_DATA
   14551                 :      127074 :       || code == OMP_TARGET_ENTER_DATA
   14552                 :      112547 :       || code == OMP_TARGET_EXIT_DATA)
   14553                 :             :     {
   14554                 :       15109 :       vec<omp_mapping_group> *groups;
   14555                 :       15109 :       groups = omp_gather_mapping_groups (list_p);
   14556                 :       15109 :       hash_map<tree_operand_hash_no_se, omp_mapping_group *> *grpmap = NULL;
   14557                 :             : 
   14558                 :       15109 :       if (groups)
   14559                 :             :         {
   14560                 :        7066 :           grpmap = omp_index_mapping_groups (groups);
   14561                 :             : 
   14562                 :        7066 :           omp_resolve_clause_dependencies (code, groups, grpmap);
   14563                 :        7066 :           omp_build_struct_sibling_lists (code, ctx->region_type, groups,
   14564                 :             :                                           &grpmap, list_p);
   14565                 :             : 
   14566                 :        7066 :           omp_mapping_group *outlist = NULL;
   14567                 :             : 
   14568                 :       14132 :           delete grpmap;
   14569                 :        7066 :           delete groups;
   14570                 :             : 
   14571                 :             :           /* Rebuild now we have struct sibling lists.  */
   14572                 :        7066 :           groups = omp_gather_mapping_groups (list_p);
   14573                 :        7066 :           grpmap = omp_index_mapping_groups (groups);
   14574                 :             : 
   14575                 :        7066 :           bool enter_exit = (code == OMP_TARGET_ENTER_DATA
   14576                 :        7066 :                              || code == OMP_TARGET_EXIT_DATA);
   14577                 :             : 
   14578                 :        7066 :           outlist = omp_tsort_mapping_groups (groups, grpmap, enter_exit);
   14579                 :        7066 :           outlist = omp_segregate_mapping_groups (outlist);
   14580                 :        7066 :           list_p = omp_reorder_mapping_groups (groups, outlist, list_p);
   14581                 :             : 
   14582                 :        7066 :           delete grpmap;
   14583                 :        7066 :           delete groups;
   14584                 :             :         }
   14585                 :       15109 :     }
   14586                 :      111965 :   else if (ctx->region_type & ORT_ACC)
   14587                 :             :     {
   14588                 :       29837 :       vec<omp_mapping_group> *groups;
   14589                 :       29837 :       groups = omp_gather_mapping_groups (list_p);
   14590                 :       29837 :       if (groups)
   14591                 :             :         {
   14592                 :        9405 :           hash_map<tree_operand_hash_no_se, omp_mapping_group *> *grpmap;
   14593                 :        9405 :           grpmap = omp_index_mapping_groups (groups);
   14594                 :             : 
   14595                 :        9405 :           oacc_resolve_clause_dependencies (groups, grpmap);
   14596                 :        9405 :           omp_build_struct_sibling_lists (code, ctx->region_type, groups,
   14597                 :             :                                           &grpmap, list_p);
   14598                 :             : 
   14599                 :        9405 :           delete groups;
   14600                 :       18810 :           delete grpmap;
   14601                 :             :         }
   14602                 :             :     }
   14603                 :             : 
   14604                 :      127074 :   tree attach_list = NULL_TREE;
   14605                 :      127074 :   tree *attach_tail = &attach_list;
   14606                 :             : 
   14607                 :      127074 :   tree *grp_start_p = NULL, grp_end = NULL_TREE;
   14608                 :             : 
   14609                 :      367076 :   while ((c = *list_p) != NULL)
   14610                 :             :     {
   14611                 :      240002 :       splay_tree_node n;
   14612                 :      240002 :       bool remove = false;
   14613                 :      240002 :       bool move_attach = false;
   14614                 :             : 
   14615                 :      278906 :       if (grp_end && c == OMP_CLAUSE_CHAIN (grp_end))
   14616                 :             :         grp_end = NULL_TREE;
   14617                 :             : 
   14618                 :      240002 :       switch (OMP_CLAUSE_CODE (c))
   14619                 :             :         {
   14620                 :        7892 :         case OMP_CLAUSE_FIRSTPRIVATE:
   14621                 :        7892 :           if ((ctx->region_type & ORT_TARGET)
   14622                 :        7892 :               && (ctx->region_type & ORT_ACC) == 0
   14623                 :        7892 :               && TYPE_ATOMIC (strip_array_types
   14624                 :             :                                         (TREE_TYPE (OMP_CLAUSE_DECL (c)))))
   14625                 :             :             {
   14626                 :           4 :               error_at (OMP_CLAUSE_LOCATION (c),
   14627                 :             :                         "%<_Atomic%> %qD in %<firstprivate%> clause on "
   14628                 :           2 :                         "%<target%> construct", OMP_CLAUSE_DECL (c));
   14629                 :           2 :               remove = true;
   14630                 :           2 :               break;
   14631                 :             :             }
   14632                 :        7890 :           if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c))
   14633                 :             :             {
   14634                 :         380 :               decl = OMP_CLAUSE_DECL (c);
   14635                 :         380 :               n = splay_tree_lookup (ctx->variables, (splay_tree_key) decl);
   14636                 :         380 :               if ((n->value & GOVD_MAP) != 0)
   14637                 :             :                 {
   14638                 :             :                   remove = true;
   14639                 :             :                   break;
   14640                 :             :                 }
   14641                 :         368 :               OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c) = 0;
   14642                 :         368 :               OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c) = 0;
   14643                 :             :             }
   14644                 :             :           /* FALLTHRU */
   14645                 :       36615 :         case OMP_CLAUSE_PRIVATE:
   14646                 :       36615 :         case OMP_CLAUSE_SHARED:
   14647                 :       36615 :         case OMP_CLAUSE_LINEAR:
   14648                 :       36615 :           decl = OMP_CLAUSE_DECL (c);
   14649                 :       36615 :           n = splay_tree_lookup (ctx->variables, (splay_tree_key) decl);
   14650                 :       36615 :           remove = !(n->value & GOVD_SEEN);
   14651                 :       36615 :           if ((n->value & GOVD_LASTPRIVATE_CONDITIONAL) != 0
   14652                 :          48 :               && code == OMP_PARALLEL
   14653                 :       36637 :               && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE)
   14654                 :             :             remove = true;
   14655                 :       36593 :           if (! remove)
   14656                 :             :             {
   14657                 :       32023 :               bool shared = OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED;
   14658                 :       32023 :               if ((n->value & GOVD_DEBUG_PRIVATE)
   14659                 :       32023 :                   || lang_hooks.decls.omp_private_debug_clause (decl, shared))
   14660                 :             :                 {
   14661                 :          83 :                   gcc_assert ((n->value & GOVD_DEBUG_PRIVATE) == 0
   14662                 :             :                               || ((n->value & GOVD_DATA_SHARE_CLASS)
   14663                 :             :                                   == GOVD_SHARED));
   14664                 :          83 :                   OMP_CLAUSE_SET_CODE (c, OMP_CLAUSE_PRIVATE);
   14665                 :          83 :                   OMP_CLAUSE_PRIVATE_DEBUG (c) = 1;
   14666                 :             :                 }
   14667                 :       32023 :               if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
   14668                 :        4129 :                   && ctx->has_depend
   14669                 :       32581 :                   && DECL_P (decl))
   14670                 :         558 :                 n->value |= GOVD_WRITTEN;
   14671                 :       32023 :               if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
   14672                 :        4129 :                   && (n->value & GOVD_WRITTEN) == 0
   14673                 :        3018 :                   && DECL_P (decl)
   14674                 :       35041 :                   && omp_shared_to_firstprivate_optimizable_decl_p (decl))
   14675                 :         526 :                 OMP_CLAUSE_SHARED_READONLY (c) = 1;
   14676                 :       31497 :               else if (DECL_P (decl)
   14677                 :       31497 :                        && ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
   14678                 :        3603 :                             && (n->value & GOVD_WRITTEN) != 0)
   14679                 :       30386 :                            || (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR
   14680                 :        9039 :                                && !OMP_CLAUSE_LINEAR_NO_COPYOUT (c)))
   14681                 :       38537 :                        && omp_shared_to_firstprivate_optimizable_decl_p (decl))
   14682                 :        5736 :                 omp_mark_stores (gimplify_omp_ctxp->outer_context, decl);
   14683                 :             :             }
   14684                 :             :           else
   14685                 :        4592 :             n->value &= ~GOVD_EXPLICIT;
   14686                 :             :           break;
   14687                 :             : 
   14688                 :       12996 :         case OMP_CLAUSE_LASTPRIVATE:
   14689                 :             :           /* Make sure OMP_CLAUSE_LASTPRIVATE_FIRSTPRIVATE is set to
   14690                 :             :              accurately reflect the presence of a FIRSTPRIVATE clause.  */
   14691                 :       12996 :           decl = OMP_CLAUSE_DECL (c);
   14692                 :       12996 :           n = splay_tree_lookup (ctx->variables, (splay_tree_key) decl);
   14693                 :       12996 :           OMP_CLAUSE_LASTPRIVATE_FIRSTPRIVATE (c)
   14694                 :       12996 :             = (n->value & GOVD_FIRSTPRIVATE) != 0;
   14695                 :       12996 :           if (code == OMP_DISTRIBUTE
   14696                 :       12996 :               && OMP_CLAUSE_LASTPRIVATE_FIRSTPRIVATE (c))
   14697                 :             :             {
   14698                 :           4 :               remove = true;
   14699                 :           4 :               error_at (OMP_CLAUSE_LOCATION (c),
   14700                 :             :                         "same variable used in %<firstprivate%> and "
   14701                 :             :                         "%<lastprivate%> clauses on %<distribute%> "
   14702                 :             :                         "construct");
   14703                 :             :             }
   14704                 :       12996 :           if (!remove
   14705                 :       12992 :               && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
   14706                 :       12992 :               && DECL_P (decl)
   14707                 :       12992 :               && omp_shared_to_firstprivate_optimizable_decl_p (decl))
   14708                 :       11399 :             omp_mark_stores (gimplify_omp_ctxp->outer_context, decl);
   14709                 :       12996 :           if (OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c) && code == OMP_PARALLEL)
   14710                 :             :             remove = true;
   14711                 :             :           break;
   14712                 :             : 
   14713                 :         824 :         case OMP_CLAUSE_ALIGNED:
   14714                 :         824 :           decl = OMP_CLAUSE_DECL (c);
   14715                 :         824 :           if (!is_global_var (decl))
   14716                 :             :             {
   14717                 :         738 :               n = splay_tree_lookup (ctx->variables, (splay_tree_key) decl);
   14718                 :         738 :               remove = n == NULL || !(n->value & GOVD_SEEN);
   14719                 :          88 :               if (!remove && TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE)
   14720                 :             :                 {
   14721                 :          88 :                   struct gimplify_omp_ctx *octx;
   14722                 :          88 :                   if (n != NULL
   14723                 :          88 :                       && (n->value & (GOVD_DATA_SHARE_CLASS
   14724                 :             :                                       & ~GOVD_FIRSTPRIVATE)))
   14725                 :             :                     remove = true;
   14726                 :             :                   else
   14727                 :         100 :                     for (octx = ctx->outer_context; octx;
   14728                 :          12 :                          octx = octx->outer_context)
   14729                 :             :                       {
   14730                 :          24 :                         n = splay_tree_lookup (octx->variables,
   14731                 :             :                                                (splay_tree_key) decl);
   14732                 :          24 :                         if (n == NULL)
   14733                 :          12 :                           continue;
   14734                 :          12 :                         if (n->value & GOVD_LOCAL)
   14735                 :             :                           break;
   14736                 :             :                         /* We have to avoid assigning a shared variable
   14737                 :             :                            to itself when trying to add
   14738                 :             :                            __builtin_assume_aligned.  */
   14739                 :          12 :                         if (n->value & GOVD_SHARED)
   14740                 :             :                           {
   14741                 :             :                             remove = true;
   14742                 :             :                             break;
   14743                 :             :                           }
   14744                 :             :                       }
   14745                 :             :                 }
   14746                 :             :             }
   14747                 :          86 :           else if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
   14748                 :             :             {
   14749                 :          83 :               n = splay_tree_lookup (ctx->variables, (splay_tree_key) decl);
   14750                 :          83 :               if (n != NULL && (n->value & GOVD_DATA_SHARE_CLASS) != 0)
   14751                 :             :                 remove = true;
   14752                 :             :             }
   14753                 :             :           break;
   14754                 :             : 
   14755                 :         538 :         case OMP_CLAUSE_HAS_DEVICE_ADDR:
   14756                 :         538 :           decl = OMP_CLAUSE_DECL (c);
   14757                 :         538 :           while (INDIRECT_REF_P (decl)
   14758                 :         587 :                  || TREE_CODE (decl) == ARRAY_REF)
   14759                 :          49 :             decl = TREE_OPERAND (decl, 0);
   14760                 :         538 :           n = splay_tree_lookup (ctx->variables, (splay_tree_key) decl);
   14761                 :         538 :           remove = n == NULL || !(n->value & GOVD_SEEN);
   14762                 :             :           break;
   14763                 :             : 
   14764                 :         881 :         case OMP_CLAUSE_IS_DEVICE_PTR:
   14765                 :         881 :         case OMP_CLAUSE_NONTEMPORAL:
   14766                 :         881 :           decl = OMP_CLAUSE_DECL (c);
   14767                 :         881 :           n = splay_tree_lookup (ctx->variables, (splay_tree_key) decl);
   14768                 :         881 :           remove = n == NULL || !(n->value & GOVD_SEEN);
   14769                 :             :           break;
   14770                 :             : 
   14771                 :       51508 :         case OMP_CLAUSE_MAP:
   14772                 :       51508 :           decl = OMP_CLAUSE_DECL (c);
   14773                 :       51508 :           if (!grp_end)
   14774                 :             :             {
   14775                 :       29002 :               grp_start_p = list_p;
   14776                 :       29002 :               grp_end = *omp_group_last (grp_start_p);
   14777                 :             :             }
   14778                 :       51508 :           switch (OMP_CLAUSE_MAP_KIND (c))
   14779                 :             :             {
   14780                 :         123 :             case GOMP_MAP_PRESENT_ALLOC:
   14781                 :         123 :             case GOMP_MAP_PRESENT_TO:
   14782                 :         123 :             case GOMP_MAP_PRESENT_FROM:
   14783                 :         123 :             case GOMP_MAP_PRESENT_TOFROM:
   14784                 :         123 :               OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_FORCE_PRESENT);
   14785                 :         123 :               break;
   14786                 :             :             default:
   14787                 :             :               break;
   14788                 :             :             }
   14789                 :       51508 :           switch (code)
   14790                 :             :             {
   14791                 :        4567 :             case OACC_DATA:
   14792                 :        4567 :               if (TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE)
   14793                 :             :                 break;
   14794                 :             :               /* Fallthrough.  */
   14795                 :       16605 :             case OACC_HOST_DATA:
   14796                 :       16605 :             case OACC_ENTER_DATA:
   14797                 :       16605 :             case OACC_EXIT_DATA:
   14798                 :       16605 :             case OMP_TARGET_DATA:
   14799                 :       16605 :             case OMP_TARGET_ENTER_DATA:
   14800                 :       16605 :             case OMP_TARGET_EXIT_DATA:
   14801                 :       16605 :               if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FIRSTPRIVATE_POINTER
   14802                 :       16605 :                   || (OMP_CLAUSE_MAP_KIND (c)
   14803                 :             :                       == GOMP_MAP_FIRSTPRIVATE_REFERENCE))
   14804                 :             :                 /* For target {,enter ,exit }data only the array slice is
   14805                 :             :                    mapped, but not the pointer to it.  */
   14806                 :             :                 remove = true;
   14807                 :       16605 :               if (code == OMP_TARGET_EXIT_DATA
   14808                 :       16605 :                   && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ALWAYS_POINTER
   14809                 :        1613 :                       || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER))
   14810                 :             :                 remove = true;
   14811                 :             :               break;
   14812                 :             :             case OMP_TARGET:
   14813                 :             :               break;
   14814                 :             :             default:
   14815                 :             :               break;
   14816                 :             :             }
   14817                 :       16603 :           if (remove)
   14818                 :             :             break;
   14819                 :       51173 :           if (OMP_CLAUSE_SIZE (c) == NULL_TREE)
   14820                 :             :             {
   14821                 :             :               /* Sanity check: attach/detach map kinds use the size as a bias,
   14822                 :             :                  and it's never right to use the decl size for such
   14823                 :             :                  mappings.  */
   14824                 :       16331 :               gcc_assert (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH
   14825                 :             :                           && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_DETACH
   14826                 :             :                           && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FORCE_DETACH
   14827                 :             :                           && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH_DETACH
   14828                 :             :                           && (OMP_CLAUSE_MAP_KIND (c)
   14829                 :             :                               != GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION));
   14830                 :       19987 :               OMP_CLAUSE_SIZE (c) = DECL_P (decl) ? DECL_SIZE_UNIT (decl)
   14831                 :        3656 :                                     : TYPE_SIZE_UNIT (TREE_TYPE (decl));
   14832                 :             :             }
   14833                 :       51173 :           gimplify_omp_ctxp = ctx->outer_context;
   14834                 :       51173 :           if (gimplify_expr (&OMP_CLAUSE_SIZE (c), pre_p, NULL,
   14835                 :             :                                   is_gimple_val, fb_rvalue) == GS_ERROR)
   14836                 :             :             {
   14837                 :           0 :               gimplify_omp_ctxp = ctx;
   14838                 :           0 :               remove = true;
   14839                 :           0 :               break;
   14840                 :             :             }
   14841                 :       51173 :           else if ((OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FIRSTPRIVATE_POINTER
   14842                 :       48473 :                     || (OMP_CLAUSE_MAP_KIND (c)
   14843                 :             :                         == GOMP_MAP_FIRSTPRIVATE_REFERENCE)
   14844                 :       48090 :                     || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH_DETACH)
   14845                 :       56874 :                    && TREE_CODE (OMP_CLAUSE_SIZE (c)) != INTEGER_CST)
   14846                 :             :             {
   14847                 :         774 :               OMP_CLAUSE_SIZE (c)
   14848                 :        1548 :                 = get_initialized_tmp_var (OMP_CLAUSE_SIZE (c), pre_p, NULL,
   14849                 :             :                                            false);
   14850                 :         774 :               if ((ctx->region_type & ORT_TARGET) != 0)
   14851                 :         599 :                 omp_add_variable (ctx, OMP_CLAUSE_SIZE (c),
   14852                 :             :                                   GOVD_FIRSTPRIVATE | GOVD_SEEN);
   14853                 :             :             }
   14854                 :       51173 :           gimplify_omp_ctxp = ctx;
   14855                 :             :           /* Data clauses associated with reductions must be
   14856                 :             :              compatible with present_or_copy.  Warn and adjust the clause
   14857                 :             :              if that is not the case.  */
   14858                 :       51173 :           if (ctx->region_type == ORT_ACC_PARALLEL
   14859                 :       42203 :               || ctx->region_type == ORT_ACC_SERIAL)
   14860                 :             :             {
   14861                 :        9498 :               tree t = DECL_P (decl) ? decl : TREE_OPERAND (decl, 0);
   14862                 :        9498 :               n = NULL;
   14863                 :             : 
   14864                 :        9498 :               if (DECL_P (t))
   14865                 :        7737 :                 n = splay_tree_lookup (ctx->variables, (splay_tree_key) t);
   14866                 :             : 
   14867                 :        7737 :               if (n && (n->value & GOVD_REDUCTION))
   14868                 :             :                 {
   14869                 :         807 :                   enum gomp_map_kind kind = OMP_CLAUSE_MAP_KIND (c);
   14870                 :             : 
   14871                 :         807 :                   OMP_CLAUSE_MAP_IN_REDUCTION (c) = 1;
   14872                 :         807 :                   if ((kind & GOMP_MAP_TOFROM) != GOMP_MAP_TOFROM
   14873                 :         159 :                       && kind != GOMP_MAP_FORCE_PRESENT
   14874                 :         159 :                       && kind != GOMP_MAP_POINTER)
   14875                 :             :                     {
   14876                 :         120 :                       warning_at (OMP_CLAUSE_LOCATION (c), 0,
   14877                 :             :                                   "incompatible data clause with reduction "
   14878                 :             :                                   "on %qE; promoting to %<present_or_copy%>",
   14879                 :         120 :                                   DECL_NAME (t));
   14880                 :         120 :                       OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TOFROM);
   14881                 :             :                     }
   14882                 :             :                 }
   14883                 :             :             }
   14884                 :       51173 :           if ((OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_STRUCT
   14885                 :       48735 :                || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_STRUCT_UNORD)
   14886                 :       51281 :               && (code == OMP_TARGET_EXIT_DATA || code == OACC_EXIT_DATA))
   14887                 :             :             {
   14888                 :             :               remove = true;
   14889                 :             :               break;
   14890                 :             :             }
   14891                 :             :           /* If we have a DECL_VALUE_EXPR (e.g. this is a class member and/or
   14892                 :             :              a variable captured in a lambda closure), look through that now
   14893                 :             :              before the DECL_P check below.  (A code other than COMPONENT_REF,
   14894                 :             :              i.e. INDIRECT_REF, will be a VLA/variable-length array
   14895                 :             :              section.  A global var may be a variable in a common block.  We
   14896                 :             :              don't want to do this here for either of those.)  */
   14897                 :       50778 :           if ((ctx->region_type & ORT_ACC) == 0
   14898                 :       24727 :               && DECL_P (decl)
   14899                 :       10891 :               && !is_global_var (decl)
   14900                 :        9635 :               && DECL_HAS_VALUE_EXPR_P (decl)
   14901                 :       50968 :               && TREE_CODE (DECL_VALUE_EXPR (decl)) == COMPONENT_REF)
   14902                 :           0 :             decl = OMP_CLAUSE_DECL (c) = DECL_VALUE_EXPR (decl);
   14903                 :       50778 :           if (TREE_CODE (decl) == TARGET_EXPR)
   14904                 :             :             {
   14905                 :           0 :               if (gimplify_expr (&OMP_CLAUSE_DECL (c), pre_p, NULL,
   14906                 :             :                                  is_gimple_lvalue, fb_lvalue) == GS_ERROR)
   14907                 :       24324 :                 remove = true;
   14908                 :             :             }
   14909                 :       50778 :           else if (!DECL_P (decl))
   14910                 :             :             {
   14911                 :       26454 :               if ((ctx->region_type & ORT_TARGET) != 0
   14912                 :       26454 :                   && OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FIRSTPRIVATE_POINTER)
   14913                 :             :                 {
   14914                 :          22 :                   if (INDIRECT_REF_P (decl)
   14915                 :           0 :                       && TREE_CODE (TREE_OPERAND (decl, 0)) == COMPONENT_REF
   14916                 :          22 :                       && (TREE_CODE (TREE_TYPE (TREE_OPERAND (decl, 0)))
   14917                 :             :                           == REFERENCE_TYPE))
   14918                 :           0 :                     decl = TREE_OPERAND (decl, 0);
   14919                 :          22 :                   if (TREE_CODE (decl) == COMPONENT_REF)
   14920                 :             :                     {
   14921                 :           0 :                       while (TREE_CODE (decl) == COMPONENT_REF)
   14922                 :           0 :                         decl = TREE_OPERAND (decl, 0);
   14923                 :           0 :                       if (DECL_P (decl))
   14924                 :             :                         {
   14925                 :           0 :                           n = splay_tree_lookup (ctx->variables,
   14926                 :             :                                                  (splay_tree_key) decl);
   14927                 :           0 :                           if (!(n->value & GOVD_SEEN))
   14928                 :       26454 :                             remove = true;
   14929                 :             :                         }
   14930                 :             :                     }
   14931                 :             :                 }
   14932                 :             : 
   14933                 :       26454 :               tree d = decl, *pd;
   14934                 :       26454 :               if (TREE_CODE (d) == ARRAY_REF)
   14935                 :             :                 {
   14936                 :        5422 :                   while (TREE_CODE (d) == ARRAY_REF)
   14937                 :        2769 :                     d = TREE_OPERAND (d, 0);
   14938                 :        2653 :                   if (TREE_CODE (d) == COMPONENT_REF
   14939                 :        2653 :                       && TREE_CODE (TREE_TYPE (d)) == ARRAY_TYPE)
   14940                 :             :                     decl = d;
   14941                 :             :                 }
   14942                 :       26454 :               pd = &OMP_CLAUSE_DECL (c);
   14943                 :       26454 :               if (d == decl
   14944                 :       24150 :                   && TREE_CODE (decl) == INDIRECT_REF
   14945                 :       14399 :                   && TREE_CODE (TREE_OPERAND (decl, 0)) == COMPONENT_REF
   14946                 :        1383 :                   && (TREE_CODE (TREE_TYPE (TREE_OPERAND (decl, 0)))
   14947                 :             :                       == REFERENCE_TYPE)
   14948                 :       27254 :                   && (OMP_CLAUSE_MAP_KIND (c)
   14949                 :             :                       != GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION))
   14950                 :             :                 {
   14951                 :         796 :                   pd = &TREE_OPERAND (decl, 0);
   14952                 :         796 :                   decl = TREE_OPERAND (decl, 0);
   14953                 :             :                 }
   14954                 :             : 
   14955                 :       26454 :               if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH_DETACH)
   14956                 :        2415 :                 switch (code)
   14957                 :             :                   {
   14958                 :         427 :                   case OACC_ENTER_DATA:
   14959                 :         427 :                   case OACC_EXIT_DATA:
   14960                 :         427 :                     if (TREE_CODE (TREE_TYPE (OMP_CLAUSE_DECL (c)))
   14961                 :             :                         == ARRAY_TYPE)
   14962                 :             :                       remove = true;
   14963                 :         417 :                     else if (code == OACC_ENTER_DATA)
   14964                 :         263 :                       goto change_to_attach;
   14965                 :             :                     /* Fallthrough.  */
   14966                 :         328 :                   case OMP_TARGET_EXIT_DATA:
   14967                 :         328 :                     OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_DETACH);
   14968                 :         328 :                     break;
   14969                 :          71 :                   case OACC_UPDATE:
   14970                 :             :                     /* An "attach/detach" operation on an update directive
   14971                 :             :                        should behave as a GOMP_MAP_ALWAYS_POINTER.  Note that
   14972                 :             :                        both GOMP_MAP_ATTACH_DETACH and GOMP_MAP_ALWAYS_POINTER
   14973                 :             :                        kinds depend on the previous mapping (for non-TARGET
   14974                 :             :                        regions).  */
   14975                 :          71 :                     OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALWAYS_POINTER);
   14976                 :          71 :                     break;
   14977                 :        2016 :                   default:
   14978                 :        2016 :                   change_to_attach:
   14979                 :        2016 :                     OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ATTACH);
   14980                 :        2016 :                     if ((ctx->region_type & ORT_TARGET) != 0)
   14981                 :        1631 :                       move_attach = true;
   14982                 :             :                   }
   14983                 :       24039 :               else if ((ctx->region_type & ORT_TARGET) != 0
   14984                 :       24039 :                        && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
   14985                 :       10896 :                            || (OMP_CLAUSE_MAP_KIND (c)
   14986                 :             :                                == GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION)))
   14987                 :             :                 move_attach = true;
   14988                 :             : 
   14989                 :             :               /* If we have e.g. map(struct: *var), don't gimplify the
   14990                 :             :                  argument since omp-low.cc wants to see the decl itself.  */
   14991                 :       26454 :               if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_STRUCT)
   14992                 :             :                 break;
   14993                 :             : 
   14994                 :             :               /* We've already partly gimplified this in
   14995                 :             :                  gimplify_scan_omp_clauses.  Don't do any more.  */
   14996                 :       25348 :               if (code == OMP_TARGET && OMP_CLAUSE_MAP_IN_REDUCTION (c))
   14997                 :             :                 break;
   14998                 :             : 
   14999                 :       25260 :               gimplify_omp_ctxp = ctx->outer_context;
   15000                 :       25260 :               if (gimplify_expr (pd, pre_p, NULL, is_gimple_lvalue,
   15001                 :             :                                  fb_lvalue) == GS_ERROR)
   15002                 :           0 :                 remove = true;
   15003                 :       25260 :               gimplify_omp_ctxp = ctx;
   15004                 :       25260 :               break;
   15005                 :             :             }
   15006                 :             : 
   15007                 :       24324 :          if ((code == OMP_TARGET
   15008                 :             :               || code == OMP_TARGET_DATA
   15009                 :             :               || code == OMP_TARGET_ENTER_DATA
   15010                 :       14187 :               || code == OMP_TARGET_EXIT_DATA)
   15011                 :       24816 :              && OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH_DETACH)
   15012                 :             :            {
   15013                 :         203 :              bool firstprivatize = false;
   15014                 :             : 
   15015                 :         208 :              for (struct gimplify_omp_ctx *octx = ctx->outer_context; octx;
   15016                 :           5 :                   octx = octx->outer_context)
   15017                 :             :                {
   15018                 :           6 :                  splay_tree_node n
   15019                 :          12 :                    = splay_tree_lookup (octx->variables,
   15020                 :           6 :                                         (splay_tree_key) OMP_CLAUSE_DECL (c));
   15021                 :             :                  /* If this is contained in an outer OpenMP region as a
   15022                 :             :                     firstprivate value, remove the attach/detach.  */
   15023                 :           6 :                  if (n && (n->value & GOVD_FIRSTPRIVATE))
   15024                 :             :                    {
   15025                 :             :                      firstprivatize = true;
   15026                 :             :                      break;
   15027                 :             :                    }
   15028                 :             :                }
   15029                 :             : 
   15030                 :         203 :              enum gomp_map_kind map_kind;
   15031                 :         203 :              if (firstprivatize)
   15032                 :             :                map_kind = GOMP_MAP_FIRSTPRIVATE_POINTER;
   15033                 :         202 :              else if (code == OMP_TARGET_EXIT_DATA)
   15034                 :             :                map_kind = GOMP_MAP_DETACH;
   15035                 :             :              else
   15036                 :         161 :                map_kind = GOMP_MAP_ATTACH;
   15037                 :         203 :              OMP_CLAUSE_SET_MAP_KIND (c, map_kind);
   15038                 :             :            }
   15039                 :       24121 :          else if ((ctx->region_type & ORT_ACC) != 0
   15040                 :       24121 :                   && OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH_DETACH)
   15041                 :             :            {
   15042                 :           0 :              enum gomp_map_kind map_kind = (code == OACC_EXIT_DATA
   15043                 :           0 :                                             ? GOMP_MAP_DETACH
   15044                 :             :                                             : GOMP_MAP_ATTACH);
   15045                 :           0 :              OMP_CLAUSE_SET_MAP_KIND (c, map_kind);
   15046                 :             :            }
   15047                 :             : 
   15048                 :       24324 :           n = splay_tree_lookup (ctx->variables, (splay_tree_key) decl);
   15049                 :       24324 :           if ((ctx->region_type & ORT_TARGET) != 0
   15050                 :       14924 :               && !(n->value & GOVD_SEEN)
   15051                 :        1362 :               && GOMP_MAP_ALWAYS_P (OMP_CLAUSE_MAP_KIND (c)) == 0
   15052                 :       25443 :               && (!is_global_var (decl)
   15053                 :          75 :                   || !lookup_attribute ("omp declare target link",
   15054                 :          75 :                                         DECL_ATTRIBUTES (decl))))
   15055                 :             :             {
   15056                 :        1107 :               remove = true;
   15057                 :             :               /* For struct element mapping, if struct is never referenced
   15058                 :             :                  in target block and none of the mapping has always modifier,
   15059                 :             :                  remove all the struct element mappings, which immediately
   15060                 :             :                  follow the GOMP_MAP_STRUCT map clause.  */
   15061                 :        1107 :               if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_STRUCT
   15062                 :        1107 :                   || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_STRUCT_UNORD)
   15063                 :             :                 {
   15064                 :          28 :                   HOST_WIDE_INT cnt = tree_to_shwi (OMP_CLAUSE_SIZE (c));
   15065                 :          76 :                   while (cnt--)
   15066                 :          48 :                     OMP_CLAUSE_CHAIN (c)
   15067                 :          48 :                       = OMP_CLAUSE_CHAIN (OMP_CLAUSE_CHAIN (c));
   15068                 :             :                 }
   15069                 :             :             }
   15070                 :       23217 :           else if (DECL_SIZE (decl)
   15071                 :       23193 :                    && !poly_int_tree_p (DECL_SIZE (decl))
   15072                 :         199 :                    && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_POINTER
   15073                 :         199 :                    && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FIRSTPRIVATE_POINTER
   15074                 :       23268 :                    && (OMP_CLAUSE_MAP_KIND (c)
   15075                 :             :                        != GOMP_MAP_FIRSTPRIVATE_REFERENCE))
   15076                 :             :             {
   15077                 :             :               /* For GOMP_MAP_FORCE_DEVICEPTR, we'll never enter here, because
   15078                 :             :                  for these, TREE_CODE (DECL_SIZE (decl)) will always be
   15079                 :             :                  INTEGER_CST.  */
   15080                 :          51 :               gcc_assert (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FORCE_DEVICEPTR);
   15081                 :             : 
   15082                 :          51 :               tree decl2 = DECL_VALUE_EXPR (decl);
   15083                 :          51 :               gcc_assert (INDIRECT_REF_P (decl2));
   15084                 :          51 :               decl2 = TREE_OPERAND (decl2, 0);
   15085                 :          51 :               gcc_assert (DECL_P (decl2));
   15086                 :          51 :               tree mem = build_simple_mem_ref (decl2);
   15087                 :          51 :               OMP_CLAUSE_DECL (c) = mem;
   15088                 :          51 :               OMP_CLAUSE_SIZE (c) = TYPE_SIZE_UNIT (TREE_TYPE (decl));
   15089                 :          51 :               if (ctx->outer_context)
   15090                 :             :                 {
   15091                 :          15 :                   omp_notice_variable (ctx->outer_context, decl2, true);
   15092                 :          30 :                   omp_notice_variable (ctx->outer_context,
   15093                 :          15 :                                        OMP_CLAUSE_SIZE (c), true);
   15094                 :             :                 }
   15095                 :          51 :               if (((ctx->region_type & ORT_TARGET) != 0
   15096                 :          24 :                    || !ctx->target_firstprivatize_array_bases)
   15097                 :          34 :                   && ((n->value & GOVD_SEEN) == 0
   15098                 :          30 :                       || (n->value & (GOVD_PRIVATE | GOVD_FIRSTPRIVATE)) == 0))
   15099                 :             :                 {
   15100                 :          34 :                   tree nc = build_omp_clause (OMP_CLAUSE_LOCATION (c),
   15101                 :             :                                               OMP_CLAUSE_MAP);
   15102                 :          34 :                   OMP_CLAUSE_DECL (nc) = decl;
   15103                 :          34 :                   OMP_CLAUSE_SIZE (nc) = size_zero_node;
   15104                 :          34 :                   if (ctx->target_firstprivatize_array_bases)
   15105                 :          27 :                     OMP_CLAUSE_SET_MAP_KIND (nc,
   15106                 :             :                                              GOMP_MAP_FIRSTPRIVATE_POINTER);
   15107                 :             :                   else
   15108                 :           7 :                     OMP_CLAUSE_SET_MAP_KIND (nc, GOMP_MAP_POINTER);
   15109                 :          34 :                   OMP_CLAUSE_CHAIN (nc) = OMP_CLAUSE_CHAIN (c);
   15110                 :          34 :                   OMP_CLAUSE_CHAIN (c) = nc;
   15111                 :          34 :                   c = nc;
   15112                 :             :                 }
   15113                 :             :             }
   15114                 :             :           else
   15115                 :             :             {
   15116                 :       23166 :               if (OMP_CLAUSE_SIZE (c) == NULL_TREE)
   15117                 :           0 :                 OMP_CLAUSE_SIZE (c) = DECL_SIZE_UNIT (decl);
   15118                 :       23166 :               gcc_assert ((n->value & GOVD_SEEN) == 0
   15119                 :             :                           || ((n->value & (GOVD_PRIVATE | GOVD_FIRSTPRIVATE))
   15120                 :             :                               == 0));
   15121                 :             :             }
   15122                 :             : 
   15123                 :             :           /* If we have a target region, we can push all the attaches to the
   15124                 :             :              end of the list (we may have standalone "attach" operations
   15125                 :             :              synthesized for GOMP_MAP_STRUCT nodes that must be processed after
   15126                 :             :              the attachment point AND the pointed-to block have been mapped).
   15127                 :             :              If we have something else, e.g. "enter data", we need to keep
   15128                 :             :              "attach" nodes together with the previous node they attach to so
   15129                 :             :              that separate "exit data" operations work properly (see
   15130                 :             :              libgomp/target.c).  */
   15131                 :       24324 :           if ((ctx->region_type & ORT_TARGET) != 0
   15132                 :       24324 :               && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
   15133                 :       14826 :                   || (OMP_CLAUSE_MAP_KIND (c)
   15134                 :             :                       == GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION)))
   15135                 :             :             move_attach = true;
   15136                 :             : 
   15137                 :             :           break;
   15138                 :             : 
   15139                 :        8188 :         case OMP_CLAUSE_TO:
   15140                 :        8188 :         case OMP_CLAUSE_FROM:
   15141                 :        8188 :         case OMP_CLAUSE__CACHE_:
   15142                 :        8188 :           decl = OMP_CLAUSE_DECL (c);
   15143                 :        8188 :           if (!DECL_P (decl))
   15144                 :             :             break;
   15145                 :        6181 :           if (DECL_SIZE (decl)
   15146                 :        6181 :               && TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
   15147                 :             :             {
   15148                 :           4 :               tree decl2 = DECL_VALUE_EXPR (decl);
   15149                 :           4 :               gcc_assert (INDIRECT_REF_P (decl2));
   15150                 :           4 :               decl2 = TREE_OPERAND (decl2, 0);
   15151                 :           4 :               gcc_assert (DECL_P (decl2));
   15152                 :           4 :               tree mem = build_simple_mem_ref (decl2);
   15153                 :           4 :               OMP_CLAUSE_DECL (c) = mem;
   15154                 :           4 :               OMP_CLAUSE_SIZE (c) = TYPE_SIZE_UNIT (TREE_TYPE (decl));
   15155                 :           4 :               if (ctx->outer_context)
   15156                 :             :                 {
   15157                 :           4 :                   omp_notice_variable (ctx->outer_context, decl2, true);
   15158                 :           4 :                   omp_notice_variable (ctx->outer_context,
   15159                 :           4 :                                        OMP_CLAUSE_SIZE (c), true);
   15160                 :             :                 }
   15161                 :             :             }
   15162                 :        6177 :           else if (OMP_CLAUSE_SIZE (c) == NULL_TREE)
   15163                 :           0 :             OMP_CLAUSE_SIZE (c) = DECL_SIZE_UNIT (decl);
   15164                 :             :           break;
   15165                 :             : 
   15166                 :       15257 :         case OMP_CLAUSE_REDUCTION:
   15167                 :       15257 :           if (OMP_CLAUSE_REDUCTION_INSCAN (c))
   15168                 :             :             {
   15169                 :         811 :               decl = OMP_CLAUSE_DECL (c);
   15170                 :         811 :               n = splay_tree_lookup (ctx->variables, (splay_tree_key) decl);
   15171                 :         811 :               if ((n->value & GOVD_REDUCTION_INSCAN) == 0)
   15172                 :             :                 {
   15173                 :          69 :                   remove = true;
   15174                 :          69 :                   error_at (OMP_CLAUSE_LOCATION (c),
   15175                 :             :                             "%qD specified in %<inscan%> %<reduction%> clause "
   15176                 :             :                             "but not in %<scan%> directive clause", decl);
   15177                 :          69 :                   break;
   15178                 :             :                 }
   15179                 :             :               has_inscan_reductions = true;
   15180                 :             :             }
   15181                 :             :           /* FALLTHRU */
   15182                 :       17788 :         case OMP_CLAUSE_IN_REDUCTION:
   15183                 :       17788 :         case OMP_CLAUSE_TASK_REDUCTION:
   15184                 :       17788 :           decl = OMP_CLAUSE_DECL (c);
   15185                 :             :           /* OpenACC reductions need a present_or_copy data clause.
   15186                 :             :              Add one if necessary.  Emit error when the reduction is private.  */
   15187                 :       17788 :           if (ctx->region_type == ORT_ACC_PARALLEL
   15188                 :       17257 :               || ctx->region_type == ORT_ACC_SERIAL)
   15189                 :             :             {
   15190                 :         801 :               n = splay_tree_lookup (ctx->variables, (splay_tree_key) decl);
   15191                 :         801 :               if (n->value & (GOVD_PRIVATE | GOVD_FIRSTPRIVATE))
   15192                 :             :                 {
   15193                 :          13 :                   remove = true;
   15194                 :          13 :                   error_at (OMP_CLAUSE_LOCATION (c), "invalid private "
   15195                 :          13 :                             "reduction on %qE", DECL_NAME (decl));
   15196                 :             :                 }
   15197                 :         788 :               else if ((n->value & GOVD_MAP) == 0)
   15198                 :             :                 {
   15199                 :         522 :                   tree next = OMP_CLAUSE_CHAIN (c);
   15200                 :         522 :                   tree nc = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE_MAP);
   15201                 :         522 :                   OMP_CLAUSE_SET_MAP_KIND (nc, GOMP_MAP_TOFROM);
   15202                 :         522 :                   OMP_CLAUSE_DECL (nc) = decl;
   15203                 :         522 :                   OMP_CLAUSE_CHAIN (c) = nc;
   15204                 :         522 :                   lang_hooks.decls.omp_finish_clause (nc, pre_p,
   15205                 :         522 :                                                       (ctx->region_type
   15206                 :             :                                                        & ORT_ACC) != 0);
   15207                 :         548 :                   while (1)
   15208                 :             :                     {
   15209                 :         535 :                       OMP_CLAUSE_MAP_IN_REDUCTION (nc) = 1;
   15210                 :         535 :                       if (OMP_CLAUSE_CHAIN (nc) == NULL)
   15211                 :             :                         break;
   15212                 :          13 :                       nc = OMP_CLAUSE_CHAIN (nc);
   15213                 :             :                     }
   15214                 :         522 :                   OMP_CLAUSE_CHAIN (nc) = next;
   15215                 :         522 :                   n->value |= GOVD_MAP;
   15216                 :             :                 }
   15217                 :             :             }
   15218                 :       17788 :           if (DECL_P (decl)
   15219                 :       17788 :               && omp_shared_to_firstprivate_optimizable_decl_p (decl))
   15220                 :        7962 :             omp_mark_stores (gimplify_omp_ctxp->outer_context, decl);
   15221                 :             :           break;
   15222                 :             : 
   15223                 :        3541 :         case OMP_CLAUSE_ALLOCATE:
   15224                 :        3541 :           decl = OMP_CLAUSE_DECL (c);
   15225                 :        3541 :           n = splay_tree_lookup (ctx->variables, (splay_tree_key) decl);
   15226                 :        3541 :           if (n != NULL && !(n->value & GOVD_SEEN))
   15227                 :             :             {
   15228                 :        1176 :               if ((n->value & (GOVD_PRIVATE | GOVD_FIRSTPRIVATE | GOVD_LINEAR))
   15229                 :             :                   != 0
   15230                 :        1176 :                   && (n->value & (GOVD_REDUCTION | GOVD_LASTPRIVATE)) == 0)
   15231                 :             :                 remove = true;
   15232                 :             :             }
   15233                 :             :           if (!remove
   15234                 :        2365 :               && OMP_CLAUSE_ALLOCATE_ALLOCATOR (c)
   15235                 :        1153 :               && TREE_CODE (OMP_CLAUSE_ALLOCATE_ALLOCATOR (c)) != INTEGER_CST
   15236                 :         471 :               && ((ctx->region_type & (ORT_PARALLEL | ORT_TARGET)) != 0
   15237                 :         347 :                   || (ctx->region_type & ORT_TASKLOOP) == ORT_TASK
   15238                 :         287 :                   || (ctx->region_type & ORT_HOST_TEAMS) == ORT_HOST_TEAMS))
   15239                 :             :             {
   15240                 :         202 :               tree allocator = OMP_CLAUSE_ALLOCATE_ALLOCATOR (c);
   15241                 :         202 :               n = splay_tree_lookup (ctx->variables, (splay_tree_key) allocator);
   15242                 :         202 :               if (n == NULL)
   15243                 :             :                 {
   15244                 :          82 :                   enum omp_clause_default_kind default_kind
   15245                 :             :                     = ctx->default_kind;
   15246                 :          82 :                   ctx->default_kind = OMP_CLAUSE_DEFAULT_FIRSTPRIVATE;
   15247                 :          82 :                   omp_notice_variable (ctx, OMP_CLAUSE_ALLOCATE_ALLOCATOR (c),
   15248                 :             :                                        true);
   15249                 :          82 :                   ctx->default_kind = default_kind;
   15250                 :             :                 }
   15251                 :             :               else
   15252                 :         120 :                 omp_notice_variable (ctx, OMP_CLAUSE_ALLOCATE_ALLOCATOR (c),
   15253                 :             :                                      true);
   15254                 :             :             }
   15255                 :             :           break;
   15256                 :             : 
   15257                 :             :         case OMP_CLAUSE_COPYIN:
   15258                 :             :         case OMP_CLAUSE_COPYPRIVATE:
   15259                 :             :         case OMP_CLAUSE_IF:
   15260                 :             :         case OMP_CLAUSE_SELF:
   15261                 :             :         case OMP_CLAUSE_NUM_THREADS:
   15262                 :             :         case OMP_CLAUSE_NUM_TEAMS:
   15263                 :             :         case OMP_CLAUSE_THREAD_LIMIT:
   15264                 :             :         case OMP_CLAUSE_DIST_SCHEDULE:
   15265                 :             :         case OMP_CLAUSE_DEVICE:
   15266                 :             :         case OMP_CLAUSE_SCHEDULE:
   15267                 :             :         case OMP_CLAUSE_NOWAIT:
   15268                 :             :         case OMP_CLAUSE_ORDERED:
   15269                 :             :         case OMP_CLAUSE_DEFAULT:
   15270                 :             :         case OMP_CLAUSE_UNTIED:
   15271                 :             :         case OMP_CLAUSE_COLLAPSE:
   15272                 :             :         case OMP_CLAUSE_FINAL:
   15273                 :             :         case OMP_CLAUSE_MERGEABLE:
   15274                 :             :         case OMP_CLAUSE_PROC_BIND:
   15275                 :             :         case OMP_CLAUSE_SAFELEN:
   15276                 :             :         case OMP_CLAUSE_SIMDLEN:
   15277                 :             :         case OMP_CLAUSE_DEPEND:
   15278                 :             :         case OMP_CLAUSE_DOACROSS:
   15279                 :             :         case OMP_CLAUSE_PRIORITY:
   15280                 :             :         case OMP_CLAUSE_GRAINSIZE:
   15281                 :             :         case OMP_CLAUSE_NUM_TASKS:
   15282                 :             :         case OMP_CLAUSE_NOGROUP:
   15283                 :             :         case OMP_CLAUSE_THREADS:
   15284                 :             :         case OMP_CLAUSE_SIMD:
   15285                 :             :         case OMP_CLAUSE_FILTER:
   15286                 :             :         case OMP_CLAUSE_HINT:
   15287                 :             :         case OMP_CLAUSE_DEFAULTMAP:
   15288                 :             :         case OMP_CLAUSE_ORDER:
   15289                 :             :         case OMP_CLAUSE_BIND:
   15290                 :             :         case OMP_CLAUSE_DETACH:
   15291                 :             :         case OMP_CLAUSE_USE_DEVICE_PTR:
   15292                 :             :         case OMP_CLAUSE_USE_DEVICE_ADDR:
   15293                 :             :         case OMP_CLAUSE_ASYNC:
   15294                 :             :         case OMP_CLAUSE_WAIT:
   15295                 :             :         case OMP_CLAUSE_INDEPENDENT:
   15296                 :             :         case OMP_CLAUSE_NUM_GANGS:
   15297                 :             :         case OMP_CLAUSE_NUM_WORKERS:
   15298                 :             :         case OMP_CLAUSE_VECTOR_LENGTH:
   15299                 :             :         case OMP_CLAUSE_GANG:
   15300                 :             :         case OMP_CLAUSE_WORKER:
   15301                 :             :         case OMP_CLAUSE_VECTOR:
   15302                 :             :         case OMP_CLAUSE_AUTO:
   15303                 :             :         case OMP_CLAUSE_SEQ:
   15304                 :             :         case OMP_CLAUSE_TILE:
   15305                 :             :         case OMP_CLAUSE_IF_PRESENT:
   15306                 :             :         case OMP_CLAUSE_FINALIZE:
   15307                 :             :         case OMP_CLAUSE_INCLUSIVE:
   15308                 :             :         case OMP_CLAUSE_EXCLUSIVE:
   15309                 :             :           break;
   15310                 :             : 
   15311                 :           0 :         case OMP_CLAUSE_NOHOST:
   15312                 :           0 :         default:
   15313                 :           0 :           gcc_unreachable ();
   15314                 :             :         }
   15315                 :             : 
   15316                 :      123825 :       if (remove)
   15317                 :        9529 :         *list_p = OMP_CLAUSE_CHAIN (c);
   15318                 :      230473 :       else if (move_attach)
   15319                 :             :         {
   15320                 :             :           /* Remove attach node from here, separate out into its own list.  */
   15321                 :        2132 :           *attach_tail = c;
   15322                 :        2132 :           *list_p = OMP_CLAUSE_CHAIN (c);
   15323                 :        2132 :           OMP_CLAUSE_CHAIN (c) = NULL_TREE;
   15324                 :        2132 :           attach_tail = &OMP_CLAUSE_CHAIN (c);
   15325                 :             :         }
   15326                 :             :       else
   15327                 :      228341 :         list_p = &OMP_CLAUSE_CHAIN (c);
   15328                 :             :     }
   15329                 :             : 
   15330                 :             :   /* Splice attach nodes at the end of the list.  */
   15331                 :      127074 :   if (attach_list)
   15332                 :             :     {
   15333                 :        1020 :       *list_p = attach_list;
   15334                 :        1020 :       list_p = attach_tail;
   15335                 :             :     }
   15336                 :             : 
   15337                 :             :   /* Add in any implicit data sharing.  */
   15338                 :      127074 :   struct gimplify_adjust_omp_clauses_data data;
   15339                 :      127074 :   if ((gimplify_omp_ctxp->region_type & ORT_ACC) == 0)
   15340                 :             :     {
   15341                 :             :       /* OpenMP.  Implicit clauses are added at the start of the clause list,
   15342                 :             :          but after any non-map clauses.  */
   15343                 :             :       tree *implicit_add_list_p = orig_list_p;
   15344                 :      246892 :       while (*implicit_add_list_p
   15345                 :      246892 :              && OMP_CLAUSE_CODE (*implicit_add_list_p) != OMP_CLAUSE_MAP)
   15346                 :      149655 :         implicit_add_list_p = &OMP_CLAUSE_CHAIN (*implicit_add_list_p);
   15347                 :       97237 :       data.list_p = implicit_add_list_p;
   15348                 :             :     }
   15349                 :             :   else
   15350                 :             :     /* OpenACC.  */
   15351                 :       29837 :     data.list_p = list_p;
   15352                 :      127074 :   data.pre_p = pre_p;
   15353                 :      127074 :   splay_tree_foreach (ctx->variables, gimplify_adjust_omp_clauses_1, &data);
   15354                 :             : 
   15355                 :      127074 :   if (has_inscan_reductions)
   15356                 :        2431 :     for (c = *orig_list_p; c; c = OMP_CLAUSE_CHAIN (c))
   15357                 :        1822 :       if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR
   15358                 :        1822 :           && !OMP_CLAUSE_LINEAR_NO_COPYIN (c))
   15359                 :             :         {
   15360                 :           5 :           error_at (OMP_CLAUSE_LOCATION (c),
   15361                 :             :                     "%<inscan%> %<reduction%> clause used together with "
   15362                 :             :                     "%<linear%> clause for a variable other than loop "
   15363                 :             :                     "iterator");
   15364                 :           5 :           break;
   15365                 :             :         }
   15366                 :             : 
   15367                 :      127074 :   gimplify_omp_ctxp = ctx->outer_context;
   15368                 :      127074 :   delete_omp_context (ctx);
   15369                 :      127074 : }
   15370                 :             : 
   15371                 :             : /* Try to evaluate a novariants clause. Return 1 if true, 0 if false or absent,
   15372                 :             :  * -1 if run-time evaluation is needed. */
   15373                 :             : 
   15374                 :             : int
   15375                 :      200248 : omp_has_novariants (void)
   15376                 :             : {
   15377                 :      200248 :   struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp;
   15378                 :      200248 :   if (ctx != NULL && ctx->code == OMP_DISPATCH && !ctx->in_call_args)
   15379                 :             :     {
   15380                 :        3063 :       tree c = omp_find_clause (ctx->clauses, OMP_CLAUSE_NOVARIANTS);
   15381                 :        3063 :       if (c != NULL_TREE)
   15382                 :             :         {
   15383                 :         287 :           if (integer_nonzerop (OMP_CLAUSE_NOVARIANTS_EXPR (c)))
   15384                 :             :             return 1;
   15385                 :         171 :           else if (integer_zerop (OMP_CLAUSE_NOVARIANTS_EXPR (c)))
   15386                 :             :             return 0;
   15387                 :             :           else
   15388                 :             :             return -1;
   15389                 :             :         }
   15390                 :             :       return 0;
   15391                 :             :     }
   15392                 :             :   return 0;
   15393                 :             : }
   15394                 :             : 
   15395                 :             : /* Try to evaluate a nocontext clause. Return 1 if true, 0 if false or absent,
   15396                 :             :  * -1 if run-time evaluation is needed. */
   15397                 :             : 
   15398                 :             : static int
   15399                 :        1815 : omp_has_nocontext (void)
   15400                 :             : {
   15401                 :        1815 :   struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp;
   15402                 :        1815 :   if (ctx != NULL && ctx->code == OMP_DISPATCH)
   15403                 :             :     {
   15404                 :        1815 :       tree c = omp_find_clause (ctx->clauses, OMP_CLAUSE_NOCONTEXT);
   15405                 :        1815 :       if (c != NULL_TREE)
   15406                 :             :         {
   15407                 :         250 :           if (integer_nonzerop (OMP_CLAUSE_NOCONTEXT_EXPR (c)))
   15408                 :             :             return 1;
   15409                 :          94 :           else if (integer_zerop (OMP_CLAUSE_NOCONTEXT_EXPR (c)))
   15410                 :             :             return 0;
   15411                 :             :           else
   15412                 :             :             return -1;
   15413                 :             :         }
   15414                 :             :       return 0;
   15415                 :             :     }
   15416                 :             :   return 0;
   15417                 :             : }
   15418                 :             : 
   15419                 :             : /* Collect a list of traits for enclosing constructs in the current
   15420                 :             :    OpenMP context.  The list is in the same format as the trait selector
   15421                 :             :    list of construct trait sets built by the front ends.
   15422                 :             : 
   15423                 :             :    Per the OpenMP specification, the construct trait set includes constructs
   15424                 :             :    up to an enclosing "target" construct.  If there is no "target" construct,
   15425                 :             :    then additional things may be added to the construct trait set (simd for
   15426                 :             :    simd clones, additional constructs associated with "declare variant",
   15427                 :             :    the target trait for "declare target"); those are not handled here.
   15428                 :             :    In particular simd clones are not known during gimplification so
   15429                 :             :    matching/scoring of context selectors that might involve them needs
   15430                 :             :    to be deferred to the omp_device_lower pass.  */
   15431                 :             : 
   15432                 :             : tree
   15433                 :        1937 : omp_get_construct_context (void)
   15434                 :             : {
   15435                 :        1937 :   tree result = NULL_TREE;
   15436                 :        3841 :   for (struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp; ctx;)
   15437                 :             :     {
   15438                 :        1985 :       if (((ctx->region_type & (ORT_TARGET | ORT_IMPLICIT_TARGET | ORT_ACC))
   15439                 :             :                 == ORT_TARGET)
   15440                 :          81 :                && ctx->code == OMP_TARGET)
   15441                 :             :         {
   15442                 :          81 :           result = make_trait_selector (OMP_TRAIT_CONSTRUCT_TARGET,
   15443                 :             :                                         NULL_TREE, NULL_TREE, result);
   15444                 :             :           /* We're not interested in any outer constructs.  */
   15445                 :          81 :           break;
   15446                 :             :         }
   15447                 :        1904 :       else if ((ctx->region_type & ORT_PARALLEL) && ctx->code == OMP_PARALLEL)
   15448                 :         210 :         result = make_trait_selector (OMP_TRAIT_CONSTRUCT_PARALLEL,
   15449                 :             :                                       NULL_TREE, NULL_TREE, result);
   15450                 :        1694 :       else if ((ctx->region_type & ORT_TEAMS) && ctx->code == OMP_TEAMS)
   15451                 :          71 :         result = make_trait_selector (OMP_TRAIT_CONSTRUCT_TEAMS,
   15452                 :             :                                       NULL_TREE, NULL_TREE, result);
   15453                 :        1623 :       else if (ctx->region_type == ORT_WORKSHARE && ctx->code == OMP_FOR)
   15454                 :         164 :         result = make_trait_selector (OMP_TRAIT_CONSTRUCT_FOR,
   15455                 :             :                                       NULL_TREE, NULL_TREE, result);
   15456                 :        1459 :       else if (ctx->code == OMP_DISPATCH && omp_has_nocontext () != 1)
   15457                 :        1226 :         result = make_trait_selector (OMP_TRAIT_CONSTRUCT_DISPATCH,
   15458                 :             :                                       NULL_TREE, NULL_TREE, result);
   15459                 :         233 :       else if (ctx->region_type == ORT_SIMD
   15460                 :          32 :                && ctx->code == OMP_SIMD
   15461                 :         265 :                && !omp_find_clause (ctx->clauses, OMP_CLAUSE_BIND))
   15462                 :             :         {
   15463                 :          32 :           tree props = NULL_TREE;
   15464                 :          32 :           tree *last = &props;
   15465                 :          72 :           for (tree c = ctx->clauses; c; c = OMP_CLAUSE_CHAIN (c))
   15466                 :          40 :             if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SIMDLEN
   15467                 :          32 :                 || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_INBRANCH
   15468                 :          72 :                 || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NOTINBRANCH)
   15469                 :             :               {
   15470                 :           8 :                 *last = unshare_expr (c);
   15471                 :           8 :                 last = &(OMP_CLAUSE_CHAIN (c));
   15472                 :             :               }
   15473                 :          32 :           result = make_trait_selector (OMP_TRAIT_CONSTRUCT_SIMD,
   15474                 :             :                                         NULL_TREE, props, result);
   15475                 :             :         }
   15476                 :         201 :       else if (ctx->region_type == ORT_WORKSHARE
   15477                 :           5 :                && ctx->code == OMP_LOOP
   15478                 :           0 :                && ctx->outer_context
   15479                 :           0 :                && ctx->outer_context->region_type == ORT_COMBINED_PARALLEL
   15480                 :           0 :                && ctx->outer_context->outer_context
   15481                 :           0 :                && ctx->outer_context->outer_context->code == OMP_LOOP
   15482                 :           0 :                && ctx->outer_context->outer_context->distribute)
   15483                 :        1904 :         ctx = ctx->outer_context->outer_context;
   15484                 :        1904 :       ctx = ctx->outer_context;
   15485                 :             :     }
   15486                 :             : 
   15487                 :        1937 :   return result;
   15488                 :             : }
   15489                 :             : 
   15490                 :             : /* Gimplify OACC_CACHE.  */
   15491                 :             : 
   15492                 :             : static void
   15493                 :         706 : gimplify_oacc_cache (tree *expr_p, gimple_seq *pre_p)
   15494                 :             : {
   15495                 :         706 :   tree expr = *expr_p;
   15496                 :             : 
   15497                 :         706 :   gimplify_scan_omp_clauses (&OACC_CACHE_CLAUSES (expr), pre_p, ORT_ACC,
   15498                 :             :                              OACC_CACHE);
   15499                 :         706 :   gimplify_adjust_omp_clauses (pre_p, NULL, &OACC_CACHE_CLAUSES (expr),
   15500                 :             :                                OACC_CACHE);
   15501                 :             : 
   15502                 :             :   /* TODO: Do something sensible with this information.  */
   15503                 :             : 
   15504                 :         706 :   *expr_p = NULL_TREE;
   15505                 :         706 : }
   15506                 :             : 
   15507                 :             : /* Helper function of gimplify_oacc_declare.  The helper's purpose is to,
   15508                 :             :    if required, translate 'kind' in CLAUSE into an 'entry' kind and 'exit'
   15509                 :             :    kind.  The entry kind will replace the one in CLAUSE, while the exit
   15510                 :             :    kind will be used in a new omp_clause and returned to the caller.  */
   15511                 :             : 
   15512                 :             : static tree
   15513                 :         190 : gimplify_oacc_declare_1 (tree clause)
   15514                 :             : {
   15515                 :         190 :   HOST_WIDE_INT kind, new_op;
   15516                 :         190 :   bool ret = false;
   15517                 :         190 :   tree c = NULL;
   15518                 :             : 
   15519                 :         190 :   kind = OMP_CLAUSE_MAP_KIND (clause);
   15520                 :             : 
   15521                 :         190 :   switch (kind)
   15522                 :             :     {
   15523                 :             :       case GOMP_MAP_ALLOC:
   15524                 :             :         new_op = GOMP_MAP_RELEASE;
   15525                 :             :         ret = true;
   15526                 :             :         break;
   15527                 :             : 
   15528                 :          29 :       case GOMP_MAP_FROM:
   15529                 :          29 :         OMP_CLAUSE_SET_MAP_KIND (clause, GOMP_MAP_FORCE_ALLOC);
   15530                 :          29 :         new_op = GOMP_MAP_FROM;
   15531                 :          29 :         ret = true;
   15532                 :          29 :         break;
   15533                 :             : 
   15534                 :          40 :       case GOMP_MAP_TOFROM:
   15535                 :          40 :         OMP_CLAUSE_SET_MAP_KIND (clause, GOMP_MAP_TO);
   15536                 :          40 :         new_op = GOMP_MAP_FROM;
   15537                 :          40 :         ret = true;
   15538                 :          40 :         break;
   15539                 :             : 
   15540                 :             :       case GOMP_MAP_DEVICE_RESIDENT:
   15541                 :             :       case GOMP_MAP_FORCE_DEVICEPTR:
   15542                 :             :       case GOMP_MAP_FORCE_PRESENT:
   15543                 :             :       case GOMP_MAP_LINK:
   15544                 :             :       case GOMP_MAP_POINTER:
   15545                 :             :       case GOMP_MAP_TO:
   15546                 :             :         break;
   15547                 :             : 
   15548                 :           0 :       default:
   15549                 :           0 :         gcc_unreachable ();
   15550                 :          69 :         break;
   15551                 :             :     }
   15552                 :             : 
   15553                 :          69 :   if (ret)
   15554                 :             :     {
   15555                 :         116 :       c = build_omp_clause (OMP_CLAUSE_LOCATION (clause), OMP_CLAUSE_MAP);
   15556                 :         116 :       OMP_CLAUSE_SET_MAP_KIND (c, new_op);
   15557                 :         116 :       OMP_CLAUSE_DECL (c) = OMP_CLAUSE_DECL (clause);
   15558                 :             :     }
   15559                 :             : 
   15560                 :         190 :   return c;
   15561                 :             : }
   15562                 :             : 
   15563                 :             : /* Gimplify OACC_DECLARE.  */
   15564                 :             : 
   15565                 :             : static void
   15566                 :         254 : gimplify_oacc_declare (tree *expr_p, gimple_seq *pre_p)
   15567                 :             : {
   15568                 :         254 :   tree expr = *expr_p;
   15569                 :         254 :   gomp_target *stmt;
   15570                 :         254 :   tree clauses, t, decl;
   15571                 :             : 
   15572                 :         254 :   clauses = OACC_DECLARE_CLAUSES (expr);
   15573                 :             : 
   15574                 :         254 :   gimplify_scan_omp_clauses (&clauses, pre_p, ORT_TARGET_DATA, OACC_DECLARE);
   15575                 :         254 :   gimplify_adjust_omp_clauses (pre_p, NULL, &clauses, OACC_DECLARE);
   15576                 :             : 
   15577                 :         516 :   for (t = clauses; t; t = OMP_CLAUSE_CHAIN (t))
   15578                 :             :     {
   15579                 :         262 :       decl = OMP_CLAUSE_DECL (t);
   15580                 :             : 
   15581                 :         262 :       if (TREE_CODE (decl) == MEM_REF)
   15582                 :           8 :         decl = TREE_OPERAND (decl, 0);
   15583                 :             : 
   15584                 :         262 :       if (VAR_P (decl) && !is_oacc_declared (decl))
   15585                 :             :         {
   15586                 :         262 :           tree attr = get_identifier ("oacc declare target");
   15587                 :         262 :           DECL_ATTRIBUTES (decl) = tree_cons (attr, NULL_TREE,
   15588                 :         262 :                                               DECL_ATTRIBUTES (decl));
   15589                 :             :         }
   15590                 :             : 
   15591                 :         262 :       if (VAR_P (decl)
   15592                 :         262 :           && !is_global_var (decl)
   15593                 :         452 :           && DECL_CONTEXT (decl) == current_function_decl)
   15594                 :             :         {
   15595                 :         190 :           tree c = gimplify_oacc_declare_1 (t);
   15596                 :         190 :           if (c)
   15597                 :             :             {
   15598                 :         116 :               if (oacc_declare_returns == NULL)
   15599                 :          40 :                 oacc_declare_returns = new hash_map<tree, tree>;
   15600                 :             : 
   15601                 :         116 :               oacc_declare_returns->put (decl, c);
   15602                 :             :             }
   15603                 :             :         }
   15604                 :             : 
   15605                 :         262 :       if (gimplify_omp_ctxp)
   15606                 :          72 :         omp_add_variable (gimplify_omp_ctxp, decl, GOVD_SEEN);
   15607                 :             :     }
   15608                 :             : 
   15609                 :         254 :   stmt = gimple_build_omp_target (NULL, GF_OMP_TARGET_KIND_OACC_DECLARE,
   15610                 :             :                                   clauses);
   15611                 :             : 
   15612                 :         254 :   gimplify_seq_add_stmt (pre_p, stmt);
   15613                 :             : 
   15614                 :         254 :   *expr_p = NULL_TREE;
   15615                 :         254 : }
   15616                 :             : 
   15617                 :             : /* Gimplify the contents of an OMP_PARALLEL statement.  This involves
   15618                 :             :    gimplification of the body, as well as scanning the body for used
   15619                 :             :    variables.  We need to do this scan now, because variable-sized
   15620                 :             :    decls will be decomposed during gimplification.  */
   15621                 :             : 
   15622                 :             : static void
   15623                 :       18198 : gimplify_omp_parallel (tree *expr_p, gimple_seq *pre_p)
   15624                 :             : {
   15625                 :       18198 :   tree expr = *expr_p;
   15626                 :       18198 :   gimple *g;
   15627                 :       18198 :   gimple_seq body = NULL;
   15628                 :             : 
   15629                 :       36396 :   gimplify_scan_omp_clauses (&OMP_PARALLEL_CLAUSES (expr), pre_p,
   15630                 :       18198 :                              OMP_PARALLEL_COMBINED (expr)
   15631                 :             :                              ? ORT_COMBINED_PARALLEL
   15632                 :             :                              : ORT_PARALLEL, OMP_PARALLEL);
   15633                 :             : 
   15634                 :       18198 :   push_gimplify_context ();
   15635                 :             : 
   15636                 :       18198 :   g = gimplify_and_return_first (OMP_PARALLEL_BODY (expr), &body);
   15637                 :       18198 :   if (gimple_code (g) == GIMPLE_BIND)
   15638                 :       18198 :     pop_gimplify_context (g);
   15639                 :             :   else
   15640                 :           0 :     pop_gimplify_context (NULL);
   15641                 :             : 
   15642                 :       18198 :   gimplify_adjust_omp_clauses (pre_p, body, &OMP_PARALLEL_CLAUSES (expr),
   15643                 :             :                                OMP_PARALLEL);
   15644                 :             : 
   15645                 :       36396 :   g = gimple_build_omp_parallel (body,
   15646                 :       18198 :                                  OMP_PARALLEL_CLAUSES (expr),
   15647                 :             :                                  NULL_TREE, NULL_TREE);
   15648                 :       18198 :   if (OMP_PARALLEL_COMBINED (expr))
   15649                 :       12528 :     gimple_omp_set_subcode (g, GF_OMP_PARALLEL_COMBINED);
   15650                 :       18198 :   gimplify_seq_add_stmt (pre_p, g);
   15651                 :       18198 :   *expr_p = NULL_TREE;
   15652                 :       18198 : }
   15653                 :             : 
   15654                 :             : /* Gimplify the contents of an OMP_TASK statement.  This involves
   15655                 :             :    gimplification of the body, as well as scanning the body for used
   15656                 :             :    variables.  We need to do this scan now, because variable-sized
   15657                 :             :    decls will be decomposed during gimplification.  */
   15658                 :             : 
   15659                 :             : static void
   15660                 :        4011 : gimplify_omp_task (tree *expr_p, gimple_seq *pre_p)
   15661                 :             : {
   15662                 :        4011 :   tree expr = *expr_p;
   15663                 :        4011 :   gimple *g;
   15664                 :        4011 :   gimple_seq body = NULL;
   15665                 :        4011 :   bool nowait = false;
   15666                 :        4011 :   bool has_depend = false;
   15667                 :             : 
   15668                 :        4011 :   if (OMP_TASK_BODY (expr) == NULL_TREE)
   15669                 :             :     {
   15670                 :         230 :       for (tree c = OMP_TASK_CLAUSES (expr); c; c = OMP_CLAUSE_CHAIN (c))
   15671                 :         147 :         if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND)
   15672                 :             :           {
   15673                 :         105 :             has_depend = true;
   15674                 :         105 :             if (OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_MUTEXINOUTSET)
   15675                 :             :               {
   15676                 :           9 :                 error_at (OMP_CLAUSE_LOCATION (c),
   15677                 :             :                           "%<mutexinoutset%> kind in %<depend%> clause on a "
   15678                 :             :                           "%<taskwait%> construct");
   15679                 :           9 :                 break;
   15680                 :             :               }
   15681                 :             :           }
   15682                 :          42 :         else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NOWAIT)
   15683                 :          42 :           nowait = true;
   15684                 :          92 :       if (nowait && !has_depend)
   15685                 :             :         {
   15686                 :           5 :           error_at (EXPR_LOCATION (expr),
   15687                 :             :                     "%<taskwait%> construct with %<nowait%> clause but no "
   15688                 :             :                     "%<depend%> clauses");
   15689                 :           5 :           *expr_p = NULL_TREE;
   15690                 :           5 :           return;
   15691                 :             :         }
   15692                 :             :     }
   15693                 :             : 
   15694                 :       12018 :   gimplify_scan_omp_clauses (&OMP_TASK_CLAUSES (expr), pre_p,
   15695                 :        4006 :                              omp_find_clause (OMP_TASK_CLAUSES (expr),
   15696                 :             :                                               OMP_CLAUSE_UNTIED)
   15697                 :             :                              ? ORT_UNTIED_TASK : ORT_TASK, OMP_TASK);
   15698                 :             : 
   15699                 :        4006 :   if (OMP_TASK_BODY (expr))
   15700                 :             :     {
   15701                 :        3919 :       push_gimplify_context ();
   15702                 :             : 
   15703                 :        3919 :       g = gimplify_and_return_first (OMP_TASK_BODY (expr), &body);
   15704                 :        3919 :       if (gimple_code (g) == GIMPLE_BIND)
   15705                 :        3919 :         pop_gimplify_context (g);
   15706                 :             :       else
   15707                 :           0 :         pop_gimplify_context (NULL);
   15708                 :             :     }
   15709                 :             : 
   15710                 :        4006 :   gimplify_adjust_omp_clauses (pre_p, body, &OMP_TASK_CLAUSES (expr),
   15711                 :             :                                OMP_TASK);
   15712                 :             : 
   15713                 :        8012 :   g = gimple_build_omp_task (body,
   15714                 :        4006 :                              OMP_TASK_CLAUSES (expr),
   15715                 :             :                              NULL_TREE, NULL_TREE,
   15716                 :             :                              NULL_TREE, NULL_TREE, NULL_TREE);
   15717                 :        4006 :   if (OMP_TASK_BODY (expr) == NULL_TREE)
   15718                 :          87 :     gimple_omp_task_set_taskwait_p (g, true);
   15719                 :        4006 :   gimplify_seq_add_stmt (pre_p, g);
   15720                 :        4006 :   *expr_p = NULL_TREE;
   15721                 :             : }
   15722                 :             : 
   15723                 :             : /* Helper function for gimplify_omp_for.  If *TP is not a gimple constant,
   15724                 :             :    force it into a temporary initialized in PRE_P and add firstprivate clause
   15725                 :             :    to ORIG_FOR_STMT.  */
   15726                 :             : 
   15727                 :             : static void
   15728                 :        4445 : gimplify_omp_taskloop_expr (tree type, tree *tp, gimple_seq *pre_p,
   15729                 :             :                             tree orig_for_stmt)
   15730                 :             : {
   15731                 :        4445 :   if (*tp == NULL || is_gimple_constant (*tp))
   15732                 :             :     return;
   15733                 :             : 
   15734                 :         796 :   if (TREE_CODE (*tp) == SAVE_EXPR)
   15735                 :         135 :     gimplify_save_expr (tp, pre_p, NULL);
   15736                 :             :   else
   15737                 :         661 :     *tp = get_initialized_tmp_var (*tp, pre_p, NULL, false);
   15738                 :             :   /* Reference to pointer conversion is considered useless,
   15739                 :             :      but is significant for firstprivate clause.  Force it
   15740                 :             :      here.  */
   15741                 :         796 :   if (type
   15742                 :         704 :       && TREE_CODE (type) == POINTER_TYPE
   15743                 :         886 :       && TREE_CODE (TREE_TYPE (*tp)) == REFERENCE_TYPE)
   15744                 :             :     {
   15745                 :          12 :       tree v = create_tmp_var (TYPE_MAIN_VARIANT (type));
   15746                 :          12 :       tree m = build2 (INIT_EXPR, TREE_TYPE (v), v, *tp);
   15747                 :          12 :       gimplify_and_add (m, pre_p);
   15748                 :          12 :       *tp = v;
   15749                 :             :     }
   15750                 :             : 
   15751                 :         796 :   tree c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE);
   15752                 :         796 :   OMP_CLAUSE_DECL (c) = *tp;
   15753                 :         796 :   OMP_CLAUSE_CHAIN (c) = OMP_FOR_CLAUSES (orig_for_stmt);
   15754                 :         796 :   OMP_FOR_CLAUSES (orig_for_stmt) = c;
   15755                 :             : }
   15756                 :             : 
   15757                 :             : /* Helper function of gimplify_omp_for, find OMP_ORDERED with
   15758                 :             :    null OMP_ORDERED_BODY inside of OMP_FOR's body.  */
   15759                 :             : 
   15760                 :             : static tree
   15761                 :       16449 : find_standalone_omp_ordered (tree *tp, int *walk_subtrees, void *)
   15762                 :             : {
   15763                 :       16449 :   switch (TREE_CODE (*tp))
   15764                 :             :     {
   15765                 :         896 :     case OMP_ORDERED:
   15766                 :         896 :       if (OMP_ORDERED_BODY (*tp) == NULL_TREE)
   15767                 :             :         return *tp;
   15768                 :             :       break;
   15769                 :          23 :     case OMP_SIMD:
   15770                 :          23 :     case OMP_PARALLEL:
   15771                 :          23 :     case OMP_TARGET:
   15772                 :          23 :       *walk_subtrees = 0;
   15773                 :          23 :       break;
   15774                 :             :     default:
   15775                 :             :       break;
   15776                 :             :     }
   15777                 :             :   return NULL_TREE;
   15778                 :             : }
   15779                 :             : 
   15780                 :             : /* Gimplify standalone loop transforming directive which has the
   15781                 :             :    transformations applied already.  So, all that is needed is gimplify
   15782                 :             :    the remaining loops as normal loops.  */
   15783                 :             : 
   15784                 :             : static enum gimplify_status
   15785                 :        2274 : gimplify_omp_loop_xform (tree *expr_p, gimple_seq *pre_p)
   15786                 :             : {
   15787                 :        2274 :   tree for_stmt = *expr_p;
   15788                 :             : 
   15789                 :        2274 :   if (OMP_FOR_PRE_BODY (for_stmt))
   15790                 :         759 :     gimplify_and_add (OMP_FOR_PRE_BODY (for_stmt), pre_p);
   15791                 :             : 
   15792                 :        2274 :   gimple_seq pre_body = NULL, post_body = NULL;
   15793                 :        5223 :   for (int i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)); i++)
   15794                 :             :     {
   15795                 :        2949 :       if (TREE_VEC_ELT (OMP_FOR_INIT (for_stmt), i) == NULL_TREE)
   15796                 :        1712 :         continue;
   15797                 :        1288 :       tree iters = NULL_TREE;
   15798                 :        1288 :       if (i == 0
   15799                 :         831 :           && TREE_CODE (for_stmt) == OMP_UNROLL
   15800                 :        1781 :           && !omp_find_clause (OMP_FOR_CLAUSES (for_stmt), OMP_CLAUSE_PARTIAL))
   15801                 :             :         {
   15802                 :         316 :           if (omp_find_clause (OMP_FOR_CLAUSES (for_stmt), OMP_CLAUSE_FULL))
   15803                 :         274 :             iters = omp_loop_number_of_iterations (for_stmt, 0, NULL);
   15804                 :             :           else
   15805                 :          42 :             iters = build_int_cst (integer_type_node, 8);
   15806                 :             :         }
   15807                 :        1288 :       tree t = TREE_VEC_ELT (OMP_FOR_INIT (for_stmt), i);
   15808                 :        1288 :       gcc_assert (TREE_CODE (t) == MODIFY_EXPR);
   15809                 :        1288 :       tree decl = TREE_OPERAND (t, 0);
   15810                 :        1288 :       gcc_assert (DECL_P (decl));
   15811                 :        1288 :       gcc_assert (INTEGRAL_TYPE_P (TREE_TYPE (decl))
   15812                 :             :                   || POINTER_TYPE_P (TREE_TYPE (decl)));
   15813                 :        1288 :       if (DECL_ARTIFICIAL (decl)
   15814                 :         876 :           && TREE_PRIVATE (t)
   15815                 :         867 :           && gimplify_omp_ctxp
   15816                 :        1618 :           && gimplify_omp_ctxp->region_type != ORT_NONE)
   15817                 :             :         {
   15818                 :             :           struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp;
   15819                 :         504 :           do
   15820                 :             :             {
   15821                 :         504 :               splay_tree_node n
   15822                 :         504 :                 = splay_tree_lookup (ctx->variables, (splay_tree_key) decl);
   15823                 :         504 :               if (n != NULL)
   15824                 :             :                 break;
   15825                 :         346 :               else if (ctx->region_type != ORT_WORKSHARE
   15826                 :             :                        && ctx->region_type != ORT_TASKGROUP
   15827                 :          62 :                        && ctx->region_type != ORT_SIMD
   15828                 :          38 :                        && ctx->region_type != ORT_ACC
   15829                 :          38 :                        && !(ctx->region_type & ORT_TARGET_DATA))
   15830                 :             :                 {
   15831                 :          38 :                   omp_add_variable (ctx, decl, GOVD_PRIVATE);
   15832                 :          38 :                   break;
   15833                 :             :                 }
   15834                 :         308 :               ctx = ctx->outer_context;
   15835                 :             :             }
   15836                 :         308 :           while (ctx);
   15837                 :             :         }
   15838                 :        1288 :       if (TREE_CODE (TREE_OPERAND (t, 1)) == TREE_VEC)
   15839                 :             :         {
   15840                 :          23 :           gcc_assert (seen_error ());
   15841                 :          23 :           continue;
   15842                 :             :         }
   15843                 :        1265 :       gimplify_expr (&TREE_OPERAND (t, 1), pre_p, NULL, is_gimple_val,
   15844                 :             :                      fb_rvalue);
   15845                 :        1265 :       gimplify_and_add (t, &pre_body);
   15846                 :        1265 :       t = TREE_VEC_ELT (OMP_FOR_COND (for_stmt), i);
   15847                 :        1265 :       gcc_assert (TREE_OPERAND (t, 0) == decl);
   15848                 :        1265 :       if (TREE_CODE (TREE_OPERAND (t, 1)) == TREE_VEC)
   15849                 :             :         {
   15850                 :          28 :           gcc_assert (seen_error ());
   15851                 :          28 :           continue;
   15852                 :             :         }
   15853                 :        1237 :       gimplify_expr (&TREE_OPERAND (t, 1), pre_p, NULL, is_gimple_val,
   15854                 :             :                      fb_rvalue);
   15855                 :        1237 :       tree l1 = create_artificial_label (UNKNOWN_LOCATION);
   15856                 :        1237 :       tree l2 = create_artificial_label (UNKNOWN_LOCATION);
   15857                 :        1237 :       tree l3 = create_artificial_label (UNKNOWN_LOCATION);
   15858                 :        1237 :       gimplify_seq_add_stmt (&pre_body, gimple_build_goto (l2));
   15859                 :        1237 :       gimplify_seq_add_stmt (&pre_body, gimple_build_label (l1));
   15860                 :        1237 :       gimple_seq this_post_body = NULL;
   15861                 :        1237 :       t = TREE_VEC_ELT (OMP_FOR_INCR (for_stmt), i);
   15862                 :        1237 :       if (TREE_CODE (t) == MODIFY_EXPR)
   15863                 :             :         {
   15864                 :         980 :           t = TREE_OPERAND (t, 1);
   15865                 :         980 :           if (TREE_CODE (t) == PLUS_EXPR
   15866                 :         980 :               && TREE_OPERAND (t, 1) == decl)
   15867                 :             :             {
   15868                 :           0 :               TREE_OPERAND (t, 1) = TREE_OPERAND (t, 0);
   15869                 :           0 :               TREE_OPERAND (t, 0) = decl;
   15870                 :             :             }
   15871                 :         980 :           gimplify_expr (&TREE_OPERAND (t, 1), pre_p, NULL, is_gimple_val,
   15872                 :             :                          fb_rvalue);
   15873                 :             :         }
   15874                 :        1237 :       gimplify_and_add (TREE_VEC_ELT (OMP_FOR_INCR (for_stmt), i),
   15875                 :             :                         &this_post_body);
   15876                 :        1237 :       gimplify_seq_add_stmt (&this_post_body, gimple_build_label (l2));
   15877                 :        1237 :       t = TREE_VEC_ELT (OMP_FOR_COND (for_stmt), i);
   15878                 :        1237 :       gcond *cond = NULL;
   15879                 :        1237 :       tree d = decl;
   15880                 :        1237 :       gimplify_expr (&d, &this_post_body, NULL, is_gimple_val, fb_rvalue);
   15881                 :        1237 :       if (iters && tree_fits_uhwi_p (iters))
   15882                 :             :         {
   15883                 :         304 :           unsigned HOST_WIDE_INT niters = tree_to_uhwi (iters);
   15884                 :         304 :           if ((unsigned HOST_WIDE_INT) (int) niters == niters
   15885                 :         304 :               && (int) niters > 0)
   15886                 :             :             {
   15887                 :         304 :               t = build2 (TREE_CODE (t), boolean_type_node, d,
   15888                 :         304 :                           TREE_OPERAND (t, 1));
   15889                 :         608 :               t = build3 (ANNOTATE_EXPR, TREE_TYPE (t), t,
   15890                 :         304 :                           build_int_cst (integer_type_node,
   15891                 :         304 :                                          annot_expr_unroll_kind),
   15892                 :         304 :                           build_int_cst (integer_type_node, niters));
   15893                 :         304 :               gimplify_expr (&t, &this_post_body, NULL, is_gimple_val,
   15894                 :             :                              fb_rvalue);
   15895                 :         304 :               cond = gimple_build_cond (NE_EXPR, t, boolean_false_node,
   15896                 :             :                                         l1, l3);
   15897                 :             :             }
   15898                 :             :         }
   15899                 :         304 :       if (cond == NULL)
   15900                 :         933 :         cond = gimple_build_cond (TREE_CODE (t), d, TREE_OPERAND (t, 1),
   15901                 :             :                                   l1, l3);
   15902                 :        1237 :       gimplify_seq_add_stmt (&this_post_body, cond);
   15903                 :        1237 :       gimplify_seq_add_stmt (&this_post_body, gimple_build_label (l3));
   15904                 :        1237 :       gimplify_seq_add_seq (&this_post_body, post_body);
   15905                 :        1237 :       post_body = this_post_body;
   15906                 :             :     }
   15907                 :        2274 :   gimplify_seq_add_seq (pre_p, pre_body);
   15908                 :        2274 :   gimplify_and_add (OMP_FOR_BODY (for_stmt), pre_p);
   15909                 :        2274 :   gimplify_seq_add_seq (pre_p, post_body);
   15910                 :             : 
   15911                 :        2274 :   *expr_p = NULL_TREE;
   15912                 :        2274 :   return GS_ALL_DONE;
   15913                 :             : }
   15914                 :             : 
   15915                 :             : /* Gimplify the gross structure of an OMP_FOR statement.  */
   15916                 :             : 
   15917                 :             : static enum gimplify_status
   15918                 :       58064 : gimplify_omp_for (tree *expr_p, gimple_seq *pre_p)
   15919                 :             : {
   15920                 :       58064 :   tree for_stmt, orig_for_stmt, inner_for_stmt = NULL_TREE, decl, var, t;
   15921                 :       58064 :   enum gimplify_status ret = GS_ALL_DONE;
   15922                 :       58064 :   enum gimplify_status tret;
   15923                 :       58064 :   gomp_for *gfor;
   15924                 :       58064 :   gimple_seq for_body, for_pre_body;
   15925                 :       58064 :   int i;
   15926                 :       58064 :   bitmap has_decl_expr = NULL;
   15927                 :       58064 :   enum omp_region_type ort = ORT_WORKSHARE;
   15928                 :       58064 :   bool openacc = TREE_CODE (*expr_p) == OACC_LOOP;
   15929                 :             : 
   15930                 :       58064 :   orig_for_stmt = for_stmt = *expr_p;
   15931                 :             : 
   15932                 :       58064 :   bool loop_p = (omp_find_clause (OMP_FOR_CLAUSES (for_stmt), OMP_CLAUSE_BIND)
   15933                 :       58064 :                  != NULL_TREE);
   15934                 :       58135 :   while (OMP_FOR_INIT (for_stmt) == NULL_TREE)
   15935                 :             :     {
   15936                 :       17700 :       tree *data[4] = { NULL, NULL, NULL, NULL };
   15937                 :       17700 :       gcc_assert (TREE_CODE (for_stmt) != OACC_LOOP);
   15938                 :       17700 :       inner_for_stmt = walk_tree (&OMP_FOR_BODY (for_stmt),
   15939                 :             :                                   find_combined_omp_for, data, NULL);
   15940                 :       17700 :       if (inner_for_stmt == NULL_TREE)
   15941                 :             :         {
   15942                 :          36 :           gcc_assert (seen_error ());
   15943                 :          36 :           *expr_p = NULL_TREE;
   15944                 :        3713 :           return GS_ERROR;
   15945                 :             :         }
   15946                 :       17664 :       gcc_assert (inner_for_stmt == *data[3]);
   15947                 :       17664 :       omp_maybe_apply_loop_xforms (data[3],
   15948                 :       17664 :                                    data[2]
   15949                 :        4270 :                                    ? OMP_FOR_CLAUSES (*data[2])
   15950                 :       13394 :                                    : TREE_CODE (for_stmt) == OMP_FOR
   15951                 :       13394 :                                    ? OMP_FOR_CLAUSES (for_stmt)
   15952                 :             :                                    : NULL_TREE);
   15953                 :       17664 :       if (inner_for_stmt != *data[3])
   15954                 :          71 :         continue;
   15955                 :       17593 :       if (data[2] && OMP_FOR_PRE_BODY (*data[2]))
   15956                 :             :         {
   15957                 :           2 :           append_to_statement_list_force (OMP_FOR_PRE_BODY (*data[2]),
   15958                 :             :                                           &OMP_FOR_PRE_BODY (for_stmt));
   15959                 :           2 :           OMP_FOR_PRE_BODY (*data[2]) = NULL_TREE;
   15960                 :             :         }
   15961                 :       17593 :       if (OMP_FOR_PRE_BODY (inner_for_stmt))
   15962                 :             :         {
   15963                 :        7194 :           append_to_statement_list_force (OMP_FOR_PRE_BODY (inner_for_stmt),
   15964                 :             :                                           &OMP_FOR_PRE_BODY (for_stmt));
   15965                 :        7194 :           OMP_FOR_PRE_BODY (inner_for_stmt) = NULL_TREE;
   15966                 :             :         }
   15967                 :             : 
   15968                 :       17593 :       if (data[0])
   15969                 :             :         {
   15970                 :             :           /* We have some statements or variable declarations in between
   15971                 :             :              the composite construct directives.  Move them around the
   15972                 :             :              inner_for_stmt.  */
   15973                 :        3677 :           data[0] = expr_p;
   15974                 :       14708 :           for (i = 0; i < 3; i++)
   15975                 :       11031 :             if (data[i])
   15976                 :             :               {
   15977                 :        6977 :                 tree t = *data[i];
   15978                 :        6977 :                 if (i < 2 && data[i + 1] == &OMP_BODY (t))
   15979                 :        1002 :                   data[i + 1] = data[i];
   15980                 :        6977 :                 *data[i] = OMP_BODY (t);
   15981                 :        6977 :                 tree body = build3 (BIND_EXPR, void_type_node, NULL_TREE,
   15982                 :             :                                     NULL_TREE, make_node (BLOCK));
   15983                 :        6977 :                 OMP_BODY (t) = body;
   15984                 :        6977 :                 append_to_statement_list_force (inner_for_stmt,
   15985                 :             :                                                 &BIND_EXPR_BODY (body));
   15986                 :        6977 :                 *data[3] = t;
   15987                 :        6977 :                 data[3] = tsi_stmt_ptr (tsi_start (BIND_EXPR_BODY (body)));
   15988                 :        6977 :                 gcc_assert (*data[3] == inner_for_stmt);
   15989                 :             :               }
   15990                 :             :           return GS_OK;
   15991                 :             :         }
   15992                 :             : 
   15993                 :       36686 :       for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (inner_for_stmt)); i++)
   15994                 :       22770 :         if (!loop_p
   15995                 :       21915 :             && OMP_FOR_ORIG_DECLS (inner_for_stmt)
   15996                 :       11094 :             && TREE_CODE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (inner_for_stmt),
   15997                 :             :                                         i)) == TREE_LIST
   15998                 :       22838 :             && TREE_PURPOSE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (inner_for_stmt),
   15999                 :             :                                            i)))
   16000                 :             :           {
   16001                 :          40 :             tree orig = TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (inner_for_stmt), i);
   16002                 :             :             /* Class iterators aren't allowed on OMP_SIMD, so the only
   16003                 :             :                case we need to solve is distribute parallel for.  They are
   16004                 :             :                allowed on the loop construct, but that is already handled
   16005                 :             :                in gimplify_omp_loop.  */
   16006                 :          40 :             gcc_assert (TREE_CODE (inner_for_stmt) == OMP_FOR
   16007                 :             :                         && TREE_CODE (for_stmt) == OMP_DISTRIBUTE
   16008                 :             :                         && data[1]);
   16009                 :          40 :             tree orig_decl = TREE_PURPOSE (orig);
   16010                 :          40 :             tree last = TREE_VALUE (orig);
   16011                 :          40 :             tree *pc;
   16012                 :          40 :             for (pc = &OMP_FOR_CLAUSES (inner_for_stmt);
   16013                 :          74 :                  *pc; pc = &OMP_CLAUSE_CHAIN (*pc))
   16014                 :          42 :               if ((OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_PRIVATE
   16015                 :          35 :                    || OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_LASTPRIVATE)
   16016                 :          43 :                   && OMP_CLAUSE_DECL (*pc) == orig_decl)
   16017                 :             :                 break;
   16018                 :          40 :             if (*pc == NULL_TREE)
   16019                 :             :               {
   16020                 :          32 :                 tree *spc;
   16021                 :          32 :                 for (spc = &OMP_PARALLEL_CLAUSES (*data[1]);
   16022                 :          98 :                      *spc; spc = &OMP_CLAUSE_CHAIN (*spc))
   16023                 :          67 :                   if (OMP_CLAUSE_CODE (*spc) == OMP_CLAUSE_PRIVATE
   16024                 :          67 :                       && OMP_CLAUSE_DECL (*spc) == orig_decl)
   16025                 :             :                     break;
   16026                 :          32 :                 if (*spc)
   16027                 :             :                   {
   16028                 :           1 :                     tree c = *spc;
   16029                 :           1 :                     *spc = OMP_CLAUSE_CHAIN (c);
   16030                 :           1 :                     OMP_CLAUSE_CHAIN (c) = NULL_TREE;
   16031                 :           1 :                     *pc = c;
   16032                 :             :                   }
   16033                 :             :               }
   16034                 :          40 :             if (*pc == NULL_TREE)
   16035                 :             :               ;
   16036                 :           9 :             else if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_PRIVATE)
   16037                 :             :               {
   16038                 :             :                 /* private clause will appear only on inner_for_stmt.
   16039                 :             :                    Change it into firstprivate, and add private clause
   16040                 :             :                    on for_stmt.  */
   16041                 :           8 :                 tree c = copy_node (*pc);
   16042                 :           8 :                 OMP_CLAUSE_CHAIN (c) = OMP_FOR_CLAUSES (for_stmt);
   16043                 :           8 :                 OMP_FOR_CLAUSES (for_stmt) = c;
   16044                 :           8 :                 OMP_CLAUSE_CODE (*pc) = OMP_CLAUSE_FIRSTPRIVATE;
   16045                 :           8 :                 lang_hooks.decls.omp_finish_clause (*pc, pre_p, openacc);
   16046                 :             :               }
   16047                 :             :             else
   16048                 :             :               {
   16049                 :             :                 /* lastprivate clause will appear on both inner_for_stmt
   16050                 :             :                    and for_stmt.  Add firstprivate clause to
   16051                 :             :                    inner_for_stmt.  */
   16052                 :           1 :                 tree c = build_omp_clause (OMP_CLAUSE_LOCATION (*pc),
   16053                 :             :                                            OMP_CLAUSE_FIRSTPRIVATE);
   16054                 :           1 :                 OMP_CLAUSE_DECL (c) = OMP_CLAUSE_DECL (*pc);
   16055                 :           1 :                 OMP_CLAUSE_CHAIN (c) = *pc;
   16056                 :           1 :                 *pc = c;
   16057                 :           1 :                 lang_hooks.decls.omp_finish_clause (*pc, pre_p, openacc);
   16058                 :             :               }
   16059                 :          40 :             tree c = build_omp_clause (UNKNOWN_LOCATION,
   16060                 :             :                                        OMP_CLAUSE_FIRSTPRIVATE);
   16061                 :          40 :             OMP_CLAUSE_DECL (c) = last;
   16062                 :          40 :             OMP_CLAUSE_CHAIN (c) = OMP_PARALLEL_CLAUSES (*data[1]);
   16063                 :          40 :             OMP_PARALLEL_CLAUSES (*data[1]) = c;
   16064                 :          40 :             c = build_omp_clause (UNKNOWN_LOCATION,
   16065                 :          40 :                                   *pc ? OMP_CLAUSE_SHARED
   16066                 :             :                                       : OMP_CLAUSE_FIRSTPRIVATE);
   16067                 :          40 :             OMP_CLAUSE_DECL (c) = orig_decl;
   16068                 :          40 :             OMP_CLAUSE_CHAIN (c) = OMP_PARALLEL_CLAUSES (*data[1]);
   16069                 :          40 :             OMP_PARALLEL_CLAUSES (*data[1]) = c;
   16070                 :             :           }
   16071                 :             :       /* Similarly, take care of C++ range for temporaries, those should
   16072                 :             :          be firstprivate on OMP_PARALLEL if any.  */
   16073                 :       13916 :       if (data[1])
   16074                 :       17480 :         for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (inner_for_stmt)); i++)
   16075                 :       11090 :           if (OMP_FOR_ORIG_DECLS (inner_for_stmt)
   16076                 :        5723 :               && TREE_CODE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (inner_for_stmt),
   16077                 :             :                                           i)) == TREE_LIST
   16078                 :       11166 :               && TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (inner_for_stmt),
   16079                 :             :                                            i)))
   16080                 :             :             {
   16081                 :          49 :               tree orig
   16082                 :          49 :                 = TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (inner_for_stmt), i);
   16083                 :          49 :               tree v = TREE_CHAIN (orig);
   16084                 :          49 :               tree c = build_omp_clause (UNKNOWN_LOCATION,
   16085                 :             :                                          OMP_CLAUSE_FIRSTPRIVATE);
   16086                 :             :               /* First add firstprivate clause for the __for_end artificial
   16087                 :             :                  decl.  */
   16088                 :          49 :               OMP_CLAUSE_DECL (c) = TREE_VEC_ELT (v, 1);
   16089                 :          49 :               if (TREE_CODE (TREE_TYPE (OMP_CLAUSE_DECL (c)))
   16090                 :             :                   == REFERENCE_TYPE)
   16091                 :           0 :                 OMP_CLAUSE_FIRSTPRIVATE_NO_REFERENCE (c) = 1;
   16092                 :          49 :               OMP_CLAUSE_CHAIN (c) = OMP_PARALLEL_CLAUSES (*data[1]);
   16093                 :          49 :               OMP_PARALLEL_CLAUSES (*data[1]) = c;
   16094                 :          49 :               if (TREE_VEC_ELT (v, 0))
   16095                 :             :                 {
   16096                 :             :                   /* And now the same for __for_range artificial decl if it
   16097                 :             :                      exists.  */
   16098                 :          49 :                   c = build_omp_clause (UNKNOWN_LOCATION,
   16099                 :             :                                         OMP_CLAUSE_FIRSTPRIVATE);
   16100                 :          49 :                   OMP_CLAUSE_DECL (c) = TREE_VEC_ELT (v, 0);
   16101                 :          49 :                   if (TREE_CODE (TREE_TYPE (OMP_CLAUSE_DECL (c)))
   16102                 :             :                       == REFERENCE_TYPE)
   16103                 :          49 :                     OMP_CLAUSE_FIRSTPRIVATE_NO_REFERENCE (c) = 1;
   16104                 :          49 :                   OMP_CLAUSE_CHAIN (c) = OMP_PARALLEL_CLAUSES (*data[1]);
   16105                 :          49 :                   OMP_PARALLEL_CLAUSES (*data[1]) = c;
   16106                 :             :                 }
   16107                 :             :             }
   16108                 :       13916 :       break;
   16109                 :             :     }
   16110                 :       54351 :   if (OMP_FOR_INIT (for_stmt) != NULL_TREE)
   16111                 :             :     {
   16112                 :       40435 :       omp_maybe_apply_loop_xforms (expr_p, NULL_TREE);
   16113                 :       40435 :       if (*expr_p != for_stmt)
   16114                 :             :         return GS_OK;
   16115                 :             :     }
   16116                 :             : 
   16117                 :       53464 :   switch (TREE_CODE (for_stmt))
   16118                 :             :     {
   16119                 :       18152 :     case OMP_FOR:
   16120                 :       30340 :       if (OMP_FOR_NON_RECTANGULAR (inner_for_stmt ? inner_for_stmt : for_stmt))
   16121                 :             :         {
   16122                 :         458 :           if (omp_find_clause (OMP_FOR_CLAUSES (for_stmt),
   16123                 :             :                                OMP_CLAUSE_SCHEDULE))
   16124                 :          47 :             error_at (EXPR_LOCATION (for_stmt),
   16125                 :             :                       "%qs clause may not appear on non-rectangular %qs",
   16126                 :          27 :                       "schedule", lang_GNU_Fortran () ? "do" : "for");
   16127                 :         458 :           if (omp_find_clause (OMP_FOR_CLAUSES (for_stmt), OMP_CLAUSE_ORDERED))
   16128                 :          34 :             error_at (EXPR_LOCATION (for_stmt),
   16129                 :             :                       "%qs clause may not appear on non-rectangular %qs",
   16130                 :          18 :                       "ordered", lang_GNU_Fortran () ? "do" : "for");
   16131                 :             :         }
   16132                 :             :       break;
   16133                 :        8214 :     case OMP_DISTRIBUTE:
   16134                 :        9125 :       if (OMP_FOR_NON_RECTANGULAR (inner_for_stmt ? inner_for_stmt : for_stmt)
   16135                 :        8214 :           && omp_find_clause (OMP_FOR_CLAUSES (for_stmt),
   16136                 :             :                               OMP_CLAUSE_DIST_SCHEDULE))
   16137                 :          29 :         error_at (EXPR_LOCATION (for_stmt),
   16138                 :             :                   "%qs clause may not appear on non-rectangular %qs",
   16139                 :             :                   "dist_schedule", "distribute");
   16140                 :             :       break;
   16141                 :             :     case OACC_LOOP:
   16142                 :             :       ort = ORT_ACC;
   16143                 :             :       break;
   16144                 :        1599 :     case OMP_TASKLOOP:
   16145                 :        2549 :       if (OMP_FOR_NON_RECTANGULAR (inner_for_stmt ? inner_for_stmt : for_stmt))
   16146                 :             :         {
   16147                 :          36 :           if (omp_find_clause (OMP_FOR_CLAUSES (for_stmt),
   16148                 :             :                                OMP_CLAUSE_GRAINSIZE))
   16149                 :          11 :             error_at (EXPR_LOCATION (for_stmt),
   16150                 :             :                       "%qs clause may not appear on non-rectangular %qs",
   16151                 :             :                       "grainsize", "taskloop");
   16152                 :          36 :           if (omp_find_clause (OMP_FOR_CLAUSES (for_stmt),
   16153                 :             :                                OMP_CLAUSE_NUM_TASKS))
   16154                 :           6 :             error_at (EXPR_LOCATION (for_stmt),
   16155                 :             :                       "%qs clause may not appear on non-rectangular %qs",
   16156                 :             :                       "num_tasks", "taskloop");
   16157                 :             :         }
   16158                 :        1599 :       if (omp_find_clause (OMP_FOR_CLAUSES (for_stmt), OMP_CLAUSE_UNTIED))
   16159                 :             :         ort = ORT_UNTIED_TASKLOOP;
   16160                 :             :       else
   16161                 :             :         ort = ORT_TASKLOOP;
   16162                 :             :       break;
   16163                 :       10656 :     case OMP_SIMD:
   16164                 :       10656 :       ort = ORT_SIMD;
   16165                 :       10656 :       break;
   16166                 :        2274 :     case OMP_TILE:
   16167                 :        2274 :     case OMP_UNROLL:
   16168                 :        2274 :       gcc_assert (inner_for_stmt == NULL_TREE);
   16169                 :        2274 :       return gimplify_omp_loop_xform (expr_p, pre_p);
   16170                 :           0 :     default:
   16171                 :           0 :       gcc_unreachable ();
   16172                 :             :     }
   16173                 :             : 
   16174                 :             :   /* Set OMP_CLAUSE_LINEAR_NO_COPYIN flag on explicit linear
   16175                 :             :      clause for the IV.  */
   16176                 :       10703 :   if (ort == ORT_SIMD && TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)) == 1)
   16177                 :             :     {
   16178                 :        7844 :       t = TREE_VEC_ELT (OMP_FOR_INIT (for_stmt), 0);
   16179                 :        7844 :       gcc_assert (TREE_CODE (t) == MODIFY_EXPR);
   16180                 :        7844 :       decl = TREE_OPERAND (t, 0);
   16181                 :       18674 :       for (tree c = OMP_FOR_CLAUSES (for_stmt); c; c = OMP_CLAUSE_CHAIN (c))
   16182                 :       11954 :         if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR
   16183                 :       11954 :             && OMP_CLAUSE_DECL (c) == decl)
   16184                 :             :           {
   16185                 :        1124 :             OMP_CLAUSE_LINEAR_NO_COPYIN (c) = 1;
   16186                 :        1124 :             break;
   16187                 :             :           }
   16188                 :             :     }
   16189                 :             : 
   16190                 :       51190 :   if (TREE_CODE (for_stmt) != OMP_TASKLOOP)
   16191                 :       51494 :     gimplify_scan_omp_clauses (&OMP_FOR_CLAUSES (for_stmt), pre_p, ort,
   16192                 :        1903 :                                loop_p && TREE_CODE (for_stmt) != OMP_SIMD
   16193                 :             :                                ? OMP_LOOP : TREE_CODE (for_stmt));
   16194                 :             : 
   16195                 :       51190 :   if (TREE_CODE (for_stmt) == OMP_DISTRIBUTE)
   16196                 :        8214 :     gimplify_omp_ctxp->distribute = true;
   16197                 :             : 
   16198                 :             :   /* Handle OMP_FOR_INIT.  */
   16199                 :       51190 :   for_pre_body = NULL;
   16200                 :       51190 :   if ((ort == ORT_SIMD
   16201                 :       40534 :        || (inner_for_stmt && TREE_CODE (inner_for_stmt) == OMP_SIMD))
   16202                 :       61916 :       && OMP_FOR_PRE_BODY (for_stmt))
   16203                 :             :     {
   16204                 :        6781 :       has_decl_expr = BITMAP_ALLOC (NULL);
   16205                 :        6781 :       if (TREE_CODE (OMP_FOR_PRE_BODY (for_stmt)) == DECL_EXPR
   16206                 :        6781 :           && VAR_P (DECL_EXPR_DECL (OMP_FOR_PRE_BODY (for_stmt))))
   16207                 :             :         {
   16208                 :          18 :           t = OMP_FOR_PRE_BODY (for_stmt);
   16209                 :          18 :           bitmap_set_bit (has_decl_expr, DECL_UID (DECL_EXPR_DECL (t)));
   16210                 :             :         }
   16211                 :        6763 :       else if (TREE_CODE (OMP_FOR_PRE_BODY (for_stmt)) == STATEMENT_LIST)
   16212                 :             :         {
   16213                 :        6761 :           tree_stmt_iterator si;
   16214                 :       11216 :           for (si = tsi_start (OMP_FOR_PRE_BODY (for_stmt)); !tsi_end_p (si);
   16215                 :        4455 :                tsi_next (&si))
   16216                 :             :             {
   16217                 :        4455 :               t = tsi_stmt (si);
   16218                 :        4455 :               if (TREE_CODE (t) == DECL_EXPR
   16219                 :        4455 :                   && VAR_P (DECL_EXPR_DECL (t)))
   16220                 :        4382 :                 bitmap_set_bit (has_decl_expr, DECL_UID (DECL_EXPR_DECL (t)));
   16221                 :             :             }
   16222                 :             :         }
   16223                 :             :     }
   16224                 :       51190 :   if (OMP_FOR_PRE_BODY (for_stmt))
   16225                 :             :     {
   16226                 :       20973 :       if (TREE_CODE (for_stmt) != OMP_TASKLOOP || gimplify_omp_ctxp)
   16227                 :       20252 :         gimplify_and_add (OMP_FOR_PRE_BODY (for_stmt), &for_pre_body);
   16228                 :             :       else
   16229                 :             :         {
   16230                 :         721 :           struct gimplify_omp_ctx ctx;
   16231                 :         721 :           memset (&ctx, 0, sizeof (ctx));
   16232                 :         721 :           ctx.region_type = ORT_NONE;
   16233                 :         721 :           gimplify_omp_ctxp = &ctx;
   16234                 :         721 :           gimplify_and_add (OMP_FOR_PRE_BODY (for_stmt), &for_pre_body);
   16235                 :         721 :           gimplify_omp_ctxp = NULL;
   16236                 :             :         }
   16237                 :             :     }
   16238                 :       51190 :   OMP_FOR_PRE_BODY (for_stmt) = NULL_TREE;
   16239                 :             : 
   16240                 :       51190 :   if (OMP_FOR_INIT (for_stmt) == NULL_TREE)
   16241                 :       13916 :     for_stmt = inner_for_stmt;
   16242                 :             : 
   16243                 :             :   /* For taskloop, need to gimplify the start, end and step before the
   16244                 :             :      taskloop, outside of the taskloop omp context.  */
   16245                 :       51190 :   if (TREE_CODE (orig_for_stmt) == OMP_TASKLOOP)
   16246                 :             :     {
   16247                 :        3484 :       for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)); i++)
   16248                 :             :         {
   16249                 :        1885 :           t = TREE_VEC_ELT (OMP_FOR_INIT (for_stmt), i);
   16250                 :        1885 :           gimple_seq *for_pre_p = (gimple_seq_empty_p (for_pre_body)
   16251                 :        1885 :                                    ? pre_p : &for_pre_body);
   16252                 :        1885 :               tree type = TREE_TYPE (TREE_OPERAND (t, 0));
   16253                 :        1885 :           if (TREE_CODE (TREE_OPERAND (t, 1)) == TREE_VEC)
   16254                 :             :             {
   16255                 :          34 :               tree v = TREE_OPERAND (t, 1);
   16256                 :          34 :               gimplify_omp_taskloop_expr (type, &TREE_VEC_ELT (v, 1),
   16257                 :             :                                           for_pre_p, orig_for_stmt);
   16258                 :          34 :               gimplify_omp_taskloop_expr (type, &TREE_VEC_ELT (v, 2),
   16259                 :             :                                           for_pre_p, orig_for_stmt);
   16260                 :             :             }
   16261                 :             :           else
   16262                 :        1851 :             gimplify_omp_taskloop_expr (type, &TREE_OPERAND (t, 1), for_pre_p,
   16263                 :             :                                         orig_for_stmt);
   16264                 :             : 
   16265                 :             :           /* Handle OMP_FOR_COND.  */
   16266                 :        1885 :           t = TREE_VEC_ELT (OMP_FOR_COND (for_stmt), i);
   16267                 :        1885 :           if (TREE_CODE (TREE_OPERAND (t, 1)) == TREE_VEC)
   16268                 :             :             {
   16269                 :          31 :               tree v = TREE_OPERAND (t, 1);
   16270                 :          31 :               gimplify_omp_taskloop_expr (type, &TREE_VEC_ELT (v, 1),
   16271                 :             :                                           for_pre_p, orig_for_stmt);
   16272                 :          31 :               gimplify_omp_taskloop_expr (type, &TREE_VEC_ELT (v, 2),
   16273                 :             :                                           for_pre_p, orig_for_stmt);
   16274                 :             :             }
   16275                 :             :           else
   16276                 :        1854 :             gimplify_omp_taskloop_expr (type, &TREE_OPERAND (t, 1), for_pre_p,
   16277                 :             :                                         orig_for_stmt);
   16278                 :             : 
   16279                 :             :           /* Handle OMP_FOR_INCR.  */
   16280                 :        1885 :           t = TREE_VEC_ELT (OMP_FOR_INCR (for_stmt), i);
   16281                 :        1885 :           if (TREE_CODE (t) == MODIFY_EXPR)
   16282                 :             :             {
   16283                 :         610 :               decl = TREE_OPERAND (t, 0);
   16284                 :         610 :               t = TREE_OPERAND (t, 1);
   16285                 :         610 :               tree *tp = &TREE_OPERAND (t, 1);
   16286                 :         610 :               if (TREE_CODE (t) == PLUS_EXPR && *tp == decl)
   16287                 :          22 :                 tp = &TREE_OPERAND (t, 0);
   16288                 :             : 
   16289                 :         610 :               gimplify_omp_taskloop_expr (NULL_TREE, tp, for_pre_p,
   16290                 :             :                                           orig_for_stmt);
   16291                 :             :             }
   16292                 :             :         }
   16293                 :             : 
   16294                 :        1599 :       gimplify_scan_omp_clauses (&OMP_FOR_CLAUSES (orig_for_stmt), pre_p, ort,
   16295                 :             :                                  OMP_TASKLOOP);
   16296                 :             :     }
   16297                 :             : 
   16298                 :       51190 :   if (orig_for_stmt != for_stmt)
   16299                 :       13916 :     gimplify_omp_ctxp->combined_loop = true;
   16300                 :             : 
   16301                 :       51190 :   for_body = NULL;
   16302                 :       51190 :   gcc_assert (TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt))
   16303                 :             :               == TREE_VEC_LENGTH (OMP_FOR_COND (for_stmt)));
   16304                 :       51190 :   gcc_assert (TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt))
   16305                 :             :               == TREE_VEC_LENGTH (OMP_FOR_INCR (for_stmt)));
   16306                 :             : 
   16307                 :       51190 :   tree c = omp_find_clause (OMP_FOR_CLAUSES (for_stmt), OMP_CLAUSE_ORDERED);
   16308                 :       51190 :   bool is_doacross = false;
   16309                 :       51190 :   if (c && walk_tree_without_duplicates (&OMP_FOR_BODY (for_stmt),
   16310                 :             :                                          find_standalone_omp_ordered, NULL))
   16311                 :             :     {
   16312                 :         526 :       OMP_CLAUSE_ORDERED_DOACROSS (c) = 1;
   16313                 :         526 :       is_doacross = true;
   16314                 :         526 :       int len = TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt));
   16315                 :         526 :       gimplify_omp_ctxp->loop_iter_var.create (len * 2);
   16316                 :        2190 :       for (tree *pc = &OMP_FOR_CLAUSES (for_stmt); *pc; )
   16317                 :        1664 :         if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_LINEAR)
   16318                 :             :           {
   16319                 :          10 :             error_at (OMP_CLAUSE_LOCATION (*pc),
   16320                 :             :                       "%<linear%> clause may not be specified together "
   16321                 :             :                       "with %<ordered%> clause if stand-alone %<ordered%> "
   16322                 :             :                       "construct is nested in it");
   16323                 :          10 :             *pc = OMP_CLAUSE_CHAIN (*pc);
   16324                 :             :           }
   16325                 :             :         else
   16326                 :        1654 :           pc = &OMP_CLAUSE_CHAIN (*pc);
   16327                 :             :     }
   16328                 :       51190 :   int collapse = 1, tile = 0;
   16329                 :       51190 :   c = omp_find_clause (OMP_FOR_CLAUSES (for_stmt), OMP_CLAUSE_COLLAPSE);
   16330                 :       51190 :   if (c)
   16331                 :       13657 :     collapse = tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (c));
   16332                 :       51190 :   c = omp_find_clause (OMP_FOR_CLAUSES (for_stmt), OMP_CLAUSE_TILE);
   16333                 :       51190 :   if (c)
   16334                 :         384 :     tile = list_length (OMP_CLAUSE_TILE_LIST (c));
   16335                 :       51190 :   c = omp_find_clause (OMP_FOR_CLAUSES (for_stmt), OMP_CLAUSE_ALLOCATE);
   16336                 :       51190 :   hash_set<tree> *allocate_uids = NULL;
   16337                 :       51190 :   if (c)
   16338                 :             :     {
   16339                 :         275 :       allocate_uids = new hash_set<tree>;
   16340                 :        1682 :       for (; c; c = OMP_CLAUSE_CHAIN (c))
   16341                 :        1132 :         if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ALLOCATE)
   16342                 :         478 :           allocate_uids->add (OMP_CLAUSE_DECL (c));
   16343                 :             :     }
   16344                 :      124053 :   for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)); i++)
   16345                 :             :     {
   16346                 :       72863 :       t = TREE_VEC_ELT (OMP_FOR_INIT (for_stmt), i);
   16347                 :       72863 :       gcc_assert (TREE_CODE (t) == MODIFY_EXPR);
   16348                 :       72863 :       decl = TREE_OPERAND (t, 0);
   16349                 :       72863 :       gcc_assert (DECL_P (decl));
   16350                 :       72863 :       gcc_assert (INTEGRAL_TYPE_P (TREE_TYPE (decl))
   16351                 :             :                   || POINTER_TYPE_P (TREE_TYPE (decl)));
   16352                 :       72863 :       if (is_doacross)
   16353                 :             :         {
   16354                 :        1649 :           if (TREE_CODE (for_stmt) == OMP_FOR && OMP_FOR_ORIG_DECLS (for_stmt))
   16355                 :             :             {
   16356                 :         956 :               tree orig_decl = TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (for_stmt), i);
   16357                 :         956 :               if (TREE_CODE (orig_decl) == TREE_LIST)
   16358                 :             :                 {
   16359                 :          15 :                   orig_decl = TREE_PURPOSE (orig_decl);
   16360                 :          15 :                   if (!orig_decl)
   16361                 :           0 :                     orig_decl = decl;
   16362                 :             :                 }
   16363                 :         956 :               gimplify_omp_ctxp->loop_iter_var.quick_push (orig_decl);
   16364                 :             :             }
   16365                 :             :           else
   16366                 :         693 :             gimplify_omp_ctxp->loop_iter_var.quick_push (decl);
   16367                 :        1649 :           gimplify_omp_ctxp->loop_iter_var.quick_push (decl);
   16368                 :             :         }
   16369                 :             : 
   16370                 :       72863 :       if (for_stmt == orig_for_stmt)
   16371                 :             :         {
   16372                 :       50093 :           tree orig_decl = decl;
   16373                 :       50093 :           if (OMP_FOR_ORIG_DECLS (for_stmt))
   16374                 :             :             {
   16375                 :       23895 :               tree orig_decl = TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (for_stmt), i);
   16376                 :       23895 :               if (TREE_CODE (orig_decl) == TREE_LIST)
   16377                 :             :                 {
   16378                 :             :                   orig_decl = TREE_PURPOSE (orig_decl);
   16379                 :             :                   if (!orig_decl)
   16380                 :             :                     orig_decl = decl;
   16381                 :             :                 }
   16382                 :             :             }
   16383                 :       50093 :           if (is_global_var (orig_decl) && DECL_THREAD_LOCAL_P (orig_decl))
   16384                 :          36 :             error_at (EXPR_LOCATION (for_stmt),
   16385                 :             :                       "threadprivate iteration variable %qD", orig_decl);
   16386                 :             :         }
   16387                 :             : 
   16388                 :             :       /* Make sure the iteration variable is private.  */
   16389                 :       72863 :       tree c = NULL_TREE;
   16390                 :       72863 :       tree c2 = NULL_TREE;
   16391                 :       72863 :       if (orig_for_stmt != for_stmt)
   16392                 :             :         {
   16393                 :             :           /* Preserve this information until we gimplify the inner simd.  */
   16394                 :       22770 :           if (has_decl_expr
   16395                 :       22770 :               && bitmap_bit_p (has_decl_expr, DECL_UID (decl)))
   16396                 :        3396 :             TREE_PRIVATE (t) = 1;
   16397                 :             :         }
   16398                 :       50093 :       else if (ort == ORT_SIMD)
   16399                 :             :         {
   16400                 :       15712 :           splay_tree_node n = splay_tree_lookup (gimplify_omp_ctxp->variables,
   16401                 :             :                                                  (splay_tree_key) decl);
   16402                 :       15712 :           omp_is_private (gimplify_omp_ctxp, decl,
   16403                 :       15712 :                           1 + (TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt))
   16404                 :             :                                != 1));
   16405                 :       15712 :           if (n != NULL && (n->value & GOVD_DATA_SHARE_CLASS) != 0)
   16406                 :             :             {
   16407                 :        2522 :               omp_notice_variable (gimplify_omp_ctxp, decl, true);
   16408                 :        2522 :               if (n->value & GOVD_LASTPRIVATE_CONDITIONAL)
   16409                 :           0 :                 for (tree c3 = omp_find_clause (OMP_FOR_CLAUSES (for_stmt),
   16410                 :             :                                                 OMP_CLAUSE_LASTPRIVATE);
   16411                 :           0 :                      c3; c3 = omp_find_clause (OMP_CLAUSE_CHAIN (c3),
   16412                 :             :                                                OMP_CLAUSE_LASTPRIVATE))
   16413                 :           0 :                   if (OMP_CLAUSE_DECL (c3) == decl)
   16414                 :             :                     {
   16415                 :           0 :                       warning_at (OMP_CLAUSE_LOCATION (c3), OPT_Wopenmp,
   16416                 :             :                                   "conditional %<lastprivate%> on loop "
   16417                 :             :                                   "iterator %qD ignored", decl);
   16418                 :           0 :                       OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c3) = 0;
   16419                 :           0 :                       n->value &= ~GOVD_LASTPRIVATE_CONDITIONAL;
   16420                 :             :                     }
   16421                 :             :             }
   16422                 :       13190 :           else if (TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)) == 1 && !loop_p)
   16423                 :             :             {
   16424                 :        5636 :               c = build_omp_clause (input_location, OMP_CLAUSE_LINEAR);
   16425                 :        5636 :               OMP_CLAUSE_LINEAR_NO_COPYIN (c) = 1;
   16426                 :        5636 :               unsigned int flags = GOVD_LINEAR | GOVD_EXPLICIT | GOVD_SEEN;
   16427                 :        5636 :               if ((has_decl_expr
   16428                 :        1311 :                    && bitmap_bit_p (has_decl_expr, DECL_UID (decl)))
   16429                 :        6320 :                   || TREE_PRIVATE (t))
   16430                 :             :                 {
   16431                 :        2282 :                   OMP_CLAUSE_LINEAR_NO_COPYOUT (c) = 1;
   16432                 :        2282 :                   flags |= GOVD_LINEAR_LASTPRIVATE_NO_OUTER;
   16433                 :             :                 }
   16434                 :        5636 :               struct gimplify_omp_ctx *outer
   16435                 :        5636 :                 = gimplify_omp_ctxp->outer_context;
   16436                 :        5636 :               if (outer && !OMP_CLAUSE_LINEAR_NO_COPYOUT (c))
   16437                 :             :                 {
   16438                 :        2433 :                   if (outer->region_type == ORT_WORKSHARE
   16439                 :        2193 :                       && outer->combined_loop)
   16440                 :             :                     {
   16441                 :        2142 :                       n = splay_tree_lookup (outer->variables,
   16442                 :             :                                              (splay_tree_key)decl);
   16443                 :        2142 :                       if (n != NULL && (n->value & GOVD_LOCAL) != 0)
   16444                 :             :                         {
   16445                 :           0 :                           OMP_CLAUSE_LINEAR_NO_COPYOUT (c) = 1;
   16446                 :           0 :                           flags |= GOVD_LINEAR_LASTPRIVATE_NO_OUTER;
   16447                 :             :                         }
   16448                 :             :                       else
   16449                 :             :                         {
   16450                 :        2142 :                           struct gimplify_omp_ctx *octx = outer->outer_context;
   16451                 :        2142 :                           if (octx
   16452                 :        1714 :                               && octx->region_type == ORT_COMBINED_PARALLEL
   16453                 :        1476 :                               && octx->outer_context
   16454                 :        1209 :                               && (octx->outer_context->region_type
   16455                 :             :                                   == ORT_WORKSHARE)
   16456                 :        1079 :                               && octx->outer_context->combined_loop)
   16457                 :             :                             {
   16458                 :        1079 :                               octx = octx->outer_context;
   16459                 :        1079 :                               n = splay_tree_lookup (octx->variables,
   16460                 :             :                                                      (splay_tree_key)decl);
   16461                 :        1079 :                               if (n != NULL && (n->value & GOVD_LOCAL) != 0)
   16462                 :             :                                 {
   16463                 :           0 :                                   OMP_CLAUSE_LINEAR_NO_COPYOUT (c) = 1;
   16464                 :           0 :                                   flags |= GOVD_LINEAR_LASTPRIVATE_NO_OUTER;
   16465                 :             :                                 }
   16466                 :             :                             }
   16467                 :             :                         }
   16468                 :             :                     }
   16469                 :             :                 }
   16470                 :             : 
   16471                 :        5636 :               OMP_CLAUSE_DECL (c) = decl;
   16472                 :        5636 :               OMP_CLAUSE_CHAIN (c) = OMP_FOR_CLAUSES (for_stmt);
   16473                 :        5636 :               OMP_FOR_CLAUSES (for_stmt) = c;
   16474                 :        5636 :               omp_add_variable (gimplify_omp_ctxp, decl, flags);
   16475                 :        5636 :               if (outer && !OMP_CLAUSE_LINEAR_NO_COPYOUT (c))
   16476                 :        2433 :                 omp_lastprivate_for_combined_outer_constructs (outer, decl,
   16477                 :             :                                                                true);
   16478                 :             :             }
   16479                 :             :           else
   16480                 :             :             {
   16481                 :        7554 :               bool lastprivate
   16482                 :             :                 = (!has_decl_expr
   16483                 :        7554 :                    || !bitmap_bit_p (has_decl_expr, DECL_UID (decl)));
   16484                 :        7554 :               if (TREE_PRIVATE (t))
   16485                 :        1771 :                 lastprivate = false;
   16486                 :        7554 :               if (loop_p && OMP_FOR_ORIG_DECLS (for_stmt))
   16487                 :             :                 {
   16488                 :         507 :                   tree elt = TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (for_stmt), i);
   16489                 :         507 :                   if (TREE_CODE (elt) == TREE_LIST && TREE_PURPOSE (elt))
   16490                 :             :                     lastprivate = false;
   16491                 :             :                 }
   16492                 :             : 
   16493                 :        7554 :               struct gimplify_omp_ctx *outer
   16494                 :        7554 :                 = gimplify_omp_ctxp->outer_context;
   16495                 :        7554 :               if (outer && lastprivate)
   16496                 :        4890 :                 omp_lastprivate_for_combined_outer_constructs (outer, decl,
   16497                 :             :                                                                true);
   16498                 :             : 
   16499                 :        9544 :               c = build_omp_clause (input_location,
   16500                 :             :                                     lastprivate ? OMP_CLAUSE_LASTPRIVATE
   16501                 :             :                                                 : OMP_CLAUSE_PRIVATE);
   16502                 :        7554 :               OMP_CLAUSE_DECL (c) = decl;
   16503                 :        7554 :               OMP_CLAUSE_CHAIN (c) = OMP_FOR_CLAUSES (for_stmt);
   16504                 :        7554 :               OMP_FOR_CLAUSES (for_stmt) = c;
   16505                 :        7554 :               omp_add_variable (gimplify_omp_ctxp, decl,
   16506                 :             :                                 (lastprivate ? GOVD_LASTPRIVATE : GOVD_PRIVATE)
   16507                 :             :                                 | GOVD_EXPLICIT | GOVD_SEEN);
   16508                 :        7554 :               c = NULL_TREE;
   16509                 :             :             }
   16510                 :             :         }
   16511                 :       34381 :       else if (omp_is_private (gimplify_omp_ctxp, decl, 0))
   16512                 :             :         {
   16513                 :        8731 :           omp_notice_variable (gimplify_omp_ctxp, decl, true);
   16514                 :        8731 :           splay_tree_node n = splay_tree_lookup (gimplify_omp_ctxp->variables,
   16515                 :             :                                                  (splay_tree_key) decl);
   16516                 :        8731 :           if (n && (n->value & GOVD_LASTPRIVATE_CONDITIONAL))
   16517                 :          80 :             for (tree c3 = omp_find_clause (OMP_FOR_CLAUSES (for_stmt),
   16518                 :             :                                             OMP_CLAUSE_LASTPRIVATE);
   16519                 :          80 :                  c3; c3 = omp_find_clause (OMP_CLAUSE_CHAIN (c3),
   16520                 :             :                                            OMP_CLAUSE_LASTPRIVATE))
   16521                 :          40 :               if (OMP_CLAUSE_DECL (c3) == decl)
   16522                 :             :                 {
   16523                 :          40 :                   warning_at (OMP_CLAUSE_LOCATION (c3), OPT_Wopenmp,
   16524                 :             :                               "conditional %<lastprivate%> on loop "
   16525                 :             :                               "iterator %qD ignored", decl);
   16526                 :          40 :                   OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c3) = 0;
   16527                 :          40 :                   n->value &= ~GOVD_LASTPRIVATE_CONDITIONAL;
   16528                 :             :                 }
   16529                 :             :         }
   16530                 :             :       else
   16531                 :       25650 :         omp_add_variable (gimplify_omp_ctxp, decl, GOVD_PRIVATE | GOVD_SEEN);
   16532                 :             : 
   16533                 :             :       /* If DECL is not a gimple register, create a temporary variable to act
   16534                 :             :          as an iteration counter.  This is valid, since DECL cannot be
   16535                 :             :          modified in the body of the loop.  Similarly for any iteration vars
   16536                 :             :          in simd with collapse > 1 where the iterator vars must be
   16537                 :             :          lastprivate.  And similarly for vars mentioned in allocate clauses.  */
   16538                 :       72863 :       if (orig_for_stmt != for_stmt)
   16539                 :       22770 :         var = decl;
   16540                 :       50093 :       else if (!is_gimple_reg (decl)
   16541                 :       46828 :                || (ort == ORT_SIMD
   16542                 :       14113 :                    && TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)) > 1)
   16543                 :       89884 :                || (allocate_uids && allocate_uids->contains (decl)))
   16544                 :             :         {
   16545                 :       10334 :           struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp;
   16546                 :             :           /* Make sure omp_add_variable is not called on it prematurely.
   16547                 :             :              We call it ourselves a few lines later.  */
   16548                 :       10334 :           gimplify_omp_ctxp = NULL;
   16549                 :       10334 :           var = create_tmp_var (TREE_TYPE (decl), get_name (decl));
   16550                 :       10334 :           gimplify_omp_ctxp = ctx;
   16551                 :       10334 :           TREE_OPERAND (t, 0) = var;
   16552                 :             : 
   16553                 :       10334 :           gimplify_seq_add_stmt (&for_body, gimple_build_assign (decl, var));
   16554                 :             : 
   16555                 :       10334 :           if (ort == ORT_SIMD
   16556                 :       10334 :               && TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)) == 1)
   16557                 :             :             {
   16558                 :         768 :               c2 = build_omp_clause (input_location, OMP_CLAUSE_LINEAR);
   16559                 :         768 :               OMP_CLAUSE_LINEAR_NO_COPYIN (c2) = 1;
   16560                 :         768 :               OMP_CLAUSE_LINEAR_NO_COPYOUT (c2) = 1;
   16561                 :         768 :               OMP_CLAUSE_DECL (c2) = var;
   16562                 :         768 :               OMP_CLAUSE_CHAIN (c2) = OMP_FOR_CLAUSES (for_stmt);
   16563                 :         768 :               OMP_FOR_CLAUSES (for_stmt) = c2;
   16564                 :         768 :               omp_add_variable (gimplify_omp_ctxp, var,
   16565                 :             :                                 GOVD_LINEAR | GOVD_EXPLICIT | GOVD_SEEN);
   16566                 :         768 :               if (c == NULL_TREE)
   16567                 :             :                 {
   16568                 :         518 :                   c = c2;
   16569                 :         518 :                   c2 = NULL_TREE;
   16570                 :             :                 }
   16571                 :             :             }
   16572                 :             :           else
   16573                 :        9566 :             omp_add_variable (gimplify_omp_ctxp, var,
   16574                 :             :                               GOVD_PRIVATE | GOVD_SEEN);
   16575                 :             :         }
   16576                 :             :       else
   16577                 :             :         var = decl;
   16578                 :             : 
   16579                 :       72863 :       gimplify_omp_ctxp->in_for_exprs = true;
   16580                 :       72863 :       if (TREE_CODE (TREE_OPERAND (t, 1)) == TREE_VEC)
   16581                 :             :         {
   16582                 :         719 :           tree lb = TREE_OPERAND (t, 1);
   16583                 :         719 :           tret = gimplify_expr (&TREE_VEC_ELT (lb, 1), &for_pre_body, NULL,
   16584                 :             :                                 is_gimple_val, fb_rvalue, false);
   16585                 :         719 :           ret = MIN (ret, tret);
   16586                 :         719 :           tret = gimplify_expr (&TREE_VEC_ELT (lb, 2), &for_pre_body, NULL,
   16587                 :             :                                 is_gimple_val, fb_rvalue, false);
   16588                 :             :         }
   16589                 :             :       else
   16590                 :       72144 :         tret = gimplify_expr (&TREE_OPERAND (t, 1), &for_pre_body, NULL,
   16591                 :             :                               is_gimple_val, fb_rvalue, false);
   16592                 :       72863 :       gimplify_omp_ctxp->in_for_exprs = false;
   16593                 :       72863 :       ret = MIN (ret, tret);
   16594                 :       72863 :       if (ret == GS_ERROR)
   16595                 :             :         return ret;
   16596                 :             : 
   16597                 :             :       /* Handle OMP_FOR_COND.  */
   16598                 :       72863 :       t = TREE_VEC_ELT (OMP_FOR_COND (for_stmt), i);
   16599                 :       72863 :       gcc_assert (COMPARISON_CLASS_P (t));
   16600                 :       72863 :       gcc_assert (TREE_OPERAND (t, 0) == decl);
   16601                 :             : 
   16602                 :       72863 :       gimplify_omp_ctxp->in_for_exprs = true;
   16603                 :       72863 :       if (TREE_CODE (TREE_OPERAND (t, 1)) == TREE_VEC)
   16604                 :             :         {
   16605                 :         599 :           tree ub = TREE_OPERAND (t, 1);
   16606                 :         599 :           tret = gimplify_expr (&TREE_VEC_ELT (ub, 1), &for_pre_body, NULL,
   16607                 :             :                                 is_gimple_val, fb_rvalue, false);
   16608                 :         599 :           ret = MIN (ret, tret);
   16609                 :         599 :           tret = gimplify_expr (&TREE_VEC_ELT (ub, 2), &for_pre_body, NULL,
   16610                 :             :                                 is_gimple_val, fb_rvalue, false);
   16611                 :             :         }
   16612                 :             :       else
   16613                 :       72264 :         tret = gimplify_expr (&TREE_OPERAND (t, 1), &for_pre_body, NULL,
   16614                 :             :                               is_gimple_val, fb_rvalue, false);
   16615                 :       72863 :       gimplify_omp_ctxp->in_for_exprs = false;
   16616                 :       72863 :       ret = MIN (ret, tret);
   16617                 :             : 
   16618                 :             :       /* Handle OMP_FOR_INCR.  */
   16619                 :       72863 :       t = TREE_VEC_ELT (OMP_FOR_INCR (for_stmt), i);
   16620                 :       72863 :       switch (TREE_CODE (t))
   16621                 :             :         {
   16622                 :       35609 :         case PREINCREMENT_EXPR:
   16623                 :       35609 :         case POSTINCREMENT_EXPR:
   16624                 :       35609 :           {
   16625                 :       35609 :             tree decl = TREE_OPERAND (t, 0);
   16626                 :             :             /* c_omp_for_incr_canonicalize_ptr() should have been
   16627                 :             :                called to massage things appropriately.  */
   16628                 :       35609 :             gcc_assert (!POINTER_TYPE_P (TREE_TYPE (decl)));
   16629                 :             : 
   16630                 :       35609 :             if (orig_for_stmt != for_stmt)
   16631                 :             :               break;
   16632                 :       25256 :             t = build_int_cst (TREE_TYPE (decl), 1);
   16633                 :       25256 :             if (c)
   16634                 :        4466 :               OMP_CLAUSE_LINEAR_STEP (c) = t;
   16635                 :       25256 :             t = build2 (PLUS_EXPR, TREE_TYPE (decl), var, t);
   16636                 :       25256 :             t = build2 (MODIFY_EXPR, TREE_TYPE (var), var, t);
   16637                 :       25256 :             TREE_VEC_ELT (OMP_FOR_INCR (for_stmt), i) = t;
   16638                 :       25256 :             break;
   16639                 :             :           }
   16640                 :             : 
   16641                 :        3826 :         case PREDECREMENT_EXPR:
   16642                 :        3826 :         case POSTDECREMENT_EXPR:
   16643                 :             :           /* c_omp_for_incr_canonicalize_ptr() should have been
   16644                 :             :              called to massage things appropriately.  */
   16645                 :        3826 :           gcc_assert (!POINTER_TYPE_P (TREE_TYPE (decl)));
   16646                 :        3826 :           if (orig_for_stmt != for_stmt)
   16647                 :             :             break;
   16648                 :        1988 :           t = build_int_cst (TREE_TYPE (decl), -1);
   16649                 :        1988 :           if (c)
   16650                 :         112 :             OMP_CLAUSE_LINEAR_STEP (c) = t;
   16651                 :        1988 :           t = build2 (PLUS_EXPR, TREE_TYPE (decl), var, t);
   16652                 :        1988 :           t = build2 (MODIFY_EXPR, TREE_TYPE (var), var, t);
   16653                 :        1988 :           TREE_VEC_ELT (OMP_FOR_INCR (for_stmt), i) = t;
   16654                 :        1988 :           break;
   16655                 :             : 
   16656                 :       33428 :         case MODIFY_EXPR:
   16657                 :       33428 :           gcc_assert (TREE_OPERAND (t, 0) == decl);
   16658                 :       33428 :           TREE_OPERAND (t, 0) = var;
   16659                 :             : 
   16660                 :       33428 :           t = TREE_OPERAND (t, 1);
   16661                 :       33428 :           switch (TREE_CODE (t))
   16662                 :             :             {
   16663                 :       26503 :             case PLUS_EXPR:
   16664                 :       26503 :               if (TREE_OPERAND (t, 1) == decl)
   16665                 :             :                 {
   16666                 :         215 :                   TREE_OPERAND (t, 1) = TREE_OPERAND (t, 0);
   16667                 :         215 :                   TREE_OPERAND (t, 0) = var;
   16668                 :         215 :                   break;
   16669                 :             :                 }
   16670                 :             : 
   16671                 :             :               /* Fallthru.  */
   16672                 :       33213 :             case MINUS_EXPR:
   16673                 :       33213 :             case POINTER_PLUS_EXPR:
   16674                 :       33213 :               gcc_assert (TREE_OPERAND (t, 0) == decl);
   16675                 :       33213 :               TREE_OPERAND (t, 0) = var;
   16676                 :       33213 :               break;
   16677                 :           0 :             default:
   16678                 :           0 :               gcc_unreachable ();
   16679                 :             :             }
   16680                 :             : 
   16681                 :       33428 :           gimplify_omp_ctxp->in_for_exprs = true;
   16682                 :       33428 :           tret = gimplify_expr (&TREE_OPERAND (t, 1), &for_pre_body, NULL,
   16683                 :             :                                 is_gimple_val, fb_rvalue, false);
   16684                 :       33428 :           ret = MIN (ret, tret);
   16685                 :       33428 :           if (c)
   16686                 :             :             {
   16687                 :        1576 :               tree step = TREE_OPERAND (t, 1);
   16688                 :        1576 :               tree stept = TREE_TYPE (decl);
   16689                 :        1576 :               if (POINTER_TYPE_P (stept))
   16690                 :         280 :                 stept = sizetype;
   16691                 :        1576 :               step = fold_convert (stept, step);
   16692                 :        1576 :               if (TREE_CODE (t) == MINUS_EXPR)
   16693                 :         295 :                 step = fold_build1 (NEGATE_EXPR, stept, step);
   16694                 :        1576 :               OMP_CLAUSE_LINEAR_STEP (c) = step;
   16695                 :        1576 :               if (step != TREE_OPERAND (t, 1))
   16696                 :             :                 {
   16697                 :         295 :                   tret = gimplify_expr (&OMP_CLAUSE_LINEAR_STEP (c),
   16698                 :             :                                         &for_pre_body, NULL,
   16699                 :             :                                         is_gimple_val, fb_rvalue, false);
   16700                 :         295 :                   ret = MIN (ret, tret);
   16701                 :             :                 }
   16702                 :             :             }
   16703                 :       33428 :           gimplify_omp_ctxp->in_for_exprs = false;
   16704                 :       33428 :           break;
   16705                 :             : 
   16706                 :           0 :         default:
   16707                 :           0 :           gcc_unreachable ();
   16708                 :             :         }
   16709                 :             : 
   16710                 :       72863 :       if (c2)
   16711                 :             :         {
   16712                 :         250 :           gcc_assert (c);
   16713                 :         250 :           OMP_CLAUSE_LINEAR_STEP (c2) = OMP_CLAUSE_LINEAR_STEP (c);
   16714                 :             :         }
   16715                 :             : 
   16716                 :       72863 :       if ((var != decl || collapse > 1 || tile) && orig_for_stmt == for_stmt)
   16717                 :             :         {
   16718                 :       86387 :           for (c = OMP_FOR_CLAUSES (for_stmt); c ; c = OMP_CLAUSE_CHAIN (c))
   16719                 :       64910 :             if (((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
   16720                 :       16198 :                   && OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (c) == NULL)
   16721                 :       55912 :                  || (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR
   16722                 :        2155 :                      && !OMP_CLAUSE_LINEAR_NO_COPYOUT (c)
   16723                 :        1371 :                      && OMP_CLAUSE_LINEAR_GIMPLE_SEQ (c) == NULL))
   16724                 :       75257 :                 && OMP_CLAUSE_DECL (c) == decl)
   16725                 :             :               {
   16726                 :        7522 :                 if (is_doacross && (collapse == 1 || i >= collapse))
   16727                 :             :                   t = var;
   16728                 :             :                 else
   16729                 :             :                   {
   16730                 :        7449 :                     t = TREE_VEC_ELT (OMP_FOR_INCR (for_stmt), i);
   16731                 :        7449 :                     gcc_assert (TREE_CODE (t) == MODIFY_EXPR);
   16732                 :        7449 :                     gcc_assert (TREE_OPERAND (t, 0) == var);
   16733                 :        7449 :                     t = TREE_OPERAND (t, 1);
   16734                 :        7449 :                     gcc_assert (TREE_CODE (t) == PLUS_EXPR
   16735                 :             :                                 || TREE_CODE (t) == MINUS_EXPR
   16736                 :             :                                 || TREE_CODE (t) == POINTER_PLUS_EXPR);
   16737                 :        7449 :                     gcc_assert (TREE_OPERAND (t, 0) == var);
   16738                 :       14796 :                     t = build2 (TREE_CODE (t), TREE_TYPE (decl),
   16739                 :             :                                 is_doacross ? var : decl,
   16740                 :        7449 :                                 TREE_OPERAND (t, 1));
   16741                 :             :                   }
   16742                 :        7522 :                 gimple_seq *seq;
   16743                 :        7522 :                 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE)
   16744                 :        6928 :                   seq = &OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (c);
   16745                 :             :                 else
   16746                 :         594 :                   seq = &OMP_CLAUSE_LINEAR_GIMPLE_SEQ (c);
   16747                 :        7522 :                 push_gimplify_context ();
   16748                 :        7522 :                 gimplify_assign (decl, t, seq);
   16749                 :        7522 :                 gimple *bind = NULL;
   16750                 :        7522 :                 if (gimplify_ctxp->temps)
   16751                 :             :                   {
   16752                 :        2070 :                     bind = gimple_build_bind (NULL_TREE, *seq, NULL_TREE);
   16753                 :        2070 :                     *seq = NULL;
   16754                 :        2070 :                     gimplify_seq_add_stmt (seq, bind);
   16755                 :             :                   }
   16756                 :        7522 :                 pop_gimplify_context (bind);
   16757                 :             :               }
   16758                 :             :         }
   16759                 :       72863 :       if (OMP_FOR_NON_RECTANGULAR (for_stmt) && var != decl)
   16760                 :        2609 :         for (int j = i + 1; j < TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)); j++)
   16761                 :             :           {
   16762                 :        1197 :             t = TREE_VEC_ELT (OMP_FOR_INIT (for_stmt), j);
   16763                 :        1197 :             gcc_assert (TREE_CODE (t) == MODIFY_EXPR);
   16764                 :        1197 :             if (TREE_CODE (TREE_OPERAND (t, 1)) == TREE_VEC
   16765                 :        1197 :                 && TREE_VEC_ELT (TREE_OPERAND (t, 1), 0) == decl)
   16766                 :         336 :               TREE_VEC_ELT (TREE_OPERAND (t, 1), 0) = var;
   16767                 :        1197 :             t = TREE_VEC_ELT (OMP_FOR_COND (for_stmt), j);
   16768                 :        1197 :             gcc_assert (COMPARISON_CLASS_P (t));
   16769                 :        1197 :             if (TREE_CODE (TREE_OPERAND (t, 1)) == TREE_VEC
   16770                 :        1197 :                 && TREE_VEC_ELT (TREE_OPERAND (t, 1), 0) == decl)
   16771                 :         343 :               TREE_VEC_ELT (TREE_OPERAND (t, 1), 0) = var;
   16772                 :             :           }
   16773                 :             :     }
   16774                 :             : 
   16775                 :       51190 :   BITMAP_FREE (has_decl_expr);
   16776                 :       51465 :   delete allocate_uids;
   16777                 :             : 
   16778                 :       51190 :   if (TREE_CODE (orig_for_stmt) == OMP_TASKLOOP
   16779                 :       49591 :       || (loop_p && orig_for_stmt == for_stmt))
   16780                 :             :     {
   16781                 :        2656 :       push_gimplify_context ();
   16782                 :        2656 :       if (TREE_CODE (OMP_FOR_BODY (orig_for_stmt)) != BIND_EXPR)
   16783                 :             :         {
   16784                 :        1908 :           OMP_FOR_BODY (orig_for_stmt)
   16785                 :        3816 :             = build3 (BIND_EXPR, void_type_node, NULL,
   16786                 :        1908 :                       OMP_FOR_BODY (orig_for_stmt), NULL);
   16787                 :        1908 :           TREE_SIDE_EFFECTS (OMP_FOR_BODY (orig_for_stmt)) = 1;
   16788                 :             :         }
   16789                 :             :     }
   16790                 :             : 
   16791                 :       51190 :   gimple *g = gimplify_and_return_first (OMP_FOR_BODY (orig_for_stmt),
   16792                 :             :                                          &for_body);
   16793                 :             : 
   16794                 :       51190 :   if (TREE_CODE (orig_for_stmt) == OMP_TASKLOOP
   16795                 :       49591 :       || (loop_p && orig_for_stmt == for_stmt))
   16796                 :             :     {
   16797                 :        2656 :       if (gimple_code (g) == GIMPLE_BIND)
   16798                 :        2656 :         pop_gimplify_context (g);
   16799                 :             :       else
   16800                 :           0 :         pop_gimplify_context (NULL);
   16801                 :             :     }
   16802                 :             : 
   16803                 :       51190 :   if (orig_for_stmt != for_stmt)
   16804                 :       36686 :     for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)); i++)
   16805                 :             :       {
   16806                 :       22770 :         t = TREE_VEC_ELT (OMP_FOR_INIT (for_stmt), i);
   16807                 :       22770 :         decl = TREE_OPERAND (t, 0);
   16808                 :       22770 :         struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp;
   16809                 :       22770 :         if (TREE_CODE (orig_for_stmt) == OMP_TASKLOOP)
   16810                 :         772 :           gimplify_omp_ctxp = ctx->outer_context;
   16811                 :       22770 :         var = create_tmp_var (TREE_TYPE (decl), get_name (decl));
   16812                 :       22770 :         gimplify_omp_ctxp = ctx;
   16813                 :       22770 :         omp_add_variable (gimplify_omp_ctxp, var, GOVD_PRIVATE | GOVD_SEEN);
   16814                 :       22770 :         TREE_OPERAND (t, 0) = var;
   16815                 :       22770 :         t = TREE_VEC_ELT (OMP_FOR_INCR (for_stmt), i);
   16816                 :       22770 :         TREE_OPERAND (t, 1) = copy_node (TREE_OPERAND (t, 1));
   16817                 :       22770 :         TREE_OPERAND (TREE_OPERAND (t, 1), 0) = var;
   16818                 :       22770 :         if (OMP_FOR_NON_RECTANGULAR (for_stmt))
   16819                 :         791 :           for (int j = i + 1;
   16820                 :         791 :                j < TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)); j++)
   16821                 :             :             {
   16822                 :         377 :               t = TREE_VEC_ELT (OMP_FOR_INIT (for_stmt), j);
   16823                 :         377 :               gcc_assert (TREE_CODE (t) == MODIFY_EXPR);
   16824                 :         377 :               if (TREE_CODE (TREE_OPERAND (t, 1)) == TREE_VEC
   16825                 :         377 :                   && TREE_VEC_ELT (TREE_OPERAND (t, 1), 0) == decl)
   16826                 :             :                 {
   16827                 :         133 :                   TREE_OPERAND (t, 1) = copy_node (TREE_OPERAND (t, 1));
   16828                 :         133 :                   TREE_VEC_ELT (TREE_OPERAND (t, 1), 0) = var;
   16829                 :             :                 }
   16830                 :         377 :               t = TREE_VEC_ELT (OMP_FOR_COND (for_stmt), j);
   16831                 :         377 :               gcc_assert (COMPARISON_CLASS_P (t));
   16832                 :         377 :               if (TREE_CODE (TREE_OPERAND (t, 1)) == TREE_VEC
   16833                 :         377 :                   && TREE_VEC_ELT (TREE_OPERAND (t, 1), 0) == decl)
   16834                 :             :                 {
   16835                 :          67 :                   TREE_OPERAND (t, 1) = copy_node (TREE_OPERAND (t, 1));
   16836                 :          67 :                   TREE_VEC_ELT (TREE_OPERAND (t, 1), 0) = var;
   16837                 :             :                 }
   16838                 :             :           }
   16839                 :             :       }
   16840                 :             : 
   16841                 :       51190 :   gimplify_adjust_omp_clauses (pre_p, for_body,
   16842                 :             :                                &OMP_FOR_CLAUSES (orig_for_stmt),
   16843                 :       51190 :                                TREE_CODE (orig_for_stmt));
   16844                 :             : 
   16845                 :       51190 :   int kind;
   16846                 :       51190 :   switch (TREE_CODE (orig_for_stmt))
   16847                 :             :     {
   16848                 :             :     case OMP_FOR: kind = GF_OMP_FOR_KIND_FOR; break;
   16849                 :       10656 :     case OMP_SIMD: kind = GF_OMP_FOR_KIND_SIMD; break;
   16850                 :        8214 :     case OMP_DISTRIBUTE: kind = GF_OMP_FOR_KIND_DISTRIBUTE; break;
   16851                 :        1599 :     case OMP_TASKLOOP: kind = GF_OMP_FOR_KIND_TASKLOOP; break;
   16852                 :       12569 :     case OACC_LOOP: kind = GF_OMP_FOR_KIND_OACC_LOOP; break;
   16853                 :           0 :     default:
   16854                 :           0 :       gcc_unreachable ();
   16855                 :             :     }
   16856                 :       51190 :   if (loop_p && kind == GF_OMP_FOR_KIND_SIMD)
   16857                 :             :     {
   16858                 :        1057 :       gimplify_seq_add_seq (pre_p, for_pre_body);
   16859                 :        1057 :       for_pre_body = NULL;
   16860                 :             :     }
   16861                 :       51190 :   gfor = gimple_build_omp_for (for_body, kind, OMP_FOR_CLAUSES (orig_for_stmt),
   16862                 :       51190 :                                TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)),
   16863                 :             :                                for_pre_body);
   16864                 :       51190 :   if (orig_for_stmt != for_stmt)
   16865                 :       13916 :     gimple_omp_for_set_combined_p (gfor, true);
   16866                 :       51190 :   if (gimplify_omp_ctxp
   16867                 :       42572 :       && (gimplify_omp_ctxp->combined_loop
   16868                 :       35046 :           || (gimplify_omp_ctxp->region_type == ORT_COMBINED_PARALLEL
   16869                 :       12291 :               && gimplify_omp_ctxp->outer_context
   16870                 :        7860 :               && gimplify_omp_ctxp->outer_context->combined_loop)))
   16871                 :             :     {
   16872                 :       13916 :       gimple_omp_for_set_combined_into_p (gfor, true);
   16873                 :       13916 :       if (gimplify_omp_ctxp->combined_loop)
   16874                 :        7526 :         gcc_assert (TREE_CODE (orig_for_stmt) == OMP_SIMD);
   16875                 :             :       else
   16876                 :        6390 :         gcc_assert (TREE_CODE (orig_for_stmt) == OMP_FOR);
   16877                 :             :     }
   16878                 :             : 
   16879                 :      124053 :   for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)); i++)
   16880                 :             :     {
   16881                 :       72863 :       t = TREE_VEC_ELT (OMP_FOR_INIT (for_stmt), i);
   16882                 :       72863 :       gimple_omp_for_set_index (gfor, i, TREE_OPERAND (t, 0));
   16883                 :       72863 :       gimple_omp_for_set_initial (gfor, i, TREE_OPERAND (t, 1));
   16884                 :       72863 :       t = TREE_VEC_ELT (OMP_FOR_COND (for_stmt), i);
   16885                 :       72863 :       gimple_omp_for_set_cond (gfor, i, TREE_CODE (t));
   16886                 :       72863 :       gimple_omp_for_set_final (gfor, i, TREE_OPERAND (t, 1));
   16887                 :       72863 :       t = TREE_VEC_ELT (OMP_FOR_INCR (for_stmt), i);
   16888                 :       72863 :       gimple_omp_for_set_incr (gfor, i, TREE_OPERAND (t, 1));
   16889                 :             :     }
   16890                 :             : 
   16891                 :             :   /* OMP_TASKLOOP is gimplified as two GIMPLE_OMP_FOR taskloop
   16892                 :             :      constructs with GIMPLE_OMP_TASK sandwiched in between them.
   16893                 :             :      The outer taskloop stands for computing the number of iterations,
   16894                 :             :      counts for collapsed loops and holding taskloop specific clauses.
   16895                 :             :      The task construct stands for the effect of data sharing on the
   16896                 :             :      explicit task it creates and the inner taskloop stands for expansion
   16897                 :             :      of the static loop inside of the explicit task construct.  */
   16898                 :       51190 :   if (TREE_CODE (orig_for_stmt) == OMP_TASKLOOP)
   16899                 :             :     {
   16900                 :        1599 :       tree *gfor_clauses_ptr = gimple_omp_for_clauses_ptr (gfor);
   16901                 :        1599 :       tree task_clauses = NULL_TREE;
   16902                 :        1599 :       tree c = *gfor_clauses_ptr;
   16903                 :        1599 :       tree *gtask_clauses_ptr = &task_clauses;
   16904                 :        1599 :       tree outer_for_clauses = NULL_TREE;
   16905                 :        1599 :       tree *gforo_clauses_ptr = &outer_for_clauses;
   16906                 :        1599 :       bitmap lastprivate_uids = NULL;
   16907                 :        1599 :       if (omp_find_clause (c, OMP_CLAUSE_ALLOCATE))
   16908                 :             :         {
   16909                 :          36 :           c = omp_find_clause (c, OMP_CLAUSE_LASTPRIVATE);
   16910                 :          36 :           if (c)
   16911                 :             :             {
   16912                 :          18 :               lastprivate_uids = BITMAP_ALLOC (NULL);
   16913                 :          54 :               for (; c; c = omp_find_clause (OMP_CLAUSE_CHAIN (c),
   16914                 :             :                                              OMP_CLAUSE_LASTPRIVATE))
   16915                 :          18 :                 bitmap_set_bit (lastprivate_uids,
   16916                 :          18 :                                 DECL_UID (OMP_CLAUSE_DECL (c)));
   16917                 :             :             }
   16918                 :          36 :           c = *gfor_clauses_ptr;
   16919                 :             :         }
   16920                 :       12365 :       for (; c; c = OMP_CLAUSE_CHAIN (c))
   16921                 :       10766 :         switch (OMP_CLAUSE_CODE (c))
   16922                 :             :           {
   16923                 :             :           /* These clauses are allowed on task, move them there.  */
   16924                 :        6290 :           case OMP_CLAUSE_SHARED:
   16925                 :        6290 :           case OMP_CLAUSE_FIRSTPRIVATE:
   16926                 :        6290 :           case OMP_CLAUSE_DEFAULT:
   16927                 :        6290 :           case OMP_CLAUSE_IF:
   16928                 :        6290 :           case OMP_CLAUSE_UNTIED:
   16929                 :        6290 :           case OMP_CLAUSE_FINAL:
   16930                 :        6290 :           case OMP_CLAUSE_MERGEABLE:
   16931                 :        6290 :           case OMP_CLAUSE_PRIORITY:
   16932                 :        6290 :           case OMP_CLAUSE_REDUCTION:
   16933                 :        6290 :           case OMP_CLAUSE_IN_REDUCTION:
   16934                 :        6290 :             *gtask_clauses_ptr = c;
   16935                 :        6290 :             gtask_clauses_ptr = &OMP_CLAUSE_CHAIN (c);
   16936                 :        6290 :             break;
   16937                 :        2101 :           case OMP_CLAUSE_PRIVATE:
   16938                 :        2101 :             if (OMP_CLAUSE_PRIVATE_TASKLOOP_IV (c))
   16939                 :             :               {
   16940                 :             :                 /* We want private on outer for and firstprivate
   16941                 :             :                    on task.  */
   16942                 :          26 :                 *gtask_clauses_ptr
   16943                 :          26 :                   = build_omp_clause (OMP_CLAUSE_LOCATION (c),
   16944                 :             :                                       OMP_CLAUSE_FIRSTPRIVATE);
   16945                 :          26 :                 OMP_CLAUSE_DECL (*gtask_clauses_ptr) = OMP_CLAUSE_DECL (c);
   16946                 :          26 :                 lang_hooks.decls.omp_finish_clause (*gtask_clauses_ptr, NULL,
   16947                 :             :                                                     openacc);
   16948                 :          26 :                 gtask_clauses_ptr = &OMP_CLAUSE_CHAIN (*gtask_clauses_ptr);
   16949                 :          26 :                 *gforo_clauses_ptr = c;
   16950                 :          26 :                 gforo_clauses_ptr = &OMP_CLAUSE_CHAIN (c);
   16951                 :             :               }
   16952                 :             :             else
   16953                 :             :               {
   16954                 :        2075 :                 *gtask_clauses_ptr = c;
   16955                 :        2075 :                 gtask_clauses_ptr = &OMP_CLAUSE_CHAIN (c);
   16956                 :             :               }
   16957                 :             :             break;
   16958                 :             :           /* These clauses go into outer taskloop clauses.  */
   16959                 :         549 :           case OMP_CLAUSE_GRAINSIZE:
   16960                 :         549 :           case OMP_CLAUSE_NUM_TASKS:
   16961                 :         549 :           case OMP_CLAUSE_NOGROUP:
   16962                 :         549 :             *gforo_clauses_ptr = c;
   16963                 :         549 :             gforo_clauses_ptr = &OMP_CLAUSE_CHAIN (c);
   16964                 :         549 :             break;
   16965                 :             :           /* Collapse clause we duplicate on both taskloops.  */
   16966                 :         580 :           case OMP_CLAUSE_COLLAPSE:
   16967                 :         580 :             *gfor_clauses_ptr = c;
   16968                 :         580 :             gfor_clauses_ptr = &OMP_CLAUSE_CHAIN (c);
   16969                 :         580 :             *gforo_clauses_ptr = copy_node (c);
   16970                 :         580 :             gforo_clauses_ptr = &OMP_CLAUSE_CHAIN (*gforo_clauses_ptr);
   16971                 :         580 :             break;
   16972                 :             :           /* For lastprivate, keep the clause on inner taskloop, and add
   16973                 :             :              a shared clause on task.  If the same decl is also firstprivate,
   16974                 :             :              add also firstprivate clause on the inner taskloop.  */
   16975                 :        1184 :           case OMP_CLAUSE_LASTPRIVATE:
   16976                 :        1184 :             if (OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c))
   16977                 :             :               {
   16978                 :             :                 /* For taskloop C++ lastprivate IVs, we want:
   16979                 :             :                    1) private on outer taskloop
   16980                 :             :                    2) firstprivate and shared on task
   16981                 :             :                    3) lastprivate on inner taskloop  */
   16982                 :          38 :                 *gtask_clauses_ptr
   16983                 :          38 :                   = build_omp_clause (OMP_CLAUSE_LOCATION (c),
   16984                 :             :                                       OMP_CLAUSE_FIRSTPRIVATE);
   16985                 :          38 :                 OMP_CLAUSE_DECL (*gtask_clauses_ptr) = OMP_CLAUSE_DECL (c);
   16986                 :          38 :                 lang_hooks.decls.omp_finish_clause (*gtask_clauses_ptr, NULL,
   16987                 :             :                                                     openacc);
   16988                 :          38 :                 gtask_clauses_ptr = &OMP_CLAUSE_CHAIN (*gtask_clauses_ptr);
   16989                 :          38 :                 OMP_CLAUSE_LASTPRIVATE_FIRSTPRIVATE (c) = 1;
   16990                 :          38 :                 *gforo_clauses_ptr = build_omp_clause (OMP_CLAUSE_LOCATION (c),
   16991                 :             :                                                        OMP_CLAUSE_PRIVATE);
   16992                 :          38 :                 OMP_CLAUSE_DECL (*gforo_clauses_ptr) = OMP_CLAUSE_DECL (c);
   16993                 :          38 :                 OMP_CLAUSE_PRIVATE_TASKLOOP_IV (*gforo_clauses_ptr) = 1;
   16994                 :          38 :                 TREE_TYPE (*gforo_clauses_ptr) = TREE_TYPE (c);
   16995                 :          38 :                 gforo_clauses_ptr = &OMP_CLAUSE_CHAIN (*gforo_clauses_ptr);
   16996                 :             :               }
   16997                 :        1184 :             *gfor_clauses_ptr = c;
   16998                 :        1184 :             gfor_clauses_ptr = &OMP_CLAUSE_CHAIN (c);
   16999                 :        1184 :             *gtask_clauses_ptr
   17000                 :        1184 :               = build_omp_clause (OMP_CLAUSE_LOCATION (c), OMP_CLAUSE_SHARED);
   17001                 :        1184 :             OMP_CLAUSE_DECL (*gtask_clauses_ptr) = OMP_CLAUSE_DECL (c);
   17002                 :        1184 :             if (OMP_CLAUSE_LASTPRIVATE_FIRSTPRIVATE (c))
   17003                 :         309 :               OMP_CLAUSE_SHARED_FIRSTPRIVATE (*gtask_clauses_ptr) = 1;
   17004                 :        1184 :             gtask_clauses_ptr
   17005                 :        1184 :               = &OMP_CLAUSE_CHAIN (*gtask_clauses_ptr);
   17006                 :        1184 :             break;
   17007                 :             :           /* Allocate clause we duplicate on task and inner taskloop
   17008                 :             :              if the decl is lastprivate, otherwise just put on task.  */
   17009                 :          62 :           case OMP_CLAUSE_ALLOCATE:
   17010                 :          62 :             if (OMP_CLAUSE_ALLOCATE_ALLOCATOR (c)
   17011                 :          62 :                 && DECL_P (OMP_CLAUSE_ALLOCATE_ALLOCATOR (c)))
   17012                 :             :               {
   17013                 :             :                 /* Additionally, put firstprivate clause on task
   17014                 :             :                    for the allocator if it is not constant.  */
   17015                 :          34 :                 *gtask_clauses_ptr
   17016                 :          34 :                   = build_omp_clause (OMP_CLAUSE_LOCATION (c),
   17017                 :             :                                       OMP_CLAUSE_FIRSTPRIVATE);
   17018                 :          34 :                 OMP_CLAUSE_DECL (*gtask_clauses_ptr)
   17019                 :          34 :                   = OMP_CLAUSE_ALLOCATE_ALLOCATOR (c);
   17020                 :          34 :                 gtask_clauses_ptr = &OMP_CLAUSE_CHAIN (*gtask_clauses_ptr);
   17021                 :             :               }
   17022                 :          62 :             if (lastprivate_uids
   17023                 :          97 :                 && bitmap_bit_p (lastprivate_uids,
   17024                 :          35 :                                  DECL_UID (OMP_CLAUSE_DECL (c))))
   17025                 :             :               {
   17026                 :          17 :                 *gfor_clauses_ptr = c;
   17027                 :          17 :                 gfor_clauses_ptr = &OMP_CLAUSE_CHAIN (c);
   17028                 :          17 :                 *gtask_clauses_ptr = copy_node (c);
   17029                 :          17 :                 gtask_clauses_ptr = &OMP_CLAUSE_CHAIN (*gtask_clauses_ptr);
   17030                 :             :               }
   17031                 :             :             else
   17032                 :             :               {
   17033                 :          45 :                 *gtask_clauses_ptr = c;
   17034                 :          45 :                 gtask_clauses_ptr = &OMP_CLAUSE_CHAIN (c);
   17035                 :             :               }
   17036                 :             :             break;
   17037                 :           0 :           default:
   17038                 :           0 :             gcc_unreachable ();
   17039                 :             :           }
   17040                 :        1599 :       *gfor_clauses_ptr = NULL_TREE;
   17041                 :        1599 :       *gtask_clauses_ptr = NULL_TREE;
   17042                 :        1599 :       *gforo_clauses_ptr = NULL_TREE;
   17043                 :        1599 :       BITMAP_FREE (lastprivate_uids);
   17044                 :        1599 :       gimple_set_location (gfor, input_location);
   17045                 :        1599 :       g = gimple_build_bind (NULL_TREE, gfor, NULL_TREE);
   17046                 :        1599 :       g = gimple_build_omp_task (g, task_clauses, NULL_TREE, NULL_TREE,
   17047                 :             :                                  NULL_TREE, NULL_TREE, NULL_TREE);
   17048                 :        1599 :       gimple_set_location (g, input_location);
   17049                 :        1599 :       gimple_omp_task_set_taskloop_p (g, true);
   17050                 :        1599 :       g = gimple_build_bind (NULL_TREE, g, NULL_TREE);
   17051                 :        1599 :       gomp_for *gforo
   17052                 :        1599 :         = gimple_build_omp_for (g, GF_OMP_FOR_KIND_TASKLOOP, outer_for_clauses,
   17053                 :             :                                 gimple_omp_for_collapse (gfor),
   17054                 :             :                                 gimple_omp_for_pre_body (gfor));
   17055                 :        1599 :       gimple_omp_for_set_pre_body (gfor, NULL);
   17056                 :        1599 :       gimple_omp_for_set_combined_p (gforo, true);
   17057                 :        1599 :       gimple_omp_for_set_combined_into_p (gfor, true);
   17058                 :        3484 :       for (i = 0; i < (int) gimple_omp_for_collapse (gfor); i++)
   17059                 :             :         {
   17060                 :        1885 :           tree type = TREE_TYPE (gimple_omp_for_index (gfor, i));
   17061                 :        1885 :           tree v = create_tmp_var (type);
   17062                 :        1885 :           gimple_omp_for_set_index (gforo, i, v);
   17063                 :        1885 :           t = unshare_expr (gimple_omp_for_initial (gfor, i));
   17064                 :        1885 :           gimple_omp_for_set_initial (gforo, i, t);
   17065                 :        1885 :           gimple_omp_for_set_cond (gforo, i,
   17066                 :             :                                    gimple_omp_for_cond (gfor, i));
   17067                 :        1885 :           t = unshare_expr (gimple_omp_for_final (gfor, i));
   17068                 :        1885 :           gimple_omp_for_set_final (gforo, i, t);
   17069                 :        1885 :           t = unshare_expr (gimple_omp_for_incr (gfor, i));
   17070                 :        1885 :           gcc_assert (TREE_OPERAND (t, 0) == gimple_omp_for_index (gfor, i));
   17071                 :        1885 :           TREE_OPERAND (t, 0) = v;
   17072                 :        1885 :           gimple_omp_for_set_incr (gforo, i, t);
   17073                 :        1885 :           t = build_omp_clause (input_location, OMP_CLAUSE_PRIVATE);
   17074                 :        1885 :           OMP_CLAUSE_DECL (t) = v;
   17075                 :        1885 :           OMP_CLAUSE_CHAIN (t) = gimple_omp_for_clauses (gforo);
   17076                 :        1885 :           gimple_omp_for_set_clauses (gforo, t);
   17077                 :        1885 :           if (OMP_FOR_NON_RECTANGULAR (for_stmt))
   17078                 :             :             {
   17079                 :          90 :               tree *p1 = NULL, *p2 = NULL;
   17080                 :          90 :               t = gimple_omp_for_initial (gforo, i);
   17081                 :          90 :               if (TREE_CODE (t) == TREE_VEC)
   17082                 :          34 :                 p1 = &TREE_VEC_ELT (t, 0);
   17083                 :          90 :               t = gimple_omp_for_final (gforo, i);
   17084                 :          90 :               if (TREE_CODE (t) == TREE_VEC)
   17085                 :             :                 {
   17086                 :          31 :                   if (p1)
   17087                 :          23 :                     p2 = &TREE_VEC_ELT (t, 0);
   17088                 :             :                   else
   17089                 :           8 :                     p1 = &TREE_VEC_ELT (t, 0);
   17090                 :             :                 }
   17091                 :          90 :               if (p1)
   17092                 :             :                 {
   17093                 :             :                   int j;
   17094                 :          58 :                   for (j = 0; j < i; j++)
   17095                 :          58 :                     if (*p1 == gimple_omp_for_index (gfor, j))
   17096                 :             :                       {
   17097                 :          42 :                         *p1 = gimple_omp_for_index (gforo, j);
   17098                 :          42 :                         if (p2)
   17099                 :          23 :                           *p2 = *p1;
   17100                 :             :                         break;
   17101                 :             :                       }
   17102                 :          42 :                   gcc_assert (j < i);
   17103                 :             :                 }
   17104                 :             :             }
   17105                 :             :         }
   17106                 :        1599 :       gimplify_seq_add_stmt (pre_p, gforo);
   17107                 :             :     }
   17108                 :             :   else
   17109                 :       49591 :     gimplify_seq_add_stmt (pre_p, gfor);
   17110                 :             : 
   17111                 :       51190 :   if (TREE_CODE (orig_for_stmt) == OMP_FOR)
   17112                 :             :     {
   17113                 :       18152 :       struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp;
   17114                 :       18152 :       unsigned lastprivate_conditional = 0;
   17115                 :       18152 :       while (ctx
   17116                 :       18188 :              && (ctx->region_type == ORT_TARGET_DATA
   17117                 :       14175 :                  || ctx->region_type == ORT_TASKGROUP))
   17118                 :          36 :         ctx = ctx->outer_context;
   17119                 :       18152 :       if (ctx && (ctx->region_type & ORT_PARALLEL) != 0)
   17120                 :       13915 :         for (tree c = gimple_omp_for_clauses (gfor);
   17121                 :       63104 :              c; c = OMP_CLAUSE_CHAIN (c))
   17122                 :       49189 :           if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
   17123                 :       49189 :               && OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c))
   17124                 :         158 :             ++lastprivate_conditional;
   17125                 :       13915 :       if (lastprivate_conditional)
   17126                 :             :         {
   17127                 :         118 :           struct omp_for_data fd;
   17128                 :         118 :           omp_extract_for_data (gfor, &fd, NULL);
   17129                 :         118 :           tree type = build_array_type_nelts (unsigned_type_for (fd.iter_type),
   17130                 :             :                                               lastprivate_conditional);
   17131                 :         118 :           tree var = create_tmp_var_raw (type);
   17132                 :         118 :           tree c = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE__CONDTEMP_);
   17133                 :         118 :           OMP_CLAUSE_DECL (c) = var;
   17134                 :         118 :           OMP_CLAUSE_CHAIN (c) = gimple_omp_for_clauses (gfor);
   17135                 :         118 :           gimple_omp_for_set_clauses (gfor, c);
   17136                 :         118 :           omp_add_variable (ctx, var, GOVD_CONDTEMP | GOVD_SEEN);
   17137                 :             :         }
   17138                 :             :     }
   17139                 :       33038 :   else if (TREE_CODE (orig_for_stmt) == OMP_SIMD)
   17140                 :             :     {
   17141                 :       10656 :       unsigned lastprivate_conditional = 0;
   17142                 :       49105 :       for (tree c = gimple_omp_for_clauses (gfor); c; c = OMP_CLAUSE_CHAIN (c))
   17143                 :       38449 :         if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
   17144                 :       38449 :             && OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c))
   17145                 :         119 :           ++lastprivate_conditional;
   17146                 :       10656 :       if (lastprivate_conditional)
   17147                 :             :         {
   17148                 :          91 :           struct omp_for_data fd;
   17149                 :          91 :           omp_extract_for_data (gfor, &fd, NULL);
   17150                 :          91 :           tree type = unsigned_type_for (fd.iter_type);
   17151                 :         301 :           while (lastprivate_conditional--)
   17152                 :             :             {
   17153                 :         119 :               tree c = build_omp_clause (UNKNOWN_LOCATION,
   17154                 :             :                                          OMP_CLAUSE__CONDTEMP_);
   17155                 :         119 :               OMP_CLAUSE_DECL (c) = create_tmp_var (type);
   17156                 :         119 :               OMP_CLAUSE_CHAIN (c) = gimple_omp_for_clauses (gfor);
   17157                 :         119 :               gimple_omp_for_set_clauses (gfor, c);
   17158                 :             :             }
   17159                 :             :         }
   17160                 :             :     }
   17161                 :             : 
   17162                 :       51190 :   if (ret != GS_ALL_DONE)
   17163                 :             :     return GS_ERROR;
   17164                 :       51190 :   *expr_p = NULL_TREE;
   17165                 :       51190 :   return GS_ALL_DONE;
   17166                 :             : }
   17167                 :             : 
   17168                 :             : /* Helper for gimplify_omp_loop, called through walk_tree.  */
   17169                 :             : 
   17170                 :             : static tree
   17171                 :         294 : note_no_context_vars (tree *tp, int *, void *data)
   17172                 :             : {
   17173                 :         294 :   if (VAR_P (*tp)
   17174                 :          56 :       && DECL_CONTEXT (*tp) == NULL_TREE
   17175                 :         309 :       && !is_global_var (*tp))
   17176                 :             :     {
   17177                 :          15 :       vec<tree> *d = (vec<tree> *) data;
   17178                 :          15 :       d->safe_push (*tp);
   17179                 :          15 :       DECL_CONTEXT (*tp) = current_function_decl;
   17180                 :             :     }
   17181                 :         294 :   return NULL_TREE;
   17182                 :             : }
   17183                 :             : 
   17184                 :             : /* Gimplify the gross structure of an OMP_LOOP statement.  */
   17185                 :             : 
   17186                 :             : static enum gimplify_status
   17187                 :        1057 : gimplify_omp_loop (tree *expr_p, gimple_seq *pre_p)
   17188                 :             : {
   17189                 :        1057 :   tree for_stmt = *expr_p;
   17190                 :        1057 :   tree clauses = OMP_FOR_CLAUSES (for_stmt);
   17191                 :        1057 :   struct gimplify_omp_ctx *octx = gimplify_omp_ctxp;
   17192                 :        1057 :   enum omp_clause_bind_kind kind = OMP_CLAUSE_BIND_THREAD;
   17193                 :        1057 :   int i;
   17194                 :             : 
   17195                 :        1057 :   omp_maybe_apply_loop_xforms (expr_p, NULL_TREE);
   17196                 :        1057 :   if (*expr_p != for_stmt)
   17197                 :             :     return GS_OK;
   17198                 :             : 
   17199                 :             :   /* If order is not present, the behavior is as if order(concurrent)
   17200                 :             :      appeared.  */
   17201                 :        1057 :   tree order = omp_find_clause (clauses, OMP_CLAUSE_ORDER);
   17202                 :        1057 :   if (order == NULL_TREE)
   17203                 :             :     {
   17204                 :         804 :       order = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE_ORDER);
   17205                 :         804 :       OMP_CLAUSE_CHAIN (order) = clauses;
   17206                 :         804 :       OMP_FOR_CLAUSES (for_stmt) = clauses = order;
   17207                 :             :     }
   17208                 :             : 
   17209                 :        1057 :   tree bind = omp_find_clause (clauses, OMP_CLAUSE_BIND);
   17210                 :        1057 :   if (bind == NULL_TREE)
   17211                 :             :     {
   17212                 :         579 :       if (!flag_openmp) /* flag_openmp_simd */
   17213                 :             :         ;
   17214                 :         562 :       else if (octx && (octx->region_type & ORT_TEAMS) != 0)
   17215                 :             :         kind = OMP_CLAUSE_BIND_TEAMS;
   17216                 :         337 :       else if (octx && (octx->region_type & ORT_PARALLEL) != 0)
   17217                 :             :         kind = OMP_CLAUSE_BIND_PARALLEL;
   17218                 :             :       else
   17219                 :             :         {
   17220                 :         187 :           for (; octx; octx = octx->outer_context)
   17221                 :             :             {
   17222                 :          79 :               if ((octx->region_type & ORT_ACC) != 0
   17223                 :          79 :                   || octx->region_type == ORT_NONE
   17224                 :          79 :                   || octx->region_type == ORT_IMPLICIT_TARGET)
   17225                 :           0 :                 continue;
   17226                 :             :               break;
   17227                 :             :             }
   17228                 :         187 :           if (octx == NULL && !in_omp_construct)
   17229                 :           4 :             error_at (EXPR_LOCATION (for_stmt),
   17230                 :             :                       "%<bind%> clause not specified on a %<loop%> "
   17231                 :             :                       "construct not nested inside another OpenMP construct");
   17232                 :             :         }
   17233                 :         579 :       bind = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE_BIND);
   17234                 :         579 :       OMP_CLAUSE_CHAIN (bind) = clauses;
   17235                 :         579 :       OMP_CLAUSE_BIND_KIND (bind) = kind;
   17236                 :         579 :       OMP_FOR_CLAUSES (for_stmt) = bind;
   17237                 :             :     }
   17238                 :             :   else
   17239                 :         478 :     switch (OMP_CLAUSE_BIND_KIND (bind))
   17240                 :             :       {
   17241                 :             :       case OMP_CLAUSE_BIND_THREAD:
   17242                 :             :         break;
   17243                 :         166 :       case OMP_CLAUSE_BIND_PARALLEL:
   17244                 :         166 :         if (!flag_openmp) /* flag_openmp_simd */
   17245                 :             :           {
   17246                 :           0 :             OMP_CLAUSE_BIND_KIND (bind) = OMP_CLAUSE_BIND_THREAD;
   17247                 :           0 :             break;
   17248                 :             :           }
   17249                 :         240 :         for (; octx; octx = octx->outer_context)
   17250                 :          78 :           if (octx->region_type == ORT_SIMD
   17251                 :          78 :               && omp_find_clause (octx->clauses, OMP_CLAUSE_BIND) == NULL_TREE)
   17252                 :             :             {
   17253                 :           4 :               error_at (EXPR_LOCATION (for_stmt),
   17254                 :             :                         "%<bind(parallel)%> on a %<loop%> construct nested "
   17255                 :             :                         "inside %<simd%> construct");
   17256                 :           4 :               OMP_CLAUSE_BIND_KIND (bind) = OMP_CLAUSE_BIND_THREAD;
   17257                 :           4 :               break;
   17258                 :             :             }
   17259                 :             :         kind = OMP_CLAUSE_BIND_PARALLEL;
   17260                 :             :         break;
   17261                 :         158 :       case OMP_CLAUSE_BIND_TEAMS:
   17262                 :         158 :         if (!flag_openmp) /* flag_openmp_simd */
   17263                 :             :           {
   17264                 :           0 :             OMP_CLAUSE_BIND_KIND (bind) = OMP_CLAUSE_BIND_THREAD;
   17265                 :           0 :             break;
   17266                 :             :           }
   17267                 :         158 :         if ((octx
   17268                 :         128 :              && octx->region_type != ORT_IMPLICIT_TARGET
   17269                 :         111 :              && octx->region_type != ORT_NONE
   17270                 :         111 :              && (octx->region_type & ORT_TEAMS) == 0)
   17271                 :         106 :             || in_omp_construct)
   17272                 :             :           {
   17273                 :          64 :             error_at (EXPR_LOCATION (for_stmt),
   17274                 :             :                       "%<bind(teams)%> on a %<loop%> region not strictly "
   17275                 :             :                       "nested inside of a %<teams%> region");
   17276                 :          64 :             OMP_CLAUSE_BIND_KIND (bind) = OMP_CLAUSE_BIND_THREAD;
   17277                 :          64 :             break;
   17278                 :             :           }
   17279                 :             :         kind = OMP_CLAUSE_BIND_TEAMS;
   17280                 :             :         break;
   17281                 :           0 :       default:
   17282                 :           0 :         gcc_unreachable ();
   17283                 :             :       }
   17284                 :             : 
   17285                 :        4268 :   for (tree *pc = &OMP_FOR_CLAUSES (for_stmt); *pc; )
   17286                 :        3211 :     switch (OMP_CLAUSE_CODE (*pc))
   17287                 :             :       {
   17288                 :         343 :       case OMP_CLAUSE_REDUCTION:
   17289                 :         343 :         if (OMP_CLAUSE_REDUCTION_INSCAN (*pc))
   17290                 :             :           {
   17291                 :           4 :             error_at (OMP_CLAUSE_LOCATION (*pc),
   17292                 :             :                       "%<inscan%> %<reduction%> clause on "
   17293                 :             :                       "%qs construct", "loop");
   17294                 :           4 :             OMP_CLAUSE_REDUCTION_INSCAN (*pc) = 0;
   17295                 :             :           }
   17296                 :         343 :         if (OMP_CLAUSE_REDUCTION_TASK (*pc))
   17297                 :             :           {
   17298                 :           8 :             error_at (OMP_CLAUSE_LOCATION (*pc),
   17299                 :             :                       "invalid %<task%> reduction modifier on construct "
   17300                 :             :                       "other than %<parallel%>, %qs or %<sections%>",
   17301                 :           4 :                       lang_GNU_Fortran () ? "do" : "for");
   17302                 :           4 :             OMP_CLAUSE_REDUCTION_TASK (*pc) = 0;
   17303                 :             :           }
   17304                 :         343 :         pc = &OMP_CLAUSE_CHAIN (*pc);
   17305                 :         343 :         break;
   17306                 :             :       case OMP_CLAUSE_LASTPRIVATE:
   17307                 :         293 :         for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)); i++)
   17308                 :             :           {
   17309                 :         289 :             tree t = TREE_VEC_ELT (OMP_FOR_INIT (for_stmt), i);
   17310                 :         289 :             gcc_assert (TREE_CODE (t) == MODIFY_EXPR);
   17311                 :         289 :             if (OMP_CLAUSE_DECL (*pc) == TREE_OPERAND (t, 0))
   17312                 :             :               break;
   17313                 :          26 :             if (OMP_FOR_ORIG_DECLS (for_stmt)
   17314                 :          25 :                 && TREE_CODE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (for_stmt),
   17315                 :             :                                             i)) == TREE_LIST
   17316                 :          48 :                 && TREE_PURPOSE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (for_stmt),
   17317                 :             :                                                i)))
   17318                 :             :               {
   17319                 :          22 :                 tree orig = TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (for_stmt), i);
   17320                 :          22 :                 if (OMP_CLAUSE_DECL (*pc) == TREE_PURPOSE (orig))
   17321                 :             :                   break;
   17322                 :             :               }
   17323                 :             :           }
   17324                 :         289 :         if (i == TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)))
   17325                 :             :           {
   17326                 :           4 :             error_at (OMP_CLAUSE_LOCATION (*pc),
   17327                 :             :                       "%<lastprivate%> clause on a %<loop%> construct refers "
   17328                 :             :                       "to a variable %qD which is not the loop iterator",
   17329                 :           4 :                       OMP_CLAUSE_DECL (*pc));
   17330                 :           4 :             *pc = OMP_CLAUSE_CHAIN (*pc);
   17331                 :           4 :             break;
   17332                 :             :           }
   17333                 :         285 :         pc = &OMP_CLAUSE_CHAIN (*pc);
   17334                 :         285 :         break;
   17335                 :        2579 :       default:
   17336                 :        2579 :         pc = &OMP_CLAUSE_CHAIN (*pc);
   17337                 :        2579 :         break;
   17338                 :             :     }
   17339                 :             : 
   17340                 :        1057 :   TREE_SET_CODE (for_stmt, OMP_SIMD);
   17341                 :             : 
   17342                 :        1057 :   int last;
   17343                 :        1057 :   switch (kind)
   17344                 :             :     {
   17345                 :             :     case OMP_CLAUSE_BIND_THREAD: last = 0; break;
   17346                 :         424 :     case OMP_CLAUSE_BIND_PARALLEL: last = 1; break;
   17347                 :         211 :     case OMP_CLAUSE_BIND_TEAMS: last = 2; break;
   17348                 :             :     }
   17349                 :        1903 :   for (int pass = 1; pass <= last; pass++)
   17350                 :             :     {
   17351                 :         846 :       if (pass == 2)
   17352                 :             :         {
   17353                 :         211 :           tree bind = build3 (BIND_EXPR, void_type_node, NULL, NULL,
   17354                 :             :                               make_node (BLOCK));
   17355                 :         211 :           append_to_statement_list (*expr_p, &BIND_EXPR_BODY (bind));
   17356                 :         211 :           *expr_p = make_node (OMP_PARALLEL);
   17357                 :         211 :           TREE_TYPE (*expr_p) = void_type_node;
   17358                 :         211 :           OMP_PARALLEL_BODY (*expr_p) = bind;
   17359                 :         211 :           OMP_PARALLEL_COMBINED (*expr_p) = 1;
   17360                 :         211 :           SET_EXPR_LOCATION (*expr_p, EXPR_LOCATION (for_stmt));
   17361                 :         211 :           tree *pc = &OMP_PARALLEL_CLAUSES (*expr_p);
   17362                 :         425 :           for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)); i++)
   17363                 :         214 :             if (OMP_FOR_ORIG_DECLS (for_stmt)
   17364                 :         214 :                 && (TREE_CODE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (for_stmt), i))
   17365                 :             :                     == TREE_LIST))
   17366                 :             :               {
   17367                 :          16 :                 tree elt = TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (for_stmt), i);
   17368                 :          16 :                 if (TREE_PURPOSE (elt) && TREE_VALUE (elt))
   17369                 :             :                   {
   17370                 :          13 :                     *pc = build_omp_clause (UNKNOWN_LOCATION,
   17371                 :             :                                             OMP_CLAUSE_FIRSTPRIVATE);
   17372                 :          13 :                     OMP_CLAUSE_DECL (*pc) = TREE_VALUE (elt);
   17373                 :          13 :                     pc = &OMP_CLAUSE_CHAIN (*pc);
   17374                 :             :                   }
   17375                 :             :               }
   17376                 :             :         }
   17377                 :         846 :       tree t = make_node (pass == 2 ? OMP_DISTRIBUTE : OMP_FOR);
   17378                 :         846 :       tree *pc = &OMP_FOR_CLAUSES (t);
   17379                 :         846 :       TREE_TYPE (t) = void_type_node;
   17380                 :         846 :       OMP_FOR_BODY (t) = *expr_p;
   17381                 :         846 :       SET_EXPR_LOCATION (t, EXPR_LOCATION (for_stmt));
   17382                 :        3914 :       for (tree c = OMP_FOR_CLAUSES (for_stmt); c; c = OMP_CLAUSE_CHAIN (c))
   17383                 :        3068 :         switch (OMP_CLAUSE_CODE (c))
   17384                 :             :           {
   17385                 :        1958 :           case OMP_CLAUSE_BIND:
   17386                 :        1958 :           case OMP_CLAUSE_ORDER:
   17387                 :        1958 :           case OMP_CLAUSE_COLLAPSE:
   17388                 :        1958 :             *pc = copy_node (c);
   17389                 :        1958 :             pc = &OMP_CLAUSE_CHAIN (*pc);
   17390                 :        1958 :             break;
   17391                 :             :           case OMP_CLAUSE_PRIVATE:
   17392                 :             :           case OMP_CLAUSE_FIRSTPRIVATE:
   17393                 :             :             /* Only needed on innermost.  */
   17394                 :             :             break;
   17395                 :         351 :           case OMP_CLAUSE_LASTPRIVATE:
   17396                 :         351 :             if (OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c) && pass != last)
   17397                 :             :               {
   17398                 :           7 :                 *pc = build_omp_clause (OMP_CLAUSE_LOCATION (c),
   17399                 :             :                                         OMP_CLAUSE_FIRSTPRIVATE);
   17400                 :           7 :                 OMP_CLAUSE_DECL (*pc) = OMP_CLAUSE_DECL (c);
   17401                 :           7 :                 lang_hooks.decls.omp_finish_clause (*pc, NULL, false);
   17402                 :           7 :                 pc = &OMP_CLAUSE_CHAIN (*pc);
   17403                 :             :               }
   17404                 :         351 :             *pc = copy_node (c);
   17405                 :         351 :             OMP_CLAUSE_LASTPRIVATE_STMT (*pc) = NULL_TREE;
   17406                 :         351 :             TREE_TYPE (*pc) = unshare_expr (TREE_TYPE (c));
   17407                 :         351 :             if (OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c))
   17408                 :             :               {
   17409                 :          22 :                 if (pass != last)
   17410                 :           7 :                   OMP_CLAUSE_LASTPRIVATE_FIRSTPRIVATE (*pc) = 1;
   17411                 :             :                 else
   17412                 :          15 :                   lang_hooks.decls.omp_finish_clause (*pc, NULL, false);
   17413                 :          22 :                 OMP_CLAUSE_LASTPRIVATE_LOOP_IV (*pc) = 0;
   17414                 :             :               }
   17415                 :         351 :             pc = &OMP_CLAUSE_CHAIN (*pc);
   17416                 :         351 :             break;
   17417                 :         463 :           case OMP_CLAUSE_REDUCTION:
   17418                 :         463 :             *pc = copy_node (c);
   17419                 :         463 :             OMP_CLAUSE_DECL (*pc) = unshare_expr (OMP_CLAUSE_DECL (c));
   17420                 :         463 :             TREE_TYPE (*pc) = unshare_expr (TREE_TYPE (c));
   17421                 :         463 :             if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (*pc))
   17422                 :             :               {
   17423                 :          15 :                 auto_vec<tree> no_context_vars;
   17424                 :          15 :                 int walk_subtrees = 0;
   17425                 :          15 :                 note_no_context_vars (&OMP_CLAUSE_REDUCTION_PLACEHOLDER (c),
   17426                 :             :                                       &walk_subtrees, &no_context_vars);
   17427                 :          15 :                 if (tree p = OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c))
   17428                 :           0 :                   note_no_context_vars (&p, &walk_subtrees, &no_context_vars);
   17429                 :          15 :                 walk_tree_without_duplicates (&OMP_CLAUSE_REDUCTION_INIT (c),
   17430                 :             :                                               note_no_context_vars,
   17431                 :             :                                               &no_context_vars);
   17432                 :          15 :                 walk_tree_without_duplicates (&OMP_CLAUSE_REDUCTION_MERGE (c),
   17433                 :             :                                               note_no_context_vars,
   17434                 :             :                                               &no_context_vars);
   17435                 :             : 
   17436                 :          15 :                 OMP_CLAUSE_REDUCTION_PLACEHOLDER (*pc)
   17437                 :          30 :                   = copy_node (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c));
   17438                 :          15 :                 if (OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (*pc))
   17439                 :           0 :                   OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (*pc)
   17440                 :           0 :                     = copy_node (OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c));
   17441                 :             : 
   17442                 :          15 :                 hash_map<tree, tree> decl_map;
   17443                 :          15 :                 decl_map.put (OMP_CLAUSE_DECL (c), OMP_CLAUSE_DECL (c));
   17444                 :          15 :                 decl_map.put (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c),
   17445                 :          15 :                               OMP_CLAUSE_REDUCTION_PLACEHOLDER (*pc));
   17446                 :          15 :                 if (OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (*pc))
   17447                 :           0 :                   decl_map.put (OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c),
   17448                 :           0 :                                 OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (*pc));
   17449                 :             : 
   17450                 :          15 :                 copy_body_data id;
   17451                 :          15 :                 memset (&id, 0, sizeof (id));
   17452                 :          15 :                 id.src_fn = current_function_decl;
   17453                 :          15 :                 id.dst_fn = current_function_decl;
   17454                 :          15 :                 id.src_cfun = cfun;
   17455                 :          15 :                 id.decl_map = &decl_map;
   17456                 :          15 :                 id.copy_decl = copy_decl_no_change;
   17457                 :          15 :                 id.transform_call_graph_edges = CB_CGE_DUPLICATE;
   17458                 :          15 :                 id.transform_new_cfg = true;
   17459                 :          15 :                 id.transform_return_to_modify = false;
   17460                 :          15 :                 id.eh_lp_nr = 0;
   17461                 :          15 :                 walk_tree (&OMP_CLAUSE_REDUCTION_INIT (*pc), copy_tree_body_r,
   17462                 :             :                            &id, NULL);
   17463                 :          15 :                 walk_tree (&OMP_CLAUSE_REDUCTION_MERGE (*pc), copy_tree_body_r,
   17464                 :             :                            &id, NULL);
   17465                 :             : 
   17466                 :          60 :                 for (tree d : no_context_vars)
   17467                 :             :                   {
   17468                 :          15 :                     DECL_CONTEXT (d) = NULL_TREE;
   17469                 :          15 :                     DECL_CONTEXT (*decl_map.get (d)) = NULL_TREE;
   17470                 :             :                   }
   17471                 :          15 :               }
   17472                 :             :             else
   17473                 :             :               {
   17474                 :         448 :                 OMP_CLAUSE_REDUCTION_INIT (*pc)
   17475                 :         896 :                   = unshare_expr (OMP_CLAUSE_REDUCTION_INIT (c));
   17476                 :         448 :                 OMP_CLAUSE_REDUCTION_MERGE (*pc)
   17477                 :         896 :                   = unshare_expr (OMP_CLAUSE_REDUCTION_MERGE (c));
   17478                 :             :               }
   17479                 :         463 :             pc = &OMP_CLAUSE_CHAIN (*pc);
   17480                 :         463 :             break;
   17481                 :           0 :           default:
   17482                 :           0 :             gcc_unreachable ();
   17483                 :             :           }
   17484                 :         846 :       *pc = NULL_TREE;
   17485                 :         846 :       *expr_p = t;
   17486                 :             :     }
   17487                 :        1057 :   return gimplify_expr (expr_p, pre_p, NULL, is_gimple_stmt, fb_none);
   17488                 :             : }
   17489                 :             : 
   17490                 :             : 
   17491                 :             : /* Helper function of optimize_target_teams, find OMP_TEAMS inside
   17492                 :             :    of OMP_TARGET's body.  */
   17493                 :             : 
   17494                 :             : static tree
   17495                 :       69244 : find_omp_teams (tree *tp, int *walk_subtrees, void *)
   17496                 :             : {
   17497                 :       69244 :   *walk_subtrees = 0;
   17498                 :       69244 :   switch (TREE_CODE (*tp))
   17499                 :             :     {
   17500                 :             :     case OMP_TEAMS:
   17501                 :             :       return *tp;
   17502                 :       21305 :     case BIND_EXPR:
   17503                 :       21305 :     case STATEMENT_LIST:
   17504                 :       21305 :       *walk_subtrees = 1;
   17505                 :       21305 :       break;
   17506                 :             :     default:
   17507                 :             :       break;
   17508                 :             :     }
   17509                 :             :   return NULL_TREE;
   17510                 :             : }
   17511                 :             : 
   17512                 :             : /* Helper function of optimize_target_teams, determine if the expression
   17513                 :             :    can be computed safely before the target construct on the host.  */
   17514                 :             : 
   17515                 :             : static tree
   17516                 :        1311 : computable_teams_clause (tree *tp, int *walk_subtrees, void *)
   17517                 :             : {
   17518                 :        1831 :   splay_tree_node n;
   17519                 :             : 
   17520                 :        1831 :   if (TYPE_P (*tp))
   17521                 :             :     {
   17522                 :           0 :       *walk_subtrees = 0;
   17523                 :           0 :       return NULL_TREE;
   17524                 :             :     }
   17525                 :        1831 :   switch (TREE_CODE (*tp))
   17526                 :             :     {
   17527                 :         990 :     case VAR_DECL:
   17528                 :         990 :     case PARM_DECL:
   17529                 :         990 :     case RESULT_DECL:
   17530                 :         990 :       *walk_subtrees = 0;
   17531                 :         990 :       if (error_operand_p (*tp)
   17532                 :         990 :           || !INTEGRAL_TYPE_P (TREE_TYPE (*tp))
   17533                 :         990 :           || DECL_HAS_VALUE_EXPR_P (*tp)
   17534                 :         990 :           || DECL_THREAD_LOCAL_P (*tp)
   17535                 :         990 :           || TREE_SIDE_EFFECTS (*tp)
   17536                 :        1980 :           || TREE_THIS_VOLATILE (*tp))
   17537                 :           0 :         return *tp;
   17538                 :         990 :       if (is_global_var (*tp)
   17539                 :         990 :           && (lookup_attribute ("omp declare target", DECL_ATTRIBUTES (*tp))
   17540                 :           0 :               || lookup_attribute ("omp declare target link",
   17541                 :           0 :                                    DECL_ATTRIBUTES (*tp))))
   17542                 :          16 :         return *tp;
   17543                 :         974 :       if (VAR_P (*tp)
   17544                 :         668 :           && !DECL_SEEN_IN_BIND_EXPR_P (*tp)
   17545                 :          50 :           && !is_global_var (*tp)
   17546                 :        1024 :           && decl_function_context (*tp) == current_function_decl)
   17547                 :          50 :         return *tp;
   17548                 :        1848 :       n = splay_tree_lookup (gimplify_omp_ctxp->variables,
   17549                 :         924 :                              (splay_tree_key) *tp);
   17550                 :         924 :       if (n == NULL)
   17551                 :             :         {
   17552                 :         292 :           if (gimplify_omp_ctxp->defaultmap[GDMK_SCALAR] & GOVD_FIRSTPRIVATE)
   17553                 :             :             return NULL_TREE;
   17554                 :          24 :           return *tp;
   17555                 :             :         }
   17556                 :         632 :       else if (n->value & GOVD_LOCAL)
   17557                 :           0 :         return *tp;
   17558                 :         632 :       else if (n->value & GOVD_FIRSTPRIVATE)
   17559                 :             :         return NULL_TREE;
   17560                 :         112 :       else if ((n->value & (GOVD_MAP | GOVD_MAP_ALWAYS_TO))
   17561                 :             :                == (GOVD_MAP | GOVD_MAP_ALWAYS_TO))
   17562                 :             :         return NULL_TREE;
   17563                 :          96 :       return *tp;
   17564                 :          76 :     case INTEGER_CST:
   17565                 :          76 :       if (!INTEGRAL_TYPE_P (TREE_TYPE (*tp)))
   17566                 :             :         return *tp;
   17567                 :             :       return NULL_TREE;
   17568                 :         520 :     case TARGET_EXPR:
   17569                 :         520 :       if (TARGET_EXPR_INITIAL (*tp)
   17570                 :         520 :           || TREE_CODE (TARGET_EXPR_SLOT (*tp)) != VAR_DECL)
   17571                 :             :         return *tp;
   17572                 :         520 :       return computable_teams_clause (&TARGET_EXPR_SLOT (*tp),
   17573                 :         520 :                                       walk_subtrees, NULL);
   17574                 :             :     /* Allow some reasonable subset of integral arithmetics.  */
   17575                 :         193 :     case PLUS_EXPR:
   17576                 :         193 :     case MINUS_EXPR:
   17577                 :         193 :     case MULT_EXPR:
   17578                 :         193 :     case TRUNC_DIV_EXPR:
   17579                 :         193 :     case CEIL_DIV_EXPR:
   17580                 :         193 :     case FLOOR_DIV_EXPR:
   17581                 :         193 :     case ROUND_DIV_EXPR:
   17582                 :         193 :     case TRUNC_MOD_EXPR:
   17583                 :         193 :     case CEIL_MOD_EXPR:
   17584                 :         193 :     case FLOOR_MOD_EXPR:
   17585                 :         193 :     case ROUND_MOD_EXPR:
   17586                 :         193 :     case RDIV_EXPR:
   17587                 :         193 :     case EXACT_DIV_EXPR:
   17588                 :         193 :     case MIN_EXPR:
   17589                 :         193 :     case MAX_EXPR:
   17590                 :         193 :     case LSHIFT_EXPR:
   17591                 :         193 :     case RSHIFT_EXPR:
   17592                 :         193 :     case BIT_IOR_EXPR:
   17593                 :         193 :     case BIT_XOR_EXPR:
   17594                 :         193 :     case BIT_AND_EXPR:
   17595                 :         193 :     case NEGATE_EXPR:
   17596                 :         193 :     case ABS_EXPR:
   17597                 :         193 :     case BIT_NOT_EXPR:
   17598                 :         193 :     case NON_LVALUE_EXPR:
   17599                 :         193 :     CASE_CONVERT:
   17600                 :         193 :       if (!INTEGRAL_TYPE_P (TREE_TYPE (*tp)))
   17601                 :             :         return *tp;
   17602                 :             :       return NULL_TREE;
   17603                 :             :     /* And disallow anything else, except for comparisons.  */
   17604                 :          52 :     default:
   17605                 :          52 :       if (COMPARISON_CLASS_P (*tp))
   17606                 :             :         return NULL_TREE;
   17607                 :             :       return *tp;
   17608                 :             :     }
   17609                 :             : }
   17610                 :             : 
   17611                 :             : /* Try to determine if the num_teams and/or thread_limit expressions
   17612                 :             :    can have their values determined already before entering the
   17613                 :             :    target construct.
   17614                 :             :    INTEGER_CSTs trivially are,
   17615                 :             :    integral decls that are firstprivate (explicitly or implicitly)
   17616                 :             :    or explicitly map(always, to:) or map(always, tofrom:) on the target
   17617                 :             :    region too, and expressions involving simple arithmetics on those
   17618                 :             :    too, function calls are not ok, dereferencing something neither etc.
   17619                 :             :    Add NUM_TEAMS and THREAD_LIMIT clauses to the OMP_CLAUSES of
   17620                 :             :    EXPR based on what we find:
   17621                 :             :    0 stands for clause not specified at all, use implementation default
   17622                 :             :    -1 stands for value that can't be determined easily before entering
   17623                 :             :       the target construct.
   17624                 :             :    -2 means that no explicit teams construct was specified
   17625                 :             :    If teams construct is not present at all, use 1 for num_teams
   17626                 :             :    and 0 for thread_limit (only one team is involved, and the thread
   17627                 :             :    limit is implementation defined.  */
   17628                 :             : 
   17629                 :             : static void
   17630                 :       11983 : optimize_target_teams (tree target, gimple_seq *pre_p)
   17631                 :             : {
   17632                 :       11983 :   tree body = OMP_BODY (target);
   17633                 :       11983 :   tree teams = walk_tree (&body, find_omp_teams, NULL, NULL);
   17634                 :       11983 :   tree num_teams_lower = NULL_TREE;
   17635                 :       11983 :   tree num_teams_upper = integer_zero_node;
   17636                 :       11983 :   tree thread_limit = integer_zero_node;
   17637                 :       11983 :   location_t num_teams_loc = EXPR_LOCATION (target);
   17638                 :       11983 :   location_t thread_limit_loc = EXPR_LOCATION (target);
   17639                 :       11983 :   tree c, *p, expr;
   17640                 :       11983 :   struct gimplify_omp_ctx *target_ctx = gimplify_omp_ctxp;
   17641                 :             : 
   17642                 :       11983 :   if (teams == NULL_TREE)
   17643                 :        5915 :     num_teams_upper = build_int_cst (integer_type_node, -2);
   17644                 :             :   else
   17645                 :       10521 :     for (c = OMP_TEAMS_CLAUSES (teams); c; c = OMP_CLAUSE_CHAIN (c))
   17646                 :             :       {
   17647                 :        4453 :         if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NUM_TEAMS)
   17648                 :             :           {
   17649                 :         617 :             p = &num_teams_upper;
   17650                 :         617 :             num_teams_loc = OMP_CLAUSE_LOCATION (c);
   17651                 :         617 :             if (OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c))
   17652                 :             :               {
   17653                 :         148 :                 expr = OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c);
   17654                 :         148 :                 if (TREE_CODE (expr) == INTEGER_CST)
   17655                 :          21 :                   num_teams_lower = expr;
   17656                 :         127 :                 else if (walk_tree (&expr, computable_teams_clause,
   17657                 :             :                                     NULL, NULL))
   17658                 :          19 :                   num_teams_lower = integer_minus_one_node;
   17659                 :             :                 else
   17660                 :             :                   {
   17661                 :         108 :                     num_teams_lower = expr;
   17662                 :         108 :                     gimplify_omp_ctxp = gimplify_omp_ctxp->outer_context;
   17663                 :         108 :                     if (gimplify_expr (&num_teams_lower, pre_p, NULL,
   17664                 :             :                                        is_gimple_val, fb_rvalue, false)
   17665                 :             :                         == GS_ERROR)
   17666                 :             :                       {
   17667                 :           0 :                         gimplify_omp_ctxp = target_ctx;
   17668                 :           0 :                         num_teams_lower = integer_minus_one_node;
   17669                 :             :                       }
   17670                 :             :                     else
   17671                 :             :                       {
   17672                 :         108 :                         gimplify_omp_ctxp = target_ctx;
   17673                 :         108 :                         if (!DECL_P (expr) && TREE_CODE (expr) != TARGET_EXPR)
   17674                 :          28 :                           OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c)
   17675                 :          28 :                             = num_teams_lower;
   17676                 :             :                       }
   17677                 :             :                   }
   17678                 :             :               }
   17679                 :             :           }
   17680                 :        3836 :         else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_THREAD_LIMIT)
   17681                 :             :           {
   17682                 :         471 :             p = &thread_limit;
   17683                 :         471 :             thread_limit_loc = OMP_CLAUSE_LOCATION (c);
   17684                 :             :           }
   17685                 :             :         else
   17686                 :        3365 :           continue;
   17687                 :        1088 :         expr = OMP_CLAUSE_OPERAND (c, 0);
   17688                 :        1088 :         if (TREE_CODE (expr) == INTEGER_CST)
   17689                 :             :           {
   17690                 :         173 :             *p = expr;
   17691                 :         173 :             continue;
   17692                 :             :           }
   17693                 :         915 :         if (walk_tree (&expr, computable_teams_clause, NULL, NULL))
   17694                 :             :           {
   17695                 :         219 :             *p = integer_minus_one_node;
   17696                 :         219 :             continue;
   17697                 :             :           }
   17698                 :         696 :         *p = expr;
   17699                 :         696 :         gimplify_omp_ctxp = gimplify_omp_ctxp->outer_context;
   17700                 :         696 :         if (gimplify_expr (p, pre_p, NULL, is_gimple_val, fb_rvalue, false)
   17701                 :             :             == GS_ERROR)
   17702                 :             :           {
   17703                 :           0 :             gimplify_omp_ctxp = target_ctx;
   17704                 :           0 :             *p = integer_minus_one_node;
   17705                 :           0 :             continue;
   17706                 :             :           }
   17707                 :         696 :         gimplify_omp_ctxp = target_ctx;
   17708                 :         696 :         if (!DECL_P (expr) && TREE_CODE (expr) != TARGET_EXPR)
   17709                 :          48 :           OMP_CLAUSE_OPERAND (c, 0) = *p;
   17710                 :             :       }
   17711                 :       11983 :   if (!omp_find_clause (OMP_TARGET_CLAUSES (target), OMP_CLAUSE_THREAD_LIMIT))
   17712                 :             :     {
   17713                 :       11715 :       c = build_omp_clause (thread_limit_loc, OMP_CLAUSE_THREAD_LIMIT);
   17714                 :       11715 :       OMP_CLAUSE_THREAD_LIMIT_EXPR (c) = thread_limit;
   17715                 :       11715 :       OMP_CLAUSE_CHAIN (c) = OMP_TARGET_CLAUSES (target);
   17716                 :       11715 :       OMP_TARGET_CLAUSES (target) = c;
   17717                 :             :     }
   17718                 :       11983 :   c = build_omp_clause (num_teams_loc, OMP_CLAUSE_NUM_TEAMS);
   17719                 :       11983 :   OMP_CLAUSE_NUM_TEAMS_UPPER_EXPR (c) = num_teams_upper;
   17720                 :       11983 :   OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c) = num_teams_lower;
   17721                 :       11983 :   OMP_CLAUSE_CHAIN (c) = OMP_TARGET_CLAUSES (target);
   17722                 :       11983 :   OMP_TARGET_CLAUSES (target) = c;
   17723                 :       11983 : }
   17724                 :             : 
   17725                 :             : /* Gimplify the gross structure of several OMP constructs.  */
   17726                 :             : 
   17727                 :             : static void
   17728                 :       38265 : gimplify_omp_workshare (tree *expr_p, gimple_seq *pre_p)
   17729                 :             : {
   17730                 :       38265 :   tree expr = *expr_p;
   17731                 :       38265 :   gimple *stmt;
   17732                 :       38265 :   gimple_seq body = NULL;
   17733                 :       38265 :   enum omp_region_type ort;
   17734                 :             : 
   17735                 :       38265 :   switch (TREE_CODE (expr))
   17736                 :             :     {
   17737                 :             :     case OMP_SECTIONS:
   17738                 :             :     case OMP_SINGLE:
   17739                 :             :       ort = ORT_WORKSHARE;
   17740                 :             :       break;
   17741                 :         214 :     case OMP_SCOPE:
   17742                 :         214 :       ort = ORT_TASKGROUP;
   17743                 :         214 :       break;
   17744                 :       11983 :     case OMP_TARGET:
   17745                 :       11983 :       ort = OMP_TARGET_COMBINED (expr) ? ORT_COMBINED_TARGET : ORT_TARGET;
   17746                 :             :       break;
   17747                 :        2564 :     case OACC_KERNELS:
   17748                 :        2564 :       ort = ORT_ACC_KERNELS;
   17749                 :        2564 :       break;
   17750                 :        7894 :     case OACC_PARALLEL:
   17751                 :        7894 :       ort = ORT_ACC_PARALLEL;
   17752                 :        7894 :       break;
   17753                 :        1004 :     case OACC_SERIAL:
   17754                 :        1004 :       ort = ORT_ACC_SERIAL;
   17755                 :        1004 :       break;
   17756                 :        1949 :     case OACC_DATA:
   17757                 :        1949 :       ort = ORT_ACC_DATA;
   17758                 :        1949 :       break;
   17759                 :        1851 :     case OMP_TARGET_DATA:
   17760                 :        1851 :       ort = ORT_TARGET_DATA;
   17761                 :        1851 :       break;
   17762                 :        8779 :     case OMP_TEAMS:
   17763                 :        8779 :       ort = OMP_TEAMS_COMBINED (expr) ? ORT_COMBINED_TEAMS : ORT_TEAMS;
   17764                 :        8779 :       if (gimplify_omp_ctxp == NULL
   17765                 :        6108 :           || gimplify_omp_ctxp->region_type == ORT_IMPLICIT_TARGET)
   17766                 :        2671 :         ort = (enum omp_region_type) (ort | ORT_HOST_TEAMS);
   17767                 :             :       break;
   17768                 :         117 :     case OACC_HOST_DATA:
   17769                 :         117 :       ort = ORT_ACC_HOST_DATA;
   17770                 :         117 :       break;
   17771                 :           0 :     default:
   17772                 :           0 :       gcc_unreachable ();
   17773                 :             :     }
   17774                 :             : 
   17775                 :       38265 :   bool save_in_omp_construct = in_omp_construct;
   17776                 :       38265 :   if ((ort & ORT_ACC) == 0)
   17777                 :       24737 :     in_omp_construct = false;
   17778                 :       38265 :   gimplify_scan_omp_clauses (&OMP_CLAUSES (expr), pre_p, ort,
   17779                 :             :                              TREE_CODE (expr));
   17780                 :       38265 :   if (TREE_CODE (expr) == OMP_TARGET)
   17781                 :       11983 :     optimize_target_teams (expr, pre_p);
   17782                 :       38265 :   if ((ort & (ORT_TARGET | ORT_TARGET_DATA)) != 0
   17783                 :       10903 :       || (ort & ORT_HOST_TEAMS) == ORT_HOST_TEAMS)
   17784                 :             :     {
   17785                 :       30033 :       push_gimplify_context ();
   17786                 :       30033 :       gimple *g = gimplify_and_return_first (OMP_BODY (expr), &body);
   17787                 :       30033 :       if (gimple_code (g) == GIMPLE_BIND)
   17788                 :       30033 :         pop_gimplify_context (g);
   17789                 :             :       else
   17790                 :           0 :         pop_gimplify_context (NULL);
   17791                 :       30033 :       if ((ort & ORT_TARGET_DATA) != 0)
   17792                 :             :         {
   17793                 :        3917 :           enum built_in_function end_ix;
   17794                 :        3917 :           switch (TREE_CODE (expr))
   17795                 :             :             {
   17796                 :             :             case OACC_DATA:
   17797                 :             :             case OACC_HOST_DATA:
   17798                 :             :               end_ix = BUILT_IN_GOACC_DATA_END;
   17799                 :             :               break;
   17800                 :        1851 :             case OMP_TARGET_DATA:
   17801                 :        1851 :               end_ix = BUILT_IN_GOMP_TARGET_END_DATA;
   17802                 :        1851 :               break;
   17803                 :           0 :             default:
   17804                 :           0 :               gcc_unreachable ();
   17805                 :             :             }
   17806                 :        3917 :           tree fn = builtin_decl_explicit (end_ix);
   17807                 :        3917 :           g = gimple_build_call (fn, 0);
   17808                 :        3917 :           gimple_seq cleanup = NULL;
   17809                 :        3917 :           gimple_seq_add_stmt (&cleanup, g);
   17810                 :        3917 :           g = gimple_build_try (body, cleanup, GIMPLE_TRY_FINALLY);
   17811                 :        3917 :           body = NULL;
   17812                 :        3917 :           gimple_seq_add_stmt (&body, g);
   17813                 :             :         }
   17814                 :             :     }
   17815                 :             :   else
   17816                 :        8232 :     gimplify_and_add (OMP_BODY (expr), &body);
   17817                 :       38265 :   gimplify_adjust_omp_clauses (pre_p, body, &OMP_CLAUSES (expr),
   17818                 :       38265 :                                TREE_CODE (expr));
   17819                 :       38265 :   in_omp_construct = save_in_omp_construct;
   17820                 :             : 
   17821                 :       38265 :   switch (TREE_CODE (expr))
   17822                 :             :     {
   17823                 :        1949 :     case OACC_DATA:
   17824                 :        3898 :       stmt = gimple_build_omp_target (body, GF_OMP_TARGET_KIND_OACC_DATA,
   17825                 :        1949 :                                       OMP_CLAUSES (expr));
   17826                 :        1949 :       break;
   17827                 :         117 :     case OACC_HOST_DATA:
   17828                 :         117 :       if (omp_find_clause (OMP_CLAUSES (expr), OMP_CLAUSE_IF_PRESENT))
   17829                 :             :         {
   17830                 :         128 :           for (tree c = OMP_CLAUSES (expr); c; c = OMP_CLAUSE_CHAIN (c))
   17831                 :          95 :             if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR)
   17832                 :          57 :               OMP_CLAUSE_USE_DEVICE_PTR_IF_PRESENT (c) = 1;
   17833                 :             :         }
   17834                 :             : 
   17835                 :         234 :       stmt = gimple_build_omp_target (body, GF_OMP_TARGET_KIND_OACC_HOST_DATA,
   17836                 :         117 :                                       OMP_CLAUSES (expr));
   17837                 :         117 :       break;
   17838                 :        2564 :     case OACC_KERNELS:
   17839                 :        5128 :       stmt = gimple_build_omp_target (body, GF_OMP_TARGET_KIND_OACC_KERNELS,
   17840                 :        2564 :                                       OMP_CLAUSES (expr));
   17841                 :        2564 :       break;
   17842                 :        7894 :     case OACC_PARALLEL:
   17843                 :       15788 :       stmt = gimple_build_omp_target (body, GF_OMP_TARGET_KIND_OACC_PARALLEL,
   17844                 :        7894 :                                       OMP_CLAUSES (expr));
   17845                 :        7894 :       break;
   17846                 :        1004 :     case OACC_SERIAL:
   17847                 :        2008 :       stmt = gimple_build_omp_target (body, GF_OMP_TARGET_KIND_OACC_SERIAL,
   17848                 :        1004 :                                       OMP_CLAUSES (expr));
   17849                 :        1004 :       break;
   17850                 :         626 :     case OMP_SECTIONS:
   17851                 :         626 :       stmt = gimple_build_omp_sections (body, OMP_CLAUSES (expr));
   17852                 :         626 :       break;
   17853                 :        1284 :     case OMP_SINGLE:
   17854                 :        1284 :       stmt = gimple_build_omp_single (body, OMP_CLAUSES (expr));
   17855                 :        1284 :       break;
   17856                 :         214 :     case OMP_SCOPE:
   17857                 :         214 :       stmt = gimple_build_omp_scope (body, OMP_CLAUSES (expr));
   17858                 :         214 :       break;
   17859                 :       11983 :     case OMP_TARGET:
   17860                 :       23966 :       stmt = gimple_build_omp_target (body, GF_OMP_TARGET_KIND_REGION,
   17861                 :       11983 :                                       OMP_CLAUSES (expr));
   17862                 :       11983 :       break;
   17863                 :        1851 :     case OMP_TARGET_DATA:
   17864                 :             :       /* Put use_device_{ptr,addr} clauses last, as map clauses are supposed
   17865                 :             :          to be evaluated before the use_device_{ptr,addr} clauses if they
   17866                 :             :          refer to the same variables.  */
   17867                 :        1851 :       {
   17868                 :        1851 :         tree use_device_clauses;
   17869                 :        1851 :         tree *pc, *uc = &use_device_clauses;
   17870                 :        9888 :         for (pc = &OMP_CLAUSES (expr); *pc; )
   17871                 :        8037 :           if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_USE_DEVICE_PTR
   17872                 :        8037 :               || OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_USE_DEVICE_ADDR)
   17873                 :             :             {
   17874                 :        1959 :               *uc = *pc;
   17875                 :        1959 :               *pc = OMP_CLAUSE_CHAIN (*pc);
   17876                 :        1959 :               uc = &OMP_CLAUSE_CHAIN (*uc);
   17877                 :             :             }
   17878                 :             :           else
   17879                 :        6078 :             pc = &OMP_CLAUSE_CHAIN (*pc);
   17880                 :        1851 :         *uc = NULL_TREE;
   17881                 :        1851 :         *pc = use_device_clauses;
   17882                 :        1851 :         stmt = gimple_build_omp_target (body, GF_OMP_TARGET_KIND_DATA,
   17883                 :        1851 :                                         OMP_CLAUSES (expr));
   17884                 :             :       }
   17885                 :        1851 :       break;
   17886                 :        8779 :     case OMP_TEAMS:
   17887                 :        8779 :       stmt = gimple_build_omp_teams (body, OMP_CLAUSES (expr));
   17888                 :        8779 :       if ((ort & ORT_HOST_TEAMS) == ORT_HOST_TEAMS)
   17889                 :        2671 :         gimple_omp_teams_set_host (as_a <gomp_teams *> (stmt), true);
   17890                 :             :       break;
   17891                 :           0 :     default:
   17892                 :           0 :       gcc_unreachable ();
   17893                 :             :     }
   17894                 :             : 
   17895                 :       38265 :   gimplify_seq_add_stmt (pre_p, stmt);
   17896                 :       38265 :   *expr_p = NULL_TREE;
   17897                 :       38265 : }
   17898                 :             : 
   17899                 :             : /* Gimplify the gross structure of OpenACC enter/exit data, update, and OpenMP
   17900                 :             :    target update constructs.  */
   17901                 :             : 
   17902                 :             : static void
   17903                 :       11734 : gimplify_omp_target_update (tree *expr_p, gimple_seq *pre_p)
   17904                 :             : {
   17905                 :       11734 :   tree expr = *expr_p;
   17906                 :       11734 :   int kind;
   17907                 :       11734 :   gomp_target *stmt;
   17908                 :       11734 :   enum omp_region_type ort = ORT_WORKSHARE;
   17909                 :             : 
   17910                 :       11734 :   switch (TREE_CODE (expr))
   17911                 :             :     {
   17912                 :             :     case OACC_ENTER_DATA:
   17913                 :             :       kind = GF_OMP_TARGET_KIND_OACC_ENTER_DATA;
   17914                 :             :       ort = ORT_ACC;
   17915                 :             :       break;
   17916                 :             :     case OACC_EXIT_DATA:
   17917                 :             :       kind = GF_OMP_TARGET_KIND_OACC_EXIT_DATA;
   17918                 :             :       ort = ORT_ACC;
   17919                 :             :       break;
   17920                 :             :     case OACC_UPDATE:
   17921                 :             :       kind = GF_OMP_TARGET_KIND_OACC_UPDATE;
   17922                 :             :       ort = ORT_ACC;
   17923                 :             :       break;
   17924                 :             :     case OMP_TARGET_UPDATE:
   17925                 :             :       kind = GF_OMP_TARGET_KIND_UPDATE;
   17926                 :             :       break;
   17927                 :             :     case OMP_TARGET_ENTER_DATA:
   17928                 :             :       kind = GF_OMP_TARGET_KIND_ENTER_DATA;
   17929                 :             :       break;
   17930                 :             :     case OMP_TARGET_EXIT_DATA:
   17931                 :             :       kind = GF_OMP_TARGET_KIND_EXIT_DATA;
   17932                 :             :       break;
   17933                 :           0 :     default:
   17934                 :           0 :       gcc_unreachable ();
   17935                 :             :     }
   17936                 :       11734 :   gimplify_scan_omp_clauses (&OMP_STANDALONE_CLAUSES (expr), pre_p,
   17937                 :             :                              ort, TREE_CODE (expr));
   17938                 :       11734 :   gimplify_adjust_omp_clauses (pre_p, NULL, &OMP_STANDALONE_CLAUSES (expr),
   17939                 :       11734 :                                TREE_CODE (expr));
   17940                 :       11734 :   if (TREE_CODE (expr) == OACC_UPDATE
   17941                 :       11734 :       && omp_find_clause (OMP_STANDALONE_CLAUSES (expr),
   17942                 :             :                           OMP_CLAUSE_IF_PRESENT))
   17943                 :             :     {
   17944                 :             :       /* The runtime uses GOMP_MAP_{TO,FROM} to denote the if_present
   17945                 :             :          clause.  */
   17946                 :         123 :       for (tree c = OMP_STANDALONE_CLAUSES (expr); c; c = OMP_CLAUSE_CHAIN (c))
   17947                 :          97 :         if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP)
   17948                 :          47 :           switch (OMP_CLAUSE_MAP_KIND (c))
   17949                 :             :             {
   17950                 :          14 :             case GOMP_MAP_FORCE_TO:
   17951                 :          14 :               OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TO);
   17952                 :          14 :               break;
   17953                 :          24 :             case GOMP_MAP_FORCE_FROM:
   17954                 :          24 :               OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_FROM);
   17955                 :          24 :               break;
   17956                 :             :             default:
   17957                 :             :               break;
   17958                 :             :             }
   17959                 :             :     }
   17960                 :       11708 :   else if (TREE_CODE (expr) == OACC_EXIT_DATA
   17961                 :       11708 :            && omp_find_clause (OMP_STANDALONE_CLAUSES (expr),
   17962                 :             :                                OMP_CLAUSE_FINALIZE))
   17963                 :             :     {
   17964                 :             :       /* Use GOMP_MAP_DELETE/GOMP_MAP_FORCE_FROM to denote "finalize"
   17965                 :             :          semantics.  */
   17966                 :          69 :       bool have_clause = false;
   17967                 :         253 :       for (tree c = OMP_STANDALONE_CLAUSES (expr); c; c = OMP_CLAUSE_CHAIN (c))
   17968                 :         184 :         if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP)
   17969                 :         111 :           switch (OMP_CLAUSE_MAP_KIND (c))
   17970                 :             :             {
   17971                 :          41 :             case GOMP_MAP_FROM:
   17972                 :          41 :               OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_FORCE_FROM);
   17973                 :          41 :               have_clause = true;
   17974                 :          41 :               break;
   17975                 :          43 :             case GOMP_MAP_RELEASE:
   17976                 :          43 :               OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_DELETE);
   17977                 :          43 :               have_clause = true;
   17978                 :          43 :               break;
   17979                 :             :             case GOMP_MAP_TO_PSET:
   17980                 :             :               /* Fortran arrays with descriptors must map that descriptor when
   17981                 :             :                  doing standalone "attach" operations (in OpenACC).  In that
   17982                 :             :                  case GOMP_MAP_TO_PSET appears by itself with no preceding
   17983                 :             :                  clause (see trans-openmp.cc:gfc_trans_omp_clauses).  */
   17984                 :             :               break;
   17985                 :           2 :             case GOMP_MAP_POINTER:
   17986                 :             :               /* TODO PR92929: we may see these here, but they'll always follow
   17987                 :             :                  one of the clauses above, and will be handled by libgomp as
   17988                 :             :                  one group, so no handling required here.  */
   17989                 :           2 :               gcc_assert (have_clause);
   17990                 :             :               break;
   17991                 :          24 :             case GOMP_MAP_DETACH:
   17992                 :          24 :               OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_FORCE_DETACH);
   17993                 :          24 :               have_clause = false;
   17994                 :          24 :               break;
   17995                 :             :             case GOMP_MAP_STRUCT:
   17996                 :             :             case GOMP_MAP_STRUCT_UNORD:
   17997                 :          24 :               have_clause = false;
   17998                 :             :               break;
   17999                 :           0 :             default:
   18000                 :           0 :               gcc_unreachable ();
   18001                 :             :             }
   18002                 :             :     }
   18003                 :       11734 :   stmt = gimple_build_omp_target (NULL, kind, OMP_STANDALONE_CLAUSES (expr));
   18004                 :             : 
   18005                 :       11734 :   gimplify_seq_add_stmt (pre_p, stmt);
   18006                 :       11734 :   *expr_p = NULL_TREE;
   18007                 :       11734 : }
   18008                 :             : 
   18009                 :             : /* A subroutine of gimplify_omp_atomic.  The front end is supposed to have
   18010                 :             :    stabilized the lhs of the atomic operation as *ADDR.  Return true if
   18011                 :             :    EXPR is this stabilized form.  */
   18012                 :             : 
   18013                 :             : static bool
   18014                 :       36771 : goa_lhs_expr_p (tree expr, tree addr)
   18015                 :             : {
   18016                 :             :   /* Also include casts to other type variants.  The C front end is fond
   18017                 :             :      of adding these for e.g. volatile variables.  This is like
   18018                 :             :      STRIP_TYPE_NOPS but includes the main variant lookup.  */
   18019                 :       36771 :   STRIP_USELESS_TYPE_CONVERSION (expr);
   18020                 :             : 
   18021                 :       36771 :   if (INDIRECT_REF_P (expr))
   18022                 :             :     {
   18023                 :        4983 :       expr = TREE_OPERAND (expr, 0);
   18024                 :        4983 :       while (expr != addr
   18025                 :          92 :              && (CONVERT_EXPR_P (expr)
   18026                 :          92 :                  || TREE_CODE (expr) == NON_LVALUE_EXPR)
   18027                 :           0 :              && TREE_CODE (expr) == TREE_CODE (addr)
   18028                 :        4983 :              && types_compatible_p (TREE_TYPE (expr), TREE_TYPE (addr)))
   18029                 :             :         {
   18030                 :           0 :           expr = TREE_OPERAND (expr, 0);
   18031                 :           0 :           addr = TREE_OPERAND (addr, 0);
   18032                 :             :         }
   18033                 :        4983 :       if (expr == addr)
   18034                 :             :         return true;
   18035                 :          92 :       return (TREE_CODE (addr) == ADDR_EXPR
   18036                 :          62 :               && TREE_CODE (expr) == ADDR_EXPR
   18037                 :          92 :               && TREE_OPERAND (addr, 0) == TREE_OPERAND (expr, 0));
   18038                 :             :     }
   18039                 :       31788 :   if (TREE_CODE (addr) == ADDR_EXPR && expr == TREE_OPERAND (addr, 0))
   18040                 :             :     return true;
   18041                 :             :   return false;
   18042                 :             : }
   18043                 :             : 
   18044                 :             : /* Walk *EXPR_P and replace appearances of *LHS_ADDR with LHS_VAR.  If an
   18045                 :             :    expression does not involve the lhs, evaluate it into a temporary.
   18046                 :             :    Return 1 if the lhs appeared as a subexpression, 0 if it did not,
   18047                 :             :    or -1 if an error was encountered.  */
   18048                 :             : 
   18049                 :             : static int
   18050                 :       36771 : goa_stabilize_expr (tree *expr_p, gimple_seq *pre_p, tree lhs_addr,
   18051                 :             :                     tree lhs_var, tree &target_expr, bool rhs, int depth)
   18052                 :             : {
   18053                 :       36771 :   tree expr = *expr_p;
   18054                 :       36771 :   int saw_lhs = 0;
   18055                 :             : 
   18056                 :       36771 :   if (goa_lhs_expr_p (expr, lhs_addr))
   18057                 :             :     {
   18058                 :        9174 :       if (pre_p)
   18059                 :        8516 :         *expr_p = lhs_var;
   18060                 :        9174 :       return 1;
   18061                 :             :     }
   18062                 :       27597 :   if (is_gimple_val (expr))
   18063                 :             :     return 0;
   18064                 :             : 
   18065                 :             :   /* Maximum depth of lhs in expression is for the
   18066                 :             :      __builtin_clear_padding (...), __builtin_clear_padding (...),
   18067                 :             :      __builtin_memcmp (&TARGET_EXPR <lhs, >, ...) == 0 ? ... : lhs;  */
   18068                 :       17249 :   if (++depth > 7)
   18069                 :          16 :     goto finish;
   18070                 :             : 
   18071                 :       17233 :   switch (TREE_CODE_CLASS (TREE_CODE (expr)))
   18072                 :             :     {
   18073                 :        9643 :     case tcc_binary:
   18074                 :        9643 :     case tcc_comparison:
   18075                 :        9643 :       saw_lhs |= goa_stabilize_expr (&TREE_OPERAND (expr, 1), pre_p, lhs_addr,
   18076                 :             :                                      lhs_var, target_expr, true, depth);
   18077                 :             :       /* FALLTHRU */
   18078                 :       11692 :     case tcc_unary:
   18079                 :       11692 :       saw_lhs |= goa_stabilize_expr (&TREE_OPERAND (expr, 0), pre_p, lhs_addr,
   18080                 :             :                                      lhs_var, target_expr, true, depth);
   18081                 :       11692 :       break;
   18082                 :        2982 :     case tcc_expression:
   18083                 :        2982 :       switch (TREE_CODE (expr))
   18084                 :             :         {
   18085                 :         836 :         case TRUTH_ANDIF_EXPR:
   18086                 :         836 :         case TRUTH_ORIF_EXPR:
   18087                 :         836 :         case TRUTH_AND_EXPR:
   18088                 :         836 :         case TRUTH_OR_EXPR:
   18089                 :         836 :         case TRUTH_XOR_EXPR:
   18090                 :         836 :         case BIT_INSERT_EXPR:
   18091                 :         836 :           saw_lhs |= goa_stabilize_expr (&TREE_OPERAND (expr, 1), pre_p,
   18092                 :             :                                          lhs_addr, lhs_var, target_expr, true,
   18093                 :             :                                          depth);
   18094                 :             :           /* FALLTHRU */
   18095                 :         888 :         case TRUTH_NOT_EXPR:
   18096                 :         888 :           saw_lhs |= goa_stabilize_expr (&TREE_OPERAND (expr, 0), pre_p,
   18097                 :             :                                          lhs_addr, lhs_var, target_expr, true,
   18098                 :             :                                          depth);
   18099                 :         888 :           break;
   18100                 :         550 :         case MODIFY_EXPR:
   18101                 :         550 :           if (pre_p && !goa_stabilize_expr (expr_p, NULL, lhs_addr, lhs_var,
   18102                 :             :                                             target_expr, true, depth))
   18103                 :             :             break;
   18104                 :         544 :           saw_lhs |= goa_stabilize_expr (&TREE_OPERAND (expr, 1), pre_p,
   18105                 :             :                                          lhs_addr, lhs_var, target_expr, true,
   18106                 :             :                                          depth);
   18107                 :         544 :           saw_lhs |= goa_stabilize_expr (&TREE_OPERAND (expr, 0), pre_p,
   18108                 :             :                                          lhs_addr, lhs_var, target_expr, false,
   18109                 :             :                                          depth);
   18110                 :         544 :           break;
   18111                 :             :           /* FALLTHRU */
   18112                 :         164 :         case ADDR_EXPR:
   18113                 :         164 :           if (pre_p && !goa_stabilize_expr (expr_p, NULL, lhs_addr, lhs_var,
   18114                 :             :                                             target_expr, true, depth))
   18115                 :             :             break;
   18116                 :         138 :           saw_lhs |= goa_stabilize_expr (&TREE_OPERAND (expr, 0), pre_p,
   18117                 :             :                                          lhs_addr, lhs_var, target_expr, false,
   18118                 :             :                                          depth);
   18119                 :         138 :           break;
   18120                 :             :         case COMPOUND_EXPR:
   18121                 :             :           /* Break out any preevaluations from cp_build_modify_expr.  */
   18122                 :          76 :           for (; TREE_CODE (expr) == COMPOUND_EXPR;
   18123                 :          38 :                expr = TREE_OPERAND (expr, 1))
   18124                 :             :             {
   18125                 :             :               /* Special-case __builtin_clear_padding call before
   18126                 :             :                  __builtin_memcmp.  */
   18127                 :          38 :               if (TREE_CODE (TREE_OPERAND (expr, 0)) == CALL_EXPR)
   18128                 :             :                 {
   18129                 :           2 :                   tree fndecl = get_callee_fndecl (TREE_OPERAND (expr, 0));
   18130                 :           2 :                   if (fndecl
   18131                 :           2 :                       && fndecl_built_in_p (fndecl, BUILT_IN_CLEAR_PADDING)
   18132                 :           0 :                       && VOID_TYPE_P (TREE_TYPE (TREE_OPERAND (expr, 0)))
   18133                 :           2 :                       && (!pre_p
   18134                 :           0 :                           || goa_stabilize_expr (&TREE_OPERAND (expr, 0), NULL,
   18135                 :             :                                                  lhs_addr, lhs_var,
   18136                 :             :                                                  target_expr, true, depth)))
   18137                 :             :                     {
   18138                 :           0 :                       if (pre_p)
   18139                 :           0 :                         *expr_p = expr;
   18140                 :           0 :                       saw_lhs = goa_stabilize_expr (&TREE_OPERAND (expr, 0),
   18141                 :             :                                                     pre_p, lhs_addr, lhs_var,
   18142                 :             :                                                     target_expr, true, depth);
   18143                 :           0 :                       saw_lhs |= goa_stabilize_expr (&TREE_OPERAND (expr, 1),
   18144                 :             :                                                      pre_p, lhs_addr, lhs_var,
   18145                 :             :                                                      target_expr, rhs, depth);
   18146                 :           0 :                       return saw_lhs;
   18147                 :             :                     }
   18148                 :             :                 }
   18149                 :             : 
   18150                 :          38 :               if (pre_p)
   18151                 :          35 :                 gimplify_stmt (&TREE_OPERAND (expr, 0), pre_p);
   18152                 :             :             }
   18153                 :          38 :           if (!pre_p)
   18154                 :           3 :             return goa_stabilize_expr (&expr, pre_p, lhs_addr, lhs_var,
   18155                 :           3 :                                        target_expr, rhs, depth);
   18156                 :          35 :           *expr_p = expr;
   18157                 :          35 :           return goa_stabilize_expr (expr_p, pre_p, lhs_addr, lhs_var,
   18158                 :          35 :                                      target_expr, rhs, depth);
   18159                 :         441 :         case COND_EXPR:
   18160                 :         441 :           if (!goa_stabilize_expr (&TREE_OPERAND (expr, 0), NULL, lhs_addr,
   18161                 :             :                                    lhs_var, target_expr, true, depth))
   18162                 :             :             break;
   18163                 :         428 :           saw_lhs |= goa_stabilize_expr (&TREE_OPERAND (expr, 0), pre_p,
   18164                 :             :                                          lhs_addr, lhs_var, target_expr, true,
   18165                 :             :                                          depth);
   18166                 :         428 :           saw_lhs |= goa_stabilize_expr (&TREE_OPERAND (expr, 1), pre_p,
   18167                 :             :                                          lhs_addr, lhs_var, target_expr, true,
   18168                 :             :                                          depth);
   18169                 :         428 :           saw_lhs |= goa_stabilize_expr (&TREE_OPERAND (expr, 2), pre_p,
   18170                 :             :                                          lhs_addr, lhs_var, target_expr, true,
   18171                 :             :                                          depth);
   18172                 :         428 :           break;
   18173                 :         880 :         case TARGET_EXPR:
   18174                 :         880 :           if (TARGET_EXPR_INITIAL (expr))
   18175                 :             :             {
   18176                 :         880 :               if (pre_p && !goa_stabilize_expr (expr_p, NULL, lhs_addr,
   18177                 :             :                                                 lhs_var, target_expr, true,
   18178                 :             :                                                 depth))
   18179                 :             :                 break;
   18180                 :         702 :               if (expr == target_expr)
   18181                 :             :                 saw_lhs = 1;
   18182                 :             :               else
   18183                 :             :                 {
   18184                 :         702 :                   saw_lhs = goa_stabilize_expr (&TARGET_EXPR_INITIAL (expr),
   18185                 :             :                                                 pre_p, lhs_addr, lhs_var,
   18186                 :             :                                                 target_expr, true, depth);
   18187                 :         702 :                   if (saw_lhs && target_expr == NULL_TREE && pre_p)
   18188                 :          26 :                     target_expr = expr;
   18189                 :             :                 }
   18190                 :             :             }
   18191                 :             :           break;
   18192                 :             :         default:
   18193                 :             :           break;
   18194                 :             :         }
   18195                 :             :       break;
   18196                 :         565 :     case tcc_reference:
   18197                 :         565 :       if (TREE_CODE (expr) == BIT_FIELD_REF
   18198                 :         499 :           || TREE_CODE (expr) == VIEW_CONVERT_EXPR)
   18199                 :         362 :         saw_lhs |= goa_stabilize_expr (&TREE_OPERAND (expr, 0), pre_p,
   18200                 :             :                                        lhs_addr, lhs_var, target_expr, true,
   18201                 :             :                                        depth);
   18202                 :             :       break;
   18203                 :          56 :     case tcc_vl_exp:
   18204                 :          56 :       if (TREE_CODE (expr) == CALL_EXPR)
   18205                 :             :         {
   18206                 :          56 :           if (tree fndecl = get_callee_fndecl (expr))
   18207                 :          56 :             if (fndecl_built_in_p (fndecl, BUILT_IN_CLEAR_PADDING,
   18208                 :             :                                            BUILT_IN_MEMCMP))
   18209                 :             :               {
   18210                 :          56 :                 int nargs = call_expr_nargs (expr);
   18211                 :         224 :                 for (int i = 0; i < nargs; i++)
   18212                 :         168 :                   saw_lhs |= goa_stabilize_expr (&CALL_EXPR_ARG (expr, i),
   18213                 :             :                                                  pre_p, lhs_addr, lhs_var,
   18214                 :             :                                                  target_expr, true, depth);
   18215                 :             :               }
   18216                 :             :         }
   18217                 :             :       break;
   18218                 :             :     default:
   18219                 :             :       break;
   18220                 :             :     }
   18221                 :             : 
   18222                 :       17211 :  finish:
   18223                 :       17211 :   if (saw_lhs == 0 && pre_p)
   18224                 :             :     {
   18225                 :        3465 :       enum gimplify_status gs;
   18226                 :        3465 :       if (TREE_CODE (expr) == CALL_EXPR && VOID_TYPE_P (TREE_TYPE (expr)))
   18227                 :             :         {
   18228                 :           0 :           gimplify_stmt (&expr, pre_p);
   18229                 :           0 :           return saw_lhs;
   18230                 :             :         }
   18231                 :        3465 :       else if (rhs)
   18232                 :        3287 :         gs = gimplify_expr (expr_p, pre_p, NULL, is_gimple_val, fb_rvalue);
   18233                 :             :       else
   18234                 :         178 :         gs = gimplify_expr (expr_p, pre_p, NULL, is_gimple_lvalue, fb_lvalue);
   18235                 :        3465 :       if (gs != GS_ALL_DONE)
   18236                 :       36771 :         saw_lhs = -1;
   18237                 :             :     }
   18238                 :             : 
   18239                 :             :   return saw_lhs;
   18240                 :             : }
   18241                 :             : 
   18242                 :             : /* Gimplify an OMP_ATOMIC statement.  */
   18243                 :             : 
   18244                 :             : static enum gimplify_status
   18245                 :       10232 : gimplify_omp_atomic (tree *expr_p, gimple_seq *pre_p)
   18246                 :             : {
   18247                 :       10232 :   tree addr = TREE_OPERAND (*expr_p, 0);
   18248                 :       10232 :   tree rhs = TREE_CODE (*expr_p) == OMP_ATOMIC_READ
   18249                 :       10232 :              ? NULL : TREE_OPERAND (*expr_p, 1);
   18250                 :       10232 :   tree type = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (addr)));
   18251                 :       10232 :   tree tmp_load;
   18252                 :       10232 :   gomp_atomic_load *loadstmt;
   18253                 :       10232 :   gomp_atomic_store *storestmt;
   18254                 :       10232 :   tree target_expr = NULL_TREE;
   18255                 :             : 
   18256                 :       10232 :   tmp_load = create_tmp_reg (type);
   18257                 :       10232 :   if (rhs
   18258                 :       10232 :       && goa_stabilize_expr (&rhs, pre_p, addr, tmp_load, target_expr,
   18259                 :             :                              true, 0) < 0)
   18260                 :             :     return GS_ERROR;
   18261                 :             : 
   18262                 :       10232 :   if (gimplify_expr (&addr, pre_p, NULL, is_gimple_val, fb_rvalue)
   18263                 :             :       != GS_ALL_DONE)
   18264                 :             :     return GS_ERROR;
   18265                 :             : 
   18266                 :       10232 :   loadstmt = gimple_build_omp_atomic_load (tmp_load, addr,
   18267                 :       10232 :                                            OMP_ATOMIC_MEMORY_ORDER (*expr_p));
   18268                 :       10232 :   gimplify_seq_add_stmt (pre_p, loadstmt);
   18269                 :       10232 :   if (rhs)
   18270                 :             :     {
   18271                 :             :       /* BIT_INSERT_EXPR is not valid for non-integral bitfield
   18272                 :             :          representatives.  Use BIT_FIELD_REF on the lhs instead.  */
   18273                 :        9051 :       tree rhsarg = rhs;
   18274                 :        9051 :       if (TREE_CODE (rhs) == COND_EXPR)
   18275                 :         428 :         rhsarg = TREE_OPERAND (rhs, 1);
   18276                 :        9051 :       if (TREE_CODE (rhsarg) == BIT_INSERT_EXPR
   18277                 :        9051 :           && !INTEGRAL_TYPE_P (TREE_TYPE (tmp_load)))
   18278                 :             :         {
   18279                 :          32 :           tree bitpos = TREE_OPERAND (rhsarg, 2);
   18280                 :          32 :           tree op1 = TREE_OPERAND (rhsarg, 1);
   18281                 :          32 :           tree bitsize;
   18282                 :          32 :           tree tmp_store = tmp_load;
   18283                 :          32 :           if (TREE_CODE (*expr_p) == OMP_ATOMIC_CAPTURE_OLD)
   18284                 :          12 :             tmp_store = get_initialized_tmp_var (tmp_load, pre_p);
   18285                 :          32 :           if (INTEGRAL_TYPE_P (TREE_TYPE (op1)))
   18286                 :          32 :             bitsize = bitsize_int (TYPE_PRECISION (TREE_TYPE (op1)));
   18287                 :             :           else
   18288                 :           0 :             bitsize = TYPE_SIZE (TREE_TYPE (op1));
   18289                 :          32 :           gcc_assert (TREE_OPERAND (rhsarg, 0) == tmp_load);
   18290                 :          32 :           tree t = build2_loc (EXPR_LOCATION (rhsarg),
   18291                 :             :                                MODIFY_EXPR, void_type_node,
   18292                 :          32 :                                build3_loc (EXPR_LOCATION (rhsarg),
   18293                 :          32 :                                            BIT_FIELD_REF, TREE_TYPE (op1),
   18294                 :             :                                            tmp_store, bitsize, bitpos), op1);
   18295                 :          32 :           if (TREE_CODE (rhs) == COND_EXPR)
   18296                 :          16 :             t = build3_loc (EXPR_LOCATION (rhs), COND_EXPR, void_type_node,
   18297                 :          16 :                             TREE_OPERAND (rhs, 0), t, void_node);
   18298                 :          32 :           gimplify_and_add (t, pre_p);
   18299                 :          32 :           rhs = tmp_store;
   18300                 :             :         }
   18301                 :        9051 :       bool save_allow_rhs_cond_expr = gimplify_ctxp->allow_rhs_cond_expr;
   18302                 :        9051 :       if (TREE_CODE (rhs) == COND_EXPR)
   18303                 :         412 :         gimplify_ctxp->allow_rhs_cond_expr = true;
   18304                 :        9051 :       enum gimplify_status gs = gimplify_expr (&rhs, pre_p, NULL,
   18305                 :             :                                                is_gimple_val, fb_rvalue);
   18306                 :        9051 :       gimplify_ctxp->allow_rhs_cond_expr = save_allow_rhs_cond_expr;
   18307                 :        9051 :       if (gs != GS_ALL_DONE)
   18308                 :             :         return GS_ERROR;
   18309                 :             :     }
   18310                 :             : 
   18311                 :       10232 :   if (TREE_CODE (*expr_p) == OMP_ATOMIC_READ)
   18312                 :        1181 :     rhs = tmp_load;
   18313                 :       10232 :   storestmt
   18314                 :       10232 :     = gimple_build_omp_atomic_store (rhs, OMP_ATOMIC_MEMORY_ORDER (*expr_p));
   18315                 :       10232 :   if (TREE_CODE (*expr_p) != OMP_ATOMIC_READ && OMP_ATOMIC_WEAK (*expr_p))
   18316                 :             :     {
   18317                 :          37 :       gimple_omp_atomic_set_weak (loadstmt);
   18318                 :          37 :       gimple_omp_atomic_set_weak (storestmt);
   18319                 :             :     }
   18320                 :       10232 :   gimplify_seq_add_stmt (pre_p, storestmt);
   18321                 :       10232 :   switch (TREE_CODE (*expr_p))
   18322                 :             :     {
   18323                 :        2085 :     case OMP_ATOMIC_READ:
   18324                 :        2085 :     case OMP_ATOMIC_CAPTURE_OLD:
   18325                 :        2085 :       *expr_p = tmp_load;
   18326                 :        2085 :       gimple_omp_atomic_set_need_value (loadstmt);
   18327                 :        2085 :       break;
   18328                 :         868 :     case OMP_ATOMIC_CAPTURE_NEW:
   18329                 :         868 :       *expr_p = rhs;
   18330                 :         868 :       gimple_omp_atomic_set_need_value (storestmt);
   18331                 :         868 :       break;
   18332                 :        7279 :     default:
   18333                 :        7279 :       *expr_p = NULL;
   18334                 :        7279 :       break;
   18335                 :             :     }
   18336                 :             : 
   18337                 :             :   return GS_ALL_DONE;
   18338                 :             : }
   18339                 :             : 
   18340                 :             : /* Gimplify a TRANSACTION_EXPR.  This involves gimplification of the
   18341                 :             :    body, and adding some EH bits.  */
   18342                 :             : 
   18343                 :             : static enum gimplify_status
   18344                 :         478 : gimplify_transaction (tree *expr_p, gimple_seq *pre_p)
   18345                 :             : {
   18346                 :         478 :   tree expr = *expr_p, temp, tbody = TRANSACTION_EXPR_BODY (expr);
   18347                 :         478 :   gimple *body_stmt;
   18348                 :         478 :   gtransaction *trans_stmt;
   18349                 :         478 :   gimple_seq body = NULL;
   18350                 :         478 :   int subcode = 0;
   18351                 :             : 
   18352                 :             :   /* Wrap the transaction body in a BIND_EXPR so we have a context
   18353                 :             :      where to put decls for OMP.  */
   18354                 :         478 :   if (TREE_CODE (tbody) != BIND_EXPR)
   18355                 :             :     {
   18356                 :         439 :       tree bind = build3 (BIND_EXPR, void_type_node, NULL, tbody, NULL);
   18357                 :         439 :       TREE_SIDE_EFFECTS (bind) = 1;
   18358                 :         439 :       SET_EXPR_LOCATION (bind, EXPR_LOCATION (tbody));
   18359                 :         439 :       TRANSACTION_EXPR_BODY (expr) = bind;
   18360                 :             :     }
   18361                 :             : 
   18362                 :         478 :   push_gimplify_context ();
   18363                 :         478 :   temp = voidify_wrapper_expr (*expr_p, NULL);
   18364                 :             : 
   18365                 :         478 :   body_stmt = gimplify_and_return_first (TRANSACTION_EXPR_BODY (expr), &body);
   18366                 :         478 :   pop_gimplify_context (body_stmt);
   18367                 :             : 
   18368                 :         478 :   trans_stmt = gimple_build_transaction (body);
   18369                 :         478 :   if (TRANSACTION_EXPR_OUTER (expr))
   18370                 :             :     subcode = GTMA_IS_OUTER;
   18371                 :         447 :   else if (TRANSACTION_EXPR_RELAXED (expr))
   18372                 :          81 :     subcode = GTMA_IS_RELAXED;
   18373                 :         478 :   gimple_transaction_set_subcode (trans_stmt, subcode);
   18374                 :             : 
   18375                 :         478 :   gimplify_seq_add_stmt (pre_p, trans_stmt);
   18376                 :             : 
   18377                 :         478 :   if (temp)
   18378                 :             :     {
   18379                 :          76 :       *expr_p = temp;
   18380                 :          76 :       return GS_OK;
   18381                 :             :     }
   18382                 :             : 
   18383                 :         402 :   *expr_p = NULL_TREE;
   18384                 :         402 :   return GS_ALL_DONE;
   18385                 :             : }
   18386                 :             : 
   18387                 :             : /* Gimplify an OMP_ORDERED construct.  EXPR is the tree version.  BODY
   18388                 :             :    is the OMP_BODY of the original EXPR (which has already been
   18389                 :             :    gimplified so it's not present in the EXPR).
   18390                 :             : 
   18391                 :             :    Return the gimplified GIMPLE_OMP_ORDERED tuple.  */
   18392                 :             : 
   18393                 :             : static gimple *
   18394                 :        1940 : gimplify_omp_ordered (tree expr, gimple_seq body)
   18395                 :             : {
   18396                 :        1940 :   tree c, decls;
   18397                 :        1940 :   int failures = 0;
   18398                 :        1940 :   unsigned int i;
   18399                 :        1940 :   tree source_c = NULL_TREE;
   18400                 :        1940 :   tree sink_c = NULL_TREE;
   18401                 :             : 
   18402                 :        1940 :   if (gimplify_omp_ctxp)
   18403                 :             :     {
   18404                 :        3271 :       for (c = OMP_ORDERED_CLAUSES (expr); c; c = OMP_CLAUSE_CHAIN (c))
   18405                 :        1505 :         if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DOACROSS
   18406                 :        1505 :             && gimplify_omp_ctxp->loop_iter_var.is_empty ())
   18407                 :             :           {
   18408                 :          74 :             error_at (OMP_CLAUSE_LOCATION (c),
   18409                 :             :                       "%<ordered%> construct with %qs clause must be "
   18410                 :             :                       "closely nested inside a loop with %<ordered%> clause",
   18411                 :          74 :                       OMP_CLAUSE_DOACROSS_DEPEND (c) ? "depend" : "doacross");
   18412                 :          74 :             failures++;
   18413                 :             :           }
   18414                 :        1431 :         else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DOACROSS
   18415                 :        1431 :                  && OMP_CLAUSE_DOACROSS_KIND (c) == OMP_CLAUSE_DOACROSS_SINK)
   18416                 :             :           {
   18417                 :         637 :             bool fail = false;
   18418                 :         637 :             sink_c = c;
   18419                 :         637 :             if (OMP_CLAUSE_DECL (c) == NULL_TREE)
   18420                 :          72 :               continue;  /* omp_cur_iteration - 1 */
   18421                 :         565 :             for (decls = OMP_CLAUSE_DECL (c), i = 0;
   18422                 :        3191 :                  decls && TREE_CODE (decls) == TREE_LIST;
   18423                 :        2626 :                  decls = TREE_CHAIN (decls), ++i)
   18424                 :        2626 :               if (i >= gimplify_omp_ctxp->loop_iter_var.length () / 2)
   18425                 :           4 :                 continue;
   18426                 :        5244 :               else if (TREE_VALUE (decls)
   18427                 :        2622 :                        != gimplify_omp_ctxp->loop_iter_var[2 * i])
   18428                 :             :                 {
   18429                 :           8 :                   error_at (OMP_CLAUSE_LOCATION (c),
   18430                 :             :                             "variable %qE is not an iteration "
   18431                 :             :                             "of outermost loop %d, expected %qE",
   18432                 :           8 :                             TREE_VALUE (decls), i + 1,
   18433                 :           8 :                             gimplify_omp_ctxp->loop_iter_var[2 * i]);
   18434                 :           8 :                   fail = true;
   18435                 :           8 :                   failures++;
   18436                 :             :                 }
   18437                 :             :               else
   18438                 :        5228 :                 TREE_VALUE (decls)
   18439                 :        2614 :                   = gimplify_omp_ctxp->loop_iter_var[2 * i + 1];
   18440                 :        1126 :             if (!fail && i != gimplify_omp_ctxp->loop_iter_var.length () / 2)
   18441                 :             :               {
   18442                 :          16 :                 error_at (OMP_CLAUSE_LOCATION (c),
   18443                 :             :                           "number of variables in %qs clause with "
   18444                 :             :                           "%<sink%> modifier does not match number of "
   18445                 :             :                           "iteration variables",
   18446                 :          16 :                           OMP_CLAUSE_DOACROSS_DEPEND (c)
   18447                 :             :                           ? "depend" : "doacross");
   18448                 :          16 :                 failures++;
   18449                 :             :               }
   18450                 :             :           }
   18451                 :         794 :         else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DOACROSS
   18452                 :         794 :                  && OMP_CLAUSE_DOACROSS_KIND (c) == OMP_CLAUSE_DOACROSS_SOURCE)
   18453                 :             :           {
   18454                 :         470 :             if (source_c)
   18455                 :             :               {
   18456                 :           4 :                 error_at (OMP_CLAUSE_LOCATION (c),
   18457                 :             :                           "more than one %qs clause with %<source%> "
   18458                 :             :                           "modifier on an %<ordered%> construct",
   18459                 :           4 :                           OMP_CLAUSE_DOACROSS_DEPEND (source_c)
   18460                 :             :                           ? "depend" : "doacross");
   18461                 :           4 :                 failures++;
   18462                 :             :               }
   18463                 :             :             else
   18464                 :             :               source_c = c;
   18465                 :             :           }
   18466                 :             :     }
   18467                 :        1940 :   if (source_c && sink_c)
   18468                 :             :     {
   18469                 :           4 :       error_at (OMP_CLAUSE_LOCATION (source_c),
   18470                 :             :                 "%qs clause with %<source%> modifier specified "
   18471                 :             :                 "together with %qs clauses with %<sink%> modifier "
   18472                 :             :                 "on the same construct",
   18473                 :           4 :                 OMP_CLAUSE_DOACROSS_DEPEND (source_c) ? "depend" : "doacross",
   18474                 :           4 :                 OMP_CLAUSE_DOACROSS_DEPEND (sink_c) ? "depend" : "doacross");
   18475                 :           4 :       failures++;
   18476                 :             :     }
   18477                 :             : 
   18478                 :        1940 :   if (failures)
   18479                 :         102 :     return gimple_build_nop ();
   18480                 :        1838 :   return gimple_build_omp_ordered (body, OMP_ORDERED_CLAUSES (expr));
   18481                 :             : }
   18482                 :             : 
   18483                 :             : /* Callback for walk_tree to find an IFN_GOMP_DISPATCH.  */
   18484                 :             : 
   18485                 :             : static tree
   18486                 :        3039 : find_ifn_gomp_dispatch (tree *tp, int *, void *modify)
   18487                 :             : {
   18488                 :        3039 :   tree t = *tp;
   18489                 :             : 
   18490                 :        3039 :   if (TREE_CODE (t) == CALL_EXPR && CALL_EXPR_IFN (t) == IFN_GOMP_DISPATCH)
   18491                 :        1362 :     return *(tree *) modify ? *(tree *) modify : *tp;
   18492                 :             : 
   18493                 :        2220 :   if (TREE_CODE (t) == MODIFY_EXPR)
   18494                 :         499 :     *(tree *) modify = *tp;
   18495                 :             : 
   18496                 :             :   return NULL_TREE;
   18497                 :             : }
   18498                 :             : 
   18499                 :             : /* Gimplify an OMP_DISPATCH construct.  */
   18500                 :             : 
   18501                 :             : static enum gimplify_status
   18502                 :         819 : gimplify_omp_dispatch (tree *expr_p, gimple_seq *pre_p)
   18503                 :             : {
   18504                 :         819 :   tree expr = *expr_p;
   18505                 :         819 :   gimple_seq body = NULL;
   18506                 :             : 
   18507                 :         819 :   gimplify_scan_omp_clauses (&OMP_DISPATCH_CLAUSES (expr), pre_p, ORT_DISPATCH,
   18508                 :             :                              OMP_DISPATCH);
   18509                 :         819 :   push_gimplify_context ();
   18510                 :             : 
   18511                 :             :   // If device clause, adjust ICV
   18512                 :         819 :   tree device
   18513                 :         819 :     = omp_find_clause (OMP_DISPATCH_CLAUSES (expr), OMP_CLAUSE_DEVICE);
   18514                 :             :   // If no device clause exists but an interop clause with a single list
   18515                 :             :   // item, use it to obtain the device number.
   18516                 :         819 :   if (device)
   18517                 :         265 :     device = OMP_CLAUSE_DEVICE_ID (device);
   18518                 :             :   else
   18519                 :             :     {
   18520                 :         554 :       tree first_interop_obj
   18521                 :         554 :         = omp_find_clause (OMP_DISPATCH_CLAUSES (expr), OMP_CLAUSE_INTEROP);
   18522                 :         554 :       if (first_interop_obj)
   18523                 :          88 :         for (tree c = TREE_CHAIN (first_interop_obj); c; c = TREE_CHAIN (c))
   18524                 :           8 :           if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_INTEROP)
   18525                 :             :             {
   18526                 :             :               first_interop_obj = NULL_TREE;
   18527                 :             :               break;
   18528                 :             :             }
   18529                 :          87 :       if (first_interop_obj)
   18530                 :             :         {
   18531                 :          80 :           device = create_tmp_var (integer_type_node);
   18532                 :          80 :           tree c = build_omp_clause (OMP_CLAUSE_LOCATION (first_interop_obj),
   18533                 :             :                                      OMP_CLAUSE_DEVICE);
   18534                 :          80 :           OMP_CLAUSE_DEVICE_ID (c) = device;
   18535                 :          80 :           TREE_CHAIN (c) = TREE_CHAIN (first_interop_obj);
   18536                 :          80 :           TREE_CHAIN (first_interop_obj) = c;
   18537                 :          80 :           first_interop_obj = OMP_CLAUSE_DECL (first_interop_obj);
   18538                 :             :           /* device = omp_get_interop_int (obj, omp_ipr_device_num, NULL);  */
   18539                 :          80 :           tree fn = builtin_decl_explicit (BUILT_IN_OMP_GET_INTEROP_INT);
   18540                 :          80 :           fn = build_call_expr (fn, 3, first_interop_obj,
   18541                 :          80 :                                 build_int_cst (integer_type_node, -5),
   18542                 :             :                                 null_pointer_node);
   18543                 :          80 :           gimplify_assign (device, fold_convert (integer_type_node, fn), &body);
   18544                 :             :         }
   18545                 :             :     }
   18546                 :         819 :   tree saved_device_icv = NULL_TREE;
   18547                 :         819 :   if (device
   18548                 :         819 :       && (TREE_CODE (device) != INTEGER_CST
   18549                 :         690 :           || !wi::eq_p (wi::to_wide (device), -1 /* omp_initial_device */)))
   18550                 :             :     {
   18551                 :             :       // Save current default-device-var ICV
   18552                 :         345 :       saved_device_icv = create_tmp_var (integer_type_node);
   18553                 :         345 :       tree fn = builtin_decl_explicit (BUILT_IN_OMP_GET_DEFAULT_DEVICE);
   18554                 :         345 :       gcall *call = gimple_build_call (fn, 0);
   18555                 :         345 :       gimple_call_set_lhs (call, saved_device_icv);
   18556                 :         345 :       gimplify_seq_add_stmt (&body, call);
   18557                 :             : 
   18558                 :             :       // Set default device
   18559                 :         345 :       fn = builtin_decl_explicit (BUILT_IN_OMP_SET_DEFAULT_DEVICE);
   18560                 :         345 :       call = gimple_build_call (fn, 1, device);
   18561                 :         345 :       gimplify_seq_add_stmt (&body, call);
   18562                 :             :     }
   18563                 :             : 
   18564                 :             :   // If the novariants and nocontext clauses are not compile-time constants,
   18565                 :             :   // we need to generate code for all possible cases:
   18566                 :             :   //   if (novariants) // implies nocontext
   18567                 :             :   //       base()
   18568                 :             :   //   else if (nocontext)
   18569                 :             :   //       variant1()
   18570                 :             :   //   else
   18571                 :             :   //       variant2()
   18572                 :         819 :   tree *dispatch_body_p = &OMP_DISPATCH_BODY (expr);
   18573                 :         819 :   if (TREE_CODE (*dispatch_body_p) == BIND_EXPR)
   18574                 :          28 :     dispatch_body_p = &BIND_EXPR_BODY (*dispatch_body_p);
   18575                 :         819 :   tree dispatch_body = *dispatch_body_p;
   18576                 :             : 
   18577                 :             :   // Look for IFN_GOMP_DISPATCH and extract the base function call
   18578                 :         819 :   tree base_call_expr = NULL_TREE;
   18579                 :         819 :   if (TREE_CODE (dispatch_body) == STATEMENT_LIST)
   18580                 :         243 :     for (tree_stmt_iterator tsi = tsi_start (dispatch_body); !tsi_end_p (tsi);
   18581                 :         187 :          tsi_next (&tsi))
   18582                 :             :       {
   18583                 :         243 :         tree modify = NULL_TREE;
   18584                 :         243 :         tree stmt = tsi_stmt (tsi);
   18585                 :         243 :         base_call_expr
   18586                 :         243 :           = walk_tree (&stmt, find_ifn_gomp_dispatch, &modify, NULL);
   18587                 :         243 :         if (base_call_expr != NULL_TREE)
   18588                 :             :           break;
   18589                 :             :       }
   18590                 :             :   else
   18591                 :             :     {
   18592                 :         763 :       tree modify = NULL_TREE;
   18593                 :         763 :       base_call_expr
   18594                 :         763 :         = walk_tree (dispatch_body_p, find_ifn_gomp_dispatch, &modify, NULL);
   18595                 :             :     }
   18596                 :         819 :   gcc_assert (base_call_expr != NULL_TREE);
   18597                 :             : 
   18598                 :         819 :   tree dst = NULL_TREE;
   18599                 :         819 :   if (TREE_CODE (base_call_expr) == MODIFY_EXPR)
   18600                 :             :     {
   18601                 :         276 :       dst = TREE_OPERAND (base_call_expr, 0);
   18602                 :         276 :       base_call_expr = TREE_OPERAND (base_call_expr, 1);
   18603                 :             :     }
   18604                 :             : 
   18605                 :         847 :   while (TREE_CODE (base_call_expr) == FLOAT_EXPR
   18606                 :             :          || TREE_CODE (base_call_expr) == CONVERT_EXPR
   18607                 :             :          || TREE_CODE (base_call_expr) == COMPLEX_EXPR
   18608                 :             :          || TREE_CODE (base_call_expr) == INDIRECT_REF
   18609                 :         847 :          || TREE_CODE (base_call_expr) == NOP_EXPR)
   18610                 :          28 :     base_call_expr = TREE_OPERAND (base_call_expr, 0);
   18611                 :             : 
   18612                 :         819 :   gcc_assert (CALL_EXPR_IFN (base_call_expr) == IFN_GOMP_DISPATCH);
   18613                 :         819 :   base_call_expr = CALL_EXPR_ARG (base_call_expr, 0);
   18614                 :             : 
   18615                 :         819 :   tree base_fndecl = get_callee_fndecl (base_call_expr);
   18616                 :         819 :   if (base_fndecl != NULL_TREE)
   18617                 :             :     {
   18618                 :         811 :       if (DECL_VIRTUAL_P (base_fndecl))
   18619                 :             :         {
   18620                 :           6 :           error_at (
   18621                 :           3 :             EXPR_LOCATION (base_call_expr),
   18622                 :             :             "%qD is a virtual function but only a direct call is allowed "
   18623                 :             :             "in a dispatch construct",
   18624                 :           3 :             DECL_NAME (base_fndecl));
   18625                 :             :         }
   18626                 :             : 
   18627                 :             :       /* We are not actually going to expand the variant call or use
   18628                 :             :          the result of omp_get_dynamic candidates here; only check that
   18629                 :             :          it does not trivially resolve to a call to the base function
   18630                 :             :          so that we can avoid some extra work in building code that's
   18631                 :             :          not needed in that case.  */
   18632                 :         811 :       tree construct_context = omp_get_construct_context ();
   18633                 :         811 :       vec<struct omp_variant> all_candidates
   18634                 :         811 :         = omp_declare_variant_candidates (base_fndecl, construct_context);
   18635                 :         811 :       gcc_assert (!all_candidates.is_empty ());
   18636                 :         811 :       vec<struct omp_variant> candidates
   18637                 :         811 :         = omp_get_dynamic_candidates (all_candidates, construct_context);
   18638                 :         811 :       tree variant_fndecl
   18639                 :        1610 :         = (candidates.length () == 1 ? candidates[0].alternative : NULL_TREE);
   18640                 :             : 
   18641                 :         811 :       if (base_fndecl != variant_fndecl
   18642                 :         811 :           && (omp_has_novariants () == -1 || omp_has_nocontext () == -1))
   18643                 :             :         {
   18644                 :          22 :           tree novariants_clause = NULL_TREE, nocontext_clause = NULL_TREE,
   18645                 :          22 :                novariants_cond = NULL_TREE, nocontext_cond = NULL_TREE;
   18646                 :          59 :           for (tree c = OMP_DISPATCH_CLAUSES (expr); c; c = TREE_CHAIN (c))
   18647                 :             :             {
   18648                 :          37 :               if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NOVARIANTS
   18649                 :          37 :                   && !integer_zerop (OMP_CLAUSE_NOVARIANTS_EXPR (c)))
   18650                 :             :                 {
   18651                 :          16 :                   gcc_assert (novariants_cond == NULL_TREE);
   18652                 :          16 :                   novariants_clause = c;
   18653                 :          16 :                   novariants_cond = OMP_CLAUSE_NOVARIANTS_EXPR (c);
   18654                 :             :                 }
   18655                 :          21 :               else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NOCONTEXT
   18656                 :          21 :                        && !integer_zerop (OMP_CLAUSE_NOCONTEXT_EXPR (c)))
   18657                 :             :                 {
   18658                 :          16 :                   gcc_assert (nocontext_cond == NULL_TREE);
   18659                 :          16 :                   nocontext_clause = c;
   18660                 :          16 :                   nocontext_cond = OMP_CLAUSE_NOCONTEXT_EXPR (c);
   18661                 :             :                 }
   18662                 :             :             }
   18663                 :          22 :           gcc_assert (novariants_cond != NULL_TREE
   18664                 :             :                       || nocontext_cond != NULL_TREE);
   18665                 :             : 
   18666                 :          22 :           enum gimplify_status ret
   18667                 :          22 :             = gimplify_expr (&novariants_cond, &body, NULL, is_gimple_val,
   18668                 :             :                              fb_rvalue);
   18669                 :          22 :           if (ret == GS_ERROR || ret == GS_UNHANDLED)
   18670                 :           0 :             return ret;
   18671                 :          22 :           ret = gimplify_expr (&nocontext_cond, &body, NULL, is_gimple_val,
   18672                 :             :                                fb_rvalue);
   18673                 :          22 :           if (ret == GS_ERROR || ret == GS_UNHANDLED)
   18674                 :             :             return ret;
   18675                 :             : 
   18676                 :          22 :           tree end_label = create_artificial_label (UNKNOWN_LOCATION);
   18677                 :             : 
   18678                 :          22 :           if (novariants_cond != NULL_TREE)
   18679                 :             :             {
   18680                 :          16 :               tree base_label = create_artificial_label (UNKNOWN_LOCATION);
   18681                 :          16 :               tree cond_label = create_artificial_label (UNKNOWN_LOCATION);
   18682                 :          16 :               gcond *novariants_cond_stmt
   18683                 :          16 :                 = gimple_build_cond_from_tree (novariants_cond, base_label,
   18684                 :             :                                                cond_label);
   18685                 :          16 :               gimplify_seq_add_stmt (&body, novariants_cond_stmt);
   18686                 :             : 
   18687                 :          16 :               gimplify_seq_add_stmt (&body, gimple_build_label (base_label));
   18688                 :          16 :               tree base_call_expr2 = copy_node (base_call_expr);
   18689                 :          16 :               base_call_expr2
   18690                 :          16 :                 = build_call_expr_internal_loc (EXPR_LOCATION (base_call_expr2),
   18691                 :             :                                                 IFN_GOMP_DISPATCH,
   18692                 :          16 :                                                 TREE_TYPE (base_call_expr2), 1,
   18693                 :             :                                                 base_call_expr2);
   18694                 :          16 :               if (TREE_CODE (dispatch_body) == MODIFY_EXPR)
   18695                 :             :                 {
   18696                 :          16 :                   base_call_expr2 = build2 (MODIFY_EXPR, TREE_TYPE (dst), dst,
   18697                 :             :                                             base_call_expr2);
   18698                 :             :                 }
   18699                 :          16 :               OMP_CLAUSE_NOVARIANTS_EXPR (novariants_clause)
   18700                 :          16 :                 = boolean_true_node;
   18701                 :          16 :               gimplify_and_add (base_call_expr2, &body);
   18702                 :          16 :               gimplify_seq_add_stmt (&body, gimple_build_goto (end_label));
   18703                 :             : 
   18704                 :          16 :               OMP_CLAUSE_NOVARIANTS_EXPR (novariants_clause)
   18705                 :          16 :                 = boolean_false_node;
   18706                 :          16 :               gimplify_seq_add_stmt (&body, gimple_build_label (cond_label));
   18707                 :             :             }
   18708                 :             : 
   18709                 :          22 :           if (nocontext_cond != NULL_TREE)
   18710                 :             :             {
   18711                 :          16 :               tree variant1_label = create_artificial_label (UNKNOWN_LOCATION);
   18712                 :          16 :               tree variant2_label = create_artificial_label (UNKNOWN_LOCATION);
   18713                 :          16 :               gcond *nocontext_cond_stmt
   18714                 :          16 :                 = gimple_build_cond_from_tree (nocontext_cond, variant1_label,
   18715                 :             :                                                variant2_label);
   18716                 :          16 :               gimplify_seq_add_stmt (&body, nocontext_cond_stmt);
   18717                 :             : 
   18718                 :          32 :               gimplify_seq_add_stmt (&body,
   18719                 :          16 :                                      gimple_build_label (variant1_label));
   18720                 :          16 :               tree variant_call_expr = copy_node (base_call_expr);
   18721                 :          32 :               variant_call_expr = build_call_expr_internal_loc (
   18722                 :          16 :                 EXPR_LOCATION (variant_call_expr), IFN_GOMP_DISPATCH,
   18723                 :          16 :                 TREE_TYPE (variant_call_expr), 1, variant_call_expr);
   18724                 :          16 :               if (TREE_CODE (dispatch_body) == MODIFY_EXPR)
   18725                 :             :                 {
   18726                 :          16 :                   variant_call_expr = build2 (MODIFY_EXPR, TREE_TYPE (dst), dst,
   18727                 :             :                                               variant_call_expr);
   18728                 :             :                 }
   18729                 :          16 :               OMP_CLAUSE_NOCONTEXT_EXPR (nocontext_clause) = boolean_true_node;
   18730                 :          16 :               gimplify_and_add (variant_call_expr, &body);
   18731                 :          16 :               gimplify_seq_add_stmt (&body, gimple_build_goto (end_label));
   18732                 :          16 :               OMP_CLAUSE_NOCONTEXT_EXPR (nocontext_clause) = boolean_false_node;
   18733                 :          32 :               gimplify_seq_add_stmt (&body,
   18734                 :          16 :                                      gimple_build_label (variant2_label));
   18735                 :             :             }
   18736                 :             : 
   18737                 :          22 :           tree variant_call_expr = base_call_expr;
   18738                 :          22 :           variant_call_expr
   18739                 :          22 :             = build_call_expr_internal_loc (EXPR_LOCATION (variant_call_expr),
   18740                 :             :                                             IFN_GOMP_DISPATCH,
   18741                 :          22 :                                             TREE_TYPE (variant_call_expr), 1,
   18742                 :             :                                             variant_call_expr);
   18743                 :          22 :           if (TREE_CODE (dispatch_body) == MODIFY_EXPR)
   18744                 :             :             {
   18745                 :          22 :               variant_call_expr
   18746                 :          22 :                 = build2 (MODIFY_EXPR, TREE_TYPE (dst), dst, variant_call_expr);
   18747                 :             :             }
   18748                 :          22 :           gimplify_and_add (variant_call_expr, &body);
   18749                 :          22 :           gimplify_seq_add_stmt (&body, gimple_build_label (end_label));
   18750                 :             :         }
   18751                 :             :       else
   18752                 :         789 :         gimplify_and_add (OMP_DISPATCH_BODY (expr), &body);
   18753                 :             :     }
   18754                 :             :   else
   18755                 :           8 :     gimplify_and_add (OMP_DISPATCH_BODY (expr), &body);
   18756                 :             : 
   18757                 :             :   // Restore default-device-var ICV
   18758                 :         819 :   if (saved_device_icv != NULL_TREE)
   18759                 :             :     {
   18760                 :         345 :       tree fn = builtin_decl_explicit (BUILT_IN_OMP_SET_DEFAULT_DEVICE);
   18761                 :         345 :       gcall *call = gimple_build_call (fn, 1, saved_device_icv);
   18762                 :         345 :       gimplify_seq_add_stmt (&body, call);
   18763                 :             :     }
   18764                 :             : 
   18765                 :             :   // Wrap dispatch body into a bind
   18766                 :         819 :   gimple *bind = gimple_build_bind (NULL_TREE, body, NULL_TREE);
   18767                 :         819 :   pop_gimplify_context (bind);
   18768                 :             : 
   18769                 :             :   // Manually tear down context created by gimplify_scan_omp_clauses to avoid a
   18770                 :             :   // call to gimplify_adjust_omp_clauses
   18771                 :         819 :   gimplify_omp_ctx *ctx = gimplify_omp_ctxp;
   18772                 :         819 :   if (ctx != NULL)
   18773                 :             :     {
   18774                 :         819 :       gcc_assert (ctx->code == OMP_DISPATCH);
   18775                 :         819 :       gimplify_omp_ctxp = ctx->outer_context;
   18776                 :         819 :       delete_omp_context (ctx);
   18777                 :             :     }
   18778                 :             : 
   18779                 :             :   // Remove nowait as it has no effect on dispatch (OpenMP 5.2), device as it
   18780                 :             :   // has been handled above, and depend as the front end handled it by inserting
   18781                 :             :   // taskwait.
   18782                 :         819 :   tree *dispatch_clauses_ptr = &OMP_DISPATCH_CLAUSES (expr);
   18783                 :        1395 :   for (tree c = *dispatch_clauses_ptr; c; c = *dispatch_clauses_ptr)
   18784                 :             :     {
   18785                 :         959 :       if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NOWAIT
   18786                 :             :           || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
   18787                 :             :           || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEVICE)
   18788                 :             :         {
   18789                 :         383 :           *dispatch_clauses_ptr = OMP_CLAUSE_CHAIN (c);
   18790                 :         383 :           break;
   18791                 :             :         }
   18792                 :             :       else
   18793                 :         576 :         dispatch_clauses_ptr = &OMP_CLAUSE_CHAIN (c);
   18794                 :             :     }
   18795                 :             : 
   18796                 :         819 :   gimple *stmt = gimple_build_omp_dispatch (bind, OMP_DISPATCH_CLAUSES (expr));
   18797                 :         819 :   gimplify_seq_add_stmt (pre_p, stmt);
   18798                 :         819 :   *expr_p = NULL_TREE;
   18799                 :         819 :   return GS_ALL_DONE;
   18800                 :             : }
   18801                 :             : 
   18802                 :             : /* Expand a metadirective that has been resolved at gimplification time
   18803                 :             :    into the candidate directive variants in CANDIDATES.  */
   18804                 :             : 
   18805                 :             : static enum gimplify_status
   18806                 :         158 : expand_omp_metadirective (vec<struct omp_variant> &candidates,
   18807                 :             :                           gimple_seq *pre_p)
   18808                 :             : {
   18809                 :         158 :   auto_vec<tree> selectors;
   18810                 :         158 :   auto_vec<tree> directive_labels;
   18811                 :         158 :   auto_vec<gimple_seq> directive_bodies;
   18812                 :         158 :   tree body_label = NULL_TREE;
   18813                 :         158 :   tree end_label = create_artificial_label (UNKNOWN_LOCATION);
   18814                 :             : 
   18815                 :             :   /* Construct bodies for each candidate.  */
   18816                 :         381 :   for (unsigned i = 0; i < candidates.length(); i++)
   18817                 :             :     {
   18818                 :         223 :       struct omp_variant &candidate = candidates[i];
   18819                 :         223 :       gimple_seq body = NULL;
   18820                 :             : 
   18821                 :         223 :       selectors.safe_push (omp_dynamic_cond (candidate.selector,
   18822                 :             :                                              find_supercontext ()));
   18823                 :         223 :       directive_labels.safe_push (create_artificial_label (UNKNOWN_LOCATION));
   18824                 :             : 
   18825                 :         223 :       gimplify_seq_add_stmt (&body,
   18826                 :         223 :                              gimple_build_label (directive_labels.last ()));
   18827                 :         223 :       if (candidate.alternative != NULL_TREE)
   18828                 :         223 :         gimplify_stmt (&candidate.alternative, &body);
   18829                 :         223 :       if (candidate.body != NULL_TREE)
   18830                 :             :         {
   18831                 :          34 :           if (body_label != NULL_TREE)
   18832                 :           0 :             gimplify_seq_add_stmt (&body, gimple_build_goto (body_label));
   18833                 :             :           else
   18834                 :             :             {
   18835                 :          34 :               body_label = create_artificial_label (UNKNOWN_LOCATION);
   18836                 :          34 :               gimplify_seq_add_stmt (&body, gimple_build_label (body_label));
   18837                 :          34 :               gimplify_stmt (&candidate.body, &body);
   18838                 :             :             }
   18839                 :             :         }
   18840                 :             : 
   18841                 :         223 :       directive_bodies.safe_push (body);
   18842                 :             :     }
   18843                 :             : 
   18844                 :         158 :   auto_vec<tree> cond_labels;
   18845                 :             : 
   18846                 :         158 :   cond_labels.safe_push (NULL_TREE);
   18847                 :         352 :   for (unsigned i = 1; i < candidates.length () - 1; i++)
   18848                 :          18 :     cond_labels.safe_push (create_artificial_label (UNKNOWN_LOCATION));
   18849                 :         158 :   if (candidates.length () > 1)
   18850                 :          47 :     cond_labels.safe_push (directive_labels.last ());
   18851                 :             : 
   18852                 :             :   /* Generate conditionals to test each dynamic selector in turn, executing
   18853                 :             :      the directive candidate if successful.  */
   18854                 :         446 :   for (unsigned i = 0; i < candidates.length () - 1; i++)
   18855                 :             :     {
   18856                 :          65 :       if (i != 0)
   18857                 :          18 :         gimplify_seq_add_stmt (pre_p, gimple_build_label (cond_labels [i]));
   18858                 :             : 
   18859                 :          65 :       enum gimplify_status ret = gimplify_expr (&selectors[i], pre_p, NULL,
   18860                 :             :                                                 is_gimple_val, fb_rvalue);
   18861                 :          65 :       if (ret == GS_ERROR || ret == GS_UNHANDLED)
   18862                 :             :         return ret;
   18863                 :             : 
   18864                 :          65 :       gcond *cond_stmt
   18865                 :          65 :         = gimple_build_cond_from_tree (selectors[i], directive_labels[i],
   18866                 :          65 :                                        cond_labels[i + 1]);
   18867                 :             : 
   18868                 :          65 :       gimplify_seq_add_stmt (pre_p, cond_stmt);
   18869                 :          65 :       gimplify_seq_add_seq (pre_p, directive_bodies[i]);
   18870                 :          65 :       gimplify_seq_add_stmt (pre_p, gimple_build_goto (end_label));
   18871                 :             :     }
   18872                 :             : 
   18873                 :         158 :   gimplify_seq_add_seq (pre_p, directive_bodies.last ());
   18874                 :         158 :   gimplify_seq_add_stmt (pre_p, gimple_build_label (end_label));
   18875                 :             : 
   18876                 :         158 :   return GS_ALL_DONE;
   18877                 :         158 : }
   18878                 :             : 
   18879                 :             : /* Expand a variant construct that requires late resolution in the ompdevlow
   18880                 :             :    pass.  It's a bit easier to do this in tree form and then gimplify that,
   18881                 :             :    than to emit gimple.  The output is going to look something like:
   18882                 :             : 
   18883                 :             :      switch_var = OMP_NEXT_VARIANT (0, state);
   18884                 :             :      loop_label:
   18885                 :             :      switch (switch_var)
   18886                 :             :        {
   18887                 :             :        case 1:
   18888                 :             :          if (dynamic_selector_predicate_1)
   18889                 :             :            {
   18890                 :             :              alternative_1;
   18891                 :             :              goto end_label;
   18892                 :             :            }
   18893                 :             :          else
   18894                 :             :            {
   18895                 :             :              switch_var = OMP_NEXT_VARIANT (1, state);
   18896                 :             :              goto loop_label;
   18897                 :             :            }
   18898                 :             :         case 2:
   18899                 :             :           ...
   18900                 :             :         }
   18901                 :             :       end_label:
   18902                 :             : 
   18903                 :             :   OMP_NEXT_VARIANT is a magic cookie that is replaced with the switch variable
   18904                 :             :   index of the next variant to try, after late resolution.  */
   18905                 :             : 
   18906                 :             : static tree
   18907                 :          16 : expand_late_variant_directive (vec<struct omp_variant> all_candidates,
   18908                 :             :                                tree construct_context)
   18909                 :             : {
   18910                 :          16 :   tree body_label = NULL_TREE;
   18911                 :          16 :   tree standalone_body = NULL_TREE;
   18912                 :          16 :   tree loop_label = create_artificial_label (UNKNOWN_LOCATION);
   18913                 :          16 :   tree end_label = create_artificial_label (UNKNOWN_LOCATION);
   18914                 :          32 :   tree selectors = make_tree_vec (all_candidates.length ());
   18915                 :          16 :   tree switch_body = NULL_TREE;
   18916                 :          16 :   tree switch_var = create_tmp_var (integer_type_node, "variant");
   18917                 :          16 :   tree state = tree_cons (NULL_TREE, construct_context, selectors);
   18918                 :             : 
   18919                 :          92 :   for (unsigned int i = 0; i < all_candidates.length (); i++)
   18920                 :             :     {
   18921                 :          76 :       tree selector = all_candidates[i].selector;
   18922                 :          76 :       tree alternative = all_candidates[i].alternative;
   18923                 :          76 :       tree body = all_candidates[i].body;
   18924                 :          76 :       TREE_VEC_ELT (selectors, i) = selector;
   18925                 :             : 
   18926                 :             :       /* Case label.  Numbering is 1-based.  */
   18927                 :          76 :       tree case_val = build_int_cst (integer_type_node, i + 1);
   18928                 :          76 :       tree case_label
   18929                 :          76 :         = build_case_label (case_val, NULL_TREE,
   18930                 :             :                             create_artificial_label (UNKNOWN_LOCATION));
   18931                 :          76 :       append_to_statement_list (case_label, &switch_body);
   18932                 :             : 
   18933                 :             :       /* The actual body of the variant.  */
   18934                 :          76 :       tree variant_body = NULL_TREE;
   18935                 :          76 :       append_to_statement_list (alternative, &variant_body);
   18936                 :             : 
   18937                 :          76 :       if (body != NULL_TREE)
   18938                 :             :         {
   18939                 :           0 :           if (standalone_body == NULL)
   18940                 :             :             {
   18941                 :           0 :               standalone_body = body;
   18942                 :           0 :               body_label = create_artificial_label (UNKNOWN_LOCATION);
   18943                 :             :             }
   18944                 :           0 :           append_to_statement_list (build1 (GOTO_EXPR, void_type_node,
   18945                 :             :                                             body_label),
   18946                 :             :                                     &variant_body);
   18947                 :             :         }
   18948                 :             :       else
   18949                 :          76 :         append_to_statement_list (build1 (GOTO_EXPR, void_type_node,
   18950                 :             :                                           end_label),
   18951                 :             :                                   &variant_body);
   18952                 :             : 
   18953                 :             :       /* If this is a dynamic selector, wrap variant_body with a conditional.
   18954                 :             :          If the predicate doesn't match, the else clause sets switch_var and
   18955                 :             :          jumps to loop_var to try again.  */
   18956                 :          76 :       tree dynamic_selector = omp_dynamic_cond (selector, find_supercontext ());
   18957                 :          76 :       if (dynamic_selector)
   18958                 :             :         {
   18959                 :          20 :           tree else_stmt = NULL_TREE;
   18960                 :          20 :           tree next = build2 (OMP_NEXT_VARIANT, integer_type_node,
   18961                 :             :                               case_val, state);
   18962                 :          20 :           append_to_statement_list (build2 (MODIFY_EXPR, integer_type_node,
   18963                 :             :                                             switch_var, next),
   18964                 :             :                                     &else_stmt);
   18965                 :          20 :           append_to_statement_list (build1 (GOTO_EXPR, void_type_node,
   18966                 :             :                                             loop_label),
   18967                 :             :                                     &else_stmt);
   18968                 :          20 :           variant_body = build3 (COND_EXPR, void_type_node, dynamic_selector,
   18969                 :             :                                  variant_body, else_stmt);
   18970                 :             :         }
   18971                 :          76 :       append_to_statement_list (variant_body, &switch_body);
   18972                 :             :     }
   18973                 :             : 
   18974                 :             :   /* Put it all together.  */
   18975                 :          16 :   tree result = NULL_TREE;
   18976                 :          16 :   tree first = build2 (OMP_NEXT_VARIANT, integer_type_node, integer_zero_node,
   18977                 :             :                        state);
   18978                 :          16 :   append_to_statement_list (build2 (MODIFY_EXPR, integer_type_node,
   18979                 :             :                                     switch_var, first),
   18980                 :             :                             &result);
   18981                 :          16 :   append_to_statement_list (build1 (LABEL_EXPR, void_type_node, loop_label),
   18982                 :             :                             &result);
   18983                 :          16 :   append_to_statement_list (build2 (SWITCH_EXPR, integer_type_node,
   18984                 :             :                                     switch_var, switch_body),
   18985                 :             :                             &result);
   18986                 :          16 :   if (standalone_body)
   18987                 :             :     {
   18988                 :           0 :       append_to_statement_list (build1 (LABEL_EXPR, void_type_node,
   18989                 :             :                                         body_label),
   18990                 :             :                                 &result);
   18991                 :           0 :       append_to_statement_list (standalone_body, &result);
   18992                 :             :     }
   18993                 :          16 :   append_to_statement_list (build1 (LABEL_EXPR, void_type_node, end_label),
   18994                 :             :                             &result);
   18995                 :          16 :   cgraph_node::get (cfun->decl)->has_omp_variant_constructs = 1;
   18996                 :          16 :   return result;
   18997                 :             : }
   18998                 :             : 
   18999                 :             : 
   19000                 :             : /* Gimplify an OMP_METADIRECTIVE construct.   EXPR is the tree version.
   19001                 :             :    The metadirective will be resolved at this point if possible, otherwise
   19002                 :             :    a GIMPLE_OMP_VARIANT_CONSTRUCT is created.  */
   19003                 :             : 
   19004                 :             : static enum gimplify_status
   19005                 :         162 : gimplify_omp_metadirective (tree *expr_p, gimple_seq *pre_p, gimple_seq *,
   19006                 :             :                             bool (*) (tree), fallback_t)
   19007                 :             : {
   19008                 :             :   /* Try to resolve the metadirective.  */
   19009                 :         162 :   tree construct_context = omp_get_construct_context ();
   19010                 :         162 :   vec<struct omp_variant> all_candidates
   19011                 :         162 :     = omp_metadirective_candidates (*expr_p, construct_context);
   19012                 :         162 :   vec<struct omp_variant> candidates
   19013                 :         162 :     = omp_get_dynamic_candidates (all_candidates, construct_context);
   19014                 :         162 :   if (!candidates.is_empty ())
   19015                 :         158 :     return expand_omp_metadirective (candidates, pre_p);
   19016                 :             : 
   19017                 :             :   /* The metadirective cannot be resolved yet.  Turn it into a loop with
   19018                 :             :      a nested switch statement, using OMP_NEXT_VARIANT to set the control
   19019                 :             :      variable for the switch.  */
   19020                 :           4 :   *expr_p = expand_late_variant_directive (all_candidates, construct_context);
   19021                 :           4 :   return GS_OK;
   19022                 :             : }
   19023                 :             : 
   19024                 :             : /* Convert the GENERIC expression tree *EXPR_P to GIMPLE.  If the
   19025                 :             :    expression produces a value to be used as an operand inside a GIMPLE
   19026                 :             :    statement, the value will be stored back in *EXPR_P.  This value will
   19027                 :             :    be a tree of class tcc_declaration, tcc_constant, tcc_reference or
   19028                 :             :    an SSA_NAME.  The corresponding sequence of GIMPLE statements is
   19029                 :             :    emitted in PRE_P and POST_P.
   19030                 :             : 
   19031                 :             :    Additionally, this process may overwrite parts of the input
   19032                 :             :    expression during gimplification.  Ideally, it should be
   19033                 :             :    possible to do non-destructive gimplification.
   19034                 :             : 
   19035                 :             :    EXPR_P points to the GENERIC expression to convert to GIMPLE.  If
   19036                 :             :       the expression needs to evaluate to a value to be used as
   19037                 :             :       an operand in a GIMPLE statement, this value will be stored in
   19038                 :             :       *EXPR_P on exit.  This happens when the caller specifies one
   19039                 :             :       of fb_lvalue or fb_rvalue fallback flags.
   19040                 :             : 
   19041                 :             :    PRE_P will contain the sequence of GIMPLE statements corresponding
   19042                 :             :        to the evaluation of EXPR and all the side-effects that must
   19043                 :             :        be executed before the main expression.  On exit, the last
   19044                 :             :        statement of PRE_P is the core statement being gimplified.  For
   19045                 :             :        instance, when gimplifying 'if (++a)' the last statement in
   19046                 :             :        PRE_P will be 'if (t.1)' where t.1 is the result of
   19047                 :             :        pre-incrementing 'a'.
   19048                 :             : 
   19049                 :             :    POST_P will contain the sequence of GIMPLE statements corresponding
   19050                 :             :        to the evaluation of all the side-effects that must be executed
   19051                 :             :        after the main expression.  If this is NULL, the post
   19052                 :             :        side-effects are stored at the end of PRE_P.
   19053                 :             : 
   19054                 :             :        The reason why the output is split in two is to handle post
   19055                 :             :        side-effects explicitly.  In some cases, an expression may have
   19056                 :             :        inner and outer post side-effects which need to be emitted in
   19057                 :             :        an order different from the one given by the recursive
   19058                 :             :        traversal.  For instance, for the expression (*p--)++ the post
   19059                 :             :        side-effects of '--' must actually occur *after* the post
   19060                 :             :        side-effects of '++'.  However, gimplification will first visit
   19061                 :             :        the inner expression, so if a separate POST sequence was not
   19062                 :             :        used, the resulting sequence would be:
   19063                 :             : 
   19064                 :             :             1   t.1 = *p
   19065                 :             :             2   p = p - 1
   19066                 :             :             3   t.2 = t.1 + 1
   19067                 :             :             4   *p = t.2
   19068                 :             : 
   19069                 :             :        However, the post-decrement operation in line #2 must not be
   19070                 :             :        evaluated until after the store to *p at line #4, so the
   19071                 :             :        correct sequence should be:
   19072                 :             : 
   19073                 :             :             1   t.1 = *p
   19074                 :             :             2   t.2 = t.1 + 1
   19075                 :             :             3   *p = t.2
   19076                 :             :             4   p = p - 1
   19077                 :             : 
   19078                 :             :        So, by specifying a separate post queue, it is possible
   19079                 :             :        to emit the post side-effects in the correct order.
   19080                 :             :        If POST_P is NULL, an internal queue will be used.  Before
   19081                 :             :        returning to the caller, the sequence POST_P is appended to
   19082                 :             :        the main output sequence PRE_P.
   19083                 :             : 
   19084                 :             :    GIMPLE_TEST_F points to a function that takes a tree T and
   19085                 :             :        returns nonzero if T is in the GIMPLE form requested by the
   19086                 :             :        caller.  The GIMPLE predicates are in gimple.cc.
   19087                 :             : 
   19088                 :             :    FALLBACK tells the function what sort of a temporary we want if
   19089                 :             :        gimplification cannot produce an expression that complies with
   19090                 :             :        GIMPLE_TEST_F.
   19091                 :             : 
   19092                 :             :        fb_none means that no temporary should be generated
   19093                 :             :        fb_rvalue means that an rvalue is OK to generate
   19094                 :             :        fb_lvalue means that an lvalue is OK to generate
   19095                 :             :        fb_either means that either is OK, but an lvalue is preferable.
   19096                 :             :        fb_mayfail means that gimplification may fail (in which case
   19097                 :             :        GS_ERROR will be returned)
   19098                 :             : 
   19099                 :             :    The return value is either GS_ERROR or GS_ALL_DONE, since this
   19100                 :             :    function iterates until EXPR is completely gimplified or an error
   19101                 :             :    occurs.  */
   19102                 :             : 
   19103                 :             : enum gimplify_status
   19104                 :   491931908 : gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
   19105                 :             :                bool (*gimple_test_f) (tree), fallback_t fallback)
   19106                 :             : {
   19107                 :   491931908 :   tree tmp;
   19108                 :   491931908 :   gimple_seq internal_pre = NULL;
   19109                 :   491931908 :   gimple_seq internal_post = NULL;
   19110                 :   491931908 :   tree save_expr;
   19111                 :   491931908 :   bool is_statement;
   19112                 :   491931908 :   location_t saved_location;
   19113                 :   491931908 :   enum gimplify_status ret;
   19114                 :   491931908 :   gimple_stmt_iterator pre_last_gsi, post_last_gsi;
   19115                 :   491931908 :   tree label;
   19116                 :             : 
   19117                 :   491931908 :   save_expr = *expr_p;
   19118                 :   491931908 :   if (save_expr == NULL_TREE)
   19119                 :             :     return GS_ALL_DONE;
   19120                 :             : 
   19121                 :             :   /* If we are gimplifying a top-level statement, PRE_P must be valid.  */
   19122                 :   442844212 :   is_statement = gimple_test_f == is_gimple_stmt;
   19123                 :   442844212 :   if (is_statement)
   19124                 :    96978689 :     gcc_assert (pre_p);
   19125                 :             : 
   19126                 :             :   /* Consistency checks.  */
   19127                 :   442844212 :   if (gimple_test_f == is_gimple_reg)
   19128                 :     6154186 :     gcc_assert (fallback & (fb_rvalue | fb_lvalue));
   19129                 :   436690026 :   else if (gimple_test_f == is_gimple_val
   19130                 :   322503589 :            || gimple_test_f == is_gimple_call_addr
   19131                 :   307263224 :            || gimple_test_f == is_gimple_condexpr_for_cond
   19132                 :   301952819 :            || gimple_test_f == is_gimple_mem_rhs
   19133                 :   301810711 :            || gimple_test_f == is_gimple_mem_rhs_or_call
   19134                 :   291291929 :            || gimple_test_f == is_gimple_reg_rhs
   19135                 :   290721125 :            || gimple_test_f == is_gimple_reg_rhs_or_call
   19136                 :   221983528 :            || gimple_test_f == is_gimple_asm_val
   19137                 :   221945845 :            || gimple_test_f == is_gimple_mem_ref_addr)
   19138                 :   229494405 :     gcc_assert (fallback & fb_rvalue);
   19139                 :   207195621 :   else if (gimple_test_f == is_gimple_min_lval
   19140                 :   178558738 :            || gimple_test_f == is_gimple_lvalue)
   19141                 :    79685548 :     gcc_assert (fallback & fb_lvalue);
   19142                 :   127510073 :   else if (gimple_test_f == is_gimple_addressable)
   19143                 :    30531384 :     gcc_assert (fallback & fb_either);
   19144                 :    96978689 :   else if (gimple_test_f == is_gimple_stmt)
   19145                 :    96978689 :     gcc_assert (fallback == fb_none);
   19146                 :             :   else
   19147                 :             :     {
   19148                 :             :       /* We should have recognized the GIMPLE_TEST_F predicate to
   19149                 :             :          know what kind of fallback to use in case a temporary is
   19150                 :             :          needed to hold the value or address of *EXPR_P.  */
   19151                 :           0 :       gcc_unreachable ();
   19152                 :             :     }
   19153                 :             : 
   19154                 :             :   /* We used to check the predicate here and return immediately if it
   19155                 :             :      succeeds.  This is wrong; the design is for gimplification to be
   19156                 :             :      idempotent, and for the predicates to only test for valid forms, not
   19157                 :             :      whether they are fully simplified.  */
   19158                 :   442844212 :   if (pre_p == NULL)
   19159                 :           0 :     pre_p = &internal_pre;
   19160                 :             : 
   19161                 :   442844212 :   if (post_p == NULL)
   19162                 :   177833292 :     post_p = &internal_post;
   19163                 :             : 
   19164                 :             :   /* Remember the last statements added to PRE_P and POST_P.  Every
   19165                 :             :      new statement added by the gimplification helpers needs to be
   19166                 :             :      annotated with location information.  To centralize the
   19167                 :             :      responsibility, we remember the last statement that had been
   19168                 :             :      added to both queues before gimplifying *EXPR_P.  If
   19169                 :             :      gimplification produces new statements in PRE_P and POST_P, those
   19170                 :             :      statements will be annotated with the same location information
   19171                 :             :      as *EXPR_P.  */
   19172                 :   442844212 :   pre_last_gsi = gsi_last (*pre_p);
   19173                 :   442844212 :   post_last_gsi = gsi_last (*post_p);
   19174                 :             : 
   19175                 :   442844212 :   saved_location = input_location;
   19176                 :   442844212 :   if (save_expr != error_mark_node
   19177                 :   442844212 :       && EXPR_HAS_LOCATION (*expr_p))
   19178                 :   166033674 :     input_location = EXPR_LOCATION (*expr_p);
   19179                 :             : 
   19180                 :             :   /* Loop over the specific gimplifiers until the toplevel node
   19181                 :             :      remains the same.  */
   19182                 :   460363582 :   do
   19183                 :             :     {
   19184                 :             :       /* Strip away as many useless type conversions as possible
   19185                 :             :          at the toplevel.  */
   19186                 :   460363582 :       STRIP_USELESS_TYPE_CONVERSION (*expr_p);
   19187                 :             : 
   19188                 :             :       /* Remember the expr.  */
   19189                 :   460363582 :       save_expr = *expr_p;
   19190                 :             : 
   19191                 :             :       /* Die, die, die, my darling.  */
   19192                 :   460363582 :       if (error_operand_p (save_expr))
   19193                 :             :         {
   19194                 :             :           ret = GS_ERROR;
   19195                 :             :           break;
   19196                 :             :         }
   19197                 :             : 
   19198                 :             :       /* Do any language-specific gimplification.  */
   19199                 :   460360132 :       ret = ((enum gimplify_status)
   19200                 :   460360132 :              lang_hooks.gimplify_expr (expr_p, pre_p, post_p));
   19201                 :   460360132 :       if (ret == GS_OK)
   19202                 :             :         {
   19203                 :    26098115 :           if (*expr_p == NULL_TREE)
   19204                 :             :             break;
   19205                 :    26098115 :           if (*expr_p != save_expr)
   19206                 :     4612543 :             continue;
   19207                 :             :         }
   19208                 :   434262017 :       else if (ret != GS_UNHANDLED)
   19209                 :             :         break;
   19210                 :             : 
   19211                 :             :       /* Make sure that all the cases set 'ret' appropriately.  */
   19212                 :   455193071 :       ret = GS_UNHANDLED;
   19213                 :   455193071 :       switch (TREE_CODE (*expr_p))
   19214                 :             :         {
   19215                 :             :           /* First deal with the special cases.  */
   19216                 :             : 
   19217                 :     1112804 :         case POSTINCREMENT_EXPR:
   19218                 :     1112804 :         case POSTDECREMENT_EXPR:
   19219                 :     1112804 :         case PREINCREMENT_EXPR:
   19220                 :     1112804 :         case PREDECREMENT_EXPR:
   19221                 :     2225608 :           ret = gimplify_self_mod_expr (expr_p, pre_p, post_p,
   19222                 :             :                                         fallback != fb_none,
   19223                 :     1112804 :                                         TREE_TYPE (*expr_p));
   19224                 :     1112804 :           break;
   19225                 :             : 
   19226                 :      639841 :         case VIEW_CONVERT_EXPR:
   19227                 :      639841 :           if ((fallback & fb_rvalue)
   19228                 :      639730 :               && is_gimple_reg_type (TREE_TYPE (*expr_p))
   19229                 :     1105726 :               && is_gimple_reg_type (TREE_TYPE (TREE_OPERAND (*expr_p, 0))))
   19230                 :             :             {
   19231                 :      455198 :               ret = gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p,
   19232                 :             :                                    post_p, is_gimple_val, fb_rvalue);
   19233                 :      455198 :               recalculate_side_effects (*expr_p);
   19234                 :      455198 :               break;
   19235                 :             :             }
   19236                 :             :           /* Fallthru.  */
   19237                 :             : 
   19238                 :    28574885 :         case ARRAY_REF:
   19239                 :    28574885 :         case ARRAY_RANGE_REF:
   19240                 :    28574885 :         case REALPART_EXPR:
   19241                 :    28574885 :         case IMAGPART_EXPR:
   19242                 :    28574885 :         case COMPONENT_REF:
   19243                 :    28574885 :           ret = gimplify_compound_lval (expr_p, pre_p, post_p,
   19244                 :             :                                         fallback ? fallback : fb_rvalue);
   19245                 :    28574885 :           break;
   19246                 :             : 
   19247                 :     5910709 :         case COND_EXPR:
   19248                 :     5910709 :           ret = gimplify_cond_expr (expr_p, pre_p, fallback);
   19249                 :             : 
   19250                 :             :           /* C99 code may assign to an array in a structure value of a
   19251                 :             :              conditional expression, and this has undefined behavior
   19252                 :             :              only on execution, so create a temporary if an lvalue is
   19253                 :             :              required.  */
   19254                 :     5910709 :           if (fallback == fb_lvalue)
   19255                 :             :             {
   19256                 :           7 :               *expr_p = get_initialized_tmp_var (*expr_p, pre_p, post_p, false);
   19257                 :           7 :               mark_addressable (*expr_p);
   19258                 :           7 :               ret = GS_OK;
   19259                 :             :             }
   19260                 :             :           break;
   19261                 :             : 
   19262                 :    15613227 :         case CALL_EXPR:
   19263                 :    15613227 :           ret = gimplify_call_expr (expr_p, pre_p, fallback);
   19264                 :             : 
   19265                 :             :           /* C99 code may assign to an array in a structure returned
   19266                 :             :              from a function, and this has undefined behavior only on
   19267                 :             :              execution, so create a temporary if an lvalue is
   19268                 :             :              required.  */
   19269                 :    15613227 :           if (fallback == fb_lvalue)
   19270                 :             :             {
   19271                 :       14145 :               *expr_p = get_initialized_tmp_var (*expr_p, pre_p, post_p, false);
   19272                 :       14145 :               mark_addressable (*expr_p);
   19273                 :       14145 :               ret = GS_OK;
   19274                 :             :             }
   19275                 :             :           break;
   19276                 :             : 
   19277                 :           0 :         case TREE_LIST:
   19278                 :           0 :           gcc_unreachable ();
   19279                 :             : 
   19280                 :           0 :         case OMP_ARRAY_SECTION:
   19281                 :           0 :           gcc_unreachable ();
   19282                 :             : 
   19283                 :      368010 :         case COMPOUND_EXPR:
   19284                 :      368010 :           ret = gimplify_compound_expr (expr_p, pre_p, fallback != fb_none);
   19285                 :      368010 :           break;
   19286                 :             : 
   19287                 :       36527 :         case COMPOUND_LITERAL_EXPR:
   19288                 :       36527 :           ret = gimplify_compound_literal_expr (expr_p, pre_p,
   19289                 :             :                                                 gimple_test_f, fallback);
   19290                 :       36527 :           break;
   19291                 :             : 
   19292                 :    47877043 :         case MODIFY_EXPR:
   19293                 :    47877043 :         case INIT_EXPR:
   19294                 :    47877043 :           ret = gimplify_modify_expr (expr_p, pre_p, post_p,
   19295                 :             :                                       fallback != fb_none);
   19296                 :    47877043 :           break;
   19297                 :             : 
   19298                 :      110339 :         case TRUTH_ANDIF_EXPR:
   19299                 :      110339 :         case TRUTH_ORIF_EXPR:
   19300                 :      110339 :           {
   19301                 :             :             /* Preserve the original type of the expression and the
   19302                 :             :                source location of the outer expression.  */
   19303                 :      110339 :             tree org_type = TREE_TYPE (*expr_p);
   19304                 :      110339 :             *expr_p = gimple_boolify (*expr_p);
   19305                 :      110339 :             *expr_p = build3_loc (input_location, COND_EXPR,
   19306                 :             :                                   org_type, *expr_p,
   19307                 :             :                                   fold_convert_loc
   19308                 :             :                                     (input_location,
   19309                 :             :                                      org_type, boolean_true_node),
   19310                 :             :                                   fold_convert_loc
   19311                 :             :                                     (input_location,
   19312                 :             :                                      org_type, boolean_false_node));
   19313                 :      110339 :             ret = GS_OK;
   19314                 :      110339 :             break;
   19315                 :             :           }
   19316                 :             : 
   19317                 :      236182 :         case TRUTH_NOT_EXPR:
   19318                 :      236182 :           {
   19319                 :      236182 :             tree type = TREE_TYPE (*expr_p);
   19320                 :             :             /* The parsers are careful to generate TRUTH_NOT_EXPR
   19321                 :             :                only with operands that are always zero or one.
   19322                 :             :                We do not fold here but handle the only interesting case
   19323                 :             :                manually, as fold may re-introduce the TRUTH_NOT_EXPR.  */
   19324                 :      236182 :             *expr_p = gimple_boolify (*expr_p);
   19325                 :      236182 :             if (TYPE_PRECISION (TREE_TYPE (*expr_p)) == 1)
   19326                 :      236182 :               *expr_p = build1_loc (input_location, BIT_NOT_EXPR,
   19327                 :      236182 :                                     TREE_TYPE (*expr_p),
   19328                 :      236182 :                                     TREE_OPERAND (*expr_p, 0));
   19329                 :             :             else
   19330                 :           0 :               *expr_p = build2_loc (input_location, BIT_XOR_EXPR,
   19331                 :           0 :                                     TREE_TYPE (*expr_p),
   19332                 :           0 :                                     TREE_OPERAND (*expr_p, 0),
   19333                 :           0 :                                     build_int_cst (TREE_TYPE (*expr_p), 1));
   19334                 :      236182 :             if (!useless_type_conversion_p (type, TREE_TYPE (*expr_p)))
   19335                 :        5618 :               *expr_p = fold_convert_loc (input_location, type, *expr_p);
   19336                 :             :             ret = GS_OK;
   19337                 :             :             break;
   19338                 :             :           }
   19339                 :             : 
   19340                 :    30603020 :         case ADDR_EXPR:
   19341                 :    30603020 :           ret = gimplify_addr_expr (expr_p, pre_p, post_p);
   19342                 :    30603020 :           break;
   19343                 :             : 
   19344                 :        4992 :         case ANNOTATE_EXPR:
   19345                 :        4992 :           {
   19346                 :        4992 :             tree cond = TREE_OPERAND (*expr_p, 0);
   19347                 :        4992 :             tree kind = TREE_OPERAND (*expr_p, 1);
   19348                 :        4992 :             tree data = TREE_OPERAND (*expr_p, 2);
   19349                 :        4992 :             tree type = TREE_TYPE (cond);
   19350                 :        4992 :             if (!INTEGRAL_TYPE_P (type))
   19351                 :             :               {
   19352                 :           0 :                 *expr_p = cond;
   19353                 :           0 :                 ret = GS_OK;
   19354                 :           0 :                 break;
   19355                 :             :               }
   19356                 :        4992 :             tree tmp = create_tmp_var (type);
   19357                 :        4992 :             gimplify_arg (&cond, pre_p, EXPR_LOCATION (*expr_p));
   19358                 :        4992 :             gcall *call
   19359                 :        4992 :               = gimple_build_call_internal (IFN_ANNOTATE, 3, cond, kind, data);
   19360                 :        4992 :             gimple_call_set_lhs (call, tmp);
   19361                 :        4992 :             gimplify_seq_add_stmt (pre_p, call);
   19362                 :        4992 :             *expr_p = tmp;
   19363                 :        4992 :             ret = GS_ALL_DONE;
   19364                 :        4992 :             break;
   19365                 :             :           }
   19366                 :             : 
   19367                 :       50788 :         case VA_ARG_EXPR:
   19368                 :       50788 :           ret = gimplify_va_arg_expr (expr_p, pre_p, post_p);
   19369                 :       50788 :           break;
   19370                 :             : 
   19371                 :    16859801 :         CASE_CONVERT:
   19372                 :    16859801 :           if (IS_EMPTY_STMT (*expr_p))
   19373                 :             :             {
   19374                 :             :               ret = GS_ALL_DONE;
   19375                 :             :               break;
   19376                 :             :             }
   19377                 :             : 
   19378                 :    15202782 :           if (VOID_TYPE_P (TREE_TYPE (*expr_p))
   19379                 :    15202782 :               || fallback == fb_none)
   19380                 :             :             {
   19381                 :             :               /* Just strip a conversion to void (or in void context) and
   19382                 :             :                  try again.  */
   19383                 :     2527342 :               *expr_p = TREE_OPERAND (*expr_p, 0);
   19384                 :     2527342 :               ret = GS_OK;
   19385                 :     2527342 :               break;
   19386                 :             :             }
   19387                 :             : 
   19388                 :    12675440 :           ret = gimplify_conversion (expr_p);
   19389                 :    12675440 :           if (ret == GS_ERROR)
   19390                 :             :             break;
   19391                 :    12675440 :           if (*expr_p != save_expr)
   19392                 :             :             break;
   19393                 :             :           /* FALLTHRU */
   19394                 :             : 
   19395                 :    12800440 :         case FIX_TRUNC_EXPR:
   19396                 :             :           /* unary_expr: ... | '(' cast ')' val | ...  */
   19397                 :    12800440 :           ret = gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p,
   19398                 :             :                                is_gimple_val, fb_rvalue);
   19399                 :    12800440 :           recalculate_side_effects (*expr_p);
   19400                 :    12800440 :           break;
   19401                 :             : 
   19402                 :     6093014 :         case INDIRECT_REF:
   19403                 :     6093014 :           {
   19404                 :     6093014 :             bool volatilep = TREE_THIS_VOLATILE (*expr_p);
   19405                 :     6093014 :             bool notrap = TREE_THIS_NOTRAP (*expr_p);
   19406                 :     6093014 :             tree saved_ptr_type = TREE_TYPE (TREE_OPERAND (*expr_p, 0));
   19407                 :             : 
   19408                 :     6093014 :             *expr_p = fold_indirect_ref_loc (input_location, *expr_p);
   19409                 :     6093014 :             if (*expr_p != save_expr)
   19410                 :             :               {
   19411                 :             :                 ret = GS_OK;
   19412                 :             :                 break;
   19413                 :             :               }
   19414                 :             : 
   19415                 :     6078315 :             ret = gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p,
   19416                 :             :                                  is_gimple_reg, fb_rvalue);
   19417                 :     6078315 :             if (ret == GS_ERROR)
   19418                 :             :               break;
   19419                 :             : 
   19420                 :     6078314 :             recalculate_side_effects (*expr_p);
   19421                 :     6078314 :             *expr_p = fold_build2_loc (input_location, MEM_REF,
   19422                 :     6078314 :                                        TREE_TYPE (*expr_p),
   19423                 :     6078314 :                                        TREE_OPERAND (*expr_p, 0),
   19424                 :     6078314 :                                        build_int_cst (saved_ptr_type, 0));
   19425                 :     6078314 :             TREE_THIS_VOLATILE (*expr_p) = volatilep;
   19426                 :     6078314 :             TREE_THIS_NOTRAP (*expr_p) = notrap;
   19427                 :     6078314 :             ret = GS_OK;
   19428                 :     6078314 :             break;
   19429                 :             :           }
   19430                 :             : 
   19431                 :             :         /* We arrive here through the various re-gimplifcation paths.  */
   19432                 :    15257403 :         case MEM_REF:
   19433                 :             :           /* First try re-folding the whole thing.  */
   19434                 :    15257403 :           tmp = fold_binary (MEM_REF, TREE_TYPE (*expr_p),
   19435                 :             :                              TREE_OPERAND (*expr_p, 0),
   19436                 :             :                              TREE_OPERAND (*expr_p, 1));
   19437                 :    15257403 :           if (tmp)
   19438                 :             :             {
   19439                 :        2870 :               REF_REVERSE_STORAGE_ORDER (tmp)
   19440                 :        2870 :                 = REF_REVERSE_STORAGE_ORDER (*expr_p);
   19441                 :        2870 :               *expr_p = tmp;
   19442                 :        2870 :               recalculate_side_effects (*expr_p);
   19443                 :        2870 :               ret = GS_OK;
   19444                 :        2870 :               break;
   19445                 :             :             }
   19446                 :             :           /* Avoid re-gimplifying the address operand if it is already
   19447                 :             :              in suitable form.  Re-gimplifying would mark the address
   19448                 :             :              operand addressable.  Always gimplify when not in SSA form
   19449                 :             :              as we still may have to gimplify decls with value-exprs.  */
   19450                 :    15254533 :           if (!gimplify_ctxp || !gimple_in_ssa_p (cfun)
   19451                 :    16245184 :               || !is_gimple_mem_ref_addr (TREE_OPERAND (*expr_p, 0)))
   19452                 :             :             {
   19453                 :    14318390 :               ret = gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p,
   19454                 :             :                                    is_gimple_mem_ref_addr, fb_rvalue);
   19455                 :    14318390 :               if (ret == GS_ERROR)
   19456                 :             :                 break;
   19457                 :             :             }
   19458                 :    15254533 :           recalculate_side_effects (*expr_p);
   19459                 :    15254533 :           ret = GS_ALL_DONE;
   19460                 :    15254533 :           break;
   19461                 :             : 
   19462                 :             :         /* Constants need not be gimplified.  */
   19463                 :    41262104 :         case INTEGER_CST:
   19464                 :    41262104 :         case REAL_CST:
   19465                 :    41262104 :         case FIXED_CST:
   19466                 :    41262104 :         case STRING_CST:
   19467                 :    41262104 :         case COMPLEX_CST:
   19468                 :    41262104 :         case VECTOR_CST:
   19469                 :             :           /* Drop the overflow flag on constants, we do not want
   19470                 :             :              that in the GIMPLE IL.  */
   19471                 :    41262104 :           if (TREE_OVERFLOW_P (*expr_p))
   19472                 :         796 :             *expr_p = drop_tree_overflow (*expr_p);
   19473                 :             :           ret = GS_ALL_DONE;
   19474                 :             :           break;
   19475                 :             : 
   19476                 :      115362 :         case CONST_DECL:
   19477                 :             :           /* If we require an lvalue, such as for ADDR_EXPR, retain the
   19478                 :             :              CONST_DECL node.  Otherwise the decl is replaceable by its
   19479                 :             :              value.  */
   19480                 :             :           /* ??? Should be == fb_lvalue, but ADDR_EXPR passes fb_either.  */
   19481                 :      115362 :           if (fallback & fb_lvalue)
   19482                 :             :             ret = GS_ALL_DONE;
   19483                 :             :           else
   19484                 :             :             {
   19485                 :        3768 :               *expr_p = DECL_INITIAL (*expr_p);
   19486                 :        3768 :               ret = GS_OK;
   19487                 :             :             }
   19488                 :             :           break;
   19489                 :             : 
   19490                 :     6310062 :         case DECL_EXPR:
   19491                 :     6310062 :           ret = gimplify_decl_expr (expr_p, pre_p);
   19492                 :     6310062 :           break;
   19493                 :             : 
   19494                 :     5750961 :         case BIND_EXPR:
   19495                 :     5750961 :           ret = gimplify_bind_expr (expr_p, pre_p);
   19496                 :     5750961 :           break;
   19497                 :             : 
   19498                 :      184102 :         case LOOP_EXPR:
   19499                 :      184102 :           ret = gimplify_loop_expr (expr_p, pre_p);
   19500                 :      184102 :           break;
   19501                 :             : 
   19502                 :       48637 :         case SWITCH_EXPR:
   19503                 :       48637 :           ret = gimplify_switch_expr (expr_p, pre_p);
   19504                 :       48637 :           break;
   19505                 :             : 
   19506                 :        2939 :         case EXIT_EXPR:
   19507                 :        2939 :           ret = gimplify_exit_expr (expr_p);
   19508                 :        2939 :           break;
   19509                 :             : 
   19510                 :     1054604 :         case GOTO_EXPR:
   19511                 :             :           /* If the target is not LABEL, then it is a computed jump
   19512                 :             :              and the target needs to be gimplified.  */
   19513                 :     1054604 :           if (TREE_CODE (GOTO_DESTINATION (*expr_p)) != LABEL_DECL)
   19514                 :             :             {
   19515                 :        1082 :               ret = gimplify_expr (&GOTO_DESTINATION (*expr_p), pre_p,
   19516                 :             :                                    NULL, is_gimple_val, fb_rvalue);
   19517                 :        1082 :               if (ret == GS_ERROR)
   19518                 :             :                 break;
   19519                 :             :             }
   19520                 :     2109206 :           gimplify_seq_add_stmt (pre_p,
   19521                 :     1054603 :                           gimple_build_goto (GOTO_DESTINATION (*expr_p)));
   19522                 :     1054603 :           ret = GS_ALL_DONE;
   19523                 :     1054603 :           break;
   19524                 :             : 
   19525                 :      103249 :         case PREDICT_EXPR:
   19526                 :      412996 :           gimplify_seq_add_stmt (pre_p,
   19527                 :      103249 :                         gimple_build_predict (PREDICT_EXPR_PREDICTOR (*expr_p),
   19528                 :      103249 :                                               PREDICT_EXPR_OUTCOME (*expr_p)));
   19529                 :      103249 :           ret = GS_ALL_DONE;
   19530                 :      103249 :           break;
   19531                 :             : 
   19532                 :     2407302 :         case LABEL_EXPR:
   19533                 :     2407302 :           ret = gimplify_label_expr (expr_p, pre_p);
   19534                 :     2407302 :           label = LABEL_EXPR_LABEL (*expr_p);
   19535                 :     2407302 :           gcc_assert (decl_function_context (label) == current_function_decl);
   19536                 :             : 
   19537                 :             :           /* If the label is used in a goto statement, or address of the label
   19538                 :             :              is taken, we need to unpoison all variables that were seen so far.
   19539                 :             :              Doing so would prevent us from reporting a false positives.  */
   19540                 :     2407302 :           if (asan_poisoned_variables
   19541                 :        2511 :               && asan_used_labels != NULL
   19542                 :         272 :               && asan_used_labels->contains (label)
   19543                 :     2407481 :               && !gimplify_omp_ctxp)
   19544                 :         171 :             asan_poison_variables (asan_poisoned_variables, false, pre_p);
   19545                 :             :           break;
   19546                 :             : 
   19547                 :     1047343 :         case CASE_LABEL_EXPR:
   19548                 :     1047343 :           ret = gimplify_case_label_expr (expr_p, pre_p);
   19549                 :             : 
   19550                 :     1047343 :           if (gimplify_ctxp->live_switch_vars)
   19551                 :     1047156 :             asan_poison_variables (gimplify_ctxp->live_switch_vars, false,
   19552                 :             :                                    pre_p);
   19553                 :             :           break;
   19554                 :             : 
   19555                 :     2070234 :         case RETURN_EXPR:
   19556                 :     2070234 :           ret = gimplify_return_expr (*expr_p, pre_p);
   19557                 :     2070234 :           break;
   19558                 :             : 
   19559                 :      908000 :         case CONSTRUCTOR:
   19560                 :             :           /* Don't reduce this in place; let gimplify_init_constructor work its
   19561                 :             :              magic.  Buf if we're just elaborating this for side effects, just
   19562                 :             :              gimplify any element that has side-effects.  */
   19563                 :      908000 :           if (fallback == fb_none)
   19564                 :             :             {
   19565                 :         275 :               unsigned HOST_WIDE_INT ix;
   19566                 :         275 :               tree val;
   19567                 :         275 :               tree temp = NULL_TREE;
   19568                 :         291 :               FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (*expr_p), ix, val)
   19569                 :          16 :                 if (TREE_SIDE_EFFECTS (val))
   19570                 :           4 :                   append_to_statement_list (val, &temp);
   19571                 :             : 
   19572                 :         275 :               *expr_p = temp;
   19573                 :         275 :               ret = temp ? GS_OK : GS_ALL_DONE;
   19574                 :             :             }
   19575                 :             :           /* C99 code may assign to an array in a constructed
   19576                 :             :              structure or union, and this has undefined behavior only
   19577                 :             :              on execution, so create a temporary if an lvalue is
   19578                 :             :              required.  */
   19579                 :      907725 :           else if (fallback == fb_lvalue)
   19580                 :             :             {
   19581                 :           3 :               *expr_p = get_initialized_tmp_var (*expr_p, pre_p, post_p, false);
   19582                 :           3 :               mark_addressable (*expr_p);
   19583                 :           3 :               ret = GS_OK;
   19584                 :             :             }
   19585                 :             :           else
   19586                 :             :             ret = GS_ALL_DONE;
   19587                 :             :           break;
   19588                 :             : 
   19589                 :             :           /* The following are special cases that are not handled by the
   19590                 :             :              original GIMPLE grammar.  */
   19591                 :             : 
   19592                 :             :           /* SAVE_EXPR nodes are converted into a GIMPLE identifier and
   19593                 :             :              eliminated.  */
   19594                 :      407841 :         case SAVE_EXPR:
   19595                 :      407841 :           ret = gimplify_save_expr (expr_p, pre_p, post_p);
   19596                 :      407841 :           break;
   19597                 :             : 
   19598                 :      398564 :         case BIT_FIELD_REF:
   19599                 :      398564 :           ret = gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p,
   19600                 :             :                                post_p, is_gimple_lvalue, fb_either);
   19601                 :      398564 :           recalculate_side_effects (*expr_p);
   19602                 :      398564 :           break;
   19603                 :             : 
   19604                 :        1299 :         case TARGET_MEM_REF:
   19605                 :        1299 :           {
   19606                 :        1299 :             enum gimplify_status r0 = GS_ALL_DONE, r1 = GS_ALL_DONE;
   19607                 :             : 
   19608                 :        1299 :             if (TMR_BASE (*expr_p))
   19609                 :        1299 :               r0 = gimplify_expr (&TMR_BASE (*expr_p), pre_p,
   19610                 :             :                                   post_p, is_gimple_mem_ref_addr, fb_either);
   19611                 :        1299 :             if (TMR_INDEX (*expr_p))
   19612                 :        1119 :               r1 = gimplify_expr (&TMR_INDEX (*expr_p), pre_p,
   19613                 :             :                                   post_p, is_gimple_val, fb_rvalue);
   19614                 :        1299 :             if (TMR_INDEX2 (*expr_p))
   19615                 :          75 :               r1 = gimplify_expr (&TMR_INDEX2 (*expr_p), pre_p,
   19616                 :             :                                   post_p, is_gimple_val, fb_rvalue);
   19617                 :             :             /* TMR_STEP and TMR_OFFSET are always integer constants.  */
   19618                 :        1299 :             ret = MIN (r0, r1);
   19619                 :             :           }
   19620                 :             :           break;
   19621                 :             : 
   19622                 :           0 :         case NON_LVALUE_EXPR:
   19623                 :             :           /* This should have been stripped above.  */
   19624                 :           0 :           gcc_unreachable ();
   19625                 :             : 
   19626                 :       94867 :         case ASM_EXPR:
   19627                 :       94867 :           ret = gimplify_asm_expr (expr_p, pre_p, post_p);
   19628                 :       94867 :           break;
   19629                 :             : 
   19630                 :      493233 :         case TRY_FINALLY_EXPR:
   19631                 :      493233 :         case TRY_CATCH_EXPR:
   19632                 :      493233 :           {
   19633                 :      493233 :             gimple_seq eval, cleanup;
   19634                 :      493233 :             gtry *try_;
   19635                 :             : 
   19636                 :             :             /* Calls to destructors are generated automatically in FINALLY/CATCH
   19637                 :             :                block. They should have location as UNKNOWN_LOCATION. However,
   19638                 :             :                gimplify_call_expr will reset these call stmts to input_location
   19639                 :             :                if it finds stmt's location is unknown. To prevent resetting for
   19640                 :             :                destructors, we set the input_location to unknown.
   19641                 :             :                Note that this only affects the destructor calls in FINALLY/CATCH
   19642                 :             :                block, and will automatically reset to its original value by the
   19643                 :             :                end of gimplify_expr.  */
   19644                 :      493233 :             input_location = UNKNOWN_LOCATION;
   19645                 :      493233 :             eval = cleanup = NULL;
   19646                 :      493233 :             gimplify_and_add (TREE_OPERAND (*expr_p, 0), &eval);
   19647                 :      493233 :             bool save_in_handler_expr = gimplify_ctxp->in_handler_expr;
   19648                 :      493233 :             if (TREE_CODE (*expr_p) == TRY_FINALLY_EXPR
   19649                 :      493233 :                 && TREE_CODE (TREE_OPERAND (*expr_p, 1)) == EH_ELSE_EXPR)
   19650                 :             :               {
   19651                 :          84 :                 gimple_seq n = NULL, e = NULL;
   19652                 :          84 :                 gimplify_ctxp->in_handler_expr = true;
   19653                 :          84 :                 gimplify_and_add (TREE_OPERAND (TREE_OPERAND (*expr_p, 1),
   19654                 :             :                                                 0), &n);
   19655                 :          84 :                 gimplify_and_add (TREE_OPERAND (TREE_OPERAND (*expr_p, 1),
   19656                 :             :                                                 1), &e);
   19657                 :          84 :                 if (!gimple_seq_empty_p (n) || !gimple_seq_empty_p (e))
   19658                 :             :                   {
   19659                 :          83 :                     geh_else *stmt = gimple_build_eh_else (n, e);
   19660                 :          83 :                     gimple_seq_add_stmt (&cleanup, stmt);
   19661                 :             :                   }
   19662                 :             :               }
   19663                 :             :             else
   19664                 :             :               {
   19665                 :      493149 :                 gimplify_ctxp->in_handler_expr = true;
   19666                 :      493149 :                 gimplify_and_add (TREE_OPERAND (*expr_p, 1), &cleanup);
   19667                 :             :               }
   19668                 :      493233 :             gimplify_ctxp->in_handler_expr = save_in_handler_expr;
   19669                 :             :             /* Don't create bogus GIMPLE_TRY with empty cleanup.  */
   19670                 :      493233 :             if (gimple_seq_empty_p (cleanup))
   19671                 :             :               {
   19672                 :       27486 :                 gimple_seq_add_seq (pre_p, eval);
   19673                 :       27486 :                 ret = GS_ALL_DONE;
   19674                 :       27486 :                 break;
   19675                 :             :               }
   19676                 :      465747 :             try_ = gimple_build_try (eval, cleanup,
   19677                 :      465747 :                                      TREE_CODE (*expr_p) == TRY_FINALLY_EXPR
   19678                 :             :                                      ? GIMPLE_TRY_FINALLY
   19679                 :             :                                      : GIMPLE_TRY_CATCH);
   19680                 :      465747 :             if (EXPR_HAS_LOCATION (save_expr))
   19681                 :      852142 :               gimple_set_location (try_, EXPR_LOCATION (save_expr));
   19682                 :       39676 :             else if (LOCATION_LOCUS (saved_location) != UNKNOWN_LOCATION)
   19683                 :       26829 :               gimple_set_location (try_, saved_location);
   19684                 :      465747 :             if (TREE_CODE (*expr_p) == TRY_CATCH_EXPR)
   19685                 :      172976 :               gimple_try_set_catch_is_cleanup (try_,
   19686                 :      172976 :                                                TRY_CATCH_IS_CLEANUP (*expr_p));
   19687                 :      465747 :             gimplify_seq_add_stmt (pre_p, try_);
   19688                 :      465747 :             ret = GS_ALL_DONE;
   19689                 :      465747 :             break;
   19690                 :             :           }
   19691                 :             : 
   19692                 :     5064052 :         case CLEANUP_POINT_EXPR:
   19693                 :     5064052 :           ret = gimplify_cleanup_point_expr (expr_p, pre_p);
   19694                 :     5064052 :           break;
   19695                 :             : 
   19696                 :      697665 :         case TARGET_EXPR:
   19697                 :      697665 :           ret = gimplify_target_expr (expr_p, pre_p, post_p);
   19698                 :      697665 :           break;
   19699                 :             : 
   19700                 :       38431 :         case CATCH_EXPR:
   19701                 :       38431 :           {
   19702                 :       38431 :             gimple *c;
   19703                 :       38431 :             gimple_seq handler = NULL;
   19704                 :       38431 :             gimplify_and_add (CATCH_BODY (*expr_p), &handler);
   19705                 :       38431 :             c = gimple_build_catch (CATCH_TYPES (*expr_p), handler);
   19706                 :       38431 :             gimplify_seq_add_stmt (pre_p, c);
   19707                 :       38431 :             ret = GS_ALL_DONE;
   19708                 :       38431 :             break;
   19709                 :             :           }
   19710                 :             : 
   19711                 :        4227 :         case EH_FILTER_EXPR:
   19712                 :        4227 :           {
   19713                 :        4227 :             gimple *ehf;
   19714                 :        4227 :             gimple_seq failure = NULL;
   19715                 :             : 
   19716                 :        4227 :             gimplify_and_add (EH_FILTER_FAILURE (*expr_p), &failure);
   19717                 :        4227 :             ehf = gimple_build_eh_filter (EH_FILTER_TYPES (*expr_p), failure);
   19718                 :        4227 :             copy_warning (ehf, *expr_p);
   19719                 :        4227 :             gimplify_seq_add_stmt (pre_p, ehf);
   19720                 :        4227 :             ret = GS_ALL_DONE;
   19721                 :        4227 :             break;
   19722                 :             :           }
   19723                 :             : 
   19724                 :       47046 :         case OBJ_TYPE_REF:
   19725                 :       47046 :           {
   19726                 :       47046 :             enum gimplify_status r0, r1;
   19727                 :       47046 :             r0 = gimplify_expr (&OBJ_TYPE_REF_OBJECT (*expr_p), pre_p,
   19728                 :             :                                 post_p, is_gimple_val, fb_rvalue);
   19729                 :       47046 :             r1 = gimplify_expr (&OBJ_TYPE_REF_EXPR (*expr_p), pre_p,
   19730                 :             :                                 post_p, is_gimple_val, fb_rvalue);
   19731                 :       47046 :             TREE_SIDE_EFFECTS (*expr_p) = 0;
   19732                 :       47046 :             ret = MIN (r0, r1);
   19733                 :             :           }
   19734                 :             :           break;
   19735                 :             : 
   19736                 :       39296 :         case LABEL_DECL:
   19737                 :             :           /* We get here when taking the address of a label.  We mark
   19738                 :             :              the label as "forced"; meaning it can never be removed and
   19739                 :             :              it is a potential target for any computed goto.  */
   19740                 :       39296 :           FORCED_LABEL (*expr_p) = 1;
   19741                 :       39296 :           ret = GS_ALL_DONE;
   19742                 :       39296 :           break;
   19743                 :             : 
   19744                 :     8480390 :         case STATEMENT_LIST:
   19745                 :     8480390 :           ret = gimplify_statement_list (expr_p, pre_p);
   19746                 :     8480390 :           break;
   19747                 :             : 
   19748                 :        1549 :         case WITH_SIZE_EXPR:
   19749                 :        1549 :           {
   19750                 :        1831 :             gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p,
   19751                 :             :                            post_p == &internal_post ? NULL : post_p,
   19752                 :             :                            gimple_test_f, fallback);
   19753                 :        1549 :             gimplify_expr (&TREE_OPERAND (*expr_p, 1), pre_p, post_p,
   19754                 :             :                            is_gimple_val, fb_rvalue);
   19755                 :        1549 :             ret = GS_ALL_DONE;
   19756                 :             :           }
   19757                 :        1549 :           break;
   19758                 :             : 
   19759                 :   103221387 :         case VAR_DECL:
   19760                 :   103221387 :         case PARM_DECL:
   19761                 :   103221387 :           ret = gimplify_var_or_parm_decl (expr_p);
   19762                 :   103221387 :           break;
   19763                 :             : 
   19764                 :      305029 :         case RESULT_DECL:
   19765                 :             :           /* When within an OMP context, notice uses of variables.  */
   19766                 :      305029 :           if (gimplify_omp_ctxp)
   19767                 :         674 :             omp_notice_variable (gimplify_omp_ctxp, *expr_p, true);
   19768                 :             :           /* Handlers can refer to the function result; if that has been
   19769                 :             :              moved, we need to track it.  */
   19770                 :      305029 :           if (gimplify_ctxp->in_handler_expr && gimplify_ctxp->return_temp)
   19771                 :          48 :             *expr_p = gimplify_ctxp->return_temp;
   19772                 :             :           ret = GS_ALL_DONE;
   19773                 :             :           break;
   19774                 :             : 
   19775                 :           0 :         case DEBUG_EXPR_DECL:
   19776                 :           0 :           gcc_unreachable ();
   19777                 :             : 
   19778                 :     2578850 :         case DEBUG_BEGIN_STMT:
   19779                 :     5157700 :           gimplify_seq_add_stmt (pre_p,
   19780                 :             :                                  gimple_build_debug_begin_stmt
   19781                 :     2578850 :                                  (TREE_BLOCK (*expr_p),
   19782                 :     2578850 :                                   EXPR_LOCATION (*expr_p)));
   19783                 :     2578850 :           ret = GS_ALL_DONE;
   19784                 :     2578850 :           *expr_p = NULL;
   19785                 :     2578850 :           break;
   19786                 :             : 
   19787                 :             :         case SSA_NAME:
   19788                 :             :           /* Allow callbacks into the gimplifier during optimization.  */
   19789                 :             :           ret = GS_ALL_DONE;
   19790                 :             :           break;
   19791                 :             : 
   19792                 :       18198 :         case OMP_PARALLEL:
   19793                 :       18198 :           gimplify_omp_parallel (expr_p, pre_p);
   19794                 :       18198 :           ret = GS_ALL_DONE;
   19795                 :       18198 :           break;
   19796                 :             : 
   19797                 :        4011 :         case OMP_TASK:
   19798                 :        4011 :           gimplify_omp_task (expr_p, pre_p);
   19799                 :        4011 :           ret = GS_ALL_DONE;
   19800                 :        4011 :           break;
   19801                 :             : 
   19802                 :       10691 :         case OMP_SIMD:
   19803                 :       10691 :           {
   19804                 :             :             /* Temporarily disable into_ssa, as scan_omp_simd
   19805                 :             :                which calls copy_gimple_seq_and_replace_locals can't deal
   19806                 :             :                with SSA_NAMEs defined outside of the body properly.  */
   19807                 :       10691 :             bool saved_into_ssa = gimplify_ctxp->into_ssa;
   19808                 :       10691 :             gimplify_ctxp->into_ssa = false;
   19809                 :       10691 :             ret = gimplify_omp_for (expr_p, pre_p);
   19810                 :       10691 :             gimplify_ctxp->into_ssa = saved_into_ssa;
   19811                 :       10691 :             break;
   19812                 :             :           }
   19813                 :             : 
   19814                 :       47373 :         case OMP_FOR:
   19815                 :       47373 :         case OMP_DISTRIBUTE:
   19816                 :       47373 :         case OMP_TASKLOOP:
   19817                 :       47373 :         case OMP_TILE:
   19818                 :       47373 :         case OMP_UNROLL:
   19819                 :       47373 :         case OACC_LOOP:
   19820                 :       47373 :           ret = gimplify_omp_for (expr_p, pre_p);
   19821                 :       47373 :           break;
   19822                 :             : 
   19823                 :        1057 :         case OMP_LOOP:
   19824                 :        1057 :           ret = gimplify_omp_loop (expr_p, pre_p);
   19825                 :        1057 :           break;
   19826                 :             : 
   19827                 :         706 :         case OACC_CACHE:
   19828                 :         706 :           gimplify_oacc_cache (expr_p, pre_p);
   19829                 :         706 :           ret = GS_ALL_DONE;
   19830                 :         706 :           break;
   19831                 :             : 
   19832                 :         254 :         case OACC_DECLARE:
   19833                 :         254 :           gimplify_oacc_declare (expr_p, pre_p);
   19834                 :         254 :           ret = GS_ALL_DONE;
   19835                 :         254 :           break;
   19836                 :             : 
   19837                 :       38265 :         case OACC_HOST_DATA:
   19838                 :       38265 :         case OACC_DATA:
   19839                 :       38265 :         case OACC_KERNELS:
   19840                 :       38265 :         case OACC_PARALLEL:
   19841                 :       38265 :         case OACC_SERIAL:
   19842                 :       38265 :         case OMP_SCOPE:
   19843                 :       38265 :         case OMP_SECTIONS:
   19844                 :       38265 :         case OMP_SINGLE:
   19845                 :       38265 :         case OMP_TARGET:
   19846                 :       38265 :         case OMP_TARGET_DATA:
   19847                 :       38265 :         case OMP_TEAMS:
   19848                 :       38265 :           gimplify_omp_workshare (expr_p, pre_p);
   19849                 :       38265 :           ret = GS_ALL_DONE;
   19850                 :       38265 :           break;
   19851                 :             : 
   19852                 :       11734 :         case OACC_ENTER_DATA:
   19853                 :       11734 :         case OACC_EXIT_DATA:
   19854                 :       11734 :         case OACC_UPDATE:
   19855                 :       11734 :         case OMP_TARGET_UPDATE:
   19856                 :       11734 :         case OMP_TARGET_ENTER_DATA:
   19857                 :       11734 :         case OMP_TARGET_EXIT_DATA:
   19858                 :       11734 :           gimplify_omp_target_update (expr_p, pre_p);
   19859                 :       11734 :           ret = GS_ALL_DONE;
   19860                 :       11734 :           break;
   19861                 :             : 
   19862                 :        6981 :         case OMP_SECTION:
   19863                 :        6981 :         case OMP_STRUCTURED_BLOCK:
   19864                 :        6981 :         case OMP_MASTER:
   19865                 :        6981 :         case OMP_MASKED:
   19866                 :        6981 :         case OMP_ORDERED:
   19867                 :        6981 :         case OMP_CRITICAL:
   19868                 :        6981 :         case OMP_SCAN:
   19869                 :        6981 :           {
   19870                 :        6981 :             gimple_seq body = NULL;
   19871                 :        6981 :             gimple *g;
   19872                 :        6981 :             bool saved_in_omp_construct = in_omp_construct;
   19873                 :             : 
   19874                 :        6981 :             in_omp_construct = true;
   19875                 :        6981 :             gimplify_and_add (OMP_BODY (*expr_p), &body);
   19876                 :        6981 :             in_omp_construct = saved_in_omp_construct;
   19877                 :        6981 :             switch (TREE_CODE (*expr_p))
   19878                 :             :               {
   19879                 :        1271 :               case OMP_SECTION:
   19880                 :        1271 :                 g = gimple_build_omp_section (body);
   19881                 :        1271 :                 break;
   19882                 :         774 :               case OMP_STRUCTURED_BLOCK:
   19883                 :         774 :                 g = gimple_build_omp_structured_block (body);
   19884                 :         774 :                 break;
   19885                 :         886 :               case OMP_MASTER:
   19886                 :         886 :                 g = gimple_build_omp_master (body);
   19887                 :         886 :                 break;
   19888                 :        1940 :               case OMP_ORDERED:
   19889                 :        1940 :                 g = gimplify_omp_ordered (*expr_p, body);
   19890                 :        1940 :                 if (OMP_BODY (*expr_p) == NULL_TREE
   19891                 :        1940 :                     && gimple_code (g) == GIMPLE_OMP_ORDERED)
   19892                 :        1015 :                   gimple_omp_ordered_standalone (g);
   19893                 :             :                 break;
   19894                 :         446 :               case OMP_MASKED:
   19895                 :         446 :                 gimplify_scan_omp_clauses (&OMP_MASKED_CLAUSES (*expr_p),
   19896                 :             :                                            pre_p, ORT_WORKSHARE, OMP_MASKED);
   19897                 :         446 :                 gimplify_adjust_omp_clauses (pre_p, body,
   19898                 :             :                                              &OMP_MASKED_CLAUSES (*expr_p),
   19899                 :             :                                              OMP_MASKED);
   19900                 :         892 :                 g = gimple_build_omp_masked (body,
   19901                 :         446 :                                              OMP_MASKED_CLAUSES (*expr_p));
   19902                 :         446 :                 break;
   19903                 :         546 :               case OMP_CRITICAL:
   19904                 :         546 :                 gimplify_scan_omp_clauses (&OMP_CRITICAL_CLAUSES (*expr_p),
   19905                 :             :                                            pre_p, ORT_WORKSHARE, OMP_CRITICAL);
   19906                 :         546 :                 gimplify_adjust_omp_clauses (pre_p, body,
   19907                 :             :                                              &OMP_CRITICAL_CLAUSES (*expr_p),
   19908                 :             :                                              OMP_CRITICAL);
   19909                 :        1638 :                 g = gimple_build_omp_critical (body,
   19910                 :         546 :                                                OMP_CRITICAL_NAME (*expr_p),
   19911                 :         546 :                                                OMP_CRITICAL_CLAUSES (*expr_p));
   19912                 :         546 :                 break;
   19913                 :        1118 :               case OMP_SCAN:
   19914                 :        1118 :                 gimplify_scan_omp_clauses (&OMP_SCAN_CLAUSES (*expr_p),
   19915                 :             :                                            pre_p, ORT_WORKSHARE, OMP_SCAN);
   19916                 :        1118 :                 gimplify_adjust_omp_clauses (pre_p, body,
   19917                 :             :                                              &OMP_SCAN_CLAUSES (*expr_p),
   19918                 :             :                                              OMP_SCAN);
   19919                 :        1118 :                 g = gimple_build_omp_scan (body, OMP_SCAN_CLAUSES (*expr_p));
   19920                 :        1118 :                 break;
   19921                 :           0 :               default:
   19922                 :           0 :                 gcc_unreachable ();
   19923                 :             :               }
   19924                 :        6981 :             gimplify_seq_add_stmt (pre_p, g);
   19925                 :        6981 :             ret = GS_ALL_DONE;
   19926                 :        6981 :             break;
   19927                 :             :           }
   19928                 :             : 
   19929                 :         611 :         case OMP_TASKGROUP:
   19930                 :         611 :           {
   19931                 :         611 :             gimple_seq body = NULL;
   19932                 :             : 
   19933                 :         611 :             tree *pclauses = &OMP_TASKGROUP_CLAUSES (*expr_p);
   19934                 :         611 :             bool saved_in_omp_construct = in_omp_construct;
   19935                 :         611 :             gimplify_scan_omp_clauses (pclauses, pre_p, ORT_TASKGROUP,
   19936                 :             :                                        OMP_TASKGROUP);
   19937                 :         611 :             gimplify_adjust_omp_clauses (pre_p, NULL, pclauses, OMP_TASKGROUP);
   19938                 :             : 
   19939                 :         611 :             in_omp_construct = true;
   19940                 :         611 :             gimplify_and_add (OMP_BODY (*expr_p), &body);
   19941                 :         611 :             in_omp_construct = saved_in_omp_construct;
   19942                 :         611 :             gimple_seq cleanup = NULL;
   19943                 :         611 :             tree fn = builtin_decl_explicit (BUILT_IN_GOMP_TASKGROUP_END);
   19944                 :         611 :             gimple *g = gimple_build_call (fn, 0);
   19945                 :         611 :             gimple_seq_add_stmt (&cleanup, g);
   19946                 :         611 :             g = gimple_build_try (body, cleanup, GIMPLE_TRY_FINALLY);
   19947                 :         611 :             body = NULL;
   19948                 :         611 :             gimple_seq_add_stmt (&body, g);
   19949                 :         611 :             g = gimple_build_omp_taskgroup (body, *pclauses);
   19950                 :         611 :             gimplify_seq_add_stmt (pre_p, g);
   19951                 :         611 :             ret = GS_ALL_DONE;
   19952                 :         611 :             break;
   19953                 :             :           }
   19954                 :             : 
   19955                 :         477 :         case OMP_INTEROP:
   19956                 :         477 :           sorry_at (EXPR_LOCATION (*expr_p),
   19957                 :             :                     "%<#pragma omp interop%> not yet supported");
   19958                 :         477 :           ret = GS_ERROR;
   19959                 :         477 :           break;
   19960                 :       10232 :         case OMP_ATOMIC:
   19961                 :       10232 :         case OMP_ATOMIC_READ:
   19962                 :       10232 :         case OMP_ATOMIC_CAPTURE_OLD:
   19963                 :       10232 :         case OMP_ATOMIC_CAPTURE_NEW:
   19964                 :       10232 :           ret = gimplify_omp_atomic (expr_p, pre_p);
   19965                 :       10232 :           break;
   19966                 :             : 
   19967                 :         819 :         case OMP_DISPATCH:
   19968                 :         819 :           ret = gimplify_omp_dispatch (expr_p, pre_p);
   19969                 :         819 :           break;
   19970                 :             : 
   19971                 :         162 :         case OMP_METADIRECTIVE:
   19972                 :         162 :           ret = gimplify_omp_metadirective (expr_p, pre_p, post_p,
   19973                 :             :                                             gimple_test_f, fallback);
   19974                 :         162 :           break;
   19975                 :             : 
   19976                 :          36 :         case OMP_NEXT_VARIANT:
   19977                 :          36 :         case OMP_TARGET_DEVICE_MATCHES:
   19978                 :             :           /* These are placeholders for constants.  There's nothing to do with
   19979                 :             :              them here but we must mark the containing function as needing
   19980                 :             :              to run the ompdevlow pass to resolve them.  Note that
   19981                 :             :              OMP_TARGET_DEVICE_MATCHES, in particular, may be inserted by
   19982                 :             :              the front ends.  */
   19983                 :          36 :           cgraph_node::get (cfun->decl)->has_omp_variant_constructs = 1;
   19984                 :          36 :           ret = GS_ALL_DONE;
   19985                 :          36 :           break;
   19986                 :             : 
   19987                 :         478 :         case TRANSACTION_EXPR:
   19988                 :         478 :           ret = gimplify_transaction (expr_p, pre_p);
   19989                 :         478 :           break;
   19990                 :             : 
   19991                 :      284090 :         case TRUTH_AND_EXPR:
   19992                 :      284090 :         case TRUTH_OR_EXPR:
   19993                 :      284090 :         case TRUTH_XOR_EXPR:
   19994                 :      284090 :           {
   19995                 :      284090 :             tree orig_type = TREE_TYPE (*expr_p);
   19996                 :      284090 :             tree new_type, xop0, xop1;
   19997                 :      284090 :             *expr_p = gimple_boolify (*expr_p);
   19998                 :      284090 :             new_type = TREE_TYPE (*expr_p);
   19999                 :      284090 :             if (!useless_type_conversion_p (orig_type, new_type))
   20000                 :             :               {
   20001                 :        1114 :                 *expr_p = fold_convert_loc (input_location, orig_type, *expr_p);
   20002                 :        1114 :                 ret = GS_OK;
   20003                 :        1114 :                 break;
   20004                 :             :               }
   20005                 :             : 
   20006                 :             :           /* Boolified binary truth expressions are semantically equivalent
   20007                 :             :              to bitwise binary expressions.  Canonicalize them to the
   20008                 :             :              bitwise variant.  */
   20009                 :      282976 :             switch (TREE_CODE (*expr_p))
   20010                 :             :               {
   20011                 :      165008 :               case TRUTH_AND_EXPR:
   20012                 :      165008 :                 TREE_SET_CODE (*expr_p, BIT_AND_EXPR);
   20013                 :      165008 :                 break;
   20014                 :      117378 :               case TRUTH_OR_EXPR:
   20015                 :      117378 :                 TREE_SET_CODE (*expr_p, BIT_IOR_EXPR);
   20016                 :      117378 :                 break;
   20017                 :         590 :               case TRUTH_XOR_EXPR:
   20018                 :         590 :                 TREE_SET_CODE (*expr_p, BIT_XOR_EXPR);
   20019                 :         590 :                 break;
   20020                 :             :               default:
   20021                 :             :                 break;
   20022                 :             :               }
   20023                 :             :             /* Now make sure that operands have compatible type to
   20024                 :             :                expression's new_type.  */
   20025                 :      282976 :             xop0 = TREE_OPERAND (*expr_p, 0);
   20026                 :      282976 :             xop1 = TREE_OPERAND (*expr_p, 1);
   20027                 :      282976 :             if (!useless_type_conversion_p (new_type, TREE_TYPE (xop0)))
   20028                 :         326 :               TREE_OPERAND (*expr_p, 0) = fold_convert_loc (input_location,
   20029                 :             :                                                             new_type,
   20030                 :             :                                                             xop0);
   20031                 :      282976 :             if (!useless_type_conversion_p (new_type, TREE_TYPE (xop1)))
   20032                 :         366 :               TREE_OPERAND (*expr_p, 1) = fold_convert_loc (input_location,
   20033                 :             :                                                             new_type,
   20034                 :             :                                                             xop1);
   20035                 :             :             /* Continue classified as tcc_binary.  */
   20036                 :      282976 :             goto expr_2;
   20037                 :             :           }
   20038                 :             : 
   20039                 :        9786 :         case VEC_COND_EXPR:
   20040                 :        9786 :           goto expr_3;
   20041                 :             : 
   20042                 :      132598 :         case VEC_PERM_EXPR:
   20043                 :             :           /* Classified as tcc_expression.  */
   20044                 :      132598 :           goto expr_3;
   20045                 :             : 
   20046                 :          48 :         case BIT_INSERT_EXPR:
   20047                 :             :           /* Argument 3 is a constant.  */
   20048                 :          48 :           goto expr_2;
   20049                 :             : 
   20050                 :     3640709 :         case POINTER_PLUS_EXPR:
   20051                 :     3640709 :           {
   20052                 :     3640709 :             enum gimplify_status r0, r1;
   20053                 :     3640709 :             r0 = gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p,
   20054                 :             :                                 post_p, is_gimple_val, fb_rvalue);
   20055                 :     3640709 :             r1 = gimplify_expr (&TREE_OPERAND (*expr_p, 1), pre_p,
   20056                 :             :                                 post_p, is_gimple_val, fb_rvalue);
   20057                 :     3640709 :             recalculate_side_effects (*expr_p);
   20058                 :     3640709 :             ret = MIN (r0, r1);
   20059                 :             :             break;
   20060                 :             :           }
   20061                 :             : 
   20062                 :    41826178 :         default:
   20063                 :    41826178 :           switch (TREE_CODE_CLASS (TREE_CODE (*expr_p)))
   20064                 :             :             {
   20065                 :     6660192 :             case tcc_comparison:
   20066                 :             :               /* Handle comparison of objects of non scalar mode aggregates
   20067                 :             :                  with a call to memcmp.  It would be nice to only have to do
   20068                 :             :                  this for variable-sized objects, but then we'd have to allow
   20069                 :             :                  the same nest of reference nodes we allow for MODIFY_EXPR and
   20070                 :             :                  that's too complex.
   20071                 :             : 
   20072                 :             :                  Compare scalar mode aggregates as scalar mode values.  Using
   20073                 :             :                  memcmp for them would be very inefficient at best, and is
   20074                 :             :                  plain wrong if bitfields are involved.  */
   20075                 :     6660192 :               if (error_operand_p (TREE_OPERAND (*expr_p, 1)))
   20076                 :             :                 ret = GS_ERROR;
   20077                 :             :               else
   20078                 :             :                 {
   20079                 :     6660192 :                   tree type = TREE_TYPE (TREE_OPERAND (*expr_p, 1));
   20080                 :             : 
   20081                 :             :                   /* Vector comparisons need no boolification.  */
   20082                 :     6660192 :                   if (TREE_CODE (type) == VECTOR_TYPE)
   20083                 :       11688 :                     goto expr_2;
   20084                 :     6648504 :                   else if (!AGGREGATE_TYPE_P (type))
   20085                 :             :                     {
   20086                 :     6648490 :                       tree org_type = TREE_TYPE (*expr_p);
   20087                 :     6648490 :                       *expr_p = gimple_boolify (*expr_p);
   20088                 :     6648490 :                       if (!useless_type_conversion_p (org_type,
   20089                 :     6648490 :                                                       TREE_TYPE (*expr_p)))
   20090                 :             :                         {
   20091                 :       58781 :                           *expr_p = fold_convert_loc (input_location,
   20092                 :             :                                                       org_type, *expr_p);
   20093                 :       58781 :                           ret = GS_OK;
   20094                 :             :                         }
   20095                 :             :                       else
   20096                 :     6589709 :                         goto expr_2;
   20097                 :             :                     }
   20098                 :          14 :                   else if (SCALAR_INT_MODE_P (TYPE_MODE (type)))
   20099                 :          14 :                     ret = gimplify_scalar_mode_aggregate_compare (expr_p);
   20100                 :             :                   else
   20101                 :           0 :                     ret = gimplify_variable_sized_compare (expr_p);
   20102                 :             :                 }
   20103                 :             :               break;
   20104                 :             : 
   20105                 :             :             /* If *EXPR_P does not need to be special-cased, handle it
   20106                 :             :                according to its class.  */
   20107                 :     1537117 :             case tcc_unary:
   20108                 :     1537117 :               ret = gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p,
   20109                 :             :                                    post_p, is_gimple_val, fb_rvalue);
   20110                 :     1537117 :               break;
   20111                 :             : 
   20112                 :    25119549 :             case tcc_binary:
   20113                 :    25119549 :             expr_2:
   20114                 :    25119549 :               {
   20115                 :    25119549 :                 enum gimplify_status r0, r1;
   20116                 :             : 
   20117                 :    25119549 :                 r0 = gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p,
   20118                 :             :                                     post_p, is_gimple_val, fb_rvalue);
   20119                 :    25119549 :                 r1 = gimplify_expr (&TREE_OPERAND (*expr_p, 1), pre_p,
   20120                 :             :                                     post_p, is_gimple_val, fb_rvalue);
   20121                 :             : 
   20122                 :    25119549 :                 ret = MIN (r0, r1);
   20123                 :             :                 break;
   20124                 :             :               }
   20125                 :             : 
   20126                 :      142384 :             expr_3:
   20127                 :      142384 :               {
   20128                 :      142384 :                 enum gimplify_status r0, r1, r2;
   20129                 :             : 
   20130                 :      142384 :                 r0 = gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p,
   20131                 :             :                                     post_p, is_gimple_val, fb_rvalue);
   20132                 :      142384 :                 r1 = gimplify_expr (&TREE_OPERAND (*expr_p, 1), pre_p,
   20133                 :             :                                     post_p, is_gimple_val, fb_rvalue);
   20134                 :      142384 :                 r2 = gimplify_expr (&TREE_OPERAND (*expr_p, 2), pre_p,
   20135                 :             :                                     post_p, is_gimple_val, fb_rvalue);
   20136                 :             : 
   20137                 :      142384 :                 ret = MIN (MIN (r0, r1), r2);
   20138                 :             :                 break;
   20139                 :             :               }
   20140                 :             : 
   20141                 :    15393741 :             case tcc_declaration:
   20142                 :    15393741 :             case tcc_constant:
   20143                 :    15393741 :               ret = GS_ALL_DONE;
   20144                 :    15393741 :               goto dont_recalculate;
   20145                 :             : 
   20146                 :           0 :             default:
   20147                 :           0 :               gcc_unreachable ();
   20148                 :             :             }
   20149                 :             : 
   20150                 :    26857845 :           recalculate_side_effects (*expr_p);
   20151                 :             : 
   20152                 :   455193071 :         dont_recalculate:
   20153                 :             :           break;
   20154                 :             :         }
   20155                 :             : 
   20156                 :   455193071 :       gcc_assert (*expr_p || ret != GS_OK);
   20157                 :             :     }
   20158                 :   459805614 :   while (ret == GS_OK);
   20159                 :             : 
   20160                 :             :   /* If we encountered an error_mark somewhere nested inside, either
   20161                 :             :      stub out the statement or propagate the error back out.  */
   20162                 :   442844212 :   if (ret == GS_ERROR)
   20163                 :             :     {
   20164                 :        5091 :       if (is_statement)
   20165                 :        4137 :         *expr_p = NULL;
   20166                 :        5091 :       goto out;
   20167                 :             :     }
   20168                 :             : 
   20169                 :             :   /* This was only valid as a return value from the langhook, which
   20170                 :             :      we handled.  Make sure it doesn't escape from any other context.  */
   20171                 :   442839121 :   gcc_assert (ret != GS_UNHANDLED);
   20172                 :             : 
   20173                 :   442839121 :   if (fallback == fb_none && *expr_p && !is_gimple_stmt (*expr_p))
   20174                 :             :     {
   20175                 :             :       /* We aren't looking for a value, and we don't have a valid
   20176                 :             :          statement.  If it doesn't have side-effects, throw it away.
   20177                 :             :          We can also get here with code such as "*&&L;", where L is
   20178                 :             :          a LABEL_DECL that is marked as FORCED_LABEL.  */
   20179                 :      999195 :       if (TREE_CODE (*expr_p) == LABEL_DECL
   20180                 :      999195 :           || !TREE_SIDE_EFFECTS (*expr_p))
   20181                 :      998174 :         *expr_p = NULL;
   20182                 :        1021 :       else if (!TREE_THIS_VOLATILE (*expr_p))
   20183                 :             :         {
   20184                 :             :           /* This is probably a _REF that contains something nested that
   20185                 :             :              has side effects.  Recurse through the operands to find it.  */
   20186                 :           0 :           enum tree_code code = TREE_CODE (*expr_p);
   20187                 :             : 
   20188                 :           0 :           switch (code)
   20189                 :             :             {
   20190                 :           0 :             case COMPONENT_REF:
   20191                 :           0 :             case REALPART_EXPR:
   20192                 :           0 :             case IMAGPART_EXPR:
   20193                 :           0 :             case VIEW_CONVERT_EXPR:
   20194                 :           0 :               gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p,
   20195                 :             :                              gimple_test_f, fallback);
   20196                 :           0 :               break;
   20197                 :             : 
   20198                 :           0 :             case ARRAY_REF:
   20199                 :           0 :             case ARRAY_RANGE_REF:
   20200                 :           0 :               gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p,
   20201                 :             :                              gimple_test_f, fallback);
   20202                 :           0 :               gimplify_expr (&TREE_OPERAND (*expr_p, 1), pre_p, post_p,
   20203                 :             :                              gimple_test_f, fallback);
   20204                 :           0 :               break;
   20205                 :             : 
   20206                 :           0 :             default:
   20207                 :             :                /* Anything else with side-effects must be converted to
   20208                 :             :                   a valid statement before we get here.  */
   20209                 :           0 :               gcc_unreachable ();
   20210                 :             :             }
   20211                 :             : 
   20212                 :           0 :           *expr_p = NULL;
   20213                 :             :         }
   20214                 :        1021 :       else if (COMPLETE_TYPE_P (TREE_TYPE (*expr_p))
   20215                 :         971 :                && TYPE_MODE (TREE_TYPE (*expr_p)) != BLKmode
   20216                 :        1980 :                && !is_empty_type (TREE_TYPE (*expr_p)))
   20217                 :             :         {
   20218                 :             :           /* Historically, the compiler has treated a bare reference
   20219                 :             :              to a non-BLKmode volatile lvalue as forcing a load.  */
   20220                 :         893 :           tree type = TYPE_MAIN_VARIANT (TREE_TYPE (*expr_p));
   20221                 :             : 
   20222                 :             :           /* Normally, we do not want to create a temporary for a
   20223                 :             :              TREE_ADDRESSABLE type because such a type should not be
   20224                 :             :              copied by bitwise-assignment.  However, we make an
   20225                 :             :              exception here, as all we are doing here is ensuring that
   20226                 :             :              we read the bytes that make up the type.  We use
   20227                 :             :              create_tmp_var_raw because create_tmp_var will abort when
   20228                 :             :              given a TREE_ADDRESSABLE type.  */
   20229                 :         893 :           tree tmp = create_tmp_var_raw (type, "vol");
   20230                 :         893 :           gimple_add_tmp_var (tmp);
   20231                 :         893 :           gimplify_assign (tmp, *expr_p, pre_p);
   20232                 :         893 :           *expr_p = NULL;
   20233                 :             :         }
   20234                 :             :       else
   20235                 :             :         /* We can't do anything useful with a volatile reference to
   20236                 :             :            an incomplete type, so just throw it away.  Likewise for
   20237                 :             :            a BLKmode type, since any implicit inner load should
   20238                 :             :            already have been turned into an explicit one by the
   20239                 :             :            gimplification process.  */
   20240                 :         128 :         *expr_p = NULL;
   20241                 :             :     }
   20242                 :             : 
   20243                 :             :   /* If we are gimplifying at the statement level, we're done.  Tack
   20244                 :             :      everything together and return.  */
   20245                 :   442839121 :   if (fallback == fb_none || is_statement)
   20246                 :             :     {
   20247                 :             :       /* Since *EXPR_P has been converted into a GIMPLE tuple, clear
   20248                 :             :          it out for GC to reclaim it.  */
   20249                 :    96974552 :       *expr_p = NULL_TREE;
   20250                 :             : 
   20251                 :    96974552 :       if (!gimple_seq_empty_p (internal_pre)
   20252                 :    96974552 :           || !gimple_seq_empty_p (internal_post))
   20253                 :             :         {
   20254                 :          19 :           gimplify_seq_add_seq (&internal_pre, internal_post);
   20255                 :          19 :           gimplify_seq_add_seq (pre_p, internal_pre);
   20256                 :             :         }
   20257                 :             : 
   20258                 :             :       /* The result of gimplifying *EXPR_P is going to be the last few
   20259                 :             :          statements in *PRE_P and *POST_P.  Add location information
   20260                 :             :          to all the statements that were added by the gimplification
   20261                 :             :          helpers.  */
   20262                 :    96974552 :       if (!gimple_seq_empty_p (*pre_p))
   20263                 :    94568345 :         annotate_all_with_location_after (*pre_p, pre_last_gsi, input_location);
   20264                 :             : 
   20265                 :    96974552 :       if (!gimple_seq_empty_p (*post_p))
   20266                 :          19 :         annotate_all_with_location_after (*post_p, post_last_gsi,
   20267                 :             :                                           input_location);
   20268                 :             : 
   20269                 :    96974552 :       goto out;
   20270                 :             :     }
   20271                 :             : 
   20272                 :             : #ifdef ENABLE_GIMPLE_CHECKING
   20273                 :   345864569 :   if (*expr_p)
   20274                 :             :     {
   20275                 :   345864569 :       enum tree_code code = TREE_CODE (*expr_p);
   20276                 :             :       /* These expressions should already be in gimple IR form.  */
   20277                 :   345864569 :       gcc_assert (code != MODIFY_EXPR
   20278                 :             :                   && code != ASM_EXPR
   20279                 :             :                   && code != BIND_EXPR
   20280                 :             :                   && code != CATCH_EXPR
   20281                 :             :                   && (code != COND_EXPR || gimplify_ctxp->allow_rhs_cond_expr)
   20282                 :             :                   && code != EH_FILTER_EXPR
   20283                 :             :                   && code != GOTO_EXPR
   20284                 :             :                   && code != LABEL_EXPR
   20285                 :             :                   && code != LOOP_EXPR
   20286                 :             :                   && code != SWITCH_EXPR
   20287                 :             :                   && code != TRY_FINALLY_EXPR
   20288                 :             :                   && code != EH_ELSE_EXPR
   20289                 :             :                   && code != OACC_PARALLEL
   20290                 :             :                   && code != OACC_KERNELS
   20291                 :             :                   && code != OACC_SERIAL
   20292                 :             :                   && code != OACC_DATA
   20293                 :             :                   && code != OACC_HOST_DATA
   20294                 :             :                   && code != OACC_DECLARE
   20295                 :             :                   && code != OACC_UPDATE
   20296                 :             :                   && code != OACC_ENTER_DATA
   20297                 :             :                   && code != OACC_EXIT_DATA
   20298                 :             :                   && code != OACC_CACHE
   20299                 :             :                   && code != OMP_CRITICAL
   20300                 :             :                   && code != OMP_FOR
   20301                 :             :                   && code != OACC_LOOP
   20302                 :             :                   && code != OMP_MASTER
   20303                 :             :                   && code != OMP_MASKED
   20304                 :             :                   && code != OMP_TASKGROUP
   20305                 :             :                   && code != OMP_ORDERED
   20306                 :             :                   && code != OMP_PARALLEL
   20307                 :             :                   && code != OMP_SCAN
   20308                 :             :                   && code != OMP_SECTIONS
   20309                 :             :                   && code != OMP_SECTION
   20310                 :             :                   && code != OMP_STRUCTURED_BLOCK
   20311                 :             :                   && code != OMP_SINGLE
   20312                 :             :                   && code != OMP_SCOPE
   20313                 :             :                   && code != OMP_DISPATCH);
   20314                 :             :     }
   20315                 :             : #endif
   20316                 :             : 
   20317                 :             :   /* Otherwise we're gimplifying a subexpression, so the resulting
   20318                 :             :      value is interesting.  If it's a valid operand that matches
   20319                 :             :      GIMPLE_TEST_F, we're done. Unless we are handling some
   20320                 :             :      post-effects internally; if that's the case, we need to copy into
   20321                 :             :      a temporary before adding the post-effects to POST_P.  */
   20322                 :   345864569 :   if (gimple_seq_empty_p (internal_post) && (*gimple_test_f) (*expr_p))
   20323                 :   320880631 :     goto out;
   20324                 :             : 
   20325                 :             :   /* Otherwise, we need to create a new temporary for the gimplified
   20326                 :             :      expression.  */
   20327                 :             : 
   20328                 :             :   /* We can't return an lvalue if we have an internal postqueue.  The
   20329                 :             :      object the lvalue refers to would (probably) be modified by the
   20330                 :             :      postqueue; we need to copy the value out first, which means an
   20331                 :             :      rvalue.  */
   20332                 :    24983938 :   if ((fallback & fb_lvalue)
   20333                 :      551421 :       && gimple_seq_empty_p (internal_post)
   20334                 :    25535359 :       && is_gimple_addressable (*expr_p))
   20335                 :             :     {
   20336                 :             :       /* An lvalue will do.  Take the address of the expression, store it
   20337                 :             :          in a temporary, and replace the expression with an INDIRECT_REF of
   20338                 :             :          that temporary.  */
   20339                 :          15 :       tree ref_alias_type = reference_alias_ptr_type (*expr_p);
   20340                 :          15 :       unsigned int ref_align = get_object_alignment (*expr_p);
   20341                 :          15 :       tree ref_type = TREE_TYPE (*expr_p);
   20342                 :          15 :       tmp = build_fold_addr_expr_loc (input_location, *expr_p);
   20343                 :          15 :       gimplify_expr (&tmp, pre_p, post_p, is_gimple_reg, fb_rvalue);
   20344                 :          15 :       if (TYPE_ALIGN (ref_type) != ref_align)
   20345                 :           1 :         ref_type = build_aligned_type (ref_type, ref_align);
   20346                 :          15 :       *expr_p = build2 (MEM_REF, ref_type,
   20347                 :             :                         tmp, build_zero_cst (ref_alias_type));
   20348                 :             :     }
   20349                 :    24983923 :   else if ((fallback & fb_rvalue) && is_gimple_reg_rhs_or_call (*expr_p))
   20350                 :             :     {
   20351                 :             :       /* An rvalue will do.  Assign the gimplified expression into a
   20352                 :             :          new temporary TMP and replace the original expression with
   20353                 :             :          TMP.  First, make sure that the expression has a type so that
   20354                 :             :          it can be assigned into a temporary.  */
   20355                 :    24983915 :       gcc_assert (!VOID_TYPE_P (TREE_TYPE (*expr_p)));
   20356                 :    24983915 :       *expr_p = get_formal_tmp_var (*expr_p, pre_p);
   20357                 :             :     }
   20358                 :             :   else
   20359                 :             :     {
   20360                 :             : #ifdef ENABLE_GIMPLE_CHECKING
   20361                 :           8 :       if (!(fallback & fb_mayfail))
   20362                 :             :         {
   20363                 :           0 :           fprintf (stderr, "gimplification failed:\n");
   20364                 :           0 :           print_generic_expr (stderr, *expr_p);
   20365                 :           0 :           debug_tree (*expr_p);
   20366                 :           0 :           internal_error ("gimplification failed");
   20367                 :             :         }
   20368                 :             : #endif
   20369                 :           8 :       gcc_assert (fallback & fb_mayfail);
   20370                 :             : 
   20371                 :             :       /* If this is an asm statement, and the user asked for the
   20372                 :             :          impossible, don't die.  Fail and let gimplify_asm_expr
   20373                 :             :          issue an error.  */
   20374                 :           8 :       ret = GS_ERROR;
   20375                 :           8 :       goto out;
   20376                 :             :     }
   20377                 :             : 
   20378                 :             :   /* Make sure the temporary matches our predicate.  */
   20379                 :    24983930 :   gcc_assert ((*gimple_test_f) (*expr_p));
   20380                 :             : 
   20381                 :    24983930 :   if (!gimple_seq_empty_p (internal_post))
   20382                 :             :     {
   20383                 :           0 :       annotate_all_with_location (internal_post, input_location);
   20384                 :           0 :       gimplify_seq_add_seq (pre_p, internal_post);
   20385                 :             :     }
   20386                 :             : 
   20387                 :    24983930 :  out:
   20388                 :   442844212 :   input_location = saved_location;
   20389                 :   442844212 :   return ret;
   20390                 :             : }
   20391                 :             : 
   20392                 :             : /* Like gimplify_expr but make sure the gimplified result is not itself
   20393                 :             :    a SSA name (but a decl if it were).  Temporaries required by
   20394                 :             :    evaluating *EXPR_P may be still SSA names.  */
   20395                 :             : 
   20396                 :             : static enum gimplify_status
   20397                 :    30968830 : gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
   20398                 :             :                bool (*gimple_test_f) (tree), fallback_t fallback,
   20399                 :             :                bool allow_ssa)
   20400                 :             : {
   20401                 :    30968830 :   enum gimplify_status ret = gimplify_expr (expr_p, pre_p, post_p,
   20402                 :             :                                             gimple_test_f, fallback);
   20403                 :    30968830 :   if (! allow_ssa
   20404                 :      264462 :       && TREE_CODE (*expr_p) == SSA_NAME)
   20405                 :       67377 :     *expr_p = get_initialized_tmp_var (*expr_p, pre_p, NULL, false);
   20406                 :    30968830 :   return ret;
   20407                 :             : }
   20408                 :             : 
   20409                 :             : /* Look through TYPE for variable-sized objects and gimplify each such
   20410                 :             :    size that we find.  Add to LIST_P any statements generated.  */
   20411                 :             : 
   20412                 :             : void
   20413                 :     7657252 : gimplify_type_sizes (tree type, gimple_seq *list_p)
   20414                 :             : {
   20415                 :     7657252 :   if (type == NULL || type == error_mark_node)
   20416                 :             :     return;
   20417                 :             : 
   20418                 :     7657008 :   const bool ignored_p
   20419                 :     7657008 :     = TYPE_NAME (type)
   20420                 :     3873391 :       && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
   20421                 :    11311226 :       && DECL_IGNORED_P (TYPE_NAME (type));
   20422                 :     7657008 :   tree t;
   20423                 :             : 
   20424                 :             :   /* We first do the main variant, then copy into any other variants.  */
   20425                 :     7657008 :   type = TYPE_MAIN_VARIANT (type);
   20426                 :             : 
   20427                 :             :   /* Avoid infinite recursion.  */
   20428                 :     7657008 :   if (TYPE_SIZES_GIMPLIFIED (type))
   20429                 :             :     return;
   20430                 :             : 
   20431                 :     2288161 :   TYPE_SIZES_GIMPLIFIED (type) = 1;
   20432                 :             : 
   20433                 :     2288161 :   switch (TREE_CODE (type))
   20434                 :             :     {
   20435                 :      469123 :     case INTEGER_TYPE:
   20436                 :      469123 :     case ENUMERAL_TYPE:
   20437                 :      469123 :     case BOOLEAN_TYPE:
   20438                 :      469123 :     case REAL_TYPE:
   20439                 :      469123 :     case FIXED_POINT_TYPE:
   20440                 :      469123 :       gimplify_one_sizepos (&TYPE_MIN_VALUE (type), list_p);
   20441                 :      469123 :       gimplify_one_sizepos (&TYPE_MAX_VALUE (type), list_p);
   20442                 :             : 
   20443                 :     7812233 :       for (t = TYPE_NEXT_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
   20444                 :             :         {
   20445                 :     7343110 :           TYPE_MIN_VALUE (t) = TYPE_MIN_VALUE (type);
   20446                 :     7343110 :           TYPE_MAX_VALUE (t) = TYPE_MAX_VALUE (type);
   20447                 :             :         }
   20448                 :             :       break;
   20449                 :             : 
   20450                 :      171705 :     case ARRAY_TYPE:
   20451                 :             :       /* These types may not have declarations, so handle them here.  */
   20452                 :      171705 :       gimplify_type_sizes (TREE_TYPE (type), list_p);
   20453                 :      171705 :       gimplify_type_sizes (TYPE_DOMAIN (type), list_p);
   20454                 :             :       /* Ensure VLA bounds aren't removed, for -O0 they should be variables
   20455                 :             :          with assigned stack slots, for -O1+ -g they should be tracked
   20456                 :             :          by VTA.  */
   20457                 :      171705 :       if (!ignored_p
   20458                 :      171705 :           && TYPE_DOMAIN (type)
   20459                 :      343185 :           && INTEGRAL_TYPE_P (TYPE_DOMAIN (type)))
   20460                 :             :         {
   20461                 :      171480 :           t = TYPE_MIN_VALUE (TYPE_DOMAIN (type));
   20462                 :      171480 :           if (t && VAR_P (t) && DECL_ARTIFICIAL (t))
   20463                 :           0 :             DECL_IGNORED_P (t) = 0;
   20464                 :      171480 :           t = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
   20465                 :      171480 :           if (t && VAR_P (t) && DECL_ARTIFICIAL (t))
   20466                 :       18578 :             DECL_IGNORED_P (t) = 0;
   20467                 :             :         }
   20468                 :             :       break;
   20469                 :             : 
   20470                 :      453969 :     case RECORD_TYPE:
   20471                 :      453969 :     case UNION_TYPE:
   20472                 :      453969 :     case QUAL_UNION_TYPE:
   20473                 :     9480957 :       for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
   20474                 :     9026988 :         if (TREE_CODE (field) == FIELD_DECL)
   20475                 :             :           {
   20476                 :     1017754 :             gimplify_one_sizepos (&DECL_FIELD_OFFSET (field), list_p);
   20477                 :             :             /* Likewise, ensure variable offsets aren't removed.  */
   20478                 :     1017754 :             if (!ignored_p
   20479                 :     1017754 :                 && (t = DECL_FIELD_OFFSET (field))
   20480                 :     1017742 :                 && VAR_P (t)
   20481                 :     1017914 :                 && DECL_ARTIFICIAL (t))
   20482                 :         160 :               DECL_IGNORED_P (t) = 0;
   20483                 :     1017754 :             gimplify_one_sizepos (&DECL_SIZE (field), list_p);
   20484                 :     1017754 :             gimplify_one_sizepos (&DECL_SIZE_UNIT (field), list_p);
   20485                 :     1017754 :             gimplify_type_sizes (TREE_TYPE (field), list_p);
   20486                 :             :           }
   20487                 :             :       break;
   20488                 :             : 
   20489                 :             :     case POINTER_TYPE:
   20490                 :             :     case REFERENCE_TYPE:
   20491                 :             :         /* We used to recurse on the pointed-to type here, which turned out to
   20492                 :             :            be incorrect because its definition might refer to variables not
   20493                 :             :            yet initialized at this point if a forward declaration is involved.
   20494                 :             : 
   20495                 :             :            It was actually useful for anonymous pointed-to types to ensure
   20496                 :             :            that the sizes evaluation dominates every possible later use of the
   20497                 :             :            values.  Restricting to such types here would be safe since there
   20498                 :             :            is no possible forward declaration around, but would introduce an
   20499                 :             :            undesirable middle-end semantic to anonymity.  We then defer to
   20500                 :             :            front-ends the responsibility of ensuring that the sizes are
   20501                 :             :            evaluated both early and late enough, e.g. by attaching artificial
   20502                 :             :            type declarations to the tree.  */
   20503                 :             :       break;
   20504                 :             : 
   20505                 :             :     default:
   20506                 :             :       break;
   20507                 :             :     }
   20508                 :             : 
   20509                 :     2288161 :   gimplify_one_sizepos (&TYPE_SIZE (type), list_p);
   20510                 :     2288161 :   gimplify_one_sizepos (&TYPE_SIZE_UNIT (type), list_p);
   20511                 :             : 
   20512                 :    13211618 :   for (t = TYPE_NEXT_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
   20513                 :             :     {
   20514                 :    10923457 :       TYPE_SIZE (t) = TYPE_SIZE (type);
   20515                 :    10923457 :       TYPE_SIZE_UNIT (t) = TYPE_SIZE_UNIT (type);
   20516                 :    10923457 :       TYPE_SIZES_GIMPLIFIED (t) = 1;
   20517                 :             :     }
   20518                 :             : }
   20519                 :             : 
   20520                 :             : /* A subroutine of gimplify_type_sizes to make sure that *EXPR_P,
   20521                 :             :    a size or position, has had all of its SAVE_EXPRs evaluated.
   20522                 :             :    We add any required statements to *STMT_P.  */
   20523                 :             : 
   20524                 :             : void
   20525                 :     8585666 : gimplify_one_sizepos (tree *expr_p, gimple_seq *stmt_p)
   20526                 :             : {
   20527                 :     8585666 :   tree expr = *expr_p;
   20528                 :             : 
   20529                 :             :   /* We don't do anything if the value isn't there, is constant, or contains
   20530                 :             :      A PLACEHOLDER_EXPR.  We also don't want to do anything if it's already
   20531                 :             :      a VAR_DECL.  If it's a VAR_DECL from another function, the gimplifier
   20532                 :             :      will want to replace it with a new variable, but that will cause problems
   20533                 :             :      if this type is from outside the function.  It's OK to have that here.  */
   20534                 :     8585666 :   if (expr == NULL_TREE
   20535                 :     8589434 :       || is_gimple_constant (expr)
   20536                 :       79228 :       || VAR_P (expr)
   20537                 :     8661126 :       || CONTAINS_PLACEHOLDER_P (expr))
   20538                 :     8510206 :     return;
   20539                 :             : 
   20540                 :       75460 :   *expr_p = unshare_expr (expr);
   20541                 :             : 
   20542                 :             :   /* SSA names in decl/type fields are a bad idea - they'll get reclaimed
   20543                 :             :      if the def vanishes.  */
   20544                 :       75460 :   gimplify_expr (expr_p, stmt_p, NULL, is_gimple_val, fb_rvalue, false);
   20545                 :             : 
   20546                 :             :   /* If expr wasn't already is_gimple_sizepos or is_gimple_constant from the
   20547                 :             :      FE, ensure that it is a VAR_DECL, otherwise we might handle some decls
   20548                 :             :      as gimplify_vla_decl even when they would have all sizes INTEGER_CSTs.  */
   20549                 :       75460 :   if (is_gimple_constant (*expr_p))
   20550                 :         493 :     *expr_p = get_initialized_tmp_var (*expr_p, stmt_p, NULL, false);
   20551                 :             : }
   20552                 :             : 
   20553                 :             : /* Gimplify the body of statements of FNDECL and return a GIMPLE_BIND node
   20554                 :             :    containing the sequence of corresponding GIMPLE statements.  If DO_PARMS
   20555                 :             :    is true, also gimplify the parameters.  */
   20556                 :             : 
   20557                 :             : gbind *
   20558                 :     2712129 : gimplify_body (tree fndecl, bool do_parms)
   20559                 :             : {
   20560                 :     2712129 :   location_t saved_location = input_location;
   20561                 :     2712129 :   gimple_seq parm_stmts, parm_cleanup = NULL, seq;
   20562                 :     2712129 :   gimple *outer_stmt;
   20563                 :     2712129 :   gbind *outer_bind;
   20564                 :             : 
   20565                 :     2712129 :   timevar_push (TV_TREE_GIMPLIFY);
   20566                 :             : 
   20567                 :     2712129 :   init_tree_ssa (cfun);
   20568                 :             : 
   20569                 :             :   /* Initialize for optimize_insn_for_s{ize,peed}_p possibly called during
   20570                 :             :      gimplification.  */
   20571                 :     2712129 :   default_rtl_profile ();
   20572                 :             : 
   20573                 :     2712129 :   gcc_assert (gimplify_ctxp == NULL);
   20574                 :     2712129 :   push_gimplify_context (true);
   20575                 :             : 
   20576                 :     2712129 :   if (flag_openacc || flag_openmp)
   20577                 :             :     {
   20578                 :       43554 :       gcc_assert (gimplify_omp_ctxp == NULL);
   20579                 :       43554 :       if (lookup_attribute ("omp declare target", DECL_ATTRIBUTES (fndecl)))
   20580                 :        3393 :         gimplify_omp_ctxp = new_omp_context (ORT_IMPLICIT_TARGET);
   20581                 :             :     }
   20582                 :             : 
   20583                 :             :   /* Unshare most shared trees in the body and in that of any nested functions.
   20584                 :             :      It would seem we don't have to do this for nested functions because
   20585                 :             :      they are supposed to be output and then the outer function gimplified
   20586                 :             :      first, but the g++ front end doesn't always do it that way.  */
   20587                 :     2712129 :   unshare_body (fndecl);
   20588                 :     2712129 :   unvisit_body (fndecl);
   20589                 :             : 
   20590                 :             :   /* Make sure input_location isn't set to something weird.  */
   20591                 :     2712129 :   input_location = DECL_SOURCE_LOCATION (fndecl);
   20592                 :             : 
   20593                 :             :   /* Resolve callee-copies.  This has to be done before processing
   20594                 :             :      the body so that DECL_VALUE_EXPR gets processed correctly.  */
   20595                 :     2712129 :   parm_stmts = do_parms ? gimplify_parameters (&parm_cleanup) : NULL;
   20596                 :             : 
   20597                 :             :   /* Gimplify the function's body.  */
   20598                 :     2712129 :   seq = NULL;
   20599                 :     2712129 :   gimplify_stmt (&DECL_SAVED_TREE (fndecl), &seq);
   20600                 :     2712129 :   outer_stmt = gimple_seq_first_nondebug_stmt (seq);
   20601                 :     2712129 :   if (!outer_stmt)
   20602                 :             :     {
   20603                 :       24247 :       outer_stmt = gimple_build_nop ();
   20604                 :       24247 :       gimplify_seq_add_stmt (&seq, outer_stmt);
   20605                 :             :     }
   20606                 :             : 
   20607                 :             :   /* The body must contain exactly one statement, a GIMPLE_BIND.  If this is
   20608                 :             :      not the case, wrap everything in a GIMPLE_BIND to make it so.  */
   20609                 :     2712129 :   if (gimple_code (outer_stmt) == GIMPLE_BIND
   20610                 :     2712129 :       && (gimple_seq_first_nondebug_stmt (seq)
   20611                 :     1482421 :           == gimple_seq_last_nondebug_stmt (seq)))
   20612                 :             :     {
   20613                 :     1419340 :       outer_bind = as_a <gbind *> (outer_stmt);
   20614                 :     1419340 :       if (gimple_seq_first_stmt (seq) != outer_stmt
   20615                 :     1419340 :           || gimple_seq_last_stmt (seq) != outer_stmt)
   20616                 :             :         {
   20617                 :             :           /* If there are debug stmts before or after outer_stmt, move them
   20618                 :             :              inside of outer_bind body.  */
   20619                 :           1 :           gimple_stmt_iterator gsi = gsi_for_stmt (outer_stmt, &seq);
   20620                 :           1 :           gimple_seq second_seq = NULL;
   20621                 :           1 :           if (gimple_seq_first_stmt (seq) != outer_stmt
   20622                 :           2 :               && gimple_seq_last_stmt (seq) != outer_stmt)
   20623                 :             :             {
   20624                 :           0 :               second_seq = gsi_split_seq_after (gsi);
   20625                 :           0 :               gsi_remove (&gsi, false);
   20626                 :             :             }
   20627                 :           1 :           else if (gimple_seq_first_stmt (seq) != outer_stmt)
   20628                 :           1 :             gsi_remove (&gsi, false);
   20629                 :             :           else
   20630                 :             :             {
   20631                 :           0 :               gsi_remove (&gsi, false);
   20632                 :           0 :               second_seq = seq;
   20633                 :           0 :               seq = NULL;
   20634                 :             :             }
   20635                 :           1 :           gimple_seq_add_seq_without_update (&seq,
   20636                 :             :                                              gimple_bind_body (outer_bind));
   20637                 :           1 :           gimple_seq_add_seq_without_update (&seq, second_seq);
   20638                 :           1 :           gimple_bind_set_body (outer_bind, seq);
   20639                 :             :         }
   20640                 :             :     }
   20641                 :             :   else
   20642                 :     1292789 :     outer_bind = gimple_build_bind (NULL_TREE, seq, NULL);
   20643                 :             : 
   20644                 :     2712129 :   DECL_SAVED_TREE (fndecl) = NULL_TREE;
   20645                 :             : 
   20646                 :             :   /* If we had callee-copies statements, insert them at the beginning
   20647                 :             :      of the function and clear DECL_HAS_VALUE_EXPR_P on the parameters.  */
   20648                 :     2712129 :   if (!gimple_seq_empty_p (parm_stmts))
   20649                 :             :     {
   20650                 :          41 :       tree parm;
   20651                 :             : 
   20652                 :          41 :       gimplify_seq_add_seq (&parm_stmts, gimple_bind_body (outer_bind));
   20653                 :          41 :       if (parm_cleanup)
   20654                 :             :         {
   20655                 :           0 :           gtry *g = gimple_build_try (parm_stmts, parm_cleanup,
   20656                 :             :                                       GIMPLE_TRY_FINALLY);
   20657                 :           0 :           parm_stmts = NULL;
   20658                 :           0 :           gimple_seq_add_stmt (&parm_stmts, g);
   20659                 :             :         }
   20660                 :          41 :       gimple_bind_set_body (outer_bind, parm_stmts);
   20661                 :             : 
   20662                 :          41 :       for (parm = DECL_ARGUMENTS (current_function_decl);
   20663                 :         101 :            parm; parm = DECL_CHAIN (parm))
   20664                 :          60 :         if (DECL_HAS_VALUE_EXPR_P (parm))
   20665                 :             :           {
   20666                 :           0 :             DECL_HAS_VALUE_EXPR_P (parm) = 0;
   20667                 :           0 :             DECL_IGNORED_P (parm) = 0;
   20668                 :             :           }
   20669                 :             :     }
   20670                 :             : 
   20671                 :     2712129 :   if ((flag_openacc || flag_openmp || flag_openmp_simd)
   20672                 :       45808 :       && gimplify_omp_ctxp)
   20673                 :             :     {
   20674                 :        3393 :       delete_omp_context (gimplify_omp_ctxp);
   20675                 :        3393 :       gimplify_omp_ctxp = NULL;
   20676                 :             :     }
   20677                 :             : 
   20678                 :     2712129 :   pop_gimplify_context (outer_bind);
   20679                 :     2712129 :   gcc_assert (gimplify_ctxp == NULL);
   20680                 :             : 
   20681                 :     2712129 :   if (flag_checking && !seen_error ())
   20682                 :     2664657 :     verify_gimple_in_seq (gimple_bind_body (outer_bind));
   20683                 :             : 
   20684                 :     2712129 :   timevar_pop (TV_TREE_GIMPLIFY);
   20685                 :     2712129 :   input_location = saved_location;
   20686                 :             : 
   20687                 :     2712129 :   return outer_bind;
   20688                 :             : }
   20689                 :             : 
   20690                 :             : typedef char *char_p; /* For DEF_VEC_P.  */
   20691                 :             : 
   20692                 :             : /* Return whether we should exclude FNDECL from instrumentation.  */
   20693                 :             : 
   20694                 :             : static bool
   20695                 :          36 : flag_instrument_functions_exclude_p (tree fndecl)
   20696                 :             : {
   20697                 :          36 :   vec<char_p> *v;
   20698                 :             : 
   20699                 :          36 :   v = (vec<char_p> *) flag_instrument_functions_exclude_functions;
   20700                 :          37 :   if (v && v->length () > 0)
   20701                 :             :     {
   20702                 :           1 :       const char *name;
   20703                 :           1 :       int i;
   20704                 :           1 :       char *s;
   20705                 :             : 
   20706                 :           1 :       name = lang_hooks.decl_printable_name (fndecl, 1);
   20707                 :           2 :       FOR_EACH_VEC_ELT (*v, i, s)
   20708                 :           1 :         if (strstr (name, s) != NULL)
   20709                 :           2 :           return true;
   20710                 :             :     }
   20711                 :             : 
   20712                 :          35 :   v = (vec<char_p> *) flag_instrument_functions_exclude_files;
   20713                 :          36 :   if (v && v->length () > 0)
   20714                 :             :     {
   20715                 :           1 :       const char *name;
   20716                 :           1 :       int i;
   20717                 :           1 :       char *s;
   20718                 :             : 
   20719                 :           1 :       name = DECL_SOURCE_FILE (fndecl);
   20720                 :           1 :       FOR_EACH_VEC_ELT (*v, i, s)
   20721                 :           1 :         if (strstr (name, s) != NULL)
   20722                 :           2 :           return true;
   20723                 :             :     }
   20724                 :             : 
   20725                 :             :   return false;
   20726                 :             : }
   20727                 :             : 
   20728                 :             : /* Build a call to the instrumentation function FNCODE and add it to SEQ.
   20729                 :             :    If COND_VAR is not NULL, it is a boolean variable guarding the call to
   20730                 :             :    the instrumentation function.  IF STMT is not NULL, it is a statement
   20731                 :             :    to be executed just before the call to the instrumentation function.  */
   20732                 :             : 
   20733                 :             : static void
   20734                 :          68 : build_instrumentation_call (gimple_seq *seq, enum built_in_function fncode,
   20735                 :             :                             tree cond_var, gimple *stmt)
   20736                 :             : {
   20737                 :             :   /* The instrumentation hooks aren't going to call the instrumented
   20738                 :             :      function and the address they receive is expected to be matchable
   20739                 :             :      against symbol addresses.  Make sure we don't create a trampoline,
   20740                 :             :      in case the current function is nested.  */
   20741                 :          68 :   tree this_fn_addr = build_fold_addr_expr (current_function_decl);
   20742                 :          68 :   TREE_NO_TRAMPOLINE (this_fn_addr) = 1;
   20743                 :             : 
   20744                 :          68 :   tree label_true, label_false;
   20745                 :          68 :   if (cond_var)
   20746                 :             :     {
   20747                 :          10 :       label_true = create_artificial_label (UNKNOWN_LOCATION);
   20748                 :          10 :       label_false = create_artificial_label (UNKNOWN_LOCATION);
   20749                 :          10 :       gcond *cond = gimple_build_cond (EQ_EXPR, cond_var, boolean_false_node,
   20750                 :             :                                       label_true, label_false);
   20751                 :          10 :       gimplify_seq_add_stmt (seq, cond);
   20752                 :          10 :       gimplify_seq_add_stmt (seq, gimple_build_label (label_true));
   20753                 :          10 :       gimplify_seq_add_stmt (seq, gimple_build_predict (PRED_COLD_LABEL,
   20754                 :             :                                                         NOT_TAKEN));
   20755                 :             :     }
   20756                 :             : 
   20757                 :          68 :   if (stmt)
   20758                 :           5 :     gimplify_seq_add_stmt (seq, stmt);
   20759                 :             : 
   20760                 :          68 :   tree x = builtin_decl_implicit (BUILT_IN_RETURN_ADDRESS);
   20761                 :          68 :   gcall *call = gimple_build_call (x, 1, integer_zero_node);
   20762                 :          68 :   tree tmp_var = create_tmp_var (ptr_type_node, "return_addr");
   20763                 :          68 :   gimple_call_set_lhs (call, tmp_var);
   20764                 :          68 :   gimplify_seq_add_stmt (seq, call);
   20765                 :          68 :   x = builtin_decl_implicit (fncode);
   20766                 :          68 :   call = gimple_build_call (x, 2, this_fn_addr, tmp_var);
   20767                 :          68 :   gimplify_seq_add_stmt (seq, call);
   20768                 :             : 
   20769                 :          68 :   if (cond_var)
   20770                 :          10 :     gimplify_seq_add_stmt (seq, gimple_build_label (label_false));
   20771                 :          68 : }
   20772                 :             : 
   20773                 :             : /* Entry point to the gimplification pass.  FNDECL is the FUNCTION_DECL
   20774                 :             :    node for the function we want to gimplify.
   20775                 :             : 
   20776                 :             :    Return the sequence of GIMPLE statements corresponding to the body
   20777                 :             :    of FNDECL.  */
   20778                 :             : 
   20779                 :             : void
   20780                 :     2711611 : gimplify_function_tree (tree fndecl)
   20781                 :             : {
   20782                 :     2711611 :   gimple_seq seq;
   20783                 :     2711611 :   gbind *bind;
   20784                 :             : 
   20785                 :     2711611 :   gcc_assert (!gimple_body (fndecl));
   20786                 :             : 
   20787                 :     2711611 :   if (DECL_STRUCT_FUNCTION (fndecl))
   20788                 :     2708165 :     push_cfun (DECL_STRUCT_FUNCTION (fndecl));
   20789                 :             :   else
   20790                 :        3446 :     push_struct_function (fndecl);
   20791                 :             : 
   20792                 :     2711611 :   reset_cond_uid ();
   20793                 :     2711611 :   if (cond_uids)
   20794                 :             :     {
   20795                 :          65 :       delete cond_uids;
   20796                 :          65 :       cond_uids = NULL;
   20797                 :             :     }
   20798                 :             : 
   20799                 :             :   /* Tentatively set PROP_gimple_lva here, and reset it in gimplify_va_arg_expr
   20800                 :             :      if necessary.  */
   20801                 :     2711611 :   cfun->curr_properties |= PROP_gimple_lva;
   20802                 :             : 
   20803                 :     2711611 :   if (asan_sanitize_use_after_scope ())
   20804                 :        7976 :     asan_poisoned_variables = new hash_set<tree> ();
   20805                 :     2711611 :   if (flag_openmp)
   20806                 :       36042 :     omp_resolved_variant_calls = new hash_set<tree> ();
   20807                 :             : 
   20808                 :     2711611 :   bind = gimplify_body (fndecl, true);
   20809                 :             : 
   20810                 :     2711611 :   if (omp_resolved_variant_calls)
   20811                 :             :     {
   20812                 :       36042 :       delete omp_resolved_variant_calls;
   20813                 :       36042 :       omp_resolved_variant_calls = NULL;
   20814                 :             :     }
   20815                 :     2711611 :   if (asan_poisoned_variables)
   20816                 :             :     {
   20817                 :        7976 :       delete asan_poisoned_variables;
   20818                 :        7976 :       asan_poisoned_variables = NULL;
   20819                 :             :     }
   20820                 :             : 
   20821                 :             :   /* The tree body of the function is no longer needed, replace it
   20822                 :             :      with the new GIMPLE body.  */
   20823                 :     2711611 :   seq = NULL;
   20824                 :     2711611 :   gimple_seq_add_stmt (&seq, bind);
   20825                 :     2711611 :   gimple_set_body (fndecl, seq);
   20826                 :             : 
   20827                 :             :   /* If we're instrumenting function entry/exit, then prepend the call to
   20828                 :             :      the entry hook and wrap the whole function in a TRY_FINALLY_EXPR to
   20829                 :             :      catch the exit hook.  */
   20830                 :             :   /* ??? Add some way to ignore exceptions for this TFE.  */
   20831                 :     2711611 :   if (flag_instrument_function_entry_exit
   20832                 :          86 :       && !DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (fndecl)
   20833                 :             :       /* Do not instrument extern inline functions.  */
   20834                 :          37 :       && !(DECL_DECLARED_INLINE_P (fndecl)
   20835                 :           5 :            && DECL_EXTERNAL (fndecl)
   20836                 :           1 :            && DECL_DISREGARD_INLINE_LIMITS (fndecl))
   20837                 :     2711647 :       && !flag_instrument_functions_exclude_p (fndecl))
   20838                 :             :     {
   20839                 :          34 :       gimple_seq body = NULL, cleanup = NULL;
   20840                 :          34 :       gassign *assign;
   20841                 :          34 :       tree cond_var;
   20842                 :             : 
   20843                 :             :       /* If -finstrument-functions-once is specified, generate:
   20844                 :             : 
   20845                 :             :            static volatile bool C.0 = false;
   20846                 :             :            bool tmp_called;
   20847                 :             : 
   20848                 :             :            tmp_called = C.0;
   20849                 :             :            if (!tmp_called)
   20850                 :             :              {
   20851                 :             :                C.0 = true;
   20852                 :             :                [call profiling enter function]
   20853                 :             :              }
   20854                 :             : 
   20855                 :             :          without specific protection for data races.  */
   20856                 :          34 :       if (flag_instrument_function_entry_exit > 1)
   20857                 :             :         {
   20858                 :           5 :           tree first_var
   20859                 :           5 :             = build_decl (DECL_SOURCE_LOCATION (current_function_decl),
   20860                 :             :                           VAR_DECL,
   20861                 :             :                           create_tmp_var_name ("C"),
   20862                 :             :                           boolean_type_node);
   20863                 :           5 :           DECL_ARTIFICIAL (first_var) = 1;
   20864                 :           5 :           DECL_IGNORED_P (first_var) = 1;
   20865                 :           5 :           TREE_STATIC (first_var) = 1;
   20866                 :           5 :           TREE_THIS_VOLATILE (first_var) = 1;
   20867                 :           5 :           TREE_USED (first_var) = 1;
   20868                 :           5 :           DECL_INITIAL (first_var) = boolean_false_node;
   20869                 :           5 :           varpool_node::add (first_var);
   20870                 :             : 
   20871                 :           5 :           cond_var = create_tmp_var (boolean_type_node, "tmp_called");
   20872                 :           5 :           assign = gimple_build_assign (cond_var, first_var);
   20873                 :           5 :           gimplify_seq_add_stmt (&body, assign);
   20874                 :             : 
   20875                 :           5 :           assign = gimple_build_assign (first_var, boolean_true_node);
   20876                 :             :         }
   20877                 :             : 
   20878                 :             :       else
   20879                 :             :         {
   20880                 :             :           cond_var = NULL_TREE;
   20881                 :             :           assign = NULL;
   20882                 :             :         }
   20883                 :             : 
   20884                 :          34 :       build_instrumentation_call (&body, BUILT_IN_PROFILE_FUNC_ENTER,
   20885                 :             :                                   cond_var, assign);
   20886                 :             : 
   20887                 :             :       /* If -finstrument-functions-once is specified, generate:
   20888                 :             : 
   20889                 :             :            if (!tmp_called)
   20890                 :             :              [call profiling exit function]
   20891                 :             : 
   20892                 :             :          without specific protection for data races.  */
   20893                 :          34 :       build_instrumentation_call (&cleanup, BUILT_IN_PROFILE_FUNC_EXIT,
   20894                 :             :                                   cond_var, NULL);
   20895                 :             : 
   20896                 :          34 :       gimple *tf = gimple_build_try (seq, cleanup, GIMPLE_TRY_FINALLY);
   20897                 :          34 :       gimplify_seq_add_stmt (&body, tf);
   20898                 :          34 :       gbind *new_bind = gimple_build_bind (NULL, body, NULL);
   20899                 :             : 
   20900                 :             :       /* Replace the current function body with the body
   20901                 :             :          wrapped in the try/finally TF.  */
   20902                 :          34 :       seq = NULL;
   20903                 :          34 :       gimple_seq_add_stmt (&seq, new_bind);
   20904                 :          34 :       gimple_set_body (fndecl, seq);
   20905                 :          34 :       bind = new_bind;
   20906                 :             :     }
   20907                 :             : 
   20908                 :     2711611 :   if (sanitize_flags_p (SANITIZE_THREAD)
   20909                 :     2711611 :       && param_tsan_instrument_func_entry_exit)
   20910                 :             :     {
   20911                 :        1075 :       gcall *call = gimple_build_call_internal (IFN_TSAN_FUNC_EXIT, 0);
   20912                 :        1075 :       gimple *tf = gimple_build_try (seq, call, GIMPLE_TRY_FINALLY);
   20913                 :        1075 :       gbind *new_bind = gimple_build_bind (NULL, tf, NULL);
   20914                 :             :       /* Replace the current function body with the body
   20915                 :             :          wrapped in the try/finally TF.  */
   20916                 :        1075 :       seq = NULL;
   20917                 :        1075 :       gimple_seq_add_stmt (&seq, new_bind);
   20918                 :        1075 :       gimple_set_body (fndecl, seq);
   20919                 :             :     }
   20920                 :             : 
   20921                 :     2711611 :   DECL_SAVED_TREE (fndecl) = NULL_TREE;
   20922                 :     2711611 :   cfun->curr_properties |= PROP_gimple_any;
   20923                 :             : 
   20924                 :     2711611 :   pop_cfun ();
   20925                 :             : 
   20926                 :     2711611 :   dump_function (TDI_gimple, fndecl);
   20927                 :     2711611 : }
   20928                 :             : 
   20929                 :             : /* Return a dummy expression of type TYPE in order to keep going after an
   20930                 :             :    error.  */
   20931                 :             : 
   20932                 :             : static tree
   20933                 :          30 : dummy_object (tree type)
   20934                 :             : {
   20935                 :          30 :   tree t = build_int_cst (build_pointer_type (type), 0);
   20936                 :          30 :   return build2 (MEM_REF, type, t, t);
   20937                 :             : }
   20938                 :             : 
   20939                 :             : /* Gimplify __builtin_va_arg, aka VA_ARG_EXPR, which is not really a
   20940                 :             :    builtin function, but a very special sort of operator.  */
   20941                 :             : 
   20942                 :             : enum gimplify_status
   20943                 :       50788 : gimplify_va_arg_expr (tree *expr_p, gimple_seq *pre_p,
   20944                 :             :                       gimple_seq *post_p ATTRIBUTE_UNUSED)
   20945                 :             : {
   20946                 :       50788 :   tree promoted_type, have_va_type;
   20947                 :       50788 :   tree valist = TREE_OPERAND (*expr_p, 0);
   20948                 :       50788 :   tree type = TREE_TYPE (*expr_p);
   20949                 :       50788 :   tree t, tag, aptag;
   20950                 :       50788 :   location_t loc = EXPR_LOCATION (*expr_p);
   20951                 :             : 
   20952                 :             :   /* Verify that valist is of the proper type.  */
   20953                 :       50788 :   have_va_type = TREE_TYPE (valist);
   20954                 :       50788 :   if (have_va_type == error_mark_node)
   20955                 :             :     return GS_ERROR;
   20956                 :       50769 :   have_va_type = targetm.canonical_va_list_type (have_va_type);
   20957                 :       50769 :   if (have_va_type == NULL_TREE
   20958                 :       50769 :       && POINTER_TYPE_P (TREE_TYPE (valist)))
   20959                 :             :     /* Handle 'Case 1: Not an array type' from c-common.cc/build_va_arg.  */
   20960                 :         258 :     have_va_type
   20961                 :         258 :       = targetm.canonical_va_list_type (TREE_TYPE (TREE_TYPE (valist)));
   20962                 :       50769 :   gcc_assert (have_va_type != NULL_TREE);
   20963                 :             : 
   20964                 :             :   /* Generate a diagnostic for requesting data of a type that cannot
   20965                 :             :      be passed through `...' due to type promotion at the call site.  */
   20966                 :       50769 :   if ((promoted_type = lang_hooks.types.type_promotes_to (type))
   20967                 :             :            != type)
   20968                 :             :     {
   20969                 :          30 :       static bool gave_help;
   20970                 :          30 :       bool warned;
   20971                 :             :       /* Use the expansion point to handle cases such as passing bool (defined
   20972                 :             :          in a system header) through `...'.  */
   20973                 :          30 :       location_t xloc
   20974                 :          30 :         = expansion_point_location_if_in_system_header (loc);
   20975                 :             : 
   20976                 :             :       /* Unfortunately, this is merely undefined, rather than a constraint
   20977                 :             :          violation, so we cannot make this an error.  If this call is never
   20978                 :             :          executed, the program is still strictly conforming.  */
   20979                 :          30 :       auto_diagnostic_group d;
   20980                 :          30 :       warned = warning_at (xloc, 0,
   20981                 :             :                            "%qT is promoted to %qT when passed through %<...%>",
   20982                 :             :                            type, promoted_type);
   20983                 :          30 :       if (!gave_help && warned)
   20984                 :             :         {
   20985                 :          15 :           gave_help = true;
   20986                 :          15 :           inform (xloc, "(so you should pass %qT not %qT to %<va_arg%>)",
   20987                 :             :                   promoted_type, type);
   20988                 :             :         }
   20989                 :             : 
   20990                 :             :       /* We can, however, treat "undefined" any way we please.
   20991                 :             :          Call abort to encourage the user to fix the program.  */
   20992                 :          23 :       if (warned)
   20993                 :          23 :         inform (xloc, "if this code is reached, the program will abort");
   20994                 :             :       /* Before the abort, allow the evaluation of the va_list
   20995                 :             :          expression to exit or longjmp.  */
   20996                 :          30 :       gimplify_and_add (valist, pre_p);
   20997                 :          60 :       t = build_call_expr_loc (loc,
   20998                 :             :                                builtin_decl_implicit (BUILT_IN_TRAP), 0);
   20999                 :          30 :       gimplify_and_add (t, pre_p);
   21000                 :             : 
   21001                 :             :       /* This is dead code, but go ahead and finish so that the
   21002                 :             :          mode of the result comes out right.  */
   21003                 :          30 :       *expr_p = dummy_object (type);
   21004                 :          30 :       return GS_ALL_DONE;
   21005                 :          30 :     }
   21006                 :             : 
   21007                 :       50739 :   tag = build_int_cst (build_pointer_type (type), 0);
   21008                 :       50739 :   aptag = build_int_cst (TREE_TYPE (valist), 0);
   21009                 :             : 
   21010                 :       50739 :   *expr_p = build_call_expr_internal_loc (loc, IFN_VA_ARG, type, 3,
   21011                 :             :                                           valist, tag, aptag);
   21012                 :             : 
   21013                 :             :   /* Clear the tentatively set PROP_gimple_lva, to indicate that IFN_VA_ARG
   21014                 :             :      needs to be expanded.  */
   21015                 :       50739 :   cfun->curr_properties &= ~PROP_gimple_lva;
   21016                 :             : 
   21017                 :       50739 :   return GS_OK;
   21018                 :             : }
   21019                 :             : 
   21020                 :             : /* Build a new GIMPLE_ASSIGN tuple and append it to the end of *SEQ_P.
   21021                 :             : 
   21022                 :             :    DST/SRC are the destination and source respectively.  You can pass
   21023                 :             :    ungimplified trees in DST or SRC, in which case they will be
   21024                 :             :    converted to a gimple operand if necessary.
   21025                 :             : 
   21026                 :             :    This function returns the newly created GIMPLE_ASSIGN tuple.  */
   21027                 :             : 
   21028                 :             : gimple *
   21029                 :      720942 : gimplify_assign (tree dst, tree src, gimple_seq *seq_p)
   21030                 :             : {
   21031                 :      720942 :   tree t = build2 (MODIFY_EXPR, TREE_TYPE (dst), dst, src);
   21032                 :      720942 :   gimplify_and_add (t, seq_p);
   21033                 :      720942 :   ggc_free (t);
   21034                 :      720942 :   return gimple_seq_last_stmt (*seq_p);
   21035                 :             : }
   21036                 :             : 
   21037                 :             : inline hashval_t
   21038                 :     1548521 : gimplify_hasher::hash (const elt_t *p)
   21039                 :             : {
   21040                 :     1548521 :   tree t = p->val;
   21041                 :     1548521 :   return iterative_hash_expr (t, 0);
   21042                 :             : }
   21043                 :             : 
   21044                 :             : inline bool
   21045                 :      596944 : gimplify_hasher::equal (const elt_t *p1, const elt_t *p2)
   21046                 :             : {
   21047                 :      596944 :   tree t1 = p1->val;
   21048                 :      596944 :   tree t2 = p2->val;
   21049                 :      596944 :   enum tree_code code = TREE_CODE (t1);
   21050                 :             : 
   21051                 :      596944 :   if (TREE_CODE (t2) != code
   21052                 :      596944 :       || TREE_TYPE (t1) != TREE_TYPE (t2))
   21053                 :             :     return false;
   21054                 :             : 
   21055                 :      343014 :   if (!operand_equal_p (t1, t2, 0))
   21056                 :             :     return false;
   21057                 :             : 
   21058                 :             :   return true;
   21059                 :             : }
        

Generated by: LCOV version 2.1-beta

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.