comparison gcc/fortran/trans-openmp.c @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
1 /* OpenMP directive translation -- generate GCC trees from gfc_code. 1 /* OpenMP directive translation -- generate GCC trees from gfc_code.
2 Copyright (C) 2005-2018 Free Software Foundation, Inc. 2 Copyright (C) 2005-2020 Free Software Foundation, Inc.
3 Contributed by Jakub Jelinek <jakub@redhat.com> 3 Contributed by Jakub Jelinek <jakub@redhat.com>
4 4
5 This file is part of GCC. 5 This file is part of GCC.
6 6
7 GCC is free software; you can redistribute it and/or modify it under 7 GCC is free software; you can redistribute it and/or modify it under
41 #undef GCC_DIAG_STYLE 41 #undef GCC_DIAG_STYLE
42 #define GCC_DIAG_STYLE __gcc_tdiag__ 42 #define GCC_DIAG_STYLE __gcc_tdiag__
43 #include "diagnostic-core.h" 43 #include "diagnostic-core.h"
44 #undef GCC_DIAG_STYLE 44 #undef GCC_DIAG_STYLE
45 #define GCC_DIAG_STYLE __gcc_gfc__ 45 #define GCC_DIAG_STYLE __gcc_gfc__
46 #include "attribs.h"
46 47
47 int ompws_flags; 48 int ompws_flags;
49
50 /* True if OpenMP should regard this DECL as being a scalar which has Fortran's
51 allocatable or pointer attribute. */
52
53 bool
54 gfc_omp_is_allocatable_or_ptr (const_tree decl)
55 {
56 return (DECL_P (decl)
57 && (GFC_DECL_GET_SCALAR_POINTER (decl)
58 || GFC_DECL_GET_SCALAR_ALLOCATABLE (decl)));
59 }
60
61 /* True if the argument is an optional argument; except that false is also
62 returned for arguments with the value attribute (nonpointers) and for
63 assumed-shape variables (decl is a local variable containing arg->data).
64 Note that pvoid_type_node is for 'type(c_ptr), value. */
65
66 static bool
67 gfc_omp_is_optional_argument (const_tree decl)
68 {
69 return (TREE_CODE (decl) == PARM_DECL
70 && DECL_LANG_SPECIFIC (decl)
71 && TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE
72 && !VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl)))
73 && GFC_DECL_OPTIONAL_ARGUMENT (decl));
74 }
75
76 /* Check whether this DECL belongs to a Fortran optional argument.
77 With 'for_present_check' set to false, decls which are optional parameters
78 themselve are returned as tree - or a NULL_TREE otherwise. Those decls are
79 always pointers. With 'for_present_check' set to true, the decl for checking
80 whether an argument is present is returned; for arguments with value
81 attribute this is the hidden argument and of BOOLEAN_TYPE. If the decl is
82 unrelated to optional arguments, NULL_TREE is returned. */
83
84 tree
85 gfc_omp_check_optional_argument (tree decl, bool for_present_check)
86 {
87 if (!for_present_check)
88 return gfc_omp_is_optional_argument (decl) ? decl : NULL_TREE;
89
90 if (!DECL_LANG_SPECIFIC (decl))
91 return NULL_TREE;
92
93 bool is_array_type = false;
94
95 /* For assumed-shape arrays, a local decl with arg->data is used. */
96 if (TREE_CODE (decl) != PARM_DECL
97 && (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl))
98 || GFC_ARRAY_TYPE_P (TREE_TYPE (decl))))
99 {
100 is_array_type = true;
101 decl = GFC_DECL_SAVED_DESCRIPTOR (decl);
102 }
103
104 if (decl == NULL_TREE
105 || TREE_CODE (decl) != PARM_DECL
106 || !DECL_LANG_SPECIFIC (decl)
107 || !GFC_DECL_OPTIONAL_ARGUMENT (decl))
108 return NULL_TREE;
109
110 /* Scalars with VALUE attribute which are passed by value use a hidden
111 argument to denote the present status. They are passed as nonpointer type
112 with one exception: 'type(c_ptr), value' as 'void*'. */
113 /* Cf. trans-expr.c's gfc_conv_expr_present. */
114 if (TREE_CODE (TREE_TYPE (decl)) != POINTER_TYPE
115 || VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl))))
116 {
117 char name[GFC_MAX_SYMBOL_LEN + 2];
118 tree tree_name;
119
120 name[0] = '_';
121 strcpy (&name[1], IDENTIFIER_POINTER (DECL_NAME (decl)));
122 tree_name = get_identifier (name);
123
124 /* Walk function argument list to find the hidden arg. */
125 decl = DECL_ARGUMENTS (DECL_CONTEXT (decl));
126 for ( ; decl != NULL_TREE; decl = TREE_CHAIN (decl))
127 if (DECL_NAME (decl) == tree_name
128 && DECL_ARTIFICIAL (decl))
129 break;
130
131 gcc_assert (decl);
132 return decl;
133 }
134
135 tree cond = fold_build2_loc (input_location, NE_EXPR, boolean_type_node,
136 decl, null_pointer_node);
137
138 /* Fortran regards unallocated allocatables/disassociated pointer which
139 are passed to a nonallocatable, nonpointer argument as not associated;
140 cf. F2018, 15.5.2.12, Paragraph 1. */
141 if (is_array_type)
142 {
143 tree cond2 = build_fold_indirect_ref_loc (input_location, decl);
144 cond2 = gfc_conv_array_data (cond2);
145 cond2 = fold_build2_loc (input_location, NE_EXPR, boolean_type_node,
146 cond2, null_pointer_node);
147 cond = fold_build2_loc (input_location, TRUTH_ANDIF_EXPR,
148 boolean_type_node, cond, cond2);
149 }
150
151 return cond;
152 }
153
154
155 /* Returns tree with NULL if it is not an array descriptor and with the tree to
156 access the 'data' component otherwise. With type_only = true, it returns the
157 TREE_TYPE without creating a new tree. */
158
159 tree
160 gfc_omp_array_data (tree decl, bool type_only)
161 {
162 tree type = TREE_TYPE (decl);
163
164 if (POINTER_TYPE_P (type))
165 type = TREE_TYPE (type);
166
167 if (!GFC_DESCRIPTOR_TYPE_P (type))
168 return NULL_TREE;
169
170 if (type_only)
171 return GFC_TYPE_ARRAY_DATAPTR_TYPE (type);
172
173 if (POINTER_TYPE_P (TREE_TYPE (decl)))
174 decl = build_fold_indirect_ref (decl);
175
176 decl = gfc_conv_descriptor_data_get (decl);
177 STRIP_NOPS (decl);
178 return decl;
179 }
48 180
49 /* True if OpenMP should privatize what this DECL points to rather 181 /* True if OpenMP should privatize what this DECL points to rather
50 than the DECL itself. */ 182 than the DECL itself. */
51 183
52 bool 184 bool
56 188
57 if (TREE_CODE (type) == REFERENCE_TYPE 189 if (TREE_CODE (type) == REFERENCE_TYPE
58 && (!DECL_ARTIFICIAL (decl) || TREE_CODE (decl) == PARM_DECL)) 190 && (!DECL_ARTIFICIAL (decl) || TREE_CODE (decl) == PARM_DECL))
59 return true; 191 return true;
60 192
193 if (TREE_CODE (type) == POINTER_TYPE
194 && gfc_omp_is_optional_argument (decl))
195 return true;
196
61 if (TREE_CODE (type) == POINTER_TYPE) 197 if (TREE_CODE (type) == POINTER_TYPE)
62 { 198 {
199 while (TREE_CODE (decl) == COMPONENT_REF)
200 decl = TREE_OPERAND (decl, 1);
201
63 /* Array POINTER/ALLOCATABLE have aggregate types, all user variables 202 /* Array POINTER/ALLOCATABLE have aggregate types, all user variables
64 that have POINTER_TYPE type and aren't scalar pointers, scalar 203 that have POINTER_TYPE type and aren't scalar pointers, scalar
65 allocatables, Cray pointees or C pointers are supposed to be 204 allocatables, Cray pointees or C pointers are supposed to be
66 privatized by reference. */ 205 privatized by reference. */
67 if (GFC_DECL_GET_SCALAR_POINTER (decl) 206 if (GFC_DECL_GET_SCALAR_POINTER (decl)
147 /* These are either array or derived parameters, or vtables. 286 /* These are either array or derived parameters, or vtables.
148 In the former cases, the OpenMP standard doesn't consider them to be 287 In the former cases, the OpenMP standard doesn't consider them to be
149 variables at all (they can't be redefined), but they can nevertheless appear 288 variables at all (they can't be redefined), but they can nevertheless appear
150 in parallel/task regions and for default(none) purposes treat them as shared. 289 in parallel/task regions and for default(none) purposes treat them as shared.
151 For vtables likely the same handling is desirable. */ 290 For vtables likely the same handling is desirable. */
152 if (VAR_P (decl) && TREE_READONLY (decl) && TREE_STATIC (decl)) 291 if (VAR_P (decl) && TREE_READONLY (decl)
292 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
153 return OMP_CLAUSE_DEFAULT_SHARED; 293 return OMP_CLAUSE_DEFAULT_SHARED;
154 294
155 return OMP_CLAUSE_DEFAULT_UNSPECIFIED; 295 return OMP_CLAUSE_DEFAULT_UNSPECIFIED;
156 } 296 }
157 297
294 gfc_array_index_type, tem, 434 gfc_array_index_type, tem,
295 gfc_index_one_node); 435 gfc_index_one_node);
296 } 436 }
297 else 437 else
298 { 438 {
439 bool compute_nelts = false;
299 if (!TYPE_DOMAIN (type) 440 if (!TYPE_DOMAIN (type)
300 || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE 441 || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE
301 || TYPE_MIN_VALUE (TYPE_DOMAIN (type)) == error_mark_node 442 || TYPE_MIN_VALUE (TYPE_DOMAIN (type)) == error_mark_node
302 || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == error_mark_node) 443 || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == error_mark_node)
444 compute_nelts = true;
445 else if (VAR_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
446 {
447 tree a = DECL_ATTRIBUTES (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
448 if (lookup_attribute ("omp dummy var", a))
449 compute_nelts = true;
450 }
451 if (compute_nelts)
303 { 452 {
304 tem = fold_build2 (EXACT_DIV_EXPR, sizetype, 453 tem = fold_build2 (EXACT_DIV_EXPR, sizetype,
305 TYPE_SIZE_UNIT (type), 454 TYPE_SIZE_UNIT (type),
306 TYPE_SIZE_UNIT (TREE_TYPE (type))); 455 TYPE_SIZE_UNIT (TREE_TYPE (type)));
307 tem = size_binop (MINUS_EXPR, tem, size_one_node); 456 tem = size_binop (MINUS_EXPR, tem, size_one_node);
458 || OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_LINEAR 607 || OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_LINEAR
459 || OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_REDUCTION); 608 || OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_REDUCTION);
460 609
461 if ((! GFC_DESCRIPTOR_TYPE_P (type) 610 if ((! GFC_DESCRIPTOR_TYPE_P (type)
462 || GFC_TYPE_ARRAY_AKIND (type) != GFC_ARRAY_ALLOCATABLE) 611 || GFC_TYPE_ARRAY_AKIND (type) != GFC_ARRAY_ALLOCATABLE)
463 && !GFC_DECL_GET_SCALAR_ALLOCATABLE (OMP_CLAUSE_DECL (clause))) 612 && (!GFC_DECL_GET_SCALAR_ALLOCATABLE (OMP_CLAUSE_DECL (clause))
613 || !POINTER_TYPE_P (type)))
464 { 614 {
465 if (gfc_has_alloc_comps (type, OMP_CLAUSE_DECL (clause))) 615 if (gfc_has_alloc_comps (type, OMP_CLAUSE_DECL (clause)))
466 { 616 {
467 gcc_assert (outer); 617 gcc_assert (outer);
468 gfc_start_block (&block); 618 gfc_start_block (&block);
544 tem, null_pointer_node); 694 tem, null_pointer_node);
545 gfc_add_expr_to_block (&block, 695 gfc_add_expr_to_block (&block,
546 build3_loc (input_location, COND_EXPR, 696 build3_loc (input_location, COND_EXPR,
547 void_type_node, cond, then_b, 697 void_type_node, cond, then_b,
548 else_b)); 698 else_b));
699 /* Avoid -W*uninitialized warnings. */
700 if (DECL_P (decl))
701 TREE_NO_WARNING (decl) = 1;
549 } 702 }
550 else 703 else
551 gfc_add_expr_to_block (&block, then_b); 704 gfc_add_expr_to_block (&block, then_b);
552 705
553 return gfc_finish_block (&block); 706 return gfc_finish_block (&block);
565 gcc_assert (OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_FIRSTPRIVATE 718 gcc_assert (OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_FIRSTPRIVATE
566 || OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_LINEAR); 719 || OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_LINEAR);
567 720
568 if ((! GFC_DESCRIPTOR_TYPE_P (type) 721 if ((! GFC_DESCRIPTOR_TYPE_P (type)
569 || GFC_TYPE_ARRAY_AKIND (type) != GFC_ARRAY_ALLOCATABLE) 722 || GFC_TYPE_ARRAY_AKIND (type) != GFC_ARRAY_ALLOCATABLE)
570 && !GFC_DECL_GET_SCALAR_ALLOCATABLE (OMP_CLAUSE_DECL (clause))) 723 && (!GFC_DECL_GET_SCALAR_ALLOCATABLE (OMP_CLAUSE_DECL (clause))
724 || !POINTER_TYPE_P (type)))
571 { 725 {
572 if (gfc_has_alloc_comps (type, OMP_CLAUSE_DECL (clause))) 726 if (gfc_has_alloc_comps (type, OMP_CLAUSE_DECL (clause)))
573 { 727 {
574 gfc_start_block (&block); 728 gfc_start_block (&block);
575 gfc_add_modify (&block, dest, src); 729 gfc_add_modify (&block, dest, src);
649 cond = fold_build2_loc (input_location, NE_EXPR, logical_type_node, 803 cond = fold_build2_loc (input_location, NE_EXPR, logical_type_node,
650 unshare_expr (srcptr), null_pointer_node); 804 unshare_expr (srcptr), null_pointer_node);
651 gfc_add_expr_to_block (&block, 805 gfc_add_expr_to_block (&block,
652 build3_loc (input_location, COND_EXPR, 806 build3_loc (input_location, COND_EXPR,
653 void_type_node, cond, then_b, else_b)); 807 void_type_node, cond, then_b, else_b));
808 /* Avoid -W*uninitialized warnings. */
809 if (DECL_P (dest))
810 TREE_NO_WARNING (dest) = 1;
654 811
655 return gfc_finish_block (&block); 812 return gfc_finish_block (&block);
656 } 813 }
657 814
658 /* Similarly, except use an intrinsic or pointer assignment operator 815 /* Similarly, except use an intrinsic or pointer assignment operator
665 tree cond, then_b, else_b; 822 tree cond, then_b, else_b;
666 stmtblock_t block, cond_block, cond_block2, inner_block; 823 stmtblock_t block, cond_block, cond_block2, inner_block;
667 824
668 if ((! GFC_DESCRIPTOR_TYPE_P (type) 825 if ((! GFC_DESCRIPTOR_TYPE_P (type)
669 || GFC_TYPE_ARRAY_AKIND (type) != GFC_ARRAY_ALLOCATABLE) 826 || GFC_TYPE_ARRAY_AKIND (type) != GFC_ARRAY_ALLOCATABLE)
670 && !GFC_DECL_GET_SCALAR_ALLOCATABLE (OMP_CLAUSE_DECL (clause))) 827 && (!GFC_DECL_GET_SCALAR_ALLOCATABLE (OMP_CLAUSE_DECL (clause))
828 || !POINTER_TYPE_P (type)))
671 { 829 {
672 if (gfc_has_alloc_comps (type, OMP_CLAUSE_DECL (clause))) 830 if (gfc_has_alloc_comps (type, OMP_CLAUSE_DECL (clause)))
673 { 831 {
674 gfc_start_block (&block); 832 gfc_start_block (&block);
675 /* First dealloc any allocatable components in DEST. */ 833 /* First dealloc any allocatable components in DEST. */
903 gfc_start_block (&block); 1061 gfc_start_block (&block);
904 add = gfc_evaluate_now (add, &block); 1062 add = gfc_evaluate_now (add, &block);
905 1063
906 if ((! GFC_DESCRIPTOR_TYPE_P (type) 1064 if ((! GFC_DESCRIPTOR_TYPE_P (type)
907 || GFC_TYPE_ARRAY_AKIND (type) != GFC_ARRAY_ALLOCATABLE) 1065 || GFC_TYPE_ARRAY_AKIND (type) != GFC_ARRAY_ALLOCATABLE)
908 && !GFC_DECL_GET_SCALAR_ALLOCATABLE (OMP_CLAUSE_DECL (clause))) 1066 && (!GFC_DECL_GET_SCALAR_ALLOCATABLE (OMP_CLAUSE_DECL (clause))
909 { 1067 || !POINTER_TYPE_P (type)))
1068 {
1069 bool compute_nelts = false;
910 gcc_assert (TREE_CODE (type) == ARRAY_TYPE); 1070 gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
911 if (!TYPE_DOMAIN (type) 1071 if (!TYPE_DOMAIN (type)
912 || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE 1072 || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE
913 || TYPE_MIN_VALUE (TYPE_DOMAIN (type)) == error_mark_node 1073 || TYPE_MIN_VALUE (TYPE_DOMAIN (type)) == error_mark_node
914 || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == error_mark_node) 1074 || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == error_mark_node)
1075 compute_nelts = true;
1076 else if (VAR_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
1077 {
1078 tree a = DECL_ATTRIBUTES (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
1079 if (lookup_attribute ("omp dummy var", a))
1080 compute_nelts = true;
1081 }
1082 if (compute_nelts)
915 { 1083 {
916 nelems = fold_build2 (EXACT_DIV_EXPR, sizetype, 1084 nelems = fold_build2 (EXACT_DIV_EXPR, sizetype,
917 TYPE_SIZE_UNIT (type), 1085 TYPE_SIZE_UNIT (type),
918 TYPE_SIZE_UNIT (TREE_TYPE (type))); 1086 TYPE_SIZE_UNIT (TREE_TYPE (type)));
919 nelems = size_binop (MINUS_EXPR, nelems, size_one_node); 1087 nelems = size_binop (MINUS_EXPR, nelems, size_one_node);
987 { 1155 {
988 tree type = TREE_TYPE (decl), tem; 1156 tree type = TREE_TYPE (decl), tem;
989 1157
990 if ((! GFC_DESCRIPTOR_TYPE_P (type) 1158 if ((! GFC_DESCRIPTOR_TYPE_P (type)
991 || GFC_TYPE_ARRAY_AKIND (type) != GFC_ARRAY_ALLOCATABLE) 1159 || GFC_TYPE_ARRAY_AKIND (type) != GFC_ARRAY_ALLOCATABLE)
992 && !GFC_DECL_GET_SCALAR_ALLOCATABLE (OMP_CLAUSE_DECL (clause))) 1160 && (!GFC_DECL_GET_SCALAR_ALLOCATABLE (OMP_CLAUSE_DECL (clause))
1161 || !POINTER_TYPE_P (type)))
993 { 1162 {
994 if (gfc_has_alloc_comps (type, OMP_CLAUSE_DECL (clause))) 1163 if (gfc_has_alloc_comps (type, OMP_CLAUSE_DECL (clause)))
995 return gfc_walk_alloc_comps (decl, NULL_TREE, 1164 return gfc_walk_alloc_comps (decl, NULL_TREE,
996 OMP_CLAUSE_DECL (clause), 1165 OMP_CLAUSE_DECL (clause),
997 WALK_ALLOC_COMPS_DTOR); 1166 WALK_ALLOC_COMPS_DTOR);
1034 then_b, build_empty_stmt (input_location)); 1203 then_b, build_empty_stmt (input_location));
1035 } 1204 }
1036 return tem; 1205 return tem;
1037 } 1206 }
1038 1207
1208 /* Build a conditional expression in BLOCK. If COND_VAL is not
1209 null, then the block THEN_B is executed, otherwise ELSE_VAL
1210 is assigned to VAL. */
1211
1212 static void
1213 gfc_build_cond_assign (stmtblock_t *block, tree val, tree cond_val,
1214 tree then_b, tree else_val)
1215 {
1216 stmtblock_t cond_block;
1217 tree else_b = NULL_TREE;
1218 tree val_ty = TREE_TYPE (val);
1219
1220 if (else_val)
1221 {
1222 gfc_init_block (&cond_block);
1223 gfc_add_modify (&cond_block, val, fold_convert (val_ty, else_val));
1224 else_b = gfc_finish_block (&cond_block);
1225 }
1226 gfc_add_expr_to_block (block,
1227 build3_loc (input_location, COND_EXPR, void_type_node,
1228 cond_val, then_b, else_b));
1229 }
1230
1231 /* Build a conditional expression in BLOCK, returning a temporary
1232 variable containing the result. If COND_VAL is not null, then
1233 THEN_VAL will be assigned to the variable, otherwise ELSE_VAL
1234 is assigned.
1235 */
1236
1237 static tree
1238 gfc_build_cond_assign_expr (stmtblock_t *block, tree cond_val,
1239 tree then_val, tree else_val)
1240 {
1241 tree val;
1242 tree val_ty = TREE_TYPE (then_val);
1243 stmtblock_t cond_block;
1244
1245 val = create_tmp_var (val_ty);
1246
1247 gfc_init_block (&cond_block);
1248 gfc_add_modify (&cond_block, val, then_val);
1249 tree then_b = gfc_finish_block (&cond_block);
1250
1251 gfc_build_cond_assign (block, val, cond_val, then_b, else_val);
1252
1253 return val;
1254 }
1039 1255
1040 void 1256 void
1041 gfc_omp_finish_clause (tree c, gimple_seq *pre_p) 1257 gfc_omp_finish_clause (tree c, gimple_seq *pre_p)
1042 { 1258 {
1043 if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP) 1259 if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
1058 "implicit mapping of assumed size array %qD", decl); 1274 "implicit mapping of assumed size array %qD", decl);
1059 return; 1275 return;
1060 } 1276 }
1061 1277
1062 tree c2 = NULL_TREE, c3 = NULL_TREE, c4 = NULL_TREE; 1278 tree c2 = NULL_TREE, c3 = NULL_TREE, c4 = NULL_TREE;
1279 tree present = gfc_omp_check_optional_argument (decl, true);
1063 if (POINTER_TYPE_P (TREE_TYPE (decl))) 1280 if (POINTER_TYPE_P (TREE_TYPE (decl)))
1064 { 1281 {
1065 if (!gfc_omp_privatize_by_reference (decl) 1282 if (!gfc_omp_privatize_by_reference (decl)
1066 && !GFC_DECL_GET_SCALAR_POINTER (decl) 1283 && !GFC_DECL_GET_SCALAR_POINTER (decl)
1067 && !GFC_DECL_GET_SCALAR_ALLOCATABLE (decl) 1284 && !GFC_DECL_GET_SCALAR_ALLOCATABLE (decl)
1068 && !GFC_DECL_CRAY_POINTEE (decl) 1285 && !GFC_DECL_CRAY_POINTEE (decl)
1069 && !GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (TREE_TYPE (decl)))) 1286 && !GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (TREE_TYPE (decl))))
1070 return; 1287 return;
1071 tree orig_decl = decl; 1288 tree orig_decl = decl;
1289
1290 /* For nonallocatable, nonpointer arrays, a temporary variable is
1291 generated, but this one is only defined if the variable is present;
1292 hence, we now set it to NULL to avoid accessing undefined variables.
1293 We cannot use a temporary variable here as otherwise the replacement
1294 of the variables in omp-low.c will not work. */
1295 if (present && GFC_ARRAY_TYPE_P (TREE_TYPE (decl)))
1296 {
1297 tree tmp = fold_build2_loc (input_location, MODIFY_EXPR,
1298 void_type_node, decl, null_pointer_node);
1299 tree cond = fold_build1_loc (input_location, TRUTH_NOT_EXPR,
1300 boolean_type_node, present);
1301 tmp = build3_loc (input_location, COND_EXPR, void_type_node,
1302 cond, tmp, NULL_TREE);
1303 gimplify_and_add (tmp, pre_p);
1304 }
1305
1072 c4 = build_omp_clause (OMP_CLAUSE_LOCATION (c), OMP_CLAUSE_MAP); 1306 c4 = build_omp_clause (OMP_CLAUSE_LOCATION (c), OMP_CLAUSE_MAP);
1073 OMP_CLAUSE_SET_MAP_KIND (c4, GOMP_MAP_POINTER); 1307 OMP_CLAUSE_SET_MAP_KIND (c4, GOMP_MAP_POINTER);
1074 OMP_CLAUSE_DECL (c4) = decl; 1308 OMP_CLAUSE_DECL (c4) = decl;
1075 OMP_CLAUSE_SIZE (c4) = size_int (0); 1309 OMP_CLAUSE_SIZE (c4) = size_int (0);
1076 decl = build_fold_indirect_ref (decl); 1310 decl = build_fold_indirect_ref (decl);
1077 OMP_CLAUSE_DECL (c) = decl; 1311 if (present
1078 OMP_CLAUSE_SIZE (c) = NULL_TREE; 1312 && (GFC_DECL_GET_SCALAR_POINTER (orig_decl)
1313 || GFC_DECL_GET_SCALAR_ALLOCATABLE (orig_decl)))
1314 {
1315 c2 = build_omp_clause (input_location, OMP_CLAUSE_MAP);
1316 OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_POINTER);
1317 OMP_CLAUSE_DECL (c2) = decl;
1318 OMP_CLAUSE_SIZE (c2) = size_int (0);
1319
1320 stmtblock_t block;
1321 gfc_start_block (&block);
1322 tree ptr = decl;
1323 ptr = gfc_build_cond_assign_expr (&block, present, decl,
1324 null_pointer_node);
1325 gimplify_and_add (gfc_finish_block (&block), pre_p);
1326 ptr = build_fold_indirect_ref (ptr);
1327 OMP_CLAUSE_DECL (c) = ptr;
1328 OMP_CLAUSE_SIZE (c) = TYPE_SIZE_UNIT (TREE_TYPE (ptr));
1329 }
1330 else
1331 {
1332 OMP_CLAUSE_DECL (c) = decl;
1333 OMP_CLAUSE_SIZE (c) = NULL_TREE;
1334 }
1079 if (TREE_CODE (TREE_TYPE (orig_decl)) == REFERENCE_TYPE 1335 if (TREE_CODE (TREE_TYPE (orig_decl)) == REFERENCE_TYPE
1080 && (GFC_DECL_GET_SCALAR_POINTER (orig_decl) 1336 && (GFC_DECL_GET_SCALAR_POINTER (orig_decl)
1081 || GFC_DECL_GET_SCALAR_ALLOCATABLE (orig_decl))) 1337 || GFC_DECL_GET_SCALAR_ALLOCATABLE (orig_decl)))
1082 { 1338 {
1083 c3 = build_omp_clause (OMP_CLAUSE_LOCATION (c), OMP_CLAUSE_MAP); 1339 c3 = build_omp_clause (OMP_CLAUSE_LOCATION (c), OMP_CLAUSE_MAP);
1092 { 1348 {
1093 stmtblock_t block; 1349 stmtblock_t block;
1094 gfc_start_block (&block); 1350 gfc_start_block (&block);
1095 tree type = TREE_TYPE (decl); 1351 tree type = TREE_TYPE (decl);
1096 tree ptr = gfc_conv_descriptor_data_get (decl); 1352 tree ptr = gfc_conv_descriptor_data_get (decl);
1353
1354 if (present)
1355 ptr = gfc_build_cond_assign_expr (&block, present, ptr,
1356 null_pointer_node);
1097 ptr = fold_convert (build_pointer_type (char_type_node), ptr); 1357 ptr = fold_convert (build_pointer_type (char_type_node), ptr);
1098 ptr = build_fold_indirect_ref (ptr); 1358 ptr = build_fold_indirect_ref (ptr);
1099 OMP_CLAUSE_DECL (c) = ptr; 1359 OMP_CLAUSE_DECL (c) = ptr;
1100 c2 = build_omp_clause (input_location, OMP_CLAUSE_MAP); 1360 c2 = build_omp_clause (input_location, OMP_CLAUSE_MAP);
1101 OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_TO_PSET); 1361 OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_TO_PSET);
1102 OMP_CLAUSE_DECL (c2) = decl; 1362 if (present)
1363 {
1364 ptr = create_tmp_var (TREE_TYPE (TREE_OPERAND (decl, 0)));
1365 gfc_add_modify (&block, ptr, TREE_OPERAND (decl, 0));
1366
1367 OMP_CLAUSE_DECL (c2) = build_fold_indirect_ref (ptr);
1368 }
1369 else
1370 OMP_CLAUSE_DECL (c2) = decl;
1103 OMP_CLAUSE_SIZE (c2) = TYPE_SIZE_UNIT (type); 1371 OMP_CLAUSE_SIZE (c2) = TYPE_SIZE_UNIT (type);
1104 c3 = build_omp_clause (OMP_CLAUSE_LOCATION (c), OMP_CLAUSE_MAP); 1372 c3 = build_omp_clause (OMP_CLAUSE_LOCATION (c), OMP_CLAUSE_MAP);
1105 OMP_CLAUSE_SET_MAP_KIND (c3, GOMP_MAP_POINTER); 1373 OMP_CLAUSE_SET_MAP_KIND (c3, GOMP_MAP_POINTER);
1106 OMP_CLAUSE_DECL (c3) = gfc_conv_descriptor_data_get (decl); 1374 if (present)
1375 {
1376 ptr = gfc_conv_descriptor_data_get (decl);
1377 ptr = gfc_build_addr_expr (NULL, ptr);
1378 ptr = gfc_build_cond_assign_expr (&block, present,
1379 ptr, null_pointer_node);
1380 ptr = build_fold_indirect_ref (ptr);
1381 OMP_CLAUSE_DECL (c3) = ptr;
1382 }
1383 else
1384 OMP_CLAUSE_DECL (c3) = gfc_conv_descriptor_data_get (decl);
1107 OMP_CLAUSE_SIZE (c3) = size_int (0); 1385 OMP_CLAUSE_SIZE (c3) = size_int (0);
1108 tree size = create_tmp_var (gfc_array_index_type); 1386 tree size = create_tmp_var (gfc_array_index_type);
1109 tree elemsz = TYPE_SIZE_UNIT (gfc_get_element_type (type)); 1387 tree elemsz = TYPE_SIZE_UNIT (gfc_get_element_type (type));
1110 elemsz = fold_convert (gfc_array_index_type, elemsz); 1388 elemsz = fold_convert (gfc_array_index_type, elemsz);
1111 if (GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_POINTER 1389 if (GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_POINTER
1127 gfc_add_modify (&cond_block, size, zero); 1405 gfc_add_modify (&cond_block, size, zero);
1128 else_b = gfc_finish_block (&cond_block); 1406 else_b = gfc_finish_block (&cond_block);
1129 tem = gfc_conv_descriptor_data_get (decl); 1407 tem = gfc_conv_descriptor_data_get (decl);
1130 tem = fold_convert (pvoid_type_node, tem); 1408 tem = fold_convert (pvoid_type_node, tem);
1131 cond = fold_build2_loc (input_location, NE_EXPR, 1409 cond = fold_build2_loc (input_location, NE_EXPR,
1132 logical_type_node, tem, null_pointer_node); 1410 boolean_type_node, tem, null_pointer_node);
1411 if (present)
1412 {
1413 cond = fold_build2_loc (input_location, TRUTH_ANDIF_EXPR,
1414 boolean_type_node, present, cond);
1415 }
1133 gfc_add_expr_to_block (&block, build3_loc (input_location, COND_EXPR, 1416 gfc_add_expr_to_block (&block, build3_loc (input_location, COND_EXPR,
1134 void_type_node, cond, 1417 void_type_node, cond,
1135 then_b, else_b)); 1418 then_b, else_b));
1419 }
1420 else if (present)
1421 {
1422 stmtblock_t cond_block;
1423 tree then_b;
1424
1425 gfc_init_block (&cond_block);
1426 gfc_add_modify (&cond_block, size,
1427 gfc_full_array_size (&cond_block, decl,
1428 GFC_TYPE_ARRAY_RANK (type)));
1429 gfc_add_modify (&cond_block, size,
1430 fold_build2 (MULT_EXPR, gfc_array_index_type,
1431 size, elemsz));
1432 then_b = gfc_finish_block (&cond_block);
1433
1434 gfc_build_cond_assign (&block, size, present, then_b,
1435 build_int_cst (gfc_array_index_type, 0));
1136 } 1436 }
1137 else 1437 else
1138 { 1438 {
1139 gfc_add_modify (&block, size, 1439 gfc_add_modify (&block, size,
1140 gfc_full_array_size (&block, decl, 1440 gfc_full_array_size (&block, decl,
1166 } 1466 }
1167 if (c4) 1467 if (c4)
1168 { 1468 {
1169 OMP_CLAUSE_CHAIN (c4) = OMP_CLAUSE_CHAIN (last); 1469 OMP_CLAUSE_CHAIN (c4) = OMP_CLAUSE_CHAIN (last);
1170 OMP_CLAUSE_CHAIN (last) = c4; 1470 OMP_CLAUSE_CHAIN (last) = c4;
1171 last = c4;
1172 } 1471 }
1173 } 1472 }
1174 1473
1175 1474
1176 /* Return true if DECL is a scalar variable (for the purpose of 1475 /* Return true if DECL is a scalar variable (for the purpose of
1189 type = TREE_TYPE (type); 1488 type = TREE_TYPE (type);
1190 if (GFC_ARRAY_TYPE_P (type) 1489 if (GFC_ARRAY_TYPE_P (type)
1191 || GFC_CLASS_TYPE_P (type)) 1490 || GFC_CLASS_TYPE_P (type))
1192 return false; 1491 return false;
1193 } 1492 }
1194 if (TYPE_STRING_FLAG (type)) 1493 if ((TREE_CODE (type) == ARRAY_TYPE || TREE_CODE (type) == INTEGER_TYPE)
1494 && TYPE_STRING_FLAG (type))
1195 return false; 1495 return false;
1196 if (INTEGRAL_TYPE_P (type) 1496 if (INTEGRAL_TYPE_P (type)
1197 || SCALAR_FLOAT_TYPE_P (type) 1497 || SCALAR_FLOAT_TYPE_P (type)
1198 || COMPLEX_FLOAT_TYPE_P (type)) 1498 || COMPLEX_FLOAT_TYPE_P (type))
1199 return true; 1499 return true;
1713 if (namelist->sym->attr.referenced) 2013 if (namelist->sym->attr.referenced)
1714 { 2014 {
1715 tree t = gfc_trans_omp_variable (namelist->sym, false); 2015 tree t = gfc_trans_omp_variable (namelist->sym, false);
1716 if (t != error_mark_node) 2016 if (t != error_mark_node)
1717 { 2017 {
1718 tree node = build_omp_clause (where.lb->location, 2018 tree node = build_omp_clause (gfc_get_location (&namelist->where),
1719 OMP_CLAUSE_REDUCTION); 2019 OMP_CLAUSE_REDUCTION);
1720 OMP_CLAUSE_DECL (node) = t; 2020 OMP_CLAUSE_DECL (node) = t;
1721 if (mark_addressable) 2021 if (mark_addressable)
1722 TREE_ADDRESSABLE (t) = 1; 2022 TREE_ADDRESSABLE (t) = 1;
1723 switch (namelist->u.reduction_op) 2023 switch (namelist->u.reduction_op)
1789 return result; 2089 return result;
1790 } 2090 }
1791 2091
1792 static vec<tree, va_heap, vl_embed> *doacross_steps; 2092 static vec<tree, va_heap, vl_embed> *doacross_steps;
1793 2093
2094
2095 /* Translate an array section or array element. */
2096
2097 static void
2098 gfc_trans_omp_array_section (stmtblock_t *block, gfc_omp_namelist *n,
2099 tree decl, bool element, gomp_map_kind ptr_kind,
2100 tree node, tree &node2, tree &node3, tree &node4)
2101 {
2102 gfc_se se;
2103 tree ptr, ptr2;
2104
2105 gfc_init_se (&se, NULL);
2106
2107 if (element)
2108 {
2109 gfc_conv_expr_reference (&se, n->expr);
2110 gfc_add_block_to_block (block, &se.pre);
2111 ptr = se.expr;
2112 OMP_CLAUSE_SIZE (node) = TYPE_SIZE_UNIT (TREE_TYPE (ptr));
2113 }
2114 else
2115 {
2116 gfc_conv_expr_descriptor (&se, n->expr);
2117 ptr = gfc_conv_array_data (se.expr);
2118 tree type = TREE_TYPE (se.expr);
2119 gfc_add_block_to_block (block, &se.pre);
2120 OMP_CLAUSE_SIZE (node) = gfc_full_array_size (block, se.expr,
2121 GFC_TYPE_ARRAY_RANK (type));
2122 tree elemsz = TYPE_SIZE_UNIT (gfc_get_element_type (type));
2123 elemsz = fold_convert (gfc_array_index_type, elemsz);
2124 OMP_CLAUSE_SIZE (node) = fold_build2 (MULT_EXPR, gfc_array_index_type,
2125 OMP_CLAUSE_SIZE (node), elemsz);
2126 }
2127 gfc_add_block_to_block (block, &se.post);
2128 ptr = fold_convert (build_pointer_type (char_type_node), ptr);
2129 OMP_CLAUSE_DECL (node) = build_fold_indirect_ref (ptr);
2130
2131 if (POINTER_TYPE_P (TREE_TYPE (decl))
2132 && GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (TREE_TYPE (decl)))
2133 && ptr_kind == GOMP_MAP_POINTER)
2134 {
2135 node4 = build_omp_clause (input_location,
2136 OMP_CLAUSE_MAP);
2137 OMP_CLAUSE_SET_MAP_KIND (node4, GOMP_MAP_POINTER);
2138 OMP_CLAUSE_DECL (node4) = decl;
2139 OMP_CLAUSE_SIZE (node4) = size_int (0);
2140 decl = build_fold_indirect_ref (decl);
2141 }
2142 ptr = fold_convert (sizetype, ptr);
2143 if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl)))
2144 {
2145 tree type = TREE_TYPE (decl);
2146 ptr2 = gfc_conv_descriptor_data_get (decl);
2147 node2 = build_omp_clause (input_location,
2148 OMP_CLAUSE_MAP);
2149 OMP_CLAUSE_SET_MAP_KIND (node2, GOMP_MAP_TO_PSET);
2150 OMP_CLAUSE_DECL (node2) = decl;
2151 OMP_CLAUSE_SIZE (node2) = TYPE_SIZE_UNIT (type);
2152 node3 = build_omp_clause (input_location,
2153 OMP_CLAUSE_MAP);
2154 OMP_CLAUSE_SET_MAP_KIND (node3, ptr_kind);
2155 OMP_CLAUSE_DECL (node3)
2156 = gfc_conv_descriptor_data_get (decl);
2157 if (ptr_kind == GOMP_MAP_ATTACH_DETACH)
2158 STRIP_NOPS (OMP_CLAUSE_DECL (node3));
2159 }
2160 else
2161 {
2162 if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
2163 ptr2 = build_fold_addr_expr (decl);
2164 else
2165 {
2166 gcc_assert (POINTER_TYPE_P (TREE_TYPE (decl)));
2167 ptr2 = decl;
2168 }
2169 node3 = build_omp_clause (input_location,
2170 OMP_CLAUSE_MAP);
2171 OMP_CLAUSE_SET_MAP_KIND (node3, ptr_kind);
2172 OMP_CLAUSE_DECL (node3) = decl;
2173 }
2174 ptr2 = fold_convert (sizetype, ptr2);
2175 OMP_CLAUSE_SIZE (node3)
2176 = fold_build2 (MINUS_EXPR, sizetype, ptr, ptr2);
2177 }
2178
1794 static tree 2179 static tree
1795 gfc_trans_omp_clauses (stmtblock_t *block, gfc_omp_clauses *clauses, 2180 gfc_trans_omp_clauses (stmtblock_t *block, gfc_omp_clauses *clauses,
1796 locus where, bool declare_simd = false) 2181 locus where, bool declare_simd = false)
1797 { 2182 {
1798 tree omp_clauses = NULL_TREE, chunk_size, c; 2183 tree omp_clauses = NULL_TREE, chunk_size, c;
1839 clause_code = OMP_CLAUSE_UNIFORM; 2224 clause_code = OMP_CLAUSE_UNIFORM;
1840 goto add_clause; 2225 goto add_clause;
1841 case OMP_LIST_USE_DEVICE: 2226 case OMP_LIST_USE_DEVICE:
1842 case OMP_LIST_USE_DEVICE_PTR: 2227 case OMP_LIST_USE_DEVICE_PTR:
1843 clause_code = OMP_CLAUSE_USE_DEVICE_PTR; 2228 clause_code = OMP_CLAUSE_USE_DEVICE_PTR;
2229 goto add_clause;
2230 case OMP_LIST_USE_DEVICE_ADDR:
2231 clause_code = OMP_CLAUSE_USE_DEVICE_ADDR;
1844 goto add_clause; 2232 goto add_clause;
1845 case OMP_LIST_IS_DEVICE_PTR: 2233 case OMP_LIST_IS_DEVICE_PTR:
1846 clause_code = OMP_CLAUSE_IS_DEVICE_PTR; 2234 clause_code = OMP_CLAUSE_IS_DEVICE_PTR;
1847 goto add_clause; 2235 goto add_clause;
1848 2236
2042 continue; 2430 continue;
2043 2431
2044 tree node = build_omp_clause (input_location, OMP_CLAUSE_DEPEND); 2432 tree node = build_omp_clause (input_location, OMP_CLAUSE_DEPEND);
2045 if (n->expr == NULL || n->expr->ref->u.ar.type == AR_FULL) 2433 if (n->expr == NULL || n->expr->ref->u.ar.type == AR_FULL)
2046 { 2434 {
2047 tree decl = gfc_get_symbol_decl (n->sym); 2435 tree decl = gfc_trans_omp_variable (n->sym, false);
2048 if (gfc_omp_privatize_by_reference (decl)) 2436 if (gfc_omp_privatize_by_reference (decl))
2049 decl = build_fold_indirect_ref (decl); 2437 decl = build_fold_indirect_ref (decl);
2050 if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl))) 2438 if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl)))
2051 { 2439 {
2052 decl = gfc_conv_descriptor_data_get (decl); 2440 decl = gfc_conv_descriptor_data_get (decl);
2103 2491
2104 tree node = build_omp_clause (input_location, OMP_CLAUSE_MAP); 2492 tree node = build_omp_clause (input_location, OMP_CLAUSE_MAP);
2105 tree node2 = NULL_TREE; 2493 tree node2 = NULL_TREE;
2106 tree node3 = NULL_TREE; 2494 tree node3 = NULL_TREE;
2107 tree node4 = NULL_TREE; 2495 tree node4 = NULL_TREE;
2108 tree decl = gfc_get_symbol_decl (n->sym); 2496 tree decl = gfc_trans_omp_variable (n->sym, false);
2109 if (DECL_P (decl)) 2497 if (DECL_P (decl))
2110 TREE_ADDRESSABLE (decl) = 1; 2498 TREE_ADDRESSABLE (decl) = 1;
2111 if (n->expr == NULL || n->expr->ref->u.ar.type == AR_FULL) 2499 if (n->expr == NULL
2500 || (n->expr->ref->type == REF_ARRAY
2501 && n->expr->ref->u.ar.type == AR_FULL))
2112 { 2502 {
2113 if (POINTER_TYPE_P (TREE_TYPE (decl)) 2503 tree present = gfc_omp_check_optional_argument (decl, true);
2114 && (gfc_omp_privatize_by_reference (decl) 2504 if (n->sym->ts.type == BT_CLASS)
2115 || GFC_DECL_GET_SCALAR_POINTER (decl) 2505 {
2116 || GFC_DECL_GET_SCALAR_ALLOCATABLE (decl) 2506 tree type = TREE_TYPE (decl);
2117 || GFC_DECL_CRAY_POINTEE (decl) 2507 if (n->sym->attr.optional)
2118 || GFC_DESCRIPTOR_TYPE_P 2508 sorry ("optional class parameter");
2119 (TREE_TYPE (TREE_TYPE (decl))))) 2509 if (POINTER_TYPE_P (type))
2510 {
2511 node4 = build_omp_clause (input_location,
2512 OMP_CLAUSE_MAP);
2513 OMP_CLAUSE_SET_MAP_KIND (node4, GOMP_MAP_POINTER);
2514 OMP_CLAUSE_DECL (node4) = decl;
2515 OMP_CLAUSE_SIZE (node4) = size_int (0);
2516 decl = build_fold_indirect_ref (decl);
2517 }
2518 tree ptr = gfc_class_data_get (decl);
2519 ptr = build_fold_indirect_ref (ptr);
2520 OMP_CLAUSE_DECL (node) = ptr;
2521 OMP_CLAUSE_SIZE (node) = gfc_class_vtab_size_get (decl);
2522 node2 = build_omp_clause (input_location, OMP_CLAUSE_MAP);
2523 OMP_CLAUSE_SET_MAP_KIND (node2, GOMP_MAP_TO_PSET);
2524 OMP_CLAUSE_DECL (node2) = decl;
2525 OMP_CLAUSE_SIZE (node2) = TYPE_SIZE_UNIT (type);
2526 node3 = build_omp_clause (input_location, OMP_CLAUSE_MAP);
2527 OMP_CLAUSE_SET_MAP_KIND (node3, GOMP_MAP_ATTACH_DETACH);
2528 OMP_CLAUSE_DECL (node3) = gfc_class_data_get (decl);
2529 OMP_CLAUSE_SIZE (node3) = size_int (0);
2530 goto finalize_map_clause;
2531 }
2532 else if (POINTER_TYPE_P (TREE_TYPE (decl))
2533 && (gfc_omp_privatize_by_reference (decl)
2534 || GFC_DECL_GET_SCALAR_POINTER (decl)
2535 || GFC_DECL_GET_SCALAR_ALLOCATABLE (decl)
2536 || GFC_DECL_CRAY_POINTEE (decl)
2537 || GFC_DESCRIPTOR_TYPE_P
2538 (TREE_TYPE (TREE_TYPE (decl)))
2539 || n->sym->ts.type == BT_DERIVED))
2120 { 2540 {
2121 tree orig_decl = decl; 2541 tree orig_decl = decl;
2542
2543 /* For nonallocatable, nonpointer arrays, a temporary
2544 variable is generated, but this one is only defined if
2545 the variable is present; hence, we now set it to NULL
2546 to avoid accessing undefined variables. We cannot use
2547 a temporary variable here as otherwise the replacement
2548 of the variables in omp-low.c will not work. */
2549 if (present && GFC_ARRAY_TYPE_P (TREE_TYPE (decl)))
2550 {
2551 tree tmp = fold_build2_loc (input_location,
2552 MODIFY_EXPR,
2553 void_type_node, decl,
2554 null_pointer_node);
2555 tree cond = fold_build1_loc (input_location,
2556 TRUTH_NOT_EXPR,
2557 boolean_type_node,
2558 present);
2559 gfc_add_expr_to_block (block,
2560 build3_loc (input_location,
2561 COND_EXPR,
2562 void_type_node,
2563 cond, tmp,
2564 NULL_TREE));
2565 }
2122 node4 = build_omp_clause (input_location, 2566 node4 = build_omp_clause (input_location,
2123 OMP_CLAUSE_MAP); 2567 OMP_CLAUSE_MAP);
2124 OMP_CLAUSE_SET_MAP_KIND (node4, GOMP_MAP_POINTER); 2568 OMP_CLAUSE_SET_MAP_KIND (node4, GOMP_MAP_POINTER);
2125 OMP_CLAUSE_DECL (node4) = decl; 2569 OMP_CLAUSE_DECL (node4) = decl;
2126 OMP_CLAUSE_SIZE (node4) = size_int (0); 2570 OMP_CLAUSE_SIZE (node4) = size_int (0);
2127 decl = build_fold_indirect_ref (decl); 2571 decl = build_fold_indirect_ref (decl);
2128 if (TREE_CODE (TREE_TYPE (orig_decl)) == REFERENCE_TYPE 2572 if ((TREE_CODE (TREE_TYPE (orig_decl)) == REFERENCE_TYPE
2573 || gfc_omp_is_optional_argument (orig_decl))
2129 && (GFC_DECL_GET_SCALAR_POINTER (orig_decl) 2574 && (GFC_DECL_GET_SCALAR_POINTER (orig_decl)
2130 || GFC_DECL_GET_SCALAR_ALLOCATABLE (orig_decl))) 2575 || GFC_DECL_GET_SCALAR_ALLOCATABLE (orig_decl)))
2131 { 2576 {
2132 node3 = build_omp_clause (input_location, 2577 node3 = build_omp_clause (input_location,
2133 OMP_CLAUSE_MAP); 2578 OMP_CLAUSE_MAP);
2135 OMP_CLAUSE_DECL (node3) = decl; 2580 OMP_CLAUSE_DECL (node3) = decl;
2136 OMP_CLAUSE_SIZE (node3) = size_int (0); 2581 OMP_CLAUSE_SIZE (node3) = size_int (0);
2137 decl = build_fold_indirect_ref (decl); 2582 decl = build_fold_indirect_ref (decl);
2138 } 2583 }
2139 } 2584 }
2140 if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl))) 2585 if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl))
2586 && n->u.map_op != OMP_MAP_ATTACH
2587 && n->u.map_op != OMP_MAP_DETACH)
2141 { 2588 {
2142 tree type = TREE_TYPE (decl); 2589 tree type = TREE_TYPE (decl);
2143 tree ptr = gfc_conv_descriptor_data_get (decl); 2590 tree ptr = gfc_conv_descriptor_data_get (decl);
2591 if (present)
2592 ptr = gfc_build_cond_assign_expr (block, present, ptr,
2593 null_pointer_node);
2144 ptr = fold_convert (build_pointer_type (char_type_node), 2594 ptr = fold_convert (build_pointer_type (char_type_node),
2145 ptr); 2595 ptr);
2146 ptr = build_fold_indirect_ref (ptr); 2596 ptr = build_fold_indirect_ref (ptr);
2147 OMP_CLAUSE_DECL (node) = ptr; 2597 OMP_CLAUSE_DECL (node) = ptr;
2148 node2 = build_omp_clause (input_location, 2598 node2 = build_omp_clause (input_location,
2151 OMP_CLAUSE_DECL (node2) = decl; 2601 OMP_CLAUSE_DECL (node2) = decl;
2152 OMP_CLAUSE_SIZE (node2) = TYPE_SIZE_UNIT (type); 2602 OMP_CLAUSE_SIZE (node2) = TYPE_SIZE_UNIT (type);
2153 node3 = build_omp_clause (input_location, 2603 node3 = build_omp_clause (input_location,
2154 OMP_CLAUSE_MAP); 2604 OMP_CLAUSE_MAP);
2155 OMP_CLAUSE_SET_MAP_KIND (node3, GOMP_MAP_POINTER); 2605 OMP_CLAUSE_SET_MAP_KIND (node3, GOMP_MAP_POINTER);
2156 OMP_CLAUSE_DECL (node3) 2606 if (present)
2157 = gfc_conv_descriptor_data_get (decl); 2607 {
2608 ptr = gfc_conv_descriptor_data_get (decl);
2609 ptr = gfc_build_addr_expr (NULL, ptr);
2610 ptr = gfc_build_cond_assign_expr (block, present, ptr,
2611 null_pointer_node);
2612 ptr = build_fold_indirect_ref (ptr);
2613 OMP_CLAUSE_DECL (node3) = ptr;
2614 }
2615 else
2616 OMP_CLAUSE_DECL (node3)
2617 = gfc_conv_descriptor_data_get (decl);
2158 OMP_CLAUSE_SIZE (node3) = size_int (0); 2618 OMP_CLAUSE_SIZE (node3) = size_int (0);
2159 2619
2160 /* We have to check for n->sym->attr.dimension because 2620 /* We have to check for n->sym->attr.dimension because
2161 of scalar coarrays. */ 2621 of scalar coarrays. */
2162 if (n->sym->attr.pointer && n->sym->attr.dimension) 2622 if (n->sym->attr.pointer && n->sym->attr.dimension)
2177 gfc_add_modify (&cond_block, size, zero); 2637 gfc_add_modify (&cond_block, size, zero);
2178 else_b = gfc_finish_block (&cond_block); 2638 else_b = gfc_finish_block (&cond_block);
2179 tem = gfc_conv_descriptor_data_get (decl); 2639 tem = gfc_conv_descriptor_data_get (decl);
2180 tem = fold_convert (pvoid_type_node, tem); 2640 tem = fold_convert (pvoid_type_node, tem);
2181 cond = fold_build2_loc (input_location, NE_EXPR, 2641 cond = fold_build2_loc (input_location, NE_EXPR,
2182 logical_type_node, 2642 boolean_type_node,
2183 tem, null_pointer_node); 2643 tem, null_pointer_node);
2644 if (present)
2645 cond = fold_build2_loc (input_location,
2646 TRUTH_ANDIF_EXPR,
2647 boolean_type_node,
2648 present, cond);
2184 gfc_add_expr_to_block (block, 2649 gfc_add_expr_to_block (block,
2185 build3_loc (input_location, 2650 build3_loc (input_location,
2186 COND_EXPR, 2651 COND_EXPR,
2187 void_type_node, 2652 void_type_node,
2188 cond, then_b, 2653 cond, then_b,
2189 else_b)); 2654 else_b));
2190 OMP_CLAUSE_SIZE (node) = size; 2655 OMP_CLAUSE_SIZE (node) = size;
2191 } 2656 }
2192 else if (n->sym->attr.dimension) 2657 else if (n->sym->attr.dimension)
2193 OMP_CLAUSE_SIZE (node) 2658 {
2194 = gfc_full_array_size (block, decl, 2659 stmtblock_t cond_block;
2195 GFC_TYPE_ARRAY_RANK (type)); 2660 gfc_init_block (&cond_block);
2661 tree size = gfc_full_array_size (&cond_block, decl,
2662 GFC_TYPE_ARRAY_RANK (type));
2663 if (present)
2664 {
2665 tree var = gfc_create_var (gfc_array_index_type,
2666 NULL);
2667 gfc_add_modify (&cond_block, var, size);
2668 tree cond_body = gfc_finish_block (&cond_block);
2669 tree cond = build3_loc (input_location, COND_EXPR,
2670 void_type_node, present,
2671 cond_body, NULL_TREE);
2672 gfc_add_expr_to_block (block, cond);
2673 OMP_CLAUSE_SIZE (node) = var;
2674 }
2675 else
2676 {
2677 gfc_add_block_to_block (block, &cond_block);
2678 OMP_CLAUSE_SIZE (node) = size;
2679 }
2680 }
2196 if (n->sym->attr.dimension) 2681 if (n->sym->attr.dimension)
2197 { 2682 {
2198 tree elemsz 2683 tree elemsz
2199 = TYPE_SIZE_UNIT (gfc_get_element_type (type)); 2684 = TYPE_SIZE_UNIT (gfc_get_element_type (type));
2200 elemsz = fold_convert (gfc_array_index_type, elemsz); 2685 elemsz = fold_convert (gfc_array_index_type, elemsz);
2201 OMP_CLAUSE_SIZE (node) 2686 OMP_CLAUSE_SIZE (node)
2202 = fold_build2 (MULT_EXPR, gfc_array_index_type, 2687 = fold_build2 (MULT_EXPR, gfc_array_index_type,
2203 OMP_CLAUSE_SIZE (node), elemsz); 2688 OMP_CLAUSE_SIZE (node), elemsz);
2204 } 2689 }
2205 } 2690 }
2691 else if (present
2692 && TREE_CODE (decl) == INDIRECT_REF
2693 && (TREE_CODE (TREE_OPERAND (decl, 0))
2694 == INDIRECT_REF))
2695 {
2696 /* A single indirectref is handled by the middle end. */
2697 gcc_assert (!POINTER_TYPE_P (TREE_TYPE (decl)));
2698 decl = TREE_OPERAND (decl, 0);
2699 decl = gfc_build_cond_assign_expr (block, present, decl,
2700 null_pointer_node);
2701 OMP_CLAUSE_DECL (node) = build_fold_indirect_ref (decl);
2702 }
2206 else 2703 else
2207 OMP_CLAUSE_DECL (node) = decl; 2704 OMP_CLAUSE_DECL (node) = decl;
2208 } 2705 }
2209 else 2706 else if (n->expr
2707 && n->expr->expr_type == EXPR_VARIABLE
2708 && n->expr->ref->type == REF_COMPONENT)
2210 { 2709 {
2211 tree ptr, ptr2; 2710 gfc_ref *lastcomp;
2711
2712 for (gfc_ref *ref = n->expr->ref; ref; ref = ref->next)
2713 if (ref->type == REF_COMPONENT)
2714 lastcomp = ref;
2715
2716 symbol_attribute sym_attr;
2717
2718 if (lastcomp->u.c.component->ts.type == BT_CLASS)
2719 sym_attr = CLASS_DATA (lastcomp->u.c.component)->attr;
2720 else
2721 sym_attr = lastcomp->u.c.component->attr;
2722
2212 gfc_init_se (&se, NULL); 2723 gfc_init_se (&se, NULL);
2213 if (n->expr->ref->u.ar.type == AR_ELEMENT) 2724
2725 if (!sym_attr.dimension
2726 && lastcomp->u.c.component->ts.type != BT_CLASS
2727 && lastcomp->u.c.component->ts.type != BT_DERIVED)
2214 { 2728 {
2215 gfc_conv_expr_reference (&se, n->expr); 2729 /* Last component is a scalar. */
2730 gfc_conv_expr (&se, n->expr);
2216 gfc_add_block_to_block (block, &se.pre); 2731 gfc_add_block_to_block (block, &se.pre);
2217 ptr = se.expr; 2732 OMP_CLAUSE_DECL (node) = se.expr;
2218 OMP_CLAUSE_SIZE (node) 2733 gfc_add_block_to_block (block, &se.post);
2219 = TYPE_SIZE_UNIT (TREE_TYPE (ptr)); 2734 goto finalize_map_clause;
2220 } 2735 }
2221 else 2736
2737 se.expr = gfc_maybe_dereference_var (n->sym, decl);
2738
2739 for (gfc_ref *ref = n->expr->ref;
2740 ref && ref != lastcomp->next;
2741 ref = ref->next)
2222 { 2742 {
2223 gfc_conv_expr_descriptor (&se, n->expr); 2743 if (ref->type == REF_COMPONENT)
2224 ptr = gfc_conv_array_data (se.expr); 2744 {
2225 tree type = TREE_TYPE (se.expr); 2745 if (ref->u.c.sym->attr.extension)
2226 gfc_add_block_to_block (block, &se.pre); 2746 conv_parent_component_references (&se, ref);
2227 OMP_CLAUSE_SIZE (node) 2747
2228 = gfc_full_array_size (block, se.expr, 2748 gfc_conv_component_ref (&se, ref);
2229 GFC_TYPE_ARRAY_RANK (type)); 2749 }
2230 tree elemsz 2750 else
2231 = TYPE_SIZE_UNIT (gfc_get_element_type (type)); 2751 sorry ("unhandled derived-type component");
2232 elemsz = fold_convert (gfc_array_index_type, elemsz);
2233 OMP_CLAUSE_SIZE (node)
2234 = fold_build2 (MULT_EXPR, gfc_array_index_type,
2235 OMP_CLAUSE_SIZE (node), elemsz);
2236 } 2752 }
2237 gfc_add_block_to_block (block, &se.post); 2753
2238 ptr = fold_convert (build_pointer_type (char_type_node), 2754 tree inner = se.expr;
2239 ptr); 2755
2240 OMP_CLAUSE_DECL (node) = build_fold_indirect_ref (ptr); 2756 /* Last component is a derived type or class pointer. */
2241 2757 if (lastcomp->u.c.component->ts.type == BT_DERIVED
2242 if (POINTER_TYPE_P (TREE_TYPE (decl)) 2758 || lastcomp->u.c.component->ts.type == BT_CLASS)
2243 && GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (TREE_TYPE (decl))))
2244 { 2759 {
2245 node4 = build_omp_clause (input_location, 2760 if (sym_attr.allocatable || sym_attr.pointer)
2246 OMP_CLAUSE_MAP); 2761 {
2247 OMP_CLAUSE_SET_MAP_KIND (node4, GOMP_MAP_POINTER); 2762 tree data, size;
2248 OMP_CLAUSE_DECL (node4) = decl; 2763
2249 OMP_CLAUSE_SIZE (node4) = size_int (0); 2764 if (lastcomp->u.c.component->ts.type == BT_CLASS)
2250 decl = build_fold_indirect_ref (decl); 2765 {
2251 } 2766 data = gfc_class_data_get (inner);
2252 ptr = fold_convert (sizetype, ptr); 2767 size = gfc_class_vtab_size_get (inner);
2253 if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl))) 2768 }
2254 { 2769 else /* BT_DERIVED. */
2255 tree type = TREE_TYPE (decl); 2770 {
2256 ptr2 = gfc_conv_descriptor_data_get (decl); 2771 data = inner;
2257 node2 = build_omp_clause (input_location, 2772 size = TYPE_SIZE_UNIT (TREE_TYPE (inner));
2258 OMP_CLAUSE_MAP); 2773 }
2259 OMP_CLAUSE_SET_MAP_KIND (node2, GOMP_MAP_TO_PSET); 2774
2260 OMP_CLAUSE_DECL (node2) = decl; 2775 OMP_CLAUSE_DECL (node)
2261 OMP_CLAUSE_SIZE (node2) = TYPE_SIZE_UNIT (type); 2776 = build_fold_indirect_ref (data);
2262 node3 = build_omp_clause (input_location, 2777 OMP_CLAUSE_SIZE (node) = size;
2263 OMP_CLAUSE_MAP); 2778 node2 = build_omp_clause (input_location,
2264 OMP_CLAUSE_SET_MAP_KIND (node3, GOMP_MAP_POINTER); 2779 OMP_CLAUSE_MAP);
2265 OMP_CLAUSE_DECL (node3) 2780 OMP_CLAUSE_SET_MAP_KIND (node2,
2266 = gfc_conv_descriptor_data_get (decl); 2781 GOMP_MAP_ATTACH_DETACH);
2267 } 2782 OMP_CLAUSE_DECL (node2) = data;
2268 else 2783 OMP_CLAUSE_SIZE (node2) = size_int (0);
2269 { 2784 }
2270 if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
2271 ptr2 = build_fold_addr_expr (decl);
2272 else 2785 else
2273 { 2786 {
2274 gcc_assert (POINTER_TYPE_P (TREE_TYPE (decl))); 2787 OMP_CLAUSE_DECL (node) = decl;
2275 ptr2 = decl; 2788 OMP_CLAUSE_SIZE (node)
2789 = TYPE_SIZE_UNIT (TREE_TYPE (decl));
2276 } 2790 }
2277 node3 = build_omp_clause (input_location,
2278 OMP_CLAUSE_MAP);
2279 OMP_CLAUSE_SET_MAP_KIND (node3, GOMP_MAP_POINTER);
2280 OMP_CLAUSE_DECL (node3) = decl;
2281 } 2791 }
2282 ptr2 = fold_convert (sizetype, ptr2); 2792 else if (lastcomp->next
2283 OMP_CLAUSE_SIZE (node3) 2793 && lastcomp->next->type == REF_ARRAY
2284 = fold_build2 (MINUS_EXPR, sizetype, ptr, ptr2); 2794 && lastcomp->next->u.ar.type == AR_FULL)
2795 {
2796 /* Just pass the (auto-dereferenced) decl through for
2797 bare attach and detach clauses. */
2798 if (n->u.map_op == OMP_MAP_ATTACH
2799 || n->u.map_op == OMP_MAP_DETACH)
2800 {
2801 OMP_CLAUSE_DECL (node) = inner;
2802 OMP_CLAUSE_SIZE (node) = size_zero_node;
2803 goto finalize_map_clause;
2804 }
2805
2806 if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (inner)))
2807 {
2808 tree type = TREE_TYPE (inner);
2809 tree ptr = gfc_conv_descriptor_data_get (inner);
2810 ptr = build_fold_indirect_ref (ptr);
2811 OMP_CLAUSE_DECL (node) = ptr;
2812 node2 = build_omp_clause (input_location,
2813 OMP_CLAUSE_MAP);
2814 OMP_CLAUSE_SET_MAP_KIND (node2, GOMP_MAP_TO_PSET);
2815 OMP_CLAUSE_DECL (node2) = inner;
2816 OMP_CLAUSE_SIZE (node2) = TYPE_SIZE_UNIT (type);
2817 node3 = build_omp_clause (input_location,
2818 OMP_CLAUSE_MAP);
2819 OMP_CLAUSE_SET_MAP_KIND (node3,
2820 GOMP_MAP_ATTACH_DETACH);
2821 OMP_CLAUSE_DECL (node3)
2822 = gfc_conv_descriptor_data_get (inner);
2823 STRIP_NOPS (OMP_CLAUSE_DECL (node3));
2824 OMP_CLAUSE_SIZE (node3) = size_int (0);
2825 int rank = GFC_TYPE_ARRAY_RANK (type);
2826 OMP_CLAUSE_SIZE (node)
2827 = gfc_full_array_size (block, inner, rank);
2828 tree elemsz
2829 = TYPE_SIZE_UNIT (gfc_get_element_type (type));
2830 elemsz = fold_convert (gfc_array_index_type, elemsz);
2831 OMP_CLAUSE_SIZE (node)
2832 = fold_build2 (MULT_EXPR, gfc_array_index_type,
2833 OMP_CLAUSE_SIZE (node), elemsz);
2834 }
2835 else
2836 OMP_CLAUSE_DECL (node) = inner;
2837 }
2838 else /* An array element or section. */
2839 {
2840 bool element
2841 = (lastcomp->next
2842 && lastcomp->next->type == REF_ARRAY
2843 && lastcomp->next->u.ar.type == AR_ELEMENT);
2844
2845 gfc_trans_omp_array_section (block, n, inner, element,
2846 GOMP_MAP_ATTACH_DETACH,
2847 node, node2, node3, node4);
2848 }
2285 } 2849 }
2850 else /* An array element or array section. */
2851 {
2852 bool element = n->expr->ref->u.ar.type == AR_ELEMENT;
2853 gfc_trans_omp_array_section (block, n, decl, element,
2854 GOMP_MAP_POINTER, node, node2,
2855 node3, node4);
2856 }
2857
2858 finalize_map_clause:
2286 switch (n->u.map_op) 2859 switch (n->u.map_op)
2287 { 2860 {
2288 case OMP_MAP_ALLOC: 2861 case OMP_MAP_ALLOC:
2289 OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_ALLOC); 2862 OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_ALLOC);
2863 break;
2864 case OMP_MAP_IF_PRESENT:
2865 OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_IF_PRESENT);
2866 break;
2867 case OMP_MAP_ATTACH:
2868 OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_ATTACH);
2290 break; 2869 break;
2291 case OMP_MAP_TO: 2870 case OMP_MAP_TO:
2292 OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_TO); 2871 OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_TO);
2293 break; 2872 break;
2294 case OMP_MAP_FROM: 2873 case OMP_MAP_FROM:
2309 case OMP_MAP_RELEASE: 2888 case OMP_MAP_RELEASE:
2310 OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_RELEASE); 2889 OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_RELEASE);
2311 break; 2890 break;
2312 case OMP_MAP_DELETE: 2891 case OMP_MAP_DELETE:
2313 OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_DELETE); 2892 OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_DELETE);
2893 break;
2894 case OMP_MAP_DETACH:
2895 OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_DETACH);
2314 break; 2896 break;
2315 case OMP_MAP_FORCE_ALLOC: 2897 case OMP_MAP_FORCE_ALLOC:
2316 OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_FORCE_ALLOC); 2898 OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_FORCE_ALLOC);
2317 break; 2899 break;
2318 case OMP_MAP_FORCE_TO: 2900 case OMP_MAP_FORCE_TO:
2365 gcc_unreachable (); 2947 gcc_unreachable ();
2366 } 2948 }
2367 tree node = build_omp_clause (input_location, clause_code); 2949 tree node = build_omp_clause (input_location, clause_code);
2368 if (n->expr == NULL || n->expr->ref->u.ar.type == AR_FULL) 2950 if (n->expr == NULL || n->expr->ref->u.ar.type == AR_FULL)
2369 { 2951 {
2370 tree decl = gfc_get_symbol_decl (n->sym); 2952 tree decl = gfc_trans_omp_variable (n->sym, false);
2371 if (gfc_omp_privatize_by_reference (decl)) 2953 if (gfc_omp_privatize_by_reference (decl))
2372 decl = build_fold_indirect_ref (decl); 2954 {
2955 if (gfc_omp_is_allocatable_or_ptr (decl))
2956 decl = build_fold_indirect_ref (decl);
2957 decl = build_fold_indirect_ref (decl);
2958 }
2373 else if (DECL_P (decl)) 2959 else if (DECL_P (decl))
2374 TREE_ADDRESSABLE (decl) = 1; 2960 TREE_ADDRESSABLE (decl) = 1;
2375 if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl))) 2961 if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl)))
2376 { 2962 {
2377 tree type = TREE_TYPE (decl); 2963 tree type = TREE_TYPE (decl);
2389 OMP_CLAUSE_SIZE (node) 2975 OMP_CLAUSE_SIZE (node)
2390 = fold_build2 (MULT_EXPR, gfc_array_index_type, 2976 = fold_build2 (MULT_EXPR, gfc_array_index_type,
2391 OMP_CLAUSE_SIZE (node), elemsz); 2977 OMP_CLAUSE_SIZE (node), elemsz);
2392 } 2978 }
2393 else 2979 else
2394 OMP_CLAUSE_DECL (node) = decl; 2980 {
2981 OMP_CLAUSE_DECL (node) = decl;
2982 if (gfc_omp_is_allocatable_or_ptr (decl))
2983 OMP_CLAUSE_SIZE (node)
2984 = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl)));
2985 }
2395 } 2986 }
2396 else 2987 else
2397 { 2988 {
2398 tree ptr; 2989 tree ptr;
2399 gfc_init_se (&se, NULL); 2990 gfc_init_se (&se, NULL);
2442 gfc_conv_expr (&se, clauses->if_expr); 3033 gfc_conv_expr (&se, clauses->if_expr);
2443 gfc_add_block_to_block (block, &se.pre); 3034 gfc_add_block_to_block (block, &se.pre);
2444 if_var = gfc_evaluate_now (se.expr, block); 3035 if_var = gfc_evaluate_now (se.expr, block);
2445 gfc_add_block_to_block (block, &se.post); 3036 gfc_add_block_to_block (block, &se.post);
2446 3037
2447 c = build_omp_clause (where.lb->location, OMP_CLAUSE_IF); 3038 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_IF);
2448 OMP_CLAUSE_IF_MODIFIER (c) = ERROR_MARK; 3039 OMP_CLAUSE_IF_MODIFIER (c) = ERROR_MARK;
2449 OMP_CLAUSE_IF_EXPR (c) = if_var; 3040 OMP_CLAUSE_IF_EXPR (c) = if_var;
2450 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3041 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2451 } 3042 }
2452 for (ifc = 0; ifc < OMP_IF_LAST; ifc++) 3043 for (ifc = 0; ifc < OMP_IF_LAST; ifc++)
2458 gfc_conv_expr (&se, clauses->if_exprs[ifc]); 3049 gfc_conv_expr (&se, clauses->if_exprs[ifc]);
2459 gfc_add_block_to_block (block, &se.pre); 3050 gfc_add_block_to_block (block, &se.pre);
2460 if_var = gfc_evaluate_now (se.expr, block); 3051 if_var = gfc_evaluate_now (se.expr, block);
2461 gfc_add_block_to_block (block, &se.post); 3052 gfc_add_block_to_block (block, &se.post);
2462 3053
2463 c = build_omp_clause (where.lb->location, OMP_CLAUSE_IF); 3054 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_IF);
2464 switch (ifc) 3055 switch (ifc)
2465 { 3056 {
2466 case OMP_IF_PARALLEL: 3057 case OMP_IF_PARALLEL:
2467 OMP_CLAUSE_IF_MODIFIER (c) = OMP_PARALLEL; 3058 OMP_CLAUSE_IF_MODIFIER (c) = OMP_PARALLEL;
2468 break; 3059 break;
2502 gfc_conv_expr (&se, clauses->final_expr); 3093 gfc_conv_expr (&se, clauses->final_expr);
2503 gfc_add_block_to_block (block, &se.pre); 3094 gfc_add_block_to_block (block, &se.pre);
2504 final_var = gfc_evaluate_now (se.expr, block); 3095 final_var = gfc_evaluate_now (se.expr, block);
2505 gfc_add_block_to_block (block, &se.post); 3096 gfc_add_block_to_block (block, &se.post);
2506 3097
2507 c = build_omp_clause (where.lb->location, OMP_CLAUSE_FINAL); 3098 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_FINAL);
2508 OMP_CLAUSE_FINAL_EXPR (c) = final_var; 3099 OMP_CLAUSE_FINAL_EXPR (c) = final_var;
2509 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3100 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2510 } 3101 }
2511 3102
2512 if (clauses->num_threads) 3103 if (clauses->num_threads)
2517 gfc_conv_expr (&se, clauses->num_threads); 3108 gfc_conv_expr (&se, clauses->num_threads);
2518 gfc_add_block_to_block (block, &se.pre); 3109 gfc_add_block_to_block (block, &se.pre);
2519 num_threads = gfc_evaluate_now (se.expr, block); 3110 num_threads = gfc_evaluate_now (se.expr, block);
2520 gfc_add_block_to_block (block, &se.post); 3111 gfc_add_block_to_block (block, &se.post);
2521 3112
2522 c = build_omp_clause (where.lb->location, OMP_CLAUSE_NUM_THREADS); 3113 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_NUM_THREADS);
2523 OMP_CLAUSE_NUM_THREADS_EXPR (c) = num_threads; 3114 OMP_CLAUSE_NUM_THREADS_EXPR (c) = num_threads;
2524 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3115 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2525 } 3116 }
2526 3117
2527 chunk_size = NULL_TREE; 3118 chunk_size = NULL_TREE;
2534 gfc_add_block_to_block (block, &se.post); 3125 gfc_add_block_to_block (block, &se.post);
2535 } 3126 }
2536 3127
2537 if (clauses->sched_kind != OMP_SCHED_NONE) 3128 if (clauses->sched_kind != OMP_SCHED_NONE)
2538 { 3129 {
2539 c = build_omp_clause (where.lb->location, OMP_CLAUSE_SCHEDULE); 3130 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_SCHEDULE);
2540 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = chunk_size; 3131 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = chunk_size;
2541 switch (clauses->sched_kind) 3132 switch (clauses->sched_kind)
2542 { 3133 {
2543 case OMP_SCHED_STATIC: 3134 case OMP_SCHED_STATIC:
2544 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC; 3135 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
2571 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3162 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2572 } 3163 }
2573 3164
2574 if (clauses->default_sharing != OMP_DEFAULT_UNKNOWN) 3165 if (clauses->default_sharing != OMP_DEFAULT_UNKNOWN)
2575 { 3166 {
2576 c = build_omp_clause (where.lb->location, OMP_CLAUSE_DEFAULT); 3167 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_DEFAULT);
2577 switch (clauses->default_sharing) 3168 switch (clauses->default_sharing)
2578 { 3169 {
2579 case OMP_DEFAULT_NONE: 3170 case OMP_DEFAULT_NONE:
2580 OMP_CLAUSE_DEFAULT_KIND (c) = OMP_CLAUSE_DEFAULT_NONE; 3171 OMP_CLAUSE_DEFAULT_KIND (c) = OMP_CLAUSE_DEFAULT_NONE;
2581 break; 3172 break;
2597 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3188 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2598 } 3189 }
2599 3190
2600 if (clauses->nowait) 3191 if (clauses->nowait)
2601 { 3192 {
2602 c = build_omp_clause (where.lb->location, OMP_CLAUSE_NOWAIT); 3193 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_NOWAIT);
2603 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3194 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2604 } 3195 }
2605 3196
2606 if (clauses->ordered) 3197 if (clauses->ordered)
2607 { 3198 {
2608 c = build_omp_clause (where.lb->location, OMP_CLAUSE_ORDERED); 3199 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_ORDERED);
2609 OMP_CLAUSE_ORDERED_EXPR (c) 3200 OMP_CLAUSE_ORDERED_EXPR (c)
2610 = clauses->orderedc ? build_int_cst (integer_type_node, 3201 = clauses->orderedc ? build_int_cst (integer_type_node,
2611 clauses->orderedc) : NULL_TREE; 3202 clauses->orderedc) : NULL_TREE;
2612 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3203 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2613 } 3204 }
2614 3205
2615 if (clauses->untied) 3206 if (clauses->untied)
2616 { 3207 {
2617 c = build_omp_clause (where.lb->location, OMP_CLAUSE_UNTIED); 3208 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_UNTIED);
2618 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3209 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2619 } 3210 }
2620 3211
2621 if (clauses->mergeable) 3212 if (clauses->mergeable)
2622 { 3213 {
2623 c = build_omp_clause (where.lb->location, OMP_CLAUSE_MERGEABLE); 3214 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_MERGEABLE);
2624 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3215 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2625 } 3216 }
2626 3217
2627 if (clauses->collapse) 3218 if (clauses->collapse)
2628 { 3219 {
2629 c = build_omp_clause (where.lb->location, OMP_CLAUSE_COLLAPSE); 3220 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_COLLAPSE);
2630 OMP_CLAUSE_COLLAPSE_EXPR (c) 3221 OMP_CLAUSE_COLLAPSE_EXPR (c)
2631 = build_int_cst (integer_type_node, clauses->collapse); 3222 = build_int_cst (integer_type_node, clauses->collapse);
2632 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3223 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2633 } 3224 }
2634 3225
2635 if (clauses->inbranch) 3226 if (clauses->inbranch)
2636 { 3227 {
2637 c = build_omp_clause (where.lb->location, OMP_CLAUSE_INBRANCH); 3228 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_INBRANCH);
2638 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3229 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2639 } 3230 }
2640 3231
2641 if (clauses->notinbranch) 3232 if (clauses->notinbranch)
2642 { 3233 {
2643 c = build_omp_clause (where.lb->location, OMP_CLAUSE_NOTINBRANCH); 3234 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_NOTINBRANCH);
2644 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3235 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2645 } 3236 }
2646 3237
2647 switch (clauses->cancel) 3238 switch (clauses->cancel)
2648 { 3239 {
2649 case OMP_CANCEL_UNKNOWN: 3240 case OMP_CANCEL_UNKNOWN:
2650 break; 3241 break;
2651 case OMP_CANCEL_PARALLEL: 3242 case OMP_CANCEL_PARALLEL:
2652 c = build_omp_clause (where.lb->location, OMP_CLAUSE_PARALLEL); 3243 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_PARALLEL);
2653 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3244 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2654 break; 3245 break;
2655 case OMP_CANCEL_SECTIONS: 3246 case OMP_CANCEL_SECTIONS:
2656 c = build_omp_clause (where.lb->location, OMP_CLAUSE_SECTIONS); 3247 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_SECTIONS);
2657 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3248 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2658 break; 3249 break;
2659 case OMP_CANCEL_DO: 3250 case OMP_CANCEL_DO:
2660 c = build_omp_clause (where.lb->location, OMP_CLAUSE_FOR); 3251 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_FOR);
2661 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3252 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2662 break; 3253 break;
2663 case OMP_CANCEL_TASKGROUP: 3254 case OMP_CANCEL_TASKGROUP:
2664 c = build_omp_clause (where.lb->location, OMP_CLAUSE_TASKGROUP); 3255 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_TASKGROUP);
2665 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3256 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2666 break; 3257 break;
2667 } 3258 }
2668 3259
2669 if (clauses->proc_bind != OMP_PROC_BIND_UNKNOWN) 3260 if (clauses->proc_bind != OMP_PROC_BIND_UNKNOWN)
2670 { 3261 {
2671 c = build_omp_clause (where.lb->location, OMP_CLAUSE_PROC_BIND); 3262 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_PROC_BIND);
2672 switch (clauses->proc_bind) 3263 switch (clauses->proc_bind)
2673 { 3264 {
2674 case OMP_PROC_BIND_MASTER: 3265 case OMP_PROC_BIND_MASTER:
2675 OMP_CLAUSE_PROC_BIND_KIND (c) = OMP_CLAUSE_PROC_BIND_MASTER; 3266 OMP_CLAUSE_PROC_BIND_KIND (c) = OMP_CLAUSE_PROC_BIND_MASTER;
2676 break; 3267 break;
2694 gfc_conv_expr (&se, clauses->safelen_expr); 3285 gfc_conv_expr (&se, clauses->safelen_expr);
2695 gfc_add_block_to_block (block, &se.pre); 3286 gfc_add_block_to_block (block, &se.pre);
2696 safelen_var = gfc_evaluate_now (se.expr, block); 3287 safelen_var = gfc_evaluate_now (se.expr, block);
2697 gfc_add_block_to_block (block, &se.post); 3288 gfc_add_block_to_block (block, &se.post);
2698 3289
2699 c = build_omp_clause (where.lb->location, OMP_CLAUSE_SAFELEN); 3290 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_SAFELEN);
2700 OMP_CLAUSE_SAFELEN_EXPR (c) = safelen_var; 3291 OMP_CLAUSE_SAFELEN_EXPR (c) = safelen_var;
2701 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3292 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2702 } 3293 }
2703 3294
2704 if (clauses->simdlen_expr) 3295 if (clauses->simdlen_expr)
2705 { 3296 {
2706 if (declare_simd) 3297 if (declare_simd)
2707 { 3298 {
2708 c = build_omp_clause (where.lb->location, OMP_CLAUSE_SIMDLEN); 3299 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_SIMDLEN);
2709 OMP_CLAUSE_SIMDLEN_EXPR (c) 3300 OMP_CLAUSE_SIMDLEN_EXPR (c)
2710 = gfc_conv_constant_to_tree (clauses->simdlen_expr); 3301 = gfc_conv_constant_to_tree (clauses->simdlen_expr);
2711 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3302 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2712 } 3303 }
2713 else 3304 else
2718 gfc_conv_expr (&se, clauses->simdlen_expr); 3309 gfc_conv_expr (&se, clauses->simdlen_expr);
2719 gfc_add_block_to_block (block, &se.pre); 3310 gfc_add_block_to_block (block, &se.pre);
2720 simdlen_var = gfc_evaluate_now (se.expr, block); 3311 simdlen_var = gfc_evaluate_now (se.expr, block);
2721 gfc_add_block_to_block (block, &se.post); 3312 gfc_add_block_to_block (block, &se.post);
2722 3313
2723 c = build_omp_clause (where.lb->location, OMP_CLAUSE_SIMDLEN); 3314 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_SIMDLEN);
2724 OMP_CLAUSE_SIMDLEN_EXPR (c) = simdlen_var; 3315 OMP_CLAUSE_SIMDLEN_EXPR (c) = simdlen_var;
2725 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3316 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2726 } 3317 }
2727 } 3318 }
2728 3319
2734 gfc_conv_expr (&se, clauses->num_teams); 3325 gfc_conv_expr (&se, clauses->num_teams);
2735 gfc_add_block_to_block (block, &se.pre); 3326 gfc_add_block_to_block (block, &se.pre);
2736 num_teams = gfc_evaluate_now (se.expr, block); 3327 num_teams = gfc_evaluate_now (se.expr, block);
2737 gfc_add_block_to_block (block, &se.post); 3328 gfc_add_block_to_block (block, &se.post);
2738 3329
2739 c = build_omp_clause (where.lb->location, OMP_CLAUSE_NUM_TEAMS); 3330 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_NUM_TEAMS);
2740 OMP_CLAUSE_NUM_TEAMS_EXPR (c) = num_teams; 3331 OMP_CLAUSE_NUM_TEAMS_EXPR (c) = num_teams;
2741 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3332 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2742 } 3333 }
2743 3334
2744 if (clauses->device) 3335 if (clauses->device)
2749 gfc_conv_expr (&se, clauses->device); 3340 gfc_conv_expr (&se, clauses->device);
2750 gfc_add_block_to_block (block, &se.pre); 3341 gfc_add_block_to_block (block, &se.pre);
2751 device = gfc_evaluate_now (se.expr, block); 3342 device = gfc_evaluate_now (se.expr, block);
2752 gfc_add_block_to_block (block, &se.post); 3343 gfc_add_block_to_block (block, &se.post);
2753 3344
2754 c = build_omp_clause (where.lb->location, OMP_CLAUSE_DEVICE); 3345 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_DEVICE);
2755 OMP_CLAUSE_DEVICE_ID (c) = device; 3346 OMP_CLAUSE_DEVICE_ID (c) = device;
2756 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3347 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2757 } 3348 }
2758 3349
2759 if (clauses->thread_limit) 3350 if (clauses->thread_limit)
2764 gfc_conv_expr (&se, clauses->thread_limit); 3355 gfc_conv_expr (&se, clauses->thread_limit);
2765 gfc_add_block_to_block (block, &se.pre); 3356 gfc_add_block_to_block (block, &se.pre);
2766 thread_limit = gfc_evaluate_now (se.expr, block); 3357 thread_limit = gfc_evaluate_now (se.expr, block);
2767 gfc_add_block_to_block (block, &se.post); 3358 gfc_add_block_to_block (block, &se.post);
2768 3359
2769 c = build_omp_clause (where.lb->location, OMP_CLAUSE_THREAD_LIMIT); 3360 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_THREAD_LIMIT);
2770 OMP_CLAUSE_THREAD_LIMIT_EXPR (c) = thread_limit; 3361 OMP_CLAUSE_THREAD_LIMIT_EXPR (c) = thread_limit;
2771 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3362 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2772 } 3363 }
2773 3364
2774 chunk_size = NULL_TREE; 3365 chunk_size = NULL_TREE;
2781 gfc_add_block_to_block (block, &se.post); 3372 gfc_add_block_to_block (block, &se.post);
2782 } 3373 }
2783 3374
2784 if (clauses->dist_sched_kind != OMP_SCHED_NONE) 3375 if (clauses->dist_sched_kind != OMP_SCHED_NONE)
2785 { 3376 {
2786 c = build_omp_clause (where.lb->location, OMP_CLAUSE_DIST_SCHEDULE); 3377 c = build_omp_clause (gfc_get_location (&where),
3378 OMP_CLAUSE_DIST_SCHEDULE);
2787 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c) = chunk_size; 3379 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c) = chunk_size;
2788 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3380 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2789 } 3381 }
2790 3382
2791 if (clauses->grainsize) 3383 if (clauses->grainsize)
2796 gfc_conv_expr (&se, clauses->grainsize); 3388 gfc_conv_expr (&se, clauses->grainsize);
2797 gfc_add_block_to_block (block, &se.pre); 3389 gfc_add_block_to_block (block, &se.pre);
2798 grainsize = gfc_evaluate_now (se.expr, block); 3390 grainsize = gfc_evaluate_now (se.expr, block);
2799 gfc_add_block_to_block (block, &se.post); 3391 gfc_add_block_to_block (block, &se.post);
2800 3392
2801 c = build_omp_clause (where.lb->location, OMP_CLAUSE_GRAINSIZE); 3393 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_GRAINSIZE);
2802 OMP_CLAUSE_GRAINSIZE_EXPR (c) = grainsize; 3394 OMP_CLAUSE_GRAINSIZE_EXPR (c) = grainsize;
2803 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3395 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2804 } 3396 }
2805 3397
2806 if (clauses->num_tasks) 3398 if (clauses->num_tasks)
2811 gfc_conv_expr (&se, clauses->num_tasks); 3403 gfc_conv_expr (&se, clauses->num_tasks);
2812 gfc_add_block_to_block (block, &se.pre); 3404 gfc_add_block_to_block (block, &se.pre);
2813 num_tasks = gfc_evaluate_now (se.expr, block); 3405 num_tasks = gfc_evaluate_now (se.expr, block);
2814 gfc_add_block_to_block (block, &se.post); 3406 gfc_add_block_to_block (block, &se.post);
2815 3407
2816 c = build_omp_clause (where.lb->location, OMP_CLAUSE_NUM_TASKS); 3408 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_NUM_TASKS);
2817 OMP_CLAUSE_NUM_TASKS_EXPR (c) = num_tasks; 3409 OMP_CLAUSE_NUM_TASKS_EXPR (c) = num_tasks;
2818 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3410 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2819 } 3411 }
2820 3412
2821 if (clauses->priority) 3413 if (clauses->priority)
2826 gfc_conv_expr (&se, clauses->priority); 3418 gfc_conv_expr (&se, clauses->priority);
2827 gfc_add_block_to_block (block, &se.pre); 3419 gfc_add_block_to_block (block, &se.pre);
2828 priority = gfc_evaluate_now (se.expr, block); 3420 priority = gfc_evaluate_now (se.expr, block);
2829 gfc_add_block_to_block (block, &se.post); 3421 gfc_add_block_to_block (block, &se.post);
2830 3422
2831 c = build_omp_clause (where.lb->location, OMP_CLAUSE_PRIORITY); 3423 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_PRIORITY);
2832 OMP_CLAUSE_PRIORITY_EXPR (c) = priority; 3424 OMP_CLAUSE_PRIORITY_EXPR (c) = priority;
2833 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3425 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2834 } 3426 }
2835 3427
2836 if (clauses->hint) 3428 if (clauses->hint)
2841 gfc_conv_expr (&se, clauses->hint); 3433 gfc_conv_expr (&se, clauses->hint);
2842 gfc_add_block_to_block (block, &se.pre); 3434 gfc_add_block_to_block (block, &se.pre);
2843 hint = gfc_evaluate_now (se.expr, block); 3435 hint = gfc_evaluate_now (se.expr, block);
2844 gfc_add_block_to_block (block, &se.post); 3436 gfc_add_block_to_block (block, &se.post);
2845 3437
2846 c = build_omp_clause (where.lb->location, OMP_CLAUSE_HINT); 3438 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_HINT);
2847 OMP_CLAUSE_HINT_EXPR (c) = hint; 3439 OMP_CLAUSE_HINT_EXPR (c) = hint;
2848 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3440 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2849 } 3441 }
2850 3442
2851 if (clauses->simd) 3443 if (clauses->simd)
2852 { 3444 {
2853 c = build_omp_clause (where.lb->location, OMP_CLAUSE_SIMD); 3445 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_SIMD);
2854 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3446 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2855 } 3447 }
2856 if (clauses->threads) 3448 if (clauses->threads)
2857 { 3449 {
2858 c = build_omp_clause (where.lb->location, OMP_CLAUSE_THREADS); 3450 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_THREADS);
2859 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3451 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2860 } 3452 }
2861 if (clauses->nogroup) 3453 if (clauses->nogroup)
2862 { 3454 {
2863 c = build_omp_clause (where.lb->location, OMP_CLAUSE_NOGROUP); 3455 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_NOGROUP);
2864 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3456 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2865 } 3457 }
2866 if (clauses->defaultmap) 3458 if (clauses->defaultmap)
2867 { 3459 {
2868 c = build_omp_clause (where.lb->location, OMP_CLAUSE_DEFAULTMAP); 3460 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_DEFAULTMAP);
3461 OMP_CLAUSE_DEFAULTMAP_SET_KIND (c, OMP_CLAUSE_DEFAULTMAP_TOFROM,
3462 OMP_CLAUSE_DEFAULTMAP_CATEGORY_SCALAR);
2869 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3463 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2870 } 3464 }
2871 if (clauses->depend_source) 3465 if (clauses->depend_source)
2872 { 3466 {
2873 c = build_omp_clause (where.lb->location, OMP_CLAUSE_DEPEND); 3467 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_DEPEND);
2874 OMP_CLAUSE_DEPEND_KIND (c) = OMP_CLAUSE_DEPEND_SOURCE; 3468 OMP_CLAUSE_DEPEND_KIND (c) = OMP_CLAUSE_DEPEND_SOURCE;
2875 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3469 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2876 } 3470 }
2877 3471
2878 if (clauses->async) 3472 if (clauses->async)
2879 { 3473 {
2880 c = build_omp_clause (where.lb->location, OMP_CLAUSE_ASYNC); 3474 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_ASYNC);
2881 if (clauses->async_expr) 3475 if (clauses->async_expr)
2882 OMP_CLAUSE_ASYNC_EXPR (c) 3476 OMP_CLAUSE_ASYNC_EXPR (c)
2883 = gfc_convert_expr_to_tree (block, clauses->async_expr); 3477 = gfc_convert_expr_to_tree (block, clauses->async_expr);
2884 else 3478 else
2885 OMP_CLAUSE_ASYNC_EXPR (c) = NULL; 3479 OMP_CLAUSE_ASYNC_EXPR (c) = NULL;
2886 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3480 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2887 } 3481 }
2888 if (clauses->seq) 3482 if (clauses->seq)
2889 { 3483 {
2890 c = build_omp_clause (where.lb->location, OMP_CLAUSE_SEQ); 3484 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_SEQ);
2891 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3485 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2892 } 3486 }
2893 if (clauses->par_auto) 3487 if (clauses->par_auto)
2894 { 3488 {
2895 c = build_omp_clause (where.lb->location, OMP_CLAUSE_AUTO); 3489 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_AUTO);
2896 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3490 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2897 } 3491 }
2898 if (clauses->if_present) 3492 if (clauses->if_present)
2899 { 3493 {
2900 c = build_omp_clause (where.lb->location, OMP_CLAUSE_IF_PRESENT); 3494 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_IF_PRESENT);
2901 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3495 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2902 } 3496 }
2903 if (clauses->finalize) 3497 if (clauses->finalize)
2904 { 3498 {
2905 c = build_omp_clause (where.lb->location, OMP_CLAUSE_FINALIZE); 3499 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_FINALIZE);
2906 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3500 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2907 } 3501 }
2908 if (clauses->independent) 3502 if (clauses->independent)
2909 { 3503 {
2910 c = build_omp_clause (where.lb->location, OMP_CLAUSE_INDEPENDENT); 3504 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_INDEPENDENT);
2911 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3505 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2912 } 3506 }
2913 if (clauses->wait_list) 3507 if (clauses->wait_list)
2914 { 3508 {
2915 gfc_expr_list *el; 3509 gfc_expr_list *el;
2916 3510
2917 for (el = clauses->wait_list; el; el = el->next) 3511 for (el = clauses->wait_list; el; el = el->next)
2918 { 3512 {
2919 c = build_omp_clause (where.lb->location, OMP_CLAUSE_WAIT); 3513 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_WAIT);
2920 OMP_CLAUSE_DECL (c) = gfc_convert_expr_to_tree (block, el->expr); 3514 OMP_CLAUSE_DECL (c) = gfc_convert_expr_to_tree (block, el->expr);
2921 OMP_CLAUSE_CHAIN (c) = omp_clauses; 3515 OMP_CLAUSE_CHAIN (c) = omp_clauses;
2922 omp_clauses = c; 3516 omp_clauses = c;
2923 } 3517 }
2924 } 3518 }
2925 if (clauses->num_gangs_expr) 3519 if (clauses->num_gangs_expr)
2926 { 3520 {
2927 tree num_gangs_var 3521 tree num_gangs_var
2928 = gfc_convert_expr_to_tree (block, clauses->num_gangs_expr); 3522 = gfc_convert_expr_to_tree (block, clauses->num_gangs_expr);
2929 c = build_omp_clause (where.lb->location, OMP_CLAUSE_NUM_GANGS); 3523 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_NUM_GANGS);
2930 OMP_CLAUSE_NUM_GANGS_EXPR (c) = num_gangs_var; 3524 OMP_CLAUSE_NUM_GANGS_EXPR (c) = num_gangs_var;
2931 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3525 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2932 } 3526 }
2933 if (clauses->num_workers_expr) 3527 if (clauses->num_workers_expr)
2934 { 3528 {
2935 tree num_workers_var 3529 tree num_workers_var
2936 = gfc_convert_expr_to_tree (block, clauses->num_workers_expr); 3530 = gfc_convert_expr_to_tree (block, clauses->num_workers_expr);
2937 c = build_omp_clause (where.lb->location, OMP_CLAUSE_NUM_WORKERS); 3531 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_NUM_WORKERS);
2938 OMP_CLAUSE_NUM_WORKERS_EXPR (c) = num_workers_var; 3532 OMP_CLAUSE_NUM_WORKERS_EXPR (c) = num_workers_var;
2939 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3533 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2940 } 3534 }
2941 if (clauses->vector_length_expr) 3535 if (clauses->vector_length_expr)
2942 { 3536 {
2943 tree vector_length_var 3537 tree vector_length_var
2944 = gfc_convert_expr_to_tree (block, clauses->vector_length_expr); 3538 = gfc_convert_expr_to_tree (block, clauses->vector_length_expr);
2945 c = build_omp_clause (where.lb->location, OMP_CLAUSE_VECTOR_LENGTH); 3539 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_VECTOR_LENGTH);
2946 OMP_CLAUSE_VECTOR_LENGTH_EXPR (c) = vector_length_var; 3540 OMP_CLAUSE_VECTOR_LENGTH_EXPR (c) = vector_length_var;
2947 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3541 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2948 } 3542 }
2949 if (clauses->tile_list) 3543 if (clauses->tile_list)
2950 { 3544 {
2954 vec_alloc (tvec, 4); 3548 vec_alloc (tvec, 4);
2955 3549
2956 for (el = clauses->tile_list; el; el = el->next) 3550 for (el = clauses->tile_list; el; el = el->next)
2957 vec_safe_push (tvec, gfc_convert_expr_to_tree (block, el->expr)); 3551 vec_safe_push (tvec, gfc_convert_expr_to_tree (block, el->expr));
2958 3552
2959 c = build_omp_clause (where.lb->location, OMP_CLAUSE_TILE); 3553 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_TILE);
2960 OMP_CLAUSE_TILE_LIST (c) = build_tree_list_vec (tvec); 3554 OMP_CLAUSE_TILE_LIST (c) = build_tree_list_vec (tvec);
2961 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3555 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2962 tvec->truncate (0); 3556 tvec->truncate (0);
2963 } 3557 }
2964 if (clauses->vector) 3558 if (clauses->vector)
2965 { 3559 {
2966 if (clauses->vector_expr) 3560 if (clauses->vector_expr)
2967 { 3561 {
2968 tree vector_var 3562 tree vector_var
2969 = gfc_convert_expr_to_tree (block, clauses->vector_expr); 3563 = gfc_convert_expr_to_tree (block, clauses->vector_expr);
2970 c = build_omp_clause (where.lb->location, OMP_CLAUSE_VECTOR); 3564 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_VECTOR);
2971 OMP_CLAUSE_VECTOR_EXPR (c) = vector_var; 3565 OMP_CLAUSE_VECTOR_EXPR (c) = vector_var;
2972 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3566 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2973 } 3567 }
2974 else 3568 else
2975 { 3569 {
2976 c = build_omp_clause (where.lb->location, OMP_CLAUSE_VECTOR); 3570 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_VECTOR);
2977 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3571 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2978 } 3572 }
2979 } 3573 }
2980 if (clauses->worker) 3574 if (clauses->worker)
2981 { 3575 {
2982 if (clauses->worker_expr) 3576 if (clauses->worker_expr)
2983 { 3577 {
2984 tree worker_var 3578 tree worker_var
2985 = gfc_convert_expr_to_tree (block, clauses->worker_expr); 3579 = gfc_convert_expr_to_tree (block, clauses->worker_expr);
2986 c = build_omp_clause (where.lb->location, OMP_CLAUSE_WORKER); 3580 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_WORKER);
2987 OMP_CLAUSE_WORKER_EXPR (c) = worker_var; 3581 OMP_CLAUSE_WORKER_EXPR (c) = worker_var;
2988 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3582 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2989 } 3583 }
2990 else 3584 else
2991 { 3585 {
2992 c = build_omp_clause (where.lb->location, OMP_CLAUSE_WORKER); 3586 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_WORKER);
2993 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3587 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
2994 } 3588 }
2995 } 3589 }
2996 if (clauses->gang) 3590 if (clauses->gang)
2997 { 3591 {
2998 tree arg; 3592 tree arg;
2999 c = build_omp_clause (where.lb->location, OMP_CLAUSE_GANG); 3593 c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_GANG);
3000 omp_clauses = gfc_trans_add_clause (c, omp_clauses); 3594 omp_clauses = gfc_trans_add_clause (c, omp_clauses);
3001 if (clauses->gang_num_expr) 3595 if (clauses->gang_num_expr)
3002 { 3596 {
3003 arg = gfc_convert_expr_to_tree (block, clauses->gang_num_expr); 3597 arg = gfc_convert_expr_to_tree (block, clauses->gang_num_expr);
3004 OMP_CLAUSE_GANG_EXPR (c) = arg; 3598 OMP_CLAUSE_GANG_EXPR (c) = arg;
3037 else 3631 else
3038 poplevel (0, 0); 3632 poplevel (0, 0);
3039 return stmt; 3633 return stmt;
3040 } 3634 }
3041 3635
3042 /* Trans OpenACC directives. */ 3636 /* Translate OpenACC 'parallel', 'kernels', 'serial', 'data', 'host_data'
3043 /* parallel, kernels, data and host_data. */ 3637 construct. */
3638
3044 static tree 3639 static tree
3045 gfc_trans_oacc_construct (gfc_code *code) 3640 gfc_trans_oacc_construct (gfc_code *code)
3046 { 3641 {
3047 stmtblock_t block; 3642 stmtblock_t block;
3048 tree stmt, oacc_clauses; 3643 tree stmt, oacc_clauses;
3053 case EXEC_OACC_PARALLEL: 3648 case EXEC_OACC_PARALLEL:
3054 construct_code = OACC_PARALLEL; 3649 construct_code = OACC_PARALLEL;
3055 break; 3650 break;
3056 case EXEC_OACC_KERNELS: 3651 case EXEC_OACC_KERNELS:
3057 construct_code = OACC_KERNELS; 3652 construct_code = OACC_KERNELS;
3653 break;
3654 case EXEC_OACC_SERIAL:
3655 construct_code = OACC_SERIAL;
3058 break; 3656 break;
3059 case EXEC_OACC_DATA: 3657 case EXEC_OACC_DATA:
3060 construct_code = OACC_DATA; 3658 construct_code = OACC_DATA;
3061 break; 3659 break;
3062 case EXEC_OACC_HOST_DATA: 3660 case EXEC_OACC_HOST_DATA:
3164 stmtblock_t block; 3762 stmtblock_t block;
3165 tree lhsaddr, type, rhs, x; 3763 tree lhsaddr, type, rhs, x;
3166 enum tree_code op = ERROR_MARK; 3764 enum tree_code op = ERROR_MARK;
3167 enum tree_code aop = OMP_ATOMIC; 3765 enum tree_code aop = OMP_ATOMIC;
3168 bool var_on_left = false; 3766 bool var_on_left = false;
3169 bool seq_cst = (atomic_code->ext.omp_atomic & GFC_OMP_ATOMIC_SEQ_CST) != 0; 3767 enum omp_memory_order mo
3768 = ((atomic_code->ext.omp_atomic & GFC_OMP_ATOMIC_SEQ_CST)
3769 ? OMP_MEMORY_ORDER_SEQ_CST : OMP_MEMORY_ORDER_RELAXED);
3170 3770
3171 code = code->block->next; 3771 code = code->block->next;
3172 gcc_assert (code->op == EXEC_ASSIGN); 3772 gcc_assert (code->op == EXEC_ASSIGN);
3173 var = code->expr1->symtree->n.sym; 3773 var = code->expr1->symtree->n.sym;
3174 3774
3178 gfc_start_block (&block); 3778 gfc_start_block (&block);
3179 3779
3180 expr2 = code->expr2; 3780 expr2 = code->expr2;
3181 if (((atomic_code->ext.omp_atomic & GFC_OMP_ATOMIC_MASK) 3781 if (((atomic_code->ext.omp_atomic & GFC_OMP_ATOMIC_MASK)
3182 != GFC_OMP_ATOMIC_WRITE) 3782 != GFC_OMP_ATOMIC_WRITE)
3183 && (atomic_code->ext.omp_atomic & GFC_OMP_ATOMIC_SWAP) == 0
3184 && expr2->expr_type == EXPR_FUNCTION 3783 && expr2->expr_type == EXPR_FUNCTION
3185 && expr2->value.function.isym 3784 && expr2->value.function.isym
3186 && expr2->value.function.isym->id == GFC_ISYM_CONVERSION) 3785 && expr2->value.function.isym->id == GFC_ISYM_CONVERSION)
3187 expr2 = expr2->value.function.actual->expr; 3786 expr2 = expr2->value.function.actual->expr;
3188 3787
3196 gfc_add_block_to_block (&block, &lse.pre); 3795 gfc_add_block_to_block (&block, &lse.pre);
3197 type = TREE_TYPE (lse.expr); 3796 type = TREE_TYPE (lse.expr);
3198 lhsaddr = gfc_build_addr_expr (NULL, lse.expr); 3797 lhsaddr = gfc_build_addr_expr (NULL, lse.expr);
3199 3798
3200 x = build1 (OMP_ATOMIC_READ, type, lhsaddr); 3799 x = build1 (OMP_ATOMIC_READ, type, lhsaddr);
3201 OMP_ATOMIC_SEQ_CST (x) = seq_cst; 3800 OMP_ATOMIC_MEMORY_ORDER (x) = mo;
3202 x = convert (TREE_TYPE (vse.expr), x); 3801 x = convert (TREE_TYPE (vse.expr), x);
3203 gfc_add_modify (&block, vse.expr, x); 3802 gfc_add_modify (&block, vse.expr, x);
3204 3803
3205 gfc_add_block_to_block (&block, &lse.pre); 3804 gfc_add_block_to_block (&block, &lse.pre);
3206 gfc_add_block_to_block (&block, &rse.pre); 3805 gfc_add_block_to_block (&block, &rse.pre);
3396 gfc_add_block_to_block (&block, &rse.pre); 3995 gfc_add_block_to_block (&block, &rse.pre);
3397 3996
3398 if (aop == OMP_ATOMIC) 3997 if (aop == OMP_ATOMIC)
3399 { 3998 {
3400 x = build2_v (OMP_ATOMIC, lhsaddr, convert (type, x)); 3999 x = build2_v (OMP_ATOMIC, lhsaddr, convert (type, x));
3401 OMP_ATOMIC_SEQ_CST (x) = seq_cst; 4000 OMP_ATOMIC_MEMORY_ORDER (x) = mo;
3402 gfc_add_expr_to_block (&block, x); 4001 gfc_add_expr_to_block (&block, x);
3403 } 4002 }
3404 else 4003 else
3405 { 4004 {
3406 if (aop == OMP_ATOMIC_CAPTURE_NEW) 4005 if (aop == OMP_ATOMIC_CAPTURE_NEW)
3419 gfc_init_se (&lse, NULL); 4018 gfc_init_se (&lse, NULL);
3420 gfc_conv_expr (&lse, expr2); 4019 gfc_conv_expr (&lse, expr2);
3421 gfc_add_block_to_block (&block, &lse.pre); 4020 gfc_add_block_to_block (&block, &lse.pre);
3422 } 4021 }
3423 x = build2 (aop, type, lhsaddr, convert (type, x)); 4022 x = build2 (aop, type, lhsaddr, convert (type, x));
3424 OMP_ATOMIC_SEQ_CST (x) = seq_cst; 4023 OMP_ATOMIC_MEMORY_ORDER (x) = mo;
3425 x = convert (TREE_TYPE (vse.expr), x); 4024 x = convert (TREE_TYPE (vse.expr), x);
3426 gfc_add_modify (&block, vse.expr, x); 4025 gfc_add_modify (&block, vse.expr, x);
3427 } 4026 }
3428 4027
3429 return gfc_finish_block (&block); 4028 return gfc_finish_block (&block);
3859 doacross_steps = saved_doacross_steps; 4458 doacross_steps = saved_doacross_steps;
3860 4459
3861 return gfc_finish_block (&block); 4460 return gfc_finish_block (&block);
3862 } 4461 }
3863 4462
3864 /* parallel loop and kernels loop. */ 4463 /* Translate combined OpenACC 'parallel loop', 'kernels loop', 'serial loop'
4464 construct. */
4465
3865 static tree 4466 static tree
3866 gfc_trans_oacc_combined_directive (gfc_code *code) 4467 gfc_trans_oacc_combined_directive (gfc_code *code)
3867 { 4468 {
3868 stmtblock_t block, *pblock = NULL; 4469 stmtblock_t block, *pblock = NULL;
3869 gfc_omp_clauses construct_clauses, loop_clauses; 4470 gfc_omp_clauses construct_clauses, loop_clauses;
3870 tree stmt, oacc_clauses = NULL_TREE; 4471 tree stmt, oacc_clauses = NULL_TREE;
3871 enum tree_code construct_code; 4472 enum tree_code construct_code;
4473 location_t loc = input_location;
3872 4474
3873 switch (code->op) 4475 switch (code->op)
3874 { 4476 {
3875 case EXEC_OACC_PARALLEL_LOOP: 4477 case EXEC_OACC_PARALLEL_LOOP:
3876 construct_code = OACC_PARALLEL; 4478 construct_code = OACC_PARALLEL;
3877 break; 4479 break;
3878 case EXEC_OACC_KERNELS_LOOP: 4480 case EXEC_OACC_KERNELS_LOOP:
3879 construct_code = OACC_KERNELS; 4481 construct_code = OACC_KERNELS;
4482 break;
4483 case EXEC_OACC_SERIAL_LOOP:
4484 construct_code = OACC_SERIAL;
3880 break; 4485 break;
3881 default: 4486 default:
3882 gcc_unreachable (); 4487 gcc_unreachable ();
3883 } 4488 }
3884 4489
3928 if (!loop_clauses.seq) 4533 if (!loop_clauses.seq)
3929 pblock = &block; 4534 pblock = &block;
3930 else 4535 else
3931 pushlevel (); 4536 pushlevel ();
3932 stmt = gfc_trans_omp_do (code, EXEC_OACC_LOOP, pblock, &loop_clauses, NULL); 4537 stmt = gfc_trans_omp_do (code, EXEC_OACC_LOOP, pblock, &loop_clauses, NULL);
4538 protected_set_expr_location (stmt, loc);
3933 if (TREE_CODE (stmt) != BIND_EXPR) 4539 if (TREE_CODE (stmt) != BIND_EXPR)
3934 stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0)); 4540 stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
3935 else 4541 else
3936 poplevel (0, 0); 4542 poplevel (0, 0);
3937 stmt = build2_loc (input_location, construct_code, void_type_node, stmt, 4543 stmt = build2_loc (loc, construct_code, void_type_node, stmt, oacc_clauses);
3938 oacc_clauses);
3939 gfc_add_expr_to_block (&block, stmt); 4544 gfc_add_expr_to_block (&block, stmt);
3940 return gfc_finish_block (&block); 4545 return gfc_finish_block (&block);
3941 } 4546 }
3942 4547
3943 static tree 4548 static tree
4584 } 5189 }
4585 5190
4586 static tree 5191 static tree
4587 gfc_trans_omp_taskgroup (gfc_code *code) 5192 gfc_trans_omp_taskgroup (gfc_code *code)
4588 { 5193 {
4589 tree stmt = gfc_trans_code (code->block->next); 5194 tree body = gfc_trans_code (code->block->next);
4590 return build1_loc (input_location, OMP_TASKGROUP, void_type_node, stmt); 5195 tree stmt = make_node (OMP_TASKGROUP);
5196 TREE_TYPE (stmt) = void_type_node;
5197 OMP_TASKGROUP_BODY (stmt) = body;
5198 OMP_TASKGROUP_CLAUSES (stmt) = NULL_TREE;
5199 return stmt;
4591 } 5200 }
4592 5201
4593 static tree 5202 static tree
4594 gfc_trans_omp_taskwait (void) 5203 gfc_trans_omp_taskwait (void)
4595 { 5204 {
4686 { 5295 {
4687 clausesa = clausesa_buf; 5296 clausesa = clausesa_buf;
4688 gfc_split_omp_clauses (code, clausesa); 5297 gfc_split_omp_clauses (code, clausesa);
4689 } 5298 }
4690 if (flag_openmp) 5299 if (flag_openmp)
4691 omp_clauses 5300 {
4692 = chainon (omp_clauses, 5301 omp_clauses
4693 gfc_trans_omp_clauses (&block, &clausesa[GFC_OMP_SPLIT_TEAMS], 5302 = chainon (omp_clauses,
4694 code->loc)); 5303 gfc_trans_omp_clauses (&block,
5304 &clausesa[GFC_OMP_SPLIT_TEAMS],
5305 code->loc));
5306 pushlevel ();
5307 }
4695 switch (code->op) 5308 switch (code->op)
4696 { 5309 {
4697 case EXEC_OMP_TARGET_TEAMS: 5310 case EXEC_OMP_TARGET_TEAMS:
4698 case EXEC_OMP_TEAMS: 5311 case EXEC_OMP_TEAMS:
4699 stmt = gfc_trans_omp_code (code->block->next, true); 5312 stmt = gfc_trans_omp_code (code->block->next, true);
4709 stmt = gfc_trans_omp_distribute (code, clausesa); 5322 stmt = gfc_trans_omp_distribute (code, clausesa);
4710 break; 5323 break;
4711 } 5324 }
4712 if (flag_openmp) 5325 if (flag_openmp)
4713 { 5326 {
5327 stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
4714 stmt = build2_loc (input_location, OMP_TEAMS, void_type_node, stmt, 5328 stmt = build2_loc (input_location, OMP_TEAMS, void_type_node, stmt,
4715 omp_clauses); 5329 omp_clauses);
4716 if (combined) 5330 if (combined)
4717 OMP_TEAMS_COMBINED (stmt) = 1; 5331 OMP_TEAMS_COMBINED (stmt) = 1;
4718 } 5332 }
4742 break; 5356 break;
4743 case EXEC_OMP_TARGET_PARALLEL: 5357 case EXEC_OMP_TARGET_PARALLEL:
4744 { 5358 {
4745 stmtblock_t iblock; 5359 stmtblock_t iblock;
4746 5360
5361 pushlevel ();
4747 gfc_start_block (&iblock); 5362 gfc_start_block (&iblock);
4748 tree inner_clauses 5363 tree inner_clauses
4749 = gfc_trans_omp_clauses (&block, &clausesa[GFC_OMP_SPLIT_PARALLEL], 5364 = gfc_trans_omp_clauses (&block, &clausesa[GFC_OMP_SPLIT_PARALLEL],
4750 code->loc); 5365 code->loc);
4751 stmt = gfc_trans_omp_code (code->block->next, true); 5366 stmt = gfc_trans_omp_code (code->block->next, true);
5104 { 5719 {
5105 switch (code->op) 5720 switch (code->op)
5106 { 5721 {
5107 case EXEC_OACC_PARALLEL_LOOP: 5722 case EXEC_OACC_PARALLEL_LOOP:
5108 case EXEC_OACC_KERNELS_LOOP: 5723 case EXEC_OACC_KERNELS_LOOP:
5724 case EXEC_OACC_SERIAL_LOOP:
5109 return gfc_trans_oacc_combined_directive (code); 5725 return gfc_trans_oacc_combined_directive (code);
5110 case EXEC_OACC_PARALLEL: 5726 case EXEC_OACC_PARALLEL:
5111 case EXEC_OACC_KERNELS: 5727 case EXEC_OACC_KERNELS:
5728 case EXEC_OACC_SERIAL:
5112 case EXEC_OACC_DATA: 5729 case EXEC_OACC_DATA:
5113 case EXEC_OACC_HOST_DATA: 5730 case EXEC_OACC_HOST_DATA:
5114 return gfc_trans_oacc_construct (code); 5731 return gfc_trans_oacc_construct (code);
5115 case EXEC_OACC_LOOP: 5732 case EXEC_OACC_LOOP:
5116 return gfc_trans_omp_do (code, code->op, NULL, code->ext.omp_clauses, 5733 return gfc_trans_omp_do (code, code->op, NULL, code->ext.omp_clauses,