1 /* This file contains routines to construct OpenACC and OpenMP constructs,
2 called from parsing in the C and C++ front ends.
4 Copyright (C) 2005-2020 Free Software Foundation, Inc.
5 Contributed by Richard Henderson <rth@redhat.com>,
6 Diego Novillo <dnovillo@redhat.com>.
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 3, or (at your option) any later
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING3. If not see
22 <http://www.gnu.org/licenses/>. */
26 #include "coretypes.h"
29 #include "gimple-expr.h"
31 #include "stringpool.h"
32 #include "omp-general.h"
33 #include "gomp-constants.h"
37 #include "langhooks.h"
40 /* Complete a #pragma oacc wait construct. LOC is the location of
44 c_finish_oacc_wait (location_t loc
, tree parms
, tree clauses
)
46 const int nparms
= list_length (parms
);
48 vec
<tree
, va_gc
> *args
;
50 vec_alloc (args
, nparms
+ 2);
51 stmt
= builtin_decl_explicit (BUILT_IN_GOACC_WAIT
);
53 if (omp_find_clause (clauses
, OMP_CLAUSE_ASYNC
))
54 t
= OMP_CLAUSE_ASYNC_EXPR (clauses
);
56 t
= build_int_cst (integer_type_node
, GOMP_ASYNC_SYNC
);
59 args
->quick_push (build_int_cst (integer_type_node
, nparms
));
61 for (t
= parms
; t
; t
= TREE_CHAIN (t
))
63 if (TREE_CODE (OMP_CLAUSE_WAIT_EXPR (t
)) == INTEGER_CST
)
64 args
->quick_push (build_int_cst (integer_type_node
,
65 TREE_INT_CST_LOW (OMP_CLAUSE_WAIT_EXPR (t
))));
67 args
->quick_push (OMP_CLAUSE_WAIT_EXPR (t
));
70 stmt
= build_call_expr_loc_vec (loc
, stmt
, args
);
77 /* Complete a #pragma omp master construct. STMT is the structured-block
78 that follows the pragma. LOC is the location of the #pragma. */
81 c_finish_omp_master (location_t loc
, tree stmt
)
83 tree t
= add_stmt (build1 (OMP_MASTER
, void_type_node
, stmt
));
84 SET_EXPR_LOCATION (t
, loc
);
88 /* Complete a #pragma omp taskgroup construct. BODY is the structured-block
89 that follows the pragma. LOC is the location of the #pragma. */
92 c_finish_omp_taskgroup (location_t loc
, tree body
, tree clauses
)
94 tree stmt
= make_node (OMP_TASKGROUP
);
95 TREE_TYPE (stmt
) = void_type_node
;
96 OMP_TASKGROUP_BODY (stmt
) = body
;
97 OMP_TASKGROUP_CLAUSES (stmt
) = clauses
;
98 SET_EXPR_LOCATION (stmt
, loc
);
99 return add_stmt (stmt
);
102 /* Complete a #pragma omp critical construct. BODY is the structured-block
103 that follows the pragma, NAME is the identifier in the pragma, or null
104 if it was omitted. LOC is the location of the #pragma. */
107 c_finish_omp_critical (location_t loc
, tree body
, tree name
, tree clauses
)
109 gcc_assert (!clauses
|| OMP_CLAUSE_CODE (clauses
) == OMP_CLAUSE_HINT
);
110 if (name
== NULL_TREE
111 && clauses
!= NULL_TREE
112 && integer_nonzerop (OMP_CLAUSE_HINT_EXPR (clauses
)))
114 error_at (OMP_CLAUSE_LOCATION (clauses
),
115 "%<#pragma omp critical%> with %<hint%> clause requires "
116 "a name, except when %<omp_sync_hint_none%> is used");
117 return error_mark_node
;
120 tree stmt
= make_node (OMP_CRITICAL
);
121 TREE_TYPE (stmt
) = void_type_node
;
122 OMP_CRITICAL_BODY (stmt
) = body
;
123 OMP_CRITICAL_NAME (stmt
) = name
;
124 OMP_CRITICAL_CLAUSES (stmt
) = clauses
;
125 SET_EXPR_LOCATION (stmt
, loc
);
126 return add_stmt (stmt
);
129 /* Complete a #pragma omp ordered construct. STMT is the structured-block
130 that follows the pragma. LOC is the location of the #pragma. */
133 c_finish_omp_ordered (location_t loc
, tree clauses
, tree stmt
)
135 tree t
= make_node (OMP_ORDERED
);
136 TREE_TYPE (t
) = void_type_node
;
137 OMP_ORDERED_BODY (t
) = stmt
;
138 if (!flag_openmp
/* flag_openmp_simd */
139 && (OMP_CLAUSE_CODE (clauses
) != OMP_CLAUSE_SIMD
140 || OMP_CLAUSE_CHAIN (clauses
)))
141 clauses
= build_omp_clause (loc
, OMP_CLAUSE_SIMD
);
142 OMP_ORDERED_CLAUSES (t
) = clauses
;
143 SET_EXPR_LOCATION (t
, loc
);
148 /* Complete a #pragma omp barrier construct. LOC is the location of
152 c_finish_omp_barrier (location_t loc
)
156 x
= builtin_decl_explicit (BUILT_IN_GOMP_BARRIER
);
157 x
= build_call_expr_loc (loc
, x
, 0);
162 /* Complete a #pragma omp taskwait construct. LOC is the location of the
166 c_finish_omp_taskwait (location_t loc
)
170 x
= builtin_decl_explicit (BUILT_IN_GOMP_TASKWAIT
);
171 x
= build_call_expr_loc (loc
, x
, 0);
176 /* Complete a #pragma omp taskyield construct. LOC is the location of the
180 c_finish_omp_taskyield (location_t loc
)
184 x
= builtin_decl_explicit (BUILT_IN_GOMP_TASKYIELD
);
185 x
= build_call_expr_loc (loc
, x
, 0);
190 /* Complete a #pragma omp atomic construct. For CODE OMP_ATOMIC
191 the expression to be implemented atomically is LHS opcode= RHS.
192 For OMP_ATOMIC_READ V = LHS, for OMP_ATOMIC_CAPTURE_{NEW,OLD} LHS
193 opcode= RHS with the new or old content of LHS returned.
194 LOC is the location of the atomic statement. The value returned
195 is either error_mark_node (if the construct was erroneous) or an
196 OMP_ATOMIC* node which should be added to the current statement
197 tree with add_stmt. If TEST is set, avoid calling save_expr
198 or create_tmp_var*. */
201 c_finish_omp_atomic (location_t loc
, enum tree_code code
,
202 enum tree_code opcode
, tree lhs
, tree rhs
,
203 tree v
, tree lhs1
, tree rhs1
, bool swapped
,
204 enum omp_memory_order memory_order
, bool test
)
206 tree x
, type
, addr
, pre
= NULL_TREE
;
207 HOST_WIDE_INT bitpos
= 0, bitsize
= 0;
209 if (lhs
== error_mark_node
|| rhs
== error_mark_node
210 || v
== error_mark_node
|| lhs1
== error_mark_node
211 || rhs1
== error_mark_node
)
212 return error_mark_node
;
214 /* ??? According to one reading of the OpenMP spec, complex type are
215 supported, but there are no atomic stores for any architecture.
216 But at least icc 9.0 doesn't support complex types here either.
217 And lets not even talk about vector types... */
218 type
= TREE_TYPE (lhs
);
219 if (!INTEGRAL_TYPE_P (type
)
220 && !POINTER_TYPE_P (type
)
221 && !SCALAR_FLOAT_TYPE_P (type
))
223 error_at (loc
, "invalid expression type for %<#pragma omp atomic%>");
224 return error_mark_node
;
226 if (TYPE_ATOMIC (type
))
228 error_at (loc
, "%<_Atomic%> expression in %<#pragma omp atomic%>");
229 return error_mark_node
;
232 if (opcode
== RDIV_EXPR
)
233 opcode
= TRUNC_DIV_EXPR
;
235 /* ??? Validate that rhs does not overlap lhs. */
237 if (TREE_CODE (lhs
) == COMPONENT_REF
238 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == FIELD_DECL
239 && DECL_C_BIT_FIELD (TREE_OPERAND (lhs
, 1))
240 && DECL_BIT_FIELD_REPRESENTATIVE (TREE_OPERAND (lhs
, 1)))
242 tree field
= TREE_OPERAND (lhs
, 1);
243 tree repr
= DECL_BIT_FIELD_REPRESENTATIVE (field
);
244 if (tree_fits_uhwi_p (DECL_FIELD_OFFSET (field
))
245 && tree_fits_uhwi_p (DECL_FIELD_OFFSET (repr
)))
246 bitpos
= (tree_to_uhwi (DECL_FIELD_OFFSET (field
))
247 - tree_to_uhwi (DECL_FIELD_OFFSET (repr
))) * BITS_PER_UNIT
;
250 bitpos
+= (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (field
))
251 - tree_to_uhwi (DECL_FIELD_BIT_OFFSET (repr
)));
252 gcc_assert (tree_fits_shwi_p (DECL_SIZE (field
)));
253 bitsize
= tree_to_shwi (DECL_SIZE (field
));
255 type
= TREE_TYPE (repr
);
256 lhs
= build3 (COMPONENT_REF
, TREE_TYPE (repr
), TREE_OPERAND (lhs
, 0),
257 repr
, TREE_OPERAND (lhs
, 2));
260 /* Take and save the address of the lhs. From then on we'll reference it
262 addr
= build_unary_op (loc
, ADDR_EXPR
, lhs
, false);
263 if (addr
== error_mark_node
)
264 return error_mark_node
;
266 addr
= save_expr (addr
);
268 && TREE_CODE (addr
) != SAVE_EXPR
269 && (TREE_CODE (addr
) != ADDR_EXPR
270 || !VAR_P (TREE_OPERAND (addr
, 0))))
272 /* Make sure LHS is simple enough so that goa_lhs_expr_p can recognize
273 it even after unsharing function body. */
274 tree var
= create_tmp_var_raw (TREE_TYPE (addr
));
275 DECL_CONTEXT (var
) = current_function_decl
;
276 addr
= build4 (TARGET_EXPR
, TREE_TYPE (addr
), var
, addr
, NULL
, NULL
);
279 lhs
= build_indirect_ref (loc
, addr
, RO_NULL
);
282 if (code
== OMP_ATOMIC_READ
)
284 x
= build1 (OMP_ATOMIC_READ
, type
, addr
);
285 SET_EXPR_LOCATION (x
, loc
);
286 OMP_ATOMIC_MEMORY_ORDER (x
) = memory_order
;
288 x
= build3_loc (loc
, BIT_FIELD_REF
, TREE_TYPE (blhs
), x
,
289 bitsize_int (bitsize
), bitsize_int (bitpos
));
290 return build_modify_expr (loc
, v
, NULL_TREE
, NOP_EXPR
,
294 /* There are lots of warnings, errors, and conversions that need to happen
295 in the course of interpreting a statement. Use the normal mechanisms
296 to do this, and then take it apart again. */
299 lhs
= build3_loc (loc
, BIT_FIELD_REF
, TREE_TYPE (blhs
), lhs
,
300 bitsize_int (bitsize
), bitsize_int (bitpos
));
302 rhs
= build_binary_op (loc
, opcode
, rhs
, lhs
, true);
303 else if (opcode
!= NOP_EXPR
)
304 rhs
= build_binary_op (loc
, opcode
, lhs
, rhs
, true);
309 rhs
= build_binary_op (loc
, opcode
, rhs
, lhs
, true);
312 bool save
= in_late_binary_op
;
313 in_late_binary_op
= true;
314 x
= build_modify_expr (loc
, blhs
? blhs
: lhs
, NULL_TREE
, opcode
,
315 loc
, rhs
, NULL_TREE
);
316 in_late_binary_op
= save
;
317 if (x
== error_mark_node
)
318 return error_mark_node
;
319 if (TREE_CODE (x
) == COMPOUND_EXPR
)
321 pre
= TREE_OPERAND (x
, 0);
322 gcc_assert (TREE_CODE (pre
) == SAVE_EXPR
|| tree_invariant_p (pre
));
323 x
= TREE_OPERAND (x
, 1);
325 gcc_assert (TREE_CODE (x
) == MODIFY_EXPR
);
326 rhs
= TREE_OPERAND (x
, 1);
329 rhs
= build3_loc (loc
, BIT_INSERT_EXPR
, type
, new_lhs
,
330 rhs
, bitsize_int (bitpos
));
332 /* Punt the actual generation of atomic operations to common code. */
333 if (code
== OMP_ATOMIC
)
334 type
= void_type_node
;
335 x
= build2 (code
, type
, addr
, rhs
);
336 SET_EXPR_LOCATION (x
, loc
);
337 OMP_ATOMIC_MEMORY_ORDER (x
) = memory_order
;
339 /* Generally it is hard to prove lhs1 and lhs are the same memory
340 location, just diagnose different variables. */
347 if (code
== OMP_ATOMIC
)
348 error_at (loc
, "%<#pragma omp atomic update%> uses two different "
349 "variables for memory");
351 error_at (loc
, "%<#pragma omp atomic capture%> uses two different "
352 "variables for memory");
353 return error_mark_node
;
358 && TREE_CODE (lhs1
) == COMPONENT_REF
359 && TREE_CODE (TREE_OPERAND (lhs1
, 1)) == FIELD_DECL
360 && DECL_C_BIT_FIELD (TREE_OPERAND (lhs1
, 1))
361 && DECL_BIT_FIELD_REPRESENTATIVE (TREE_OPERAND (lhs1
, 1)))
363 tree field
= TREE_OPERAND (lhs1
, 1);
364 tree repr
= DECL_BIT_FIELD_REPRESENTATIVE (field
);
365 lhs1
= build3 (COMPONENT_REF
, TREE_TYPE (repr
), TREE_OPERAND (lhs1
, 0),
366 repr
, TREE_OPERAND (lhs1
, 2));
370 && TREE_CODE (rhs1
) == COMPONENT_REF
371 && TREE_CODE (TREE_OPERAND (rhs1
, 1)) == FIELD_DECL
372 && DECL_C_BIT_FIELD (TREE_OPERAND (rhs1
, 1))
373 && DECL_BIT_FIELD_REPRESENTATIVE (TREE_OPERAND (rhs1
, 1)))
375 tree field
= TREE_OPERAND (rhs1
, 1);
376 tree repr
= DECL_BIT_FIELD_REPRESENTATIVE (field
);
377 rhs1
= build3 (COMPONENT_REF
, TREE_TYPE (repr
), TREE_OPERAND (rhs1
, 0),
378 repr
, TREE_OPERAND (rhs1
, 2));
381 if (code
!= OMP_ATOMIC
)
383 /* Generally it is hard to prove lhs1 and lhs are the same memory
384 location, just diagnose different variables. */
385 if (lhs1
&& VAR_P (lhs1
) && VAR_P (orig_lhs
))
387 if (lhs1
!= orig_lhs
&& !test
)
389 error_at (loc
, "%<#pragma omp atomic capture%> uses two "
390 "different variables for memory");
391 return error_mark_node
;
396 x
= build3_loc (loc
, BIT_FIELD_REF
, TREE_TYPE (blhs
), x
,
397 bitsize_int (bitsize
), bitsize_int (bitpos
));
398 type
= TREE_TYPE (blhs
);
400 x
= build_modify_expr (loc
, v
, NULL_TREE
, NOP_EXPR
,
402 if (rhs1
&& rhs1
!= orig_lhs
)
404 tree rhs1addr
= build_unary_op (loc
, ADDR_EXPR
, rhs1
, false);
405 if (rhs1addr
== error_mark_node
)
406 return error_mark_node
;
407 x
= omit_one_operand_loc (loc
, type
, x
, rhs1addr
);
409 if (lhs1
&& lhs1
!= orig_lhs
)
411 tree lhs1addr
= build_unary_op (loc
, ADDR_EXPR
, lhs1
, false);
412 if (lhs1addr
== error_mark_node
)
413 return error_mark_node
;
414 if (code
== OMP_ATOMIC_CAPTURE_OLD
)
415 x
= omit_one_operand_loc (loc
, type
, x
, lhs1addr
);
420 x
= omit_two_operands_loc (loc
, type
, x
, x
, lhs1addr
);
424 else if (rhs1
&& rhs1
!= orig_lhs
)
426 tree rhs1addr
= build_unary_op (loc
, ADDR_EXPR
, rhs1
, false);
427 if (rhs1addr
== error_mark_node
)
428 return error_mark_node
;
429 x
= omit_one_operand_loc (loc
, type
, x
, rhs1addr
);
433 x
= omit_one_operand_loc (loc
, type
, x
, pre
);
438 /* Return true if TYPE is the implementation's omp_depend_t. */
441 c_omp_depend_t_p (tree type
)
443 type
= TYPE_MAIN_VARIANT (type
);
444 return (TREE_CODE (type
) == RECORD_TYPE
446 && ((TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
447 ? DECL_NAME (TYPE_NAME (type
)) : TYPE_NAME (type
))
448 == get_identifier ("omp_depend_t"))
449 && (!TYPE_CONTEXT (type
)
450 || TREE_CODE (TYPE_CONTEXT (type
)) == TRANSLATION_UNIT_DECL
)
451 && COMPLETE_TYPE_P (type
)
452 && TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
453 && !compare_tree_int (TYPE_SIZE (type
),
454 2 * tree_to_uhwi (TYPE_SIZE (ptr_type_node
))));
458 /* Complete a #pragma omp depobj construct. LOC is the location of the
462 c_finish_omp_depobj (location_t loc
, tree depobj
,
463 enum omp_clause_depend_kind kind
, tree clause
)
466 if (!error_operand_p (depobj
))
468 if (!c_omp_depend_t_p (TREE_TYPE (depobj
)))
470 error_at (EXPR_LOC_OR_LOC (depobj
, loc
),
471 "type of %<depobj%> expression is not %<omp_depend_t%>");
472 depobj
= error_mark_node
;
474 else if (TYPE_READONLY (TREE_TYPE (depobj
)))
476 error_at (EXPR_LOC_OR_LOC (depobj
, loc
),
477 "%<const%> qualified %<depobj%> expression");
478 depobj
= error_mark_node
;
482 depobj
= error_mark_node
;
484 if (clause
== error_mark_node
)
489 gcc_assert (TREE_CODE (clause
) == OMP_CLAUSE
490 && OMP_CLAUSE_CODE (clause
) == OMP_CLAUSE_DEPEND
);
491 if (OMP_CLAUSE_CHAIN (clause
))
492 error_at (OMP_CLAUSE_LOCATION (clause
),
493 "more than one locator in %<depend%> clause on %<depobj%> "
495 switch (OMP_CLAUSE_DEPEND_KIND (clause
))
497 case OMP_CLAUSE_DEPEND_DEPOBJ
:
498 error_at (OMP_CLAUSE_LOCATION (clause
),
499 "%<depobj%> dependence type specified in %<depend%> "
500 "clause on %<depobj%> construct");
502 case OMP_CLAUSE_DEPEND_SOURCE
:
503 case OMP_CLAUSE_DEPEND_SINK
:
504 error_at (OMP_CLAUSE_LOCATION (clause
),
505 "%<depend(%s)%> is only allowed in %<omp ordered%>",
506 OMP_CLAUSE_DEPEND_KIND (clause
) == OMP_CLAUSE_DEPEND_SOURCE
507 ? "source" : "sink");
509 case OMP_CLAUSE_DEPEND_IN
:
510 case OMP_CLAUSE_DEPEND_OUT
:
511 case OMP_CLAUSE_DEPEND_INOUT
:
512 case OMP_CLAUSE_DEPEND_MUTEXINOUTSET
:
513 kind
= OMP_CLAUSE_DEPEND_KIND (clause
);
514 t
= OMP_CLAUSE_DECL (clause
);
516 if (TREE_CODE (t
) == TREE_LIST
518 && TREE_CODE (TREE_PURPOSE (t
)) == TREE_VEC
)
520 error_at (OMP_CLAUSE_LOCATION (clause
),
521 "%<iterator%> modifier may not be specified on "
522 "%<depobj%> construct");
525 if (TREE_CODE (t
) == COMPOUND_EXPR
)
527 tree t1
= build_fold_addr_expr (TREE_OPERAND (t
, 1));
528 t
= build2 (COMPOUND_EXPR
, TREE_TYPE (t1
), TREE_OPERAND (t
, 0),
532 t
= build_fold_addr_expr (t
);
539 gcc_assert (kind
!= OMP_CLAUSE_DEPEND_SOURCE
);
541 if (depobj
== error_mark_node
)
544 depobj
= build_fold_addr_expr_loc (EXPR_LOC_OR_LOC (depobj
, loc
), depobj
);
546 = build_pointer_type_for_mode (ptr_type_node
, TYPE_MODE (ptr_type_node
),
548 depobj
= fold_convert (dtype
, depobj
);
552 depobj
= save_expr (depobj
);
553 r
= build_indirect_ref (loc
, depobj
, RO_UNARY_STAR
);
554 add_stmt (build2 (MODIFY_EXPR
, void_type_node
, r
, t
));
559 case OMP_CLAUSE_DEPEND_IN
:
562 case OMP_CLAUSE_DEPEND_OUT
:
565 case OMP_CLAUSE_DEPEND_INOUT
:
566 k
= GOMP_DEPEND_INOUT
;
568 case OMP_CLAUSE_DEPEND_MUTEXINOUTSET
:
569 k
= GOMP_DEPEND_MUTEXINOUTSET
;
571 case OMP_CLAUSE_DEPEND_LAST
:
577 t
= build_int_cst (ptr_type_node
, k
);
578 depobj
= build2_loc (loc
, POINTER_PLUS_EXPR
, TREE_TYPE (depobj
), depobj
,
579 TYPE_SIZE_UNIT (ptr_type_node
));
580 r
= build_indirect_ref (loc
, depobj
, RO_UNARY_STAR
);
581 add_stmt (build2 (MODIFY_EXPR
, void_type_node
, r
, t
));
585 /* Complete a #pragma omp flush construct. We don't do anything with
586 the variable list that the syntax allows. LOC is the location of
590 c_finish_omp_flush (location_t loc
, int mo
)
594 if (mo
== MEMMODEL_LAST
)
596 x
= builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE
);
597 x
= build_call_expr_loc (loc
, x
, 0);
601 x
= builtin_decl_explicit (BUILT_IN_ATOMIC_THREAD_FENCE
);
602 x
= build_call_expr_loc (loc
, x
, 1,
603 build_int_cst (integer_type_node
, mo
));
609 /* Check and canonicalize OMP_FOR increment expression.
610 Helper function for c_finish_omp_for. */
613 check_omp_for_incr_expr (location_t loc
, tree exp
, tree decl
)
617 if (!INTEGRAL_TYPE_P (TREE_TYPE (exp
))
618 || TYPE_PRECISION (TREE_TYPE (exp
)) < TYPE_PRECISION (TREE_TYPE (decl
)))
619 return error_mark_node
;
622 return build_int_cst (TREE_TYPE (exp
), 0);
624 switch (TREE_CODE (exp
))
627 t
= check_omp_for_incr_expr (loc
, TREE_OPERAND (exp
, 0), decl
);
628 if (t
!= error_mark_node
)
629 return fold_convert_loc (loc
, TREE_TYPE (exp
), t
);
632 t
= check_omp_for_incr_expr (loc
, TREE_OPERAND (exp
, 0), decl
);
633 if (t
!= error_mark_node
)
634 return fold_build2_loc (loc
, MINUS_EXPR
,
635 TREE_TYPE (exp
), t
, TREE_OPERAND (exp
, 1));
638 t
= check_omp_for_incr_expr (loc
, TREE_OPERAND (exp
, 0), decl
);
639 if (t
!= error_mark_node
)
640 return fold_build2_loc (loc
, PLUS_EXPR
,
641 TREE_TYPE (exp
), t
, TREE_OPERAND (exp
, 1));
642 t
= check_omp_for_incr_expr (loc
, TREE_OPERAND (exp
, 1), decl
);
643 if (t
!= error_mark_node
)
644 return fold_build2_loc (loc
, PLUS_EXPR
,
645 TREE_TYPE (exp
), TREE_OPERAND (exp
, 0), t
);
649 /* cp_build_modify_expr forces preevaluation of the RHS to make
650 sure that it is evaluated before the lvalue-rvalue conversion
651 is applied to the LHS. Reconstruct the original expression. */
652 tree op0
= TREE_OPERAND (exp
, 0);
653 if (TREE_CODE (op0
) == TARGET_EXPR
654 && !VOID_TYPE_P (TREE_TYPE (op0
)))
656 tree op1
= TREE_OPERAND (exp
, 1);
657 tree temp
= TARGET_EXPR_SLOT (op0
);
658 if (BINARY_CLASS_P (op1
)
659 && TREE_OPERAND (op1
, 1) == temp
)
661 op1
= copy_node (op1
);
662 TREE_OPERAND (op1
, 1) = TARGET_EXPR_INITIAL (op0
);
663 return check_omp_for_incr_expr (loc
, op1
, decl
);
672 return error_mark_node
;
675 /* If the OMP_FOR increment expression in INCR is of pointer type,
676 canonicalize it into an expression handled by gimplify_omp_for()
677 and return it. DECL is the iteration variable. */
680 c_omp_for_incr_canonicalize_ptr (location_t loc
, tree decl
, tree incr
)
682 if (POINTER_TYPE_P (TREE_TYPE (decl
))
683 && TREE_OPERAND (incr
, 1))
685 tree t
= fold_convert_loc (loc
,
686 sizetype
, TREE_OPERAND (incr
, 1));
688 if (TREE_CODE (incr
) == POSTDECREMENT_EXPR
689 || TREE_CODE (incr
) == PREDECREMENT_EXPR
)
690 t
= fold_build1_loc (loc
, NEGATE_EXPR
, sizetype
, t
);
691 t
= fold_build_pointer_plus (decl
, t
);
692 incr
= build2 (MODIFY_EXPR
, void_type_node
, decl
, t
);
697 /* Validate and generate OMP_FOR.
698 DECLV is a vector of iteration variables, for each collapsed loop.
700 ORIG_DECLV, if non-NULL, is a vector with the original iteration
701 variables (prior to any transformations, by say, C++ iterators).
703 INITV, CONDV and INCRV are vectors containing initialization
704 expressions, controlling predicates and increment expressions.
705 BODY is the body of the loop and PRE_BODY statements that go before
709 c_finish_omp_for (location_t locus
, enum tree_code code
, tree declv
,
710 tree orig_declv
, tree initv
, tree condv
, tree incrv
,
711 tree body
, tree pre_body
, bool final_p
)
717 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (initv
));
718 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (condv
));
719 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (incrv
));
720 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); i
++)
722 tree decl
= TREE_VEC_ELT (declv
, i
);
723 tree init
= TREE_VEC_ELT (initv
, i
);
724 tree cond
= TREE_VEC_ELT (condv
, i
);
725 tree incr
= TREE_VEC_ELT (incrv
, i
);
728 if (EXPR_HAS_LOCATION (init
))
729 elocus
= EXPR_LOCATION (init
);
731 /* Validate the iteration variable. */
732 if (!INTEGRAL_TYPE_P (TREE_TYPE (decl
))
733 && TREE_CODE (TREE_TYPE (decl
)) != POINTER_TYPE
)
735 error_at (elocus
, "invalid type for iteration variable %qE", decl
);
738 else if (TYPE_ATOMIC (TREE_TYPE (decl
)))
740 error_at (elocus
, "%<_Atomic%> iteration variable %qE", decl
);
742 /* _Atomic iterator confuses stuff too much, so we risk ICE
743 trying to diagnose it further. */
747 /* In the case of "for (int i = 0...)", init will be a decl. It should
748 have a DECL_INITIAL that we can turn into an assignment. */
751 elocus
= DECL_SOURCE_LOCATION (decl
);
753 init
= DECL_INITIAL (decl
);
756 error_at (elocus
, "%qE is not initialized", decl
);
757 init
= integer_zero_node
;
760 DECL_INITIAL (decl
) = NULL_TREE
;
762 init
= build_modify_expr (elocus
, decl
, NULL_TREE
, NOP_EXPR
,
763 /* FIXME diagnostics: This should
764 be the location of the INIT. */
769 if (init
!= error_mark_node
)
771 gcc_assert (TREE_CODE (init
) == MODIFY_EXPR
);
772 gcc_assert (TREE_OPERAND (init
, 0) == decl
);
775 if (cond
== NULL_TREE
)
777 error_at (elocus
, "missing controlling predicate");
782 bool cond_ok
= false;
784 /* E.g. C sizeof (vla) could add COMPOUND_EXPRs with
785 evaluation of the vla VAR_DECL. We need to readd
786 them to the non-decl operand. See PR45784. */
787 while (TREE_CODE (cond
) == COMPOUND_EXPR
)
788 cond
= TREE_OPERAND (cond
, 1);
790 if (EXPR_HAS_LOCATION (cond
))
791 elocus
= EXPR_LOCATION (cond
);
793 if (TREE_CODE (cond
) == LT_EXPR
794 || TREE_CODE (cond
) == LE_EXPR
795 || TREE_CODE (cond
) == GT_EXPR
796 || TREE_CODE (cond
) == GE_EXPR
797 || TREE_CODE (cond
) == NE_EXPR
798 || TREE_CODE (cond
) == EQ_EXPR
)
800 tree op0
= TREE_OPERAND (cond
, 0);
801 tree op1
= TREE_OPERAND (cond
, 1);
803 /* 2.5.1. The comparison in the condition is computed in
804 the type of DECL, otherwise the behavior is undefined.
810 according to ISO will be evaluated as:
815 if (TREE_CODE (op0
) == NOP_EXPR
816 && decl
== TREE_OPERAND (op0
, 0))
818 TREE_OPERAND (cond
, 0) = TREE_OPERAND (op0
, 0);
819 TREE_OPERAND (cond
, 1)
820 = fold_build1_loc (elocus
, NOP_EXPR
, TREE_TYPE (decl
),
821 TREE_OPERAND (cond
, 1));
823 else if (TREE_CODE (op1
) == NOP_EXPR
824 && decl
== TREE_OPERAND (op1
, 0))
826 TREE_OPERAND (cond
, 1) = TREE_OPERAND (op1
, 0);
827 TREE_OPERAND (cond
, 0)
828 = fold_build1_loc (elocus
, NOP_EXPR
, TREE_TYPE (decl
),
829 TREE_OPERAND (cond
, 0));
832 if (decl
== TREE_OPERAND (cond
, 0))
834 else if (decl
== TREE_OPERAND (cond
, 1))
837 swap_tree_comparison (TREE_CODE (cond
)));
838 TREE_OPERAND (cond
, 1) = TREE_OPERAND (cond
, 0);
839 TREE_OPERAND (cond
, 0) = decl
;
843 if (TREE_CODE (cond
) == NE_EXPR
844 || TREE_CODE (cond
) == EQ_EXPR
)
846 if (!INTEGRAL_TYPE_P (TREE_TYPE (decl
)))
848 if (code
== OACC_LOOP
|| TREE_CODE (cond
) == EQ_EXPR
)
851 else if (operand_equal_p (TREE_OPERAND (cond
, 1),
852 TYPE_MIN_VALUE (TREE_TYPE (decl
)),
854 TREE_SET_CODE (cond
, TREE_CODE (cond
) == NE_EXPR
855 ? GT_EXPR
: LE_EXPR
);
856 else if (operand_equal_p (TREE_OPERAND (cond
, 1),
857 TYPE_MAX_VALUE (TREE_TYPE (decl
)),
859 TREE_SET_CODE (cond
, TREE_CODE (cond
) == NE_EXPR
860 ? LT_EXPR
: GE_EXPR
);
861 else if (code
== OACC_LOOP
|| TREE_CODE (cond
) == EQ_EXPR
)
865 if (cond_ok
&& TREE_VEC_ELT (condv
, i
) != cond
)
867 tree ce
= NULL_TREE
, *pce
= &ce
;
868 tree type
= TREE_TYPE (TREE_OPERAND (cond
, 1));
869 for (tree c
= TREE_VEC_ELT (condv
, i
); c
!= cond
;
870 c
= TREE_OPERAND (c
, 1))
872 *pce
= build2 (COMPOUND_EXPR
, type
, TREE_OPERAND (c
, 0),
873 TREE_OPERAND (cond
, 1));
874 pce
= &TREE_OPERAND (*pce
, 1);
876 TREE_OPERAND (cond
, 1) = ce
;
877 TREE_VEC_ELT (condv
, i
) = cond
;
883 error_at (elocus
, "invalid controlling predicate");
888 if (incr
== NULL_TREE
)
890 error_at (elocus
, "missing increment expression");
895 bool incr_ok
= false;
897 if (EXPR_HAS_LOCATION (incr
))
898 elocus
= EXPR_LOCATION (incr
);
900 /* Check all the valid increment expressions: v++, v--, ++v, --v,
901 v = v + incr, v = incr + v and v = v - incr. */
902 switch (TREE_CODE (incr
))
904 case POSTINCREMENT_EXPR
:
905 case PREINCREMENT_EXPR
:
906 case POSTDECREMENT_EXPR
:
907 case PREDECREMENT_EXPR
:
908 if (TREE_OPERAND (incr
, 0) != decl
)
913 && TREE_CODE (cond
) == NE_EXPR
914 && TREE_CODE (TREE_TYPE (decl
)) == POINTER_TYPE
915 && TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl
)))
916 && (TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl
))))
919 /* For pointer to VLA, transform != into < or >
920 depending on whether incr is increment or decrement. */
921 if (TREE_CODE (incr
) == PREINCREMENT_EXPR
922 || TREE_CODE (incr
) == POSTINCREMENT_EXPR
)
923 TREE_SET_CODE (cond
, LT_EXPR
);
925 TREE_SET_CODE (cond
, GT_EXPR
);
927 incr
= c_omp_for_incr_canonicalize_ptr (elocus
, decl
, incr
);
931 if (TREE_CODE (TREE_OPERAND (incr
, 0)) != SAVE_EXPR
932 || TREE_CODE (TREE_OPERAND (incr
, 1)) != MODIFY_EXPR
)
934 incr
= TREE_OPERAND (incr
, 1);
937 if (TREE_OPERAND (incr
, 0) != decl
)
939 if (TREE_OPERAND (incr
, 1) == decl
)
941 if (TREE_CODE (TREE_OPERAND (incr
, 1)) == PLUS_EXPR
942 && (TREE_OPERAND (TREE_OPERAND (incr
, 1), 0) == decl
943 || TREE_OPERAND (TREE_OPERAND (incr
, 1), 1) == decl
))
945 else if ((TREE_CODE (TREE_OPERAND (incr
, 1)) == MINUS_EXPR
946 || (TREE_CODE (TREE_OPERAND (incr
, 1))
947 == POINTER_PLUS_EXPR
))
948 && TREE_OPERAND (TREE_OPERAND (incr
, 1), 0) == decl
)
952 tree t
= check_omp_for_incr_expr (elocus
,
953 TREE_OPERAND (incr
, 1),
955 if (t
!= error_mark_node
)
958 t
= build2 (PLUS_EXPR
, TREE_TYPE (decl
), decl
, t
);
959 incr
= build2 (MODIFY_EXPR
, void_type_node
, decl
, t
);
964 && TREE_CODE (cond
) == NE_EXPR
)
966 tree i
= TREE_OPERAND (incr
, 1);
967 i
= TREE_OPERAND (i
, TREE_OPERAND (i
, 0) == decl
);
968 i
= c_fully_fold (i
, false, NULL
);
970 && TREE_CODE (i
) != INTEGER_CST
)
972 else if (TREE_CODE (TREE_TYPE (decl
)) == POINTER_TYPE
)
975 = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl
)));
978 enum tree_code ccode
= GT_EXPR
;
979 unit
= c_fully_fold (unit
, false, NULL
);
980 i
= fold_convert (TREE_TYPE (unit
), i
);
981 if (operand_equal_p (unit
, i
, 0))
983 if (ccode
== GT_EXPR
)
985 i
= fold_unary (NEGATE_EXPR
, TREE_TYPE (i
), i
);
987 || !operand_equal_p (unit
, i
, 0))
990 "increment is not constant 1 or "
991 "-1 for %<!=%> condition");
995 if (TREE_CODE (unit
) != INTEGER_CST
)
996 /* For pointer to VLA, transform != into < or >
997 depending on whether the pointer is
998 incremented or decremented in each
1000 TREE_SET_CODE (cond
, ccode
);
1005 if (!integer_onep (i
) && !integer_minus_onep (i
))
1008 "increment is not constant 1 or -1 for"
1009 " %<!=%> condition");
1021 error_at (elocus
, "invalid increment expression");
1026 TREE_VEC_ELT (initv
, i
) = init
;
1027 TREE_VEC_ELT (incrv
, i
) = incr
;
1034 tree t
= make_node (code
);
1036 TREE_TYPE (t
) = void_type_node
;
1037 OMP_FOR_INIT (t
) = initv
;
1038 OMP_FOR_COND (t
) = condv
;
1039 OMP_FOR_INCR (t
) = incrv
;
1040 OMP_FOR_BODY (t
) = body
;
1041 OMP_FOR_PRE_BODY (t
) = pre_body
;
1042 OMP_FOR_ORIG_DECLS (t
) = orig_declv
;
1044 SET_EXPR_LOCATION (t
, locus
);
1049 /* Type for passing data in between c_omp_check_loop_iv and
1050 c_omp_check_loop_iv_r. */
1052 struct c_omp_check_loop_iv_data
1057 location_t stmt_loc
;
1058 location_t expr_loc
;
1062 hash_set
<tree
> *ppset
;
1065 /* Return -1 if DECL is not a loop iterator in loop nest D, otherwise
1066 return the index of the loop in which it is an iterator.
1067 Return TREE_VEC_LENGTH (d->declv) if it is a C++ range for iterator. */
1070 c_omp_is_loop_iterator (tree decl
, struct c_omp_check_loop_iv_data
*d
)
1072 for (int i
= 0; i
< TREE_VEC_LENGTH (d
->declv
); i
++)
1073 if (decl
== TREE_VEC_ELT (d
->declv
, i
)
1074 || (TREE_CODE (TREE_VEC_ELT (d
->declv
, i
)) == TREE_LIST
1075 && decl
== TREE_PURPOSE (TREE_VEC_ELT (d
->declv
, i
))))
1077 else if (TREE_CODE (TREE_VEC_ELT (d
->declv
, i
)) == TREE_LIST
1078 && TREE_CHAIN (TREE_VEC_ELT (d
->declv
, i
))
1079 && (TREE_CODE (TREE_CHAIN (TREE_VEC_ELT (d
->declv
, i
)))
1081 && decl
== TREE_VEC_ELT (TREE_CHAIN (TREE_VEC_ELT (d
->declv
,
1083 return TREE_VEC_LENGTH (d
->declv
);
1087 /* Helper function called via walk_tree, to diagnose uses
1088 of associated loop IVs inside of lb, b and incr expressions
1092 c_omp_check_loop_iv_r (tree
*tp
, int *walk_subtrees
, void *data
)
1094 struct c_omp_check_loop_iv_data
*d
1095 = (struct c_omp_check_loop_iv_data
*) data
;
1098 int idx
= c_omp_is_loop_iterator (*tp
, d
);
1102 if ((d
->kind
& 4) && idx
< d
->idx
)
1104 d
->maybe_nonrect
= true;
1108 if (d
->ppset
->add (*tp
))
1111 location_t loc
= d
->expr_loc
;
1112 if (loc
== UNKNOWN_LOCATION
)
1115 switch (d
->kind
& 3)
1118 error_at (loc
, "initializer expression refers to "
1119 "iteration variable %qD", *tp
);
1122 error_at (loc
, "condition expression refers to "
1123 "iteration variable %qD", *tp
);
1126 error_at (loc
, "increment expression refers to "
1127 "iteration variable %qD", *tp
);
1132 else if (d
->ppset
->add (*tp
))
1134 /* Don't walk dtors added by C++ wrap_cleanups_r. */
1135 else if (TREE_CODE (*tp
) == TRY_CATCH_EXPR
1136 && TRY_CATCH_IS_CLEANUP (*tp
))
1139 return walk_tree_1 (&TREE_OPERAND (*tp
, 0), c_omp_check_loop_iv_r
, data
,
1146 /* Check the allowed expressions for non-rectangular loop nest lb and b
1147 expressions. Return the outer var decl referenced in the expression. */
1150 c_omp_check_nonrect_loop_iv (tree
*tp
, struct c_omp_check_loop_iv_data
*d
,
1153 d
->maybe_nonrect
= false;
1157 hash_set
<tree
> pset
;
1158 hash_set
<tree
> *ppset
= d
->ppset
;
1162 if (TREE_CODE (t
) == TREE_VEC
1163 && TREE_VEC_LENGTH (t
) == 3
1164 && DECL_P (TREE_VEC_ELT (t
, 0))
1165 && c_omp_is_loop_iterator (TREE_VEC_ELT (t
, 0), d
) >= 0)
1168 walk_tree_1 (&TREE_VEC_ELT (t
, 1), c_omp_check_loop_iv_r
, d
, NULL
, lh
);
1169 walk_tree_1 (&TREE_VEC_ELT (t
, 1), c_omp_check_loop_iv_r
, d
, NULL
, lh
);
1171 return d
->fail
? NULL_TREE
: TREE_VEC_ELT (t
, 0);
1174 while (CONVERT_EXPR_P (t
))
1175 t
= TREE_OPERAND (t
, 0);
1177 tree a1
= t
, a2
= integer_zero_node
;
1178 bool neg_a1
= false, neg_a2
= false;
1179 switch (TREE_CODE (t
))
1183 a1
= TREE_OPERAND (t
, 0);
1184 a2
= TREE_OPERAND (t
, 1);
1185 while (CONVERT_EXPR_P (a1
))
1186 a1
= TREE_OPERAND (a1
, 0);
1187 while (CONVERT_EXPR_P (a2
))
1188 a2
= TREE_OPERAND (a2
, 0);
1189 if (DECL_P (a1
) && c_omp_is_loop_iterator (a1
, d
) >= 0)
1191 a2
= TREE_OPERAND (t
, 1);
1192 if (TREE_CODE (t
) == MINUS_EXPR
)
1197 if (DECL_P (a2
) && c_omp_is_loop_iterator (a2
, d
) >= 0)
1199 a1
= TREE_OPERAND (t
, 0);
1200 if (TREE_CODE (t
) == MINUS_EXPR
)
1206 if (TREE_CODE (a1
) == MULT_EXPR
&& TREE_CODE (a2
) == MULT_EXPR
)
1208 tree o1
= TREE_OPERAND (a1
, 0);
1209 tree o2
= TREE_OPERAND (a1
, 1);
1210 while (CONVERT_EXPR_P (o1
))
1211 o1
= TREE_OPERAND (o1
, 0);
1212 while (CONVERT_EXPR_P (o2
))
1213 o2
= TREE_OPERAND (o2
, 0);
1214 if ((DECL_P (o1
) && c_omp_is_loop_iterator (o1
, d
) >= 0)
1215 || (DECL_P (o2
) && c_omp_is_loop_iterator (o2
, d
) >= 0))
1217 a2
= TREE_OPERAND (t
, 1);
1218 if (TREE_CODE (t
) == MINUS_EXPR
)
1224 if (TREE_CODE (a2
) == MULT_EXPR
)
1226 a1
= TREE_OPERAND (t
, 0);
1227 if (TREE_CODE (t
) == MINUS_EXPR
)
1233 if (TREE_CODE (a1
) == MULT_EXPR
)
1235 a2
= TREE_OPERAND (t
, 1);
1236 if (TREE_CODE (t
) == MINUS_EXPR
)
1241 a2
= integer_zero_node
;
1247 a1
= integer_one_node
;
1248 if (TREE_CODE (t
) == MULT_EXPR
)
1250 tree o1
= TREE_OPERAND (t
, 0);
1251 tree o2
= TREE_OPERAND (t
, 1);
1252 while (CONVERT_EXPR_P (o1
))
1253 o1
= TREE_OPERAND (o1
, 0);
1254 while (CONVERT_EXPR_P (o2
))
1255 o2
= TREE_OPERAND (o2
, 0);
1256 if (DECL_P (o1
) && c_omp_is_loop_iterator (o1
, d
) >= 0)
1258 a1
= TREE_OPERAND (t
, 1);
1261 else if (DECL_P (o2
) && c_omp_is_loop_iterator (o2
, d
) >= 0)
1263 a1
= TREE_OPERAND (t
, 0);
1269 tree ret
= NULL_TREE
;
1270 if (DECL_P (t
) && c_omp_is_loop_iterator (t
, d
) >= 0)
1272 location_t loc
= d
->expr_loc
;
1273 if (loc
== UNKNOWN_LOCATION
)
1275 if (!lang_hooks
.types_compatible_p (TREE_TYPE (*tp
), TREE_TYPE (t
)))
1278 error_at (loc
, "outer iteration variable %qD used in initializer"
1279 " expression has type other than %qT",
1280 t
, TREE_TYPE (*tp
));
1282 error_at (loc
, "outer iteration variable %qD used in condition"
1283 " expression has type other than %qT",
1284 t
, TREE_TYPE (*tp
));
1287 else if (!INTEGRAL_TYPE_P (TREE_TYPE (a1
)))
1289 error_at (loc
, "outer iteration variable %qD multiplier expression"
1290 " %qE is not integral", t
, a1
);
1293 else if (!INTEGRAL_TYPE_P (TREE_TYPE (a2
)))
1295 error_at (loc
, "outer iteration variable %qD addend expression"
1296 " %qE is not integral", t
, a2
);
1301 walk_tree_1 (&a1
, c_omp_check_loop_iv_r
, d
, NULL
, lh
);
1302 walk_tree_1 (&a2
, c_omp_check_loop_iv_r
, d
, NULL
, lh
);
1306 a1
= fold_convert (TREE_TYPE (*tp
), a1
);
1307 a2
= fold_convert (TREE_TYPE (*tp
), a2
);
1309 a1
= fold_build1 (NEGATE_EXPR
, TREE_TYPE (a1
), a1
);
1311 a2
= fold_build1 (NEGATE_EXPR
, TREE_TYPE (a2
), a2
);
1313 *tp
= make_tree_vec (3);
1314 TREE_VEC_ELT (*tp
, 0) = t
;
1315 TREE_VEC_ELT (*tp
, 1) = a1
;
1316 TREE_VEC_ELT (*tp
, 2) = a2
;
1320 walk_tree_1 (&t
, c_omp_check_loop_iv_r
, d
, NULL
, lh
);
1326 /* Diagnose invalid references to loop iterators in lb, b and incr
1330 c_omp_check_loop_iv (tree stmt
, tree declv
, walk_tree_lh lh
)
1332 hash_set
<tree
> pset
;
1333 struct c_omp_check_loop_iv_data data
;
1338 data
.maybe_nonrect
= false;
1339 data
.stmt_loc
= EXPR_LOCATION (stmt
);
1342 for (i
= 0; i
< TREE_VEC_LENGTH (OMP_FOR_INIT (stmt
)); i
++)
1344 tree init
= TREE_VEC_ELT (OMP_FOR_INIT (stmt
), i
);
1345 gcc_assert (TREE_CODE (init
) == MODIFY_EXPR
);
1346 tree decl
= TREE_OPERAND (init
, 0);
1347 tree cond
= TREE_VEC_ELT (OMP_FOR_COND (stmt
), i
);
1348 gcc_assert (COMPARISON_CLASS_P (cond
));
1349 gcc_assert (TREE_OPERAND (cond
, 0) == decl
);
1350 tree incr
= TREE_VEC_ELT (OMP_FOR_INCR (stmt
), i
);
1351 data
.expr_loc
= EXPR_LOCATION (TREE_OPERAND (init
, 1));
1352 tree vec_outer1
= NULL_TREE
, vec_outer2
= NULL_TREE
;
1355 && (unsigned) c_omp_is_loop_iterator (decl
, &data
) < (unsigned) i
)
1357 location_t loc
= data
.expr_loc
;
1358 if (loc
== UNKNOWN_LOCATION
)
1359 loc
= data
.stmt_loc
;
1360 error_at (loc
, "the same loop iteration variables %qD used in "
1361 "multiple associated loops", decl
);
1364 /* Handle non-rectangular loop nests. */
1365 if (TREE_CODE (stmt
) != OACC_LOOP
1366 && (TREE_CODE (TREE_OPERAND (init
, 1)) == TREE_VEC
1367 || INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 1))))
1372 walk_tree_1 (&TREE_OPERAND (init
, 1),
1373 c_omp_check_loop_iv_r
, &data
, NULL
, lh
);
1374 if (data
.maybe_nonrect
)
1375 vec_outer1
= c_omp_check_nonrect_loop_iv (&TREE_OPERAND (init
, 1),
1377 /* Don't warn for C++ random access iterators here, the
1378 expression then involves the subtraction and always refers
1379 to the original value. The C++ FE needs to warn on those
1381 if (decl
== TREE_VEC_ELT (declv
, i
)
1382 || (TREE_CODE (TREE_VEC_ELT (declv
, i
)) == TREE_LIST
1383 && decl
== TREE_PURPOSE (TREE_VEC_ELT (declv
, i
))))
1385 data
.expr_loc
= EXPR_LOCATION (cond
);
1386 data
.kind
= kind
| 1;
1387 walk_tree_1 (&TREE_OPERAND (cond
, 1),
1388 c_omp_check_loop_iv_r
, &data
, NULL
, lh
);
1389 if (data
.maybe_nonrect
)
1390 vec_outer2
= c_omp_check_nonrect_loop_iv (&TREE_OPERAND (cond
, 1),
1393 if (vec_outer1
&& vec_outer2
&& vec_outer1
!= vec_outer2
)
1395 location_t loc
= data
.expr_loc
;
1396 if (loc
== UNKNOWN_LOCATION
)
1397 loc
= data
.stmt_loc
;
1398 error_at (loc
, "two different outer iteration variables %qD and %qD"
1399 " used in a single loop", vec_outer1
, vec_outer2
);
1402 if (vec_outer1
|| vec_outer2
)
1403 OMP_FOR_NON_RECTANGULAR (stmt
) = 1;
1404 if (TREE_CODE (incr
) == MODIFY_EXPR
)
1406 gcc_assert (TREE_OPERAND (incr
, 0) == decl
);
1407 incr
= TREE_OPERAND (incr
, 1);
1409 if (TREE_CODE (incr
) == PLUS_EXPR
1410 && TREE_OPERAND (incr
, 1) == decl
)
1412 data
.expr_loc
= EXPR_LOCATION (TREE_OPERAND (incr
, 0));
1413 walk_tree_1 (&TREE_OPERAND (incr
, 0),
1414 c_omp_check_loop_iv_r
, &data
, NULL
, lh
);
1418 data
.expr_loc
= EXPR_LOCATION (TREE_OPERAND (incr
, 1));
1419 walk_tree_1 (&TREE_OPERAND (incr
, 1),
1420 c_omp_check_loop_iv_r
, &data
, NULL
, lh
);
1427 /* Similar, but allows to check the init or cond expressions individually. */
1430 c_omp_check_loop_iv_exprs (location_t stmt_loc
, tree declv
, int i
, tree decl
,
1431 tree init
, tree cond
, walk_tree_lh lh
)
1433 hash_set
<tree
> pset
;
1434 struct c_omp_check_loop_iv_data data
;
1438 data
.maybe_nonrect
= false;
1439 data
.stmt_loc
= stmt_loc
;
1444 && (unsigned) c_omp_is_loop_iterator (decl
, &data
) < (unsigned) i
)
1446 error_at (stmt_loc
, "the same loop iteration variables %qD used in "
1447 "multiple associated loops", decl
);
1452 data
.expr_loc
= EXPR_LOCATION (init
);
1455 c_omp_check_loop_iv_r
, &data
, NULL
, lh
);
1459 gcc_assert (COMPARISON_CLASS_P (cond
));
1460 data
.expr_loc
= EXPR_LOCATION (init
);
1462 if (TREE_OPERAND (cond
, 0) == decl
)
1463 walk_tree_1 (&TREE_OPERAND (cond
, 1),
1464 c_omp_check_loop_iv_r
, &data
, NULL
, lh
);
1466 walk_tree_1 (&TREE_OPERAND (cond
, 0),
1467 c_omp_check_loop_iv_r
, &data
, NULL
, lh
);
1472 /* This function splits clauses for OpenACC combined loop
1473 constructs. OpenACC combined loop constructs are:
1474 #pragma acc kernels loop
1475 #pragma acc parallel loop */
1478 c_oacc_split_loop_clauses (tree clauses
, tree
*not_loop_clauses
,
1481 tree next
, loop_clauses
, nc
;
1483 loop_clauses
= *not_loop_clauses
= NULL_TREE
;
1484 for (; clauses
; clauses
= next
)
1486 next
= OMP_CLAUSE_CHAIN (clauses
);
1488 switch (OMP_CLAUSE_CODE (clauses
))
1491 case OMP_CLAUSE_COLLAPSE
:
1492 case OMP_CLAUSE_TILE
:
1493 case OMP_CLAUSE_GANG
:
1494 case OMP_CLAUSE_WORKER
:
1495 case OMP_CLAUSE_VECTOR
:
1496 case OMP_CLAUSE_AUTO
:
1497 case OMP_CLAUSE_SEQ
:
1498 case OMP_CLAUSE_INDEPENDENT
:
1499 case OMP_CLAUSE_PRIVATE
:
1500 OMP_CLAUSE_CHAIN (clauses
) = loop_clauses
;
1501 loop_clauses
= clauses
;
1504 /* Reductions must be duplicated on both constructs. */
1505 case OMP_CLAUSE_REDUCTION
:
1508 nc
= build_omp_clause (OMP_CLAUSE_LOCATION (clauses
),
1509 OMP_CLAUSE_REDUCTION
);
1510 OMP_CLAUSE_DECL (nc
) = OMP_CLAUSE_DECL (clauses
);
1511 OMP_CLAUSE_REDUCTION_CODE (nc
)
1512 = OMP_CLAUSE_REDUCTION_CODE (clauses
);
1513 OMP_CLAUSE_CHAIN (nc
) = *not_loop_clauses
;
1514 *not_loop_clauses
= nc
;
1517 OMP_CLAUSE_CHAIN (clauses
) = loop_clauses
;
1518 loop_clauses
= clauses
;
1521 /* Parallel/kernels clauses. */
1523 OMP_CLAUSE_CHAIN (clauses
) = *not_loop_clauses
;
1524 *not_loop_clauses
= clauses
;
1529 return loop_clauses
;
1532 /* This function attempts to split or duplicate clauses for OpenMP
1533 combined/composite constructs. Right now there are 30 different
1534 constructs. CODE is the innermost construct in the combined construct,
1535 and MASK allows to determine which constructs are combined together,
1536 as every construct has at least one clause that no other construct
1537 has (except for OMP_SECTIONS, but that can be only combined with parallel,
1538 and OMP_MASTER, which doesn't have any clauses at all).
1539 OpenMP combined/composite constructs are:
1540 #pragma omp distribute parallel for
1541 #pragma omp distribute parallel for simd
1542 #pragma omp distribute simd
1543 #pragma omp for simd
1544 #pragma omp master taskloop
1545 #pragma omp master taskloop simd
1546 #pragma omp parallel for
1547 #pragma omp parallel for simd
1548 #pragma omp parallel loop
1549 #pragma omp parallel master
1550 #pragma omp parallel master taskloop
1551 #pragma omp parallel master taskloop simd
1552 #pragma omp parallel sections
1553 #pragma omp target parallel
1554 #pragma omp target parallel for
1555 #pragma omp target parallel for simd
1556 #pragma omp target parallel loop
1557 #pragma omp target teams
1558 #pragma omp target teams distribute
1559 #pragma omp target teams distribute parallel for
1560 #pragma omp target teams distribute parallel for simd
1561 #pragma omp target teams distribute simd
1562 #pragma omp target teams loop
1563 #pragma omp target simd
1564 #pragma omp taskloop simd
1565 #pragma omp teams distribute
1566 #pragma omp teams distribute parallel for
1567 #pragma omp teams distribute parallel for simd
1568 #pragma omp teams distribute simd
1569 #pragma omp teams loop */
1572 c_omp_split_clauses (location_t loc
, enum tree_code code
,
1573 omp_clause_mask mask
, tree clauses
, tree
*cclauses
)
1576 enum c_omp_clause_split s
;
1579 for (i
= 0; i
< C_OMP_CLAUSE_SPLIT_COUNT
; i
++)
1581 /* Add implicit nowait clause on
1582 #pragma omp parallel {for,for simd,sections}. */
1583 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NUM_THREADS
)) != 0)
1588 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_SCHEDULE
)) != 0)
1589 cclauses
[C_OMP_CLAUSE_SPLIT_FOR
]
1590 = build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
1593 cclauses
[C_OMP_CLAUSE_SPLIT_SECTIONS
]
1594 = build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
1600 for (; clauses
; clauses
= next
)
1602 next
= OMP_CLAUSE_CHAIN (clauses
);
1604 switch (OMP_CLAUSE_CODE (clauses
))
1606 /* First the clauses that are unique to some constructs. */
1607 case OMP_CLAUSE_DEVICE
:
1608 case OMP_CLAUSE_MAP
:
1609 case OMP_CLAUSE_IS_DEVICE_PTR
:
1610 case OMP_CLAUSE_DEFAULTMAP
:
1611 case OMP_CLAUSE_DEPEND
:
1612 s
= C_OMP_CLAUSE_SPLIT_TARGET
;
1614 case OMP_CLAUSE_NUM_TEAMS
:
1615 case OMP_CLAUSE_THREAD_LIMIT
:
1616 s
= C_OMP_CLAUSE_SPLIT_TEAMS
;
1618 case OMP_CLAUSE_DIST_SCHEDULE
:
1619 s
= C_OMP_CLAUSE_SPLIT_DISTRIBUTE
;
1621 case OMP_CLAUSE_COPYIN
:
1622 case OMP_CLAUSE_NUM_THREADS
:
1623 case OMP_CLAUSE_PROC_BIND
:
1624 s
= C_OMP_CLAUSE_SPLIT_PARALLEL
;
1626 case OMP_CLAUSE_ORDERED
:
1627 s
= C_OMP_CLAUSE_SPLIT_FOR
;
1629 case OMP_CLAUSE_SCHEDULE
:
1630 s
= C_OMP_CLAUSE_SPLIT_FOR
;
1631 if (code
!= OMP_SIMD
)
1632 OMP_CLAUSE_SCHEDULE_SIMD (clauses
) = 0;
1634 case OMP_CLAUSE_SAFELEN
:
1635 case OMP_CLAUSE_SIMDLEN
:
1636 case OMP_CLAUSE_ALIGNED
:
1637 case OMP_CLAUSE_NONTEMPORAL
:
1638 s
= C_OMP_CLAUSE_SPLIT_SIMD
;
1640 case OMP_CLAUSE_GRAINSIZE
:
1641 case OMP_CLAUSE_NUM_TASKS
:
1642 case OMP_CLAUSE_FINAL
:
1643 case OMP_CLAUSE_UNTIED
:
1644 case OMP_CLAUSE_MERGEABLE
:
1645 case OMP_CLAUSE_NOGROUP
:
1646 case OMP_CLAUSE_PRIORITY
:
1647 s
= C_OMP_CLAUSE_SPLIT_TASKLOOP
;
1649 case OMP_CLAUSE_BIND
:
1650 s
= C_OMP_CLAUSE_SPLIT_LOOP
;
1652 /* Duplicate this to all of taskloop, distribute, for, simd and
1654 case OMP_CLAUSE_COLLAPSE
:
1655 if (code
== OMP_SIMD
)
1657 if ((mask
& ((OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_SCHEDULE
)
1658 | (OMP_CLAUSE_MASK_1
1659 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)
1660 | (OMP_CLAUSE_MASK_1
1661 << PRAGMA_OMP_CLAUSE_NOGROUP
))) != 0)
1663 c
= build_omp_clause (OMP_CLAUSE_LOCATION (clauses
),
1664 OMP_CLAUSE_COLLAPSE
);
1665 OMP_CLAUSE_COLLAPSE_EXPR (c
)
1666 = OMP_CLAUSE_COLLAPSE_EXPR (clauses
);
1667 OMP_CLAUSE_CHAIN (c
) = cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
];
1668 cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
] = c
;
1672 /* This must be #pragma omp target simd */
1673 s
= C_OMP_CLAUSE_SPLIT_SIMD
;
1677 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_SCHEDULE
)) != 0)
1679 if ((mask
& (OMP_CLAUSE_MASK_1
1680 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
1682 c
= build_omp_clause (OMP_CLAUSE_LOCATION (clauses
),
1683 OMP_CLAUSE_COLLAPSE
);
1684 OMP_CLAUSE_COLLAPSE_EXPR (c
)
1685 = OMP_CLAUSE_COLLAPSE_EXPR (clauses
);
1686 OMP_CLAUSE_CHAIN (c
) = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
1687 cclauses
[C_OMP_CLAUSE_SPLIT_FOR
] = c
;
1688 s
= C_OMP_CLAUSE_SPLIT_DISTRIBUTE
;
1691 s
= C_OMP_CLAUSE_SPLIT_FOR
;
1693 else if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOGROUP
))
1695 s
= C_OMP_CLAUSE_SPLIT_TASKLOOP
;
1696 else if (code
== OMP_LOOP
)
1697 s
= C_OMP_CLAUSE_SPLIT_LOOP
;
1699 s
= C_OMP_CLAUSE_SPLIT_DISTRIBUTE
;
1701 /* Private clause is supported on all constructs but master,
1702 it is enough to put it on the innermost one other than master. For
1703 #pragma omp {for,sections} put it on parallel though,
1704 as that's what we did for OpenMP 3.1. */
1705 case OMP_CLAUSE_PRIVATE
:
1708 case OMP_SIMD
: s
= C_OMP_CLAUSE_SPLIT_SIMD
; break;
1709 case OMP_FOR
: case OMP_SECTIONS
:
1710 case OMP_PARALLEL
: s
= C_OMP_CLAUSE_SPLIT_PARALLEL
; break;
1711 case OMP_DISTRIBUTE
: s
= C_OMP_CLAUSE_SPLIT_DISTRIBUTE
; break;
1712 case OMP_TEAMS
: s
= C_OMP_CLAUSE_SPLIT_TEAMS
; break;
1713 case OMP_MASTER
: s
= C_OMP_CLAUSE_SPLIT_PARALLEL
; break;
1714 case OMP_TASKLOOP
: s
= C_OMP_CLAUSE_SPLIT_TASKLOOP
; break;
1715 case OMP_LOOP
: s
= C_OMP_CLAUSE_SPLIT_LOOP
; break;
1716 default: gcc_unreachable ();
1719 /* Firstprivate clause is supported on all constructs but
1720 simd, master and loop. Put it on the outermost of those and
1721 duplicate on teams and parallel. */
1722 case OMP_CLAUSE_FIRSTPRIVATE
:
1723 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_MAP
))
1726 if (code
== OMP_SIMD
1727 && (mask
& ((OMP_CLAUSE_MASK_1
1728 << PRAGMA_OMP_CLAUSE_NUM_THREADS
)
1729 | (OMP_CLAUSE_MASK_1
1730 << PRAGMA_OMP_CLAUSE_NUM_TEAMS
))) == 0)
1732 /* This must be #pragma omp target simd. */
1733 s
= C_OMP_CLAUSE_SPLIT_TARGET
;
1736 c
= build_omp_clause (OMP_CLAUSE_LOCATION (clauses
),
1737 OMP_CLAUSE_FIRSTPRIVATE
);
1738 OMP_CLAUSE_DECL (c
) = OMP_CLAUSE_DECL (clauses
);
1739 OMP_CLAUSE_CHAIN (c
) = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
1740 cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
] = c
;
1742 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NUM_THREADS
))
1745 if ((mask
& ((OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NUM_TEAMS
)
1746 | (OMP_CLAUSE_MASK_1
1747 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
))) != 0)
1749 c
= build_omp_clause (OMP_CLAUSE_LOCATION (clauses
),
1750 OMP_CLAUSE_FIRSTPRIVATE
);
1751 OMP_CLAUSE_DECL (c
) = OMP_CLAUSE_DECL (clauses
);
1752 OMP_CLAUSE_CHAIN (c
) = cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
];
1753 cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
] = c
;
1754 if ((mask
& (OMP_CLAUSE_MASK_1
1755 << PRAGMA_OMP_CLAUSE_NUM_TEAMS
)) != 0)
1756 s
= C_OMP_CLAUSE_SPLIT_TEAMS
;
1758 s
= C_OMP_CLAUSE_SPLIT_DISTRIBUTE
;
1760 else if ((mask
& (OMP_CLAUSE_MASK_1
1761 << PRAGMA_OMP_CLAUSE_NOGROUP
)) != 0)
1763 #pragma omp parallel master taskloop{, simd}. */
1764 s
= C_OMP_CLAUSE_SPLIT_TASKLOOP
;
1767 #pragma omp parallel{, for{, simd}, sections,loop}
1769 #pragma omp target parallel. */
1770 s
= C_OMP_CLAUSE_SPLIT_PARALLEL
;
1772 else if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NUM_TEAMS
))
1775 /* This must be one of
1776 #pragma omp {,target }teams {distribute,loop}
1777 #pragma omp target teams
1778 #pragma omp {,target }teams distribute simd. */
1779 gcc_assert (code
== OMP_DISTRIBUTE
1781 || code
== OMP_TEAMS
1782 || code
== OMP_SIMD
);
1783 s
= C_OMP_CLAUSE_SPLIT_TEAMS
;
1785 else if ((mask
& (OMP_CLAUSE_MASK_1
1786 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
1788 /* This must be #pragma omp distribute simd. */
1789 gcc_assert (code
== OMP_SIMD
);
1790 s
= C_OMP_CLAUSE_SPLIT_DISTRIBUTE
;
1792 else if ((mask
& (OMP_CLAUSE_MASK_1
1793 << PRAGMA_OMP_CLAUSE_NOGROUP
)) != 0)
1795 /* This must be #pragma omp {,{,parallel }master }taskloop simd
1797 #pragma omp {,parallel }master taskloop. */
1798 gcc_assert (code
== OMP_SIMD
|| code
== OMP_TASKLOOP
);
1799 s
= C_OMP_CLAUSE_SPLIT_TASKLOOP
;
1803 /* This must be #pragma omp for simd. */
1804 gcc_assert (code
== OMP_SIMD
);
1805 s
= C_OMP_CLAUSE_SPLIT_FOR
;
1808 /* Lastprivate is allowed on distribute, for, sections, taskloop, loop
1809 and simd. In parallel {for{, simd},sections} we actually want to
1810 put it on parallel rather than for or sections. */
1811 case OMP_CLAUSE_LASTPRIVATE
:
1812 if (code
== OMP_DISTRIBUTE
)
1814 s
= C_OMP_CLAUSE_SPLIT_DISTRIBUTE
;
1817 if ((mask
& (OMP_CLAUSE_MASK_1
1818 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
1820 c
= build_omp_clause (OMP_CLAUSE_LOCATION (clauses
),
1821 OMP_CLAUSE_LASTPRIVATE
);
1822 OMP_CLAUSE_DECL (c
) = OMP_CLAUSE_DECL (clauses
);
1823 OMP_CLAUSE_CHAIN (c
) = cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
1824 OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c
)
1825 = OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (clauses
);
1826 cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
] = c
;
1828 if (code
== OMP_FOR
|| code
== OMP_SECTIONS
)
1830 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NUM_THREADS
))
1832 s
= C_OMP_CLAUSE_SPLIT_PARALLEL
;
1834 s
= C_OMP_CLAUSE_SPLIT_FOR
;
1837 if (code
== OMP_TASKLOOP
)
1839 s
= C_OMP_CLAUSE_SPLIT_TASKLOOP
;
1842 if (code
== OMP_LOOP
)
1844 s
= C_OMP_CLAUSE_SPLIT_LOOP
;
1847 gcc_assert (code
== OMP_SIMD
);
1848 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_SCHEDULE
)) != 0)
1850 c
= build_omp_clause (OMP_CLAUSE_LOCATION (clauses
),
1851 OMP_CLAUSE_LASTPRIVATE
);
1852 OMP_CLAUSE_DECL (c
) = OMP_CLAUSE_DECL (clauses
);
1853 OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c
)
1854 = OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (clauses
);
1855 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NUM_THREADS
))
1857 s
= C_OMP_CLAUSE_SPLIT_PARALLEL
;
1859 s
= C_OMP_CLAUSE_SPLIT_FOR
;
1860 OMP_CLAUSE_CHAIN (c
) = cclauses
[s
];
1863 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOGROUP
)) != 0)
1865 c
= build_omp_clause (OMP_CLAUSE_LOCATION (clauses
),
1866 OMP_CLAUSE_LASTPRIVATE
);
1867 OMP_CLAUSE_DECL (c
) = OMP_CLAUSE_DECL (clauses
);
1868 OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c
)
1869 = OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (clauses
);
1870 OMP_CLAUSE_CHAIN (c
) = cclauses
[C_OMP_CLAUSE_SPLIT_TASKLOOP
];
1871 cclauses
[C_OMP_CLAUSE_SPLIT_TASKLOOP
] = c
;
1873 s
= C_OMP_CLAUSE_SPLIT_SIMD
;
1875 /* Shared and default clauses are allowed on parallel, teams and
1877 case OMP_CLAUSE_SHARED
:
1878 case OMP_CLAUSE_DEFAULT
:
1879 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOGROUP
))
1882 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NUM_THREADS
))
1885 c
= build_omp_clause (OMP_CLAUSE_LOCATION (clauses
),
1886 OMP_CLAUSE_CODE (clauses
));
1887 if (OMP_CLAUSE_CODE (clauses
) == OMP_CLAUSE_SHARED
)
1888 OMP_CLAUSE_DECL (c
) = OMP_CLAUSE_DECL (clauses
);
1890 OMP_CLAUSE_DEFAULT_KIND (c
)
1891 = OMP_CLAUSE_DEFAULT_KIND (clauses
);
1892 OMP_CLAUSE_CHAIN (c
) = cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
];
1893 cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
] = c
;
1895 s
= C_OMP_CLAUSE_SPLIT_TASKLOOP
;
1898 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NUM_TEAMS
))
1901 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NUM_THREADS
))
1904 s
= C_OMP_CLAUSE_SPLIT_TEAMS
;
1907 c
= build_omp_clause (OMP_CLAUSE_LOCATION (clauses
),
1908 OMP_CLAUSE_CODE (clauses
));
1909 if (OMP_CLAUSE_CODE (clauses
) == OMP_CLAUSE_SHARED
)
1910 OMP_CLAUSE_DECL (c
) = OMP_CLAUSE_DECL (clauses
);
1912 OMP_CLAUSE_DEFAULT_KIND (c
)
1913 = OMP_CLAUSE_DEFAULT_KIND (clauses
);
1914 OMP_CLAUSE_CHAIN (c
) = cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
1915 cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
] = c
;
1917 s
= C_OMP_CLAUSE_SPLIT_PARALLEL
;
1919 /* order clauses are allowed on for, simd and loop. */
1920 case OMP_CLAUSE_ORDER
:
1921 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_SCHEDULE
)) != 0)
1923 if (code
== OMP_SIMD
)
1925 c
= build_omp_clause (OMP_CLAUSE_LOCATION (clauses
),
1927 OMP_CLAUSE_CHAIN (c
) = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
1928 cclauses
[C_OMP_CLAUSE_SPLIT_FOR
] = c
;
1929 s
= C_OMP_CLAUSE_SPLIT_SIMD
;
1932 s
= C_OMP_CLAUSE_SPLIT_FOR
;
1934 else if (code
== OMP_LOOP
)
1935 s
= C_OMP_CLAUSE_SPLIT_LOOP
;
1937 s
= C_OMP_CLAUSE_SPLIT_SIMD
;
1939 /* Reduction is allowed on simd, for, parallel, sections, taskloop,
1940 teams and loop. Duplicate it on all of them, but omit on for or
1941 sections if parallel is present (unless inscan, in that case
1942 omit on parallel). If taskloop or loop is combined with
1943 parallel, omit it on parallel. */
1944 case OMP_CLAUSE_REDUCTION
:
1945 if (OMP_CLAUSE_REDUCTION_TASK (clauses
))
1947 if (code
== OMP_SIMD
|| code
== OMP_LOOP
)
1949 error_at (OMP_CLAUSE_LOCATION (clauses
),
1950 "invalid %<task%> reduction modifier on construct "
1951 "combined with %<simd%> or %<loop%>");
1952 OMP_CLAUSE_REDUCTION_TASK (clauses
) = 0;
1954 else if (code
!= OMP_SECTIONS
1955 && (mask
& (OMP_CLAUSE_MASK_1
1956 << PRAGMA_OMP_CLAUSE_NUM_THREADS
)) == 0
1957 && (mask
& (OMP_CLAUSE_MASK_1
1958 << PRAGMA_OMP_CLAUSE_SCHEDULE
)) == 0)
1960 error_at (OMP_CLAUSE_LOCATION (clauses
),
1961 "invalid %<task%> reduction modifier on construct "
1962 "not combined with %<parallel%>, %<for%> or "
1964 OMP_CLAUSE_REDUCTION_TASK (clauses
) = 0;
1967 if (OMP_CLAUSE_REDUCTION_INSCAN (clauses
)
1968 && ((mask
& ((OMP_CLAUSE_MASK_1
1969 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)
1970 | (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_MAP
)))
1973 error_at (OMP_CLAUSE_LOCATION (clauses
),
1974 "%<inscan%> %<reduction%> clause on construct other "
1975 "than %<for%>, %<simd%>, %<for simd%>, "
1976 "%<parallel for%>, %<parallel for simd%>");
1977 OMP_CLAUSE_REDUCTION_INSCAN (clauses
) = 0;
1979 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_SCHEDULE
)) != 0)
1981 if (code
== OMP_SIMD
)
1983 c
= build_omp_clause (OMP_CLAUSE_LOCATION (clauses
),
1984 OMP_CLAUSE_REDUCTION
);
1985 OMP_CLAUSE_DECL (c
) = OMP_CLAUSE_DECL (clauses
);
1986 OMP_CLAUSE_REDUCTION_CODE (c
)
1987 = OMP_CLAUSE_REDUCTION_CODE (clauses
);
1988 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
)
1989 = OMP_CLAUSE_REDUCTION_PLACEHOLDER (clauses
);
1990 OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c
)
1991 = OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (clauses
);
1992 OMP_CLAUSE_REDUCTION_INSCAN (c
)
1993 = OMP_CLAUSE_REDUCTION_INSCAN (clauses
);
1994 OMP_CLAUSE_CHAIN (c
) = cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
];
1995 cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
] = c
;
1997 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NUM_TEAMS
))
2000 c
= build_omp_clause (OMP_CLAUSE_LOCATION (clauses
),
2001 OMP_CLAUSE_REDUCTION
);
2002 OMP_CLAUSE_DECL (c
) = OMP_CLAUSE_DECL (clauses
);
2003 OMP_CLAUSE_REDUCTION_CODE (c
)
2004 = OMP_CLAUSE_REDUCTION_CODE (clauses
);
2005 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
)
2006 = OMP_CLAUSE_REDUCTION_PLACEHOLDER (clauses
);
2007 OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c
)
2008 = OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (clauses
);
2009 OMP_CLAUSE_REDUCTION_INSCAN (c
)
2010 = OMP_CLAUSE_REDUCTION_INSCAN (clauses
);
2011 OMP_CLAUSE_CHAIN (c
) = cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
2012 cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
] = c
;
2013 s
= C_OMP_CLAUSE_SPLIT_PARALLEL
;
2015 else if ((mask
& (OMP_CLAUSE_MASK_1
2016 << PRAGMA_OMP_CLAUSE_NUM_THREADS
)) != 0
2017 && !OMP_CLAUSE_REDUCTION_INSCAN (clauses
))
2018 s
= C_OMP_CLAUSE_SPLIT_PARALLEL
;
2020 s
= C_OMP_CLAUSE_SPLIT_FOR
;
2022 else if (code
== OMP_SECTIONS
2023 || code
== OMP_PARALLEL
2024 || code
== OMP_MASTER
)
2025 s
= C_OMP_CLAUSE_SPLIT_PARALLEL
;
2026 else if (code
== OMP_TASKLOOP
)
2027 s
= C_OMP_CLAUSE_SPLIT_TASKLOOP
;
2028 else if (code
== OMP_LOOP
)
2029 s
= C_OMP_CLAUSE_SPLIT_LOOP
;
2030 else if (code
== OMP_SIMD
)
2032 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOGROUP
))
2035 c
= build_omp_clause (OMP_CLAUSE_LOCATION (clauses
),
2036 OMP_CLAUSE_REDUCTION
);
2037 OMP_CLAUSE_DECL (c
) = OMP_CLAUSE_DECL (clauses
);
2038 OMP_CLAUSE_REDUCTION_CODE (c
)
2039 = OMP_CLAUSE_REDUCTION_CODE (clauses
);
2040 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
)
2041 = OMP_CLAUSE_REDUCTION_PLACEHOLDER (clauses
);
2042 OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c
)
2043 = OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (clauses
);
2044 OMP_CLAUSE_REDUCTION_INSCAN (c
)
2045 = OMP_CLAUSE_REDUCTION_INSCAN (clauses
);
2046 OMP_CLAUSE_CHAIN (c
) = cclauses
[C_OMP_CLAUSE_SPLIT_TASKLOOP
];
2047 cclauses
[C_OMP_CLAUSE_SPLIT_TASKLOOP
] = c
;
2049 s
= C_OMP_CLAUSE_SPLIT_SIMD
;
2052 s
= C_OMP_CLAUSE_SPLIT_TEAMS
;
2054 case OMP_CLAUSE_IN_REDUCTION
:
2055 /* in_reduction on taskloop simd becomes reduction on the simd
2056 and keeps being in_reduction on taskloop. */
2057 if (code
== OMP_SIMD
)
2059 c
= build_omp_clause (OMP_CLAUSE_LOCATION (clauses
),
2060 OMP_CLAUSE_REDUCTION
);
2061 OMP_CLAUSE_DECL (c
) = OMP_CLAUSE_DECL (clauses
);
2062 OMP_CLAUSE_REDUCTION_CODE (c
)
2063 = OMP_CLAUSE_REDUCTION_CODE (clauses
);
2064 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
)
2065 = OMP_CLAUSE_REDUCTION_PLACEHOLDER (clauses
);
2066 OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c
)
2067 = OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (clauses
);
2068 OMP_CLAUSE_CHAIN (c
) = cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
];
2069 cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
] = c
;
2071 s
= C_OMP_CLAUSE_SPLIT_TASKLOOP
;
2074 if (OMP_CLAUSE_IF_MODIFIER (clauses
) != ERROR_MARK
)
2076 s
= C_OMP_CLAUSE_SPLIT_COUNT
;
2077 switch (OMP_CLAUSE_IF_MODIFIER (clauses
))
2080 if ((mask
& (OMP_CLAUSE_MASK_1
2081 << PRAGMA_OMP_CLAUSE_NUM_THREADS
)) != 0)
2082 s
= C_OMP_CLAUSE_SPLIT_PARALLEL
;
2085 if (code
== OMP_SIMD
)
2086 s
= C_OMP_CLAUSE_SPLIT_SIMD
;
2089 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOGROUP
))
2091 s
= C_OMP_CLAUSE_SPLIT_TASKLOOP
;
2094 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_MAP
))
2096 s
= C_OMP_CLAUSE_SPLIT_TARGET
;
2101 if (s
!= C_OMP_CLAUSE_SPLIT_COUNT
)
2103 /* Error-recovery here, invalid if-modifier specified, add the
2104 clause to just one construct. */
2105 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_MAP
)) != 0)
2106 s
= C_OMP_CLAUSE_SPLIT_TARGET
;
2107 else if ((mask
& (OMP_CLAUSE_MASK_1
2108 << PRAGMA_OMP_CLAUSE_NUM_THREADS
)) != 0)
2109 s
= C_OMP_CLAUSE_SPLIT_PARALLEL
;
2110 else if ((mask
& (OMP_CLAUSE_MASK_1
2111 << PRAGMA_OMP_CLAUSE_NOGROUP
)) != 0)
2112 s
= C_OMP_CLAUSE_SPLIT_TASKLOOP
;
2113 else if (code
== OMP_SIMD
)
2114 s
= C_OMP_CLAUSE_SPLIT_SIMD
;
2119 /* Otherwise, duplicate if clause to all constructs. */
2120 if (code
== OMP_SIMD
)
2122 if ((mask
& ((OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_MAP
)
2123 | (OMP_CLAUSE_MASK_1
2124 << PRAGMA_OMP_CLAUSE_NUM_THREADS
)
2125 | (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOGROUP
)))
2128 c
= build_omp_clause (OMP_CLAUSE_LOCATION (clauses
),
2130 OMP_CLAUSE_IF_MODIFIER (c
)
2131 = OMP_CLAUSE_IF_MODIFIER (clauses
);
2132 OMP_CLAUSE_IF_EXPR (c
) = OMP_CLAUSE_IF_EXPR (clauses
);
2133 OMP_CLAUSE_CHAIN (c
) = cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
];
2134 cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
] = c
;
2138 s
= C_OMP_CLAUSE_SPLIT_SIMD
;
2142 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOGROUP
))
2145 if ((mask
& (OMP_CLAUSE_MASK_1
2146 << PRAGMA_OMP_CLAUSE_NUM_THREADS
)) != 0)
2148 c
= build_omp_clause (OMP_CLAUSE_LOCATION (clauses
),
2150 OMP_CLAUSE_IF_MODIFIER (c
)
2151 = OMP_CLAUSE_IF_MODIFIER (clauses
);
2152 OMP_CLAUSE_IF_EXPR (c
) = OMP_CLAUSE_IF_EXPR (clauses
);
2153 OMP_CLAUSE_CHAIN (c
) = cclauses
[C_OMP_CLAUSE_SPLIT_TASKLOOP
];
2154 cclauses
[C_OMP_CLAUSE_SPLIT_TASKLOOP
] = c
;
2155 s
= C_OMP_CLAUSE_SPLIT_PARALLEL
;
2158 s
= C_OMP_CLAUSE_SPLIT_TASKLOOP
;
2160 else if ((mask
& (OMP_CLAUSE_MASK_1
2161 << PRAGMA_OMP_CLAUSE_NUM_THREADS
)) != 0)
2163 if ((mask
& (OMP_CLAUSE_MASK_1
2164 << PRAGMA_OMP_CLAUSE_MAP
)) != 0)
2166 c
= build_omp_clause (OMP_CLAUSE_LOCATION (clauses
),
2168 OMP_CLAUSE_IF_MODIFIER (c
)
2169 = OMP_CLAUSE_IF_MODIFIER (clauses
);
2170 OMP_CLAUSE_IF_EXPR (c
) = OMP_CLAUSE_IF_EXPR (clauses
);
2171 OMP_CLAUSE_CHAIN (c
) = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
2172 cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
] = c
;
2173 s
= C_OMP_CLAUSE_SPLIT_PARALLEL
;
2176 s
= C_OMP_CLAUSE_SPLIT_PARALLEL
;
2179 s
= C_OMP_CLAUSE_SPLIT_TARGET
;
2181 case OMP_CLAUSE_LINEAR
:
2182 /* Linear clause is allowed on simd and for. Put it on the
2183 innermost construct. */
2184 if (code
== OMP_SIMD
)
2185 s
= C_OMP_CLAUSE_SPLIT_SIMD
;
2187 s
= C_OMP_CLAUSE_SPLIT_FOR
;
2189 case OMP_CLAUSE_NOWAIT
:
2190 /* Nowait clause is allowed on target, for and sections, but
2191 is not allowed on parallel for or parallel sections. Therefore,
2192 put it on target construct if present, because that can only
2193 be combined with parallel for{, simd} and not with for{, simd},
2194 otherwise to the worksharing construct. */
2195 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_MAP
))
2197 s
= C_OMP_CLAUSE_SPLIT_TARGET
;
2199 s
= C_OMP_CLAUSE_SPLIT_FOR
;
2204 OMP_CLAUSE_CHAIN (clauses
) = cclauses
[s
];
2205 cclauses
[s
] = clauses
;
2211 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_MAP
)) == 0)
2212 gcc_assert (cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
] == NULL_TREE
);
2213 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NUM_TEAMS
)) == 0)
2214 gcc_assert (cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
] == NULL_TREE
);
2215 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) == 0)
2216 gcc_assert (cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
] == NULL_TREE
);
2217 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NUM_THREADS
)) == 0)
2218 gcc_assert (cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
] == NULL_TREE
);
2219 if ((mask
& ((OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_SCHEDULE
)
2220 | (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOGROUP
))) == 0
2221 && code
!= OMP_SECTIONS
2222 && code
!= OMP_LOOP
)
2223 gcc_assert (cclauses
[C_OMP_CLAUSE_SPLIT_FOR
] == NULL_TREE
);
2224 if (code
!= OMP_SIMD
)
2225 gcc_assert (cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
] == NULL_TREE
);
2229 /* qsort callback to compare #pragma omp declare simd clauses. */
2232 c_omp_declare_simd_clause_cmp (const void *p
, const void *q
)
2234 tree a
= *(const tree
*) p
;
2235 tree b
= *(const tree
*) q
;
2236 if (OMP_CLAUSE_CODE (a
) != OMP_CLAUSE_CODE (b
))
2238 if (OMP_CLAUSE_CODE (a
) > OMP_CLAUSE_CODE (b
))
2242 if (OMP_CLAUSE_CODE (a
) != OMP_CLAUSE_SIMDLEN
2243 && OMP_CLAUSE_CODE (a
) != OMP_CLAUSE_INBRANCH
2244 && OMP_CLAUSE_CODE (a
) != OMP_CLAUSE_NOTINBRANCH
)
2246 int c
= tree_to_shwi (OMP_CLAUSE_DECL (a
));
2247 int d
= tree_to_shwi (OMP_CLAUSE_DECL (b
));
2256 /* Change PARM_DECLs in OMP_CLAUSE_DECL of #pragma omp declare simd
2257 CLAUSES on FNDECL into argument indexes and sort them. */
2260 c_omp_declare_simd_clauses_to_numbers (tree parms
, tree clauses
)
2263 vec
<tree
> clvec
= vNULL
;
2265 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
2267 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_SIMDLEN
2268 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_INBRANCH
2269 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_NOTINBRANCH
)
2271 tree decl
= OMP_CLAUSE_DECL (c
);
2274 for (arg
= parms
, idx
= 0; arg
;
2275 arg
= TREE_CHAIN (arg
), idx
++)
2278 if (arg
== NULL_TREE
)
2280 error_at (OMP_CLAUSE_LOCATION (c
),
2281 "%qD is not a function argument", decl
);
2284 OMP_CLAUSE_DECL (c
) = build_int_cst (integer_type_node
, idx
);
2285 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINEAR
2286 && OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c
))
2288 decl
= OMP_CLAUSE_LINEAR_STEP (c
);
2289 for (arg
= parms
, idx
= 0; arg
;
2290 arg
= TREE_CHAIN (arg
), idx
++)
2293 if (arg
== NULL_TREE
)
2295 error_at (OMP_CLAUSE_LOCATION (c
),
2296 "%qD is not a function argument", decl
);
2299 OMP_CLAUSE_LINEAR_STEP (c
)
2300 = build_int_cst (integer_type_node
, idx
);
2303 clvec
.safe_push (c
);
2305 if (!clvec
.is_empty ())
2307 unsigned int len
= clvec
.length (), i
;
2308 clvec
.qsort (c_omp_declare_simd_clause_cmp
);
2310 for (i
= 0; i
< len
; i
++)
2311 OMP_CLAUSE_CHAIN (clvec
[i
]) = (i
< len
- 1) ? clvec
[i
+ 1] : NULL_TREE
;
2314 clauses
= NULL_TREE
;
2319 /* Change argument indexes in CLAUSES of FNDECL back to PARM_DECLs. */
2322 c_omp_declare_simd_clauses_to_decls (tree fndecl
, tree clauses
)
2326 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
2327 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_SIMDLEN
2328 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_INBRANCH
2329 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_NOTINBRANCH
)
2331 int idx
= tree_to_shwi (OMP_CLAUSE_DECL (c
)), i
;
2333 for (arg
= DECL_ARGUMENTS (fndecl
), i
= 0; arg
;
2334 arg
= TREE_CHAIN (arg
), i
++)
2338 OMP_CLAUSE_DECL (c
) = arg
;
2339 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINEAR
2340 && OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c
))
2342 idx
= tree_to_shwi (OMP_CLAUSE_LINEAR_STEP (c
));
2343 for (arg
= DECL_ARGUMENTS (fndecl
), i
= 0; arg
;
2344 arg
= TREE_CHAIN (arg
), i
++)
2348 OMP_CLAUSE_LINEAR_STEP (c
) = arg
;
2353 /* Return true for __func__ and similar function-local predefined
2354 variables (which are in OpenMP predetermined shared, allowed in
2355 shared/firstprivate clauses). */
2358 c_omp_predefined_variable (tree decl
)
2361 && DECL_ARTIFICIAL (decl
)
2362 && TREE_READONLY (decl
)
2363 && TREE_STATIC (decl
)
2365 && (DECL_NAME (decl
) == ridpointers
[RID_C99_FUNCTION_NAME
]
2366 || DECL_NAME (decl
) == ridpointers
[RID_FUNCTION_NAME
]
2367 || DECL_NAME (decl
) == ridpointers
[RID_PRETTY_FUNCTION_NAME
]))
2372 /* OMP_CLAUSE_DEFAULT_UNSPECIFIED unless OpenMP sharing attribute of DECL
2373 is predetermined. */
2375 enum omp_clause_default_kind
2376 c_omp_predetermined_sharing (tree decl
)
2378 /* Predetermine artificial variables holding integral values, those
2379 are usually result of gimplify_one_sizepos or SAVE_EXPR
2382 && DECL_ARTIFICIAL (decl
)
2383 && INTEGRAL_TYPE_P (TREE_TYPE (decl
)))
2384 return OMP_CLAUSE_DEFAULT_SHARED
;
2386 if (c_omp_predefined_variable (decl
))
2387 return OMP_CLAUSE_DEFAULT_SHARED
;
2389 return OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
2392 /* OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED unless OpenMP mapping attribute
2393 of DECL is predetermined. */
2395 enum omp_clause_defaultmap_kind
2396 c_omp_predetermined_mapping (tree decl
)
2398 /* Predetermine artificial variables holding integral values, those
2399 are usually result of gimplify_one_sizepos or SAVE_EXPR
2402 && DECL_ARTIFICIAL (decl
)
2403 && INTEGRAL_TYPE_P (TREE_TYPE (decl
)))
2404 return OMP_CLAUSE_DEFAULTMAP_FIRSTPRIVATE
;
2406 if (c_omp_predefined_variable (decl
))
2407 return OMP_CLAUSE_DEFAULTMAP_TO
;
2409 return OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED
;
2413 /* Diagnose errors in an OpenMP context selector, return CTX if
2414 it is correct or error_mark_node otherwise. */
2417 c_omp_check_context_selector (location_t loc
, tree ctx
)
2419 /* Each trait-set-selector-name can only be specified once.
2420 There are just 4 set names. */
2421 for (tree t1
= ctx
; t1
; t1
= TREE_CHAIN (t1
))
2422 for (tree t2
= TREE_CHAIN (t1
); t2
; t2
= TREE_CHAIN (t2
))
2423 if (TREE_PURPOSE (t1
) == TREE_PURPOSE (t2
))
2425 error_at (loc
, "selector set %qs specified more than once",
2426 IDENTIFIER_POINTER (TREE_PURPOSE (t1
)));
2427 return error_mark_node
;
2429 for (tree t
= ctx
; t
; t
= TREE_CHAIN (t
))
2431 /* Each trait-selector-name can only be specified once. */
2432 if (list_length (TREE_VALUE (t
)) < 5)
2434 for (tree t1
= TREE_VALUE (t
); t1
; t1
= TREE_CHAIN (t1
))
2435 for (tree t2
= TREE_CHAIN (t1
); t2
; t2
= TREE_CHAIN (t2
))
2436 if (TREE_PURPOSE (t1
) == TREE_PURPOSE (t2
))
2439 "selector %qs specified more than once in set %qs",
2440 IDENTIFIER_POINTER (TREE_PURPOSE (t1
)),
2441 IDENTIFIER_POINTER (TREE_PURPOSE (t
)));
2442 return error_mark_node
;
2447 hash_set
<tree
> pset
;
2448 for (tree t1
= TREE_VALUE (t
); t1
; t1
= TREE_CHAIN (t1
))
2449 if (pset
.add (TREE_PURPOSE (t1
)))
2452 "selector %qs specified more than once in set %qs",
2453 IDENTIFIER_POINTER (TREE_PURPOSE (t1
)),
2454 IDENTIFIER_POINTER (TREE_PURPOSE (t
)));
2455 return error_mark_node
;
2459 static const char *const kind
[] = {
2460 "host", "nohost", "cpu", "gpu", "fpga", "any", NULL
};
2461 static const char *const vendor
[] = {
2462 "amd", "arm", "bsc", "cray", "fujitsu", "gnu", "ibm", "intel",
2463 "llvm", "nvidia", "pgi", "ti", "unknown", NULL
};
2464 static const char *const extension
[] = { NULL
};
2465 static const char *const atomic_default_mem_order
[] = {
2466 "seq_cst", "relaxed", "acq_rel", NULL
};
2467 struct known_properties
{ const char *set
; const char *selector
;
2468 const char *const *props
; };
2469 known_properties props
[] = {
2470 { "device", "kind", kind
},
2471 { "implementation", "vendor", vendor
},
2472 { "implementation", "extension", extension
},
2473 { "implementation", "atomic_default_mem_order",
2474 atomic_default_mem_order
} };
2475 for (tree t1
= TREE_VALUE (t
); t1
; t1
= TREE_CHAIN (t1
))
2476 for (unsigned i
= 0; i
< ARRAY_SIZE (props
); i
++)
2477 if (!strcmp (IDENTIFIER_POINTER (TREE_PURPOSE (t1
)),
2479 && !strcmp (IDENTIFIER_POINTER (TREE_PURPOSE (t
)),
2481 for (tree t2
= TREE_VALUE (t1
); t2
; t2
= TREE_CHAIN (t2
))
2482 for (unsigned j
= 0; ; j
++)
2484 if (props
[i
].props
[j
] == NULL
)
2486 if (TREE_PURPOSE (t2
)
2487 && !strcmp (IDENTIFIER_POINTER (TREE_PURPOSE (t2
)),
2490 if (props
[i
].props
== atomic_default_mem_order
)
2493 "incorrect property %qs of %qs selector",
2494 IDENTIFIER_POINTER (TREE_PURPOSE (t2
)),
2495 "atomic_default_mem_order");
2496 return error_mark_node
;
2498 else if (TREE_PURPOSE (t2
))
2500 "unknown property %qs of %qs selector",
2501 IDENTIFIER_POINTER (TREE_PURPOSE (t2
)),
2505 "unknown property %qE of %qs selector",
2506 TREE_VALUE (t2
), props
[i
].selector
);
2509 else if (TREE_PURPOSE (t2
) == NULL_TREE
)
2511 const char *str
= TREE_STRING_POINTER (TREE_VALUE (t2
));
2512 if (!strcmp (str
, props
[i
].props
[j
])
2513 && ((size_t) TREE_STRING_LENGTH (TREE_VALUE (t2
))
2514 == strlen (str
) + 1))
2517 else if (!strcmp (IDENTIFIER_POINTER (TREE_PURPOSE (t2
)),
2525 /* Register VARIANT as variant of some base function marked with
2526 #pragma omp declare variant. CONSTRUCT is corresponding construct
2530 c_omp_mark_declare_variant (location_t loc
, tree variant
, tree construct
)
2532 tree attr
= lookup_attribute ("omp declare variant variant",
2533 DECL_ATTRIBUTES (variant
));
2534 if (attr
== NULL_TREE
)
2536 attr
= tree_cons (get_identifier ("omp declare variant variant"),
2537 unshare_expr (construct
),
2538 DECL_ATTRIBUTES (variant
));
2539 DECL_ATTRIBUTES (variant
) = attr
;
2542 if ((TREE_VALUE (attr
) != NULL_TREE
) != (construct
!= NULL_TREE
)
2543 || (construct
!= NULL_TREE
2544 && omp_context_selector_set_compare ("construct", TREE_VALUE (attr
),
2546 error_at (loc
, "%qD used as a variant with incompatible %<construct%> "
2547 "selector sets", variant
);
2550 /* For OpenACC, the OMP_CLAUSE_MAP_KIND of an OMP_CLAUSE_MAP is used internally
2551 to distinguish clauses as seen by the user. Return the "friendly" clause
2552 name for error messages etc., where possible. See also
2553 c/c-parser.c:c_parser_oacc_data_clause and
2554 cp/parser.c:cp_parser_oacc_data_clause. */
2557 c_omp_map_clause_name (tree clause
, bool oacc
)
2559 if (oacc
&& OMP_CLAUSE_CODE (clause
) == OMP_CLAUSE_MAP
)
2560 switch (OMP_CLAUSE_MAP_KIND (clause
))
2562 case GOMP_MAP_FORCE_ALLOC
:
2563 case GOMP_MAP_ALLOC
: return "create";
2564 case GOMP_MAP_FORCE_TO
:
2565 case GOMP_MAP_TO
: return "copyin";
2566 case GOMP_MAP_FORCE_FROM
:
2567 case GOMP_MAP_FROM
: return "copyout";
2568 case GOMP_MAP_FORCE_TOFROM
:
2569 case GOMP_MAP_TOFROM
: return "copy";
2570 case GOMP_MAP_RELEASE
: return "delete";
2571 case GOMP_MAP_FORCE_PRESENT
: return "present";
2572 case GOMP_MAP_ATTACH
: return "attach";
2573 case GOMP_MAP_FORCE_DETACH
:
2574 case GOMP_MAP_DETACH
: return "detach";
2575 case GOMP_MAP_DEVICE_RESIDENT
: return "device_resident";
2576 case GOMP_MAP_LINK
: return "link";
2577 case GOMP_MAP_FORCE_DEVICEPTR
: return "deviceptr";
2580 return omp_clause_code_name
[OMP_CLAUSE_CODE (clause
)];