LCOV - code coverage report
Current view: top level - gcc/fortran - trans-openmp.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 96.1 % 5188 4988
Test Date: 2024-04-20 14:03:02 Functions: 100.0 % 97 97
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* OpenMP directive translation -- generate GCC trees from gfc_code.
       2                 :             :    Copyright (C) 2005-2024 Free Software Foundation, Inc.
       3                 :             :    Contributed by Jakub Jelinek <jakub@redhat.com>
       4                 :             : 
       5                 :             : This file is part of GCC.
       6                 :             : 
       7                 :             : GCC is free software; you can redistribute it and/or modify it under
       8                 :             : the terms of the GNU General Public License as published by the Free
       9                 :             : Software Foundation; either version 3, or (at your option) any later
      10                 :             : version.
      11                 :             : 
      12                 :             : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      13                 :             : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      14                 :             : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      15                 :             : for more details.
      16                 :             : 
      17                 :             : You should have received a copy of the GNU General Public License
      18                 :             : along with GCC; see the file COPYING3.  If not see
      19                 :             : <http://www.gnu.org/licenses/>.  */
      20                 :             : 
      21                 :             : 
      22                 :             : #include "config.h"
      23                 :             : #include "system.h"
      24                 :             : #include "coretypes.h"
      25                 :             : #include "options.h"
      26                 :             : #include "tree.h"
      27                 :             : #include "gfortran.h"
      28                 :             : #include "gimple-expr.h"
      29                 :             : #include "trans.h"
      30                 :             : #include "stringpool.h"
      31                 :             : #include "fold-const.h"
      32                 :             : #include "gimplify.h" /* For create_tmp_var_raw.  */
      33                 :             : #include "trans-stmt.h"
      34                 :             : #include "trans-types.h"
      35                 :             : #include "trans-array.h"
      36                 :             : #include "trans-const.h"
      37                 :             : #include "arith.h"
      38                 :             : #include "constructor.h"
      39                 :             : #include "gomp-constants.h"
      40                 :             : #include "omp-general.h"
      41                 :             : #include "omp-low.h"
      42                 :             : #include "memmodel.h"  /* For MEMMODEL_ enums.  */
      43                 :             : #include "dependency.h"
      44                 :             : 
      45                 :             : #undef GCC_DIAG_STYLE
      46                 :             : #define GCC_DIAG_STYLE __gcc_tdiag__
      47                 :             : #include "diagnostic-core.h"
      48                 :             : #undef GCC_DIAG_STYLE
      49                 :             : #define GCC_DIAG_STYLE __gcc_gfc__
      50                 :             : #include "attribs.h"
      51                 :             : #include "function.h"
      52                 :             : 
      53                 :             : int ompws_flags;
      54                 :             : 
      55                 :             : /* True if OpenMP should regard this DECL as being a scalar which has Fortran's
      56                 :             :    allocatable or pointer attribute.  */
      57                 :             : 
      58                 :             : bool
      59                 :        5911 : gfc_omp_is_allocatable_or_ptr (const_tree decl)
      60                 :             : {
      61                 :        5911 :   return (DECL_P (decl)
      62                 :        5911 :           && (GFC_DECL_GET_SCALAR_POINTER (decl)
      63                 :        4180 :               || GFC_DECL_GET_SCALAR_ALLOCATABLE (decl)));
      64                 :             : }
      65                 :             : 
      66                 :             : /* True if the argument is an optional argument; except that false is also
      67                 :             :    returned for arguments with the value attribute (nonpointers) and for
      68                 :             :    assumed-shape variables (decl is a local variable containing arg->data).
      69                 :             :    Note that for 'procedure(), optional' the value false is used as that's
      70                 :             :    always a pointer and no additional indirection is used.
      71                 :             :    Note that pvoid_type_node is for 'type(c_ptr), value' (and c_funloc).  */
      72                 :             : 
      73                 :             : static bool
      74                 :       44206 : gfc_omp_is_optional_argument (const_tree decl)
      75                 :             : {
      76                 :             :   /* Note: VAR_DECL can occur with BIND(C) and array descriptors.  */
      77                 :       29199 :   return ((TREE_CODE (decl) == PARM_DECL || VAR_P (decl))
      78                 :       44206 :           && DECL_LANG_SPECIFIC (decl)
      79                 :       20150 :           && TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE
      80                 :       19968 :           && !VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl)))
      81                 :       19737 :           && TREE_CODE (TREE_TYPE (TREE_TYPE (decl))) != FUNCTION_TYPE
      82                 :       63919 :           && GFC_DECL_OPTIONAL_ARGUMENT (decl));
      83                 :             : }
      84                 :             : 
      85                 :             : /* Check whether this DECL belongs to a Fortran optional argument.
      86                 :             :    With 'for_present_check' set to false, decls which are optional parameters
      87                 :             :    themselves are returned as tree - or a NULL_TREE otherwise. Those decls are
      88                 :             :    always pointers.  With 'for_present_check' set to true, the decl for checking
      89                 :             :    whether an argument is present is returned; for arguments with value
      90                 :             :    attribute this is the hidden argument and of BOOLEAN_TYPE.  If the decl is
      91                 :             :    unrelated to optional arguments, NULL_TREE is returned.  */
      92                 :             : 
      93                 :             : tree
      94                 :       20892 : gfc_omp_check_optional_argument (tree decl, bool for_present_check)
      95                 :             : {
      96                 :       20892 :   if (!for_present_check)
      97                 :        2104 :     return gfc_omp_is_optional_argument (decl) ? decl : NULL_TREE;
      98                 :             : 
      99                 :       18788 :   if (!DECL_LANG_SPECIFIC (decl))
     100                 :             :     return NULL_TREE;
     101                 :             : 
     102                 :        5010 :   tree orig_decl = decl;
     103                 :             : 
     104                 :             :   /* For assumed-shape arrays, a local decl with arg->data is used.  */
     105                 :        5010 :   if (TREE_CODE (decl) != PARM_DECL
     106                 :        5010 :       && (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl))
     107                 :        1646 :           || GFC_ARRAY_TYPE_P (TREE_TYPE (decl))))
     108                 :         722 :     decl = GFC_DECL_SAVED_DESCRIPTOR (decl);
     109                 :             : 
     110                 :             :   /* Note: With BIND(C), array descriptors are converted to a VAR_DECL.  */
     111                 :        5010 :   if (decl == NULL_TREE
     112                 :        4891 :       || (TREE_CODE (decl) != PARM_DECL && TREE_CODE (decl) != VAR_DECL)
     113                 :        4891 :       || !DECL_LANG_SPECIFIC (decl)
     114                 :        9499 :       || !GFC_DECL_OPTIONAL_ARGUMENT (decl))
     115                 :             :     return NULL_TREE;
     116                 :             : 
     117                 :             :    /* Scalars with VALUE attribute which are passed by value use a hidden
     118                 :             :       argument to denote the present status.  They are passed as nonpointer type
     119                 :             :       with one exception: 'type(c_ptr), value' as 'void*'.  */
     120                 :             :    /* Cf. trans-expr.cc's gfc_conv_expr_present.  */
     121                 :        2810 :    if (TREE_CODE (TREE_TYPE (decl)) != POINTER_TYPE
     122                 :        2810 :        || VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl))))
     123                 :             :     {
     124                 :         205 :       char name[GFC_MAX_SYMBOL_LEN + 2];
     125                 :         205 :       tree tree_name;
     126                 :             : 
     127                 :         205 :       name[0] = '.';
     128                 :         205 :       strcpy (&name[1], IDENTIFIER_POINTER (DECL_NAME (decl)));
     129                 :         205 :       tree_name = get_identifier (name);
     130                 :             : 
     131                 :             :       /* Walk function argument list to find the hidden arg.  */
     132                 :         205 :       decl = DECL_ARGUMENTS (DECL_CONTEXT (decl));
     133                 :        1437 :       for ( ; decl != NULL_TREE; decl = TREE_CHAIN (decl))
     134                 :        1437 :         if (DECL_NAME (decl) == tree_name
     135                 :        1437 :             && DECL_ARTIFICIAL (decl))
     136                 :             :           break;
     137                 :             : 
     138                 :         205 :       gcc_assert (decl);
     139                 :         205 :       return decl;
     140                 :             :     }
     141                 :             : 
     142                 :        2605 :   return fold_build2_loc (input_location, NE_EXPR, boolean_type_node,
     143                 :        2605 :                           orig_decl, null_pointer_node);
     144                 :             : }
     145                 :             : 
     146                 :             : 
     147                 :             : /* Returns tree with NULL if it is not an array descriptor and with the tree to
     148                 :             :    access the 'data' component otherwise.  With type_only = true, it returns the
     149                 :             :    TREE_TYPE without creating a new tree.  */
     150                 :             : 
     151                 :             : tree
     152                 :       18194 : gfc_omp_array_data (tree decl, bool type_only)
     153                 :             : {
     154                 :       18194 :   tree type = TREE_TYPE (decl);
     155                 :             : 
     156                 :       18194 :   if (POINTER_TYPE_P (type))
     157                 :        9961 :     type = TREE_TYPE (type);
     158                 :             : 
     159                 :       18194 :   if (!GFC_DESCRIPTOR_TYPE_P (type))
     160                 :             :     return NULL_TREE;
     161                 :             : 
     162                 :        4540 :   if (type_only)
     163                 :        3322 :     return GFC_TYPE_ARRAY_DATAPTR_TYPE (type);
     164                 :             : 
     165                 :        1218 :   if (POINTER_TYPE_P (TREE_TYPE (decl)))
     166                 :         414 :     decl = build_fold_indirect_ref (decl);
     167                 :             : 
     168                 :        1218 :   decl = gfc_conv_descriptor_data_get (decl);
     169                 :        1218 :   STRIP_NOPS (decl);
     170                 :        1218 :   return decl;
     171                 :             : }
     172                 :             : 
     173                 :             : /* Return the byte-size of the passed array descriptor. */
     174                 :             : 
     175                 :             : tree
     176                 :          18 : gfc_omp_array_size (tree decl, gimple_seq *pre_p)
     177                 :             : {
     178                 :          18 :   stmtblock_t block;
     179                 :          18 :   if (POINTER_TYPE_P (TREE_TYPE (decl)))
     180                 :          18 :     decl = build_fold_indirect_ref (decl);
     181                 :          18 :   tree type = TREE_TYPE (decl);
     182                 :          18 :   gcc_assert (GFC_DESCRIPTOR_TYPE_P (type));
     183                 :          18 :   bool allocatable = (GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_ALLOCATABLE
     184                 :           2 :                       || GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_POINTER
     185                 :          18 :                       || GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_POINTER_CONT);
     186                 :          18 :   gfc_init_block (&block);
     187                 :          54 :   tree size = gfc_full_array_size (&block, decl,
     188                 :          18 :                                    GFC_TYPE_ARRAY_RANK (TREE_TYPE (decl)));
     189                 :          18 :   size = fold_convert (size_type_node, size);
     190                 :          18 :   tree elemsz = gfc_get_element_type (TREE_TYPE (decl));
     191                 :          18 :   if (TREE_CODE (elemsz) == ARRAY_TYPE && TYPE_STRING_FLAG (elemsz))
     192                 :           6 :     elemsz = gfc_conv_descriptor_elem_len (decl);
     193                 :             :   else
     194                 :          12 :     elemsz = TYPE_SIZE_UNIT (elemsz);
     195                 :          18 :   size = fold_build2 (MULT_EXPR, size_type_node, size, elemsz);
     196                 :          18 :   if (!allocatable)
     197                 :           0 :     gimplify_and_add (gfc_finish_block (&block), pre_p);
     198                 :             :   else
     199                 :             :     {
     200                 :          18 :       tree var = create_tmp_var (size_type_node);
     201                 :          18 :       gfc_add_expr_to_block (&block, build2 (MODIFY_EXPR, sizetype, var, size));
     202                 :          18 :       tree tmp = fold_build2_loc (input_location, NE_EXPR, boolean_type_node,
     203                 :             :                                   gfc_conv_descriptor_data_get (decl),
     204                 :             :                                   null_pointer_node);
     205                 :          18 :       tmp = build3_loc (input_location, COND_EXPR, void_type_node, tmp,
     206                 :             :                         gfc_finish_block (&block),
     207                 :             :                         build2 (MODIFY_EXPR, sizetype, var, size_zero_node));
     208                 :          18 :       gimplify_and_add (tmp, pre_p);
     209                 :          18 :       size = var;
     210                 :             :     }
     211                 :          18 :   return size;
     212                 :             : }
     213                 :             : 
     214                 :             : 
     215                 :             : /* True if OpenMP should privatize what this DECL points to rather
     216                 :             :    than the DECL itself.  */
     217                 :             : 
     218                 :             : bool
     219                 :      437755 : gfc_omp_privatize_by_reference (const_tree decl)
     220                 :             : {
     221                 :      437755 :   tree type = TREE_TYPE (decl);
     222                 :             : 
     223                 :      437755 :   if (TREE_CODE (type) == REFERENCE_TYPE
     224                 :      437755 :       && (!DECL_ARTIFICIAL (decl) || TREE_CODE (decl) == PARM_DECL))
     225                 :             :     return true;
     226                 :             : 
     227                 :      415374 :   if (TREE_CODE (type) == POINTER_TYPE
     228                 :      415374 :       && gfc_omp_is_optional_argument (decl))
     229                 :             :     return true;
     230                 :             : 
     231                 :      406326 :   if (TREE_CODE (type) == POINTER_TYPE)
     232                 :             :     {
     233                 :       31021 :       while (TREE_CODE (decl) == COMPONENT_REF)
     234                 :           0 :         decl = TREE_OPERAND (decl, 1);
     235                 :             : 
     236                 :             :       /* Array POINTER/ALLOCATABLE have aggregate types, all user variables
     237                 :             :          that have POINTER_TYPE type and aren't scalar pointers, scalar
     238                 :             :          allocatables, Cray pointees or C pointers are supposed to be
     239                 :             :          privatized by reference.  */
     240                 :       31021 :       if (GFC_DECL_GET_SCALAR_POINTER (decl)
     241                 :       29531 :           || GFC_DECL_GET_SCALAR_ALLOCATABLE (decl)
     242                 :       27294 :           || GFC_DECL_CRAY_POINTEE (decl)
     243                 :       27288 :           || GFC_DECL_ASSOCIATE_VAR_P (decl)
     244                 :       36130 :           || VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl))))
     245                 :             :         return false;
     246                 :             : 
     247                 :       19565 :       if (!DECL_ARTIFICIAL (decl)
     248                 :       19565 :           && TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE)
     249                 :             :         return true;
     250                 :             : 
     251                 :             :       /* Some arrays are expanded as DECL_ARTIFICIAL pointers
     252                 :             :          by the frontend.  */
     253                 :       12781 :       if (DECL_LANG_SPECIFIC (decl)
     254                 :       12781 :           && GFC_DECL_SAVED_DESCRIPTOR (decl))
     255                 :             :         return true;
     256                 :             :     }
     257                 :             : 
     258                 :             :   return false;
     259                 :             : }
     260                 :             : 
     261                 :             : /* OMP_CLAUSE_DEFAULT_UNSPECIFIED unless OpenMP sharing attribute
     262                 :             :    of DECL is predetermined.  */
     263                 :             : 
     264                 :             : enum omp_clause_default_kind
     265                 :        7400 : gfc_omp_predetermined_sharing (tree decl)
     266                 :             : {
     267                 :             :   /* Associate names preserve the association established during ASSOCIATE.
     268                 :             :      As they are implemented either as pointers to the selector or array
     269                 :             :      descriptor and shouldn't really change in the ASSOCIATE region,
     270                 :             :      this decl can be either shared or firstprivate.  If it is a pointer,
     271                 :             :      use firstprivate, as it is cheaper that way, otherwise make it shared.  */
     272                 :        7400 :   if (GFC_DECL_ASSOCIATE_VAR_P (decl))
     273                 :             :     {
     274                 :          45 :       if (TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE)
     275                 :             :         return OMP_CLAUSE_DEFAULT_FIRSTPRIVATE;
     276                 :             :       else
     277                 :          18 :         return OMP_CLAUSE_DEFAULT_SHARED;
     278                 :             :     }
     279                 :             : 
     280                 :        7355 :   if (DECL_ARTIFICIAL (decl)
     281                 :        1299 :       && ! GFC_DECL_RESULT (decl)
     282                 :        8654 :       && ! (DECL_LANG_SPECIFIC (decl)
     283                 :         156 :             && GFC_DECL_SAVED_DESCRIPTOR (decl)))
     284                 :             :     return OMP_CLAUSE_DEFAULT_SHARED;
     285                 :             : 
     286                 :             :   /* Cray pointees shouldn't be listed in any clauses and should be
     287                 :             :      gimplified to dereference of the corresponding Cray pointer.
     288                 :             :      Make them all private, so that they are emitted in the debug
     289                 :             :      information.  */
     290                 :        6188 :   if (GFC_DECL_CRAY_POINTEE (decl))
     291                 :             :     return OMP_CLAUSE_DEFAULT_PRIVATE;
     292                 :             : 
     293                 :             :   /* Assumed-size arrays are predetermined shared.  */
     294                 :        6152 :   if (TREE_CODE (decl) == PARM_DECL
     295                 :        1479 :       && GFC_ARRAY_TYPE_P (TREE_TYPE (decl))
     296                 :         507 :       && GFC_TYPE_ARRAY_AKIND (TREE_TYPE (decl)) == GFC_ARRAY_UNKNOWN
     297                 :        6659 :       && GFC_TYPE_ARRAY_UBOUND (TREE_TYPE (decl),
     298                 :             :                                 GFC_TYPE_ARRAY_RANK (TREE_TYPE (decl)) - 1)
     299                 :             :          == NULL)
     300                 :             :     return OMP_CLAUSE_DEFAULT_SHARED;
     301                 :             : 
     302                 :             :   /* Dummy procedures aren't considered variables by OpenMP, thus are
     303                 :             :      disallowed in OpenMP clauses.  They are represented as PARM_DECLs
     304                 :             :      in the middle-end, so return OMP_CLAUSE_DEFAULT_FIRSTPRIVATE here
     305                 :             :      to avoid complaining about their uses with default(none).  */
     306                 :        6084 :   if (TREE_CODE (decl) == PARM_DECL
     307                 :        1411 :       && TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE
     308                 :        6617 :       && TREE_CODE (TREE_TYPE (TREE_TYPE (decl))) == FUNCTION_TYPE)
     309                 :             :     return OMP_CLAUSE_DEFAULT_FIRSTPRIVATE;
     310                 :             : 
     311                 :             :   /* COMMON and EQUIVALENCE decls are shared.  They
     312                 :             :      are only referenced through DECL_VALUE_EXPR of the variables
     313                 :             :      contained in them.  If those are privatized, they will not be
     314                 :             :      gimplified to the COMMON or EQUIVALENCE decls.  */
     315                 :        6069 :   if (GFC_DECL_COMMON_OR_EQUIV (decl) && ! DECL_HAS_VALUE_EXPR_P (decl))
     316                 :             :     return OMP_CLAUSE_DEFAULT_SHARED;
     317                 :             : 
     318                 :        6040 :   if (GFC_DECL_RESULT (decl) && ! DECL_HAS_VALUE_EXPR_P (decl))
     319                 :             :     return OMP_CLAUSE_DEFAULT_SHARED;
     320                 :             : 
     321                 :             :   /* These are either array or derived parameters, or vtables.
     322                 :             :      In the former cases, the OpenMP standard doesn't consider them to be
     323                 :             :      variables at all (they can't be redefined), but they can nevertheless appear
     324                 :             :      in parallel/task regions and for default(none) purposes treat them as shared.
     325                 :             :      For vtables likely the same handling is desirable.  */
     326                 :        4644 :   if (VAR_P (decl) && TREE_READONLY (decl)
     327                 :        6043 :       && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
     328                 :           3 :     return OMP_CLAUSE_DEFAULT_SHARED;
     329                 :             : 
     330                 :             :   return OMP_CLAUSE_DEFAULT_UNSPECIFIED;
     331                 :             : }
     332                 :             : 
     333                 :             : 
     334                 :             : /* OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED unless OpenMP mapping attribute
     335                 :             :    of DECL is predetermined.  */
     336                 :             : 
     337                 :             : enum omp_clause_defaultmap_kind
     338                 :        3610 : gfc_omp_predetermined_mapping (tree decl)
     339                 :             : {
     340                 :        3610 :   if (DECL_ARTIFICIAL (decl)
     341                 :         817 :       && ! GFC_DECL_RESULT (decl)
     342                 :        4427 :       && ! (DECL_LANG_SPECIFIC (decl)
     343                 :          64 :             && GFC_DECL_SAVED_DESCRIPTOR (decl)))
     344                 :             :     return OMP_CLAUSE_DEFAULTMAP_TO;
     345                 :             : 
     346                 :             :   /* Dummy procedures aren't considered variables by OpenMP, thus are
     347                 :             :      disallowed in OpenMP clauses.  They are represented as PARM_DECLs
     348                 :             :      in the middle-end, so return OMP_CLAUSE_DEFAULTMAP_FIRSTPRIVATE here
     349                 :             :      to avoid complaining about their uses with defaultmap(none).  */
     350                 :        2833 :   if (TREE_CODE (decl) == PARM_DECL
     351                 :        1703 :       && TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE
     352                 :        3183 :       && TREE_CODE (TREE_TYPE (TREE_TYPE (decl))) == FUNCTION_TYPE)
     353                 :             :     return OMP_CLAUSE_DEFAULTMAP_FIRSTPRIVATE;
     354                 :             : 
     355                 :             :   /* These are either array or derived parameters, or vtables.  */
     356                 :        1130 :   if (VAR_P (decl) && TREE_READONLY (decl)
     357                 :        2826 :       && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
     358                 :             :     return OMP_CLAUSE_DEFAULTMAP_TO;
     359                 :             : 
     360                 :             :   return OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED;
     361                 :             : }
     362                 :             : 
     363                 :             : 
     364                 :             : /* Return decl that should be used when reporting DEFAULT(NONE)
     365                 :             :    diagnostics.  */
     366                 :             : 
     367                 :             : tree
     368                 :         104 : gfc_omp_report_decl (tree decl)
     369                 :             : {
     370                 :         104 :   if (DECL_ARTIFICIAL (decl)
     371                 :           3 :       && DECL_LANG_SPECIFIC (decl)
     372                 :         107 :       && GFC_DECL_SAVED_DESCRIPTOR (decl))
     373                 :           3 :     return GFC_DECL_SAVED_DESCRIPTOR (decl);
     374                 :             : 
     375                 :             :   return decl;
     376                 :             : }
     377                 :             : 
     378                 :             : /* Return true if TYPE has any allocatable components.  */
     379                 :             : 
     380                 :             : static bool
     381                 :       91964 : gfc_has_alloc_comps (tree type, tree decl)
     382                 :             : {
     383                 :       91964 :   tree field, ftype;
     384                 :             : 
     385                 :       91964 :   if (POINTER_TYPE_P (type))
     386                 :             :     {
     387                 :        3083 :       if (GFC_DECL_GET_SCALAR_ALLOCATABLE (decl))
     388                 :        2313 :         type = TREE_TYPE (type);
     389                 :         770 :       else if (GFC_DECL_GET_SCALAR_POINTER (decl))
     390                 :             :         return false;
     391                 :             :     }
     392                 :             : 
     393                 :       91831 :   if (GFC_DESCRIPTOR_TYPE_P (type)
     394                 :       91831 :       && (GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_POINTER
     395                 :        2886 :           || GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_POINTER_CONT))
     396                 :             :     return false;
     397                 :             : 
     398                 :       91722 :   if (GFC_DESCRIPTOR_TYPE_P (type) || GFC_ARRAY_TYPE_P (type))
     399                 :        6543 :     type = gfc_get_element_type (type);
     400                 :             : 
     401                 :       91722 :   if (TREE_CODE (type) != RECORD_TYPE)
     402                 :             :     return false;
     403                 :             : 
     404                 :        6063 :   for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
     405                 :             :     {
     406                 :        5576 :       ftype = TREE_TYPE (field);
     407                 :        5576 :       if (GFC_DECL_GET_SCALAR_ALLOCATABLE (field))
     408                 :             :         return true;
     409                 :        5574 :       if (GFC_DESCRIPTOR_TYPE_P (ftype)
     410                 :        5574 :           && GFC_TYPE_ARRAY_AKIND (ftype) == GFC_ARRAY_ALLOCATABLE)
     411                 :             :         return true;
     412                 :        3846 :       if (gfc_has_alloc_comps (ftype, field))
     413                 :             :         return true;
     414                 :             :     }
     415                 :             :   return false;
     416                 :             : }
     417                 :             : 
     418                 :             : /* Return true if TYPE is polymorphic but not with pointer attribute.  */
     419                 :             : 
     420                 :             : static bool
     421                 :       39330 : gfc_is_polymorphic_nonptr (tree type)
     422                 :             : {
     423                 :       39330 :   if (POINTER_TYPE_P (type))
     424                 :        3317 :     type = TREE_TYPE (type);
     425                 :       39330 :   return GFC_CLASS_TYPE_P (type);
     426                 :             : }
     427                 :             : 
     428                 :             : /* Return true if TYPE is unlimited polymorphic but not with pointer attribute;
     429                 :             :    unlimited means also intrinsic types are handled and _len is used.  */
     430                 :             : 
     431                 :             : static bool
     432                 :          36 : gfc_is_unlimited_polymorphic_nonptr (tree type)
     433                 :             : {
     434                 :          36 :   if (POINTER_TYPE_P (type))
     435                 :           0 :     type = TREE_TYPE (type);
     436                 :          36 :   if (!GFC_CLASS_TYPE_P (type))
     437                 :             :     return false;
     438                 :             : 
     439                 :          36 :   tree field = TYPE_FIELDS (type); /* _data */
     440                 :          36 :   gcc_assert (field);
     441                 :          36 :   field = DECL_CHAIN (field); /* _vptr */
     442                 :          36 :   gcc_assert (field);
     443                 :          36 :   field = DECL_CHAIN (field);
     444                 :          36 :   if (!field)
     445                 :             :     return false;
     446                 :          24 :   gcc_assert (strcmp ("_len", IDENTIFIER_POINTER (DECL_NAME (field))) == 0);
     447                 :             :   return true;
     448                 :             : }
     449                 :             : 
     450                 :             : /* Return true if the DECL is for an allocatable array or scalar.  */
     451                 :             : 
     452                 :             : bool
     453                 :        3610 : gfc_omp_allocatable_p (tree decl)
     454                 :             : {
     455                 :        3610 :   if (!DECL_P (decl))
     456                 :             :     return false;
     457                 :             : 
     458                 :        3610 :   if (GFC_DECL_GET_SCALAR_ALLOCATABLE (decl))
     459                 :             :     return true;
     460                 :             : 
     461                 :        3413 :   tree type = TREE_TYPE (decl);
     462                 :        3413 :   if (gfc_omp_privatize_by_reference (decl))
     463                 :        1689 :     type = TREE_TYPE (type);
     464                 :             : 
     465                 :        3413 :   if (GFC_DESCRIPTOR_TYPE_P (type)
     466                 :        3413 :       && GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_ALLOCATABLE)
     467                 :             :     return true;
     468                 :             : 
     469                 :             :   return false;
     470                 :             : }
     471                 :             : 
     472                 :             : 
     473                 :             : /* Return true if DECL in private clause needs
     474                 :             :    OMP_CLAUSE_PRIVATE_OUTER_REF on the private clause.  */
     475                 :             : bool
     476                 :       13436 : gfc_omp_private_outer_ref (tree decl)
     477                 :             : {
     478                 :       13436 :   tree type = TREE_TYPE (decl);
     479                 :             : 
     480                 :       13436 :   if (gfc_omp_privatize_by_reference (decl))
     481                 :         611 :     type = TREE_TYPE (type);
     482                 :             : 
     483                 :       13436 :   if (GFC_DESCRIPTOR_TYPE_P (type)
     484                 :       13436 :       && GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_ALLOCATABLE)
     485                 :             :     return true;
     486                 :             : 
     487                 :       13310 :   if (GFC_DECL_GET_SCALAR_ALLOCATABLE (decl))
     488                 :             :     return true;
     489                 :             : 
     490                 :       13224 :   if (gfc_has_alloc_comps (type, decl))
     491                 :             :     return true;
     492                 :             : 
     493                 :             :   return false;
     494                 :             : }
     495                 :             : 
     496                 :             : /* Callback for gfc_omp_unshare_expr.  */
     497                 :             : 
     498                 :             : static tree
     499                 :       92286 : gfc_omp_unshare_expr_r (tree *tp, int *walk_subtrees, void *)
     500                 :             : {
     501                 :       92286 :   tree t = *tp;
     502                 :       92286 :   enum tree_code code = TREE_CODE (t);
     503                 :             : 
     504                 :             :   /* Stop at types, decls, constants like copy_tree_r.  */
     505                 :       92286 :   if (TREE_CODE_CLASS (code) == tcc_type
     506                 :             :       || TREE_CODE_CLASS (code) == tcc_declaration
     507                 :       92286 :       || TREE_CODE_CLASS (code) == tcc_constant
     508                 :       61181 :       || code == BLOCK)
     509                 :       31105 :     *walk_subtrees = 0;
     510                 :       61181 :   else if (handled_component_p (t)
     511                 :       46252 :            || TREE_CODE (t) == MEM_REF)
     512                 :             :     {
     513                 :       14989 :       *tp = unshare_expr (t);
     514                 :       14989 :       *walk_subtrees = 0;
     515                 :             :     }
     516                 :             : 
     517                 :       92286 :   return NULL_TREE;
     518                 :             : }
     519                 :             : 
     520                 :             : /* Unshare in expr anything that the FE which normally doesn't
     521                 :             :    care much about tree sharing (because during gimplification
     522                 :             :    everything is unshared) could cause problems with tree sharing
     523                 :             :    at omp-low.cc time.  */
     524                 :             : 
     525                 :             : static tree
     526                 :        5067 : gfc_omp_unshare_expr (tree expr)
     527                 :             : {
     528                 :        5067 :   walk_tree (&expr, gfc_omp_unshare_expr_r, NULL, NULL);
     529                 :        5067 :   return expr;
     530                 :             : }
     531                 :             : 
     532                 :             : enum walk_alloc_comps
     533                 :             : {
     534                 :             :   WALK_ALLOC_COMPS_DTOR,
     535                 :             :   WALK_ALLOC_COMPS_DEFAULT_CTOR,
     536                 :             :   WALK_ALLOC_COMPS_COPY_CTOR
     537                 :             : };
     538                 :             : 
     539                 :             : /* Handle allocatable components in OpenMP clauses.  */
     540                 :             : 
     541                 :             : static tree
     542                 :        2801 : gfc_walk_alloc_comps (tree decl, tree dest, tree var,
     543                 :             :                       enum walk_alloc_comps kind)
     544                 :             : {
     545                 :        2801 :   stmtblock_t block, tmpblock;
     546                 :        2801 :   tree type = TREE_TYPE (decl), then_b, tem, field;
     547                 :        2801 :   gfc_init_block (&block);
     548                 :             : 
     549                 :        2801 :   if (GFC_ARRAY_TYPE_P (type) || GFC_DESCRIPTOR_TYPE_P (type))
     550                 :             :     {
     551                 :        1092 :       if (GFC_DESCRIPTOR_TYPE_P (type))
     552                 :             :         {
     553                 :         548 :           gfc_init_block (&tmpblock);
     554                 :        1644 :           tem = gfc_full_array_size (&tmpblock, decl,
     555                 :         548 :                                      GFC_TYPE_ARRAY_RANK (type));
     556                 :         548 :           then_b = gfc_finish_block (&tmpblock);
     557                 :         548 :           gfc_add_expr_to_block (&block, gfc_omp_unshare_expr (then_b));
     558                 :         548 :           tem = gfc_omp_unshare_expr (tem);
     559                 :         548 :           tem = fold_build2_loc (input_location, MINUS_EXPR,
     560                 :             :                                  gfc_array_index_type, tem,
     561                 :             :                                  gfc_index_one_node);
     562                 :             :         }
     563                 :             :       else
     564                 :             :         {
     565                 :         544 :           bool compute_nelts = false;
     566                 :         544 :           if (!TYPE_DOMAIN (type)
     567                 :         544 :               || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE
     568                 :         544 :               || TYPE_MIN_VALUE (TYPE_DOMAIN (type)) == error_mark_node
     569                 :        1088 :               || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == error_mark_node)
     570                 :             :             compute_nelts = true;
     571                 :         544 :           else if (VAR_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
     572                 :             :             {
     573                 :          80 :               tree a = DECL_ATTRIBUTES (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
     574                 :          80 :               if (lookup_attribute ("omp dummy var", a))
     575                 :             :                 compute_nelts = true;
     576                 :             :             }
     577                 :             :           if (compute_nelts)
     578                 :             :             {
     579                 :          80 :               tem = fold_build2 (EXACT_DIV_EXPR, sizetype,
     580                 :             :                                  TYPE_SIZE_UNIT (type),
     581                 :             :                                  TYPE_SIZE_UNIT (TREE_TYPE (type)));
     582                 :          80 :               tem = size_binop (MINUS_EXPR, tem, size_one_node);
     583                 :             :             }
     584                 :             :           else
     585                 :         464 :             tem = array_type_nelts (type);
     586                 :         544 :           tem = fold_convert (gfc_array_index_type, tem);
     587                 :             :         }
     588                 :             : 
     589                 :        1092 :       tree nelems = gfc_evaluate_now (tem, &block);
     590                 :        1092 :       tree index = gfc_create_var (gfc_array_index_type, "S");
     591                 :             : 
     592                 :        1092 :       gfc_init_block (&tmpblock);
     593                 :        1092 :       tem = gfc_conv_array_data (decl);
     594                 :        1092 :       tree declvar = build_fold_indirect_ref_loc (input_location, tem);
     595                 :        1092 :       tree declvref = gfc_build_array_ref (declvar, index, NULL);
     596                 :        1092 :       tree destvar, destvref = NULL_TREE;
     597                 :        1092 :       if (dest)
     598                 :             :         {
     599                 :         546 :           tem = gfc_conv_array_data (dest);
     600                 :         546 :           destvar = build_fold_indirect_ref_loc (input_location, tem);
     601                 :         546 :           destvref = gfc_build_array_ref (destvar, index, NULL);
     602                 :             :         }
     603                 :        1092 :       gfc_add_expr_to_block (&tmpblock,
     604                 :             :                              gfc_walk_alloc_comps (declvref, destvref,
     605                 :             :                                                    var, kind));
     606                 :             : 
     607                 :        1092 :       gfc_loopinfo loop;
     608                 :        1092 :       gfc_init_loopinfo (&loop);
     609                 :        1092 :       loop.dimen = 1;
     610                 :        1092 :       loop.from[0] = gfc_index_zero_node;
     611                 :        1092 :       loop.loopvar[0] = index;
     612                 :        1092 :       loop.to[0] = nelems;
     613                 :        1092 :       gfc_trans_scalarizing_loops (&loop, &tmpblock);
     614                 :        1092 :       gfc_add_block_to_block (&block, &loop.pre);
     615                 :        1092 :       return gfc_finish_block (&block);
     616                 :             :     }
     617                 :        1709 :   else if (GFC_DECL_GET_SCALAR_ALLOCATABLE (var))
     618                 :             :     {
     619                 :         536 :       decl = build_fold_indirect_ref_loc (input_location, decl);
     620                 :         536 :       if (dest)
     621                 :         268 :         dest = build_fold_indirect_ref_loc (input_location, dest);
     622                 :         536 :       type = TREE_TYPE (decl);
     623                 :             :     }
     624                 :             : 
     625                 :        1709 :   gcc_assert (TREE_CODE (type) == RECORD_TYPE);
     626                 :       11488 :   for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
     627                 :             :     {
     628                 :        9779 :       tree ftype = TREE_TYPE (field);
     629                 :        9779 :       tree declf, destf = NULL_TREE;
     630                 :        9779 :       bool has_alloc_comps = gfc_has_alloc_comps (ftype, field);
     631                 :        9779 :       if ((!GFC_DESCRIPTOR_TYPE_P (ftype)
     632                 :        1708 :            || GFC_TYPE_ARRAY_AKIND (ftype) != GFC_ARRAY_ALLOCATABLE)
     633                 :        8071 :           && !GFC_DECL_GET_SCALAR_ALLOCATABLE (field)
     634                 :       16153 :           && !has_alloc_comps)
     635                 :        5950 :         continue;
     636                 :        3829 :       declf = fold_build3_loc (input_location, COMPONENT_REF, ftype,
     637                 :             :                                decl, field, NULL_TREE);
     638                 :        3829 :       if (dest)
     639                 :        1915 :         destf = fold_build3_loc (input_location, COMPONENT_REF, ftype,
     640                 :             :                                  dest, field, NULL_TREE);
     641                 :             : 
     642                 :        3829 :       tem = NULL_TREE;
     643                 :        3829 :       switch (kind)
     644                 :             :         {
     645                 :             :         case WALK_ALLOC_COMPS_DTOR:
     646                 :             :           break;
     647                 :         961 :         case WALK_ALLOC_COMPS_DEFAULT_CTOR:
     648                 :         961 :           if (GFC_DESCRIPTOR_TYPE_P (ftype)
     649                 :         961 :               && GFC_TYPE_ARRAY_AKIND (ftype) == GFC_ARRAY_ALLOCATABLE)
     650                 :             :             {
     651                 :         430 :               gfc_add_modify (&block, unshare_expr (destf),
     652                 :             :                               unshare_expr (declf));
     653                 :         430 :               tem = gfc_duplicate_allocatable_nocopy
     654                 :         430 :                                         (destf, declf, ftype,
     655                 :         430 :                                          GFC_TYPE_ARRAY_RANK (ftype));
     656                 :             :             }
     657                 :         531 :           else if (GFC_DECL_GET_SCALAR_ALLOCATABLE (field))
     658                 :         425 :             tem = gfc_duplicate_allocatable_nocopy (destf, declf, ftype, 0);
     659                 :             :           break;
     660                 :         954 :         case WALK_ALLOC_COMPS_COPY_CTOR:
     661                 :         954 :           if (GFC_DESCRIPTOR_TYPE_P (ftype)
     662                 :         954 :               && GFC_TYPE_ARRAY_AKIND (ftype) == GFC_ARRAY_ALLOCATABLE)
     663                 :         848 :             tem = gfc_duplicate_allocatable (destf, declf, ftype,
     664                 :         424 :                                              GFC_TYPE_ARRAY_RANK (ftype),
     665                 :             :                                              NULL_TREE);
     666                 :         530 :           else if (GFC_DECL_GET_SCALAR_ALLOCATABLE (field))
     667                 :         424 :             tem = gfc_duplicate_allocatable (destf, declf, ftype, 0,
     668                 :             :                                              NULL_TREE);
     669                 :             :           break;
     670                 :             :         }
     671                 :        1703 :       if (tem)
     672                 :        1703 :         gfc_add_expr_to_block (&block, gfc_omp_unshare_expr (tem));
     673                 :        3829 :       if (has_alloc_comps)
     674                 :             :         {
     675                 :        1272 :           gfc_init_block (&tmpblock);
     676                 :        1272 :           gfc_add_expr_to_block (&tmpblock,
     677                 :             :                                  gfc_walk_alloc_comps (declf, destf,
     678                 :             :                                                        field, kind));
     679                 :        1272 :           then_b = gfc_finish_block (&tmpblock);
     680                 :        1272 :           if (GFC_DESCRIPTOR_TYPE_P (ftype)
     681                 :        1272 :               && GFC_TYPE_ARRAY_AKIND (ftype) == GFC_ARRAY_ALLOCATABLE)
     682                 :         424 :             tem = gfc_conv_descriptor_data_get (unshare_expr (declf));
     683                 :         848 :           else if (GFC_DECL_GET_SCALAR_ALLOCATABLE (field))
     684                 :         424 :             tem = unshare_expr (declf);
     685                 :             :           else
     686                 :             :             tem = NULL_TREE;
     687                 :         848 :           if (tem)
     688                 :             :             {
     689                 :         848 :               tem = fold_convert (pvoid_type_node, tem);
     690                 :         848 :               tem = fold_build2_loc (input_location, NE_EXPR,
     691                 :             :                                      logical_type_node, tem,
     692                 :             :                                      null_pointer_node);
     693                 :         848 :               then_b = build3_loc (input_location, COND_EXPR, void_type_node,
     694                 :             :                                    tem, then_b,
     695                 :             :                                    build_empty_stmt (input_location));
     696                 :             :             }
     697                 :        1272 :           gfc_add_expr_to_block (&block, then_b);
     698                 :             :         }
     699                 :        3829 :       if (kind == WALK_ALLOC_COMPS_DTOR)
     700                 :             :         {
     701                 :        1914 :           if (GFC_DESCRIPTOR_TYPE_P (ftype)
     702                 :        1914 :               && GFC_TYPE_ARRAY_AKIND (ftype) == GFC_ARRAY_ALLOCATABLE)
     703                 :             :             {
     704                 :         854 :               tem = gfc_conv_descriptor_data_get (unshare_expr (declf));
     705                 :         854 :               tem = gfc_deallocate_with_status (tem, NULL_TREE, NULL_TREE,
     706                 :             :                                                 NULL_TREE, NULL_TREE, true,
     707                 :             :                                                 NULL,
     708                 :             :                                                 GFC_CAF_COARRAY_NOCOARRAY);
     709                 :         854 :               gfc_add_expr_to_block (&block, gfc_omp_unshare_expr (tem));
     710                 :             :             }
     711                 :        1060 :           else if (GFC_DECL_GET_SCALAR_ALLOCATABLE (field))
     712                 :             :             {
     713                 :         848 :               tem = gfc_call_free (unshare_expr (declf));
     714                 :         848 :               gfc_add_expr_to_block (&block, gfc_omp_unshare_expr (tem));
     715                 :             :             }
     716                 :             :         }
     717                 :             :     }
     718                 :             : 
     719                 :        1709 :   return gfc_finish_block (&block);
     720                 :             : }
     721                 :             : 
     722                 :             : /* Return code to initialize DECL with its default constructor, or
     723                 :             :    NULL if there's nothing to do.  */
     724                 :             : 
     725                 :             : tree
     726                 :       19284 : gfc_omp_clause_default_ctor (tree clause, tree decl, tree outer)
     727                 :             : {
     728                 :       19284 :   tree type = TREE_TYPE (decl), size, ptr, cond, then_b, else_b;
     729                 :       19284 :   stmtblock_t block, cond_block;
     730                 :             : 
     731                 :       19284 :   switch (OMP_CLAUSE_CODE (clause))
     732                 :             :     {
     733                 :             :     case OMP_CLAUSE__LOOPTEMP_:
     734                 :             :     case OMP_CLAUSE__REDUCTEMP_:
     735                 :             :     case OMP_CLAUSE__CONDTEMP_:
     736                 :             :     case OMP_CLAUSE__SCANTEMP_:
     737                 :             :       return NULL;
     738                 :       19257 :     case OMP_CLAUSE_PRIVATE:
     739                 :       19257 :     case OMP_CLAUSE_LASTPRIVATE:
     740                 :       19257 :     case OMP_CLAUSE_LINEAR:
     741                 :       19257 :     case OMP_CLAUSE_REDUCTION:
     742                 :       19257 :     case OMP_CLAUSE_IN_REDUCTION:
     743                 :       19257 :     case OMP_CLAUSE_TASK_REDUCTION:
     744                 :       19257 :       break;
     745                 :           0 :     default:
     746                 :           0 :       gcc_unreachable ();
     747                 :             :     }
     748                 :             : 
     749                 :       19257 :   if ((! GFC_DESCRIPTOR_TYPE_P (type)
     750                 :         263 :        || GFC_TYPE_ARRAY_AKIND (type) != GFC_ARRAY_ALLOCATABLE)
     751                 :       19276 :       && (!GFC_DECL_GET_SCALAR_ALLOCATABLE (OMP_CLAUSE_DECL (clause))
     752                 :          85 :           || !POINTER_TYPE_P (type)))
     753                 :             :     {
     754                 :       18928 :       if (gfc_has_alloc_comps (type, OMP_CLAUSE_DECL (clause)))
     755                 :             :         {
     756                 :          51 :           gcc_assert (outer);
     757                 :          51 :           gfc_start_block (&block);
     758                 :         102 :           tree tem = gfc_walk_alloc_comps (outer, decl,
     759                 :          51 :                                            OMP_CLAUSE_DECL (clause),
     760                 :             :                                            WALK_ALLOC_COMPS_DEFAULT_CTOR);
     761                 :          51 :           gfc_add_expr_to_block (&block, tem);
     762                 :          51 :           return gfc_finish_block (&block);
     763                 :             :         }
     764                 :             :       return NULL_TREE;
     765                 :             :     }
     766                 :             : 
     767                 :         329 :   gcc_assert (outer != NULL_TREE);
     768                 :             : 
     769                 :             :   /* Allocatable arrays and scalars in PRIVATE clauses need to be set to
     770                 :             :      "not currently allocated" allocation status if outer
     771                 :             :      array is "not currently allocated", otherwise should be allocated.  */
     772                 :         329 :   gfc_start_block (&block);
     773                 :             : 
     774                 :         329 :   gfc_init_block (&cond_block);
     775                 :             : 
     776                 :         329 :   if (GFC_DESCRIPTOR_TYPE_P (type))
     777                 :             :     {
     778                 :         244 :       gfc_add_modify (&cond_block, decl, outer);
     779                 :         244 :       tree rank = gfc_rank_cst[GFC_TYPE_ARRAY_RANK (type) - 1];
     780                 :         244 :       size = gfc_conv_descriptor_ubound_get (decl, rank);
     781                 :         244 :       size = fold_build2_loc (input_location, MINUS_EXPR, gfc_array_index_type,
     782                 :             :                               size,
     783                 :             :                               gfc_conv_descriptor_lbound_get (decl, rank));
     784                 :         244 :       size = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type,
     785                 :             :                               size, gfc_index_one_node);
     786                 :         244 :       if (GFC_TYPE_ARRAY_RANK (type) > 1)
     787                 :         130 :         size = fold_build2_loc (input_location, MULT_EXPR,
     788                 :             :                                 gfc_array_index_type, size,
     789                 :             :                                 gfc_conv_descriptor_stride_get (decl, rank));
     790                 :         244 :       tree esize = fold_convert (gfc_array_index_type,
     791                 :             :                                  TYPE_SIZE_UNIT (gfc_get_element_type (type)));
     792                 :         244 :       size = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type,
     793                 :             :                               size, esize);
     794                 :         244 :       size = unshare_expr (size);
     795                 :         244 :       size = gfc_evaluate_now (fold_convert (size_type_node, size),
     796                 :             :                                &cond_block);
     797                 :             :     }
     798                 :             :   else
     799                 :          85 :     size = fold_convert (size_type_node, TYPE_SIZE_UNIT (TREE_TYPE (type)));
     800                 :         329 :   ptr = gfc_create_var (pvoid_type_node, NULL);
     801                 :         329 :   gfc_allocate_using_malloc (&cond_block, ptr, size, NULL_TREE);
     802                 :         329 :   if (GFC_DESCRIPTOR_TYPE_P (type))
     803                 :         244 :     gfc_conv_descriptor_data_set (&cond_block, unshare_expr (decl), ptr);
     804                 :             :   else
     805                 :          85 :     gfc_add_modify (&cond_block, unshare_expr (decl),
     806                 :          85 :                     fold_convert (TREE_TYPE (decl), ptr));
     807                 :         329 :   if (gfc_has_alloc_comps (type, OMP_CLAUSE_DECL (clause)))
     808                 :             :     {
     809                 :         124 :       tree tem = gfc_walk_alloc_comps (outer, decl,
     810                 :          62 :                                        OMP_CLAUSE_DECL (clause),
     811                 :             :                                        WALK_ALLOC_COMPS_DEFAULT_CTOR);
     812                 :          62 :       gfc_add_expr_to_block (&cond_block, tem);
     813                 :             :     }
     814                 :         329 :   then_b = gfc_finish_block (&cond_block);
     815                 :             : 
     816                 :             :   /* Reduction clause requires allocated ALLOCATABLE.  */
     817                 :         329 :   if (OMP_CLAUSE_CODE (clause) != OMP_CLAUSE_REDUCTION
     818                 :         185 :       && OMP_CLAUSE_CODE (clause) != OMP_CLAUSE_IN_REDUCTION
     819                 :         514 :       && OMP_CLAUSE_CODE (clause) != OMP_CLAUSE_TASK_REDUCTION)
     820                 :             :     {
     821                 :         185 :       gfc_init_block (&cond_block);
     822                 :         185 :       if (GFC_DESCRIPTOR_TYPE_P (type))
     823                 :         124 :         gfc_conv_descriptor_data_set (&cond_block, unshare_expr (decl),
     824                 :             :                                       null_pointer_node);
     825                 :             :       else
     826                 :          61 :         gfc_add_modify (&cond_block, unshare_expr (decl),
     827                 :          61 :                         build_zero_cst (TREE_TYPE (decl)));
     828                 :         185 :       else_b = gfc_finish_block (&cond_block);
     829                 :             : 
     830                 :         185 :       tree tem = fold_convert (pvoid_type_node,
     831                 :             :                                GFC_DESCRIPTOR_TYPE_P (type)
     832                 :             :                                ? gfc_conv_descriptor_data_get (outer) : outer);
     833                 :         185 :       tem = unshare_expr (tem);
     834                 :         185 :       cond = fold_build2_loc (input_location, NE_EXPR, logical_type_node,
     835                 :             :                               tem, null_pointer_node);
     836                 :         185 :       gfc_add_expr_to_block (&block,
     837                 :             :                              build3_loc (input_location, COND_EXPR,
     838                 :             :                                          void_type_node, cond, then_b,
     839                 :             :                                          else_b));
     840                 :             :       /* Avoid -W*uninitialized warnings.  */
     841                 :         185 :       if (DECL_P (decl))
     842                 :         146 :         suppress_warning (decl, OPT_Wuninitialized);
     843                 :             :     }
     844                 :             :   else
     845                 :         144 :     gfc_add_expr_to_block (&block, then_b);
     846                 :             : 
     847                 :         329 :   return gfc_finish_block (&block);
     848                 :             : }
     849                 :             : 
     850                 :             : /* Build and return code for a copy constructor from SRC to DEST.  */
     851                 :             : 
     852                 :             : tree
     853                 :        8826 : gfc_omp_clause_copy_ctor (tree clause, tree dest, tree src)
     854                 :             : {
     855                 :        8826 :   tree type = TREE_TYPE (dest), ptr, size, call;
     856                 :        8826 :   tree decl_type = TREE_TYPE (OMP_CLAUSE_DECL (clause));
     857                 :        8826 :   tree cond, then_b, else_b;
     858                 :        8826 :   stmtblock_t block, cond_block;
     859                 :             : 
     860                 :        8826 :   gcc_assert (OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_FIRSTPRIVATE
     861                 :             :               || OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_LINEAR);
     862                 :             : 
     863                 :             :   /* Privatize pointer, only; cf. gfc_omp_predetermined_sharing. */
     864                 :        8826 :   if (DECL_P (OMP_CLAUSE_DECL (clause))
     865                 :        8826 :       && GFC_DECL_ASSOCIATE_VAR_P (OMP_CLAUSE_DECL (clause)))
     866                 :          27 :     return build2 (MODIFY_EXPR, TREE_TYPE (dest), dest, src);
     867                 :             : 
     868                 :        8799 :   if (DECL_ARTIFICIAL (OMP_CLAUSE_DECL (clause))
     869                 :        5726 :       && DECL_LANG_SPECIFIC (OMP_CLAUSE_DECL (clause))
     870                 :        8980 :       && GFC_DECL_SAVED_DESCRIPTOR (OMP_CLAUSE_DECL (clause)))
     871                 :         167 :     decl_type
     872                 :         167 :       = TREE_TYPE (GFC_DECL_SAVED_DESCRIPTOR (OMP_CLAUSE_DECL (clause)));
     873                 :             : 
     874                 :        8799 :   if (gfc_is_polymorphic_nonptr (decl_type))
     875                 :             :     {
     876                 :          40 :       if (POINTER_TYPE_P (decl_type))
     877                 :          27 :         decl_type = TREE_TYPE (decl_type);
     878                 :          40 :       decl_type = TREE_TYPE (TYPE_FIELDS (decl_type));
     879                 :          40 :       if (GFC_DESCRIPTOR_TYPE_P (decl_type) || GFC_ARRAY_TYPE_P (decl_type))
     880                 :           4 :         fatal_error (input_location,
     881                 :             :                      "Sorry, polymorphic arrays not yet supported for "
     882                 :             :                      "firstprivate");
     883                 :          36 :       tree src_len;
     884                 :          36 :       tree nelems = build_int_cst (size_type_node, 1);  /* Scalar.  */
     885                 :          36 :       tree src_data = gfc_class_data_get (unshare_expr (src));
     886                 :          36 :       tree dest_data = gfc_class_data_get (unshare_expr (dest));
     887                 :          36 :       bool unlimited = gfc_is_unlimited_polymorphic_nonptr (type);
     888                 :             : 
     889                 :          36 :       gfc_start_block (&block);
     890                 :          36 :       gfc_add_modify (&block, gfc_class_vptr_get (dest),
     891                 :             :                       gfc_class_vptr_get (src));
     892                 :          36 :       gfc_init_block (&cond_block);
     893                 :             : 
     894                 :          36 :       if (unlimited)
     895                 :             :         {
     896                 :          24 :           src_len = gfc_class_len_get (src);
     897                 :          24 :           gfc_add_modify (&cond_block, gfc_class_len_get (unshare_expr (dest)), src_len);
     898                 :             :         }
     899                 :             : 
     900                 :             :       /* Use: size = class._vtab._size * (class._len > 0 ? class._len : 1).  */
     901                 :          36 :       size = fold_convert (size_type_node, gfc_class_vtab_size_get (src));
     902                 :          36 :       if (unlimited)
     903                 :             :         {
     904                 :          24 :           cond = fold_build2_loc (input_location, GT_EXPR, boolean_type_node,
     905                 :             :                                   unshare_expr (src_len),
     906                 :          24 :                                   build_zero_cst (TREE_TYPE (src_len)));
     907                 :          24 :           cond = build3_loc (input_location, COND_EXPR, size_type_node, cond,
     908                 :             :                              fold_convert (size_type_node,
     909                 :             :                                            unshare_expr (src_len)),
     910                 :          24 :                              build_int_cst (size_type_node, 1));
     911                 :          24 :           size = fold_build2_loc (input_location, MULT_EXPR, size_type_node,
     912                 :             :                                   size, cond);
     913                 :             :         }
     914                 :             : 
     915                 :             :       /* Malloc memory + call class->_vpt->_copy.  */
     916                 :          36 :       call = builtin_decl_explicit (BUILT_IN_MALLOC);
     917                 :          36 :       call = build_call_expr_loc (input_location, call, 1, size);
     918                 :          36 :       gfc_add_modify (&cond_block, dest_data,
     919                 :          36 :                       fold_convert (TREE_TYPE (dest_data), call));
     920                 :          36 :       gfc_add_expr_to_block (&cond_block,
     921                 :             :                              gfc_copy_class_to_class (src, dest, nelems,
     922                 :             :                                                       unlimited));
     923                 :             : 
     924                 :          36 :       gcc_assert (TREE_CODE (dest_data) == COMPONENT_REF);
     925                 :          36 :       if (!GFC_DECL_GET_SCALAR_ALLOCATABLE (TREE_OPERAND (dest_data, 1)))
     926                 :             :         {
     927                 :          12 :           gfc_add_block_to_block (&block, &cond_block);
     928                 :             :         }
     929                 :             :       else
     930                 :             :         {
     931                 :             :           /* Create: if (class._data != 0) <cond_block> else class._data = NULL; */
     932                 :          24 :           cond = fold_build2_loc (input_location, NE_EXPR, boolean_type_node,
     933                 :             :                                   src_data, null_pointer_node);
     934                 :          24 :           gfc_add_expr_to_block (&block, build3_loc (input_location, COND_EXPR,
     935                 :             :                                  void_type_node, cond,
     936                 :             :                                  gfc_finish_block (&cond_block),
     937                 :             :                                  fold_build2_loc (input_location, MODIFY_EXPR, void_type_node,
     938                 :             :                                  unshare_expr (dest_data), null_pointer_node)));
     939                 :             :         }
     940                 :          36 :       return gfc_finish_block (&block);
     941                 :             :     }
     942                 :             : 
     943                 :        8759 :   if ((! GFC_DESCRIPTOR_TYPE_P (type)
     944                 :         138 :        || GFC_TYPE_ARRAY_AKIND (type) != GFC_ARRAY_ALLOCATABLE)
     945                 :        8783 :       && (!GFC_DECL_GET_SCALAR_ALLOCATABLE (OMP_CLAUSE_DECL (clause))
     946                 :          77 :           || !POINTER_TYPE_P (type)))
     947                 :             :     {
     948                 :        8570 :       if (gfc_has_alloc_comps (type, OMP_CLAUSE_DECL (clause)))
     949                 :             :         {
     950                 :          20 :           gfc_start_block (&block);
     951                 :          20 :           gfc_add_modify (&block, dest, src);
     952                 :          20 :           tree tem = gfc_walk_alloc_comps (src, dest, OMP_CLAUSE_DECL (clause),
     953                 :             :                                            WALK_ALLOC_COMPS_COPY_CTOR);
     954                 :          20 :           gfc_add_expr_to_block (&block, tem);
     955                 :          20 :           return gfc_finish_block (&block);
     956                 :             :         }
     957                 :             :       else
     958                 :        8550 :         return build2_v (MODIFY_EXPR, dest, src);
     959                 :             :     }
     960                 :             : 
     961                 :             :   /* Allocatable arrays in FIRSTPRIVATE clauses need to be allocated
     962                 :             :      and copied from SRC.  */
     963                 :         189 :   gfc_start_block (&block);
     964                 :             : 
     965                 :         189 :   gfc_init_block (&cond_block);
     966                 :             : 
     967                 :         189 :   gfc_add_modify (&cond_block, dest, fold_convert (TREE_TYPE (dest), src));
     968                 :         189 :   if (GFC_DESCRIPTOR_TYPE_P (type))
     969                 :             :     {
     970                 :         114 :       tree rank = gfc_rank_cst[GFC_TYPE_ARRAY_RANK (type) - 1];
     971                 :         114 :       size = gfc_conv_descriptor_ubound_get (dest, rank);
     972                 :         114 :       size = fold_build2_loc (input_location, MINUS_EXPR, gfc_array_index_type,
     973                 :             :                               size,
     974                 :             :                               gfc_conv_descriptor_lbound_get (dest, rank));
     975                 :         114 :       size = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type,
     976                 :             :                               size, gfc_index_one_node);
     977                 :         114 :       if (GFC_TYPE_ARRAY_RANK (type) > 1)
     978                 :          42 :         size = fold_build2_loc (input_location, MULT_EXPR,
     979                 :             :                                 gfc_array_index_type, size,
     980                 :             :                                 gfc_conv_descriptor_stride_get (dest, rank));
     981                 :         114 :       tree esize = fold_convert (gfc_array_index_type,
     982                 :             :                                  TYPE_SIZE_UNIT (gfc_get_element_type (type)));
     983                 :         114 :       size = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type,
     984                 :             :                               size, esize);
     985                 :         114 :       size = unshare_expr (size);
     986                 :         114 :       size = gfc_evaluate_now (fold_convert (size_type_node, size),
     987                 :             :                                &cond_block);
     988                 :             :     }
     989                 :             :   else
     990                 :          75 :     size = fold_convert (size_type_node, TYPE_SIZE_UNIT (TREE_TYPE (type)));
     991                 :         189 :   ptr = gfc_create_var (pvoid_type_node, NULL);
     992                 :         189 :   gfc_allocate_using_malloc (&cond_block, ptr, size, NULL_TREE);
     993                 :         189 :   if (GFC_DESCRIPTOR_TYPE_P (type))
     994                 :         114 :     gfc_conv_descriptor_data_set (&cond_block, unshare_expr (dest), ptr);
     995                 :             :   else
     996                 :          75 :     gfc_add_modify (&cond_block, unshare_expr (dest),
     997                 :          75 :                     fold_convert (TREE_TYPE (dest), ptr));
     998                 :             : 
     999                 :         189 :   tree srcptr = GFC_DESCRIPTOR_TYPE_P (type)
    1000                 :         189 :                 ? gfc_conv_descriptor_data_get (src) : src;
    1001                 :         189 :   srcptr = unshare_expr (srcptr);
    1002                 :         189 :   srcptr = fold_convert (pvoid_type_node, srcptr);
    1003                 :         189 :   call = build_call_expr_loc (input_location,
    1004                 :             :                               builtin_decl_explicit (BUILT_IN_MEMCPY), 3, ptr,
    1005                 :             :                               srcptr, size);
    1006                 :         189 :   gfc_add_expr_to_block (&cond_block, fold_convert (void_type_node, call));
    1007                 :         189 :   if (gfc_has_alloc_comps (type, OMP_CLAUSE_DECL (clause)))
    1008                 :             :     {
    1009                 :          48 :       tree tem = gfc_walk_alloc_comps (src, dest,
    1010                 :          24 :                                        OMP_CLAUSE_DECL (clause),
    1011                 :             :                                        WALK_ALLOC_COMPS_COPY_CTOR);
    1012                 :          24 :       gfc_add_expr_to_block (&cond_block, tem);
    1013                 :             :     }
    1014                 :         189 :   then_b = gfc_finish_block (&cond_block);
    1015                 :             : 
    1016                 :         189 :   gfc_init_block (&cond_block);
    1017                 :         189 :   if (GFC_DESCRIPTOR_TYPE_P (type))
    1018                 :         114 :     gfc_conv_descriptor_data_set (&cond_block, unshare_expr (dest),
    1019                 :             :                                   null_pointer_node);
    1020                 :             :   else
    1021                 :          75 :     gfc_add_modify (&cond_block, unshare_expr (dest),
    1022                 :          75 :                     build_zero_cst (TREE_TYPE (dest)));
    1023                 :         189 :   else_b = gfc_finish_block (&cond_block);
    1024                 :             : 
    1025                 :         189 :   cond = fold_build2_loc (input_location, NE_EXPR, logical_type_node,
    1026                 :             :                           unshare_expr (srcptr), null_pointer_node);
    1027                 :         189 :   gfc_add_expr_to_block (&block,
    1028                 :             :                          build3_loc (input_location, COND_EXPR,
    1029                 :             :                                      void_type_node, cond, then_b, else_b));
    1030                 :             :   /* Avoid -W*uninitialized warnings.  */
    1031                 :         189 :   if (DECL_P (dest))
    1032                 :         121 :     suppress_warning (dest, OPT_Wuninitialized);
    1033                 :             : 
    1034                 :         189 :   return gfc_finish_block (&block);
    1035                 :             : }
    1036                 :             : 
    1037                 :             : /* Similarly, except use an intrinsic or pointer assignment operator
    1038                 :             :    instead.  */
    1039                 :             : 
    1040                 :             : tree
    1041                 :        6266 : gfc_omp_clause_assign_op (tree clause, tree dest, tree src)
    1042                 :             : {
    1043                 :        6266 :   tree type = TREE_TYPE (dest), ptr, size, call, nonalloc;
    1044                 :        6266 :   tree cond, then_b, else_b;
    1045                 :        6266 :   stmtblock_t block, cond_block, cond_block2, inner_block;
    1046                 :             : 
    1047                 :        6266 :   if ((! GFC_DESCRIPTOR_TYPE_P (type)
    1048                 :         234 :        || GFC_TYPE_ARRAY_AKIND (type) != GFC_ARRAY_ALLOCATABLE)
    1049                 :       12329 :       && (!GFC_DECL_GET_SCALAR_ALLOCATABLE (OMP_CLAUSE_DECL (clause))
    1050                 :         136 :           || !POINTER_TYPE_P (type)))
    1051                 :             :     {
    1052                 :        5927 :       if (gfc_has_alloc_comps (type, OMP_CLAUSE_DECL (clause)))
    1053                 :             :         {
    1054                 :          30 :           gfc_start_block (&block);
    1055                 :             :           /* First dealloc any allocatable components in DEST.  */
    1056                 :          60 :           tree tem = gfc_walk_alloc_comps (dest, NULL_TREE,
    1057                 :          30 :                                            OMP_CLAUSE_DECL (clause),
    1058                 :             :                                            WALK_ALLOC_COMPS_DTOR);
    1059                 :          30 :           gfc_add_expr_to_block (&block, tem);
    1060                 :             :           /* Then copy over toplevel data.  */
    1061                 :          30 :           gfc_add_modify (&block, dest, src);
    1062                 :             :           /* Finally allocate any allocatable components and copy.  */
    1063                 :          30 :           tem = gfc_walk_alloc_comps (src, dest, OMP_CLAUSE_DECL (clause),
    1064                 :             :                                            WALK_ALLOC_COMPS_COPY_CTOR);
    1065                 :          30 :           gfc_add_expr_to_block (&block, tem);
    1066                 :          30 :           return gfc_finish_block (&block);
    1067                 :             :         }
    1068                 :             :       else
    1069                 :        5897 :         return build2_v (MODIFY_EXPR, dest, src);
    1070                 :             :     }
    1071                 :             : 
    1072                 :         339 :   gfc_start_block (&block);
    1073                 :             : 
    1074                 :         339 :   if (gfc_has_alloc_comps (type, OMP_CLAUSE_DECL (clause)))
    1075                 :             :     {
    1076                 :          32 :       then_b = gfc_walk_alloc_comps (dest, NULL_TREE, OMP_CLAUSE_DECL (clause),
    1077                 :             :                                      WALK_ALLOC_COMPS_DTOR);
    1078                 :          32 :       tree tem = fold_convert (pvoid_type_node,
    1079                 :             :                                GFC_DESCRIPTOR_TYPE_P (type)
    1080                 :             :                                ? gfc_conv_descriptor_data_get (dest) : dest);
    1081                 :          32 :       tem = unshare_expr (tem);
    1082                 :          32 :       cond = fold_build2_loc (input_location, NE_EXPR, logical_type_node,
    1083                 :             :                               tem, null_pointer_node);
    1084                 :          32 :       tem = build3_loc (input_location, COND_EXPR, void_type_node, cond,
    1085                 :             :                         then_b, build_empty_stmt (input_location));
    1086                 :          32 :       gfc_add_expr_to_block (&block, tem);
    1087                 :             :     }
    1088                 :             : 
    1089                 :         339 :   gfc_init_block (&cond_block);
    1090                 :             : 
    1091                 :         339 :   if (GFC_DESCRIPTOR_TYPE_P (type))
    1092                 :             :     {
    1093                 :         203 :       tree rank = gfc_rank_cst[GFC_TYPE_ARRAY_RANK (type) - 1];
    1094                 :         203 :       size = gfc_conv_descriptor_ubound_get (src, rank);
    1095                 :         203 :       size = fold_build2_loc (input_location, MINUS_EXPR, gfc_array_index_type,
    1096                 :             :                               size,
    1097                 :             :                               gfc_conv_descriptor_lbound_get (src, rank));
    1098                 :         203 :       size = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type,
    1099                 :             :                               size, gfc_index_one_node);
    1100                 :         203 :       if (GFC_TYPE_ARRAY_RANK (type) > 1)
    1101                 :          88 :         size = fold_build2_loc (input_location, MULT_EXPR,
    1102                 :             :                                 gfc_array_index_type, size,
    1103                 :             :                                 gfc_conv_descriptor_stride_get (src, rank));
    1104                 :         203 :       tree esize = fold_convert (gfc_array_index_type,
    1105                 :             :                                  TYPE_SIZE_UNIT (gfc_get_element_type (type)));
    1106                 :         203 :       size = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type,
    1107                 :             :                               size, esize);
    1108                 :         203 :       size = unshare_expr (size);
    1109                 :         203 :       size = gfc_evaluate_now (fold_convert (size_type_node, size),
    1110                 :             :                                &cond_block);
    1111                 :             :     }
    1112                 :             :   else
    1113                 :         136 :     size = fold_convert (size_type_node, TYPE_SIZE_UNIT (TREE_TYPE (type)));
    1114                 :         339 :   ptr = gfc_create_var (pvoid_type_node, NULL);
    1115                 :             : 
    1116                 :         339 :   tree destptr = GFC_DESCRIPTOR_TYPE_P (type)
    1117                 :         339 :                  ? gfc_conv_descriptor_data_get (dest) : dest;
    1118                 :         339 :   destptr = unshare_expr (destptr);
    1119                 :         339 :   destptr = fold_convert (pvoid_type_node, destptr);
    1120                 :         339 :   gfc_add_modify (&cond_block, ptr, destptr);
    1121                 :             : 
    1122                 :         339 :   nonalloc = fold_build2_loc (input_location, EQ_EXPR, logical_type_node,
    1123                 :             :                               destptr, null_pointer_node);
    1124                 :         339 :   cond = nonalloc;
    1125                 :         339 :   if (GFC_DESCRIPTOR_TYPE_P (type))
    1126                 :             :     {
    1127                 :             :       int i;
    1128                 :         494 :       for (i = 0; i < GFC_TYPE_ARRAY_RANK (type); i++)
    1129                 :             :         {
    1130                 :         291 :           tree rank = gfc_rank_cst[i];
    1131                 :         291 :           tree tem = gfc_conv_descriptor_ubound_get (src, rank);
    1132                 :         291 :           tem = fold_build2_loc (input_location, MINUS_EXPR,
    1133                 :             :                                  gfc_array_index_type, tem,
    1134                 :             :                                  gfc_conv_descriptor_lbound_get (src, rank));
    1135                 :         291 :           tem = fold_build2_loc (input_location, PLUS_EXPR,
    1136                 :             :                                  gfc_array_index_type, tem,
    1137                 :             :                                  gfc_conv_descriptor_lbound_get (dest, rank));
    1138                 :         291 :           tem = fold_build2_loc (input_location, NE_EXPR, logical_type_node,
    1139                 :             :                                  tem, gfc_conv_descriptor_ubound_get (dest,
    1140                 :             :                                                                       rank));
    1141                 :         291 :           cond = fold_build2_loc (input_location, TRUTH_ORIF_EXPR,
    1142                 :             :                                   logical_type_node, cond, tem);
    1143                 :             :         }
    1144                 :             :     }
    1145                 :             : 
    1146                 :         339 :   gfc_init_block (&cond_block2);
    1147                 :             : 
    1148                 :         339 :   if (GFC_DESCRIPTOR_TYPE_P (type))
    1149                 :             :     {
    1150                 :         203 :       gfc_init_block (&inner_block);
    1151                 :         203 :       gfc_allocate_using_malloc (&inner_block, ptr, size, NULL_TREE);
    1152                 :         203 :       then_b = gfc_finish_block (&inner_block);
    1153                 :             : 
    1154                 :         203 :       gfc_init_block (&inner_block);
    1155                 :         203 :       gfc_add_modify (&inner_block, ptr,
    1156                 :             :                       gfc_call_realloc (&inner_block, ptr, size));
    1157                 :         203 :       else_b = gfc_finish_block (&inner_block);
    1158                 :             : 
    1159                 :         203 :       gfc_add_expr_to_block (&cond_block2,
    1160                 :             :                              build3_loc (input_location, COND_EXPR,
    1161                 :             :                                          void_type_node,
    1162                 :             :                                          unshare_expr (nonalloc),
    1163                 :             :                                          then_b, else_b));
    1164                 :         203 :       gfc_add_modify (&cond_block2, dest, src);
    1165                 :         203 :       gfc_conv_descriptor_data_set (&cond_block2, unshare_expr (dest), ptr);
    1166                 :             :     }
    1167                 :             :   else
    1168                 :             :     {
    1169                 :         136 :       gfc_allocate_using_malloc (&cond_block2, ptr, size, NULL_TREE);
    1170                 :         136 :       gfc_add_modify (&cond_block2, unshare_expr (dest),
    1171                 :             :                       fold_convert (type, ptr));
    1172                 :             :     }
    1173                 :         339 :   then_b = gfc_finish_block (&cond_block2);
    1174                 :         339 :   else_b = build_empty_stmt (input_location);
    1175                 :             : 
    1176                 :         339 :   gfc_add_expr_to_block (&cond_block,
    1177                 :             :                          build3_loc (input_location, COND_EXPR,
    1178                 :             :                                      void_type_node, unshare_expr (cond),
    1179                 :             :                                      then_b, else_b));
    1180                 :             : 
    1181                 :         339 :   tree srcptr = GFC_DESCRIPTOR_TYPE_P (type)
    1182                 :         339 :                 ? gfc_conv_descriptor_data_get (src) : src;
    1183                 :         339 :   srcptr = unshare_expr (srcptr);
    1184                 :         339 :   srcptr = fold_convert (pvoid_type_node, srcptr);
    1185                 :         339 :   call = build_call_expr_loc (input_location,
    1186                 :             :                               builtin_decl_explicit (BUILT_IN_MEMCPY), 3, ptr,
    1187                 :             :                               srcptr, size);
    1188                 :         339 :   gfc_add_expr_to_block (&cond_block, fold_convert (void_type_node, call));
    1189                 :         339 :   if (gfc_has_alloc_comps (type, OMP_CLAUSE_DECL (clause)))
    1190                 :             :     {
    1191                 :          64 :       tree tem = gfc_walk_alloc_comps (src, dest,
    1192                 :          32 :                                        OMP_CLAUSE_DECL (clause),
    1193                 :             :                                        WALK_ALLOC_COMPS_COPY_CTOR);
    1194                 :          32 :       gfc_add_expr_to_block (&cond_block, tem);
    1195                 :             :     }
    1196                 :         339 :   then_b = gfc_finish_block (&cond_block);
    1197                 :             : 
    1198                 :         339 :   if (OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_COPYIN)
    1199                 :             :     {
    1200                 :          66 :       gfc_init_block (&cond_block);
    1201                 :          66 :       if (GFC_DESCRIPTOR_TYPE_P (type))
    1202                 :             :         {
    1203                 :          48 :           tree tmp = gfc_conv_descriptor_data_get (unshare_expr (dest));
    1204                 :          48 :           tmp = gfc_deallocate_with_status (tmp, NULL_TREE, NULL_TREE,
    1205                 :             :                                             NULL_TREE, NULL_TREE, true, NULL,
    1206                 :             :                                             GFC_CAF_COARRAY_NOCOARRAY);
    1207                 :          48 :           gfc_add_expr_to_block (&cond_block, tmp);
    1208                 :             :         }
    1209                 :             :       else
    1210                 :             :         {
    1211                 :          18 :           destptr = gfc_evaluate_now (destptr, &cond_block);
    1212                 :          18 :           gfc_add_expr_to_block (&cond_block, gfc_call_free (destptr));
    1213                 :          18 :           gfc_add_modify (&cond_block, unshare_expr (dest),
    1214                 :          18 :                           build_zero_cst (TREE_TYPE (dest)));
    1215                 :             :         }
    1216                 :          66 :       else_b = gfc_finish_block (&cond_block);
    1217                 :             : 
    1218                 :          66 :       cond = fold_build2_loc (input_location, NE_EXPR, logical_type_node,
    1219                 :             :                               unshare_expr (srcptr), null_pointer_node);
    1220                 :          66 :       gfc_add_expr_to_block (&block,
    1221                 :             :                              build3_loc (input_location, COND_EXPR,
    1222                 :             :                                          void_type_node, cond,
    1223                 :             :                                          then_b, else_b));
    1224                 :             :     }
    1225                 :             :   else
    1226                 :         273 :     gfc_add_expr_to_block (&block, then_b);
    1227                 :             : 
    1228                 :         339 :   return gfc_finish_block (&block);
    1229                 :             : }
    1230                 :             : 
    1231                 :             : static void
    1232                 :          84 : gfc_omp_linear_clause_add_loop (stmtblock_t *block, tree dest, tree src,
    1233                 :             :                                 tree add, tree nelems)
    1234                 :             : {
    1235                 :          84 :   stmtblock_t tmpblock;
    1236                 :          84 :   tree desta, srca, index = gfc_create_var (gfc_array_index_type, "S");
    1237                 :          84 :   nelems = gfc_evaluate_now (nelems, block);
    1238                 :             : 
    1239                 :          84 :   gfc_init_block (&tmpblock);
    1240                 :          84 :   if (TREE_CODE (TREE_TYPE (dest)) == ARRAY_TYPE)
    1241                 :             :     {
    1242                 :          60 :       desta = gfc_build_array_ref (dest, index, NULL);
    1243                 :          60 :       srca = gfc_build_array_ref (src, index, NULL);
    1244                 :             :     }
    1245                 :             :   else
    1246                 :             :     {
    1247                 :          24 :       gcc_assert (POINTER_TYPE_P (TREE_TYPE (dest)));
    1248                 :          24 :       tree idx = fold_build2 (MULT_EXPR, sizetype,
    1249                 :             :                               fold_convert (sizetype, index),
    1250                 :             :                               TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (dest))));
    1251                 :          24 :       desta = build_fold_indirect_ref (fold_build2 (POINTER_PLUS_EXPR,
    1252                 :             :                                                     TREE_TYPE (dest), dest,
    1253                 :             :                                                     idx));
    1254                 :          24 :       srca = build_fold_indirect_ref (fold_build2 (POINTER_PLUS_EXPR,
    1255                 :             :                                                    TREE_TYPE (src), src,
    1256                 :             :                                                     idx));
    1257                 :             :     }
    1258                 :          84 :   gfc_add_modify (&tmpblock, desta,
    1259                 :          84 :                   fold_build2 (PLUS_EXPR, TREE_TYPE (desta),
    1260                 :             :                                srca, add));
    1261                 :             : 
    1262                 :          84 :   gfc_loopinfo loop;
    1263                 :          84 :   gfc_init_loopinfo (&loop);
    1264                 :          84 :   loop.dimen = 1;
    1265                 :          84 :   loop.from[0] = gfc_index_zero_node;
    1266                 :          84 :   loop.loopvar[0] = index;
    1267                 :          84 :   loop.to[0] = nelems;
    1268                 :          84 :   gfc_trans_scalarizing_loops (&loop, &tmpblock);
    1269                 :          84 :   gfc_add_block_to_block (block, &loop.pre);
    1270                 :          84 : }
    1271                 :             : 
    1272                 :             : /* Build and return code for a constructor of DEST that initializes
    1273                 :             :    it to SRC plus ADD (ADD is scalar integer).  */
    1274                 :             : 
    1275                 :             : tree
    1276                 :         108 : gfc_omp_clause_linear_ctor (tree clause, tree dest, tree src, tree add)
    1277                 :             : {
    1278                 :         108 :   tree type = TREE_TYPE (dest), ptr, size, nelems = NULL_TREE;
    1279                 :         108 :   stmtblock_t block;
    1280                 :             : 
    1281                 :         108 :   gcc_assert (OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_LINEAR);
    1282                 :             : 
    1283                 :         108 :   gfc_start_block (&block);
    1284                 :         108 :   add = gfc_evaluate_now (add, &block);
    1285                 :             : 
    1286                 :         108 :   if ((! GFC_DESCRIPTOR_TYPE_P (type)
    1287                 :          24 :        || GFC_TYPE_ARRAY_AKIND (type) != GFC_ARRAY_ALLOCATABLE)
    1288                 :         192 :       && (!GFC_DECL_GET_SCALAR_ALLOCATABLE (OMP_CLAUSE_DECL (clause))
    1289                 :          24 :           || !POINTER_TYPE_P (type)))
    1290                 :             :     {
    1291                 :          60 :       bool compute_nelts = false;
    1292                 :          60 :       gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
    1293                 :          60 :       if (!TYPE_DOMAIN (type)
    1294                 :          60 :           || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE
    1295                 :          60 :           || TYPE_MIN_VALUE (TYPE_DOMAIN (type)) == error_mark_node
    1296                 :         120 :           || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == error_mark_node)
    1297                 :             :         compute_nelts = true;
    1298                 :          60 :       else if (VAR_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
    1299                 :             :         {
    1300                 :          48 :           tree a = DECL_ATTRIBUTES (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
    1301                 :          48 :           if (lookup_attribute ("omp dummy var", a))
    1302                 :             :             compute_nelts = true;
    1303                 :             :         }
    1304                 :             :       if (compute_nelts)
    1305                 :             :         {
    1306                 :          48 :           nelems = fold_build2 (EXACT_DIV_EXPR, sizetype,
    1307                 :             :                                 TYPE_SIZE_UNIT (type),
    1308                 :             :                                 TYPE_SIZE_UNIT (TREE_TYPE (type)));
    1309                 :          48 :           nelems = size_binop (MINUS_EXPR, nelems, size_one_node);
    1310                 :             :         }
    1311                 :             :       else
    1312                 :          12 :         nelems = array_type_nelts (type);
    1313                 :          60 :       nelems = fold_convert (gfc_array_index_type, nelems);
    1314                 :             : 
    1315                 :          60 :       gfc_omp_linear_clause_add_loop (&block, dest, src, add, nelems);
    1316                 :          60 :       return gfc_finish_block (&block);
    1317                 :             :     }
    1318                 :             : 
    1319                 :             :   /* Allocatable arrays in LINEAR clauses need to be allocated
    1320                 :             :      and copied from SRC.  */
    1321                 :          48 :   gfc_add_modify (&block, dest, src);
    1322                 :          48 :   if (GFC_DESCRIPTOR_TYPE_P (type))
    1323                 :             :     {
    1324                 :          24 :       tree rank = gfc_rank_cst[GFC_TYPE_ARRAY_RANK (type) - 1];
    1325                 :          24 :       size = gfc_conv_descriptor_ubound_get (dest, rank);
    1326                 :          24 :       size = fold_build2_loc (input_location, MINUS_EXPR, gfc_array_index_type,
    1327                 :             :                               size,
    1328                 :             :                               gfc_conv_descriptor_lbound_get (dest, rank));
    1329                 :          24 :       size = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type,
    1330                 :             :                               size, gfc_index_one_node);
    1331                 :          24 :       if (GFC_TYPE_ARRAY_RANK (type) > 1)
    1332                 :           0 :         size = fold_build2_loc (input_location, MULT_EXPR,
    1333                 :             :                                 gfc_array_index_type, size,
    1334                 :             :                                 gfc_conv_descriptor_stride_get (dest, rank));
    1335                 :          24 :       tree esize = fold_convert (gfc_array_index_type,
    1336                 :             :                                  TYPE_SIZE_UNIT (gfc_get_element_type (type)));
    1337                 :          24 :       nelems = gfc_evaluate_now (unshare_expr (size), &block);
    1338                 :          24 :       size = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type,
    1339                 :             :                               nelems, unshare_expr (esize));
    1340                 :          24 :       size = gfc_evaluate_now (fold_convert (size_type_node, size),
    1341                 :             :                                &block);
    1342                 :          24 :       nelems = fold_build2_loc (input_location, MINUS_EXPR,
    1343                 :             :                                 gfc_array_index_type, nelems,
    1344                 :             :                                 gfc_index_one_node);
    1345                 :             :     }
    1346                 :             :   else
    1347                 :          24 :     size = fold_convert (size_type_node, TYPE_SIZE_UNIT (TREE_TYPE (type)));
    1348                 :          48 :   ptr = gfc_create_var (pvoid_type_node, NULL);
    1349                 :          48 :   gfc_allocate_using_malloc (&block, ptr, size, NULL_TREE);
    1350                 :          48 :   if (GFC_DESCRIPTOR_TYPE_P (type))
    1351                 :             :     {
    1352                 :          24 :       gfc_conv_descriptor_data_set (&block, unshare_expr (dest), ptr);
    1353                 :          24 :       tree etype = gfc_get_element_type (type);
    1354                 :          24 :       ptr = fold_convert (build_pointer_type (etype), ptr);
    1355                 :          24 :       tree srcptr = gfc_conv_descriptor_data_get (unshare_expr (src));
    1356                 :          24 :       srcptr = fold_convert (build_pointer_type (etype), srcptr);
    1357                 :          24 :       gfc_omp_linear_clause_add_loop (&block, ptr, srcptr, add, nelems);
    1358                 :             :     }
    1359                 :             :   else
    1360                 :             :     {
    1361                 :          24 :       gfc_add_modify (&block, unshare_expr (dest),
    1362                 :          24 :                       fold_convert (TREE_TYPE (dest), ptr));
    1363                 :          24 :       ptr = fold_convert (TREE_TYPE (dest), ptr);
    1364                 :          24 :       tree dstm = build_fold_indirect_ref (ptr);
    1365                 :          24 :       tree srcm = build_fold_indirect_ref (unshare_expr (src));
    1366                 :          24 :       gfc_add_modify (&block, dstm,
    1367                 :          24 :                       fold_build2 (PLUS_EXPR, TREE_TYPE (add), srcm, add));
    1368                 :             :     }
    1369                 :          48 :   return gfc_finish_block (&block);
    1370                 :             : }
    1371                 :             : 
    1372                 :             : /* Build and return code destructing DECL.  Return NULL if nothing
    1373                 :             :    to be done.  */
    1374                 :             : 
    1375                 :             : tree
    1376                 :       30558 : gfc_omp_clause_dtor (tree clause, tree decl)
    1377                 :             : {
    1378                 :       30558 :   tree type = TREE_TYPE (decl), tem;
    1379                 :       30558 :   tree decl_type = TREE_TYPE (OMP_CLAUSE_DECL (clause));
    1380                 :             : 
    1381                 :             :   /* Only pointer was privatized; cf. gfc_omp_clause_copy_ctor. */
    1382                 :       30558 :   if (DECL_P (OMP_CLAUSE_DECL (clause))
    1383                 :       30558 :       && GFC_DECL_ASSOCIATE_VAR_P (OMP_CLAUSE_DECL (clause)))
    1384                 :             :     return NULL_TREE;
    1385                 :             : 
    1386                 :       30531 :   if (DECL_ARTIFICIAL (OMP_CLAUSE_DECL (clause))
    1387                 :       11377 :       && DECL_LANG_SPECIFIC (OMP_CLAUSE_DECL (clause))
    1388                 :       30884 :       && GFC_DECL_SAVED_DESCRIPTOR (OMP_CLAUSE_DECL (clause)))
    1389                 :         339 :     decl_type
    1390                 :         339 :         = TREE_TYPE (GFC_DECL_SAVED_DESCRIPTOR (OMP_CLAUSE_DECL (clause)));
    1391                 :       30531 :   if (gfc_is_polymorphic_nonptr (decl_type))
    1392                 :             :     {
    1393                 :          37 :       if (POINTER_TYPE_P (decl_type))
    1394                 :          24 :         decl_type = TREE_TYPE (decl_type);
    1395                 :          37 :       decl_type = TREE_TYPE (TYPE_FIELDS (decl_type));
    1396                 :          37 :       if (GFC_DESCRIPTOR_TYPE_P (decl_type) || GFC_ARRAY_TYPE_P (decl_type))
    1397                 :           0 :         fatal_error (input_location,
    1398                 :             :                      "Sorry, polymorphic arrays not yet supported for "
    1399                 :             :                      "firstprivate");
    1400                 :          37 :       stmtblock_t block, cond_block;
    1401                 :          37 :       gfc_start_block (&block);
    1402                 :          37 :       gfc_init_block (&cond_block);
    1403                 :          37 :       tree final = gfc_class_vtab_final_get (decl);
    1404                 :          37 :       tree size = fold_convert (size_type_node, gfc_class_vtab_size_get (decl));
    1405                 :          37 :       gfc_se se;
    1406                 :          37 :       gfc_init_se (&se, NULL);
    1407                 :          37 :       symbol_attribute attr = {};
    1408                 :          37 :       tree data = gfc_class_data_get (decl);
    1409                 :          37 :       tree desc = gfc_conv_scalar_to_descriptor (&se, data, attr);
    1410                 :             : 
    1411                 :             :       /* Call class->_vpt->_finalize + free.  */
    1412                 :          37 :       tree call = build_fold_indirect_ref (final);
    1413                 :          37 :       call = build_call_expr_loc (input_location, call, 3,
    1414                 :             :                                   gfc_build_addr_expr (NULL, desc),
    1415                 :             :                                   size, boolean_false_node);
    1416                 :          37 :       gfc_add_block_to_block (&cond_block, &se.pre);
    1417                 :          37 :       gfc_add_expr_to_block (&cond_block, fold_convert (void_type_node, call));
    1418                 :          37 :       gfc_add_block_to_block (&cond_block, &se.post);
    1419                 :             :       /* Create: if (_vtab && _final) <cond_block>  */
    1420                 :          37 :       tree cond = fold_build2_loc (input_location, NE_EXPR, boolean_type_node,
    1421                 :             :                                    gfc_class_vptr_get (decl),
    1422                 :             :                                    null_pointer_node);
    1423                 :          37 :       tree cond2 = fold_build2_loc (input_location, NE_EXPR, boolean_type_node,
    1424                 :             :                                    final, null_pointer_node);
    1425                 :          37 :       cond = fold_build2_loc (input_location, TRUTH_ANDIF_EXPR,
    1426                 :             :                               boolean_type_node, cond, cond2);
    1427                 :          37 :       gfc_add_expr_to_block (&block, build3_loc (input_location, COND_EXPR,
    1428                 :             :                                  void_type_node, cond,
    1429                 :             :                                  gfc_finish_block (&cond_block), NULL_TREE));
    1430                 :          37 :       call = builtin_decl_explicit (BUILT_IN_FREE);
    1431                 :          37 :       call = build_call_expr_loc (input_location, call, 1, data);
    1432                 :          37 :       gfc_add_expr_to_block (&block, fold_convert (void_type_node, call));
    1433                 :          37 :       return gfc_finish_block (&block);
    1434                 :             :     }
    1435                 :             : 
    1436                 :       30494 :   if ((! GFC_DESCRIPTOR_TYPE_P (type)
    1437                 :         433 :        || GFC_TYPE_ARRAY_AKIND (type) != GFC_ARRAY_ALLOCATABLE)
    1438                 :       30545 :       && (!GFC_DECL_GET_SCALAR_ALLOCATABLE (OMP_CLAUSE_DECL (clause))
    1439                 :         186 :           || !POINTER_TYPE_P (type)))
    1440                 :             :     {
    1441                 :       29928 :       if (gfc_has_alloc_comps (type, OMP_CLAUSE_DECL (clause)))
    1442                 :         140 :         return gfc_walk_alloc_comps (decl, NULL_TREE,
    1443                 :          70 :                                      OMP_CLAUSE_DECL (clause),
    1444                 :          70 :                                      WALK_ALLOC_COMPS_DTOR);
    1445                 :             :       return NULL_TREE;
    1446                 :             :     }
    1447                 :             : 
    1448                 :         566 :   if (GFC_DESCRIPTOR_TYPE_P (type))
    1449                 :             :     {
    1450                 :             :       /* Allocatable arrays in FIRSTPRIVATE/LASTPRIVATE etc. clauses need
    1451                 :             :          to be deallocated if they were allocated.  */
    1452                 :         382 :       tem = gfc_conv_descriptor_data_get (decl);
    1453                 :         382 :       tem = gfc_deallocate_with_status (tem, NULL_TREE, NULL_TREE, NULL_TREE,
    1454                 :             :                                         NULL_TREE, true, NULL,
    1455                 :             :                                         GFC_CAF_COARRAY_NOCOARRAY);
    1456                 :             :     }
    1457                 :             :   else
    1458                 :         184 :     tem = gfc_call_free (decl);
    1459                 :         566 :   tem = gfc_omp_unshare_expr (tem);
    1460                 :             : 
    1461                 :         566 :   if (gfc_has_alloc_comps (type, OMP_CLAUSE_DECL (clause)))
    1462                 :             :     {
    1463                 :          86 :       stmtblock_t block;
    1464                 :          86 :       tree then_b;
    1465                 :             : 
    1466                 :          86 :       gfc_init_block (&block);
    1467                 :         172 :       gfc_add_expr_to_block (&block,
    1468                 :             :                              gfc_walk_alloc_comps (decl, NULL_TREE,
    1469                 :          86 :                                                    OMP_CLAUSE_DECL (clause),
    1470                 :             :                                                    WALK_ALLOC_COMPS_DTOR));
    1471                 :          86 :       gfc_add_expr_to_block (&block, tem);
    1472                 :          86 :       then_b = gfc_finish_block (&block);
    1473                 :             : 
    1474                 :          86 :       tem = fold_convert (pvoid_type_node,
    1475                 :             :                           GFC_DESCRIPTOR_TYPE_P (type)
    1476                 :             :                           ? gfc_conv_descriptor_data_get (decl) : decl);
    1477                 :          86 :       tem = unshare_expr (tem);
    1478                 :          86 :       tree cond = fold_build2_loc (input_location, NE_EXPR, logical_type_node,
    1479                 :             :                                    tem, null_pointer_node);
    1480                 :          86 :       tem = build3_loc (input_location, COND_EXPR, void_type_node, cond,
    1481                 :             :                         then_b, build_empty_stmt (input_location));
    1482                 :             :     }
    1483                 :             :   return tem;
    1484                 :             : }
    1485                 :             : 
    1486                 :             : /* Build a conditional expression in BLOCK.  If COND_VAL is not
    1487                 :             :    null, then the block THEN_B is executed, otherwise ELSE_VAL
    1488                 :             :    is assigned to VAL.  */
    1489                 :             : 
    1490                 :             : static void
    1491                 :        1020 : gfc_build_cond_assign (stmtblock_t *block, tree val, tree cond_val,
    1492                 :             :                        tree then_b, tree else_val)
    1493                 :             : {
    1494                 :        1020 :   stmtblock_t cond_block;
    1495                 :        1020 :   tree else_b = NULL_TREE;
    1496                 :        1020 :   tree val_ty = TREE_TYPE (val);
    1497                 :             : 
    1498                 :        1020 :   if (else_val)
    1499                 :             :     {
    1500                 :        1020 :       gfc_init_block (&cond_block);
    1501                 :        1020 :       gfc_add_modify (&cond_block, val, fold_convert (val_ty, else_val));
    1502                 :        1020 :       else_b = gfc_finish_block (&cond_block);
    1503                 :             :     }
    1504                 :        1020 :   gfc_add_expr_to_block (block,
    1505                 :             :                          build3_loc (input_location, COND_EXPR, void_type_node,
    1506                 :             :                                      cond_val, then_b, else_b));
    1507                 :        1020 : }
    1508                 :             : 
    1509                 :             : /* Build a conditional expression in BLOCK, returning a temporary
    1510                 :             :    variable containing the result.  If COND_VAL is not null, then
    1511                 :             :    THEN_VAL will be assigned to the variable, otherwise ELSE_VAL
    1512                 :             :    is assigned.
    1513                 :             :  */
    1514                 :             : 
    1515                 :             : static tree
    1516                 :        1019 : gfc_build_cond_assign_expr (stmtblock_t *block, tree cond_val,
    1517                 :             :                             tree then_val, tree else_val)
    1518                 :             : {
    1519                 :        1019 :   tree val;
    1520                 :        1019 :   tree val_ty = TREE_TYPE (then_val);
    1521                 :        1019 :   stmtblock_t cond_block;
    1522                 :             : 
    1523                 :        1019 :   val = create_tmp_var (val_ty);
    1524                 :             : 
    1525                 :        1019 :   gfc_init_block (&cond_block);
    1526                 :        1019 :   gfc_add_modify (&cond_block, val, then_val);
    1527                 :        1019 :   tree then_b = gfc_finish_block (&cond_block);
    1528                 :             : 
    1529                 :        1019 :   gfc_build_cond_assign (block, val, cond_val, then_b, else_val);
    1530                 :             : 
    1531                 :        1019 :   return val;
    1532                 :             : }
    1533                 :             : 
    1534                 :             : void
    1535                 :       26816 : gfc_omp_finish_clause (tree c, gimple_seq *pre_p, bool openacc)
    1536                 :             : {
    1537                 :       26816 :   if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
    1538                 :             :     return;
    1539                 :             : 
    1540                 :        6595 :   tree decl = OMP_CLAUSE_DECL (c);
    1541                 :             : 
    1542                 :             :   /* Assumed-size arrays can't be mapped implicitly, they have to be
    1543                 :             :      mapped explicitly using array sections.  */
    1544                 :        6595 :   if (TREE_CODE (decl) == PARM_DECL
    1545                 :        1023 :       && GFC_ARRAY_TYPE_P (TREE_TYPE (decl))
    1546                 :         356 :       && GFC_TYPE_ARRAY_AKIND (TREE_TYPE (decl)) == GFC_ARRAY_UNKNOWN
    1547                 :        6951 :       && GFC_TYPE_ARRAY_UBOUND (TREE_TYPE (decl),
    1548                 :             :                                 GFC_TYPE_ARRAY_RANK (TREE_TYPE (decl)) - 1)
    1549                 :             :          == NULL)
    1550                 :             :     {
    1551                 :           1 :       error_at (OMP_CLAUSE_LOCATION (c),
    1552                 :             :                 "implicit mapping of assumed size array %qD", decl);
    1553                 :           1 :       return;
    1554                 :             :     }
    1555                 :             : 
    1556                 :        6594 :   tree c2 = NULL_TREE, c3 = NULL_TREE, c4 = NULL_TREE;
    1557                 :        6594 :   tree present = gfc_omp_check_optional_argument (decl, true);
    1558                 :        6594 :   if (POINTER_TYPE_P (TREE_TYPE (decl)))
    1559                 :             :     {
    1560                 :        1243 :       if (!gfc_omp_privatize_by_reference (decl)
    1561                 :         137 :           && !GFC_DECL_GET_SCALAR_POINTER (decl)
    1562                 :          74 :           && !GFC_DECL_GET_SCALAR_ALLOCATABLE (decl)
    1563                 :           3 :           && !GFC_DECL_CRAY_POINTEE (decl)
    1564                 :        1246 :           && !GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (TREE_TYPE (decl))))
    1565                 :             :         return;
    1566                 :        1240 :       tree orig_decl = decl;
    1567                 :             : 
    1568                 :        1240 :       c4 = build_omp_clause (OMP_CLAUSE_LOCATION (c), OMP_CLAUSE_MAP);
    1569                 :        1240 :       OMP_CLAUSE_SET_MAP_KIND (c4, GOMP_MAP_POINTER);
    1570                 :        1240 :       OMP_CLAUSE_DECL (c4) = decl;
    1571                 :        1240 :       OMP_CLAUSE_SIZE (c4) = size_int (0);
    1572                 :        1240 :       decl = build_fold_indirect_ref (decl);
    1573                 :        1240 :       if (present
    1574                 :        1240 :           && (GFC_DECL_GET_SCALAR_POINTER (orig_decl)
    1575                 :         265 :               || GFC_DECL_GET_SCALAR_ALLOCATABLE (orig_decl)))
    1576                 :             :         {
    1577                 :          66 :           c2 = build_omp_clause (input_location, OMP_CLAUSE_MAP);
    1578                 :          66 :           OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_POINTER);
    1579                 :          66 :           OMP_CLAUSE_DECL (c2) = decl;
    1580                 :          66 :           OMP_CLAUSE_SIZE (c2) = size_int (0);
    1581                 :             : 
    1582                 :          66 :           stmtblock_t block;
    1583                 :          66 :           gfc_start_block (&block);
    1584                 :          66 :           tree ptr = decl;
    1585                 :          66 :           ptr = gfc_build_cond_assign_expr (&block, present, decl,
    1586                 :             :                                             null_pointer_node);
    1587                 :          66 :           gimplify_and_add (gfc_finish_block (&block), pre_p);
    1588                 :          66 :           ptr = build_fold_indirect_ref (ptr);
    1589                 :          66 :           OMP_CLAUSE_DECL (c) = ptr;
    1590                 :          66 :           OMP_CLAUSE_SIZE (c) = TYPE_SIZE_UNIT (TREE_TYPE (ptr));
    1591                 :             :         }
    1592                 :             :       else
    1593                 :             :         {
    1594                 :        1174 :           OMP_CLAUSE_DECL (c) = decl;
    1595                 :        1174 :           OMP_CLAUSE_SIZE (c) = NULL_TREE;
    1596                 :             :         }
    1597                 :        1240 :       if (TREE_CODE (TREE_TYPE (orig_decl)) == REFERENCE_TYPE
    1598                 :        1240 :           && (GFC_DECL_GET_SCALAR_POINTER (orig_decl)
    1599                 :         385 :               || GFC_DECL_GET_SCALAR_ALLOCATABLE (orig_decl)))
    1600                 :             :         {
    1601                 :          66 :           c3 = build_omp_clause (OMP_CLAUSE_LOCATION (c), OMP_CLAUSE_MAP);
    1602                 :          66 :           OMP_CLAUSE_SET_MAP_KIND (c3, GOMP_MAP_POINTER);
    1603                 :          66 :           OMP_CLAUSE_DECL (c3) = unshare_expr (decl);
    1604                 :          66 :           OMP_CLAUSE_SIZE (c3) = size_int (0);
    1605                 :          66 :           decl = build_fold_indirect_ref (decl);
    1606                 :          66 :           OMP_CLAUSE_DECL (c) = decl;
    1607                 :             :         }
    1608                 :             :     }
    1609                 :        6591 :   if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl)))
    1610                 :             :     {
    1611                 :        1721 :       stmtblock_t block;
    1612                 :        1721 :       gfc_start_block (&block);
    1613                 :        1721 :       tree type = TREE_TYPE (decl);
    1614                 :        1721 :       tree ptr = gfc_conv_descriptor_data_get (decl);
    1615                 :             : 
    1616                 :             :       /* OpenMP: automatically map pointer targets with the pointer;
    1617                 :             :          hence, always update the descriptor/pointer itself.
    1618                 :             :          NOTE: This also remaps the pointer for allocatable arrays with
    1619                 :             :          'target' attribute which also don't have the 'restrict' qualifier.  */
    1620                 :        1721 :       bool always_modifier = false;
    1621                 :             : 
    1622                 :        1721 :       if (!openacc
    1623                 :        1721 :           && !(TYPE_QUALS (TREE_TYPE (ptr)) & TYPE_QUAL_RESTRICT))
    1624                 :             :         always_modifier = true;
    1625                 :             : 
    1626                 :        1721 :       if (present)
    1627                 :          55 :         ptr = gfc_build_cond_assign_expr (&block, present, ptr,
    1628                 :             :                                           null_pointer_node);
    1629                 :        1721 :       gcc_assert (POINTER_TYPE_P (TREE_TYPE (ptr)));
    1630                 :        1721 :       ptr = build_fold_indirect_ref (ptr);
    1631                 :        1721 :       OMP_CLAUSE_DECL (c) = ptr;
    1632                 :        1721 :       c2 = build_omp_clause (input_location, OMP_CLAUSE_MAP);
    1633                 :        1721 :       OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_TO_PSET);
    1634                 :        1721 :       if (present)
    1635                 :             :         {
    1636                 :          55 :           ptr = create_tmp_var (TREE_TYPE (TREE_OPERAND (decl, 0)));
    1637                 :          55 :           gfc_add_modify (&block, ptr, TREE_OPERAND (decl, 0));
    1638                 :             : 
    1639                 :          55 :           OMP_CLAUSE_DECL (c2) = build_fold_indirect_ref (ptr);
    1640                 :             :         }
    1641                 :             :       else
    1642                 :        1666 :         OMP_CLAUSE_DECL (c2) = decl;
    1643                 :        1721 :       OMP_CLAUSE_SIZE (c2) = TYPE_SIZE_UNIT (type);
    1644                 :        1721 :       c3 = build_omp_clause (OMP_CLAUSE_LOCATION (c), OMP_CLAUSE_MAP);
    1645                 :        3231 :       OMP_CLAUSE_SET_MAP_KIND (c3, always_modifier ? GOMP_MAP_ALWAYS_POINTER
    1646                 :             :                                                    : GOMP_MAP_POINTER);
    1647                 :        1721 :       if (present)
    1648                 :             :         {
    1649                 :          55 :           ptr = gfc_conv_descriptor_data_get (decl);
    1650                 :          55 :           ptr = gfc_build_addr_expr (NULL, ptr);
    1651                 :          55 :           ptr = gfc_build_cond_assign_expr (&block, present,
    1652                 :             :                                             ptr, null_pointer_node);
    1653                 :          55 :           ptr = build_fold_indirect_ref (ptr);
    1654                 :          55 :           OMP_CLAUSE_DECL (c3) = ptr;
    1655                 :             :         }
    1656                 :             :       else
    1657                 :        1666 :         OMP_CLAUSE_DECL (c3) = gfc_conv_descriptor_data_get (decl);
    1658                 :        1721 :       OMP_CLAUSE_SIZE (c3) = size_int (0);
    1659                 :        1721 :       tree size = create_tmp_var (gfc_array_index_type);
    1660                 :        1721 :       tree elemsz = TYPE_SIZE_UNIT (gfc_get_element_type (type));
    1661                 :        1721 :       elemsz = fold_convert (gfc_array_index_type, elemsz);
    1662                 :        1721 :       if (GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_ALLOCATABLE
    1663                 :         212 :           || GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_POINTER
    1664                 :        1722 :           || GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_POINTER_CONT)
    1665                 :             :         {
    1666                 :        1720 :           stmtblock_t cond_block;
    1667                 :        1720 :           tree tem, then_b, else_b, zero, cond;
    1668                 :             : 
    1669                 :        1720 :           gfc_init_block (&cond_block);
    1670                 :        5160 :           tem = gfc_full_array_size (&cond_block, decl,
    1671                 :        1720 :                                      GFC_TYPE_ARRAY_RANK (type));
    1672                 :        1720 :           gfc_add_modify (&cond_block, size, tem);
    1673                 :        1720 :           gfc_add_modify (&cond_block, size,
    1674                 :             :                           fold_build2 (MULT_EXPR, gfc_array_index_type,
    1675                 :             :                                        size, elemsz));
    1676                 :        1720 :           then_b = gfc_finish_block (&cond_block);
    1677                 :        1720 :           gfc_init_block (&cond_block);
    1678                 :        1720 :           zero = build_int_cst (gfc_array_index_type, 0);
    1679                 :        1720 :           gfc_add_modify (&cond_block, size, zero);
    1680                 :        1720 :           else_b = gfc_finish_block (&cond_block);
    1681                 :        1720 :           tem = gfc_conv_descriptor_data_get (decl);
    1682                 :        1720 :           tem = fold_convert (pvoid_type_node, tem);
    1683                 :        1720 :           cond = fold_build2_loc (input_location, NE_EXPR,
    1684                 :             :                                   boolean_type_node, tem, null_pointer_node);
    1685                 :        1720 :           if (present)
    1686                 :             :             {
    1687                 :          54 :               cond = fold_build2_loc (input_location, TRUTH_ANDIF_EXPR,
    1688                 :             :                                       boolean_type_node, present, cond);
    1689                 :             :             }
    1690                 :        1720 :           gfc_add_expr_to_block (&block, build3_loc (input_location, COND_EXPR,
    1691                 :             :                                                      void_type_node, cond,
    1692                 :             :                                                      then_b, else_b));
    1693                 :             :         }
    1694                 :           1 :       else if (present)
    1695                 :             :         {
    1696                 :           1 :           stmtblock_t cond_block;
    1697                 :           1 :           tree then_b;
    1698                 :             : 
    1699                 :           1 :           gfc_init_block (&cond_block);
    1700                 :           1 :           gfc_add_modify (&cond_block, size,
    1701                 :             :                           gfc_full_array_size (&cond_block, decl,
    1702                 :           1 :                                                GFC_TYPE_ARRAY_RANK (type)));
    1703                 :           1 :           gfc_add_modify (&cond_block, size,
    1704                 :             :                           fold_build2 (MULT_EXPR, gfc_array_index_type,
    1705                 :             :                                        size, elemsz));
    1706                 :           1 :           then_b = gfc_finish_block (&cond_block);
    1707                 :             : 
    1708                 :           1 :           gfc_build_cond_assign (&block, size, present, then_b,
    1709                 :           1 :                                  build_int_cst (gfc_array_index_type, 0));
    1710                 :             :         }
    1711                 :             :       else
    1712                 :             :         {
    1713                 :           0 :           gfc_add_modify (&block, size,
    1714                 :             :                           gfc_full_array_size (&block, decl,
    1715                 :           0 :                                                GFC_TYPE_ARRAY_RANK (type)));
    1716                 :           0 :           gfc_add_modify (&block, size,
    1717                 :             :                           fold_build2 (MULT_EXPR, gfc_array_index_type,
    1718                 :             :                                        size, elemsz));
    1719                 :             :         }
    1720                 :        1721 :       OMP_CLAUSE_SIZE (c) = size;
    1721                 :        1721 :       tree stmt = gfc_finish_block (&block);
    1722                 :        1721 :       gimplify_and_add (stmt, pre_p);
    1723                 :             :     }
    1724                 :        6591 :   tree last = c;
    1725                 :        6591 :   if (OMP_CLAUSE_SIZE (c) == NULL_TREE)
    1726                 :        1115 :     OMP_CLAUSE_SIZE (c)
    1727                 :        3175 :       = DECL_P (decl) ? DECL_SIZE_UNIT (decl)
    1728                 :         945 :                       : TYPE_SIZE_UNIT (TREE_TYPE (decl));
    1729                 :        6591 :   if (gimplify_expr (&OMP_CLAUSE_SIZE (c), pre_p,
    1730                 :             :                      NULL, is_gimple_val, fb_rvalue) == GS_ERROR)
    1731                 :           0 :     OMP_CLAUSE_SIZE (c) = size_int (0);
    1732                 :        6591 :   if (c2)
    1733                 :             :     {
    1734                 :        1787 :       OMP_CLAUSE_CHAIN (c2) = OMP_CLAUSE_CHAIN (last);
    1735                 :        1787 :       OMP_CLAUSE_CHAIN (last) = c2;
    1736                 :        1787 :       last = c2;
    1737                 :             :     }
    1738                 :        6591 :   if (c3)
    1739                 :             :     {
    1740                 :        1787 :       OMP_CLAUSE_CHAIN (c3) = OMP_CLAUSE_CHAIN (last);
    1741                 :        1787 :       OMP_CLAUSE_CHAIN (last) = c3;
    1742                 :        1787 :       last = c3;
    1743                 :             :     }
    1744                 :        6591 :   if (c4)
    1745                 :             :     {
    1746                 :        1240 :       OMP_CLAUSE_CHAIN (c4) = OMP_CLAUSE_CHAIN (last);
    1747                 :        1240 :       OMP_CLAUSE_CHAIN (last) = c4;
    1748                 :             :     }
    1749                 :             : }
    1750                 :             : 
    1751                 :             : 
    1752                 :             : /* Return true if DECL is a scalar variable (for the purpose of
    1753                 :             :    implicit firstprivatization/mapping). Only if 'ptr_alloc_ok.'
    1754                 :             :    is true, allocatables and pointers are permitted. */
    1755                 :             : 
    1756                 :             : bool
    1757                 :        3406 : gfc_omp_scalar_p (tree decl, bool ptr_alloc_ok)
    1758                 :             : {
    1759                 :        3406 :   tree type = TREE_TYPE (decl);
    1760                 :        3406 :   if (TREE_CODE (type) == REFERENCE_TYPE)
    1761                 :        1273 :     type = TREE_TYPE (type);
    1762                 :        3406 :   if (TREE_CODE (type) == POINTER_TYPE)
    1763                 :             :     {
    1764                 :         560 :       if (GFC_DECL_GET_SCALAR_ALLOCATABLE (decl)
    1765                 :         560 :           || GFC_DECL_GET_SCALAR_POINTER (decl))
    1766                 :             :         {
    1767                 :         148 :           if (!ptr_alloc_ok)
    1768                 :             :             return false;
    1769                 :           0 :           type = TREE_TYPE (type);
    1770                 :             :         }
    1771                 :         412 :       if (GFC_ARRAY_TYPE_P (type)
    1772                 :         412 :           || GFC_CLASS_TYPE_P (type))
    1773                 :             :         return false;
    1774                 :             :     }
    1775                 :        2883 :   if ((TREE_CODE (type) == ARRAY_TYPE || TREE_CODE (type) == INTEGER_TYPE)
    1776                 :        5201 :       && TYPE_STRING_FLAG (type))
    1777                 :             :     return false;
    1778                 :        2958 :   if (INTEGRAL_TYPE_P (type)
    1779                 :        2958 :       || SCALAR_FLOAT_TYPE_P (type)
    1780                 :        2958 :       || COMPLEX_FLOAT_TYPE_P (type))
    1781                 :             :     return true;
    1782                 :             :   return false;
    1783                 :             : }
    1784                 :             : 
    1785                 :             : 
    1786                 :             : /* Return true if DECL is a scalar with target attribute but does not have the
    1787                 :             :    allocatable (or pointer) attribute (for the purpose of implicit mapping).  */
    1788                 :             : 
    1789                 :             : bool
    1790                 :        3300 : gfc_omp_scalar_target_p (tree decl)
    1791                 :             : {
    1792                 :        3300 :   return (DECL_P (decl) && GFC_DECL_GET_SCALAR_TARGET (decl)
    1793                 :        3399 :           && gfc_omp_scalar_p (decl, false));
    1794                 :             : }
    1795                 :             : 
    1796                 :             : 
    1797                 :             : /* Return true if DECL's DECL_VALUE_EXPR (if any) should be
    1798                 :             :    disregarded in OpenMP construct, because it is going to be
    1799                 :             :    remapped during OpenMP lowering.  SHARED is true if DECL
    1800                 :             :    is going to be shared, false if it is going to be privatized.  */
    1801                 :             : 
    1802                 :             : bool
    1803                 :     1535589 : gfc_omp_disregard_value_expr (tree decl, bool shared)
    1804                 :             : {
    1805                 :     1535589 :   if (GFC_DECL_COMMON_OR_EQUIV (decl)
    1806                 :     1535589 :       && DECL_HAS_VALUE_EXPR_P (decl))
    1807                 :             :     {
    1808                 :        3039 :       tree value = DECL_VALUE_EXPR (decl);
    1809                 :             : 
    1810                 :        3039 :       if (TREE_CODE (value) == COMPONENT_REF
    1811                 :        3039 :           && VAR_P (TREE_OPERAND (value, 0))
    1812                 :        6078 :           && GFC_DECL_COMMON_OR_EQUIV (TREE_OPERAND (value, 0)))
    1813                 :             :         {
    1814                 :             :           /* If variable in COMMON or EQUIVALENCE is privatized, return
    1815                 :             :              true, as just that variable is supposed to be privatized,
    1816                 :             :              not the whole COMMON or whole EQUIVALENCE.
    1817                 :             :              For shared variables in COMMON or EQUIVALENCE, let them be
    1818                 :             :              gimplified to DECL_VALUE_EXPR, so that for multiple shared vars
    1819                 :             :              from the same COMMON or EQUIVALENCE just one sharing of the
    1820                 :             :              whole COMMON or EQUIVALENCE is enough.  */
    1821                 :        3039 :           return ! shared;
    1822                 :             :         }
    1823                 :             :     }
    1824                 :             : 
    1825                 :     1532550 :   if (GFC_DECL_RESULT (decl) && DECL_HAS_VALUE_EXPR_P (decl))
    1826                 :         374 :     return ! shared;
    1827                 :             : 
    1828                 :             :   return false;
    1829                 :             : }
    1830                 :             : 
    1831                 :             : /* Return true if DECL that is shared iff SHARED is true should
    1832                 :             :    be put into OMP_CLAUSE_PRIVATE with OMP_CLAUSE_PRIVATE_DEBUG
    1833                 :             :    flag set.  */
    1834                 :             : 
    1835                 :             : bool
    1836                 :       36079 : gfc_omp_private_debug_clause (tree decl, bool shared)
    1837                 :             : {
    1838                 :       36079 :   if (GFC_DECL_CRAY_POINTEE (decl))
    1839                 :             :     return true;
    1840                 :             : 
    1841                 :       36043 :   if (GFC_DECL_COMMON_OR_EQUIV (decl)
    1842                 :       36043 :       && DECL_HAS_VALUE_EXPR_P (decl))
    1843                 :             :     {
    1844                 :         326 :       tree value = DECL_VALUE_EXPR (decl);
    1845                 :             : 
    1846                 :         326 :       if (TREE_CODE (value) == COMPONENT_REF
    1847                 :         326 :           && VAR_P (TREE_OPERAND (value, 0))
    1848                 :         652 :           && GFC_DECL_COMMON_OR_EQUIV (TREE_OPERAND (value, 0)))
    1849                 :             :         return shared;
    1850                 :             :     }
    1851                 :             : 
    1852                 :             :   return false;
    1853                 :             : }
    1854                 :             : 
    1855                 :             : /* Register language specific type size variables as potentially OpenMP
    1856                 :             :    firstprivate variables.  */
    1857                 :             : 
    1858                 :             : void
    1859                 :       19741 : gfc_omp_firstprivatize_type_sizes (struct gimplify_omp_ctx *ctx, tree type)
    1860                 :             : {
    1861                 :       19741 :   if (GFC_ARRAY_TYPE_P (type) || GFC_DESCRIPTOR_TYPE_P (type))
    1862                 :             :     {
    1863                 :        3532 :       int r;
    1864                 :             : 
    1865                 :        3532 :       gcc_assert (TYPE_LANG_SPECIFIC (type) != NULL);
    1866                 :        8241 :       for (r = 0; r < GFC_TYPE_ARRAY_RANK (type); r++)
    1867                 :             :         {
    1868                 :        4709 :           omp_firstprivatize_variable (ctx, GFC_TYPE_ARRAY_LBOUND (type, r));
    1869                 :        4709 :           omp_firstprivatize_variable (ctx, GFC_TYPE_ARRAY_UBOUND (type, r));
    1870                 :        4709 :           omp_firstprivatize_variable (ctx, GFC_TYPE_ARRAY_STRIDE (type, r));
    1871                 :             :         }
    1872                 :        3532 :       omp_firstprivatize_variable (ctx, GFC_TYPE_ARRAY_SIZE (type));
    1873                 :        3532 :       omp_firstprivatize_variable (ctx, GFC_TYPE_ARRAY_OFFSET (type));
    1874                 :             :     }
    1875                 :       19741 : }
    1876                 :             : 
    1877                 :             : 
    1878                 :             : static inline tree
    1879                 :       70210 : gfc_trans_add_clause (tree node, tree tail)
    1880                 :             : {
    1881                 :       70210 :   OMP_CLAUSE_CHAIN (node) = tail;
    1882                 :       70210 :   return node;
    1883                 :             : }
    1884                 :             : 
    1885                 :             : static tree
    1886                 :       40823 : gfc_trans_omp_variable (gfc_symbol *sym, bool declare_simd)
    1887                 :             : {
    1888                 :       40823 :   if (declare_simd)
    1889                 :             :     {
    1890                 :         192 :       int cnt = 0;
    1891                 :         192 :       gfc_symbol *proc_sym;
    1892                 :         192 :       gfc_formal_arglist *f;
    1893                 :             : 
    1894                 :         192 :       gcc_assert (sym->attr.dummy);
    1895                 :         192 :       proc_sym = sym->ns->proc_name;
    1896                 :         192 :       if (proc_sym->attr.entry_master)
    1897                 :           0 :         ++cnt;
    1898                 :         192 :       if (gfc_return_by_reference (proc_sym))
    1899                 :             :         {
    1900                 :           0 :           ++cnt;
    1901                 :           0 :           if (proc_sym->ts.type == BT_CHARACTER)
    1902                 :           0 :             ++cnt;
    1903                 :             :         }
    1904                 :         364 :       for (f = gfc_sym_get_dummy_args (proc_sym); f; f = f->next)
    1905                 :         364 :         if (f->sym == sym)
    1906                 :             :           break;
    1907                 :         172 :         else if (f->sym)
    1908                 :         172 :           ++cnt;
    1909                 :         192 :       gcc_assert (f);
    1910                 :         192 :       return build_int_cst (integer_type_node, cnt);
    1911                 :             :     }
    1912                 :             : 
    1913                 :       40631 :   tree t = gfc_get_symbol_decl (sym);
    1914                 :       40631 :   tree parent_decl;
    1915                 :       40631 :   int parent_flag;
    1916                 :       40631 :   bool return_value;
    1917                 :       40631 :   bool alternate_entry;
    1918                 :       40631 :   bool entry_master;
    1919                 :             : 
    1920                 :       40631 :   return_value = sym->attr.function && sym->result == sym;
    1921                 :         157 :   alternate_entry = sym->attr.function && sym->attr.entry
    1922                 :       40665 :                     && sym->result == sym;
    1923                 :       81262 :   entry_master = sym->attr.result
    1924                 :         109 :                  && sym->ns->proc_name->attr.entry_master
    1925                 :       40643 :                  && !gfc_return_by_reference (sym->ns->proc_name);
    1926                 :       81262 :   parent_decl = current_function_decl
    1927                 :       40631 :                 ? DECL_CONTEXT (current_function_decl) : NULL_TREE;
    1928                 :             : 
    1929                 :       40631 :   if ((t == parent_decl && return_value)
    1930                 :       40624 :        || (sym->ns && sym->ns->proc_name
    1931                 :       40624 :            && sym->ns->proc_name->backend_decl == parent_decl
    1932                 :        2133 :            && (alternate_entry || entry_master)))
    1933                 :             :     parent_flag = 1;
    1934                 :             :   else
    1935                 :       40622 :     parent_flag = 0;
    1936                 :             : 
    1937                 :             :   /* Special case for assigning the return value of a function.
    1938                 :             :      Self recursive functions must have an explicit return value.  */
    1939                 :       40631 :   if (return_value && (t == current_function_decl || parent_flag))
    1940                 :          87 :     t = gfc_get_fake_result_decl (sym, parent_flag);
    1941                 :             : 
    1942                 :             :   /* Similarly for alternate entry points.  */
    1943                 :       40544 :   else if (alternate_entry
    1944                 :          32 :            && (sym->ns->proc_name->backend_decl == current_function_decl
    1945                 :           0 :                || parent_flag))
    1946                 :             :     {
    1947                 :          32 :       gfc_entry_list *el = NULL;
    1948                 :             : 
    1949                 :          51 :       for (el = sym->ns->entries; el; el = el->next)
    1950                 :          51 :         if (sym == el->sym)
    1951                 :             :           {
    1952                 :          32 :             t = gfc_get_fake_result_decl (sym, parent_flag);
    1953                 :          32 :             break;
    1954                 :             :           }
    1955                 :             :     }
    1956                 :             : 
    1957                 :       40512 :   else if (entry_master
    1958                 :          12 :            && (sym->ns->proc_name->backend_decl == current_function_decl
    1959                 :           0 :                || parent_flag))
    1960                 :          12 :     t = gfc_get_fake_result_decl (sym, parent_flag);
    1961                 :             : 
    1962                 :             :   return t;
    1963                 :             : }
    1964                 :             : 
    1965                 :             : static tree
    1966                 :       10772 : gfc_trans_omp_variable_list (enum omp_clause_code code,
    1967                 :             :                              gfc_omp_namelist *namelist, tree list,
    1968                 :             :                              bool declare_simd)
    1969                 :             : {
    1970                 :       28045 :   for (; namelist != NULL; namelist = namelist->next)
    1971                 :       17273 :     if (namelist->sym->attr.referenced || declare_simd)
    1972                 :             :       {
    1973                 :       17273 :         tree t = gfc_trans_omp_variable (namelist->sym, declare_simd);
    1974                 :       17273 :         if (t != error_mark_node)
    1975                 :             :           {
    1976                 :       17273 :             tree node;
    1977                 :       17273 :             node = build_omp_clause (input_location, code);
    1978                 :       17273 :             OMP_CLAUSE_DECL (node) = t;
    1979                 :       17273 :             list = gfc_trans_add_clause (node, list);
    1980                 :             : 
    1981                 :       17273 :             if (code == OMP_CLAUSE_LASTPRIVATE
    1982                 :        2822 :                 && namelist->u.lastprivate_conditional)
    1983                 :          88 :               OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (node) = 1;
    1984                 :             :           }
    1985                 :             :       }
    1986                 :       10772 :   return list;
    1987                 :             : }
    1988                 :             : 
    1989                 :             : struct omp_udr_find_orig_data
    1990                 :             : {
    1991                 :             :   gfc_omp_udr *omp_udr;
    1992                 :             :   bool omp_orig_seen;
    1993                 :             : };
    1994                 :             : 
    1995                 :             : static int
    1996                 :         678 : omp_udr_find_orig (gfc_expr **e, int *walk_subtrees ATTRIBUTE_UNUSED,
    1997                 :             :                    void *data)
    1998                 :             : {
    1999                 :         678 :   struct omp_udr_find_orig_data *cd = (struct omp_udr_find_orig_data *) data;
    2000                 :         678 :   if ((*e)->expr_type == EXPR_VARIABLE
    2001                 :         366 :       && (*e)->symtree->n.sym == cd->omp_udr->omp_orig)
    2002                 :          72 :     cd->omp_orig_seen = true;
    2003                 :             : 
    2004                 :         678 :   return 0;
    2005                 :             : }
    2006                 :             : 
    2007                 :             : static void
    2008                 :         683 : gfc_trans_omp_array_reduction_or_udr (tree c, gfc_omp_namelist *n, locus where)
    2009                 :             : {
    2010                 :         683 :   gfc_symbol *sym = n->sym;
    2011                 :         683 :   gfc_symtree *root1 = NULL, *root2 = NULL, *root3 = NULL, *root4 = NULL;
    2012                 :         683 :   gfc_symtree *symtree1, *symtree2, *symtree3, *symtree4 = NULL;
    2013                 :         683 :   gfc_symbol init_val_sym, outer_sym, intrinsic_sym;
    2014                 :         683 :   gfc_symbol omp_var_copy[4];
    2015                 :         683 :   gfc_expr *e1, *e2, *e3, *e4;
    2016                 :         683 :   gfc_ref *ref;
    2017                 :         683 :   tree decl, backend_decl, stmt, type, outer_decl;
    2018                 :         683 :   locus old_loc = gfc_current_locus;
    2019                 :         683 :   const char *iname;
    2020                 :         683 :   bool t;
    2021                 :         683 :   gfc_omp_udr *udr = n->u2.udr ? n->u2.udr->udr : NULL;
    2022                 :             : 
    2023                 :         683 :   decl = OMP_CLAUSE_DECL (c);
    2024                 :         683 :   gfc_current_locus = where;
    2025                 :         683 :   type = TREE_TYPE (decl);
    2026                 :         683 :   outer_decl = create_tmp_var_raw (type);
    2027                 :         683 :   if (TREE_CODE (decl) == PARM_DECL
    2028                 :          31 :       && TREE_CODE (type) == REFERENCE_TYPE
    2029                 :          12 :       && GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (type))
    2030                 :         695 :       && GFC_TYPE_ARRAY_AKIND (TREE_TYPE (type)) == GFC_ARRAY_ALLOCATABLE)
    2031                 :             :     {
    2032                 :          12 :       decl = build_fold_indirect_ref (decl);
    2033                 :          12 :       type = TREE_TYPE (type);
    2034                 :             :     }
    2035                 :             : 
    2036                 :             :   /* Create a fake symbol for init value.  */
    2037                 :         683 :   memset (&init_val_sym, 0, sizeof (init_val_sym));
    2038                 :         683 :   init_val_sym.ns = sym->ns;
    2039                 :         683 :   init_val_sym.name = sym->name;
    2040                 :         683 :   init_val_sym.ts = sym->ts;
    2041                 :         683 :   init_val_sym.attr.referenced = 1;
    2042                 :         683 :   init_val_sym.declared_at = where;
    2043                 :         683 :   init_val_sym.attr.flavor = FL_VARIABLE;
    2044                 :         683 :   if (OMP_CLAUSE_REDUCTION_CODE (c) != ERROR_MARK)
    2045                 :         283 :     backend_decl = omp_reduction_init (c, gfc_sym_type (&init_val_sym));
    2046                 :         400 :   else if (udr->initializer_ns)
    2047                 :             :     backend_decl = NULL;
    2048                 :             :   else
    2049                 :         130 :     switch (sym->ts.type)
    2050                 :             :       {
    2051                 :          15 :       case BT_LOGICAL:
    2052                 :          15 :       case BT_INTEGER:
    2053                 :          15 :       case BT_REAL:
    2054                 :          15 :       case BT_COMPLEX:
    2055                 :          15 :         backend_decl = build_zero_cst (gfc_sym_type (&init_val_sym));
    2056                 :          15 :         break;
    2057                 :             :       default:
    2058                 :             :         backend_decl = NULL_TREE;
    2059                 :             :         break;
    2060                 :             :       }
    2061                 :         683 :   init_val_sym.backend_decl = backend_decl;
    2062                 :             : 
    2063                 :             :   /* Create a fake symbol for the outer array reference.  */
    2064                 :         683 :   outer_sym = *sym;
    2065                 :         683 :   if (sym->as)
    2066                 :         426 :     outer_sym.as = gfc_copy_array_spec (sym->as);
    2067                 :         683 :   outer_sym.attr.dummy = 0;
    2068                 :         683 :   outer_sym.attr.result = 0;
    2069                 :         683 :   outer_sym.attr.flavor = FL_VARIABLE;
    2070                 :         683 :   outer_sym.backend_decl = outer_decl;
    2071                 :         683 :   if (decl != OMP_CLAUSE_DECL (c))
    2072                 :          12 :     outer_sym.backend_decl = build_fold_indirect_ref (outer_decl);
    2073                 :             : 
    2074                 :             :   /* Create fake symtrees for it.  */
    2075                 :         683 :   symtree1 = gfc_new_symtree (&root1, sym->name);
    2076                 :         683 :   symtree1->n.sym = sym;
    2077                 :         683 :   gcc_assert (symtree1 == root1);
    2078                 :             : 
    2079                 :         683 :   symtree2 = gfc_new_symtree (&root2, sym->name);
    2080                 :         683 :   symtree2->n.sym = &init_val_sym;
    2081                 :         683 :   gcc_assert (symtree2 == root2);
    2082                 :             : 
    2083                 :         683 :   symtree3 = gfc_new_symtree (&root3, sym->name);
    2084                 :         683 :   symtree3->n.sym = &outer_sym;
    2085                 :         683 :   gcc_assert (symtree3 == root3);
    2086                 :             : 
    2087                 :         683 :   memset (omp_var_copy, 0, sizeof omp_var_copy);
    2088                 :         683 :   if (udr)
    2089                 :             :     {
    2090                 :         400 :       omp_var_copy[0] = *udr->omp_out;
    2091                 :         400 :       omp_var_copy[1] = *udr->omp_in;
    2092                 :         400 :       *udr->omp_out = outer_sym;
    2093                 :         400 :       *udr->omp_in = *sym;
    2094                 :         400 :       if (udr->initializer_ns)
    2095                 :             :         {
    2096                 :         270 :           omp_var_copy[2] = *udr->omp_priv;
    2097                 :         270 :           omp_var_copy[3] = *udr->omp_orig;
    2098                 :         270 :           *udr->omp_priv = *sym;
    2099                 :         270 :           *udr->omp_orig = outer_sym;
    2100                 :             :         }
    2101                 :             :     }
    2102                 :             : 
    2103                 :             :   /* Create expressions.  */
    2104                 :         683 :   e1 = gfc_get_expr ();
    2105                 :         683 :   e1->expr_type = EXPR_VARIABLE;
    2106                 :         683 :   e1->where = where;
    2107                 :         683 :   e1->symtree = symtree1;
    2108                 :         683 :   e1->ts = sym->ts;
    2109                 :         683 :   if (sym->attr.dimension)
    2110                 :             :     {
    2111                 :         426 :       e1->ref = ref = gfc_get_ref ();
    2112                 :         426 :       ref->type = REF_ARRAY;
    2113                 :         426 :       ref->u.ar.where = where;
    2114                 :         426 :       ref->u.ar.as = sym->as;
    2115                 :         426 :       ref->u.ar.type = AR_FULL;
    2116                 :         426 :       ref->u.ar.dimen = 0;
    2117                 :             :     }
    2118                 :         683 :   t = gfc_resolve_expr (e1);
    2119                 :         683 :   gcc_assert (t);
    2120                 :             : 
    2121                 :         683 :   e2 = NULL;
    2122                 :         683 :   if (backend_decl != NULL_TREE)
    2123                 :             :     {
    2124                 :         298 :       e2 = gfc_get_expr ();
    2125                 :         298 :       e2->expr_type = EXPR_VARIABLE;
    2126                 :         298 :       e2->where = where;
    2127                 :         298 :       e2->symtree = symtree2;
    2128                 :         298 :       e2->ts = sym->ts;
    2129                 :         298 :       t = gfc_resolve_expr (e2);
    2130                 :         298 :       gcc_assert (t);
    2131                 :             :     }
    2132                 :         385 :   else if (udr->initializer_ns == NULL)
    2133                 :             :     {
    2134                 :         115 :       gcc_assert (sym->ts.type == BT_DERIVED);
    2135                 :         115 :       e2 = gfc_default_initializer (&sym->ts);
    2136                 :         115 :       gcc_assert (e2);
    2137                 :         115 :       t = gfc_resolve_expr (e2);
    2138                 :         115 :       gcc_assert (t);
    2139                 :             :     }
    2140                 :         270 :   else if (n->u2.udr->initializer->op == EXEC_ASSIGN)
    2141                 :             :     {
    2142                 :         204 :       e2 = gfc_copy_expr (n->u2.udr->initializer->expr2);
    2143                 :         204 :       t = gfc_resolve_expr (e2);
    2144                 :         204 :       gcc_assert (t);
    2145                 :             :     }
    2146                 :         683 :   if (udr && udr->initializer_ns)
    2147                 :             :     {
    2148                 :         270 :       struct omp_udr_find_orig_data cd;
    2149                 :         270 :       cd.omp_udr = udr;
    2150                 :         270 :       cd.omp_orig_seen = false;
    2151                 :         270 :       gfc_code_walker (&n->u2.udr->initializer,
    2152                 :             :                        gfc_dummy_code_callback, omp_udr_find_orig, &cd);
    2153                 :         270 :       if (cd.omp_orig_seen)
    2154                 :          72 :         OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c) = 1;
    2155                 :             :     }
    2156                 :             : 
    2157                 :         683 :   e3 = gfc_copy_expr (e1);
    2158                 :         683 :   e3->symtree = symtree3;
    2159                 :         683 :   t = gfc_resolve_expr (e3);
    2160                 :         683 :   gcc_assert (t);
    2161                 :             : 
    2162                 :         683 :   iname = NULL;
    2163                 :         683 :   e4 = NULL;
    2164                 :         683 :   switch (OMP_CLAUSE_REDUCTION_CODE (c))
    2165                 :             :     {
    2166                 :         159 :     case PLUS_EXPR:
    2167                 :         159 :     case MINUS_EXPR:
    2168                 :         159 :       e4 = gfc_add (e3, e1);
    2169                 :         159 :       break;
    2170                 :          26 :     case MULT_EXPR:
    2171                 :          26 :       e4 = gfc_multiply (e3, e1);
    2172                 :          26 :       break;
    2173                 :           6 :     case TRUTH_ANDIF_EXPR:
    2174                 :           6 :       e4 = gfc_and (e3, e1);
    2175                 :           6 :       break;
    2176                 :           6 :     case TRUTH_ORIF_EXPR:
    2177                 :           6 :       e4 = gfc_or (e3, e1);
    2178                 :           6 :       break;
    2179                 :           6 :     case EQ_EXPR:
    2180                 :           6 :       e4 = gfc_eqv (e3, e1);
    2181                 :           6 :       break;
    2182                 :           6 :     case NE_EXPR:
    2183                 :           6 :       e4 = gfc_neqv (e3, e1);
    2184                 :           6 :       break;
    2185                 :             :     case MIN_EXPR:
    2186                 :             :       iname = "min";
    2187                 :             :       break;
    2188                 :          24 :     case MAX_EXPR:
    2189                 :          24 :       iname = "max";
    2190                 :          24 :       break;
    2191                 :           8 :     case BIT_AND_EXPR:
    2192                 :           8 :       iname = "iand";
    2193                 :           8 :       break;
    2194                 :           6 :     case BIT_IOR_EXPR:
    2195                 :           6 :       iname = "ior";
    2196                 :           6 :       break;
    2197                 :           6 :     case BIT_XOR_EXPR:
    2198                 :           6 :       iname = "ieor";
    2199                 :           6 :       break;
    2200                 :         400 :     case ERROR_MARK:
    2201                 :         400 :       if (n->u2.udr->combiner->op == EXEC_ASSIGN)
    2202                 :             :         {
    2203                 :         334 :           gfc_free_expr (e3);
    2204                 :         334 :           e3 = gfc_copy_expr (n->u2.udr->combiner->expr1);
    2205                 :         334 :           e4 = gfc_copy_expr (n->u2.udr->combiner->expr2);
    2206                 :         334 :           t = gfc_resolve_expr (e3);
    2207                 :         334 :           gcc_assert (t);
    2208                 :         334 :           t = gfc_resolve_expr (e4);
    2209                 :         334 :           gcc_assert (t);
    2210                 :             :         }
    2211                 :             :       break;
    2212                 :           0 :     default:
    2213                 :           0 :       gcc_unreachable ();
    2214                 :             :     }
    2215                 :         683 :   if (iname != NULL)
    2216                 :             :     {
    2217                 :          74 :       memset (&intrinsic_sym, 0, sizeof (intrinsic_sym));
    2218                 :          74 :       intrinsic_sym.ns = sym->ns;
    2219                 :          74 :       intrinsic_sym.name = iname;
    2220                 :          74 :       intrinsic_sym.ts = sym->ts;
    2221                 :          74 :       intrinsic_sym.attr.referenced = 1;
    2222                 :          74 :       intrinsic_sym.attr.intrinsic = 1;
    2223                 :          74 :       intrinsic_sym.attr.function = 1;
    2224                 :          74 :       intrinsic_sym.attr.implicit_type = 1;
    2225                 :          74 :       intrinsic_sym.result = &intrinsic_sym;
    2226                 :          74 :       intrinsic_sym.declared_at = where;
    2227                 :             : 
    2228                 :          74 :       symtree4 = gfc_new_symtree (&root4, iname);
    2229                 :          74 :       symtree4->n.sym = &intrinsic_sym;
    2230                 :          74 :       gcc_assert (symtree4 == root4);
    2231                 :             : 
    2232                 :          74 :       e4 = gfc_get_expr ();
    2233                 :          74 :       e4->expr_type = EXPR_FUNCTION;
    2234                 :          74 :       e4->where = where;
    2235                 :          74 :       e4->symtree = symtree4;
    2236                 :          74 :       e4->value.function.actual = gfc_get_actual_arglist ();
    2237                 :          74 :       e4->value.function.actual->expr = e3;
    2238                 :          74 :       e4->value.function.actual->next = gfc_get_actual_arglist ();
    2239                 :          74 :       e4->value.function.actual->next->expr = e1;
    2240                 :             :     }
    2241                 :         683 :   if (OMP_CLAUSE_REDUCTION_CODE (c) != ERROR_MARK)
    2242                 :             :     {
    2243                 :             :       /* e1 and e3 have been stored as arguments of e4, avoid sharing.  */
    2244                 :         283 :       e1 = gfc_copy_expr (e1);
    2245                 :         283 :       e3 = gfc_copy_expr (e3);
    2246                 :         283 :       t = gfc_resolve_expr (e4);
    2247                 :         283 :       gcc_assert (t);
    2248                 :             :     }
    2249                 :             : 
    2250                 :             :   /* Create the init statement list.  */
    2251                 :         683 :   pushlevel ();
    2252                 :         683 :   if (e2)
    2253                 :         617 :     stmt = gfc_trans_assignment (e1, e2, false, false);
    2254                 :             :   else
    2255                 :          66 :     stmt = gfc_trans_call (n->u2.udr->initializer, false,
    2256                 :             :                            NULL_TREE, NULL_TREE, false);
    2257                 :         683 :   if (TREE_CODE (stmt) != BIND_EXPR)
    2258                 :         154 :     stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
    2259                 :             :   else
    2260                 :         529 :     poplevel (0, 0);
    2261                 :         683 :   OMP_CLAUSE_REDUCTION_INIT (c) = stmt;
    2262                 :             : 
    2263                 :             :   /* Create the merge statement list.  */
    2264                 :         683 :   pushlevel ();
    2265                 :         683 :   if (e4)
    2266                 :         617 :     stmt = gfc_trans_assignment (e3, e4, false, true);
    2267                 :             :   else
    2268                 :          66 :     stmt = gfc_trans_call (n->u2.udr->combiner, false,
    2269                 :             :                            NULL_TREE, NULL_TREE, false);
    2270                 :         683 :   if (TREE_CODE (stmt) != BIND_EXPR)
    2271                 :         233 :     stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
    2272                 :             :   else
    2273                 :         450 :     poplevel (0, 0);
    2274                 :         683 :   OMP_CLAUSE_REDUCTION_MERGE (c) = stmt;
    2275                 :             : 
    2276                 :             :   /* And stick the placeholder VAR_DECL into the clause as well.  */
    2277                 :         683 :   OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = outer_decl;
    2278                 :             : 
    2279                 :         683 :   gfc_current_locus = old_loc;
    2280                 :             : 
    2281                 :         683 :   gfc_free_expr (e1);
    2282                 :         683 :   if (e2)
    2283                 :         617 :     gfc_free_expr (e2);
    2284                 :         683 :   gfc_free_expr (e3);
    2285                 :         683 :   if (e4)
    2286                 :         617 :     gfc_free_expr (e4);
    2287                 :         683 :   free (symtree1);
    2288                 :         683 :   free (symtree2);
    2289                 :         683 :   free (symtree3);
    2290                 :         683 :   free (symtree4);
    2291                 :         683 :   if (outer_sym.as)
    2292                 :         426 :     gfc_free_array_spec (outer_sym.as);
    2293                 :             : 
    2294                 :         683 :   if (udr)
    2295                 :             :     {
    2296                 :         400 :       *udr->omp_out = omp_var_copy[0];
    2297                 :         400 :       *udr->omp_in = omp_var_copy[1];
    2298                 :         400 :       if (udr->initializer_ns)
    2299                 :             :         {
    2300                 :         270 :           *udr->omp_priv = omp_var_copy[2];
    2301                 :         270 :           *udr->omp_orig = omp_var_copy[3];
    2302                 :             :         }
    2303                 :             :     }
    2304                 :         683 : }
    2305                 :             : 
    2306                 :             : static tree
    2307                 :        3567 : gfc_trans_omp_reduction_list (int kind, gfc_omp_namelist *namelist, tree list,
    2308                 :             :                               locus where, bool mark_addressable)
    2309                 :             : {
    2310                 :        3567 :   omp_clause_code clause = OMP_CLAUSE_REDUCTION;
    2311                 :        3567 :   switch (kind)
    2312                 :             :     {
    2313                 :             :     case OMP_LIST_REDUCTION:
    2314                 :             :     case OMP_LIST_REDUCTION_INSCAN:
    2315                 :             :     case OMP_LIST_REDUCTION_TASK:
    2316                 :             :       break;
    2317                 :             :     case OMP_LIST_IN_REDUCTION:
    2318                 :             :       clause = OMP_CLAUSE_IN_REDUCTION;
    2319                 :             :       break;
    2320                 :             :     case OMP_LIST_TASK_REDUCTION:
    2321                 :             :       clause = OMP_CLAUSE_TASK_REDUCTION;
    2322                 :             :       break;
    2323                 :           0 :     default:
    2324                 :           0 :       gcc_unreachable ();
    2325                 :             :     }
    2326                 :        8049 :   for (; namelist != NULL; namelist = namelist->next)
    2327                 :        4482 :     if (namelist->sym->attr.referenced)
    2328                 :             :       {
    2329                 :        4482 :         tree t = gfc_trans_omp_variable (namelist->sym, false);
    2330                 :        4482 :         if (t != error_mark_node)
    2331                 :             :           {
    2332                 :        4482 :             tree node = build_omp_clause (gfc_get_location (&namelist->where),
    2333                 :             :                                           clause);
    2334                 :        4482 :             OMP_CLAUSE_DECL (node) = t;
    2335                 :        4482 :             if (mark_addressable)
    2336                 :          37 :               TREE_ADDRESSABLE (t) = 1;
    2337                 :        4482 :             if (kind == OMP_LIST_REDUCTION_INSCAN)
    2338                 :          20 :               OMP_CLAUSE_REDUCTION_INSCAN (node) = 1;
    2339                 :        4482 :             if (kind == OMP_LIST_REDUCTION_TASK)
    2340                 :          91 :               OMP_CLAUSE_REDUCTION_TASK (node) = 1;
    2341                 :        4482 :             switch (namelist->u.reduction_op)
    2342                 :             :               {
    2343                 :        2124 :               case OMP_REDUCTION_PLUS:
    2344                 :        2124 :                 OMP_CLAUSE_REDUCTION_CODE (node) = PLUS_EXPR;
    2345                 :        2124 :                 break;
    2346                 :         147 :               case OMP_REDUCTION_MINUS:
    2347                 :         147 :                 OMP_CLAUSE_REDUCTION_CODE (node) = MINUS_EXPR;
    2348                 :         147 :                 break;
    2349                 :         239 :               case OMP_REDUCTION_TIMES:
    2350                 :         239 :                 OMP_CLAUSE_REDUCTION_CODE (node) = MULT_EXPR;
    2351                 :         239 :                 break;
    2352                 :          90 :               case OMP_REDUCTION_AND:
    2353                 :          90 :                 OMP_CLAUSE_REDUCTION_CODE (node) = TRUTH_ANDIF_EXPR;
    2354                 :          90 :                 break;
    2355                 :         783 :               case OMP_REDUCTION_OR:
    2356                 :         783 :                 OMP_CLAUSE_REDUCTION_CODE (node) = TRUTH_ORIF_EXPR;
    2357                 :         783 :                 break;
    2358                 :          84 :               case OMP_REDUCTION_EQV:
    2359                 :          84 :                 OMP_CLAUSE_REDUCTION_CODE (node) = EQ_EXPR;
    2360                 :          84 :                 break;
    2361                 :          84 :               case OMP_REDUCTION_NEQV:
    2362                 :          84 :                 OMP_CLAUSE_REDUCTION_CODE (node) = NE_EXPR;
    2363                 :          84 :                 break;
    2364                 :         211 :               case OMP_REDUCTION_MAX:
    2365                 :         211 :                 OMP_CLAUSE_REDUCTION_CODE (node) = MAX_EXPR;
    2366                 :         211 :                 break;
    2367                 :         199 :               case OMP_REDUCTION_MIN:
    2368                 :         199 :                 OMP_CLAUSE_REDUCTION_CODE (node) = MIN_EXPR;
    2369                 :         199 :                 break;
    2370                 :          38 :               case OMP_REDUCTION_IAND:
    2371                 :          38 :                 OMP_CLAUSE_REDUCTION_CODE (node) = BIT_AND_EXPR;
    2372                 :          38 :                 break;
    2373                 :          47 :               case OMP_REDUCTION_IOR:
    2374                 :          47 :                 OMP_CLAUSE_REDUCTION_CODE (node) = BIT_IOR_EXPR;
    2375                 :          47 :                 break;
    2376                 :          36 :               case OMP_REDUCTION_IEOR:
    2377                 :          36 :                 OMP_CLAUSE_REDUCTION_CODE (node) = BIT_XOR_EXPR;
    2378                 :          36 :                 break;
    2379                 :         400 :               case OMP_REDUCTION_USER:
    2380                 :         400 :                 OMP_CLAUSE_REDUCTION_CODE (node) = ERROR_MARK;
    2381                 :         400 :                 break;
    2382                 :           0 :               default:
    2383                 :           0 :                 gcc_unreachable ();
    2384                 :             :               }
    2385                 :        4482 :             if (namelist->sym->attr.dimension
    2386                 :        4056 :                 || namelist->u.reduction_op == OMP_REDUCTION_USER
    2387                 :        3812 :                 || namelist->sym->attr.allocatable)
    2388                 :         683 :               gfc_trans_omp_array_reduction_or_udr (node, namelist, where);
    2389                 :        4482 :             list = gfc_trans_add_clause (node, list);
    2390                 :             :           }
    2391                 :             :       }
    2392                 :        3567 :   return list;
    2393                 :             : }
    2394                 :             : 
    2395                 :             : static inline tree
    2396                 :        3129 : gfc_convert_expr_to_tree (stmtblock_t *block, gfc_expr *expr)
    2397                 :             : {
    2398                 :        3129 :   gfc_se se;
    2399                 :        3129 :   tree result;
    2400                 :             : 
    2401                 :        3129 :   gfc_init_se (&se, NULL );
    2402                 :        3129 :   gfc_conv_expr (&se, expr);
    2403                 :        3129 :   gfc_add_block_to_block (block, &se.pre);
    2404                 :        3129 :   result = gfc_evaluate_now (se.expr, block);
    2405                 :        3129 :   gfc_add_block_to_block (block, &se.post);
    2406                 :             : 
    2407                 :        3129 :   return result;
    2408                 :             : }
    2409                 :             : 
    2410                 :             : static vec<tree, va_heap, vl_embed> *doacross_steps;
    2411                 :             : 
    2412                 :             : 
    2413                 :             : /* Translate an array section or array element.  */
    2414                 :             : 
    2415                 :             : static void
    2416                 :        3954 : gfc_trans_omp_array_section (stmtblock_t *block, gfc_exec_op op,
    2417                 :             :                              gfc_omp_namelist *n, tree decl, bool element,
    2418                 :             :                              bool openmp, gomp_map_kind ptr_kind, tree &node,
    2419                 :             :                              tree &node2, tree &node3, tree &node4)
    2420                 :             : {
    2421                 :        3954 :   gfc_se se;
    2422                 :        3954 :   tree ptr, ptr2;
    2423                 :        3954 :   tree elemsz = NULL_TREE;
    2424                 :             : 
    2425                 :        3954 :   gfc_init_se (&se, NULL);
    2426                 :        3954 :   if (element)
    2427                 :             :     {
    2428                 :         170 :       gfc_conv_expr_reference (&se, n->expr);
    2429                 :         170 :       gfc_add_block_to_block (block, &se.pre);
    2430                 :         170 :       ptr = se.expr;
    2431                 :             :     }
    2432                 :             :   else
    2433                 :             :     {
    2434                 :        3784 :       gfc_conv_expr_descriptor (&se, n->expr);
    2435                 :        3784 :       ptr = gfc_conv_array_data (se.expr);
    2436                 :             :     }
    2437                 :        3954 :   if (n->expr->ts.type == BT_CHARACTER && n->expr->ts.deferred)
    2438                 :             :     {
    2439                 :           0 :       gcc_assert (se.string_length);
    2440                 :           0 :       tree len = gfc_evaluate_now (se.string_length, block);
    2441                 :           0 :       elemsz = gfc_get_char_type (n->expr->ts.kind);
    2442                 :           0 :       elemsz = TYPE_SIZE_UNIT (elemsz);
    2443                 :           0 :       elemsz = fold_build2 (MULT_EXPR, size_type_node,
    2444                 :             :                             fold_convert (size_type_node, len), elemsz);
    2445                 :             :     }
    2446                 :        3954 :   if (element)
    2447                 :             :     {
    2448                 :         170 :       if (!elemsz)
    2449                 :         170 :         elemsz = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (ptr)));
    2450                 :         170 :       OMP_CLAUSE_SIZE (node) = elemsz;
    2451                 :             :     }
    2452                 :             :   else
    2453                 :             :     {
    2454                 :        3784 :       tree type = TREE_TYPE (se.expr);
    2455                 :        3784 :       gfc_add_block_to_block (block, &se.pre);
    2456                 :        3784 :       OMP_CLAUSE_SIZE (node) = gfc_full_array_size (block, se.expr,
    2457                 :        3784 :                                                     GFC_TYPE_ARRAY_RANK (type));
    2458                 :        3784 :       if (!elemsz)
    2459                 :        3784 :         elemsz = TYPE_SIZE_UNIT (gfc_get_element_type (type));
    2460                 :        3784 :       elemsz = fold_convert (gfc_array_index_type, elemsz);
    2461                 :        3784 :       OMP_CLAUSE_SIZE (node) = fold_build2 (MULT_EXPR, gfc_array_index_type,
    2462                 :             :                                             OMP_CLAUSE_SIZE (node), elemsz);
    2463                 :             :     }
    2464                 :        3954 :   gcc_assert (se.post.head == NULL_TREE);
    2465                 :        3954 :   gcc_assert (POINTER_TYPE_P (TREE_TYPE (ptr)));
    2466                 :        3954 :   OMP_CLAUSE_DECL (node) = build_fold_indirect_ref (ptr);
    2467                 :        3954 :   ptr = fold_convert (ptrdiff_type_node, ptr);
    2468                 :             : 
    2469                 :        7664 :   if (POINTER_TYPE_P (TREE_TYPE (decl))
    2470                 :         322 :       && GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (TREE_TYPE (decl)))
    2471                 :          78 :       && ptr_kind == GOMP_MAP_POINTER
    2472                 :          78 :       && op != EXEC_OMP_TARGET_EXIT_DATA
    2473                 :          78 :       && OMP_CLAUSE_MAP_KIND (node) != GOMP_MAP_RELEASE
    2474                 :        4032 :       && OMP_CLAUSE_MAP_KIND (node) != GOMP_MAP_DELETE)
    2475                 :             : 
    2476                 :             :     {
    2477                 :          78 :       node4 = build_omp_clause (input_location,
    2478                 :             :                                 OMP_CLAUSE_MAP);
    2479                 :          78 :       OMP_CLAUSE_SET_MAP_KIND (node4, GOMP_MAP_POINTER);
    2480                 :          78 :       OMP_CLAUSE_DECL (node4) = decl;
    2481                 :          78 :       OMP_CLAUSE_SIZE (node4) = size_int (0);
    2482                 :          78 :       decl = build_fold_indirect_ref (decl);
    2483                 :             :     }
    2484                 :        3876 :   else if (ptr_kind == GOMP_MAP_ALWAYS_POINTER
    2485                 :           0 :            && n->expr->ts.type == BT_CHARACTER
    2486                 :           0 :            && n->expr->ts.deferred)
    2487                 :             :     {
    2488                 :           0 :       gomp_map_kind map_kind;
    2489                 :           0 :       if (OMP_CLAUSE_MAP_KIND (node) == GOMP_MAP_DELETE)
    2490                 :           0 :         map_kind = OMP_CLAUSE_MAP_KIND (node);
    2491                 :           0 :       else if (op == EXEC_OMP_TARGET_EXIT_DATA
    2492                 :           0 :                || OMP_CLAUSE_MAP_KIND (node) == GOMP_MAP_RELEASE)
    2493                 :             :         map_kind = GOMP_MAP_RELEASE;
    2494                 :             :       else
    2495                 :             :         map_kind = GOMP_MAP_TO;
    2496                 :           0 :       gcc_assert (se.string_length);
    2497                 :           0 :       node4 = build_omp_clause (input_location, OMP_CLAUSE_MAP);
    2498                 :           0 :       OMP_CLAUSE_SET_MAP_KIND (node4, map_kind);
    2499                 :           0 :       OMP_CLAUSE_DECL (node4) = se.string_length;
    2500                 :           0 :       OMP_CLAUSE_SIZE (node4) = TYPE_SIZE_UNIT (gfc_charlen_type_node);
    2501                 :             :     }
    2502                 :        3954 :   if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl)))
    2503                 :             :     {
    2504                 :        2704 :       tree type = TREE_TYPE (decl);
    2505                 :        2704 :       ptr2 = gfc_conv_descriptor_data_get (decl);
    2506                 :        2704 :       node2 = build_omp_clause (input_location, OMP_CLAUSE_MAP);
    2507                 :        2704 :       OMP_CLAUSE_DECL (node2) = decl;
    2508                 :        2704 :       OMP_CLAUSE_SIZE (node2) = TYPE_SIZE_UNIT (type);
    2509                 :        2704 :       if (OMP_CLAUSE_MAP_KIND (node) == GOMP_MAP_DELETE
    2510                 :        2703 :           || OMP_CLAUSE_MAP_KIND (node) == GOMP_MAP_RELEASE
    2511                 :        2494 :           || op == EXEC_OMP_TARGET_EXIT_DATA
    2512                 :        5198 :           || op == EXEC_OACC_EXIT_DATA)
    2513                 :             :         {
    2514                 :         391 :           gomp_map_kind map_kind
    2515                 :         391 :             = OMP_CLAUSE_MAP_KIND (node) == GOMP_MAP_DELETE ? GOMP_MAP_DELETE
    2516                 :         391 :                                                             : GOMP_MAP_RELEASE;
    2517                 :         391 :           OMP_CLAUSE_SET_MAP_KIND (node2, map_kind);
    2518                 :         391 :           OMP_CLAUSE_RELEASE_DESCRIPTOR (node2) = 1;
    2519                 :             :         }
    2520                 :             :       else
    2521                 :        2313 :         OMP_CLAUSE_SET_MAP_KIND (node2, GOMP_MAP_TO_PSET);
    2522                 :        2704 :       node3 = build_omp_clause (input_location, OMP_CLAUSE_MAP);
    2523                 :        2704 :       OMP_CLAUSE_SET_MAP_KIND (node3, ptr_kind);
    2524                 :        2704 :       OMP_CLAUSE_DECL (node3) = gfc_conv_descriptor_data_get (decl);
    2525                 :             :       /* This purposely does not include GOMP_MAP_ALWAYS_POINTER.  The extra
    2526                 :             :          cast prevents gimplify.cc from recognising it as being part of the
    2527                 :             :          struct - and adding an 'alloc: for the 'desc.data' pointer, which
    2528                 :             :          would break as the 'desc' (the descriptor) is also mapped
    2529                 :             :          (see node4 above).  */
    2530                 :        2704 :       if (ptr_kind == GOMP_MAP_ATTACH_DETACH && !openmp)
    2531                 :         141 :         STRIP_NOPS (OMP_CLAUSE_DECL (node3));
    2532                 :             :     }
    2533                 :             :   else
    2534                 :             :     {
    2535                 :        1250 :       if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
    2536                 :             :         {
    2537                 :        1006 :           tree offset;
    2538                 :        1006 :           ptr2 = build_fold_addr_expr (decl);
    2539                 :        1006 :           offset = fold_build2 (MINUS_EXPR, ptrdiff_type_node, ptr,
    2540                 :             :                                 fold_convert (ptrdiff_type_node, ptr2));
    2541                 :        1006 :           offset = build2 (TRUNC_DIV_EXPR, ptrdiff_type_node,
    2542                 :             :                            offset, fold_convert (ptrdiff_type_node, elemsz));
    2543                 :        1006 :           offset = build4_loc (input_location, ARRAY_REF,
    2544                 :        1006 :                                TREE_TYPE (TREE_TYPE (decl)),
    2545                 :             :                                decl, offset, NULL_TREE, NULL_TREE);
    2546                 :        1006 :           OMP_CLAUSE_DECL (node) = offset;
    2547                 :             : 
    2548                 :        1006 :           if (ptr_kind == GOMP_MAP_ATTACH_DETACH && openmp)
    2549                 :         143 :             return;
    2550                 :             :         }
    2551                 :             :       else
    2552                 :             :         {
    2553                 :         244 :           gcc_assert (POINTER_TYPE_P (TREE_TYPE (decl)));
    2554                 :             :           ptr2 = decl;
    2555                 :             :         }
    2556                 :        1107 :       node3 = build_omp_clause (input_location,
    2557                 :             :                                 OMP_CLAUSE_MAP);
    2558                 :        1107 :       OMP_CLAUSE_SET_MAP_KIND (node3, ptr_kind);
    2559                 :        1107 :       OMP_CLAUSE_DECL (node3) = decl;
    2560                 :             :     }
    2561                 :        3811 :   ptr2 = fold_convert (ptrdiff_type_node, ptr2);
    2562                 :        3811 :   OMP_CLAUSE_SIZE (node3) = fold_build2 (MINUS_EXPR, ptrdiff_type_node,
    2563                 :             :                                          ptr, ptr2);
    2564                 :             : }
    2565                 :             : 
    2566                 :             : static tree
    2567                 :          43 : handle_iterator (gfc_namespace *ns, stmtblock_t *iter_block, tree block)
    2568                 :             : {
    2569                 :          43 :   tree list = NULL_TREE;
    2570                 :          88 :   for (gfc_symbol *sym = ns->omp_affinity_iterators; sym; sym = sym->tlink)
    2571                 :             :     {
    2572                 :          45 :       gfc_constructor *c;
    2573                 :          45 :       gfc_se se;
    2574                 :             : 
    2575                 :          45 :       tree last = make_tree_vec (6);
    2576                 :          45 :       tree iter_var = gfc_get_symbol_decl (sym);
    2577                 :          45 :       tree type = TREE_TYPE (iter_var);
    2578                 :          45 :       TREE_VEC_ELT (last, 0) = iter_var;
    2579                 :          45 :       DECL_CHAIN (iter_var) = BLOCK_VARS (block);
    2580                 :          45 :       BLOCK_VARS (block) = iter_var;
    2581                 :             : 
    2582                 :             :       /* begin */
    2583                 :          45 :       c = gfc_constructor_first (sym->value->value.constructor);
    2584                 :          45 :       gfc_init_se (&se, NULL);
    2585                 :          45 :       gfc_conv_expr (&se, c->expr);
    2586                 :          45 :       gfc_add_block_to_block (iter_block, &se.pre);
    2587                 :          45 :       gfc_add_block_to_block (iter_block, &se.post);
    2588                 :          45 :       TREE_VEC_ELT (last, 1) = fold_convert (type,
    2589                 :             :                                              gfc_evaluate_now (se.expr,
    2590                 :             :                                                                iter_block));
    2591                 :             :       /* end */
    2592                 :          45 :       c = gfc_constructor_next (c);
    2593                 :          45 :       gfc_init_se (&se, NULL);
    2594                 :          45 :       gfc_conv_expr (&se, c->expr);
    2595                 :          45 :       gfc_add_block_to_block (iter_block, &se.pre);
    2596                 :          45 :       gfc_add_block_to_block (iter_block, &se.post);
    2597                 :          45 :       TREE_VEC_ELT (last, 2) = fold_convert (type,
    2598                 :             :                                              gfc_evaluate_now (se.expr,
    2599                 :             :                                                                iter_block));
    2600                 :             :       /* step */
    2601                 :          45 :       c = gfc_constructor_next (c);
    2602                 :          45 :       tree step;
    2603                 :          45 :       if (c)
    2604                 :             :         {
    2605                 :           5 :           gfc_init_se (&se, NULL);
    2606                 :           5 :           gfc_conv_expr (&se, c->expr);
    2607                 :           5 :           gfc_add_block_to_block (iter_block, &se.pre);
    2608                 :           5 :           gfc_add_block_to_block (iter_block, &se.post);
    2609                 :           5 :           gfc_conv_expr (&se, c->expr);
    2610                 :           5 :           step = fold_convert (type,
    2611                 :             :                                gfc_evaluate_now (se.expr,
    2612                 :             :                                                  iter_block));
    2613                 :             :         }
    2614                 :             :       else
    2615                 :          40 :         step = build_int_cst (type, 1);
    2616                 :          45 :       TREE_VEC_ELT (last, 3) = step;
    2617                 :             :       /* orig_step */
    2618                 :          45 :       TREE_VEC_ELT (last, 4) = save_expr (step);
    2619                 :          45 :       TREE_CHAIN (last) = list;
    2620                 :          45 :       list = last;
    2621                 :             :     }
    2622                 :          43 :   return list;
    2623                 :             : }
    2624                 :             : 
    2625                 :             : /* To alleviate quadratic behaviour in checking each entry of a
    2626                 :             :    gfc_omp_namelist against every other entry, we build a hashtable indexed by
    2627                 :             :    gfc_symbol pointer, which we can use in the usual case that a map
    2628                 :             :    expression has a symbol as its root term.  Return a namelist based on the
    2629                 :             :    root symbol used by N, building a new table in SYM_ROOTED_NL using the
    2630                 :             :    gfc_omp_namelist N2 (all clauses) if we haven't done so already.  */
    2631                 :             : 
    2632                 :             : static gfc_omp_namelist *
    2633                 :         528 : get_symbol_rooted_namelist (hash_map<gfc_symbol *,
    2634                 :             :                                      gfc_omp_namelist *> *&sym_rooted_nl,
    2635                 :             :                             gfc_omp_namelist *n,
    2636                 :             :                             gfc_omp_namelist *n2, bool *sym_based)
    2637                 :             : {
    2638                 :             :   /* Early-out if we have a NULL clause list (e.g. for OpenACC).  */
    2639                 :         528 :   if (!n2)
    2640                 :             :     return NULL;
    2641                 :             : 
    2642                 :         491 :   gfc_symbol *use_sym = NULL;
    2643                 :             : 
    2644                 :             :   /* We're only interested in cases where we have an expression, e.g. a
    2645                 :             :      component access.  */
    2646                 :         491 :   if (n->expr && n->expr->expr_type == EXPR_VARIABLE && n->expr->symtree)
    2647                 :         491 :     use_sym = n->expr->symtree->n.sym;
    2648                 :             : 
    2649                 :         491 :   *sym_based = false;
    2650                 :             : 
    2651                 :         491 :   if (!use_sym)
    2652                 :             :     return n2;
    2653                 :             : 
    2654                 :         491 :   if (!sym_rooted_nl)
    2655                 :             :     {
    2656                 :         237 :       sym_rooted_nl = new hash_map<gfc_symbol *, gfc_omp_namelist *> ();
    2657                 :             : 
    2658                 :        1140 :       for (; n2 != NULL; n2 = n2->next)
    2659                 :             :         {
    2660                 :         903 :           if (!n2->expr
    2661                 :         902 :               || n2->expr->expr_type != EXPR_VARIABLE
    2662                 :         902 :               || !n2->expr->symtree)
    2663                 :           1 :             continue;
    2664                 :             : 
    2665                 :         902 :           gfc_omp_namelist *nl_copy = gfc_get_omp_namelist ();
    2666                 :         902 :           memcpy (nl_copy, n2, sizeof *nl_copy);
    2667                 :         902 :           nl_copy->u2.duplicate_of = n2;
    2668                 :         902 :           nl_copy->next = NULL;
    2669                 :             : 
    2670                 :         902 :           gfc_symbol *idx_sym = n2->expr->symtree->n.sym;
    2671                 :             : 
    2672                 :         902 :           bool existed;
    2673                 :         902 :           gfc_omp_namelist *&entry
    2674                 :         902 :             = sym_rooted_nl->get_or_insert (idx_sym, &existed);
    2675                 :         902 :           if (existed)
    2676                 :         614 :             nl_copy->next = entry;
    2677                 :         902 :           entry = nl_copy;
    2678                 :             :         }
    2679                 :             :     }
    2680                 :             : 
    2681                 :         491 :   gfc_omp_namelist **n2_sym = sym_rooted_nl->get (use_sym);
    2682                 :             : 
    2683                 :         491 :   if (n2_sym)
    2684                 :             :     {
    2685                 :         491 :       *sym_based = true;
    2686                 :         491 :       return *n2_sym;
    2687                 :             :     }
    2688                 :             : 
    2689                 :             :   return NULL;
    2690                 :             : }
    2691                 :             : 
    2692                 :             : static tree
    2693                 :       28959 : gfc_trans_omp_clauses (stmtblock_t *block, gfc_omp_clauses *clauses,
    2694                 :             :                        locus where, bool declare_simd = false,
    2695                 :             :                        bool openacc = false, gfc_exec_op op = EXEC_NOP)
    2696                 :             : {
    2697                 :       28959 :   tree omp_clauses = NULL_TREE, prev_clauses, chunk_size, c;
    2698                 :       28959 :   tree iterator = NULL_TREE;
    2699                 :       28959 :   tree tree_block = NULL_TREE;
    2700                 :       28959 :   stmtblock_t iter_block;
    2701                 :       28959 :   int list, ifc;
    2702                 :       28959 :   enum omp_clause_code clause_code;
    2703                 :       28959 :   gfc_omp_namelist *prev = NULL;
    2704                 :       28959 :   gfc_se se;
    2705                 :             : 
    2706                 :       28959 :   if (clauses == NULL)
    2707                 :             :     return NULL_TREE;
    2708                 :             : 
    2709                 :       28947 :   hash_map<gfc_symbol *, gfc_omp_namelist *> *sym_rooted_nl = NULL;
    2710                 :             : 
    2711                 :      984198 :   for (list = 0; list < OMP_LIST_NUM; list++)
    2712                 :             :     {
    2713                 :      955251 :       gfc_omp_namelist *n = clauses->lists[list];
    2714                 :             : 
    2715                 :      955251 :       if (n == NULL)
    2716                 :      929214 :         continue;
    2717                 :       26037 :       switch (list)
    2718                 :             :         {
    2719                 :        3567 :         case OMP_LIST_REDUCTION:
    2720                 :        3567 :         case OMP_LIST_REDUCTION_INSCAN:
    2721                 :        3567 :         case OMP_LIST_REDUCTION_TASK:
    2722                 :        3567 :         case OMP_LIST_IN_REDUCTION:
    2723                 :        3567 :         case OMP_LIST_TASK_REDUCTION:
    2724                 :             :           /* An OpenACC async clause indicates the need to set reduction
    2725                 :             :              arguments addressable, to allow asynchronous copy-out.  */
    2726                 :        3567 :           omp_clauses = gfc_trans_omp_reduction_list (list, n, omp_clauses,
    2727                 :        3567 :                                                       where, clauses->async);
    2728                 :        3567 :           break;
    2729                 :        5701 :         case OMP_LIST_PRIVATE:
    2730                 :        5701 :           clause_code = OMP_CLAUSE_PRIVATE;
    2731                 :        5701 :           goto add_clause;
    2732                 :        1059 :         case OMP_LIST_SHARED:
    2733                 :        1059 :           clause_code = OMP_CLAUSE_SHARED;
    2734                 :        1059 :           goto add_clause;
    2735                 :        1043 :         case OMP_LIST_FIRSTPRIVATE:
    2736                 :        1043 :           clause_code = OMP_CLAUSE_FIRSTPRIVATE;
    2737                 :        1043 :           goto add_clause;
    2738                 :        1619 :         case OMP_LIST_LASTPRIVATE:
    2739                 :        1619 :           clause_code = OMP_CLAUSE_LASTPRIVATE;
    2740                 :        1619 :           goto add_clause;
    2741                 :          96 :         case OMP_LIST_COPYIN:
    2742                 :          96 :           clause_code = OMP_CLAUSE_COPYIN;
    2743                 :          96 :           goto add_clause;
    2744                 :          74 :         case OMP_LIST_COPYPRIVATE:
    2745                 :          74 :           clause_code = OMP_CLAUSE_COPYPRIVATE;
    2746                 :          74 :           goto add_clause;
    2747                 :          66 :         case OMP_LIST_UNIFORM:
    2748                 :          66 :           clause_code = OMP_CLAUSE_UNIFORM;
    2749                 :          66 :           goto add_clause;
    2750                 :          49 :         case OMP_LIST_USE_DEVICE:
    2751                 :          49 :         case OMP_LIST_USE_DEVICE_PTR:
    2752                 :          49 :           clause_code = OMP_CLAUSE_USE_DEVICE_PTR;
    2753                 :          49 :           goto add_clause;
    2754                 :         921 :         case OMP_LIST_USE_DEVICE_ADDR:
    2755                 :         921 :           clause_code = OMP_CLAUSE_USE_DEVICE_ADDR;
    2756                 :         921 :           goto add_clause;
    2757                 :          27 :         case OMP_LIST_IS_DEVICE_PTR:
    2758                 :          27 :           clause_code = OMP_CLAUSE_IS_DEVICE_PTR;
    2759                 :          27 :           goto add_clause;
    2760                 :          99 :         case OMP_LIST_HAS_DEVICE_ADDR:
    2761                 :          99 :           clause_code = OMP_CLAUSE_HAS_DEVICE_ADDR;
    2762                 :          99 :           goto add_clause;
    2763                 :           2 :         case OMP_LIST_NONTEMPORAL:
    2764                 :           2 :           clause_code = OMP_CLAUSE_NONTEMPORAL;
    2765                 :           2 :           goto add_clause;
    2766                 :           9 :         case OMP_LIST_SCAN_IN:
    2767                 :           9 :           clause_code = OMP_CLAUSE_INCLUSIVE;
    2768                 :           9 :           goto add_clause;
    2769                 :           7 :         case OMP_LIST_SCAN_EX:
    2770                 :           7 :           clause_code = OMP_CLAUSE_EXCLUSIVE;
    2771                 :           7 :           goto add_clause;
    2772                 :             : 
    2773                 :       10772 :         add_clause:
    2774                 :       10772 :           omp_clauses
    2775                 :       10772 :             = gfc_trans_omp_variable_list (clause_code, n, omp_clauses,
    2776                 :             :                                            declare_simd);
    2777                 :       10772 :           break;
    2778                 :             :         case OMP_LIST_ALIGNED:
    2779                 :         256 :           for (; n != NULL; n = n->next)
    2780                 :         149 :             if (n->sym->attr.referenced || declare_simd)
    2781                 :             :               {
    2782                 :         149 :                 tree t = gfc_trans_omp_variable (n->sym, declare_simd);
    2783                 :         149 :                 if (t != error_mark_node)
    2784                 :             :                   {
    2785                 :         149 :                     tree node = build_omp_clause (input_location,
    2786                 :             :                                                   OMP_CLAUSE_ALIGNED);
    2787                 :         149 :                     OMP_CLAUSE_DECL (node) = t;
    2788                 :         149 :                     if (n->expr)
    2789                 :             :                       {
    2790                 :         148 :                         tree alignment_var;
    2791                 :             : 
    2792                 :         148 :                         if (declare_simd)
    2793                 :           5 :                           alignment_var = gfc_conv_constant_to_tree (n->expr);
    2794                 :             :                         else
    2795                 :             :                           {
    2796                 :         143 :                             gfc_init_se (&se, NULL);
    2797                 :         143 :                             gfc_conv_expr (&se, n->expr);
    2798                 :         143 :                             gfc_add_block_to_block (block, &se.pre);
    2799                 :         143 :                             alignment_var = gfc_evaluate_now (se.expr, block);
    2800                 :         143 :                             gfc_add_block_to_block (block, &se.post);
    2801                 :             :                           }
    2802                 :         148 :                         OMP_CLAUSE_ALIGNED_ALIGNMENT (node) = alignment_var;
    2803                 :             :                       }
    2804                 :         149 :                     omp_clauses = gfc_trans_add_clause (node, omp_clauses);
    2805                 :             :                   }
    2806                 :             :               }
    2807                 :             :           break;
    2808                 :             :         case OMP_LIST_ALLOCATE:
    2809                 :             :           {
    2810                 :             :             tree allocator_ = NULL_TREE;
    2811                 :             :             gfc_expr *alloc_expr = NULL;
    2812                 :         572 :             for (; n != NULL; n = n->next)
    2813                 :         372 :               if (n->sym->attr.referenced)
    2814                 :             :                 {
    2815                 :         372 :                   tree t = gfc_trans_omp_variable (n->sym, false);
    2816                 :         372 :                   if (t != error_mark_node)
    2817                 :             :                     {
    2818                 :         372 :                       tree node = build_omp_clause (input_location,
    2819                 :             :                                                     OMP_CLAUSE_ALLOCATE);
    2820                 :         372 :                       OMP_CLAUSE_DECL (node) = t;
    2821                 :         372 :                       if (n->u2.allocator)
    2822                 :             :                         {
    2823                 :         237 :                           if (alloc_expr != n->u2.allocator)
    2824                 :             :                             {
    2825                 :         120 :                               gfc_init_se (&se, NULL);
    2826                 :         120 :                               gfc_conv_expr (&se, n->u2.allocator);
    2827                 :         120 :                               gfc_add_block_to_block (block, &se.pre);
    2828                 :         120 :                               allocator_ = gfc_evaluate_now (se.expr, block);
    2829                 :         120 :                               gfc_add_block_to_block (block, &se.post);
    2830                 :             :                             }
    2831                 :         237 :                           OMP_CLAUSE_ALLOCATE_ALLOCATOR (node) = allocator_;
    2832                 :             :                         }
    2833                 :         372 :                       alloc_expr = n->u2.allocator;
    2834                 :         372 :                       if (n->u.align)
    2835                 :             :                         {
    2836                 :           3 :                           tree align_;
    2837                 :           3 :                           gfc_init_se (&se, NULL);
    2838                 :           3 :                           gfc_conv_expr (&se, n->u.align);
    2839                 :           3 :                           gcc_assert (CONSTANT_CLASS_P (se.expr)
    2840                 :             :                                       && se.pre.head == NULL
    2841                 :             :                                       && se.post.head == NULL);
    2842                 :           3 :                           align_ = se.expr;
    2843                 :           3 :                           OMP_CLAUSE_ALLOCATE_ALIGN (node) = align_;
    2844                 :             :                         }
    2845                 :         372 :                       omp_clauses = gfc_trans_add_clause (node, omp_clauses);
    2846                 :             :                     }
    2847                 :             :                 }
    2848                 :             :               else
    2849                 :           0 :                 alloc_expr = n->u2.allocator;
    2850                 :             :             }
    2851                 :             :           break;
    2852                 :             :         case OMP_LIST_LINEAR:
    2853                 :             :           {
    2854                 :             :             gfc_expr *last_step_expr = NULL;
    2855                 :             :             tree last_step = NULL_TREE;
    2856                 :             :             bool last_step_parm = false;
    2857                 :             : 
    2858                 :        1298 :             for (; n != NULL; n = n->next)
    2859                 :             :               {
    2860                 :         800 :                 if (n->expr)
    2861                 :             :                   {
    2862                 :         781 :                     last_step_expr = n->expr;
    2863                 :         781 :                     last_step = NULL_TREE;
    2864                 :         781 :                     last_step_parm = false;
    2865                 :             :                   }
    2866                 :         800 :                 if (n->sym->attr.referenced || declare_simd)
    2867                 :             :                   {
    2868                 :         800 :                     tree t = gfc_trans_omp_variable (n->sym, declare_simd);
    2869                 :         800 :                     if (t != error_mark_node)
    2870                 :             :                       {
    2871                 :         800 :                         tree node = build_omp_clause (input_location,
    2872                 :             :                                                       OMP_CLAUSE_LINEAR);
    2873                 :         800 :                         OMP_CLAUSE_DECL (node) = t;
    2874                 :         800 :                         omp_clause_linear_kind kind;
    2875                 :         800 :                         switch (n->u.linear.op)
    2876                 :             :                           {
    2877                 :             :                           case OMP_LINEAR_DEFAULT:
    2878                 :             :                             kind = OMP_CLAUSE_LINEAR_DEFAULT;
    2879                 :             :                             break;
    2880                 :             :                           case OMP_LINEAR_REF:
    2881                 :             :                             kind = OMP_CLAUSE_LINEAR_REF;
    2882                 :             :                             break;
    2883                 :             :                           case OMP_LINEAR_VAL:
    2884                 :             :                             kind = OMP_CLAUSE_LINEAR_VAL;
    2885                 :             :                             break;
    2886                 :             :                           case OMP_LINEAR_UVAL:
    2887                 :             :                             kind = OMP_CLAUSE_LINEAR_UVAL;
    2888                 :             :                             break;
    2889                 :           0 :                           default:
    2890                 :           0 :                             gcc_unreachable ();
    2891                 :             :                           }
    2892                 :         800 :                         OMP_CLAUSE_LINEAR_KIND (node) = kind;
    2893                 :         800 :                         OMP_CLAUSE_LINEAR_OLD_LINEAR_MODIFIER (node)
    2894                 :         800 :                           = n->u.linear.old_modifier;
    2895                 :         800 :                         if (last_step_expr && last_step == NULL_TREE)
    2896                 :             :                           {
    2897                 :         781 :                             if (!declare_simd)
    2898                 :             :                               {
    2899                 :         695 :                                 gfc_init_se (&se, NULL);
    2900                 :         695 :                                 gfc_conv_expr (&se, last_step_expr);
    2901                 :         695 :                                 gfc_add_block_to_block (block, &se.pre);
    2902                 :         695 :                                 last_step = gfc_evaluate_now (se.expr, block);
    2903                 :         695 :                                 gfc_add_block_to_block (block, &se.post);
    2904                 :             :                               }
    2905                 :          86 :                             else if (last_step_expr->expr_type == EXPR_VARIABLE)
    2906                 :             :                               {
    2907                 :           2 :                                 gfc_symbol *s = last_step_expr->symtree->n.sym;
    2908                 :           2 :                                 last_step = gfc_trans_omp_variable (s, true);
    2909                 :           2 :                                 last_step_parm = true;
    2910                 :             :                               }
    2911                 :             :                             else
    2912                 :          84 :                               last_step
    2913                 :          84 :                                 = gfc_conv_constant_to_tree (last_step_expr);
    2914                 :             :                           }
    2915                 :         800 :                         if (last_step_parm)
    2916                 :             :                           {
    2917                 :           2 :                             OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (node) = 1;
    2918                 :           2 :                             OMP_CLAUSE_LINEAR_STEP (node) = last_step;
    2919                 :             :                           }
    2920                 :             :                         else
    2921                 :             :                           {
    2922                 :         798 :                             if (kind == OMP_CLAUSE_LINEAR_REF)
    2923                 :             :                               {
    2924                 :          34 :                                 tree type;
    2925                 :          34 :                                 if (n->sym->attr.flavor == FL_PROCEDURE)
    2926                 :             :                                   {
    2927                 :           0 :                                     type = gfc_get_function_type (n->sym);
    2928                 :           0 :                                     type = build_pointer_type (type);
    2929                 :             :                                   }
    2930                 :             :                                 else
    2931                 :          34 :                                   type = gfc_sym_type (n->sym);
    2932                 :          34 :                                 if (POINTER_TYPE_P (type))
    2933                 :          34 :                                   type = TREE_TYPE (type);
    2934                 :             :                                 /* Otherwise to be determined what exactly
    2935                 :             :                                    should be done.  */
    2936                 :          34 :                                 tree t = fold_convert (sizetype, last_step);
    2937                 :          34 :                                 t = size_binop (MULT_EXPR, t,
    2938                 :             :                                                 TYPE_SIZE_UNIT (type));
    2939                 :          34 :                                 OMP_CLAUSE_LINEAR_STEP (node) = t;
    2940                 :             :                               }
    2941                 :             :                             else
    2942                 :             :                               {
    2943                 :         764 :                                 tree type
    2944                 :         764 :                                   = gfc_typenode_for_spec (&n->sym->ts);
    2945                 :         764 :                                 OMP_CLAUSE_LINEAR_STEP (node)
    2946                 :        1528 :                                   = fold_convert (type, last_step);
    2947                 :             :                               }
    2948                 :             :                           }
    2949                 :         800 :                         if (n->sym->attr.dimension || n->sym->attr.allocatable)
    2950                 :         222 :                           OMP_CLAUSE_LINEAR_ARRAY (node) = 1;
    2951                 :         800 :                         omp_clauses = gfc_trans_add_clause (node, omp_clauses);
    2952                 :             :                       }
    2953                 :             :                   }
    2954                 :             :               }
    2955                 :             :           }
    2956                 :             :           break;
    2957                 :             :         case OMP_LIST_AFFINITY:
    2958                 :             :         case OMP_LIST_DEPEND:
    2959                 :             :           iterator = NULL_TREE;
    2960                 :             :           prev = NULL;
    2961                 :             :           prev_clauses = omp_clauses;
    2962                 :        1554 :           for (; n != NULL; n = n->next)
    2963                 :             :             {
    2964                 :         841 :               if (iterator && prev->u2.ns != n->u2.ns)
    2965                 :             :                 { 
    2966                 :          12 :                   BLOCK_SUBBLOCKS (tree_block) = gfc_finish_block (&iter_block);
    2967                 :          12 :                   TREE_VEC_ELT (iterator, 5) = tree_block;
    2968                 :          26 :                   for (tree c = omp_clauses; c != prev_clauses;
    2969                 :          14 :                        c = OMP_CLAUSE_CHAIN (c))
    2970                 :          28 :                     OMP_CLAUSE_DECL (c) = build_tree_list (iterator,
    2971                 :          14 :                                                            OMP_CLAUSE_DECL (c));
    2972                 :             :                   prev_clauses = omp_clauses;
    2973                 :             :                   iterator = NULL_TREE;
    2974                 :             :                 }
    2975                 :         841 :               if (n->u2.ns && (!prev || prev->u2.ns != n->u2.ns))
    2976                 :             :                 {
    2977                 :          43 :                   gfc_init_block (&iter_block);
    2978                 :          43 :                   tree_block = make_node (BLOCK);
    2979                 :          43 :                   TREE_USED (tree_block) = 1;
    2980                 :          43 :                   BLOCK_VARS (tree_block) = NULL_TREE;
    2981                 :          43 :                   iterator = handle_iterator (n->u2.ns, block,
    2982                 :             :                                               tree_block);
    2983                 :             :                 }
    2984                 :         841 :               if (!iterator)
    2985                 :         789 :                 gfc_init_block (&iter_block);
    2986                 :         841 :               prev = n;
    2987                 :         841 :               if (list == OMP_LIST_DEPEND
    2988                 :         815 :                   && (n->u.depend_doacross_op == OMP_DOACROSS_SINK_FIRST
    2989                 :         815 :                       || n->u.depend_doacross_op == OMP_DEPEND_SINK_FIRST))
    2990                 :             :                 {
    2991                 :         227 :                   tree vec = NULL_TREE;
    2992                 :         227 :                   unsigned int i;
    2993                 :         227 :                   bool is_depend
    2994                 :             :                     = n->u.depend_doacross_op == OMP_DEPEND_SINK_FIRST;
    2995                 :         227 :                   for (i = 0; ; i++)
    2996                 :             :                     {
    2997                 :        1218 :                       tree addend = integer_zero_node, t;
    2998                 :        1218 :                       bool neg = false;
    2999                 :        1218 :                       if (n->sym && n->expr)
    3000                 :             :                         {
    3001                 :         558 :                           addend = gfc_conv_constant_to_tree (n->expr);
    3002                 :         558 :                           if (TREE_CODE (addend) == INTEGER_CST
    3003                 :         558 :                               && tree_int_cst_sgn (addend) == -1)
    3004                 :             :                             {
    3005                 :         407 :                               neg = true;
    3006                 :         407 :                               addend = const_unop (NEGATE_EXPR,
    3007                 :         407 :                                                    TREE_TYPE (addend), addend);
    3008                 :             :                             }
    3009                 :             :                         }
    3010                 :             : 
    3011                 :        1218 :                       if (n->sym == NULL)
    3012                 :           0 :                         t = null_pointer_node;  /* "omp_cur_iteration - 1".  */
    3013                 :             :                       else
    3014                 :        1218 :                         t = gfc_trans_omp_variable (n->sym, false);
    3015                 :        1218 :                       if (t != error_mark_node)
    3016                 :             :                         {
    3017                 :        1218 :                           if (i < vec_safe_length (doacross_steps)
    3018                 :         426 :                               && !integer_zerop (addend)
    3019                 :         630 :                               && (*doacross_steps)[i])
    3020                 :             :                             {
    3021                 :         204 :                               tree step = (*doacross_steps)[i];
    3022                 :         204 :                               addend = fold_convert (TREE_TYPE (step), addend);
    3023                 :         204 :                               addend = build2 (TRUNC_DIV_EXPR,
    3024                 :         204 :                                                TREE_TYPE (step), addend, step);
    3025                 :             :                             }
    3026                 :        1218 :                           vec = tree_cons (addend, t, vec);
    3027                 :        1218 :                           if (neg)
    3028                 :         407 :                             OMP_CLAUSE_DOACROSS_SINK_NEGATIVE (vec) = 1;
    3029                 :             :                         }
    3030                 :        1218 :                       if (n->next == NULL
    3031                 :        1057 :                           || n->next->u.depend_doacross_op != OMP_DOACROSS_SINK)
    3032                 :             :                         break;
    3033                 :         991 :                       n = n->next;
    3034                 :         991 :                     }
    3035                 :         227 :                   if (vec == NULL_TREE)
    3036                 :           0 :                     continue;
    3037                 :             : 
    3038                 :         227 :                   tree node = build_omp_clause (input_location,
    3039                 :             :                                                 OMP_CLAUSE_DOACROSS);
    3040                 :         227 :                   OMP_CLAUSE_DOACROSS_KIND (node) = OMP_CLAUSE_DOACROSS_SINK;
    3041                 :         227 :                   OMP_CLAUSE_DOACROSS_DEPEND (node) = is_depend;
    3042                 :         227 :                   OMP_CLAUSE_DECL (node) = nreverse (vec);
    3043                 :         227 :                   omp_clauses = gfc_trans_add_clause (node, omp_clauses);
    3044                 :         227 :                   continue;
    3045                 :         227 :                 }
    3046                 :             : 
    3047                 :         614 :               if (n->sym && !n->sym->attr.referenced)
    3048                 :           0 :                 continue;
    3049                 :             : 
    3050                 :         640 :               tree node = build_omp_clause (input_location,
    3051                 :             :                                             list == OMP_LIST_DEPEND
    3052                 :             :                                             ? OMP_CLAUSE_DEPEND
    3053                 :             :                                             : OMP_CLAUSE_AFFINITY);
    3054                 :         614 :               if (n->sym == NULL)  /* omp_all_memory  */
    3055                 :           9 :                 OMP_CLAUSE_DECL (node) = null_pointer_node;
    3056                 :         605 :               else if (n->expr == NULL || n->expr->ref->u.ar.type == AR_FULL)
    3057                 :             :                 {
    3058                 :         396 :                   tree decl = gfc_trans_omp_variable (n->sym, false);
    3059                 :         396 :                   if (gfc_omp_privatize_by_reference (decl))
    3060                 :          60 :                     decl = build_fold_indirect_ref (decl);
    3061                 :         396 :                   if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl)))
    3062                 :             :                     {
    3063                 :          23 :                       decl = gfc_conv_descriptor_data_get (decl);
    3064                 :          23 :                       gcc_assert (POINTER_TYPE_P (TREE_TYPE (decl)));
    3065                 :          23 :                       decl = build_fold_indirect_ref (decl);
    3066                 :             :                     }
    3067                 :         373 :                   else if (n->sym->attr.allocatable || n->sym->attr.pointer)
    3068                 :          22 :                     decl = build_fold_indirect_ref (decl);
    3069                 :         351 :                   else if (DECL_P (decl))
    3070                 :         320 :                     TREE_ADDRESSABLE (decl) = 1;
    3071                 :         396 :                   OMP_CLAUSE_DECL (node) = decl;
    3072                 :         396 :                 }
    3073                 :             :               else
    3074                 :             :                 {
    3075                 :         209 :                   tree ptr;
    3076                 :         209 :                   gfc_init_se (&se, NULL);
    3077                 :         209 :                   if (n->expr->ref->u.ar.type == AR_ELEMENT)
    3078                 :             :                     {
    3079                 :         130 :                       gfc_conv_expr_reference (&se, n->expr);
    3080                 :         130 :                       ptr = se.expr;
    3081                 :             :                     }
    3082                 :             :                   else
    3083                 :             :                     {
    3084                 :          79 :                       gfc_conv_expr_descriptor (&se, n->expr);
    3085                 :          79 :                       ptr = gfc_conv_array_data (se.expr);
    3086                 :             :                     }
    3087                 :         209 :                   gfc_add_block_to_block (&iter_block, &se.pre);
    3088                 :         209 :                   gfc_add_block_to_block (&iter_block, &se.post);
    3089                 :         209 :                   gcc_assert (POINTER_TYPE_P (TREE_TYPE (ptr)));
    3090                 :         209 :                   OMP_CLAUSE_DECL (node) = build_fold_indirect_ref (ptr);
    3091                 :             :                 }
    3092                 :         614 :               if (list == OMP_LIST_DEPEND)
    3093                 :         588 :                 switch (n->u.depend_doacross_op)
    3094                 :             :                   {
    3095                 :         224 :                   case OMP_DEPEND_IN:
    3096                 :         224 :                     OMP_CLAUSE_DEPEND_KIND (node) = OMP_CLAUSE_DEPEND_IN;
    3097                 :         224 :                     break;
    3098                 :         256 :                   case OMP_DEPEND_OUT:
    3099                 :         256 :                     OMP_CLAUSE_DEPEND_KIND (node) = OMP_CLAUSE_DEPEND_OUT;
    3100                 :         256 :                     break;
    3101                 :          49 :                   case OMP_DEPEND_INOUT:
    3102                 :          49 :                     OMP_CLAUSE_DEPEND_KIND (node) = OMP_CLAUSE_DEPEND_INOUT;
    3103                 :          49 :                     break;
    3104                 :           9 :                   case OMP_DEPEND_INOUTSET:
    3105                 :           9 :                     OMP_CLAUSE_DEPEND_KIND (node) = OMP_CLAUSE_DEPEND_INOUTSET;
    3106                 :           9 :                     break;
    3107                 :          15 :                   case OMP_DEPEND_MUTEXINOUTSET:
    3108                 :          15 :                     OMP_CLAUSE_DEPEND_KIND (node)
    3109                 :          15 :                       = OMP_CLAUSE_DEPEND_MUTEXINOUTSET;
    3110                 :          15 :                     break;
    3111                 :          35 :                   case OMP_DEPEND_DEPOBJ:
    3112                 :          35 :                     OMP_CLAUSE_DEPEND_KIND (node) = OMP_CLAUSE_DEPEND_DEPOBJ;
    3113                 :          35 :                     break;
    3114                 :           0 :                   default:
    3115                 :           0 :                     gcc_unreachable ();
    3116                 :             :                   }
    3117                 :         614 :               if (!iterator)
    3118                 :         562 :                 gfc_add_block_to_block (block, &iter_block);
    3119                 :         614 :               omp_clauses = gfc_trans_add_clause (node, omp_clauses);
    3120                 :             :             }
    3121                 :         713 :           if (iterator)
    3122                 :             :             { 
    3123                 :          31 :               BLOCK_SUBBLOCKS (tree_block) = gfc_finish_block (&iter_block);
    3124                 :          31 :               TREE_VEC_ELT (iterator, 5) = tree_block;
    3125                 :          70 :               for (tree c = omp_clauses; c != prev_clauses;
    3126                 :          39 :                    c = OMP_CLAUSE_CHAIN (c))
    3127                 :          78 :                 OMP_CLAUSE_DECL (c) = build_tree_list (iterator,
    3128                 :          39 :                                                        OMP_CLAUSE_DECL (c));
    3129                 :             :             }
    3130                 :             :           break;
    3131                 :             :         case OMP_LIST_MAP:
    3132                 :       22752 :           for (; n != NULL; n = n->next)
    3133                 :             :             {
    3134                 :       14360 :               if (!n->sym->attr.referenced)
    3135                 :         280 :                 continue;
    3136                 :             : 
    3137                 :       14360 :               bool always_modifier = false;
    3138                 :       14360 :               tree node = build_omp_clause (input_location, OMP_CLAUSE_MAP);
    3139                 :       14360 :               tree node2 = NULL_TREE;
    3140                 :       14360 :               tree node3 = NULL_TREE;
    3141                 :       14360 :               tree node4 = NULL_TREE;
    3142                 :       14360 :               tree node5 = NULL_TREE;
    3143                 :             : 
    3144                 :             :               /* OpenMP: automatically map pointer targets with the pointer;
    3145                 :             :                  hence, always update the descriptor/pointer itself.  */
    3146                 :       14360 :               if (!openacc
    3147                 :       14360 :                   && ((n->expr == NULL && n->sym->attr.pointer)
    3148                 :       13590 :                       || (n->expr && gfc_expr_attr (n->expr).pointer)))
    3149                 :        1333 :                 always_modifier = true;
    3150                 :             : 
    3151                 :       14360 :               if (n->u.map.readonly)
    3152                 :          22 :                 OMP_CLAUSE_MAP_READONLY (node) = 1;
    3153                 :             : 
    3154                 :       14360 :               switch (n->u.map.op)
    3155                 :             :                 {
    3156                 :         995 :                 case OMP_MAP_ALLOC:
    3157                 :         995 :                   OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_ALLOC);
    3158                 :         995 :                   break;
    3159                 :          63 :                 case OMP_MAP_IF_PRESENT:
    3160                 :          63 :                   OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_IF_PRESENT);
    3161                 :          63 :                   break;
    3162                 :          62 :                 case OMP_MAP_ATTACH:
    3163                 :          62 :                   OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_ATTACH);
    3164                 :          62 :                   break;
    3165                 :        3898 :                 case OMP_MAP_TO:
    3166                 :        3898 :                   OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_TO);
    3167                 :        3898 :                   break;
    3168                 :        2729 :                 case OMP_MAP_FROM:
    3169                 :        2729 :                   OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_FROM);
    3170                 :        2729 :                   break;
    3171                 :        4257 :                 case OMP_MAP_TOFROM:
    3172                 :        4257 :                   OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_TOFROM);
    3173                 :        4257 :                   break;
    3174                 :          32 :                 case OMP_MAP_ALWAYS_TO:
    3175                 :          32 :                   always_modifier = true;
    3176                 :          32 :                   OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_ALWAYS_TO);
    3177                 :          32 :                   break;
    3178                 :          14 :                 case OMP_MAP_ALWAYS_FROM:
    3179                 :          14 :                   always_modifier = true;
    3180                 :          14 :                   OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_ALWAYS_FROM);
    3181                 :          14 :                   break;
    3182                 :         145 :                 case OMP_MAP_ALWAYS_TOFROM:
    3183                 :         145 :                   always_modifier = true;
    3184                 :         145 :                   OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_ALWAYS_TOFROM);
    3185                 :         145 :                   break;
    3186                 :           6 :                 case OMP_MAP_PRESENT_ALLOC:
    3187                 :           6 :                   OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_PRESENT_ALLOC);
    3188                 :           6 :                   break;
    3189                 :          13 :                 case OMP_MAP_PRESENT_TO:
    3190                 :          13 :                   OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_PRESENT_TO);
    3191                 :          13 :                   break;
    3192                 :           4 :                 case OMP_MAP_PRESENT_FROM:
    3193                 :           4 :                   OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_PRESENT_FROM);
    3194                 :           4 :                   break;
    3195                 :           2 :                 case OMP_MAP_PRESENT_TOFROM:
    3196                 :           2 :                   OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_PRESENT_TOFROM);
    3197                 :           2 :                   break;
    3198                 :           8 :                 case OMP_MAP_ALWAYS_PRESENT_TO:
    3199                 :           8 :                   always_modifier = true;
    3200                 :           8 :                   OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_ALWAYS_PRESENT_TO);
    3201                 :           8 :                   break;
    3202                 :           4 :                 case OMP_MAP_ALWAYS_PRESENT_FROM:
    3203                 :           4 :                   always_modifier = true;
    3204                 :           4 :                   OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_ALWAYS_PRESENT_FROM);
    3205                 :           4 :                   break;
    3206                 :           2 :                 case OMP_MAP_ALWAYS_PRESENT_TOFROM:
    3207                 :           2 :                   always_modifier = true;
    3208                 :           2 :                   OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_ALWAYS_PRESENT_TOFROM);
    3209                 :           2 :                   break;
    3210                 :         382 :                 case OMP_MAP_RELEASE:
    3211                 :         382 :                   OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_RELEASE);
    3212                 :         382 :                   break;
    3213                 :          55 :                 case OMP_MAP_DELETE:
    3214                 :          55 :                   OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_DELETE);
    3215                 :          55 :                   break;
    3216                 :          40 :                 case OMP_MAP_DETACH:
    3217                 :          40 :                   OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_DETACH);
    3218                 :          40 :                   break;
    3219                 :          62 :                 case OMP_MAP_FORCE_ALLOC:
    3220                 :          62 :                   OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_FORCE_ALLOC);
    3221                 :          62 :                   break;
    3222                 :         465 :                 case OMP_MAP_FORCE_TO:
    3223                 :         465 :                   OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_FORCE_TO);
    3224                 :         465 :                   break;
    3225                 :         577 :                 case OMP_MAP_FORCE_FROM:
    3226                 :         577 :                   OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_FORCE_FROM);
    3227                 :         577 :                   break;
    3228                 :           0 :                 case OMP_MAP_FORCE_TOFROM:
    3229                 :           0 :                   OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_FORCE_TOFROM);
    3230                 :           0 :                   break;
    3231                 :         542 :                 case OMP_MAP_FORCE_PRESENT:
    3232                 :         542 :                   OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_FORCE_PRESENT);
    3233                 :         542 :                   break;
    3234                 :           3 :                 case OMP_MAP_FORCE_DEVICEPTR:
    3235                 :           3 :                   OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_FORCE_DEVICEPTR);
    3236                 :           3 :                   break;
    3237                 :           0 :                 default:
    3238                 :           0 :                   gcc_unreachable ();
    3239                 :             :                 }
    3240                 :             : 
    3241                 :       14360 :               tree decl = gfc_trans_omp_variable (n->sym, false);
    3242                 :       14360 :               if (DECL_P (decl))
    3243                 :       14360 :                 TREE_ADDRESSABLE (decl) = 1;
    3244                 :             : 
    3245                 :       14360 :               gfc_ref *lastref = NULL;
    3246                 :             : 
    3247                 :       14360 :               if (n->expr)
    3248                 :       12525 :                 for (gfc_ref *ref = n->expr->ref; ref; ref = ref->next)
    3249                 :        7324 :                   if (ref->type == REF_COMPONENT || ref->type == REF_ARRAY)
    3250                 :        7324 :                     lastref = ref;
    3251                 :             : 
    3252                 :        5201 :               bool allocatable = false, pointer = false;
    3253                 :             : 
    3254                 :        5201 :               if (lastref && lastref->type == REF_COMPONENT)
    3255                 :             :                 {
    3256                 :         413 :                   gfc_component *c = lastref->u.c.component;
    3257                 :             : 
    3258                 :         413 :                   if (c->ts.type == BT_CLASS)
    3259                 :             :                     {
    3260                 :          24 :                       pointer = CLASS_DATA (c)->attr.class_pointer;
    3261                 :          24 :                       allocatable = CLASS_DATA (c)->attr.allocatable;
    3262                 :             :                     }
    3263                 :             :                   else
    3264                 :             :                     {
    3265                 :         389 :                       pointer = c->attr.pointer;
    3266                 :         389 :                       allocatable = c->attr.allocatable;
    3267                 :             :                     }
    3268                 :             :                 }
    3269                 :             : 
    3270                 :       14360 :               if (n->expr == NULL
    3271                 :        5201 :                   || (n->expr->ref->type == REF_ARRAY
    3272                 :        3525 :                       && n->expr->ref->u.ar.type == AR_FULL))
    3273                 :             :                 {
    3274                 :        9159 :                   gomp_map_kind map_kind;
    3275                 :        9159 :                   tree type = TREE_TYPE (decl);
    3276                 :        9159 :                   if (n->sym->ts.type == BT_CHARACTER
    3277                 :         182 :                       && n->sym->ts.deferred
    3278                 :          68 :                       && n->sym->attr.omp_declare_target
    3279                 :           8 :                       && (always_modifier || n->sym->attr.pointer)
    3280                 :           8 :                       && op != EXEC_OMP_TARGET_EXIT_DATA
    3281                 :           4 :                       && n->u.map.op != OMP_MAP_DELETE
    3282                 :           4 :                       && n->u.map.op != OMP_MAP_RELEASE)
    3283                 :             :                     {
    3284                 :           4 :                       gcc_assert (n->sym->ts.u.cl->backend_decl);
    3285                 :           4 :                       node5 = build_omp_clause (input_location, OMP_CLAUSE_MAP);
    3286                 :           4 :                       OMP_CLAUSE_SET_MAP_KIND (node5, GOMP_MAP_ALWAYS_TO);
    3287                 :           4 :                       OMP_CLAUSE_DECL (node5) = n->sym->ts.u.cl->backend_decl;
    3288                 :           4 :                       OMP_CLAUSE_SIZE (node5)
    3289                 :           8 :                         = TYPE_SIZE_UNIT (gfc_charlen_type_node);
    3290                 :             :                     }
    3291                 :             : 
    3292                 :        9159 :                   tree present = gfc_omp_check_optional_argument (decl, true);
    3293                 :        9159 :                   if (openacc && n->sym->ts.type == BT_CLASS)
    3294                 :             :                     {
    3295                 :          60 :                       if (n->sym->attr.optional)
    3296                 :           0 :                         sorry ("optional class parameter");
    3297                 :          60 :                       tree ptr = gfc_class_data_get (decl);
    3298                 :          60 :                       ptr = build_fold_indirect_ref (ptr);
    3299                 :          60 :                       OMP_CLAUSE_DECL (node) = ptr;
    3300                 :          60 :                       OMP_CLAUSE_SIZE (node) = gfc_class_vtab_size_get (decl);
    3301                 :          60 :                       node2 = build_omp_clause (input_location, OMP_CLAUSE_MAP);
    3302                 :          60 :                       OMP_CLAUSE_SET_MAP_KIND (node2, GOMP_MAP_ATTACH_DETACH);
    3303                 :          60 :                       OMP_CLAUSE_DECL (node2) = gfc_class_data_get (decl);
    3304                 :          60 :                       OMP_CLAUSE_SIZE (node2) = size_int (0);
    3305                 :          60 :                       goto finalize_map_clause;
    3306                 :             :                     }
    3307                 :        9099 :                   else if (POINTER_TYPE_P (type)
    3308                 :        9099 :                            && (gfc_omp_privatize_by_reference (decl)
    3309                 :         419 :                                || GFC_DECL_GET_SCALAR_POINTER (decl)
    3310                 :         257 :                                || GFC_DECL_GET_SCALAR_ALLOCATABLE (decl)
    3311                 :          78 :                                || GFC_DECL_CRAY_POINTEE (decl)
    3312                 :          78 :                                || GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (type))
    3313                 :          78 :                                || (n->sym->ts.type == BT_DERIVED
    3314                 :           8 :                                    && (n->sym->ts.u.derived->ts.f90_type
    3315                 :             :                                        != BT_VOID))))
    3316                 :             :                     {
    3317                 :        3254 :                       tree orig_decl = decl;
    3318                 :             : 
    3319                 :             :                       /* For nonallocatable, nonpointer arrays, a temporary
    3320                 :             :                          variable is generated, but this one is only defined if
    3321                 :             :                          the variable is present; hence, we now set it to NULL
    3322                 :             :                          to avoid accessing undefined variables.  We cannot use
    3323                 :             :                          a temporary variable here as otherwise the replacement
    3324                 :             :                          of the variables in omp-low.cc will not work.  */
    3325                 :        3254 :                       if (present && GFC_ARRAY_TYPE_P (type))
    3326                 :             :                         {
    3327                 :         283 :                           tree tmp = fold_build2_loc (input_location,
    3328                 :             :                                                       MODIFY_EXPR,
    3329                 :             :                                                       void_type_node, decl,
    3330                 :             :                                                       null_pointer_node);
    3331                 :         283 :                           tree cond = fold_build1_loc (input_location,
    3332                 :             :                                                        TRUTH_NOT_EXPR,
    3333                 :             :                                                        boolean_type_node,
    3334                 :             :                                                        present);
    3335                 :         283 :                           gfc_add_expr_to_block (block,
    3336                 :             :                                                  build3_loc (input_location,
    3337                 :             :                                                              COND_EXPR,
    3338                 :             :                                                              void_type_node,
    3339                 :             :                                                              cond, tmp,
    3340                 :             :                                                              NULL_TREE));
    3341                 :             :                         }
    3342                 :             :                       /* For descriptor types, the unmapping happens below.  */
    3343                 :        3254 :                       if (op != EXEC_OMP_TARGET_EXIT_DATA
    3344                 :        3254 :                           || !GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl)))
    3345                 :             :                         {
    3346                 :        3254 :                           enum gomp_map_kind gmk = GOMP_MAP_POINTER;
    3347                 :        3254 :                           if (op == EXEC_OMP_TARGET_EXIT_DATA
    3348                 :          32 :                               && n->u.map.op == OMP_MAP_DELETE)
    3349                 :             :                             gmk = GOMP_MAP_DELETE;
    3350                 :          27 :                           else if (op == EXEC_OMP_TARGET_EXIT_DATA)
    3351                 :          27 :                             gmk = GOMP_MAP_RELEASE;
    3352                 :        3254 :                           tree size;
    3353                 :        3254 :                           if (gmk == GOMP_MAP_RELEASE || gmk == GOMP_MAP_DELETE)
    3354                 :          32 :                             size = TYPE_SIZE_UNIT (TREE_TYPE (decl));
    3355                 :             :                           else
    3356                 :        3222 :                             size = size_int (0);
    3357                 :        3254 :                           node4 = build_omp_clause (input_location,
    3358                 :             :                                                     OMP_CLAUSE_MAP);
    3359                 :        3254 :                           OMP_CLAUSE_SET_MAP_KIND (node4, gmk);
    3360                 :        3254 :                           OMP_CLAUSE_DECL (node4) = decl;
    3361                 :        3254 :                           OMP_CLAUSE_SIZE (node4) = size;
    3362                 :             :                         }
    3363                 :        3254 :                       decl = build_fold_indirect_ref (decl);
    3364                 :        3254 :                       if ((TREE_CODE (TREE_TYPE (orig_decl)) == REFERENCE_TYPE
    3365                 :        2033 :                            || gfc_omp_is_optional_argument (orig_decl))
    3366                 :        4302 :                           && (GFC_DECL_GET_SCALAR_POINTER (orig_decl)
    3367                 :        2099 :                               || GFC_DECL_GET_SCALAR_ALLOCATABLE (orig_decl)))
    3368                 :             :                         {
    3369                 :         406 :                           enum gomp_map_kind gmk;
    3370                 :         406 :                           if (op == EXEC_OMP_TARGET_EXIT_DATA
    3371                 :           8 :                               && n->u.map.op == OMP_MAP_DELETE)
    3372                 :             :                             gmk = GOMP_MAP_DELETE;
    3373                 :           6 :                           else if (op == EXEC_OMP_TARGET_EXIT_DATA)
    3374                 :             :                             gmk = GOMP_MAP_RELEASE;
    3375                 :             :                           else
    3376                 :             :                             gmk = GOMP_MAP_POINTER;
    3377                 :         406 :                           tree size;
    3378                 :         406 :                           if (gmk == GOMP_MAP_RELEASE || gmk == GOMP_MAP_DELETE)
    3379                 :           8 :                             size = TYPE_SIZE_UNIT (TREE_TYPE (decl));
    3380                 :             :                           else
    3381                 :         398 :                             size = size_int (0);
    3382                 :         406 :                           node3 = build_omp_clause (input_location,
    3383                 :             :                                                     OMP_CLAUSE_MAP);
    3384                 :         406 :                           OMP_CLAUSE_SET_MAP_KIND (node3, gmk);
    3385                 :         406 :                           OMP_CLAUSE_DECL (node3) = decl;
    3386                 :         406 :                           OMP_CLAUSE_SIZE (node3) = size;
    3387                 :         406 :                           decl = build_fold_indirect_ref (decl);
    3388                 :             :                         }
    3389                 :             :                     }
    3390                 :        9099 :                   if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl)))
    3391                 :             :                     {
    3392                 :        1359 :                       tree type = TREE_TYPE (decl);
    3393                 :        1359 :                       tree ptr = gfc_conv_descriptor_data_get (decl);
    3394                 :        1359 :                       if (present)
    3395                 :         308 :                         ptr = gfc_build_cond_assign_expr (block, present, ptr,
    3396                 :             :                                                           null_pointer_node);
    3397                 :        1359 :                       gcc_assert (POINTER_TYPE_P (TREE_TYPE (ptr)));
    3398                 :        1359 :                       ptr = build_fold_indirect_ref (ptr);
    3399                 :        1359 :                       OMP_CLAUSE_DECL (node) = ptr;
    3400                 :        1359 :                       node2 = build_omp_clause (input_location, OMP_CLAUSE_MAP);
    3401                 :        1359 :                       OMP_CLAUSE_DECL (node2) = decl;
    3402                 :        1359 :                       OMP_CLAUSE_SIZE (node2) = TYPE_SIZE_UNIT (type);
    3403                 :        1359 :                       if (n->u.map.op == OMP_MAP_DELETE)
    3404                 :             :                         map_kind = GOMP_MAP_DELETE;
    3405                 :        1332 :                       else if (op == EXEC_OMP_TARGET_EXIT_DATA
    3406                 :        1277 :                                || n->u.map.op == OMP_MAP_RELEASE)
    3407                 :             :                         map_kind = GOMP_MAP_RELEASE;
    3408                 :             :                       else
    3409                 :        1359 :                         map_kind = GOMP_MAP_TO_PSET;
    3410                 :        1359 :                       OMP_CLAUSE_SET_MAP_KIND (node2, map_kind);
    3411                 :             : 
    3412                 :        1359 :                       if (op != EXEC_OMP_TARGET_EXIT_DATA
    3413                 :        1277 :                           && n->u.map.op != OMP_MAP_DELETE
    3414                 :        1277 :                           && n->u.map.op != OMP_MAP_RELEASE)
    3415                 :             :                         {
    3416                 :        1235 :                           node3 = build_omp_clause (input_location,
    3417                 :             :                                                     OMP_CLAUSE_MAP);
    3418                 :        1235 :                           if (present)
    3419                 :             :                             {
    3420                 :         308 :                               ptr = gfc_conv_descriptor_data_get (decl);
    3421                 :         308 :                               ptr = gfc_build_addr_expr (NULL, ptr);
    3422                 :         308 :                               ptr = gfc_build_cond_assign_expr (
    3423                 :             :                                       block, present, ptr, null_pointer_node);
    3424                 :         308 :                               ptr = build_fold_indirect_ref (ptr);
    3425                 :         308 :                               OMP_CLAUSE_DECL (node3) = ptr;
    3426                 :             :                             }
    3427                 :             :                           else
    3428                 :         927 :                             OMP_CLAUSE_DECL (node3)
    3429                 :        1854 :                               = gfc_conv_descriptor_data_get (decl);
    3430                 :        1235 :                           OMP_CLAUSE_SIZE (node3) = size_int (0);
    3431                 :             : 
    3432                 :        1235 :                           if (n->u.map.op == OMP_MAP_ATTACH)
    3433                 :             :                             {
    3434                 :             :                               /* Standalone attach clauses used with arrays with
    3435                 :             :                                  descriptors must copy the descriptor to the
    3436                 :             :                                  target, else they won't have anything to
    3437                 :             :                                  perform the attachment onto (see OpenACC 2.6,
    3438                 :             :                                  "2.6.3. Data Structures with Pointers").  */
    3439                 :           7 :                               OMP_CLAUSE_SET_MAP_KIND (node3, GOMP_MAP_ATTACH);
    3440                 :             :                               /* We don't want to map PTR at all in this case,
    3441                 :             :                                  so delete its node and shuffle the others
    3442                 :             :                                  down.  */
    3443                 :           7 :                               node = node2;
    3444                 :           7 :                               node2 = node3;
    3445                 :           7 :                               node3 = NULL;
    3446                 :           7 :                               goto finalize_map_clause;
    3447                 :             :                             }
    3448                 :        1228 :                           else if (n->u.map.op == OMP_MAP_DETACH)
    3449                 :             :                             {
    3450                 :           2 :                               OMP_CLAUSE_SET_MAP_KIND (node3, GOMP_MAP_DETACH);
    3451                 :             :                               /* Similarly to above, we don't want to unmap PTR
    3452                 :             :                                  here.  */
    3453                 :           2 :                               node = node2;
    3454                 :           2 :                               node2 = node3;
    3455                 :           2 :                               node3 = NULL;
    3456                 :           2 :                               goto finalize_map_clause;
    3457                 :             :                             }
    3458                 :             :                           else
    3459                 :        1990 :                             OMP_CLAUSE_SET_MAP_KIND (node3,
    3460                 :             :                                                      always_modifier
    3461                 :             :                                                      ? GOMP_MAP_ALWAYS_POINTER
    3462                 :             :                                                      : GOMP_MAP_POINTER);
    3463                 :             :                         }
    3464                 :             : 
    3465                 :             :                       /* We have to check for n->sym->attr.dimension because
    3466                 :             :                          of scalar coarrays.  */
    3467                 :        1350 :                       if ((n->sym->attr.pointer || n->sym->attr.allocatable)
    3468                 :        1350 :                           && n->sym->attr.dimension)
    3469                 :             :                         {
    3470                 :        1350 :                           stmtblock_t cond_block;
    3471                 :        1350 :                           tree size
    3472                 :        1350 :                             = gfc_create_var (gfc_array_index_type, NULL);
    3473                 :        1350 :                           tree tem, then_b, else_b, zero, cond;
    3474                 :             : 
    3475                 :        1350 :                           gfc_init_block (&cond_block);
    3476                 :        1350 :                           tem
    3477                 :        2700 :                             = gfc_full_array_size (&cond_block, decl,
    3478                 :        1350 :                                                    GFC_TYPE_ARRAY_RANK (type));
    3479                 :        1350 :                           tree elemsz;
    3480                 :        1350 :                           if (n->sym->ts.type == BT_CHARACTER
    3481                 :          40 :                               && n->sym->ts.deferred)
    3482                 :             :                             {
    3483                 :          32 :                               tree len = n->sym->ts.u.cl->backend_decl;
    3484                 :          32 :                               len = fold_convert (size_type_node, len);
    3485                 :          32 :                               elemsz = gfc_get_char_type (n->sym->ts.kind);
    3486                 :          32 :                               elemsz = TYPE_SIZE_UNIT (elemsz);
    3487                 :          32 :                               elemsz = fold_build2 (MULT_EXPR, size_type_node,
    3488                 :             :                                                     len, elemsz);
    3489                 :          32 :                             }
    3490                 :             :                           else
    3491                 :        1318 :                             elemsz
    3492                 :        1318 :                               = TYPE_SIZE_UNIT (gfc_get_element_type (type));
    3493                 :        1350 :                           elemsz = fold_convert (gfc_array_index_type, elemsz);
    3494                 :        1350 :                           tem = fold_build2 (MULT_EXPR, gfc_array_index_type,
    3495                 :             :                                              tem, elemsz);
    3496                 :        1350 :                           gfc_add_modify (&cond_block, size, tem);
    3497                 :        1350 :                           then_b = gfc_finish_block (&cond_block);
    3498                 :        1350 :                           gfc_init_block (&cond_block);
    3499                 :        1350 :                           zero = build_int_cst (gfc_array_index_type, 0);
    3500                 :        1350 :                           gfc_add_modify (&cond_block, size, zero);
    3501                 :        1350 :                           else_b = gfc_finish_block (&cond_block);
    3502                 :        1350 :                           tem = gfc_conv_descriptor_data_get (decl);
    3503                 :        1350 :                           tem = fold_convert (pvoid_type_node, tem);
    3504                 :        1350 :                           cond = fold_build2_loc (input_location, NE_EXPR,
    3505                 :             :                                                   boolean_type_node,
    3506                 :             :                                                   tem, null_pointer_node);
    3507                 :        1350 :                           if (present)
    3508                 :         308 :                             cond = fold_build2_loc (input_location,
    3509                 :             :                                                     TRUTH_ANDIF_EXPR,
    3510                 :             :                                                     boolean_type_node,
    3511                 :             :                                                     present, cond);
    3512                 :        1350 :                           gfc_add_expr_to_block (block,
    3513                 :             :                                                  build3_loc (input_location,
    3514                 :             :                                                              COND_EXPR,
    3515                 :             :                                                              void_type_node,
    3516                 :             :                                                              cond, then_b,
    3517                 :             :                                                              else_b));
    3518                 :        1350 :                           OMP_CLAUSE_SIZE (node) = size;
    3519                 :        1350 :                         }
    3520                 :           0 :                       else if (n->sym->attr.dimension)
    3521                 :             :                         {
    3522                 :           0 :                           stmtblock_t cond_block;
    3523                 :           0 :                           gfc_init_block (&cond_block);
    3524                 :           0 :                           tree size = gfc_full_array_size (&cond_block, decl,
    3525                 :           0 :                                         GFC_TYPE_ARRAY_RANK (type));
    3526                 :           0 :                           tree elemsz
    3527                 :           0 :                             = TYPE_SIZE_UNIT (gfc_get_element_type (type));
    3528                 :           0 :                           elemsz = fold_convert (gfc_array_index_type, elemsz);
    3529                 :           0 :                           size = fold_build2 (MULT_EXPR, gfc_array_index_type,
    3530                 :             :                                               size, elemsz);
    3531                 :           0 :                           size = gfc_evaluate_now (size, &cond_block);
    3532                 :           0 :                           if (present)
    3533                 :             :                             {
    3534                 :           0 :                               tree var = gfc_create_var (gfc_array_index_type,
    3535                 :             :                                                          NULL);
    3536                 :           0 :                               gfc_add_modify (&cond_block, var, size);
    3537                 :           0 :                               tree cond_body = gfc_finish_block (&cond_block);
    3538                 :           0 :                               tree cond = build3_loc (input_location, COND_EXPR,
    3539                 :             :                                                       void_type_node, present,
    3540                 :             :                                                       cond_body, NULL_TREE);
    3541                 :           0 :                               gfc_add_expr_to_block (block, cond);
    3542                 :           0 :                               OMP_CLAUSE_SIZE (node) = var;
    3543                 :             :                             }
    3544                 :             :                           else
    3545                 :             :                             {
    3546                 :           0 :                               gfc_add_block_to_block (block, &cond_block);
    3547                 :           0 :                               OMP_CLAUSE_SIZE (node) = size;
    3548                 :             :                             }
    3549                 :             :                         }
    3550                 :             :                     }
    3551                 :        7740 :                   else if (present
    3552                 :         842 :                            && INDIRECT_REF_P (decl)
    3553                 :        8480 :                            && INDIRECT_REF_P (TREE_OPERAND (decl, 0)))
    3554                 :             :                     {
    3555                 :             :                       /* A single indirectref is handled by the middle end.  */
    3556                 :         227 :                       gcc_assert (!POINTER_TYPE_P (TREE_TYPE (decl)));
    3557                 :         227 :                       decl = TREE_OPERAND (decl, 0);
    3558                 :         227 :                       decl = gfc_build_cond_assign_expr (block, present, decl,
    3559                 :             :                                                          null_pointer_node);
    3560                 :         227 :                       OMP_CLAUSE_DECL (node) = build_fold_indirect_ref (decl);
    3561                 :             :                     }
    3562                 :             :                   else
    3563                 :        7513 :                     OMP_CLAUSE_DECL (node) = decl;
    3564                 :             : 
    3565                 :        9090 :                   if (!n->sym->attr.dimension
    3566                 :        5746 :                       && n->sym->ts.type == BT_CHARACTER
    3567                 :         126 :                       && n->sym->ts.deferred)
    3568                 :             :                     {
    3569                 :          36 :                       if (!DECL_P (decl))
    3570                 :             :                         {
    3571                 :          34 :                           gcc_assert (TREE_CODE (decl) == INDIRECT_REF);
    3572                 :          34 :                           decl = TREE_OPERAND (decl, 0);
    3573                 :             :                         }
    3574                 :          36 :                       tree cond = fold_build2_loc (input_location, NE_EXPR,
    3575                 :             :                                                    boolean_type_node,
    3576                 :             :                                                    decl, null_pointer_node);
    3577                 :          36 :                       if (present)
    3578                 :           2 :                         cond = fold_build2_loc (input_location,
    3579                 :             :                                                 TRUTH_ANDIF_EXPR,
    3580                 :             :                                                 boolean_type_node,
    3581                 :             :                                                 present, cond);
    3582                 :          36 :                       tree len = n->sym->ts.u.cl->backend_decl;
    3583                 :          36 :                       len = fold_convert (size_type_node, len);
    3584                 :          36 :                       tree size = gfc_get_char_type (n->sym->ts.kind);
    3585                 :          36 :                       size = TYPE_SIZE_UNIT (size);
    3586                 :          36 :                       size = fold_build2 (MULT_EXPR, size_type_node, len, size);
    3587                 :          36 :                       size = build3_loc (input_location,
    3588                 :             :                                                          COND_EXPR,
    3589                 :             :                                                          size_type_node,
    3590                 :             :                                                          cond, size,
    3591                 :             :                                                          size_zero_node);
    3592                 :          36 :                       size = gfc_evaluate_now (size, block);
    3593                 :          36 :                       OMP_CLAUSE_SIZE (node) = size;
    3594                 :             :                     }
    3595                 :             :                 }
    3596                 :        5201 :               else if (n->expr
    3597                 :        5201 :                        && n->expr->expr_type == EXPR_VARIABLE
    3598                 :        5201 :                        && n->expr->ref->type == REF_ARRAY
    3599                 :        3525 :                        && !n->expr->ref->next)
    3600                 :             :                 {
    3601                 :             :                   /* An array element or array section which is not part of a
    3602                 :             :                      derived type, etc.  */
    3603                 :        3270 :                   bool element = n->expr->ref->u.ar.type == AR_ELEMENT;
    3604                 :        3270 :                   tree type = TREE_TYPE (decl);
    3605                 :        3270 :                   gomp_map_kind k = GOMP_MAP_POINTER;
    3606                 :        3270 :                   if (!openacc
    3607                 :         423 :                       && !GFC_DESCRIPTOR_TYPE_P (type)
    3608                 :        3640 :                       && !(POINTER_TYPE_P (type)
    3609                 :         241 :                            && GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (type))))
    3610                 :             :                     k = GOMP_MAP_FIRSTPRIVATE_POINTER;
    3611                 :        3270 :                   gfc_trans_omp_array_section (block, op, n, decl, element,
    3612                 :        3270 :                                                !openacc, k, node, node2,
    3613                 :             :                                                node3, node4);
    3614                 :        3270 :                 }
    3615                 :        1931 :               else if (n->expr
    3616                 :        1931 :                        && n->expr->expr_type == EXPR_VARIABLE
    3617                 :        1931 :                        && (n->expr->ref->type == REF_COMPONENT
    3618                 :             :                            || n->expr->ref->type == REF_ARRAY)
    3619                 :        1931 :                        && lastref
    3620                 :        1931 :                        && lastref->type == REF_COMPONENT
    3621                 :         413 :                        && lastref->u.c.component->ts.type != BT_CLASS
    3622                 :         389 :                        && lastref->u.c.component->ts.type != BT_DERIVED
    3623                 :         311 :                        && !lastref->u.c.component->attr.dimension)
    3624                 :             :                 {
    3625                 :             :                   /* Derived type access with last component being a scalar.  */
    3626                 :         311 :                   gfc_init_se (&se, NULL);
    3627                 :             : 
    3628                 :         311 :                   gfc_conv_expr (&se, n->expr);
    3629                 :         311 :                   gfc_add_block_to_block (block, &se.pre);
    3630                 :             :                   /* For BT_CHARACTER a pointer is returned.  */
    3631                 :         311 :                   OMP_CLAUSE_DECL (node)
    3632                 :         534 :                     = POINTER_TYPE_P (TREE_TYPE (se.expr))
    3633                 :         311 :                       ? build_fold_indirect_ref (se.expr) : se.expr;
    3634                 :         311 :                   gfc_add_block_to_block (block, &se.post);
    3635                 :         311 :                   if (pointer || allocatable)
    3636                 :             :                     {
    3637                 :             :                       /* If it's a bare attach/detach clause, we just want
    3638                 :             :                          to perform a single attach/detach operation, of the
    3639                 :             :                          pointer itself, not of the pointed-to object.  */
    3640                 :         140 :                       if (openacc
    3641                 :          68 :                           && (n->u.map.op == OMP_MAP_ATTACH
    3642                 :          50 :                               || n->u.map.op == OMP_MAP_DETACH))
    3643                 :             :                         {
    3644                 :          36 :                           OMP_CLAUSE_DECL (node)
    3645                 :          36 :                             = build_fold_addr_expr (OMP_CLAUSE_DECL (node));
    3646                 :          36 :                           OMP_CLAUSE_SIZE (node) = size_zero_node;
    3647                 :          36 :                           goto finalize_map_clause;
    3648                 :             :                         }
    3649                 :             : 
    3650                 :         104 :                       node2 = build_omp_clause (input_location,
    3651                 :             :                                                 OMP_CLAUSE_MAP);
    3652                 :         104 :                       OMP_CLAUSE_SET_MAP_KIND (node2, GOMP_MAP_ATTACH_DETACH);
    3653                 :         104 :                       OMP_CLAUSE_DECL (node2)
    3654                 :         144 :                         = POINTER_TYPE_P (TREE_TYPE (se.expr))
    3655                 :         104 :                           ? se.expr
    3656                 :          40 :                           : gfc_build_addr_expr (NULL, se.expr);
    3657                 :         104 :                       OMP_CLAUSE_SIZE (node2) = size_int (0);
    3658                 :         104 :                       if (!openacc
    3659                 :          72 :                           && n->expr->ts.type == BT_CHARACTER
    3660                 :          48 :                           && n->expr->ts.deferred)
    3661                 :             :                         {
    3662                 :          48 :                           gcc_assert (se.string_length);
    3663                 :          48 :                           tree tmp
    3664                 :          48 :                             = gfc_get_char_type (n->expr->ts.kind);
    3665                 :          48 :                           OMP_CLAUSE_SIZE (node)
    3666                 :          48 :                             = fold_build2 (MULT_EXPR, size_type_node,
    3667                 :             :                                            fold_convert (size_type_node,
    3668                 :             :                                                se.string_length),
    3669                 :             :                                            TYPE_SIZE_UNIT (tmp));
    3670                 :          48 :                           gomp_map_kind kind;
    3671                 :          48 :                           if (n->u.map.op == OMP_MAP_DELETE)
    3672                 :             :                             kind = GOMP_MAP_DELETE;
    3673                 :          48 :                           else if (op == EXEC_OMP_TARGET_EXIT_DATA)
    3674                 :             :                             kind = GOMP_MAP_RELEASE;
    3675                 :             :                           else
    3676                 :          44 :                             kind = GOMP_MAP_TO;
    3677                 :          48 :                           node3 = build_omp_clause (input_location,
    3678                 :             :                                                     OMP_CLAUSE_MAP);
    3679                 :          48 :                           OMP_CLAUSE_SET_MAP_KIND (node3, kind);
    3680                 :          48 :                           OMP_CLAUSE_DECL (node3) = se.string_length;
    3681                 :          48 :                           OMP_CLAUSE_SIZE (node3)
    3682                 :          96 :                             = TYPE_SIZE_UNIT (gfc_charlen_type_node);
    3683                 :             :                         }
    3684                 :             :                     }
    3685                 :             :                 }
    3686                 :        1620 :               else if (n->expr
    3687                 :        1620 :                        && n->expr->expr_type == EXPR_VARIABLE
    3688                 :        1620 :                        && (n->expr->ref->type == REF_COMPONENT
    3689                 :             :                            || n->expr->ref->type == REF_ARRAY))
    3690                 :             :                 {
    3691                 :        1620 :                   gfc_init_se (&se, NULL);
    3692                 :        1620 :                   se.expr = gfc_maybe_dereference_var (n->sym, decl);
    3693                 :             : 
    3694                 :        5354 :                   for (gfc_ref *ref = n->expr->ref; ref; ref = ref->next)
    3695                 :             :                     {
    3696                 :        3734 :                       if (ref->type == REF_COMPONENT)
    3697                 :             :                         {
    3698                 :        1853 :                           if (ref->u.c.sym->attr.extension)
    3699                 :          91 :                             conv_parent_component_references (&se, ref);
    3700                 :             : 
    3701                 :        1853 :                           gfc_conv_component_ref (&se, ref);
    3702                 :             :                         }
    3703                 :        1881 :                       else if (ref->type == REF_ARRAY)
    3704                 :             :                         {
    3705                 :        1881 :                           if (ref->u.ar.type == AR_ELEMENT && ref->next)
    3706                 :         363 :                             gfc_conv_array_ref (&se, &ref->u.ar, n->expr,
    3707                 :         363 :                                                 &n->expr->where);
    3708                 :             :                           else
    3709                 :        1518 :                             gcc_assert (!ref->next);
    3710                 :             :                         }
    3711                 :             :                       else
    3712                 :           0 :                         sorry ("unhandled expression type");
    3713                 :             :                     }
    3714                 :             : 
    3715                 :        1620 :                   tree inner = se.expr;
    3716                 :             : 
    3717                 :             :                   /* Last component is a derived type or class pointer.  */
    3718                 :        1620 :                   if (lastref->type == REF_COMPONENT
    3719                 :         102 :                       && (lastref->u.c.component->ts.type == BT_DERIVED
    3720                 :          24 :                           || lastref->u.c.component->ts.type == BT_CLASS))
    3721                 :             :                     {
    3722                 :         102 :                       if (pointer || (openacc && allocatable))
    3723                 :             :                         {
    3724                 :             :                           /* If it's a bare attach/detach clause, we just want
    3725                 :             :                              to perform a single attach/detach operation, of the
    3726                 :             :                              pointer itself, not of the pointed-to object.  */
    3727                 :          55 :                           if (openacc
    3728                 :          49 :                               && (n->u.map.op == OMP_MAP_ATTACH
    3729                 :          43 :                                   || n->u.map.op == OMP_MAP_DETACH))
    3730                 :             :                             {
    3731                 :          12 :                               OMP_CLAUSE_DECL (node)
    3732                 :          12 :                                 = build_fold_addr_expr (inner);
    3733                 :          12 :                               OMP_CLAUSE_SIZE (node) = size_zero_node;
    3734                 :          18 :                               goto finalize_map_clause;
    3735                 :             :                             }
    3736                 :             : 
    3737                 :          43 :                           gfc_omp_namelist *n2
    3738                 :           6 :                             = openacc ? NULL : clauses->lists[OMP_LIST_MAP];
    3739                 :             : 
    3740                 :          43 :                           bool sym_based;
    3741                 :          43 :                           n2 = get_symbol_rooted_namelist (sym_rooted_nl, n,
    3742                 :             :                                                            n2, &sym_based);
    3743                 :             : 
    3744                 :             :                           /* If the last reference is a pointer to a derived
    3745                 :             :                              type ("foo%dt_ptr"), check if any subcomponents
    3746                 :             :                              of the same derived type member are being mapped
    3747                 :             :                              elsewhere in the clause list ("foo%dt_ptr%x",
    3748                 :             :                              etc.).  If we have such subcomponent mappings,
    3749                 :             :                              we only create an ALLOC node for the pointer
    3750                 :             :                              itself, and inhibit mapping the whole derived
    3751                 :             :                              type.  */
    3752                 :             : 
    3753                 :          43 :                           for (; n2 != NULL; n2 = n2->next)
    3754                 :             :                             {
    3755                 :           6 :                               if ((!sym_based && n == n2)
    3756                 :           6 :                                   || (sym_based && n == n2->u2.duplicate_of)
    3757                 :           6 :                                   || !n2->expr)
    3758                 :           0 :                                 continue;
    3759                 :             : 
    3760                 :           6 :                               if (!gfc_omp_expr_prefix_same (n->expr,
    3761                 :             :                                                              n2->expr))
    3762                 :           0 :                                 continue;
    3763                 :             : 
    3764                 :           6 :                               gfc_ref *ref1 = n->expr->ref;
    3765                 :           6 :                               gfc_ref *ref2 = n2->expr->ref;
    3766                 :             : 
    3767                 :           6 :                               while (ref1->next && ref2->next)
    3768                 :             :                                 {
    3769                 :             :                                   ref1 = ref1->next;
    3770                 :             :                                   ref2 = ref2->next;
    3771                 :             :                                 }
    3772                 :             : 
    3773                 :           6 :                               if (ref2->next)
    3774                 :             :                                 {
    3775                 :           6 :                                   inner = build_fold_addr_expr (inner);
    3776                 :           6 :                                   OMP_CLAUSE_SET_MAP_KIND (node,
    3777                 :             :                                                            GOMP_MAP_ALLOC);
    3778                 :           6 :                                   OMP_CLAUSE_DECL (node) = inner;
    3779                 :           6 :                                   OMP_CLAUSE_SIZE (node)
    3780                 :           6 :                                     = TYPE_SIZE_UNIT (TREE_TYPE (inner));
    3781                 :           6 :                                   goto finalize_map_clause;
    3782                 :             :                                 }
    3783                 :             :                             }
    3784                 :             : 
    3785                 :          37 :                           tree data, size;
    3786                 :             : 
    3787                 :          37 :                           if (lastref->u.c.component->ts.type == BT_CLASS)
    3788                 :             :                             {
    3789                 :          24 :                               data = gfc_class_data_get (inner);
    3790                 :          24 :                               gcc_assert (POINTER_TYPE_P (TREE_TYPE (data)));
    3791                 :          24 :                               data = build_fold_indirect_ref (data);
    3792                 :          24 :                               size = gfc_class_vtab_size_get (inner);
    3793                 :             :                             }
    3794                 :             :                           else  /* BT_DERIVED.  */
    3795                 :             :                             {
    3796                 :          13 :                               data = inner;
    3797                 :          13 :                               size = TYPE_SIZE_UNIT (TREE_TYPE (inner));
    3798                 :             :                             }
    3799                 :             : 
    3800                 :          37 :                           OMP_CLAUSE_DECL (node) = data;
    3801                 :          37 :                           OMP_CLAUSE_SIZE (node) = size;
    3802                 :          37 :                           node2 = build_omp_clause (input_location,
    3803                 :             :                                                     OMP_CLAUSE_MAP);
    3804                 :          37 :                           OMP_CLAUSE_SET_MAP_KIND (node2,
    3805                 :             :                                                    GOMP_MAP_ATTACH_DETACH);
    3806                 :          37 :                           OMP_CLAUSE_DECL (node2) = build_fold_addr_expr (data);
    3807                 :          37 :                           OMP_CLAUSE_SIZE (node2) = size_int (0);
    3808                 :          37 :                         }
    3809                 :             :                       else
    3810                 :             :                         {
    3811                 :          47 :                           OMP_CLAUSE_DECL (node) = inner;
    3812                 :          47 :                           OMP_CLAUSE_SIZE (node)
    3813                 :          94 :                             = TYPE_SIZE_UNIT (TREE_TYPE (inner));
    3814                 :             :                         }
    3815                 :             :                     }
    3816                 :        1518 :                   else if (lastref->type == REF_ARRAY
    3817                 :        1518 :                            && lastref->u.ar.type == AR_FULL)
    3818                 :             :                     {
    3819                 :             :                       /* Bare attach and detach clauses don't want any
    3820                 :             :                          additional nodes.  */
    3821                 :         834 :                       if ((n->u.map.op == OMP_MAP_ATTACH
    3822                 :         803 :                            || n->u.map.op == OMP_MAP_DETACH)
    3823                 :         848 :                           && (POINTER_TYPE_P (TREE_TYPE (inner))
    3824                 :          45 :                               || GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (inner))))
    3825                 :             :                         {
    3826                 :          45 :                           if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (inner)))
    3827                 :             :                             {
    3828                 :          45 :                               tree ptr = gfc_conv_descriptor_data_get (inner);
    3829                 :          45 :                               OMP_CLAUSE_DECL (node) = ptr;
    3830                 :             :                             }
    3831                 :             :                           else
    3832                 :           0 :                             OMP_CLAUSE_DECL (node) = inner;
    3833                 :          45 :                           OMP_CLAUSE_SIZE (node) = size_zero_node;
    3834                 :          45 :                           goto finalize_map_clause;
    3835                 :             :                         }
    3836                 :             : 
    3837                 :         789 :                       if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (inner)))
    3838                 :             :                         {
    3839                 :         625 :                           gomp_map_kind map_kind;
    3840                 :         625 :                           tree type = TREE_TYPE (inner);
    3841                 :         625 :                           tree ptr = gfc_conv_descriptor_data_get (inner);
    3842                 :         625 :                           ptr = build_fold_indirect_ref (ptr);
    3843                 :         625 :                           OMP_CLAUSE_DECL (node) = ptr;
    3844                 :         625 :                           int rank = GFC_TYPE_ARRAY_RANK (type);
    3845                 :         625 :                           OMP_CLAUSE_SIZE (node)
    3846                 :         625 :                             = gfc_full_array_size (block, inner, rank);
    3847                 :         625 :                           tree elemsz
    3848                 :         625 :                             = TYPE_SIZE_UNIT (gfc_get_element_type (type));
    3849                 :         625 :                           map_kind = OMP_CLAUSE_MAP_KIND (node);
    3850                 :         625 :                           if (GOMP_MAP_COPY_TO_P (map_kind)
    3851                 :         107 :                               || map_kind == GOMP_MAP_ALLOC)
    3852                 :         539 :                             map_kind = ((GOMP_MAP_ALWAYS_P (map_kind)
    3853                 :        1018 :                                          || gfc_expr_attr (n->expr).pointer)
    3854                 :         539 :                                         ? GOMP_MAP_ALWAYS_TO : GOMP_MAP_TO);
    3855                 :          86 :                           else if (n->u.map.op == OMP_MAP_RELEASE
    3856                 :          82 :                                    || n->u.map.op == OMP_MAP_DELETE)
    3857                 :             :                             ;
    3858                 :          81 :                           else if (op == EXEC_OMP_TARGET_EXIT_DATA
    3859                 :          81 :                                    || op == EXEC_OACC_EXIT_DATA)
    3860                 :             :                             map_kind = GOMP_MAP_RELEASE;
    3861                 :             :                           else
    3862                 :          29 :                             map_kind = GOMP_MAP_ALLOC;
    3863                 :         625 :                           if (!openacc
    3864                 :         485 :                               && n->expr->ts.type == BT_CHARACTER
    3865                 :          36 :                               && n->expr->ts.deferred)
    3866                 :             :                             {
    3867                 :          36 :                               gcc_assert (se.string_length);
    3868                 :          36 :                               tree len = fold_convert (size_type_node,
    3869                 :             :                                                        se.string_length);
    3870                 :          36 :                               elemsz = gfc_get_char_type (n->expr->ts.kind);
    3871                 :          36 :                               elemsz = TYPE_SIZE_UNIT (elemsz);
    3872                 :          36 :                               elemsz = fold_build2 (MULT_EXPR, size_type_node,
    3873                 :             :                                                     len, elemsz);
    3874                 :          36 :                               node4 = build_omp_clause (input_location,
    3875                 :             :                                                         OMP_CLAUSE_MAP);
    3876                 :          36 :                               OMP_CLAUSE_SET_MAP_KIND (node4, map_kind);
    3877                 :          36 :                               OMP_CLAUSE_DECL (node4) = se.string_length;
    3878                 :          36 :                               OMP_CLAUSE_SIZE (node4)
    3879                 :          72 :                                 = TYPE_SIZE_UNIT (gfc_charlen_type_node);
    3880                 :             :                             }
    3881                 :         625 :                           elemsz = fold_convert (gfc_array_index_type, elemsz);
    3882                 :         625 :                           OMP_CLAUSE_SIZE (node)
    3883                 :         625 :                             = fold_build2 (MULT_EXPR, gfc_array_index_type,
    3884                 :             :                                            OMP_CLAUSE_SIZE (node), elemsz);
    3885                 :         625 :                           node2 = build_omp_clause (input_location,
    3886                 :             :                                                     OMP_CLAUSE_MAP);
    3887                 :         625 :                           if (map_kind == GOMP_MAP_RELEASE
    3888                 :         625 :                               || map_kind == GOMP_MAP_DELETE)
    3889                 :             :                             {
    3890                 :          57 :                               OMP_CLAUSE_SET_MAP_KIND (node2, map_kind);
    3891                 :          57 :                               OMP_CLAUSE_RELEASE_DESCRIPTOR (node2) = 1;
    3892                 :             :                             }
    3893                 :             :                           else
    3894                 :         568 :                             OMP_CLAUSE_SET_MAP_KIND (node2,
    3895                 :             :                                                      GOMP_MAP_TO_PSET);
    3896                 :         625 :                           OMP_CLAUSE_DECL (node2) = inner;
    3897                 :         625 :                           OMP_CLAUSE_SIZE (node2) = TYPE_SIZE_UNIT (type);
    3898                 :         625 :                           if (!openacc)
    3899                 :             :                             {
    3900                 :         485 :                               gfc_omp_namelist *n2
    3901                 :             :                                 = clauses->lists[OMP_LIST_MAP];
    3902                 :             : 
    3903                 :             :                               /* If we don't have a mapping of a smaller part
    3904                 :             :                                  of the array -- or we can't prove that we do
    3905                 :             :                                  statically -- set this flag.  If there is a
    3906                 :             :                                  mapping of a smaller part of the array after
    3907                 :             :                                  all, this will turn into a no-op at
    3908                 :             :                                  runtime.  */
    3909                 :         485 :                               OMP_CLAUSE_MAP_RUNTIME_IMPLICIT_P (node) = 1;
    3910                 :             : 
    3911                 :         485 :                               bool sym_based;
    3912                 :         485 :                               n2 = get_symbol_rooted_namelist (sym_rooted_nl,
    3913                 :             :                                                                n, n2,
    3914                 :             :                                                                &sym_based);
    3915                 :             : 
    3916                 :         485 :                               bool drop_mapping = false;
    3917                 :             : 
    3918                 :        1523 :                               for (; n2 != NULL; n2 = n2->next)
    3919                 :             :                                 {
    3920                 :        1318 :                                   if ((!sym_based && n == n2)
    3921                 :        1318 :                                       || (sym_based && n == n2->u2.duplicate_of)
    3922                 :        1095 :                                       || !n2->expr)
    3923                 :         223 :                                     continue;
    3924                 :             : 
    3925                 :        1095 :                                   if (!gfc_omp_expr_prefix_same (n->expr,
    3926                 :             :                                                                  n2->expr))
    3927                 :         815 :                                     continue;
    3928                 :             : 
    3929                 :         280 :                                   gfc_ref *ref1 = n->expr->ref;
    3930                 :         280 :                                   gfc_ref *ref2 = n2->expr->ref;
    3931                 :             : 
    3932                 :             :                                   /* We know ref1 and ref2 overlap.  We're
    3933                 :             :                                      interested in whether ref2 describes a
    3934                 :             :                                      smaller part of the array than ref1, which
    3935                 :             :                                      we already know refers to the full
    3936                 :             :                                      array.  */
    3937                 :             : 
    3938                 :         620 :                                   while (ref1->next && ref2->next)
    3939                 :             :                                     {
    3940                 :             :                                       ref1 = ref1->next;
    3941                 :             :                                       ref2 = ref2->next;
    3942                 :             :                                     }
    3943                 :             : 
    3944                 :         280 :                                   if (ref2->next
    3945                 :         280 :                                       || (ref2->type == REF_ARRAY
    3946                 :         280 :                                           && (ref2->u.ar.type == AR_ELEMENT
    3947                 :         280 :                                               || (ref2->u.ar.type
    3948                 :             :                                                   == AR_SECTION))))
    3949                 :             :                                     {
    3950                 :             :                                       drop_mapping = true;
    3951                 :             :                                       break;
    3952                 :             :                                     }
    3953                 :             :                                 }
    3954                 :         485 :                               if (drop_mapping)
    3955                 :         280 :                                 continue;
    3956                 :             :                             }
    3957                 :         345 :                           node3 = build_omp_clause (input_location,
    3958                 :             :                                                     OMP_CLAUSE_MAP);
    3959                 :         345 :                           OMP_CLAUSE_SET_MAP_KIND (node3,
    3960                 :             :                                                    GOMP_MAP_ATTACH_DETACH);
    3961                 :         345 :                           OMP_CLAUSE_DECL (node3)
    3962                 :         345 :                             = gfc_conv_descriptor_data_get (inner);
    3963                 :             :                           /* Similar to gfc_trans_omp_array_section (details
    3964                 :             :                              there), we add/keep the cast for OpenMP to prevent
    3965                 :             :                              that an 'alloc:' gets added for node3 ('desc.data')
    3966                 :             :                              as that is part of the whole descriptor (node3).
    3967                 :             :                              TODO: Remove once the ME handles this properly.  */
    3968                 :         345 :                           if (!openacc)
    3969                 :         205 :                             OMP_CLAUSE_DECL (node3)
    3970                 :         410 :                                 = fold_convert (TREE_TYPE (TREE_OPERAND(ptr, 0)),
    3971                 :             :                                                 OMP_CLAUSE_DECL (node3));
    3972                 :             :                           else
    3973                 :         140 :                             STRIP_NOPS (OMP_CLAUSE_DECL (node3));
    3974                 :         345 :                           OMP_CLAUSE_SIZE (node3) = size_int (0);
    3975                 :             :                         }
    3976                 :             :                       else
    3977                 :         164 :                         OMP_CLAUSE_DECL (node) = inner;
    3978                 :             :                     }
    3979                 :         684 :                   else if (lastref->type == REF_ARRAY)
    3980                 :             :                     {
    3981                 :             :                       /* An array element or section.  */
    3982                 :         684 :                       bool element = lastref->u.ar.type == AR_ELEMENT;
    3983                 :         684 :                       gomp_map_kind kind = GOMP_MAP_ATTACH_DETACH;
    3984                 :         684 :                       gfc_trans_omp_array_section (block, op, n, inner, element,
    3985                 :         684 :                                                    !openacc, kind, node, node2,
    3986                 :             :                                                    node3, node4);
    3987                 :             :                     }
    3988                 :             :                   else
    3989                 :           0 :                     gcc_unreachable ();
    3990                 :             :                 }
    3991                 :             :               else
    3992                 :           0 :                 sorry ("unhandled expression");
    3993                 :             : 
    3994                 :       14080 :               finalize_map_clause:
    3995                 :             : 
    3996                 :       14080 :               omp_clauses = gfc_trans_add_clause (node, omp_clauses);
    3997                 :       14080 :               if (node2)
    3998                 :        4609 :                 omp_clauses = gfc_trans_add_clause (node2, omp_clauses);
    3999                 :       14080 :               if (node3)
    4000                 :        5836 :                 omp_clauses = gfc_trans_add_clause (node3, omp_clauses);
    4001                 :       14080 :               if (node4)
    4002                 :        3368 :                 omp_clauses = gfc_trans_add_clause (node4, omp_clauses);
    4003                 :       14080 :               if (node5)
    4004                 :           4 :                 omp_clauses = gfc_trans_add_clause (node5, omp_clauses);
    4005                 :             :             }
    4006                 :             :           break;
    4007                 :             :         case OMP_LIST_TO:
    4008                 :             :         case OMP_LIST_FROM:
    4009                 :             :         case OMP_LIST_CACHE:
    4010                 :        3637 :           for (; n != NULL; n = n->next)
    4011                 :             :             {
    4012                 :        1861 :               if (!n->sym->attr.referenced)
    4013                 :           0 :                 continue;
    4014                 :             : 
    4015                 :        1861 :               switch (list)
    4016                 :             :                 {
    4017                 :             :                 case OMP_LIST_TO:
    4018                 :             :                   clause_code = OMP_CLAUSE_TO;
    4019                 :             :                   break;
    4020                 :        1028 :                 case OMP_LIST_FROM:
    4021                 :        1028 :                   clause_code = OMP_CLAUSE_FROM;
    4022                 :        1028 :                   break;
    4023                 :          82 :                 case OMP_LIST_CACHE:
    4024                 :          82 :                   clause_code = OMP_CLAUSE__CACHE_;
    4025                 :          82 :                   break;
    4026                 :           0 :                 default:
    4027                 :           0 :                   gcc_unreachable ();
    4028                 :             :                 }
    4029                 :        1861 :               tree node = build_omp_clause (input_location, clause_code);
    4030                 :        1861 :               if (n->expr == NULL
    4031                 :         128 :                   || (n->expr->ref->type == REF_ARRAY
    4032                 :         116 :                       && n->expr->ref->u.ar.type == AR_FULL
    4033                 :           0 :                       && n->expr->ref->next == NULL))
    4034                 :             :                 {
    4035                 :        1733 :                   tree decl = gfc_trans_omp_variable (n->sym, false);
    4036                 :        1733 :                   if (gfc_omp_privatize_by_reference (decl))
    4037                 :             :                     {
    4038                 :        1047 :                       if (gfc_omp_is_allocatable_or_ptr (decl))
    4039                 :         240 :                         decl = build_fold_indirect_ref (decl);
    4040                 :        1047 :                       decl = build_fold_indirect_ref (decl);
    4041                 :             :                     }
    4042                 :         686 :                   else if (DECL_P (decl))
    4043                 :         686 :                     TREE_ADDRESSABLE (decl) = 1;
    4044                 :        1733 :                   if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl)))
    4045                 :             :                     {
    4046                 :         597 :                       tree type = TREE_TYPE (decl);
    4047                 :         597 :                       tree ptr = gfc_conv_descriptor_data_get (decl);
    4048                 :         597 :                       gcc_assert (POINTER_TYPE_P (TREE_TYPE (ptr)));
    4049                 :         597 :                       ptr = build_fold_indirect_ref (ptr);
    4050                 :         597 :                       OMP_CLAUSE_DECL (node) = ptr;
    4051                 :         597 :                       OMP_CLAUSE_SIZE (node)
    4052                 :         597 :                         = gfc_full_array_size (block, decl,
    4053                 :         597 :                                                GFC_TYPE_ARRAY_RANK (type));
    4054                 :         597 :                       tree elemsz
    4055                 :         597 :                         = TYPE_SIZE_UNIT (gfc_get_element_type (type));
    4056                 :         597 :                       elemsz = fold_convert (gfc_array_index_type, elemsz);
    4057                 :        1194 :                       OMP_CLAUSE_SIZE (node)
    4058                 :        1194 :                         = fold_build2 (MULT_EXPR, gfc_array_index_type,
    4059                 :             :                                        OMP_CLAUSE_SIZE (node), elemsz);
    4060                 :             :                     }
    4061                 :             :                   else
    4062                 :             :                     {
    4063                 :        1136 :                       OMP_CLAUSE_DECL (node) = decl;
    4064                 :        1136 :                       if (gfc_omp_is_allocatable_or_ptr (decl))
    4065                 :         120 :                         OMP_CLAUSE_SIZE (node)
    4066                 :         240 :                                 = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl)));
    4067                 :             :                     }
    4068                 :             :                 }
    4069                 :             :               else
    4070                 :             :                 {
    4071                 :         128 :                   tree ptr;
    4072                 :         128 :                   gfc_init_se (&se, NULL);
    4073                 :         128 :                   if (n->expr->rank == 0)
    4074                 :             :                     {
    4075                 :           5 :                       gfc_conv_expr_reference (&se, n->expr);
    4076                 :           5 :                       ptr = se.expr;
    4077                 :           5 :                       gfc_add_block_to_block (block, &se.pre);
    4078                 :           5 :                       OMP_CLAUSE_SIZE (node)
    4079                 :          10 :                         = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (ptr)));
    4080                 :             :                     }
    4081                 :             :                   else
    4082                 :             :                     {
    4083                 :         123 :                       gfc_conv_expr_descriptor (&se, n->expr);
    4084                 :         123 :                       ptr = gfc_conv_array_data (se.expr);
    4085                 :         123 :                       tree type = TREE_TYPE (se.expr);
    4086                 :         123 :                       gfc_add_block_to_block (block, &se.pre);
    4087                 :         123 :                       OMP_CLAUSE_SIZE (node)
    4088                 :         123 :                         = gfc_full_array_size (block, se.expr,
    4089                 :         123 :                                                GFC_TYPE_ARRAY_RANK (type));
    4090                 :         123 :                       tree elemsz
    4091                 :         123 :                         = TYPE_SIZE_UNIT (gfc_get_element_type (type));
    4092                 :         123 :                       elemsz = fold_convert (gfc_array_index_type, elemsz);
    4093                 :         246 :                       OMP_CLAUSE_SIZE (node)
    4094                 :         246 :                         = fold_build2 (MULT_EXPR, gfc_array_index_type,
    4095                 :             :                                        OMP_CLAUSE_SIZE (node), elemsz);
    4096                 :             :                     }
    4097                 :         128 :                   gfc_add_block_to_block (block, &se.post);
    4098                 :         128 :                   gcc_assert (POINTER_TYPE_P (TREE_TYPE (ptr)));
    4099                 :         128 :                   OMP_CLAUSE_DECL (node) = build_fold_indirect_ref (ptr);
    4100                 :             :                 }
    4101                 :        1861 :               if (n->u.present_modifier)
    4102                 :           5 :                 OMP_CLAUSE_MOTION_PRESENT (node) = 1;
    4103                 :        1861 :               if (list == OMP_LIST_CACHE && n->u.map.readonly)
    4104                 :          16 :                 OMP_CLAUSE__CACHE__READONLY (node) = 1;
    4105                 :        1861 :               omp_clauses = gfc_trans_add_clause (node, omp_clauses);
    4106                 :             :             }
    4107                 :             :           break;
    4108                 :             :         case OMP_LIST_USES_ALLOCATORS:
    4109                 :             :           /* Ignore pre-defined allocators as no special treatment is needed. */
    4110                 :          30 :           for (; n != NULL; n = n->next)
    4111                 :          28 :             if (n->sym->attr.flavor == FL_VARIABLE)
    4112                 :             :               break;
    4113                 :          12 :           if (n != NULL)
    4114                 :          10 :             sorry_at (input_location, "%<uses_allocators%> clause with traits "
    4115                 :             :                                       "and memory spaces");
    4116                 :             :           break;
    4117                 :             :         default:
    4118                 :             :           break;
    4119                 :             :         }
    4120                 :             :     }
    4121                 :             : 
    4122                 :             :   /* Free hashmap if we built it.  */
    4123                 :       28947 :   if (sym_rooted_nl)
    4124                 :             :     {
    4125                 :         237 :       typedef hash_map<gfc_symbol *, gfc_omp_namelist *>::iterator hti;
    4126                 :         813 :       for (hti it = sym_rooted_nl->begin (); it != sym_rooted_nl->end (); ++it)
    4127                 :             :         {
    4128                 :         288 :           gfc_omp_namelist *&nl = (*it).second;
    4129                 :        1190 :           while (nl)
    4130                 :             :             {
    4131                 :         902 :               gfc_omp_namelist *next = nl->next;
    4132                 :         902 :               free (nl);
    4133                 :         902 :               nl = next;
    4134                 :             :             }
    4135                 :             :         }
    4136                 :         237 :       delete sym_rooted_nl;
    4137                 :             :     }
    4138                 :             : 
    4139                 :       28947 :   if (clauses->if_expr)
    4140                 :             :     {
    4141                 :        1099 :       tree if_var;
    4142                 :             : 
    4143                 :        1099 :       gfc_init_se (&se, NULL);
    4144                 :        1099 :       gfc_conv_expr (&se, clauses->if_expr);
    4145                 :        1099 :       gfc_add_block_to_block (block, &se.pre);
    4146                 :        1099 :       if_var = gfc_evaluate_now (se.expr, block);
    4147                 :        1099 :       gfc_add_block_to_block (block, &se.post);
    4148                 :             : 
    4149                 :        1099 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_IF);
    4150                 :        1099 :       OMP_CLAUSE_IF_MODIFIER (c) = ERROR_MARK;
    4151                 :        1099 :       OMP_CLAUSE_IF_EXPR (c) = if_var;
    4152                 :        1099 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4153                 :             :     }
    4154                 :             : 
    4155                 :      318417 :   for (ifc = 0; ifc < OMP_IF_LAST; ifc++)
    4156                 :      289470 :     if (clauses->if_exprs[ifc])
    4157                 :             :       {
    4158                 :         123 :         tree if_var;
    4159                 :             : 
    4160                 :         123 :         gfc_init_se (&se, NULL);
    4161                 :         123 :         gfc_conv_expr (&se, clauses->if_exprs[ifc]);
    4162                 :         123 :         gfc_add_block_to_block (block, &se.pre);
    4163                 :         123 :         if_var = gfc_evaluate_now (se.expr, block);
    4164                 :         123 :         gfc_add_block_to_block (block, &se.post);
    4165                 :             : 
    4166                 :         123 :         c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_IF);
    4167                 :         123 :         switch (ifc)
    4168                 :             :           {
    4169                 :           0 :           case OMP_IF_CANCEL:
    4170                 :           0 :             OMP_CLAUSE_IF_MODIFIER (c) = VOID_CST;
    4171                 :           0 :             break;
    4172                 :          40 :           case OMP_IF_PARALLEL:
    4173                 :          40 :             OMP_CLAUSE_IF_MODIFIER (c) = OMP_PARALLEL;
    4174                 :          40 :             break;
    4175                 :          39 :           case OMP_IF_SIMD:
    4176                 :          39 :             OMP_CLAUSE_IF_MODIFIER (c) = OMP_SIMD;
    4177                 :          39 :             break;
    4178                 :           1 :           case OMP_IF_TASK:
    4179                 :           1 :             OMP_CLAUSE_IF_MODIFIER (c) = OMP_TASK;
    4180                 :           1 :             break;
    4181                 :          23 :           case OMP_IF_TASKLOOP:
    4182                 :          23 :             OMP_CLAUSE_IF_MODIFIER (c) = OMP_TASKLOOP;
    4183                 :          23 :             break;
    4184                 :          16 :           case OMP_IF_TARGET:
    4185                 :          16 :             OMP_CLAUSE_IF_MODIFIER (c) = OMP_TARGET;
    4186                 :          16 :             break;
    4187                 :           1 :           case OMP_IF_TARGET_DATA:
    4188                 :           1 :             OMP_CLAUSE_IF_MODIFIER (c) = OMP_TARGET_DATA;
    4189                 :           1 :             break;
    4190                 :           1 :           case OMP_IF_TARGET_UPDATE:
    4191                 :           1 :             OMP_CLAUSE_IF_MODIFIER (c) = OMP_TARGET_UPDATE;
    4192                 :           1 :             break;
    4193                 :           1 :           case OMP_IF_TARGET_ENTER_DATA:
    4194                 :           1 :             OMP_CLAUSE_IF_MODIFIER (c) = OMP_TARGET_ENTER_DATA;
    4195                 :           1 :             break;
    4196                 :           1 :           case OMP_IF_TARGET_EXIT_DATA:
    4197                 :           1 :             OMP_CLAUSE_IF_MODIFIER (c) = OMP_TARGET_EXIT_DATA;
    4198                 :           1 :             break;
    4199                 :             :           default:
    4200                 :             :             gcc_unreachable ();
    4201                 :             :           }
    4202                 :         123 :         OMP_CLAUSE_IF_EXPR (c) = if_var;
    4203                 :         123 :         omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4204                 :             :       }
    4205                 :             : 
    4206                 :       28947 :   if (clauses->self_expr)
    4207                 :             :     {
    4208                 :         158 :       tree self_var;
    4209                 :             : 
    4210                 :         158 :       gfc_init_se (&se, NULL);
    4211                 :         158 :       gfc_conv_expr (&se, clauses->self_expr);
    4212                 :         158 :       gfc_add_block_to_block (block, &se.pre);
    4213                 :         158 :       self_var = gfc_evaluate_now (se.expr, block);
    4214                 :         158 :       gfc_add_block_to_block (block, &se.post);
    4215                 :             : 
    4216                 :         158 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_SELF);
    4217                 :         158 :       OMP_CLAUSE_SELF_EXPR (c) = self_var;
    4218                 :         158 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4219                 :             :     }
    4220                 :             : 
    4221                 :       28947 :   if (clauses->final_expr)
    4222                 :             :     {
    4223                 :          64 :       tree final_var;
    4224                 :             : 
    4225                 :          64 :       gfc_init_se (&se, NULL);
    4226                 :          64 :       gfc_conv_expr (&se, clauses->final_expr);
    4227                 :          64 :       gfc_add_block_to_block (block, &se.pre);
    4228                 :          64 :       final_var = gfc_evaluate_now (se.expr, block);
    4229                 :          64 :       gfc_add_block_to_block (block, &se.post);
    4230                 :             : 
    4231                 :          64 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_FINAL);
    4232                 :          64 :       OMP_CLAUSE_FINAL_EXPR (c) = final_var;
    4233                 :          64 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4234                 :             :     }
    4235                 :             : 
    4236                 :       28947 :   if (clauses->num_threads)
    4237                 :             :     {
    4238                 :         942 :       tree num_threads;
    4239                 :             : 
    4240                 :         942 :       gfc_init_se (&se, NULL);
    4241                 :         942 :       gfc_conv_expr (&se, clauses->num_threads);
    4242                 :         942 :       gfc_add_block_to_block (block, &se.pre);
    4243                 :         942 :       num_threads = gfc_evaluate_now (se.expr, block);
    4244                 :         942 :       gfc_add_block_to_block (block, &se.post);
    4245                 :             : 
    4246                 :         942 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_NUM_THREADS);
    4247                 :         942 :       OMP_CLAUSE_NUM_THREADS_EXPR (c) = num_threads;
    4248                 :         942 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4249                 :             :     }
    4250                 :             : 
    4251                 :       28947 :   chunk_size = NULL_TREE;
    4252                 :       28947 :   if (clauses->chunk_size)
    4253                 :             :     {
    4254                 :         487 :       gfc_init_se (&se, NULL);
    4255                 :         487 :       gfc_conv_expr (&se, clauses->chunk_size);
    4256                 :         487 :       gfc_add_block_to_block (block, &se.pre);
    4257                 :         487 :       chunk_size = gfc_evaluate_now (se.expr, block);
    4258                 :         487 :       gfc_add_block_to_block (block, &se.post);
    4259                 :             :     }
    4260                 :             : 
    4261                 :       28947 :   if (clauses->sched_kind != OMP_SCHED_NONE)
    4262                 :             :     {
    4263                 :         748 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_SCHEDULE);
    4264                 :         748 :       OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = chunk_size;
    4265                 :         748 :       switch (clauses->sched_kind)
    4266                 :             :         {
    4267                 :         387 :         case OMP_SCHED_STATIC:
    4268                 :         387 :           OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
    4269                 :         387 :           break;
    4270                 :         159 :         case OMP_SCHED_DYNAMIC:
    4271                 :         159 :           OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
    4272                 :         159 :           break;
    4273                 :         111 :         case OMP_SCHED_GUIDED:
    4274                 :         111 :           OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
    4275                 :         111 :           break;
    4276                 :          84 :         case OMP_SCHED_RUNTIME:
    4277                 :          84 :           OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
    4278                 :          84 :           break;
    4279                 :           7 :         case OMP_SCHED_AUTO:
    4280                 :           7 :           OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO;
    4281                 :           7 :           break;
    4282                 :           0 :         default:
    4283                 :           0 :           gcc_unreachable ();
    4284                 :             :         }
    4285                 :         748 :       if (clauses->sched_monotonic)
    4286                 :          54 :         OMP_CLAUSE_SCHEDULE_KIND (c)
    4287                 :          27 :           = (omp_clause_schedule_kind) (OMP_CLAUSE_SCHEDULE_KIND (c)
    4288                 :             :                                         | OMP_CLAUSE_SCHEDULE_MONOTONIC);
    4289                 :         721 :       else if (clauses->sched_nonmonotonic)
    4290                 :          46 :         OMP_CLAUSE_SCHEDULE_KIND (c)
    4291                 :          23 :           = (omp_clause_schedule_kind) (OMP_CLAUSE_SCHEDULE_KIND (c)
    4292                 :             :                                         | OMP_CLAUSE_SCHEDULE_NONMONOTONIC);
    4293                 :         748 :       if (clauses->sched_simd)
    4294                 :          17 :         OMP_CLAUSE_SCHEDULE_SIMD (c) = 1;
    4295                 :         748 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4296                 :             :     }
    4297                 :             : 
    4298                 :       28947 :   if (clauses->default_sharing != OMP_DEFAULT_UNKNOWN)
    4299                 :             :     {
    4300                 :        1046 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_DEFAULT);
    4301                 :        1046 :       switch (clauses->default_sharing)
    4302                 :             :         {
    4303                 :         641 :         case OMP_DEFAULT_NONE:
    4304                 :         641 :           OMP_CLAUSE_DEFAULT_KIND (c) = OMP_CLAUSE_DEFAULT_NONE;
    4305                 :         641 :           break;
    4306                 :         183 :         case OMP_DEFAULT_SHARED:
    4307                 :         183 :           OMP_CLAUSE_DEFAULT_KIND (c) = OMP_CLAUSE_DEFAULT_SHARED;
    4308                 :         183 :           break;
    4309                 :          24 :         case OMP_DEFAULT_PRIVATE:
    4310                 :          24 :           OMP_CLAUSE_DEFAULT_KIND (c) = OMP_CLAUSE_DEFAULT_PRIVATE;
    4311                 :          24 :           break;
    4312                 :           8 :         case OMP_DEFAULT_FIRSTPRIVATE:
    4313                 :           8 :           OMP_CLAUSE_DEFAULT_KIND (c) = OMP_CLAUSE_DEFAULT_FIRSTPRIVATE;
    4314                 :           8 :           break;
    4315                 :         190 :         case OMP_DEFAULT_PRESENT:
    4316                 :         190 :           OMP_CLAUSE_DEFAULT_KIND (c) = OMP_CLAUSE_DEFAULT_PRESENT;
    4317                 :         190 :           break;
    4318                 :           0 :         default:
    4319                 :           0 :           gcc_unreachable ();
    4320                 :             :         }
    4321                 :        1046 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4322                 :             :     }
    4323                 :             : 
    4324                 :       28947 :   if (clauses->nowait)
    4325                 :             :     {
    4326                 :        1749 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_NOWAIT);
    4327                 :        1749 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4328                 :             :     }
    4329                 :             : 
    4330                 :       28947 :   if (clauses->ordered)
    4331                 :             :     {
    4332                 :         312 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_ORDERED);
    4333                 :         312 :       OMP_CLAUSE_ORDERED_EXPR (c)
    4334                 :         312 :         = clauses->orderedc ? build_int_cst (integer_type_node,
    4335                 :         131 :                                              clauses->orderedc) : NULL_TREE;
    4336                 :         312 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4337                 :             :     }
    4338                 :             : 
    4339                 :       28947 :   if (clauses->order_concurrent)
    4340                 :             :     {
    4341                 :         303 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_ORDER);
    4342                 :         303 :       OMP_CLAUSE_ORDER_UNCONSTRAINED (c) = clauses->order_unconstrained;
    4343                 :         303 :       OMP_CLAUSE_ORDER_REPRODUCIBLE (c) = clauses->order_reproducible;
    4344                 :         303 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4345                 :             :     }
    4346                 :             : 
    4347                 :       28947 :   if (clauses->untied)
    4348                 :             :     {
    4349                 :         141 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_UNTIED);
    4350                 :         141 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4351                 :             :     }
    4352                 :             : 
    4353                 :       28947 :   if (clauses->mergeable)
    4354                 :             :     {
    4355                 :          32 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_MERGEABLE);
    4356                 :          32 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4357                 :             :     }
    4358                 :             : 
    4359                 :       28947 :   if (clauses->collapse)
    4360                 :             :     {
    4361                 :        1581 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_COLLAPSE);
    4362                 :        1581 :       OMP_CLAUSE_COLLAPSE_EXPR (c)
    4363                 :        1581 :         = build_int_cst (integer_type_node, clauses->collapse);
    4364                 :        1581 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4365                 :             :     }
    4366                 :             : 
    4367                 :       28947 :   if (clauses->inbranch)
    4368                 :             :     {
    4369                 :          18 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_INBRANCH);
    4370                 :          18 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4371                 :             :     }
    4372                 :             : 
    4373                 :       28947 :   if (clauses->notinbranch)
    4374                 :             :     {
    4375                 :          28 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_NOTINBRANCH);
    4376                 :          28 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4377                 :             :     }
    4378                 :             : 
    4379                 :       28947 :   switch (clauses->cancel)
    4380                 :             :     {
    4381                 :             :     case OMP_CANCEL_UNKNOWN:
    4382                 :             :       break;
    4383                 :           0 :     case OMP_CANCEL_PARALLEL:
    4384                 :           0 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_PARALLEL);
    4385                 :           0 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4386                 :           0 :       break;
    4387                 :           0 :     case OMP_CANCEL_SECTIONS:
    4388                 :           0 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_SECTIONS);
    4389                 :           0 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4390                 :           0 :       break;
    4391                 :           0 :     case OMP_CANCEL_DO:
    4392                 :           0 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_FOR);
    4393                 :           0 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4394                 :           0 :       break;
    4395                 :           0 :     case OMP_CANCEL_TASKGROUP:
    4396                 :           0 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_TASKGROUP);
    4397                 :           0 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4398                 :           0 :       break;
    4399                 :             :     }
    4400                 :             : 
    4401                 :       28947 :   if (clauses->proc_bind != OMP_PROC_BIND_UNKNOWN)
    4402                 :             :     {
    4403                 :          64 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_PROC_BIND);
    4404                 :          64 :       switch (clauses->proc_bind)
    4405                 :             :         {
    4406                 :           1 :         case OMP_PROC_BIND_PRIMARY:
    4407                 :           1 :           OMP_CLAUSE_PROC_BIND_KIND (c) = OMP_CLAUSE_PROC_BIND_PRIMARY;
    4408                 :           1 :           break;
    4409                 :           9 :         case OMP_PROC_BIND_MASTER:
    4410                 :           9 :           OMP_CLAUSE_PROC_BIND_KIND (c) = OMP_CLAUSE_PROC_BIND_MASTER;
    4411                 :           9 :           break;
    4412                 :          53 :         case OMP_PROC_BIND_SPREAD:
    4413                 :          53 :           OMP_CLAUSE_PROC_BIND_KIND (c) = OMP_CLAUSE_PROC_BIND_SPREAD;
    4414                 :          53 :           break;
    4415                 :           1 :         case OMP_PROC_BIND_CLOSE:
    4416                 :           1 :           OMP_CLAUSE_PROC_BIND_KIND (c) = OMP_CLAUSE_PROC_BIND_CLOSE;
    4417                 :           1 :           break;
    4418                 :           0 :         default:
    4419                 :           0 :           gcc_unreachable ();
    4420                 :             :         }
    4421                 :          64 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4422                 :             :     }
    4423                 :             : 
    4424                 :       28947 :   if (clauses->safelen_expr)
    4425                 :             :     {
    4426                 :          89 :       tree safelen_var;
    4427                 :             : 
    4428                 :          89 :       gfc_init_se (&se, NULL);
    4429                 :          89 :       gfc_conv_expr (&se, clauses->safelen_expr);
    4430                 :          89 :       gfc_add_block_to_block (block, &se.pre);
    4431                 :          89 :       safelen_var = gfc_evaluate_now (se.expr, block);
    4432                 :          89 :       gfc_add_block_to_block (block, &se.post);
    4433                 :             : 
    4434                 :          89 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_SAFELEN);
    4435                 :          89 :       OMP_CLAUSE_SAFELEN_EXPR (c) = safelen_var;
    4436                 :          89 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4437                 :             :     }
    4438                 :             : 
    4439                 :       28947 :   if (clauses->simdlen_expr)
    4440                 :             :     {
    4441                 :         110 :       if (declare_simd)
    4442                 :             :         {
    4443                 :          65 :           c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_SIMDLEN);
    4444                 :          65 :           OMP_CLAUSE_SIMDLEN_EXPR (c)
    4445                 :          65 :             = gfc_conv_constant_to_tree (clauses->simdlen_expr);
    4446                 :          65 :           omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4447                 :             :         }
    4448                 :             :       else
    4449                 :             :         {
    4450                 :          45 :           tree simdlen_var;
    4451                 :             : 
    4452                 :          45 :           gfc_init_se (&se, NULL);
    4453                 :          45 :           gfc_conv_expr (&se, clauses->simdlen_expr);
    4454                 :          45 :           gfc_add_block_to_block (block, &se.pre);
    4455                 :          45 :           simdlen_var = gfc_evaluate_now (se.expr, block);
    4456                 :          45 :           gfc_add_block_to_block (block, &se.post);
    4457                 :             : 
    4458                 :          45 :           c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_SIMDLEN);
    4459                 :          45 :           OMP_CLAUSE_SIMDLEN_EXPR (c) = simdlen_var;
    4460                 :          45 :           omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4461                 :             :         }
    4462                 :             :     }
    4463                 :             : 
    4464                 :       28947 :   if (clauses->num_teams_upper)
    4465                 :             :     {
    4466                 :         111 :       tree num_teams_lower = NULL_TREE, num_teams_upper;
    4467                 :             : 
    4468                 :         111 :       gfc_init_se (&se, NULL);
    4469                 :         111 :       gfc_conv_expr (&se, clauses->num_teams_upper);
    4470                 :         111 :       gfc_add_block_to_block (block, &se.pre);
    4471                 :         111 :       num_teams_upper = gfc_evaluate_now (se.expr, block);
    4472                 :         111 :       gfc_add_block_to_block (block, &se.post);
    4473                 :             : 
    4474                 :         111 :       if (clauses->num_teams_lower)
    4475                 :             :         {
    4476                 :          21 :           gfc_init_se (&se, NULL);
    4477                 :          21 :           gfc_conv_expr (&se, clauses->num_teams_lower);
    4478                 :          21 :           gfc_add_block_to_block (block, &se.pre);
    4479                 :          21 :           num_teams_lower = gfc_evaluate_now (se.expr, block);
    4480                 :          21 :           gfc_add_block_to_block (block, &se.post);
    4481                 :             :         }
    4482                 :         111 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_NUM_TEAMS);
    4483                 :         111 :       OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c) = num_teams_lower;
    4484                 :         111 :       OMP_CLAUSE_NUM_TEAMS_UPPER_EXPR (c) = num_teams_upper;
    4485                 :         111 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4486                 :             :     }
    4487                 :             : 
    4488                 :       28947 :   if (clauses->device)
    4489                 :             :     {
    4490                 :         205 :       tree device;
    4491                 :             : 
    4492                 :         205 :       gfc_init_se (&se, NULL);
    4493                 :         205 :       gfc_conv_expr (&se, clauses->device);
    4494                 :         205 :       gfc_add_block_to_block (block, &se.pre);
    4495                 :         205 :       device = gfc_evaluate_now (se.expr, block);
    4496                 :         205 :       gfc_add_block_to_block (block, &se.post);
    4497                 :             : 
    4498                 :         205 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_DEVICE);
    4499                 :         205 :       OMP_CLAUSE_DEVICE_ID (c) = device;
    4500                 :             : 
    4501                 :         205 :       if (clauses->ancestor)
    4502                 :          39 :         OMP_CLAUSE_DEVICE_ANCESTOR (c) = 1;
    4503                 :             : 
    4504                 :         205 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4505                 :             :     }
    4506                 :             : 
    4507                 :       28947 :   if (clauses->thread_limit)
    4508                 :             :     {
    4509                 :         105 :       tree thread_limit;
    4510                 :             : 
    4511                 :         105 :       gfc_init_se (&se, NULL);
    4512                 :         105 :       gfc_conv_expr (&se, clauses->thread_limit);
    4513                 :         105 :       gfc_add_block_to_block (block, &se.pre);
    4514                 :         105 :       thread_limit = gfc_evaluate_now (se.expr, block);
    4515                 :         105 :       gfc_add_block_to_block (block, &se.post);
    4516                 :             : 
    4517                 :         105 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_THREAD_LIMIT);
    4518                 :         105 :       OMP_CLAUSE_THREAD_LIMIT_EXPR (c) = thread_limit;
    4519                 :         105 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4520                 :             :     }
    4521                 :             : 
    4522                 :       28947 :   chunk_size = NULL_TREE;
    4523                 :       28947 :   if (clauses->dist_chunk_size)
    4524                 :             :     {
    4525                 :          81 :       gfc_init_se (&se, NULL);
    4526                 :          81 :       gfc_conv_expr (&se, clauses->dist_chunk_size);
    4527                 :          81 :       gfc_add_block_to_block (block, &se.pre);
    4528                 :          81 :       chunk_size = gfc_evaluate_now (se.expr, block);
    4529                 :          81 :       gfc_add_block_to_block (block, &se.post);
    4530                 :             :     }
    4531                 :             : 
    4532                 :       28947 :   if (clauses->dist_sched_kind != OMP_SCHED_NONE)
    4533                 :             :     {
    4534                 :          94 :       c = build_omp_clause (gfc_get_location (&where),
    4535                 :             :                             OMP_CLAUSE_DIST_SCHEDULE);
    4536                 :          94 :       OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c) = chunk_size;
    4537                 :          94 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4538                 :             :     }
    4539                 :             : 
    4540                 :       28947 :   if (clauses->grainsize)
    4541                 :             :     {
    4542                 :          43 :       tree grainsize;
    4543                 :             : 
    4544                 :          43 :       gfc_init_se (&se, NULL);
    4545                 :          43 :       gfc_conv_expr (&se, clauses->grainsize);
    4546                 :          43 :       gfc_add_block_to_block (block, &se.pre);
    4547                 :          43 :       grainsize = gfc_evaluate_now (se.expr, block);
    4548                 :          43 :       gfc_add_block_to_block (block, &se.post);
    4549                 :             : 
    4550                 :          43 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_GRAINSIZE);
    4551                 :          43 :       OMP_CLAUSE_GRAINSIZE_EXPR (c) = grainsize;
    4552                 :          43 :       if (clauses->grainsize_strict)
    4553                 :           6 :         OMP_CLAUSE_GRAINSIZE_STRICT (c) = 1;
    4554                 :          43 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4555                 :             :     }
    4556                 :             : 
    4557                 :       28947 :   if (clauses->num_tasks)
    4558                 :             :     {
    4559                 :          35 :       tree num_tasks;
    4560                 :             : 
    4561                 :          35 :       gfc_init_se (&se, NULL);
    4562                 :          35 :       gfc_conv_expr (&se, clauses->num_tasks);
    4563                 :          35 :       gfc_add_block_to_block (block, &se.pre);
    4564                 :          35 :       num_tasks = gfc_evaluate_now (se.expr, block);
    4565                 :          35 :       gfc_add_block_to_block (block, &se.post);
    4566                 :             : 
    4567                 :          35 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_NUM_TASKS);
    4568                 :          35 :       OMP_CLAUSE_NUM_TASKS_EXPR (c) = num_tasks;
    4569                 :          35 :       if (clauses->num_tasks_strict)
    4570                 :           6 :         OMP_CLAUSE_NUM_TASKS_STRICT (c) = 1;
    4571                 :          35 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4572                 :             :     }
    4573                 :             : 
    4574                 :       28947 :   if (clauses->priority)
    4575                 :             :     {
    4576                 :          34 :       tree priority;
    4577                 :             : 
    4578                 :          34 :       gfc_init_se (&se, NULL);
    4579                 :          34 :       gfc_conv_expr (&se, clauses->priority);
    4580                 :          34 :       gfc_add_block_to_block (block, &se.pre);
    4581                 :          34 :       priority = gfc_evaluate_now (se.expr, block);
    4582                 :          34 :       gfc_add_block_to_block (block, &se.post);
    4583                 :             : 
    4584                 :          34 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_PRIORITY);
    4585                 :          34 :       OMP_CLAUSE_PRIORITY_EXPR (c) = priority;
    4586                 :          34 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4587                 :             :     }
    4588                 :             : 
    4589                 :       28947 :   if (clauses->detach)
    4590                 :             :     {
    4591                 :         116 :       tree detach;
    4592                 :             : 
    4593                 :         116 :       gfc_init_se (&se, NULL);
    4594                 :         116 :       gfc_conv_expr (&se, clauses->detach);
    4595                 :         116 :       gfc_add_block_to_block (block, &se.pre);
    4596                 :         116 :       detach = se.expr;
    4597                 :         116 :       gfc_add_block_to_block (block, &se.post);
    4598                 :             : 
    4599                 :         116 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_DETACH);
    4600                 :         116 :       TREE_ADDRESSABLE (detach) = 1;
    4601                 :         116 :       OMP_CLAUSE_DECL (c) = detach;
    4602                 :         116 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4603                 :             :     }
    4604                 :             : 
    4605                 :       28947 :   if (clauses->filter)
    4606                 :             :     {
    4607                 :          31 :       tree filter;
    4608                 :             : 
    4609                 :          31 :       gfc_init_se (&se, NULL);
    4610                 :          31 :       gfc_conv_expr (&se, clauses->filter);
    4611                 :          31 :       gfc_add_block_to_block (block, &se.pre);
    4612                 :          31 :       filter = gfc_evaluate_now (se.expr, block);
    4613                 :          31 :       gfc_add_block_to_block (block, &se.post);
    4614                 :             : 
    4615                 :          31 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_FILTER);
    4616                 :          31 :       OMP_CLAUSE_FILTER_EXPR (c) = filter;
    4617                 :          31 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4618                 :             :     }
    4619                 :             : 
    4620                 :       28947 :   if (clauses->hint)
    4621                 :             :     {
    4622                 :           8 :       tree hint;
    4623                 :             : 
    4624                 :           8 :       gfc_init_se (&se, NULL);
    4625                 :           8 :       gfc_conv_expr (&se, clauses->hint);
    4626                 :           8 :       gfc_add_block_to_block (block, &se.pre);
    4627                 :           8 :       hint = gfc_evaluate_now (se.expr, block);
    4628                 :           8 :       gfc_add_block_to_block (block, &se.post);
    4629                 :             : 
    4630                 :           8 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_HINT);
    4631                 :           8 :       OMP_CLAUSE_HINT_EXPR (c) = hint;
    4632                 :           8 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4633                 :             :     }
    4634                 :             : 
    4635                 :       28947 :   if (clauses->simd)
    4636                 :             :     {
    4637                 :          22 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_SIMD);
    4638                 :          22 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4639                 :             :     }
    4640                 :       28947 :   if (clauses->threads)
    4641                 :             :     {
    4642                 :          11 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_THREADS);
    4643                 :          11 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4644                 :             :     }
    4645                 :       28947 :   if (clauses->nogroup)
    4646                 :             :     {
    4647                 :          13 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_NOGROUP);
    4648                 :          13 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4649                 :             :     }
    4650                 :             : 
    4651                 :      202629 :   for (int i = 0; i < OMP_DEFAULTMAP_CAT_NUM; i++)
    4652                 :             :     {
    4653                 :      173682 :       if (clauses->defaultmap[i] == OMP_DEFAULTMAP_UNSET)
    4654                 :      173539 :        continue;
    4655                 :         143 :       enum omp_clause_defaultmap_kind behavior, category;
    4656                 :         143 :       switch ((gfc_omp_defaultmap_category) i)
    4657                 :             :         {
    4658                 :             :         case OMP_DEFAULTMAP_CAT_UNCATEGORIZED:
    4659                 :             :           category = OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED;
    4660                 :             :           break;
    4661                 :             :         case OMP_DEFAULTMAP_CAT_ALL:
    4662                 :             :           category = OMP_CLAUSE_DEFAULTMAP_CATEGORY_ALL;
    4663                 :             :           break;
    4664                 :             :         case OMP_DEFAULTMAP_CAT_SCALAR:
    4665                 :             :           category = OMP_CLAUSE_DEFAULTMAP_CATEGORY_SCALAR;
    4666                 :             :           break;
    4667                 :             :         case OMP_DEFAULTMAP_CAT_AGGREGATE:
    4668                 :             :           category = OMP_CLAUSE_DEFAULTMAP_CATEGORY_AGGREGATE;
    4669                 :             :           break;
    4670                 :             :         case OMP_DEFAULTMAP_CAT_ALLOCATABLE:
    4671                 :             :           category = OMP_CLAUSE_DEFAULTMAP_CATEGORY_ALLOCATABLE;
    4672                 :             :           break;
    4673                 :             :         case OMP_DEFAULTMAP_CAT_POINTER:
    4674                 :             :           category = OMP_CLAUSE_DEFAULTMAP_CATEGORY_POINTER;
    4675                 :             :           break;
    4676                 :             :         default: gcc_unreachable ();
    4677                 :             :         }
    4678                 :         143 :       switch (clauses->defaultmap[i])
    4679                 :             :         {
    4680                 :             :         case OMP_DEFAULTMAP_ALLOC:
    4681                 :             :           behavior = OMP_CLAUSE_DEFAULTMAP_ALLOC;
    4682                 :             :           break;
    4683                 :             :         case OMP_DEFAULTMAP_TO: behavior = OMP_CLAUSE_DEFAULTMAP_TO; break;
    4684                 :             :         case OMP_DEFAULTMAP_FROM: behavior = OMP_CLAUSE_DEFAULTMAP_FROM; break;
    4685                 :             :         case OMP_DEFAULTMAP_TOFROM:
    4686                 :             :           behavior = OMP_CLAUSE_DEFAULTMAP_TOFROM;
    4687                 :             :           break;
    4688                 :             :         case OMP_DEFAULTMAP_FIRSTPRIVATE:
    4689                 :             :           behavior = OMP_CLAUSE_DEFAULTMAP_FIRSTPRIVATE;
    4690                 :             :           break;
    4691                 :             :         case OMP_DEFAULTMAP_PRESENT:
    4692                 :             :           behavior = OMP_CLAUSE_DEFAULTMAP_PRESENT;
    4693                 :             :           break;
    4694                 :             :         case OMP_DEFAULTMAP_NONE: behavior = OMP_CLAUSE_DEFAULTMAP_NONE; break;
    4695                 :             :         case OMP_DEFAULTMAP_DEFAULT:
    4696                 :             :           behavior = OMP_CLAUSE_DEFAULTMAP_DEFAULT;
    4697                 :             :           break;
    4698                 :           0 :         default: gcc_unreachable ();
    4699                 :             :         }
    4700                 :         143 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_DEFAULTMAP);
    4701                 :         143 :       OMP_CLAUSE_DEFAULTMAP_SET_KIND (c, behavior, category);
    4702                 :         143 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4703                 :             :     }
    4704                 :             : 
    4705                 :       28947 :   if (clauses->doacross_source)
    4706                 :             :     {
    4707                 :         131 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_DOACROSS);
    4708                 :         131 :       OMP_CLAUSE_DOACROSS_KIND (c) = OMP_CLAUSE_DOACROSS_SOURCE;
    4709                 :         131 :       OMP_CLAUSE_DOACROSS_DEPEND (c) = clauses->depend_source;
    4710                 :         131 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4711                 :             :     }
    4712                 :             : 
    4713                 :       28947 :   if (clauses->async)
    4714                 :             :     {
    4715                 :         539 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_ASYNC);
    4716                 :         539 :       if (clauses->async_expr)
    4717                 :         539 :         OMP_CLAUSE_ASYNC_EXPR (c)
    4718                 :        1078 :           = gfc_convert_expr_to_tree (block, clauses->async_expr);
    4719                 :             :       else
    4720                 :           0 :         OMP_CLAUSE_ASYNC_EXPR (c) = NULL;
    4721                 :         539 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4722                 :             :     }
    4723                 :       28947 :   if (clauses->seq)
    4724                 :             :     {
    4725                 :         113 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_SEQ);
    4726                 :         113 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4727                 :             :     }
    4728                 :       28947 :   if (clauses->par_auto)
    4729                 :             :     {
    4730                 :          46 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_AUTO);
    4731                 :          46 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4732                 :             :     }
    4733                 :       28947 :   if (clauses->if_present)
    4734                 :             :     {
    4735                 :          23 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_IF_PRESENT);
    4736                 :          23 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4737                 :             :     }
    4738                 :       28947 :   if (clauses->finalize)
    4739                 :             :     {
    4740                 :          15 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_FINALIZE);
    4741                 :          15 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4742                 :             :     }
    4743                 :       28947 :   if (clauses->independent)
    4744                 :             :     {
    4745                 :         184 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_INDEPENDENT);
    4746                 :         184 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4747                 :             :     }
    4748                 :       28947 :   if (clauses->wait_list)
    4749                 :             :     {
    4750                 :             :       gfc_expr_list *el;
    4751                 :             : 
    4752                 :         317 :       for (el = clauses->wait_list; el; el = el->next)
    4753                 :             :         {
    4754                 :         172 :           c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_WAIT);
    4755                 :         172 :           OMP_CLAUSE_DECL (c) = gfc_convert_expr_to_tree (block, el->expr);
    4756                 :         172 :           OMP_CLAUSE_CHAIN (c) = omp_clauses;
    4757                 :         172 :           omp_clauses = c;
    4758                 :             :         }
    4759                 :             :     }
    4760                 :       28947 :   if (clauses->num_gangs_expr)
    4761                 :             :     {
    4762                 :         666 :       tree num_gangs_var
    4763                 :         666 :         = gfc_convert_expr_to_tree (block, clauses->num_gangs_expr);
    4764                 :         666 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_NUM_GANGS);
    4765                 :         666 :       OMP_CLAUSE_NUM_GANGS_EXPR (c) = num_gangs_var;
    4766                 :         666 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4767                 :             :     }
    4768                 :       28947 :   if (clauses->num_workers_expr)
    4769                 :             :     {
    4770                 :         583 :       tree num_workers_var
    4771                 :         583 :         = gfc_convert_expr_to_tree (block, clauses->num_workers_expr);
    4772                 :         583 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_NUM_WORKERS);
    4773                 :         583 :       OMP_CLAUSE_NUM_WORKERS_EXPR (c) = num_workers_var;
    4774                 :         583 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4775                 :             :     }
    4776                 :       28947 :   if (clauses->vector_length_expr)
    4777                 :             :     {
    4778                 :         553 :       tree vector_length_var
    4779                 :         553 :         = gfc_convert_expr_to_tree (block, clauses->vector_length_expr);
    4780                 :         553 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_VECTOR_LENGTH);
    4781                 :         553 :       OMP_CLAUSE_VECTOR_LENGTH_EXPR (c) = vector_length_var;
    4782                 :         553 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4783                 :             :     }
    4784                 :       28947 :   if (clauses->tile_list)
    4785                 :             :     {
    4786                 :          59 :       vec<tree, va_gc> *tvec;
    4787                 :          59 :       gfc_expr_list *el;
    4788                 :             : 
    4789                 :          59 :       vec_alloc (tvec, 4);
    4790                 :             : 
    4791                 :         171 :       for (el = clauses->tile_list; el; el = el->next)
    4792                 :         112 :         vec_safe_push (tvec, gfc_convert_expr_to_tree (block, el->expr));
    4793                 :             : 
    4794                 :          59 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_TILE);
    4795                 :          59 :       OMP_CLAUSE_TILE_LIST (c) = build_tree_list_vec (tvec);
    4796                 :          59 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4797                 :          59 :       tvec->truncate (0);
    4798                 :             :     }
    4799                 :       28947 :   if (clauses->vector)
    4800                 :             :     {
    4801                 :         791 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_VECTOR);
    4802                 :         791 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4803                 :             : 
    4804                 :         791 :       if (clauses->vector_expr)
    4805                 :             :         {
    4806                 :         115 :           tree vector_var
    4807                 :         115 :             = gfc_convert_expr_to_tree (block, clauses->vector_expr);
    4808                 :         115 :           OMP_CLAUSE_VECTOR_EXPR (c) = vector_var;
    4809                 :             : 
    4810                 :             :           /* TODO: We're not capturing location information for individual
    4811                 :             :              clauses.  However, if we have an expression attached to the
    4812                 :             :              clause, that one provides better location information.  */
    4813                 :         230 :           OMP_CLAUSE_LOCATION (c)
    4814                 :         115 :             = gfc_get_location (&clauses->vector_expr->where);
    4815                 :             :         }
    4816                 :             :     }
    4817                 :       28947 :   if (clauses->worker)
    4818                 :             :     {
    4819                 :         685 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_WORKER);
    4820                 :         685 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4821                 :             : 
    4822                 :         685 :       if (clauses->worker_expr)
    4823                 :             :         {
    4824                 :          85 :           tree worker_var
    4825                 :          85 :             = gfc_convert_expr_to_tree (block, clauses->worker_expr);
    4826                 :          85 :           OMP_CLAUSE_WORKER_EXPR (c) = worker_var;
    4827                 :             : 
    4828                 :             :           /* TODO: We're not capturing location information for individual
    4829                 :             :              clauses.  However, if we have an expression attached to the
    4830                 :             :              clause, that one provides better location information.  */
    4831                 :         170 :           OMP_CLAUSE_LOCATION (c)
    4832                 :          85 :             = gfc_get_location (&clauses->worker_expr->where);
    4833                 :             :         }
    4834                 :             :     }
    4835                 :       28947 :   if (clauses->gang)
    4836                 :             :     {
    4837                 :         951 :       tree arg;
    4838                 :         951 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_GANG);
    4839                 :         951 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4840                 :             : 
    4841                 :         951 :       if (clauses->gang_num_expr)
    4842                 :             :         {
    4843                 :          97 :           arg = gfc_convert_expr_to_tree (block, clauses->gang_num_expr);
    4844                 :          97 :           OMP_CLAUSE_GANG_EXPR (c) = arg;
    4845                 :             : 
    4846                 :             :           /* TODO: We're not capturing location information for individual
    4847                 :             :              clauses.  However, if we have an expression attached to the
    4848                 :             :              clause, that one provides better location information.  */
    4849                 :         194 :           OMP_CLAUSE_LOCATION (c)
    4850                 :          97 :             = gfc_get_location (&clauses->gang_num_expr->where);
    4851                 :             :         }
    4852                 :             : 
    4853                 :         951 :       if (clauses->gang_static)
    4854                 :             :         {
    4855                 :         190 :           arg = clauses->gang_static_expr
    4856                 :          95 :             ? gfc_convert_expr_to_tree (block, clauses->gang_static_expr)
    4857                 :             :             : integer_minus_one_node;
    4858                 :          95 :           OMP_CLAUSE_GANG_STATIC_EXPR (c) = arg;
    4859                 :             :         }
    4860                 :             :     }
    4861                 :       28947 :   if (clauses->bind != OMP_BIND_UNSET)
    4862                 :             :     {
    4863                 :          30 :       c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_BIND);
    4864                 :          30 :       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
    4865                 :          30 :       switch (clauses->bind)
    4866                 :             :         {
    4867                 :          10 :         case OMP_BIND_TEAMS:
    4868                 :          10 :           OMP_CLAUSE_BIND_KIND (c) = OMP_CLAUSE_BIND_TEAMS;
    4869                 :          10 :           break;
    4870                 :          15 :         case OMP_BIND_PARALLEL:
    4871                 :          15 :           OMP_CLAUSE_BIND_KIND (c) = OMP_CLAUSE_BIND_PARALLEL;
    4872                 :          15 :           break;
    4873                 :           5 :         case OMP_BIND_THREAD:
    4874                 :           5 :           OMP_CLAUSE_BIND_KIND (c) = OMP_CLAUSE_BIND_THREAD;
    4875                 :           5 :           break;
    4876                 :           0 :         default:
    4877                 :           0 :           gcc_unreachable ();
    4878                 :             :         }
    4879                 :             :     }
    4880                 :             :   /* OpenACC 'nohost' clauses cannot appear here.  */
    4881                 :       28947 :   gcc_checking_assert (!clauses->nohost);
    4882                 :             : 
    4883                 :       28947 :   return nreverse (omp_clauses);
    4884                 :             : }
    4885                 :             : 
    4886                 :             : /* Like gfc_trans_code, but force creation of a BIND_EXPR around it.  */
    4887                 :             : 
    4888                 :             : static tree
    4889                 :       19302 : gfc_trans_omp_code (gfc_code *code, bool force_empty)
    4890                 :             : {
    4891                 :       19302 :   tree stmt;
    4892                 :             : 
    4893                 :       19302 :   pushlevel ();
    4894                 :       19302 :   stmt = gfc_trans_code (code);
    4895                 :       19302 :   if (TREE_CODE (stmt) != BIND_EXPR)
    4896                 :             :     {
    4897                 :       17222 :       if (!IS_EMPTY_STMT (stmt) || force_empty)
    4898                 :             :         {
    4899                 :       17132 :           tree block = poplevel (1, 0);
    4900                 :       17132 :           stmt = build3_v (BIND_EXPR, NULL, stmt, block);
    4901                 :             :         }
    4902                 :             :       else
    4903                 :          90 :         poplevel (0, 0);
    4904                 :             :     }
    4905                 :             :   else
    4906                 :        2080 :     poplevel (0, 0);
    4907                 :       19302 :   return stmt;
    4908                 :             : }
    4909                 :             : 
    4910                 :             : /* Translate OpenACC 'parallel', 'kernels', 'serial', 'data', 'host_data'
    4911                 :             :    construct. */
    4912                 :             : 
    4913                 :             : static tree
    4914                 :        4021 : gfc_trans_oacc_construct (gfc_code *code)
    4915                 :             : {
    4916                 :        4021 :   stmtblock_t block;
    4917                 :        4021 :   tree stmt, oacc_clauses;
    4918                 :        4021 :   enum tree_code construct_code;
    4919                 :             : 
    4920                 :        4021 :   switch (code->op)
    4921                 :             :     {
    4922                 :             :       case EXEC_OACC_PARALLEL:
    4923                 :             :         construct_code = OACC_PARALLEL;
    4924                 :             :         break;
    4925                 :             :       case EXEC_OACC_KERNELS:
    4926                 :             :         construct_code = OACC_KERNELS;
    4927                 :             :         break;
    4928                 :             :       case EXEC_OACC_SERIAL:
    4929                 :             :         construct_code = OACC_SERIAL;
    4930                 :             :         break;
    4931                 :             :       case EXEC_OACC_DATA:
    4932                 :             :         construct_code = OACC_DATA;
    4933                 :             :         break;
    4934                 :             :       case EXEC_OACC_HOST_DATA:
    4935                 :             :         construct_code = OACC_HOST_DATA;
    4936                 :             :         break;
    4937                 :           0 :       default:
    4938                 :           0 :         gcc_unreachable ();
    4939                 :             :     }
    4940                 :             : 
    4941                 :        4021 :   gfc_start_block (&block);
    4942                 :        4021 :   oacc_clauses = gfc_trans_omp_clauses (&block, code->ext.omp_clauses,
    4943                 :             :                                         code->loc, false, true);
    4944                 :        4021 :   pushlevel ();
    4945                 :        4021 :   stmt = gfc_trans_omp_code (code->block->next, true);
    4946                 :        4021 :   stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
    4947                 :        4021 :   stmt = build2_loc (gfc_get_location (&code->loc), construct_code,
    4948                 :             :                      void_type_node, stmt, oacc_clauses);
    4949                 :        4021 :   gfc_add_expr_to_block (&block, stmt);
    4950                 :        4021 :   return gfc_finish_block (&block);
    4951                 :             : }
    4952                 :             : 
    4953                 :             : /* update, enter_data, exit_data, cache. */
    4954                 :             : static tree 
    4955                 :        2075 : gfc_trans_oacc_executable_directive (gfc_code *code)
    4956                 :             : {
    4957                 :        2075 :   stmtblock_t block;
    4958                 :        2075 :   tree stmt, oacc_clauses;
    4959                 :        2075 :   enum tree_code construct_code;
    4960                 :             : 
    4961                 :        2075 :   switch (code->op)
    4962                 :             :     {
    4963                 :             :       case EXEC_OACC_UPDATE:
    4964                 :             :         construct_code = OACC_UPDATE;
    4965                 :             :         break;
    4966                 :         767 :       case EXEC_OACC_ENTER_DATA:
    4967                 :         767 :         construct_code = OACC_ENTER_DATA;
    4968                 :         767 :         break;
    4969                 :         545 :       case EXEC_OACC_EXIT_DATA:
    4970                 :         545 :         construct_code = OACC_EXIT_DATA;
    4971                 :         545 :         break;
    4972                 :          74 :       case EXEC_OACC_CACHE:
    4973                 :          74 :         construct_code = OACC_CACHE;
    4974                 :          74 :         break;
    4975                 :           0 :       default:
    4976                 :           0 :         gcc_unreachable ();
    4977                 :             :     }
    4978                 :             : 
    4979                 :        2075 :   gfc_start_block (&block);
    4980                 :        2075 :   oacc_clauses = gfc_trans_omp_clauses (&block, code->ext.omp_clauses,
    4981                 :             :                                         code->loc, false, true, code->op);
    4982                 :        2075 :   stmt = build1_loc (input_location, construct_code, void_type_node, 
    4983                 :             :                      oacc_clauses);
    4984                 :        2075 :   gfc_add_expr_to_block (&block, stmt);
    4985                 :        2075 :   return gfc_finish_block (&block);
    4986                 :             : }
    4987                 :             : 
    4988                 :             : static tree
    4989                 :         167 : gfc_trans_oacc_wait_directive (gfc_code *code)
    4990                 :             : {
    4991                 :         167 :   stmtblock_t block;
    4992                 :         167 :   tree stmt, t;
    4993                 :         167 :   vec<tree, va_gc> *args;
    4994                 :         167 :   int nparms = 0;
    4995                 :         167 :   gfc_expr_list *el;
    4996                 :         167 :   gfc_omp_clauses *clauses = code->ext.omp_clauses;
    4997                 :         167 :   location_t loc = input_location;
    4998                 :             : 
    4999                 :         291 :   for (el = clauses->wait_list; el; el = el->next)
    5000                 :         124 :     nparms++;
    5001                 :             : 
    5002                 :         167 :   vec_alloc (args, nparms + 2);
    5003                 :         167 :   stmt = builtin_decl_explicit (BUILT_IN_GOACC_WAIT);
    5004                 :             : 
    5005                 :         167 :   gfc_start_block (&block);
    5006                 :             : 
    5007                 :         167 :   if (clauses->async_expr)
    5008                 :           0 :     t = gfc_convert_expr_to_tree (&block, clauses->async_expr);
    5009                 :             :   else
    5010                 :         167 :     t = build_int_cst (integer_type_node, -2);
    5011                 :             : 
    5012                 :         167 :   args->quick_push (t);
    5013                 :         167 :   args->quick_push (build_int_cst (integer_type_node, nparms));
    5014                 :             : 
    5015                 :         291 :   for (el = clauses->wait_list; el; el = el->next)
    5016                 :         124 :     args->quick_push (gfc_convert_expr_to_tree (&block, el->expr));
    5017                 :             : 
    5018                 :         167 :   stmt = build_call_expr_loc_vec (loc, stmt, args);
    5019                 :         167 :   gfc_add_expr_to_block (&block, stmt);
    5020                 :             : 
    5021                 :         167 :   vec_free (args);
    5022                 :             : 
    5023                 :         167 :   return gfc_finish_block (&block);
    5024                 :             : }
    5025                 :             : 
    5026                 :             : static tree gfc_trans_omp_sections (gfc_code *, gfc_omp_clauses *);
    5027                 :             : static tree gfc_trans_omp_workshare (gfc_code *, gfc_omp_clauses *);
    5028                 :             : 
    5029                 :             : static tree
    5030                 :          31 : gfc_trans_omp_allocators (gfc_code *code)
    5031                 :             : {
    5032                 :          31 :   static bool warned = false;
    5033                 :          31 :   gfc_omp_namelist *omp_allocate
    5034                 :          31 :     = code->ext.omp_clauses->lists[OMP_LIST_ALLOCATE];
    5035                 :          31 :   if (!flag_openmp_allocators && !warned)
    5036                 :             :     {
    5037                 :           2 :       omp_allocate = NULL;
    5038                 :           2 :       gfc_error ("%<!$OMP %s%> at %L requires %<-fopenmp-allocators%>",
    5039                 :           2 :                  code->op == EXEC_OMP_ALLOCATE ? "ALLOCATE" : "ALLOCATORS",
    5040                 :             :                  &code->loc);
    5041                 :           2 :       warning (0, "All files that might deallocate such a variable must be "
    5042                 :             :                   "compiled with %<-fopenmp-allocators%>");
    5043                 :           2 :       inform (UNKNOWN_LOCATION,
    5044                 :             :               "This includes explicit DEALLOCATE, reallocation on intrinsic "
    5045                 :             :               "assignment, INTENT(OUT) for allocatable dummy arguments, and "
    5046                 :             :               "reallocation of allocatable components allocated with an "
    5047                 :             :               "OpenMP allocator");
    5048                 :           2 :       warned = true;
    5049                 :             :     }
    5050                 :          31 :   return gfc_trans_allocate (code->block->next, omp_allocate);
    5051                 :             : }
    5052                 :             : 
    5053                 :             : static tree
    5054                 :          10 : gfc_trans_omp_assume (gfc_code *code)
    5055                 :             : {
    5056                 :          10 :   stmtblock_t block;
    5057                 :          10 :   gfc_init_block (&block);
    5058                 :          10 :   gfc_omp_assumptions *assume = code->ext.omp_clauses->assume;
    5059                 :          10 :   if (assume)
    5060                 :          19 :     for (gfc_expr_list *el = assume->holds; el; el = el->next)
    5061                 :             :       {
    5062                 :           9 :         location_t loc = gfc_get_location (&el->expr->where);
    5063                 :           9 :         gfc_se se;
    5064                 :           9 :         gfc_init_se (&se, NULL);
    5065                 :           9 :         gfc_conv_expr (&se, el->expr);
    5066                 :           9 :         tree t;
    5067                 :           9 :         if (se.pre.head == NULL_TREE && se.post.head == NULL_TREE)
    5068                 :           8 :           t = se.expr;
    5069                 :             :         else
    5070                 :             :           {
    5071                 :           1 :             tree var = create_tmp_var_raw (boolean_type_node);
    5072                 :           1 :             DECL_CONTEXT (var) = current_function_decl;
    5073                 :           1 :             stmtblock_t block2;
    5074                 :           1 :             gfc_init_block (&block2);
    5075                 :           1 :             gfc_add_block_to_block (&block2, &se.pre);
    5076                 :           1 :             gfc_add_modify_loc (loc, &block2, var,
    5077                 :             :                                 fold_convert_loc (loc, boolean_type_node,
    5078                 :             :                                                   se.expr));
    5079                 :           1 :             gfc_add_block_to_block (&block2, &se.post);
    5080                 :           1 :             t = gfc_finish_block (&block2);
    5081                 :           1 :             t = build4 (TARGET_EXPR, boolean_type_node, var, t, NULL, NULL);
    5082                 :             :           }
    5083                 :           9 :         t = build_call_expr_internal_loc (loc, IFN_ASSUME,
    5084                 :             :                                           void_type_node, 1, t);
    5085                 :           9 :         gfc_add_expr_to_block (&block, t);
    5086                 :             :       }
    5087                 :          10 :   gfc_add_expr_to_block (&block, gfc_trans_omp_code (code->block->next, true));
    5088                 :          10 :   return gfc_finish_block (&block);
    5089                 :             : }
    5090                 :             : 
    5091                 :             : static tree
    5092                 :        2589 : gfc_trans_omp_atomic (gfc_code *code)
    5093                 :             : {
    5094                 :        2589 :   gfc_code *atomic_code = code->block;
    5095                 :        2589 :   gfc_se lse;
    5096                 :        2589 :   gfc_se rse;
    5097                 :        2589 :   gfc_se vse;
    5098                 :        2589 :   gfc_expr *expr1, *expr2, *e, *capture_expr1 = NULL, *capture_expr2 = NULL;
    5099                 :        2589 :   gfc_symbol *var;
    5100                 :        2589 :   stmtblock_t block;
    5101                 :        2589 :   tree lhsaddr, type, rhs, x, compare = NULL_TREE, comp_tgt = NULL_TREE;
    5102                 :        2589 :   enum tree_code op = ERROR_MARK;
    5103                 :        2589 :   enum tree_code aop = OMP_ATOMIC;
    5104                 :        2589 :   bool var_on_left = false, else_branch = false;
    5105                 :        2589 :   enum omp_memory_order mo, fail_mo;
    5106                 :        2589 :   switch (atomic_code->ext.omp_clauses->memorder)
    5107                 :             :     {
    5108                 :             :     case OMP_MEMORDER_UNSET: mo = OMP_MEMORY_ORDER_UNSPECIFIED; break;
    5109                 :             :     case OMP_MEMORDER_ACQ_REL: mo = OMP_MEMORY_ORDER_ACQ_REL; break;
    5110                 :             :     case OMP_MEMORDER_ACQUIRE: mo = OMP_MEMORY_ORDER_ACQUIRE; break;
    5111                 :             :     case OMP_MEMORDER_RELAXED: mo = OMP_MEMORY_ORDER_RELAXED; break;
    5112                 :             :     case OMP_MEMORDER_RELEASE: mo = OMP_MEMORY_ORDER_RELEASE; break;
    5113                 :             :     case OMP_MEMORDER_SEQ_CST: mo = OMP_MEMORY_ORDER_SEQ_CST; break;
    5114                 :           0 :     default: gcc_unreachable ();
    5115                 :             :     }
    5116                 :        2589 :   switch (atomic_code->ext.omp_clauses->fail)
    5117                 :             :     {
    5118                 :             :     case OMP_MEMORDER_UNSET: fail_mo = OMP_FAIL_MEMORY_ORDER_UNSPECIFIED; break;
    5119                 :          14 :     case OMP_MEMORDER_ACQUIRE: fail_mo = OMP_FAIL_MEMORY_ORDER_ACQUIRE; break;
    5120                 :          26 :     case OMP_MEMORDER_RELAXED: fail_mo = OMP_FAIL_MEMORY_ORDER_RELAXED; break;
    5121                 :           2 :     case OMP_MEMORDER_SEQ_CST: fail_mo = OMP_FAIL_MEMORY_ORDER_SEQ_CST; break;
    5122                 :           0 :     default: gcc_unreachable ();
    5123                 :             :     }
    5124                 :        2589 :   mo = (omp_memory_order) (mo | fail_mo);
    5125                 :             : 
    5126                 :        2589 :   code = code->block->next;
    5127                 :        2589 :   if (atomic_code->ext.omp_clauses->compare)
    5128                 :             :     {
    5129                 :         144 :       gfc_expr *comp_expr;
    5130                 :         144 :       if (code->op == EXEC_IF)
    5131                 :             :         {
    5132                 :         125 :           comp_expr = code->block->expr1;
    5133                 :         125 :           gcc_assert (code->block->next->op == EXEC_ASSIGN);
    5134                 :         125 :           expr1 = code->block->next->expr1;
    5135                 :         125 :           expr2 = code->block->next->expr2;
    5136                 :         125 :           if (code->block->block)
    5137                 :             :             {
    5138                 :          64 :               gcc_assert (atomic_code->ext.omp_clauses->capture
    5139                 :             :                           && code->block->block->next->op == EXEC_ASSIGN);
    5140                 :          64 :               else_branch = true;
    5141                 :          64 :               aop = OMP_ATOMIC_CAPTURE_OLD;
    5142                 :          64 :               capture_expr1 = code->block->block->next->expr1;
    5143                 :          64 :               capture_expr2 = code->block->block->next->expr2;
    5144                 :             :             }
    5145                 :          61 :           else if (atomic_code->ext.omp_clauses->capture)
    5146                 :             :             {
    5147                 :          19 :               gcc_assert (code->next->op == EXEC_ASSIGN);
    5148                 :          19 :               aop = OMP_ATOMIC_CAPTURE_NEW;
    5149                 :          19 :               capture_expr1 = code->next->expr1;
    5150                 :          19 :               capture_expr2 = code->next->expr2;
    5151                 :             :             }
    5152                 :             :         }
    5153                 :             :       else
    5154                 :             :         {
    5155                 :          19 :           gcc_assert (atomic_code->ext.omp_clauses->capture
    5156                 :             :                       && code->op == EXEC_ASSIGN
    5157                 :             :                       && code->next->op == EXEC_IF);
    5158                 :          19 :           aop = OMP_ATOMIC_CAPTURE_OLD;
    5159                 :          19 :           capture_expr1 = code->expr1;
    5160                 :          19 :           capture_expr2 = code->expr2;
    5161                 :          19 :           expr1 = code->next->block->next->expr1;
    5162                 :          19 :           expr2 = code->next->block->next->expr2;
    5163                 :          19 :           comp_expr = code->next->block->expr1;
    5164                 :             :         }
    5165                 :         144 :       gfc_init_se (&lse, NULL);
    5166                 :         144 :       gfc_conv_expr (&lse, comp_expr->value.op.op2);
    5167                 :         144 :       gfc_add_block_to_block (&block, &lse.pre);
    5168                 :         144 :       compare = lse.expr;
    5169                 :         144 :       var = expr1->symtree->n.sym;
    5170                 :             :     }
    5171                 :             :   else
    5172                 :             :     {
    5173                 :        2445 :       gcc_assert (code->op == EXEC_ASSIGN);
    5174                 :        2445 :       expr1 = code->expr1;
    5175                 :        2445 :       expr2 = code->expr2;
    5176                 :        2445 :       if (atomic_code->ext.omp_clauses->capture
    5177                 :         483 :           && (expr2->expr_type == EXPR_VARIABLE
    5178                 :         245 :               || (expr2->expr_type == EXPR_FUNCTION
    5179                 :         113 :                   && expr2->value.function.isym
    5180                 :         113 :                   && expr2->value.function.isym->id == GFC_ISYM_CONVERSION
    5181                 :          41 :                   && (expr2->value.function.actual->expr->expr_type
    5182                 :             :                       == EXPR_VARIABLE))))
    5183                 :             :         {
    5184                 :         255 :           capture_expr1 = expr1;
    5185                 :         255 :           capture_expr2 = expr2;
    5186                 :         255 :           expr1 = code->next->expr1;
    5187                 :         255 :           expr2 = code->next->expr2;
    5188                 :         255 :           aop = OMP_ATOMIC_CAPTURE_OLD;
    5189                 :             :         }
    5190                 :        2190 :       else if (atomic_code->ext.omp_clauses->capture)
    5191                 :             :         {
    5192                 :         228 :           aop = OMP_ATOMIC_CAPTURE_NEW;
    5193                 :         228 :           capture_expr1 = code->next->expr1;
    5194                 :         228 :           capture_expr2 = code->next->expr2;
    5195                 :             :         }
    5196                 :        2445 :       var = expr1->symtree->n.sym;
    5197                 :             :     }
    5198                 :             : 
    5199                 :        2589 :   gfc_init_se (&lse, NULL);
    5200                 :        2589 :   gfc_init_se (&rse, NULL);
    5201                 :        2589 :   gfc_init_se (&vse, NULL);
    5202                 :        2589 :   gfc_start_block (&block);
    5203                 :             : 
    5204                 :        2589 :   if (((atomic_code->ext.omp_clauses->atomic_op & GFC_OMP_ATOMIC_MASK)
    5205                 :             :        != GFC_OMP_ATOMIC_WRITE)
    5206                 :        2183 :       && expr2->expr_type == EXPR_FUNCTION
    5207                 :         472 :       && expr2->value.function.isym
    5208                 :         472 :       && expr2->value.function.isym->id == GFC_ISYM_CONVERSION)
    5209                 :         139 :     expr2 = expr2->value.function.actual->expr;
    5210                 :             : 
    5211                 :        2589 :   if ((atomic_code->ext.omp_clauses->atomic_op & GFC_OMP_ATOMIC_MASK)
    5212                 :             :       == GFC_OMP_ATOMIC_READ)
    5213                 :             :     {
    5214                 :         494 :       gfc_conv_expr (&vse, expr1);
    5215                 :         494 :       gfc_add_block_to_block (&block, &vse.pre);
    5216                 :             : 
    5217                 :         494 :       gfc_conv_expr (&lse, expr2);
    5218                 :         494 :       gfc_add_block_to_block (&block, &lse.pre);
    5219                 :         494 :       type = TREE_TYPE (lse.expr);
    5220                 :         494 :       lhsaddr = gfc_build_addr_expr (NULL, lse.expr);
    5221                 :             : 
    5222                 :         494 :       x = build1 (OMP_ATOMIC_READ, type, lhsaddr);
    5223                 :         494 :       OMP_ATOMIC_MEMORY_ORDER (x) = mo;
    5224                 :         494 :       x = convert (TREE_TYPE (vse.expr), x);
    5225                 :         494 :       gfc_add_modify (&block, vse.expr, x);
    5226                 :             : 
    5227                 :         494 :       gfc_add_block_to_block (&block, &lse.pre);
    5228                 :         494 :       gfc_add_block_to_block (&block, &rse.pre);
    5229                 :             : 
    5230                 :         494 :       return gfc_finish_block (&block);
    5231                 :             :     }
    5232                 :             : 
    5233                 :        2095 :   if (capture_expr2
    5234                 :         585 :       && capture_expr2->expr_type == EXPR_FUNCTION
    5235                 :          21 :       && capture_expr2->value.function.isym
    5236                 :          21 :       && capture_expr2->value.function.isym->id == GFC_ISYM_CONVERSION)
    5237                 :          21 :     capture_expr2 = capture_expr2->value.function.actual->expr;
    5238                 :         585 :   gcc_assert (!capture_expr2 || capture_expr2->expr_type == EXPR_VARIABLE);
    5239                 :             : 
    5240                 :        2095 :   if (aop == OMP_ATOMIC_CAPTURE_OLD)
    5241                 :             :     {
    5242                 :         338 :       gfc_conv_expr (&vse, capture_expr1);
    5243                 :         338 :       gfc_add_block_to_block (&block, &vse.pre);
    5244                 :         338 :       gfc_conv_expr (&lse, capture_expr2);
    5245                 :         338 :       gfc_add_block_to_block (&block, &lse.pre);
    5246                 :         338 :       gfc_init_se (&lse, NULL);
    5247                 :             :     }
    5248                 :             : 
    5249                 :        2095 :   gfc_conv_expr (&lse, expr1);
    5250                 :        2095 :   gfc_add_block_to_block (&block, &lse.pre);
    5251                 :        2095 :   type = TREE_TYPE (lse.expr);
    5252                 :        2095 :   lhsaddr = gfc_build_addr_expr (NULL, lse.expr);
    5253                 :             : 
    5254                 :        2095 :   if (((atomic_code->ext.omp_clauses->atomic_op & GFC_OMP_ATOMIC_MASK)
    5255                 :             :        == GFC_OMP_ATOMIC_WRITE)
    5256                 :        1689 :       || (atomic_code->ext.omp_clauses->atomic_op & GFC_OMP_ATOMIC_SWAP)
    5257                 :        1667 :       || compare)
    5258                 :             :     {
    5259                 :         572 :       gfc_conv_expr (&rse, expr2);
    5260                 :         572 :       gfc_add_block_to_block (&block, &rse.pre);
    5261                 :             :     }
    5262                 :        1523 :   else if (expr2->expr_type == EXPR_OP)
    5263                 :             :     {
    5264                 :        1177 :       gfc_expr *e;
    5265                 :        1177 :       switch (expr2->value.op.op)
    5266                 :             :         {
    5267                 :             :         case INTRINSIC_PLUS:
    5268                 :             :           op = PLUS_EXPR;
    5269                 :             :           break;
    5270                 :          91 :         case INTRINSIC_TIMES:
    5271                 :          91 :           op = MULT_EXPR;
    5272                 :          91 :           break;
    5273                 :         113 :         case INTRINSIC_MINUS:
    5274                 :         113 :           op = MINUS_EXPR;
    5275                 :         113 :           break;
    5276                 :          91 :         case INTRINSIC_DIVIDE:
    5277                 :          91 :           if (expr2->ts.type == BT_INTEGER)
    5278                 :             :             op = TRUNC_DIV_EXPR;
    5279                 :             :           else
    5280                 :          74 :             op = RDIV_EXPR;
    5281                 :             :           break;
    5282                 :          43 :         case INTRINSIC_AND:
    5283                 :          43 :           op = TRUTH_ANDIF_EXPR;
    5284                 :          43 :           break;
    5285                 :          49 :         case INTRINSIC_OR:
    5286                 :          49 :           op = TRUTH_ORIF_EXPR;
    5287                 :          49 :           break;
    5288                 :          43 :         case INTRINSIC_EQV:
    5289                 :          43 :           op = EQ_EXPR;
    5290                 :          43 :           break;
    5291                 :          43 :         case INTRINSIC_NEQV:
    5292                 :          43 :           op = NE_EXPR;
    5293                 :          43 :           break;
    5294                 :           0 :         default:
    5295                 :           0 :           gcc_unreachable ();
    5296                 :             :         }
    5297                 :        1177 :       e = expr2->value.op.op1;
    5298                 :        1177 :       if (e->expr_type == EXPR_FUNCTION
    5299                 :          48 :           && e->value.function.isym
    5300                 :          48 :           && e->value.function.isym->id == GFC_ISYM_CONVERSION)
    5301                 :          48 :         e = e->value.function.actual->expr;
    5302                 :        1177 :       if (e->expr_type == EXPR_VARIABLE
    5303                 :         918 :           && e->symtree != NULL
    5304                 :         918 :           && e->symtree->n.sym == var)
    5305                 :             :         {
    5306                 :         903 :           expr2 = expr2->value.op.op2;
    5307                 :         903 :           var_on_left = true;
    5308                 :             :         }
    5309                 :             :       else
    5310                 :             :         {
    5311                 :         274 :           e = expr2->value.op.op2;
    5312                 :         274 :           if (e->expr_type == EXPR_FUNCTION
    5313                 :          48 :               && e->value.function.isym
    5314                 :          48 :               && e->value.function.isym->id == GFC_ISYM_CONVERSION)
    5315                 :          48 :             e = e->value.function.actual->expr;
    5316                 :         274 :           gcc_assert (e->expr_type == EXPR_VARIABLE
    5317                 :             :                       && e->symtree != NULL
    5318                 :             :                       && e->symtree->n.sym == var);
    5319                 :             :           expr2 = expr2->value.op.op1;
    5320                 :             :           var_on_left = false;
    5321                 :             :         }
    5322                 :        1177 :       gfc_conv_expr (&rse, expr2);
    5323                 :        1177 :       gfc_add_block_to_block (&block, &rse.pre);
    5324                 :             :     }
    5325                 :             :   else
    5326                 :             :     {
    5327                 :         346 :       gcc_assert (expr2->expr_type == EXPR_FUNCTION);
    5328                 :         346 :       switch (expr2->value.function.isym->id)
    5329                 :             :         {
    5330                 :             :         case GFC_ISYM_MIN:
    5331                 :             :           op = MIN_EXPR;
    5332                 :             :           break;
    5333                 :         114 :         case GFC_ISYM_MAX:
    5334                 :         114 :           op = MAX_EXPR;
    5335                 :         114 :           break;
    5336                 :          47 :         case GFC_ISYM_IAND:
    5337                 :          47 :           op = BIT_AND_EXPR;
    5338                 :          47 :           break;
    5339                 :          49 :         case GFC_ISYM_IOR:
    5340                 :          49 :           op = BIT_IOR_EXPR;
    5341                 :          49 :           break;
    5342                 :          45 :         case GFC_ISYM_IEOR:
    5343                 :          45 :           op = BIT_XOR_EXPR;
    5344                 :          45 :           break;
    5345                 :           0 :         default:
    5346                 :           0 :           gcc_unreachable ();
    5347                 :             :         }
    5348                 :         346 :       e = expr2->value.function.actual->expr;
    5349                 :         346 :       if (e->expr_type == EXPR_FUNCTION
    5350                 :          13 :           && e->value.function.isym
    5351                 :          13 :           && e->value.function.isym->id == GFC_ISYM_CONVERSION)
    5352                 :          13 :         e = e->value.function.actual->expr;
    5353                 :         346 :       gcc_assert (e->expr_type == EXPR_VARIABLE
    5354                 :             :                   && e->symtree != NULL
    5355                 :             :                   && e->symtree->n.sym == var);
    5356                 :             : 
    5357                 :         346 :       gfc_conv_expr (&rse, expr2->value.function.actual->next->expr);
    5358                 :         346 :       gfc_add_block_to_block (&block, &rse.pre);
    5359                 :         346 :       if (expr2->value.function.actual->next->next != NULL)
    5360                 :             :         {
    5361                 :          26 :           tree accum = gfc_create_var (TREE_TYPE (rse.expr), NULL);
    5362                 :          26 :           gfc_actual_arglist *arg;
    5363                 :             : 
    5364                 :          26 :           gfc_add_modify (&block, accum, rse.expr);
    5365                 :          64 :           for (arg = expr2->value.function.actual->next->next; arg;
    5366                 :          38 :                arg = arg->next)
    5367                 :             :             {
    5368                 :          38 :               gfc_init_block (&rse.pre);
    5369                 :          38 :               gfc_conv_expr (&rse, arg->expr);
    5370                 :          38 :               gfc_add_block_to_block (&block, &rse.pre);
    5371                 :          38 :               x = fold_build2_loc (input_location, op, TREE_TYPE (accum),
    5372                 :             :                                    accum, rse.expr);
    5373                 :          38 :               gfc_add_modify (&block, accum, x);
    5374                 :             :             }
    5375                 :             : 
    5376                 :          26 :           rse.expr = accum;
    5377                 :             :         }
    5378                 :             : 
    5379                 :         346 :       expr2 = expr2->value.function.actual->next->expr;
    5380                 :             :     }
    5381                 :             : 
    5382                 :        2095 :   lhsaddr = save_expr (lhsaddr);
    5383                 :        2095 :   if (TREE_CODE (lhsaddr) != SAVE_EXPR
    5384                 :        2095 :       && (TREE_CODE (lhsaddr) != ADDR_EXPR
    5385                 :        1659 :           || !VAR_P (TREE_OPERAND (lhsaddr, 0))))
    5386                 :             :     {
    5387                 :             :       /* Make sure LHS is simple enough so that goa_lhs_expr_p can recognize
    5388                 :             :          it even after unsharing function body.  */
    5389                 :          44 :       tree var = create_tmp_var_raw (TREE_TYPE (lhsaddr));
    5390                 :          44 :       DECL_CONTEXT (var) = current_function_decl;
    5391                 :          44 :       lhsaddr = build4 (TARGET_EXPR, TREE_TYPE (lhsaddr), var, lhsaddr,
    5392                 :             :                         NULL_TREE, NULL_TREE);
    5393                 :             :     }
    5394                 :             : 
    5395                 :        2095 :   if (compare)
    5396                 :             :     {
    5397                 :         144 :       tree var = create_tmp_var_raw (TREE_TYPE (lhsaddr));
    5398                 :         144 :       DECL_CONTEXT (var) = current_function_decl;
    5399                 :         144 :       lhsaddr = build4 (TARGET_EXPR, TREE_TYPE (lhsaddr), var, lhsaddr, NULL,
    5400                 :             :                         NULL);
    5401                 :         144 :       lse.expr = build_fold_indirect_ref_loc (input_location, lhsaddr);
    5402                 :         144 :       compare = convert (TREE_TYPE (lse.expr), compare);
    5403                 :         144 :       compare = fold_build2_loc (input_location, EQ_EXPR, boolean_type_node,
    5404                 :             :                                  lse.expr, compare);
    5405                 :             :     }
    5406                 :             : 
    5407                 :        2095 :   if (expr2->expr_type == EXPR_VARIABLE || compare)
    5408                 :         460 :     rhs = rse.expr;
    5409                 :             :   else
    5410                 :        1635 :     rhs = gfc_evaluate_now (rse.expr, &block);
    5411                 :             : 
    5412                 :        2095 :   if (((atomic_code->ext.omp_clauses->atomic_op & GFC_OMP_ATOMIC_MASK)
    5413                 :             :        == GFC_OMP_ATOMIC_WRITE)
    5414                 :        1689 :       || (atomic_code->ext.omp_clauses->atomic_op & GFC_OMP_ATOMIC_SWAP)
    5415                 :        1667 :       || compare)
    5416                 :             :     x = rhs;
    5417                 :             :   else
    5418                 :             :     {
    5419                 :        1523 :       x = convert (TREE_TYPE (rhs),
    5420                 :             :                    build_fold_indirect_ref_loc (input_location, lhsaddr));
    5421                 :        1523 :       if (var_on_left)
    5422                 :         903 :         x = fold_build2_loc (input_location, op, TREE_TYPE (rhs), x, rhs);
    5423                 :             :       else
    5424                 :         620 :         x = fold_build2_loc (input_location, op, TREE_TYPE (rhs), rhs, x);
    5425                 :             :     }
    5426                 :             : 
    5427                 :        2095 :   if (TREE_CODE (TREE_TYPE (rhs)) == COMPLEX_TYPE
    5428                 :        2095 :       && TREE_CODE (type) != COMPLEX_TYPE)
    5429                 :           0 :     x = fold_build1_loc (input_location, REALPART_EXPR,
    5430                 :           0 :                          TREE_TYPE (TREE_TYPE (rhs)), x);
    5431                 :             : 
    5432                 :        2095 :   gfc_add_block_to_block (&block, &lse.pre);
    5433                 :        2095 :   gfc_add_block_to_block (&block, &rse.pre);
    5434                 :             : 
    5435                 :        2095 :   if (aop == OMP_ATOMIC_CAPTURE_NEW)
    5436                 :             :     {
    5437                 :         247 :       gfc_conv_expr (&vse, capture_expr1);
    5438                 :         247 :       gfc_add_block_to_block (&block, &vse.pre);
    5439                 :         247 :       gfc_add_block_to_block (&block, &lse.pre);
    5440                 :             :     }
    5441                 :             : 
    5442                 :        2095 :   if (compare && else_branch)
    5443                 :             :     {
    5444                 :          64 :       tree var2 = create_tmp_var_raw (boolean_type_node);
    5445                 :          64 :       DECL_CONTEXT (var2) = current_function_decl;
    5446                 :          64 :       comp_tgt = build4 (TARGET_EXPR, boolean_type_node, var2,
    5447                 :             :                          boolean_false_node, NULL, NULL);
    5448                 :          64 :       compare = fold_build2_loc (input_location, MODIFY_EXPR, TREE_TYPE (var2),
    5449                 :             :                                  var2, compare);
    5450                 :          64 :       TREE_OPERAND (compare, 0) = comp_tgt;
    5451                 :          64 :       compare = omit_one_operand_loc (input_location, boolean_type_node,
    5452                 :             :                                       compare, comp_tgt);
    5453                 :             :     }
    5454                 :             : 
    5455                 :        2095 :   if (compare)
    5456                 :         144 :     x = build3_loc (input_location, COND_EXPR, type, compare,
    5457                 :             :                     convert (type, x), lse.expr);
    5458                 :             : 
    5459                 :        2095 :   if (aop == OMP_ATOMIC)
    5460                 :             :     {
    5461                 :        1510 :       x = build2_v (OMP_ATOMIC, lhsaddr, convert (type, x));
    5462                 :        1510 :       OMP_ATOMIC_MEMORY_ORDER (x) = mo;
    5463                 :        1510 :       OMP_ATOMIC_WEAK (x) = atomic_code->ext.omp_clauses->weak;
    5464                 :        1510 :       gfc_add_expr_to_block (&block, x);
    5465                 :             :     }
    5466                 :             :   else
    5467                 :             :     {
    5468                 :         585 :       x = build2 (aop, type, lhsaddr, convert (type, x));
    5469                 :         585 :       OMP_ATOMIC_MEMORY_ORDER (x) = mo;
    5470                 :         585 :       OMP_ATOMIC_WEAK (x) = atomic_code->ext.omp_clauses->weak;
    5471                 :         585 :       if (compare && else_branch)
    5472                 :             :         {
    5473                 :          64 :           tree vtmp = create_tmp_var_raw (TREE_TYPE (x));
    5474                 :          64 :           DECL_CONTEXT (vtmp) = current_function_decl;
    5475                 :          64 :           x = fold_build2_loc (input_location, MODIFY_EXPR,
    5476                 :          64 :                                TREE_TYPE (vtmp), vtmp, x);
    5477                 :          64 :           vtmp = build4 (TARGET_EXPR, TREE_TYPE (vtmp), vtmp,
    5478                 :          64 :                          build_zero_cst (TREE_TYPE (vtmp)), NULL, NULL);
    5479                 :          64 :           TREE_OPERAND (x, 0) = vtmp;
    5480                 :          64 :           tree x2 = convert (TREE_TYPE (vse.expr), vtmp);
    5481                 :          64 :           x2 = fold_build2_loc (input_location, MODIFY_EXPR,
    5482                 :          64 :                                TREE_TYPE (vse.expr), vse.expr, x2);
    5483                 :          64 :           x2 = build3_loc (input_location, COND_EXPR, void_type_node, comp_tgt,
    5484                 :             :                            void_node, x2);
    5485                 :          64 :           x = omit_one_operand_loc (input_location, TREE_TYPE (x2), x2, x);
    5486                 :          64 :           gfc_add_expr_to_block (&block, x);
    5487                 :             :         }
    5488                 :             :       else
    5489                 :             :         {
    5490                 :         521 :           x = convert (TREE_TYPE (vse.expr), x);
    5491                 :         521 :           gfc_add_modify (&block, vse.expr, x);
    5492                 :             :         }
    5493                 :             :     }
    5494                 :             : 
    5495                 :        2095 :   return gfc_finish_block (&block);
    5496                 :             : }
    5497                 :             : 
    5498                 :             : static tree
    5499                 :         602 : gfc_trans_omp_barrier (void)
    5500                 :             : {
    5501                 :         602 :   tree decl = builtin_decl_explicit (BUILT_IN_GOMP_BARRIER);
    5502                 :         602 :   return build_call_expr_loc (input_location, decl, 0);
    5503                 :             : }
    5504                 :             : 
    5505                 :             : static tree
    5506                 :         310 : gfc_trans_omp_cancel (gfc_code *code)
    5507                 :             : {
    5508                 :         310 :   int mask = 0;
    5509                 :         310 :   tree ifc = boolean_true_node;
    5510                 :         310 :   stmtblock_t block;
    5511                 :         310 :   switch (code->ext.omp_clauses->cancel)
    5512                 :             :     {
    5513                 :             :     case OMP_CANCEL_PARALLEL: mask = 1; break;
    5514                 :             :     case OMP_CANCEL_DO: mask = 2; break;
    5515                 :             :     case OMP_CANCEL_SECTIONS: mask = 4; break;
    5516                 :             :     case OMP_CANCEL_TASKGROUP: mask = 8; break;
    5517                 :           0 :     default: gcc_unreachable ();
    5518                 :             :     }
    5519                 :         310 :   gfc_start_block (&block);
    5520                 :         310 :   if (code->ext.omp_clauses->if_expr
    5521                 :         219 :       || code->ext.omp_clauses->if_exprs[OMP_IF_CANCEL])
    5522                 :             :     {
    5523                 :          99 :       gfc_se se;
    5524                 :          99 :       tree if_var;
    5525                 :             : 
    5526                 :          99 :       gcc_assert ((code->ext.omp_clauses->if_expr == NULL)
    5527                 :             :                   ^ (code->ext.omp_clauses->if_exprs[OMP_IF_CANCEL] == NULL));
    5528                 :          99 :       gfc_init_se (&se, NULL);
    5529                 :          99 :       gfc_conv_expr (&se, code->ext.omp_clauses->if_expr != NULL
    5530                 :             :                           ? code->ext.omp_clauses->if_expr
    5531                 :             :                           : code->ext.omp_clauses->if_exprs[OMP_IF_CANCEL]);
    5532                 :          99 :       gfc_add_block_to_block (&block, &se.pre);
    5533                 :          99 :       if_var = gfc_evaluate_now (se.expr, &block);
    5534                 :          99 :       gfc_add_block_to_block (&block, &se.post);
    5535                 :          99 :       tree type = TREE_TYPE (if_var);
    5536                 :          99 :       ifc = fold_build2_loc (input_location, NE_EXPR,
    5537                 :             :                              boolean_type_node, if_var,
    5538                 :             :                              build_zero_cst (type));
    5539                 :             :     }
    5540                 :         310 :   tree decl = builtin_decl_explicit (BUILT_IN_GOMP_CANCEL);
    5541                 :         310 :   tree c_bool_type = TREE_TYPE (TREE_TYPE (decl));
    5542                 :         310 :   ifc = fold_convert (c_bool_type, ifc);
    5543                 :         310 :   gfc_add_expr_to_block (&block,
    5544                 :             :                          build_call_expr_loc (input_location, decl, 2,
    5545                 :             :                                               build_int_cst (integer_type_node,
    5546                 :             :                                                              mask), ifc));
    5547                 :         310 :   return gfc_finish_block (&block);
    5548                 :             : }
    5549                 :             : 
    5550                 :             : static tree
    5551                 :         170 : gfc_trans_omp_cancellation_point (gfc_code *code)
    5552                 :             : {
    5553                 :         170 :   int mask = 0;
    5554                 :         170 :   switch (code->ext.omp_clauses->cancel)
    5555                 :             :     {
    5556                 :             :     case OMP_CANCEL_PARALLEL: mask = 1; break;
    5557                 :             :     case OMP_CANCEL_DO: mask = 2; break;
    5558                 :             :     case OMP_CANCEL_SECTIONS: mask = 4; break;
    5559                 :             :     case OMP_CANCEL_TASKGROUP: mask = 8; break;
    5560                 :           0 :     default: gcc_unreachable ();
    5561                 :             :     }
    5562                 :         170 :   tree decl = builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT);
    5563                 :         170 :   return build_call_expr_loc (input_location, decl, 1,
    5564                 :         170 :                               build_int_cst (integer_type_node, mask));
    5565                 :             : }
    5566                 :             : 
    5567                 :             : static tree
    5568                 :         143 : gfc_trans_omp_critical (gfc_code *code)
    5569                 :             : {
    5570                 :         143 :   stmtblock_t block;
    5571                 :         143 :   tree stmt, name = NULL_TREE;
    5572                 :         143 :   if (code->ext.omp_clauses->critical_name != NULL)
    5573                 :          36 :     name = get_identifier (code->ext.omp_clauses->critical_name);
    5574                 :         143 :   gfc_start_block (&block);
    5575                 :         143 :   stmt = make_node (OMP_CRITICAL);
    5576                 :         143 :   SET_EXPR_LOCATION (stmt, gfc_get_location (&code->loc));
    5577                 :         143 :   TREE_TYPE (stmt) = void_type_node;
    5578                 :         143 :   OMP_CRITICAL_BODY (stmt) = gfc_trans_code (code->block->next);
    5579                 :         143 :   OMP_CRITICAL_NAME (stmt) = name;
    5580                 :         143 :   OMP_CRITICAL_CLAUSES (stmt) = gfc_trans_omp_clauses (&block,
    5581                 :             :                                                        code->ext.omp_clauses,
    5582                 :             :                                                        code->loc);
    5583                 :         143 :   gfc_add_expr_to_block (&block, stmt);
    5584                 :         143 :   return gfc_finish_block (&block);
    5585                 :             : }
    5586                 :             : 
    5587                 :             : typedef struct dovar_init_d {
    5588                 :             :   gfc_symbol *sym;
    5589                 :             :   tree var;
    5590                 :             :   tree init;
    5591                 :             :   bool non_unit_iter;
    5592                 :             : } dovar_init;
    5593                 :             : 
    5594                 :             : static bool
    5595                 :        2856 : gfc_nonrect_loop_expr (stmtblock_t *pblock, gfc_se *sep, int loop_n,
    5596                 :             :                        gfc_code *code, gfc_expr *expr, vec<dovar_init> *inits,
    5597                 :             :                        int simple, gfc_expr *curr_loop_var)
    5598                 :             : {
    5599                 :        2856 :   int i;
    5600                 :        4724 :   for (i = 0; i < loop_n; i++)
    5601                 :             :     {
    5602                 :        2417 :       gcc_assert (code->ext.iterator->var->expr_type == EXPR_VARIABLE);
    5603                 :        2417 :       if (gfc_find_sym_in_expr (code->ext.iterator->var->symtree->n.sym, expr))
    5604                 :             :         break;
    5605                 :        1868 :       code = code->block->next;
    5606                 :             :     }
    5607                 :        2856 :   if (i >= loop_n)
    5608                 :             :     return false;
    5609                 :             : 
    5610                 :             :   /* Canonical format: TREE_VEC with [var, multiplier, offset].  */
    5611                 :         549 :   gfc_symbol *var = code->ext.iterator->var->symtree->n.sym;
    5612                 :             : 
    5613                 :         549 :   tree tree_var = NULL_TREE;
    5614                 :         549 :   tree a1 = integer_one_node;
    5615                 :         549 :   tree a2 = integer_zero_node;
    5616                 :             : 
    5617                 :         549 :   if (!simple)
    5618                 :             :     {
    5619                 :             :       /* FIXME: Handle non-const iter steps, cf. PR fortran/110735.  */
    5620                 :           6 :       sorry_at (gfc_get_location (&curr_loop_var->where),
    5621                 :             :                 "non-rectangular loop nest with non-constant step for %qs",
    5622                 :           3 :                 curr_loop_var->symtree->n.sym->name);
    5623                 :           3 :       return false;
    5624                 :             :     }
    5625                 :             : 
    5626                 :             :   dovar_init *di;
    5627                 :             :   unsigned ix;
    5628                 :         546 :   FOR_EACH_VEC_ELT (*inits, ix, di)
    5629                 :          18 :     if (di->sym == var)
    5630                 :             :       {
    5631                 :          18 :         if (!di->non_unit_iter)
    5632                 :             :           {
    5633                 :          16 :             tree_var = di->init;
    5634                 :          16 :             gcc_assert (DECL_P (tree_var));
    5635                 :             :             break;
    5636                 :             :           }
    5637                 :             :         else
    5638                 :             :           {
    5639                 :             :             /* FIXME: Handle non-const iter steps, cf. PR fortran/110735.  */
    5640                 :           2 :             sorry_at (gfc_get_location (&code->loc),
    5641                 :             :                       "non-rectangular loop nest with non-constant step "
    5642                 :             :                       "for %qs", var->name);
    5643                 :           2 :             inform (gfc_get_location (&expr->where), "Used here");
    5644                 :           2 :             return false;
    5645                 :             :           }
    5646                 :             :       }
    5647                 :         528 :   if (tree_var == NULL_TREE)
    5648                 :         528 :     tree_var = var->backend_decl;
    5649                 :             : 
    5650                 :         544 :   if (expr->expr_type == EXPR_VARIABLE)
    5651                 :          49 :     gcc_assert (expr->symtree->n.sym == var);
    5652                 :         495 :   else if (expr->expr_type != EXPR_OP
    5653                 :         495 :            || (expr->value.op.op != INTRINSIC_TIMES
    5654                 :         479 :                && expr->value.op.op != INTRINSIC_PLUS
    5655                 :         359 :                && expr->value.op.op != INTRINSIC_MINUS))
    5656                 :           0 :     gcc_unreachable ();
    5657                 :             :   else
    5658                 :             :     {
    5659                 :         495 :       gfc_se se;
    5660                 :         495 :       gfc_expr *et = NULL, *eo = NULL, *e = expr;
    5661                 :         495 :       if (expr->value.op.op != INTRINSIC_TIMES)
    5662                 :             :         {
    5663                 :         479 :           if (gfc_find_sym_in_expr (var, expr->value.op.op1))
    5664                 :             :             {
    5665                 :         431 :               e = expr->value.op.op1;
    5666                 :         431 :               eo = expr->value.op.op2;
    5667                 :             :             }
    5668                 :             :           else
    5669                 :             :             {
    5670                 :          48 :               eo = expr->value.op.op1;
    5671                 :          48 :               e = expr->value.op.op2;
    5672                 :             :             }
    5673                 :             :         }
    5674                 :         495 :       if (e->value.op.op == INTRINSIC_TIMES)
    5675                 :             :         {
    5676                 :          91 :           if (e->value.op.op1->expr_type == EXPR_VARIABLE
    5677                 :          91 :               && e->value.op.op1->symtree->n.sym == var)
    5678                 :          51 :             et = e->value.op.op2;
    5679                 :             :           else
    5680                 :             :             {
    5681                 :          40 :               et = e->value.op.op1;
    5682                 :          40 :               gcc_assert (e->value.op.op2->expr_type == EXPR_VARIABLE
    5683                 :             :                           && e->value.op.op2->symtree->n.sym == var);
    5684                 :             :             }
    5685                 :             :         }
    5686                 :             :       else
    5687                 :         404 :         gcc_assert (e->expr_type == EXPR_VARIABLE && e->symtree->n.sym == var);
    5688                 :          91 :       if (et != NULL)
    5689                 :             :         {
    5690                 :          91 :           gfc_init_se (&se, NULL);
    5691                 :          91 :           gfc_conv_expr_val (&se, et);
    5692                 :          91 :           gfc_add_block_to_block (pblock, &se.pre);
    5693                 :          91 :           a1 = se.expr;
    5694                 :             :         }
    5695                 :         495 :       if (eo != NULL)
    5696                 :             :         {
    5697                 :         479 :           gfc_init_se (&se, NULL);
    5698                 :         479 :           gfc_conv_expr_val (&se, eo);
    5699                 :         479 :           gfc_add_block_to_block (pblock, &se.pre);
    5700                 :         479 :           a2 = se.expr;
    5701                 :         479 :           if (expr->value.op.op == INTRINSIC_MINUS && expr->value.op.op2 == eo)
    5702                 :             :             /* outer-var - a2.  */
    5703                 :         335 :             a2 = fold_build1 (NEGATE_EXPR, TREE_TYPE (a2), a2);
    5704                 :         144 :           else if (expr->value.op.op == INTRINSIC_MINUS)
    5705                 :             :             /* a2 - outer-var.  */
    5706                 :          24 :             a1 = fold_build1 (NEGATE_EXPR, TREE_TYPE (a1), a1);
    5707                 :             :         }
    5708                 :         495 :       a1 = DECL_P (a1) ? a1 : gfc_evaluate_now (a1, pblock);
    5709                 :         495 :       a2 = DECL_P (a2) ? a2 : gfc_evaluate_now (a2, pblock);
    5710                 :             :     }
    5711                 :             : 
    5712                 :         544 :   gfc_init_se (sep, NULL);
    5713                 :         544 :   sep->expr = make_tree_vec (3);
    5714                 :         544 :   TREE_VEC_ELT (sep->expr, 0) = tree_var;
    5715                 :         544 :   TREE_VEC_ELT (sep->expr, 1) = fold_convert (TREE_TYPE (tree_var), a1);
    5716                 :         544 :   TREE_VEC_ELT (sep->expr, 2) = fold_convert (TREE_TYPE (tree_var), a2);
    5717                 :             : 
    5718                 :         544 :   return true;
    5719                 :             : }
    5720                 :             : 
    5721                 :             : static tree
    5722                 :        8240 : gfc_trans_omp_do (gfc_code *code, gfc_exec_op op, stmtblock_t *pblock,
    5723                 :             :                   gfc_omp_clauses *do_clauses, tree par_clauses)
    5724                 :             : {
    5725                 :        8240 :   gfc_se se;
    5726                 :        8240 :   tree dovar, stmt, from, to, step, type, init, cond, incr, orig_decls;
    5727                 :        8240 :   tree local_dovar = NULL_TREE, cycle_label, tmp, omp_clauses;
    5728                 :        8240 :   stmtblock_t block;
    5729                 :        8240 :   stmtblock_t body;
    5730                 :        8240 :   gfc_omp_clauses *clauses = code->ext.omp_clauses;
    5731                 :        8240 :   int i, collapse = clauses->collapse;
    5732                 :        8240 :   vec<dovar_init> inits = vNULL;
    5733                 :        8240 :   dovar_init *di;
    5734                 :        8240 :   unsigned ix;
    5735                 :        8240 :   vec<tree, va_heap, vl_embed> *saved_doacross_steps = doacross_steps;
    5736                 :        8240 :   gfc_expr_list *tile = do_clauses ? do_clauses->tile_list : clauses->tile_list;
    5737                 :        8240 :   gfc_code *orig_code = code;
    5738                 :             : 
    5739                 :             :   /* Both collapsed and tiled loops are lowered the same way.  In
    5740                 :             :      OpenACC, those clauses are not compatible, so prioritize the tile
    5741                 :             :      clause, if present.  */
    5742                 :        8240 :   if (tile)
    5743                 :             :     {
    5744                 :             :       collapse = 0;
    5745                 :         171 :       for (gfc_expr_list *el = tile; el; el = el->next)
    5746                 :         112 :         collapse++;
    5747                 :             :     }
    5748                 :             : 
    5749                 :        8240 :   doacross_steps = NULL;
    5750                 :        8240 :   if (clauses->orderedc)
    5751                 :         131 :     collapse = clauses->orderedc;
    5752                 :        8240 :   if (collapse <= 0)
    5753                 :             :     collapse = 1;
    5754                 :             : 
    5755                 :        8240 :   code = code->block->next;
    5756                 :        8240 :   gcc_assert (code->op == EXEC_DO);
    5757                 :             : 
    5758                 :        8240 :   init = make_tree_vec (collapse);
    5759                 :        8240 :   cond = make_tree_vec (collapse);
    5760                 :        8240 :   incr = make_tree_vec (collapse);
    5761                 :        8240 :   orig_decls = clauses->ordered ? make_tree_vec (collapse) : NULL_TREE;
    5762                 :             : 
    5763                 :        8240 :   if (pblock == NULL)
    5764                 :             :     {
    5765                 :        5217 :       gfc_start_block (&block);
    5766                 :        5217 :       pblock = &block;
    5767                 :             :     }
    5768                 :             : 
    5769                 :             :   /* simd schedule modifier is only useful for composite do simd and other
    5770                 :             :      constructs including that, where gfc_trans_omp_do is only called
    5771                 :             :      on the simd construct and DO's clauses are translated elsewhere.  */
    5772                 :        8240 :   do_clauses->sched_simd = false;
    5773                 :             : 
    5774                 :        8240 :   omp_clauses = gfc_trans_omp_clauses (pblock, do_clauses, code->loc);
    5775                 :             : 
    5776                 :       18801 :   for (i = 0; i < collapse; i++)
    5777                 :             :     {
    5778                 :       10561 :       int simple = 0;
    5779                 :       10561 :       int dovar_found = 0;
    5780                 :       10561 :       tree dovar_decl;
    5781                 :             : 
    5782                 :       10561 :       if (clauses)
    5783                 :             :         {
    5784                 :       10561 :           gfc_omp_namelist *n = NULL;
    5785                 :       10561 :           if (op == EXEC_OMP_SIMD && collapse == 1)
    5786                 :         926 :             for (n = clauses->lists[OMP_LIST_LINEAR];
    5787                 :        1226 :                  n != NULL; n = n->next)
    5788                 :         443 :               if (code->ext.iterator->var->symtree->n.sym == n->sym)
    5789                 :             :                 {
    5790                 :             :                   dovar_found = 3;
    5791                 :             :                   break;
    5792                 :             :                 }
    5793                 :       10561 :           if (n == NULL && op != EXEC_OMP_DISTRIBUTE)
    5794                 :       10324 :             for (n = clauses->lists[OMP_LIST_LASTPRIVATE];
    5795                 :       12383 :                  n != NULL; n = n->next)
    5796                 :        3430 :               if (code->ext.iterator->var->symtree->n.sym == n->sym)
    5797                 :             :                 {
    5798                 :             :                   dovar_found = 2;
    5799                 :             :                   break;
    5800                 :             :                 }
    5801                 :       10561 :           if (n == NULL)
    5802                 :       10234 :             for (n = clauses->lists[OMP_LIST_PRIVATE]; n != NULL; n = n->next)
    5803                 :        6368 :               if (code->ext.iterator->var->symtree->n.sym == n->sym)
    5804                 :             :                 {
    5805                 :             :                   dovar_found = 1;
    5806                 :             :                   break;
    5807                 :             :                 }
    5808                 :             :         }
    5809                 :             : 
    5810                 :             :       /* Evaluate all the expressions in the iterator.  */
    5811                 :       10561 :       gfc_init_se (&se, NULL);
    5812                 :       10561 :       gfc_conv_expr_lhs (&se, code->ext.iterator->var);
    5813                 :       10561 :       gfc_add_block_to_block (pblock, &se.pre);
    5814                 :       10561 :       local_dovar = dovar_decl = dovar = se.expr;
    5815                 :       10561 :       type = TREE_TYPE (dovar);
    5816                 :       10561 :       gcc_assert (TREE_CODE (type) == INTEGER_TYPE);
    5817                 :             : 
    5818                 :       10561 :       gfc_init_se (&se, NULL);
    5819                 :       10561 :       gfc_conv_expr_val (&se, code->ext.iterator->step);
    5820                 :       10561 :       gfc_add_block_to_block (pblock, &se.pre);
    5821                 :       10561 :       step = gfc_evaluate_now (se.expr, pblock);
    5822                 :             : 
    5823                 :       10561 :       if (TREE_CODE (step) == INTEGER_CST)
    5824                 :       10010 :         simple = tree_int_cst_sgn (step);
    5825                 :             : 
    5826                 :       10561 :       gfc_init_se (&se, NULL);
    5827                 :       10561 :       if (!clauses->non_rectangular
    5828                 :       11989 :           || !gfc_nonrect_loop_expr (pblock, &se, i, orig_code->block->next,
    5829                 :             :                                      code->ext.iterator->start, &inits, simple,
    5830                 :        1428 :                                      code->ext.iterator->var))
    5831                 :             :         {
    5832                 :       10245 :           gfc_conv_expr_val (&se, code->ext.iterator->start);
    5833                 :       10245 :           gfc_add_block_to_block (pblock, &se.pre);
    5834                 :       10245 :           if (!DECL_P (se.expr))
    5835                 :        9827 :             se.expr = gfc_evaluate_now (se.expr, pblock);
    5836                 :             :         }
    5837                 :       10561 :       from = se.expr;
    5838                 :             : 
    5839                 :       10561 :       gfc_init_se (&se, NULL);
    5840                 :       10561 :       if (!clauses->non_rectangular
    5841                 :       11989 :           || !gfc_nonrect_loop_expr (pblock, &se, i, orig_code->block->next,
    5842                 :             :                                      code->ext.iterator->end, &inits, simple,
    5843                 :        1428 :                                      code->ext.iterator->var))
    5844                 :             :         {
    5845                 :       10333 :           gfc_conv_expr_val (&se, code->ext.iterator->end);
    5846                 :       10333 :           gfc_add_block_to_block (pblock, &se.pre);
    5847                 :       10333 :           if (!DECL_P (se.expr))
    5848                 :        9128 :             se.expr = gfc_evaluate_now (se.expr, pblock);
    5849                 :             :         }
    5850                 :       10561 :       to = se.expr;
    5851                 :             : 
    5852                 :       10561 :       if (!DECL_P (dovar))
    5853                 :          38 :         dovar_decl
    5854                 :          38 :           = gfc_trans_omp_variable (code->ext.iterator->var->symtree->n.sym,
    5855                 :             :                                     false);
    5856                 :       10561 :       if (simple && !DECL_P (dovar))
    5857                 :             :         {
    5858                 :          38 :           const char *name = code->ext.iterator->var->symtree->n.sym->name;
    5859                 :          38 :           local_dovar = gfc_create_var (type, name);
    5860                 :          38 :           dovar_init e = {code->ext.iterator->var->symtree->n.sym,
    5861                 :          38 :                           dovar, local_dovar, false};
    5862                 :          38 :           inits.safe_push (e);
    5863                 :             :         }
    5864                 :             :       /* Loop body.  */
    5865                 :       10561 :       if (simple)
    5866                 :             :         {
    5867                 :       10010 :           TREE_VEC_ELT (init, i) = build2_v (MODIFY_EXPR, local_dovar, from);
    5868                 :             :           /* The condition should not be folded.  */
    5869                 :       10526 :           TREE_VEC_ELT (cond, i) = build2_loc (input_location, simple > 0
    5870                 :             :                                                ? LE_EXPR : GE_EXPR,
    5871                 :             :                                                logical_type_node, local_dovar,
    5872                 :             :                                                to);
    5873                 :       10010 :           TREE_VEC_ELT (incr, i) = fold_build2_loc (input_location, PLUS_EXPR,
    5874                 :             :                                                     type, local_dovar, step);
    5875                 :       10010 :           TREE_VEC_ELT (incr, i) = fold_build2_loc (input_location,
    5876                 :             :                                                     MODIFY_EXPR,
    5877                 :             :                                                     type, local_dovar,
    5878                 :       10010 :                                                     TREE_VEC_ELT (incr, i));
    5879                 :       10010 :           if (orig_decls && !clauses->orderedc)
    5880                 :             :             orig_decls = NULL;
    5881                 :         380 :           else if (orig_decls)
    5882                 :         380 :             TREE_VEC_ELT (orig_decls, i) = dovar_decl;
    5883                 :             :         }
    5884                 :             :       else
    5885                 :             :         {
    5886                 :             :           /* STEP is not 1 or -1.  Use:
    5887                 :             :              for (count = 0; count < (to + step - from) / step; count++)
    5888                 :             :                {
    5889                 :             :                  dovar = from + count * step;
    5890                 :             :                  body;
    5891                 :             :                cycle_label:;
    5892                 :             :                }  */
    5893                 :         551 :           tmp = fold_build2_loc (input_location, MINUS_EXPR, type, step, from);
    5894                 :         551 :           tmp = fold_build2_loc (input_location, PLUS_EXPR, type, to, tmp);
    5895                 :         551 :           tmp = fold_build2_loc (input_location, TRUNC_DIV_EXPR, type, tmp,
    5896                 :             :                                  step);
    5897                 :         551 :           tmp = gfc_evaluate_now (tmp, pblock);
    5898                 :         551 :           local_dovar = gfc_create_var (type, "count");
    5899                 :         551 :           TREE_VEC_ELT (init, i) = build2_v (MODIFY_EXPR, local_dovar,
    5900                 :             :                                              build_int_cst (type, 0));
    5901                 :             :           /* The condition should not be folded.  */
    5902                 :         551 :           TREE_VEC_ELT (cond, i) = build2_loc (input_location, LT_EXPR,
    5903                 :             :                                                logical_type_node,
    5904                 :             :                                                local_dovar, tmp);
    5905                 :         551 :           TREE_VEC_ELT (incr, i) = fold_build2_loc (input_location, PLUS_EXPR,
    5906                 :             :                                                     type, local_dovar,
    5907                 :         551 :                                                     build_int_cst (type, 1));
    5908                 :         551 :           TREE_VEC_ELT (incr, i) = fold_build2_loc (input_location,
    5909                 :             :                                                     MODIFY_EXPR, type,
    5910                 :             :                                                     local_dovar,
    5911                 :         551 :                                                     TREE_VEC_ELT (incr, i));
    5912                 :             : 
    5913                 :             :           /* Initialize DOVAR.  */
    5914                 :         551 :           tmp = fold_build2_loc (input_location, MULT_EXPR, type, local_dovar,
    5915                 :             :                                  step);
    5916                 :         551 :           tmp = fold_build2_loc (input_location, PLUS_EXPR, type, from, tmp);
    5917                 :         551 :           dovar_init e = {code->ext.iterator->var->symtree->n.sym,
    5918                 :         551 :                           dovar, tmp, true};
    5919                 :         551 :           inits.safe_push (e);
    5920                 :         551 :           if (clauses->orderedc)
    5921                 :             :             {
    5922                 :         192 :               if (doacross_steps == NULL)
    5923                 :          47 :                 vec_safe_grow_cleared (doacross_steps, clauses->orderedc, true);
    5924                 :         192 :               (*doacross_steps)[i] = step;
    5925                 :             :             }
    5926                 :         551 :           if (orig_decls)
    5927                 :         198 :             TREE_VEC_ELT (orig_decls, i) = dovar_decl;
    5928                 :             :         }
    5929                 :             : 
    5930                 :       10561 :       if (dovar_found == 3
    5931                 :       10561 :           && op == EXEC_OMP_SIMD
    5932                 :         143 :           && collapse == 1
    5933                 :         143 :           && local_dovar != dovar)
    5934                 :             :         {
    5935                 :         120 :           for (tmp = omp_clauses; tmp; tmp = OMP_CLAUSE_CHAIN (tmp))
    5936                 :         120 :             if (OMP_CLAUSE_CODE (tmp) == OMP_CLAUSE_LINEAR
    5937                 :         120 :                 && OMP_CLAUSE_DECL (tmp) == dovar)
    5938                 :             :               {
    5939                 :          30 :                 OMP_CLAUSE_LINEAR_NO_COPYIN (tmp) = 1;
    5940                 :          30 :                 break;
    5941                 :             :               }
    5942                 :             :         }
    5943                 :       10561 :       if (!dovar_found && op == EXEC_OMP_SIMD)
    5944                 :             :         {
    5945                 :        1342 :           if (collapse == 1)
    5946                 :             :             {
    5947                 :         773 :               tmp = build_omp_clause (input_location, OMP_CLAUSE_LINEAR);
    5948                 :         773 :               OMP_CLAUSE_LINEAR_STEP (tmp) = step;
    5949                 :         773 :               OMP_CLAUSE_LINEAR_NO_COPYIN (tmp) = 1;
    5950                 :         773 :               OMP_CLAUSE_DECL (tmp) = dovar_decl;
    5951                 :         773 :               omp_clauses = gfc_trans_add_clause (tmp, omp_clauses);
    5952                 :         773 :               if (local_dovar != dovar)
    5953                 :             :                 dovar_found = 3;
    5954                 :             :             }
    5955                 :             :         }
    5956                 :        9219 :       else if (!dovar_found && local_dovar != dovar)
    5957                 :             :         {
    5958                 :         226 :           tmp = build_omp_clause (input_location, OMP_CLAUSE_PRIVATE);
    5959                 :         226 :           OMP_CLAUSE_DECL (tmp) = dovar_decl;
    5960                 :         226 :           omp_clauses = gfc_trans_add_clause (tmp, omp_clauses);
    5961                 :             :         }
    5962                 :       10531 :       if (dovar_found > 1)
    5963                 :             :         {
    5964                 :        1544 :           tree c = NULL;
    5965                 :             : 
    5966                 :        1544 :           tmp = NULL;
    5967                 :        1544 :           if (local_dovar != dovar)
    5968                 :             :             {
    5969                 :             :               /* If dovar is lastprivate, but different counter is used,
    5970                 :             :                  dovar += step needs to be added to
    5971                 :             :                  OMP_CLAUSE_LASTPRIVATE_STMT, otherwise the copied dovar
    5972                 :             :                  will have the value on entry of the last loop, rather
    5973                 :             :                  than value after iterator increment.  */
    5974                 :         237 :               if (clauses->orderedc)
    5975                 :             :                 {
    5976                 :          60 :                   if (clauses->collapse <= 1 || i >= clauses->collapse)
    5977                 :             :                     tmp = local_dovar;
    5978                 :             :                   else
    5979                 :          36 :                     tmp = fold_build2_loc (input_location, PLUS_EXPR,
    5980                 :             :                                            type, local_dovar,
    5981                 :             :                                            build_one_cst (type));
    5982                 :          60 :                   tmp = fold_build2_loc (input_location, MULT_EXPR, type,
    5983                 :             :                                          tmp, step);
    5984                 :          60 :                   tmp = fold_build2_loc (input_location, PLUS_EXPR, type,
    5985                 :             :                                          from, tmp);
    5986                 :             :                 }
    5987                 :             :               else
    5988                 :         177 :                 tmp = fold_build2_loc (input_location, PLUS_EXPR, type,
    5989                 :             :                                        dovar, step);
    5990                 :         237 :               tmp = fold_build2_loc (input_location, MODIFY_EXPR, type,
    5991                 :             :                                      dovar, tmp);
    5992                 :         916 :               for (c = omp_clauses; c ; c = OMP_CLAUSE_CHAIN (c))
    5993                 :         607 :                 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
    5994                 :         607 :                     && OMP_CLAUSE_DECL (c) == dovar_decl)
    5995                 :             :                   {
    5996                 :         105 :                     OMP_CLAUSE_LASTPRIVATE_STMT (c) = tmp;
    5997                 :         105 :                     break;
    5998                 :             :                   }
    5999                 :         502 :                 else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR
    6000                 :         502 :                          && OMP_CLAUSE_DECL (c) == dovar_decl)
    6001                 :             :                   {
    6002                 :          60 :                     OMP_CLAUSE_LINEAR_STMT (c) = tmp;
    6003                 :          60 :                     break;
    6004                 :             :                   }
    6005                 :             :             }
    6006                 :        1544 :           if (c == NULL && op == EXEC_OMP_DO && par_clauses != NULL)
    6007                 :             :             {
    6008                 :         880 :               for (c = par_clauses; c ; c = OMP_CLAUSE_CHAIN (c))
    6009                 :         880 :                 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
    6010                 :         880 :                     && OMP_CLAUSE_DECL (c) == dovar_decl)
    6011                 :             :                   {
    6012                 :         400 :                     tree l = build_omp_clause (input_location,
    6013                 :             :                                                OMP_CLAUSE_LASTPRIVATE);
    6014                 :         400 :                     if (OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c))
    6015                 :           4 :                       OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (l) = 1;
    6016                 :         400 :                     OMP_CLAUSE_DECL (l) = dovar_decl;
    6017                 :         400 :                     OMP_CLAUSE_CHAIN (l) = omp_clauses;
    6018                 :         400 :                     OMP_CLAUSE_LASTPRIVATE_STMT (l) = tmp;
    6019                 :         400 :                     omp_clauses = l;
    6020                 :         400 :                     OMP_CLAUSE_SET_CODE (c, OMP_CLAUSE_SHARED);
    6021                 :         400 :                     break;
    6022                 :             :                   }
    6023                 :             :             }
    6024                 :        1544 :           gcc_assert (local_dovar == dovar || c != NULL);
    6025                 :             :         }
    6026                 :       10561 :       if (local_dovar != dovar)
    6027                 :             :         {
    6028                 :         589 :           if (op != EXEC_OMP_SIMD || dovar_found == 1)
    6029                 :         510 :             tmp = build_omp_clause (input_location, OMP_CLAUSE_PRIVATE);
    6030                 :          79 :           else if (collapse == 1)
    6031                 :             :             {
    6032                 :          60 :               tmp = build_omp_clause (input_location, OMP_CLAUSE_LINEAR);
    6033                 :          60 :               OMP_CLAUSE_LINEAR_STEP (tmp) = build_int_cst (type, 1);
    6034                 :          60 :               OMP_CLAUSE_LINEAR_NO_COPYIN (tmp) = 1;
    6035                 :          60 :               OMP_CLAUSE_LINEAR_NO_COPYOUT (tmp) = 1;
    6036                 :             :             }
    6037                 :             :           else
    6038                 :          19 :             tmp = build_omp_clause (input_location, OMP_CLAUSE_LASTPRIVATE);
    6039                 :         589 :           OMP_CLAUSE_DECL (tmp) = local_dovar;
    6040                 :         589 :           omp_clauses = gfc_trans_add_clause (tmp, omp_clauses);
    6041                 :             :         }
    6042                 :             : 
    6043                 :       10561 :       if (i + 1 < collapse)
    6044                 :        2321 :         code = code->block->next;
    6045                 :             :     }
    6046                 :             : 
    6047                 :        8240 :   if (pblock != &block)
    6048                 :             :     {
    6049                 :        3023 :       pushlevel ();
    6050                 :        3023 :       gfc_start_block (&block);
    6051                 :             :     }
    6052                 :             : 
    6053                 :        8240 :   gfc_start_block (&body);
    6054                 :             : 
    6055                 :       17069 :   FOR_EACH_VEC_ELT (inits, ix, di)
    6056                 :         589 :     gfc_add_modify (&body, di->var, di->init);
    6057                 :        8240 :   inits.release ();
    6058                 :             : 
    6059                 :             :   /* Cycle statement is implemented with a goto.  Exit statement must not be
    6060                 :             :      present for this loop.  */
    6061                 :        8240 :   cycle_label = gfc_build_label_decl (NULL_TREE);
    6062                 :             : 
    6063                 :             :   /* Put these labels where they can be found later.  */
    6064                 :             : 
    6065                 :        8240 :   code->cycle_label = cycle_label;
    6066                 :        8240 :   code->exit_label = NULL_TREE;
    6067                 :             : 
    6068                 :             :   /* Main loop body.  */
    6069                 :        8240 :   if (clauses->lists[OMP_LIST_REDUCTION_INSCAN])
    6070                 :             :     {
    6071                 :          16 :       gfc_code *code1, *scan, *code2, *tmpcode;
    6072                 :          16 :       code1 = tmpcode = code->block->next;
    6073                 :          16 :       if (tmpcode && tmpcode->op != EXEC_OMP_SCAN)
    6074                 :          18 :         while (tmpcode && tmpcode->next && tmpcode->next->op != EXEC_OMP_SCAN)
    6075                 :             :           tmpcode = tmpcode->next;
    6076                 :          16 :       scan = tmpcode->op == EXEC_OMP_SCAN ? tmpcode : tmpcode->next;
    6077                 :          16 :       if (code1 != scan)
    6078                 :          16 :         tmpcode->next = NULL;
    6079                 :          16 :       code2 = scan->next;
    6080                 :          16 :       gcc_assert (scan->op == EXEC_OMP_SCAN);
    6081                 :          16 :       location_t loc = gfc_get_location (&scan->loc);
    6082                 :             : 
    6083                 :          16 :       tmp = code1 != scan ? gfc_trans_code (code1) : build_empty_stmt (loc);
    6084                 :          16 :       tmp = build2 (OMP_SCAN, void_type_node, tmp, NULL_TREE);
    6085                 :          16 :       SET_EXPR_LOCATION (tmp, loc);
    6086                 :          16 :       gfc_add_expr_to_block (&body, tmp);
    6087                 :          16 :       input_location = loc;
    6088                 :          16 :       tree c = gfc_trans_omp_clauses (&body, scan->ext.omp_clauses, scan->loc);
    6089                 :          16 :       tmp = code2 ? gfc_trans_code (code2) : build_empty_stmt (loc);
    6090                 :          16 :       tmp = build2 (OMP_SCAN, void_type_node, tmp, c);
    6091                 :          16 :       SET_EXPR_LOCATION (tmp, loc);
    6092                 :          16 :       if (code1 != scan)
    6093                 :          16 :         tmpcode->next = scan;
    6094                 :             :     }
    6095                 :             :   else
    6096                 :        8224 :     tmp = gfc_trans_omp_code (code->block->next, true);
    6097                 :        8240 :   gfc_add_expr_to_block (&body, tmp);
    6098                 :             : 
    6099                 :             :   /* Label for cycle statements (if needed).  */
    6100                 :        8240 :   if (TREE_USED (cycle_label))
    6101                 :             :     {
    6102                 :        8240 :       tmp = build1_v (LABEL_EXPR, cycle_label);
    6103                 :        8240 :       gfc_add_expr_to_block (&body, tmp);
    6104                 :             :     }
    6105                 :             : 
    6106                 :             :   /* End of loop body.  */
    6107                 :        8240 :   switch (op)
    6108                 :             :     {
    6109                 :        1438 :     case EXEC_OMP_SIMD: stmt = make_node (OMP_SIMD); break;
    6110                 :        2052 :     case EXEC_OMP_DO: stmt = make_node (OMP_FOR); break;
    6111                 :          80 :     case EXEC_OMP_DISTRIBUTE: stmt = make_node (OMP_DISTRIBUTE); break;
    6112                 :          98 :     case EXEC_OMP_LOOP: stmt = make_node (OMP_LOOP); break;
    6113                 :         112 :     case EXEC_OMP_TASKLOOP: stmt = make_node (OMP_TASKLOOP); break;
    6114                 :        4460 :     case EXEC_OACC_LOOP: stmt = make_node (OACC_LOOP); break;
    6115                 :           0 :     default: gcc_unreachable ();
    6116                 :             :     }
    6117                 :             : 
    6118                 :        8240 :   SET_EXPR_LOCATION (stmt, gfc_get_location (&orig_code->loc));
    6119                 :        8240 :   TREE_TYPE (stmt) = void_type_node;
    6120                 :        8240 :   OMP_FOR_BODY (stmt) = gfc_finish_block (&body);
    6121                 :        8240 :   OMP_FOR_CLAUSES (stmt) = omp_clauses;
    6122                 :        8240 :   OMP_FOR_INIT (stmt) = init;
    6123                 :        8240 :   OMP_FOR_COND (stmt) = cond;
    6124                 :        8240 :   OMP_FOR_INCR (stmt) = incr;
    6125                 :        8240 :   if (orig_decls)
    6126                 :         137 :     OMP_FOR_ORIG_DECLS (stmt) = orig_decls;
    6127                 :        8240 :   OMP_FOR_NON_RECTANGULAR (stmt) = clauses->non_rectangular;
    6128                 :        8240 :   gfc_add_expr_to_block (&block, stmt);
    6129                 :             : 
    6130                 :        8240 :   vec_free (doacross_steps);
    6131                 :        8240 :   doacross_steps = saved_doacross_steps;
    6132                 :             : 
    6133                 :        8240 :   return gfc_finish_block (&block);
    6134                 :             : }
    6135                 :             : 
    6136                 :             : /* Translate combined OpenACC 'parallel loop', 'kernels loop', 'serial loop'
    6137                 :             :    construct. */
    6138                 :             : 
    6139                 :             : static tree
    6140                 :        1374 : gfc_trans_oacc_combined_directive (gfc_code *code)
    6141                 :             : {
    6142                 :        1374 :   stmtblock_t block, *pblock = NULL;
    6143                 :        1374 :   gfc_omp_clauses construct_clauses, loop_clauses;
    6144                 :        1374 :   tree stmt, oacc_clauses = NULL_TREE;
    6145                 :        1374 :   enum tree_code construct_code;
    6146                 :        1374 :   location_t loc = input_location;
    6147                 :             : 
    6148                 :        1374 :   switch (code->op)
    6149                 :             :     {
    6150                 :             :       case EXEC_OACC_PARALLEL_LOOP:
    6151                 :             :         construct_code = OACC_PARALLEL;
    6152                 :             :         break;
    6153                 :             :       case EXEC_OACC_KERNELS_LOOP:
    6154                 :             :         construct_code = OACC_KERNELS;
    6155                 :             :         break;
    6156                 :             :       case EXEC_OACC_SERIAL_LOOP:
    6157                 :             :         construct_code = OACC_SERIAL;
    6158                 :             :         break;
    6159                 :           0 :       default:
    6160                 :           0 :         gcc_unreachable ();
    6161                 :             :     }
    6162                 :             : 
    6163                 :        1374 :   gfc_start_block (&block);
    6164                 :             : 
    6165                 :        1374 :   memset (&loop_clauses, 0, sizeof (loop_clauses));
    6166                 :        1374 :   if (code->ext.omp_clauses != NULL)
    6167                 :             :     {
    6168                 :        1374 :       memcpy (&construct_clauses, code->ext.omp_clauses,
    6169                 :             :               sizeof (construct_clauses));
    6170                 :        1374 :       loop_clauses.collapse = construct_clauses.collapse;
    6171                 :        1374 :       loop_clauses.gang = construct_clauses.gang;
    6172                 :        1374 :       loop_clauses.gang_static = construct_clauses.gang_static;
    6173                 :        1374 :       loop_clauses.gang_num_expr = construct_clauses.gang_num_expr;
    6174                 :        1374 :       loop_clauses.gang_static_expr = construct_clauses.gang_static_expr;
    6175                 :        1374 :       loop_clauses.vector = construct_clauses.vector;
    6176                 :        1374 :       loop_clauses.vector_expr = construct_clauses.vector_expr;
    6177                 :        1374 :       loop_clauses.worker = construct_clauses.worker;
    6178                 :        1374 :       loop_clauses.worker_expr = construct_clauses.worker_expr;
    6179                 :        1374 :       loop_clauses.seq = construct_clauses.seq;
    6180                 :        1374 :       loop_clauses.par_auto = construct_clauses.par_auto;
    6181                 :        1374 :       loop_clauses.independent = construct_clauses.independent;
    6182                 :        1374 :       loop_clauses.tile_list = construct_clauses.tile_list;
    6183                 :        1374 :       loop_clauses.lists[OMP_LIST_PRIVATE]
    6184                 :        1374 :         = construct_clauses.lists[OMP_LIST_PRIVATE];
    6185                 :        1374 :       loop_clauses.lists[OMP_LIST_REDUCTION]
    6186                 :        1374 :         = construct_clauses.lists[OMP_LIST_REDUCTION];
    6187                 :        1374 :       construct_clauses.gang = false;
    6188                 :        1374 :       construct_clauses.gang_static = false;
    6189                 :        1374 :       construct_clauses.gang_num_expr = NULL;
    6190                 :        1374 :       construct_clauses.gang_static_expr = NULL;
    6191                 :        1374 :       construct_clauses.vector = false;
    6192                 :        1374 :       construct_clauses.vector_expr = NULL;
    6193                 :        1374 :       construct_clauses.worker = false;
    6194                 :        1374 :       construct_clauses.worker_expr = NULL;
    6195                 :        1374 :       construct_clauses.seq = false;
    6196                 :        1374 :       construct_clauses.par_auto = false;
    6197                 :        1374 :       construct_clauses.independent = false;
    6198                 :        1374 :       construct_clauses.independent = false;
    6199                 :        1374 :       construct_clauses.tile_list = NULL;
    6200                 :        1374 :       construct_clauses.lists[OMP_LIST_PRIVATE] = NULL;
    6201                 :        1374 :       if (construct_code == OACC_KERNELS)
    6202                 :          86 :         construct_clauses.lists[OMP_LIST_REDUCTION] = NULL;
    6203                 :        1374 :       oacc_clauses = gfc_trans_omp_clauses (&block, &construct_clauses,
    6204                 :             :                                             code->loc, false, true);
    6205                 :             :     }
    6206                 :        1374 :   if (!loop_clauses.seq)
    6207                 :             :     pblock = &block;
    6208                 :             :   else
    6209                 :          31 :     pushlevel ();
    6210                 :        1374 :   stmt = gfc_trans_omp_do (code, EXEC_OACC_LOOP, pblock, &loop_clauses, NULL);
    6211                 :        1374 :   protected_set_expr_location (stmt, loc);
    6212                 :        1374 :   if (TREE_CODE (stmt) != BIND_EXPR)
    6213                 :        1374 :     stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
    6214                 :             :   else
    6215                 :           0 :     poplevel (0, 0);
    6216                 :        1374 :   stmt = build2_loc (loc, construct_code, void_type_node, stmt, oacc_clauses);
    6217                 :        1374 :   gfc_add_expr_to_block (&block, stmt);
    6218                 :        1374 :   return gfc_finish_block (&block);
    6219                 :             : }
    6220                 :             : 
    6221                 :             : static tree
    6222                 :         106 : gfc_trans_omp_depobj (gfc_code *code)
    6223                 :             : {
    6224                 :         106 :   stmtblock_t block;
    6225                 :         106 :   gfc_se se;
    6226                 :         106 :   gfc_init_se (&se, NULL);
    6227                 :         106 :   gfc_init_block (&block);
    6228                 :         106 :   gfc_conv_expr (&se, code->ext.omp_clauses->depobj);
    6229                 :         106 :   gcc_assert (se.pre.head == NULL && se.post.head == NULL);
    6230                 :         106 :   tree depobj = se.expr;
    6231                 :         106 :   location_t loc = EXPR_LOCATION (depobj);
    6232                 :         106 :   if (!POINTER_TYPE_P (TREE_TYPE (depobj)))
    6233                 :         106 :     depobj = gfc_build_addr_expr (NULL, depobj);
    6234                 :         106 :   depobj = fold_convert (build_pointer_type_for_mode (ptr_type_node,
    6235                 :             :                                                       TYPE_MODE (ptr_type_node),
    6236                 :             :                                                       true), depobj);
    6237                 :         106 :   gfc_omp_namelist *n = code->ext.omp_clauses->lists[OMP_LIST_DEPEND];
    6238                 :         106 :   if (n)
    6239                 :             :     {
    6240                 :          82 :       tree var;
    6241                 :          82 :       if (!n->sym)  /* omp_all_memory.  */
    6242                 :           3 :         var = null_pointer_node;
    6243                 :          79 :       else if (n->expr && n->expr->ref->u.ar.type != AR_FULL)
    6244                 :             :         {
    6245                 :          18 :           gfc_init_se (&se, NULL);
    6246                 :          18 :           if (n->expr->ref->u.ar.type == AR_ELEMENT)
    6247                 :             :             {
    6248                 :          18 :               gfc_conv_expr_reference (&se, n->expr);
    6249                 :          18 :               var = se.expr;
    6250                 :             :             }
    6251                 :             :           else
    6252                 :             :             {
    6253                 :           0 :               gfc_conv_expr_descriptor (&se, n->expr);
    6254                 :           0 :               var = gfc_conv_array_data (se.expr);
    6255                 :             :             }
    6256                 :          18 :           gfc_add_block_to_block (&block, &se.pre);
    6257                 :          18 :           gfc_add_block_to_block (&block, &se.post);
    6258                 :          18 :           gcc_assert (POINTER_TYPE_P (TREE_TYPE (var)));
    6259                 :             :         }
    6260                 :             :       else
    6261                 :             :         {
    6262                 :          61 :           var = gfc_get_symbol_decl (n->sym);
    6263                 :          98 :           if (POINTER_TYPE_P (TREE_TYPE (var))
    6264                 :          71 :               && GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (TREE_TYPE (var))))
    6265                 :           8 :             var = build_fold_indirect_ref (var);
    6266                 :          61 :           if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (var)))
    6267                 :             :             {
    6268                 :          12 :               var = gfc_conv_descriptor_data_get (var);
    6269                 :          12 :               gcc_assert (POINTER_TYPE_P (TREE_TYPE (var)));
    6270                 :             :             }
    6271                 :          49 :           else if ((n->sym->attr.allocatable || n->sym->attr.pointer)
    6272                 :          13 :                    && n->sym->attr.dummy)
    6273                 :           8 :             var = build_fold_indirect_ref (var);
    6274                 :          66 :           else if (!POINTER_TYPE_P (TREE_TYPE (var))
    6275                 :          43 :                    || (n->sym->ts.f90_type == BT_VOID
    6276                 :          11 :                        && !POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (var)))
    6277                 :           7 :                        && !GFC_ARRAY_TYPE_P (TREE_TYPE (TREE_TYPE (var)))))
    6278                 :             :             {
    6279                 :          28 :               TREE_ADDRESSABLE (var) = 1;
    6280                 :          28 :               var = gfc_build_addr_expr (NULL, var);
    6281                 :             :             }
    6282                 :             :         }
    6283                 :          82 :       depobj = save_expr (depobj);
    6284                 :          82 :       tree r = build_fold_indirect_ref_loc (loc, depobj);
    6285                 :          82 :       gfc_add_expr_to_block (&block,
    6286                 :             :                              build2 (MODIFY_EXPR, void_type_node, r, var));
    6287                 :             :     }
    6288                 :             : 
    6289                 :             :   /* Only one may be set. */
    6290                 :         106 :   gcc_assert (((int)(n != NULL) + (int)(code->ext.omp_clauses->destroy)
    6291                 :             :               + (int)(code->ext.omp_clauses->depobj_update != OMP_DEPEND_UNSET))
    6292                 :             :               == 1);
    6293                 :         106 :   int k = -1; /* omp_clauses->destroy */
    6294                 :         106 :   if (!code->ext.omp_clauses->destroy)
    6295                 :          91 :     switch (code->ext.omp_clauses->depobj_update != OMP_DEPEND_UNSET
    6296                 :          91 :             ? code->ext.omp_clauses->depobj_update : n->u.depend_doacross_op)
    6297                 :             :       {
    6298                 :             :       case OMP_DEPEND_IN: k = GOMP_DEPEND_IN; break;
    6299                 :             :       case OMP_DEPEND_OUT: k = GOMP_DEPEND_OUT; break;
    6300                 :             :       case OMP_DEPEND_INOUT: k = GOMP_DEPEND_INOUT; break;
    6301                 :             :       case OMP_DEPEND_INOUTSET: k = GOMP_DEPEND_INOUTSET; break;
    6302                 :             :       case OMP_DEPEND_MUTEXINOUTSET: k = GOMP_DEPEND_MUTEXINOUTSET; break;
    6303                 :           0 :       default: gcc_unreachable ();
    6304                 :             :       }
    6305                 :         106 :   tree t = build_int_cst (ptr_type_node, k);
    6306                 :         106 :   depobj = build2_loc (loc, POINTER_PLUS_EXPR, TREE_TYPE (depobj), depobj,
    6307                 :         106 :                        TYPE_SIZE_UNIT (ptr_type_node));
    6308                 :         106 :   depobj = build_fold_indirect_ref_loc (loc, depobj);
    6309                 :         106 :   gfc_add_expr_to_block (&block, build2 (MODIFY_EXPR, void_type_node, depobj, t));
    6310                 :             : 
    6311                 :         106 :   return gfc_finish_block (&block);
    6312                 :             : }
    6313                 :             : 
    6314                 :             : static tree
    6315                 :          18 : gfc_trans_omp_error (gfc_code *code)
    6316                 :             : {
    6317                 :          18 :   stmtblock_t block;
    6318                 :          18 :   gfc_se se;
    6319                 :          18 :   tree len, message;
    6320                 :          18 :   bool fatal = code->ext.omp_clauses->severity == OMP_SEVERITY_FATAL;
    6321                 :          31 :   tree fndecl = builtin_decl_explicit (fatal ? BUILT_IN_GOMP_ERROR
    6322                 :             :                                              : BUILT_IN_GOMP_WARNING);
    6323                 :          18 :   gfc_start_block (&block);
    6324                 :          18 :   gfc_init_se (&se, NULL );
    6325                 :          18 :   if (!code->ext.omp_clauses->message)
    6326                 :             :     {
    6327                 :           3 :       message = null_pointer_node;
    6328                 :           3 :       len = build_int_cst (size_type_node, 0);
    6329                 :             :     }
    6330                 :             :   else
    6331                 :             :     {
    6332                 :          15 :       gfc_conv_expr (&se, code->ext.omp_clauses->message);
    6333                 :          15 :       message = se.expr;
    6334                 :          15 :       if (!POINTER_TYPE_P (TREE_TYPE (message)))
    6335                 :             :         /* To ensure an ARRAY_TYPE is not passed as such.  */
    6336                 :           6 :         message = gfc_build_addr_expr (NULL, message);
    6337                 :          15 :       len = se.string_length;
    6338                 :             :     }
    6339                 :          18 :   gfc_add_block_to_block (&block, &se.pre);
    6340                 :          18 :   gfc_add_expr_to_block (&block, build_call_expr_loc (input_location, fndecl,
    6341                 :             :                                                       2, message, len));
    6342                 :          18 :   gfc_add_block_to_block (&block, &se.post);
    6343                 :          18 :   return gfc_finish_block (&block);
    6344                 :             : }
    6345                 :             : 
    6346                 :             : static tree
    6347                 :          69 : gfc_trans_omp_flush (gfc_code *code)
    6348                 :             : {
    6349                 :          69 :   tree call;
    6350                 :          69 :   if (!code->ext.omp_clauses
    6351                 :           4 :       || code->ext.omp_clauses->memorder == OMP_MEMORDER_UNSET
    6352                 :           4 :       || code->ext.omp_clauses->memorder == OMP_MEMORDER_SEQ_CST)
    6353                 :             :     {
    6354                 :          66 :       call = builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE);
    6355                 :          66 :       call = build_call_expr_loc (input_location, call, 0);
    6356                 :             :     }
    6357                 :             :   else
    6358                 :             :     {
    6359                 :           3 :       enum memmodel mo = MEMMODEL_LAST;
    6360                 :           3 :       switch (code->ext.omp_clauses->memorder)
    6361                 :             :         {
    6362                 :             :         case OMP_MEMORDER_ACQ_REL: mo = MEMMODEL_ACQ_REL; break;
    6363                 :             :         case OMP_MEMORDER_RELEASE: mo = MEMMODEL_RELEASE; break;
    6364                 :             :         case OMP_MEMORDER_ACQUIRE: mo = MEMMODEL_ACQUIRE; break;
    6365                 :           0 :         default: gcc_unreachable (); break;
    6366                 :             :         }
    6367                 :           3 :       call = builtin_decl_explicit (BUILT_IN_ATOMIC_THREAD_FENCE);
    6368                 :           3 :       call = build_call_expr_loc (input_location, call, 1,
    6369                 :             :                                   build_int_cst (integer_type_node, mo));
    6370                 :             :     }
    6371                 :          69 :   return call;
    6372                 :             : }
    6373                 :             : 
    6374                 :             : static tree
    6375                 :         115 : gfc_trans_omp_master (gfc_code *code)
    6376                 :             : {
    6377                 :         115 :   tree stmt = gfc_trans_code (code->block->next);
    6378                 :         115 :   if (IS_EMPTY_STMT (stmt))
    6379                 :             :     return stmt;
    6380                 :         109 :   return build1_v (OMP_MASTER, stmt);
    6381                 :             : }
    6382                 :             : 
    6383                 :             : static tree
    6384                 :          48 : gfc_trans_omp_masked (gfc_code *code, gfc_omp_clauses *clauses)
    6385                 :             : {
    6386                 :          48 :   stmtblock_t block;
    6387                 :          48 :   tree body = gfc_trans_code (code->block->next);
    6388                 :          48 :   if (IS_EMPTY_STMT (body))
    6389                 :             :     return body;
    6390                 :          39 :   if (!clauses)
    6391                 :          32 :     clauses = code->ext.omp_clauses;
    6392                 :          39 :   gfc_start_block (&block);
    6393                 :          39 :   tree omp_clauses = gfc_trans_omp_clauses (&block, clauses, code->loc);
    6394                 :          39 :   tree stmt = make_node (OMP_MASKED);
    6395                 :          39 :   SET_EXPR_LOCATION (stmt, gfc_get_location (&code->loc));
    6396                 :          39 :   TREE_TYPE (stmt) = void_type_node;
    6397                 :          39 :   OMP_MASKED_BODY (stmt) = body;
    6398                 :          39 :   OMP_MASKED_CLAUSES (stmt) = omp_clauses;
    6399                 :          39 :   gfc_add_expr_to_block (&block, stmt);
    6400                 :          39 :   return gfc_finish_block (&block);
    6401                 :             : }
    6402                 :             : 
    6403                 :             : 
    6404                 :             : static tree
    6405                 :         519 : gfc_trans_omp_ordered (gfc_code *code)
    6406                 :             : {
    6407                 :         519 :   if (!flag_openmp)
    6408                 :             :     {
    6409                 :           5 :       if (!code->ext.omp_clauses->simd)
    6410                 :           3 :         return gfc_trans_code (code->block ? code->block->next : NULL);
    6411                 :           2 :       code->ext.omp_clauses->threads = 0;
    6412                 :             :     }
    6413                 :         516 :   tree omp_clauses = gfc_trans_omp_clauses (NULL, code->ext.omp_clauses,
    6414                 :             :                                             code->loc);
    6415                 :         516 :   return build2_loc (input_location, OMP_ORDERED, void_type_node,
    6416                 :         516 :                      code->block ? gfc_trans_code (code->block->next)
    6417                 :         516 :                      : NULL_TREE, omp_clauses);
    6418                 :             : }
    6419                 :             : 
    6420                 :             : static tree
    6421                 :        1848 : gfc_trans_omp_parallel (gfc_code *code)
    6422                 :             : {
    6423                 :        1848 :   stmtblock_t block;
    6424                 :        1848 :   tree stmt, omp_clauses;
    6425                 :             : 
    6426                 :        1848 :   gfc_start_block (&block);
    6427                 :        1848 :   omp_clauses = gfc_trans_omp_clauses (&block, code->ext.omp_clauses,
    6428                 :             :                                        code->loc);
    6429                 :        1848 :   pushlevel ();
    6430                 :        1848 :   stmt = gfc_trans_omp_code (code->block->next, true);
    6431                 :        1848 :   stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
    6432                 :        1848 :   stmt = build2_loc (input_location, OMP_PARALLEL, void_type_node, stmt,
    6433                 :             :                      omp_clauses);
    6434                 :        1848 :   gfc_add_expr_to_block (&block, stmt);
    6435                 :        1848 :   return gfc_finish_block (&block);
    6436                 :             : }
    6437                 :             : 
    6438                 :             : enum
    6439                 :             : {
    6440                 :             :   GFC_OMP_SPLIT_SIMD,
    6441                 :             :   GFC_OMP_SPLIT_DO,
    6442                 :             :   GFC_OMP_SPLIT_PARALLEL,
    6443                 :             :   GFC_OMP_SPLIT_DISTRIBUTE,
    6444                 :             :   GFC_OMP_SPLIT_TEAMS,
    6445                 :             :   GFC_OMP_SPLIT_TARGET,
    6446                 :             :   GFC_OMP_SPLIT_TASKLOOP,
    6447                 :             :   GFC_OMP_SPLIT_MASKED,
    6448                 :             :   GFC_OMP_SPLIT_NUM
    6449                 :             : };
    6450                 :             : 
    6451                 :             : enum
    6452                 :             : {
    6453                 :             :   GFC_OMP_MASK_SIMD = (1 << GFC_OMP_SPLIT_SIMD),
    6454                 :             :   GFC_OMP_MASK_DO = (1 << GFC_OMP_SPLIT_DO),
    6455                 :             :   GFC_OMP_MASK_PARALLEL = (1 << GFC_OMP_SPLIT_PARALLEL),
    6456                 :             :   GFC_OMP_MASK_DISTRIBUTE = (1 << GFC_OMP_SPLIT_DISTRIBUTE),
    6457                 :             :   GFC_OMP_MASK_TEAMS = (1 << GFC_OMP_SPLIT_TEAMS),
    6458                 :             :   GFC_OMP_MASK_TARGET = (1 << GFC_OMP_SPLIT_TARGET),
    6459                 :             :   GFC_OMP_MASK_TASKLOOP = (1 << GFC_OMP_SPLIT_TASKLOOP),
    6460                 :             :   GFC_OMP_MASK_MASKED = (1 << GFC_OMP_SPLIT_MASKED)
    6461                 :             : };
    6462                 :             : 
    6463                 :             : /* If a var is in lastprivate/firstprivate/reduction but not in a
    6464                 :             :    data mapping/sharing clause, add it to 'map(tofrom:' if is_target
    6465                 :             :    and to 'shared' otherwise.  */
    6466                 :             : static void
    6467                 :        2147 : gfc_add_clause_implicitly (gfc_omp_clauses *clauses_out,
    6468                 :             :                            gfc_omp_clauses *clauses_in,
    6469                 :             :                            bool is_target, bool is_parallel_do)
    6470                 :             : {
    6471                 :        2147 :   int clauselist_to_add = is_target ? OMP_LIST_MAP : OMP_LIST_SHARED;
    6472                 :        2147 :   gfc_omp_namelist *tail = NULL;
    6473                 :       12882 :   for (int i = 0; i < 5; ++i)
    6474                 :             :     {
    6475                 :       10735 :       gfc_omp_namelist *n;
    6476                 :       10735 :       switch (i)
    6477                 :             :         {
    6478                 :        2147 :         case 0: n = clauses_in->lists[OMP_LIST_FIRSTPRIVATE]; break;
    6479                 :        2147 :         case 1: n = clauses_in->lists[OMP_LIST_LASTPRIVATE]; break;
    6480                 :        2147 :         case 2: n = clauses_in->lists[OMP_LIST_REDUCTION]; break;
    6481                 :        2147 :         case 3: n = clauses_in->lists[OMP_LIST_REDUCTION_INSCAN]; break;
    6482                 :        2147 :         case 4: n = clauses_in->lists[OMP_LIST_REDUCTION_TASK]; break;
    6483                 :             :         default: gcc_unreachable ();
    6484                 :             :         }
    6485                 :       13954 :       for (; n != NULL; n = n->next)
    6486                 :             :         {
    6487                 :             :           gfc_omp_namelist *n2, **n_firstp = NULL, **n_lastp = NULL;
    6488                 :       20075 :           for (int j = 0; j < 6; ++j)
    6489                 :             :             {
    6490                 :       17650 :               gfc_omp_namelist **n2ref = NULL, *prev2 = NULL;
    6491                 :       17650 :               switch (j)
    6492                 :             :                 {
    6493                 :        3219 :                 case 0:
    6494                 :        3219 :                   n2ref = &clauses_out->lists[clauselist_to_add];
    6495                 :        3219 :                   break;
    6496                 :        3189 :                 case 1:
    6497                 :        3189 :                   n2ref = &clauses_out->lists[OMP_LIST_FIRSTPRIVATE];
    6498                 :        3189 :                   break;
    6499                 :        3189 :                 case 2:
    6500                 :        3189 :                   if (is_target)
    6501                 :         255 :                     n2ref = &clauses_in->lists[OMP_LIST_LASTPRIVATE];
    6502                 :             :                   else
    6503                 :        2934 :                     n2ref = &clauses_out->lists[OMP_LIST_LASTPRIVATE];
    6504                 :             :                   break;
    6505                 :        3189 :                 case 3: n2ref = &clauses_out->lists[OMP_LIST_REDUCTION]; break;
    6506                 :        2432 :                 case 4:
    6507                 :        2432 :                   n2ref = &clauses_out->lists[OMP_LIST_REDUCTION_INSCAN];
    6508                 :        2432 :                   break;
    6509                 :        2432 :                 case 5:
    6510                 :        2432 :                   n2ref = &clauses_out->lists[OMP_LIST_REDUCTION_TASK];
    6511                 :        2432 :                   break;
    6512                 :             :                 default: gcc_unreachable ();
    6513                 :             :                 }
    6514                 :       27888 :               for (n2 = *n2ref; n2 != NULL; prev2 = n2, n2 = n2->next)
    6515                 :       13384 :                 if (n2->sym == n->sym)
    6516                 :             :                   break;
    6517                 :       17650 :               if (n2)
    6518                 :             :                 {
    6519                 :        3146 :                   if (j == 0 /* clauselist_to_add */)
    6520                 :             :                     break;  /* Already present.  */
    6521                 :        3116 :                   if (j == 1 /* OMP_LIST_FIRSTPRIVATE */)
    6522                 :             :                     {
    6523                 :        1128 :                       n_firstp = prev2 ? &prev2->next : n2ref;
    6524                 :        1128 :                       continue;
    6525                 :             :                     }
    6526                 :        1988 :                   if (j == 2 /* OMP_LIST_LASTPRIVATE */)
    6527                 :             :                     {
    6528                 :        1224 :                       n_lastp = prev2 ? &prev2->next : n2ref;
    6529                 :        1224 :                       continue;
    6530                 :             :                     }
    6531                 :             :                   break;
    6532                 :             :                 }
    6533                 :             :             }
    6534                 :        3219 :           if (n_firstp && n_lastp)
    6535                 :             :             {
    6536                 :             :               /* For parallel do, GCC puts firstprivate/lastprivate
    6537                 :             :                  on the parallel.  */
    6538                 :         283 :               if (is_parallel_do)
    6539                 :         280 :                 continue;
    6540                 :           3 :               *n_firstp = (*n_firstp)->next;
    6541                 :           3 :               if (!is_target)
    6542                 :           0 :                 *n_lastp = (*n_lastp)->next;
    6543                 :             :             }
    6544                 :        2936 :           else if (is_target && n_lastp)
    6545                 :             :             ;
    6546                 :        2881 :           else if (n2 || n_firstp || n_lastp)
    6547                 :        2525 :             continue;
    6548                 :         414 :           if (clauses_out->lists[clauselist_to_add]
    6549                 :         305 :               && (clauses_out->lists[clauselist_to_add]
    6550                 :         305 :                   == clauses_in->lists[clauselist_to_add]))
    6551                 :             :             {
    6552                 :             :               gfc_omp_namelist *p = NULL;
    6553                 :         421 :               for (n2 = clauses_in->lists[clauselist_to_add]; n2; n2 = n2->next)
    6554                 :             :                 {
    6555                 :         273 :                   if (p)
    6556                 :             :                     {
    6557                 :         125 :                       p->next = gfc_get_omp_namelist ();
    6558                 :         125 :                       p = p->next;
    6559                 :             :                     }
    6560                 :             :                   else
    6561                 :             :                     {
    6562                 :         148 :                       p = gfc_get_omp_namelist ();
    6563                 :         148 :                       clauses_out->lists[clauselist_to_add] = p;
    6564                 :             :                     }
    6565                 :         273 :                   *p = *n2;
    6566                 :             :                 }
    6567                 :             :             }
    6568                 :         414 :           if (!tail)
    6569                 :             :             {
    6570                 :         285 :               tail = clauses_out->lists[clauselist_to_add];
    6571                 :         410 :               for (; tail && tail->next; tail = tail->next)
    6572                 :             :                 ;
    6573                 :             :             }
    6574                 :         414 :           n2 = gfc_get_omp_namelist ();
    6575                 :         414 :           n2->where = n->where;
    6576                 :         414 :           n2->sym = n->sym;
    6577                 :         414 :           if (is_target)
    6578                 :         119 :             n2->u.map.op = OMP_MAP_TOFROM;
    6579                 :         414 :           if (tail)
    6580                 :             :             {
    6581                 :         305 :               tail->next = n2;
    6582                 :         305 :               tail = n2;
    6583                 :             :             }
    6584                 :             :           else
    6585                 :         109 :             clauses_out->lists[clauselist_to_add] = n2;
    6586                 :             :         }
    6587                 :             :     }
    6588                 :        2147 : }
    6589                 :             : 
    6590                 :             : /* Kind of opposite to above, add firstprivate to CLAUSES_OUT if it is mapped
    6591                 :             :    in CLAUSES_IN's FIRSTPRIVATE list but not its MAP list.  */
    6592                 :             : 
    6593                 :             : static void
    6594                 :         295 : gfc_add_firstprivate_if_unmapped (gfc_omp_clauses *clauses_out,
    6595                 :             :                                   gfc_omp_clauses *clauses_in)
    6596                 :             : {
    6597                 :         295 :   gfc_omp_namelist *n = clauses_in->lists[OMP_LIST_FIRSTPRIVATE];
    6598                 :         295 :   gfc_omp_namelist **tail = NULL;
    6599                 :             : 
    6600                 :         445 :   for (; n != NULL; n = n->next)
    6601                 :             :     {
    6602                 :         150 :       gfc_omp_namelist *n2 = clauses_out->lists[OMP_LIST_MAP];
    6603                 :         192 :       for (; n2 != NULL; n2 = n2->next)
    6604                 :          53 :         if (n->sym == n2->sym)
    6605                 :             :           break;
    6606                 :         150 :       if (n2 == NULL)
    6607                 :             :         {
    6608                 :         139 :           gfc_omp_namelist *dup = gfc_get_omp_namelist ();
    6609                 :         139 :           *dup = *n;
    6610                 :         139 :           dup->next = NULL;
    6611                 :         139 :           if (!tail)
    6612                 :             :             {
    6613                 :          76 :               tail = &clauses_out->lists[OMP_LIST_FIRSTPRIVATE];
    6614                 :          76 :               while (*tail && (*tail)->next)
    6615                 :           0 :                 tail = &(*tail)->next;
    6616                 :             :             }
    6617                 :         139 :           *tail = dup;
    6618                 :         139 :           tail = &(*tail)->next;
    6619                 :             :         }
    6620                 :             :     }
    6621                 :         295 : }
    6622                 :             : 
    6623                 :             : static void
    6624                 :        3569 : gfc_free_split_omp_clauses (gfc_code *code, gfc_omp_clauses *clausesa)
    6625                 :             : {
    6626                 :       32121 :   for (int i = 0; i < GFC_OMP_SPLIT_NUM; ++i)
    6627                 :      970768 :     for (int j = 0; j < OMP_LIST_NUM; ++j)
    6628                 :      942216 :       if (clausesa[i].lists[j] && clausesa[i].lists[j] != code->ext.omp_clauses->lists[j])
    6629                 :        1389 :         for (gfc_omp_namelist *n = clausesa[i].lists[j]; n;)
    6630                 :             :           {
    6631                 :         952 :             gfc_omp_namelist *p = n;
    6632                 :         952 :             n = n->next;
    6633                 :         952 :             free (p);
    6634                 :             :           }
    6635                 :        3569 : }
    6636                 :             : 
    6637                 :             : static void
    6638                 :        3569 : gfc_split_omp_clauses (gfc_code *code,
    6639                 :             :                        gfc_omp_clauses clausesa[GFC_OMP_SPLIT_NUM])
    6640                 :             : {
    6641                 :        3569 :   int mask = 0, innermost = 0;
    6642                 :        3569 :   bool is_loop = false;
    6643                 :        3569 :   memset (clausesa, 0, GFC_OMP_SPLIT_NUM * sizeof (gfc_omp_clauses));
    6644                 :        3569 :   switch (code->op)
    6645                 :             :     {
    6646                 :             :     case EXEC_OMP_DISTRIBUTE:
    6647                 :             :       innermost = GFC_OMP_SPLIT_DISTRIBUTE;
    6648                 :             :       break;
    6649                 :          30 :     case EXEC_OMP_DISTRIBUTE_PARALLEL_DO:
    6650                 :          30 :       mask = GFC_OMP_MASK_DISTRIBUTE | GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_DO;
    6651                 :          30 :       innermost = GFC_OMP_SPLIT_DO;
    6652                 :          30 :       break;
    6653                 :          28 :     case EXEC_OMP_DISTRIBUTE_PARALLEL_DO_SIMD:
    6654                 :          28 :       mask = GFC_OMP_MASK_DISTRIBUTE | GFC_OMP_MASK_PARALLEL
    6655                 :             :              | GFC_OMP_MASK_DO | GFC_OMP_MASK_SIMD;
    6656                 :          28 :       innermost = GFC_OMP_SPLIT_SIMD;
    6657                 :          28 :       break;
    6658                 :          47 :     case EXEC_OMP_DISTRIBUTE_SIMD:
    6659                 :          47 :       mask = GFC_OMP_MASK_DISTRIBUTE | GFC_OMP_MASK_SIMD;
    6660                 :          47 :       innermost = GFC_OMP_SPLIT_SIMD;
    6661                 :          47 :       break;
    6662                 :           0 :     case EXEC_OMP_DO:
    6663                 :           0 :     case EXEC_OMP_LOOP:
    6664                 :           0 :       innermost = GFC_OMP_SPLIT_DO;
    6665                 :           0 :       break;
    6666                 :         126 :     case EXEC_OMP_DO_SIMD:
    6667                 :         126 :       mask = GFC_OMP_MASK_DO | GFC_OMP_MASK_SIMD;
    6668                 :         126 :       innermost = GFC_OMP_SPLIT_SIMD;
    6669                 :         126 :       break;
    6670                 :           0 :     case EXEC_OMP_PARALLEL:
    6671                 :           0 :       innermost = GFC_OMP_SPLIT_PARALLEL;
    6672                 :           0 :       break;
    6673                 :         841 :     case EXEC_OMP_PARALLEL_DO:
    6674                 :         841 :     case EXEC_OMP_PARALLEL_LOOP:
    6675                 :         841 :       mask = GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_DO;
    6676                 :         841 :       innermost = GFC_OMP_SPLIT_DO;
    6677                 :         841 :       break;
    6678                 :         278 :     case EXEC_OMP_PARALLEL_DO_SIMD:
    6679                 :         278 :       mask = GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_DO | GFC_OMP_MASK_SIMD;
    6680                 :         278 :       innermost = GFC_OMP_SPLIT_SIMD;
    6681                 :         278 :       break;
    6682                 :          11 :     case EXEC_OMP_PARALLEL_MASKED:
    6683                 :          11 :       mask = GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_MASKED;
    6684                 :          11 :       innermost = GFC_OMP_SPLIT_MASKED;
    6685                 :          11 :       break;
    6686                 :          14 :     case EXEC_OMP_PARALLEL_MASKED_TASKLOOP:
    6687                 :          14 :       mask = (GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_MASKED
    6688                 :             :               | GFC_OMP_MASK_TASKLOOP | GFC_OMP_MASK_SIMD);
    6689                 :          14 :       innermost = GFC_OMP_SPLIT_TASKLOOP;
    6690                 :          14 :       break;
    6691                 :          20 :     case EXEC_OMP_PARALLEL_MASTER_TASKLOOP:
    6692                 :          20 :       mask = GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_TASKLOOP | GFC_OMP_MASK_SIMD;
    6693                 :          20 :       innermost = GFC_OMP_SPLIT_TASKLOOP;
    6694                 :          20 :       break;
    6695                 :          24 :     case EXEC_OMP_PARALLEL_MASKED_TASKLOOP_SIMD:
    6696                 :          24 :       mask = (GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_MASKED
    6697                 :             :               | GFC_OMP_MASK_TASKLOOP | GFC_OMP_MASK_SIMD);
    6698                 :          24 :       innermost = GFC_OMP_SPLIT_SIMD;
    6699                 :          24 :       break;
    6700                 :          26 :     case EXEC_OMP_PARALLEL_MASTER_TASKLOOP_SIMD:
    6701                 :          26 :       mask = GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_TASKLOOP | GFC_OMP_MASK_SIMD;
    6702                 :          26 :       innermost = GFC_OMP_SPLIT_SIMD;
    6703                 :          26 :       break;
    6704                 :           0 :     case EXEC_OMP_SIMD:
    6705                 :           0 :       innermost = GFC_OMP_SPLIT_SIMD;
    6706                 :           0 :       break;
    6707                 :        1488 :     case EXEC_OMP_TARGET:
    6708                 :        1488 :       innermost = GFC_OMP_SPLIT_TARGET;
    6709                 :        1488 :       break;
    6710                 :          20 :     case EXEC_OMP_TARGET_PARALLEL:
    6711                 :          20 :       mask = GFC_OMP_MASK_TARGET | GFC_OMP_MASK_PARALLEL;
    6712                 :          20 :       innermost = GFC_OMP_SPLIT_PARALLEL;
    6713                 :          20 :       break;
    6714                 :          51 :     case EXEC_OMP_TARGET_PARALLEL_DO:
    6715                 :          51 :     case EXEC_OMP_TARGET_PARALLEL_LOOP:
    6716                 :          51 :       mask = GFC_OMP_MASK_TARGET | GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_DO;
    6717                 :          51 :       innermost = GFC_OMP_SPLIT_DO;
    6718                 :          51 :       break;
    6719                 :          15 :     case EXEC_OMP_TARGET_PARALLEL_DO_SIMD:
    6720                 :          15 :       mask = GFC_OMP_MASK_TARGET | GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_DO
    6721                 :             :              | GFC_OMP_MASK_SIMD;
    6722                 :          15 :       innermost = GFC_OMP_SPLIT_SIMD;
    6723                 :          15 :       break;
    6724                 :          26 :     case EXEC_OMP_TARGET_SIMD:
    6725                 :          26 :       mask = GFC_OMP_MASK_TARGET | GFC_OMP_MASK_SIMD;
    6726                 :          26 :       innermost = GFC_OMP_SPLIT_SIMD;
    6727                 :          26 :       break;
    6728                 :          63 :     case EXEC_OMP_TARGET_TEAMS:
    6729                 :          63 :       mask = GFC_OMP_MASK_TARGET | GFC_OMP_MASK_TEAMS;
    6730                 :          63 :       innermost = GFC_OMP_SPLIT_TEAMS;
    6731                 :          63 :       break;
    6732                 :          14 :     case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE:
    6733                 :          14 :       mask = GFC_OMP_MASK_TARGET | GFC_OMP_MASK_TEAMS
    6734                 :             :              | GFC_OMP_MASK_DISTRIBUTE;
    6735                 :          14 :       innermost = GFC_OMP_SPLIT_DISTRIBUTE;
    6736                 :          14 :       break;
    6737                 :          49 :     case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO:
    6738                 :          49 :       mask = GFC_OMP_MASK_TARGET | GFC_OMP_MASK_TEAMS | GFC_OMP_MASK_DISTRIBUTE
    6739                 :             :              | GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_DO;
    6740                 :          49 :       innermost = GFC_OMP_SPLIT_DO;
    6741                 :          49 :       break;
    6742                 :          29 :     case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
    6743                 :          29 :       mask = GFC_OMP_MASK_TARGET | GFC_OMP_MASK_TEAMS | GFC_OMP_MASK_DISTRIBUTE
    6744                 :             :              | GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_DO | GFC_OMP_MASK_SIMD;
    6745                 :          29 :       innermost = GFC_OMP_SPLIT_SIMD;
    6746                 :          29 :       break;
    6747                 :          16 :     case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD:
    6748                 :          16 :       mask = GFC_OMP_MASK_TARGET | GFC_OMP_MASK_TEAMS
    6749                 :             :              | GFC_OMP_MASK_DISTRIBUTE | GFC_OMP_MASK_SIMD;
    6750                 :          16 :       innermost = GFC_OMP_SPLIT_SIMD;
    6751                 :          16 :       break;
    6752                 :          12 :     case EXEC_OMP_TARGET_TEAMS_LOOP:
    6753                 :          12 :       mask = GFC_OMP_MASK_TARGET | GFC_OMP_MASK_TEAMS | GFC_OMP_MASK_DO;
    6754                 :          12 :       innermost = GFC_OMP_SPLIT_DO;
    6755                 :          12 :       break;
    6756                 :           8 :     case EXEC_OMP_MASKED_TASKLOOP:
    6757                 :           8 :       mask = GFC_OMP_MASK_MASKED | GFC_OMP_MASK_TASKLOOP;
    6758                 :           8 :       innermost = GFC_OMP_SPLIT_TASKLOOP;
    6759                 :           8 :       break;
    6760                 :           0 :     case EXEC_OMP_MASTER_TASKLOOP:
    6761                 :           0 :     case EXEC_OMP_TASKLOOP:
    6762                 :           0 :       innermost = GFC_OMP_SPLIT_TASKLOOP;
    6763                 :           0 :       break;
    6764                 :          22 :     case EXEC_OMP_MASKED_TASKLOOP_SIMD:
    6765                 :          22 :       mask = GFC_OMP_MASK_MASKED | GFC_OMP_MASK_TASKLOOP | GFC_OMP_MASK_SIMD;
    6766                 :          22 :       innermost = GFC_OMP_SPLIT_SIMD;
    6767                 :          22 :       break;
    6768                 :          45 :     case EXEC_OMP_MASTER_TASKLOOP_SIMD:
    6769                 :          45 :     case EXEC_OMP_TASKLOOP_SIMD:
    6770                 :          45 :       mask = GFC_OMP_MASK_TASKLOOP | GFC_OMP_MASK_SIMD;
    6771                 :          45 :       innermost = GFC_OMP_SPLIT_SIMD;
    6772                 :          45 :       break;
    6773                 :         121 :     case EXEC_OMP_TEAMS:
    6774                 :         121 :       innermost = GFC_OMP_SPLIT_TEAMS;
    6775                 :         121 :       break;
    6776                 :          14 :     case EXEC_OMP_TEAMS_DISTRIBUTE:
    6777                 :          14 :       mask = GFC_OMP_MASK_TEAMS | GFC_OMP_MASK_DISTRIBUTE;
    6778                 :          14 :       innermost = GFC_OMP_SPLIT_DISTRIBUTE;
    6779                 :          14 :       break;
    6780                 :          32 :     case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO:
    6781                 :          32 :       mask = GFC_OMP_MASK_TEAMS | GFC_OMP_MASK_DISTRIBUTE
    6782                 :             :              | GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_DO;
    6783                 :          32 :       innermost = GFC_OMP_SPLIT_DO;
    6784                 :          32 :       break;
    6785                 :          56 :     case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
    6786                 :          56 :       mask = GFC_OMP_MASK_TEAMS | GFC_OMP_MASK_DISTRIBUTE
    6787                 :             :              | GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_DO | GFC_OMP_MASK_SIMD;
    6788                 :          56 :       innermost = GFC_OMP_SPLIT_SIMD;
    6789                 :          56 :       break;
    6790                 :          37 :     case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD:
    6791                 :          37 :       mask = GFC_OMP_MASK_TEAMS | GFC_OMP_MASK_DISTRIBUTE | GFC_OMP_MASK_SIMD;
    6792                 :          37 :       innermost = GFC_OMP_SPLIT_SIMD;
    6793                 :          37 :       break;
    6794                 :             :     case EXEC_OMP_TEAMS_LOOP:
    6795                 :             :       mask = GFC_OMP_MASK_TEAMS | GFC_OMP_MASK_DO;
    6796                 :             :       innermost = GFC_OMP_SPLIT_DO;
    6797                 :             :       break;
    6798                 :           0 :     default:
    6799                 :           0 :       gcc_unreachable ();
    6800                 :             :     }
    6801                 :        3563 :   if (mask == 0)
    6802                 :             :     {
    6803                 :        1609 :       clausesa[innermost] = *code->ext.omp_clauses;
    6804                 :        1609 :       return;
    6805                 :             :     }
    6806                 :             :   /* Loops are similar to DO but still a bit different.  */
    6807                 :        1960 :   switch (code->op)
    6808                 :             :     {
    6809                 :          39 :     case EXEC_OMP_LOOP:
    6810                 :          39 :     case EXEC_OMP_PARALLEL_LOOP:
    6811                 :          39 :     case EXEC_OMP_TEAMS_LOOP:
    6812                 :          39 :     case EXEC_OMP_TARGET_PARALLEL_LOOP:
    6813                 :          39 :     case EXEC_OMP_TARGET_TEAMS_LOOP:
    6814                 :          39 :       is_loop = true;
    6815                 :        1960 :     default:
    6816                 :        1960 :       break;
    6817                 :             :     }
    6818                 :        1960 :   if (code->ext.omp_clauses != NULL)
    6819                 :             :     {
    6820                 :        1960 :       if (mask & GFC_OMP_MASK_TARGET)
    6821                 :             :         {
    6822                 :             :           /* First the clauses that are unique to some constructs.  */
    6823                 :         295 :           clausesa[GFC_OMP_SPLIT_TARGET].lists[OMP_LIST_MAP]
    6824                 :         295 :             = code->ext.omp_clauses->lists[OMP_LIST_MAP];
    6825                 :         295 :           clausesa[GFC_OMP_SPLIT_TARGET].lists[OMP_LIST_IS_DEVICE_PTR]
    6826                 :         295 :             = code->ext.omp_clauses->lists[OMP_LIST_IS_DEVICE_PTR];
    6827                 :         295 :           clausesa[GFC_OMP_SPLIT_TARGET].lists[OMP_LIST_HAS_DEVICE_ADDR]
    6828                 :         295 :             = code->ext.omp_clauses->lists[OMP_LIST_HAS_DEVICE_ADDR];
    6829                 :         295 :           clausesa[GFC_OMP_SPLIT_TARGET].device
    6830                 :         295 :             = code->ext.omp_clauses->device;
    6831                 :         295 :           clausesa[GFC_OMP_SPLIT_TARGET].thread_limit
    6832                 :         295 :             = code->ext.omp_clauses->thread_limit;
    6833                 :         295 :           clausesa[GFC_OMP_SPLIT_TARGET].lists[OMP_LIST_USES_ALLOCATORS]
    6834                 :         295 :             = code->ext.omp_clauses->lists[OMP_LIST_USES_ALLOCATORS];
    6835                 :        2065 :           for (int i = 0; i < OMP_DEFAULTMAP_CAT_NUM; i++)
    6836                 :        1770 :             clausesa[GFC_OMP_SPLIT_TARGET].defaultmap[i]
    6837                 :        1770 :               = code->ext.omp_clauses->defaultmap[i];
    6838                 :         295 :           clausesa[GFC_OMP_SPLIT_TARGET].if_exprs[OMP_IF_TARGET]
    6839                 :         295 :             = code->ext.omp_clauses->if_exprs[OMP_IF_TARGET];
    6840                 :             :           /* And this is copied to all.  */
    6841                 :         295 :           clausesa[GFC_OMP_SPLIT_TARGET].if_expr
    6842                 :         295 :             = code->ext.omp_clauses->if_expr;
    6843                 :         295 :           clausesa[GFC_OMP_SPLIT_TARGET].nowait
    6844                 :         295 :             = code->ext.omp_clauses->nowait;
    6845                 :             :         }
    6846                 :        1960 :       if (mask & GFC_OMP_MASK_TEAMS)
    6847                 :             :         {
    6848                 :             :           /* First the clauses that are unique to some constructs.  */
    6849                 :         328 :           clausesa[GFC_OMP_SPLIT_TEAMS].num_teams_lower
    6850                 :         328 :             = code->ext.omp_clauses->num_teams_lower;
    6851                 :         328 :           clausesa[GFC_OMP_SPLIT_TEAMS].num_teams_upper
    6852                 :         328 :             = code->ext.omp_clauses->num_teams_upper;
    6853                 :         328 :           clausesa[GFC_OMP_SPLIT_TEAMS].thread_limit
    6854                 :         328 :             = code->ext.omp_clauses->thread_limit;
    6855                 :             :           /* Shared and default clauses are allowed on parallel, teams
    6856                 :             :              and taskloop.  */
    6857                 :         328 :           clausesa[GFC_OMP_SPLIT_TEAMS].lists[OMP_LIST_SHARED]
    6858                 :         328 :             = code->ext.omp_clauses->lists[OMP_LIST_SHARED];
    6859                 :         328 :           clausesa[GFC_OMP_SPLIT_TEAMS].default_sharing
    6860                 :         328 :             = code->ext.omp_clauses->default_sharing;
    6861                 :             :         }
    6862                 :        1960 :       if (mask & GFC_OMP_MASK_DISTRIBUTE)
    6863                 :             :         {
    6864                 :             :           /* First the clauses that are unique to some constructs.  */
    6865                 :         352 :           clausesa[GFC_OMP_SPLIT_DISTRIBUTE].dist_sched_kind
    6866                 :         352 :             = code->ext.omp_clauses->dist_sched_kind;
    6867                 :         352 :           clausesa[GFC_OMP_SPLIT_DISTRIBUTE].dist_chunk_size
    6868                 :         352 :             = code->ext.omp_clauses->dist_chunk_size;
    6869                 :             :           /* Duplicate collapse.  */
    6870                 :         352 :           clausesa[GFC_OMP_SPLIT_DISTRIBUTE].collapse
    6871                 :         352 :             = code->ext.omp_clauses->collapse;
    6872                 :         352 :           clausesa[GFC_OMP_SPLIT_DISTRIBUTE].order_concurrent
    6873                 :         352 :             = code->ext.omp_clauses->order_concurrent;
    6874                 :         352 :           clausesa[GFC_OMP_SPLIT_DISTRIBUTE].order_unconstrained
    6875                 :         352 :             = code->ext.omp_clauses->order_unconstrained;
    6876                 :         352 :           clausesa[GFC_OMP_SPLIT_DISTRIBUTE].order_reproducible
    6877                 :         352 :             = code->ext.omp_clauses->order_reproducible;
    6878                 :             :         }
    6879                 :        1960 :       if (mask & GFC_OMP_MASK_PARALLEL)
    6880                 :             :         {
    6881                 :             :           /* First the clauses that are unique to some constructs.  */
    6882                 :        1524 :           clausesa[GFC_OMP_SPLIT_PARALLEL].lists[OMP_LIST_COPYIN]
    6883                 :        1524 :             = code->ext.omp_clauses->lists[OMP_LIST_COPYIN];
    6884                 :        1524 :           clausesa[GFC_OMP_SPLIT_PARALLEL].num_threads
    6885                 :        1524 :             = code->ext.omp_clauses->num_threads;
    6886                 :        1524 :           clausesa[GFC_OMP_SPLIT_PARALLEL].proc_bind
    6887                 :        1524 :             = code->ext.omp_clauses->proc_bind;
    6888                 :             :           /* Shared and default clauses are allowed on parallel, teams
    6889                 :             :              and taskloop.  */
    6890                 :        1524 :           clausesa[GFC_OMP_SPLIT_PARALLEL].lists[OMP_LIST_SHARED]
    6891                 :        1524 :             = code->ext.omp_clauses->lists[OMP_LIST_SHARED];
    6892                 :        1524 :           clausesa[GFC_OMP_SPLIT_PARALLEL].default_sharing
    6893                 :        1524 :             = code->ext.omp_clauses->default_sharing;
    6894                 :        1524 :           clausesa[GFC_OMP_SPLIT_PARALLEL].if_exprs[OMP_IF_PARALLEL]
    6895                 :        1524 :             = code->ext.omp_clauses->if_exprs[OMP_IF_PARALLEL];
    6896                 :             :           /* And this is copied to all.  */
    6897                 :        1524 :           clausesa[GFC_OMP_SPLIT_PARALLEL].if_expr
    6898                 :        1524 :             = code->ext.omp_clauses->if_expr;
    6899                 :             :         }
    6900                 :        1960 :       if (mask & GFC_OMP_MASK_MASKED)
    6901                 :          79 :         clausesa[GFC_OMP_SPLIT_MASKED].filter = code->ext.omp_clauses->filter;
    6902                 :        1960 :       if ((mask & GFC_OMP_MASK_DO) && !is_loop)
    6903                 :             :         {
    6904                 :             :           /* First the clauses that are unique to some constructs.  */
    6905                 :        1514 :           clausesa[GFC_OMP_SPLIT_DO].ordered
    6906                 :        1514 :             = code->ext.omp_clauses->ordered;
    6907                 :        1514 :           clausesa[GFC_OMP_SPLIT_DO].orderedc
    6908                 :        1514 :             = code->ext.omp_clauses->orderedc;
    6909                 :        1514 :           clausesa[GFC_OMP_SPLIT_DO].sched_kind
    6910                 :        1514 :             = code->ext.omp_clauses->sched_kind;
    6911                 :        1514 :           if (innermost == GFC_OMP_SPLIT_SIMD)
    6912                 :         532 :             clausesa[GFC_OMP_SPLIT_DO].sched_simd
    6913                 :         532 :               = code->ext.omp_clauses->sched_simd;
    6914                 :        1514 :           clausesa[GFC_OMP_SPLIT_DO].sched_monotonic
    6915                 :        1514 :             = code->ext.omp_clauses->sched_monotonic;
    6916                 :        1514 :           clausesa[GFC_OMP_SPLIT_DO].sched_nonmonotonic
    6917                 :        1514 :             = code->ext.omp_clauses->sched_nonmonotonic;
    6918                 :        1514 :           clausesa[GFC_OMP_SPLIT_DO].chunk_size
    6919                 :        1514 :             = code->ext.omp_clauses->chunk_size;
    6920                 :        1514 :           clausesa[GFC_OMP_SPLIT_DO].nowait
    6921                 :        1514 :             = code->ext.omp_clauses->nowait;
    6922                 :             :         }
    6923                 :        1553 :       if (mask & GFC_OMP_MASK_DO)
    6924                 :             :         {
    6925                 :        1553 :           clausesa[GFC_OMP_SPLIT_DO].bind
    6926                 :        1553 :             = code->ext.omp_clauses->bind;
    6927                 :             :           /* Duplicate collapse.  */
    6928                 :        1553 :           clausesa[GFC_OMP_SPLIT_DO].collapse
    6929                 :        1553 :             = code->ext.omp_clauses->collapse;
    6930                 :        1553 :           clausesa[GFC_OMP_SPLIT_DO].order_concurrent
    6931                 :        1553 :             = code->ext.omp_clauses->order_concurrent;
    6932                 :        1553 :           clausesa[GFC_OMP_SPLIT_DO].order_unconstrained
    6933                 :        1553 :             = code->ext.omp_clauses->order_unconstrained;
    6934                 :        1553 :           clausesa[GFC_OMP_SPLIT_DO].order_reproducible
    6935                 :        1553 :             = code->ext.omp_clauses->order_reproducible;
    6936                 :             :         }
    6937                 :        1960 :       if (mask & GFC_OMP_MASK_SIMD)
    6938                 :             :         {
    6939                 :         809 :           clausesa[GFC_OMP_SPLIT_SIMD].safelen_expr
    6940                 :         809 :             = code->ext.omp_clauses->safelen_expr;
    6941                 :         809 :           clausesa[GFC_OMP_SPLIT_SIMD].simdlen_expr
    6942                 :         809 :             = code->ext.omp_clauses->simdlen_expr;
    6943                 :         809 :           clausesa[GFC_OMP_SPLIT_SIMD].lists[OMP_LIST_ALIGNED]
    6944                 :         809 :             = code->ext.omp_clauses->lists[OMP_LIST_ALIGNED];
    6945                 :             :           /* Duplicate collapse.  */
    6946                 :         809 :           clausesa[GFC_OMP_SPLIT_SIMD].collapse
    6947                 :         809 :             = code->ext.omp_clauses->collapse;
    6948                 :         809 :           clausesa[GFC_OMP_SPLIT_SIMD].if_exprs[OMP_IF_SIMD]
    6949                 :         809 :             = code->ext.omp_clauses->if_exprs[OMP_IF_SIMD];
    6950                 :         809 :           clausesa[GFC_OMP_SPLIT_SIMD].order_concurrent
    6951                 :         809 :             = code->ext.omp_clauses->order_concurrent;
    6952                 :         809 :           clausesa[GFC_OMP_SPLIT_SIMD].order_unconstrained
    6953                 :         809 :             = code->ext.omp_clauses->order_unconstrained;
    6954                 :         809 :           clausesa[GFC_OMP_SPLIT_SIMD].order_reproducible
    6955                 :         809 :             = code->ext.omp_clauses->order_reproducible;
    6956                 :             :           /* And this is copied to all.  */
    6957                 :         809 :           clausesa[GFC_OMP_SPLIT_SIMD].if_expr
    6958                 :         809 :             = code->ext.omp_clauses->if_expr;
    6959                 :             :         }
    6960                 :        1960 :       if (mask & GFC_OMP_MASK_TASKLOOP)
    6961                 :             :         {
    6962                 :             :           /* First the clauses that are unique to some constructs.  */
    6963                 :         159 :           clausesa[GFC_OMP_SPLIT_TASKLOOP].nogroup
    6964                 :         159 :             = code->ext.omp_clauses->nogroup;
    6965                 :         159 :           clausesa[GFC_OMP_SPLIT_TASKLOOP].grainsize
    6966                 :         159 :             = code->ext.omp_clauses->grainsize;
    6967                 :         159 :           clausesa[GFC_OMP_SPLIT_TASKLOOP].grainsize_strict
    6968                 :         159 :             = code->ext.omp_clauses->grainsize_strict;
    6969                 :         159 :           clausesa[GFC_OMP_SPLIT_TASKLOOP].num_tasks
    6970                 :         159 :             = code->ext.omp_clauses->num_tasks;
    6971                 :         159 :           clausesa[GFC_OMP_SPLIT_TASKLOOP].num_tasks_strict
    6972                 :         159 :             = code->ext.omp_clauses->num_tasks_strict;
    6973                 :         159 :           clausesa[GFC_OMP_SPLIT_TASKLOOP].priority
    6974                 :         159 :             = code->ext.omp_clauses->priority;
    6975                 :         159 :           clausesa[GFC_OMP_SPLIT_TASKLOOP].final_expr
    6976                 :         159 :             = code->ext.omp_clauses->final_expr;
    6977                 :         159 :           clausesa[GFC_OMP_SPLIT_TASKLOOP].untied
    6978                 :         159 :             = code->ext.omp_clauses->untied;
    6979                 :         159 :           clausesa[GFC_OMP_SPLIT_TASKLOOP].mergeable
    6980                 :         159 :             = code->ext.omp_clauses->mergeable;
    6981                 :         159 :           clausesa[GFC_OMP_SPLIT_TASKLOOP].if_exprs[OMP_IF_TASKLOOP]
    6982                 :         159 :             = code->ext.omp_clauses->if_exprs[OMP_IF_TASKLOOP];
    6983                 :             :           /* And this is copied to all.  */
    6984                 :         159 :           clausesa[GFC_OMP_SPLIT_TASKLOOP].if_expr
    6985                 :         159 :             = code->ext.omp_clauses->if_expr;
    6986                 :             :           /* Shared and default clauses are allowed on parallel, teams
    6987                 :             :              and taskloop.  */
    6988                 :         159 :           clausesa[GFC_OMP_SPLIT_TASKLOOP].lists[OMP_LIST_SHARED]
    6989                 :         159 :             = code->ext.omp_clauses->lists[OMP_LIST_SHARED];
    6990                 :         159 :           clausesa[GFC_OMP_SPLIT_TASKLOOP].default_sharing
    6991                 :         159 :             = code->ext.omp_clauses->default_sharing;
    6992                 :             :           /* Duplicate collapse.  */
    6993                 :         159 :           clausesa[GFC_OMP_SPLIT_TASKLOOP].collapse
    6994                 :         159 :             = code->ext.omp_clauses->collapse;
    6995                 :             :         }
    6996                 :             :       /* Private clause is supported on all constructs but master/masked,
    6997                 :             :          it is enough to put it on the innermost one except for master/masked.  For
    6998                 :             :          !$ omp parallel do put it on parallel though,
    6999                 :             :          as that's what we did for OpenMP 3.1.  */
    7000                 :        1960 :       clausesa[((innermost == GFC_OMP_SPLIT_DO && !is_loop)
    7001                 :             :                 || code->op == EXEC_OMP_PARALLEL_MASTER
    7002                 :         978 :                 || code->op == EXEC_OMP_PARALLEL_MASKED)
    7003                 :         967 :                ? (int) GFC_OMP_SPLIT_PARALLEL
    7004                 :        2927 :                : innermost].lists[OMP_LIST_PRIVATE]
    7005                 :        1960 :         = code->ext.omp_clauses->lists[OMP_LIST_PRIVATE];
    7006                 :             :       /* Firstprivate clause is supported on all constructs but
    7007                 :             :          simd and masked/master.  Put it on the outermost of those and duplicate
    7008                 :             :          on parallel and teams.  */
    7009                 :        1960 :       if (mask & GFC_OMP_MASK_TARGET)
    7010                 :         295 :         gfc_add_firstprivate_if_unmapped (&clausesa[GFC_OMP_SPLIT_TARGET],
    7011                 :             :                                           code->ext.omp_clauses);
    7012                 :        1960 :       if (mask & GFC_OMP_MASK_TEAMS)
    7013                 :         328 :         clausesa[GFC_OMP_SPLIT_TEAMS].lists[OMP_LIST_FIRSTPRIVATE]
    7014                 :         328 :           = code->ext.omp_clauses->lists[OMP_LIST_FIRSTPRIVATE];
    7015                 :        1632 :       else if (mask & GFC_OMP_MASK_DISTRIBUTE)
    7016                 :         105 :         clausesa[GFC_OMP_SPLIT_DISTRIBUTE].lists[OMP_LIST_FIRSTPRIVATE]
    7017                 :         105 :           = code->ext.omp_clauses->lists[OMP_LIST_FIRSTPRIVATE];
    7018                 :        1960 :       if (mask & GFC_OMP_MASK_TASKLOOP)
    7019                 :         159 :         clausesa[GFC_OMP_SPLIT_TASKLOOP].lists[OMP_LIST_FIRSTPRIVATE]
    7020                 :         159 :           = code->ext.omp_clauses->lists[OMP_LIST_FIRSTPRIVATE];
    7021                 :        1960 :       if ((mask & GFC_OMP_MASK_PARALLEL)
    7022                 :             :           && !(mask & GFC_OMP_MASK_TASKLOOP))
    7023                 :        1440 :         clausesa[GFC_OMP_SPLIT_PARALLEL].lists[OMP_LIST_FIRSTPRIVATE]
    7024                 :        1440 :           = code->ext.omp_clauses->lists[OMP_LIST_FIRSTPRIVATE];
    7025                 :         520 :       else if ((mask & GFC_OMP_MASK_DO) && !is_loop)
    7026                 :         126 :         clausesa[GFC_OMP_SPLIT_DO].lists[OMP_LIST_FIRSTPRIVATE]
    7027                 :         126 :           = code->ext.omp_clauses->lists[OMP_LIST_FIRSTPRIVATE];
    7028                 :             :       /* Lastprivate is allowed on distribute, do, simd, taskloop and loop.
    7029                 :             :          In parallel do{, simd} we actually want to put it on
    7030                 :             :          parallel rather than do.  */
    7031                 :        1960 :       if (mask & GFC_OMP_MASK_DISTRIBUTE)
    7032                 :         352 :         clausesa[GFC_OMP_SPLIT_DISTRIBUTE].lists[OMP_LIST_LASTPRIVATE]
    7033                 :         352 :           = code->ext.omp_clauses->lists[OMP_LIST_LASTPRIVATE];
    7034                 :        1960 :       if (mask & GFC_OMP_MASK_TASKLOOP)
    7035                 :         159 :         clausesa[GFC_OMP_SPLIT_TASKLOOP].lists[OMP_LIST_LASTPRIVATE]
    7036                 :         159 :           = code->ext.omp_clauses->lists[OMP_LIST_LASTPRIVATE];
    7037                 :        1960 :       if ((mask & GFC_OMP_MASK_PARALLEL) && !is_loop
    7038                 :        1503 :           && !(mask & GFC_OMP_MASK_TASKLOOP))
    7039                 :        1419 :         clausesa[GFC_OMP_SPLIT_PARALLEL].lists[OMP_LIST_LASTPRIVATE]
    7040                 :        1419 :           = code->ext.omp_clauses->lists[OMP_LIST_LASTPRIVATE];
    7041                 :         541 :       else if (mask & GFC_OMP_MASK_DO)
    7042                 :         165 :         clausesa[GFC_OMP_SPLIT_DO].lists[OMP_LIST_LASTPRIVATE]
    7043                 :         165 :           = code->ext.omp_clauses->lists[OMP_LIST_LASTPRIVATE];
    7044                 :        1960 :       if (mask & GFC_OMP_MASK_SIMD)
    7045                 :         809 :         clausesa[GFC_OMP_SPLIT_SIMD].lists[OMP_LIST_LASTPRIVATE]
    7046                 :         809 :           = code->ext.omp_clauses->lists[OMP_LIST_LASTPRIVATE];
    7047                 :             :       /* Reduction is allowed on simd, do, parallel, teams, taskloop, and loop.
    7048                 :             :          Duplicate it on all of them, but
    7049                 :             :          - omit on do if parallel is present;
    7050                 :             :          - omit on task and parallel if loop is present;
    7051                 :             :          additionally, inscan applies to do/simd only.  */
    7052                 :        7840 :       for (int i = OMP_LIST_REDUCTION; i <= OMP_LIST_REDUCTION_TASK; i++)
    7053                 :             :         {
    7054                 :        5880 :           if (mask & GFC_OMP_MASK_TASKLOOP
    7055                 :         477 :               && i != OMP_LIST_REDUCTION_INSCAN)
    7056                 :         318 :             clausesa[GFC_OMP_SPLIT_TASKLOOP].lists[i]
    7057                 :         318 :               = code->ext.omp_clauses->lists[i];
    7058                 :        5880 :           if (mask & GFC_OMP_MASK_TEAMS
    7059                 :         984 :               && i != OMP_LIST_REDUCTION_INSCAN
    7060                 :         984 :               && !is_loop)
    7061                 :         620 :             clausesa[GFC_OMP_SPLIT_TEAMS].lists[i]
    7062                 :         620 :               = code->ext.omp_clauses->lists[i];
    7063                 :        5880 :           if (mask & GFC_OMP_MASK_PARALLEL
    7064                 :        4572 :               && i != OMP_LIST_REDUCTION_INSCAN
    7065                 :        3048 :               && !(mask & GFC_OMP_MASK_TASKLOOP)
    7066                 :        2880 :               && !is_loop)
    7067                 :        2838 :             clausesa[GFC_OMP_SPLIT_PARALLEL].lists[i]
    7068                 :        2838 :               = code->ext.omp_clauses->lists[i];
    7069                 :        3042 :           else if (mask & GFC_OMP_MASK_DO)
    7070                 :        1883 :             clausesa[GFC_OMP_SPLIT_DO].lists[i]
    7071                 :        1883 :               = code->ext.omp_clauses->lists[i];
    7072                 :        5880 :           if (mask & GFC_OMP_MASK_SIMD)
    7073                 :        2427 :             clausesa[GFC_OMP_SPLIT_SIMD].lists[i]
    7074                 :        2427 :               = code->ext.omp_clauses->lists[i];
    7075                 :             :         }
    7076                 :        1960 :       if (mask & GFC_OMP_MASK_TARGET)
    7077                 :         295 :         clausesa[GFC_OMP_SPLIT_TARGET].lists[OMP_LIST_IN_REDUCTION]
    7078                 :         295 :           = code->ext.omp_clauses->lists[OMP_LIST_IN_REDUCTION];
    7079                 :        1960 :       if (mask & GFC_OMP_MASK_TASKLOOP)
    7080                 :         159 :         clausesa[GFC_OMP_SPLIT_TASKLOOP].lists[OMP_LIST_IN_REDUCTION]
    7081                 :         159 :           = code->ext.omp_clauses->lists[OMP_LIST_IN_REDUCTION];
    7082                 :             :       /* Linear clause is supported on do and simd,
    7083                 :             :          put it on the innermost one.  */
    7084                 :        1960 :       clausesa[innermost].lists[OMP_LIST_LINEAR]
    7085                 :        1960 :         = code->ext.omp_clauses->lists[OMP_LIST_LINEAR];
    7086                 :             :     }
    7087                 :             :    /* Propagate firstprivate/lastprivate/reduction vars to
    7088                 :             :       shared (parallel, teams) and map-tofrom (target).  */
    7089                 :        1960 :    if (mask & GFC_OMP_MASK_TARGET)
    7090                 :         295 :      gfc_add_clause_implicitly (&clausesa[GFC_OMP_SPLIT_TARGET],
    7091                 :             :                                 code->ext.omp_clauses, true, false);
    7092                 :        1960 :    if ((mask & GFC_OMP_MASK_PARALLEL) && innermost != GFC_OMP_MASK_PARALLEL)
    7093                 :        1524 :      gfc_add_clause_implicitly (&clausesa[GFC_OMP_SPLIT_PARALLEL],
    7094                 :             :                                 code->ext.omp_clauses, false,
    7095                 :        1524 :                                 mask & GFC_OMP_MASK_DO);
    7096                 :        1960 :    if (mask & GFC_OMP_MASK_TEAMS && innermost != GFC_OMP_MASK_TEAMS)
    7097                 :         328 :      gfc_add_clause_implicitly (&clausesa[GFC_OMP_SPLIT_TEAMS],
    7098                 :             :                                 code->ext.omp_clauses, false, false);
    7099                 :        1960 :    if (((mask & (GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_DO))
    7100                 :             :         == (GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_DO))
    7101                 :        1409 :        && !is_loop)
    7102                 :        1388 :     clausesa[GFC_OMP_SPLIT_DO].nowait = true;
    7103                 :             : 
    7104                 :             :    /* Distribute allocate clause to do, parallel, distribute, teams, target
    7105                 :             :       and taskloop.  The code below iterates over variables in the
    7106                 :             :       allocate list and checks if that available is also in any
    7107                 :             :       privatization clause on those construct.  If yes, then we add it
    7108                 :             :       to the list of 'allocate'ed variables for that construct.  If a
    7109                 :             :       variable is found in none of them then we issue an error.  */
    7110                 :             : 
    7111                 :        1960 :    if (code->ext.omp_clauses->lists[OMP_LIST_ALLOCATE])
    7112                 :             :      {
    7113                 :             :        gfc_omp_namelist *alloc_nl, *priv_nl;
    7114                 :             :        gfc_omp_namelist *tails[GFC_OMP_SPLIT_NUM];
    7115                 :         102 :        for (alloc_nl = code->ext.omp_clauses->lists[OMP_LIST_ALLOCATE];
    7116                 :         177 :            alloc_nl; alloc_nl = alloc_nl->next)
    7117                 :             :          {
    7118                 :             :            bool found = false;
    7119                 :         714 :            for (int i = GFC_OMP_SPLIT_DO; i <= GFC_OMP_SPLIT_TASKLOOP; i++)
    7120                 :             :              {
    7121                 :             :                gfc_omp_namelist *p;
    7122                 :             :                int list;
    7123                 :       20808 :                for (list = 0; list < OMP_LIST_NUM; list++)
    7124                 :             :                  {
    7125                 :       20196 :                    switch (list)
    7126                 :             :                    {
    7127                 :        5508 :                      case OMP_LIST_PRIVATE:
    7128                 :        5508 :                      case OMP_LIST_FIRSTPRIVATE:
    7129                 :        5508 :                      case OMP_LIST_LASTPRIVATE:
    7130                 :        5508 :                      case OMP_LIST_REDUCTION:
    7131                 :        5508 :                      case OMP_LIST_REDUCTION_INSCAN:
    7132                 :        5508 :                      case OMP_LIST_REDUCTION_TASK:
    7133                 :        5508 :                      case OMP_LIST_IN_REDUCTION:
    7134                 :        5508 :                      case OMP_LIST_TASK_REDUCTION:
    7135                 :        5508 :                      case OMP_LIST_LINEAR:
    7136                 :        5982 :                        for (priv_nl = clausesa[i].lists[list]; priv_nl;
    7137                 :         474 :                             priv_nl = priv_nl->next)
    7138                 :         474 :                          if (alloc_nl->sym == priv_nl->sym)
    7139                 :             :                            {
    7140                 :         129 :                              found = true;
    7141                 :         129 :                              p = gfc_get_omp_namelist ();
    7142                 :         129 :                              p->sym = alloc_nl->sym;
    7143                 :         129 :                              p->expr = alloc_nl->expr;
    7144                 :         129 :                              p->u.align = alloc_nl->u.align;
    7145                 :         129 :                              p->u2.allocator = alloc_nl->u2.allocator;
    7146                 :         129 :                              p->where = alloc_nl->where;
    7147                 :         129 :                              if (clausesa[i].lists[OMP_LIST_ALLOCATE] == NULL)
    7148                 :             :                                {
    7149                 :         107 :                                  clausesa[i].lists[OMP_LIST_ALLOCATE] = p;
    7150                 :         107 :                                  tails[i] = p;
    7151                 :             :                                }
    7152                 :             :                              else
    7153                 :             :                                {
    7154                 :          22 :                                  tails[i]->next = p;
    7155                 :          22 :                                  tails[i] = tails[i]->next;
    7156                 :             :                                }
    7157                 :             :                            }
    7158                 :             :                        break;
    7159                 :             :                      default:
    7160                 :             :                        break;
    7161                 :             :                    }
    7162                 :             :                  }
    7163                 :             :              }
    7164                 :         102 :            if (!found)
    7165                 :           1 :              gfc_error ("%qs specified in 'allocate' clause at %L but not "
    7166                 :             :                         "in an explicit privatization clause",
    7167                 :           1 :                         alloc_nl->sym->name, &alloc_nl->where);
    7168                 :             :          }
    7169                 :             :      }
    7170                 :             : }
    7171                 :             : 
    7172                 :             : static tree
    7173                 :         532 : gfc_trans_omp_do_simd (gfc_code *code, stmtblock_t *pblock,
    7174                 :             :                        gfc_omp_clauses *clausesa, tree omp_clauses)
    7175                 :             : {
    7176                 :         532 :   stmtblock_t block;
    7177                 :         532 :   gfc_omp_clauses clausesa_buf[GFC_OMP_SPLIT_NUM];
    7178                 :         532 :   tree stmt, body, omp_do_clauses = NULL_TREE;
    7179                 :         532 :   bool free_clausesa = false;
    7180                 :             : 
    7181                 :         532 :   if (pblock == NULL)
    7182                 :         404 :     gfc_start_block (&block);
    7183                 :             :   else
    7184                 :         128 :     gfc_init_block (&block);
    7185                 :             : 
    7186                 :         532 :   if (clausesa == NULL)
    7187                 :             :     {
    7188                 :         126 :       clausesa = clausesa_buf;
    7189                 :         126 :       gfc_split_omp_clauses (code, clausesa);
    7190                 :         126 :       free_clausesa = true;
    7191                 :             :     }
    7192                 :         532 :   if (flag_openmp)
    7193                 :         527 :     omp_do_clauses
    7194                 :         527 :       = gfc_trans_omp_clauses (&block, &clausesa[GFC_OMP_SPLIT_DO], code->loc);
    7195                 :         660 :   body = gfc_trans_omp_do (code, EXEC_OMP_SIMD, pblock ? pblock : &block,
    7196                 :             :                            &clausesa[GFC_OMP_SPLIT_SIMD], omp_clauses);
    7197                 :         532 :   if (pblock == NULL)
    7198                 :             :     {
    7199                 :         404 :       if (TREE_CODE (body) != BIND_EXPR)
    7200                 :         404 :         body = build3_v (BIND_EXPR, NULL, body, poplevel (1, 0));
    7201                 :             :       else
    7202                 :           0 :         poplevel (0, 0);
    7203                 :             :     }
    7204                 :         128 :   else if (TREE_CODE (body) != BIND_EXPR)
    7205                 :         128 :     body = build3_v (BIND_EXPR, NULL, body, NULL_TREE);
    7206                 :         532 :   if (flag_openmp)
    7207                 :             :     {
    7208                 :         527 :       stmt = make_node (OMP_FOR);
    7209                 :         527 :       SET_EXPR_LOCATION (stmt, gfc_get_location (&code->loc));
    7210                 :         527 :       TREE_TYPE (stmt) = void_type_node;
    7211                 :         527 :       OMP_FOR_BODY (stmt) = body;
    7212                 :         527 :       OMP_FOR_CLAUSES (stmt) = omp_do_clauses;
    7213                 :             :     }
    7214                 :             :   else
    7215                 :             :     stmt = body;
    7216                 :         532 :   gfc_add_expr_to_block (&block, stmt);
    7217                 :         532 :   if (free_clausesa)
    7218                 :         126 :     gfc_free_split_omp_clauses (code, clausesa);
    7219                 :         532 :   return gfc_finish_block (&block);
    7220                 :             : }
    7221                 :             : 
    7222                 :             : static tree
    7223                 :        1003 : gfc_trans_omp_parallel_do (gfc_code *code, bool is_loop, stmtblock_t *pblock,
    7224                 :             :                            gfc_omp_clauses *clausesa)
    7225                 :             : {
    7226                 :        1003 :   stmtblock_t block, *new_pblock = pblock;
    7227                 :        1003 :   gfc_omp_clauses clausesa_buf[GFC_OMP_SPLIT_NUM];
    7228                 :        1003 :   tree stmt, omp_clauses = NULL_TREE;
    7229                 :        1003 :   bool free_clausesa = false;
    7230                 :             : 
    7231                 :        1003 :   if (pblock == NULL)
    7232                 :         841 :     gfc_start_block (&block);
    7233                 :             :   else
    7234                 :         162 :     gfc_init_block (&block);
    7235                 :             : 
    7236                 :        1003 :   if (clausesa == NULL)
    7237                 :             :     {
    7238                 :         841 :       clausesa = clausesa_buf;
    7239                 :         841 :       gfc_split_omp_clauses (code, clausesa);
    7240                 :         841 :       free_clausesa = true;
    7241                 :             :     }
    7242                 :        1003 :   omp_clauses
    7243                 :        1003 :     = gfc_trans_omp_clauses (&block, &clausesa[GFC_OMP_SPLIT_PARALLEL],
    7244                 :             :                              code->loc);
    7245                 :        1003 :   if (pblock == NULL)
    7246                 :             :     {
    7247                 :         841 :       if (!clausesa[GFC_OMP_SPLIT_DO].ordered
    7248                 :         833 :           && clausesa[GFC_OMP_SPLIT_DO].sched_kind != OMP_SCHED_STATIC)
    7249                 :             :         new_pblock = &block;
    7250                 :             :       else
    7251                 :          58 :         pushlevel ();
    7252                 :             :     }
    7253                 :        1985 :   stmt = gfc_trans_omp_do (code, is_loop ? EXEC_OMP_LOOP : EXEC_OMP_DO,
    7254                 :             :                            new_pblock, &clausesa[GFC_OMP_SPLIT_DO],
    7255                 :             :                            omp_clauses);
    7256                 :        1003 :   if (pblock == NULL)
    7257                 :             :     {
    7258                 :         841 :       if (TREE_CODE (stmt) != BIND_EXPR)
    7259                 :         825 :         stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
    7260                 :             :       else
    7261                 :          16 :         poplevel (0, 0);
    7262                 :             :     }
    7263                 :         162 :   else if (TREE_CODE (stmt) != BIND_EXPR)
    7264                 :         162 :     stmt = build3_v (BIND_EXPR, NULL, stmt, NULL_TREE);
    7265                 :        1003 :   stmt = build2_loc (gfc_get_location (&code->loc), OMP_PARALLEL,
    7266                 :             :                      void_type_node, stmt, omp_clauses);
    7267                 :        1003 :   OMP_PARALLEL_COMBINED (stmt) = 1;
    7268                 :        1003 :   gfc_add_expr_to_block (&block, stmt);
    7269                 :        1003 :   if (free_clausesa)
    7270                 :         841 :     gfc_free_split_omp_clauses (code, clausesa);
    7271                 :        1003 :   return gfc_finish_block (&block);
    7272                 :             : }
    7273                 :             : 
    7274                 :             : static tree
    7275                 :         406 : gfc_trans_omp_parallel_do_simd (gfc_code *code, stmtblock_t *pblock,
    7276                 :             :                                 gfc_omp_clauses *clausesa)
    7277                 :             : {
    7278                 :         406 :   stmtblock_t block;
    7279                 :         406 :   gfc_omp_clauses clausesa_buf[GFC_OMP_SPLIT_NUM];
    7280                 :         406 :   tree stmt, omp_clauses = NULL_TREE;
    7281                 :         406 :   bool free_clausesa = false;
    7282                 :             : 
    7283                 :         406 :   if (pblock == NULL)
    7284                 :         278 :     gfc_start_block (&block);
    7285                 :             :   else
    7286                 :         128 :     gfc_init_block (&block);
    7287                 :             : 
    7288                 :         406 :   if (clausesa == NULL)
    7289                 :             :     {
    7290                 :         278 :       clausesa = clausesa_buf;
    7291                 :         278 :       gfc_split_omp_clauses (code, clausesa);
    7292                 :         278 :       free_clausesa = true;
    7293                 :             :     }
    7294                 :         406 :   if (flag_openmp)
    7295                 :         403 :     omp_clauses
    7296                 :         403 :       = gfc_trans_omp_clauses (&block, &clausesa[GFC_OMP_SPLIT_PARALLEL],
    7297                 :             :                                code->loc);
    7298                 :         406 :   if (pblock == NULL)
    7299                 :         278 :     pushlevel ();
    7300                 :         406 :   stmt = gfc_trans_omp_do_simd (code, pblock, clausesa, omp_clauses);
    7301                 :         406 :   if (pblock == NULL)
    7302                 :             :     {
    7303                 :         278 :       if (TREE_CODE (stmt) != BIND_EXPR)
    7304                 :         207 :         stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
    7305                 :             :       else
    7306                 :          71 :         poplevel (0, 0);
    7307                 :             :     }
    7308                 :         128 :   else if (TREE_CODE (stmt) != BIND_EXPR)
    7309                 :         128 :     stmt = build3_v (BIND_EXPR, NULL, stmt, NULL_TREE);
    7310                 :         406 :   if (flag_openmp)
    7311                 :             :     {
    7312                 :         403 :       stmt = build2_loc (gfc_get_location (&code->loc), OMP_PARALLEL,
    7313                 :             :                          void_type_node, stmt, omp_clauses);
    7314                 :         403 :       OMP_PARALLEL_COMBINED (stmt) = 1;
    7315                 :             :     }
    7316                 :         406 :   gfc_add_expr_to_block (&block, stmt);
    7317                 :         406 :   if (free_clausesa)
    7318                 :         278 :     gfc_free_split_omp_clauses (code, clausesa);
    7319                 :         406 :   return gfc_finish_block (&block);
    7320                 :             : }
    7321                 :             : 
    7322                 :             : static tree
    7323                 :          54 : gfc_trans_omp_parallel_sections (gfc_code *code)
    7324                 :             : {
    7325                 :          54 :   stmtblock_t block;
    7326                 :          54 :   gfc_omp_clauses section_clauses;
    7327                 :          54 :   tree stmt, omp_clauses;
    7328                 :             : 
    7329                 :          54 :   memset (&section_clauses, 0, sizeof (section_clauses));
    7330                 :          54 :   section_clauses.nowait = true;
    7331                 :             : 
    7332                 :          54 :   gfc_start_block (&block);
    7333                 :          54 :   omp_clauses = gfc_trans_omp_clauses (&block, code->ext.omp_clauses,
    7334                 :             :                                        code->loc);
    7335                 :          54 :   pushlevel ();
    7336                 :          54 :   stmt = gfc_trans_omp_sections (code, &section_clauses);
    7337                 :          54 :   if (TREE_CODE (stmt) != BIND_EXPR)
    7338                 :          54 :     stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
    7339                 :             :   else
    7340                 :           0 :     poplevel (0, 0);
    7341                 :          54 :   stmt = build2_loc (gfc_get_location (&code->loc), OMP_PARALLEL,
    7342                 :             :                      void_type_node, stmt, omp_clauses);
    7343                 :          54 :   OMP_PARALLEL_COMBINED (stmt) = 1;
    7344                 :          54 :   gfc_add_expr_to_block (&block, stmt);
    7345                 :          54 :   return gfc_finish_block (&block);
    7346                 :             : }
    7347                 :             : 
    7348                 :             : static tree
    7349                 :          50 : gfc_trans_omp_parallel_workshare (gfc_code *code)
    7350                 :             : {
    7351                 :          50 :   stmtblock_t block;
    7352                 :          50 :   gfc_omp_clauses workshare_clauses;
    7353                 :          50 :   tree stmt, omp_clauses;
    7354                 :             : 
    7355                 :          50 :   memset (&workshare_clauses, 0, sizeof (workshare_clauses));
    7356                 :          50 :   workshare_clauses.nowait = true;
    7357                 :             : 
    7358                 :          50 :   gfc_start_block (&block);
    7359                 :          50 :   omp_clauses = gfc_trans_omp_clauses (&block, code->ext.omp_clauses,
    7360                 :             :                                        code->loc);
    7361                 :          50 :   pushlevel ();
    7362                 :          50 :   stmt = gfc_trans_omp_workshare (code, &workshare_clauses);
    7363                 :          50 :   stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
    7364                 :          50 :   stmt = build2_loc (gfc_get_location (&code->loc), OMP_PARALLEL,
    7365                 :             :                      void_type_node, stmt, omp_clauses);
    7366                 :          50 :   OMP_PARALLEL_COMBINED (stmt) = 1;
    7367                 :          50 :   gfc_add_expr_to_block (&block, stmt);
    7368                 :          50 :   return gfc_finish_block (&block);
    7369                 :             : }
    7370                 :             : 
    7371                 :             : static tree
    7372                 :          53 : gfc_trans_omp_scope (gfc_code *code)
    7373                 :             : {
    7374                 :          53 :   stmtblock_t block;
    7375                 :          53 :   tree body = gfc_trans_code (code->block->next);
    7376                 :          53 :   if (IS_EMPTY_STMT (body))
    7377                 :             :     return body;
    7378                 :          51 :   gfc_start_block (&block);
    7379                 :          51 :   tree omp_clauses = gfc_trans_omp_clauses (&block, code->ext.omp_clauses,
    7380                 :             :                                             code->loc);
    7381                 :          51 :   tree stmt = make_node (OMP_SCOPE);
    7382                 :          51 :   SET_EXPR_LOCATION (stmt, gfc_get_location (&code->loc));
    7383                 :          51 :   TREE_TYPE (stmt) = void_type_node;
    7384                 :          51 :   OMP_SCOPE_BODY (stmt) = body;
    7385                 :          51 :   OMP_SCOPE_CLAUSES (stmt) = omp_clauses;
    7386                 :          51 :   gfc_add_expr_to_block (&block, stmt);
    7387                 :          51 :   return gfc_finish_block (&block);
    7388                 :             : }
    7389                 :             : 
    7390                 :             : static tree
    7391                 :         129 : gfc_trans_omp_sections (gfc_code *code, gfc_omp_clauses *clauses)
    7392                 :             : {
    7393                 :         129 :   stmtblock_t block, body;
    7394                 :         129 :   tree omp_clauses, stmt;
    7395                 :         129 :   bool has_lastprivate = clauses->lists[OMP_LIST_LASTPRIVATE] != NULL;
    7396                 :         129 :   location_t loc = gfc_get_location (&code->loc);
    7397                 :             : 
    7398                 :         129 :   gfc_start_block (&block);
    7399                 :             : 
    7400                 :         129 :   omp_clauses = gfc_trans_omp_clauses (&block, clauses, code->loc);
    7401                 :             : 
    7402                 :         129 :   gfc_init_block (&body);
    7403                 :         499 :   for (code = code->block; code; code = code->block)
    7404                 :             :     {
    7405                 :             :       /* Last section is special because of lastprivate, so even if it
    7406                 :             :          is empty, chain it in.  */
    7407                 :         370 :       stmt = gfc_trans_omp_code (code->next,
    7408                 :         370 :                                  has_lastprivate && code->block == NULL);
    7409                 :         370 :       if (! IS_EMPTY_STMT (stmt))
    7410                 :             :         {
    7411                 :         280 :           stmt = build1_v (OMP_SECTION, stmt);
    7412                 :         280 :           gfc_add_expr_to_block (&body, stmt);
    7413                 :             :         }
    7414                 :             :     }
    7415                 :         129 :   stmt = gfc_finish_block (&body);
    7416                 :             : 
    7417                 :         129 :   stmt = build2_loc (loc, OMP_SECTIONS, void_type_node, stmt, omp_clauses);
    7418                 :         129 :   gfc_add_expr_to_block (&block, stmt);
    7419                 :             : 
    7420                 :         129 :   return gfc_finish_block (&block);
    7421                 :             : }
    7422                 :             : 
    7423                 :             : static tree
    7424                 :         565 : gfc_trans_omp_single (gfc_code *code, gfc_omp_clauses *clauses)
    7425                 :             : {
    7426                 :         565 :   stmtblock_t block;
    7427                 :         565 :   gfc_start_block (&block);
    7428                 :         565 :   tree omp_clauses = gfc_trans_omp_clauses (&block, clauses, code->loc);
    7429                 :         565 :   tree stmt = gfc_trans_omp_code (code->block->next, true);
    7430                 :         565 :   stmt = build2_loc (gfc_get_location (&code->loc), OMP_SINGLE, void_type_node,
    7431                 :             :                      stmt, omp_clauses);
    7432                 :         565 :   gfc_add_expr_to_block (&block, stmt);
    7433                 :         565 :   return gfc_finish_block (&block);
    7434                 :             : }
    7435                 :             : 
    7436                 :             : static tree
    7437                 :        1120 : gfc_trans_omp_task (gfc_code *code)
    7438                 :             : {
    7439                 :        1120 :   stmtblock_t block;
    7440                 :        1120 :   tree stmt, omp_clauses;
    7441                 :             : 
    7442                 :        1120 :   gfc_start_block (&block);
    7443                 :        1120 :   omp_clauses = gfc_trans_omp_clauses (&block, code->ext.omp_clauses,
    7444                 :             :                                        code->loc);
    7445                 :        1120 :   pushlevel ();
    7446                 :        1120 :   stmt = gfc_trans_omp_code (code->block->next, true);
    7447                 :        1120 :   stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
    7448                 :        1120 :   stmt = build2_loc (gfc_get_location (&code->loc), OMP_TASK, void_type_node,
    7449                 :             :                      stmt, omp_clauses);
    7450                 :        1120 :   gfc_add_expr_to_block (&block, stmt);
    7451                 :        1120 :   return gfc_finish_block (&block);
    7452                 :             : }
    7453                 :             : 
    7454                 :             : static tree
    7455                 :         181 : gfc_trans_omp_taskgroup (gfc_code *code)
    7456                 :             : {
    7457                 :         181 :   stmtblock_t block;
    7458                 :         181 :   gfc_start_block (&block);
    7459                 :         181 :   tree body = gfc_trans_code (code->block->next);
    7460                 :         181 :   tree stmt = make_node (OMP_TASKGROUP);
    7461                 :         181 :   SET_EXPR_LOCATION (stmt, gfc_get_location (&code->loc));
    7462                 :         181 :   TREE_TYPE (stmt) = void_type_node;
    7463                 :         181 :   OMP_TASKGROUP_BODY (stmt) = body;
    7464                 :         181 :   OMP_TASKGROUP_CLAUSES (stmt) = gfc_trans_omp_clauses (&block,
    7465                 :             :                                                         code->ext.omp_clauses,
    7466                 :             :                                                         code->loc);
    7467                 :         181 :   gfc_add_expr_to_block (&block, stmt);
    7468                 :         181 :   return gfc_finish_block (&block);
    7469                 :             : }
    7470                 :             : 
    7471                 :             : static tree
    7472                 :         143 : gfc_trans_omp_taskwait (gfc_code *code)
    7473                 :             : {
    7474                 :         143 :   if (!code->ext.omp_clauses)
    7475                 :             :     {
    7476                 :         131 :       tree decl = builtin_decl_explicit (BUILT_IN_GOMP_TASKWAIT);
    7477                 :         131 :       return build_call_expr_loc (input_location, decl, 0);
    7478                 :             :     }
    7479                 :          12 :   stmtblock_t block;
    7480                 :          12 :   gfc_start_block (&block);
    7481                 :          12 :   tree stmt = make_node (OMP_TASK);
    7482                 :          12 :   SET_EXPR_LOCATION (stmt, gfc_get_location (&code->loc));
    7483                 :          12 :   TREE_TYPE (stmt) = void_type_node;
    7484                 :          12 :   OMP_TASK_BODY (stmt) = NULL_TREE;
    7485                 :          12 :   OMP_TASK_CLAUSES (stmt) = gfc_trans_omp_clauses (&block,
    7486                 :             :                                                    code->ext.omp_clauses,
    7487                 :             :                                                    code->loc);
    7488                 :          12 :   gfc_add_expr_to_block (&block, stmt);
    7489                 :          12 :   return gfc_finish_block (&block);
    7490                 :             : }
    7491                 :             : 
    7492                 :             : static tree
    7493                 :           8 : gfc_trans_omp_taskyield (void)
    7494                 :             : {
    7495                 :           8 :   tree decl = builtin_decl_explicit (BUILT_IN_GOMP_TASKYIELD);
    7496                 :           8 :   return build_call_expr_loc (input_location, decl, 0);
    7497                 :             : }
    7498                 :             : 
    7499                 :             : static tree
    7500                 :         324 : gfc_trans_omp_distribute (gfc_code *code, gfc_omp_clauses *clausesa)
    7501                 :             : {
    7502                 :         324 :   stmtblock_t block;
    7503                 :         324 :   gfc_omp_clauses clausesa_buf[GFC_OMP_SPLIT_NUM];
    7504                 :         324 :   tree stmt, omp_clauses = NULL_TREE;
    7505                 :         324 :   bool free_clausesa = false;
    7506                 :             : 
    7507                 :         324 :   gfc_start_block (&block);
    7508                 :         324 :   if (clausesa == NULL)
    7509                 :             :     {
    7510                 :         105 :       clausesa = clausesa_buf;
    7511                 :         105 :       gfc_split_omp_clauses (code, clausesa);
    7512                 :         105 :       free_clausesa = true;
    7513                 :             :     }
    7514                 :         324 :   if (flag_openmp)
    7515                 :         324 :     omp_clauses
    7516                 :         324 :       = gfc_trans_omp_clauses (&block, &clausesa[GFC_OMP_SPLIT_DISTRIBUTE],
    7517                 :             :                                code->loc);
    7518                 :         324 :   switch (code->op)
    7519                 :             :     {
    7520                 :           0 :     case EXEC_OMP_DISTRIBUTE:
    7521                 :           0 :     case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE:
    7522                 :           0 :     case EXEC_OMP_TEAMS_DISTRIBUTE:
    7523                 :             :       /* This is handled in gfc_trans_omp_do.  */
    7524                 :           0 :       gcc_unreachable ();
    7525                 :         111 :       break;
    7526                 :         111 :     case EXEC_OMP_DISTRIBUTE_PARALLEL_DO:
    7527                 :         111 :     case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO:
    7528                 :         111 :     case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO:
    7529                 :         111 :       stmt = gfc_trans_omp_parallel_do (code, false, &block, clausesa);
    7530                 :         111 :       if (TREE_CODE (stmt) != BIND_EXPR)
    7531                 :         111 :         stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
    7532                 :             :       else
    7533                 :           0 :         poplevel (0, 0);
    7534                 :             :       break;
    7535                 :         113 :     case EXEC_OMP_DISTRIBUTE_PARALLEL_DO_SIMD:
    7536                 :         113 :     case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
    7537                 :         113 :     case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
    7538                 :         113 :       stmt = gfc_trans_omp_parallel_do_simd (code, &block, clausesa);
    7539                 :         113 :       if (TREE_CODE (stmt) != BIND_EXPR)
    7540                 :         113 :         stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
    7541                 :             :       else
    7542                 :           0 :         poplevel (0, 0);
    7543                 :             :       break;
    7544                 :         100 :     case EXEC_OMP_DISTRIBUTE_SIMD:
    7545                 :         100 :     case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD:
    7546                 :         100 :     case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD:
    7547                 :         100 :       stmt = gfc_trans_omp_do (code, EXEC_OMP_SIMD, &block,
    7548                 :             :                                &clausesa[GFC_OMP_SPLIT_SIMD], NULL_TREE);
    7549                 :         100 :       if (TREE_CODE (stmt) != BIND_EXPR)
    7550                 :         100 :         stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
    7551                 :             :       else
    7552                 :           0 :         poplevel (0, 0);
    7553                 :             :       break;
    7554                 :           0 :     default:
    7555                 :           0 :       gcc_unreachable ();
    7556                 :             :     }
    7557                 :         324 :   if (flag_openmp)
    7558                 :             :     {
    7559                 :         324 :       tree distribute = make_node (OMP_DISTRIBUTE);
    7560                 :         324 :       SET_EXPR_LOCATION (distribute, gfc_get_location (&code->loc));
    7561                 :         324 :       TREE_TYPE (distribute) = void_type_node;
    7562                 :         324 :       OMP_FOR_BODY (distribute) = stmt;
    7563                 :         324 :       OMP_FOR_CLAUSES (distribute) = omp_clauses;
    7564                 :         324 :       stmt = distribute;
    7565                 :             :     }
    7566                 :         324 :   gfc_add_expr_to_block (&block, stmt);
    7567                 :         324 :   if (free_clausesa)
    7568                 :         105 :     gfc_free_split_omp_clauses (code, clausesa);
    7569                 :         324 :   return gfc_finish_block (&block);
    7570                 :             : }
    7571                 :             : 
    7572                 :             : static tree
    7573                 :         449 : gfc_trans_omp_teams (gfc_code *code, gfc_omp_clauses *clausesa,
    7574                 :             :                      tree omp_clauses)
    7575                 :             : {
    7576                 :         449 :   stmtblock_t block;
    7577                 :         449 :   gfc_omp_clauses clausesa_buf[GFC_OMP_SPLIT_NUM];
    7578                 :         449 :   tree stmt;
    7579                 :         449 :   bool combined = true, free_clausesa = false;
    7580                 :             : 
    7581                 :         449 :   gfc_start_block (&block);
    7582                 :         449 :   if (clausesa == NULL)
    7583                 :             :     {
    7584                 :         266 :       clausesa = clausesa_buf;
    7585                 :         266 :       gfc_split_omp_clauses (code, clausesa);
    7586                 :         266 :       free_clausesa = true;
    7587                 :             :     }
    7588                 :         449 :   if (flag_openmp)
    7589                 :             :     {
    7590                 :         449 :       omp_clauses
    7591                 :         449 :         = chainon (omp_clauses,
    7592                 :             :                    gfc_trans_omp_clauses (&block,
    7593                 :             :                                           &clausesa[GFC_OMP_SPLIT_TEAMS],
    7594                 :             :                                           code->loc));
    7595                 :         449 :       pushlevel ();
    7596                 :             :     }
    7597                 :         449 :   switch (code->op)
    7598                 :             :     {
    7599                 :         184 :     case EXEC_OMP_TARGET_TEAMS:
    7600                 :         184 :     case EXEC_OMP_TEAMS:
    7601                 :         184 :       stmt = gfc_trans_omp_code (code->block->next, true);
    7602                 :         184 :       combined = false;
    7603                 :         184 :       break;
    7604                 :          28 :     case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE:
    7605                 :          28 :     case EXEC_OMP_TEAMS_DISTRIBUTE:
    7606                 :          28 :       stmt = gfc_trans_omp_do (code, EXEC_OMP_DISTRIBUTE, NULL,
    7607                 :             :                                &clausesa[GFC_OMP_SPLIT_DISTRIBUTE],
    7608                 :             :                                NULL);
    7609                 :          28 :       break;
    7610                 :          18 :     case EXEC_OMP_TARGET_TEAMS_LOOP:
    7611                 :          18 :     case EXEC_OMP_TEAMS_LOOP:
    7612                 :          18 :       stmt = gfc_trans_omp_do (code, EXEC_OMP_LOOP, NULL,
    7613                 :             :                                &clausesa[GFC_OMP_SPLIT_DO],
    7614                 :             :                                NULL);
    7615                 :          18 :       break;
    7616                 :         219 :     default:
    7617                 :         219 :       stmt = gfc_trans_omp_distribute (code, clausesa);
    7618                 :         219 :       break;
    7619                 :             :     }
    7620                 :         449 :   if (flag_openmp)
    7621                 :             :     {
    7622                 :         449 :       stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
    7623                 :         449 :       stmt = build2_loc (gfc_get_location (&code->loc), OMP_TEAMS,
    7624                 :             :                          void_type_node, stmt, omp_clauses);
    7625                 :         449 :       if (combined)
    7626                 :         265 :         OMP_TEAMS_COMBINED (stmt) = 1;
    7627                 :             :     }
    7628                 :         449 :   gfc_add_expr_to_block (&block, stmt);
    7629                 :         449 :   if (free_clausesa)
    7630                 :         266 :     gfc_free_split_omp_clauses (code, clausesa);
    7631                 :         449 :   return gfc_finish_block (&block);
    7632                 :             : }
    7633                 :             : 
    7634                 :             : static tree
    7635                 :        1783 : gfc_trans_omp_target (gfc_code *code)
    7636                 :             : {
    7637                 :        1783 :   stmtblock_t block;
    7638                 :        1783 :   gfc_omp_clauses clausesa[GFC_OMP_SPLIT_NUM];
    7639                 :        1783 :   tree stmt, omp_clauses = NULL_TREE;
    7640                 :             : 
    7641                 :        1783 :   gfc_start_block (&block);
    7642                 :        1783 :   gfc_split_omp_clauses (code, clausesa);
    7643                 :        1783 :   if (flag_openmp)
    7644                 :        1783 :     omp_clauses
    7645                 :        1783 :       = gfc_trans_omp_clauses (&block, &clausesa[GFC_OMP_SPLIT_TARGET],
    7646                 :             :                                code->loc);
    7647                 :        1783 :   switch (code->op)
    7648                 :             :     {
    7649                 :        1488 :     case EXEC_OMP_TARGET:
    7650                 :        1488 :       pushlevel ();
    7651                 :        1488 :       stmt = gfc_trans_omp_code (code->block->next, true);
    7652                 :        1488 :       stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
    7653                 :        1488 :       break;
    7654                 :          20 :     case EXEC_OMP_TARGET_PARALLEL:
    7655                 :          20 :       {
    7656                 :          20 :         stmtblock_t iblock;
    7657                 :             : 
    7658                 :          20 :         pushlevel ();
    7659                 :          20 :         gfc_start_block (&iblock);
    7660                 :          20 :         tree inner_clauses
    7661                 :          20 :           = gfc_trans_omp_clauses (&iblock, &clausesa[GFC_OMP_SPLIT_PARALLEL],
    7662                 :             :                                    code->loc);
    7663                 :          20 :         stmt = gfc_trans_omp_code (code->block->next, true);
    7664                 :          20 :         stmt = build2_loc (input_location, OMP_PARALLEL, void_type_node, stmt,
    7665                 :             :                            inner_clauses);
    7666                 :          20 :         gfc_add_expr_to_block (&iblock, stmt);
    7667                 :          20 :         stmt = gfc_finish_block (&iblock);
    7668                 :          20 :         if (TREE_CODE (stmt) != BIND_EXPR)
    7669                 :          17 :           stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
    7670                 :             :         else
    7671                 :           3 :           poplevel (0, 0);
    7672                 :             :       }
    7673                 :          20 :       break;
    7674                 :          51 :     case EXEC_OMP_TARGET_PARALLEL_DO:
    7675                 :          51 :     case EXEC_OMP_TARGET_PARALLEL_LOOP:
    7676                 :          51 :       stmt = gfc_trans_omp_parallel_do (code,
    7677                 :             :                                         (code->op
    7678                 :             :                                          == EXEC_OMP_TARGET_PARALLEL_LOOP),
    7679                 :             :                                         &block, clausesa);
    7680                 :          51 :       if (TREE_CODE (stmt) != BIND_EXPR)
    7681                 :          51 :         stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
    7682                 :             :       else
    7683                 :           0 :         poplevel (0, 0);
    7684                 :             :       break;
    7685                 :          15 :     case EXEC_OMP_TARGET_PARALLEL_DO_SIMD:
    7686                 :          15 :       stmt = gfc_trans_omp_parallel_do_simd (code, &block, clausesa);
    7687                 :          15 :       if (TREE_CODE (stmt) != BIND_EXPR)
    7688                 :          15 :         stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
    7689                 :             :       else
    7690                 :           0 :         poplevel (0, 0);
    7691                 :             :       break;
    7692                 :          26 :     case EXEC_OMP_TARGET_SIMD:
    7693                 :          26 :       stmt = gfc_trans_omp_do (code, EXEC_OMP_SIMD, &block,
    7694                 :             :                                &clausesa[GFC_OMP_SPLIT_SIMD], NULL_TREE);
    7695                 :          26 :       if (TREE_CODE (stmt) != BIND_EXPR)
    7696                 :          26 :         stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
    7697                 :             :       else
    7698                 :           0 :         poplevel (0, 0);
    7699                 :             :       break;
    7700                 :         183 :     default:
    7701                 :         183 :       if (flag_openmp
    7702                 :         183 :           && (clausesa[GFC_OMP_SPLIT_TEAMS].num_teams_upper
    7703                 :         133 :               || clausesa[GFC_OMP_SPLIT_TEAMS].thread_limit))
    7704                 :             :         {
    7705                 :          51 :           gfc_omp_clauses clausesb;
    7706                 :          51 :           tree teams_clauses;
    7707                 :             :           /* For combined !$omp target teams, the num_teams and
    7708                 :             :              thread_limit clauses are evaluated before entering the
    7709                 :             :              target construct.  */
    7710                 :          51 :           memset (&clausesb, '\0', sizeof (clausesb));
    7711                 :          51 :           clausesb.num_teams_lower
    7712                 :          51 :             = clausesa[GFC_OMP_SPLIT_TEAMS].num_teams_lower;
    7713                 :          51 :           clausesb.num_teams_upper
    7714                 :          51 :             = clausesa[GFC_OMP_SPLIT_TEAMS].num_teams_upper;
    7715                 :          51 :           clausesb.thread_limit = clausesa[GFC_OMP_SPLIT_TEAMS].thread_limit;
    7716                 :          51 :           clausesa[GFC_OMP_SPLIT_TEAMS].num_teams_lower = NULL;
    7717                 :          51 :           clausesa[GFC_OMP_SPLIT_TEAMS].num_teams_upper = NULL;
    7718                 :          51 :           clausesa[GFC_OMP_SPLIT_TEAMS].thread_limit = NULL;
    7719                 :          51 :           teams_clauses
    7720                 :          51 :             = gfc_trans_omp_clauses (&block, &clausesb, code->loc);
    7721                 :          51 :           pushlevel ();
    7722                 :          51 :           stmt = gfc_trans_omp_teams (code, clausesa, teams_clauses);
    7723                 :          51 :         }
    7724                 :             :       else
    7725                 :             :         {
    7726                 :         132 :           pushlevel ();
    7727                 :         132 :           stmt = gfc_trans_omp_teams (code, clausesa, NULL_TREE);
    7728                 :             :         }
    7729                 :         183 :       if (TREE_CODE (stmt) != BIND_EXPR)
    7730                 :         182 :         stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
    7731                 :             :       else
    7732                 :           1 :         poplevel (0, 0);
    7733                 :             :       break;
    7734                 :             :     }
    7735                 :        1783 :   if (flag_openmp)
    7736                 :             :     {
    7737                 :        1783 :       stmt = build2_loc (gfc_get_location (&code->loc), OMP_TARGET,
    7738                 :             :                          void_type_node, stmt, omp_clauses);
    7739                 :        1783 :       if (code->op != EXEC_OMP_TARGET)
    7740                 :         295 :         OMP_TARGET_COMBINED (stmt) = 1;
    7741                 :        1783 :       cfun->has_omp_target = true;
    7742                 :             :     }
    7743                 :        1783 :   gfc_add_expr_to_block (&block, stmt);
    7744                 :        1783 :   gfc_free_split_omp_clauses (code, clausesa);
    7745                 :        1783 :   return gfc_finish_block (&block);
    7746                 :             : }
    7747                 :             : 
    7748                 :             : static tree
    7749                 :          77 : gfc_trans_omp_taskloop (gfc_code *code, gfc_exec_op op)
    7750                 :             : {
    7751                 :          77 :   stmtblock_t block;
    7752                 :          77 :   gfc_omp_clauses clausesa[GFC_OMP_SPLIT_NUM];
    7753                 :          77 :   tree stmt, omp_clauses = NULL_TREE;
    7754                 :             : 
    7755                 :          77 :   gfc_start_block (&block);
    7756                 :          77 :   gfc_split_omp_clauses (code, clausesa);
    7757                 :          77 :   if (flag_openmp)
    7758                 :          77 :     omp_clauses
    7759                 :          77 :       = gfc_trans_omp_clauses (&block, &clausesa[GFC_OMP_SPLIT_TASKLOOP],
    7760                 :             :                                code->loc);
    7761                 :          77 :   switch (op)
    7762                 :             :     {
    7763                 :           0 :     case EXEC_OMP_TASKLOOP:
    7764                 :             :       /* This is handled in gfc_trans_omp_do.  */
    7765                 :           0 :       gcc_unreachable ();
    7766                 :          77 :       break;
    7767                 :          77 :     case EXEC_OMP_TASKLOOP_SIMD:
    7768                 :          77 :       stmt = gfc_trans_omp_do (code, EXEC_OMP_SIMD, &block,
    7769                 :             :                                &clausesa[GFC_OMP_SPLIT_SIMD], NULL_TREE);
    7770                 :          77 :       if (TREE_CODE (stmt) != BIND_EXPR)
    7771                 :          77 :         stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
    7772                 :             :       else
    7773                 :           0 :         poplevel (0, 0);
    7774                 :          77 :       break;
    7775                 :           0 :     default:
    7776                 :           0 :       gcc_unreachable ();
    7777                 :             :     }
    7778                 :          77 :   if (flag_openmp)
    7779                 :             :     {
    7780                 :          77 :       tree taskloop = make_node (OMP_TASKLOOP);
    7781                 :          77 :       SET_EXPR_LOCATION (taskloop, gfc_get_location (&code->loc));
    7782                 :          77 :       TREE_TYPE (taskloop) = void_type_node;
    7783                 :          77 :       OMP_FOR_BODY (taskloop) = stmt;
    7784                 :          77 :       OMP_FOR_CLAUSES (taskloop) = omp_clauses;
    7785                 :          77 :       stmt = taskloop;
    7786                 :             :     }
    7787                 :          77 :   gfc_add_expr_to_block (&block, stmt);
    7788                 :          77 :   gfc_free_split_omp_clauses (code, clausesa);
    7789                 :          77 :   return gfc_finish_block (&block);
    7790                 :             : }
    7791                 :             : 
    7792                 :             : static tree
    7793                 :          83 : gfc_trans_omp_master_masked_taskloop (gfc_code *code, gfc_exec_op op)
    7794                 :             : {
    7795                 :          83 :   gfc_omp_clauses clausesa[GFC_OMP_SPLIT_NUM];
    7796                 :          83 :   stmtblock_t block;
    7797                 :          83 :   tree stmt;
    7798                 :             : 
    7799                 :          83 :   if (op != EXEC_OMP_MASTER_TASKLOOP_SIMD
    7800                 :          55 :       && code->op != EXEC_OMP_MASTER_TASKLOOP)
    7801                 :          44 :     gfc_split_omp_clauses (code, clausesa);
    7802                 :             : 
    7803                 :          83 :   pushlevel ();
    7804                 :          83 :   if (op == EXEC_OMP_MASKED_TASKLOOP_SIMD
    7805                 :          83 :       || op == EXEC_OMP_MASTER_TASKLOOP_SIMD)
    7806                 :          47 :     stmt = gfc_trans_omp_taskloop (code, EXEC_OMP_TASKLOOP_SIMD);
    7807                 :             :   else
    7808                 :             :     {
    7809                 :          36 :       gcc_assert (op == EXEC_OMP_MASKED_TASKLOOP
    7810                 :             :                   || op == EXEC_OMP_MASTER_TASKLOOP);
    7811                 :          36 :       stmt = gfc_trans_omp_do (code, EXEC_OMP_TASKLOOP, NULL,
    7812                 :          36 :                                code->op != EXEC_OMP_MASTER_TASKLOOP
    7813                 :             :                                ? &clausesa[GFC_OMP_SPLIT_TASKLOOP]
    7814                 :             :                                : code->ext.omp_clauses, NULL);
    7815                 :             :     }
    7816                 :          83 :   if (TREE_CODE (stmt) != BIND_EXPR)
    7817                 :          54 :     stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
    7818                 :             :   else
    7819                 :          29 :     poplevel (0, 0);
    7820                 :          83 :   gfc_start_block (&block);
    7821                 :          83 :   if (op == EXEC_OMP_MASKED_TASKLOOP || op == EXEC_OMP_MASKED_TASKLOOP_SIMD)
    7822                 :             :     {
    7823                 :          34 :       tree clauses = gfc_trans_omp_clauses (&block,
    7824                 :             :                                             &clausesa[GFC_OMP_SPLIT_MASKED],
    7825                 :             :                                             code->loc);
    7826                 :          34 :       tree msk = make_node (OMP_MASKED);
    7827                 :          34 :       SET_EXPR_LOCATION (msk, gfc_get_location (&code->loc));
    7828                 :          34 :       TREE_TYPE (msk) = void_type_node;
    7829                 :          34 :       OMP_MASKED_BODY (msk) = stmt;
    7830                 :          34 :       OMP_MASKED_CLAUSES (msk) = clauses;
    7831                 :          34 :       OMP_MASKED_COMBINED (msk) = 1;
    7832                 :          34 :       gfc_add_expr_to_block (&block, msk);
    7833                 :             :     }
    7834                 :             :   else
    7835                 :             :     {
    7836                 :          49 :       gcc_assert (op == EXEC_OMP_MASTER_TASKLOOP
    7837                 :             :                   || op == EXEC_OMP_MASTER_TASKLOOP_SIMD);
    7838                 :          49 :       stmt = build1_v (OMP_MASTER, stmt);
    7839                 :          49 :       gfc_add_expr_to_block (&block, stmt);
    7840                 :             :     }
    7841                 :          83 :   if (op != EXEC_OMP_MASTER_TASKLOOP_SIMD
    7842                 :          55 :       && code->op != EXEC_OMP_MASTER_TASKLOOP)
    7843                 :          44 :     gfc_free_split_omp_clauses (code, clausesa);
    7844                 :          83 :   return gfc_finish_block (&block);
    7845                 :             : }
    7846                 :             : 
    7847                 :             : static tree
    7848                 :          60 : gfc_trans_omp_parallel_master_masked (gfc_code *code)
    7849                 :             : {
    7850                 :          60 :   stmtblock_t block;
    7851                 :          60 :   tree stmt, omp_clauses;
    7852                 :          60 :   gfc_omp_clauses clausesa[GFC_OMP_SPLIT_NUM];
    7853                 :          60 :   bool parallel_combined = false;
    7854                 :             : 
    7855                 :          60 :   if (code->op != EXEC_OMP_PARALLEL_MASTER)
    7856                 :          49 :     gfc_split_omp_clauses (code, clausesa);
    7857                 :             : 
    7858                 :          60 :   gfc_start_block (&block);
    7859                 :          60 :   omp_clauses = gfc_trans_omp_clauses (&block,
    7860                 :          60 :                                        code->op == EXEC_OMP_PARALLEL_MASTER
    7861                 :             :                                        ? code->ext.omp_clauses
    7862                 :             :                                        : &clausesa[GFC_OMP_SPLIT_PARALLEL],
    7863                 :             :                                        code->loc);
    7864                 :          60 :   pushlevel ();
    7865                 :          60 :   if (code->op == EXEC_OMP_PARALLEL_MASTER)
    7866                 :          11 :     stmt = gfc_trans_omp_master (code);
    7867                 :          49 :   else if (code->op == EXEC_OMP_PARALLEL_MASKED)
    7868                 :          11 :     stmt = gfc_trans_omp_masked (code, &clausesa[GFC_OMP_SPLIT_MASKED]);
    7869                 :             :   else
    7870                 :             :     {
    7871                 :          38 :       gfc_exec_op op;
    7872                 :          38 :       switch (code->op)
    7873                 :             :         {
    7874                 :             :         case EXEC_OMP_PARALLEL_MASKED_TASKLOOP:
    7875                 :             :           op = EXEC_OMP_MASKED_TASKLOOP;
    7876                 :             :           break;
    7877                 :           8 :         case EXEC_OMP_PARALLEL_MASKED_TASKLOOP_SIMD:
    7878                 :           8 :           op = EXEC_OMP_MASKED_TASKLOOP_SIMD;
    7879                 :           8 :           break;
    7880                 :          10 :         case EXEC_OMP_PARALLEL_MASTER_TASKLOOP:
    7881                 :          10 :           op = EXEC_OMP_MASTER_TASKLOOP;
    7882                 :          10 :           break;
    7883                 :          13 :         case EXEC_OMP_PARALLEL_MASTER_TASKLOOP_SIMD:
    7884                 :          13 :           op = EXEC_OMP_MASTER_TASKLOOP_SIMD;
    7885                 :          13 :           break;
    7886                 :           0 :         default:
    7887                 :           0 :           gcc_unreachable ();
    7888                 :             :         }
    7889                 :          38 :       stmt = gfc_trans_omp_master_masked_taskloop (code, op);
    7890                 :          38 :       parallel_combined = true;
    7891                 :             :     }
    7892                 :          60 :   if (TREE_CODE (stmt) != BIND_EXPR)
    7893                 :          47 :     stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
    7894                 :             :   else
    7895                 :          13 :     poplevel (0, 0);
    7896                 :          60 :   stmt = build2_loc (gfc_get_location (&code->loc), OMP_PARALLEL,
    7897                 :             :                      void_type_node, stmt, omp_clauses);
    7898                 :             :   /* masked does have just filter clause, but during gimplification
    7899                 :             :      isn't represented by a gimplification omp context, so for
    7900                 :             :        !$omp parallel masked don't set OMP_PARALLEL_COMBINED,
    7901                 :             :      so that
    7902                 :             :        !$omp parallel masked
    7903                 :             :        !$omp taskloop simd lastprivate (x)
    7904                 :             :      isn't confused with
    7905                 :             :        !$omp parallel masked taskloop simd lastprivate (x)  */
    7906                 :          60 :   if (parallel_combined)
    7907                 :          38 :     OMP_PARALLEL_COMBINED (stmt) = 1;
    7908                 :          60 :   gfc_add_expr_to_block (&block, stmt);
    7909                 :          60 :   if (code->op != EXEC_OMP_PARALLEL_MASTER)
    7910                 :          49 :     gfc_free_split_omp_clauses (code, clausesa);
    7911                 :          60 :   return gfc_finish_block (&block);
    7912                 :             : }
    7913                 :             : 
    7914                 :             : static tree
    7915                 :        1379 : gfc_trans_omp_target_data (gfc_code *code)
    7916                 :             : {
    7917                 :        1379 :   stmtblock_t block;
    7918                 :        1379 :   tree stmt, omp_clauses;
    7919                 :             : 
    7920                 :        1379 :   gfc_start_block (&block);
    7921                 :        1379 :   omp_clauses = gfc_trans_omp_clauses (&block, code->ext.omp_clauses,
    7922                 :             :                                        code->loc);
    7923                 :        1379 :   stmt = gfc_trans_omp_code (code->block->next, true);
    7924                 :        1379 :   stmt = build2_loc (gfc_get_location (&code->loc), OMP_TARGET_DATA,
    7925                 :             :                      void_type_node, stmt, omp_clauses);
    7926                 :        1379 :   gfc_add_expr_to_block (&block, stmt);
    7927                 :        1379 :   return gfc_finish_block (&block);
    7928                 :             : }
    7929                 :             : 
    7930                 :             : static tree
    7931                 :         262 : gfc_trans_omp_target_enter_data (gfc_code *code)
    7932                 :             : {
    7933                 :         262 :   stmtblock_t block;
    7934                 :         262 :   tree stmt, omp_clauses;
    7935                 :             : 
    7936                 :         262 :   gfc_start_block (&block);
    7937                 :         262 :   omp_clauses = gfc_trans_omp_clauses (&block, code->ext.omp_clauses,
    7938                 :             :                                        code->loc);
    7939                 :         262 :   stmt = build1_loc (input_location, OMP_TARGET_ENTER_DATA, void_type_node,
    7940                 :             :                      omp_clauses);
    7941                 :         262 :   gfc_add_expr_to_block (&block, stmt);
    7942                 :         262 :   return gfc_finish_block (&block);
    7943                 :             : }
    7944                 :             : 
    7945                 :             : static tree
    7946                 :         207 : gfc_trans_omp_target_exit_data (gfc_code *code)
    7947                 :             : {
    7948                 :         207 :   stmtblock_t block;
    7949                 :         207 :   tree stmt, omp_clauses;
    7950                 :             : 
    7951                 :         207 :   gfc_start_block (&block);
    7952                 :         207 :   omp_clauses = gfc_trans_omp_clauses (&block, code->ext.omp_clauses,
    7953                 :             :                                        code->loc, false, false, code->op);
    7954                 :         207 :   stmt = build1_loc (input_location, OMP_TARGET_EXIT_DATA, void_type_node,
    7955                 :             :                      omp_clauses);
    7956                 :         207 :   gfc_add_expr_to_block (&block, stmt);
    7957                 :         207 :   return gfc_finish_block (&block);
    7958                 :             : }
    7959                 :             : 
    7960                 :             : static tree
    7961                 :        1701 : gfc_trans_omp_target_update (gfc_code *code)
    7962                 :             : {
    7963                 :        1701 :   stmtblock_t block;
    7964                 :        1701 :   tree stmt, omp_clauses;
    7965                 :             : 
    7966                 :        1701 :   gfc_start_block (&block);
    7967                 :        1701 :   omp_clauses = gfc_trans_omp_clauses (&block, code->ext.omp_clauses,
    7968                 :             :                                        code->loc);
    7969                 :        1701 :   stmt = build1_loc (input_location, OMP_TARGET_UPDATE, void_type_node,
    7970                 :             :                      omp_clauses);
    7971                 :        1701 :   gfc_add_expr_to_block (&block, stmt);
    7972                 :        1701 :   return gfc_finish_block (&block);
    7973                 :             : }
    7974                 :             : 
    7975                 :             : static tree
    7976                 :          85 : gfc_trans_omp_workshare (gfc_code *code, gfc_omp_clauses *clauses)
    7977                 :             : {
    7978                 :          85 :   tree res, tmp, stmt;
    7979                 :          85 :   stmtblock_t block, *pblock = NULL;
    7980                 :          85 :   stmtblock_t singleblock;
    7981                 :          85 :   int saved_ompws_flags;
    7982                 :          85 :   bool singleblock_in_progress = false;
    7983                 :             :   /* True if previous gfc_code in workshare construct is not workshared.  */
    7984                 :          85 :   bool prev_singleunit;
    7985                 :          85 :   location_t loc = gfc_get_location (&code->loc);
    7986                 :             : 
    7987                 :          85 :   code = code->block->next;
    7988                 :             : 
    7989                 :          85 :   pushlevel ();
    7990                 :             : 
    7991                 :          85 :   gfc_start_block (&block);
    7992                 :          85 :   pblock = &block;
    7993                 :             : 
    7994                 :          85 :   ompws_flags = OMPWS_WORKSHARE_FLAG;
    7995                 :          85 :   prev_singleunit = false;
    7996                 :             : 
    7997                 :             :   /* Translate statements one by one to trees until we reach
    7998                 :             :      the end of the workshare construct.  Adjacent gfc_codes that
    7999                 :             :      are a single unit of work are clustered and encapsulated in a
    8000                 :             :      single OMP_SINGLE construct.  */
    8001                 :         282 :   for (; code; code = code->next)
    8002                 :             :     {
    8003                 :         197 :       if (code->here != 0)
    8004                 :             :         {
    8005                 :           0 :           res = gfc_trans_label_here (code);
    8006                 :           0 :           gfc_add_expr_to_block (pblock, res);
    8007                 :             :         }
    8008                 :             : 
    8009                 :             :       /* No dependence analysis, use for clauses with wait.
    8010                 :             :          If this is the last gfc_code, use default omp_clauses.  */
    8011                 :         197 :       if (code->next == NULL && clauses->nowait)
    8012                 :          60 :         ompws_flags |= OMPWS_NOWAIT;
    8013                 :             : 
    8014                 :             :       /* By default, every gfc_code is a single unit of work.  */
    8015                 :         197 :       ompws_flags |= OMPWS_CURR_SINGLEUNIT;
    8016                 :         197 :       ompws_flags &= ~(OMPWS_SCALARIZER_WS | OMPWS_SCALARIZER_BODY);
    8017                 :             : 
    8018                 :         197 :       switch (code->op)
    8019                 :             :         {
    8020                 :             :         case EXEC_NOP:
    8021                 :             :           res = NULL_TREE;
    8022                 :             :           break;
    8023                 :             : 
    8024                 :         125 :         case EXEC_ASSIGN:
    8025                 :         125 :           res = gfc_trans_assign (code);
    8026                 :         125 :           break;
    8027                 :             : 
    8028                 :           0 :         case EXEC_POINTER_ASSIGN:
    8029                 :           0 :           res = gfc_trans_pointer_assign (code);
    8030                 :           0 :           break;
    8031                 :             : 
    8032                 :           0 :         case EXEC_INIT_ASSIGN:
    8033                 :           0 :           res = gfc_trans_init_assign (code);
    8034                 :           0 :           break;
    8035                 :             : 
    8036                 :          24 :         case EXEC_FORALL:
    8037                 :          24 :           res = gfc_trans_forall (code);
    8038                 :          24 :           break;
    8039                 :             : 
    8040                 :          19 :         case EXEC_WHERE:
    8041                 :          19 :           res = gfc_trans_where (code);
    8042                 :          19 :           break;
    8043                 :             : 
    8044                 :           7 :         case EXEC_OMP_ATOMIC:
    8045                 :           7 :           res = gfc_trans_omp_directive (code);
    8046                 :           7 :           break;
    8047                 :             : 
    8048                 :          17 :         case EXEC_OMP_PARALLEL:
    8049                 :          17 :         case EXEC_OMP_PARALLEL_DO:
    8050                 :          17 :         case EXEC_OMP_PARALLEL_MASTER:
    8051                 :          17 :         case EXEC_OMP_PARALLEL_SECTIONS:
    8052                 :          17 :         case EXEC_OMP_PARALLEL_WORKSHARE:
    8053                 :          17 :         case EXEC_OMP_CRITICAL:
    8054                 :          17 :           saved_ompws_flags = ompws_flags;
    8055                 :          17 :           ompws_flags = 0;
    8056                 :          17 :           res = gfc_trans_omp_directive (code);
    8057                 :          17 :           ompws_flags = saved_ompws_flags;
    8058                 :          17 :           break;
    8059                 :             : 
    8060                 :           5 :         case EXEC_BLOCK:
    8061                 :           5 :           res = gfc_trans_block_construct (code);
    8062                 :           5 :           break;
    8063                 :             : 
    8064                 :           0 :         default:
    8065                 :           0 :           gfc_internal_error ("gfc_trans_omp_workshare(): Bad statement code");
    8066                 :             :         }
    8067                 :             : 
    8068                 :         197 :       gfc_set_backend_locus (&code->loc);
    8069                 :             : 
    8070                 :         197 :       if (res != NULL_TREE && ! IS_EMPTY_STMT (res))
    8071                 :             :         {
    8072                 :         197 :           if (prev_singleunit)
    8073                 :             :             {
    8074                 :          72 :               if (ompws_flags & OMPWS_CURR_SINGLEUNIT)
    8075                 :             :                 /* Add current gfc_code to single block.  */
    8076                 :          44 :                 gfc_add_expr_to_block (&singleblock, res);
    8077                 :             :               else
    8078                 :             :                 {
    8079                 :             :                   /* Finish single block and add it to pblock.  */
    8080                 :          28 :                   tmp = gfc_finish_block (&singleblock);
    8081                 :          28 :                   tmp = build2_loc (loc, OMP_SINGLE,
    8082                 :             :                                     void_type_node, tmp, NULL_TREE);
    8083                 :          28 :                   gfc_add_expr_to_block (pblock, tmp);
    8084                 :             :                   /* Add current gfc_code to pblock.  */
    8085                 :          28 :                   gfc_add_expr_to_block (pblock, res);
    8086                 :          28 :                   singleblock_in_progress = false;
    8087                 :             :                 }
    8088                 :             :             }
    8089                 :             :           else
    8090                 :             :             {
    8091                 :         125 :               if (ompws_flags & OMPWS_CURR_SINGLEUNIT)
    8092                 :             :                 {
    8093                 :             :                   /* Start single block.  */
    8094                 :          73 :                   gfc_init_block (&singleblock);
    8095                 :          73 :                   gfc_add_expr_to_block (&singleblock, res);
    8096                 :          73 :                   singleblock_in_progress = true;
    8097                 :          73 :                   loc = gfc_get_location (&code->loc);
    8098                 :             :                 }
    8099                 :             :               else
    8100                 :             :                 /* Add the new statement to the block.  */
    8101                 :          52 :                 gfc_add_expr_to_block (pblock, res);
    8102                 :             :             }
    8103                 :         197 :           prev_singleunit = (ompws_flags & OMPWS_CURR_SINGLEUNIT) != 0;
    8104                 :             :         }
    8105                 :             :     }
    8106                 :             : 
    8107                 :             :   /* Finish remaining SINGLE block, if we were in the middle of one.  */
    8108                 :          85 :   if (singleblock_in_progress)
    8109                 :             :     {
    8110                 :             :       /* Finish single block and add it to pblock.  */
    8111                 :          45 :       tmp = gfc_finish_block (&singleblock);
    8112                 :          45 :       tmp = build2_loc (loc, OMP_SINGLE, void_type_node, tmp,
    8113                 :          45 :                         clauses->nowait
    8114                 :          27 :                         ? build_omp_clause (input_location, OMP_CLAUSE_NOWAIT)
    8115                 :             :                         : NULL_TREE);
    8116                 :          45 :       gfc_add_expr_to_block (pblock, tmp);
    8117                 :             :     }
    8118                 :             : 
    8119                 :          85 :   stmt = gfc_finish_block (pblock);
    8120                 :          85 :   if (TREE_CODE (stmt) != BIND_EXPR)
    8121                 :             :     {
    8122                 :          65 :       if (!IS_EMPTY_STMT (stmt))
    8123                 :             :         {
    8124                 :          65 :           tree bindblock = poplevel (1, 0);
    8125                 :          65 :           stmt = build3_v (BIND_EXPR, NULL, stmt, bindblock);
    8126                 :             :         }
    8127                 :             :       else
    8128                 :           0 :         poplevel (0, 0);
    8129                 :             :     }
    8130                 :             :   else
    8131                 :          20 :     poplevel (0, 0);
    8132                 :             : 
    8133                 :          85 :   if (IS_EMPTY_STMT (stmt) && !clauses->nowait)
    8134                 :           0 :     stmt = gfc_trans_omp_barrier ();
    8135                 :             : 
    8136                 :          85 :   ompws_flags = 0;
    8137                 :          85 :   return stmt;
    8138                 :             : }
    8139                 :             : 
    8140                 :             : tree
    8141                 :          73 : gfc_trans_oacc_declare (gfc_code *code)
    8142                 :             : {
    8143                 :          73 :   stmtblock_t block;
    8144                 :          73 :   tree stmt, oacc_clauses;
    8145                 :          73 :   enum tree_code construct_code;
    8146                 :             : 
    8147                 :          73 :   construct_code = OACC_DATA;
    8148                 :             : 
    8149                 :          73 :   gfc_start_block (&block);
    8150                 :             : 
    8151                 :          73 :   oacc_clauses = gfc_trans_omp_clauses (&block, code->ext.oacc_declare->clauses,
    8152                 :             :                                         code->loc, false, true);
    8153                 :          73 :   stmt = gfc_trans_omp_code (code->block->next, true);
    8154                 :          73 :   stmt = build2_loc (input_location, construct_code, void_type_node, stmt,
    8155                 :             :                      oacc_clauses);
    8156                 :          73 :   gfc_add_expr_to_block (&block, stmt);
    8157                 :             : 
    8158                 :          73 :   return gfc_finish_block (&block);
    8159                 :             : }
    8160                 :             : 
    8161                 :             : tree
    8162                 :       11339 : gfc_trans_oacc_directive (gfc_code *code)
    8163                 :             : {
    8164                 :       11339 :   switch (code->op)
    8165                 :             :     {
    8166                 :        1374 :     case EXEC_OACC_PARALLEL_LOOP:
    8167                 :        1374 :     case EXEC_OACC_KERNELS_LOOP:
    8168                 :        1374 :     case EXEC_OACC_SERIAL_LOOP:
    8169                 :        1374 :       return gfc_trans_oacc_combined_directive (code);
    8170                 :        4021 :     case EXEC_OACC_PARALLEL:
    8171                 :        4021 :     case EXEC_OACC_KERNELS:
    8172                 :        4021 :     case EXEC_OACC_SERIAL:
    8173                 :        4021 :     case EXEC_OACC_DATA:
    8174                 :        4021 :     case EXEC_OACC_HOST_DATA:
    8175                 :        4021 :       return gfc_trans_oacc_construct (code);
    8176                 :        3086 :     case EXEC_OACC_LOOP:
    8177                 :        3086 :       return gfc_trans_omp_do (code, code->op, NULL, code->ext.omp_clauses,
    8178                 :        3086 :                                NULL);
    8179                 :        2075 :     case EXEC_OACC_UPDATE:
    8180                 :        2075 :     case EXEC_OACC_CACHE:
    8181                 :        2075 :     case EXEC_OACC_ENTER_DATA:
    8182                 :        2075 :     case EXEC_OACC_EXIT_DATA:
    8183                 :        2075 :       return gfc_trans_oacc_executable_directive (code);
    8184                 :         167 :     case EXEC_OACC_WAIT:
    8185                 :         167 :       return gfc_trans_oacc_wait_directive (code);
    8186                 :         543 :     case EXEC_OACC_ATOMIC:
    8187                 :         543 :       return gfc_trans_omp_atomic (code);
    8188                 :          73 :     case EXEC_OACC_DECLARE:
    8189                 :          73 :       return gfc_trans_oacc_declare (code);
    8190                 :           0 :     default:
    8191                 :           0 :       gcc_unreachable ();
    8192                 :             :     }
    8193                 :             : }
    8194                 :             : 
    8195                 :             : tree
    8196                 :       17340 : gfc_trans_omp_directive (gfc_code *code)
    8197                 :             : {
    8198                 :       17340 :   switch (code->op)
    8199                 :             :     {
    8200                 :          31 :     case EXEC_OMP_ALLOCATE:
    8201                 :          31 :     case EXEC_OMP_ALLOCATORS:
    8202                 :          31 :       return gfc_trans_omp_allocators (code);
    8203                 :          10 :     case EXEC_OMP_ASSUME:
    8204                 :          10 :       return gfc_trans_omp_assume (code);
    8205                 :        2046 :     case EXEC_OMP_ATOMIC:
    8206                 :        2046 :       return gfc_trans_omp_atomic (code);
    8207                 :         602 :     case EXEC_OMP_BARRIER:
    8208                 :         602 :       return gfc_trans_omp_barrier ();
    8209                 :         310 :     case EXEC_OMP_CANCEL:
    8210                 :         310 :       return gfc_trans_omp_cancel (code);
    8211                 :         170 :     case EXEC_OMP_CANCELLATION_POINT:
    8212                 :         170 :       return gfc_trans_omp_cancellation_point (code);
    8213                 :         143 :     case EXEC_OMP_CRITICAL:
    8214                 :         143 :       return gfc_trans_omp_critical (code);
    8215                 :         106 :     case EXEC_OMP_DEPOBJ:
    8216                 :         106 :       return gfc_trans_omp_depobj (code);
    8217                 :        1960 :     case EXEC_OMP_DISTRIBUTE:
    8218                 :        1960 :     case EXEC_OMP_DO:
    8219                 :        1960 :     case EXEC_OMP_LOOP:
    8220                 :        1960 :     case EXEC_OMP_SIMD:
    8221                 :        1960 :     case EXEC_OMP_TASKLOOP:
    8222                 :        1960 :       return gfc_trans_omp_do (code, code->op, NULL, code->ext.omp_clauses,
    8223                 :        1960 :                                NULL);
    8224                 :         105 :     case EXEC_OMP_DISTRIBUTE_PARALLEL_DO:
    8225                 :         105 :     case EXEC_OMP_DISTRIBUTE_PARALLEL_DO_SIMD:
    8226                 :         105 :     case EXEC_OMP_DISTRIBUTE_SIMD:
    8227                 :         105 :       return gfc_trans_omp_distribute (code, NULL);
    8228                 :         126 :     case EXEC_OMP_DO_SIMD:
    8229                 :         126 :       return gfc_trans_omp_do_simd (code, NULL, NULL, NULL_TREE);
    8230                 :          18 :     case EXEC_OMP_ERROR:
    8231                 :          18 :       return gfc_trans_omp_error (code);
    8232                 :          69 :     case EXEC_OMP_FLUSH:
    8233                 :          69 :       return gfc_trans_omp_flush (code);
    8234                 :          37 :     case EXEC_OMP_MASKED:
    8235                 :          37 :       return gfc_trans_omp_masked (code, NULL);
    8236                 :         104 :     case EXEC_OMP_MASTER:
    8237                 :         104 :       return gfc_trans_omp_master (code);
    8238                 :          45 :     case EXEC_OMP_MASKED_TASKLOOP:
    8239                 :          45 :     case EXEC_OMP_MASKED_TASKLOOP_SIMD:
    8240                 :          45 :     case EXEC_OMP_MASTER_TASKLOOP:
    8241                 :          45 :     case EXEC_OMP_MASTER_TASKLOOP_SIMD:
    8242                 :          45 :       return gfc_trans_omp_master_masked_taskloop (code, code->op);
    8243                 :         519 :     case EXEC_OMP_ORDERED:
    8244                 :         519 :       return gfc_trans_omp_ordered (code);
    8245                 :        1848 :     case EXEC_OMP_PARALLEL:
    8246                 :        1848 :       return gfc_trans_omp_parallel (code);
    8247                 :         831 :     case EXEC_OMP_PARALLEL_DO:
    8248                 :         831 :       return gfc_trans_omp_parallel_do (code, false, NULL, NULL);
    8249                 :          10 :     case EXEC_OMP_PARALLEL_LOOP:
    8250                 :          10 :       return gfc_trans_omp_parallel_do (code, true, NULL, NULL);
    8251                 :         278 :     case EXEC_OMP_PARALLEL_DO_SIMD:
    8252                 :         278 :       return gfc_trans_omp_parallel_do_simd (code, NULL, NULL);
    8253                 :          60 :     case EXEC_OMP_PARALLEL_MASKED:
    8254                 :          60 :     case EXEC_OMP_PARALLEL_MASKED_TASKLOOP:
    8255                 :          60 :     case EXEC_OMP_PARALLEL_MASKED_TASKLOOP_SIMD:
    8256                 :          60 :     case EXEC_OMP_PARALLEL_MASTER:
    8257                 :          60 :     case EXEC_OMP_PARALLEL_MASTER_TASKLOOP:
    8258                 :          60 :     case EXEC_OMP_PARALLEL_MASTER_TASKLOOP_SIMD:
    8259                 :          60 :       return gfc_trans_omp_parallel_master_masked (code);
    8260                 :          54 :     case EXEC_OMP_PARALLEL_SECTIONS:
    8261                 :          54 :       return gfc_trans_omp_parallel_sections (code);
    8262                 :          50 :     case EXEC_OMP_PARALLEL_WORKSHARE:
    8263                 :          50 :       return gfc_trans_omp_parallel_workshare (code);
    8264                 :          53 :     case EXEC_OMP_SCOPE:
    8265                 :          53 :       return gfc_trans_omp_scope (code);
    8266                 :          75 :     case EXEC_OMP_SECTIONS:
    8267                 :          75 :       return gfc_trans_omp_sections (code, code->ext.omp_clauses);
    8268                 :         565 :     case EXEC_OMP_SINGLE:
    8269                 :         565 :       return gfc_trans_omp_single (code, code->ext.omp_clauses);
    8270                 :        1783 :     case EXEC_OMP_TARGET:
    8271                 :        1783 :     case EXEC_OMP_TARGET_PARALLEL:
    8272                 :        1783 :     case EXEC_OMP_TARGET_PARALLEL_DO:
    8273                 :        1783 :     case EXEC_OMP_TARGET_PARALLEL_DO_SIMD:
    8274                 :        1783 :     case EXEC_OMP_TARGET_PARALLEL_LOOP:
    8275                 :        1783 :     case EXEC_OMP_TARGET_SIMD:
    8276                 :        1783 :     case EXEC_OMP_TARGET_TEAMS:
    8277                 :        1783 :     case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE:
    8278                 :        1783 :     case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO:
    8279                 :        1783 :     case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
    8280                 :        1783 :     case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD:
    8281                 :        1783 :     case EXEC_OMP_TARGET_TEAMS_LOOP:
    8282                 :        1783 :       return gfc_trans_omp_target (code);
    8283                 :        1379 :     case EXEC_OMP_TARGET_DATA:
    8284                 :        1379 :       return gfc_trans_omp_target_data (code);
    8285                 :         262 :     case EXEC_OMP_TARGET_ENTER_DATA:
    8286                 :         262 :       return gfc_trans_omp_target_enter_data (code);
    8287                 :         207 :     case EXEC_OMP_TARGET_EXIT_DATA:
    8288                 :         207 :       return gfc_trans_omp_target_exit_data (code);
    8289                 :        1701 :     case EXEC_OMP_TARGET_UPDATE:
    8290                 :        1701 :       return gfc_trans_omp_target_update (code);
    8291                 :        1120 :     case EXEC_OMP_TASK:
    8292                 :        1120 :       return gfc_trans_omp_task (code);
    8293                 :         181 :     case EXEC_OMP_TASKGROUP:
    8294                 :         181 :       return gfc_trans_omp_taskgroup (code);
    8295                 :          30 :     case EXEC_OMP_TASKLOOP_SIMD:
    8296                 :          30 :       return gfc_trans_omp_taskloop (code, code->op);
    8297                 :         143 :     case EXEC_OMP_TASKWAIT:
    8298                 :         143 :       return gfc_trans_omp_taskwait (code);
    8299                 :           8 :     case EXEC_OMP_TASKYIELD:
    8300                 :           8 :       return gfc_trans_omp_taskyield ();
    8301                 :         266 :     case EXEC_OMP_TEAMS:
    8302                 :         266 :     case EXEC_OMP_TEAMS_DISTRIBUTE:
    8303                 :         266 :     case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO:
    8304                 :         266 :     case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
    8305                 :         266 :     case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD:
    8306                 :         266 :     case EXEC_OMP_TEAMS_LOOP:
    8307                 :         266 :       return gfc_trans_omp_teams (code, NULL, NULL_TREE);
    8308                 :          35 :     case EXEC_OMP_WORKSHARE:
    8309                 :          35 :       return gfc_trans_omp_workshare (code, code->ext.omp_clauses);
    8310                 :           0 :     default:
    8311                 :           0 :       gcc_unreachable ();
    8312                 :             :     }
    8313                 :             : }
    8314                 :             : 
    8315                 :             : void
    8316                 :         114 : gfc_trans_omp_declare_simd (gfc_namespace *ns)
    8317                 :             : {
    8318                 :         114 :   if (ns->entries)
    8319                 :             :     return;
    8320                 :             : 
    8321                 :         114 :   gfc_omp_declare_simd *ods;
    8322                 :         272 :   for (ods = ns->omp_declare_simd; ods; ods = ods->next)
    8323                 :             :     {
    8324                 :         158 :       tree c = gfc_trans_omp_clauses (NULL, ods->clauses, ods->where, true);
    8325                 :         158 :       tree fndecl = ns->proc_name->backend_decl;
    8326                 :         158 :       if (c != NULL_TREE)
    8327                 :         108 :         c = tree_cons (NULL_TREE, c, NULL_TREE);
    8328                 :         158 :       c = build_tree_list (get_identifier ("omp declare simd"), c);
    8329                 :         158 :       TREE_CHAIN (c) = DECL_ATTRIBUTES (fndecl);
    8330                 :         158 :       DECL_ATTRIBUTES (fndecl) = c;
    8331                 :             :     }
    8332                 :             : }
    8333                 :             : 
    8334                 :             : void
    8335                 :        8923 : gfc_trans_omp_declare_variant (gfc_namespace *ns)
    8336                 :             : {
    8337                 :        8923 :   tree base_fn_decl = ns->proc_name->backend_decl;
    8338                 :        8923 :   gfc_namespace *search_ns = ns;
    8339                 :        8923 :   gfc_omp_declare_variant *next;
    8340                 :             : 
    8341                 :        8923 :   for (gfc_omp_declare_variant *odv = search_ns->omp_declare_variant;
    8342                 :       22369 :        search_ns; odv = next)
    8343                 :             :     {
    8344                 :             :       /* Look in the parent namespace if there are no more directives in the
    8345                 :             :          current namespace.  */
    8346                 :       13446 :       if (!odv)
    8347                 :             :         {
    8348                 :       13164 :           search_ns = search_ns->parent;
    8349                 :       13164 :           if (search_ns)
    8350                 :        4241 :             next = search_ns->omp_declare_variant;
    8351                 :       13164 :           continue;
    8352                 :             :         }
    8353                 :             : 
    8354                 :         282 :       next = odv->next;
    8355                 :             : 
    8356                 :         282 :       if (odv->error_p)
    8357                 :          17 :         continue;
    8358                 :             : 
    8359                 :             :       /* Check directive the first time it is encountered.  */
    8360                 :         265 :       bool error_found = true;
    8361                 :             : 
    8362                 :         265 :       if (odv->checked_p)
    8363                 :          32 :         error_found = false;
    8364                 :         265 :       if (odv->base_proc_symtree == NULL)
    8365                 :             :         {
    8366                 :         250 :           if (!search_ns->proc_name->attr.function
    8367                 :         250 :               && !search_ns->proc_name->attr.subroutine)
    8368                 :           1 :             gfc_error ("The base name for 'declare variant' must be "
    8369                 :             :                        "specified at %L ", &odv->where);
    8370                 :             :           else
    8371                 :             :             error_found = false;
    8372                 :             :         }
    8373                 :             :       else
    8374                 :             :         {
    8375                 :          15 :           if (!search_ns->contained
    8376                 :           3 :               && strcmp (odv->base_proc_symtree->name,
    8377                 :           3 :                          ns->proc_name->name))
    8378                 :           1 :             gfc_error ("The base name at %L does not match the name of the "
    8379                 :             :                        "current procedure", &odv->where);
    8380                 :          14 :           else if (odv->base_proc_symtree->n.sym->attr.entry)
    8381                 :           1 :             gfc_error ("The base name at %L must not be an entry name",
    8382                 :             :                         &odv->where);
    8383                 :          13 :           else if (odv->base_proc_symtree->n.sym->attr.generic)
    8384                 :           1 :             gfc_error ("The base name at %L must not be a generic name",
    8385                 :             :                         &odv->where);
    8386                 :          12 :           else if (odv->base_proc_symtree->n.sym->attr.proc_pointer)
    8387                 :           1 :             gfc_error ("The base name at %L must not be a procedure pointer",
    8388                 :             :                         &odv->where);
    8389                 :          11 :           else if (odv->base_proc_symtree->n.sym->attr.implicit_type)
    8390                 :           1 :             gfc_error ("The base procedure at %L must have an explicit "
    8391                 :             :                         "interface", &odv->where);
    8392                 :             :           else
    8393                 :             :             error_found = false;
    8394                 :             :         }
    8395                 :             : 
    8396                 :         265 :       odv->checked_p = true;
    8397                 :         265 :       if (error_found)
    8398                 :             :         {
    8399                 :           6 :           odv->error_p = true;
    8400                 :           6 :           continue;
    8401                 :             :         }
    8402                 :             : 
    8403                 :             :       /* Ignore directives that do not apply to the current procedure.  */
    8404                 :         259 :       if ((odv->base_proc_symtree == NULL && search_ns != ns)
    8405                 :         233 :           || (odv->base_proc_symtree != NULL
    8406                 :          10 :               && strcmp (odv->base_proc_symtree->name, ns->proc_name->name)))
    8407                 :          33 :         continue;
    8408                 :             : 
    8409                 :         226 :       tree set_selectors = NULL_TREE;
    8410                 :         226 :       gfc_omp_set_selector *oss;
    8411                 :             : 
    8412                 :         500 :       for (oss = odv->set_selectors; oss; oss = oss->next)
    8413                 :             :         {
    8414                 :         274 :           tree selectors = NULL_TREE;
    8415                 :         274 :           gfc_omp_selector *os;
    8416                 :         274 :           enum omp_tss_code set = oss->code;
    8417                 :         274 :           gcc_assert (set != OMP_TRAIT_SET_INVALID);
    8418                 :             : 
    8419                 :         643 :           for (os = oss->trait_selectors; os; os = os->next)
    8420                 :             :             {
    8421                 :         369 :               tree scoreval = NULL_TREE;
    8422                 :         369 :               tree properties = NULL_TREE;
    8423                 :         369 :               gfc_omp_trait_property *otp;
    8424                 :         369 :               enum omp_ts_code sel = os->code;
    8425                 :             : 
    8426                 :             :               /* Per the spec, "Implementations can ignore specified
    8427                 :             :                  selectors that are not those described in this section";
    8428                 :             :                  however, we  must record such selectors because they
    8429                 :             :                  cause match failures.  */
    8430                 :         369 :               if (sel == OMP_TRAIT_INVALID)
    8431                 :             :                 {
    8432                 :           1 :                   selectors = make_trait_selector (sel, NULL_TREE, NULL_TREE,
    8433                 :             :                                                    selectors);
    8434                 :           1 :                   continue;
    8435                 :             :                 }
    8436                 :             : 
    8437                 :         626 :               for (otp = os->properties; otp; otp = otp->next)
    8438                 :             :                 {
    8439                 :         258 :                   switch (otp->property_kind)
    8440                 :             :                     {
    8441                 :          33 :                     case OMP_TRAIT_PROPERTY_DEV_NUM_EXPR:
    8442                 :          33 :                     case OMP_TRAIT_PROPERTY_BOOL_EXPR:
    8443                 :          33 :                       {
    8444                 :          33 :                         gfc_se se;
    8445                 :          33 :                         gfc_init_se (&se, NULL);
    8446                 :          33 :                         gfc_conv_expr (&se, otp->expr);
    8447                 :          33 :                         properties = make_trait_property (NULL_TREE, se.expr,
    8448                 :             :                                                           properties);
    8449                 :             :                       }
    8450                 :          33 :                       break;
    8451                 :          22 :                     case OMP_TRAIT_PROPERTY_ID:
    8452                 :          22 :                       properties
    8453                 :          22 :                         = make_trait_property (get_identifier (otp->name),
    8454                 :             :                                                NULL_TREE, properties);
    8455                 :          22 :                       break;
    8456                 :         189 :                     case OMP_TRAIT_PROPERTY_NAME_LIST:
    8457                 :         189 :                       {
    8458                 :         189 :                         tree prop = OMP_TP_NAMELIST_NODE;
    8459                 :         189 :                         tree value = NULL_TREE;
    8460                 :         189 :                         if (otp->is_name)
    8461                 :         147 :                           value = get_identifier (otp->name);
    8462                 :             :                         else
    8463                 :          42 :                           value = gfc_conv_constant_to_tree (otp->expr);
    8464                 :             : 
    8465                 :         189 :                         properties = make_trait_property (prop, value,
    8466                 :             :                                                           properties);
    8467                 :             :                       }
    8468                 :         189 :                       break;
    8469                 :          14 :                     case OMP_TRAIT_PROPERTY_CLAUSE_LIST:
    8470                 :          14 :                       properties = gfc_trans_omp_clauses (NULL, otp->clauses,
    8471                 :             :                                                           odv->where, true);
    8472                 :          14 :                       break;
    8473                 :           0 :                     default:
    8474                 :           0 :                       gcc_unreachable ();
    8475                 :             :                     }
    8476                 :             :                 }
    8477                 :             : 
    8478                 :         368 :               if (os->score)
    8479                 :             :                 {
    8480                 :          49 :                   gfc_se se;
    8481                 :          49 :                   gfc_init_se (&se, NULL);
    8482                 :          49 :                   gfc_conv_expr (&se, os->score);
    8483                 :          49 :                   scoreval = se.expr;
    8484                 :             :                 }
    8485                 :             : 
    8486                 :         368 :               selectors = make_trait_selector (sel, scoreval,
    8487                 :             :                                                properties, selectors);
    8488                 :             :             }
    8489                 :         274 :           set_selectors = make_trait_set_selector (set, selectors,
    8490                 :             :                                                    set_selectors);
    8491                 :             :         }
    8492                 :             : 
    8493                 :         226 :       const char *variant_proc_name = odv->variant_proc_symtree->name;
    8494                 :         226 :       gfc_symbol *variant_proc_sym = odv->variant_proc_symtree->n.sym;
    8495                 :         226 :       if (variant_proc_sym == NULL || variant_proc_sym->attr.implicit_type)
    8496                 :             :         {
    8497                 :           4 :           gfc_symtree *proc_st;
    8498                 :           4 :           gfc_find_sym_tree (variant_proc_name, gfc_current_ns, 1, &proc_st);
    8499                 :           4 :           variant_proc_sym = proc_st->n.sym;
    8500                 :             :         }
    8501                 :           4 :       if (variant_proc_sym == NULL)
    8502                 :             :         {
    8503                 :           0 :           gfc_error ("Cannot find symbol %qs", variant_proc_name);
    8504                 :           0 :           continue;
    8505                 :             :         }
    8506                 :         226 :       set_selectors = omp_check_context_selector
    8507                 :         226 :           (gfc_get_location (&odv->where), set_selectors);
    8508                 :         226 :       if (set_selectors != error_mark_node)
    8509                 :             :         {
    8510                 :         216 :           if (!variant_proc_sym->attr.implicit_type
    8511                 :             :               && !variant_proc_sym->attr.subroutine
    8512                 :         216 :               && !variant_proc_sym->attr.function)
    8513                 :             :             {
    8514                 :           0 :               gfc_error ("variant %qs at %L is not a function or subroutine",
    8515                 :             :                          variant_proc_name, &odv->where);
    8516                 :           0 :               variant_proc_sym = NULL;
    8517                 :             :             }
    8518                 :         216 :           else if (omp_get_context_selector (set_selectors,
    8519                 :             :                                              OMP_TRAIT_SET_CONSTRUCT,
    8520                 :             :                                              OMP_TRAIT_CONSTRUCT_SIMD)
    8521                 :             :                    == NULL_TREE)
    8522                 :             :             {
    8523                 :         202 :               char err[256];
    8524                 :         202 :               if (!gfc_compare_interfaces (ns->proc_name, variant_proc_sym,
    8525                 :             :                                            variant_proc_sym->name, 0, 1,
    8526                 :             :                                            err, sizeof (err), NULL, NULL))
    8527                 :             :                 {
    8528                 :           2 :                   gfc_error ("variant %qs and base %qs at %L have "
    8529                 :             :                              "incompatible types: %s",
    8530                 :           2 :                              variant_proc_name, ns->proc_name->name,
    8531                 :             :                              &odv->where, err);
    8532                 :           2 :                   variant_proc_sym = NULL;
    8533                 :             :                 }
    8534                 :             :             }
    8535                 :         202 :           if (variant_proc_sym != NULL)
    8536                 :             :             {
    8537                 :         214 :               gfc_set_sym_referenced (variant_proc_sym);
    8538                 :         214 :               tree construct
    8539                 :         214 :                 = omp_get_context_selector_list (set_selectors,
    8540                 :             :                                                  OMP_TRAIT_SET_CONSTRUCT);
    8541                 :         214 :               omp_mark_declare_variant (gfc_get_location (&odv->where),
    8542                 :             :                                         gfc_get_symbol_decl (variant_proc_sym),
    8543                 :             :                                         construct);
    8544                 :         214 :               if (omp_context_selector_matches (set_selectors))
    8545                 :             :                 {
    8546                 :         135 :                   tree id = get_identifier ("omp declare variant base");
    8547                 :         135 :                   tree variant = gfc_get_symbol_decl (variant_proc_sym);
    8548                 :         135 :                   DECL_ATTRIBUTES (base_fn_decl)
    8549                 :         270 :                     = tree_cons (id, build_tree_list (variant, set_selectors),
    8550                 :         135 :                                  DECL_ATTRIBUTES (base_fn_decl));
    8551                 :             :                 }
    8552                 :             :             }
    8553                 :             :         }
    8554                 :             :     }
    8555                 :        8923 : }
    8556                 :             : 
    8557                 :             : /* Add ptr for tracking as being allocated by GOMP_alloc. */
    8558                 :             : 
    8559                 :             : tree
    8560                 :          29 : gfc_omp_call_add_alloc (tree ptr)
    8561                 :             : {
    8562                 :          29 :   static tree fn = NULL_TREE;
    8563                 :          29 :   if (fn == NULL_TREE)
    8564                 :             :     {
    8565                 :           6 :       fn = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
    8566                 :           6 :       tree att = build_tree_list (NULL_TREE, build_string (4, ". R "));
    8567                 :           6 :       att = tree_cons (get_identifier ("fn spec"), att, TYPE_ATTRIBUTES (fn));
    8568                 :           6 :       fn = build_type_attribute_variant (fn, att);
    8569                 :           6 :       fn = build_fn_decl ("GOMP_add_alloc", fn);
    8570                 :             :     }
    8571                 :          29 :   return build_call_expr_loc (input_location, fn, 1, ptr);
    8572                 :             : }
    8573                 :             : 
    8574                 :             : /* Generated function returns true when it was tracked via GOMP_add_alloc and
    8575                 :             :    removes it from the tracking.  As called just before GOMP_free or omp_realloc
    8576                 :             :    the pointer is or might become invalid, thus, it is always removed. */
    8577                 :             : 
    8578                 :             : tree
    8579                 :          47 : gfc_omp_call_is_alloc (tree ptr)
    8580                 :             : {
    8581                 :          47 :   static tree fn = NULL_TREE;
    8582                 :          47 :   if (fn == NULL_TREE)
    8583                 :             :     {
    8584                 :           6 :       fn = build_function_type_list (boolean_type_node, ptr_type_node,
    8585                 :             :                                      NULL_TREE);
    8586                 :           6 :       tree att = build_tree_list (NULL_TREE, build_string (4, ". R "));
    8587                 :           6 :       att = tree_cons (get_identifier ("fn spec"), att, TYPE_ATTRIBUTES (fn));
    8588                 :           6 :       fn = build_type_attribute_variant (fn, att);
    8589                 :           6 :       fn = build_fn_decl ("GOMP_is_alloc", fn);
    8590                 :             :     }
    8591                 :          47 :   return build_call_expr_loc (input_location, fn, 1, ptr);
    8592                 :             : }
        

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.