diff options
Diffstat (limited to 'gcc')
137 files changed, 11586 insertions, 1190 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c3e77f3..d461960 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,307 @@ +2018-11-08 Jakub Jelinek <jakub@redhat.com> + + * builtin-types.def (BT_FN_VOID_BOOL, BT_FN_VOID_SIZE_SIZE_PTR, + BT_FN_UINT_UINT_PTR_PTR, BT_FN_UINT_OMPFN_PTR_UINT_UINT, + BT_FN_BOOL_UINT_LONGPTR_LONG_LONG_LONGPTR_LONGPTR_PTR_PTR, + BT_FN_BOOL_UINT_ULLPTR_LONG_ULL_ULLPTR_ULLPTR_PTR_PTR, + BT_FN_BOOL_LONG_LONG_LONG_LONG_LONG_LONGPTR_LONGPTR_PTR_PTR, + BT_FN_BOOL_BOOL_ULL_ULL_ULL_LONG_ULL_ULLPTR_ULLPTR_PTR_PTR): New. + * gengtype.c (open_base_files): Add omp-general.h. + * gimple.c (gimple_build_omp_critical): + (gimple_build_omp_taskgroup): Add CLAUSES argument. Call + gimple_omp_taskgroup_set_clauses. + (gimple_build_omp_atomic_load): Add mo argument, call + gimple_omp_atomic_set_memory_order. + (gimple_build_omp_atomic_store): Likewise. + (gimple_copy): Adjust handling of GIMPLE_OMP_TASKGROUP. + * gimple.def (GIMPLE_OMP_TASKGROUP): Use GSS_OMP_SINGLE_LAYOUT + instead of GSS_OMP. + (GIMPLE_OMP_TEAMS): Use GSS_OMP_PARALLEL_LAYOUT instead + of GSS_OMP_SINGLE_LAYOUT, adjust comments. + * gimple.h (enum gf_mask): Add GF_OMP_TEAMS_HOST, GF_OMP_TASK_TASKWAIT + and GF_OMP_ATOMIC_MEMORY_ORDER. Remove GF_OMP_ATOMIC_SEQ_CST, use + different value for GF_OMP_ATOMIC_NEED_VALUE. + (struct gimple_statement_omp_taskreg): Add GIMPLE_OMP_TEAMS to + comments. + (struct gimple_statement_omp_single_layout): And remove here. + (struct gomp_teams): Inherit from gimple_statement_omp_taskreg rather + than gimple_statement_omp_single_layout. + (is_a_helper <gimple_statement_omp_taskreg *>::test): Allow + GIMPLE_OMP_TEAMS. + (is_a_helper <const gimple_statement_omp_taskreg *>::test): Likewise. + (gimple_omp_subcode): Formatting fix. + (gimple_omp_teams_child_fn, gimple_omp_teams_child_fn_ptr, + gimple_omp_teams_set_child_fn, gimple_omp_teams_data_arg, + gimple_omp_teams_data_arg_ptr, gimple_omp_teams_set_data_arg, + gimple_omp_teams_host, gimple_omp_teams_set_host, + gimple_omp_task_taskwait_p, gimple_omp_task_set_taskwait_p, + gimple_omp_taskgroup_clauses, gimple_omp_taskgroup_clauses_ptr, + gimple_omp_taskgroup_set_clauses): New inline functions. + (gimple_build_omp_atomic_load): Add enum omp_memory_order argument. + (gimple_build_omp_atomic_store): Likewise. + (gimple_omp_atomic_seq_cst_p): Remove. + (gimple_omp_atomic_memory_order): New function. + (gimple_omp_atomic_set_seq_cst): Remove. + (gimple_omp_atomic_set_memory_order): New function. + (gimple_build_omp_taskgroup): Add clauses argument. + * gimple-pretty-print.c (dump_gimple_omp_taskgroup): New function. + (dump_gimple_omp_task): Print taskwait with depend clauses. + (dump_gimple_omp_atomic_load, dump_gimple_omp_atomic_store): Use + dump_omp_atomic_memory_order. + (pp_gimple_stmt_1): Handle GIMPLE_OMP_TASKGROUP. + * gimplify.c (enum gimplify_omp_var_data): Add GOVD_MAP_ALLOC_ONLY, + GOVD_MAP_FROM_ONLY and GOVD_NONTEMPORAL. + (enum omp_region_type): Reserve bits 1 and 2 for auxiliary flags, + renumber values of most of ORT_* enumerators, add ORT_HOST_TEAMS, + ORT_COMBINED_HOST_TEAMS, ORT_TASKGROUP, ORT_TASKLOOP and + ORT_UNTIED_TASKLOOP enumerators. + (enum gimplify_defaultmap_kind): New. + (struct gimplify_omp_ctx): Remove target_map_scalars_firstprivate and + target_map_pointers_as_0len_arrays members, add defaultmap. + (new_omp_context): Initialize defaultmap member. + (gimple_add_tmp_var): Handle ORT_TASKGROUP like ORT_WORKSHARE. + (maybe_fold_stmt): Don't fold even in host teams regions. + (omp_firstprivatize_variable): Handle ORT_TASKGROUP like + ORT_WORKSHARE. Test ctx->defaultmap[GDMK_SCALAR] instead of + ctx->omp_firstprivatize_variable. + (omp_add_variable): Don't add private/firstprivate for VLAs in + ORT_TASKGROUP. + (omp_default_clause): Print "taskloop" rather than "task" if + ORT_*TASKLOOP. + (omp_notice_variable): Handle ORT_TASKGROUP like ORT_WORKSHARE. + Handle new defaultmap clause kinds. + (omp_is_private): Handle ORT_TASKGROUP like ORT_WORKSHARE. Allow simd + iterator to be lastprivate or private. Fix up diagnostics if linear + is used on collapse>1 simd iterator. + (omp_check_private): Handle ORT_TASKGROUP like ORT_WORKSHARE. + (gimplify_omp_depend): New function. + (gimplify_scan_omp_clauses): Add shared clause on parallel for + combined parallel master taskloop{, simd} if taskloop has + firstprivate, lastprivate or reduction clause. Handle + OMP_CLAUSE_REDUCTION_TASK diagnostics. Adjust tests for + ORT_COMBINED_TEAMS. Gimplify depend clauses with iterators. Handle + cancel and simd OMP_CLAUSE_IF_MODIFIERs. Handle + OMP_CLAUSE_NONTEMPORAL. Handle new defaultmap clause kinds. Handle + OMP_CLAUSE_{TASK,IN}_REDUCTION. Diagnose invalid conditional + lastprivate. + (gimplify_adjust_omp_clauses_1): Ignore GOVD_NONTEMPORAL. Handle + GOVD_MAP_ALLOC_ONLY and GOVD_MAP_FROM_ONLY. + (gimplify_adjust_omp_clauses): Handle OMP_CLAUSE_NONTEMPORAL. Handle + OMP_CLAUSE_{TASK,IN}_REDUCTION. + (gimplify_omp_task): Handle taskwait with depend clauses. + (gimplify_omp_for): Add shared clause on parallel for combined + parallel master taskloop{, simd} if taskloop has firstprivate, + lastprivate or reduction clause. Use ORT_TASKLOOP or + ORT_UNTIED_TASKLOOP instead of ORT_TASK or ORT_UNTIED_TASK. Adjust + tests for ORT_COMBINED_TEAMS. Handle C++ range for loops with + NULL TREE_PURPOSE in OMP_FOR_ORIG_DECLS. Firstprivatize + __for_end and __for_range temporaries on OMP_PARALLEL for + distribute parallel for{, simd}. Move OMP_CLAUSE_REDUCTION + and OMP_CLAUSE_IN_REDUCTION from taskloop to the task construct + sandwiched in between two taskloops. + (computable_teams_clause): Test ctx->defaultmap[GDMK_SCALAR] + instead of ctx->omp_firstprivatize_variable. + (gimplify_omp_workshare): Set ort to ORT_HOST_TEAMS or + ORT_COMBINED_HOST_TEAMS if not inside of target construct. If + host teams, use gimplify_and_return_first etc. for body like + for target or target data constructs, and at the end call + gimple_omp_teams_set_host on the GIMPLE_OMP_TEAMS object. + (gimplify_omp_atomic): Use OMP_ATOMIC_MEMORY_ORDER instead + of OMP_ATOMIC_SEQ_CST, pass it as new argument to + gimple_build_omp_atomic_load and gimple_build_omp_atomic_store, remove + gimple_omp_atomic_set_seq_cst calls. + (gimplify_expr) <case OMP_TASKGROUP>: Move handling into a separate + case, handle taskgroup clauses. + * lto-streamer-out.c (hash_tree): Handle + OMP_CLAUSE_{TASK,IN}_REDUCTION. + * Makefile.in (GTFILES): Add omp-general.h. + * omp-builtins.def (BUILT_IN_GOMP_TASKWAIT_DEPEND, + BUILT_IN_GOMP_LOOP_NONMONOTONIC_RUNTIME_START, + BUILT_IN_GOMP_LOOP_MAYBE_NONMONOTONIC_RUNTIME_START, + BUILT_IN_GOMP_LOOP_START, BUILT_IN_GOMP_LOOP_ORDERED_START, + BUILT_IN_GOMP_LOOP_DOACROSS_START, + BUILT_IN_GOMP_LOOP_NONMONOTONIC_RUNTIME_NEXT, + BUILT_IN_GOMP_LOOP_MAYBE_NONMONOTONIC_RUNTIME_NEXT, + BUILT_IN_GOMP_LOOP_ULL_NONMONOTONIC_RUNTIME_START, + BUILT_IN_GOMP_LOOP_ULL_MAYBE_NONMONOTONIC_RUNTIME_START, + BUILT_IN_GOMP_LOOP_ULL_START, BUILT_IN_GOMP_LOOP_ULL_ORDERED_START, + BUILT_IN_GOMP_LOOP_ULL_DOACROSS_START, + BUILT_IN_GOMP_LOOP_ULL_NONMONOTONIC_RUNTIME_NEXT, + BUILT_IN_GOMP_LOOP_ULL_MAYBE_NONMONOTONIC_RUNTIME_NEXT, + BUILT_IN_GOMP_PARALLEL_LOOP_NONMONOTONIC_RUNTIME, + BUILT_IN_GOMP_PARALLEL_LOOP_MAYBE_NONMONOTONIC_RUNTIME, + BUILT_IN_GOMP_PARALLEL_REDUCTIONS, BUILT_IN_GOMP_SECTIONS2_START, + BUILT_IN_GOMP_TEAMS_REG, BUILT_IN_GOMP_TASKGROUP_REDUCTION_REGISTER, + BUILT_IN_GOMP_TASKGROUP_REDUCTION_UNREGISTER, + BUILT_IN_GOMP_TASK_REDUCTION_REMAP, + BUILT_IN_GOMP_WORKSHARE_TASK_REDUCTION_UNREGISTER): New builtins. + * omp-expand.c (workshare_safe_to_combine_p): Return false for + non-worksharing loops. + (omp_adjust_chunk_size): Don't adjust anything if chunk_size is zero. + (determine_parallel_type): Don't combine parallel with worksharing + which has _reductemp_ clause. + (expand_parallel_call): Emit the GOMP_*nonmonotonic_runtime* or + GOMP_*maybe_nonmonotonic_runtime* builtins instead of GOMP_*runtime* + if there is nonmonotonic modifier or if there is no modifier and no + ordered clause. For dynamic and guided schedule without monotonic + and nonmonotonic modifier, default to nonmonotonic. + (expand_omp_for): Likewise. Adjust expand_omp_for_generic caller, use + GOMP_loop{,_ull}{,_ordered,_doacross}_start builtins if there are + task reductions. + (expand_task_call): Add GOMP_TASK_FLAG_REDUCTION flag to flags if + there are any reduction clauses. + (expand_taskwait_call): New function. + (expand_teams_call): New function. + (expand_omp_taskreg): Allow GIMPLE_OMP_TEAMS and call + expand_teams_call for it. Formatting fix. Handle taskwait with + depend clauses. + (expand_omp_for_generic): Add SCHED_ARG argument. Handle expansion + of worksharing loops with task reductions. + (expand_omp_for_static_nochunk, expand_omp_for_static_chunk): Handle + expansion of worksharing loops with task reductions. + (expand_omp_sections): Handle expansion of sections with task + reductions. + (expand_omp_synch): For host teams call expand_omp_taskreg. + (omp_memory_order_to_memmodel): New function. + (expand_omp_atomic_load, expand_omp_atomic_store, + expand_omp_atomic_fetch_op): Use it and gimple_omp_atomic_memory_order + instead of gimple_omp_atomic_seq_cst_p. + (build_omp_regions_1, omp_make_gimple_edges): Treat taskwait with + depend clauses as a standalone directive. + * omp-general.c (enum omp_requires): New variable. + (omp_extract_for_data): Initialize have_reductemp member. Allow + NE_EXPR even in OpenMP loops, transform them into LT_EXPR or + GT_EXPR loops depending on incr sign. Formatting fixes. + * omp-general.h (struct omp_for_data): Add have_reductemp member. + (enum omp_requires): New enum. + (omp_requires_mask): Declare. + * omp-grid.c (grid_eliminate_combined_simd_part): Formatting fix. + Fix comment typos. + * omp-low.c (struct omp_context): Add task_reductions and + task_reduction_map fields. + (is_host_teams_ctx): New function. + (is_taskreg_ctx): Return true also if is_host_teams_ctx. + (use_pointer_for_field): Use is_global_var instead of + TREE_STATIC || DECL_EXTERNAL, and apply only if not privatized + in outer contexts. + (build_outer_var_ref): Ignore taskgroup outer contexts. + (delete_omp_context): Release task_reductions and task_reduction_map. + (scan_sharing_clauses): Don't add any fields for reduction clause on + taskloop. Handle OMP_CLAUSE__REDUCTEMP_. Handle + OMP_CLAUSE_{IN,TASK}_REDUCTION and OMP_CLAUSE_REDUCTION with task + modifier. Don't ignore shared clauses in is_host_teams_ctx contexts. + Handle OMP_CLAUSE_NONTEMPORAL. + (add_taskreg_looptemp_clauses): Add OMP_CLAUSE__REDUCTEMP_ clause if + needed. + (scan_omp_parallel): Add _reductemp_ clause if there are any reduction + clauses with task modifier. + (scan_omp_task): Handle taskwait with depend clauses. + (finish_taskreg_scan): Move field corresponding to _reductemp_ clause + first. Move also OMP_CLAUSE__REDUCTEMP_ clause in front if present. + Handle GIMPLE_OMP_TEAMS like GIMPLE_OMP_PARALLEL. + (scan_omp_for): Fix comment formatting. + (scan_omp_teams): Handle host teams constructs. + (check_omp_nesting_restrictions): Allow teams with no outer + OpenMP context. Adjust diagnostics for teams strictly nested into + some explicit OpenMP construct other than target. Allow OpenMP atomics + inside of simd regions. + (scan_omp_1_stmt): Call scan_sharing_clauses for taskgroups. + (scan_omp_1_stmt) <case GIMPLE_OMP_TEAMS>: Temporarily bump + taskreg_nesting_level while scanning host teams construct. + (task_reduction_read): New function. + (lower_rec_input_clauses): Handle OMP_CLAUSE_REDUCTION on taskloop + construct. Handle OMP_CLAUSE_IN_REDUCTION and OMP_CLAUSE__REDUCTEMP_ + clauses. Handle OMP_CLAUSE_REDUCTION with task modifier. Remove + second argument create_tmp_var if it is NULL. Don't ignore shared + clauses in is_host_teams_ctx contexts. Handle + OMP_CLAUSE_FIRSTPRIVATE_NO_REFERENCE on OMP_CLAUSE_FIRSTPRIVATE + clauses. + (lower_reduction_clauses): Ignore reduction clauses with task + modifier. Remove second argument create_tmp_var if it is NULL. + Initialize OMP_ATOMIC_MEMORY_ORDER to relaxed. + (lower_send_clauses): Ignore reduction clauses with task modifier. + Handle OMP_CLAUSE__REDUCTEMP_. Don't send anything for + OMP_CLAUSE_REDUCTION on taskloop. Handle OMP_CLAUSE_IN_REDUCTION. + (maybe_add_implicit_barrier_cancel): Add OMP_RETURN argument, don't + rely that it is the last stmt in body so far. Ignore outer taskgroup + contexts. + (omp_task_reductions_find_first, omp_task_reduction_iterate, + lower_omp_task_reductions): New functions. + (lower_omp_sections): Handle reduction clauses with taskgroup + modifiers. Adjust maybe_add_implicit_barrier_cancel caller. + (lower_omp_single): Adjust maybe_add_implicit_barrier_cancel caller. + (lower_omp_for): Likewise. Handle reduction clauses with taskgroup + modifiers. + (lower_omp_taskgroup): Handle taskgroup reductions. + (create_task_copyfn): Copy over OMP_CLAUSE__REDUCTEMP_ pointer. + Handle OMP_CLAUSE_IN_REDUCTION and OMP_CLAUSE_REDUCTION clauses. + (lower_depend_clauses): If there are any + OMP_CLAUSE_DEPEND_DEPOBJ or OMP_CLAUSE_DEPEND_MUTEXINOUTSET + depend clauses, use a new array format. If OMP_CLAUSE_DEPEND_LAST is + seen, assume lowering is done already and return early. Set kind + on artificial depend clause to OMP_CLAUSE_DEPEND_LAST. + (lower_omp_taskreg): Handle reduction clauses with task modifier on + parallel construct. Handle reduction clause on taskloop construct. + Handle taskwait with depend clauses. + (lower_omp_1): Use lower_omp_taskreg instead of lower_omp_teams + for host teams constructs. + * tree.c (omp_clause_num_ops): Add in_reduction, task_reduction, + nontemporal and _reductemp_ clause entries. + (omp_clause_code_name): Likewise. + (walk_tree_1): Handle OMP_CLAUSE_{IN,TASK}_REDUCTION, + OMP_CLAUSE_NONTEMPORAL and OMP_CLAUSE__REDUCTEMP_. + * tree-core.h (enum omp_clause_code): Add + OMP_CLAUSE_{{IN,TASK}_REDUCTION,NONTEMPORAL,_REDUCTEMP_}. + (enum omp_clause_defaultmap_kind, enum omp_memory_order): New. + (struct tree_base): Add omp_atomic_memory_order field into union. + Remove OMP_ATOMIC_SEQ_CST comment. + (enum omp_clause_depend_kind): Add OMP_CLAUSE_DEPEND_MUTEXINOUTSET + and OMP_CLAUSE_DEPEND_DEPOBJ. + (struct tree_omp_clause): Add subcode.defaultmap_kind. + * tree.def (OMP_TASKGROUP): Add another operand, move next to other + OpenMP constructs with body and clauses operands. + * tree.h (OMP_BODY): Use OMP_MASTER instead of OMP_TASKGROUP. + (OMP_CLAUSES): Use OMP_TASKGROUP instead of OMP_SINGLE. + (OMP_TASKGROUP_CLAUSES): Define. + (OMP_CLAUSE_DECL): Use OMP_CLAUSE__REDUCTEMP_ instead of + OMP_CLAUSE__LOOPTEMP_. + (OMP_ATOMIC_SEQ_CST): Remove. + (OMP_ATOMIC_MEMORY_ORDER, OMP_CLAUSE_FIRSTPRIVATE_NO_REFERENCE, + OMP_CLAUSE_LASTPRIVATE_CONDITIONAL): Define. + (OMP_CLAUSE_REDUCTION_CODE, OMP_CLAUSE_REDUCTION_INIT, + OMP_CLAUSE_REDUCTION_MERGE, OMP_CLAUSE_REDUCTION_PLACEHOLDER, + OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER, + OMP_CLAUSE_REDUCTION_OMP_ORIG_REF): Handle + OMP_CLAUSE_{,IN_,TASK_}REDUCTION. + (OMP_CLAUSE_REDUCTION_TASK, OMP_CLAUSE_REDUCTION_INSCAN, + OMP_CLAUSE_DEFAULTMAP_KIND, OMP_CLAUSE_DEFAULTMAP_CATEGORY, + OMP_CLAUSE_DEFAULTMAP_BEHAVIOR, OMP_CLAUSE_DEFAULTMAP_SET_KIND): + Define. + * tree-inline.c (remap_gimple_stmt): Remap taskgroup clauses. + * tree-nested.c (convert_nonlocal_omp_clauses): Handle + OMP_CLAUSE__REDUCTEMP_, OMP_CLAUSE_NONTEMPORAL. + (convert_local_omp_clauses): Likewise. Remove useless test. + * tree-parloops.c (create_call_for_reduction_1): Pass + OMP_MEMORY_ORDER_RELAXED as new argument to + dump_gimple_omp_atomic_load and dump_gimple_omp_atomic_store. + * tree-pretty-print.c (dump_omp_iterators): New function. + (dump_omp_clause): Handle OMP_CLAUSE__REDUCTEMP_, + OMP_CLAUSE_NONTEMPORAL, OMP_CLAUSE_{TASK,IN}_REDUCTION. Print + reduction modifiers. Handle OMP_CLAUSE_DEPEND_DEPOBJ and + OMP_CLAUSE_DEPEND_MUTEXINOUTSET. Print iterators in depend clauses. + Print __internal__ for OMP_CLAUSE_DEPEND_LAST. Handle cancel and + simd OMP_CLAUSE_IF_MODIFIERs. Handle new kinds of + OMP_CLAUSE_DEFAULTMAP. Print conditional: for + OMP_CLAUSE_LASTPRIVATE_CONDITIONAL. + (dump_omp_atomic_memory_order): New function. + (dump_generic_node): Use it. Print taskgroup clauses. Print + taskwait with depend clauses. + * tree-pretty-print.h (dump_omp_atomic_memory_order): Declare. + * tree-streamer-in.c (unpack_ts_omp_clause_value_fields): + Handle OMP_CLAUSE_{TASK,IN}_REDUCTION. + * tree-streamer-out.c (pack_ts_omp_clause_value_fields, + write_ts_omp_clause_tree_pointers): Likewise. + 2018-11-08 David Malcolm <dmalcolm@redhat.com> PR ipa/86395 diff --git a/gcc/Makefile.in b/gcc/Makefile.in index 6130554..16c9ed6 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -2579,6 +2579,7 @@ GTFILES = $(CPPLIB_H) $(srcdir)/input.h $(srcdir)/coretypes.h \ $(srcdir)/internal-fn.h \ $(srcdir)/hsa-common.c \ $(srcdir)/calls.c \ + $(srcdir)/omp-general.h \ @all_gtfiles@ # Compute the list of GT header files from the corresponding C sources, diff --git a/gcc/builtin-types.def b/gcc/builtin-types.def index f13da6a..685b22f 100644 --- a/gcc/builtin-types.def +++ b/gcc/builtin-types.def @@ -251,6 +251,7 @@ DEF_FUNCTION_TYPE_1 (BT_FN_INT_CONST_STRING, BT_INT, BT_CONST_STRING) DEF_FUNCTION_TYPE_1 (BT_FN_PTR_PTR, BT_PTR, BT_PTR) DEF_FUNCTION_TYPE_1 (BT_FN_VOID_VALIST_REF, BT_VOID, BT_VALIST_REF) DEF_FUNCTION_TYPE_1 (BT_FN_VOID_INT, BT_VOID, BT_INT) +DEF_FUNCTION_TYPE_1 (BT_FN_VOID_BOOL, BT_VOID, BT_BOOL) DEF_FUNCTION_TYPE_1 (BT_FN_FLOAT_CONST_STRING, BT_FLOAT, BT_CONST_STRING) DEF_FUNCTION_TYPE_1 (BT_FN_DOUBLE_CONST_STRING, BT_DOUBLE, BT_CONST_STRING) DEF_FUNCTION_TYPE_1 (BT_FN_LONGDOUBLE_CONST_STRING, @@ -621,6 +622,9 @@ DEF_FUNCTION_TYPE_3 (BT_FN_VOID_UINT32_UINT64_PTR, BT_VOID, BT_UINT32, BT_UINT64, BT_PTR) DEF_FUNCTION_TYPE_3 (BT_FN_VOID_UINT32_UINT32_PTR, BT_VOID, BT_UINT32, BT_UINT32, BT_PTR) +DEF_FUNCTION_TYPE_3 (BT_FN_VOID_SIZE_SIZE_PTR, BT_VOID, BT_SIZE, BT_SIZE, + BT_PTR) +DEF_FUNCTION_TYPE_3 (BT_FN_UINT_UINT_PTR_PTR, BT_UINT, BT_UINT, BT_PTR, BT_PTR) DEF_FUNCTION_TYPE_4 (BT_FN_SIZE_CONST_PTR_SIZE_SIZE_FILEPTR, BT_SIZE, BT_CONST_PTR, BT_SIZE, BT_SIZE, BT_FILEPTR) @@ -644,6 +648,8 @@ DEF_FUNCTION_TYPE_4 (BT_FN_INT_FILEPTR_INT_CONST_STRING_VALIST_ARG, BT_INT, BT_FILEPTR, BT_INT, BT_CONST_STRING, BT_VALIST_ARG) DEF_FUNCTION_TYPE_4 (BT_FN_VOID_OMPFN_PTR_UINT_UINT, BT_VOID, BT_PTR_FN_VOID_PTR, BT_PTR, BT_UINT, BT_UINT) +DEF_FUNCTION_TYPE_4 (BT_FN_UINT_OMPFN_PTR_UINT_UINT, + BT_UINT, BT_PTR_FN_VOID_PTR, BT_PTR, BT_UINT, BT_UINT) DEF_FUNCTION_TYPE_4 (BT_FN_VOID_PTR_WORD_WORD_PTR, BT_VOID, BT_PTR, BT_WORD, BT_WORD, BT_PTR) DEF_FUNCTION_TYPE_4 (BT_FN_VOID_SIZE_VPTR_PTR_INT, BT_VOID, BT_SIZE, @@ -729,6 +735,12 @@ DEF_FUNCTION_TYPE_7 (BT_FN_VOID_INT_SIZE_PTR_PTR_PTR_UINT_PTR, DEF_FUNCTION_TYPE_8 (BT_FN_VOID_OMPFN_PTR_UINT_LONG_LONG_LONG_LONG_UINT, BT_VOID, BT_PTR_FN_VOID_PTR, BT_PTR, BT_UINT, BT_LONG, BT_LONG, BT_LONG, BT_LONG, BT_UINT) +DEF_FUNCTION_TYPE_8 (BT_FN_BOOL_UINT_LONGPTR_LONG_LONG_LONGPTR_LONGPTR_PTR_PTR, + BT_BOOL, BT_UINT, BT_PTR_LONG, BT_LONG, BT_LONG, + BT_PTR_LONG, BT_PTR_LONG, BT_PTR, BT_PTR) +DEF_FUNCTION_TYPE_8 (BT_FN_BOOL_UINT_ULLPTR_LONG_ULL_ULLPTR_ULLPTR_PTR_PTR, + BT_BOOL, BT_UINT, BT_PTR_ULONGLONG, BT_LONG, BT_ULONGLONG, + BT_PTR_ULONGLONG, BT_PTR_ULONGLONG, BT_PTR, BT_PTR) DEF_FUNCTION_TYPE_9 (BT_FN_VOID_OMPFN_PTR_OMPCPYFN_LONG_LONG_BOOL_UINT_PTR_INT, BT_VOID, BT_PTR_FN_VOID_PTR, BT_PTR, @@ -737,6 +749,14 @@ DEF_FUNCTION_TYPE_9 (BT_FN_VOID_OMPFN_PTR_OMPCPYFN_LONG_LONG_BOOL_UINT_PTR_INT, DEF_FUNCTION_TYPE_9 (BT_FN_VOID_INT_OMPFN_SIZE_PTR_PTR_PTR_UINT_PTR_PTR, BT_VOID, BT_INT, BT_PTR_FN_VOID_PTR, BT_SIZE, BT_PTR, BT_PTR, BT_PTR, BT_UINT, BT_PTR, BT_PTR) +DEF_FUNCTION_TYPE_9 (BT_FN_BOOL_LONG_LONG_LONG_LONG_LONG_LONGPTR_LONGPTR_PTR_PTR, + BT_BOOL, BT_LONG, BT_LONG, BT_LONG, BT_LONG, BT_LONG, + BT_PTR_LONG, BT_PTR_LONG, BT_PTR, BT_PTR) + +DEF_FUNCTION_TYPE_10 (BT_FN_BOOL_BOOL_ULL_ULL_ULL_LONG_ULL_ULLPTR_ULLPTR_PTR_PTR, + BT_BOOL, BT_BOOL, BT_ULONGLONG, BT_ULONGLONG, + BT_ULONGLONG, BT_LONG, BT_ULONGLONG, BT_PTR_ULONGLONG, + BT_PTR_ULONGLONG, BT_PTR, BT_PTR) DEF_FUNCTION_TYPE_11 (BT_FN_VOID_OMPFN_PTR_OMPCPYFN_LONG_LONG_UINT_LONG_INT_LONG_LONG_LONG, BT_VOID, BT_PTR_FN_VOID_PTR, BT_PTR, diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index ac23539..f1b9b27 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,41 @@ +2018-11-08 Jakub Jelinek <jakub@redhat.com> + + * c-common.h (c_finish_omp_taskgroup): Add CLAUSES argument. + (c_finish_omp_atomic): Replace bool SEQ_CST argument with + enum omp_memory_order MEMORY_ORDER. + (c_finish_omp_flush): Add MO argument. + (c_omp_depend_t_p, c_finish_omp_depobj): Declare. + (c_finish_omp_for): Add FINAL_P argument. + * c-omp.c: Include memmodel.h. + (c_finish_omp_taskgroup): Add CLAUSES argument. Set + OMP_TASKGROUP_CLAUSES to it. + (c_finish_omp_atomic): Replace bool SEQ_CST argument with + enum omp_memory_order MEMORY_ORDER. Set OMP_ATOMIC_MEMORY_ORDER + instead of OMP_ATOMIC_SEQ_CST. + (c_omp_depend_t_p, c_finish_omp_depobj): New functions. + (c_finish_omp_flush): Add MO argument, if not MEMMODEL_LAST, emit + __atomic_thread_fence call with the given value. + (check_omp_for_incr_expr): Formatting fixes. + (c_finish_omp_for): Add FINAL_P argument. Allow NE_EXPR + even in OpenMP loops, diagnose if NE_EXPR and incr expression + is not constant expression 1 or -1. Transform NE_EXPR loops + with iterators pointers to VLA into LT_EXPR or GT_EXPR loops. + (c_omp_check_loop_iv_r): Look for orig decl of C++ range for + loops too. + (c_omp_split_clauses): Add support for combined + #pragma omp parallel master and + #pragma omp {,parallel }master taskloop{, simd} constructs. + Handle OMP_CLAUSE_IN_REDUCTION. Handle OMP_CLAUSE_REDUCTION_TASK. + Handle OMP_CLAUSE_NONTEMPORAL. Handle splitting OMP_CLAUSE_IF + also to OMP_SIMD. Copy OMP_CLAUSE_LASTPRIVATE_CONDITIONAL. + (c_omp_predetermined_sharing): Don't return + OMP_CLAUSE_DEFAULT_SHARED for const qualified decls. + * c-pragma.c (omp_pragmas): Add PRAGMA_OMP_DEPOBJ and + PRAGMA_OMP_REQUIRES. + * c-pragma.h (enum pragma_kind): Likewise. + (enum pragma_omp_clause): Add PRAGMA_OMP_CLAUSE_NONTEMPORAL + and PRAGMA_OMP_CLAUSE_{IN,TASK}_REDUCTION. + 2018-11-08 David Malcolm <dmalcolm@redhat.com> * c-format.c (gcc_dump_printf_char_table): Add entry for %f. diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index 641fe57..a218432 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -1149,18 +1149,21 @@ enum c_omp_region_type }; extern tree c_finish_omp_master (location_t, tree); -extern tree c_finish_omp_taskgroup (location_t, tree); +extern tree c_finish_omp_taskgroup (location_t, tree, tree); extern tree c_finish_omp_critical (location_t, tree, tree, tree); extern tree c_finish_omp_ordered (location_t, tree, tree); extern void c_finish_omp_barrier (location_t); extern tree c_finish_omp_atomic (location_t, enum tree_code, enum tree_code, - tree, tree, tree, tree, tree, bool, bool, - bool = false); -extern void c_finish_omp_flush (location_t); + tree, tree, tree, tree, tree, bool, + enum omp_memory_order, bool = false); +extern bool c_omp_depend_t_p (tree); +extern void c_finish_omp_depobj (location_t, tree, enum omp_clause_depend_kind, + tree); +extern void c_finish_omp_flush (location_t, int); extern void c_finish_omp_taskwait (location_t); extern void c_finish_omp_taskyield (location_t); extern tree c_finish_omp_for (location_t, enum tree_code, tree, tree, tree, - tree, tree, tree, tree); + tree, tree, tree, tree, bool); extern bool c_omp_check_loop_iv (tree, tree, walk_tree_lh); extern bool c_omp_check_loop_iv_exprs (location_t, tree, tree, tree, tree, walk_tree_lh); diff --git a/gcc/c-family/c-omp.c b/gcc/c-family/c-omp.c index 8984937..c7d4456 100644 --- a/gcc/c-family/c-omp.c +++ b/gcc/c-family/c-omp.c @@ -28,8 +28,10 @@ along with GCC; see the file COPYING3. If not see #include "c-common.h" #include "gimple-expr.h" #include "c-pragma.h" +#include "stringpool.h" #include "omp-general.h" #include "gomp-constants.h" +#include "memmodel.h" /* Complete a #pragma oacc wait construct. LOC is the location of @@ -70,7 +72,7 @@ c_finish_oacc_wait (location_t loc, tree parms, tree clauses) } /* Complete a #pragma omp master construct. STMT is the structured-block - that follows the pragma. LOC is the l*/ + that follows the pragma. LOC is the location of the #pragma. */ tree c_finish_omp_master (location_t loc, tree stmt) @@ -80,18 +82,21 @@ c_finish_omp_master (location_t loc, tree stmt) return t; } -/* Complete a #pragma omp taskgroup construct. STMT is the structured-block - that follows the pragma. LOC is the l*/ +/* Complete a #pragma omp taskgroup construct. BODY is the structured-block + that follows the pragma. LOC is the location of the #pragma. */ tree -c_finish_omp_taskgroup (location_t loc, tree stmt) +c_finish_omp_taskgroup (location_t loc, tree body, tree clauses) { - tree t = add_stmt (build1 (OMP_TASKGROUP, void_type_node, stmt)); - SET_EXPR_LOCATION (t, loc); - return t; + tree stmt = make_node (OMP_TASKGROUP); + TREE_TYPE (stmt) = void_type_node; + OMP_TASKGROUP_BODY (stmt) = body; + OMP_TASKGROUP_CLAUSES (stmt) = clauses; + SET_EXPR_LOCATION (stmt, loc); + return add_stmt (stmt); } -/* Complete a #pragma omp critical construct. STMT is the structured-block +/* Complete a #pragma omp critical construct. BODY is the structured-block that follows the pragma, NAME is the identifier in the pragma, or null if it was omitted. LOC is the location of the #pragma. */ @@ -181,8 +186,8 @@ c_finish_omp_taskyield (location_t loc) tree c_finish_omp_atomic (location_t loc, enum tree_code code, enum tree_code opcode, tree lhs, tree rhs, - tree v, tree lhs1, tree rhs1, bool swapped, bool seq_cst, - bool test) + tree v, tree lhs1, tree rhs1, bool swapped, + enum omp_memory_order memory_order, bool test) { tree x, type, addr, pre = NULL_TREE; HOST_WIDE_INT bitpos = 0, bitsize = 0; @@ -264,7 +269,7 @@ c_finish_omp_atomic (location_t loc, enum tree_code code, { x = build1 (OMP_ATOMIC_READ, type, addr); SET_EXPR_LOCATION (x, loc); - OMP_ATOMIC_SEQ_CST (x) = seq_cst; + OMP_ATOMIC_MEMORY_ORDER (x) = memory_order; if (blhs) x = build3_loc (loc, BIT_FIELD_REF, TREE_TYPE (blhs), x, bitsize_int (bitsize), bitsize_int (bitpos)); @@ -315,7 +320,7 @@ c_finish_omp_atomic (location_t loc, enum tree_code code, type = void_type_node; x = build2 (code, type, addr, rhs); SET_EXPR_LOCATION (x, loc); - OMP_ATOMIC_SEQ_CST (x) = seq_cst; + OMP_ATOMIC_MEMORY_ORDER (x) = memory_order; /* Generally it is hard to prove lhs1 and lhs are the same memory location, just diagnose different variables. */ @@ -413,17 +418,173 @@ c_finish_omp_atomic (location_t loc, enum tree_code code, } +/* Return true if TYPE is the implementation's omp_depend_t. */ + +bool +c_omp_depend_t_p (tree type) +{ + type = TYPE_MAIN_VARIANT (type); + return (TREE_CODE (type) == RECORD_TYPE + && TYPE_NAME (type) + && ((TREE_CODE (TYPE_NAME (type)) == TYPE_DECL + ? DECL_NAME (TYPE_NAME (type)) : TYPE_NAME (type)) + == get_identifier ("omp_depend_t")) + && (!TYPE_CONTEXT (type) + || TREE_CODE (TYPE_CONTEXT (type)) == TRANSLATION_UNIT_DECL) + && COMPLETE_TYPE_P (type) + && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST + && !compare_tree_int (TYPE_SIZE (type), + 2 * tree_to_uhwi (TYPE_SIZE (ptr_type_node)))); +} + + +/* Complete a #pragma omp depobj construct. LOC is the location of the + #pragma. */ + +void +c_finish_omp_depobj (location_t loc, tree depobj, + enum omp_clause_depend_kind kind, tree clause) +{ + tree t = NULL_TREE; + if (!error_operand_p (depobj)) + { + if (!c_omp_depend_t_p (TREE_TYPE (depobj))) + { + error_at (EXPR_LOC_OR_LOC (depobj, loc), + "type of %<depobj%> expression is not %<omp_depend_t%>"); + depobj = error_mark_node; + } + else if (TYPE_READONLY (TREE_TYPE (depobj))) + { + error_at (EXPR_LOC_OR_LOC (depobj, loc), + "%<const%> qualified %<depobj%> expression"); + depobj = error_mark_node; + } + } + else + depobj = error_mark_node; + + if (clause == error_mark_node) + return; + + if (clause) + { + gcc_assert (TREE_CODE (clause) == OMP_CLAUSE + && OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_DEPEND); + if (OMP_CLAUSE_CHAIN (clause)) + error_at (OMP_CLAUSE_LOCATION (clause), + "more than one locator in %<depend%> clause on %<depobj%> " + "construct"); + switch (OMP_CLAUSE_DEPEND_KIND (clause)) + { + case OMP_CLAUSE_DEPEND_DEPOBJ: + error_at (OMP_CLAUSE_LOCATION (clause), + "%<depobj%> dependence type specified in %<depend%> " + "clause on %<depobj%> construct"); + return; + case OMP_CLAUSE_DEPEND_SOURCE: + case OMP_CLAUSE_DEPEND_SINK: + error_at (OMP_CLAUSE_LOCATION (clause), + "%<depend(%s)%> is only allowed in %<omp ordered%>", + OMP_CLAUSE_DEPEND_KIND (clause) == OMP_CLAUSE_DEPEND_SOURCE + ? "source" : "sink"); + return; + case OMP_CLAUSE_DEPEND_IN: + case OMP_CLAUSE_DEPEND_OUT: + case OMP_CLAUSE_DEPEND_INOUT: + case OMP_CLAUSE_DEPEND_MUTEXINOUTSET: + kind = OMP_CLAUSE_DEPEND_KIND (clause); + t = OMP_CLAUSE_DECL (clause); + gcc_assert (t); + if (TREE_CODE (t) == TREE_LIST + && TREE_PURPOSE (t) + && TREE_CODE (TREE_PURPOSE (t)) == TREE_VEC) + { + error_at (OMP_CLAUSE_LOCATION (clause), + "%<iterator%> modifier may not be specified on " + "%<depobj%> construct"); + return; + } + if (TREE_CODE (t) == COMPOUND_EXPR) + { + tree t1 = build_fold_addr_expr (TREE_OPERAND (t, 1)); + t = build2 (COMPOUND_EXPR, TREE_TYPE (t1), TREE_OPERAND (t, 0), + t1); + } + else + t = build_fold_addr_expr (t); + break; + default: + gcc_unreachable (); + } + } + else + gcc_assert (kind != OMP_CLAUSE_DEPEND_SOURCE); + + if (depobj == error_mark_node) + return; + + depobj = build_fold_addr_expr_loc (EXPR_LOC_OR_LOC (depobj, loc), depobj); + tree dtype + = build_pointer_type_for_mode (ptr_type_node, TYPE_MODE (ptr_type_node), + true); + depobj = fold_convert (dtype, depobj); + tree r; + if (clause) + { + depobj = save_expr (depobj); + r = build_indirect_ref (loc, depobj, RO_UNARY_STAR); + add_stmt (build2 (MODIFY_EXPR, void_type_node, r, t)); + } + int k; + switch (kind) + { + case OMP_CLAUSE_DEPEND_IN: + k = GOMP_DEPEND_IN; + break; + case OMP_CLAUSE_DEPEND_OUT: + k = GOMP_DEPEND_OUT; + break; + case OMP_CLAUSE_DEPEND_INOUT: + k = GOMP_DEPEND_INOUT; + break; + case OMP_CLAUSE_DEPEND_MUTEXINOUTSET: + k = GOMP_DEPEND_MUTEXINOUTSET; + break; + case OMP_CLAUSE_DEPEND_LAST: + k = -1; + break; + default: + gcc_unreachable (); + } + t = build_int_cst (ptr_type_node, k); + depobj = build2_loc (loc, POINTER_PLUS_EXPR, TREE_TYPE (depobj), depobj, + TYPE_SIZE_UNIT (ptr_type_node)); + r = build_indirect_ref (loc, depobj, RO_UNARY_STAR); + add_stmt (build2 (MODIFY_EXPR, void_type_node, r, t)); +} + + /* Complete a #pragma omp flush construct. We don't do anything with the variable list that the syntax allows. LOC is the location of the #pragma. */ void -c_finish_omp_flush (location_t loc) +c_finish_omp_flush (location_t loc, int mo) { tree x; - x = builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE); - x = build_call_expr_loc (loc, x, 0); + if (mo == MEMMODEL_LAST) + { + x = builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE); + x = build_call_expr_loc (loc, x, 0); + } + else + { + x = builtin_decl_explicit (BUILT_IN_ATOMIC_THREAD_FENCE); + x = build_call_expr_loc (loc, x, 1, + build_int_cst (integer_type_node, mo)); + } add_stmt (x); } @@ -454,17 +615,17 @@ check_omp_for_incr_expr (location_t loc, tree exp, tree decl) t = check_omp_for_incr_expr (loc, TREE_OPERAND (exp, 0), decl); if (t != error_mark_node) return fold_build2_loc (loc, MINUS_EXPR, - TREE_TYPE (exp), t, TREE_OPERAND (exp, 1)); + TREE_TYPE (exp), t, TREE_OPERAND (exp, 1)); break; case PLUS_EXPR: t = check_omp_for_incr_expr (loc, TREE_OPERAND (exp, 0), decl); if (t != error_mark_node) return fold_build2_loc (loc, PLUS_EXPR, - TREE_TYPE (exp), t, TREE_OPERAND (exp, 1)); + TREE_TYPE (exp), t, TREE_OPERAND (exp, 1)); t = check_omp_for_incr_expr (loc, TREE_OPERAND (exp, 1), decl); if (t != error_mark_node) return fold_build2_loc (loc, PLUS_EXPR, - TREE_TYPE (exp), TREE_OPERAND (exp, 0), t); + TREE_TYPE (exp), TREE_OPERAND (exp, 0), t); break; case COMPOUND_EXPR: { @@ -530,7 +691,7 @@ c_omp_for_incr_canonicalize_ptr (location_t loc, tree decl, tree incr) tree c_finish_omp_for (location_t locus, enum tree_code code, tree declv, tree orig_declv, tree initv, tree condv, tree incrv, - tree body, tree pre_body) + tree body, tree pre_body, bool final_p) { location_t elocus; bool fail = false; @@ -667,7 +828,8 @@ c_finish_omp_for (location_t locus, enum tree_code code, tree declv, { if (!INTEGRAL_TYPE_P (TREE_TYPE (decl))) { - cond_ok = false; + if (code == OACC_LOOP || TREE_CODE (cond) == EQ_EXPR) + cond_ok = false; } else if (operand_equal_p (TREE_OPERAND (cond, 1), TYPE_MIN_VALUE (TREE_TYPE (decl)), @@ -679,7 +841,7 @@ c_finish_omp_for (location_t locus, enum tree_code code, tree declv, 0)) TREE_SET_CODE (cond, TREE_CODE (cond) == NE_EXPR ? LT_EXPR : GE_EXPR); - else + else if (code == OACC_LOOP || TREE_CODE (cond) == EQ_EXPR) cond_ok = false; } @@ -730,6 +892,21 @@ c_finish_omp_for (location_t locus, enum tree_code code, tree declv, break; incr_ok = true; + if (!fail + && TREE_CODE (cond) == NE_EXPR + && TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE + && TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl))) + && (TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl)))) + != INTEGER_CST)) + { + /* For pointer to VLA, transform != into < or > + depending on whether incr is increment or decrement. */ + if (TREE_CODE (incr) == PREINCREMENT_EXPR + || TREE_CODE (incr) == POSTINCREMENT_EXPR) + TREE_SET_CODE (cond, LT_EXPR); + else + TREE_SET_CODE (cond, GT_EXPR); + } incr = c_omp_for_incr_canonicalize_ptr (elocus, decl, incr); break; @@ -765,6 +942,58 @@ c_finish_omp_for (location_t locus, enum tree_code code, tree declv, incr = build2 (MODIFY_EXPR, void_type_node, decl, t); } } + if (!fail + && incr_ok + && TREE_CODE (cond) == NE_EXPR) + { + tree i = TREE_OPERAND (incr, 1); + i = TREE_OPERAND (i, TREE_OPERAND (i, 0) == decl); + i = c_fully_fold (i, false, NULL); + if (!final_p + && TREE_CODE (i) != INTEGER_CST) + ; + else if (TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE) + { + tree unit + = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl))); + if (unit) + { + enum tree_code ccode = GT_EXPR; + unit = c_fully_fold (unit, false, NULL); + i = fold_convert (TREE_TYPE (unit), i); + if (operand_equal_p (unit, i, 0)) + ccode = LT_EXPR; + if (ccode == GT_EXPR) + { + i = fold_unary (NEGATE_EXPR, TREE_TYPE (i), i); + if (i == NULL_TREE + || !operand_equal_p (unit, i, 0)) + { + error_at (elocus, + "increment is not constant 1 or " + "-1 for != condition"); + fail = true; + } + } + if (TREE_CODE (unit) != INTEGER_CST) + /* For pointer to VLA, transform != into < or > + depending on whether the pointer is + incremented or decremented in each + iteration. */ + TREE_SET_CODE (cond, ccode); + } + } + else + { + if (!integer_onep (i) && !integer_minus_onep (i)) + { + error_at (elocus, + "increment is not constant 1 or -1 for" + " != condition"); + fail = true; + } + } + } break; default: @@ -829,7 +1058,13 @@ c_omp_check_loop_iv_r (tree *tp, int *walk_subtrees, void *data) for (i = 0; i < TREE_VEC_LENGTH (d->declv); i++) if (*tp == TREE_VEC_ELT (d->declv, i) || (TREE_CODE (TREE_VEC_ELT (d->declv, i)) == TREE_LIST - && *tp == TREE_PURPOSE (TREE_VEC_ELT (d->declv, i)))) + && *tp == TREE_PURPOSE (TREE_VEC_ELT (d->declv, i))) + || (TREE_CODE (TREE_VEC_ELT (d->declv, i)) == TREE_LIST + && TREE_CHAIN (TREE_VEC_ELT (d->declv, i)) + && (TREE_CODE (TREE_CHAIN (TREE_VEC_ELT (d->declv, i))) + == TREE_VEC) + && *tp == TREE_VEC_ELT (TREE_CHAIN (TREE_VEC_ELT (d->declv, + i)), 2))) { location_t loc = d->expr_loc; if (loc == UNKNOWN_LOCATION) @@ -1025,18 +1260,24 @@ c_oacc_split_loop_clauses (tree clauses, tree *not_loop_clauses, } /* This function attempts to split or duplicate clauses for OpenMP - combined/composite constructs. Right now there are 21 different + combined/composite constructs. Right now there are 26 different constructs. CODE is the innermost construct in the combined construct, and MASK allows to determine which constructs are combined together, as every construct has at least one clause that no other construct - has (except for OMP_SECTIONS, but that can be only combined with parallel). + has (except for OMP_SECTIONS, but that can be only combined with parallel, + and OMP_MASTER, which doesn't have any clauses at all). OpenMP combined/composite constructs are: #pragma omp distribute parallel for #pragma omp distribute parallel for simd #pragma omp distribute simd #pragma omp for simd + #pragma omp master taskloop + #pragma omp master taskloop simd #pragma omp parallel for #pragma omp parallel for simd + #pragma omp parallel master + #pragma omp parallel master taskloop + #pragma omp parallel master taskloop simd #pragma omp parallel sections #pragma omp target parallel #pragma omp target parallel for @@ -1070,8 +1311,9 @@ c_omp_split_clauses (location_t loc, enum tree_code code, { case OMP_FOR: case OMP_SIMD: - cclauses[C_OMP_CLAUSE_SPLIT_FOR] - = build_omp_clause (loc, OMP_CLAUSE_NOWAIT); + if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE)) != 0) + cclauses[C_OMP_CLAUSE_SPLIT_FOR] + = build_omp_clause (loc, OMP_CLAUSE_NOWAIT); break; case OMP_SECTIONS: cclauses[C_OMP_CLAUSE_SPLIT_SECTIONS] @@ -1118,6 +1360,7 @@ c_omp_split_clauses (location_t loc, enum tree_code code, case OMP_CLAUSE_SAFELEN: case OMP_CLAUSE_SIMDLEN: case OMP_CLAUSE_ALIGNED: + case OMP_CLAUSE_NONTEMPORAL: s = C_OMP_CLAUSE_SPLIT_SIMD; break; case OMP_CLAUSE_GRAINSIZE: @@ -1175,8 +1418,8 @@ c_omp_split_clauses (location_t loc, enum tree_code code, else s = C_OMP_CLAUSE_SPLIT_DISTRIBUTE; break; - /* Private clause is supported on all constructs, - it is enough to put it on the innermost one. For + /* Private clause is supported on all constructs but master, + it is enough to put it on the innermost one other than master. For #pragma omp {for,sections} put it on parallel though, as that's what we did for OpenMP 3.1. */ case OMP_CLAUSE_PRIVATE: @@ -1187,12 +1430,14 @@ c_omp_split_clauses (location_t loc, enum tree_code code, case OMP_PARALLEL: s = C_OMP_CLAUSE_SPLIT_PARALLEL; break; case OMP_DISTRIBUTE: s = C_OMP_CLAUSE_SPLIT_DISTRIBUTE; break; case OMP_TEAMS: s = C_OMP_CLAUSE_SPLIT_TEAMS; break; + case OMP_MASTER: s = C_OMP_CLAUSE_SPLIT_PARALLEL; break; + case OMP_TASKLOOP: s = C_OMP_CLAUSE_SPLIT_TASKLOOP; break; default: gcc_unreachable (); } break; /* Firstprivate clause is supported on all constructs but - simd. Put it on the outermost of those and duplicate on teams - and parallel. */ + simd and master. Put it on the outermost of those and duplicate on + teams and parallel. */ case OMP_CLAUSE_FIRSTPRIVATE: if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP)) != 0) @@ -1231,6 +1476,11 @@ c_omp_split_clauses (location_t loc, enum tree_code code, else s = C_OMP_CLAUSE_SPLIT_DISTRIBUTE; } + else if ((mask & (OMP_CLAUSE_MASK_1 + << PRAGMA_OMP_CLAUSE_NOGROUP)) != 0) + /* This must be + #pragma omp parallel master taskloop{, simd}. */ + s = C_OMP_CLAUSE_SPLIT_TASKLOOP; else /* This must be #pragma omp parallel{, for{, simd}, sections} @@ -1260,8 +1510,10 @@ c_omp_split_clauses (location_t loc, enum tree_code code, else if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP)) != 0) { - /* This must be #pragma omp taskloop simd. */ - gcc_assert (code == OMP_SIMD); + /* This must be #pragma omp {,{,parallel }master }taskloop simd + or + #pragma omp {,parallel }master taskloop. */ + gcc_assert (code == OMP_SIMD || code == OMP_TASKLOOP); s = C_OMP_CLAUSE_SPLIT_TASKLOOP; } else @@ -1271,9 +1523,9 @@ c_omp_split_clauses (location_t loc, enum tree_code code, s = C_OMP_CLAUSE_SPLIT_FOR; } break; - /* Lastprivate is allowed on distribute, for, sections and simd. In - parallel {for{, simd},sections} we actually want to put it on - parallel rather than for or sections. */ + /* Lastprivate is allowed on distribute, for, sections, taskloop and + simd. In parallel {for{, simd},sections} we actually want to put + it on parallel rather than for or sections. */ case OMP_CLAUSE_LASTPRIVATE: if (code == OMP_DISTRIBUTE) { @@ -1287,6 +1539,8 @@ c_omp_split_clauses (location_t loc, enum tree_code code, OMP_CLAUSE_LASTPRIVATE); OMP_CLAUSE_DECL (c) = OMP_CLAUSE_DECL (clauses); OMP_CLAUSE_CHAIN (c) = cclauses[C_OMP_CLAUSE_SPLIT_DISTRIBUTE]; + OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c) + = OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (clauses); cclauses[C_OMP_CLAUSE_SPLIT_DISTRIBUTE] = c; } if (code == OMP_FOR || code == OMP_SECTIONS) @@ -1298,12 +1552,19 @@ c_omp_split_clauses (location_t loc, enum tree_code code, s = C_OMP_CLAUSE_SPLIT_FOR; break; } + if (code == OMP_TASKLOOP) + { + s = C_OMP_CLAUSE_SPLIT_TASKLOOP; + break; + } gcc_assert (code == OMP_SIMD); if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE)) != 0) { c = build_omp_clause (OMP_CLAUSE_LOCATION (clauses), OMP_CLAUSE_LASTPRIVATE); OMP_CLAUSE_DECL (c) = OMP_CLAUSE_DECL (clauses); + OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c) + = OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (clauses); if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS)) != 0) s = C_OMP_CLAUSE_SPLIT_PARALLEL; @@ -1312,6 +1573,16 @@ c_omp_split_clauses (location_t loc, enum tree_code code, OMP_CLAUSE_CHAIN (c) = cclauses[s]; cclauses[s] = c; } + if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP)) != 0) + { + c = build_omp_clause (OMP_CLAUSE_LOCATION (clauses), + OMP_CLAUSE_LASTPRIVATE); + OMP_CLAUSE_DECL (c) = OMP_CLAUSE_DECL (clauses); + OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c) + = OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (clauses); + OMP_CLAUSE_CHAIN (c) = cclauses[C_OMP_CLAUSE_SPLIT_TASKLOOP]; + cclauses[C_OMP_CLAUSE_SPLIT_TASKLOOP] = c; + } s = C_OMP_CLAUSE_SPLIT_SIMD; break; /* Shared and default clauses are allowed on parallel, teams and @@ -1321,6 +1592,19 @@ c_omp_split_clauses (location_t loc, enum tree_code code, if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP)) != 0) { + if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS)) + != 0) + { + c = build_omp_clause (OMP_CLAUSE_LOCATION (clauses), + OMP_CLAUSE_CODE (clauses)); + if (OMP_CLAUSE_CODE (clauses) == OMP_CLAUSE_SHARED) + OMP_CLAUSE_DECL (c) = OMP_CLAUSE_DECL (clauses); + else + OMP_CLAUSE_DEFAULT_KIND (c) + = OMP_CLAUSE_DEFAULT_KIND (clauses); + OMP_CLAUSE_CHAIN (c) = cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL]; + cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL] = c; + } s = C_OMP_CLAUSE_SPLIT_TASKLOOP; break; } @@ -1345,10 +1629,33 @@ c_omp_split_clauses (location_t loc, enum tree_code code, } s = C_OMP_CLAUSE_SPLIT_PARALLEL; break; - /* Reduction is allowed on simd, for, parallel, sections and teams. - Duplicate it on all of them, but omit on for or sections if - parallel is present. */ + /* Reduction is allowed on simd, for, parallel, sections, taskloop + and teams. Duplicate it on all of them, but omit on for or + sections if parallel is present. If taskloop is combined with + parallel, omit it on parallel. */ case OMP_CLAUSE_REDUCTION: + if (OMP_CLAUSE_REDUCTION_TASK (clauses)) + { + if (code == OMP_SIMD /* || code == OMP_LOOP */) + { + error_at (OMP_CLAUSE_LOCATION (clauses), + "invalid %<task%> reduction modifier on construct " + "combined with %<simd%>" /* or %<loop%> */); + OMP_CLAUSE_REDUCTION_TASK (clauses) = 0; + } + else if (code != OMP_SECTIONS + && (mask & (OMP_CLAUSE_MASK_1 + << PRAGMA_OMP_CLAUSE_SCHEDULE)) == 0 + && (mask & (OMP_CLAUSE_MASK_1 + << PRAGMA_OMP_CLAUSE_SCHEDULE)) == 0) + { + error_at (OMP_CLAUSE_LOCATION (clauses), + "invalid %<task%> reduction modifier on construct " + "not combined with %<parallel%>, %<for%> or " + "%<sections%>"); + OMP_CLAUSE_REDUCTION_TASK (clauses) = 0; + } + } if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE)) != 0) { if (code == OMP_SIMD) @@ -1377,9 +1684,9 @@ c_omp_split_clauses (location_t loc, enum tree_code code, = OMP_CLAUSE_REDUCTION_PLACEHOLDER (clauses); OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c) = OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (clauses); - OMP_CLAUSE_CHAIN (c) = cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL]; - cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL] = c; - s = C_OMP_CLAUSE_SPLIT_TEAMS; + OMP_CLAUSE_CHAIN (c) = cclauses[C_OMP_CLAUSE_SPLIT_TEAMS]; + cclauses[C_OMP_CLAUSE_SPLIT_TEAMS] = c; + s = C_OMP_CLAUSE_SPLIT_PARALLEL; } else if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS)) != 0) @@ -1387,46 +1694,154 @@ c_omp_split_clauses (location_t loc, enum tree_code code, else s = C_OMP_CLAUSE_SPLIT_FOR; } - else if (code == OMP_SECTIONS || code == OMP_PARALLEL) + else if (code == OMP_SECTIONS + || code == OMP_PARALLEL + || code == OMP_MASTER) s = C_OMP_CLAUSE_SPLIT_PARALLEL; + else if (code == OMP_TASKLOOP) + s = C_OMP_CLAUSE_SPLIT_TASKLOOP; else if (code == OMP_SIMD) - s = C_OMP_CLAUSE_SPLIT_SIMD; + { + if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP)) + != 0) + { + c = build_omp_clause (OMP_CLAUSE_LOCATION (clauses), + OMP_CLAUSE_REDUCTION); + OMP_CLAUSE_DECL (c) = OMP_CLAUSE_DECL (clauses); + OMP_CLAUSE_REDUCTION_CODE (c) + = OMP_CLAUSE_REDUCTION_CODE (clauses); + OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) + = OMP_CLAUSE_REDUCTION_PLACEHOLDER (clauses); + OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c) + = OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (clauses); + OMP_CLAUSE_CHAIN (c) = cclauses[C_OMP_CLAUSE_SPLIT_TASKLOOP]; + cclauses[C_OMP_CLAUSE_SPLIT_TASKLOOP] = c; + } + s = C_OMP_CLAUSE_SPLIT_SIMD; + } else s = C_OMP_CLAUSE_SPLIT_TEAMS; break; + case OMP_CLAUSE_IN_REDUCTION: + /* in_reduction on taskloop simd becomes reduction on the simd + and keeps being in_reduction on taskloop. */ + if (code == OMP_SIMD) + { + c = build_omp_clause (OMP_CLAUSE_LOCATION (clauses), + OMP_CLAUSE_REDUCTION); + OMP_CLAUSE_DECL (c) = OMP_CLAUSE_DECL (clauses); + OMP_CLAUSE_REDUCTION_CODE (c) + = OMP_CLAUSE_REDUCTION_CODE (clauses); + OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) + = OMP_CLAUSE_REDUCTION_PLACEHOLDER (clauses); + OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c) + = OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (clauses); + OMP_CLAUSE_CHAIN (c) = cclauses[C_OMP_CLAUSE_SPLIT_SIMD]; + cclauses[C_OMP_CLAUSE_SPLIT_SIMD] = c; + } + s = C_OMP_CLAUSE_SPLIT_TASKLOOP; + break; case OMP_CLAUSE_IF: + if (OMP_CLAUSE_IF_MODIFIER (clauses) != ERROR_MARK) + { + s = C_OMP_CLAUSE_SPLIT_COUNT; + switch (OMP_CLAUSE_IF_MODIFIER (clauses)) + { + case OMP_PARALLEL: + if ((mask & (OMP_CLAUSE_MASK_1 + << PRAGMA_OMP_CLAUSE_NUM_THREADS)) != 0) + s = C_OMP_CLAUSE_SPLIT_PARALLEL; + break; + case OMP_SIMD: + if (code == OMP_SIMD) + s = C_OMP_CLAUSE_SPLIT_SIMD; + break; + case OMP_TASKLOOP: + if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP)) + != 0) + s = C_OMP_CLAUSE_SPLIT_TASKLOOP; + break; + case OMP_TARGET: + if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP)) + != 0) + s = C_OMP_CLAUSE_SPLIT_TARGET; + break; + default: + break; + } + if (s != C_OMP_CLAUSE_SPLIT_COUNT) + break; + /* Error-recovery here, invalid if-modifier specified, add the + clause to just one construct. */ + if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP)) != 0) + s = C_OMP_CLAUSE_SPLIT_TARGET; + else if ((mask & (OMP_CLAUSE_MASK_1 + << PRAGMA_OMP_CLAUSE_NUM_THREADS)) != 0) + s = C_OMP_CLAUSE_SPLIT_PARALLEL; + else if ((mask & (OMP_CLAUSE_MASK_1 + << PRAGMA_OMP_CLAUSE_NOGROUP)) != 0) + s = C_OMP_CLAUSE_SPLIT_TASKLOOP; + else if (code == OMP_SIMD) + s = C_OMP_CLAUSE_SPLIT_SIMD; + else + gcc_unreachable (); + break; + } + /* Otherwise, duplicate if clause to all constructs. */ + if (code == OMP_SIMD) + { + if ((mask & ((OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) + | (OMP_CLAUSE_MASK_1 + << PRAGMA_OMP_CLAUSE_NUM_THREADS) + | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP))) + != 0) + { + c = build_omp_clause (OMP_CLAUSE_LOCATION (clauses), + OMP_CLAUSE_IF); + OMP_CLAUSE_IF_MODIFIER (c) + = OMP_CLAUSE_IF_MODIFIER (clauses); + OMP_CLAUSE_IF_EXPR (c) = OMP_CLAUSE_IF_EXPR (clauses); + OMP_CLAUSE_CHAIN (c) = cclauses[C_OMP_CLAUSE_SPLIT_SIMD]; + cclauses[C_OMP_CLAUSE_SPLIT_SIMD] = c; + } + else + { + s = C_OMP_CLAUSE_SPLIT_SIMD; + break; + } + } if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP)) != 0) - s = C_OMP_CLAUSE_SPLIT_TASKLOOP; + { + if ((mask & (OMP_CLAUSE_MASK_1 + << PRAGMA_OMP_CLAUSE_NUM_THREADS)) != 0) + { + c = build_omp_clause (OMP_CLAUSE_LOCATION (clauses), + OMP_CLAUSE_IF); + OMP_CLAUSE_IF_MODIFIER (c) + = OMP_CLAUSE_IF_MODIFIER (clauses); + OMP_CLAUSE_IF_EXPR (c) = OMP_CLAUSE_IF_EXPR (clauses); + OMP_CLAUSE_CHAIN (c) = cclauses[C_OMP_CLAUSE_SPLIT_TASKLOOP]; + cclauses[C_OMP_CLAUSE_SPLIT_TASKLOOP] = c; + s = C_OMP_CLAUSE_SPLIT_PARALLEL; + } + else + s = C_OMP_CLAUSE_SPLIT_TASKLOOP; + } else if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS)) != 0) { if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP)) != 0) { - if (OMP_CLAUSE_IF_MODIFIER (clauses) == OMP_PARALLEL) - s = C_OMP_CLAUSE_SPLIT_PARALLEL; - else if (OMP_CLAUSE_IF_MODIFIER (clauses) == OMP_TARGET) - s = C_OMP_CLAUSE_SPLIT_TARGET; - else if (OMP_CLAUSE_IF_MODIFIER (clauses) == ERROR_MARK) - { - c = build_omp_clause (OMP_CLAUSE_LOCATION (clauses), - OMP_CLAUSE_IF); - OMP_CLAUSE_IF_MODIFIER (c) - = OMP_CLAUSE_IF_MODIFIER (clauses); - OMP_CLAUSE_IF_EXPR (c) = OMP_CLAUSE_IF_EXPR (clauses); - OMP_CLAUSE_CHAIN (c) - = cclauses[C_OMP_CLAUSE_SPLIT_TARGET]; - cclauses[C_OMP_CLAUSE_SPLIT_TARGET] = c; - s = C_OMP_CLAUSE_SPLIT_PARALLEL; - } - else - { - error_at (OMP_CLAUSE_LOCATION (clauses), - "expected %<parallel%> or %<target%> %<if%> " - "clause modifier"); - continue; - } + c = build_omp_clause (OMP_CLAUSE_LOCATION (clauses), + OMP_CLAUSE_IF); + OMP_CLAUSE_IF_MODIFIER (c) + = OMP_CLAUSE_IF_MODIFIER (clauses); + OMP_CLAUSE_IF_EXPR (c) = OMP_CLAUSE_IF_EXPR (clauses); + OMP_CLAUSE_CHAIN (c) = cclauses[C_OMP_CLAUSE_SPLIT_TARGET]; + cclauses[C_OMP_CLAUSE_SPLIT_TARGET] = c; + s = C_OMP_CLAUSE_SPLIT_PARALLEL; } else s = C_OMP_CLAUSE_SPLIT_PARALLEL; @@ -1610,11 +2025,6 @@ c_omp_declare_simd_clauses_to_decls (tree fndecl, tree clauses) enum omp_clause_default_kind c_omp_predetermined_sharing (tree decl) { - /* Variables with const-qualified type having no mutable member - are predetermined shared. */ - if (TREE_READONLY (decl)) - return OMP_CLAUSE_DEFAULT_SHARED; - /* Predetermine artificial variables holding integral values, those are usually result of gimplify_one_sizepos or SAVE_EXPR gimplification. */ diff --git a/gcc/c-family/c-pragma.c b/gcc/c-family/c-pragma.c index 84e4341..fe21120 100644 --- a/gcc/c-family/c-pragma.c +++ b/gcc/c-family/c-pragma.c @@ -1286,9 +1286,11 @@ static const struct omp_pragma_def omp_pragmas[] = { { "cancel", PRAGMA_OMP_CANCEL }, { "cancellation", PRAGMA_OMP_CANCELLATION_POINT }, { "critical", PRAGMA_OMP_CRITICAL }, + { "depobj", PRAGMA_OMP_DEPOBJ }, { "end", PRAGMA_OMP_END_DECLARE_TARGET }, { "flush", PRAGMA_OMP_FLUSH }, { "master", PRAGMA_OMP_MASTER }, + { "requires", PRAGMA_OMP_REQUIRES }, { "section", PRAGMA_OMP_SECTION }, { "sections", PRAGMA_OMP_SECTIONS }, { "single", PRAGMA_OMP_SINGLE }, diff --git a/gcc/c-family/c-pragma.h b/gcc/c-family/c-pragma.h index b322547b..b781f73 100644 --- a/gcc/c-family/c-pragma.h +++ b/gcc/c-family/c-pragma.h @@ -47,6 +47,7 @@ enum pragma_kind { PRAGMA_OMP_CANCELLATION_POINT, PRAGMA_OMP_CRITICAL, PRAGMA_OMP_DECLARE, + PRAGMA_OMP_DEPOBJ, PRAGMA_OMP_DISTRIBUTE, PRAGMA_OMP_END_DECLARE_TARGET, PRAGMA_OMP_FLUSH, @@ -54,6 +55,7 @@ enum pragma_kind { PRAGMA_OMP_MASTER, PRAGMA_OMP_ORDERED, PRAGMA_OMP_PARALLEL, + PRAGMA_OMP_REQUIRES, PRAGMA_OMP_SECTION, PRAGMA_OMP_SECTIONS, PRAGMA_OMP_SIMD, @@ -75,8 +77,8 @@ enum pragma_kind { }; -/* All clauses defined by OpenACC 2.0, and OpenMP 2.5, 3.0, 3.1, 4.0 and 4.5. - Used internally by both C and C++ parsers. */ +/* All clauses defined by OpenACC 2.0, and OpenMP 2.5, 3.0, 3.1, 4.0, 4.5 + and 5.0. Used internally by both C and C++ parsers. */ enum pragma_omp_clause { PRAGMA_OMP_CLAUSE_NONE = 0, @@ -96,6 +98,7 @@ enum pragma_omp_clause { PRAGMA_OMP_CLAUSE_GRAINSIZE, PRAGMA_OMP_CLAUSE_HINT, PRAGMA_OMP_CLAUSE_IF, + PRAGMA_OMP_CLAUSE_IN_REDUCTION, PRAGMA_OMP_CLAUSE_INBRANCH, PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR, PRAGMA_OMP_CLAUSE_LASTPRIVATE, @@ -104,6 +107,7 @@ enum pragma_omp_clause { PRAGMA_OMP_CLAUSE_MAP, PRAGMA_OMP_CLAUSE_MERGEABLE, PRAGMA_OMP_CLAUSE_NOGROUP, + PRAGMA_OMP_CLAUSE_NONTEMPORAL, PRAGMA_OMP_CLAUSE_NOTINBRANCH, PRAGMA_OMP_CLAUSE_NOWAIT, PRAGMA_OMP_CLAUSE_NUM_TASKS, @@ -121,6 +125,7 @@ enum pragma_omp_clause { PRAGMA_OMP_CLAUSE_SHARED, PRAGMA_OMP_CLAUSE_SIMD, PRAGMA_OMP_CLAUSE_SIMDLEN, + PRAGMA_OMP_CLAUSE_TASK_REDUCTION, PRAGMA_OMP_CLAUSE_TASKGROUP, PRAGMA_OMP_CLAUSE_THREAD_LIMIT, PRAGMA_OMP_CLAUSE_THREADS, diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 708ef5d..04f667b 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,90 @@ +2018-11-08 Jakub Jelinek <jakub@redhat.com> + + * c-parser.c: Include memmode.h. + (c_parser_omp_depobj, c_parser_omp_requires): New functions. + (c_parser_pragma): Handle PRAGMA_OMP_DEPOBJ and PRAGMA_OMP_REQUIRES. + (c_parser_omp_clause_name): Handle nontemporal, in_reduction and + task_reduction clauses. + (c_parser_omp_variable_list): Handle OMP_CLAUSE_{IN,TASK}_REDUCTION. + For OMP_CLAUSE_DEPEND, parse clause operands as either an array + section, or lvalue assignment expression. + (c_parser_omp_clause_if): Handle cancel and simd modifiers. + (c_parser_omp_clause_lastprivate): Parse optional + conditional: modifier. + (c_parser_omp_clause_hint): Require constant integer expression rather + than just integer expression. + (c_parser_omp_clause_defaultmap): Parse new kinds of defaultmap + clause. + (c_parser_omp_clause_reduction): Add IS_OMP and KIND arguments. + Parse reduction modifiers. Pass KIND to c_parser_omp_variable_list. + (c_parser_omp_clause_nontemporal, c_parser_omp_iterators): New + functions. + (c_parser_omp_clause_depend): Parse iterator modifier and handle + iterators. Parse mutexinoutset and depobj kinds. + (c_parser_oacc_all_clauses): Adjust c_parser_omp_clause_reduction + callers. + (c_parser_omp_all_clauses): Likewise. Handle + PRAGMA_OMP_CLAUSE_NONTEMPORAL and + PRAGMA_OMP_CLAUSE_{IN,TASK}_REDUCTION. + (c_parser_omp_atomic): Parse hint and memory order clauses. Handle + default memory order from requires directive if any. Adjust + c_finish_omp_atomic caller. + (c_parser_omp_critical): Allow comma in between (name) and hint clause. + (c_parser_omp_flush): Parse flush with memory-order-clause. + (c_parser_omp_for_loop): Allow NE_EXPR even in + OpenMP loops, adjust c_finish_omp_for caller. + (OMP_SIMD_CLAUSE_MASK): Add if and nontemporal clauses. + (c_parser_omp_master): Add p_name, mask and cclauses arguments. + Allow to be called while parsing combined parallel master. + Parse combined master taskloop{, simd}. + (c_parser_omp_parallel): Parse combined + parallel master{, taskloop{, simd}} constructs. + (OMP_TASK_CLAUSE_MASK): Add in_reduction clause. + (OMP_TASKGROUP_CLAUSE_MASK): Define. + (c_parser_omp_taskgroup): Add LOC argument. Parse taskgroup clauses. + (OMP_TASKWAIT_CLAUSE_MASK): Define. + (c_parser_omp_taskwait): Handle taskwait with depend clauses. + (c_parser_omp_teams): Force a BIND_EXPR with BLOCK + around teams body. Use SET_EXPR_LOCATION. + (c_parser_omp_target_data): Allow target data + with only use_device_ptr clauses. + (c_parser_omp_target): Use SET_EXPR_LOCATION. Set + OMP_REQUIRES_TARGET_USED bit in omp_requires_mask. + (c_parser_omp_requires): New function. + (c_finish_taskloop_clauses): New function. + (OMP_TASKLOOP_CLAUSE_MASK): Add reduction and in_reduction clauses. + (c_parser_omp_taskloop): Use c_finish_taskloop_clauses. Add forward + declaration. Disallow in_reduction clause when combined with parallel + master. + (c_parser_omp_construct): Adjust c_parser_omp_master and + c_parser_omp_taskgroup callers. + * c-typeck.c (c_finish_omp_cancel): Diagnose if clause with modifier + other than cancel. + (handle_omp_array_sections_1): Handle OMP_CLAUSE_{IN,TASK}_REDUCTION + like OMP_CLAUSE_REDUCTION. + (handle_omp_array_sections): Likewise. Call save_expr on array + reductions before calling build_index_type. Handle depend clauses + with iterators. + (struct c_find_omp_var_s): New type. + (c_find_omp_var_r, c_omp_finish_iterators): New functions. + (c_finish_omp_clauses): Don't diagnose nonmonotonic clause + with static, runtime or auto schedule kinds. Call save_expr for whole + array reduction sizes. Diagnose reductions with zero sized elements + or variable length structures. Diagnose nogroup clause used with + reduction clause(s). Handle depend clause with + OMP_CLAUSE_DEPEND_DEPOBJ. Diagnose bit-fields. Require + omp_depend_t type for OMP_CLAUSE_DEPEND_DEPOBJ kinds and + some different type for other kinds. Use build_unary_op with + ADDR_EXPR and build_indirect_ref instead of c_mark_addressable. + Handle depend clauses with iterators. Remove no longer needed special + case that predetermined const qualified vars may be specified in + firstprivate clause. Complain if const qualified vars are mentioned + in data-sharing clauses other than firstprivate or shared. Use + error_at with OMP_CLAUSE_LOCATION (c) as first argument instead of + error. Formatting fix. Handle OMP_CLAUSE_NONTEMPORAL and + OMP_CLAUSE_{IN,TASK}_REDUCTION. Allow any lvalue as + OMP_CLAUSE_DEPEND operand (besides array section), adjust diagnostics. + 2018-10-29 David Malcolm <dmalcolm@redhat.com> * c-decl.c (implicit_decl_warning): Update "is there a suggestion" diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index b36fca9..624d5a3 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -68,6 +68,7 @@ along with GCC; see the file COPYING3. If not see #include "intl.h" #include "c-family/name-hint.h" #include "tree-iterator.h" +#include "memmodel.h" /* We need to walk over decls with incomplete struct/union/enum types after parsing the whole translation unit. @@ -1450,6 +1451,7 @@ static void c_parser_oacc_update (c_parser *); static void c_parser_omp_construct (c_parser *, bool *); static void c_parser_omp_threadprivate (c_parser *); static void c_parser_omp_barrier (c_parser *); +static void c_parser_omp_depobj (c_parser *); static void c_parser_omp_flush (c_parser *); static tree c_parser_omp_for_loop (location_t, c_parser *, enum tree_code, tree, tree *, bool *); @@ -1464,6 +1466,7 @@ static void c_parser_omp_cancellation_point (c_parser *, enum pragma_context); static bool c_parser_omp_target (c_parser *, enum pragma_context, bool *); static void c_parser_omp_end_declare_target (c_parser *); static void c_parser_omp_declare (c_parser *, enum pragma_context); +static void c_parser_omp_requires (c_parser *); static bool c_parser_omp_ordered (c_parser *, enum pragma_context, bool *); static void c_parser_oacc_routine (c_parser *, enum pragma_context); @@ -11168,6 +11171,15 @@ c_parser_pragma (c_parser *parser, enum pragma_context context, bool *if_p) c_parser_omp_barrier (parser); return false; + case PRAGMA_OMP_DEPOBJ: + if (context != pragma_compound) + { + construct = "omp depobj"; + goto in_compound; + } + c_parser_omp_depobj (parser); + return false; + case PRAGMA_OMP_FLUSH: if (context != pragma_compound) { @@ -11230,6 +11242,10 @@ c_parser_pragma (c_parser *parser, enum pragma_context context, bool *if_p) c_parser_omp_declare (parser, context); return false; + case PRAGMA_OMP_REQUIRES: + c_parser_omp_requires (parser); + return false; + case PRAGMA_OMP_ORDERED: return c_parser_omp_ordered (parser, context, if_p); @@ -11452,6 +11468,8 @@ c_parser_omp_clause_name (c_parser *parser) case 'i': if (!strcmp ("if_present", p)) result = PRAGMA_OACC_CLAUSE_IF_PRESENT; + else if (!strcmp ("in_reduction", p)) + result = PRAGMA_OMP_CLAUSE_IN_REDUCTION; else if (!strcmp ("inbranch", p)) result = PRAGMA_OMP_CLAUSE_INBRANCH; else if (!strcmp ("independent", p)) @@ -11476,6 +11494,8 @@ c_parser_omp_clause_name (c_parser *parser) case 'n': if (!strcmp ("nogroup", p)) result = PRAGMA_OMP_CLAUSE_NOGROUP; + else if (!strcmp ("nontemporal", p)) + result = PRAGMA_OMP_CLAUSE_NONTEMPORAL; else if (!strcmp ("notinbranch", p)) result = PRAGMA_OMP_CLAUSE_NOTINBRANCH; else if (!strcmp ("nowait", p)) @@ -11544,7 +11564,9 @@ c_parser_omp_clause_name (c_parser *parser) result = PRAGMA_OMP_CLAUSE_SIMDLEN; break; case 't': - if (!strcmp ("taskgroup", p)) + if (!strcmp ("task_reduction", p)) + result = PRAGMA_OMP_CLAUSE_TASK_REDUCTION; + else if (!strcmp ("taskgroup", p)) result = PRAGMA_OMP_CLAUSE_TASKGROUP; else if (!strcmp ("thread_limit", p)) result = PRAGMA_OMP_CLAUSE_THREAD_LIMIT; @@ -11671,13 +11693,87 @@ c_parser_omp_variable_list (c_parser *parser, location_t clause_loc, enum omp_clause_code kind, tree list) { - if (c_parser_next_token_is_not (parser, CPP_NAME) - || c_parser_peek_token (parser)->id_kind != C_ID_ID) + auto_vec<c_token> tokens; + unsigned int tokens_avail = 0; + + if (kind != OMP_CLAUSE_DEPEND + && (c_parser_next_token_is_not (parser, CPP_NAME) + || c_parser_peek_token (parser)->id_kind != C_ID_ID)) c_parser_error (parser, "expected identifier"); - while (c_parser_next_token_is (parser, CPP_NAME) - && c_parser_peek_token (parser)->id_kind == C_ID_ID) + while (kind == OMP_CLAUSE_DEPEND + || (c_parser_next_token_is (parser, CPP_NAME) + && c_parser_peek_token (parser)->id_kind == C_ID_ID)) { + bool array_section_p = false; + if (kind == OMP_CLAUSE_DEPEND) + { + if (c_parser_next_token_is_not (parser, CPP_NAME) + || c_parser_peek_token (parser)->id_kind != C_ID_ID) + { + struct c_expr expr = c_parser_expr_no_commas (parser, NULL); + if (expr.value != error_mark_node) + { + tree u = build_omp_clause (clause_loc, kind); + OMP_CLAUSE_DECL (u) = expr.value; + OMP_CLAUSE_CHAIN (u) = list; + list = u; + } + + if (c_parser_next_token_is_not (parser, CPP_COMMA)) + break; + + c_parser_consume_token (parser); + continue; + } + + tokens.truncate (0); + unsigned int nesting_depth = 0; + while (1) + { + c_token *token = c_parser_peek_token (parser); + switch (token->type) + { + case CPP_EOF: + case CPP_PRAGMA_EOL: + break; + case CPP_OPEN_BRACE: + case CPP_OPEN_PAREN: + case CPP_OPEN_SQUARE: + ++nesting_depth; + goto add; + case CPP_CLOSE_BRACE: + case CPP_CLOSE_PAREN: + case CPP_CLOSE_SQUARE: + if (nesting_depth-- == 0) + break; + goto add; + case CPP_COMMA: + if (nesting_depth == 0) + break; + goto add; + default: + add: + tokens.safe_push (*token); + c_parser_consume_token (parser); + continue; + } + break; + } + + /* Make sure nothing tries to read past the end of the tokens. */ + c_token eof_token; + memset (&eof_token, 0, sizeof (eof_token)); + eof_token.type = CPP_EOF; + tokens.safe_push (eof_token); + tokens.safe_push (eof_token); + + tokens_avail = parser->tokens_avail; + gcc_assert (parser->tokens == &parser->tokens_buf[0]); + parser->tokens = tokens.address (); + parser->tokens_avail = tokens.length (); + } + tree t = lookup_name (c_parser_peek_token (parser)->value); if (t == NULL_TREE) @@ -11728,6 +11824,8 @@ c_parser_omp_variable_list (c_parser *parser, /* FALLTHROUGH */ case OMP_CLAUSE_DEPEND: case OMP_CLAUSE_REDUCTION: + case OMP_CLAUSE_IN_REDUCTION: + case OMP_CLAUSE_TASK_REDUCTION: while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)) { tree low_bound = NULL_TREE, length = NULL_TREE; @@ -11753,6 +11851,7 @@ c_parser_omp_variable_list (c_parser *parser, t = error_mark_node; break; } + array_section_p = true; if (!c_parser_next_token_is (parser, CPP_CLOSE_SQUARE)) { location_t expr_loc @@ -11773,6 +11872,30 @@ c_parser_omp_variable_list (c_parser *parser, t = tree_cons (low_bound, length, t); } + if (kind == OMP_CLAUSE_DEPEND + && t != error_mark_node + && parser->tokens_avail != 2) + { + if (array_section_p) + { + error_at (c_parser_peek_token (parser)->location, + "expected %<)%> or %<,%>"); + t = error_mark_node; + } + else + { + parser->tokens = tokens.address (); + parser->tokens_avail = tokens.length (); + + t = c_parser_expr_no_commas (parser, NULL).value; + if (t != error_mark_node && parser->tokens_avail != 2) + { + error_at (c_parser_peek_token (parser)->location, + "expected %<)%> or %<,%>"); + t = error_mark_node; + } + } + } break; default: break; @@ -11789,6 +11912,11 @@ c_parser_omp_variable_list (c_parser *parser, else list = tree_cons (t, NULL_TREE, list); + if (kind == OMP_CLAUSE_DEPEND) + { + parser->tokens = &parser->tokens_buf[0]; + parser->tokens_avail = tokens_avail; + } if (c_parser_next_token_is_not (parser, CPP_COMMA)) break; @@ -12080,7 +12208,11 @@ c_parser_omp_clause_final (c_parser *parser, tree list) directive-name-modifier: parallel | task | taskloop | target data | target | target update - | target enter data | target exit data */ + | target enter data | target exit data + + OpenMP 5.0: + directive-name-modifier: + ... | simd | cancel */ static tree c_parser_omp_clause_if (c_parser *parser, tree list, bool is_omp) @@ -12096,8 +12228,12 @@ c_parser_omp_clause_if (c_parser *parser, tree list, bool is_omp) { const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); int n = 2; - if (strcmp (p, "parallel") == 0) + if (strcmp (p, "cancel") == 0) + if_modifier = VOID_CST; + else if (strcmp (p, "parallel") == 0) if_modifier = OMP_PARALLEL; + else if (strcmp (p, "simd") == 0) + if_modifier = OMP_SIMD; else if (strcmp (p, "task") == 0) if_modifier = OMP_TASK; else if (strcmp (p, "taskloop") == 0) @@ -12181,7 +12317,9 @@ c_parser_omp_clause_if (c_parser *parser, tree list, bool is_omp) const char *p = NULL; switch (if_modifier) { + case VOID_CST: p = "cancel"; break; case OMP_PARALLEL: p = "parallel"; break; + case OMP_SIMD: p = "simd"; break; case OMP_TASK: p = "task"; break; case OMP_TASKLOOP: p = "taskloop"; break; case OMP_TARGET_DATA: p = "target data"; break; @@ -12220,12 +12358,41 @@ c_parser_omp_clause_if (c_parser *parser, tree list, bool is_omp) } /* OpenMP 2.5: - lastprivate ( variable-list ) */ + lastprivate ( variable-list ) + + OpenMP 5.0: + lastprivate ( [ lastprivate-modifier : ] variable-list ) */ static tree c_parser_omp_clause_lastprivate (c_parser *parser, tree list) { - return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list); + /* The clauses location. */ + location_t loc = c_parser_peek_token (parser)->location; + + if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) + { + bool conditional = false; + if (c_parser_next_token_is (parser, CPP_NAME) + && c_parser_peek_2nd_token (parser)->type == CPP_COLON) + { + const char *p + = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); + if (strcmp (p, "conditional") == 0) + { + conditional = true; + c_parser_consume_token (parser); + c_parser_consume_token (parser); + } + } + tree nlist = c_parser_omp_variable_list (parser, loc, + OMP_CLAUSE_LASTPRIVATE, list); + c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); + if (conditional) + for (tree c = nlist; c != list; c = OMP_CLAUSE_CHAIN (c)) + OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c) = 1; + return nlist; + } + return list; } /* OpenMP 3.1: @@ -12465,9 +12632,10 @@ c_parser_omp_clause_hint (c_parser *parser, tree list) parens.skip_until_found_close (parser); - if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) + if (!INTEGRAL_TYPE_P (TREE_TYPE (t)) + || TREE_CODE (t) != INTEGER_CST) { - c_parser_error (parser, "expected integer expression"); + c_parser_error (parser, "expected constant integer expression"); return list; } @@ -12483,7 +12651,10 @@ c_parser_omp_clause_hint (c_parser *parser, tree list) } /* OpenMP 4.5: - defaultmap ( tofrom : scalar ) */ + defaultmap ( tofrom : scalar ) + + OpenMP 5.0: + defaultmap ( implicit-behavior [ : variable-category ] ) */ static tree c_parser_omp_clause_defaultmap (c_parser *parser, tree list) @@ -12491,39 +12662,155 @@ c_parser_omp_clause_defaultmap (c_parser *parser, tree list) location_t loc = c_parser_peek_token (parser)->location; tree c; const char *p; + enum omp_clause_defaultmap_kind behavior = OMP_CLAUSE_DEFAULTMAP_DEFAULT; + enum omp_clause_defaultmap_kind category + = OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED; matching_parens parens; if (!parens.require_open (parser)) return list; - if (!c_parser_next_token_is (parser, CPP_NAME)) - { - c_parser_error (parser, "expected %<tofrom%>"); + if (c_parser_next_token_is_keyword (parser, RID_DEFAULT)) + p = "default"; + else if (!c_parser_next_token_is (parser, CPP_NAME)) + { + invalid_behavior: + c_parser_error (parser, "expected %<alloc%>, %<to%>, %<from%>, " + "%<tofrom%>, %<firstprivate%>, %<none%> " + "or %<default%>"); goto out_err; } - p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); - if (strcmp (p, "tofrom") != 0) + else + p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); + + switch (p[0]) { - c_parser_error (parser, "expected %<tofrom%>"); - goto out_err; + case 'a': + if (strcmp ("alloc", p) == 0) + behavior = OMP_CLAUSE_DEFAULTMAP_ALLOC; + else + goto invalid_behavior; + break; + + case 'd': + if (strcmp ("default", p) == 0) + behavior = OMP_CLAUSE_DEFAULTMAP_DEFAULT; + else + goto invalid_behavior; + break; + + case 'f': + if (strcmp ("firstprivate", p) == 0) + behavior = OMP_CLAUSE_DEFAULTMAP_FIRSTPRIVATE; + else if (strcmp ("from", p) == 0) + behavior = OMP_CLAUSE_DEFAULTMAP_FROM; + else + goto invalid_behavior; + break; + + case 'n': + if (strcmp ("none", p) == 0) + behavior = OMP_CLAUSE_DEFAULTMAP_NONE; + else + goto invalid_behavior; + break; + + case 't': + if (strcmp ("tofrom", p) == 0) + behavior = OMP_CLAUSE_DEFAULTMAP_TOFROM; + else if (strcmp ("to", p) == 0) + behavior = OMP_CLAUSE_DEFAULTMAP_TO; + else + goto invalid_behavior; + break; + + default: + goto invalid_behavior; } c_parser_consume_token (parser); - if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) - goto out_err; - if (!c_parser_next_token_is (parser, CPP_NAME)) - { - c_parser_error (parser, "expected %<scalar%>"); - goto out_err; - } - p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); - if (strcmp (p, "scalar") != 0) + + if (!c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) { - c_parser_error (parser, "expected %<scalar%>"); - goto out_err; + if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) + goto out_err; + if (!c_parser_next_token_is (parser, CPP_NAME)) + { + invalid_category: + c_parser_error (parser, "expected %<scalar%>, %<aggregate%> or " + "%<pointer%>"); + goto out_err; + } + p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); + switch (p[0]) + { + case 'a': + if (strcmp ("aggregate", p) == 0) + category = OMP_CLAUSE_DEFAULTMAP_CATEGORY_AGGREGATE; + else + goto invalid_category; + break; + + case 'p': + if (strcmp ("pointer", p) == 0) + category = OMP_CLAUSE_DEFAULTMAP_CATEGORY_POINTER; + else + goto invalid_category; + break; + + case 's': + if (strcmp ("scalar", p) == 0) + category = OMP_CLAUSE_DEFAULTMAP_CATEGORY_SCALAR; + else + goto invalid_category; + break; + + default: + goto invalid_category; + } + + c_parser_consume_token (parser); } - c_parser_consume_token (parser); parens.skip_until_found_close (parser); - check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULTMAP, "defaultmap"); + + for (c = list; c ; c = OMP_CLAUSE_CHAIN (c)) + if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEFAULTMAP + && (category == OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED + || OMP_CLAUSE_DEFAULTMAP_CATEGORY (c) == category + || (OMP_CLAUSE_DEFAULTMAP_CATEGORY (c) + == OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED))) + { + enum omp_clause_defaultmap_kind cat = category; + location_t loc = OMP_CLAUSE_LOCATION (c); + if (cat == OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED) + cat = OMP_CLAUSE_DEFAULTMAP_CATEGORY (c); + p = NULL; + switch (cat) + { + case OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED: + p = NULL; + break; + case OMP_CLAUSE_DEFAULTMAP_CATEGORY_AGGREGATE: + p = "aggregate"; + break; + case OMP_CLAUSE_DEFAULTMAP_CATEGORY_POINTER: + p = "pointer"; + break; + case OMP_CLAUSE_DEFAULTMAP_CATEGORY_SCALAR: + p = "scalar"; + break; + default: + gcc_unreachable (); + } + if (p) + error_at (loc, "too many %<defaultmap%> clauses with %qs category", + p); + else + error_at (loc, "too many %<defaultmap%> clauses with unspecified " + "category"); + break; + } + c = build_omp_clause (loc, OMP_CLAUSE_DEFAULTMAP); + OMP_CLAUSE_DEFAULTMAP_SET_KIND (c, behavior, category); OMP_CLAUSE_CHAIN (c) = list; return c; @@ -12957,18 +13244,51 @@ c_parser_omp_clause_private (c_parser *parser, tree list) reduction-operator: One of: + * - & ^ | && || - identifier */ + identifier + + OpenMP 5.0: + reduction ( reduction-modifier, reduction-operator : variable-list ) + in_reduction ( reduction-operator : variable-list ) + task_reduction ( reduction-operator : variable-list ) */ static tree -c_parser_omp_clause_reduction (c_parser *parser, tree list) +c_parser_omp_clause_reduction (c_parser *parser, enum omp_clause_code kind, + bool is_omp, tree list) { location_t clause_loc = c_parser_peek_token (parser)->location; matching_parens parens; if (parens.require_open (parser)) { + bool task = false; + bool inscan = false; enum tree_code code = ERROR_MARK; tree reduc_id = NULL_TREE; + if (kind == OMP_CLAUSE_REDUCTION && is_omp) + { + if (c_parser_next_token_is_keyword (parser, RID_DEFAULT) + && c_parser_peek_2nd_token (parser)->type == CPP_COMMA) + { + c_parser_consume_token (parser); + c_parser_consume_token (parser); + } + else if (c_parser_next_token_is (parser, CPP_NAME) + && c_parser_peek_2nd_token (parser)->type == CPP_COMMA) + { + const char *p + = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); + if (strcmp (p, "task") == 0) + task = true; + else if (strcmp (p, "inscan") == 0) + inscan = true; + if (task || inscan) + { + c_parser_consume_token (parser); + c_parser_consume_token (parser); + } + } + } + switch (c_parser_peek_token (parser)->type) { case CPP_PLUS: @@ -13025,8 +13345,7 @@ c_parser_omp_clause_reduction (c_parser *parser, tree list) { tree nl, c; - nl = c_parser_omp_variable_list (parser, clause_loc, - OMP_CLAUSE_REDUCTION, list); + nl = c_parser_omp_variable_list (parser, clause_loc, kind, list); for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) { tree d = OMP_CLAUSE_DECL (c), type; @@ -13051,6 +13370,10 @@ c_parser_omp_clause_reduction (c_parser *parser, tree list) while (TREE_CODE (type) == ARRAY_TYPE) type = TREE_TYPE (type); OMP_CLAUSE_REDUCTION_CODE (c) = code; + if (task) + OMP_CLAUSE_REDUCTION_TASK (c) = 1; + else if (inscan) + OMP_CLAUSE_REDUCTION_INSCAN (c) = 1; if (code == ERROR_MARK || !(INTEGRAL_TYPE_P (type) || TREE_CODE (type) == REAL_TYPE @@ -13510,6 +13833,15 @@ c_parser_omp_clause_linear (c_parser *parser, tree list) return nl; } +/* OpenMP 5.0: + nontemporal ( variable-list ) */ + +static tree +c_parser_omp_clause_nontemporal (c_parser *parser, tree list) +{ + return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_NONTEMPORAL, list); +} + /* OpenMP 4.0: safelen ( constant-expression ) */ @@ -13670,6 +14002,106 @@ c_parser_omp_clause_depend_sink (c_parser *parser, location_t clause_loc, return u; } +/* OpenMP 5.0: + iterators ( iterators-definition ) + + iterators-definition: + iterator-specifier + iterator-specifier , iterators-definition + + iterator-specifier: + identifier = range-specification + iterator-type identifier = range-specification + + range-specification: + begin : end + begin : end : step */ + +static tree +c_parser_omp_iterators (c_parser *parser) +{ + tree ret = NULL_TREE, *last = &ret; + c_parser_consume_token (parser); + + push_scope (); + + matching_parens parens; + if (!parens.require_open (parser)) + return error_mark_node; + + do + { + tree iter_type = NULL_TREE, type_expr = NULL_TREE; + if (c_parser_next_tokens_start_typename (parser, cla_prefer_id)) + { + struct c_type_name *type = c_parser_type_name (parser); + if (type != NULL) + iter_type = groktypename (type, &type_expr, NULL); + } + if (iter_type == NULL_TREE) + iter_type = integer_type_node; + + location_t loc = c_parser_peek_token (parser)->location; + if (!c_parser_next_token_is (parser, CPP_NAME)) + { + c_parser_error (parser, "expected identifier"); + break; + } + + tree id = c_parser_peek_token (parser)->value; + c_parser_consume_token (parser); + + if (!c_parser_require (parser, CPP_EQ, "expected %<=%>")) + break; + + location_t eloc = c_parser_peek_token (parser)->location; + c_expr expr = c_parser_expr_no_commas (parser, NULL); + expr = convert_lvalue_to_rvalue (eloc, expr, true, false); + tree begin = expr.value; + + if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) + break; + + eloc = c_parser_peek_token (parser)->location; + expr = c_parser_expr_no_commas (parser, NULL); + expr = convert_lvalue_to_rvalue (eloc, expr, true, false); + tree end = expr.value; + + tree step = integer_one_node; + if (c_parser_next_token_is (parser, CPP_COLON)) + { + c_parser_consume_token (parser); + eloc = c_parser_peek_token (parser)->location; + expr = c_parser_expr_no_commas (parser, NULL); + expr = convert_lvalue_to_rvalue (eloc, expr, true, false); + step = expr.value; + } + + tree iter_var = build_decl (loc, VAR_DECL, id, iter_type); + DECL_ARTIFICIAL (iter_var) = 1; + DECL_CONTEXT (iter_var) = current_function_decl; + pushdecl (iter_var); + + *last = make_tree_vec (6); + TREE_VEC_ELT (*last, 0) = iter_var; + TREE_VEC_ELT (*last, 1) = begin; + TREE_VEC_ELT (*last, 2) = end; + TREE_VEC_ELT (*last, 3) = step; + last = &TREE_CHAIN (*last); + + if (c_parser_next_token_is (parser, CPP_COMMA)) + { + c_parser_consume_token (parser); + continue; + } + break; + } + while (1); + + parens.skip_until_found_close (parser); + return ret ? ret : error_mark_node; +} + /* OpenMP 4.0: depend ( depend-kind: variable-list ) @@ -13679,40 +14111,71 @@ c_parser_omp_clause_depend_sink (c_parser *parser, location_t clause_loc, OpenMP 4.5: depend ( source ) - depend ( sink : vec ) */ + depend ( sink : vec ) + + OpenMP 5.0: + depend ( depend-modifier , depend-kind: variable-list ) + + depend-kind: + in | out | inout | mutexinoutset | depobj + + depend-modifier: + iterator ( iterators-definition ) */ static tree c_parser_omp_clause_depend (c_parser *parser, tree list) { location_t clause_loc = c_parser_peek_token (parser)->location; - enum omp_clause_depend_kind kind = OMP_CLAUSE_DEPEND_INOUT; - tree nl, c; + enum omp_clause_depend_kind kind = OMP_CLAUSE_DEPEND_LAST; + tree nl, c, iterators = NULL_TREE; matching_parens parens; if (!parens.require_open (parser)) return list; - if (c_parser_next_token_is (parser, CPP_NAME)) + do { + if (c_parser_next_token_is_not (parser, CPP_NAME)) + goto invalid_kind; + const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); + if (strcmp ("iterator", p) == 0 && iterators == NULL_TREE) + { + iterators = c_parser_omp_iterators (parser); + c_parser_require (parser, CPP_COMMA, "expected %<,%>"); + continue; + } if (strcmp ("in", p) == 0) kind = OMP_CLAUSE_DEPEND_IN; else if (strcmp ("inout", p) == 0) kind = OMP_CLAUSE_DEPEND_INOUT; + else if (strcmp ("mutexinoutset", p) == 0) + kind = OMP_CLAUSE_DEPEND_MUTEXINOUTSET; else if (strcmp ("out", p) == 0) kind = OMP_CLAUSE_DEPEND_OUT; - else if (strcmp ("source", p) == 0) - kind = OMP_CLAUSE_DEPEND_SOURCE; + else if (strcmp ("depobj", p) == 0) + kind = OMP_CLAUSE_DEPEND_DEPOBJ; else if (strcmp ("sink", p) == 0) kind = OMP_CLAUSE_DEPEND_SINK; + else if (strcmp ("source", p) == 0) + kind = OMP_CLAUSE_DEPEND_SOURCE; else goto invalid_kind; + break; } - else - goto invalid_kind; + while (1); c_parser_consume_token (parser); + if (iterators + && (kind == OMP_CLAUSE_DEPEND_SOURCE || kind == OMP_CLAUSE_DEPEND_SINK)) + { + pop_scope (); + error_at (clause_loc, "%<iterator%> modifier incompatible with %qs", + kind == OMP_CLAUSE_DEPEND_SOURCE ? "source" : "sink"); + iterators = NULL_TREE; + } + if (kind == OMP_CLAUSE_DEPEND_SOURCE) { c = build_omp_clause (clause_loc, OMP_CLAUSE_DEPEND); @@ -13733,8 +14196,22 @@ c_parser_omp_clause_depend (c_parser *parser, tree list) nl = c_parser_omp_variable_list (parser, clause_loc, OMP_CLAUSE_DEPEND, list); + if (iterators) + { + tree block = pop_scope (); + if (iterators == error_mark_node) + iterators = NULL_TREE; + else + TREE_VEC_ELT (iterators, 5) = block; + } + for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) - OMP_CLAUSE_DEPEND_KIND (c) = kind; + { + OMP_CLAUSE_DEPEND_KIND (c) = kind; + if (iterators) + OMP_CLAUSE_DECL (c) + = build_tree_list (iterators, OMP_CLAUSE_DECL (c)); + } } parens.skip_until_found_close (parser); @@ -13744,6 +14221,8 @@ c_parser_omp_clause_depend (c_parser *parser, tree list) c_parser_error (parser, "invalid depend kind"); resync_fail: parens.skip_until_found_close (parser); + if (iterators) + pop_scope (); return list; } @@ -14169,12 +14648,14 @@ c_parser_oacc_all_clauses (c_parser *parser, omp_clause_mask mask, c_name = "private"; break; case PRAGMA_OACC_CLAUSE_REDUCTION: - clauses = c_parser_omp_clause_reduction (parser, clauses); + clauses + = c_parser_omp_clause_reduction (parser, OMP_CLAUSE_REDUCTION, + false, clauses); c_name = "reduction"; break; case PRAGMA_OACC_CLAUSE_SEQ: clauses = c_parser_oacc_simple_clause (parser, OMP_CLAUSE_SEQ, - clauses); + clauses); c_name = "seq"; break; case PRAGMA_OACC_CLAUSE_TILE: @@ -14295,6 +14776,12 @@ c_parser_omp_all_clauses (c_parser *parser, omp_clause_mask mask, clauses = c_parser_omp_clause_if (parser, clauses, true); c_name = "if"; break; + case PRAGMA_OMP_CLAUSE_IN_REDUCTION: + clauses + = c_parser_omp_clause_reduction (parser, OMP_CLAUSE_IN_REDUCTION, + true, clauses); + c_name = "in_reduction"; + break; case PRAGMA_OMP_CLAUSE_LASTPRIVATE: clauses = c_parser_omp_clause_lastprivate (parser, clauses); c_name = "lastprivate"; @@ -14328,7 +14815,9 @@ c_parser_omp_all_clauses (c_parser *parser, omp_clause_mask mask, c_name = "private"; break; case PRAGMA_OMP_CLAUSE_REDUCTION: - clauses = c_parser_omp_clause_reduction (parser, clauses); + clauses + = c_parser_omp_clause_reduction (parser, OMP_CLAUSE_REDUCTION, + true, clauses); c_name = "reduction"; break; case PRAGMA_OMP_CLAUSE_SCHEDULE: @@ -14339,6 +14828,12 @@ c_parser_omp_all_clauses (c_parser *parser, omp_clause_mask mask, clauses = c_parser_omp_clause_shared (parser, clauses); c_name = "shared"; break; + case PRAGMA_OMP_CLAUSE_TASK_REDUCTION: + clauses + = c_parser_omp_clause_reduction (parser, OMP_CLAUSE_TASK_REDUCTION, + true, clauses); + c_name = "task_reduction"; + break; case PRAGMA_OMP_CLAUSE_UNTIED: clauses = c_parser_omp_clause_untied (parser, clauses); c_name = "untied"; @@ -14348,6 +14843,10 @@ c_parser_omp_all_clauses (c_parser *parser, omp_clause_mask mask, clauses); c_name = "inbranch"; break; + case PRAGMA_OMP_CLAUSE_NONTEMPORAL: + clauses = c_parser_omp_clause_nontemporal (parser, clauses); + c_name = "nontemporal"; + break; case PRAGMA_OMP_CLAUSE_NOTINBRANCH: clauses = c_parser_omp_clause_branch (parser, OMP_CLAUSE_NOTINBRANCH, clauses); @@ -15252,62 +15751,157 @@ c_parser_omp_atomic (location_t loc, c_parser *parser) tree lhs = NULL_TREE, rhs = NULL_TREE, v = NULL_TREE; tree lhs1 = NULL_TREE, rhs1 = NULL_TREE; tree stmt, orig_lhs, unfolded_lhs = NULL_TREE, unfolded_lhs1 = NULL_TREE; - enum tree_code code = OMP_ATOMIC, opcode = NOP_EXPR; + enum tree_code code = ERROR_MARK, opcode = NOP_EXPR; + enum omp_memory_order memory_order = OMP_MEMORY_ORDER_UNSPECIFIED; struct c_expr expr; location_t eloc; bool structured_block = false; bool swapped = false; - bool seq_cst = false; bool non_lvalue_p; + bool first = true; + tree clauses = NULL_TREE; - if (c_parser_next_token_is (parser, CPP_NAME)) - { - const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); - if (!strcmp (p, "seq_cst")) - { - seq_cst = true; - c_parser_consume_token (parser); - if (c_parser_next_token_is (parser, CPP_COMMA) - && c_parser_peek_2nd_token (parser)->type == CPP_NAME) - c_parser_consume_token (parser); - } - } - if (c_parser_next_token_is (parser, CPP_NAME)) - { - const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); - - if (!strcmp (p, "read")) - code = OMP_ATOMIC_READ; - else if (!strcmp (p, "write")) - code = NOP_EXPR; - else if (!strcmp (p, "update")) - code = OMP_ATOMIC; - else if (!strcmp (p, "capture")) - code = OMP_ATOMIC_CAPTURE_NEW; - else - p = NULL; - if (p) - c_parser_consume_token (parser); - } - if (!seq_cst) + while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) { - if (c_parser_next_token_is (parser, CPP_COMMA) - && c_parser_peek_2nd_token (parser)->type == CPP_NAME) + if (!first && c_parser_next_token_is (parser, CPP_COMMA)) c_parser_consume_token (parser); + first = false; + if (c_parser_next_token_is (parser, CPP_NAME)) { const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); - if (!strcmp (p, "seq_cst")) + location_t cloc = c_parser_peek_token (parser)->location; + enum tree_code new_code = ERROR_MARK; + enum omp_memory_order new_memory_order + = OMP_MEMORY_ORDER_UNSPECIFIED; + + if (!strcmp (p, "read")) + new_code = OMP_ATOMIC_READ; + else if (!strcmp (p, "write")) + new_code = NOP_EXPR; + else if (!strcmp (p, "update")) + new_code = OMP_ATOMIC; + else if (!strcmp (p, "capture")) + new_code = OMP_ATOMIC_CAPTURE_NEW; + else if (!strcmp (p, "seq_cst")) + new_memory_order = OMP_MEMORY_ORDER_SEQ_CST; + else if (!strcmp (p, "acq_rel")) + new_memory_order = OMP_MEMORY_ORDER_ACQ_REL; + else if (!strcmp (p, "release")) + new_memory_order = OMP_MEMORY_ORDER_RELEASE; + else if (!strcmp (p, "acquire")) + new_memory_order = OMP_MEMORY_ORDER_ACQUIRE; + else if (!strcmp (p, "relaxed")) + new_memory_order = OMP_MEMORY_ORDER_RELAXED; + else if (!strcmp (p, "hint")) + { + c_parser_consume_token (parser); + clauses = c_parser_omp_clause_hint (parser, clauses); + continue; + } + else + { + p = NULL; + error_at (cloc, "expected %<read%>, %<write%>, %<update%>, " + "%<capture%>, %<seq_cst%>, %<acq_rel%>, " + "%<release%>, %<relaxed%> or %<hint%> clause"); + } + if (p) { - seq_cst = true; + if (new_code != ERROR_MARK) + { + if (code != ERROR_MARK) + error_at (cloc, "too many atomic clauses"); + else + code = new_code; + } + else if (new_memory_order != OMP_MEMORY_ORDER_UNSPECIFIED) + { + if (memory_order != OMP_MEMORY_ORDER_UNSPECIFIED) + error_at (cloc, "too many memory order clauses"); + else + memory_order = new_memory_order; + } c_parser_consume_token (parser); + continue; } } + break; } c_parser_skip_to_pragma_eol (parser); + if (code == ERROR_MARK) + code = OMP_ATOMIC; + if (memory_order == OMP_MEMORY_ORDER_UNSPECIFIED) + { + omp_requires_mask + = (enum omp_requires) (omp_requires_mask + | OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER_USED); + switch ((enum omp_memory_order) + (omp_requires_mask & OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER)) + { + case OMP_MEMORY_ORDER_UNSPECIFIED: + case OMP_MEMORY_ORDER_RELAXED: + memory_order = OMP_MEMORY_ORDER_RELAXED; + break; + case OMP_MEMORY_ORDER_SEQ_CST: + memory_order = OMP_MEMORY_ORDER_SEQ_CST; + break; + case OMP_MEMORY_ORDER_ACQ_REL: + switch (code) + { + case OMP_ATOMIC_READ: + memory_order = OMP_MEMORY_ORDER_ACQUIRE; + break; + case NOP_EXPR: /* atomic write */ + case OMP_ATOMIC: + memory_order = OMP_MEMORY_ORDER_RELEASE; + break; + default: + memory_order = OMP_MEMORY_ORDER_ACQ_REL; + break; + } + break; + default: + gcc_unreachable (); + } + } + else + switch (code) + { + case OMP_ATOMIC_READ: + if (memory_order == OMP_MEMORY_ORDER_ACQ_REL + || memory_order == OMP_MEMORY_ORDER_RELEASE) + { + error_at (loc, "%<#pragma omp atomic read%> incompatible with " + "%<acq_rel%> or %<release%> clauses"); + memory_order = OMP_MEMORY_ORDER_SEQ_CST; + } + break; + case NOP_EXPR: /* atomic write */ + if (memory_order == OMP_MEMORY_ORDER_ACQ_REL + || memory_order == OMP_MEMORY_ORDER_ACQUIRE) + { + error_at (loc, "%<#pragma omp atomic write%> incompatible with " + "%<acq_rel%> or %<acquire%> clauses"); + memory_order = OMP_MEMORY_ORDER_SEQ_CST; + } + break; + case OMP_ATOMIC: + if (memory_order == OMP_MEMORY_ORDER_ACQ_REL + || memory_order == OMP_MEMORY_ORDER_ACQUIRE) + { + error_at (loc, "%<#pragma omp atomic update%> incompatible with " + "%<acq_rel%> or %<acquire%> clauses"); + memory_order = OMP_MEMORY_ORDER_SEQ_CST; + } + break; + default: + break; + } + switch (code) { case OMP_ATOMIC_READ: @@ -15624,7 +16218,7 @@ done: } else stmt = c_finish_omp_atomic (loc, code, opcode, lhs, rhs, v, lhs1, rhs1, - swapped, seq_cst); + swapped, memory_order); if (stmt != error_mark_node) add_stmt (stmt); @@ -15676,6 +16270,10 @@ c_parser_omp_critical (location_t loc, c_parser *parser, bool *if_p) else c_parser_error (parser, "expected identifier"); + if (c_parser_next_token_is (parser, CPP_COMMA) + && c_parser_peek_2nd_token (parser)->type == CPP_NAME) + c_parser_consume_token (parser); + clauses = c_parser_omp_all_clauses (parser, OMP_CRITICAL_CLAUSE_MASK, "#pragma omp critical"); @@ -15691,24 +16289,159 @@ c_parser_omp_critical (location_t loc, c_parser *parser, bool *if_p) return c_finish_omp_critical (loc, stmt, name, clauses); } +/* OpenMP 5.0: + # pragma omp depobj ( depobj ) depobj-clause new-line + + depobj-clause: + depend (dependence-type : locator) + destroy + update (dependence-type) + + dependence-type: + in + out + inout + mutexinout */ + +static void +c_parser_omp_depobj (c_parser *parser) +{ + location_t loc = c_parser_peek_token (parser)->location; + c_parser_consume_pragma (parser); + matching_parens parens; + if (!parens.require_open (parser)) + { + c_parser_skip_to_pragma_eol (parser); + return; + } + + tree depobj = c_parser_expr_no_commas (parser, NULL).value; + if (depobj != error_mark_node) + { + if (!lvalue_p (depobj)) + { + error_at (EXPR_LOC_OR_LOC (depobj, loc), + "%<depobj%> expression is not lvalue expression"); + depobj = error_mark_node; + } + else + { + tree addr = build_unary_op (EXPR_LOC_OR_LOC (depobj, loc), ADDR_EXPR, + depobj, false); + if (addr == error_mark_node) + depobj = error_mark_node; + else + depobj = build_indirect_ref (EXPR_LOC_OR_LOC (depobj, loc), + addr, RO_UNARY_STAR); + } + } + + parens.skip_until_found_close (parser); + tree clause = NULL_TREE; + enum omp_clause_depend_kind kind = OMP_CLAUSE_DEPEND_SOURCE; + location_t c_loc = c_parser_peek_token (parser)->location; + if (c_parser_next_token_is (parser, CPP_NAME)) + { + const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); + + c_parser_consume_token (parser); + if (!strcmp ("depend", p)) + { + clause = c_parser_omp_clause_depend (parser, NULL_TREE); + clause = c_finish_omp_clauses (clause, C_ORT_OMP); + if (!clause) + clause = error_mark_node; + } + else if (!strcmp ("destroy", p)) + kind = OMP_CLAUSE_DEPEND_LAST; + else if (!strcmp ("update", p)) + { + matching_parens c_parens; + if (c_parens.require_open (parser)) + { + location_t c2_loc = c_parser_peek_token (parser)->location; + if (c_parser_next_token_is (parser, CPP_NAME)) + { + const char *p2 + = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); + + c_parser_consume_token (parser); + if (!strcmp ("in", p2)) + kind = OMP_CLAUSE_DEPEND_IN; + else if (!strcmp ("out", p2)) + kind = OMP_CLAUSE_DEPEND_OUT; + else if (!strcmp ("inout", p2)) + kind = OMP_CLAUSE_DEPEND_INOUT; + else if (!strcmp ("mutexinoutset", p2)) + kind = OMP_CLAUSE_DEPEND_MUTEXINOUTSET; + } + if (kind == OMP_CLAUSE_DEPEND_SOURCE) + { + clause = error_mark_node; + error_at (c2_loc, "expected %<in%>, %<out%>, %<inout%> or " + "%<mutexinoutset%>"); + } + c_parens.skip_until_found_close (parser); + } + else + clause = error_mark_node; + } + } + if (!clause && kind == OMP_CLAUSE_DEPEND_SOURCE) + { + clause = error_mark_node; + error_at (c_loc, "expected %<depend%>, %<destroy%> or %<update%> clause"); + } + c_parser_skip_to_pragma_eol (parser); + + c_finish_omp_depobj (loc, depobj, kind, clause); +} + + /* OpenMP 2.5: # pragma omp flush flush-vars[opt] new-line flush-vars: - ( variable-list ) */ + ( variable-list ) + + OpenMP 5.0: + # pragma omp flush memory-order-clause new-line */ static void c_parser_omp_flush (c_parser *parser) { location_t loc = c_parser_peek_token (parser)->location; c_parser_consume_pragma (parser); + enum memmodel mo = MEMMODEL_LAST; + if (c_parser_next_token_is (parser, CPP_NAME)) + { + const char *p + = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); + + if (!strcmp (p, "acq_rel")) + mo = MEMMODEL_ACQ_REL; + else if (!strcmp (p, "release")) + mo = MEMMODEL_RELEASE; + else if (!strcmp (p, "acquire")) + mo = MEMMODEL_ACQUIRE; + else + error_at (c_parser_peek_token (parser)->location, + "expected %<acq_rel%>, %<release%> or %<acquire%>"); + c_parser_consume_token (parser); + } if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) - c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL); + { + if (mo != MEMMODEL_LAST) + error_at (c_parser_peek_token (parser)->location, + "%<flush%> list specified together with memory order " + "clause"); + c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL); + } else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) c_parser_error (parser, "expected %<(%> or end of line"); c_parser_skip_to_pragma_eol (parser); - c_finish_omp_flush (loc); + c_finish_omp_flush (loc, mo); } /* Parse the restricted form of loop statements allowed by OpenACC and OpenMP. @@ -15880,6 +16613,10 @@ c_parser_omp_for_loop (location_t loc, c_parser *parser, enum tree_code code, case LT_EXPR: case LE_EXPR: break; + case NE_EXPR: + if (code != OACC_LOOP) + break; + /* FALLTHRU. */ default: /* Can't be cond = error_mark_node, because we want to preserve the location until c_finish_omp_for. */ @@ -16011,7 +16748,7 @@ c_parser_omp_for_loop (location_t loc, c_parser *parser, enum tree_code code, if (!fail) { stmt = c_finish_omp_for (loc, code, declv, NULL, initv, condv, - incrv, body, pre_body); + incrv, body, pre_body, true); /* Check for iterators appearing in lb, b or incr expressions. */ if (stmt && !c_omp_check_loop_iv (stmt, declv, NULL)) @@ -16108,7 +16845,9 @@ omp_split_clauses (location_t loc, enum tree_code code, | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \ | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \ - | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE)) + | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \ + | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \ + | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NONTEMPORAL)) static tree c_parser_omp_simd (location_t loc, c_parser *parser, @@ -16236,6 +16975,9 @@ c_parser_omp_for (location_t loc, c_parser *parser, return ret; } +static tree c_parser_omp_taskloop (location_t, c_parser *, char *, + omp_clause_mask, tree *, bool *); + /* OpenMP 2.5: # pragma omp master new-line structured-block @@ -16244,9 +16986,52 @@ c_parser_omp_for (location_t loc, c_parser *parser, */ static tree -c_parser_omp_master (location_t loc, c_parser *parser, bool *if_p) +c_parser_omp_master (location_t loc, c_parser *parser, + char *p_name, omp_clause_mask mask, tree *cclauses, + bool *if_p) { - c_parser_skip_to_pragma_eol (parser); + tree block, clauses, ret; + + strcat (p_name, " master"); + + if (c_parser_next_token_is (parser, CPP_NAME)) + { + const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); + + if (strcmp (p, "taskloop") == 0) + { + tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; + if (cclauses == NULL) + cclauses = cclauses_buf; + + c_parser_consume_token (parser); + if (!flag_openmp) /* flag_openmp_simd */ + return c_parser_omp_taskloop (loc, parser, p_name, mask, cclauses, + if_p); + block = c_begin_compound_stmt (true); + ret = c_parser_omp_taskloop (loc, parser, p_name, mask, cclauses, + if_p); + block = c_end_compound_stmt (loc, block, true); + if (ret == NULL_TREE) + return ret; + ret = c_finish_omp_master (loc, block); + return ret; + } + } + if (!flag_openmp) /* flag_openmp_simd */ + { + c_parser_skip_to_pragma_eol (parser, false); + return NULL_TREE; + } + + if (cclauses) + { + clauses = c_parser_omp_all_clauses (parser, mask, p_name, false); + omp_split_clauses (loc, OMP_MASTER, mask, clauses, cclauses); + } + else + c_parser_skip_to_pragma_eol (parser); + return c_finish_omp_master (loc, c_parser_omp_structured_block (parser, if_p)); } @@ -16508,19 +17293,38 @@ c_parser_omp_parallel (location_t loc, c_parser *parser, c_parser_skip_to_pragma_eol (parser); return NULL_TREE; } - else if (!flag_openmp) /* flag_openmp_simd */ - { - c_parser_skip_to_pragma_eol (parser, false); - return NULL_TREE; - } else if (cclauses == NULL && c_parser_next_token_is (parser, CPP_NAME)) { const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); - if (strcmp (p, "sections") == 0) + if (strcmp (p, "master") == 0) { tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; - if (cclauses == NULL) - cclauses = cclauses_buf; + cclauses = cclauses_buf; + + c_parser_consume_token (parser); + if (!flag_openmp) /* flag_openmp_simd */ + return c_parser_omp_master (loc, parser, p_name, mask, cclauses, + if_p); + block = c_begin_omp_parallel (); + tree ret = c_parser_omp_master (loc, parser, p_name, mask, cclauses, + if_p); + stmt = c_finish_omp_parallel (loc, + cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL], + block); + OMP_PARALLEL_COMBINED (stmt) = 1; + if (ret == NULL) + return ret; + return stmt; + } + else if (!flag_openmp) /* flag_openmp_simd */ + { + c_parser_skip_to_pragma_eol (parser, false); + return NULL_TREE; + } + else if (strcmp (p, "sections") == 0) + { + tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; + cclauses = cclauses_buf; c_parser_consume_token (parser); block = c_begin_omp_parallel (); @@ -16532,6 +17336,11 @@ c_parser_omp_parallel (location_t loc, c_parser *parser, return stmt; } } + else if (!flag_openmp) /* flag_openmp_simd */ + { + c_parser_skip_to_pragma_eol (parser, false); + return NULL_TREE; + } clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL); if (cclauses) @@ -16591,7 +17400,8 @@ c_parser_omp_single (location_t loc, c_parser *parser, bool *if_p) | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \ | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \ | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \ - | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY)) + | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY) \ + | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IN_REDUCTION)) static tree c_parser_omp_task (location_t loc, c_parser *parser, bool *if_p) @@ -16608,16 +17418,35 @@ c_parser_omp_task (location_t loc, c_parser *parser, bool *if_p) /* OpenMP 3.0: # pragma omp taskwait new-line + + OpenMP 5.0: + # pragma omp taskwait taskwait-clause[optseq] new-line */ +#define OMP_TASKWAIT_CLAUSE_MASK \ + (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) + static void c_parser_omp_taskwait (c_parser *parser) { location_t loc = c_parser_peek_token (parser)->location; c_parser_consume_pragma (parser); - c_parser_skip_to_pragma_eol (parser); - c_finish_omp_taskwait (loc); + tree clauses + = c_parser_omp_all_clauses (parser, OMP_TASKWAIT_CLAUSE_MASK, + "#pragma omp taskwait"); + + if (clauses) + { + tree stmt = make_node (OMP_TASK); + TREE_TYPE (stmt) = void_node; + OMP_TASK_CLAUSES (stmt) = clauses; + OMP_TASK_BODY (stmt) = NULL_TREE; + SET_EXPR_LOCATION (stmt, loc); + add_stmt (stmt); + } + else + c_finish_omp_taskwait (loc); } /* OpenMP 3.1: @@ -16636,15 +17465,22 @@ c_parser_omp_taskyield (c_parser *parser) /* OpenMP 4.0: # pragma omp taskgroup new-line + + OpenMP 5.0: + # pragma omp taskgroup taskgroup-clause[optseq] new-line */ +#define OMP_TASKGROUP_CLAUSE_MASK \ + ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASK_REDUCTION)) + static tree -c_parser_omp_taskgroup (c_parser *parser, bool *if_p) +c_parser_omp_taskgroup (location_t loc, c_parser *parser, bool *if_p) { - location_t loc = c_parser_peek_token (parser)->location; - c_parser_skip_to_pragma_eol (parser); - return c_finish_omp_taskgroup (loc, c_parser_omp_structured_block (parser, - if_p)); + tree clauses = c_parser_omp_all_clauses (parser, OMP_TASKGROUP_CLAUSE_MASK, + "#pragma omp taskgroup"); + + tree body = c_parser_omp_structured_block (parser, if_p); + return c_finish_omp_taskgroup (loc, body, clauses); } /* OpenMP 4.0: @@ -16850,7 +17686,7 @@ c_parser_omp_teams (location_t loc, c_parser *parser, if (!flag_openmp) /* flag_openmp_simd */ return c_parser_omp_distribute (loc, parser, p_name, mask, cclauses, if_p); - block = c_begin_compound_stmt (true); + block = c_begin_omp_parallel (); ret = c_parser_omp_distribute (loc, parser, p_name, mask, cclauses, if_p); block = c_end_compound_stmt (loc, block, true); @@ -16862,6 +17698,7 @@ c_parser_omp_teams (location_t loc, c_parser *parser, OMP_TEAMS_CLAUSES (ret) = clauses; OMP_TEAMS_BODY (ret) = block; OMP_TEAMS_COMBINED (ret) = 1; + SET_EXPR_LOCATION (ret, loc); return add_stmt (ret); } } @@ -16881,7 +17718,10 @@ c_parser_omp_teams (location_t loc, c_parser *parser, tree stmt = make_node (OMP_TEAMS); TREE_TYPE (stmt) = void_type_node; OMP_TEAMS_CLAUSES (stmt) = clauses; - OMP_TEAMS_BODY (stmt) = c_parser_omp_structured_block (parser, if_p); + block = c_begin_omp_parallel (); + add_stmt (c_parser_omp_structured_block (parser, if_p)); + OMP_TEAMS_BODY (stmt) = c_end_compound_stmt (loc, block, true); + SET_EXPR_LOCATION (stmt, loc); return add_stmt (stmt); } @@ -16929,6 +17769,8 @@ c_parser_omp_target_data (location_t loc, c_parser *parser, bool *if_p) *pc = OMP_CLAUSE_CHAIN (*pc); continue; } + else if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_USE_DEVICE_PTR) + map_seen = 3; pc = &OMP_CLAUSE_CHAIN (*pc); } @@ -16937,7 +17779,7 @@ c_parser_omp_target_data (location_t loc, c_parser *parser, bool *if_p) if (map_seen == 0) error_at (loc, "%<#pragma omp target data%> must contain at least " - "one %<map%> clause"); + "one %<map%> or %<use_device_ptr%> clause"); return NULL_TREE; } @@ -17196,6 +18038,10 @@ c_parser_omp_target (c_parser *parser, enum pragma_context context, bool *if_p) return false; } + if (flag_openmp) + omp_requires_mask + = (enum omp_requires) (omp_requires_mask | OMP_REQUIRES_TARGET_USED); + if (c_parser_next_token_is (parser, CPP_NAME)) { const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); @@ -17296,6 +18142,7 @@ c_parser_omp_target (c_parser *parser, enum pragma_context context, bool *if_p) OMP_TARGET_CLAUSES (stmt) = cclauses[C_OMP_CLAUSE_SPLIT_TARGET]; OMP_TARGET_BODY (stmt) = block; OMP_TARGET_COMBINED (stmt) = 1; + SET_EXPR_LOCATION (stmt, loc); add_stmt (stmt); pc = &OMP_TARGET_CLAUSES (stmt); goto check_clauses; @@ -18082,6 +18929,176 @@ c_parser_omp_declare (c_parser *parser, enum pragma_context context) c_parser_skip_to_pragma_eol (parser); } +/* OpenMP 5.0 + #pragma omp requires clauses[optseq] new-line */ + +static void +c_parser_omp_requires (c_parser *parser) +{ + bool first = true; + enum omp_requires new_req = (enum omp_requires) 0; + + c_parser_consume_pragma (parser); + + location_t loc = c_parser_peek_token (parser)->location; + while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) + { + if (!first && c_parser_next_token_is (parser, CPP_COMMA)) + c_parser_consume_token (parser); + + first = false; + + if (c_parser_next_token_is (parser, CPP_NAME)) + { + const char *p + = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); + location_t cloc = c_parser_peek_token (parser)->location; + enum omp_requires this_req = (enum omp_requires) 0; + + if (!strcmp (p, "unified_address")) + this_req = OMP_REQUIRES_UNIFIED_ADDRESS; + else if (!strcmp (p, "unified_shared_memory")) + this_req = OMP_REQUIRES_UNIFIED_SHARED_MEMORY; + else if (!strcmp (p, "dynamic_allocators")) + this_req = OMP_REQUIRES_DYNAMIC_ALLOCATORS; + else if (!strcmp (p, "reverse_offload")) + this_req = OMP_REQUIRES_REVERSE_OFFLOAD; + else if (!strcmp (p, "atomic_default_mem_order")) + { + c_parser_consume_token (parser); + + matching_parens parens; + if (parens.require_open (parser)) + { + if (c_parser_next_token_is (parser, CPP_NAME)) + { + tree v = c_parser_peek_token (parser)->value; + p = IDENTIFIER_POINTER (v); + + if (!strcmp (p, "seq_cst")) + this_req + = (enum omp_requires) OMP_MEMORY_ORDER_SEQ_CST; + else if (!strcmp (p, "relaxed")) + this_req + = (enum omp_requires) OMP_MEMORY_ORDER_RELAXED; + else if (!strcmp (p, "acq_rel")) + this_req + = (enum omp_requires) OMP_MEMORY_ORDER_ACQ_REL; + } + if (this_req == 0) + { + error_at (c_parser_peek_token (parser)->location, + "expected %<seq_cst%>, %<relaxed%> or " + "%<acq_rel%>"); + if (c_parser_peek_2nd_token (parser)->type + == CPP_CLOSE_PAREN) + c_parser_consume_token (parser); + } + else + c_parser_consume_token (parser); + + parens.skip_until_found_close (parser); + if (this_req == 0) + { + c_parser_skip_to_pragma_eol (parser, false); + return; + } + } + p = NULL; + } + else + { + error_at (cloc, "expected %<unified_address%>, " + "%<unified_shared_memory%>, " + "%<dynamic_allocators%>, " + "%<reverse_offload%> " + "or %<atomic_default_mem_order%> clause"); + c_parser_skip_to_pragma_eol (parser, false); + return; + } + if (p) + c_parser_consume_token (parser); + if (this_req) + { + if ((this_req & ~OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER) != 0) + { + if ((this_req & new_req) != 0) + error_at (cloc, "too many %qs clauses", p); + if (this_req != OMP_REQUIRES_DYNAMIC_ALLOCATORS + && (omp_requires_mask & OMP_REQUIRES_TARGET_USED) != 0) + error_at (cloc, "%qs clause used lexically after first " + "target construct or offloading API", p); + } + else if ((new_req & OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER) != 0) + { + error_at (cloc, "too many %qs clauses", + "atomic_default_mem_order"); + this_req = (enum omp_requires) 0; + } + else if ((omp_requires_mask + & OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER) != 0) + { + error_at (cloc, "more than one %<atomic_default_mem_order%>" + " clause in a single compilation unit"); + this_req + = (enum omp_requires) + (omp_requires_mask + & OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER); + } + else if ((omp_requires_mask + & OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER_USED) != 0) + error_at (cloc, "%<atomic_default_mem_order%> clause used " + "lexically after first %<atomic%> construct " + "without memory order clause"); + new_req = (enum omp_requires) (new_req | this_req); + omp_requires_mask + = (enum omp_requires) (omp_requires_mask | this_req); + continue; + } + } + break; + } + c_parser_skip_to_pragma_eol (parser); + + if (new_req == 0) + error_at (loc, "%<pragma omp requires%> requires at least one clause"); +} + +/* Helper function for c_parser_omp_taskloop. + Disallow zero sized or potentially zero sized task reductions. */ + +static tree +c_finish_taskloop_clauses (tree clauses) +{ + tree *pc = &clauses; + for (tree c = clauses; c; c = *pc) + { + bool remove = false; + if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION) + { + tree type = strip_array_types (TREE_TYPE (OMP_CLAUSE_DECL (c))); + if (integer_zerop (TYPE_SIZE_UNIT (type))) + { + error_at (OMP_CLAUSE_LOCATION (c), + "zero sized type %qT in %<reduction%> clause", type); + remove = true; + } + else if (TREE_CODE (TYPE_SIZE_UNIT (type)) != INTEGER_CST) + { + error_at (OMP_CLAUSE_LOCATION (c), + "variable sized type %qT in %<reduction%> clause", + type); + remove = true; + } + } + if (remove) + *pc = OMP_CLAUSE_CHAIN (c); + else + pc = &OMP_CLAUSE_CHAIN (c); + } + return clauses; +} + /* OpenMP 4.5: #pragma omp taskloop taskloop-clause[optseq] new-line for-loop @@ -18103,7 +19120,9 @@ c_parser_omp_declare (c_parser *parser, enum pragma_context context) | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \ | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \ | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP) \ - | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY)) + | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY) \ + | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \ + | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IN_REDUCTION)) static tree c_parser_omp_taskloop (location_t loc, c_parser *parser, @@ -18114,6 +19133,10 @@ c_parser_omp_taskloop (location_t loc, c_parser *parser, strcat (p_name, " taskloop"); mask |= OMP_TASKLOOP_CLAUSE_MASK; + /* #pragma omp parallel master taskloop{, simd} disallow in_reduction + clause. */ + if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS)) != 0) + mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IN_REDUCTION); if (c_parser_next_token_is (parser, CPP_NAME)) { @@ -18124,7 +19147,6 @@ c_parser_omp_taskloop (location_t loc, c_parser *parser, tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; if (cclauses == NULL) cclauses = cclauses_buf; - mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION); c_parser_consume_token (parser); if (!flag_openmp) /* flag_openmp_simd */ return c_parser_omp_simd (loc, parser, p_name, mask, cclauses, @@ -18138,6 +19160,8 @@ c_parser_omp_taskloop (location_t loc, c_parser *parser, TREE_TYPE (ret) = void_type_node; OMP_FOR_BODY (ret) = block; OMP_FOR_CLAUSES (ret) = cclauses[C_OMP_CLAUSE_SPLIT_TASKLOOP]; + OMP_FOR_CLAUSES (ret) + = c_finish_taskloop_clauses (OMP_FOR_CLAUSES (ret)); SET_EXPR_LOCATION (ret, loc); add_stmt (ret); return ret; @@ -18156,6 +19180,7 @@ c_parser_omp_taskloop (location_t loc, c_parser *parser, clauses = cclauses[C_OMP_CLAUSE_SPLIT_TASKLOOP]; } + clauses = c_finish_taskloop_clauses (clauses); block = c_begin_compound_stmt (true); ret = c_parser_omp_for_loop (loc, parser, OMP_TASKLOOP, clauses, NULL, if_p); block = c_end_compound_stmt (loc, block, true); @@ -18223,7 +19248,8 @@ c_parser_omp_construct (c_parser *parser, bool *if_p) stmt = c_parser_omp_for (loc, parser, p_name, mask, NULL, if_p); break; case PRAGMA_OMP_MASTER: - stmt = c_parser_omp_master (loc, parser, if_p); + strcpy (p_name, "#pragma omp"); + stmt = c_parser_omp_master (loc, parser, p_name, mask, NULL, if_p); break; case PRAGMA_OMP_PARALLEL: strcpy (p_name, "#pragma omp"); @@ -18244,7 +19270,7 @@ c_parser_omp_construct (c_parser *parser, bool *if_p) stmt = c_parser_omp_task (loc, parser, if_p); break; case PRAGMA_OMP_TASKGROUP: - stmt = c_parser_omp_taskgroup (parser, if_p); + stmt = c_parser_omp_taskgroup (loc, parser, if_p); break; case PRAGMA_OMP_TASKLOOP: strcpy (p_name, "#pragma omp"); diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index 9d09b8d..144977e 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -12525,6 +12525,11 @@ c_finish_omp_cancel (location_t loc, tree clauses) tree ifc = omp_find_clause (clauses, OMP_CLAUSE_IF); if (ifc != NULL_TREE) { + if (OMP_CLAUSE_IF_MODIFIER (ifc) != ERROR_MARK + && OMP_CLAUSE_IF_MODIFIER (ifc) != VOID_CST) + error_at (OMP_CLAUSE_LOCATION (ifc), + "expected %<cancel%> %<if%> clause modifier"); + tree type = TREE_TYPE (OMP_CLAUSE_IF_EXPR (ifc)); ifc = fold_build2_loc (OMP_CLAUSE_LOCATION (ifc), NE_EXPR, boolean_type_node, OMP_CLAUSE_IF_EXPR (ifc), @@ -12717,7 +12722,9 @@ handle_omp_array_sections_1 (tree c, tree t, vec<tree> &types, if (!integer_nonzerop (length)) { if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND - || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION) + || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION + || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION + || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION) { if (integer_zerop (length)) { @@ -12783,7 +12790,9 @@ handle_omp_array_sections_1 (tree c, tree t, vec<tree> &types, if (tree_int_cst_equal (size, low_bound)) { if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND - || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION) + || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION + || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION + || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION) { error_at (OMP_CLAUSE_LOCATION (c), "zero length array section in %qs clause", @@ -12802,7 +12811,9 @@ handle_omp_array_sections_1 (tree c, tree t, vec<tree> &types, else if (length == NULL_TREE) { if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND - && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION) + && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION + && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION + && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION) maybe_zero_len = true; if (first_non_one == types.length ()) first_non_one++; @@ -12838,7 +12849,9 @@ handle_omp_array_sections_1 (tree c, tree t, vec<tree> &types, else if (length == NULL_TREE) { if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND - && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION) + && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION + && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION + && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION) maybe_zero_len = true; if (first_non_one == types.length ()) first_non_one++; @@ -12910,7 +12923,13 @@ handle_omp_array_sections (tree c, enum c_omp_region_type ort) bool maybe_zero_len = false; unsigned int first_non_one = 0; auto_vec<tree, 10> types; - tree first = handle_omp_array_sections_1 (c, OMP_CLAUSE_DECL (c), types, + tree *tp = &OMP_CLAUSE_DECL (c); + if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND + && TREE_CODE (*tp) == TREE_LIST + && TREE_PURPOSE (*tp) + && TREE_CODE (TREE_PURPOSE (*tp)) == TREE_VEC) + tp = &TREE_VALUE (*tp); + tree first = handle_omp_array_sections_1 (c, *tp, types, maybe_zero_len, first_non_one, ort); if (first == error_mark_node) @@ -12919,7 +12938,7 @@ handle_omp_array_sections (tree c, enum c_omp_region_type ort) return false; if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND) { - tree t = OMP_CLAUSE_DECL (c); + tree t = *tp; tree tem = NULL_TREE; /* Need to evaluate side effects in the length expressions if any. */ @@ -12938,7 +12957,7 @@ handle_omp_array_sections (tree c, enum c_omp_region_type ort) if (tem) first = build2 (COMPOUND_EXPR, TREE_TYPE (first), tem, first); first = c_fully_fold (first, false, NULL, true); - OMP_CLAUSE_DECL (c) = first; + *tp = first; } else { @@ -13010,7 +13029,9 @@ handle_omp_array_sections (tree c, enum c_omp_region_type ort) if (i > first_non_one && ((length && integer_nonzerop (length)) - || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)) + || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION + || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION + || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)) continue; if (length) l = fold_convert (sizetype, length); @@ -13038,7 +13059,9 @@ handle_omp_array_sections (tree c, enum c_omp_region_type ort) tree eltype = TREE_TYPE (types[num - 1]); while (TREE_CODE (eltype) == ARRAY_TYPE) eltype = TREE_TYPE (eltype); - if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION) + if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION + || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION + || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION) { if (integer_zerop (size) || integer_zerop (size_in_bytes (eltype))) @@ -13062,10 +13085,13 @@ handle_omp_array_sections (tree c, enum c_omp_region_type ort) } if (side_effects) size = build2 (COMPOUND_EXPR, sizetype, side_effects, size); - if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION) + if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION + || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION + || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION) { size = size_binop (MINUS_EXPR, size, size_one_node); size = c_fully_fold (size, false, NULL); + size = save_expr (size); tree index_type = build_index_type (size); tree eltype = TREE_TYPE (first); while (TREE_CODE (eltype) == ARRAY_TYPE) @@ -13195,6 +13221,178 @@ c_find_omp_placeholder_r (tree *tp, int *, void *data) return NULL_TREE; } +/* Similarly, but also walk aggregate fields. */ + +struct c_find_omp_var_s { tree var; hash_set<tree> *pset; }; + +static tree +c_find_omp_var_r (tree *tp, int *, void *data) +{ + if (*tp == ((struct c_find_omp_var_s *) data)->var) + return *tp; + if (RECORD_OR_UNION_TYPE_P (*tp)) + { + tree field; + hash_set<tree> *pset = ((struct c_find_omp_var_s *) data)->pset; + + for (field = TYPE_FIELDS (*tp); field; + field = DECL_CHAIN (field)) + if (TREE_CODE (field) == FIELD_DECL) + { + tree ret = walk_tree (&DECL_FIELD_OFFSET (field), + c_find_omp_var_r, data, pset); + if (ret) + return ret; + ret = walk_tree (&DECL_SIZE (field), c_find_omp_var_r, data, pset); + if (ret) + return ret; + ret = walk_tree (&DECL_SIZE_UNIT (field), c_find_omp_var_r, data, + pset); + if (ret) + return ret; + ret = walk_tree (&TREE_TYPE (field), c_find_omp_var_r, data, pset); + if (ret) + return ret; + } + } + else if (INTEGRAL_TYPE_P (*tp)) + return walk_tree (&TYPE_MAX_VALUE (*tp), c_find_omp_var_r, data, + ((struct c_find_omp_var_s *) data)->pset); + return NULL_TREE; +} + +/* Finish OpenMP iterators ITER. Return true if they are errorneous + and clauses containing them should be removed. */ + +static bool +c_omp_finish_iterators (tree iter) +{ + bool ret = false; + for (tree it = iter; it; it = TREE_CHAIN (it)) + { + tree var = TREE_VEC_ELT (it, 0); + tree begin = TREE_VEC_ELT (it, 1); + tree end = TREE_VEC_ELT (it, 2); + tree step = TREE_VEC_ELT (it, 3); + tree orig_step; + tree type = TREE_TYPE (var); + location_t loc = DECL_SOURCE_LOCATION (var); + if (type == error_mark_node) + { + ret = true; + continue; + } + if (!INTEGRAL_TYPE_P (type) && !POINTER_TYPE_P (type)) + { + error_at (loc, "iterator %qD has neither integral nor pointer type", + var); + ret = true; + continue; + } + else if (TYPE_ATOMIC (type)) + { + error_at (loc, "iterator %qD has %<_Atomic%> qualified type", var); + ret = true; + continue; + } + else if (TYPE_READONLY (type)) + { + error_at (loc, "iterator %qD has const qualified type", var); + ret = true; + continue; + } + else if (step == error_mark_node + || TREE_TYPE (step) == error_mark_node) + { + ret = true; + continue; + } + else if (!INTEGRAL_TYPE_P (TREE_TYPE (step))) + { + error_at (EXPR_LOC_OR_LOC (step, loc), + "iterator step with non-integral type"); + ret = true; + continue; + } + begin = c_fully_fold (build_c_cast (loc, type, begin), false, NULL); + end = c_fully_fold (build_c_cast (loc, type, end), false, NULL); + orig_step = save_expr (c_fully_fold (step, false, NULL)); + tree stype = POINTER_TYPE_P (type) ? sizetype : type; + step = c_fully_fold (build_c_cast (loc, stype, orig_step), false, NULL); + if (POINTER_TYPE_P (type)) + { + begin = save_expr (begin); + step = pointer_int_sum (loc, PLUS_EXPR, begin, step); + step = fold_build2_loc (loc, MINUS_EXPR, sizetype, + fold_convert (sizetype, step), + fold_convert (sizetype, begin)); + step = fold_convert (ssizetype, step); + } + if (integer_zerop (step)) + { + error_at (loc, "iterator %qD has zero step", var); + ret = true; + continue; + } + + if (begin == error_mark_node + || end == error_mark_node + || step == error_mark_node + || orig_step == error_mark_node) + { + ret = true; + continue; + } + hash_set<tree> pset; + tree it2; + for (it2 = TREE_CHAIN (it); it2; it2 = TREE_CHAIN (it2)) + { + tree var2 = TREE_VEC_ELT (it2, 0); + tree begin2 = TREE_VEC_ELT (it2, 1); + tree end2 = TREE_VEC_ELT (it2, 2); + tree step2 = TREE_VEC_ELT (it2, 3); + tree type2 = TREE_TYPE (var2); + location_t loc2 = DECL_SOURCE_LOCATION (var2); + struct c_find_omp_var_s data = { var, &pset }; + if (walk_tree (&type2, c_find_omp_var_r, &data, &pset)) + { + error_at (loc2, + "type of iterator %qD refers to outer iterator %qD", + var2, var); + break; + } + else if (walk_tree (&begin2, c_find_omp_var_r, &data, &pset)) + { + error_at (EXPR_LOC_OR_LOC (begin2, loc2), + "begin expression refers to outer iterator %qD", var); + break; + } + else if (walk_tree (&end2, c_find_omp_var_r, &data, &pset)) + { + error_at (EXPR_LOC_OR_LOC (end2, loc2), + "end expression refers to outer iterator %qD", var); + break; + } + else if (walk_tree (&step2, c_find_omp_var_r, &data, &pset)) + { + error_at (EXPR_LOC_OR_LOC (step2, loc2), + "step expression refers to outer iterator %qD", var); + break; + } + } + if (it2) + { + ret = true; + continue; + } + TREE_VEC_ELT (it, 1) = begin; + TREE_VEC_ELT (it, 2) = end; + TREE_VEC_ELT (it, 3) = step; + TREE_VEC_ELT (it, 4) = orig_step; + } + return ret; +} + /* For all elements of CLAUSES, validate them against their constraints. Remove any elements from the list that are invalid. */ @@ -13212,14 +13410,20 @@ c_finish_omp_clauses (tree clauses, enum c_omp_region_type ort) bool ordered_seen = false; tree schedule_clause = NULL_TREE; bool oacc_async = false; + tree last_iterators = NULL_TREE; + bool last_iterators_remove = false; + tree *nogroup_seen = NULL; + bool reduction_seen = false; bitmap_obstack_initialize (NULL); bitmap_initialize (&generic_head, &bitmap_default_obstack); bitmap_initialize (&firstprivate_head, &bitmap_default_obstack); bitmap_initialize (&lastprivate_head, &bitmap_default_obstack); bitmap_initialize (&aligned_head, &bitmap_default_obstack); + /* If ort == C_ORT_OMP_DECLARE_SIMD used as uniform_head instead. */ bitmap_initialize (&map_head, &bitmap_default_obstack); bitmap_initialize (&map_field_head, &bitmap_default_obstack); + /* If ort == C_ORT_OMP used as nontemporal_head instead. */ bitmap_initialize (&oacc_reduction_head, &bitmap_default_obstack); if (ort & C_ORT_ACC) @@ -13248,6 +13452,10 @@ c_finish_omp_clauses (tree clauses, enum c_omp_region_type ort) goto check_dup_generic; case OMP_CLAUSE_REDUCTION: + reduction_seen = true; + /* FALLTHRU */ + case OMP_CLAUSE_IN_REDUCTION: + case OMP_CLAUSE_TASK_REDUCTION: need_implicitly_determined = true; t = OMP_CLAUSE_DECL (c); if (TREE_CODE (t) == TREE_LIST) @@ -13296,6 +13504,7 @@ c_finish_omp_clauses (tree clauses, enum c_omp_region_type ort) break; } size = size_binop (MINUS_EXPR, size, size_one_node); + size = save_expr (size); tree index_type = build_index_type (size); tree atype = build_array_type (type, index_type); tree ptype = build_pointer_type (type); @@ -13311,6 +13520,28 @@ c_finish_omp_clauses (tree clauses, enum c_omp_region_type ort) remove = true; break; } + if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION + || OMP_CLAUSE_REDUCTION_TASK (c)) + { + /* Disallow zero sized or potentially zero sized task + reductions. */ + if (integer_zerop (TYPE_SIZE_UNIT (type))) + { + error_at (OMP_CLAUSE_LOCATION (c), + "zero sized type %qT in %qs clause", type, + omp_clause_code_name[OMP_CLAUSE_CODE (c)]); + remove = true; + break; + } + else if (TREE_CODE (TYPE_SIZE_UNIT (type)) != INTEGER_CST) + { + error_at (OMP_CLAUSE_LOCATION (c), + "variable sized type %qT in %qs clause", type, + omp_clause_code_name[OMP_CLAUSE_CODE (c)]); + remove = true; + break; + } + } if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) == NULL_TREE && (FLOAT_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE)) @@ -13512,7 +13743,7 @@ c_finish_omp_clauses (tree clauses, enum c_omp_region_type ort) if (TYPE_ATOMIC (TREE_TYPE (t))) { error_at (OMP_CLAUSE_LOCATION (c), - "%<_Atomic%> %qD in %<linear%> clause", t); + "%<_Atomic%> %qD in %<linear%> clause", t); remove = true; break; } @@ -13570,7 +13801,9 @@ c_finish_omp_clauses (tree clauses, enum c_omp_region_type ort) { if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t))) { - error ("%qD appears more than once in reduction clauses", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qD appears more than once in reduction clauses", + t); remove = true; } else @@ -13588,9 +13821,11 @@ c_finish_omp_clauses (tree clauses, enum c_omp_region_type ort) && bitmap_bit_p (&map_head, DECL_UID (t))) { if (ort == C_ORT_ACC) - error ("%qD appears more than once in data clauses", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qD appears more than once in data clauses", t); else - error ("%qD appears both in data and map clauses", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qD appears both in data and map clauses", t); remove = true; } else @@ -13617,9 +13852,11 @@ c_finish_omp_clauses (tree clauses, enum c_omp_region_type ort) else if (bitmap_bit_p (&map_head, DECL_UID (t))) { if (ort == C_ORT_ACC) - error ("%qD appears more than once in data clauses", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qD appears more than once in data clauses", t); else - error ("%qD appears both in data and map clauses", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qD appears both in data and map clauses", t); remove = true; } else @@ -13681,6 +13918,25 @@ c_finish_omp_clauses (tree clauses, enum c_omp_region_type ort) bitmap_set_bit (&aligned_head, DECL_UID (t)); break; + case OMP_CLAUSE_NONTEMPORAL: + t = OMP_CLAUSE_DECL (c); + if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL) + { + error_at (OMP_CLAUSE_LOCATION (c), + "%qE is not a variable in %<nontemporal%> clause", t); + remove = true; + } + else if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t))) + { + error_at (OMP_CLAUSE_LOCATION (c), + "%qE appears more than once in %<nontemporal%> " + "clauses", t); + remove = true; + } + else + bitmap_set_bit (&oacc_reduction_head, DECL_UID (t)); + break; + case OMP_CLAUSE_DEPEND: t = OMP_CLAUSE_DECL (c); if (t == NULL_TREE) @@ -13717,22 +13973,89 @@ c_finish_omp_clauses (tree clauses, enum c_omp_region_type ort) } break; } + if (TREE_CODE (t) == TREE_LIST + && TREE_PURPOSE (t) + && TREE_CODE (TREE_PURPOSE (t)) == TREE_VEC) + { + if (TREE_PURPOSE (t) != last_iterators) + last_iterators_remove + = c_omp_finish_iterators (TREE_PURPOSE (t)); + last_iterators = TREE_PURPOSE (t); + t = TREE_VALUE (t); + if (last_iterators_remove) + t = error_mark_node; + } + else + last_iterators = NULL_TREE; if (TREE_CODE (t) == TREE_LIST) { if (handle_omp_array_sections (c, ort)) remove = true; + else if (OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_DEPOBJ) + { + error_at (OMP_CLAUSE_LOCATION (c), + "%<depend%> clause with %<depobj%> dependence " + "type on array section"); + remove = true; + } break; } if (t == error_mark_node) remove = true; - else if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL) + else if (!lvalue_p (t)) { error_at (OMP_CLAUSE_LOCATION (c), - "%qE is not a variable in %<depend%> clause", t); + "%qE is not lvalue expression nor array section in " + "%<depend%> clause", t); remove = true; } - else if (!c_mark_addressable (t)) - remove = true; + else if (TREE_CODE (t) == COMPONENT_REF + && DECL_C_BIT_FIELD (TREE_OPERAND (t, 1))) + { + error_at (OMP_CLAUSE_LOCATION (c), + "bit-field %qE in %qs clause", t, "depend"); + remove = true; + } + else if (OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_DEPOBJ) + { + if (!c_omp_depend_t_p (TREE_TYPE (t))) + { + error_at (OMP_CLAUSE_LOCATION (c), + "%qE does not have %<omp_depend_t%> type in " + "%<depend%> clause with %<depobj%> dependence " + "type", t); + remove = true; + } + } + else if (c_omp_depend_t_p (TREE_TYPE (t))) + { + error_at (OMP_CLAUSE_LOCATION (c), + "%qE should not have %<omp_depend_t%> type in " + "%<depend%> clause with dependence type other than " + "%<depobj%>", t); + remove = true; + } + if (!remove) + { + tree addr = build_unary_op (OMP_CLAUSE_LOCATION (c), ADDR_EXPR, + t, false); + if (addr == error_mark_node) + remove = true; + else + { + t = build_indirect_ref (OMP_CLAUSE_LOCATION (c), addr, + RO_UNARY_STAR); + if (t == error_mark_node) + remove = true; + else if (TREE_CODE (OMP_CLAUSE_DECL (c)) == TREE_LIST + && TREE_PURPOSE (OMP_CLAUSE_DECL (c)) + && (TREE_CODE (TREE_PURPOSE (OMP_CLAUSE_DECL (c))) + == TREE_VEC)) + TREE_VALUE (OMP_CLAUSE_DECL (c)) = t; + else + OMP_CLAUSE_DECL (c) = t; + } + } break; case OMP_CLAUSE_MAP: @@ -13774,14 +14097,17 @@ c_finish_omp_clauses (tree clauses, enum c_omp_region_type ort) if (bitmap_bit_p (&map_head, DECL_UID (t))) { if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP) - error ("%qD appears more than once in motion" - " clauses", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qD appears more than once in motion " + "clauses", t); else if (ort == C_ORT_ACC) - error ("%qD appears more than once in data" - " clauses", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qD appears more than once in data " + "clauses", t); else - error ("%qD appears more than once in map" - " clauses", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qD appears more than once in map " + "clauses", t); remove = true; } else @@ -13891,15 +14217,18 @@ c_finish_omp_clauses (tree clauses, enum c_omp_region_type ort) if (bitmap_bit_p (&generic_head, DECL_UID (t)) || bitmap_bit_p (&firstprivate_head, DECL_UID (t))) { - error ("%qD appears more than once in data clauses", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qD appears more than once in data clauses", t); remove = true; } else if (bitmap_bit_p (&map_head, DECL_UID (t))) { if (ort == C_ORT_ACC) - error ("%qD appears more than once in data clauses", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qD appears more than once in data clauses", t); else - error ("%qD appears both in data and map clauses", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qD appears both in data and map clauses", t); remove = true; } else @@ -13908,20 +14237,25 @@ c_finish_omp_clauses (tree clauses, enum c_omp_region_type ort) else if (bitmap_bit_p (&map_head, DECL_UID (t))) { if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP) - error ("%qD appears more than once in motion clauses", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qD appears more than once in motion clauses", t); else if (ort == C_ORT_ACC) - error ("%qD appears more than once in data clauses", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qD appears more than once in data clauses", t); else - error ("%qD appears more than once in map clauses", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qD appears more than once in map clauses", t); remove = true; } else if (bitmap_bit_p (&generic_head, DECL_UID (t)) || bitmap_bit_p (&firstprivate_head, DECL_UID (t))) { if (ort == C_ORT_ACC) - error ("%qD appears more than once in data clauses", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qD appears more than once in data clauses", t); else - error ("%qD appears both in data and map clauses", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qD appears both in data and map clauses", t); remove = true; } else @@ -14041,7 +14375,6 @@ c_finish_omp_clauses (tree clauses, enum c_omp_region_type ort) case OMP_CLAUSE_PRIORITY: case OMP_CLAUSE_GRAINSIZE: case OMP_CLAUSE_NUM_TASKS: - case OMP_CLAUSE_NOGROUP: case OMP_CLAUSE_THREADS: case OMP_CLAUSE_SIMD: case OMP_CLAUSE_HINT: @@ -14063,30 +14396,12 @@ c_finish_omp_clauses (tree clauses, enum c_omp_region_type ort) pc = &OMP_CLAUSE_CHAIN (c); continue; + case OMP_CLAUSE_NOGROUP: + nogroup_seen = pc; + pc = &OMP_CLAUSE_CHAIN (c); + continue; + case OMP_CLAUSE_SCHEDULE: - if (OMP_CLAUSE_SCHEDULE_KIND (c) & OMP_CLAUSE_SCHEDULE_NONMONOTONIC) - { - const char *p = NULL; - switch (OMP_CLAUSE_SCHEDULE_KIND (c) & OMP_CLAUSE_SCHEDULE_MASK) - { - case OMP_CLAUSE_SCHEDULE_STATIC: p = "static"; break; - case OMP_CLAUSE_SCHEDULE_DYNAMIC: break; - case OMP_CLAUSE_SCHEDULE_GUIDED: break; - case OMP_CLAUSE_SCHEDULE_AUTO: p = "auto"; break; - case OMP_CLAUSE_SCHEDULE_RUNTIME: p = "runtime"; break; - default: gcc_unreachable (); - } - if (p) - { - error_at (OMP_CLAUSE_LOCATION (c), - "%<nonmonotonic%> modifier specified for %qs " - "schedule kind", p); - OMP_CLAUSE_SCHEDULE_KIND (c) - = (enum omp_clause_schedule_kind) - (OMP_CLAUSE_SCHEDULE_KIND (c) - & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC); - } - } schedule_clause = c; pc = &OMP_CLAUSE_CHAIN (c); continue; @@ -14145,10 +14460,6 @@ c_finish_omp_clauses (tree clauses, enum c_omp_region_type ort) case OMP_CLAUSE_DEFAULT_UNSPECIFIED: break; case OMP_CLAUSE_DEFAULT_SHARED: - /* const vars may be specified in firstprivate clause. */ - if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE - && TREE_READONLY (t)) - break; share_name = "shared"; break; case OMP_CLAUSE_DEFAULT_PRIVATE: @@ -14165,6 +14476,15 @@ c_finish_omp_clauses (tree clauses, enum c_omp_region_type ort) omp_clause_code_name[OMP_CLAUSE_CODE (c)]); remove = true; } + else if (TREE_READONLY (t) + && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED + && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_FIRSTPRIVATE) + { + error_at (OMP_CLAUSE_LOCATION (c), + "%<const%> qualified %qE may appear only in " + "%<shared%> or %<firstprivate%> clauses", t); + remove = true; + } } } @@ -14222,6 +14542,14 @@ c_finish_omp_clauses (tree clauses, enum c_omp_region_type ort) pc = &OMP_CLAUSE_CHAIN (c); } + if (nogroup_seen && reduction_seen) + { + error_at (OMP_CLAUSE_LOCATION (*nogroup_seen), + "%<nogroup%> clause must not be used together with " + "%<reduction%> clause"); + *nogroup_seen = OMP_CLAUSE_CHAIN (*nogroup_seen); + } + bitmap_obstack_release (NULL); return clauses; } diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 79cc673..1497dab 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,167 @@ +2018-11-08 Jakub Jelinek <jakub@redhat.com> + + * constexpr.c (potential_constant_expression_1): Handle OMP_DEPOBJ. + * cp-gimplify.c (cp_genericize_r): Handle + OMP_CLAUSE_{IN,TASK}_REDUCTION. + (cxx_omp_predetermined_sharing_1): Don't return + OMP_CLAUSE_DEFAULT_SHARED for const qualified decls with no mutable + member. Return OMP_CLAUSE_DEFAULT_FIRSTPRIVATE for this pointer. + * cp-objcp-common.c (cp_common_init_ts): Handle OMP_DEPOBJ. + * cp-tree.def (OMP_DEPOBJ): New tree code. + * cp-tree.h (OMP_ATOMIC_DEPENDENT_P): Return true also for first + argument being OMP_CLAUSE. + (OMP_DEPOBJ_DEPOBJ, OMP_DEPOBJ_CLAUSES): Define. + (cp_convert_omp_range_for, cp_finish_omp_range_for): Declare. + (finish_omp_atomic): Add LOC, CLAUSES and MO arguments. Remove + SEQ_CST argument. + (finish_omp_for_block): Declare. + (finish_omp_flush): Add MO argument. + (finish_omp_depobj): Declare. + * cxx-pretty-print.c (cxx_pretty_printer::statement): Handle + OMP_DEPOBJ. + * dump.c (cp_dump_tree): Likewise. + * lex.c (cxx_init): Likewise. + * parser.c: Include memmodel.h. + (cp_parser_for): Pass false as new is_omp argument to + cp_parser_range_for. + (cp_parser_range_for): Add IS_OMP argument, return before finalizing + if it is true. + (cp_parser_omp_clause_name): Handle nontemporal, in_reduction and + task_reduction clauses. + (cp_parser_omp_var_list_no_open): Handle + OMP_CLAUSE_{IN,TASK}_REDUCTION. For OMP_CLAUSE_DEPEND, parse clause + operands as either an array section, or lvalue assignment expression. + (cp_parser_omp_clause_if): Handle cancel and simd modifiers. + (cp_parser_omp_clause_defaultmap): Parse new kinds of defaultmap + clause. + (cp_parser_omp_clause_reduction): Add IS_OMP and KIND arguments. + Parse reduction modifiers. Pass KIND to c_parser_omp_variable_list. + (cp_parser_omp_clause_lastprivate, cp_parser_omp_iterators): New + functions. + (cp_parser_omp_clause_depend): Parse iterator modifier and handle + iterators. Parse mutexinoutset and depobj kinds. + (cp_parser_oacc_all_clauses): Adjust cp_parser_omp_clause_reduction + callers. + (cp_parser_omp_all_clauses): Likewise. Handle + PRAGMA_OMP_CLAUSE_NONTEMPORAL and + PRAGMA_OMP_CLAUSE_{IN,TASK}_REDUCTION. Call + cp_parser_omp_clause_lastprivate for OpenMP lastprivate clause. + (cp_parser_omp_atomic): Pass pragma_tok->location as + LOC to finish_omp_atomic. Parse hint and memory order clauses. + Handle default memory order from requires directive if any. Adjust + finish_omp_atomic caller. + (cp_parser_omp_critical): Allow comma in between (name) and hint + clause. + (cp_parser_omp_depobj): New function. + (cp_parser_omp_flush): Parse flush with memory-order-clause. + (cp_parser_omp_for_cond): Allow NE_EXPR even in OpenMP loops. + (cp_convert_omp_range_for, cp_finish_omp_range_for): New functions. + (cp_parser_omp_for_loop): Parse C++11 range for loops among omp + loops. Handle OMP_CLAUSE_IN_REDUCTION like OMP_CLAUSE_REDUCTION. + (OMP_SIMD_CLAUSE_MASK): Add if and nontemporal clauses. + (cp_parser_omp_simd, cp_parser_omp_for): Call keep_next_level before + begin_omp_structured_block and call finish_omp_for_block on + finish_omp_structured_block result. + (cp_parser_omp_master): Add p_name, mask and cclauses arguments. + Allow to be called while parsing combined parallel master. + Parse combined master taskloop{, simd}. + (cp_parser_omp_parallel): Parse combined + parallel master{, taskloop{, simd}} constructs. + (cp_parser_omp_single): Use SET_EXPR_LOCATION. + (OMP_TASK_CLAUSE_MASK): Add in_reduction clause. + (OMP_TASKWAIT_CLAUSE_MASK): Define. + (cp_parser_omp_taskwait): Handle taskwait with depend clauses. + (OMP_TASKGROUP_CLAUSE_MASK): Define. + (cp_parser_omp_taskgroup): Parse taskgroup clauses, adjust + c_finish_omp_taskgroup caller. + (cp_parser_omp_distribute): Call keep_next_level before + begin_omp_structured_block and call finish_omp_for_block on + finish_omp_structured_block result. + (cp_parser_omp_teams): Force a BIND_EXPR with BLOCK around teams + body. + (cp_parser_omp_target_data): Allow target data with only + use_device_ptr clauses. + (cp_parser_omp_target): Set OMP_REQUIRES_TARGET_USED bit in + omp_requires_mask. + (cp_parser_omp_requires): New function. + (OMP_TASKLOOP_CLAUSE_MASK): Add reduction and in_reduction clauses. + (cp_parser_omp_taskloop): Add forward declaration. Disallow + in_reduction clause when combined with parallel master. Call + keep_next_level before begin_omp_structured_block and call + finish_omp_for_block on finish_omp_structured_block result. + (cp_parser_omp_construct): Adjust cp_parser_omp_master caller. + (cp_parser_pragma): Handle PRAGMA_OMP_DEPOBJ and PRAGMA_OMP_REQUIRES. + * pt.c (tsubst_omp_clause_decl): Add iterators_cache argument. + Adjust recursive calls. Handle iterators. + (tsubst_omp_clauses): Handle OMP_CLAUSE_{IN,TASK}_REDUCTION and + OMP_CLAUSE_NONTEMPORAL. Adjust tsubst_omp_clause_decl callers. + (tsubst_decomp_names): + (tsubst_omp_for_iterator): Change orig_declv into a reference. + Handle range for loops. Move orig_declv handling after declv/initv + handling. + (tsubst_expr): Force a BIND_EXPR with BLOCK around teams body. + Adjust finish_omp_atomic caller. Call keep_next_level before + begin_omp_structured_block. Call cp_finish_omp_range_for for range + for loops and use {begin,finish}_omp_structured_block instead of + {push,pop}_stmt_list if there are any range for loops. Call + finish_omp_for_block on finish_omp_structured_block result. + Handle OMP_DEPOBJ. Handle taskwait with depend clauses. For + OMP_ATOMIC call tsubst_omp_clauses on clauses if any, adjust + finish_omp_atomic caller. Use OMP_ATOMIC_MEMORY_ORDER rather + than OMP_ATOMIC_SEQ_CST. Handle clauses on OMP_TASKGROUP. + (dependent_omp_for_p): Always return true for range for loops if + processing_template_decl. Return true if class type iterator + does not have INTEGER_CST increment. + * semantics.c: Include memmodel.h. + (handle_omp_array_sections_1): Handle OMP_CLAUSE_{IN,TASK}_REDUCTION + like OMP_CLAUSE_REDUCTION. + (handle_omp_array_sections): Likewise. Call save_expr on array + reductions before calling build_index_type. Handle depend clauses + with iterators. + (finish_omp_reduction_clause): Call save_expr for whole array + reduction sizes. Don't mark OMP_CLAUSE_DECL addressable if it has + reference type. Do mark decl_placeholder addressable if needed. + Use error_at with OMP_CLAUSE_LOCATION (c) as first argument instead + of error. + (cp_omp_finish_iterators): New function. + (finish_omp_clauses): Don't diagnose nonmonotonic clause with static, + runtime or auto schedule kinds. Diagnose nogroup clause used with + reduction clause(s). Handle depend clause with + OMP_CLAUSE_DEPEND_DEPOBJ. Diagnose bit-fields. Require + omp_depend_t type for OMP_CLAUSE_DEPEND_DEPOBJ kinds and + some different type for other kinds. Use cp_build_addr_expr + and cp_build_indirect_ref instead of cxx_mark_addressable. + Handle depend clauses with iterators. Only handle static data members + in the special case that const qualified vars may be specified in + firstprivate clause. Complain if const qualified vars without mutable + members are mentioned in data-sharing clauses other than firstprivate + or shared. Use error_at with OMP_CLAUSE_LOCATION (c) as first + argument instead of error. Diagnose more than one nontemporal clause + refering to the same variable. Use error_at rather than error for + priority and hint clause diagnostics. Fix pasto for hint clause. + Diagnose hint expression that doesn't fold into INTEGER_CST. + Diagnose if clause with modifier other than cancel. Handle + OMP_CLAUSE_{IN,TASK}_REDUCTION like OMP_CLAUSE_REDUCTION. Allow any + lvalue as OMP_CLAUSE_DEPEND operand (besides array section), adjust + diagnostics. + (handle_omp_for_class_iterator): Don't create a new TREE_LIST if one + has been created already for range for, just fill TREE_PURPOSE and + TREE_VALUE. Call cp_fully_fold on incr. + (finish_omp_for): Don't check cond/incr if cond is global_namespace. + Pass to c_omp_check_loop_iv_exprs orig_declv if non-NULL. Don't + use IS_EMPTY_STMT on NULL pre_body. Adjust c_finish_omp_for caller. + (finish_omp_for_block): New function. + (finish_omp_atomic): Add LOC argument, pass it through + to c_finish_omp_atomic and set it as location of OMP_ATOMIC* trees. + Remove SEQ_CST argument. Add CLAUSES and MO arguments. Adjust + c_finish_omp_atomic caller. Stick clauses if any into first argument + of wrapping OMP_ATOMIC. + (finish_omp_depobj): New function. + (finish_omp_flush): Add MO argument, if not + MEMMODEL_LAST, emit __atomic_thread_fence call with the given value. + (finish_omp_cancel): Diagnose if clause with modifier other than + cancel. + 2018-11-07 Nathan Sidwell <nathan@acm.org> PR c++/87904 diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 4fb1ba5..7b696da 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -5917,6 +5917,7 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, case OMP_ATOMIC_READ: case OMP_ATOMIC_CAPTURE_OLD: case OMP_ATOMIC_CAPTURE_NEW: + case OMP_DEPOBJ: case OACC_PARALLEL: case OACC_KERNELS: case OACC_DATA: diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c index 90a8f9f..eb761b1 100644 --- a/gcc/cp/cp-gimplify.c +++ b/gcc/cp/cp-gimplify.c @@ -1178,6 +1178,8 @@ cp_genericize_r (tree *stmt_p, int *walk_subtrees, void *data) *walk_subtrees = 0; break; case OMP_CLAUSE_REDUCTION: + case OMP_CLAUSE_IN_REDUCTION: + case OMP_CLAUSE_TASK_REDUCTION: /* Don't dereference an invisiref in reduction clause's OMP_CLAUSE_DECL either. OMP_CLAUSE_REDUCTION_{INIT,MERGE} still needs to be genericized. */ @@ -1986,10 +1988,10 @@ cxx_omp_predetermined_sharing_1 (tree decl) return OMP_CLAUSE_DEFAULT_SHARED; } - /* Const qualified vars having no mutable member are predetermined - shared. */ - if (cxx_omp_const_qual_no_mutable (decl)) - return OMP_CLAUSE_DEFAULT_SHARED; + /* this may not be specified in data-sharing clauses, still we need + to predetermined it firstprivate. */ + if (decl == current_class_ptr) + return OMP_CLAUSE_DEFAULT_FIRSTPRIVATE; return OMP_CLAUSE_DEFAULT_UNSPECIFIED; } diff --git a/gcc/cp/cp-objcp-common.c b/gcc/cp/cp-objcp-common.c index eef7ed6..584f428 100644 --- a/gcc/cp/cp-objcp-common.c +++ b/gcc/cp/cp-objcp-common.c @@ -446,6 +446,7 @@ cp_common_init_ts (void) MARK_TS_TYPED (UNARY_RIGHT_FOLD_EXPR); MARK_TS_TYPED (BINARY_LEFT_FOLD_EXPR); MARK_TS_TYPED (BINARY_RIGHT_FOLD_EXPR); + MARK_TS_TYPED (OMP_DEPOBJ); } #include "gt-cp-cp-objcp-common.h" diff --git a/gcc/cp/cp-tree.def b/gcc/cp/cp-tree.def index c64225d..43d90eb 100644 --- a/gcc/cp/cp-tree.def +++ b/gcc/cp/cp-tree.def @@ -499,6 +499,11 @@ DEFTREECODE (BASES, "bases", tcc_type, 0) instantiation time. */ DEFTREECODE (TEMPLATE_INFO, "template_info", tcc_exceptional, 0) +/* OpenMP - #pragma omp depobj + Operand 0: OMP_DEPOBJ_DEPOBJ: Depobj expression + Operand 1: OMP_DEPOBJ_CLAUSES: List of clauses. */ +DEFTREECODE (OMP_DEPOBJ, "omp_depobj", tcc_statement, 2) + /* Extensions for Concepts. */ /* Used to represent information associated with constrained declarations. */ diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 91f5755..6ca138d 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -4874,9 +4874,10 @@ more_aggr_init_expr_args_p (const aggr_init_expr_arg_iterator *iter) (TREE_LANG_FLAG_1 (SCOPE_REF_CHECK (NODE))) /* True for an OMP_ATOMIC that has dependent parameters. These are stored - as an expr in operand 1, and integer_zero_node in operand 0. */ + as an expr in operand 1, and integer_zero_node or clauses in operand 0. */ #define OMP_ATOMIC_DEPENDENT_P(NODE) \ - (TREE_CODE (TREE_OPERAND (OMP_ATOMIC_CHECK (NODE), 0)) == INTEGER_CST) + (TREE_CODE (TREE_OPERAND (OMP_ATOMIC_CHECK (NODE), 0)) == INTEGER_CST \ + || TREE_CODE (TREE_OPERAND (OMP_ATOMIC_CHECK (NODE), 0)) == OMP_CLAUSE) /* Used while gimplifying continue statements bound to OMP_FOR nodes. */ #define OMP_FOR_GIMPLIFYING_P(NODE) \ @@ -5016,6 +5017,13 @@ more_aggr_init_expr_args_p (const aggr_init_expr_arg_iterator *iter) #define ALIGNOF_EXPR_STD_P(NODE) \ TREE_LANG_FLAG_0 (ALIGNOF_EXPR_CHECK (NODE)) +/* OMP_DEPOBJ accessors. These give access to the depobj expression of the + #pragma omp depobj directive and the clauses, respectively. If + OMP_DEPOBJ_CLAUSES is INTEGER_CST, it is instead the update clause kind + or OMP_CLAUSE_DEPEND_LAST for destroy clause. */ +#define OMP_DEPOBJ_DEPOBJ(NODE) TREE_OPERAND (OMP_DEPOBJ_CHECK (NODE), 0) +#define OMP_DEPOBJ_CLAUSES(NODE) TREE_OPERAND (OMP_DEPOBJ_CHECK (NODE), 1) + /* An enumeration of the kind of tags that C++ accepts. */ enum tag_types { none_type = 0, /* Not a tag type. */ @@ -6630,6 +6638,9 @@ extern bool maybe_clone_body (tree); /* In parser.c */ extern tree cp_convert_range_for (tree, tree, tree, tree, unsigned int, bool, unsigned short); +extern void cp_convert_omp_range_for (tree &, vec<tree, va_gc> *, tree &, + tree &, tree &, tree &, tree &, tree &); +extern void cp_finish_omp_range_for (tree, tree); extern bool parsing_nsdmi (void); extern bool parsing_default_capturing_generic_lambda_in_template (void); extern void inject_this_parameter (tree, cp_cv_quals); @@ -7054,11 +7065,16 @@ extern tree finish_omp_task (tree, tree); extern tree finish_omp_for (location_t, enum tree_code, tree, tree, tree, tree, tree, tree, tree, vec<tree> *, tree); -extern void finish_omp_atomic (enum tree_code, enum tree_code, - tree, tree, tree, tree, tree, - bool); +extern tree finish_omp_for_block (tree, tree); +extern void finish_omp_atomic (location_t, enum tree_code, + enum tree_code, tree, tree, + tree, tree, tree, tree, + enum omp_memory_order); extern void finish_omp_barrier (void); -extern void finish_omp_flush (void); +extern void finish_omp_depobj (location_t, tree, + enum omp_clause_depend_kind, + tree); +extern void finish_omp_flush (int); extern void finish_omp_taskwait (void); extern void finish_omp_taskyield (void); extern void finish_omp_cancel (tree); diff --git a/gcc/cp/cxx-pretty-print.c b/gcc/cp/cxx-pretty-print.c index c138c50..b79ff51 100644 --- a/gcc/cp/cxx-pretty-print.c +++ b/gcc/cp/cxx-pretty-print.c @@ -2112,6 +2112,42 @@ cxx_pretty_printer::statement (tree t) declaration (t); break; + case OMP_DEPOBJ: + pp_cxx_ws_string (this, "#pragma omp depobj"); + pp_space (this); + pp_cxx_left_paren (this); + expression (OMP_DEPOBJ_DEPOBJ (t)); + pp_cxx_right_paren (this); + if (OMP_DEPOBJ_CLAUSES (t) && OMP_DEPOBJ_CLAUSES (t) != error_mark_node) + { + if (TREE_CODE (OMP_DEPOBJ_CLAUSES (t)) == OMP_CLAUSE) + dump_omp_clauses (this, OMP_DEPOBJ_CLAUSES (t), + pp_indentation (this), TDF_NONE); + else + switch (tree_to_uhwi (OMP_DEPOBJ_CLAUSES (t))) + { + case OMP_CLAUSE_DEPEND_IN: + pp_cxx_ws_string (this, " update(in)"); + break; + case OMP_CLAUSE_DEPEND_INOUT: + pp_cxx_ws_string (this, " update(inout)"); + break; + case OMP_CLAUSE_DEPEND_OUT: + pp_cxx_ws_string (this, " update(out)"); + break; + case OMP_CLAUSE_DEPEND_MUTEXINOUTSET: + pp_cxx_ws_string (this, " update(mutexinoutset)"); + break; + case OMP_CLAUSE_DEPEND_LAST: + pp_cxx_ws_string (this, " destroy"); + break; + default: + break; + } + } + pp_needs_newline (this) = true; + break; + default: c_pretty_printer::statement (t); break; diff --git a/gcc/cp/dump.c b/gcc/cp/dump.c index d9b868b..1653886 100644 --- a/gcc/cp/dump.c +++ b/gcc/cp/dump.c @@ -328,6 +328,12 @@ cp_dump_tree (void* dump_info, tree t) dump_child ("expr", EXPR_STMT_EXPR (t)); break; + case OMP_DEPOBJ: + dump_stmt (di, t); + dump_child ("depobj", OMP_DEPOBJ_DEPOBJ (t)); + dump_child ("clauses", OMP_DEPOBJ_CLAUSES (t)); + break; + default: break; } diff --git a/gcc/cp/lex.c b/gcc/cp/lex.c index 26ec52f..49bcf51 100644 --- a/gcc/cp/lex.c +++ b/gcc/cp/lex.c @@ -293,7 +293,7 @@ cxx_init (void) IF_STMT, CLEANUP_STMT, FOR_STMT, RANGE_FOR_STMT, WHILE_STMT, DO_STMT, BREAK_STMT, CONTINUE_STMT, SWITCH_STMT, - EXPR_STMT + EXPR_STMT, OMP_DEPOBJ }; memset (&statement_code_p, 0, sizeof (statement_code_p)); diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 30a4766..deaca5c 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -44,6 +44,7 @@ along with GCC; see the file COPYING3. If not see #include "gcc-rich-location.h" #include "tree-iterator.h" #include "cp-name-hint.h" +#include "memmodel.h" /* The lexer. */ @@ -2110,7 +2111,7 @@ static tree cp_parser_for static tree cp_parser_c_for (cp_parser *, tree, tree, bool, unsigned short); static tree cp_parser_range_for - (cp_parser *, tree, tree, tree, bool, unsigned short); + (cp_parser *, tree, tree, tree, bool, unsigned short, bool); static void do_range_for_auto_deduction (tree, tree); static tree cp_parser_perform_range_for_lookup @@ -11843,7 +11844,8 @@ cp_parser_for (cp_parser *parser, bool ivdep, unsigned short unroll) is_range_for = cp_parser_init_statement (parser, &decl); if (is_range_for) - return cp_parser_range_for (parser, scope, init, decl, ivdep, unroll); + return cp_parser_range_for (parser, scope, init, decl, ivdep, unroll, + false); else return cp_parser_c_for (parser, scope, init, ivdep, unroll); } @@ -11901,7 +11903,7 @@ cp_parser_c_for (cp_parser *parser, tree scope, tree init, bool ivdep, static tree cp_parser_range_for (cp_parser *parser, tree scope, tree init, tree range_decl, - bool ivdep, unsigned short unroll) + bool ivdep, unsigned short unroll, bool is_omp) { tree stmt, range_expr; auto_vec <cxx_binding *, 16> bindings; @@ -11961,6 +11963,11 @@ cp_parser_range_for (cp_parser *parser, tree scope, tree init, tree range_decl, IDENTIFIER_BINDING (names[i]) = binding; } + /* finish_omp_for has its own code for the following, so just + return the range_expr instead. */ + if (is_omp) + return range_expr; + /* If in template, STMT is converted to a normal for-statement at instantiation. If not, it is done just ahead. */ if (processing_template_decl) @@ -31490,7 +31497,7 @@ cp_parser_objc_at_dynamic_declaration (cp_parser *parser) } -/* OpenMP 2.5 / 3.0 / 3.1 / 4.0 parsing routines. */ +/* OpenMP 2.5 / 3.0 / 3.1 / 4.0 / 4.5 / 5.0 parsing routines. */ /* Returns name of the next clause. If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and @@ -31580,6 +31587,8 @@ cp_parser_omp_clause_name (cp_parser *parser) case 'i': if (!strcmp ("if_present", p)) result = PRAGMA_OACC_CLAUSE_IF_PRESENT; + else if (!strcmp ("in_reduction", p)) + result = PRAGMA_OMP_CLAUSE_IN_REDUCTION; else if (!strcmp ("inbranch", p)) result = PRAGMA_OMP_CLAUSE_INBRANCH; else if (!strcmp ("independent", p)) @@ -31604,6 +31613,8 @@ cp_parser_omp_clause_name (cp_parser *parser) case 'n': if (!strcmp ("nogroup", p)) result = PRAGMA_OMP_CLAUSE_NOGROUP; + else if (!strcmp ("nontemporal", p)) + result = PRAGMA_OMP_CLAUSE_NONTEMPORAL; else if (!strcmp ("notinbranch", p)) result = PRAGMA_OMP_CLAUSE_NOTINBRANCH; else if (!strcmp ("nowait", p)) @@ -31668,7 +31679,9 @@ cp_parser_omp_clause_name (cp_parser *parser) result = PRAGMA_OMP_CLAUSE_SIMDLEN; break; case 't': - if (!strcmp ("taskgroup", p)) + if (!strcmp ("task_reduction", p)) + result = PRAGMA_OMP_CLAUSE_TASK_REDUCTION; + else if (!strcmp ("taskgroup", p)) result = PRAGMA_OMP_CLAUSE_TASKGROUP; else if (!strcmp ("thread_limit", p)) result = PRAGMA_OMP_CLAUSE_THREAD_LIMIT; @@ -31759,6 +31772,8 @@ cp_parser_omp_var_list_no_open (cp_parser *parser, enum omp_clause_code kind, { tree name, decl; + if (kind == OMP_CLAUSE_DEPEND) + cp_parser_parse_tentatively (parser); token = cp_lexer_peek_token (parser->lexer); if (kind != 0 && current_class_ptr @@ -31778,15 +31793,25 @@ cp_parser_omp_var_list_no_open (cp_parser *parser, enum omp_clause_code kind, /*declarator_p=*/false, /*optional_p=*/false); if (name == error_mark_node) - goto skip_comma; + { + if (kind == OMP_CLAUSE_DEPEND + && cp_parser_simulate_error (parser)) + goto depend_lvalue; + goto skip_comma; + } if (identifier_p (name)) decl = cp_parser_lookup_name_simple (parser, name, token->location); else decl = name; if (decl == error_mark_node) - cp_parser_name_lookup_error (parser, name, decl, NLE_NULL, - token->location); + { + if (kind == OMP_CLAUSE_DEPEND + && cp_parser_simulate_error (parser)) + goto depend_lvalue; + cp_parser_name_lookup_error (parser, name, decl, NLE_NULL, + token->location); + } } if (decl == error_mark_node) ; @@ -31822,6 +31847,8 @@ cp_parser_omp_var_list_no_open (cp_parser *parser, enum omp_clause_code kind, /* FALLTHROUGH. */ case OMP_CLAUSE_DEPEND: case OMP_CLAUSE_REDUCTION: + case OMP_CLAUSE_IN_REDUCTION: + case OMP_CLAUSE_TASK_REDUCTION: while (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_SQUARE)) { tree low_bound = NULL_TREE, length = NULL_TREE; @@ -31839,7 +31866,14 @@ cp_parser_omp_var_list_no_open (cp_parser *parser, enum omp_clause_code kind, { /* Look for `:'. */ if (!cp_parser_require (parser, CPP_COLON, RT_COLON)) - goto skip_comma; + { + if (kind == OMP_CLAUSE_DEPEND + && cp_parser_simulate_error (parser)) + goto depend_lvalue; + goto skip_comma; + } + if (kind == OMP_CLAUSE_DEPEND) + cp_parser_commit_to_tentative_parse (parser); if (!cp_lexer_next_token_is (parser->lexer, CPP_CLOSE_SQUARE)) length = cp_parser_expression (parser); @@ -31847,7 +31881,12 @@ cp_parser_omp_var_list_no_open (cp_parser *parser, enum omp_clause_code kind, /* Look for the closing `]'. */ if (!cp_parser_require (parser, CPP_CLOSE_SQUARE, RT_CLOSE_SQUARE)) - goto skip_comma; + { + if (kind == OMP_CLAUSE_DEPEND + && cp_parser_simulate_error (parser)) + goto depend_lvalue; + goto skip_comma; + } decl = tree_cons (low_bound, length, decl); } @@ -31856,6 +31895,21 @@ cp_parser_omp_var_list_no_open (cp_parser *parser, enum omp_clause_code kind, break; } + if (kind == OMP_CLAUSE_DEPEND) + { + if (cp_lexer_next_token_is_not (parser->lexer, CPP_COMMA) + && cp_lexer_next_token_is_not (parser->lexer, CPP_CLOSE_PAREN) + && cp_parser_simulate_error (parser)) + { + depend_lvalue: + cp_parser_abort_tentative_parse (parser); + decl = cp_parser_assignment_expression (parser, NULL, + false, false); + } + else + cp_parser_parse_definitely (parser); + } + tree u = build_omp_clause (token->location, kind); OMP_CLAUSE_DECL (u) = decl; OMP_CLAUSE_CHAIN (u) = list; @@ -32440,7 +32494,11 @@ cp_parser_omp_clause_final (cp_parser *parser, tree list, location_t location) directive-name-modifier: parallel | task | taskloop | target data | target | target update - | target enter data | target exit data */ + | target enter data | target exit data + + OpenMP 5.0: + directive-name-modifier: + ... | simd | cancel */ static tree cp_parser_omp_clause_if (cp_parser *parser, tree list, location_t location, @@ -32459,8 +32517,12 @@ cp_parser_omp_clause_if (cp_parser *parser, tree list, location_t location, const char *p = IDENTIFIER_POINTER (id); int n = 2; - if (strcmp ("parallel", p) == 0) + if (strcmp ("cancel", p) == 0) + if_modifier = VOID_CST; + else if (strcmp ("parallel", p) == 0) if_modifier = OMP_PARALLEL; + else if (strcmp ("simd", p) == 0) + if_modifier = OMP_SIMD; else if (strcmp ("task", p) == 0) if_modifier = OMP_TASK; else if (strcmp ("taskloop", p) == 0) @@ -32547,7 +32609,9 @@ cp_parser_omp_clause_if (cp_parser *parser, tree list, location_t location, const char *p = NULL; switch (if_modifier) { + case VOID_CST: p = "cancel"; break; case OMP_PARALLEL: p = "parallel"; break; + case OMP_SIMD: p = "simd"; break; case OMP_TASK: p = "task"; break; case OMP_TASKLOOP: p = "taskloop"; break; case OMP_TARGET_DATA: p = "target data"; break; @@ -32774,7 +32838,10 @@ cp_parser_omp_clause_hint (cp_parser *parser, tree list, } /* OpenMP 4.5: - defaultmap ( tofrom : scalar ) */ + defaultmap ( tofrom : scalar ) + + OpenMP 5.0: + defaultmap ( implicit-behavior [ : variable-category ] ) */ static tree cp_parser_omp_clause_defaultmap (cp_parser *parser, tree list, @@ -32782,47 +32849,163 @@ cp_parser_omp_clause_defaultmap (cp_parser *parser, tree list, { tree c, id; const char *p; + enum omp_clause_defaultmap_kind behavior = OMP_CLAUSE_DEFAULTMAP_DEFAULT; + enum omp_clause_defaultmap_kind category + = OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED; matching_parens parens; if (!parens.require_open (parser)) return list; - if (!cp_lexer_next_token_is (parser->lexer, CPP_NAME)) + if (cp_lexer_next_token_is_keyword (parser->lexer, RID_DEFAULT)) + p = "default"; + else if (!cp_lexer_next_token_is (parser->lexer, CPP_NAME)) { - cp_parser_error (parser, "expected %<tofrom%>"); + invalid_behavior: + cp_parser_error (parser, "expected %<alloc%>, %<to%>, %<from%>, " + "%<tofrom%>, %<firstprivate%>, %<none%> " + "or %<default%>"); goto out_err; } - id = cp_lexer_peek_token (parser->lexer)->u.value; - p = IDENTIFIER_POINTER (id); - if (strcmp (p, "tofrom") != 0) + else { - cp_parser_error (parser, "expected %<tofrom%>"); - goto out_err; + id = cp_lexer_peek_token (parser->lexer)->u.value; + p = IDENTIFIER_POINTER (id); } - cp_lexer_consume_token (parser->lexer); - if (!cp_parser_require (parser, CPP_COLON, RT_COLON)) - goto out_err; - if (!cp_lexer_next_token_is (parser->lexer, CPP_NAME)) + switch (p[0]) { - cp_parser_error (parser, "expected %<scalar%>"); - goto out_err; + case 'a': + if (strcmp ("alloc", p) == 0) + behavior = OMP_CLAUSE_DEFAULTMAP_ALLOC; + else + goto invalid_behavior; + break; + + case 'd': + if (strcmp ("default", p) == 0) + behavior = OMP_CLAUSE_DEFAULTMAP_DEFAULT; + else + goto invalid_behavior; + break; + + case 'f': + if (strcmp ("firstprivate", p) == 0) + behavior = OMP_CLAUSE_DEFAULTMAP_FIRSTPRIVATE; + else if (strcmp ("from", p) == 0) + behavior = OMP_CLAUSE_DEFAULTMAP_FROM; + else + goto invalid_behavior; + break; + + case 'n': + if (strcmp ("none", p) == 0) + behavior = OMP_CLAUSE_DEFAULTMAP_NONE; + else + goto invalid_behavior; + break; + + case 't': + if (strcmp ("tofrom", p) == 0) + behavior = OMP_CLAUSE_DEFAULTMAP_TOFROM; + else if (strcmp ("to", p) == 0) + behavior = OMP_CLAUSE_DEFAULTMAP_TO; + else + goto invalid_behavior; + break; + + default: + goto invalid_behavior; } - id = cp_lexer_peek_token (parser->lexer)->u.value; - p = IDENTIFIER_POINTER (id); - if (strcmp (p, "scalar") != 0) + cp_lexer_consume_token (parser->lexer); + + if (!cp_lexer_next_token_is (parser->lexer, CPP_CLOSE_PAREN)) { - cp_parser_error (parser, "expected %<scalar%>"); - goto out_err; + if (!cp_parser_require (parser, CPP_COLON, RT_COLON)) + goto out_err; + + if (!cp_lexer_next_token_is (parser->lexer, CPP_NAME)) + { + invalid_category: + cp_parser_error (parser, "expected %<scalar%>, %<aggregate%> or " + "%<pointer%>"); + goto out_err; + } + id = cp_lexer_peek_token (parser->lexer)->u.value; + p = IDENTIFIER_POINTER (id); + + switch (p[0]) + { + case 'a': + if (strcmp ("aggregate", p) == 0) + category = OMP_CLAUSE_DEFAULTMAP_CATEGORY_AGGREGATE; + else + goto invalid_category; + break; + + case 'p': + if (strcmp ("pointer", p) == 0) + category = OMP_CLAUSE_DEFAULTMAP_CATEGORY_POINTER; + else + goto invalid_category; + break; + + case 's': + if (strcmp ("scalar", p) == 0) + category = OMP_CLAUSE_DEFAULTMAP_CATEGORY_SCALAR; + else + goto invalid_category; + break; + + default: + goto invalid_category; + } + + cp_lexer_consume_token (parser->lexer); } - cp_lexer_consume_token (parser->lexer); if (!parens.require_close (parser)) goto out_err; - check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULTMAP, "defaultmap", - location); + for (c = list; c ; c = OMP_CLAUSE_CHAIN (c)) + if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEFAULTMAP + && (category == OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED + || OMP_CLAUSE_DEFAULTMAP_CATEGORY (c) == category + || (OMP_CLAUSE_DEFAULTMAP_CATEGORY (c) + == OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED))) + { + enum omp_clause_defaultmap_kind cat = category; + location_t loc = OMP_CLAUSE_LOCATION (c); + if (cat == OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED) + cat = OMP_CLAUSE_DEFAULTMAP_CATEGORY (c); + p = NULL; + switch (cat) + { + case OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED: + p = NULL; + break; + case OMP_CLAUSE_DEFAULTMAP_CATEGORY_AGGREGATE: + p = "aggregate"; + break; + case OMP_CLAUSE_DEFAULTMAP_CATEGORY_POINTER: + p = "pointer"; + break; + case OMP_CLAUSE_DEFAULTMAP_CATEGORY_SCALAR: + p = "scalar"; + break; + default: + gcc_unreachable (); + } + if (p) + error_at (loc, "too many %<defaultmap%> clauses with %qs category", + p); + else + error_at (loc, "too many %<defaultmap%> clauses with unspecified " + "category"); + break; + } c = build_omp_clause (location, OMP_CLAUSE_DEFAULTMAP); + OMP_CLAUSE_DEFAULTMAP_SET_KIND (c, behavior, category); OMP_CLAUSE_CHAIN (c) = list; return c; @@ -32897,17 +33080,50 @@ cp_parser_omp_clause_ordered (cp_parser *parser, reduction-operator: One of: + * - & ^ | && || - id-expression */ + id-expression + + OpenMP 5.0: + reduction ( reduction-modifier, reduction-operator : variable-list ) + in_reduction ( reduction-operator : variable-list ) + task_reduction ( reduction-operator : variable-list ) */ static tree -cp_parser_omp_clause_reduction (cp_parser *parser, tree list) +cp_parser_omp_clause_reduction (cp_parser *parser, enum omp_clause_code kind, + bool is_omp, tree list) { enum tree_code code = ERROR_MARK; tree nlist, c, id = NULL_TREE; + bool task = false; + bool inscan = false; if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN)) return list; + if (kind == OMP_CLAUSE_REDUCTION && is_omp) + { + if (cp_lexer_next_token_is_keyword (parser->lexer, RID_DEFAULT) + && cp_lexer_nth_token_is (parser->lexer, 2, CPP_COMMA)) + { + cp_lexer_consume_token (parser->lexer); + cp_lexer_consume_token (parser->lexer); + } + else if (cp_lexer_next_token_is (parser->lexer, CPP_NAME) + && cp_lexer_nth_token_is (parser->lexer, 2, CPP_COMMA)) + { + tree id = cp_lexer_peek_token (parser->lexer)->u.value; + const char *p = IDENTIFIER_POINTER (id); + if (strcmp (p, "task") == 0) + task = true; + else if (strcmp (p, "inscan") == 0) + inscan = true; + if (task || inscan) + { + cp_lexer_consume_token (parser->lexer); + cp_lexer_consume_token (parser->lexer); + } + } + } + switch (cp_lexer_peek_token (parser->lexer)->type) { case CPP_PLUS: code = PLUS_EXPR; break; @@ -32980,11 +33196,15 @@ cp_parser_omp_clause_reduction (cp_parser *parser, tree list) if (!cp_parser_require (parser, CPP_COLON, RT_COLON)) goto resync_fail; - nlist = cp_parser_omp_var_list_no_open (parser, OMP_CLAUSE_REDUCTION, list, + nlist = cp_parser_omp_var_list_no_open (parser, kind, list, NULL); for (c = nlist; c != list; c = OMP_CLAUSE_CHAIN (c)) { OMP_CLAUSE_REDUCTION_CODE (c) = code; + if (task) + OMP_CLAUSE_REDUCTION_TASK (c) = 1; + else if (inscan) + OMP_CLAUSE_REDUCTION_INSCAN (c) = 1; OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = id; } @@ -33303,6 +33523,43 @@ cp_parser_omp_clause_aligned (cp_parser *parser, tree list) return nlist; } +/* OpenMP 2.5: + lastprivate ( variable-list ) + + OpenMP 5.0: + lastprivate ( [ lastprivate-modifier : ] variable-list ) */ + +static tree +cp_parser_omp_clause_lastprivate (cp_parser *parser, tree list) +{ + bool conditional = false; + + if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN)) + return list; + + if (cp_lexer_next_token_is (parser->lexer, CPP_NAME) + && cp_lexer_nth_token_is (parser->lexer, 2, CPP_COLON)) + { + tree id = cp_lexer_peek_token (parser->lexer)->u.value; + const char *p = IDENTIFIER_POINTER (id); + + if (strcmp ("conditional", p) == 0) + { + conditional = true; + cp_lexer_consume_token (parser->lexer); + cp_lexer_consume_token (parser->lexer); + } + } + + tree nlist = cp_parser_omp_var_list_no_open (parser, OMP_CLAUSE_LASTPRIVATE, + list, NULL); + + if (conditional) + for (tree c = nlist; c != list; c = OMP_CLAUSE_CHAIN (c)) + OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c) = 1; + return nlist; +} + /* OpenMP 4.0: linear ( variable-list ) linear ( variable-list : expression ) @@ -33545,6 +33802,118 @@ cp_parser_omp_clause_depend_sink (cp_parser *parser, location_t clause_loc, return list; } +/* OpenMP 5.0: + iterators ( iterators-definition ) + + iterators-definition: + iterator-specifier + iterator-specifier , iterators-definition + + iterator-specifier: + identifier = range-specification + iterator-type identifier = range-specification + + range-specification: + begin : end + begin : end : step */ + +static tree +cp_parser_omp_iterators (cp_parser *parser) +{ + tree ret = NULL_TREE, *last = &ret; + cp_lexer_consume_token (parser->lexer); + + matching_parens parens; + if (!parens.require_open (parser)) + return error_mark_node; + + bool saved_colon_corrects_to_scope_p + = parser->colon_corrects_to_scope_p; + bool saved_colon_doesnt_start_class_def_p + = parser->colon_doesnt_start_class_def_p; + + do + { + tree iter_type; + if (cp_lexer_next_token_is (parser->lexer, CPP_NAME) + && cp_lexer_nth_token_is (parser->lexer, 2, CPP_EQ)) + iter_type = integer_type_node; + else + { + const char *saved_message + = parser->type_definition_forbidden_message; + parser->type_definition_forbidden_message + = G_("types may not be defined in iterator type"); + + iter_type = cp_parser_type_id (parser); + + parser->type_definition_forbidden_message = saved_message; + } + + location_t loc = cp_lexer_peek_token (parser->lexer)->location; + if (cp_lexer_next_token_is_not (parser->lexer, CPP_NAME)) + { + cp_parser_error (parser, "expected identifier"); + break; + } + + tree id = cp_parser_identifier (parser); + if (id == error_mark_node) + break; + + if (!cp_parser_require (parser, CPP_EQ, RT_EQ)) + break; + + parser->colon_corrects_to_scope_p = false; + parser->colon_doesnt_start_class_def_p = true; + tree begin = cp_parser_assignment_expression (parser); + + if (!cp_parser_require (parser, CPP_COLON, RT_COLON)) + break; + + tree end = cp_parser_assignment_expression (parser); + + tree step = integer_one_node; + if (cp_lexer_next_token_is (parser->lexer, CPP_COLON)) + { + cp_lexer_consume_token (parser->lexer); + step = cp_parser_assignment_expression (parser); + } + + tree iter_var = build_decl (loc, VAR_DECL, id, iter_type); + DECL_ARTIFICIAL (iter_var) = 1; + DECL_CONTEXT (iter_var) = current_function_decl; + pushdecl (iter_var); + + *last = make_tree_vec (6); + TREE_VEC_ELT (*last, 0) = iter_var; + TREE_VEC_ELT (*last, 1) = begin; + TREE_VEC_ELT (*last, 2) = end; + TREE_VEC_ELT (*last, 3) = step; + last = &TREE_CHAIN (*last); + + if (cp_lexer_next_token_is (parser->lexer, CPP_COMMA)) + { + cp_lexer_consume_token (parser->lexer); + continue; + } + break; + } + while (1); + + parser->colon_corrects_to_scope_p = saved_colon_corrects_to_scope_p; + parser->colon_doesnt_start_class_def_p + = saved_colon_doesnt_start_class_def_p; + + if (!parens.require_close (parser)) + cp_parser_skip_to_closing_parenthesis (parser, + /*recovering=*/true, + /*or_comma=*/false, + /*consume_paren=*/true); + + return ret ? ret : error_mark_node; +} + /* OpenMP 4.0: depend ( depend-kind : variable-list ) @@ -33554,41 +33923,73 @@ cp_parser_omp_clause_depend_sink (cp_parser *parser, location_t clause_loc, OpenMP 4.5: depend ( source ) - depend ( sink : vec ) */ + depend ( sink : vec ) + + OpenMP 5.0: + depend ( depend-modifier , depend-kind: variable-list ) + + depend-kind: + in | out | inout | mutexinoutset | depobj + + depend-modifier: + iterator ( iterators-definition ) */ static tree cp_parser_omp_clause_depend (cp_parser *parser, tree list, location_t loc) { - tree nlist, c; - enum omp_clause_depend_kind kind = OMP_CLAUSE_DEPEND_INOUT; + tree nlist, c, iterators = NULL_TREE; + enum omp_clause_depend_kind kind = OMP_CLAUSE_DEPEND_LAST; matching_parens parens; if (!parens.require_open (parser)) return list; - if (cp_lexer_next_token_is (parser->lexer, CPP_NAME)) + do { + if (cp_lexer_next_token_is_not (parser->lexer, CPP_NAME)) + goto invalid_kind; + tree id = cp_lexer_peek_token (parser->lexer)->u.value; const char *p = IDENTIFIER_POINTER (id); + if (strcmp ("iterator", p) == 0 && iterators == NULL_TREE) + { + begin_scope (sk_omp, NULL); + iterators = cp_parser_omp_iterators (parser); + cp_parser_require (parser, CPP_COMMA, RT_COMMA); + continue; + } if (strcmp ("in", p) == 0) kind = OMP_CLAUSE_DEPEND_IN; else if (strcmp ("inout", p) == 0) kind = OMP_CLAUSE_DEPEND_INOUT; + else if (strcmp ("mutexinoutset", p) == 0) + kind = OMP_CLAUSE_DEPEND_MUTEXINOUTSET; else if (strcmp ("out", p) == 0) kind = OMP_CLAUSE_DEPEND_OUT; - else if (strcmp ("source", p) == 0) - kind = OMP_CLAUSE_DEPEND_SOURCE; + else if (strcmp ("depobj", p) == 0) + kind = OMP_CLAUSE_DEPEND_DEPOBJ; else if (strcmp ("sink", p) == 0) kind = OMP_CLAUSE_DEPEND_SINK; + else if (strcmp ("source", p) == 0) + kind = OMP_CLAUSE_DEPEND_SOURCE; else goto invalid_kind; + break; } - else - goto invalid_kind; + while (1); cp_lexer_consume_token (parser->lexer); + if (iterators + && (kind == OMP_CLAUSE_DEPEND_SOURCE || kind == OMP_CLAUSE_DEPEND_SINK)) + { + poplevel (0, 1, 0); + error_at (loc, "%<iterator%> modifier incompatible with %qs", + kind == OMP_CLAUSE_DEPEND_SOURCE ? "source" : "sink"); + iterators = NULL_TREE; + } + if (kind == OMP_CLAUSE_DEPEND_SOURCE) { c = build_omp_clause (loc, OMP_CLAUSE_DEPEND); @@ -33612,14 +34013,30 @@ cp_parser_omp_clause_depend (cp_parser *parser, tree list, location_t loc) nlist = cp_parser_omp_var_list_no_open (parser, OMP_CLAUSE_DEPEND, list, NULL); + if (iterators) + { + tree block = poplevel (1, 1, 0); + if (iterators == error_mark_node) + iterators = NULL_TREE; + else + TREE_VEC_ELT (iterators, 5) = block; + } + for (c = nlist; c != list; c = OMP_CLAUSE_CHAIN (c)) - OMP_CLAUSE_DEPEND_KIND (c) = kind; + { + OMP_CLAUSE_DEPEND_KIND (c) = kind; + if (iterators) + OMP_CLAUSE_DECL (c) + = build_tree_list (iterators, OMP_CLAUSE_DECL (c)); + } } return nlist; invalid_kind: cp_parser_error (parser, "invalid depend kind"); resync_fail: + if (iterators) + poplevel (0, 1, 0); cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true, /*or_comma=*/false, /*consume_paren=*/true); @@ -34022,7 +34439,9 @@ cp_parser_oacc_all_clauses (cp_parser *parser, omp_clause_mask mask, c_name = "private"; break; case PRAGMA_OACC_CLAUSE_REDUCTION: - clauses = cp_parser_omp_clause_reduction (parser, clauses); + clauses + = cp_parser_omp_clause_reduction (parser, OMP_CLAUSE_REDUCTION, + false, clauses); c_name = "reduction"; break; case PRAGMA_OACC_CLAUSE_SEQ: @@ -34169,9 +34588,14 @@ cp_parser_omp_all_clauses (cp_parser *parser, omp_clause_mask mask, true); c_name = "if"; break; + case PRAGMA_OMP_CLAUSE_IN_REDUCTION: + clauses + = cp_parser_omp_clause_reduction (parser, OMP_CLAUSE_IN_REDUCTION, + true, clauses); + c_name = "in_reduction"; + break; case PRAGMA_OMP_CLAUSE_LASTPRIVATE: - clauses = cp_parser_omp_var_list (parser, OMP_CLAUSE_LASTPRIVATE, - clauses); + clauses = cp_parser_omp_clause_lastprivate (parser, clauses); c_name = "lastprivate"; break; case PRAGMA_OMP_CLAUSE_MERGEABLE: @@ -34209,7 +34633,9 @@ cp_parser_omp_all_clauses (cp_parser *parser, omp_clause_mask mask, c_name = "private"; break; case PRAGMA_OMP_CLAUSE_REDUCTION: - clauses = cp_parser_omp_clause_reduction (parser, clauses); + clauses + = cp_parser_omp_clause_reduction (parser, OMP_CLAUSE_REDUCTION, + true, clauses); c_name = "reduction"; break; case PRAGMA_OMP_CLAUSE_SCHEDULE: @@ -34222,6 +34648,13 @@ cp_parser_omp_all_clauses (cp_parser *parser, omp_clause_mask mask, clauses); c_name = "shared"; break; + case PRAGMA_OMP_CLAUSE_TASK_REDUCTION: + clauses + = cp_parser_omp_clause_reduction (parser, + OMP_CLAUSE_TASK_REDUCTION, + true, clauses); + c_name = "task_reduction"; + break; case PRAGMA_OMP_CLAUSE_UNTIED: clauses = cp_parser_omp_clause_untied (parser, clauses, token->location); @@ -34232,6 +34665,11 @@ cp_parser_omp_all_clauses (cp_parser *parser, omp_clause_mask mask, clauses, token->location); c_name = "inbranch"; break; + case PRAGMA_OMP_CLAUSE_NONTEMPORAL: + clauses = cp_parser_omp_var_list (parser, OMP_CLAUSE_NONTEMPORAL, + clauses); + c_name = "nontemporal"; + break; case PRAGMA_OMP_CLAUSE_NOTINBRANCH: clauses = cp_parser_omp_clause_branch (parser, OMP_CLAUSE_NOTINBRANCH, @@ -34494,62 +34932,154 @@ cp_parser_omp_atomic (cp_parser *parser, cp_token *pragma_tok) { tree lhs = NULL_TREE, rhs = NULL_TREE, v = NULL_TREE, lhs1 = NULL_TREE; tree rhs1 = NULL_TREE, orig_lhs; - enum tree_code code = OMP_ATOMIC, opcode = NOP_EXPR; + location_t loc = pragma_tok->location; + enum tree_code code = ERROR_MARK, opcode = NOP_EXPR; + enum omp_memory_order memory_order = OMP_MEMORY_ORDER_UNSPECIFIED; bool structured_block = false; - bool seq_cst = false; - - if (cp_lexer_next_token_is (parser->lexer, CPP_NAME)) - { - tree id = cp_lexer_peek_token (parser->lexer)->u.value; - const char *p = IDENTIFIER_POINTER (id); - - if (!strcmp (p, "seq_cst")) - { - seq_cst = true; - cp_lexer_consume_token (parser->lexer); - if (cp_lexer_next_token_is (parser->lexer, CPP_COMMA) - && cp_lexer_peek_nth_token (parser->lexer, 2)->type == CPP_NAME) - cp_lexer_consume_token (parser->lexer); - } - } - if (cp_lexer_next_token_is (parser->lexer, CPP_NAME)) - { - tree id = cp_lexer_peek_token (parser->lexer)->u.value; - const char *p = IDENTIFIER_POINTER (id); + bool first = true; + tree clauses = NULL_TREE; - if (!strcmp (p, "read")) - code = OMP_ATOMIC_READ; - else if (!strcmp (p, "write")) - code = NOP_EXPR; - else if (!strcmp (p, "update")) - code = OMP_ATOMIC; - else if (!strcmp (p, "capture")) - code = OMP_ATOMIC_CAPTURE_NEW; - else - p = NULL; - if (p) - cp_lexer_consume_token (parser->lexer); - } - if (!seq_cst) + while (cp_lexer_next_token_is_not (parser->lexer, CPP_PRAGMA_EOL)) { - if (cp_lexer_next_token_is (parser->lexer, CPP_COMMA) - && cp_lexer_peek_nth_token (parser->lexer, 2)->type == CPP_NAME) + if (!first && cp_lexer_next_token_is (parser->lexer, CPP_COMMA)) cp_lexer_consume_token (parser->lexer); + first = false; + if (cp_lexer_next_token_is (parser->lexer, CPP_NAME)) { tree id = cp_lexer_peek_token (parser->lexer)->u.value; + location_t cloc = cp_lexer_peek_token (parser->lexer)->location; const char *p = IDENTIFIER_POINTER (id); - - if (!strcmp (p, "seq_cst")) + enum tree_code new_code = ERROR_MARK; + enum omp_memory_order new_memory_order + = OMP_MEMORY_ORDER_UNSPECIFIED; + + if (!strcmp (p, "read")) + new_code = OMP_ATOMIC_READ; + else if (!strcmp (p, "write")) + new_code = NOP_EXPR; + else if (!strcmp (p, "update")) + new_code = OMP_ATOMIC; + else if (!strcmp (p, "capture")) + new_code = OMP_ATOMIC_CAPTURE_NEW; + else if (!strcmp (p, "seq_cst")) + new_memory_order = OMP_MEMORY_ORDER_SEQ_CST; + else if (!strcmp (p, "acq_rel")) + new_memory_order = OMP_MEMORY_ORDER_ACQ_REL; + else if (!strcmp (p, "release")) + new_memory_order = OMP_MEMORY_ORDER_RELEASE; + else if (!strcmp (p, "acquire")) + new_memory_order = OMP_MEMORY_ORDER_ACQUIRE; + else if (!strcmp (p, "relaxed")) + new_memory_order = OMP_MEMORY_ORDER_RELAXED; + else if (!strcmp (p, "hint")) { - seq_cst = true; cp_lexer_consume_token (parser->lexer); + clauses = cp_parser_omp_clause_hint (parser, clauses, cloc); + continue; + } + else + { + p = NULL; + error_at (cloc, "expected %<read%>, %<write%>, %<update%>, " + "%<capture%>, %<seq_cst%>, %<acq_rel%>, " + "%<release%>, %<relaxed%> or %<hint%> clause"); + } + if (p) + { + if (new_code != ERROR_MARK) + { + if (code != ERROR_MARK) + error_at (cloc, "too many atomic clauses"); + else + code = new_code; + } + else if (new_memory_order != OMP_MEMORY_ORDER_UNSPECIFIED) + { + if (memory_order != OMP_MEMORY_ORDER_UNSPECIFIED) + error_at (cloc, "too many memory order clauses"); + else + memory_order = new_memory_order; + } + cp_lexer_consume_token (parser->lexer); + continue; } } + break; } cp_parser_require_pragma_eol (parser, pragma_tok); + if (code == ERROR_MARK) + code = OMP_ATOMIC; + if (memory_order == OMP_MEMORY_ORDER_UNSPECIFIED) + { + omp_requires_mask + = (enum omp_requires) (omp_requires_mask + | OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER_USED); + switch ((enum omp_memory_order) + (omp_requires_mask & OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER)) + { + case OMP_MEMORY_ORDER_UNSPECIFIED: + case OMP_MEMORY_ORDER_RELAXED: + memory_order = OMP_MEMORY_ORDER_RELAXED; + break; + case OMP_MEMORY_ORDER_SEQ_CST: + memory_order = OMP_MEMORY_ORDER_SEQ_CST; + break; + case OMP_MEMORY_ORDER_ACQ_REL: + switch (code) + { + case OMP_ATOMIC_READ: + memory_order = OMP_MEMORY_ORDER_ACQUIRE; + break; + case NOP_EXPR: /* atomic write */ + case OMP_ATOMIC: + memory_order = OMP_MEMORY_ORDER_RELEASE; + break; + default: + memory_order = OMP_MEMORY_ORDER_ACQ_REL; + break; + } + break; + default: + gcc_unreachable (); + } + } + else + switch (code) + { + case OMP_ATOMIC_READ: + if (memory_order == OMP_MEMORY_ORDER_ACQ_REL + || memory_order == OMP_MEMORY_ORDER_RELEASE) + { + error_at (loc, "%<#pragma omp atomic read%> incompatible with " + "%<acq_rel%> or %<release%> clauses"); + memory_order = OMP_MEMORY_ORDER_SEQ_CST; + } + break; + case NOP_EXPR: /* atomic write */ + if (memory_order == OMP_MEMORY_ORDER_ACQ_REL + || memory_order == OMP_MEMORY_ORDER_ACQUIRE) + { + error_at (loc, "%<#pragma omp atomic write%> incompatible with " + "%<acq_rel%> or %<acquire%> clauses"); + memory_order = OMP_MEMORY_ORDER_SEQ_CST; + } + break; + case OMP_ATOMIC: + if (memory_order == OMP_MEMORY_ORDER_ACQ_REL + || memory_order == OMP_MEMORY_ORDER_ACQUIRE) + { + error_at (loc, "%<#pragma omp atomic update%> incompatible with " + "%<acq_rel%> or %<acquire%> clauses"); + memory_order = OMP_MEMORY_ORDER_SEQ_CST; + } + break; + default: + break; + } + switch (code) { case OMP_ATOMIC_READ: @@ -34849,7 +35379,9 @@ stmt_done: cp_parser_require (parser, CPP_CLOSE_BRACE, RT_CLOSE_BRACE); } done: - finish_omp_atomic (code, opcode, lhs, rhs, v, lhs1, rhs1, seq_cst); + clauses = finish_omp_clauses (clauses, C_ORT_OMP); + finish_omp_atomic (pragma_tok->location, code, opcode, lhs, rhs, v, lhs1, + rhs1, clauses, memory_order); if (!structured_block) cp_parser_consume_semicolon_at_end_of_statement (parser); return; @@ -34911,6 +35443,10 @@ cp_parser_omp_critical (cp_parser *parser, cp_token *pragma_tok, bool *if_p) if (name == error_mark_node) name = NULL; + if (cp_lexer_next_token_is (parser->lexer, CPP_COMMA) + && cp_lexer_nth_token_is (parser->lexer, 2, CPP_NAME)) + cp_lexer_consume_token (parser->lexer); + clauses = cp_parser_omp_all_clauses (parser, OMP_CRITICAL_CLAUSE_MASK, "#pragma omp critical", pragma_tok); @@ -34922,26 +35458,151 @@ cp_parser_omp_critical (cp_parser *parser, cp_token *pragma_tok, bool *if_p) return c_finish_omp_critical (input_location, stmt, name, clauses); } +/* OpenMP 5.0: + # pragma omp depobj ( depobj ) depobj-clause new-line + + depobj-clause: + depend (dependence-type : locator) + destroy + update (dependence-type) + + dependence-type: + in + out + inout + mutexinout */ + +static void +cp_parser_omp_depobj (cp_parser *parser, cp_token *pragma_tok) +{ + location_t loc = pragma_tok->location; + matching_parens parens; + if (!parens.require_open (parser)) + { + cp_parser_skip_to_pragma_eol (parser, pragma_tok); + return; + } + + tree depobj = cp_parser_assignment_expression (parser); + + if (!parens.require_close (parser)) + cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true, + /*or_comma=*/false, + /*consume_paren=*/true); + + tree clause = NULL_TREE; + enum omp_clause_depend_kind kind = OMP_CLAUSE_DEPEND_SOURCE; + location_t c_loc = cp_lexer_peek_token (parser->lexer)->location; + if (cp_lexer_next_token_is (parser->lexer, CPP_NAME)) + { + tree id = cp_lexer_peek_token (parser->lexer)->u.value; + const char *p = IDENTIFIER_POINTER (id); + + cp_lexer_consume_token (parser->lexer); + if (!strcmp ("depend", p)) + { + clause = cp_parser_omp_clause_depend (parser, NULL_TREE, c_loc); + if (clause) + clause = finish_omp_clauses (clause, C_ORT_OMP); + if (!clause) + clause = error_mark_node; + } + else if (!strcmp ("destroy", p)) + kind = OMP_CLAUSE_DEPEND_LAST; + else if (!strcmp ("update", p)) + { + matching_parens c_parens; + if (c_parens.require_open (parser)) + { + location_t c2_loc + = cp_lexer_peek_token (parser->lexer)->location; + if (cp_lexer_next_token_is (parser->lexer, CPP_NAME)) + { + tree id2 = cp_lexer_peek_token (parser->lexer)->u.value; + const char *p2 = IDENTIFIER_POINTER (id2); + + cp_lexer_consume_token (parser->lexer); + if (!strcmp ("in", p2)) + kind = OMP_CLAUSE_DEPEND_IN; + else if (!strcmp ("out", p2)) + kind = OMP_CLAUSE_DEPEND_OUT; + else if (!strcmp ("inout", p2)) + kind = OMP_CLAUSE_DEPEND_INOUT; + else if (!strcmp ("mutexinoutset", p2)) + kind = OMP_CLAUSE_DEPEND_MUTEXINOUTSET; + } + if (kind == OMP_CLAUSE_DEPEND_SOURCE) + { + clause = error_mark_node; + error_at (c2_loc, "expected %<in%>, %<out%>, %<inout%> or " + "%<mutexinoutset%>"); + } + if (!c_parens.require_close (parser)) + cp_parser_skip_to_closing_parenthesis (parser, + /*recovering=*/true, + /*or_comma=*/false, + /*consume_paren=*/true); + } + else + clause = error_mark_node; + } + } + if (!clause && kind == OMP_CLAUSE_DEPEND_SOURCE) + { + clause = error_mark_node; + error_at (c_loc, "expected %<depend%>, %<destroy%> or %<update%> clause"); + } + cp_parser_require_pragma_eol (parser, pragma_tok); + + finish_omp_depobj (loc, depobj, kind, clause); +} + + /* OpenMP 2.5: # pragma omp flush flush-vars[opt] new-line flush-vars: - ( variable-list ) */ + ( variable-list ) + + OpenMP 5.0: + # pragma omp flush memory-order-clause new-line */ static void cp_parser_omp_flush (cp_parser *parser, cp_token *pragma_tok) { + enum memmodel mo = MEMMODEL_LAST; + if (cp_lexer_next_token_is (parser->lexer, CPP_NAME)) + { + tree id = cp_lexer_peek_token (parser->lexer)->u.value; + const char *p = IDENTIFIER_POINTER (id); + if (!strcmp (p, "acq_rel")) + mo = MEMMODEL_ACQ_REL; + else if (!strcmp (p, "release")) + mo = MEMMODEL_RELEASE; + else if (!strcmp (p, "acquire")) + mo = MEMMODEL_ACQUIRE; + else + error_at (cp_lexer_peek_token (parser->lexer)->location, + "expected %<acq_rel%>, %<release%> or %<acquire%>"); + cp_lexer_consume_token (parser->lexer); + } if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN)) - (void) cp_parser_omp_var_list (parser, OMP_CLAUSE_ERROR, NULL); + { + if (mo != MEMMODEL_LAST) + error_at (cp_lexer_peek_token (parser->lexer)->location, + "%<flush%> list specified together with memory order " + "clause"); + (void) cp_parser_omp_var_list (parser, OMP_CLAUSE_ERROR, NULL); + } cp_parser_require_pragma_eol (parser, pragma_tok); - finish_omp_flush (); + finish_omp_flush (mo); } /* Helper function, to parse omp for increment expression. */ static tree -cp_parser_omp_for_cond (cp_parser *parser, tree decl) +cp_parser_omp_for_cond (cp_parser *parser, tree decl, enum tree_code code) { tree cond = cp_parser_binary_expression (parser, false, true, PREC_NOT_OPERATOR, NULL); @@ -34960,7 +35621,8 @@ cp_parser_omp_for_cond (cp_parser *parser, tree decl) case LE_EXPR: break; case NE_EXPR: - /* Fall through: OpenMP disallows NE_EXPR. */ + if (code != OACC_LOOP) + break; gcc_fallthrough (); default: return error_mark_node; @@ -35304,6 +35966,192 @@ cp_parser_omp_for_loop_init (cp_parser *parser, return add_private_clause; } +/* Helper for cp_parser_omp_for_loop, handle one range-for loop. */ + +void +cp_convert_omp_range_for (tree &this_pre_body, vec<tree, va_gc> *for_block, + tree &decl, tree &orig_decl, tree &init, + tree &orig_init, tree &cond, tree &incr) +{ + tree begin, end, range_temp_decl = NULL_TREE; + tree iter_type, begin_expr, end_expr; + + if (processing_template_decl) + { + if (check_for_bare_parameter_packs (init)) + init = error_mark_node; + if (!type_dependent_expression_p (init) + /* do_auto_deduction doesn't mess with template init-lists. */ + && !BRACE_ENCLOSED_INITIALIZER_P (init)) + { + tree d = decl; + if (decl != error_mark_node && DECL_HAS_VALUE_EXPR_P (decl)) + { + tree v = DECL_VALUE_EXPR (decl); + if (TREE_CODE (v) == ARRAY_REF + && VAR_P (TREE_OPERAND (v, 0)) + && DECL_DECOMPOSITION_P (TREE_OPERAND (v, 0))) + d = TREE_OPERAND (v, 0); + } + do_range_for_auto_deduction (d, init); + } + cond = global_namespace; + incr = NULL_TREE; + orig_init = init; + if (this_pre_body) + this_pre_body = pop_stmt_list (this_pre_body); + return; + } + + init = mark_lvalue_use (init); + + if (decl == error_mark_node || init == error_mark_node) + /* If an error happened previously do nothing or else a lot of + unhelpful errors would be issued. */ + begin_expr = end_expr = iter_type = error_mark_node; + else + { + tree range_temp; + + if (VAR_P (init) + && array_of_runtime_bound_p (TREE_TYPE (init))) + /* Can't bind a reference to an array of runtime bound. */ + range_temp = init; + else + { + range_temp = build_range_temp (init); + DECL_NAME (range_temp) = NULL_TREE; + pushdecl (range_temp); + cp_finish_decl (range_temp, init, + /*is_constant_init*/false, NULL_TREE, + LOOKUP_ONLYCONVERTING); + range_temp_decl = range_temp; + range_temp = convert_from_reference (range_temp); + } + iter_type = cp_parser_perform_range_for_lookup (range_temp, + &begin_expr, &end_expr); + } + + tree end_iter_type = iter_type; + if (cxx_dialect >= cxx17) + end_iter_type = cv_unqualified (TREE_TYPE (end_expr)); + end = build_decl (input_location, VAR_DECL, NULL_TREE, end_iter_type); + TREE_USED (end) = 1; + DECL_ARTIFICIAL (end) = 1; + pushdecl (end); + cp_finish_decl (end, end_expr, + /*is_constant_init*/false, NULL_TREE, + LOOKUP_ONLYCONVERTING); + + /* The new for initialization statement. */ + begin = build_decl (input_location, VAR_DECL, NULL_TREE, iter_type); + TREE_USED (begin) = 1; + DECL_ARTIFICIAL (begin) = 1; + pushdecl (begin); + orig_init = init; + if (CLASS_TYPE_P (iter_type)) + init = NULL_TREE; + else + { + init = begin_expr; + begin_expr = NULL_TREE; + } + cp_finish_decl (begin, begin_expr, + /*is_constant_init*/false, NULL_TREE, + LOOKUP_ONLYCONVERTING); + + /* The new for condition. */ + if (CLASS_TYPE_P (iter_type)) + cond = build2 (NE_EXPR, boolean_type_node, begin, end); + else + cond = build_x_binary_op (input_location, NE_EXPR, + begin, ERROR_MARK, + end, ERROR_MARK, + NULL, tf_warning_or_error); + + /* The new increment expression. */ + if (CLASS_TYPE_P (iter_type)) + incr = build2 (PREINCREMENT_EXPR, iter_type, begin, NULL_TREE); + else + incr = finish_unary_op_expr (input_location, + PREINCREMENT_EXPR, begin, + tf_warning_or_error); + + orig_decl = decl; + decl = begin; + if (for_block) + { + vec_safe_push (for_block, this_pre_body); + this_pre_body = NULL_TREE; + } + + tree decomp_first_name = NULL_TREE; + unsigned decomp_cnt = 0; + if (orig_decl != error_mark_node && DECL_HAS_VALUE_EXPR_P (orig_decl)) + { + tree v = DECL_VALUE_EXPR (orig_decl); + if (TREE_CODE (v) == ARRAY_REF + && VAR_P (TREE_OPERAND (v, 0)) + && DECL_DECOMPOSITION_P (TREE_OPERAND (v, 0))) + { + tree d = orig_decl; + orig_decl = TREE_OPERAND (v, 0); + decomp_cnt = tree_to_uhwi (TREE_OPERAND (v, 1)) + 1; + decomp_first_name = d; + } + } + + tree auto_node = type_uses_auto (TREE_TYPE (orig_decl)); + if (auto_node) + { + tree t = build_x_indirect_ref (input_location, begin, RO_UNARY_STAR, + tf_none); + if (!error_operand_p (t)) + TREE_TYPE (orig_decl) = do_auto_deduction (TREE_TYPE (orig_decl), + t, auto_node); + } + + tree v = make_tree_vec (decomp_cnt + 3); + TREE_VEC_ELT (v, 0) = range_temp_decl; + TREE_VEC_ELT (v, 1) = end; + TREE_VEC_ELT (v, 2) = orig_decl; + for (unsigned i = 0; i < decomp_cnt; i++) + { + TREE_VEC_ELT (v, i + 3) = decomp_first_name; + decomp_first_name = DECL_CHAIN (decomp_first_name); + } + orig_decl = tree_cons (NULL_TREE, NULL_TREE, v); +} + +/* Helper for cp_parser_omp_for_loop, finalize part of range for + inside of the collapsed body. */ + +void +cp_finish_omp_range_for (tree orig, tree begin) +{ + gcc_assert (TREE_CODE (orig) == TREE_LIST + && TREE_CODE (TREE_CHAIN (orig)) == TREE_VEC); + tree decl = TREE_VEC_ELT (TREE_CHAIN (orig), 2); + tree decomp_first_name = NULL_TREE; + unsigned int decomp_cnt = 0; + + if (VAR_P (decl) && DECL_DECOMPOSITION_P (decl)) + { + decomp_first_name = TREE_VEC_ELT (TREE_CHAIN (orig), 3); + decomp_cnt = TREE_VEC_LENGTH (TREE_CHAIN (orig)) - 3; + cp_maybe_mangle_decomp (decl, decomp_first_name, decomp_cnt); + } + + /* The declaration is initialized with *__begin inside the loop body. */ + cp_finish_decl (decl, + build_x_indirect_ref (input_location, begin, RO_UNARY_STAR, + tf_warning_or_error), + /*is_constant_init*/false, NULL_TREE, + LOOKUP_ONLYCONVERTING); + if (VAR_P (decl) && DECL_DECOMPOSITION_P (decl)) + cp_finish_decomp (decl, decomp_first_name, decomp_cnt); +} + /* Parse the restricted form of the for statement allowed by OpenMP. */ static tree @@ -35311,7 +36159,8 @@ cp_parser_omp_for_loop (cp_parser *parser, enum tree_code code, tree clauses, tree *cclauses, bool *if_p) { tree init, orig_init, cond, incr, body, decl, pre_body = NULL_TREE, ret; - tree real_decl, initv, condv, incrv, declv; + tree orig_decl; + tree real_decl, initv, condv, incrv, declv, orig_declv; tree this_pre_body, cl, ordered_cl = NULL_TREE; location_t loc_first; bool collapse_err = false; @@ -35364,6 +36213,7 @@ cp_parser_omp_for_loop (cp_parser *parser, enum tree_code code, tree clauses, initv = make_tree_vec (count); condv = make_tree_vec (count); incrv = make_tree_vec (count); + orig_declv = NULL_TREE; loc_first = cp_lexer_peek_token (parser->lexer)->location; @@ -35385,9 +36235,71 @@ cp_parser_omp_for_loop (cp_parser *parser, enum tree_code code, tree clauses, if (!parens.require_open (parser)) return NULL; - init = orig_init = decl = real_decl = NULL; + init = orig_init = decl = real_decl = orig_decl = NULL_TREE; this_pre_body = push_stmt_list (); + if (code != OACC_LOOP && cxx_dialect >= cxx11) + { + /* Save tokens so that we can put them back. */ + cp_lexer_save_tokens (parser->lexer); + + /* Look for ':' that is not nested in () or {}. */ + bool is_range_for + = (cp_parser_skip_to_closing_parenthesis_1 (parser, + /*recovering=*/false, + CPP_COLON, + /*consume_paren=*/ + false) == -1); + + /* Roll back the tokens we skipped. */ + cp_lexer_rollback_tokens (parser->lexer); + + if (is_range_for) + { + bool saved_colon_corrects_to_scope_p + = parser->colon_corrects_to_scope_p; + + /* A colon is used in range-based for. */ + parser->colon_corrects_to_scope_p = false; + + /* Parse the declaration. */ + cp_parser_simple_declaration (parser, + /*function_definition_allowed_p=*/ + false, &decl); + parser->colon_corrects_to_scope_p + = saved_colon_corrects_to_scope_p; + + cp_parser_require (parser, CPP_COLON, RT_COLON); + + init = cp_parser_range_for (parser, NULL_TREE, NULL_TREE, decl, + false, 0, true); + + cp_convert_omp_range_for (this_pre_body, for_block, decl, + orig_decl, init, orig_init, + cond, incr); + if (this_pre_body) + { + if (pre_body) + { + tree t = pre_body; + pre_body = push_stmt_list (); + add_stmt (t); + add_stmt (this_pre_body); + pre_body = pop_stmt_list (pre_body); + } + else + pre_body = this_pre_body; + } + + if (ordered_cl) + error_at (OMP_CLAUSE_LOCATION (ordered_cl), + "%<ordered%> clause with parameter on " + "range-based %<for%> loop"); + + goto parse_close_paren; + } + } + add_private_clause = cp_parser_omp_for_loop_init (parser, this_pre_body, for_block, init, orig_init, decl, real_decl); @@ -35464,7 +36376,8 @@ cp_parser_omp_for_loop (cp_parser *parser, enum tree_code code, tree clauses, error_at (loc, "iteration variable %qD " "should not be firstprivate", decl); - else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION + else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION + || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION) && OMP_CLAUSE_DECL (c) == decl) error_at (loc, "iteration variable %qD should not be reduction", decl); @@ -35493,7 +36406,7 @@ cp_parser_omp_for_loop (cp_parser *parser, enum tree_code code, tree clauses, cond = NULL; if (cp_lexer_next_token_is_not (parser->lexer, CPP_SEMICOLON)) - cond = cp_parser_omp_for_cond (parser, decl); + cond = cp_parser_omp_for_cond (parser, decl, code); cp_parser_require (parser, CPP_SEMICOLON, RT_SEMICOLON); incr = NULL; @@ -35513,6 +36426,7 @@ cp_parser_omp_for_loop (cp_parser *parser, enum tree_code code, tree clauses, protected_set_expr_location (incr, input_location); } + parse_close_paren: if (!parens.require_close (parser)) cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true, /*or_comma=*/false, @@ -35527,6 +36441,14 @@ cp_parser_omp_for_loop (cp_parser *parser, enum tree_code code, tree clauses, orig_inits.safe_grow_cleared (i + 1); orig_inits[i] = orig_init; } + if (orig_decl) + { + if (!orig_declv) + orig_declv = copy_node (declv); + TREE_VEC_ELT (orig_declv, i) = orig_decl; + } + else if (orig_declv) + TREE_VEC_ELT (orig_declv, i) = decl; if (i == count - 1) break; @@ -35575,15 +36497,27 @@ cp_parser_omp_for_loop (cp_parser *parser, enum tree_code code, tree clauses, /* Note that the grammar doesn't call for a structured block here, though the loop as a whole is a structured block. */ - body = push_stmt_list (); + if (orig_declv) + { + body = begin_omp_structured_block (); + for (i = 0; i < count; i++) + if (TREE_VEC_ELT (orig_declv, i) != TREE_VEC_ELT (declv, i)) + cp_finish_omp_range_for (TREE_VEC_ELT (orig_declv, i), + TREE_VEC_ELT (declv, i)); + } + else + body = push_stmt_list (); cp_parser_statement (parser, NULL_TREE, false, if_p); - body = pop_stmt_list (body); + if (orig_declv) + body = finish_omp_structured_block (body); + else + body = pop_stmt_list (body); if (declv == NULL_TREE) ret = NULL_TREE; else - ret = finish_omp_for (loc_first, code, declv, NULL, initv, condv, incrv, - body, pre_body, &orig_inits, clauses); + ret = finish_omp_for (loc_first, code, declv, orig_declv, initv, condv, + incrv, body, pre_body, &orig_inits, clauses); while (nbraces) { @@ -35647,7 +36581,9 @@ cp_omp_split_clauses (location_t loc, enum tree_code code, | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \ | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \ - | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE)) + | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \ + | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \ + | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NONTEMPORAL)) static tree cp_parser_omp_simd (cp_parser *parser, cp_token *pragma_tok, @@ -35678,13 +36614,14 @@ cp_parser_omp_simd (cp_parser *parser, cp_token *pragma_tok, } } + keep_next_level (true); sb = begin_omp_structured_block (); save = cp_parser_begin_omp_structured_block (parser); ret = cp_parser_omp_for_loop (parser, OMP_SIMD, clauses, cclauses, if_p); cp_parser_end_omp_structured_block (parser, save); - add_stmt (finish_omp_structured_block (sb)); + add_stmt (finish_omp_for_block (finish_omp_structured_block (sb), ret)); return ret; } @@ -35777,26 +36714,78 @@ cp_parser_omp_for (cp_parser *parser, cp_token *pragma_tok, clauses = cclauses[C_OMP_CLAUSE_SPLIT_FOR]; } + keep_next_level (true); sb = begin_omp_structured_block (); save = cp_parser_begin_omp_structured_block (parser); ret = cp_parser_omp_for_loop (parser, OMP_FOR, clauses, cclauses, if_p); cp_parser_end_omp_structured_block (parser, save); - add_stmt (finish_omp_structured_block (sb)); + add_stmt (finish_omp_for_block (finish_omp_structured_block (sb), ret)); return ret; } +static tree cp_parser_omp_taskloop (cp_parser *, cp_token *, char *, + omp_clause_mask, tree *, bool *); + /* OpenMP 2.5: # pragma omp master new-line structured-block */ static tree -cp_parser_omp_master (cp_parser *parser, cp_token *pragma_tok, bool *if_p) +cp_parser_omp_master (cp_parser *parser, cp_token *pragma_tok, + char *p_name, omp_clause_mask mask, tree *cclauses, + bool *if_p) { - cp_parser_require_pragma_eol (parser, pragma_tok); - return c_finish_omp_master (input_location, + tree clauses, sb, ret; + unsigned int save; + location_t loc = cp_lexer_peek_token (parser->lexer)->location; + + strcat (p_name, " master"); + + if (cp_lexer_next_token_is (parser->lexer, CPP_NAME)) + { + tree id = cp_lexer_peek_token (parser->lexer)->u.value; + const char *p = IDENTIFIER_POINTER (id); + + if (strcmp (p, "taskloop") == 0) + { + tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; + if (cclauses == NULL) + cclauses = cclauses_buf; + + cp_lexer_consume_token (parser->lexer); + if (!flag_openmp) /* flag_openmp_simd */ + return cp_parser_omp_taskloop (parser, pragma_tok, p_name, mask, + cclauses, if_p); + sb = begin_omp_structured_block (); + save = cp_parser_begin_omp_structured_block (parser); + ret = cp_parser_omp_taskloop (parser, pragma_tok, p_name, mask, + cclauses, if_p); + cp_parser_end_omp_structured_block (parser, save); + tree body = finish_omp_structured_block (sb); + if (ret == NULL) + return ret; + return c_finish_omp_master (loc, body); + } + } + if (!flag_openmp) /* flag_openmp_simd */ + { + cp_parser_skip_to_pragma_eol (parser, pragma_tok); + return NULL_TREE; + } + + if (cclauses) + { + clauses = cp_parser_omp_all_clauses (parser, mask, p_name, pragma_tok, + false); + cp_omp_split_clauses (loc, OMP_MASTER, mask, clauses, cclauses); + } + else + cp_parser_require_pragma_eol (parser, pragma_tok); + + return c_finish_omp_master (loc, cp_parser_omp_structured_block (parser, if_p)); } @@ -36038,16 +37027,34 @@ cp_parser_omp_parallel (cp_parser *parser, cp_token *pragma_tok, cp_parser_skip_to_pragma_eol (parser, pragma_tok); return NULL_TREE; } - else if (!flag_openmp) /* flag_openmp_simd */ - { - cp_parser_skip_to_pragma_eol (parser, pragma_tok); - return NULL_TREE; - } else if (cclauses == NULL && cp_lexer_next_token_is (parser->lexer, CPP_NAME)) { tree id = cp_lexer_peek_token (parser->lexer)->u.value; const char *p = IDENTIFIER_POINTER (id); - if (strcmp (p, "sections") == 0) + if (strcmp (p, "master") == 0) + { + tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; + cclauses = cclauses_buf; + + cp_lexer_consume_token (parser->lexer); + block = begin_omp_parallel (); + save = cp_parser_begin_omp_structured_block (parser); + tree ret = cp_parser_omp_master (parser, pragma_tok, p_name, mask, + cclauses, if_p); + cp_parser_end_omp_structured_block (parser, save); + stmt = finish_omp_parallel (cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL], + block); + OMP_PARALLEL_COMBINED (stmt) = 1; + if (ret == NULL_TREE) + return ret; + return stmt; + } + else if (!flag_openmp) /* flag_openmp_simd */ + { + cp_parser_skip_to_pragma_eol (parser, pragma_tok); + return NULL_TREE; + } + else if (strcmp (p, "sections") == 0) { tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; cclauses = cclauses_buf; @@ -36063,6 +37070,11 @@ cp_parser_omp_parallel (cp_parser *parser, cp_token *pragma_tok, return stmt; } } + else if (!flag_openmp) /* flag_openmp_simd */ + { + cp_parser_skip_to_pragma_eol (parser, pragma_tok); + return NULL_TREE; + } clauses = cp_parser_omp_all_clauses (parser, mask, p_name, pragma_tok, cclauses == NULL); @@ -36095,6 +37107,7 @@ cp_parser_omp_single (cp_parser *parser, cp_token *pragma_tok, bool *if_p) { tree stmt = make_node (OMP_SINGLE); TREE_TYPE (stmt) = void_type_node; + SET_EXPR_LOCATION (stmt, pragma_tok->location); OMP_SINGLE_CLAUSES (stmt) = cp_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK, @@ -36118,7 +37131,8 @@ cp_parser_omp_single (cp_parser *parser, cp_token *pragma_tok, bool *if_p) | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \ | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \ | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \ - | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY)) + | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY) \ + | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IN_REDUCTION)) static tree cp_parser_omp_task (cp_parser *parser, cp_token *pragma_tok, bool *if_p) @@ -36136,13 +37150,32 @@ cp_parser_omp_task (cp_parser *parser, cp_token *pragma_tok, bool *if_p) } /* OpenMP 3.0: - # pragma omp taskwait new-line */ + # pragma omp taskwait new-line + + OpenMP 5.0: + # pragma omp taskwait taskwait-clause[opt] new-line */ + +#define OMP_TASKWAIT_CLAUSE_MASK \ + (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) static void cp_parser_omp_taskwait (cp_parser *parser, cp_token *pragma_tok) { - cp_parser_require_pragma_eol (parser, pragma_tok); - finish_omp_taskwait (); + tree clauses + = cp_parser_omp_all_clauses (parser, OMP_TASKWAIT_CLAUSE_MASK, + "#pragma omp taskwait", pragma_tok); + + if (clauses) + { + tree stmt = make_node (OMP_TASK); + TREE_TYPE (stmt) = void_node; + OMP_TASK_CLAUSES (stmt) = clauses; + OMP_TASK_BODY (stmt) = NULL_TREE; + SET_EXPR_LOCATION (stmt, pragma_tok->location); + add_stmt (stmt); + } + else + finish_omp_taskwait (); } /* OpenMP 3.1: @@ -36157,15 +37190,24 @@ cp_parser_omp_taskyield (cp_parser *parser, cp_token *pragma_tok) /* OpenMP 4.0: # pragma omp taskgroup new-line - structured-block */ + structured-block + + OpenMP 5.0: + # pragma omp taskgroup taskgroup-clause[optseq] new-line */ + +#define OMP_TASKGROUP_CLAUSE_MASK \ + ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASK_REDUCTION)) static tree cp_parser_omp_taskgroup (cp_parser *parser, cp_token *pragma_tok, bool *if_p) { - cp_parser_require_pragma_eol (parser, pragma_tok); + tree clauses + = cp_parser_omp_all_clauses (parser, OMP_TASKGROUP_CLAUSE_MASK, + "#pragma omp taskgroup", pragma_tok); return c_finish_omp_taskgroup (input_location, cp_parser_omp_structured_block (parser, - if_p)); + if_p), + clauses); } @@ -36338,13 +37380,14 @@ cp_parser_omp_distribute (cp_parser *parser, cp_token *pragma_tok, clauses = cclauses[C_OMP_CLAUSE_SPLIT_DISTRIBUTE]; } + keep_next_level (true); sb = begin_omp_structured_block (); save = cp_parser_begin_omp_structured_block (parser); ret = cp_parser_omp_for_loop (parser, OMP_DISTRIBUTE, clauses, NULL, if_p); cp_parser_end_omp_structured_block (parser, save); - add_stmt (finish_omp_structured_block (sb)); + add_stmt (finish_omp_for_block (finish_omp_structured_block (sb), ret)); return ret; } @@ -36388,6 +37431,7 @@ cp_parser_omp_teams (cp_parser *parser, cp_token *pragma_tok, if (!flag_openmp) /* flag_openmp_simd */ return cp_parser_omp_distribute (parser, pragma_tok, p_name, mask, cclauses, if_p); + keep_next_level (true); sb = begin_omp_structured_block (); save = cp_parser_begin_omp_structured_block (parser); ret = cp_parser_omp_distribute (parser, pragma_tok, p_name, mask, @@ -36423,6 +37467,7 @@ cp_parser_omp_teams (cp_parser *parser, cp_token *pragma_tok, tree stmt = make_node (OMP_TEAMS); TREE_TYPE (stmt) = void_type_node; OMP_TEAMS_CLAUSES (stmt) = clauses; + keep_next_level (true); OMP_TEAMS_BODY (stmt) = cp_parser_omp_structured_block (parser, if_p); SET_EXPR_LOCATION (stmt, loc); @@ -36473,6 +37518,8 @@ cp_parser_omp_target_data (cp_parser *parser, cp_token *pragma_tok, bool *if_p) *pc = OMP_CLAUSE_CHAIN (*pc); continue; } + else if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_USE_DEVICE_PTR) + map_seen = 3; pc = &OMP_CLAUSE_CHAIN (*pc); } @@ -36481,7 +37528,7 @@ cp_parser_omp_target_data (cp_parser *parser, cp_token *pragma_tok, bool *if_p) if (map_seen == 0) error_at (pragma_tok->location, "%<#pragma omp target data%> must contain at least " - "one %<map%> clause"); + "one %<map%> or %<use_device_ptr%> clause"); return NULL_TREE; } @@ -36739,6 +37786,10 @@ cp_parser_omp_target (cp_parser *parser, cp_token *pragma_tok, { tree *pc = NULL, stmt; + if (flag_openmp) + omp_requires_mask + = (enum omp_requires) (omp_requires_mask | OMP_REQUIRES_TARGET_USED); + if (cp_lexer_next_token_is (parser->lexer, CPP_NAME)) { tree id = cp_lexer_peek_token (parser->lexer)->u.value; @@ -38092,6 +39143,147 @@ cp_parser_omp_declare (cp_parser *parser, cp_token *pragma_tok, return false; } +/* OpenMP 5.0 + #pragma omp requires clauses[optseq] new-line */ + +static bool +cp_parser_omp_requires (cp_parser *parser, cp_token *pragma_tok) +{ + bool first = true; + enum omp_requires new_req = (enum omp_requires) 0; + + location_t loc = pragma_tok->location; + while (cp_lexer_next_token_is_not (parser->lexer, CPP_PRAGMA_EOL)) + { + if (!first && cp_lexer_next_token_is (parser->lexer, CPP_COMMA)) + cp_lexer_consume_token (parser->lexer); + + first = false; + + if (cp_lexer_next_token_is (parser->lexer, CPP_NAME)) + { + tree id = cp_lexer_peek_token (parser->lexer)->u.value; + const char *p = IDENTIFIER_POINTER (id); + location_t cloc = cp_lexer_peek_token (parser->lexer)->location; + enum omp_requires this_req = (enum omp_requires) 0; + + if (!strcmp (p, "unified_address")) + this_req = OMP_REQUIRES_UNIFIED_ADDRESS; + else if (!strcmp (p, "unified_shared_memory")) + this_req = OMP_REQUIRES_UNIFIED_SHARED_MEMORY; + else if (!strcmp (p, "dynamic_allocators")) + this_req = OMP_REQUIRES_DYNAMIC_ALLOCATORS; + else if (!strcmp (p, "reverse_offload")) + this_req = OMP_REQUIRES_REVERSE_OFFLOAD; + else if (!strcmp (p, "atomic_default_mem_order")) + { + cp_lexer_consume_token (parser->lexer); + + matching_parens parens; + if (parens.require_open (parser)) + { + if (cp_lexer_next_token_is (parser->lexer, CPP_NAME)) + { + id = cp_lexer_peek_token (parser->lexer)->u.value; + p = IDENTIFIER_POINTER (id); + + if (!strcmp (p, "seq_cst")) + this_req + = (enum omp_requires) OMP_MEMORY_ORDER_SEQ_CST; + else if (!strcmp (p, "relaxed")) + this_req + = (enum omp_requires) OMP_MEMORY_ORDER_RELAXED; + else if (!strcmp (p, "acq_rel")) + this_req + = (enum omp_requires) OMP_MEMORY_ORDER_ACQ_REL; + } + if (this_req == 0) + { + error_at (cp_lexer_peek_token (parser->lexer)->location, + "expected %<seq_cst%>, %<relaxed%> or " + "%<acq_rel%>"); + if (cp_lexer_nth_token_is (parser->lexer, 2, + CPP_CLOSE_PAREN)) + cp_lexer_consume_token (parser->lexer); + } + else + cp_lexer_consume_token (parser->lexer); + + if (!parens.require_close (parser)) + cp_parser_skip_to_closing_parenthesis (parser, + /*recovering=*/true, + /*or_comma=*/false, + /*consume_paren=*/ + true); + + if (this_req == 0) + { + cp_parser_require_pragma_eol (parser, pragma_tok); + return false; + } + } + p = NULL; + } + else + { + error_at (cloc, "expected %<unified_address%>, " + "%<unified_shared_memory%>, " + "%<dynamic_allocators%>, " + "%<reverse_offload%> " + "or %<atomic_default_mem_order%> clause"); + cp_parser_skip_to_pragma_eol (parser, pragma_tok); + return false; + } + if (p) + cp_lexer_consume_token (parser->lexer); + if (this_req) + { + if ((this_req & ~OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER) != 0) + { + if ((this_req & new_req) != 0) + error_at (cloc, "too many %qs clauses", p); + if (this_req != OMP_REQUIRES_DYNAMIC_ALLOCATORS + && (omp_requires_mask & OMP_REQUIRES_TARGET_USED) != 0) + error_at (cloc, "%qs clause used lexically after first " + "target construct or offloading API", p); + } + else if ((new_req & OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER) != 0) + { + error_at (cloc, "too many %qs clauses", + "atomic_default_mem_order"); + this_req = (enum omp_requires) 0; + } + else if ((omp_requires_mask + & OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER) != 0) + { + error_at (cloc, "more than one %<atomic_default_mem_order%>" + " clause in a single compilation unit"); + this_req + = (enum omp_requires) + (omp_requires_mask + & OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER); + } + else if ((omp_requires_mask + & OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER_USED) != 0) + error_at (cloc, "%<atomic_default_mem_order%> clause used " + "lexically after first %<atomic%> construct " + "without memory order clause"); + new_req = (enum omp_requires) (new_req | this_req); + omp_requires_mask + = (enum omp_requires) (omp_requires_mask | this_req); + continue; + } + } + break; + } + cp_parser_require_pragma_eol (parser, pragma_tok); + + if (new_req == 0) + error_at (loc, "%<pragma omp requires%> requires at least one clause"); + return false; +} + + /* OpenMP 4.5: #pragma omp taskloop taskloop-clause[optseq] new-line for-loop @@ -38113,7 +39305,9 @@ cp_parser_omp_declare (cp_parser *parser, cp_token *pragma_tok, | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \ | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \ | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP) \ - | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY)) + | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY) \ + | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \ + | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IN_REDUCTION)) static tree cp_parser_omp_taskloop (cp_parser *parser, cp_token *pragma_tok, @@ -38126,6 +39320,10 @@ cp_parser_omp_taskloop (cp_parser *parser, cp_token *pragma_tok, strcat (p_name, " taskloop"); mask |= OMP_TASKLOOP_CLAUSE_MASK; + /* #pragma omp parallel master taskloop{, simd} disallow in_reduction + clause. */ + if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS)) != 0) + mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IN_REDUCTION); if (cp_lexer_next_token_is (parser->lexer, CPP_NAME)) { @@ -38173,6 +39371,7 @@ cp_parser_omp_taskloop (cp_parser *parser, cp_token *pragma_tok, clauses = cclauses[C_OMP_CLAUSE_SPLIT_TASKLOOP]; } + keep_next_level (true); sb = begin_omp_structured_block (); save = cp_parser_begin_omp_structured_block (parser); @@ -38180,7 +39379,7 @@ cp_parser_omp_taskloop (cp_parser *parser, cp_token *pragma_tok, if_p); cp_parser_end_omp_structured_block (parser, save); - add_stmt (finish_omp_structured_block (sb)); + add_stmt (finish_omp_for_block (finish_omp_structured_block (sb), ret)); return ret; } @@ -38487,7 +39686,9 @@ cp_parser_omp_construct (cp_parser *parser, cp_token *pragma_tok, bool *if_p) if_p); break; case PRAGMA_OMP_MASTER: - stmt = cp_parser_omp_master (parser, pragma_tok, if_p); + strcpy (p_name, "#pragma omp"); + stmt = cp_parser_omp_master (parser, pragma_tok, p_name, mask, NULL, + if_p); break; case PRAGMA_OMP_PARALLEL: strcpy (p_name, "#pragma omp"); @@ -38947,6 +40148,21 @@ cp_parser_pragma (cp_parser *parser, enum pragma_context context, bool *if_p) } break; + case PRAGMA_OMP_DEPOBJ: + switch (context) + { + case pragma_compound: + cp_parser_omp_depobj (parser, pragma_tok); + return false; + case pragma_stmt: + error_at (pragma_tok->location, "%<#pragma %s%> may only be " + "used in compound statements", "omp depobj"); + break; + default: + goto bad_stmt; + } + break; + case PRAGMA_OMP_FLUSH: switch (context) { @@ -39114,6 +40330,9 @@ cp_parser_pragma (cp_parser *parser, enum pragma_context context, bool *if_p) pop_omp_privatization_clauses (stmt); return true; + case PRAGMA_OMP_REQUIRES: + return cp_parser_omp_requires (parser, pragma_tok); + case PRAGMA_OMP_ORDERED: if (context != pragma_stmt && context != pragma_compound) goto bad_stmt; diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 80b4eec..fe330cd 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -16097,11 +16097,49 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl) static tree tsubst_omp_clause_decl (tree decl, tree args, tsubst_flags_t complain, - tree in_decl) + tree in_decl, tree *iterator_cache) { if (decl == NULL_TREE) return NULL_TREE; + /* Handle OpenMP iterators. */ + if (TREE_CODE (decl) == TREE_LIST + && TREE_PURPOSE (decl) + && TREE_CODE (TREE_PURPOSE (decl)) == TREE_VEC) + { + tree ret; + if (iterator_cache[0] == TREE_PURPOSE (decl)) + ret = iterator_cache[1]; + else + { + tree *tp = &ret; + begin_scope (sk_omp, NULL); + for (tree it = TREE_PURPOSE (decl); it; it = TREE_CHAIN (it)) + { + *tp = copy_node (it); + TREE_VEC_ELT (*tp, 0) + = tsubst_decl (TREE_VEC_ELT (it, 0), args, complain); + TREE_VEC_ELT (*tp, 1) + = tsubst_expr (TREE_VEC_ELT (it, 1), args, complain, in_decl, + /*integral_constant_expression_p=*/false); + TREE_VEC_ELT (*tp, 2) + = tsubst_expr (TREE_VEC_ELT (it, 2), args, complain, in_decl, + /*integral_constant_expression_p=*/false); + TREE_VEC_ELT (*tp, 3) + = tsubst_expr (TREE_VEC_ELT (it, 3), args, complain, in_decl, + /*integral_constant_expression_p=*/false); + TREE_CHAIN (*tp) = NULL_TREE; + tp = &TREE_CHAIN (*tp); + } + TREE_VEC_ELT (ret, 5) = poplevel (1, 1, 0); + iterator_cache[0] = TREE_PURPOSE (decl); + iterator_cache[1] = ret; + } + return build_tree_list (ret, tsubst_omp_clause_decl (TREE_VALUE (decl), + args, complain, + in_decl, NULL)); + } + /* Handle an OpenMP array section represented as a TREE_LIST (or OMP_CLAUSE_DEPEND_KIND). An OMP_CLAUSE_DEPEND (with a depend kind of OMP_CLAUSE_DEPEND_SINK) can also be represented as a @@ -16116,7 +16154,7 @@ tsubst_omp_clause_decl (tree decl, tree args, tsubst_flags_t complain, tree length = tsubst_expr (TREE_VALUE (decl), args, complain, in_decl, /*integral_constant_expression_p=*/false); tree chain = tsubst_omp_clause_decl (TREE_CHAIN (decl), args, complain, - in_decl); + in_decl, NULL); if (TREE_PURPOSE (decl) == low_bound && TREE_VALUE (decl) == length && TREE_CHAIN (decl) == chain) @@ -16144,6 +16182,7 @@ tsubst_omp_clauses (tree clauses, enum c_omp_region_type ort, { tree new_clauses = NULL_TREE, nc, oc; tree linear_no_step = NULL_TREE; + tree iterator_cache[2] = { NULL_TREE, NULL_TREE }; for (oc = clauses; oc ; oc = OMP_CLAUSE_CHAIN (oc)) { @@ -16173,11 +16212,12 @@ tsubst_omp_clauses (tree clauses, enum c_omp_region_type ort, case OMP_CLAUSE_FROM: case OMP_CLAUSE_TO: case OMP_CLAUSE_MAP: + case OMP_CLAUSE_NONTEMPORAL: case OMP_CLAUSE_USE_DEVICE_PTR: case OMP_CLAUSE_IS_DEVICE_PTR: OMP_CLAUSE_DECL (nc) = tsubst_omp_clause_decl (OMP_CLAUSE_DECL (oc), args, complain, - in_decl); + in_decl, iterator_cache); break; case OMP_CLAUSE_TILE: case OMP_CLAUSE_IF: @@ -16208,6 +16248,8 @@ tsubst_omp_clauses (tree clauses, enum c_omp_region_type ort, in_decl, /*integral_constant_expression_p=*/false); break; case OMP_CLAUSE_REDUCTION: + case OMP_CLAUSE_IN_REDUCTION: + case OMP_CLAUSE_TASK_REDUCTION: if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (oc)) { tree placeholder = OMP_CLAUSE_REDUCTION_PLACEHOLDER (oc); @@ -16225,13 +16267,13 @@ tsubst_omp_clauses (tree clauses, enum c_omp_region_type ort, } OMP_CLAUSE_DECL (nc) = tsubst_omp_clause_decl (OMP_CLAUSE_DECL (oc), args, complain, - in_decl); + in_decl, NULL); break; case OMP_CLAUSE_GANG: case OMP_CLAUSE_ALIGNED: OMP_CLAUSE_DECL (nc) = tsubst_omp_clause_decl (OMP_CLAUSE_DECL (oc), args, complain, - in_decl); + in_decl, NULL); OMP_CLAUSE_OPERAND (nc, 1) = tsubst_expr (OMP_CLAUSE_OPERAND (oc, 1), args, complain, in_decl, /*integral_constant_expression_p=*/false); @@ -16239,7 +16281,7 @@ tsubst_omp_clauses (tree clauses, enum c_omp_region_type ort, case OMP_CLAUSE_LINEAR: OMP_CLAUSE_DECL (nc) = tsubst_omp_clause_decl (OMP_CLAUSE_DECL (oc), args, complain, - in_decl); + in_decl, NULL); if (OMP_CLAUSE_LINEAR_STEP (oc) == NULL_TREE) { gcc_assert (!linear_no_step); @@ -16248,7 +16290,7 @@ tsubst_omp_clauses (tree clauses, enum c_omp_region_type ort, else if (OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (oc)) OMP_CLAUSE_LINEAR_STEP (nc) = tsubst_omp_clause_decl (OMP_CLAUSE_LINEAR_STEP (oc), args, - complain, in_decl); + complain, in_decl, NULL); else OMP_CLAUSE_LINEAR_STEP (nc) = tsubst_expr (OMP_CLAUSE_LINEAR_STEP (oc), args, complain, @@ -16289,6 +16331,8 @@ tsubst_omp_clauses (tree clauses, enum c_omp_region_type ort, case OMP_CLAUSE_COPYPRIVATE: case OMP_CLAUSE_LINEAR: case OMP_CLAUSE_REDUCTION: + case OMP_CLAUSE_IN_REDUCTION: + case OMP_CLAUSE_TASK_REDUCTION: case OMP_CLAUSE_USE_DEVICE_PTR: case OMP_CLAUSE_IS_DEVICE_PTR: /* tsubst_expr on SCOPE_REF results in returning @@ -16403,10 +16447,13 @@ tsubst_copy_asm_operands (tree t, tree args, tsubst_flags_t complain, static tree *omp_parallel_combined_clauses; +static tree tsubst_decomp_names (tree, tree, tree, tsubst_flags_t, tree, + tree *, unsigned int *); + /* Substitute one OMP_FOR iterator. */ -static void -tsubst_omp_for_iterator (tree t, int i, tree declv, tree orig_declv, +static bool +tsubst_omp_for_iterator (tree t, int i, tree declv, tree &orig_declv, tree initv, tree condv, tree incrv, tree *clauses, tree args, tsubst_flags_t complain, tree in_decl, bool integral_constant_expression_p) @@ -16414,26 +16461,56 @@ tsubst_omp_for_iterator (tree t, int i, tree declv, tree orig_declv, #define RECUR(NODE) \ tsubst_expr ((NODE), args, complain, in_decl, \ integral_constant_expression_p) - tree decl, init, cond, incr; + tree decl, init, cond = NULL_TREE, incr = NULL_TREE; + bool ret = false; init = TREE_VEC_ELT (OMP_FOR_INIT (t), i); gcc_assert (TREE_CODE (init) == MODIFY_EXPR); - if (orig_declv && OMP_FOR_ORIG_DECLS (t)) - { - tree o = TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (t), i); - if (TREE_CODE (o) == TREE_LIST) - TREE_VEC_ELT (orig_declv, i) - = tree_cons (RECUR (TREE_PURPOSE (o)), - RECUR (TREE_VALUE (o)), NULL_TREE); - else - TREE_VEC_ELT (orig_declv, i) = RECUR (o); - } - decl = TREE_OPERAND (init, 0); init = TREE_OPERAND (init, 1); tree decl_expr = NULL_TREE; - if (init && TREE_CODE (init) == DECL_EXPR) + bool range_for = TREE_VEC_ELT (OMP_FOR_COND (t), i) == global_namespace; + if (range_for) + { + bool decomp = false; + if (decl != error_mark_node && DECL_HAS_VALUE_EXPR_P (decl)) + { + tree v = DECL_VALUE_EXPR (decl); + if (TREE_CODE (v) == ARRAY_REF + && VAR_P (TREE_OPERAND (v, 0)) + && DECL_DECOMPOSITION_P (TREE_OPERAND (v, 0))) + { + tree decomp_first = NULL_TREE; + unsigned decomp_cnt = 0; + tree d = tsubst_decl (TREE_OPERAND (v, 0), args, complain); + maybe_push_decl (d); + d = tsubst_decomp_names (d, TREE_OPERAND (v, 0), args, complain, + in_decl, &decomp_first, &decomp_cnt); + decomp = true; + if (d == error_mark_node) + decl = error_mark_node; + else + for (unsigned int i = 0; i < decomp_cnt; i++) + { + if (!DECL_HAS_VALUE_EXPR_P (decomp_first)) + { + tree v = build_nt (ARRAY_REF, d, + size_int (decomp_cnt - i - 1), + NULL_TREE, NULL_TREE); + SET_DECL_VALUE_EXPR (decomp_first, v); + DECL_HAS_VALUE_EXPR_P (decomp_first) = 1; + } + fit_decomposition_lang_decl (decomp_first, d); + decomp_first = DECL_CHAIN (decomp_first); + } + } + } + decl = tsubst_decl (decl, args, complain); + if (!decomp) + maybe_push_decl (decl); + } + else if (init && TREE_CODE (init) == DECL_EXPR) { /* We need to jump through some hoops to handle declarations in the init-statement, since we might need to handle auto deduction, @@ -16480,14 +16557,44 @@ tsubst_omp_for_iterator (tree t, int i, tree declv, tree orig_declv, } init = RECUR (init); + if (orig_declv && OMP_FOR_ORIG_DECLS (t)) + { + tree o = TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (t), i); + if (TREE_CODE (o) == TREE_LIST) + TREE_VEC_ELT (orig_declv, i) + = tree_cons (RECUR (TREE_PURPOSE (o)), + RECUR (TREE_VALUE (o)), + NULL_TREE); + else + TREE_VEC_ELT (orig_declv, i) = RECUR (o); + } + + if (range_for) + { + tree this_pre_body = NULL_TREE; + tree orig_init = NULL_TREE; + tree orig_decl = NULL_TREE; + cp_convert_omp_range_for (this_pre_body, NULL, decl, orig_decl, init, + orig_init, cond, incr); + if (orig_decl) + { + if (orig_declv == NULL_TREE) + orig_declv = copy_node (declv); + TREE_VEC_ELT (orig_declv, i) = orig_decl; + ret = true; + } + else if (orig_declv) + TREE_VEC_ELT (orig_declv, i) = decl; + } + tree auto_node = type_uses_auto (TREE_TYPE (decl)); - if (auto_node && init) + if (!range_for && auto_node && init) TREE_TYPE (decl) = do_auto_deduction (TREE_TYPE (decl), init, auto_node, complain); gcc_assert (!type_dependent_expression_p (decl)); - if (!CLASS_TYPE_P (TREE_TYPE (decl))) + if (!CLASS_TYPE_P (TREE_TYPE (decl)) || range_for) { if (decl_expr) { @@ -16498,22 +16605,27 @@ tsubst_omp_for_iterator (tree t, int i, tree declv, tree orig_declv, DECL_INITIAL (DECL_EXPR_DECL (decl_expr)) = init_sav; } - cond = RECUR (TREE_VEC_ELT (OMP_FOR_COND (t), i)); - incr = TREE_VEC_ELT (OMP_FOR_INCR (t), i); - if (TREE_CODE (incr) == MODIFY_EXPR) + if (!range_for) { - tree lhs = RECUR (TREE_OPERAND (incr, 0)); - tree rhs = RECUR (TREE_OPERAND (incr, 1)); - incr = build_x_modify_expr (EXPR_LOCATION (incr), lhs, - NOP_EXPR, rhs, complain); + cond = RECUR (TREE_VEC_ELT (OMP_FOR_COND (t), i)); + incr = TREE_VEC_ELT (OMP_FOR_INCR (t), i); + if (TREE_CODE (incr) == MODIFY_EXPR) + { + tree lhs = RECUR (TREE_OPERAND (incr, 0)); + tree rhs = RECUR (TREE_OPERAND (incr, 1)); + incr = build_x_modify_expr (EXPR_LOCATION (incr), lhs, + NOP_EXPR, rhs, complain); + } + else + incr = RECUR (incr); + if (orig_declv && !OMP_FOR_ORIG_DECLS (t)) + TREE_VEC_ELT (orig_declv, i) = decl; } - else - incr = RECUR (incr); TREE_VEC_ELT (declv, i) = decl; TREE_VEC_ELT (initv, i) = init; TREE_VEC_ELT (condv, i) = cond; TREE_VEC_ELT (incrv, i) = incr; - return; + return ret; } if (decl_expr) @@ -16640,10 +16752,13 @@ tsubst_omp_for_iterator (tree t, int i, tree declv, tree orig_declv, break; } + if (orig_declv && !OMP_FOR_ORIG_DECLS (t)) + TREE_VEC_ELT (orig_declv, i) = decl; TREE_VEC_ELT (declv, i) = decl; TREE_VEC_ELT (initv, i) = init; TREE_VEC_ELT (condv, i) = cond; TREE_VEC_ELT (incrv, i) = incr; + return false; #undef RECUR } @@ -17254,6 +17369,15 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl, break; case OMP_TASK: + if (OMP_TASK_BODY (t) == NULL_TREE) + { + tmp = tsubst_omp_clauses (OMP_TASK_CLAUSES (t), C_ORT_OMP, args, + complain, in_decl); + t = copy_node (t); + OMP_TASK_CLAUSES (t) = tmp; + add_stmt (t); + break; + } r = push_omp_privatization_clauses (false); tmp = tsubst_omp_clauses (OMP_TASK_CLAUSES (t), C_ORT_OMP, args, complain, in_decl); @@ -17274,6 +17398,7 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl, tree orig_declv = NULL_TREE; tree incrv = NULL_TREE; enum c_omp_region_type ort = C_ORT_OMP; + bool any_range_for = false; int i; if (TREE_CODE (t) == OACC_LOOP) @@ -17292,6 +17417,7 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl, incrv = make_tree_vec (TREE_VEC_LENGTH (OMP_FOR_INIT (t))); } + keep_next_level (true); stmt = begin_omp_structured_block (); pre_body = push_stmt_list (); @@ -17300,14 +17426,31 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl, if (OMP_FOR_INIT (t) != NULL_TREE) for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (t)); i++) - tsubst_omp_for_iterator (t, i, declv, orig_declv, initv, condv, - incrv, &clauses, args, complain, in_decl, - integral_constant_expression_p); + any_range_for + |= tsubst_omp_for_iterator (t, i, declv, orig_declv, initv, + condv, incrv, &clauses, args, + complain, in_decl, + integral_constant_expression_p); omp_parallel_combined_clauses = NULL; - body = push_stmt_list (); + if (any_range_for) + { + gcc_assert (orig_declv); + body = begin_omp_structured_block (); + for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (t)); i++) + if (TREE_VEC_ELT (orig_declv, i) != TREE_VEC_ELT (declv, i) + && TREE_CODE (TREE_VEC_ELT (orig_declv, i)) == TREE_LIST + && TREE_CHAIN (TREE_VEC_ELT (orig_declv, i))) + cp_finish_omp_range_for (TREE_VEC_ELT (orig_declv, i), + TREE_VEC_ELT (declv, i)); + } + else + body = push_stmt_list (); RECUR (OMP_FOR_BODY (t)); - body = pop_stmt_list (body); + if (any_range_for) + body = finish_omp_structured_block (body); + else + body = pop_stmt_list (body); if (OMP_FOR_INIT (t) != NULL_TREE) t = finish_omp_for (EXPR_LOCATION (t), TREE_CODE (t), declv, @@ -17324,7 +17467,8 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl, add_stmt (t); } - add_stmt (finish_omp_structured_block (stmt)); + add_stmt (finish_omp_for_block (finish_omp_structured_block (stmt), + t)); pop_omp_privatization_clauses (r); } break; @@ -17335,13 +17479,24 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl, case OMP_SINGLE: case OMP_TEAMS: case OMP_CRITICAL: + case OMP_TASKGROUP: r = push_omp_privatization_clauses (TREE_CODE (t) == OMP_TEAMS && OMP_TEAMS_COMBINED (t)); tmp = tsubst_omp_clauses (OMP_CLAUSES (t), C_ORT_OMP, args, complain, in_decl); - stmt = push_stmt_list (); - RECUR (OMP_BODY (t)); - stmt = pop_stmt_list (stmt); + if (TREE_CODE (t) == OMP_TEAMS) + { + keep_next_level (true); + stmt = begin_omp_structured_block (); + RECUR (OMP_BODY (t)); + stmt = finish_omp_structured_block (stmt); + } + else + { + stmt = push_stmt_list (); + RECUR (OMP_BODY (t)); + stmt = pop_stmt_list (stmt); + } t = copy_node (t); OMP_BODY (t) = stmt; @@ -17350,6 +17505,32 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl, pop_omp_privatization_clauses (r); break; + case OMP_DEPOBJ: + r = RECUR (OMP_DEPOBJ_DEPOBJ (t)); + if (OMP_DEPOBJ_CLAUSES (t) && OMP_DEPOBJ_CLAUSES (t) != error_mark_node) + { + enum omp_clause_depend_kind kind = OMP_CLAUSE_DEPEND_SOURCE; + if (TREE_CODE (OMP_DEPOBJ_CLAUSES (t)) == OMP_CLAUSE) + { + tmp = tsubst_omp_clauses (OMP_DEPOBJ_CLAUSES (t), C_ORT_OMP, + args, complain, in_decl); + if (tmp == NULL_TREE) + tmp = error_mark_node; + } + else + { + kind = (enum omp_clause_depend_kind) + tree_to_uhwi (OMP_DEPOBJ_CLAUSES (t)); + tmp = NULL_TREE; + } + finish_omp_depobj (EXPR_LOCATION (t), r, kind, tmp); + } + else + finish_omp_depobj (EXPR_LOCATION (t), r, + OMP_CLAUSE_DEPEND_SOURCE, + OMP_DEPOBJ_CLAUSES (t)); + break; + case OACC_DATA: case OMP_TARGET_DATA: case OMP_TARGET: @@ -17441,7 +17622,6 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl, case OMP_SECTION: case OMP_MASTER: - case OMP_TASKGROUP: stmt = push_stmt_list (); RECUR (OMP_BODY (t)); stmt = pop_stmt_list (stmt); @@ -17453,6 +17633,10 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl, case OMP_ATOMIC: gcc_assert (OMP_ATOMIC_DEPENDENT_P (t)); + tmp = NULL_TREE; + if (TREE_CODE (TREE_OPERAND (t, 0)) == OMP_CLAUSE) + tmp = tsubst_omp_clauses (TREE_OPERAND (t, 0), C_ORT_OMP, args, + complain, in_decl); if (TREE_CODE (TREE_OPERAND (t, 1)) != MODIFY_EXPR) { tree op1 = TREE_OPERAND (t, 1); @@ -17465,9 +17649,9 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl, } lhs = RECUR (TREE_OPERAND (op1, 0)); rhs = RECUR (TREE_OPERAND (op1, 1)); - finish_omp_atomic (OMP_ATOMIC, TREE_CODE (op1), lhs, rhs, - NULL_TREE, NULL_TREE, rhs1, - OMP_ATOMIC_SEQ_CST (t)); + finish_omp_atomic (EXPR_LOCATION (t), OMP_ATOMIC, TREE_CODE (op1), + lhs, rhs, NULL_TREE, NULL_TREE, rhs1, tmp, + OMP_ATOMIC_MEMORY_ORDER (t)); } else { @@ -17504,8 +17688,8 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl, lhs = RECUR (TREE_OPERAND (op1, 0)); rhs = RECUR (TREE_OPERAND (op1, 1)); } - finish_omp_atomic (code, opcode, lhs, rhs, v, lhs1, rhs1, - OMP_ATOMIC_SEQ_CST (t)); + finish_omp_atomic (EXPR_LOCATION (t), code, opcode, lhs, rhs, v, + lhs1, rhs1, tmp, OMP_ATOMIC_MEMORY_ORDER (t)); } break; @@ -25865,6 +26049,9 @@ dependent_omp_for_p (tree declv, tree initv, tree condv, tree incrv) if (init && type_dependent_expression_p (init)) return true; + if (cond == global_namespace) + return true; + if (type_dependent_expression_p (cond)) return true; @@ -25891,6 +26078,20 @@ dependent_omp_for_p (tree declv, tree initv, tree condv, tree incrv) if (type_dependent_expression_p (TREE_OPERAND (t, 0)) || type_dependent_expression_p (TREE_OPERAND (t, 1))) return true; + + /* If this loop has a class iterator with != comparison + with increment other than i++/++i/i--/--i, make sure the + increment is constant. */ + if (CLASS_TYPE_P (TREE_TYPE (decl)) + && TREE_CODE (cond) == NE_EXPR) + { + if (TREE_OPERAND (t, 0) == decl) + t = TREE_OPERAND (t, 1); + else + t = TREE_OPERAND (t, 0); + if (TREE_CODE (t) != INTEGER_CST) + return true; + } } } } diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index b54ecb0..182d360 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -44,6 +44,7 @@ along with GCC; see the file COPYING3. If not see #include "attribs.h" #include "gomp-constants.h" #include "predict.h" +#include "memmodel.h" /* There routines provide a modular interface to perform many parsing operations. They may therefore be used during actual parsing, or @@ -4634,7 +4635,9 @@ handle_omp_array_sections_1 (tree c, tree t, vec<tree> &types, } if (ort == C_ORT_OMP - && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION + && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION + || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION + || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION) && TREE_CODE (TREE_CHAIN (t)) == FIELD_DECL) TREE_CHAIN (t) = omp_privatize_field (TREE_CHAIN (t), false); ret = handle_omp_array_sections_1 (c, TREE_CHAIN (t), types, @@ -4693,7 +4696,9 @@ handle_omp_array_sections_1 (tree c, tree t, vec<tree> &types, if (!integer_nonzerop (length)) { if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND - || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION) + || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION + || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION + || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION) { if (integer_zerop (length)) { @@ -4759,7 +4764,9 @@ handle_omp_array_sections_1 (tree c, tree t, vec<tree> &types, if (tree_int_cst_equal (size, low_bound)) { if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND - || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION) + || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION + || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION + || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION) { error_at (OMP_CLAUSE_LOCATION (c), "zero length array section in %qs clause", @@ -4778,7 +4785,9 @@ handle_omp_array_sections_1 (tree c, tree t, vec<tree> &types, else if (length == NULL_TREE) { if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND - && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION) + && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION + && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION + && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION) maybe_zero_len = true; if (first_non_one == types.length ()) first_non_one++; @@ -4814,7 +4823,9 @@ handle_omp_array_sections_1 (tree c, tree t, vec<tree> &types, else if (length == NULL_TREE) { if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND - && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION) + && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION + && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION + && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION) maybe_zero_len = true; if (first_non_one == types.length ()) first_non_one++; @@ -4886,7 +4897,13 @@ handle_omp_array_sections (tree c, enum c_omp_region_type ort) bool maybe_zero_len = false; unsigned int first_non_one = 0; auto_vec<tree, 10> types; - tree first = handle_omp_array_sections_1 (c, OMP_CLAUSE_DECL (c), types, + tree *tp = &OMP_CLAUSE_DECL (c); + if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND + && TREE_CODE (*tp) == TREE_LIST + && TREE_PURPOSE (*tp) + && TREE_CODE (TREE_PURPOSE (*tp)) == TREE_VEC) + tp = &TREE_VALUE (*tp); + tree first = handle_omp_array_sections_1 (c, *tp, types, maybe_zero_len, first_non_one, ort); if (first == error_mark_node) @@ -4895,7 +4912,7 @@ handle_omp_array_sections (tree c, enum c_omp_region_type ort) return false; if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND) { - tree t = OMP_CLAUSE_DECL (c); + tree t = *tp; tree tem = NULL_TREE; if (processing_template_decl) return false; @@ -4915,7 +4932,7 @@ handle_omp_array_sections (tree c, enum c_omp_region_type ort) } if (tem) first = build2 (COMPOUND_EXPR, TREE_TYPE (first), tem, first); - OMP_CLAUSE_DECL (c) = first; + *tp = first; } else { @@ -4992,7 +5009,9 @@ handle_omp_array_sections (tree c, enum c_omp_region_type ort) if (i > first_non_one && ((length && integer_nonzerop (length)) - || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)) + || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION + || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION + || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)) continue; if (length) l = fold_convert (sizetype, length); @@ -5020,7 +5039,9 @@ handle_omp_array_sections (tree c, enum c_omp_region_type ort) tree eltype = TREE_TYPE (types[num - 1]); while (TREE_CODE (eltype) == ARRAY_TYPE) eltype = TREE_TYPE (eltype); - if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION) + if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION + || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION + || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION) size = size_binop (EXACT_DIV_EXPR, size, size_in_bytes (eltype)); size = size_binop (MULT_EXPR, size, l); @@ -5036,9 +5057,12 @@ handle_omp_array_sections (tree c, enum c_omp_region_type ort) { if (side_effects) size = build2 (COMPOUND_EXPR, sizetype, side_effects, size); - if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION) + if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION + || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION + || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION) { size = size_binop (MINUS_EXPR, size, size_one_node); + size = save_expr (size); tree index_type = build_index_type (size); tree eltype = TREE_TYPE (first); while (TREE_CODE (eltype) == ARRAY_TYPE) @@ -5576,11 +5600,13 @@ finish_omp_reduction_clause (tree c, bool *need_default_ctor, bool *need_dtor) TYPE_SIZE_UNIT (type)); if (integer_zerop (size)) { - error ("%qE in %<reduction%> clause is a zero size array", - omp_clause_printable_decl (t)); + error_at (OMP_CLAUSE_LOCATION (c), + "%qE in %<reduction%> clause is a zero size array", + omp_clause_printable_decl (t)); return true; } size = size_binop (MINUS_EXPR, size, size_one_node); + size = save_expr (size); tree index_type = build_index_type (size); tree atype = build_array_type (type, index_type); tree ptype = build_pointer_type (type); @@ -5624,8 +5650,9 @@ finish_omp_reduction_clause (tree c, bool *need_default_ctor, bool *need_dtor) } else if (TYPE_READONLY (type)) { - error ("%qE has const type for %<reduction%>", - omp_clause_printable_decl (t)); + error_at (OMP_CLAUSE_LOCATION (c), + "%qE has const type for %<reduction%>", + omp_clause_printable_decl (t)); return true; } else if (!processing_template_decl) @@ -5699,7 +5726,8 @@ finish_omp_reduction_clause (tree c, bool *need_default_ctor, bool *need_dtor) if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[0]))) cxx_mark_addressable (placeholder); if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[1])) - && !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c)))) + && (decl_placeholder + || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c))))) cxx_mark_addressable (decl_placeholder ? decl_placeholder : OMP_CLAUSE_DECL (c)); tree omp_out = placeholder; @@ -5725,7 +5753,9 @@ finish_omp_reduction_clause (tree c, bool *need_default_ctor, bool *need_dtor) { gcc_assert (TREE_CODE (stmts[3]) == DECL_EXPR && TREE_CODE (stmts[4]) == DECL_EXPR); - if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[3]))) + if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[3])) + && (decl_placeholder + || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c))))) cxx_mark_addressable (decl_placeholder ? decl_placeholder : OMP_CLAUSE_DECL (c)); if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[4]))) @@ -5786,8 +5816,9 @@ finish_omp_reduction_clause (tree c, bool *need_default_ctor, bool *need_dtor) *need_dtor = true; else { - error ("user defined reduction not found for %qE", - omp_clause_printable_decl (t)); + error_at (OMP_CLAUSE_LOCATION (c), + "user defined reduction not found for %qE", + omp_clause_printable_decl (t)); return true; } if (TREE_CODE (OMP_CLAUSE_DECL (c)) == MEM_REF) @@ -5868,6 +5899,155 @@ cp_finish_omp_clause_depend_sink (tree sink_clause) return false; } +/* Finish OpenMP iterators ITER. Return true if they are errorneous + and clauses containing them should be removed. */ + +static bool +cp_omp_finish_iterators (tree iter) +{ + bool ret = false; + for (tree it = iter; it; it = TREE_CHAIN (it)) + { + tree var = TREE_VEC_ELT (it, 0); + tree begin = TREE_VEC_ELT (it, 1); + tree end = TREE_VEC_ELT (it, 2); + tree step = TREE_VEC_ELT (it, 3); + tree orig_step; + tree type = TREE_TYPE (var); + location_t loc = DECL_SOURCE_LOCATION (var); + if (type == error_mark_node) + { + ret = true; + continue; + } + if (type_dependent_expression_p (var)) + continue; + if (!INTEGRAL_TYPE_P (type) && !POINTER_TYPE_P (type)) + { + error_at (loc, "iterator %qD has neither integral nor pointer type", + var); + ret = true; + continue; + } + else if (TYPE_READONLY (type)) + { + error_at (loc, "iterator %qD has const qualified type", var); + ret = true; + continue; + } + if (type_dependent_expression_p (begin) + || type_dependent_expression_p (end) + || type_dependent_expression_p (step)) + continue; + else if (error_operand_p (step)) + { + ret = true; + continue; + } + else if (!INTEGRAL_TYPE_P (TREE_TYPE (step))) + { + error_at (EXPR_LOC_OR_LOC (step, loc), + "iterator step with non-integral type"); + ret = true; + continue; + } + + begin = mark_rvalue_use (begin); + end = mark_rvalue_use (end); + step = mark_rvalue_use (step); + begin = cp_build_c_cast (type, begin, tf_warning_or_error); + end = cp_build_c_cast (type, end, tf_warning_or_error); + orig_step = step; + if (!processing_template_decl) + step = orig_step = save_expr (step); + tree stype = POINTER_TYPE_P (type) ? sizetype : type; + step = cp_build_c_cast (stype, step, tf_warning_or_error); + if (POINTER_TYPE_P (type) && !processing_template_decl) + { + begin = save_expr (begin); + step = pointer_int_sum (loc, PLUS_EXPR, begin, step); + step = fold_build2_loc (loc, MINUS_EXPR, sizetype, + fold_convert (sizetype, step), + fold_convert (sizetype, begin)); + step = fold_convert (ssizetype, step); + } + if (!processing_template_decl) + { + begin = maybe_constant_value (begin); + end = maybe_constant_value (end); + step = maybe_constant_value (step); + orig_step = maybe_constant_value (orig_step); + } + if (integer_zerop (step)) + { + error_at (loc, "iterator %qD has zero step", var); + ret = true; + continue; + } + + if (begin == error_mark_node + || end == error_mark_node + || step == error_mark_node + || orig_step == error_mark_node) + { + ret = true; + continue; + } + + if (!processing_template_decl) + { + begin = fold_build_cleanup_point_expr (TREE_TYPE (begin), begin); + end = fold_build_cleanup_point_expr (TREE_TYPE (end), end); + step = fold_build_cleanup_point_expr (TREE_TYPE (step), step); + orig_step = fold_build_cleanup_point_expr (TREE_TYPE (orig_step), + orig_step); + } + hash_set<tree> pset; + tree it2; + for (it2 = TREE_CHAIN (it); it2; it2 = TREE_CHAIN (it2)) + { + tree var2 = TREE_VEC_ELT (it2, 0); + tree begin2 = TREE_VEC_ELT (it2, 1); + tree end2 = TREE_VEC_ELT (it2, 2); + tree step2 = TREE_VEC_ELT (it2, 3); + location_t loc2 = DECL_SOURCE_LOCATION (var2); + if (cp_walk_tree (&begin2, find_omp_placeholder_r, var, &pset)) + { + error_at (EXPR_LOC_OR_LOC (begin2, loc2), + "begin expression refers to outer iterator %qD", var); + break; + } + else if (cp_walk_tree (&end2, find_omp_placeholder_r, var, &pset)) + { + error_at (EXPR_LOC_OR_LOC (end2, loc2), + "end expression refers to outer iterator %qD", var); + break; + } + else if (cp_walk_tree (&step2, find_omp_placeholder_r, var, &pset)) + { + error_at (EXPR_LOC_OR_LOC (step2, loc2), + "step expression refers to outer iterator %qD", var); + break; + } + } + if (it2) + { + ret = true; + continue; + } + TREE_VEC_ELT (it, 1) = begin; + TREE_VEC_ELT (it, 2) = end; + if (processing_template_decl) + TREE_VEC_ELT (it, 3) = orig_step; + else + { + TREE_VEC_ELT (it, 3) = step; + TREE_VEC_ELT (it, 4) = orig_step; + } + } + return ret; +} + /* For all elements of CLAUSES, validate them vs OpenMP constraints. Remove any elements from the list that are invalid. */ @@ -5882,14 +6062,19 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) bool copyprivate_seen = false; bool ordered_seen = false; bool oacc_async = false; + tree last_iterators = NULL_TREE; + bool last_iterators_remove = false; + bool reduction_seen = false; bitmap_obstack_initialize (NULL); bitmap_initialize (&generic_head, &bitmap_default_obstack); bitmap_initialize (&firstprivate_head, &bitmap_default_obstack); bitmap_initialize (&lastprivate_head, &bitmap_default_obstack); bitmap_initialize (&aligned_head, &bitmap_default_obstack); + /* If ort == C_ORT_OMP_DECLARE_SIMD used as uniform_head instead. */ bitmap_initialize (&map_head, &bitmap_default_obstack); bitmap_initialize (&map_field_head, &bitmap_default_obstack); + /* If ort == C_ORT_OMP used as nontemporal_head instead. */ bitmap_initialize (&oacc_reduction_head, &bitmap_default_obstack); if (ort & C_ORT_ACC) @@ -5914,6 +6099,10 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP); goto check_dup_generic; case OMP_CLAUSE_REDUCTION: + reduction_seen = true; + /* FALLTHRU */ + case OMP_CLAUSE_IN_REDUCTION: + case OMP_CLAUSE_TASK_REDUCTION: field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP); t = OMP_CLAUSE_DECL (c); if (TREE_CODE (t) == TREE_LIST) @@ -5971,10 +6160,11 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) || OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_UVAL) && !TYPE_REF_P (type)) { - error ("linear clause with %qs modifier applied to " - "non-reference variable with %qT type", - OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF - ? "ref" : "uval", TREE_TYPE (t)); + error_at (OMP_CLAUSE_LOCATION (c), + "linear clause with %qs modifier applied to " + "non-reference variable with %qT type", + OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF + ? "ref" : "uval", TREE_TYPE (t)); remove = true; break; } @@ -5985,8 +6175,10 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) if (!INTEGRAL_TYPE_P (type) && !TYPE_PTR_P (type)) { - error ("linear clause applied to non-integral non-pointer" - " variable with %qT type", TREE_TYPE (t)); + error_at (OMP_CLAUSE_LOCATION (c), + "linear clause applied to non-integral " + "non-pointer variable with %qT type", + TREE_TYPE (t)); remove = true; break; } @@ -6007,7 +6199,8 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) || !TYPE_REF_P (TREE_TYPE (t)) || !INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (t))))) { - error ("linear step expression must be integral"); + error_at (OMP_CLAUSE_LOCATION (c), + "linear step expression must be integral"); remove = true; break; } @@ -6099,8 +6292,9 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) || (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_LINEAR && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_UNIFORM))) { - error ("%<this%> allowed in OpenMP only in %<declare simd%>" - " clauses"); + error_at (OMP_CLAUSE_LOCATION (c), + "%<this%> allowed in OpenMP only in %<declare simd%>" + " clauses"); remove = true; break; } @@ -6110,11 +6304,13 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) if (processing_template_decl && TREE_CODE (t) != OVERLOAD) break; if (DECL_P (t)) - error ("%qD is not a variable in clause %qs", t, - omp_clause_code_name[OMP_CLAUSE_CODE (c)]); + error_at (OMP_CLAUSE_LOCATION (c), + "%qD is not a variable in clause %qs", t, + omp_clause_code_name[OMP_CLAUSE_CODE (c)]); else - error ("%qE is not a variable in clause %qs", t, - omp_clause_code_name[OMP_CLAUSE_CODE (c)]); + error_at (OMP_CLAUSE_LOCATION (c), + "%qE is not a variable in clause %qs", t, + omp_clause_code_name[OMP_CLAUSE_CODE (c)]); remove = true; } else if (ort == C_ORT_ACC @@ -6122,7 +6318,9 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) { if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t))) { - error ("%qD appears more than once in reduction clauses", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qD appears more than once in reduction clauses", + t); remove = true; } else @@ -6132,16 +6330,19 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) || bitmap_bit_p (&firstprivate_head, DECL_UID (t)) || bitmap_bit_p (&lastprivate_head, DECL_UID (t))) { - error ("%qD appears more than once in data clauses", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qD appears more than once in data clauses", t); remove = true; } else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE && bitmap_bit_p (&map_head, DECL_UID (t))) { if (ort == C_ORT_ACC) - error ("%qD appears more than once in data clauses", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qD appears more than once in data clauses", t); else - error ("%qD appears both in data and map clauses", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qD appears both in data and map clauses", t); remove = true; } else @@ -6170,8 +6371,9 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) t = OMP_CLAUSE_DECL (c); if (ort != C_ORT_ACC && t == current_class_ptr) { - error ("%<this%> allowed in OpenMP only in %<declare simd%>" - " clauses"); + error_at (OMP_CLAUSE_LOCATION (c), + "%<this%> allowed in OpenMP only in %<declare simd%>" + " clauses"); remove = true; break; } @@ -6182,23 +6384,30 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) if (processing_template_decl && TREE_CODE (t) != OVERLOAD) break; if (DECL_P (t)) - error ("%qD is not a variable in clause %<firstprivate%>", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qD is not a variable in clause %<firstprivate%>", + t); else - error ("%qE is not a variable in clause %<firstprivate%>", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qE is not a variable in clause %<firstprivate%>", + t); remove = true; } else if (bitmap_bit_p (&generic_head, DECL_UID (t)) || bitmap_bit_p (&firstprivate_head, DECL_UID (t))) { - error ("%qD appears more than once in data clauses", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qD appears more than once in data clauses", t); remove = true; } else if (bitmap_bit_p (&map_head, DECL_UID (t))) { if (ort == C_ORT_ACC) - error ("%qD appears more than once in data clauses", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qD appears more than once in data clauses", t); else - error ("%qD appears both in data and map clauses", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qD appears both in data and map clauses", t); remove = true; } else @@ -6213,8 +6422,9 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) t = OMP_CLAUSE_DECL (c); if (t == current_class_ptr) { - error ("%<this%> allowed in OpenMP only in %<declare simd%>" - " clauses"); + error_at (OMP_CLAUSE_LOCATION (c), + "%<this%> allowed in OpenMP only in %<declare simd%>" + " clauses"); remove = true; break; } @@ -6225,15 +6435,20 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) if (processing_template_decl && TREE_CODE (t) != OVERLOAD) break; if (DECL_P (t)) - error ("%qD is not a variable in clause %<lastprivate%>", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qD is not a variable in clause %<lastprivate%>", + t); else - error ("%qE is not a variable in clause %<lastprivate%>", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qE is not a variable in clause %<lastprivate%>", + t); remove = true; } else if (bitmap_bit_p (&generic_head, DECL_UID (t)) || bitmap_bit_p (&lastprivate_head, DECL_UID (t))) { - error ("%qD appears more than once in data clauses", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qD appears more than once in data clauses", t); remove = true; } else @@ -6270,7 +6485,8 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) else if (!type_dependent_expression_p (t) && !INTEGRAL_TYPE_P (TREE_TYPE (t))) { - error ("%<gang%> static expression must be integral"); + error_at (OMP_CLAUSE_LOCATION (c), + "%<gang%> static expression must be integral"); remove = true; } else @@ -6374,30 +6590,6 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) break; case OMP_CLAUSE_SCHEDULE: - if (OMP_CLAUSE_SCHEDULE_KIND (c) & OMP_CLAUSE_SCHEDULE_NONMONOTONIC) - { - const char *p = NULL; - switch (OMP_CLAUSE_SCHEDULE_KIND (c) & OMP_CLAUSE_SCHEDULE_MASK) - { - case OMP_CLAUSE_SCHEDULE_STATIC: p = "static"; break; - case OMP_CLAUSE_SCHEDULE_DYNAMIC: break; - case OMP_CLAUSE_SCHEDULE_GUIDED: break; - case OMP_CLAUSE_SCHEDULE_AUTO: p = "auto"; break; - case OMP_CLAUSE_SCHEDULE_RUNTIME: p = "runtime"; break; - default: gcc_unreachable (); - } - if (p) - { - error_at (OMP_CLAUSE_LOCATION (c), - "%<nonmonotonic%> modifier specified for %qs " - "schedule kind", p); - OMP_CLAUSE_SCHEDULE_KIND (c) - = (enum omp_clause_schedule_kind) - (OMP_CLAUSE_SCHEDULE_KIND (c) - & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC); - } - } - t = OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c); if (t == NULL) ; @@ -6406,7 +6598,8 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) else if (!type_dependent_expression_p (t) && !INTEGRAL_TYPE_P (TREE_TYPE (t))) { - error ("schedule chunk size expression must be integral"); + error_at (OMP_CLAUSE_LOCATION (c), + "schedule chunk size expression must be integral"); remove = true; } else @@ -6436,8 +6629,9 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) else if (!type_dependent_expression_p (t) && !INTEGRAL_TYPE_P (TREE_TYPE (t))) { - error ("%qs length expression must be integral", - omp_clause_code_name[OMP_CLAUSE_CODE (c)]); + error_at (OMP_CLAUSE_LOCATION (c), + "%qs length expression must be integral", + omp_clause_code_name[OMP_CLAUSE_CODE (c)]); remove = true; } else @@ -6449,9 +6643,10 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) if (TREE_CODE (t) != INTEGER_CST || tree_int_cst_sgn (t) != 1) { - error ("%qs length expression must be positive constant" - " integer expression", - omp_clause_code_name[OMP_CLAUSE_CODE (c)]); + error_at (OMP_CLAUSE_LOCATION (c), + "%qs length expression must be positive " + "constant integer expression", + omp_clause_code_name[OMP_CLAUSE_CODE (c)]); remove = true; } } @@ -6468,7 +6663,8 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) else if (!type_dependent_expression_p (t) && !INTEGRAL_TYPE_P (TREE_TYPE (t))) { - error ("%<async%> expression must be integral"); + error_at (OMP_CLAUSE_LOCATION (c), + "%<async%> expression must be integral"); remove = true; } else @@ -6496,7 +6692,8 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) else if (!type_dependent_expression_p (t) && !INTEGRAL_TYPE_P (TREE_TYPE (t))) { - error ("%<thread_limit%> expression must be integral"); + error_at (OMP_CLAUSE_LOCATION (c), + "%<thread_limit%> expression must be integral"); remove = true; } else @@ -6525,7 +6722,8 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) else if (!type_dependent_expression_p (t) && !INTEGRAL_TYPE_P (TREE_TYPE (t))) { - error ("%<device%> id must be integral"); + error_at (OMP_CLAUSE_LOCATION (c), + "%<device%> id must be integral"); remove = true; } else @@ -6546,14 +6744,15 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) else if (!type_dependent_expression_p (t) && !INTEGRAL_TYPE_P (TREE_TYPE (t))) { - error ("%<dist_schedule%> chunk size expression must be " - "integral"); + error_at (OMP_CLAUSE_LOCATION (c), + "%<dist_schedule%> chunk size expression must be " + "integral"); remove = true; } else { t = mark_rvalue_use (t); - if (!processing_template_decl) + if (!processing_template_decl) t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c) = t; } @@ -6563,8 +6762,9 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) t = OMP_CLAUSE_DECL (c); if (t == current_class_ptr && ort != C_ORT_OMP_DECLARE_SIMD) { - error ("%<this%> allowed in OpenMP only in %<declare simd%>" - " clauses"); + error_at (OMP_CLAUSE_LOCATION (c), + "%<this%> allowed in OpenMP only in %<declare simd%>" + " clauses"); remove = true; break; } @@ -6573,9 +6773,11 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) if (processing_template_decl && TREE_CODE (t) != OVERLOAD) break; if (DECL_P (t)) - error ("%qD is not a variable in %<aligned%> clause", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qD is not a variable in %<aligned%> clause", t); else - error ("%qE is not a variable in %<aligned%> clause", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qE is not a variable in %<aligned%> clause", t); remove = true; } else if (!type_dependent_expression_p (t) @@ -6593,7 +6795,9 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) } else if (bitmap_bit_p (&aligned_head, DECL_UID (t))) { - error ("%qD appears more than once in %<aligned%> clauses", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qD appears more than once in %<aligned%> clauses", + t); remove = true; } else @@ -6606,8 +6810,9 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) else if (!type_dependent_expression_p (t) && !INTEGRAL_TYPE_P (TREE_TYPE (t))) { - error ("%<aligned%> clause alignment expression must " - "be integral"); + error_at (OMP_CLAUSE_LOCATION (c), + "%<aligned%> clause alignment expression must " + "be integral"); remove = true; } else @@ -6619,15 +6824,45 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) if (TREE_CODE (t) != INTEGER_CST || tree_int_cst_sgn (t) != 1) { - error ("%<aligned%> clause alignment expression must be " - "positive constant integer expression"); + error_at (OMP_CLAUSE_LOCATION (c), + "%<aligned%> clause alignment expression must " + "be positive constant integer expression"); remove = true; } + else + t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); } OMP_CLAUSE_ALIGNED_ALIGNMENT (c) = t; } break; + case OMP_CLAUSE_NONTEMPORAL: + t = OMP_CLAUSE_DECL (c); + if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL) + { + if (processing_template_decl && TREE_CODE (t) != OVERLOAD) + break; + if (DECL_P (t)) + error_at (OMP_CLAUSE_LOCATION (c), + "%qD is not a variable in %<nontemporal%> clause", + t); + else + error_at (OMP_CLAUSE_LOCATION (c), + "%qE is not a variable in %<nontemporal%> clause", + t); + remove = true; + } + else if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t))) + { + error_at (OMP_CLAUSE_LOCATION (c), + "%qD appears more than once in %<nontemporal%> " + "clauses", t); + remove = true; + } + else + bitmap_set_bit (&oacc_reduction_head, DECL_UID (t)); + break; + case OMP_CLAUSE_DEPEND: t = OMP_CLAUSE_DECL (c); if (t == NULL_TREE) @@ -6642,33 +6877,108 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) remove = true; break; } + if (TREE_CODE (t) == TREE_LIST + && TREE_PURPOSE (t) + && TREE_CODE (TREE_PURPOSE (t)) == TREE_VEC) + { + if (TREE_PURPOSE (t) != last_iterators) + last_iterators_remove + = cp_omp_finish_iterators (TREE_PURPOSE (t)); + last_iterators = TREE_PURPOSE (t); + t = TREE_VALUE (t); + if (last_iterators_remove) + t = error_mark_node; + } + else + last_iterators = NULL_TREE; + if (TREE_CODE (t) == TREE_LIST) { if (handle_omp_array_sections (c, ort)) remove = true; + else if (OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_DEPOBJ) + { + error_at (OMP_CLAUSE_LOCATION (c), + "%<depend%> clause with %<depobj%> dependence " + "type on array section"); + remove = true; + } break; } if (t == error_mark_node) remove = true; - else if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL) + else if (t == current_class_ptr) + { + error_at (OMP_CLAUSE_LOCATION (c), + "%<this%> allowed in OpenMP only in %<declare simd%>" + " clauses"); + remove = true; + } + else if (processing_template_decl && TREE_CODE (t) != OVERLOAD) + break; + else if (!lvalue_p (t)) { - if (processing_template_decl && TREE_CODE (t) != OVERLOAD) - break; if (DECL_P (t)) - error ("%qD is not a variable in %<depend%> clause", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qD is not lvalue expression nor array section " + "in %<depend%> clause", t); else - error ("%qE is not a variable in %<depend%> clause", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qE is not lvalue expression nor array section " + "in %<depend%> clause", t); remove = true; } - else if (t == current_class_ptr) + else if (TREE_CODE (t) == COMPONENT_REF + && TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL + && DECL_BIT_FIELD (TREE_OPERAND (t, 1))) { - error ("%<this%> allowed in OpenMP only in %<declare simd%>" - " clauses"); + error_at (OMP_CLAUSE_LOCATION (c), + "bit-field %qE in %qs clause", t, "depend"); remove = true; } - else if (!processing_template_decl - && !cxx_mark_addressable (t)) - remove = true; + else if (OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_DEPOBJ) + { + if (!c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t)) + ? TREE_TYPE (TREE_TYPE (t)) + : TREE_TYPE (t))) + { + error_at (OMP_CLAUSE_LOCATION (c), + "%qE does not have %<omp_depend_t%> type in " + "%<depend%> clause with %<depobj%> dependence " + "type", t); + remove = true; + } + } + else if (c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t)) + ? TREE_TYPE (TREE_TYPE (t)) + : TREE_TYPE (t))) + { + error_at (OMP_CLAUSE_LOCATION (c), + "%qE should not have %<omp_depend_t%> type in " + "%<depend%> clause with dependence type other than " + "%<depobj%>", t); + remove = true; + } + if (!remove) + { + tree addr = cp_build_addr_expr (t, tf_warning_or_error); + if (addr == error_mark_node) + remove = true; + else + { + t = cp_build_indirect_ref (addr, RO_UNARY_STAR, + tf_warning_or_error); + if (t == error_mark_node) + remove = true; + else if (TREE_CODE (OMP_CLAUSE_DECL (c)) == TREE_LIST + && TREE_PURPOSE (OMP_CLAUSE_DECL (c)) + && (TREE_CODE (TREE_PURPOSE (OMP_CLAUSE_DECL (c))) + == TREE_VEC)) + TREE_VALUE (OMP_CLAUSE_DECL (c)) = t; + else + OMP_CLAUSE_DECL (c) = t; + } + } break; case OMP_CLAUSE_MAP: @@ -6707,14 +7017,17 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) if (bitmap_bit_p (&map_head, DECL_UID (t))) { if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP) - error ("%qD appears more than once in motion" - " clauses", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qD appears more than once in motion" + " clauses", t); else if (ort == C_ORT_ACC) - error ("%qD appears more than once in data" - " clauses", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qD appears more than once in data" + " clauses", t); else - error ("%qD appears more than once in map" - " clauses", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qD appears more than once in map" + " clauses", t); remove = true; } else @@ -6790,23 +7103,27 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ALWAYS_POINTER)) break; if (DECL_P (t)) - error ("%qD is not a variable in %qs clause", t, - omp_clause_code_name[OMP_CLAUSE_CODE (c)]); + error_at (OMP_CLAUSE_LOCATION (c), + "%qD is not a variable in %qs clause", t, + omp_clause_code_name[OMP_CLAUSE_CODE (c)]); else - error ("%qE is not a variable in %qs clause", t, - omp_clause_code_name[OMP_CLAUSE_CODE (c)]); + error_at (OMP_CLAUSE_LOCATION (c), + "%qE is not a variable in %qs clause", t, + omp_clause_code_name[OMP_CLAUSE_CODE (c)]); remove = true; } else if (VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t)) { - error ("%qD is threadprivate variable in %qs clause", t, - omp_clause_code_name[OMP_CLAUSE_CODE (c)]); + error_at (OMP_CLAUSE_LOCATION (c), + "%qD is threadprivate variable in %qs clause", t, + omp_clause_code_name[OMP_CLAUSE_CODE (c)]); remove = true; } else if (ort != C_ORT_ACC && t == current_class_ptr) { - error ("%<this%> allowed in OpenMP only in %<declare simd%>" - " clauses"); + error_at (OMP_CLAUSE_LOCATION (c), + "%<this%> allowed in OpenMP only in %<declare simd%>" + " clauses"); remove = true; break; } @@ -6837,7 +7154,8 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) && !type_dependent_expression_p (t) && !INDIRECT_TYPE_P (TREE_TYPE (t))) { - error ("%qD is not a pointer variable", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qD is not a pointer variable", t); remove = true; } else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP @@ -6846,15 +7164,18 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) if (bitmap_bit_p (&generic_head, DECL_UID (t)) || bitmap_bit_p (&firstprivate_head, DECL_UID (t))) { - error ("%qD appears more than once in data clauses", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qD appears more than once in data clauses", t); remove = true; } else if (bitmap_bit_p (&map_head, DECL_UID (t))) { if (ort == C_ORT_ACC) - error ("%qD appears more than once in data clauses", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qD appears more than once in data clauses", t); else - error ("%qD appears both in data and map clauses", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qD appears both in data and map clauses", t); remove = true; } else @@ -6863,20 +7184,25 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) else if (bitmap_bit_p (&map_head, DECL_UID (t))) { if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP) - error ("%qD appears more than once in motion clauses", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qD appears more than once in motion clauses", t); if (ort == C_ORT_ACC) - error ("%qD appears more than once in data clauses", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qD appears more than once in data clauses", t); else - error ("%qD appears more than once in map clauses", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qD appears more than once in map clauses", t); remove = true; } else if (bitmap_bit_p (&generic_head, DECL_UID (t)) || bitmap_bit_p (&firstprivate_head, DECL_UID (t))) { if (ort == C_ORT_ACC) - error ("%qD appears more than once in data clauses", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qD appears more than once in data clauses", t); else - error ("%qD appears both in data and map clauses", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qD appears both in data and map clauses", t); remove = true; } else @@ -6991,9 +7317,11 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) if (processing_template_decl) break; if (DECL_P (t)) - error ("%qD is not an argument in %<uniform%> clause", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qD is not an argument in %<uniform%> clause", t); else - error ("%qE is not an argument in %<uniform%> clause", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qE is not an argument in %<uniform%> clause", t); remove = true; break; } @@ -7008,7 +7336,8 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) else if (!type_dependent_expression_p (t) && !INTEGRAL_TYPE_P (TREE_TYPE (t))) { - error ("%<grainsize%> expression must be integral"); + error_at (OMP_CLAUSE_LOCATION (c), + "%<grainsize%> expression must be integral"); remove = true; } else @@ -7037,7 +7366,8 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) else if (!type_dependent_expression_p (t) && !INTEGRAL_TYPE_P (TREE_TYPE (t))) { - error ("%<priority%> expression must be integral"); + error_at (OMP_CLAUSE_LOCATION (c), + "%<priority%> expression must be integral"); remove = true; } else @@ -7066,7 +7396,8 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) else if (!type_dependent_expression_p (t) && !INTEGRAL_TYPE_P (TREE_TYPE (t))) { - error ("%<num_tasks%> expression must be integral"); + error_at (OMP_CLAUSE_LOCATION (c), + "%<hint%> expression must be integral"); remove = true; } else @@ -7076,6 +7407,13 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) { t = maybe_constant_value (t); t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); + if (TREE_CODE (t) != INTEGER_CST) + { + error_at (OMP_CLAUSE_LOCATION (c), + "%<hint%> expression must be constant integer " + "expression"); + remove = true; + } } OMP_CLAUSE_HINT_EXPR (c) = t; } @@ -7172,8 +7510,9 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) case OMP_CLAUSE_NOTINBRANCH: if (branch_seen) { - error ("%<inbranch%> clause is incompatible with " - "%<notinbranch%>"); + error_at (OMP_CLAUSE_LOCATION (c), + "%<inbranch%> clause is incompatible with " + "%<notinbranch%>"); remove = true; } branch_seen = true; @@ -7224,6 +7563,8 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) need_implicitly_determined = true; break; case OMP_CLAUSE_REDUCTION: + case OMP_CLAUSE_IN_REDUCTION: + case OMP_CLAUSE_TASK_REDUCTION: need_implicitly_determined = true; break; case OMP_CLAUSE_LINEAR: @@ -7276,6 +7617,17 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) } pc = &OMP_CLAUSE_CHAIN (c); continue; + case OMP_CLAUSE_NOGROUP: + if (reduction_seen) + { + error_at (OMP_CLAUSE_LOCATION (c), + "%<nogroup%> clause must not be used together with " + "%<reduction%> clause"); + *pc = OMP_CLAUSE_CHAIN (c); + continue; + } + pc = &OMP_CLAUSE_CHAIN (c); + continue; case OMP_CLAUSE_NOWAIT: if (copyprivate_seen) { @@ -7310,6 +7662,8 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) break; case OMP_CLAUSE_REDUCTION: + case OMP_CLAUSE_IN_REDUCTION: + case OMP_CLAUSE_TASK_REDUCTION: if (finish_omp_reduction_clause (c, &need_default_ctor, &need_dtor)) remove = true; @@ -7320,7 +7674,8 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) case OMP_CLAUSE_COPYIN: if (!VAR_P (t) || !CP_DECL_THREAD_LOCAL_P (t)) { - error ("%qE must be %<threadprivate%> for %<copyin%>", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qE must be %<threadprivate%> for %<copyin%>", t); remove = true; } break; @@ -7349,10 +7704,17 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) case OMP_CLAUSE_DEFAULT_UNSPECIFIED: break; case OMP_CLAUSE_DEFAULT_SHARED: - /* const vars may be specified in firstprivate clause. */ - if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE + if (VAR_P (t) + && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE + && TREE_STATIC (t) && cxx_omp_const_qual_no_mutable (t)) - break; + { + tree ctx = CP_DECL_CONTEXT (t); + /* const qualified static data members without mutable + member may be specified in firstprivate clause. */ + if (TYPE_P (ctx) && MAYBE_CLASS_TYPE_P (ctx)) + break; + } share_name = "shared"; break; case OMP_CLAUSE_DEFAULT_PRIVATE: @@ -7363,9 +7725,20 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) } if (share_name) { - error ("%qE is predetermined %qs for %qs", - omp_clause_printable_decl (t), share_name, - omp_clause_code_name[OMP_CLAUSE_CODE (c)]); + error_at (OMP_CLAUSE_LOCATION (c), + "%qE is predetermined %qs for %qs", + omp_clause_printable_decl (t), share_name, + omp_clause_code_name[OMP_CLAUSE_CODE (c)]); + remove = true; + } + else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED + && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_FIRSTPRIVATE + && cxx_omp_const_qual_no_mutable (t)) + { + error_at (OMP_CLAUSE_LOCATION (c), + "%<const%> qualified %qE without %<mutable%> member " + "may appear only in %<shared%> or %<firstprivate%> " + "clauses", omp_clause_printable_decl (t)); remove = true; } } @@ -7374,7 +7747,9 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) inner_type = type = TREE_TYPE (t); if ((need_complete_type || need_copy_assignment - || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION) + || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION + || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION + || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION) && TYPE_REF_P (inner_type)) inner_type = TREE_TYPE (inner_type); while (TREE_CODE (inner_type) == ARRAY_TYPE) @@ -7876,6 +8251,7 @@ handle_omp_for_class_iterator (int i, location_t locus, enum tree_code code, } incr = cp_convert (TREE_TYPE (diff), incr, tf_warning_or_error); + incr = cp_fully_fold (incr); bool taskloop_iv_seen = false; for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c)) if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE @@ -8011,12 +8387,22 @@ handle_omp_for_class_iterator (int i, location_t locus, enum tree_code code, = pop_stmt_list (OMP_CLAUSE_LASTPRIVATE_STMT (c)); } + if (TREE_CODE (TREE_VEC_ELT (orig_declv, i)) == TREE_LIST) + { + tree t = TREE_VEC_ELT (orig_declv, i); + gcc_assert (TREE_PURPOSE (t) == NULL_TREE + && TREE_VALUE (t) == NULL_TREE + && TREE_CODE (TREE_CHAIN (t)) == TREE_VEC); + TREE_PURPOSE (t) = TREE_VEC_ELT (declv, i); + TREE_VALUE (t) = last; + } + else + TREE_VEC_ELT (orig_declv, i) + = tree_cons (TREE_VEC_ELT (declv, i), last, NULL_TREE); TREE_VEC_ELT (declv, i) = decl; TREE_VEC_ELT (initv, i) = init; TREE_VEC_ELT (condv, i) = cond; TREE_VEC_ELT (incrv, i) = incr; - TREE_VEC_ELT (orig_declv, i) - = tree_cons (TREE_VEC_ELT (orig_declv, i), last, NULL_TREE); return false; } @@ -8098,6 +8484,9 @@ finish_omp_for (location_t locus, enum tree_code code, tree declv, if (init && EXPR_HAS_LOCATION (init)) elocus = EXPR_LOCATION (init); + if (cond == global_namespace) + continue; + if (cond == NULL) { error_at (elocus, "missing controlling predicate"); @@ -8120,7 +8509,8 @@ finish_omp_for (location_t locus, enum tree_code code, tree declv, tree orig_init; FOR_EACH_VEC_ELT (*orig_inits, i, orig_init) if (orig_init - && !c_omp_check_loop_iv_exprs (locus, declv, + && !c_omp_check_loop_iv_exprs (locus, orig_declv + ? orig_declv : declv, TREE_VEC_ELT (declv, i), orig_init, NULL_TREE, cp_walk_subtrees)) fail = true; @@ -8253,11 +8643,12 @@ finish_omp_for (location_t locus, enum tree_code code, tree declv, i++; } - if (IS_EMPTY_STMT (pre_body)) + if (pre_body && IS_EMPTY_STMT (pre_body)) pre_body = NULL; omp_for = c_finish_omp_for (locus, code, declv, orig_declv, initv, condv, - incrv, body, pre_body); + incrv, body, pre_body, + !processing_template_decl); /* Check for iterators appearing in lb, b or incr expressions. */ if (omp_for && !c_omp_check_loop_iv (omp_for, orig_declv, cp_walk_subtrees)) @@ -8369,9 +8760,55 @@ finish_omp_for (location_t locus, enum tree_code code, tree declv, return omp_for; } +/* Fix up range for decls. Those decls were pushed into BIND's BIND_EXPR_VARS + and need to be moved into the BIND_EXPR inside of the OMP_FOR's body. */ + +tree +finish_omp_for_block (tree bind, tree omp_for) +{ + if (omp_for == NULL_TREE + || !OMP_FOR_ORIG_DECLS (omp_for) + || bind == NULL_TREE + || TREE_CODE (bind) != BIND_EXPR) + return bind; + tree b = NULL_TREE; + for (int i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (omp_for)); i++) + if (TREE_CODE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i)) == TREE_LIST + && TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i))) + { + tree v = TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i)); + gcc_assert (BIND_EXPR_BLOCK (bind) + && (BIND_EXPR_VARS (bind) + == BLOCK_VARS (BIND_EXPR_BLOCK (bind)))); + for (int j = 2; j < TREE_VEC_LENGTH (v); j++) + for (tree *p = &BIND_EXPR_VARS (bind); *p; p = &DECL_CHAIN (*p)) + { + if (*p == TREE_VEC_ELT (v, j)) + { + tree var = *p; + *p = DECL_CHAIN (*p); + if (b == NULL_TREE) + { + b = make_node (BLOCK); + b = build3 (BIND_EXPR, void_type_node, NULL_TREE, + OMP_FOR_BODY (omp_for), b); + TREE_SIDE_EFFECTS (b) = 1; + OMP_FOR_BODY (omp_for) = b; + } + DECL_CHAIN (var) = BIND_EXPR_VARS (b); + BIND_EXPR_VARS (b) = var; + BLOCK_VARS (BIND_EXPR_BLOCK (b)) = var; + } + } + BLOCK_VARS (BIND_EXPR_BLOCK (bind)) = BIND_EXPR_VARS (bind); + } + return bind; +} + void -finish_omp_atomic (enum tree_code code, enum tree_code opcode, tree lhs, - tree rhs, tree v, tree lhs1, tree rhs1, bool seq_cst) +finish_omp_atomic (location_t loc, enum tree_code code, enum tree_code opcode, + tree lhs, tree rhs, tree v, tree lhs1, tree rhs1, + tree clauses, enum omp_memory_order mo) { tree orig_lhs; tree orig_rhs; @@ -8398,6 +8835,15 @@ finish_omp_atomic (enum tree_code code, enum tree_code opcode, tree lhs, || (v && type_dependent_expression_p (v)) || (lhs1 && type_dependent_expression_p (lhs1)) || (rhs1 && type_dependent_expression_p (rhs1))); + if (clauses) + { + gcc_assert (TREE_CODE (clauses) == OMP_CLAUSE + && OMP_CLAUSE_CODE (clauses) == OMP_CLAUSE_HINT + && OMP_CLAUSE_CHAIN (clauses) == NULL_TREE); + if (type_dependent_expression_p (OMP_CLAUSE_HINT_EXPR (clauses)) + || TREE_CODE (OMP_CLAUSE_HINT_EXPR (clauses)) != INTEGER_CST) + dependent_p = true; + } if (!dependent_p) { lhs = build_non_dependent_expr (lhs); @@ -8439,8 +8885,8 @@ finish_omp_atomic (enum tree_code code, enum tree_code opcode, tree lhs, "expressions for memory"); return; } - stmt = c_finish_omp_atomic (input_location, code, opcode, lhs, rhs, - v, lhs1, rhs1, swapped, seq_cst, + stmt = c_finish_omp_atomic (loc, code, opcode, lhs, rhs, + v, lhs1, rhs1, swapped, mo, processing_template_decl != 0); if (stmt == error_mark_node) return; @@ -8449,9 +8895,8 @@ finish_omp_atomic (enum tree_code code, enum tree_code opcode, tree lhs, { if (code == OMP_ATOMIC_READ) { - stmt = build_min_nt_loc (EXPR_LOCATION (orig_lhs), - OMP_ATOMIC_READ, orig_lhs); - OMP_ATOMIC_SEQ_CST (stmt) = seq_cst; + stmt = build_min_nt_loc (loc, OMP_ATOMIC_READ, orig_lhs); + OMP_ATOMIC_MEMORY_ORDER (stmt) = mo; stmt = build2 (MODIFY_EXPR, void_type_node, orig_v, stmt); } else @@ -8465,14 +8910,15 @@ finish_omp_atomic (enum tree_code code, enum tree_code opcode, tree lhs, COMPOUND_EXPR, orig_rhs1, stmt); if (code != OMP_ATOMIC) { - stmt = build_min_nt_loc (EXPR_LOCATION (orig_lhs1), - code, orig_lhs1, stmt); - OMP_ATOMIC_SEQ_CST (stmt) = seq_cst; + stmt = build_min_nt_loc (loc, code, orig_lhs1, stmt); + OMP_ATOMIC_MEMORY_ORDER (stmt) = mo; stmt = build2 (MODIFY_EXPR, void_type_node, orig_v, stmt); } } - stmt = build2 (OMP_ATOMIC, void_type_node, integer_zero_node, stmt); - OMP_ATOMIC_SEQ_CST (stmt) = seq_cst; + stmt = build2 (OMP_ATOMIC, void_type_node, + clauses ? clauses : integer_zero_node, stmt); + OMP_ATOMIC_MEMORY_ORDER (stmt) = mo; + SET_EXPR_LOCATION (stmt, loc); } finish_expr_stmt (stmt); } @@ -8488,10 +8934,50 @@ finish_omp_barrier (void) } void -finish_omp_flush (void) +finish_omp_depobj (location_t loc, tree depobj, + enum omp_clause_depend_kind kind, tree clause) +{ + if (!error_operand_p (depobj) && !type_dependent_expression_p (depobj)) + { + if (!lvalue_p (depobj)) + { + error_at (EXPR_LOC_OR_LOC (depobj, loc), + "%<depobj%> expression is not lvalue expression"); + depobj = error_mark_node; + } + } + + if (processing_template_decl) + { + if (clause == NULL_TREE) + clause = build_int_cst (integer_type_node, kind); + add_stmt (build_min_nt_loc (loc, OMP_DEPOBJ, depobj, clause)); + return; + } + + if (!error_operand_p (depobj)) + { + tree addr = cp_build_addr_expr (depobj, tf_warning_or_error); + if (addr == error_mark_node) + depobj = error_mark_node; + else + depobj = cp_build_indirect_ref (addr, RO_UNARY_STAR, + tf_warning_or_error); + } + + c_finish_omp_depobj (loc, depobj, kind, clause); +} + +void +finish_omp_flush (int mo) { tree fn = builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE); vec<tree, va_gc> *vec = make_tree_vector (); + if (mo != MEMMODEL_LAST) + { + fn = builtin_decl_explicit (BUILT_IN_ATOMIC_THREAD_FENCE); + vec->quick_push (build_int_cst (integer_type_node, mo)); + } tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error); release_tree_vector (vec); finish_expr_stmt (stmt); @@ -8540,6 +9026,11 @@ finish_omp_cancel (tree clauses) tree ifc = omp_find_clause (clauses, OMP_CLAUSE_IF); if (ifc != NULL_TREE) { + if (OMP_CLAUSE_IF_MODIFIER (ifc) != ERROR_MARK + && OMP_CLAUSE_IF_MODIFIER (ifc) != VOID_CST) + error_at (OMP_CLAUSE_LOCATION (ifc), + "expected %<cancel%> %<if%> clause modifier"); + tree type = TREE_TYPE (OMP_CLAUSE_IF_EXPR (ifc)); ifc = fold_build2_loc (OMP_CLAUSE_LOCATION (ifc), NE_EXPR, boolean_type_node, OMP_CLAUSE_IF_EXPR (ifc), diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 689c754..f5bcec3 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,19 @@ +2018-11-08 Jakub Jelinek <jakub@redhat.com> + + * trans-openmp.c (gfc_trans_omp_clauses): Use + OMP_CLAUSE_DEFAULTMAP_SET_KIND. + (gfc_trans_omp_atomic): Set OMP_ATOMIC_MEMORY_ORDER + rather than OMP_ATOMIC_SEQ_CST. + (gfc_trans_omp_taskgroup): Build OMP_TASKGROUP using + make_node instead of build1_loc. + * types.def (BT_FN_VOID_BOOL, BT_FN_VOID_SIZE_SIZE_PTR, + BT_FN_UINT_UINT_PTR_PTR, BT_FN_UINT_OMPFN_PTR_UINT_UINT, + BT_FN_BOOL_UINT_LONGPTR_LONG_LONG_LONGPTR_LONGPTR_PTR_PTR, + BT_FN_BOOL_UINT_ULLPTR_LONG_ULL_ULLPTR_ULLPTR_PTR_PTR, + BT_FN_BOOL_LONG_LONG_LONG_LONG_LONG_LONGPTR_LONGPTR_PTR_PTR, + BT_FN_BOOL_BOOL_ULL_ULL_ULL_LONG_ULL_ULLPTR_ULLPTR_PTR_PTR): New. + (BT_FN_VOID_INT_OMPFN_SIZE_PTR_PTR_PTR_UINT_PTR_PTR): Formatting fix. + 2018-11-02 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/46020 diff --git a/gcc/fortran/trans-openmp.c b/gcc/fortran/trans-openmp.c index f038f4c..483ca66 100644 --- a/gcc/fortran/trans-openmp.c +++ b/gcc/fortran/trans-openmp.c @@ -2866,6 +2866,8 @@ gfc_trans_omp_clauses (stmtblock_t *block, gfc_omp_clauses *clauses, if (clauses->defaultmap) { c = build_omp_clause (where.lb->location, OMP_CLAUSE_DEFAULTMAP); + OMP_CLAUSE_DEFAULTMAP_SET_KIND (c, OMP_CLAUSE_DEFAULTMAP_TOFROM, + OMP_CLAUSE_DEFAULTMAP_CATEGORY_SCALAR); omp_clauses = gfc_trans_add_clause (c, omp_clauses); } if (clauses->depend_source) @@ -3166,7 +3168,9 @@ gfc_trans_omp_atomic (gfc_code *code) enum tree_code op = ERROR_MARK; enum tree_code aop = OMP_ATOMIC; bool var_on_left = false; - bool seq_cst = (atomic_code->ext.omp_atomic & GFC_OMP_ATOMIC_SEQ_CST) != 0; + enum omp_memory_order mo + = ((atomic_code->ext.omp_atomic & GFC_OMP_ATOMIC_SEQ_CST) + ? OMP_MEMORY_ORDER_SEQ_CST : OMP_MEMORY_ORDER_RELAXED); code = code->block->next; gcc_assert (code->op == EXEC_ASSIGN); @@ -3198,7 +3202,7 @@ gfc_trans_omp_atomic (gfc_code *code) lhsaddr = gfc_build_addr_expr (NULL, lse.expr); x = build1 (OMP_ATOMIC_READ, type, lhsaddr); - OMP_ATOMIC_SEQ_CST (x) = seq_cst; + OMP_ATOMIC_MEMORY_ORDER (x) = mo; x = convert (TREE_TYPE (vse.expr), x); gfc_add_modify (&block, vse.expr, x); @@ -3398,7 +3402,7 @@ gfc_trans_omp_atomic (gfc_code *code) if (aop == OMP_ATOMIC) { x = build2_v (OMP_ATOMIC, lhsaddr, convert (type, x)); - OMP_ATOMIC_SEQ_CST (x) = seq_cst; + OMP_ATOMIC_MEMORY_ORDER (x) = mo; gfc_add_expr_to_block (&block, x); } else @@ -3421,7 +3425,7 @@ gfc_trans_omp_atomic (gfc_code *code) gfc_add_block_to_block (&block, &lse.pre); } x = build2 (aop, type, lhsaddr, convert (type, x)); - OMP_ATOMIC_SEQ_CST (x) = seq_cst; + OMP_ATOMIC_MEMORY_ORDER (x) = mo; x = convert (TREE_TYPE (vse.expr), x); gfc_add_modify (&block, vse.expr, x); } @@ -4586,8 +4590,12 @@ gfc_trans_omp_task (gfc_code *code) static tree gfc_trans_omp_taskgroup (gfc_code *code) { - tree stmt = gfc_trans_code (code->block->next); - return build1_loc (input_location, OMP_TASKGROUP, void_type_node, stmt); + tree body = gfc_trans_code (code->block->next); + tree stmt = make_node (OMP_TASKGROUP); + TREE_TYPE (stmt) = void_type_node; + OMP_TASKGROUP_BODY (stmt) = body; + OMP_TASKGROUP_CLAUSES (stmt) = NULL_TREE; + return stmt; } static tree diff --git a/gcc/fortran/types.def b/gcc/fortran/types.def index 78f3e20..0eabc3f 100644 --- a/gcc/fortran/types.def +++ b/gcc/fortran/types.def @@ -86,6 +86,7 @@ DEF_FUNCTION_TYPE_1 (BT_FN_INT_INT, BT_INT, BT_INT) DEF_FUNCTION_TYPE_1 (BT_FN_UINT_UINT, BT_UINT, BT_UINT) DEF_FUNCTION_TYPE_1 (BT_FN_PTR_PTR, BT_PTR, BT_PTR) DEF_FUNCTION_TYPE_1 (BT_FN_VOID_INT, BT_VOID, BT_INT) +DEF_FUNCTION_TYPE_1 (BT_FN_VOID_BOOL, BT_VOID, BT_BOOL) DEF_FUNCTION_TYPE_1 (BT_FN_BOOL_INT, BT_BOOL, BT_INT) DEF_POINTER_TYPE (BT_PTR_FN_VOID_PTR, BT_FN_VOID_PTR) @@ -145,9 +146,14 @@ DEF_FUNCTION_TYPE_3 (BT_FN_VOID_VPTR_I2_INT, BT_VOID, BT_VOLATILE_PTR, BT_I2, BT DEF_FUNCTION_TYPE_3 (BT_FN_VOID_VPTR_I4_INT, BT_VOID, BT_VOLATILE_PTR, BT_I4, BT_INT) DEF_FUNCTION_TYPE_3 (BT_FN_VOID_VPTR_I8_INT, BT_VOID, BT_VOLATILE_PTR, BT_I8, BT_INT) DEF_FUNCTION_TYPE_3 (BT_FN_VOID_VPTR_I16_INT, BT_VOID, BT_VOLATILE_PTR, BT_I16, BT_INT) +DEF_FUNCTION_TYPE_3 (BT_FN_VOID_SIZE_SIZE_PTR, BT_VOID, BT_SIZE, BT_SIZE, + BT_PTR) +DEF_FUNCTION_TYPE_3 (BT_FN_UINT_UINT_PTR_PTR, BT_UINT, BT_UINT, BT_PTR, BT_PTR) DEF_FUNCTION_TYPE_4 (BT_FN_VOID_OMPFN_PTR_UINT_UINT, BT_VOID, BT_PTR_FN_VOID_PTR, BT_PTR, BT_UINT, BT_UINT) +DEF_FUNCTION_TYPE_4 (BT_FN_UINT_OMPFN_PTR_UINT_UINT, + BT_UINT, BT_PTR_FN_VOID_PTR, BT_PTR, BT_UINT, BT_UINT) DEF_FUNCTION_TYPE_4 (BT_FN_VOID_PTR_WORD_WORD_PTR, BT_VOID, BT_PTR, BT_WORD, BT_WORD, BT_PTR) DEF_FUNCTION_TYPE_4 (BT_FN_VOID_SIZE_VPTR_PTR_INT, BT_VOID, BT_SIZE, @@ -217,14 +223,28 @@ DEF_FUNCTION_TYPE_7 (BT_FN_VOID_INT_SIZE_PTR_PTR_PTR_UINT_PTR, DEF_FUNCTION_TYPE_8 (BT_FN_VOID_OMPFN_PTR_UINT_LONG_LONG_LONG_LONG_UINT, BT_VOID, BT_PTR_FN_VOID_PTR, BT_PTR, BT_UINT, BT_LONG, BT_LONG, BT_LONG, BT_LONG, BT_UINT) +DEF_FUNCTION_TYPE_8 (BT_FN_BOOL_UINT_LONGPTR_LONG_LONG_LONGPTR_LONGPTR_PTR_PTR, + BT_BOOL, BT_UINT, BT_PTR_LONG, BT_LONG, BT_LONG, + BT_PTR_LONG, BT_PTR_LONG, BT_PTR, BT_PTR) +DEF_FUNCTION_TYPE_8 (BT_FN_BOOL_UINT_ULLPTR_LONG_ULL_ULLPTR_ULLPTR_PTR_PTR, + BT_BOOL, BT_UINT, BT_PTR_ULONGLONG, BT_LONG, BT_ULONGLONG, + BT_PTR_ULONGLONG, BT_PTR_ULONGLONG, BT_PTR, BT_PTR) DEF_FUNCTION_TYPE_9 (BT_FN_VOID_OMPFN_PTR_OMPCPYFN_LONG_LONG_BOOL_UINT_PTR_INT, BT_VOID, BT_PTR_FN_VOID_PTR, BT_PTR, BT_PTR_FN_VOID_PTR_PTR, BT_LONG, BT_LONG, BT_BOOL, BT_UINT, BT_PTR, BT_INT) DEF_FUNCTION_TYPE_9 (BT_FN_VOID_INT_OMPFN_SIZE_PTR_PTR_PTR_UINT_PTR_PTR, - BT_VOID, BT_INT, BT_PTR_FN_VOID_PTR, BT_SIZE, BT_PTR, - BT_PTR, BT_PTR, BT_UINT, BT_PTR, BT_PTR) + BT_VOID, BT_INT, BT_PTR_FN_VOID_PTR, BT_SIZE, BT_PTR, + BT_PTR, BT_PTR, BT_UINT, BT_PTR, BT_PTR) +DEF_FUNCTION_TYPE_9 (BT_FN_BOOL_LONG_LONG_LONG_LONG_LONG_LONGPTR_LONGPTR_PTR_PTR, + BT_BOOL, BT_LONG, BT_LONG, BT_LONG, BT_LONG, BT_LONG, + BT_PTR_LONG, BT_PTR_LONG, BT_PTR, BT_PTR) + +DEF_FUNCTION_TYPE_10 (BT_FN_BOOL_BOOL_ULL_ULL_ULL_LONG_ULL_ULLPTR_ULLPTR_PTR_PTR, + BT_BOOL, BT_BOOL, BT_ULONGLONG, BT_ULONGLONG, + BT_ULONGLONG, BT_LONG, BT_ULONGLONG, BT_PTR_ULONGLONG, + BT_PTR_ULONGLONG, BT_PTR, BT_PTR) DEF_FUNCTION_TYPE_11 (BT_FN_VOID_OMPFN_PTR_OMPCPYFN_LONG_LONG_UINT_LONG_INT_LONG_LONG_LONG, BT_VOID, BT_PTR_FN_VOID_PTR, BT_PTR, diff --git a/gcc/gengtype.c b/gcc/gengtype.c index 4339456..40406df 100644 --- a/gcc/gengtype.c +++ b/gcc/gengtype.c @@ -1724,7 +1724,8 @@ open_base_files (void) "tree-dfa.h", "tree-ssa.h", "reload.h", "cpplib.h", "tree-chrec.h", "except.h", "output.h", "cfgloop.h", "target.h", "lto-streamer.h", "target-globals.h", "ipa-ref.h", "cgraph.h", "symbol-summary.h", - "ipa-prop.h", "ipa-fnsummary.h", "dwarf2out.h", "omp-offload.h", NULL + "ipa-prop.h", "ipa-fnsummary.h", "dwarf2out.h", "omp-general.h", + "omp-offload.h", NULL }; const char *const *ifp; outf_p gtype_desc_c; diff --git a/gcc/gimple-pretty-print.c b/gcc/gimple-pretty-print.c index 7dfec91..276e579 100644 --- a/gcc/gimple-pretty-print.c +++ b/gcc/gimple-pretty-print.c @@ -1554,6 +1554,35 @@ dump_gimple_omp_single (pretty_printer *buffer, gomp_single *gs, } } +/* Dump a GIMPLE_OMP_TASKGROUP tuple on the pretty_printer BUFFER. */ + +static void +dump_gimple_omp_taskgroup (pretty_printer *buffer, gimple *gs, + int spc, dump_flags_t flags) +{ + if (flags & TDF_RAW) + { + dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs, + gimple_omp_body (gs)); + dump_omp_clauses (buffer, gimple_omp_taskgroup_clauses (gs), spc, flags); + dump_gimple_fmt (buffer, spc, flags, " >"); + } + else + { + pp_string (buffer, "#pragma omp taskgroup"); + dump_omp_clauses (buffer, gimple_omp_taskgroup_clauses (gs), spc, flags); + if (!gimple_seq_empty_p (gimple_omp_body (gs))) + { + newline_and_indent (buffer, spc + 2); + pp_left_brace (buffer); + pp_newline (buffer); + dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags); + newline_and_indent (buffer, spc + 2); + pp_right_brace (buffer); + } + } +} + /* Dump a GIMPLE_OMP_TARGET tuple on the pretty_printer BUFFER. */ static void @@ -1712,7 +1741,7 @@ dump_gimple_omp_sections (pretty_printer *buffer, gomp_sections *gs, } } -/* Dump a GIMPLE_OMP_{MASTER,TASKGROUP,ORDERED,SECTION} tuple on the +/* Dump a GIMPLE_OMP_{MASTER,ORDERED,SECTION} tuple on the pretty_printer BUFFER. */ static void @@ -2301,6 +2330,8 @@ dump_gimple_omp_task (pretty_printer *buffer, gomp_task *gs, int spc, gimple_seq body; if (gimple_omp_task_taskloop_p (gs)) pp_string (buffer, "#pragma omp taskloop"); + else if (gimple_omp_task_taskwait_p (gs)) + pp_string (buffer, "#pragma omp taskwait"); else pp_string (buffer, "#pragma omp task"); dump_omp_clauses (buffer, gimple_omp_task_clauses (gs), spc, flags); @@ -2353,8 +2384,8 @@ dump_gimple_omp_atomic_load (pretty_printer *buffer, gomp_atomic_load *gs, else { pp_string (buffer, "#pragma omp atomic_load"); - if (gimple_omp_atomic_seq_cst_p (gs)) - pp_string (buffer, " seq_cst"); + dump_omp_atomic_memory_order (buffer, + gimple_omp_atomic_memory_order (gs)); if (gimple_omp_atomic_need_value_p (gs)) pp_string (buffer, " [needed]"); newline_and_indent (buffer, spc + 2); @@ -2385,9 +2416,10 @@ dump_gimple_omp_atomic_store (pretty_printer *buffer, } else { - pp_string (buffer, "#pragma omp atomic_store "); - if (gimple_omp_atomic_seq_cst_p (gs)) - pp_string (buffer, "seq_cst "); + pp_string (buffer, "#pragma omp atomic_store"); + dump_omp_atomic_memory_order (buffer, + gimple_omp_atomic_memory_order (gs)); + pp_space (buffer); if (gimple_omp_atomic_need_value_p (gs)) pp_string (buffer, "[needed] "); pp_left_paren (buffer); @@ -2569,8 +2601,11 @@ pp_gimple_stmt_1 (pretty_printer *buffer, gimple *gs, int spc, pp_string (buffer, "GIMPLE_SECTIONS_SWITCH"); break; - case GIMPLE_OMP_MASTER: case GIMPLE_OMP_TASKGROUP: + dump_gimple_omp_taskgroup (buffer, gs, spc, flags); + break; + + case GIMPLE_OMP_MASTER: case GIMPLE_OMP_SECTION: case GIMPLE_OMP_GRID_BODY: dump_gimple_omp_block (buffer, gs, spc, flags); diff --git a/gcc/gimple.c b/gcc/gimple.c index 579b750..41d9f67 100644 --- a/gcc/gimple.c +++ b/gcc/gimple.c @@ -924,7 +924,7 @@ gimple_build_omp_critical (gimple_seq body, tree name, tree clauses) BODY is sequence of statements inside the for loop. KIND is the `for' variant. - CLAUSES, are any of the construct's clauses. + CLAUSES are any of the construct's clauses. COLLAPSE is the collapse count. PRE_BODY is the sequence of statements that are loop invariant. */ @@ -950,7 +950,7 @@ gimple_build_omp_for (gimple_seq body, int kind, tree clauses, size_t collapse, /* Build a GIMPLE_OMP_PARALLEL statement. BODY is sequence of statements which are executed in parallel. - CLAUSES, are the OMP parallel construct's clauses. + CLAUSES are the OMP parallel construct's clauses. CHILD_FN is the function created for the parallel threads to execute. DATA_ARG are the shared data argument(s). */ @@ -973,7 +973,7 @@ gimple_build_omp_parallel (gimple_seq body, tree clauses, tree child_fn, /* Build a GIMPLE_OMP_TASK statement. BODY is sequence of statements which are executed by the explicit task. - CLAUSES, are the OMP parallel construct's clauses. + CLAUSES are the OMP task construct's clauses. CHILD_FN is the function created for the parallel threads to execute. DATA_ARG are the shared data argument(s). COPY_FN is the optional function for firstprivate initialization. @@ -1044,12 +1044,14 @@ gimple_build_omp_grid_body (gimple_seq body) /* Build a GIMPLE_OMP_TASKGROUP statement. BODY is the sequence of statements to be executed by the taskgroup - construct. */ + construct. + CLAUSES are any of the construct's clauses. */ gimple * -gimple_build_omp_taskgroup (gimple_seq body) +gimple_build_omp_taskgroup (gimple_seq body, tree clauses) { gimple *p = gimple_alloc (GIMPLE_OMP_TASKGROUP, 0); + gimple_omp_taskgroup_set_clauses (p, clauses); if (body) gimple_omp_set_body (p, body); @@ -1192,12 +1194,13 @@ gimple_build_omp_teams (gimple_seq body, tree clauses) /* Build a GIMPLE_OMP_ATOMIC_LOAD statement. */ gomp_atomic_load * -gimple_build_omp_atomic_load (tree lhs, tree rhs) +gimple_build_omp_atomic_load (tree lhs, tree rhs, enum omp_memory_order mo) { gomp_atomic_load *p = as_a <gomp_atomic_load *> (gimple_alloc (GIMPLE_OMP_ATOMIC_LOAD, 0)); gimple_omp_atomic_load_set_lhs (p, lhs); gimple_omp_atomic_load_set_rhs (p, rhs); + gimple_omp_atomic_set_memory_order (p, mo); return p; } @@ -1206,11 +1209,12 @@ gimple_build_omp_atomic_load (tree lhs, tree rhs) VAL is the value we are storing. */ gomp_atomic_store * -gimple_build_omp_atomic_store (tree val) +gimple_build_omp_atomic_store (tree val, enum omp_memory_order mo) { gomp_atomic_store *p = as_a <gomp_atomic_store *> (gimple_alloc (GIMPLE_OMP_ATOMIC_STORE, 0)); gimple_omp_atomic_store_set_val (p, val); + gimple_omp_atomic_set_memory_order (p, mo); return p; } @@ -1935,6 +1939,11 @@ gimple_copy (gimple *stmt) gimple_omp_ordered_set_clauses (as_a <gomp_ordered *> (copy), t); goto copy_omp_body; + case GIMPLE_OMP_TASKGROUP: + t = unshare_expr (gimple_omp_taskgroup_clauses (stmt)); + gimple_omp_taskgroup_set_clauses (copy, t); + goto copy_omp_body; + case GIMPLE_OMP_SECTIONS: t = unshare_expr (gimple_omp_sections_clauses (stmt)); gimple_omp_sections_set_clauses (copy, t); @@ -1971,7 +1980,6 @@ gimple_copy (gimple *stmt) case GIMPLE_OMP_SECTION: case GIMPLE_OMP_MASTER: - case GIMPLE_OMP_TASKGROUP: case GIMPLE_OMP_GRID_BODY: copy_omp_body: new_seq = gimple_seq_copy (gimple_omp_body (stmt)); diff --git a/gcc/gimple.def b/gcc/gimple.def index 513204e..38206e9 100644 --- a/gcc/gimple.def +++ b/gcc/gimple.def @@ -279,9 +279,10 @@ DEFGSCODE(GIMPLE_OMP_FOR, "gimple_omp_for", GSS_OMP_FOR) BODY is the sequence of statements to execute in the master section. */ DEFGSCODE(GIMPLE_OMP_MASTER, "gimple_omp_master", GSS_OMP) -/* GIMPLE_OMP_TASKGROUP <BODY> represents #pragma omp taskgroup. - BODY is the sequence of statements to execute in the taskgroup section. */ -DEFGSCODE(GIMPLE_OMP_TASKGROUP, "gimple_omp_taskgroup", GSS_OMP) +/* GIMPLE_OMP_TASKGROUP <BODY, CLAUSES> represents #pragma omp taskgroup. + BODY is the sequence of statements inside the taskgroup section. + CLAUSES is an OMP_CLAUSE chain holding the associated clauses. */ +DEFGSCODE(GIMPLE_OMP_TASKGROUP, "gimple_omp_taskgroup", GSS_OMP_SINGLE_LAYOUT) /* GIMPLE_OMP_PARALLEL <BODY, CLAUSES, CHILD_FN, DATA_ARG> represents @@ -366,10 +367,12 @@ DEFGSCODE(GIMPLE_OMP_SINGLE, "gimple_omp_single", GSS_OMP_SINGLE_LAYOUT) implement the MAP clauses. */ DEFGSCODE(GIMPLE_OMP_TARGET, "gimple_omp_target", GSS_OMP_PARALLEL_LAYOUT) -/* GIMPLE_OMP_TEAMS <BODY, CLAUSES> represents #pragma omp teams +/* GIMPLE_OMP_TEAMS <BODY, CLAUSES, CHILD_FN, DATA_ARG> represents + #pragma omp teams BODY is the sequence of statements inside the single section. - CLAUSES is an OMP_CLAUSE chain holding the associated clauses. */ -DEFGSCODE(GIMPLE_OMP_TEAMS, "gimple_omp_teams", GSS_OMP_SINGLE_LAYOUT) + CLAUSES is an OMP_CLAUSE chain holding the associated clauses. + CHILD_FN and DATA_ARG like for GIMPLE_OMP_PARALLEL. */ +DEFGSCODE(GIMPLE_OMP_TEAMS, "gimple_omp_teams", GSS_OMP_PARALLEL_LAYOUT) /* GIMPLE_OMP_ORDERED <BODY, CLAUSES> represents #pragma omp ordered. BODY is the sequence of statements to execute in the ordered section. diff --git a/gcc/gimple.h b/gcc/gimple.h index cdd711d..145e9ad 100644 --- a/gcc/gimple.h +++ b/gcc/gimple.h @@ -151,6 +151,7 @@ enum gf_mask { GF_OMP_PARALLEL_COMBINED = 1 << 0, GF_OMP_PARALLEL_GRID_PHONY = 1 << 1, GF_OMP_TASK_TASKLOOP = 1 << 0, + GF_OMP_TASK_TASKWAIT = 1 << 1, GF_OMP_FOR_KIND_MASK = (1 << 4) - 1, GF_OMP_FOR_KIND_FOR = 0, GF_OMP_FOR_KIND_DISTRIBUTE = 1, @@ -183,6 +184,7 @@ enum gf_mask { GF_OMP_TARGET_KIND_OACC_DECLARE = 10, GF_OMP_TARGET_KIND_OACC_HOST_DATA = 11, GF_OMP_TEAMS_GRID_PHONY = 1 << 0, + GF_OMP_TEAMS_HOST = 1 << 1, /* True on an GIMPLE_OMP_RETURN statement if the return does not require a thread synchronization via some sort of barrier. The exact barrier @@ -191,8 +193,8 @@ enum gf_mask { GF_OMP_RETURN_NOWAIT = 1 << 0, GF_OMP_SECTION_LAST = 1 << 0, - GF_OMP_ATOMIC_NEED_VALUE = 1 << 0, - GF_OMP_ATOMIC_SEQ_CST = 1 << 1, + GF_OMP_ATOMIC_MEMORY_ORDER = (1 << 3) - 1, + GF_OMP_ATOMIC_NEED_VALUE = 1 << 3, GF_PREDICT_TAKEN = 1 << 15 }; @@ -637,7 +639,7 @@ struct GTY((tag("GSS_OMP_FOR"))) }; -/* GIMPLE_OMP_PARALLEL, GIMPLE_OMP_TARGET, GIMPLE_OMP_TASK */ +/* GIMPLE_OMP_PARALLEL, GIMPLE_OMP_TARGET, GIMPLE_OMP_TASK, GIMPLE_OMP_TEAMS */ struct GTY((tag("GSS_OMP_PARALLEL_LAYOUT"))) gimple_statement_omp_parallel_layout : public gimple_statement_omp @@ -663,7 +665,8 @@ struct GTY((tag("GSS_OMP_PARALLEL_LAYOUT"))) { /* No extra fields; adds invariant: stmt->code == GIMPLE_OMP_PARALLEL - || stmt->code == GIMPLE_OMP_TASK. */ + || stmt->code == GIMPLE_OMP_TASK + || stmt->code == GIMPLE_OMP_TEAMS. */ }; /* GIMPLE_OMP_PARALLEL */ @@ -737,7 +740,7 @@ struct GTY((tag("GSS_OMP_CONTINUE"))) tree control_use; }; -/* GIMPLE_OMP_SINGLE, GIMPLE_OMP_TEAMS, GIMPLE_OMP_ORDERED */ +/* GIMPLE_OMP_SINGLE, GIMPLE_OMP_ORDERED, GIMPLE_OMP_TASKGROUP. */ struct GTY((tag("GSS_OMP_SINGLE_LAYOUT"))) gimple_statement_omp_single_layout : public gimple_statement_omp @@ -755,8 +758,8 @@ struct GTY((tag("GSS_OMP_SINGLE_LAYOUT"))) stmt->code == GIMPLE_OMP_SINGLE. */ }; -struct GTY((tag("GSS_OMP_SINGLE_LAYOUT"))) - gomp_teams : public gimple_statement_omp_single_layout +struct GTY((tag("GSS_OMP_PARALLEL_LAYOUT"))) + gomp_teams : public gimple_statement_omp_taskreg { /* No extra fields; adds invariant: stmt->code == GIMPLE_OMP_TEAMS. */ @@ -1121,7 +1124,9 @@ template <> inline bool is_a_helper <gimple_statement_omp_taskreg *>::test (gimple *gs) { - return gs->code == GIMPLE_OMP_PARALLEL || gs->code == GIMPLE_OMP_TASK; + return (gs->code == GIMPLE_OMP_PARALLEL + || gs->code == GIMPLE_OMP_TASK + || gs->code == GIMPLE_OMP_TEAMS); } template <> @@ -1337,7 +1342,9 @@ template <> inline bool is_a_helper <const gimple_statement_omp_taskreg *>::test (const gimple *gs) { - return gs->code == GIMPLE_OMP_PARALLEL || gs->code == GIMPLE_OMP_TASK; + return (gs->code == GIMPLE_OMP_PARALLEL + || gs->code == GIMPLE_OMP_TASK + || gs->code == GIMPLE_OMP_TEAMS); } template <> @@ -1463,7 +1470,7 @@ gomp_task *gimple_build_omp_task (gimple_seq, tree, tree, tree, tree, gimple *gimple_build_omp_section (gimple_seq); gimple *gimple_build_omp_master (gimple_seq); gimple *gimple_build_omp_grid_body (gimple_seq); -gimple *gimple_build_omp_taskgroup (gimple_seq); +gimple *gimple_build_omp_taskgroup (gimple_seq, tree); gomp_continue *gimple_build_omp_continue (tree, tree); gomp_ordered *gimple_build_omp_ordered (gimple_seq, tree); gimple *gimple_build_omp_return (bool); @@ -1472,8 +1479,9 @@ gimple *gimple_build_omp_sections_switch (void); gomp_single *gimple_build_omp_single (gimple_seq, tree); gomp_target *gimple_build_omp_target (gimple_seq, int, tree); gomp_teams *gimple_build_omp_teams (gimple_seq, tree); -gomp_atomic_load *gimple_build_omp_atomic_load (tree, tree); -gomp_atomic_store *gimple_build_omp_atomic_store (tree); +gomp_atomic_load *gimple_build_omp_atomic_load (tree, tree, + enum omp_memory_order); +gomp_atomic_store *gimple_build_omp_atomic_store (tree, enum omp_memory_order); gtransaction *gimple_build_transaction (gimple_seq); extern void gimple_seq_add_stmt (gimple_seq *, gimple *); extern void gimple_seq_add_stmt_without_update (gimple_seq *, gimple *); @@ -2193,7 +2201,7 @@ static inline unsigned gimple_omp_subcode (const gimple *s) { gcc_gimple_checking_assert (gimple_code (s) >= GIMPLE_OMP_ATOMIC_LOAD - && gimple_code (s) <= GIMPLE_OMP_TEAMS); + && gimple_code (s) <= GIMPLE_OMP_TEAMS); return s->subcode; } @@ -2331,26 +2339,27 @@ gimple_omp_atomic_set_need_value (gimple *g) } -/* Return true if OMP atomic load/store statement G has the - GF_OMP_ATOMIC_SEQ_CST flag set. */ +/* Return the memory order of the OMP atomic load/store statement G. */ -static inline bool -gimple_omp_atomic_seq_cst_p (const gimple *g) +static inline enum omp_memory_order +gimple_omp_atomic_memory_order (const gimple *g) { if (gimple_code (g) != GIMPLE_OMP_ATOMIC_LOAD) GIMPLE_CHECK (g, GIMPLE_OMP_ATOMIC_STORE); - return (gimple_omp_subcode (g) & GF_OMP_ATOMIC_SEQ_CST) != 0; + return (enum omp_memory_order) + (gimple_omp_subcode (g) & GF_OMP_ATOMIC_MEMORY_ORDER); } -/* Set the GF_OMP_ATOMIC_SEQ_CST flag on G. */ +/* Set the memory order on G. */ static inline void -gimple_omp_atomic_set_seq_cst (gimple *g) +gimple_omp_atomic_set_memory_order (gimple *g, enum omp_memory_order mo) { if (gimple_code (g) != GIMPLE_OMP_ATOMIC_LOAD) GIMPLE_CHECK (g, GIMPLE_OMP_ATOMIC_STORE); - g->subcode |= GF_OMP_ATOMIC_SEQ_CST; + g->subcode = ((g->subcode & ~GF_OMP_ATOMIC_MEMORY_ORDER) + | (mo & GF_OMP_ATOMIC_MEMORY_ORDER)); } @@ -4915,6 +4924,40 @@ gimple_omp_ordered_set_clauses (gomp_ordered *ord_stmt, tree clauses) } +/* Return the clauses associated with OMP_TASKGROUP statement GS. */ + +static inline tree +gimple_omp_taskgroup_clauses (const gimple *gs) +{ + GIMPLE_CHECK (gs, GIMPLE_OMP_TASKGROUP); + return + static_cast <const gimple_statement_omp_single_layout *> (gs)->clauses; +} + + +/* Return a pointer to the clauses associated with OMP taskgroup statement + GS. */ + +static inline tree * +gimple_omp_taskgroup_clauses_ptr (gimple *gs) +{ + GIMPLE_CHECK (gs, GIMPLE_OMP_TASKGROUP); + return &static_cast <gimple_statement_omp_single_layout *> (gs)->clauses; +} + + +/* Set CLAUSES to be the clauses associated with OMP taskgroup statement + GS. */ + +static inline void +gimple_omp_taskgroup_set_clauses (gimple *gs, tree clauses) +{ + GIMPLE_CHECK (gs, GIMPLE_OMP_TASKGROUP); + static_cast <gimple_statement_omp_single_layout *> (gs)->clauses + = clauses; +} + + /* Return the kind of the OMP_FOR statemement G. */ static inline int @@ -5441,6 +5484,31 @@ gimple_omp_task_set_taskloop_p (gimple *g, bool taskloop_p) } +/* Return true if OMP task statement G has the + GF_OMP_TASK_TASKWAIT flag set. */ + +static inline bool +gimple_omp_task_taskwait_p (const gimple *g) +{ + GIMPLE_CHECK (g, GIMPLE_OMP_TASK); + return (gimple_omp_subcode (g) & GF_OMP_TASK_TASKWAIT) != 0; +} + + +/* Set the GF_OMP_TASK_TASKWAIT field in G depending on the boolean + value of TASKWAIT_P. */ + +static inline void +gimple_omp_task_set_taskwait_p (gimple *g, bool taskwait_p) +{ + GIMPLE_CHECK (g, GIMPLE_OMP_TASK); + if (taskwait_p) + g->subcode |= GF_OMP_TASK_TASKWAIT; + else + g->subcode &= ~GF_OMP_TASK_TASKWAIT; +} + + /* Return the child function used to hold the body of OMP_TASK GS. */ static inline tree @@ -5857,6 +5925,60 @@ gimple_omp_teams_set_clauses (gomp_teams *omp_teams_stmt, tree clauses) omp_teams_stmt->clauses = clauses; } +/* Return the child function used to hold the body of OMP_TEAMS_STMT. */ + +static inline tree +gimple_omp_teams_child_fn (const gomp_teams *omp_teams_stmt) +{ + return omp_teams_stmt->child_fn; +} + +/* Return a pointer to the child function used to hold the body of + OMP_TEAMS_STMT. */ + +static inline tree * +gimple_omp_teams_child_fn_ptr (gomp_teams *omp_teams_stmt) +{ + return &omp_teams_stmt->child_fn; +} + + +/* Set CHILD_FN to be the child function for OMP_TEAMS_STMT. */ + +static inline void +gimple_omp_teams_set_child_fn (gomp_teams *omp_teams_stmt, tree child_fn) +{ + omp_teams_stmt->child_fn = child_fn; +} + + +/* Return the artificial argument used to send variables and values + from the parent to the children threads in OMP_TEAMS_STMT. */ + +static inline tree +gimple_omp_teams_data_arg (const gomp_teams *omp_teams_stmt) +{ + return omp_teams_stmt->data_arg; +} + + +/* Return a pointer to the data argument for OMP_TEAMS_STMT. */ + +static inline tree * +gimple_omp_teams_data_arg_ptr (gomp_teams *omp_teams_stmt) +{ + return &omp_teams_stmt->data_arg; +} + + +/* Set DATA_ARG to be the data argument for OMP_TEAMS_STMT. */ + +static inline void +gimple_omp_teams_set_data_arg (gomp_teams *omp_teams_stmt, tree data_arg) +{ + omp_teams_stmt->data_arg = data_arg; +} + /* Return the kernel_phony flag of an OMP_TEAMS_STMT. */ static inline bool @@ -5876,6 +5998,25 @@ gimple_omp_teams_set_grid_phony (gomp_teams *omp_teams_stmt, bool value) omp_teams_stmt->subcode &= ~GF_OMP_TEAMS_GRID_PHONY; } +/* Return the host flag of an OMP_TEAMS_STMT. */ + +static inline bool +gimple_omp_teams_host (const gomp_teams *omp_teams_stmt) +{ + return (gimple_omp_subcode (omp_teams_stmt) & GF_OMP_TEAMS_HOST) != 0; +} + +/* Set host flag of an OMP_TEAMS_STMT to VALUE. */ + +static inline void +gimple_omp_teams_set_host (gomp_teams *omp_teams_stmt, bool value) +{ + if (value) + omp_teams_stmt->subcode |= GF_OMP_TEAMS_HOST; + else + omp_teams_stmt->subcode &= ~GF_OMP_TEAMS_HOST; +} + /* Return the clauses associated with OMP_SECTIONS GS. */ static inline tree diff --git a/gcc/gimplify.c b/gcc/gimplify.c index 509fc2f..61dca24 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -105,6 +105,14 @@ enum gimplify_omp_var_data /* Flag for GOVD_MAP: must be present already. */ GOVD_MAP_FORCE_PRESENT = 524288, + /* Flag for GOVD_MAP: only allocate. */ + GOVD_MAP_ALLOC_ONLY = 1048576, + + /* Flag for GOVD_MAP: only copy back. */ + GOVD_MAP_FROM_ONLY = 2097152, + + GOVD_NONTEMPORAL = 4194304, + GOVD_DATA_SHARE_CLASS = (GOVD_SHARED | GOVD_PRIVATE | GOVD_FIRSTPRIVATE | GOVD_LASTPRIVATE | GOVD_REDUCTION | GOVD_LINEAR | GOVD_LOCAL) @@ -114,34 +122,39 @@ enum gimplify_omp_var_data enum omp_region_type { ORT_WORKSHARE = 0x00, - ORT_SIMD = 0x01, + ORT_TASKGROUP = 0x01, + ORT_SIMD = 0x04, - ORT_PARALLEL = 0x02, - ORT_COMBINED_PARALLEL = 0x03, + ORT_PARALLEL = 0x08, + ORT_COMBINED_PARALLEL = ORT_PARALLEL | 1, - ORT_TASK = 0x04, - ORT_UNTIED_TASK = 0x05, + ORT_TASK = 0x10, + ORT_UNTIED_TASK = ORT_TASK | 1, + ORT_TASKLOOP = ORT_TASK | 2, + ORT_UNTIED_TASKLOOP = ORT_UNTIED_TASK | 2, - ORT_TEAMS = 0x08, - ORT_COMBINED_TEAMS = 0x09, + ORT_TEAMS = 0x20, + ORT_COMBINED_TEAMS = ORT_TEAMS | 1, + ORT_HOST_TEAMS = ORT_TEAMS | 2, + ORT_COMBINED_HOST_TEAMS = ORT_COMBINED_TEAMS | 2, /* Data region. */ - ORT_TARGET_DATA = 0x10, + ORT_TARGET_DATA = 0x40, /* Data region with offloading. */ - ORT_TARGET = 0x20, - ORT_COMBINED_TARGET = 0x21, + ORT_TARGET = 0x80, + ORT_COMBINED_TARGET = ORT_TARGET | 1, /* OpenACC variants. */ - ORT_ACC = 0x40, /* A generic OpenACC region. */ + ORT_ACC = 0x100, /* A generic OpenACC region. */ ORT_ACC_DATA = ORT_ACC | ORT_TARGET_DATA, /* Data construct. */ ORT_ACC_PARALLEL = ORT_ACC | ORT_TARGET, /* Parallel construct */ - ORT_ACC_KERNELS = ORT_ACC | ORT_TARGET | 0x80, /* Kernels construct. */ - ORT_ACC_HOST_DATA = ORT_ACC | ORT_TARGET_DATA | 0x80, /* Host data. */ + ORT_ACC_KERNELS = ORT_ACC | ORT_TARGET | 2, /* Kernels construct. */ + ORT_ACC_HOST_DATA = ORT_ACC | ORT_TARGET_DATA | 2, /* Host data. */ /* Dummy OpenMP region, used to disable expansion of DECL_VALUE_EXPRs in taskloop pre body. */ - ORT_NONE = 0x100 + ORT_NONE = 0x200 }; /* Gimplify hashtable helper. */ @@ -176,6 +189,14 @@ struct gimplify_ctx unsigned in_switch_expr : 1; }; +enum gimplify_defaultmap_kind +{ + GDMK_SCALAR, + GDMK_AGGREGATE, + GDMK_ALLOCATABLE, + GDMK_POINTER +}; + struct gimplify_omp_ctx { struct gimplify_omp_ctx *outer_context; @@ -188,9 +209,8 @@ struct gimplify_omp_ctx enum omp_region_type region_type; bool combined_loop; bool distribute; - bool target_map_scalars_firstprivate; - bool target_map_pointers_as_0len_arrays; bool target_firstprivatize_array_bases; + int defaultmap[4]; }; static struct gimplify_ctx *gimplify_ctxp; @@ -413,6 +433,10 @@ new_omp_context (enum omp_region_type region_type) c->default_kind = OMP_CLAUSE_DEFAULT_SHARED; else c->default_kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED; + c->defaultmap[GDMK_SCALAR] = GOVD_MAP; + c->defaultmap[GDMK_AGGREGATE] = GOVD_MAP; + c->defaultmap[GDMK_ALLOCATABLE] = GOVD_MAP; + c->defaultmap[GDMK_POINTER] = GOVD_MAP; return c; } @@ -738,6 +762,7 @@ gimple_add_tmp_var (tree tmp) struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp; while (ctx && (ctx->region_type == ORT_WORKSHARE + || ctx->region_type == ORT_TASKGROUP || ctx->region_type == ORT_SIMD || ctx->region_type == ORT_ACC)) ctx = ctx->outer_context; @@ -3150,6 +3175,8 @@ maybe_fold_stmt (gimple_stmt_iterator *gsi) for (ctx = gimplify_omp_ctxp; ctx; ctx = ctx->outer_context) if ((ctx->region_type & (ORT_TARGET | ORT_PARALLEL | ORT_TASK)) != 0) return false; + else if ((ctx->region_type & ORT_HOST_TEAMS) == ORT_HOST_TEAMS) + return false; return fold_stmt (gsi); } @@ -6641,12 +6668,13 @@ omp_firstprivatize_variable (struct gimplify_omp_ctx *ctx, tree decl) } else if ((ctx->region_type & ORT_TARGET) != 0) { - if (ctx->target_map_scalars_firstprivate) + if (ctx->defaultmap[GDMK_SCALAR] & GOVD_FIRSTPRIVATE) omp_add_variable (ctx, decl, GOVD_FIRSTPRIVATE); else omp_add_variable (ctx, decl, GOVD_MAP | GOVD_MAP_TO_ONLY); } else if (ctx->region_type != ORT_WORKSHARE + && ctx->region_type != ORT_TASKGROUP && ctx->region_type != ORT_SIMD && ctx->region_type != ORT_ACC && !(ctx->region_type & ORT_TARGET_DATA)) @@ -6760,7 +6788,7 @@ omp_add_variable (struct gimplify_omp_ctx *ctx, tree decl, unsigned int flags) replacement is private, else FIRSTPRIVATE since we'll need the address of the original variable either for SHARED, or for the copy into or out of the context. */ - if (!(flags & GOVD_LOCAL)) + if (!(flags & GOVD_LOCAL) && ctx->region_type != ORT_TASKGROUP) { if (flags & GOVD_MAP) nflags = GOVD_MAP | GOVD_MAP_TO_ONLY | GOVD_EXPLICIT; @@ -6962,6 +6990,8 @@ omp_default_clause (struct gimplify_omp_ctx *ctx, tree decl, if (ctx->region_type & ORT_PARALLEL) rtype = "parallel"; + else if ((ctx->region_type & ORT_TASKLOOP) == ORT_TASKLOOP) + rtype = "taskloop"; else if (ctx->region_type & ORT_TASK) rtype = "task"; else if (ctx->region_type & ORT_TEAMS) @@ -7173,11 +7203,9 @@ omp_notice_variable (struct gimplify_omp_ctx *ctx, tree decl, bool in_code) if (n == NULL) { unsigned nflags = flags; - if (ctx->target_map_pointers_as_0len_arrays - || ctx->target_map_scalars_firstprivate) + if ((ctx->region_type & ORT_ACC) == 0) { bool is_declare_target = false; - bool is_scalar = false; if (is_global_var (decl) && varpool_node::get_create (decl)->offloadable) { @@ -7194,18 +7222,34 @@ omp_notice_variable (struct gimplify_omp_ctx *ctx, tree decl, bool in_code) } is_declare_target = octx == NULL; } - if (!is_declare_target && ctx->target_map_scalars_firstprivate) - is_scalar = lang_hooks.decls.omp_scalar_p (decl); - if (is_declare_target) - ; - else if (ctx->target_map_pointers_as_0len_arrays - && (TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE - || (TREE_CODE (TREE_TYPE (decl)) == REFERENCE_TYPE - && TREE_CODE (TREE_TYPE (TREE_TYPE (decl))) - == POINTER_TYPE))) - nflags |= GOVD_MAP | GOVD_MAP_0LEN_ARRAY; - else if (is_scalar) - nflags |= GOVD_FIRSTPRIVATE; + if (!is_declare_target) + { + int gdmk; + if (TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE + || (TREE_CODE (TREE_TYPE (decl)) == REFERENCE_TYPE + && (TREE_CODE (TREE_TYPE (TREE_TYPE (decl))) + == POINTER_TYPE))) + gdmk = GDMK_POINTER; + else if (lang_hooks.decls.omp_scalar_p (decl)) + gdmk = GDMK_SCALAR; + else + gdmk = GDMK_AGGREGATE; + if (ctx->defaultmap[gdmk] == 0) + { + tree d = lang_hooks.decls.omp_report_decl (decl); + error ("%qE not specified in enclosing %<target%>", + DECL_NAME (d)); + error_at (ctx->location, "enclosing %<target%>"); + } + else if (ctx->defaultmap[gdmk] + & (GOVD_MAP_0LEN_ARRAY | GOVD_FIRSTPRIVATE)) + nflags |= ctx->defaultmap[gdmk]; + else + { + gcc_assert (ctx->defaultmap[gdmk] & GOVD_MAP); + nflags |= ctx->defaultmap[gdmk] & ~GOVD_MAP; + } + } } struct gimplify_omp_ctx *octx = ctx->outer_context; @@ -7236,28 +7280,28 @@ omp_notice_variable (struct gimplify_omp_ctx *ctx, tree decl, bool in_code) } } - { - tree type = TREE_TYPE (decl); - - if (nflags == flags - && gimplify_omp_ctxp->target_firstprivatize_array_bases - && lang_hooks.decls.omp_privatize_by_reference (decl)) - type = TREE_TYPE (type); - if (nflags == flags - && !lang_hooks.types.omp_mappable_type (type)) - { - error ("%qD referenced in target region does not have " - "a mappable type", decl); - nflags |= GOVD_MAP | GOVD_EXPLICIT; - } - else if (nflags == flags) - { - if ((ctx->region_type & ORT_ACC) != 0) - nflags = oacc_default_clause (ctx, decl, flags); - else - nflags |= GOVD_MAP; - } - } + if ((nflags & ~(GOVD_MAP_TO_ONLY | GOVD_MAP_FROM_ONLY + | GOVD_MAP_ALLOC_ONLY)) == flags) + { + tree type = TREE_TYPE (decl); + + if (gimplify_omp_ctxp->target_firstprivatize_array_bases + && lang_hooks.decls.omp_privatize_by_reference (decl)) + type = TREE_TYPE (type); + if (!lang_hooks.types.omp_mappable_type (type)) + { + error ("%qD referenced in target region does not have " + "a mappable type", decl); + nflags |= GOVD_MAP | GOVD_EXPLICIT; + } + else + { + if ((ctx->region_type & ORT_ACC) != 0) + nflags = oacc_default_clause (ctx, decl, flags); + else + nflags |= GOVD_MAP; + } + } found_outer: omp_add_variable (ctx, decl, nflags); } @@ -7275,6 +7319,7 @@ omp_notice_variable (struct gimplify_omp_ctx *ctx, tree decl, bool in_code) if (n == NULL) { if (ctx->region_type == ORT_WORKSHARE + || ctx->region_type == ORT_TASKGROUP || ctx->region_type == ORT_SIMD || ctx->region_type == ORT_ACC || (ctx->region_type & ORT_TARGET_DATA) != 0) @@ -7386,18 +7431,9 @@ omp_is_private (struct gimplify_omp_ctx *ctx, tree decl, int simd) else if ((n->value & GOVD_REDUCTION) != 0) error ("iteration variable %qE should not be reduction", DECL_NAME (decl)); - else if (simd == 0 && (n->value & GOVD_LINEAR) != 0) + else if (simd != 1 && (n->value & GOVD_LINEAR) != 0) error ("iteration variable %qE should not be linear", DECL_NAME (decl)); - else if (simd == 1 && (n->value & GOVD_LASTPRIVATE) != 0) - error ("iteration variable %qE should not be lastprivate", - DECL_NAME (decl)); - else if (simd && (n->value & GOVD_PRIVATE) != 0) - error ("iteration variable %qE should not be private", - DECL_NAME (decl)); - else if (simd == 2 && (n->value & GOVD_LINEAR) != 0) - error ("iteration variable %qE is predetermined linear", - DECL_NAME (decl)); } return (ctx == gimplify_omp_ctxp || (ctx->region_type == ORT_COMBINED_PARALLEL @@ -7405,6 +7441,7 @@ omp_is_private (struct gimplify_omp_ctx *ctx, tree decl, int simd) } if (ctx->region_type != ORT_WORKSHARE + && ctx->region_type != ORT_TASKGROUP && ctx->region_type != ORT_SIMD && ctx->region_type != ORT_ACC) return false; @@ -7462,6 +7499,7 @@ omp_check_private (struct gimplify_omp_ctx *ctx, tree decl, bool copyprivate) } } while (ctx->region_type == ORT_WORKSHARE + || ctx->region_type == ORT_TASKGROUP || ctx->region_type == ORT_SIMD || ctx->region_type == ORT_ACC); return false; @@ -7483,6 +7521,452 @@ find_decl_expr (tree *tp, int *walk_subtrees, void *data) return NULL_TREE; } +/* If *LIST_P contains any OpenMP depend clauses with iterators, + lower all the depend clauses by populating corresponding depend + array. Returns 0 if there are no such depend clauses, or + 2 if all depend clauses should be removed, 1 otherwise. */ + +static int +gimplify_omp_depend (tree *list_p, gimple_seq *pre_p) +{ + tree c; + gimple *g; + size_t n[4] = { 0, 0, 0, 0 }; + bool unused[4]; + tree counts[4] = { NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE }; + tree last_iter = NULL_TREE, last_count = NULL_TREE; + size_t i, j; + location_t first_loc = UNKNOWN_LOCATION; + + for (c = *list_p; c; c = OMP_CLAUSE_CHAIN (c)) + if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND) + { + switch (OMP_CLAUSE_DEPEND_KIND (c)) + { + case OMP_CLAUSE_DEPEND_IN: + i = 2; + break; + case OMP_CLAUSE_DEPEND_OUT: + case OMP_CLAUSE_DEPEND_INOUT: + i = 0; + break; + case OMP_CLAUSE_DEPEND_MUTEXINOUTSET: + i = 1; + break; + case OMP_CLAUSE_DEPEND_DEPOBJ: + i = 3; + break; + case OMP_CLAUSE_DEPEND_SOURCE: + case OMP_CLAUSE_DEPEND_SINK: + continue; + default: + gcc_unreachable (); + } + tree t = OMP_CLAUSE_DECL (c); + if (first_loc == UNKNOWN_LOCATION) + first_loc = OMP_CLAUSE_LOCATION (c); + if (TREE_CODE (t) == TREE_LIST + && TREE_PURPOSE (t) + && TREE_CODE (TREE_PURPOSE (t)) == TREE_VEC) + { + if (TREE_PURPOSE (t) != last_iter) + { + tree tcnt = size_one_node; + for (tree it = TREE_PURPOSE (t); it; it = TREE_CHAIN (it)) + { + if (gimplify_expr (&TREE_VEC_ELT (it, 1), pre_p, NULL, + is_gimple_val, fb_rvalue) == GS_ERROR + || gimplify_expr (&TREE_VEC_ELT (it, 2), pre_p, NULL, + is_gimple_val, fb_rvalue) == GS_ERROR + || gimplify_expr (&TREE_VEC_ELT (it, 3), pre_p, NULL, + is_gimple_val, fb_rvalue) == GS_ERROR + || (gimplify_expr (&TREE_VEC_ELT (it, 4), pre_p, NULL, + is_gimple_val, fb_rvalue) + == GS_ERROR)) + return 2; + tree var = TREE_VEC_ELT (it, 0); + tree begin = TREE_VEC_ELT (it, 1); + tree end = TREE_VEC_ELT (it, 2); + tree step = TREE_VEC_ELT (it, 3); + tree orig_step = TREE_VEC_ELT (it, 4); + tree type = TREE_TYPE (var); + tree stype = TREE_TYPE (step); + location_t loc = DECL_SOURCE_LOCATION (var); + tree endmbegin; + /* Compute count for this iterator as + orig_step > 0 + ? (begin < end ? (end - begin + (step - 1)) / step : 0) + : (begin > end ? (end - begin + (step + 1)) / step : 0) + and compute product of those for the entire depend + clause. */ + if (POINTER_TYPE_P (type)) + endmbegin = fold_build2_loc (loc, POINTER_DIFF_EXPR, + stype, end, begin); + else + endmbegin = fold_build2_loc (loc, MINUS_EXPR, type, + end, begin); + tree stepm1 = fold_build2_loc (loc, MINUS_EXPR, stype, + step, + build_int_cst (stype, 1)); + tree stepp1 = fold_build2_loc (loc, PLUS_EXPR, stype, step, + build_int_cst (stype, 1)); + tree pos = fold_build2_loc (loc, PLUS_EXPR, stype, + unshare_expr (endmbegin), + stepm1); + pos = fold_build2_loc (loc, TRUNC_DIV_EXPR, stype, + pos, step); + tree neg = fold_build2_loc (loc, PLUS_EXPR, stype, + endmbegin, stepp1); + if (TYPE_UNSIGNED (stype)) + { + neg = fold_build1_loc (loc, NEGATE_EXPR, stype, neg); + step = fold_build1_loc (loc, NEGATE_EXPR, stype, step); + } + neg = fold_build2_loc (loc, TRUNC_DIV_EXPR, stype, + neg, step); + step = NULL_TREE; + tree cond = fold_build2_loc (loc, LT_EXPR, + boolean_type_node, + begin, end); + pos = fold_build3_loc (loc, COND_EXPR, stype, cond, pos, + build_int_cst (stype, 0)); + cond = fold_build2_loc (loc, LT_EXPR, boolean_type_node, + end, begin); + neg = fold_build3_loc (loc, COND_EXPR, stype, cond, neg, + build_int_cst (stype, 0)); + tree osteptype = TREE_TYPE (orig_step); + cond = fold_build2_loc (loc, GT_EXPR, boolean_type_node, + orig_step, + build_int_cst (osteptype, 0)); + tree cnt = fold_build3_loc (loc, COND_EXPR, stype, + cond, pos, neg); + cnt = fold_convert_loc (loc, sizetype, cnt); + if (gimplify_expr (&cnt, pre_p, NULL, is_gimple_val, + fb_rvalue) == GS_ERROR) + return 2; + tcnt = size_binop_loc (loc, MULT_EXPR, tcnt, cnt); + } + if (gimplify_expr (&tcnt, pre_p, NULL, is_gimple_val, + fb_rvalue) == GS_ERROR) + return 2; + last_iter = TREE_PURPOSE (t); + last_count = tcnt; + } + if (counts[i] == NULL_TREE) + counts[i] = last_count; + else + counts[i] = size_binop_loc (OMP_CLAUSE_LOCATION (c), + PLUS_EXPR, counts[i], last_count); + } + else + n[i]++; + } + for (i = 0; i < 4; i++) + if (counts[i]) + break; + if (i == 4) + return 0; + + tree total = size_zero_node; + for (i = 0; i < 4; i++) + { + unused[i] = counts[i] == NULL_TREE && n[i] == 0; + if (counts[i] == NULL_TREE) + counts[i] = size_zero_node; + if (n[i]) + counts[i] = size_binop (PLUS_EXPR, counts[i], size_int (n[i])); + if (gimplify_expr (&counts[i], pre_p, NULL, is_gimple_val, + fb_rvalue) == GS_ERROR) + return 2; + total = size_binop (PLUS_EXPR, total, counts[i]); + } + + if (gimplify_expr (&total, pre_p, NULL, is_gimple_val, fb_rvalue) + == GS_ERROR) + return 2; + bool is_old = unused[1] && unused[3]; + tree totalpx = size_binop (PLUS_EXPR, unshare_expr (total), + size_int (is_old ? 1 : 4)); + tree type = build_array_type (ptr_type_node, build_index_type (totalpx)); + tree array = create_tmp_var_raw (type); + TREE_ADDRESSABLE (array) = 1; + if (TREE_CODE (totalpx) != INTEGER_CST) + { + if (!TYPE_SIZES_GIMPLIFIED (TREE_TYPE (array))) + gimplify_type_sizes (TREE_TYPE (array), pre_p); + if (gimplify_omp_ctxp) + { + struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp; + while (ctx + && (ctx->region_type == ORT_WORKSHARE + || ctx->region_type == ORT_TASKGROUP + || ctx->region_type == ORT_SIMD + || ctx->region_type == ORT_ACC)) + ctx = ctx->outer_context; + if (ctx) + omp_add_variable (ctx, array, GOVD_LOCAL | GOVD_SEEN); + } + gimplify_vla_decl (array, pre_p); + } + else + gimple_add_tmp_var (array); + tree r = build4 (ARRAY_REF, ptr_type_node, array, size_int (0), NULL_TREE, + NULL_TREE); + tree tem; + if (!is_old) + { + tem = build2 (MODIFY_EXPR, void_type_node, r, + build_int_cst (ptr_type_node, 0)); + gimplify_and_add (tem, pre_p); + r = build4 (ARRAY_REF, ptr_type_node, array, size_int (1), NULL_TREE, + NULL_TREE); + } + tem = build2 (MODIFY_EXPR, void_type_node, r, + fold_convert (ptr_type_node, total)); + gimplify_and_add (tem, pre_p); + for (i = 1; i < (is_old ? 2 : 4); i++) + { + r = build4 (ARRAY_REF, ptr_type_node, array, size_int (i + !is_old), + NULL_TREE, NULL_TREE); + tem = build2 (MODIFY_EXPR, void_type_node, r, counts[i - 1]); + gimplify_and_add (tem, pre_p); + } + + tree cnts[4]; + for (j = 4; j; j--) + if (!unused[j - 1]) + break; + for (i = 0; i < 4; i++) + { + if (i && (i >= j || unused[i - 1])) + { + cnts[i] = cnts[i - 1]; + continue; + } + cnts[i] = create_tmp_var (sizetype); + if (i == 0) + g = gimple_build_assign (cnts[i], size_int (is_old ? 2 : 5)); + else + { + tree t; + if (is_old) + t = size_binop (PLUS_EXPR, counts[0], size_int (2)); + else + t = size_binop (PLUS_EXPR, cnts[i - 1], counts[i - 1]); + if (gimplify_expr (&t, pre_p, NULL, is_gimple_val, fb_rvalue) + == GS_ERROR) + return 2; + g = gimple_build_assign (cnts[i], t); + } + gimple_seq_add_stmt (pre_p, g); + } + + last_iter = NULL_TREE; + tree last_bind = NULL_TREE; + tree *last_body = NULL; + for (c = *list_p; c; c = OMP_CLAUSE_CHAIN (c)) + if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND) + { + switch (OMP_CLAUSE_DEPEND_KIND (c)) + { + case OMP_CLAUSE_DEPEND_IN: + i = 2; + break; + case OMP_CLAUSE_DEPEND_OUT: + case OMP_CLAUSE_DEPEND_INOUT: + i = 0; + break; + case OMP_CLAUSE_DEPEND_MUTEXINOUTSET: + i = 1; + break; + case OMP_CLAUSE_DEPEND_DEPOBJ: + i = 3; + break; + case OMP_CLAUSE_DEPEND_SOURCE: + case OMP_CLAUSE_DEPEND_SINK: + continue; + default: + gcc_unreachable (); + } + tree t = OMP_CLAUSE_DECL (c); + if (TREE_CODE (t) == TREE_LIST + && TREE_PURPOSE (t) + && TREE_CODE (TREE_PURPOSE (t)) == TREE_VEC) + { + if (TREE_PURPOSE (t) != last_iter) + { + if (last_bind) + gimplify_and_add (last_bind, pre_p); + tree block = TREE_VEC_ELT (TREE_PURPOSE (t), 5); + last_bind = build3 (BIND_EXPR, void_type_node, + BLOCK_VARS (block), NULL, block); + TREE_SIDE_EFFECTS (last_bind) = 1; + SET_EXPR_LOCATION (last_bind, OMP_CLAUSE_LOCATION (c)); + tree *p = &BIND_EXPR_BODY (last_bind); + for (tree it = TREE_PURPOSE (t); it; it = TREE_CHAIN (it)) + { + tree var = TREE_VEC_ELT (it, 0); + tree begin = TREE_VEC_ELT (it, 1); + tree end = TREE_VEC_ELT (it, 2); + tree step = TREE_VEC_ELT (it, 3); + tree orig_step = TREE_VEC_ELT (it, 4); + tree type = TREE_TYPE (var); + location_t loc = DECL_SOURCE_LOCATION (var); + /* Emit: + var = begin; + goto cond_label; + beg_label: + ... + var = var + step; + cond_label: + if (orig_step > 0) { + if (var < end) goto beg_label; + } else { + if (var > end) goto beg_label; + } + for each iterator, with inner iterators added to + the ... above. */ + tree beg_label = create_artificial_label (loc); + tree cond_label = NULL_TREE; + tem = build2_loc (loc, MODIFY_EXPR, void_type_node, + var, begin); + append_to_statement_list_force (tem, p); + tem = build_and_jump (&cond_label); + append_to_statement_list_force (tem, p); + tem = build1 (LABEL_EXPR, void_type_node, beg_label); + append_to_statement_list (tem, p); + tree bind = build3 (BIND_EXPR, void_type_node, NULL_TREE, + NULL_TREE, NULL_TREE); + TREE_SIDE_EFFECTS (bind) = 1; + SET_EXPR_LOCATION (bind, loc); + append_to_statement_list_force (bind, p); + if (POINTER_TYPE_P (type)) + tem = build2_loc (loc, POINTER_PLUS_EXPR, type, + var, fold_convert_loc (loc, sizetype, + step)); + else + tem = build2_loc (loc, PLUS_EXPR, type, var, step); + tem = build2_loc (loc, MODIFY_EXPR, void_type_node, + var, tem); + append_to_statement_list_force (tem, p); + tem = build1 (LABEL_EXPR, void_type_node, cond_label); + append_to_statement_list (tem, p); + tree cond = fold_build2_loc (loc, LT_EXPR, + boolean_type_node, + var, end); + tree pos + = fold_build3_loc (loc, COND_EXPR, void_type_node, + cond, build_and_jump (&beg_label), + void_node); + cond = fold_build2_loc (loc, GT_EXPR, boolean_type_node, + var, end); + tree neg + = fold_build3_loc (loc, COND_EXPR, void_type_node, + cond, build_and_jump (&beg_label), + void_node); + tree osteptype = TREE_TYPE (orig_step); + cond = fold_build2_loc (loc, GT_EXPR, boolean_type_node, + orig_step, + build_int_cst (osteptype, 0)); + tem = fold_build3_loc (loc, COND_EXPR, void_type_node, + cond, pos, neg); + append_to_statement_list_force (tem, p); + p = &BIND_EXPR_BODY (bind); + } + last_body = p; + } + last_iter = TREE_PURPOSE (t); + if (TREE_CODE (TREE_VALUE (t)) == COMPOUND_EXPR) + { + append_to_statement_list (TREE_OPERAND (TREE_VALUE (t), + 0), last_body); + TREE_VALUE (t) = TREE_OPERAND (TREE_VALUE (t), 1); + } + if (error_operand_p (TREE_VALUE (t))) + return 2; + TREE_VALUE (t) = build_fold_addr_expr (TREE_VALUE (t)); + r = build4 (ARRAY_REF, ptr_type_node, array, cnts[i], + NULL_TREE, NULL_TREE); + tem = build2_loc (OMP_CLAUSE_LOCATION (c), MODIFY_EXPR, + void_type_node, r, TREE_VALUE (t)); + append_to_statement_list_force (tem, last_body); + tem = build2_loc (OMP_CLAUSE_LOCATION (c), MODIFY_EXPR, + void_type_node, cnts[i], + size_binop (PLUS_EXPR, cnts[i], size_int (1))); + append_to_statement_list_force (tem, last_body); + TREE_VALUE (t) = null_pointer_node; + } + else + { + if (last_bind) + { + gimplify_and_add (last_bind, pre_p); + last_bind = NULL_TREE; + } + if (TREE_CODE (OMP_CLAUSE_DECL (c)) == COMPOUND_EXPR) + { + gimplify_expr (&TREE_OPERAND (OMP_CLAUSE_DECL (c), 0), pre_p, + NULL, is_gimple_val, fb_rvalue); + OMP_CLAUSE_DECL (c) = TREE_OPERAND (OMP_CLAUSE_DECL (c), 1); + } + if (error_operand_p (OMP_CLAUSE_DECL (c))) + return 2; + OMP_CLAUSE_DECL (c) = build_fold_addr_expr (OMP_CLAUSE_DECL (c)); + if (gimplify_expr (&OMP_CLAUSE_DECL (c), pre_p, NULL, + is_gimple_val, fb_rvalue) == GS_ERROR) + return 2; + r = build4 (ARRAY_REF, ptr_type_node, array, cnts[i], + NULL_TREE, NULL_TREE); + tem = build2 (MODIFY_EXPR, void_type_node, r, OMP_CLAUSE_DECL (c)); + gimplify_and_add (tem, pre_p); + g = gimple_build_assign (cnts[i], size_binop (PLUS_EXPR, cnts[i], + size_int (1))); + gimple_seq_add_stmt (pre_p, g); + } + } + if (last_bind) + gimplify_and_add (last_bind, pre_p); + tree cond = boolean_false_node; + if (is_old) + { + if (!unused[0]) + cond = build2_loc (first_loc, NE_EXPR, boolean_type_node, cnts[0], + size_binop_loc (first_loc, PLUS_EXPR, counts[0], + size_int (2))); + if (!unused[2]) + cond = build2_loc (first_loc, TRUTH_OR_EXPR, boolean_type_node, cond, + build2_loc (first_loc, NE_EXPR, boolean_type_node, + cnts[2], + size_binop_loc (first_loc, PLUS_EXPR, + totalpx, + size_int (1)))); + } + else + { + tree prev = size_int (5); + for (i = 0; i < 4; i++) + { + if (unused[i]) + continue; + prev = size_binop_loc (first_loc, PLUS_EXPR, counts[i], prev); + cond = build2_loc (first_loc, TRUTH_OR_EXPR, boolean_type_node, cond, + build2_loc (first_loc, NE_EXPR, boolean_type_node, + cnts[i], unshare_expr (prev))); + } + } + tem = build3_loc (first_loc, COND_EXPR, void_type_node, cond, + build_call_expr_loc (first_loc, + builtin_decl_explicit (BUILT_IN_TRAP), + 0), void_node); + gimplify_and_add (tem, pre_p); + c = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE_DEPEND); + OMP_CLAUSE_DEPEND_KIND (c) = OMP_CLAUSE_DEPEND_LAST; + OMP_CLAUSE_DECL (c) = build_fold_addr_expr (array); + OMP_CLAUSE_CHAIN (c) = *list_p; + *list_p = c; + return 1; +} + /* Scan the OMP clauses in *LIST_P, installing mappings into a new and previous omp contexts. */ @@ -7495,14 +7979,16 @@ gimplify_scan_omp_clauses (tree *list_p, gimple_seq *pre_p, tree c; hash_map<tree, tree> *struct_map_to_clause = NULL; tree *prev_list_p = NULL; + int handled_depend_iterators = -1; + int nowait = -1; ctx = new_omp_context (region_type); outer_ctx = ctx->outer_context; if (code == OMP_TARGET) { if (!lang_GNU_Fortran ()) - ctx->target_map_pointers_as_0len_arrays = true; - ctx->target_map_scalars_firstprivate = true; + ctx->defaultmap[GDMK_POINTER] = GOVD_MAP | GOVD_MAP_0LEN_ARRAY; + ctx->defaultmap[GDMK_SCALAR] = GOVD_FIRSTPRIVATE; } if (!lang_GNU_Fortran ()) switch (code) @@ -7548,16 +8034,43 @@ gimplify_scan_omp_clauses (tree *list_p, gimple_seq *pre_p, check_non_private = "firstprivate"; goto do_add; case OMP_CLAUSE_LASTPRIVATE: + if (OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c)) + switch (code) + { + case OMP_DISTRIBUTE: + error_at (OMP_CLAUSE_LOCATION (c), + "conditional %<lastprivate%> clause on " + "%<distribute%> construct"); + OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c) = 0; + break; + case OMP_TASKLOOP: + error_at (OMP_CLAUSE_LOCATION (c), + "conditional %<lastprivate%> clause on " + "%<taskloop%> construct"); + OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c) = 0; + break; + default: + break; + } flags = GOVD_LASTPRIVATE | GOVD_SEEN | GOVD_EXPLICIT; check_non_private = "lastprivate"; decl = OMP_CLAUSE_DECL (c); if (error_operand_p (decl)) goto do_add; - else if (outer_ctx - && (outer_ctx->region_type == ORT_COMBINED_PARALLEL - || outer_ctx->region_type == ORT_COMBINED_TEAMS) - && splay_tree_lookup (outer_ctx->variables, - (splay_tree_key) decl) == NULL) + if (OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c) + && !lang_hooks.decls.omp_scalar_p (decl)) + { + error_at (OMP_CLAUSE_LOCATION (c), + "non-scalar variable %qD in conditional " + "%<lastprivate%> clause", decl); + OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c) = 0; + } + if (outer_ctx + && (outer_ctx->region_type == ORT_COMBINED_PARALLEL + || ((outer_ctx->region_type & ORT_COMBINED_TEAMS) + == ORT_COMBINED_TEAMS)) + && splay_tree_lookup (outer_ctx->variables, + (splay_tree_key) decl) == NULL) { omp_add_variable (outer_ctx, decl, GOVD_SHARED | GOVD_SEEN); if (outer_ctx->outer_context) @@ -7603,7 +8116,8 @@ gimplify_scan_omp_clauses (tree *list_p, gimple_seq *pre_p, GOVD_LASTPRIVATE | GOVD_SEEN); octx = octx->outer_context; if (octx - && octx->region_type == ORT_COMBINED_TEAMS + && ((octx->region_type & ORT_COMBINED_TEAMS) + == ORT_COMBINED_TEAMS) && (splay_tree_lookup (octx->variables, (splay_tree_key) decl) == NULL)) @@ -7622,10 +8136,40 @@ gimplify_scan_omp_clauses (tree *list_p, gimple_seq *pre_p, } goto do_add; case OMP_CLAUSE_REDUCTION: + if (OMP_CLAUSE_REDUCTION_TASK (c)) + { + if (region_type == ORT_WORKSHARE) + { + if (nowait == -1) + nowait = omp_find_clause (*list_p, + OMP_CLAUSE_NOWAIT) != NULL_TREE; + if (nowait + && (outer_ctx == NULL + || outer_ctx->region_type != ORT_COMBINED_PARALLEL)) + { + error_at (OMP_CLAUSE_LOCATION (c), + "%<task%> reduction modifier on a construct " + "with a %<nowait%> clause"); + OMP_CLAUSE_REDUCTION_TASK (c) = 0; + } + } + else if ((region_type & ORT_PARALLEL) != ORT_PARALLEL) + { + error_at (OMP_CLAUSE_LOCATION (c), + "invalid %<task%> reduction modifier on construct " + "other than %<parallel%>, %<for%> or %<sections%>"); + OMP_CLAUSE_REDUCTION_TASK (c) = 0; + } + } + /* FALLTHRU */ + case OMP_CLAUSE_IN_REDUCTION: + case OMP_CLAUSE_TASK_REDUCTION: flags = GOVD_REDUCTION | GOVD_SEEN | GOVD_EXPLICIT; /* OpenACC permits reductions on private variables. */ - if (!(region_type & ORT_ACC)) - check_non_private = "reduction"; + if (!(region_type & ORT_ACC) + /* taskgroup is actually not a worksharing region. */ + && code != OMP_TASKGROUP) + check_non_private = omp_clause_code_name[OMP_CLAUSE_CODE (c)]; decl = OMP_CLAUSE_DECL (c); if (TREE_CODE (decl) == MEM_REF) { @@ -7746,7 +8290,8 @@ gimplify_scan_omp_clauses (tree *list_p, gimple_seq *pre_p, && octx == outer_ctx) flags = GOVD_SEEN | GOVD_SHARED; else if (octx - && octx->region_type == ORT_COMBINED_TEAMS) + && ((octx->region_type & ORT_COMBINED_TEAMS) + == ORT_COMBINED_TEAMS)) flags = GOVD_SEEN | GOVD_SHARED; else if (octx && octx->region_type == ORT_COMBINED_TARGET) @@ -8229,6 +8774,14 @@ gimplify_scan_omp_clauses (tree *list_p, gimple_seq *pre_p, } else if (OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_SOURCE) break; + if (handled_depend_iterators == -1) + handled_depend_iterators = gimplify_omp_depend (list_p, pre_p); + if (handled_depend_iterators) + { + if (handled_depend_iterators == 2) + remove = true; + break; + } if (TREE_CODE (OMP_CLAUSE_DECL (c)) == COMPOUND_EXPR) { gimplify_expr (&TREE_OPERAND (OMP_CLAUSE_DECL (c), 0), pre_p, @@ -8311,7 +8864,9 @@ gimplify_scan_omp_clauses (tree *list_p, gimple_seq *pre_p, && OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FIRSTPRIVATE_POINTER) flags |= GOVD_MAP_0LEN_ARRAY; omp_add_variable (ctx, decl, flags); - if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION + if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION + || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION + || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION) && OMP_CLAUSE_REDUCTION_PLACEHOLDER (c)) { omp_add_variable (ctx, OMP_CLAUSE_REDUCTION_PLACEHOLDER (c), @@ -8423,6 +8978,31 @@ gimplify_scan_omp_clauses (tree *list_p, gimple_seq *pre_p, " or private in outer context", DECL_NAME (decl)); } do_notice: + if ((region_type & ORT_TASKLOOP) == ORT_TASKLOOP + && outer_ctx + && outer_ctx->region_type == ORT_COMBINED_PARALLEL + && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION + || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE + || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE)) + { + splay_tree_node on + = splay_tree_lookup (outer_ctx->variables, + (splay_tree_key)decl); + if (on == NULL || (on->value & GOVD_DATA_SHARE_CLASS) == 0) + { + if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION + && TREE_CODE (OMP_CLAUSE_DECL (c)) == MEM_REF + && (TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE + || (TREE_CODE (TREE_TYPE (decl)) == REFERENCE_TYPE + && (TREE_CODE (TREE_TYPE (TREE_TYPE (decl))) + == POINTER_TYPE)))) + omp_firstprivatize_variable (outer_ctx, decl); + else + omp_add_variable (outer_ctx, decl, + GOVD_SEEN | GOVD_SHARED); + omp_notice_variable (outer_ctx, decl, true); + } + } if (outer_ctx) omp_notice_variable (outer_ctx, decl, true); if (check_non_private @@ -8453,7 +9033,9 @@ gimplify_scan_omp_clauses (tree *list_p, gimple_seq *pre_p, for (int i = 0; i < 2; i++) switch (i ? OMP_CLAUSE_IF_MODIFIER (c) : code) { + case VOID_CST: p[i] = "cancel"; break; case OMP_PARALLEL: p[i] = "parallel"; break; + case OMP_SIMD: p[i] = "simd"; break; case OMP_TASK: p[i] = "task"; break; case OMP_TASKLOOP: p[i] = "taskloop"; break; case OMP_TARGET_DATA: p[i] = "target data"; break; @@ -8508,6 +9090,9 @@ gimplify_scan_omp_clauses (tree *list_p, gimple_seq *pre_p, break; case OMP_CLAUSE_NOWAIT: + nowait = 1; + break; + case OMP_CLAUSE_ORDERED: case OMP_CLAUSE_UNTIED: case OMP_CLAUSE_COLLAPSE: @@ -8527,7 +9112,69 @@ gimplify_scan_omp_clauses (tree *list_p, gimple_seq *pre_p, break; case OMP_CLAUSE_DEFAULTMAP: - ctx->target_map_scalars_firstprivate = false; + enum gimplify_defaultmap_kind gdmkmin, gdmkmax; + switch (OMP_CLAUSE_DEFAULTMAP_CATEGORY (c)) + { + case OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED: + gdmkmin = GDMK_SCALAR; + gdmkmax = GDMK_POINTER; + break; + case OMP_CLAUSE_DEFAULTMAP_CATEGORY_SCALAR: + gdmkmin = gdmkmax = GDMK_SCALAR; + break; + case OMP_CLAUSE_DEFAULTMAP_CATEGORY_AGGREGATE: + gdmkmin = gdmkmax = GDMK_AGGREGATE; + break; + case OMP_CLAUSE_DEFAULTMAP_CATEGORY_ALLOCATABLE: + gdmkmin = gdmkmax = GDMK_ALLOCATABLE; + break; + case OMP_CLAUSE_DEFAULTMAP_CATEGORY_POINTER: + gdmkmin = gdmkmax = GDMK_POINTER; + break; + default: + gcc_unreachable (); + } + for (int gdmk = gdmkmin; gdmk <= gdmkmax; gdmk++) + switch (OMP_CLAUSE_DEFAULTMAP_BEHAVIOR (c)) + { + case OMP_CLAUSE_DEFAULTMAP_ALLOC: + ctx->defaultmap[gdmk] = GOVD_MAP | GOVD_MAP_ALLOC_ONLY; + break; + case OMP_CLAUSE_DEFAULTMAP_TO: + ctx->defaultmap[gdmk] = GOVD_MAP | GOVD_MAP_TO_ONLY; + break; + case OMP_CLAUSE_DEFAULTMAP_FROM: + ctx->defaultmap[gdmk] = GOVD_MAP | GOVD_MAP_FROM_ONLY; + break; + case OMP_CLAUSE_DEFAULTMAP_TOFROM: + ctx->defaultmap[gdmk] = GOVD_MAP; + break; + case OMP_CLAUSE_DEFAULTMAP_FIRSTPRIVATE: + ctx->defaultmap[gdmk] = GOVD_FIRSTPRIVATE; + break; + case OMP_CLAUSE_DEFAULTMAP_NONE: + ctx->defaultmap[gdmk] = 0; + break; + case OMP_CLAUSE_DEFAULTMAP_DEFAULT: + switch (gdmk) + { + case GDMK_SCALAR: + ctx->defaultmap[gdmk] = GOVD_FIRSTPRIVATE; + break; + case GDMK_AGGREGATE: + case GDMK_ALLOCATABLE: + ctx->defaultmap[gdmk] = GOVD_MAP; + break; + case GDMK_POINTER: + ctx->defaultmap[gdmk] = GOVD_MAP | GOVD_MAP_0LEN_ARRAY; + break; + default: + gcc_unreachable (); + } + break; + default: + gcc_unreachable (); + } break; case OMP_CLAUSE_ALIGNED: @@ -8548,6 +9195,16 @@ gimplify_scan_omp_clauses (tree *list_p, gimple_seq *pre_p, omp_add_variable (ctx, decl, GOVD_ALIGNED); break; + case OMP_CLAUSE_NONTEMPORAL: + decl = OMP_CLAUSE_DECL (c); + if (error_operand_p (decl)) + { + remove = true; + break; + } + omp_add_variable (ctx, decl, GOVD_NONTEMPORAL); + break; + case OMP_CLAUSE_DEFAULT: ctx->default_kind = OMP_CLAUSE_DEFAULT_KIND (c); break; @@ -8773,7 +9430,7 @@ gimplify_adjust_omp_clauses_1 (splay_tree_node n, void *data) } else if (flags & GOVD_LASTPRIVATE) code = OMP_CLAUSE_LASTPRIVATE; - else if (flags & GOVD_ALIGNED) + else if (flags & (GOVD_ALIGNED | GOVD_NONTEMPORAL)) return 0; else gcc_unreachable (); @@ -8827,7 +9484,9 @@ gimplify_adjust_omp_clauses_1 (splay_tree_node n, void *data) /* Not all combinations of these GOVD_MAP flags are actually valid. */ switch (flags & (GOVD_MAP_TO_ONLY | GOVD_MAP_FORCE - | GOVD_MAP_FORCE_PRESENT)) + | GOVD_MAP_FORCE_PRESENT + | GOVD_MAP_ALLOC_ONLY + | GOVD_MAP_FROM_ONLY)) { case 0: kind = GOMP_MAP_TOFROM; @@ -8838,6 +9497,12 @@ gimplify_adjust_omp_clauses_1 (splay_tree_node n, void *data) case GOVD_MAP_TO_ONLY: kind = GOMP_MAP_TO; break; + case GOVD_MAP_FROM_ONLY: + kind = GOMP_MAP_FROM; + break; + case GOVD_MAP_ALLOC_ONLY: + kind = GOMP_MAP_ALLOC; + break; case GOVD_MAP_TO_ONLY | GOVD_MAP_FORCE: kind = GOMP_MAP_TO | GOMP_MAP_FLAG_FORCE; break; @@ -9062,6 +9727,12 @@ gimplify_adjust_omp_clauses (gimple_seq *pre_p, gimple_seq body, tree *list_p, } break; + case OMP_CLAUSE_NONTEMPORAL: + decl = OMP_CLAUSE_DECL (c); + n = splay_tree_lookup (ctx->variables, (splay_tree_key) decl); + remove = n == NULL || !(n->value & GOVD_SEEN); + break; + case OMP_CLAUSE_MAP: if (code == OMP_TARGET_EXIT_DATA && OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ALWAYS_POINTER) @@ -9229,6 +9900,8 @@ gimplify_adjust_omp_clauses (gimple_seq *pre_p, gimple_seq body, tree *list_p, break; case OMP_CLAUSE_REDUCTION: + case OMP_CLAUSE_IN_REDUCTION: + case OMP_CLAUSE_TASK_REDUCTION: decl = OMP_CLAUSE_DECL (c); /* OpenACC reductions need a present_or_copy data clause. Add one if necessary. Emit error when the reduction is private. */ @@ -9506,18 +10179,32 @@ gimplify_omp_task (tree *expr_p, gimple_seq *pre_p) gimple *g; gimple_seq body = NULL; + if (OMP_TASK_BODY (expr) == NULL_TREE) + for (tree c = OMP_TASK_CLAUSES (expr); c; c = OMP_CLAUSE_CHAIN (c)) + if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND + && OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_MUTEXINOUTSET) + { + error_at (OMP_CLAUSE_LOCATION (c), + "%<mutexinoutset%> kind in %<depend%> clause on a " + "%<taskwait%> construct"); + break; + } + gimplify_scan_omp_clauses (&OMP_TASK_CLAUSES (expr), pre_p, omp_find_clause (OMP_TASK_CLAUSES (expr), OMP_CLAUSE_UNTIED) ? ORT_UNTIED_TASK : ORT_TASK, OMP_TASK); - push_gimplify_context (); + if (OMP_TASK_BODY (expr)) + { + push_gimplify_context (); - g = gimplify_and_return_first (OMP_TASK_BODY (expr), &body); - if (gimple_code (g) == GIMPLE_BIND) - pop_gimplify_context (g); - else - pop_gimplify_context (NULL); + g = gimplify_and_return_first (OMP_TASK_BODY (expr), &body); + if (gimple_code (g) == GIMPLE_BIND) + pop_gimplify_context (g); + else + pop_gimplify_context (NULL); + } gimplify_adjust_omp_clauses (pre_p, body, &OMP_TASK_CLAUSES (expr), OMP_TASK); @@ -9526,6 +10213,8 @@ gimplify_omp_task (tree *expr_p, gimple_seq *pre_p) OMP_TASK_CLAUSES (expr), NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE); + if (OMP_TASK_BODY (expr) == NULL_TREE) + gimple_omp_task_set_taskwait_p (g, true); gimplify_seq_add_stmt (pre_p, g); *expr_p = NULL_TREE; } @@ -9655,7 +10344,9 @@ gimplify_omp_for (tree *expr_p, gimple_seq *pre_p) for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (inner_for_stmt)); i++) if (OMP_FOR_ORIG_DECLS (inner_for_stmt) && TREE_CODE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (inner_for_stmt), - i)) == TREE_LIST) + i)) == TREE_LIST + && TREE_PURPOSE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (inner_for_stmt), + i))) { tree orig = TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (inner_for_stmt), i); /* Class iterators aren't allowed on OMP_SIMD, so the only @@ -9709,6 +10400,43 @@ gimplify_omp_for (tree *expr_p, gimple_seq *pre_p) OMP_CLAUSE_CHAIN (c) = OMP_PARALLEL_CLAUSES (*data[1]); OMP_PARALLEL_CLAUSES (*data[1]) = c; } + /* Similarly, take care of C++ range for temporaries, those should + be firstprivate on OMP_PARALLEL if any. */ + if (data[1]) + for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (inner_for_stmt)); i++) + if (OMP_FOR_ORIG_DECLS (inner_for_stmt) + && TREE_CODE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (inner_for_stmt), + i)) == TREE_LIST + && TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (inner_for_stmt), + i))) + { + tree orig + = TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (inner_for_stmt), i); + tree v = TREE_CHAIN (orig); + tree c = build_omp_clause (UNKNOWN_LOCATION, + OMP_CLAUSE_FIRSTPRIVATE); + /* First add firstprivate clause for the __for_end artificial + decl. */ + OMP_CLAUSE_DECL (c) = TREE_VEC_ELT (v, 1); + if (TREE_CODE (TREE_TYPE (OMP_CLAUSE_DECL (c))) + == REFERENCE_TYPE) + OMP_CLAUSE_FIRSTPRIVATE_NO_REFERENCE (c) = 1; + OMP_CLAUSE_CHAIN (c) = OMP_PARALLEL_CLAUSES (*data[1]); + OMP_PARALLEL_CLAUSES (*data[1]) = c; + if (TREE_VEC_ELT (v, 0)) + { + /* And now the same for __for_range artificial decl if it + exists. */ + c = build_omp_clause (UNKNOWN_LOCATION, + OMP_CLAUSE_FIRSTPRIVATE); + OMP_CLAUSE_DECL (c) = TREE_VEC_ELT (v, 0); + if (TREE_CODE (TREE_TYPE (OMP_CLAUSE_DECL (c))) + == REFERENCE_TYPE) + OMP_CLAUSE_FIRSTPRIVATE_NO_REFERENCE (c) = 1; + OMP_CLAUSE_CHAIN (c) = OMP_PARALLEL_CLAUSES (*data[1]); + OMP_PARALLEL_CLAUSES (*data[1]) = c; + } + } } switch (TREE_CODE (for_stmt)) @@ -9721,9 +10449,9 @@ gimplify_omp_for (tree *expr_p, gimple_seq *pre_p) break; case OMP_TASKLOOP: if (omp_find_clause (OMP_FOR_CLAUSES (for_stmt), OMP_CLAUSE_UNTIED)) - ort = ORT_UNTIED_TASK; + ort = ORT_UNTIED_TASKLOOP; else - ort = ORT_TASK; + ort = ORT_TASKLOOP; break; case OMP_SIMD: ort = ORT_SIMD; @@ -9935,7 +10663,11 @@ gimplify_omp_for (tree *expr_p, gimple_seq *pre_p) { tree orig_decl = TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (for_stmt), i); if (TREE_CODE (orig_decl) == TREE_LIST) - orig_decl = TREE_PURPOSE (orig_decl); + { + orig_decl = TREE_PURPOSE (orig_decl); + if (!orig_decl) + orig_decl = decl; + } gimplify_omp_ctxp->loop_iter_var.quick_push (orig_decl); } else @@ -10027,7 +10759,8 @@ gimplify_omp_for (tree *expr_p, gimple_seq *pre_p) else if (omp_check_private (outer, decl, false)) outer = NULL; } - else if (((outer->region_type & ORT_TASK) != 0) + else if (((outer->region_type & ORT_TASKLOOP) + == ORT_TASKLOOP) && outer->combined_loop && !omp_check_private (gimplify_omp_ctxp, decl, false)) @@ -10066,8 +10799,12 @@ gimplify_omp_for (tree *expr_p, gimple_seq *pre_p) outer = NULL; } if (outer && outer->outer_context - && (outer->outer_context->region_type - == ORT_COMBINED_TEAMS)) + && ((outer->outer_context->region_type + & ORT_COMBINED_TEAMS) == ORT_COMBINED_TEAMS + || (((outer->region_type & ORT_TASKLOOP) + == ORT_TASKLOOP) + && (outer->outer_context->region_type + == ORT_COMBINED_PARALLEL)))) { outer = outer->outer_context; n = splay_tree_lookup (outer->variables, @@ -10114,7 +10851,8 @@ gimplify_omp_for (tree *expr_p, gimple_seq *pre_p) else if (omp_check_private (outer, decl, false)) outer = NULL; } - else if (((outer->region_type & ORT_TASK) != 0) + else if (((outer->region_type & ORT_TASKLOOP) + == ORT_TASKLOOP) && outer->combined_loop && !omp_check_private (gimplify_omp_ctxp, decl, false)) @@ -10153,8 +10891,12 @@ gimplify_omp_for (tree *expr_p, gimple_seq *pre_p) outer = NULL; } if (outer && outer->outer_context - && (outer->outer_context->region_type - == ORT_COMBINED_TEAMS)) + && ((outer->outer_context->region_type + & ORT_COMBINED_TEAMS) == ORT_COMBINED_TEAMS + || (((outer->region_type & ORT_TASKLOOP) + == ORT_TASKLOOP) + && (outer->outer_context->region_type + == ORT_COMBINED_PARALLEL)))) { outer = outer->outer_context; n = splay_tree_lookup (outer->variables, @@ -10496,6 +11238,8 @@ gimplify_omp_for (tree *expr_p, gimple_seq *pre_p) case OMP_CLAUSE_FINAL: case OMP_CLAUSE_MERGEABLE: case OMP_CLAUSE_PRIORITY: + case OMP_CLAUSE_REDUCTION: + case OMP_CLAUSE_IN_REDUCTION: *gtask_clauses_ptr = c; gtask_clauses_ptr = &OMP_CLAUSE_CHAIN (c); break; @@ -10676,7 +11420,7 @@ computable_teams_clause (tree *tp, int *walk_subtrees, void *) (splay_tree_key) *tp); if (n == NULL) { - if (gimplify_omp_ctxp->target_map_scalars_firstprivate) + if (gimplify_omp_ctxp->defaultmap[GDMK_SCALAR] & GOVD_FIRSTPRIVATE) return NULL_TREE; return *tp; } @@ -10848,6 +11592,12 @@ gimplify_omp_workshare (tree *expr_p, gimple_seq *pre_p) break; case OMP_TEAMS: ort = OMP_TEAMS_COMBINED (expr) ? ORT_COMBINED_TEAMS : ORT_TEAMS; + if (gimplify_omp_ctxp == NULL + || (gimplify_omp_ctxp->region_type == ORT_TARGET + && gimplify_omp_ctxp->outer_context == NULL + && lookup_attribute ("omp declare target", + DECL_ATTRIBUTES (current_function_decl)))) + ort = (enum omp_region_type) (ort | ORT_HOST_TEAMS); break; case OACC_HOST_DATA: ort = ORT_ACC_HOST_DATA; @@ -10859,7 +11609,8 @@ gimplify_omp_workshare (tree *expr_p, gimple_seq *pre_p) TREE_CODE (expr)); if (TREE_CODE (expr) == OMP_TARGET) optimize_target_teams (expr, pre_p); - if ((ort & (ORT_TARGET | ORT_TARGET_DATA)) != 0) + if ((ort & (ORT_TARGET | ORT_TARGET_DATA)) != 0 + || (ort & ORT_HOST_TEAMS) == ORT_HOST_TEAMS) { push_gimplify_context (); gimple *g = gimplify_and_return_first (OMP_BODY (expr), &body); @@ -10930,6 +11681,8 @@ gimplify_omp_workshare (tree *expr_p, gimple_seq *pre_p) break; case OMP_TEAMS: stmt = gimple_build_omp_teams (body, OMP_CLAUSES (expr)); + if ((ort & ORT_HOST_TEAMS) == ORT_HOST_TEAMS) + gimple_omp_teams_set_host (as_a <gomp_teams *> (stmt), true); break; default: gcc_unreachable (); @@ -11165,7 +11918,8 @@ gimplify_omp_atomic (tree *expr_p, gimple_seq *pre_p) != GS_ALL_DONE) return GS_ERROR; - loadstmt = gimple_build_omp_atomic_load (tmp_load, addr); + loadstmt = gimple_build_omp_atomic_load (tmp_load, addr, + OMP_ATOMIC_MEMORY_ORDER (*expr_p)); gimplify_seq_add_stmt (pre_p, loadstmt); if (rhs && gimplify_expr (&rhs, pre_p, NULL, is_gimple_val, fb_rvalue) != GS_ALL_DONE) @@ -11173,13 +11927,9 @@ gimplify_omp_atomic (tree *expr_p, gimple_seq *pre_p) if (TREE_CODE (*expr_p) == OMP_ATOMIC_READ) rhs = tmp_load; - storestmt = gimple_build_omp_atomic_store (rhs); + storestmt + = gimple_build_omp_atomic_store (rhs, OMP_ATOMIC_MEMORY_ORDER (*expr_p)); gimplify_seq_add_stmt (pre_p, storestmt); - if (OMP_ATOMIC_SEQ_CST (*expr_p)) - { - gimple_omp_atomic_set_seq_cst (loadstmt); - gimple_omp_atomic_set_seq_cst (storestmt); - } switch (TREE_CODE (*expr_p)) { case OMP_ATOMIC_READ: @@ -12126,7 +12876,6 @@ gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, case OMP_SECTION: case OMP_MASTER: - case OMP_TASKGROUP: case OMP_ORDERED: case OMP_CRITICAL: { @@ -12142,19 +12891,6 @@ gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, case OMP_MASTER: g = gimple_build_omp_master (body); break; - case OMP_TASKGROUP: - { - gimple_seq cleanup = NULL; - tree fn - = builtin_decl_explicit (BUILT_IN_GOMP_TASKGROUP_END); - g = gimple_build_call (fn, 0); - gimple_seq_add_stmt (&cleanup, g); - g = gimple_build_try (body, cleanup, GIMPLE_TRY_FINALLY); - body = NULL; - gimple_seq_add_stmt (&body, g); - g = gimple_build_omp_taskgroup (body); - } - break; case OMP_ORDERED: g = gimplify_omp_ordered (*expr_p, body); break; @@ -12176,6 +12912,28 @@ gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, break; } + case OMP_TASKGROUP: + { + gimple_seq body = NULL; + + tree *pclauses = &OMP_TASKGROUP_CLAUSES (*expr_p); + gimplify_scan_omp_clauses (pclauses, pre_p, ORT_TASKGROUP, + OMP_TASKGROUP); + gimplify_adjust_omp_clauses (pre_p, NULL, pclauses, OMP_TASKGROUP); + gimplify_and_add (OMP_BODY (*expr_p), &body); + gimple_seq cleanup = NULL; + tree fn = builtin_decl_explicit (BUILT_IN_GOMP_TASKGROUP_END); + gimple *g = gimple_build_call (fn, 0); + gimple_seq_add_stmt (&cleanup, g); + g = gimple_build_try (body, cleanup, GIMPLE_TRY_FINALLY); + body = NULL; + gimple_seq_add_stmt (&body, g); + g = gimple_build_omp_taskgroup (body, *pclauses); + gimplify_seq_add_stmt (pre_p, g); + ret = GS_ALL_DONE; + break; + } + case OMP_ATOMIC: case OMP_ATOMIC_READ: case OMP_ATOMIC_CAPTURE_OLD: diff --git a/gcc/lto-streamer-out.c b/gcc/lto-streamer-out.c index e8f6a69..2cb0402 100644 --- a/gcc/lto-streamer-out.c +++ b/gcc/lto-streamer-out.c @@ -1356,6 +1356,8 @@ hash_tree (struct streamer_tree_cache_d *cache, hash_map<tree, hashval_t> *map, val = OMP_CLAUSE_PROC_BIND_KIND (t); break; case OMP_CLAUSE_REDUCTION: + case OMP_CLAUSE_TASK_REDUCTION: + case OMP_CLAUSE_IN_REDUCTION: val = OMP_CLAUSE_REDUCTION_CODE (t); break; default: diff --git a/gcc/omp-builtins.def b/gcc/omp-builtins.def index 55e5633..7005163 100644 --- a/gcc/omp-builtins.def +++ b/gcc/omp-builtins.def @@ -75,6 +75,8 @@ DEF_GOMP_BUILTIN (BUILT_IN_GOMP_BARRIER_CANCEL, "GOMP_barrier_cancel", BT_FN_BOOL, ATTR_NOTHROW_LEAF_LIST) DEF_GOMP_BUILTIN (BUILT_IN_GOMP_TASKWAIT, "GOMP_taskwait", BT_FN_VOID, ATTR_NOTHROW_LEAF_LIST) +DEF_GOMP_BUILTIN (BUILT_IN_GOMP_TASKWAIT_DEPEND, "GOMP_taskwait_depend", + BT_FN_VOID_PTR, ATTR_NOTHROW_LEAF_LIST) DEF_GOMP_BUILTIN (BUILT_IN_GOMP_TASKYIELD, "GOMP_taskyield", BT_FN_VOID, ATTR_NOTHROW_LEAF_LIST) DEF_GOMP_BUILTIN (BUILT_IN_GOMP_TASKGROUP_START, "GOMP_taskgroup_start", @@ -122,6 +124,14 @@ DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_NONMONOTONIC_GUIDED_START, "GOMP_loop_nonmonotonic_guided_start", BT_FN_BOOL_LONG_LONG_LONG_LONG_LONGPTR_LONGPTR, ATTR_NOTHROW_LEAF_LIST) +DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_NONMONOTONIC_RUNTIME_START, + "GOMP_loop_nonmonotonic_runtime_start", + BT_FN_BOOL_LONG_LONG_LONG_LONG_LONGPTR_LONGPTR, + ATTR_NOTHROW_LEAF_LIST) +DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_MAYBE_NONMONOTONIC_RUNTIME_START, + "GOMP_loop_maybe_nonmonotonic_runtime_start", + BT_FN_BOOL_LONG_LONG_LONG_LONG_LONGPTR_LONGPTR, + ATTR_NOTHROW_LEAF_LIST) DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_ORDERED_STATIC_START, "GOMP_loop_ordered_static_start", BT_FN_BOOL_LONG_LONG_LONG_LONG_LONGPTR_LONGPTR, @@ -154,6 +164,18 @@ DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_DOACROSS_RUNTIME_START, "GOMP_loop_doacross_runtime_start", BT_FN_BOOL_UINT_LONGPTR_LONGPTR_LONGPTR, ATTR_NOTHROW_LEAF_LIST) +DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_START, + "GOMP_loop_start", + BT_FN_BOOL_LONG_LONG_LONG_LONG_LONG_LONGPTR_LONGPTR_PTR_PTR, + ATTR_NOTHROW_LEAF_LIST) +DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_ORDERED_START, + "GOMP_loop_ordered_start", + BT_FN_BOOL_LONG_LONG_LONG_LONG_LONG_LONGPTR_LONGPTR_PTR_PTR, + ATTR_NOTHROW_LEAF_LIST) +DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_DOACROSS_START, + "GOMP_loop_doacross_start", + BT_FN_BOOL_UINT_LONGPTR_LONG_LONG_LONGPTR_LONGPTR_PTR_PTR, + ATTR_NOTHROW_LEAF_LIST) DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_STATIC_NEXT, "GOMP_loop_static_next", BT_FN_BOOL_LONGPTR_LONGPTR, ATTR_NOTHROW_LEAF_LIST) DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_DYNAMIC_NEXT, "GOMP_loop_dynamic_next", @@ -168,6 +190,12 @@ DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_NONMONOTONIC_DYNAMIC_NEXT, DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_NONMONOTONIC_GUIDED_NEXT, "GOMP_loop_nonmonotonic_guided_next", BT_FN_BOOL_LONGPTR_LONGPTR, ATTR_NOTHROW_LEAF_LIST) +DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_NONMONOTONIC_RUNTIME_NEXT, + "GOMP_loop_nonmonotonic_runtime_next", + BT_FN_BOOL_LONGPTR_LONGPTR, ATTR_NOTHROW_LEAF_LIST) +DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_MAYBE_NONMONOTONIC_RUNTIME_NEXT, + "GOMP_loop_maybe_nonmonotonic_runtime_next", + BT_FN_BOOL_LONGPTR_LONGPTR, ATTR_NOTHROW_LEAF_LIST) DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_ORDERED_STATIC_NEXT, "GOMP_loop_ordered_static_next", BT_FN_BOOL_LONGPTR_LONGPTR, ATTR_NOTHROW_LEAF_LIST) @@ -204,6 +232,14 @@ DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_ULL_NONMONOTONIC_GUIDED_START, "GOMP_loop_ull_nonmonotonic_guided_start", BT_FN_BOOL_BOOL_ULL_ULL_ULL_ULL_ULLPTR_ULLPTR, ATTR_NOTHROW_LEAF_LIST) +DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_ULL_NONMONOTONIC_RUNTIME_START, + "GOMP_loop_ull_nonmonotonic_runtime_start", + BT_FN_BOOL_BOOL_ULL_ULL_ULL_ULL_ULLPTR_ULLPTR, + ATTR_NOTHROW_LEAF_LIST) +DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_ULL_MAYBE_NONMONOTONIC_RUNTIME_START, + "GOMP_loop_ull_maybe_nonmonotonic_runtime_start", + BT_FN_BOOL_BOOL_ULL_ULL_ULL_ULL_ULLPTR_ULLPTR, + ATTR_NOTHROW_LEAF_LIST) DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_ULL_ORDERED_STATIC_START, "GOMP_loop_ull_ordered_static_start", BT_FN_BOOL_BOOL_ULL_ULL_ULL_ULL_ULLPTR_ULLPTR, @@ -236,6 +272,18 @@ DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_ULL_DOACROSS_RUNTIME_START, "GOMP_loop_ull_doacross_runtime_start", BT_FN_BOOL_UINT_ULLPTR_ULLPTR_ULLPTR, ATTR_NOTHROW_LEAF_LIST) +DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_ULL_START, + "GOMP_loop_ull_start", + BT_FN_BOOL_BOOL_ULL_ULL_ULL_LONG_ULL_ULLPTR_ULLPTR_PTR_PTR, + ATTR_NOTHROW_LEAF_LIST) +DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_ULL_ORDERED_START, + "GOMP_loop_ull_ordered_start", + BT_FN_BOOL_BOOL_ULL_ULL_ULL_LONG_ULL_ULLPTR_ULLPTR_PTR_PTR, + ATTR_NOTHROW_LEAF_LIST) +DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_ULL_DOACROSS_START, + "GOMP_loop_ull_doacross_start", + BT_FN_BOOL_UINT_ULLPTR_LONG_ULL_ULLPTR_ULLPTR_PTR_PTR, + ATTR_NOTHROW_LEAF_LIST) DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_ULL_STATIC_NEXT, "GOMP_loop_ull_static_next", BT_FN_BOOL_ULONGLONGPTR_ULONGLONGPTR, ATTR_NOTHROW_LEAF_LIST) @@ -254,6 +302,12 @@ DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_ULL_NONMONOTONIC_DYNAMIC_NEXT, DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_ULL_NONMONOTONIC_GUIDED_NEXT, "GOMP_loop_ull_nonmonotonic_guided_next", BT_FN_BOOL_ULONGLONGPTR_ULONGLONGPTR, ATTR_NOTHROW_LEAF_LIST) +DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_ULL_NONMONOTONIC_RUNTIME_NEXT, + "GOMP_loop_ull_nonmonotonic_runtime_next", + BT_FN_BOOL_ULONGLONGPTR_ULONGLONGPTR, ATTR_NOTHROW_LEAF_LIST) +DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_ULL_MAYBE_NONMONOTONIC_RUNTIME_NEXT, + "GOMP_loop_ull_maybe_nonmonotonic_runtime_next", + BT_FN_BOOL_ULONGLONGPTR_ULONGLONGPTR, ATTR_NOTHROW_LEAF_LIST) DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_ULL_ORDERED_STATIC_NEXT, "GOMP_loop_ull_ordered_static_next", BT_FN_BOOL_ULONGLONGPTR_ULONGLONGPTR, ATTR_NOTHROW_LEAF_LIST) @@ -293,6 +347,14 @@ DEF_GOMP_BUILTIN (BUILT_IN_GOMP_PARALLEL_LOOP_NONMONOTONIC_GUIDED, "GOMP_parallel_loop_nonmonotonic_guided", BT_FN_VOID_OMPFN_PTR_UINT_LONG_LONG_LONG_LONG_UINT, ATTR_NOTHROW_LIST) +DEF_GOMP_BUILTIN (BUILT_IN_GOMP_PARALLEL_LOOP_NONMONOTONIC_RUNTIME, + "GOMP_parallel_loop_nonmonotonic_runtime", + BT_FN_VOID_OMPFN_PTR_UINT_LONG_LONG_LONG_LONG_UINT, + ATTR_NOTHROW_LIST) +DEF_GOMP_BUILTIN (BUILT_IN_GOMP_PARALLEL_LOOP_MAYBE_NONMONOTONIC_RUNTIME, + "GOMP_parallel_loop_maybe_nonmonotonic_runtime", + BT_FN_VOID_OMPFN_PTR_UINT_LONG_LONG_LONG_LONG_UINT, + ATTR_NOTHROW_LIST) DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_END, "GOMP_loop_end", BT_FN_VOID, ATTR_NOTHROW_LEAF_LIST) DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_END_CANCEL, "GOMP_loop_end_cancel", @@ -313,6 +375,9 @@ DEF_GOMP_BUILTIN (BUILT_IN_GOMP_DOACROSS_ULL_WAIT, "GOMP_doacross_ull_wait", BT_FN_VOID_ULL_VAR, ATTR_NOTHROW_LEAF_LIST) DEF_GOMP_BUILTIN (BUILT_IN_GOMP_PARALLEL, "GOMP_parallel", BT_FN_VOID_OMPFN_PTR_UINT_UINT, ATTR_NOTHROW_LIST) +DEF_GOMP_BUILTIN (BUILT_IN_GOMP_PARALLEL_REDUCTIONS, + "GOMP_parallel_reductions", + BT_FN_UINT_OMPFN_PTR_UINT_UINT, ATTR_NOTHROW_LIST) DEF_GOMP_BUILTIN (BUILT_IN_GOMP_TASK, "GOMP_task", BT_FN_VOID_OMPFN_PTR_OMPCPYFN_LONG_LONG_BOOL_UINT_PTR_INT, ATTR_NOTHROW_LIST) @@ -324,6 +389,8 @@ DEF_GOMP_BUILTIN (BUILT_IN_GOMP_TASKLOOP_ULL, "GOMP_taskloop_ull", ATTR_NOTHROW_LIST) DEF_GOMP_BUILTIN (BUILT_IN_GOMP_SECTIONS_START, "GOMP_sections_start", BT_FN_UINT_UINT, ATTR_NOTHROW_LEAF_LIST) +DEF_GOMP_BUILTIN (BUILT_IN_GOMP_SECTIONS2_START, "GOMP_sections2_start", + BT_FN_UINT_UINT_PTR_PTR, ATTR_NOTHROW_LEAF_LIST) DEF_GOMP_BUILTIN (BUILT_IN_GOMP_SECTIONS_NEXT, "GOMP_sections_next", BT_FN_UINT, ATTR_NOTHROW_LEAF_LIST) DEF_GOMP_BUILTIN (BUILT_IN_GOMP_PARALLEL_SECTIONS, @@ -363,5 +430,19 @@ DEF_GOMP_BUILTIN (BUILT_IN_GOMP_TARGET_ENTER_EXIT_DATA, BT_FN_VOID_INT_SIZE_PTR_PTR_PTR_UINT_PTR, ATTR_NOTHROW_LIST) DEF_GOMP_BUILTIN (BUILT_IN_GOMP_TEAMS, "GOMP_teams", BT_FN_VOID_UINT_UINT, ATTR_NOTHROW_LIST) +DEF_GOMP_BUILTIN (BUILT_IN_GOMP_TEAMS_REG, "GOMP_teams_reg", + BT_FN_VOID_OMPFN_PTR_UINT_UINT_UINT, ATTR_NOTHROW_LIST) +DEF_GOMP_BUILTIN (BUILT_IN_GOMP_TASKGROUP_REDUCTION_REGISTER, + "GOMP_taskgroup_reduction_register", + BT_FN_VOID_PTR, ATTR_NOTHROW_LEAF_LIST) +DEF_GOMP_BUILTIN (BUILT_IN_GOMP_TASKGROUP_REDUCTION_UNREGISTER, + "GOMP_taskgroup_reduction_unregister", + BT_FN_VOID_PTR, ATTR_NOTHROW_LEAF_LIST) +DEF_GOMP_BUILTIN (BUILT_IN_GOMP_TASK_REDUCTION_REMAP, + "GOMP_task_reduction_remap", + BT_FN_VOID_SIZE_SIZE_PTR, ATTR_NOTHROW_LEAF_LIST) +DEF_GOMP_BUILTIN (BUILT_IN_GOMP_WORKSHARE_TASK_REDUCTION_UNREGISTER, + "GOMP_workshare_task_reduction_unregister", + BT_FN_VOID_BOOL, ATTR_NOTHROW_LEAF_LIST) DEF_GOACC_BUILTIN (BUILT_IN_GOACC_DECLARE, "GOACC_declare", BT_FN_VOID_INT_SIZE_PTR_PTR_PTR, ATTR_NOTHROW_LIST) diff --git a/gcc/omp-expand.c b/gcc/omp-expand.c index 1185a26..95b89a6 100644 --- a/gcc/omp-expand.c +++ b/gcc/omp-expand.c @@ -174,6 +174,8 @@ workshare_safe_to_combine_p (basic_block ws_entry_bb) return true; gcc_assert (gimple_code (ws_stmt) == GIMPLE_OMP_FOR); + if (gimple_omp_for_kind (ws_stmt) != GF_OMP_FOR_KIND_FOR) + return false; omp_extract_for_data (as_a <gomp_for *> (ws_stmt), &fd, NULL); @@ -202,7 +204,7 @@ workshare_safe_to_combine_p (basic_block ws_entry_bb) static tree omp_adjust_chunk_size (tree chunk_size, bool simd_schedule) { - if (!simd_schedule) + if (!simd_schedule || integer_zerop (chunk_size)) return chunk_size; poly_uint64 vf = omp_max_vf (); @@ -310,6 +312,13 @@ determine_parallel_type (struct omp_region *region) ws_entry_bb = region->inner->entry; ws_exit_bb = region->inner->exit; + /* Give up for task reductions on the parallel, while it is implementable, + adding another big set of APIs or slowing down the normal paths is + not acceptable. */ + tree pclauses = gimple_omp_parallel_clauses (last_stmt (par_entry_bb)); + if (omp_find_clause (pclauses, OMP_CLAUSE__REDUCTEMP_)) + return; + if (single_succ (par_entry_bb) == ws_entry_bb && single_succ (ws_exit_bb) == par_exit_bb && workshare_safe_to_combine_p (ws_entry_bb) @@ -336,13 +345,14 @@ determine_parallel_type (struct omp_region *region) if (c == NULL || ((OMP_CLAUSE_SCHEDULE_KIND (c) & OMP_CLAUSE_SCHEDULE_MASK) == OMP_CLAUSE_SCHEDULE_STATIC) - || omp_find_clause (clauses, OMP_CLAUSE_ORDERED)) - { - region->is_combined_parallel = false; - region->inner->is_combined_parallel = false; - return; - } + || omp_find_clause (clauses, OMP_CLAUSE_ORDERED) + || omp_find_clause (clauses, OMP_CLAUSE__REDUCTEMP_)) + return; } + else if (region->inner->type == GIMPLE_OMP_SECTIONS + && omp_find_clause (gimple_omp_sections_clauses (ws_stmt), + OMP_CLAUSE__REDUCTEMP_)) + return; region->is_combined_parallel = true; region->inner->is_combined_parallel = true; @@ -534,7 +544,7 @@ adjust_context_and_scope (tree entry_block, tree child_fndecl) } } -/* Build the function calls to GOMP_parallel_start etc to actually +/* Build the function calls to GOMP_parallel etc to actually generate the parallel operation. REGION is the parallel region being expanded. BB is the block where to insert the code. WS_ARGS will be set if this is a call to a combined parallel+workshare @@ -559,7 +569,10 @@ expand_parallel_call (struct omp_region *region, basic_block bb, /* Determine what flavor of GOMP_parallel we will be emitting. */ start_ix = BUILT_IN_GOMP_PARALLEL; - if (is_combined_parallel (region)) + tree rtmp = omp_find_clause (clauses, OMP_CLAUSE__REDUCTEMP_); + if (rtmp) + start_ix = BUILT_IN_GOMP_PARALLEL_REDUCTIONS; + else if (is_combined_parallel (region)) { switch (region->inner->type) { @@ -568,12 +581,19 @@ expand_parallel_call (struct omp_region *region, basic_block bb, switch (region->inner->sched_kind) { case OMP_CLAUSE_SCHEDULE_RUNTIME: - start_ix2 = 3; + if ((region->inner->sched_modifiers + & OMP_CLAUSE_SCHEDULE_NONMONOTONIC) != 0) + start_ix2 = 6; + else if ((region->inner->sched_modifiers + & OMP_CLAUSE_SCHEDULE_MONOTONIC) == 0) + start_ix2 = 7; + else + start_ix2 = 3; break; case OMP_CLAUSE_SCHEDULE_DYNAMIC: case OMP_CLAUSE_SCHEDULE_GUIDED: - if (region->inner->sched_modifiers - & OMP_CLAUSE_SCHEDULE_NONMONOTONIC) + if ((region->inner->sched_modifiers + & OMP_CLAUSE_SCHEDULE_MONOTONIC) == 0) { start_ix2 = 3 + region->inner->sched_kind; break; @@ -716,6 +736,13 @@ expand_parallel_call (struct omp_region *region, basic_block bb, t = build_call_expr_loc_vec (UNKNOWN_LOCATION, builtin_decl_explicit (start_ix), args); + if (rtmp) + { + tree type = TREE_TYPE (OMP_CLAUSE_DECL (rtmp)); + t = build2 (MODIFY_EXPR, type, OMP_CLAUSE_DECL (rtmp), + fold_convert (type, + fold_convert (pointer_sized_int_node, t))); + } force_gimple_operand_gsi (&gsi, t, true, NULL_TREE, false, GSI_CONTINUE_LINKING); @@ -792,6 +819,8 @@ expand_task_call (struct omp_region *region, basic_block bb, if (omp_find_clause (tclauses, OMP_CLAUSE_NOGROUP)) iflags |= GOMP_TASK_FLAG_NOGROUP; ull = fd.iter_type == long_long_unsigned_type_node; + if (omp_find_clause (clauses, OMP_CLAUSE_REDUCTION)) + iflags |= GOMP_TASK_FLAG_REDUCTION; } else if (priority) iflags |= GOMP_TASK_FLAG_PRIORITY; @@ -866,6 +895,82 @@ expand_task_call (struct omp_region *region, basic_block bb, false, GSI_CONTINUE_LINKING); } +/* Build the function call to GOMP_taskwait_depend to actually + generate the taskwait operation. BB is the block where to insert the + code. */ + +static void +expand_taskwait_call (basic_block bb, gomp_task *entry_stmt) +{ + tree clauses = gimple_omp_task_clauses (entry_stmt); + tree depend = omp_find_clause (clauses, OMP_CLAUSE_DEPEND); + if (depend == NULL_TREE) + return; + + depend = OMP_CLAUSE_DECL (depend); + + gimple_stmt_iterator gsi = gsi_last_nondebug_bb (bb); + tree t + = build_call_expr (builtin_decl_explicit (BUILT_IN_GOMP_TASKWAIT_DEPEND), + 1, depend); + + force_gimple_operand_gsi (&gsi, t, true, NULL_TREE, + false, GSI_CONTINUE_LINKING); +} + +/* Build the function call to GOMP_teams_reg to actually + generate the host teams operation. REGION is the teams region + being expanded. BB is the block where to insert the code. */ + +static void +expand_teams_call (basic_block bb, gomp_teams *entry_stmt) +{ + tree clauses = gimple_omp_teams_clauses (entry_stmt); + tree num_teams = omp_find_clause (clauses, OMP_CLAUSE_NUM_TEAMS); + if (num_teams == NULL_TREE) + num_teams = build_int_cst (unsigned_type_node, 0); + else + { + num_teams = OMP_CLAUSE_NUM_TEAMS_EXPR (num_teams); + num_teams = fold_convert (unsigned_type_node, num_teams); + } + tree thread_limit = omp_find_clause (clauses, OMP_CLAUSE_THREAD_LIMIT); + if (thread_limit == NULL_TREE) + thread_limit = build_int_cst (unsigned_type_node, 0); + else + { + thread_limit = OMP_CLAUSE_THREAD_LIMIT_EXPR (thread_limit); + thread_limit = fold_convert (unsigned_type_node, thread_limit); + } + + gimple_stmt_iterator gsi = gsi_last_nondebug_bb (bb); + tree t = gimple_omp_teams_data_arg (entry_stmt), t1; + if (t == NULL) + t1 = null_pointer_node; + else + t1 = build_fold_addr_expr (t); + tree child_fndecl = gimple_omp_teams_child_fn (entry_stmt); + tree t2 = build_fold_addr_expr (child_fndecl); + + adjust_context_and_scope (gimple_block (entry_stmt), child_fndecl); + + vec<tree, va_gc> *args; + vec_alloc (args, 5); + args->quick_push (t2); + args->quick_push (t1); + args->quick_push (num_teams); + args->quick_push (thread_limit); + /* For future extensibility. */ + args->quick_push (build_zero_cst (unsigned_type_node)); + + t = build_call_expr_loc_vec (UNKNOWN_LOCATION, + builtin_decl_explicit (BUILT_IN_GOMP_TEAMS_REG), + args); + + force_gimple_operand_gsi (&gsi, t, true, NULL_TREE, + false, GSI_CONTINUE_LINKING); +} + /* Chain all the DECLs in LIST by their TREE_CHAIN fields. */ static tree @@ -1112,6 +1217,17 @@ expand_omp_taskreg (struct omp_region *region) vec<tree, va_gc> *ws_args; entry_stmt = last_stmt (region->entry); + if (gimple_code (entry_stmt) == GIMPLE_OMP_TASK + && gimple_omp_task_taskwait_p (entry_stmt)) + { + new_bb = region->entry; + gsi = gsi_last_nondebug_bb (region->entry); + gcc_assert (gimple_code (gsi_stmt (gsi)) == GIMPLE_OMP_TASK); + gsi_remove (&gsi, true); + expand_taskwait_call (new_bb, as_a <gomp_task *> (entry_stmt)); + return; + } + child_fn = gimple_omp_taskreg_child_fn (entry_stmt); child_cfun = DECL_STRUCT_FUNCTION (child_fn); @@ -1137,7 +1253,8 @@ expand_omp_taskreg (struct omp_region *region) gsi = gsi_last_nondebug_bb (entry_bb); gcc_assert (gimple_code (gsi_stmt (gsi)) == GIMPLE_OMP_PARALLEL - || gimple_code (gsi_stmt (gsi)) == GIMPLE_OMP_TASK); + || gimple_code (gsi_stmt (gsi)) == GIMPLE_OMP_TASK + || gimple_code (gsi_stmt (gsi)) == GIMPLE_OMP_TEAMS); gsi_remove (&gsi, true); new_bb = entry_bb; @@ -1190,8 +1307,8 @@ expand_omp_taskreg (struct omp_region *region) effectively doing a STRIP_NOPS. */ if (TREE_CODE (arg) == ADDR_EXPR - && TREE_OPERAND (arg, 0) - == gimple_omp_taskreg_data_arg (entry_stmt)) + && (TREE_OPERAND (arg, 0) + == gimple_omp_taskreg_data_arg (entry_stmt))) { parcopy_stmt = stmt; break; @@ -1251,12 +1368,13 @@ expand_omp_taskreg (struct omp_region *region) gsi = gsi_last_nondebug_bb (entry_bb); stmt = gsi_stmt (gsi); gcc_assert (stmt && (gimple_code (stmt) == GIMPLE_OMP_PARALLEL - || gimple_code (stmt) == GIMPLE_OMP_TASK)); + || gimple_code (stmt) == GIMPLE_OMP_TASK + || gimple_code (stmt) == GIMPLE_OMP_TEAMS)); e = split_block (entry_bb, stmt); gsi_remove (&gsi, true); entry_bb = e->dest; edge e2 = NULL; - if (gimple_code (entry_stmt) == GIMPLE_OMP_PARALLEL) + if (gimple_code (entry_stmt) != GIMPLE_OMP_TASK) single_succ_edge (entry_bb)->flags = EDGE_FALLTHRU; else { @@ -1382,6 +1500,8 @@ expand_omp_taskreg (struct omp_region *region) if (gimple_code (entry_stmt) == GIMPLE_OMP_PARALLEL) expand_parallel_call (region, new_bb, as_a <gomp_parallel *> (entry_stmt), ws_args); + else if (gimple_code (entry_stmt) == GIMPLE_OMP_TEAMS) + expand_teams_call (new_bb, as_a <gomp_teams *> (entry_stmt)); else expand_task_call (region, new_bb, as_a <gomp_task *> (entry_stmt)); if (gimple_in_ssa_p (cfun)) @@ -2499,6 +2619,7 @@ expand_omp_for_generic (struct omp_region *region, struct omp_for_data *fd, enum built_in_function start_fn, enum built_in_function next_fn, + tree sched_arg, gimple *inner_stmt) { tree type, istart0, iend0, iend; @@ -2546,6 +2667,30 @@ expand_omp_for_generic (struct omp_region *region, && omp_find_clause (gimple_omp_for_clauses (gsi_stmt (gsi)), OMP_CLAUSE_LASTPRIVATE)) ordered_lastprivate = false; + tree reductions = NULL_TREE; + tree mem = NULL_TREE; + if (sched_arg) + { + if (fd->have_reductemp) + { + tree c = omp_find_clause (gimple_omp_for_clauses (gsi_stmt (gsi)), + OMP_CLAUSE__REDUCTEMP_); + reductions = OMP_CLAUSE_DECL (c); + gcc_assert (TREE_CODE (reductions) == SSA_NAME); + gimple *g = SSA_NAME_DEF_STMT (reductions); + reductions = gimple_assign_rhs1 (g); + OMP_CLAUSE_DECL (c) = reductions; + entry_bb = gimple_bb (g); + edge e = split_block (entry_bb, g); + if (region->entry == entry_bb) + region->entry = e->dest; + gsi = gsi_last_bb (entry_bb); + } + else + reductions = null_pointer_node; + /* For now. */ + mem = null_pointer_node; + } if (fd->collapse > 1 || fd->ordered) { int first_zero_iter1 = -1, first_zero_iter2 = -1; @@ -2732,7 +2877,18 @@ expand_omp_for_generic (struct omp_region *region, { t = fold_convert (fd->iter_type, fd->chunk_size); t = omp_adjust_chunk_size (t, fd->simd_schedule); - if (fd->ordered) + if (sched_arg) + { + if (fd->ordered) + t = build_call_expr (builtin_decl_explicit (start_fn), + 8, t0, t1, sched_arg, t, t3, t4, + reductions, mem); + else + t = build_call_expr (builtin_decl_explicit (start_fn), + 9, t0, t1, t2, sched_arg, t, t3, t4, + reductions, mem); + } + else if (fd->ordered) t = build_call_expr (builtin_decl_explicit (start_fn), 5, t0, t1, t, t3, t4); else @@ -2765,7 +2921,11 @@ expand_omp_for_generic (struct omp_region *region, tree bfn_decl = builtin_decl_explicit (start_fn); t = fold_convert (fd->iter_type, fd->chunk_size); t = omp_adjust_chunk_size (t, fd->simd_schedule); - t = build_call_expr (bfn_decl, 7, t5, t0, t1, t2, t, t3, t4); + if (sched_arg) + t = build_call_expr (bfn_decl, 10, t5, t0, t1, t2, sched_arg, + t, t3, t4, reductions, mem); + else + t = build_call_expr (bfn_decl, 7, t5, t0, t1, t2, t, t3, t4); } else t = build_call_expr (builtin_decl_explicit (start_fn), @@ -2784,6 +2944,17 @@ expand_omp_for_generic (struct omp_region *region, gsi_insert_before (&gsi, gimple_build_assign (arr, clobber), GSI_SAME_STMT); } + if (fd->have_reductemp) + { + gimple *g = gsi_stmt (gsi); + gsi_remove (&gsi, true); + release_ssa_name (gimple_assign_lhs (g)); + + entry_bb = region->entry; + gsi = gsi_last_nondebug_bb (entry_bb); + + gcc_assert (gimple_code (gsi_stmt (gsi)) == GIMPLE_OMP_FOR); + } gsi_insert_after (&gsi, gimple_build_cond_empty (t), GSI_SAME_STMT); /* Remove the GIMPLE_OMP_FOR statement. */ @@ -3082,9 +3253,6 @@ expand_omp_for_generic (struct omp_region *region, else t = builtin_decl_explicit (BUILT_IN_GOMP_LOOP_END); gcall *call_stmt = gimple_build_call (t, 0); - if (gimple_omp_return_lhs (gsi_stmt (gsi))) - gimple_call_set_lhs (call_stmt, gimple_omp_return_lhs (gsi_stmt (gsi))); - gsi_insert_after (&gsi, call_stmt, GSI_SAME_STMT); if (fd->ordered) { tree arr = counts[fd->ordered]; @@ -3093,6 +3261,17 @@ expand_omp_for_generic (struct omp_region *region, gsi_insert_after (&gsi, gimple_build_assign (arr, clobber), GSI_SAME_STMT); } + if (gimple_omp_return_lhs (gsi_stmt (gsi))) + { + gimple_call_set_lhs (call_stmt, gimple_omp_return_lhs (gsi_stmt (gsi))); + if (fd->have_reductemp) + { + gimple *g = gimple_build_assign (reductions, NOP_EXPR, + gimple_call_lhs (call_stmt)); + gsi_insert_after (&gsi, g, GSI_SAME_STMT); + } + } + gsi_insert_after (&gsi, call_stmt, GSI_SAME_STMT); gsi_remove (&gsi, true); /* Connect the new blocks. */ @@ -3275,6 +3454,7 @@ expand_omp_for_static_nochunk (struct omp_region *region, bool broken_loop = region->cont == NULL; tree *counts = NULL; tree n1, n2, step; + tree reductions = NULL_TREE; itype = type = TREE_TYPE (fd->loop.v); if (POINTER_TYPE_P (type)) @@ -3358,6 +3538,29 @@ expand_omp_for_static_nochunk (struct omp_region *region, gsi = gsi_last_bb (entry_bb); } + if (fd->have_reductemp) + { + tree t1 = build_int_cst (long_integer_type_node, 0); + tree t2 = build_int_cst (long_integer_type_node, 1); + tree t3 = build_int_cstu (long_integer_type_node, + (HOST_WIDE_INT_1U << 31) + 1); + tree clauses = gimple_omp_for_clauses (fd->for_stmt); + clauses = omp_find_clause (clauses, OMP_CLAUSE__REDUCTEMP_); + reductions = OMP_CLAUSE_DECL (clauses); + gcc_assert (TREE_CODE (reductions) == SSA_NAME); + gimple *g = SSA_NAME_DEF_STMT (reductions); + reductions = gimple_assign_rhs1 (g); + OMP_CLAUSE_DECL (clauses) = reductions; + gimple_stmt_iterator gsi2 = gsi_for_stmt (g); + tree t + = build_call_expr (builtin_decl_explicit (BUILT_IN_GOMP_LOOP_START), + 9, t1, t2, t2, t3, t1, null_pointer_node, + null_pointer_node, reductions, null_pointer_node); + force_gimple_operand_gsi (&gsi2, t, true, NULL_TREE, + true, GSI_SAME_STMT); + gsi_remove (&gsi2, true); + release_ssa_name (gimple_assign_lhs (g)); + } switch (gimple_omp_for_kind (fd->for_stmt)) { case GF_OMP_FOR_KIND_FOR: @@ -3628,7 +3831,25 @@ expand_omp_for_static_nochunk (struct omp_region *region, if (!gimple_omp_return_nowait_p (gsi_stmt (gsi))) { t = gimple_omp_return_lhs (gsi_stmt (gsi)); - gsi_insert_after (&gsi, omp_build_barrier (t), GSI_SAME_STMT); + if (fd->have_reductemp) + { + tree fn; + if (t) + fn = builtin_decl_explicit (BUILT_IN_GOMP_LOOP_END_CANCEL); + else + fn = builtin_decl_explicit (BUILT_IN_GOMP_LOOP_END); + gcall *g = gimple_build_call (fn, 0); + if (t) + { + gimple_call_set_lhs (g, t); + gsi_insert_after (&gsi, gimple_build_assign (reductions, + NOP_EXPR, t), + GSI_SAME_STMT); + } + gsi_insert_after (&gsi, g, GSI_SAME_STMT); + } + else + gsi_insert_after (&gsi, omp_build_barrier (t), GSI_SAME_STMT); } gsi_remove (&gsi, true); @@ -3765,6 +3986,7 @@ expand_omp_for_static_chunk (struct omp_region *region, bool broken_loop = region->cont == NULL; tree *counts = NULL; tree n1, n2, step; + tree reductions = NULL_TREE; itype = type = TREE_TYPE (fd->loop.v); if (POINTER_TYPE_P (type)) @@ -3852,6 +4074,29 @@ expand_omp_for_static_chunk (struct omp_region *region, gsi = gsi_last_bb (entry_bb); } + if (fd->have_reductemp) + { + tree t1 = build_int_cst (long_integer_type_node, 0); + tree t2 = build_int_cst (long_integer_type_node, 1); + tree t3 = build_int_cstu (long_integer_type_node, + (HOST_WIDE_INT_1U << 31) + 1); + tree clauses = gimple_omp_for_clauses (fd->for_stmt); + clauses = omp_find_clause (clauses, OMP_CLAUSE__REDUCTEMP_); + reductions = OMP_CLAUSE_DECL (clauses); + gcc_assert (TREE_CODE (reductions) == SSA_NAME); + gimple *g = SSA_NAME_DEF_STMT (reductions); + reductions = gimple_assign_rhs1 (g); + OMP_CLAUSE_DECL (clauses) = reductions; + gimple_stmt_iterator gsi2 = gsi_for_stmt (g); + tree t + = build_call_expr (builtin_decl_explicit (BUILT_IN_GOMP_LOOP_START), + 9, t1, t2, t2, t3, t1, null_pointer_node, + null_pointer_node, reductions, null_pointer_node); + force_gimple_operand_gsi (&gsi2, t, true, NULL_TREE, + true, GSI_SAME_STMT); + gsi_remove (&gsi2, true); + release_ssa_name (gimple_assign_lhs (g)); + } switch (gimple_omp_for_kind (fd->for_stmt)) { case GF_OMP_FOR_KIND_FOR: @@ -4155,7 +4400,25 @@ expand_omp_for_static_chunk (struct omp_region *region, if (!gimple_omp_return_nowait_p (gsi_stmt (gsi))) { t = gimple_omp_return_lhs (gsi_stmt (gsi)); - gsi_insert_after (&gsi, omp_build_barrier (t), GSI_SAME_STMT); + if (fd->have_reductemp) + { + tree fn; + if (t) + fn = builtin_decl_explicit (BUILT_IN_GOMP_LOOP_END_CANCEL); + else + fn = builtin_decl_explicit (BUILT_IN_GOMP_LOOP_END); + gcall *g = gimple_build_call (fn, 0); + if (t) + { + gimple_call_set_lhs (g, t); + gsi_insert_after (&gsi, gimple_build_assign (reductions, + NOP_EXPR, t), + GSI_SAME_STMT); + } + gsi_insert_after (&gsi, g, GSI_SAME_STMT); + } + else + gsi_insert_after (&gsi, omp_build_barrier (t), GSI_SAME_STMT); } gsi_remove (&gsi, true); @@ -5690,39 +5953,72 @@ expand_omp_for (struct omp_region *region, gimple *inner_stmt) else { int fn_index, start_ix, next_ix; + unsigned HOST_WIDE_INT sched = 0; + tree sched_arg = NULL_TREE; gcc_assert (gimple_omp_for_kind (fd.for_stmt) == GF_OMP_FOR_KIND_FOR); if (fd.chunk_size == NULL && fd.sched_kind == OMP_CLAUSE_SCHEDULE_STATIC) fd.chunk_size = integer_zero_node; - gcc_assert (fd.sched_kind != OMP_CLAUSE_SCHEDULE_AUTO); switch (fd.sched_kind) { case OMP_CLAUSE_SCHEDULE_RUNTIME: - fn_index = 3; + if ((fd.sched_modifiers & OMP_CLAUSE_SCHEDULE_NONMONOTONIC) != 0) + { + gcc_assert (!fd.have_ordered); + fn_index = 6; + sched = 4; + } + else if ((fd.sched_modifiers & OMP_CLAUSE_SCHEDULE_MONOTONIC) == 0 + && !fd.have_ordered) + fn_index = 7; + else + { + fn_index = 3; + sched = (HOST_WIDE_INT_1U << 31); + } break; case OMP_CLAUSE_SCHEDULE_DYNAMIC: case OMP_CLAUSE_SCHEDULE_GUIDED: - if ((fd.sched_modifiers & OMP_CLAUSE_SCHEDULE_NONMONOTONIC) - && !fd.ordered + if ((fd.sched_modifiers & OMP_CLAUSE_SCHEDULE_MONOTONIC) == 0 && !fd.have_ordered) { fn_index = 3 + fd.sched_kind; + sched = (fd.sched_kind == OMP_CLAUSE_SCHEDULE_GUIDED) + 2; break; } - /* FALLTHRU */ - default: fn_index = fd.sched_kind; + sched = (fd.sched_kind == OMP_CLAUSE_SCHEDULE_GUIDED) + 2; + sched += (HOST_WIDE_INT_1U << 31); break; + case OMP_CLAUSE_SCHEDULE_STATIC: + gcc_assert (fd.have_ordered); + fn_index = 0; + sched = (HOST_WIDE_INT_1U << 31) + 1; + break; + default: + gcc_unreachable (); } if (!fd.ordered) - fn_index += fd.have_ordered * 6; + fn_index += fd.have_ordered * 8; if (fd.ordered) start_ix = ((int)BUILT_IN_GOMP_LOOP_DOACROSS_STATIC_START) + fn_index; else start_ix = ((int)BUILT_IN_GOMP_LOOP_STATIC_START) + fn_index; next_ix = ((int)BUILT_IN_GOMP_LOOP_STATIC_NEXT) + fn_index; + if (fd.have_reductemp) + { + if (fd.ordered) + start_ix = (int)BUILT_IN_GOMP_LOOP_DOACROSS_START; + else if (fd.have_ordered) + start_ix = (int)BUILT_IN_GOMP_LOOP_ORDERED_START; + else + start_ix = (int)BUILT_IN_GOMP_LOOP_START; + sched_arg = build_int_cstu (long_integer_type_node, sched); + if (!fd.chunk_size) + fd.chunk_size = integer_zero_node; + } if (fd.iter_type == long_long_unsigned_type_node) { start_ix += ((int)BUILT_IN_GOMP_LOOP_ULL_STATIC_START @@ -5731,7 +6027,8 @@ expand_omp_for (struct omp_region *region, gimple *inner_stmt) - (int)BUILT_IN_GOMP_LOOP_STATIC_NEXT); } expand_omp_for_generic (region, &fd, (enum built_in_function) start_ix, - (enum built_in_function) next_ix, inner_stmt); + (enum built_in_function) next_ix, sched_arg, + inner_stmt); } if (gimple_in_ssa_p (cfun)) @@ -5831,7 +6128,25 @@ expand_omp_sections (struct omp_region *region) sections_stmt = as_a <gomp_sections *> (gsi_stmt (si)); gcc_assert (gimple_code (sections_stmt) == GIMPLE_OMP_SECTIONS); vin = gimple_omp_sections_control (sections_stmt); - if (!is_combined_parallel (region)) + tree clauses = gimple_omp_sections_clauses (sections_stmt); + tree reductmp = omp_find_clause (clauses, OMP_CLAUSE__REDUCTEMP_); + if (reductmp) + { + tree reductions = OMP_CLAUSE_DECL (reductmp); + gcc_assert (TREE_CODE (reductions) == SSA_NAME); + gimple *g = SSA_NAME_DEF_STMT (reductions); + reductions = gimple_assign_rhs1 (g); + OMP_CLAUSE_DECL (reductmp) = reductions; + gimple_stmt_iterator gsi = gsi_for_stmt (g); + t = build_int_cst (unsigned_type_node, len - 1); + u = builtin_decl_explicit (BUILT_IN_GOMP_SECTIONS2_START); + stmt = gimple_build_call (u, 3, t, reductions, null_pointer_node); + gimple_call_set_lhs (stmt, vin); + gsi_insert_before (&gsi, stmt, GSI_SAME_STMT); + gsi_remove (&gsi, true); + release_ssa_name (gimple_assign_lhs (g)); + } + else if (!is_combined_parallel (region)) { /* If we are not inside a combined parallel+sections region, call GOMP_sections_start. */ @@ -5845,8 +6160,11 @@ expand_omp_sections (struct omp_region *region) u = builtin_decl_explicit (BUILT_IN_GOMP_SECTIONS_NEXT); stmt = gimple_build_call (u, 0); } - gimple_call_set_lhs (stmt, vin); - gsi_insert_after (&si, stmt, GSI_SAME_STMT); + if (!reductmp) + { + gimple_call_set_lhs (stmt, vin); + gsi_insert_after (&si, stmt, GSI_SAME_STMT); + } gsi_remove (&si, true); /* The switch() statement replacing GIMPLE_OMP_SECTIONS_SWITCH goes in @@ -6004,6 +6322,12 @@ expand_omp_synch (struct omp_region *region) || gimple_code (gsi_stmt (si)) == GIMPLE_OMP_ORDERED || gimple_code (gsi_stmt (si)) == GIMPLE_OMP_CRITICAL || gimple_code (gsi_stmt (si)) == GIMPLE_OMP_TEAMS); + if (gimple_code (gsi_stmt (si)) == GIMPLE_OMP_TEAMS + && gimple_omp_teams_host (as_a <gomp_teams *> (gsi_stmt (si)))) + { + expand_omp_taskreg (region); + return; + } gsi_remove (&si, true); single_succ_edge (entry_bb)->flags = EDGE_FALLTHRU; @@ -6016,6 +6340,24 @@ expand_omp_synch (struct omp_region *region) } } +/* Translate enum omp_memory_order to enum memmodel. The two enums + are using different numbers so that OMP_MEMORY_ORDER_UNSPECIFIED + is 0. */ + +static enum memmodel +omp_memory_order_to_memmodel (enum omp_memory_order mo) +{ + switch (mo) + { + case OMP_MEMORY_ORDER_RELAXED: return MEMMODEL_RELAXED; + case OMP_MEMORY_ORDER_ACQUIRE: return MEMMODEL_ACQUIRE; + case OMP_MEMORY_ORDER_RELEASE: return MEMMODEL_RELEASE; + case OMP_MEMORY_ORDER_ACQ_REL: return MEMMODEL_ACQ_REL; + case OMP_MEMORY_ORDER_SEQ_CST: return MEMMODEL_SEQ_CST; + default: gcc_unreachable (); + } +} + /* A subroutine of expand_omp_atomic. Attempt to implement the atomic operation as a normal volatile load. */ @@ -6047,11 +6389,9 @@ expand_omp_atomic_load (basic_block load_bb, tree addr, type = TREE_TYPE (loaded_val); itype = TREE_TYPE (TREE_TYPE (decl)); - call = build_call_expr_loc (loc, decl, 2, addr, - build_int_cst (NULL, - gimple_omp_atomic_seq_cst_p (stmt) - ? MEMMODEL_SEQ_CST - : MEMMODEL_RELAXED)); + enum omp_memory_order omo = gimple_omp_atomic_memory_order (stmt); + tree mo = build_int_cst (NULL, omp_memory_order_to_memmodel (omo)); + call = build_call_expr_loc (loc, decl, 2, addr, mo); if (!useless_type_conversion_p (type, itype)) call = fold_build1_loc (loc, VIEW_CONVERT_EXPR, type, call); call = build2_loc (loc, MODIFY_EXPR, void_type_node, loaded_val, call); @@ -6122,11 +6462,9 @@ expand_omp_atomic_store (basic_block load_bb, tree addr, if (!useless_type_conversion_p (itype, type)) stored_val = fold_build1_loc (loc, VIEW_CONVERT_EXPR, itype, stored_val); - call = build_call_expr_loc (loc, decl, 3, addr, stored_val, - build_int_cst (NULL, - gimple_omp_atomic_seq_cst_p (stmt) - ? MEMMODEL_SEQ_CST - : MEMMODEL_RELAXED)); + enum omp_memory_order omo = gimple_omp_atomic_memory_order (stmt); + tree mo = build_int_cst (NULL, omp_memory_order_to_memmodel (omo)); + call = build_call_expr_loc (loc, decl, 3, addr, stored_val, mo); if (exchange) { if (!useless_type_conversion_p (type, itype)) @@ -6167,7 +6505,6 @@ expand_omp_atomic_fetch_op (basic_block load_bb, enum tree_code code; bool need_old, need_new; machine_mode imode; - bool seq_cst; /* We expect to find the following sequences: @@ -6200,7 +6537,9 @@ expand_omp_atomic_fetch_op (basic_block load_bb, return false; need_new = gimple_omp_atomic_need_value_p (gsi_stmt (gsi)); need_old = gimple_omp_atomic_need_value_p (last_stmt (load_bb)); - seq_cst = gimple_omp_atomic_seq_cst_p (last_stmt (load_bb)); + enum omp_memory_order omo + = gimple_omp_atomic_memory_order (last_stmt (load_bb)); + enum memmodel mo = omp_memory_order_to_memmodel (omo); gcc_checking_assert (!need_old || !need_new); if (!operand_equal_p (gimple_assign_lhs (stmt), stored_val, 0)) @@ -6267,9 +6606,7 @@ expand_omp_atomic_fetch_op (basic_block load_bb, use the RELAXED memory model. */ call = build_call_expr_loc (loc, decl, 3, addr, fold_convert_loc (loc, itype, rhs), - build_int_cst (NULL, - seq_cst ? MEMMODEL_SEQ_CST - : MEMMODEL_RELAXED)); + build_int_cst (NULL, mo)); if (need_old || need_new) { @@ -7921,6 +8258,10 @@ build_omp_regions_1 (basic_block bb, struct omp_region *parent, /* #pragma omp ordered depend is also just a stand-alone directive. */ region = NULL; + else if (code == GIMPLE_OMP_TASK + && gimple_omp_task_taskwait_p (stmt)) + /* #pragma omp taskwait depend(...) is a stand-alone directive. */ + region = NULL; /* ..., this directive becomes the parent for a new region. */ if (region) parent = region; @@ -8111,7 +8452,6 @@ omp_make_gimple_edges (basic_block bb, struct omp_region **region, switch (code) { case GIMPLE_OMP_PARALLEL: - case GIMPLE_OMP_TASK: case GIMPLE_OMP_FOR: case GIMPLE_OMP_SINGLE: case GIMPLE_OMP_TEAMS: @@ -8124,6 +8464,13 @@ omp_make_gimple_edges (basic_block bb, struct omp_region **region, fallthru = true; break; + case GIMPLE_OMP_TASK: + cur_region = new_omp_region (bb, code, cur_region); + fallthru = true; + if (gimple_omp_task_taskwait_p (last)) + cur_region = cur_region->outer; + break; + case GIMPLE_OMP_ORDERED: cur_region = new_omp_region (bb, code, cur_region); fallthru = true; diff --git a/gcc/omp-general.c b/gcc/omp-general.c index cabbbbc..99d8226 100644 --- a/gcc/omp-general.c +++ b/gcc/omp-general.c @@ -36,6 +36,8 @@ along with GCC; see the file COPYING3. If not see #include "stringpool.h" #include "attribs.h" +enum omp_requires omp_requires_mask; + tree omp_find_clause (tree clauses, enum omp_clause_code kind) { @@ -136,6 +138,7 @@ omp_extract_for_data (gomp_for *for_stmt, struct omp_for_data *fd, fd->pre = NULL; fd->have_nowait = distribute || simd; fd->have_ordered = false; + fd->have_reductemp = false; fd->tiling = NULL_TREE; fd->collapse = 1; fd->ordered = 0; @@ -186,6 +189,8 @@ omp_extract_for_data (gomp_for *for_stmt, struct omp_for_data *fd, collapse_iter = &OMP_CLAUSE_TILE_ITERVAR (t); collapse_count = &OMP_CLAUSE_TILE_COUNT (t); break; + case OMP_CLAUSE__REDUCTEMP_: + fd->have_reductemp = true; default: break; } @@ -250,13 +255,45 @@ omp_extract_for_data (gomp_for *for_stmt, struct omp_for_data *fd, loop->cond_code = gimple_omp_for_cond (for_stmt, i); loop->n2 = gimple_omp_for_final (for_stmt, i); - gcc_assert (loop->cond_code != NE_EXPR); + gcc_assert (loop->cond_code != NE_EXPR + || (gimple_omp_for_kind (for_stmt) + != GF_OMP_FOR_KIND_OACC_LOOP)); omp_adjust_for_condition (loc, &loop->cond_code, &loop->n2); t = gimple_omp_for_incr (for_stmt, i); gcc_assert (TREE_OPERAND (t, 0) == var); loop->step = omp_get_for_step_from_incr (loc, t); + if (loop->cond_code == NE_EXPR) + { + gcc_assert (TREE_CODE (loop->step) == INTEGER_CST); + if (TREE_CODE (TREE_TYPE (loop->v)) == INTEGER_TYPE) + { + if (integer_onep (loop->step)) + loop->cond_code = LT_EXPR; + else + { + gcc_assert (integer_minus_onep (loop->step)); + loop->cond_code = GT_EXPR; + } + } + else + { + tree unit = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (loop->v))); + gcc_assert (TREE_CODE (unit) == INTEGER_CST); + if (tree_int_cst_equal (unit, loop->step)) + loop->cond_code = LT_EXPR; + else + { + gcc_assert (wi::neg (wi::to_widest (unit)) + == wi::to_widest (loop->step)); + loop->cond_code = GT_EXPR; + } + } + } + + omp_adjust_for_condition (loc, &loop->cond_code, &loop->n2); + if (simd || (fd->sched_kind == OMP_CLAUSE_SCHEDULE_STATIC && !fd->have_ordered)) @@ -281,9 +318,8 @@ omp_extract_for_data (gomp_for *for_stmt, struct omp_for_data *fd, tree n; if (loop->cond_code == LT_EXPR) - n = fold_build2_loc (loc, - PLUS_EXPR, TREE_TYPE (loop->v), - loop->n2, loop->step); + n = fold_build2_loc (loc, PLUS_EXPR, TREE_TYPE (loop->v), + loop->n2, loop->step); else n = loop->n1; if (TREE_CODE (n) != INTEGER_CST @@ -298,15 +334,13 @@ omp_extract_for_data (gomp_for *for_stmt, struct omp_for_data *fd, if (loop->cond_code == LT_EXPR) { n1 = loop->n1; - n2 = fold_build2_loc (loc, - PLUS_EXPR, TREE_TYPE (loop->v), - loop->n2, loop->step); + n2 = fold_build2_loc (loc, PLUS_EXPR, TREE_TYPE (loop->v), + loop->n2, loop->step); } else { - n1 = fold_build2_loc (loc, - MINUS_EXPR, TREE_TYPE (loop->v), - loop->n2, loop->step); + n1 = fold_build2_loc (loc, MINUS_EXPR, TREE_TYPE (loop->v), + loop->n2, loop->step); n2 = loop->n1; } if (TREE_CODE (n1) != INTEGER_CST @@ -338,27 +372,31 @@ omp_extract_for_data (gomp_for *for_stmt, struct omp_for_data *fd, if (POINTER_TYPE_P (itype)) itype = signed_type_for (itype); t = build_int_cst (itype, (loop->cond_code == LT_EXPR ? -1 : 1)); - t = fold_build2_loc (loc, - PLUS_EXPR, itype, - fold_convert_loc (loc, itype, loop->step), t); + t = fold_build2_loc (loc, PLUS_EXPR, itype, + fold_convert_loc (loc, itype, loop->step), + t); t = fold_build2_loc (loc, PLUS_EXPR, itype, t, - fold_convert_loc (loc, itype, loop->n2)); + fold_convert_loc (loc, itype, loop->n2)); t = fold_build2_loc (loc, MINUS_EXPR, itype, t, - fold_convert_loc (loc, itype, loop->n1)); + fold_convert_loc (loc, itype, loop->n1)); if (TYPE_UNSIGNED (itype) && loop->cond_code == GT_EXPR) - t = fold_build2_loc (loc, TRUNC_DIV_EXPR, itype, - fold_build1_loc (loc, NEGATE_EXPR, itype, t), - fold_build1_loc (loc, NEGATE_EXPR, itype, - fold_convert_loc (loc, itype, - loop->step))); + { + tree step = fold_convert_loc (loc, itype, loop->step); + t = fold_build2_loc (loc, TRUNC_DIV_EXPR, itype, + fold_build1_loc (loc, NEGATE_EXPR, + itype, t), + fold_build1_loc (loc, NEGATE_EXPR, + itype, step)); + } else t = fold_build2_loc (loc, TRUNC_DIV_EXPR, itype, t, - fold_convert_loc (loc, itype, loop->step)); + fold_convert_loc (loc, itype, + loop->step)); t = fold_convert_loc (loc, long_long_unsigned_type_node, t); if (count != NULL_TREE) - count = fold_build2_loc (loc, - MULT_EXPR, long_long_unsigned_type_node, - count, t); + count = fold_build2_loc (loc, MULT_EXPR, + long_long_unsigned_type_node, + count, t); else count = t; if (TREE_CODE (count) != INTEGER_CST) diff --git a/gcc/omp-general.h b/gcc/omp-general.h index 66f0a33..b847506 100644 --- a/gcc/omp-general.h +++ b/gcc/omp-general.h @@ -62,7 +62,7 @@ struct omp_for_data tree tiling; /* Tiling values (if non null). */ int collapse; /* Collapsed loops, 1 for a non-collapsed loop. */ int ordered; - bool have_nowait, have_ordered, simd_schedule; + bool have_nowait, have_ordered, simd_schedule, have_reductemp; unsigned char sched_modifiers; enum omp_clause_schedule_kind sched_kind; struct omp_for_data_loop *loops; @@ -89,4 +89,16 @@ extern bool offloading_function_p (tree fn); extern int oacc_get_fn_dim_size (tree fn, int axis); extern int oacc_get_ifn_dim_arg (const gimple *stmt); +enum omp_requires { + OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER = 0xf, + OMP_REQUIRES_UNIFIED_ADDRESS = 0x10, + OMP_REQUIRES_UNIFIED_SHARED_MEMORY = 0x20, + OMP_REQUIRES_DYNAMIC_ALLOCATORS = 0x40, + OMP_REQUIRES_REVERSE_OFFLOAD = 0x80, + OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER_USED = 0x100, + OMP_REQUIRES_TARGET_USED = 0x200 +}; + +extern GTY(()) enum omp_requires omp_requires_mask; + #endif /* GCC_OMP_GENERAL_H */ diff --git a/gcc/omp-grid.c b/gcc/omp-grid.c index 6edc92f..d443bce 100644 --- a/gcc/omp-grid.c +++ b/gcc/omp-grid.c @@ -1053,8 +1053,8 @@ grid_eliminate_combined_simd_part (gomp_for *parloop) while (*tgt) tgt = &OMP_CLAUSE_CHAIN (*tgt); - /* Copy over all clauses, except for linaer clauses, which are turned into - private clauses, and all other simd-specificl clauses, which are + /* Copy over all clauses, except for linear clauses, which are turned into + private clauses, and all other simd-specific clauses, which are ignored. */ tree *pc = gimple_omp_for_clauses_ptr (simd); while (*pc) @@ -1083,7 +1083,7 @@ grid_eliminate_combined_simd_part (gomp_for *parloop) *pc = OMP_CLAUSE_CHAIN (c); OMP_CLAUSE_CHAIN (c) = NULL; *tgt = c; - tgt = &OMP_CLAUSE_CHAIN(c); + tgt = &OMP_CLAUSE_CHAIN (c); break; } } diff --git a/gcc/omp-low.c b/gcc/omp-low.c index b06ddb3..ca78d7a 100644 --- a/gcc/omp-low.c +++ b/gcc/omp-low.c @@ -114,6 +114,15 @@ struct omp_context otherwise. */ gimple *simt_stmt; + /* For task reductions registered in this context, a vector containing + the length of the private copies block (if constant, otherwise NULL) + and then offsets (if constant, otherwise NULL) for each entry. */ + vec<tree> task_reductions; + + /* And a hash map from the reduction clauses to the registered array + elts. */ + hash_map<tree, unsigned> *task_reduction_map; + /* Nesting depth of this context. Used to beautify error messages re invalid gotos. The outermost ctx is depth 1, with depth 0 being reserved for the main body of the function. */ @@ -280,12 +289,23 @@ is_taskloop_ctx (omp_context *ctx) } -/* Return true if CTX is for an omp parallel or omp task. */ +/* Return true if CTX is for a host omp teams. */ + +static inline bool +is_host_teams_ctx (omp_context *ctx) +{ + return gimple_code (ctx->stmt) == GIMPLE_OMP_TEAMS + && gimple_omp_teams_host (as_a <gomp_teams *> (ctx->stmt)); +} + +/* Return true if CTX is for an omp parallel or omp task or host omp teams + (the last one is strictly not a task region in OpenMP speak, but we + need to treat it similarly). */ static inline bool is_taskreg_ctx (omp_context *ctx) { - return is_parallel_ctx (ctx) || is_task_ctx (ctx); + return is_parallel_ctx (ctx) || is_task_ctx (ctx) || is_host_teams_ctx (ctx); } /* Return true if EXPR is variable sized. */ @@ -371,7 +391,7 @@ use_pointer_for_field (tree decl, omp_context *shared_ctx) be passing an address in this case? Should we simply assert this to be false, or should we have a cleanup pass that removes these from the list of mappings? */ - if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)) + if (is_global_var (maybe_lookup_decl_in_outer_ctx (decl, shared_ctx))) return true; /* For variables with DECL_HAS_VALUE_EXPR_P set, we cannot tell @@ -522,6 +542,9 @@ build_outer_var_ref (tree var, omp_context *ctx, enum omp_clause_code code = OMP_CLAUSE_ERROR) { tree x; + omp_context *outer = ctx->outer; + while (outer && gimple_code (outer->stmt) == GIMPLE_OMP_TASKGROUP) + outer = outer->outer; if (is_global_var (maybe_lookup_decl_in_outer_ctx (var, ctx))) x = var; @@ -548,44 +571,43 @@ build_outer_var_ref (tree var, omp_context *ctx, Similarly for OMP_CLAUSE_PRIVATE with outer ref, that can refer to private vars in all worksharing constructs. */ x = NULL_TREE; - if (ctx->outer && is_taskreg_ctx (ctx)) - x = lookup_decl (var, ctx->outer); - else if (ctx->outer) + if (outer && is_taskreg_ctx (outer)) + x = lookup_decl (var, outer); + else if (outer) x = maybe_lookup_decl_in_outer_ctx (var, ctx); if (x == NULL_TREE) x = var; } else if (code == OMP_CLAUSE_LASTPRIVATE && is_taskloop_ctx (ctx)) { - gcc_assert (ctx->outer); + gcc_assert (outer); splay_tree_node n - = splay_tree_lookup (ctx->outer->field_map, + = splay_tree_lookup (outer->field_map, (splay_tree_key) &DECL_UID (var)); if (n == NULL) { - if (is_global_var (maybe_lookup_decl_in_outer_ctx (var, ctx->outer))) + if (is_global_var (maybe_lookup_decl_in_outer_ctx (var, outer))) x = var; else - x = lookup_decl (var, ctx->outer); + x = lookup_decl (var, outer); } else { tree field = (tree) n->value; /* If the receiver record type was remapped in the child function, remap the field into the new record type. */ - x = maybe_lookup_field (field, ctx->outer); + x = maybe_lookup_field (field, outer); if (x != NULL) field = x; - x = build_simple_mem_ref (ctx->outer->receiver_decl); + x = build_simple_mem_ref (outer->receiver_decl); x = omp_build_component_ref (x, field); - if (use_pointer_for_field (var, ctx->outer)) + if (use_pointer_for_field (var, outer)) x = build_simple_mem_ref (x); } } - else if (ctx->outer) + else if (outer) { - omp_context *outer = ctx->outer; if (gimple_code (outer->stmt) == GIMPLE_OMP_GRID_BODY) { outer = outer->outer; @@ -925,6 +947,12 @@ delete_omp_context (splay_tree_value value) if (is_task_ctx (ctx)) finalize_task_copyfn (as_a <gomp_task *> (ctx->stmt)); + if (ctx->task_reduction_map) + { + ctx->task_reductions.release (); + delete ctx->task_reduction_map; + } + XDELETE (ctx); } @@ -1011,8 +1039,10 @@ scan_sharing_clauses (tree clauses, omp_context *ctx) case OMP_CLAUSE_SHARED: decl = OMP_CLAUSE_DECL (c); - /* Ignore shared directives in teams construct. */ - if (gimple_code (ctx->stmt) == GIMPLE_OMP_TEAMS) + /* Ignore shared directives in teams construct inside of + target construct. */ + if (gimple_code (ctx->stmt) == GIMPLE_OMP_TEAMS + && !is_host_teams_ctx (ctx)) { /* Global variables don't need to be copied, the receiver side will use them directly. */ @@ -1050,9 +1080,9 @@ scan_sharing_clauses (tree clauses, omp_context *ctx) goto do_private; case OMP_CLAUSE_REDUCTION: + case OMP_CLAUSE_IN_REDUCTION: decl = OMP_CLAUSE_DECL (c); - if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION - && TREE_CODE (decl) == MEM_REF) + if (TREE_CODE (decl) == MEM_REF) { tree t = TREE_OPERAND (decl, 0); if (TREE_CODE (t) == POINTER_PLUS_EXPR) @@ -1062,14 +1092,52 @@ scan_sharing_clauses (tree clauses, omp_context *ctx) t = TREE_OPERAND (t, 0); install_var_local (t, ctx); if (is_taskreg_ctx (ctx) - && !is_global_var (maybe_lookup_decl_in_outer_ctx (t, ctx)) - && !is_variable_sized (t)) + && (!is_global_var (maybe_lookup_decl_in_outer_ctx (t, ctx)) + || (is_task_ctx (ctx) + && (TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE + || (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE + && (TREE_CODE (TREE_TYPE (TREE_TYPE (t))) + == POINTER_TYPE))))) + && !is_variable_sized (t) + && (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION + || (!OMP_CLAUSE_REDUCTION_TASK (c) + && !is_task_ctx (ctx)))) { - by_ref = use_pointer_for_field (t, ctx); - install_var_field (t, by_ref, 3, ctx); + by_ref = use_pointer_for_field (t, NULL); + if (is_task_ctx (ctx) + && TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE + && TREE_CODE (TREE_TYPE (TREE_TYPE (t))) == POINTER_TYPE) + { + install_var_field (t, false, 1, ctx); + install_var_field (t, by_ref, 2, ctx); + } + else + install_var_field (t, by_ref, 3, ctx); } break; } + if (is_task_ctx (ctx) + || (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION + && OMP_CLAUSE_REDUCTION_TASK (c) + && is_parallel_ctx (ctx))) + { + /* Global variables don't need to be copied, + the receiver side will use them directly. */ + if (!is_global_var (maybe_lookup_decl_in_outer_ctx (decl, ctx))) + { + by_ref = use_pointer_for_field (decl, ctx); + if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION) + install_var_field (decl, by_ref, 3, ctx); + } + install_var_local (decl, ctx); + break; + } + if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION + && OMP_CLAUSE_REDUCTION_TASK (c)) + { + install_var_local (decl, ctx); + break; + } goto do_private; case OMP_CLAUSE_LASTPRIVATE: @@ -1142,6 +1210,7 @@ scan_sharing_clauses (tree clauses, omp_context *ctx) goto do_private; case OMP_CLAUSE__LOOPTEMP_: + case OMP_CLAUSE__REDUCTEMP_: gcc_assert (is_taskreg_ctx (ctx)); decl = OMP_CLAUSE_DECL (c); install_var_field (decl, false, 3, ctx); @@ -1323,8 +1392,10 @@ scan_sharing_clauses (tree clauses, omp_context *ctx) case OMP_CLAUSE_TILE: case OMP_CLAUSE__SIMT_: case OMP_CLAUSE_DEFAULT: + case OMP_CLAUSE_NONTEMPORAL: case OMP_CLAUSE_IF_PRESENT: case OMP_CLAUSE_FINALIZE: + case OMP_CLAUSE_TASK_REDUCTION: break; case OMP_CLAUSE_ALIGNED: @@ -1382,6 +1453,7 @@ scan_sharing_clauses (tree clauses, omp_context *ctx) break; case OMP_CLAUSE_REDUCTION: + case OMP_CLAUSE_IN_REDUCTION: decl = OMP_CLAUSE_DECL (c); if (TREE_CODE (decl) != MEM_REF) { @@ -1393,9 +1465,16 @@ scan_sharing_clauses (tree clauses, omp_context *ctx) scan_array_reductions = true; break; + case OMP_CLAUSE_TASK_REDUCTION: + if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c)) + scan_array_reductions = true; + break; + case OMP_CLAUSE_SHARED: - /* Ignore shared directives in teams construct. */ - if (gimple_code (ctx->stmt) == GIMPLE_OMP_TEAMS) + /* Ignore shared directives in teams construct inside of + target construct. */ + if (gimple_code (ctx->stmt) == GIMPLE_OMP_TEAMS + && !is_host_teams_ctx (ctx)) break; decl = OMP_CLAUSE_DECL (c); if (is_global_var (maybe_lookup_decl_in_outer_ctx (decl, ctx))) @@ -1472,6 +1551,7 @@ scan_sharing_clauses (tree clauses, omp_context *ctx) case OMP_CLAUSE_ALIGNED: case OMP_CLAUSE_DEPEND: case OMP_CLAUSE__LOOPTEMP_: + case OMP_CLAUSE__REDUCTEMP_: case OMP_CLAUSE_TO: case OMP_CLAUSE_FROM: case OMP_CLAUSE_PRIORITY: @@ -1482,6 +1562,7 @@ scan_sharing_clauses (tree clauses, omp_context *ctx) case OMP_CLAUSE_NOGROUP: case OMP_CLAUSE_DEFAULTMAP: case OMP_CLAUSE_USE_DEVICE_PTR: + case OMP_CLAUSE_NONTEMPORAL: case OMP_CLAUSE_ASYNC: case OMP_CLAUSE_WAIT: case OMP_CLAUSE_NUM_GANGS: @@ -1511,7 +1592,9 @@ scan_sharing_clauses (tree clauses, omp_context *ctx) if (scan_array_reductions) { for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c)) - if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION + if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION + || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION + || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION) && OMP_CLAUSE_REDUCTION_PLACEHOLDER (c)) { scan_omp (&OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c), ctx); @@ -1700,7 +1783,7 @@ omp_find_combined_for (gimple_stmt_iterator *gsi_p, return NULL; } -/* Add _LOOPTEMP_ clauses on OpenMP parallel or task. */ +/* Add _LOOPTEMP_/_REDUCTEMP_ clauses on OpenMP parallel or task. */ static void add_taskreg_looptemp_clauses (enum gf_mask msk, gimple *stmt, @@ -1747,6 +1830,18 @@ add_taskreg_looptemp_clauses (enum gf_mask msk, gimple *stmt, gimple_omp_taskreg_set_clauses (stmt, c); } } + if (msk == GF_OMP_FOR_KIND_TASKLOOP + && omp_find_clause (gimple_omp_task_clauses (stmt), + OMP_CLAUSE_REDUCTION)) + { + tree type = build_pointer_type (pointer_sized_int_node); + tree temp = create_tmp_var (type); + tree c = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE__REDUCTEMP_); + insert_decl_map (&outer_ctx->cb, temp, temp); + OMP_CLAUSE_DECL (c) = temp; + OMP_CLAUSE_CHAIN (c) = gimple_omp_task_clauses (stmt); + gimple_omp_task_set_clauses (stmt, c); + } } /* Scan an OpenMP parallel directive. */ @@ -1771,6 +1866,23 @@ scan_omp_parallel (gimple_stmt_iterator *gsi, omp_context *outer_ctx) if (gimple_omp_parallel_combined_p (stmt)) add_taskreg_looptemp_clauses (GF_OMP_FOR_KIND_FOR, stmt, outer_ctx); + for (tree c = omp_find_clause (gimple_omp_parallel_clauses (stmt), + OMP_CLAUSE_REDUCTION); + c; c = omp_find_clause (OMP_CLAUSE_CHAIN (c), OMP_CLAUSE_REDUCTION)) + if (OMP_CLAUSE_REDUCTION_TASK (c)) + { + tree type = build_pointer_type (pointer_sized_int_node); + tree temp = create_tmp_var (type); + tree c = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE__REDUCTEMP_); + if (outer_ctx) + insert_decl_map (&outer_ctx->cb, temp, temp); + OMP_CLAUSE_DECL (c) = temp; + OMP_CLAUSE_CHAIN (c) = gimple_omp_parallel_clauses (stmt); + gimple_omp_parallel_set_clauses (stmt, c); + break; + } + else if (OMP_CLAUSE_CHAIN (c) == NULL_TREE) + break; ctx = new_omp_context (stmt, outer_ctx); taskreg_contexts.safe_push (ctx); @@ -1810,6 +1922,7 @@ scan_omp_task (gimple_stmt_iterator *gsi, omp_context *outer_ctx) /* Ignore task directives with empty bodies, unless they have depend clause. */ if (optimize > 0 + && gimple_omp_body (stmt) && empty_body_p (gimple_omp_body (stmt)) && !omp_find_clause (gimple_omp_task_clauses (stmt), OMP_CLAUSE_DEPEND)) { @@ -1821,6 +1934,13 @@ scan_omp_task (gimple_stmt_iterator *gsi, omp_context *outer_ctx) add_taskreg_looptemp_clauses (GF_OMP_FOR_KIND_TASKLOOP, stmt, outer_ctx); ctx = new_omp_context (stmt, outer_ctx); + + if (gimple_omp_task_taskwait_p (stmt)) + { + scan_sharing_clauses (gimple_omp_task_clauses (stmt), ctx); + return; + } + taskreg_contexts.safe_push (ctx); if (taskreg_nesting_level > 1) ctx->is_nested = true; @@ -1897,7 +2017,7 @@ finish_taskreg_scan (omp_context *ctx) return; /* If any task_shared_vars were needed, verify all - OMP_CLAUSE_SHARED clauses on GIMPLE_OMP_{PARALLEL,TASK} + OMP_CLAUSE_SHARED clauses on GIMPLE_OMP_{PARALLEL,TASK,TEAMS} statements if use_pointer_for_field hasn't changed because of that. If it did, update field types now. */ if (task_shared_vars) @@ -1943,6 +2063,30 @@ finish_taskreg_scan (omp_context *ctx) if (gimple_code (ctx->stmt) == GIMPLE_OMP_PARALLEL) { + tree clauses = gimple_omp_parallel_clauses (ctx->stmt); + tree c = omp_find_clause (clauses, OMP_CLAUSE__REDUCTEMP_); + if (c) + { + /* Move the _reductemp_ clause first. GOMP_parallel_reductions + expects to find it at the start of data. */ + tree f = lookup_field (OMP_CLAUSE_DECL (c), ctx); + tree *p = &TYPE_FIELDS (ctx->record_type); + while (*p) + if (*p == f) + { + *p = DECL_CHAIN (*p); + break; + } + else + p = &DECL_CHAIN (*p); + DECL_CHAIN (f) = TYPE_FIELDS (ctx->record_type); + TYPE_FIELDS (ctx->record_type) = f; + } + layout_type (ctx->record_type); + fixup_child_record_type (ctx); + } + else if (gimple_code (ctx->stmt) == GIMPLE_OMP_TEAMS) + { layout_type (ctx->record_type); fixup_child_record_type (ctx); } @@ -1969,33 +2113,50 @@ finish_taskreg_scan (omp_context *ctx) /* Move fields corresponding to first and second _looptemp_ clause first. There are filled by GOMP_taskloop and thus need to be in specific positions. */ - tree c1 = gimple_omp_task_clauses (ctx->stmt); - c1 = omp_find_clause (c1, OMP_CLAUSE__LOOPTEMP_); + tree clauses = gimple_omp_task_clauses (ctx->stmt); + tree c1 = omp_find_clause (clauses, OMP_CLAUSE__LOOPTEMP_); tree c2 = omp_find_clause (OMP_CLAUSE_CHAIN (c1), OMP_CLAUSE__LOOPTEMP_); + tree c3 = omp_find_clause (clauses, OMP_CLAUSE__REDUCTEMP_); tree f1 = lookup_field (OMP_CLAUSE_DECL (c1), ctx); tree f2 = lookup_field (OMP_CLAUSE_DECL (c2), ctx); + tree f3 = c3 ? lookup_field (OMP_CLAUSE_DECL (c3), ctx) : NULL_TREE; p = &TYPE_FIELDS (ctx->record_type); while (*p) - if (*p == f1 || *p == f2) + if (*p == f1 || *p == f2 || *p == f3) *p = DECL_CHAIN (*p); else p = &DECL_CHAIN (*p); DECL_CHAIN (f1) = f2; - DECL_CHAIN (f2) = TYPE_FIELDS (ctx->record_type); + if (c3) + { + DECL_CHAIN (f2) = f3; + DECL_CHAIN (f3) = TYPE_FIELDS (ctx->record_type); + } + else + DECL_CHAIN (f2) = TYPE_FIELDS (ctx->record_type); TYPE_FIELDS (ctx->record_type) = f1; if (ctx->srecord_type) { f1 = lookup_sfield (OMP_CLAUSE_DECL (c1), ctx); f2 = lookup_sfield (OMP_CLAUSE_DECL (c2), ctx); + if (c3) + f3 = lookup_sfield (OMP_CLAUSE_DECL (c3), ctx); p = &TYPE_FIELDS (ctx->srecord_type); while (*p) - if (*p == f1 || *p == f2) + if (*p == f1 || *p == f2 || *p == f3) *p = DECL_CHAIN (*p); else p = &DECL_CHAIN (*p); DECL_CHAIN (f1) = f2; DECL_CHAIN (f2) = TYPE_FIELDS (ctx->srecord_type); + if (c3) + { + DECL_CHAIN (f2) = f3; + DECL_CHAIN (f3) = TYPE_FIELDS (ctx->srecord_type); + } + else + DECL_CHAIN (f2) = TYPE_FIELDS (ctx->srecord_type); TYPE_FIELDS (ctx->srecord_type) = f1; } } @@ -2154,7 +2315,7 @@ scan_omp_for (gomp_for *stmt, omp_context *outer_ctx) if (tgt && is_oacc_kernels (tgt)) { - /* Strip out reductions, as they are not handled yet. */ + /* Strip out reductions, as they are not handled yet. */ tree *prev_ptr = &clauses; while (tree probe = *prev_ptr) @@ -2321,8 +2482,32 @@ static void scan_omp_teams (gomp_teams *stmt, omp_context *outer_ctx) { omp_context *ctx = new_omp_context (stmt, outer_ctx); + + if (!gimple_omp_teams_host (stmt)) + { + scan_sharing_clauses (gimple_omp_teams_clauses (stmt), ctx); + scan_omp (gimple_omp_body_ptr (stmt), ctx); + return; + } + taskreg_contexts.safe_push (ctx); + gcc_assert (taskreg_nesting_level == 1); + ctx->field_map = splay_tree_new (splay_tree_compare_pointers, 0, 0); + ctx->record_type = lang_hooks.types.make_type (RECORD_TYPE); + tree name = create_tmp_var_name (".omp_data_s"); + name = build_decl (gimple_location (stmt), + TYPE_DECL, name, ctx->record_type); + DECL_ARTIFICIAL (name) = 1; + DECL_NAMELESS (name) = 1; + TYPE_NAME (ctx->record_type) = name; + TYPE_ARTIFICIAL (ctx->record_type) = 1; + create_omp_child_function (ctx, false); + gimple_omp_teams_set_child_fn (stmt, ctx->cb.dst_fn); + scan_sharing_clauses (gimple_omp_teams_clauses (stmt), ctx); scan_omp (gimple_omp_body_ptr (stmt), ctx); + + if (TYPE_FIELDS (ctx->record_type) == NULL) + ctx->record_type = ctx->receiver_decl = NULL; } /* Check nesting restrictions. */ @@ -2388,9 +2573,13 @@ check_omp_nesting_restrictions (gimple *stmt, omp_context *ctx) return true; } } + else if (gimple_code (stmt) == GIMPLE_OMP_ATOMIC_LOAD + || gimple_code (stmt) == GIMPLE_OMP_ATOMIC_STORE) + return true; error_at (gimple_location (stmt), "OpenMP constructs other than %<#pragma omp ordered simd%>" - " may not be nested inside %<simd%> region"); + " or %<#pragma omp atomic%> may not be nested inside" + " %<simd%> region"); return false; } else if (gimple_code (ctx->stmt) == GIMPLE_OMP_TEAMS) @@ -2814,13 +3003,20 @@ check_omp_nesting_restrictions (gimple *stmt, omp_context *ctx) } break; case GIMPLE_OMP_TEAMS: - if (ctx == NULL - || gimple_code (ctx->stmt) != GIMPLE_OMP_TARGET - || gimple_omp_target_kind (ctx->stmt) != GF_OMP_TARGET_KIND_REGION) + if (ctx == NULL) + break; + else if (gimple_code (ctx->stmt) != GIMPLE_OMP_TARGET + || (gimple_omp_target_kind (ctx->stmt) + != GF_OMP_TARGET_KIND_REGION)) { + /* Teams construct can appear either strictly nested inside of + target construct with no intervening stmts, or can be encountered + only by initial task (so must not appear inside any OpenMP + construct. */ error_at (gimple_location (stmt), - "%<teams%> construct not closely nested inside of " - "%<target%> construct"); + "%<teams%> construct must be closely nested inside of " + "%<target%> construct or not nested in any OpenMP " + "construct"); return false; } break; @@ -3090,7 +3286,6 @@ scan_omp_1_stmt (gimple_stmt_iterator *gsi, bool *handled_ops_p, case GIMPLE_OMP_SECTION: case GIMPLE_OMP_MASTER: - case GIMPLE_OMP_TASKGROUP: case GIMPLE_OMP_ORDERED: case GIMPLE_OMP_CRITICAL: case GIMPLE_OMP_GRID_BODY: @@ -3098,12 +3293,25 @@ scan_omp_1_stmt (gimple_stmt_iterator *gsi, bool *handled_ops_p, scan_omp (gimple_omp_body_ptr (stmt), ctx); break; + case GIMPLE_OMP_TASKGROUP: + ctx = new_omp_context (stmt, ctx); + scan_sharing_clauses (gimple_omp_taskgroup_clauses (stmt), ctx); + scan_omp (gimple_omp_body_ptr (stmt), ctx); + break; + case GIMPLE_OMP_TARGET: scan_omp_target (as_a <gomp_target *> (stmt), ctx); break; case GIMPLE_OMP_TEAMS: - scan_omp_teams (as_a <gomp_teams *> (stmt), ctx); + if (gimple_omp_teams_host (as_a <gomp_teams *> (stmt))) + { + taskreg_nesting_level++; + scan_omp_teams (as_a <gomp_teams *> (stmt), ctx); + taskreg_nesting_level--; + } + else + scan_omp_teams (as_a <gomp_teams *> (stmt), ctx); break; case GIMPLE_BIND: @@ -3515,6 +3723,30 @@ handle_simd_reference (location_t loc, tree new_vard, gimple_seq *ilist) } } +/* Helper function for lower_rec_input_clauses. Emit into ilist sequence + code to emit (type) (tskred_temp[idx]). */ + +static tree +task_reduction_read (gimple_seq *ilist, tree tskred_temp, tree type, + unsigned idx) +{ + unsigned HOST_WIDE_INT sz + = tree_to_uhwi (TYPE_SIZE_UNIT (pointer_sized_int_node)); + tree r = build2 (MEM_REF, pointer_sized_int_node, + tskred_temp, build_int_cst (TREE_TYPE (tskred_temp), + idx * sz)); + tree v = create_tmp_var (pointer_sized_int_node); + gimple *g = gimple_build_assign (v, r); + gimple_seq_add_stmt (ilist, g); + if (!useless_type_conversion_p (type, pointer_sized_int_node)) + { + v = create_tmp_var (type); + g = gimple_build_assign (v, NOP_EXPR, gimple_assign_lhs (g)); + gimple_seq_add_stmt (ilist, g); + } + return v; +} + /* Generate code to implement the input clauses, FIRSTPRIVATE and COPYIN, from the receiver (aka child) side and initializers for REFERENCE_TYPE private variables. Initialization statements go in ILIST, while calls @@ -3558,6 +3790,7 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist, sctx.max_vf = 1; break; case OMP_CLAUSE_REDUCTION: + case OMP_CLAUSE_IN_REDUCTION: if (TREE_CODE (OMP_CLAUSE_DECL (c)) == MEM_REF || is_variable_sized (OMP_CLAUSE_DECL (c))) sctx.max_vf = 1; @@ -3570,18 +3803,87 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist, if (sctx.is_simt && maybe_ne (sctx.max_vf, 1U)) sctx.simt_eargs.safe_push (NULL_TREE); + unsigned task_reduction_cnt = 0; + unsigned task_reduction_cntorig = 0; + unsigned task_reduction_cnt_full = 0; + unsigned task_reduction_cntorig_full = 0; + unsigned task_reduction_other_cnt = 0; + tree tskred_atype = NULL_TREE, tskred_avar = NULL_TREE; + tree tskred_base = NULL_TREE, tskred_temp = NULL_TREE; /* Do all the fixed sized types in the first pass, and the variable sized types in the second pass. This makes sure that the scalar arguments to the variable sized types are processed before we use them in the - variable sized operations. */ - for (pass = 0; pass < 2; ++pass) - { + variable sized operations. For task reductions we use 4 passes, in the + first two we ignore them, in the third one gather arguments for + GOMP_task_reduction_remap call and in the last pass actually handle + the task reductions. */ + for (pass = 0; pass < ((task_reduction_cnt || task_reduction_other_cnt) + ? 4 : 2); ++pass) + { + if (pass == 2 && task_reduction_cnt) + { + tskred_atype + = build_array_type_nelts (ptr_type_node, task_reduction_cnt + + task_reduction_cntorig); + tskred_avar = create_tmp_var_raw (tskred_atype); + gimple_add_tmp_var (tskred_avar); + TREE_ADDRESSABLE (tskred_avar) = 1; + task_reduction_cnt_full = task_reduction_cnt; + task_reduction_cntorig_full = task_reduction_cntorig; + } + else if (pass == 3 && task_reduction_cnt) + { + x = builtin_decl_explicit (BUILT_IN_GOMP_TASK_REDUCTION_REMAP); + gimple *g + = gimple_build_call (x, 3, size_int (task_reduction_cnt), + size_int (task_reduction_cntorig), + build_fold_addr_expr (tskred_avar)); + gimple_seq_add_stmt (ilist, g); + } + if (pass == 3 && task_reduction_other_cnt) + { + /* For reduction clauses, build + tskred_base = (void *) tskred_temp[2] + + omp_get_thread_num () * tskred_temp[1] + or if tskred_temp[1] is known to be constant, that constant + directly. This is the start of the private reduction copy block + for the current thread. */ + tree v = create_tmp_var (integer_type_node); + x = builtin_decl_explicit (BUILT_IN_OMP_GET_THREAD_NUM); + gimple *g = gimple_build_call (x, 0); + gimple_call_set_lhs (g, v); + gimple_seq_add_stmt (ilist, g); + c = omp_find_clause (clauses, OMP_CLAUSE__REDUCTEMP_); + tskred_temp = OMP_CLAUSE_DECL (c); + if (is_taskreg_ctx (ctx)) + tskred_temp = lookup_decl (tskred_temp, ctx); + tree v2 = create_tmp_var (sizetype); + g = gimple_build_assign (v2, NOP_EXPR, v); + gimple_seq_add_stmt (ilist, g); + if (ctx->task_reductions[0]) + v = fold_convert (sizetype, ctx->task_reductions[0]); + else + v = task_reduction_read (ilist, tskred_temp, sizetype, 1); + tree v3 = create_tmp_var (sizetype); + g = gimple_build_assign (v3, MULT_EXPR, v2, v); + gimple_seq_add_stmt (ilist, g); + v = task_reduction_read (ilist, tskred_temp, ptr_type_node, 2); + tskred_base = create_tmp_var (ptr_type_node); + g = gimple_build_assign (tskred_base, POINTER_PLUS_EXPR, v, v3); + gimple_seq_add_stmt (ilist, g); + } + task_reduction_cnt = 0; + task_reduction_cntorig = 0; + task_reduction_other_cnt = 0; for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c)) { enum omp_clause_code c_kind = OMP_CLAUSE_CODE (c); tree var, new_var; bool by_ref; location_t clause_loc = OMP_CLAUSE_LOCATION (c); + bool task_reduction_p = false; + bool task_reduction_needs_orig_p = false; + tree cond = NULL_TREE; switch (c_kind) { @@ -3590,8 +3892,10 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist, continue; break; case OMP_CLAUSE_SHARED: - /* Ignore shared directives in teams construct. */ - if (gimple_code (ctx->stmt) == GIMPLE_OMP_TEAMS) + /* Ignore shared directives in teams construct inside + of target construct. */ + if (gimple_code (ctx->stmt) == GIMPLE_OMP_TEAMS + && !is_host_teams_ctx (ctx)) continue; if (maybe_lookup_decl (OMP_CLAUSE_DECL (c), ctx) == NULL) { @@ -3608,11 +3912,46 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist, lastprivate_firstprivate = true; break; case OMP_CLAUSE_REDUCTION: - if (OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c)) + case OMP_CLAUSE_IN_REDUCTION: + if (is_task_ctx (ctx) || OMP_CLAUSE_REDUCTION_TASK (c)) + { + task_reduction_p = true; + if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION) + { + task_reduction_other_cnt++; + if (pass == 2) + continue; + } + else + task_reduction_cnt++; + if (OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c)) + { + var = OMP_CLAUSE_DECL (c); + /* If var is a global variable that isn't privatized + in outer contexts, we don't need to look up the + original address, it is always the address of the + global variable itself. */ + if (!DECL_P (var) + || omp_is_reference (var) + || !is_global_var + (maybe_lookup_decl_in_outer_ctx (var, ctx))) + { + task_reduction_needs_orig_p = true; + if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION) + task_reduction_cntorig++; + } + } + } + else if (OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c)) reduction_omp_orig_ref = true; break; + case OMP_CLAUSE__REDUCTEMP_: + if (!is_taskreg_ctx (ctx)) + continue; + /* FALLTHRU */ case OMP_CLAUSE__LOOPTEMP_: - /* Handle _looptemp_ clauses only on parallel/task. */ + /* Handle _looptemp_/_reductemp_ clauses only on + parallel/task. */ if (fd) continue; break; @@ -3632,7 +3971,7 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist, lastprivate_firstprivate = true; break; case OMP_CLAUSE_ALIGNED: - if (pass == 0) + if (pass != 1) continue; var = OMP_CLAUSE_DECL (c); if (TREE_CODE (TREE_TYPE (var)) == POINTER_TYPE @@ -3673,8 +4012,13 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist, continue; } + if (task_reduction_p != (pass >= 2)) + continue; + new_var = var = OMP_CLAUSE_DECL (c); - if (c_kind == OMP_CLAUSE_REDUCTION && TREE_CODE (var) == MEM_REF) + if ((c_kind == OMP_CLAUSE_REDUCTION + || c_kind == OMP_CLAUSE_IN_REDUCTION) + && TREE_CODE (var) == MEM_REF) { var = TREE_OPERAND (var, 0); if (TREE_CODE (var) == POINTER_PLUS_EXPR) @@ -3701,7 +4045,8 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist, continue; } /* C/C++ array section reductions. */ - else if (c_kind == OMP_CLAUSE_REDUCTION + else if ((c_kind == OMP_CLAUSE_REDUCTION + || c_kind == OMP_CLAUSE_IN_REDUCTION) && var != OMP_CLAUSE_DECL (c)) { if (pass == 0) @@ -3709,6 +4054,7 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist, tree bias = TREE_OPERAND (OMP_CLAUSE_DECL (c), 1); tree orig_var = TREE_OPERAND (OMP_CLAUSE_DECL (c), 0); + if (TREE_CODE (orig_var) == POINTER_PLUS_EXPR) { tree b = TREE_OPERAND (orig_var, 1); @@ -3729,6 +4075,47 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist, } orig_var = TREE_OPERAND (orig_var, 0); } + if (pass == 2) + { + tree out = maybe_lookup_decl_in_outer_ctx (var, ctx); + if (is_global_var (out) + && TREE_CODE (TREE_TYPE (out)) != POINTER_TYPE + && (TREE_CODE (TREE_TYPE (out)) != REFERENCE_TYPE + || (TREE_CODE (TREE_TYPE (TREE_TYPE (out))) + != POINTER_TYPE))) + x = var; + else + { + bool by_ref = use_pointer_for_field (var, NULL); + x = build_receiver_ref (var, by_ref, ctx); + if (TREE_CODE (TREE_TYPE (var)) == REFERENCE_TYPE + && (TREE_CODE (TREE_TYPE (TREE_TYPE (var))) + == POINTER_TYPE)) + x = build_fold_addr_expr (x); + } + if (TREE_CODE (orig_var) == INDIRECT_REF) + x = build_simple_mem_ref (x); + else if (TREE_CODE (orig_var) == ADDR_EXPR) + { + if (var == TREE_OPERAND (orig_var, 0)) + x = build_fold_addr_expr (x); + } + bias = fold_convert (sizetype, bias); + x = fold_convert (ptr_type_node, x); + x = fold_build2_loc (clause_loc, POINTER_PLUS_EXPR, + TREE_TYPE (x), x, bias); + unsigned cnt = task_reduction_cnt - 1; + if (!task_reduction_needs_orig_p) + cnt += (task_reduction_cntorig_full + - task_reduction_cntorig); + else + cnt = task_reduction_cntorig - 1; + tree r = build4 (ARRAY_REF, ptr_type_node, tskred_avar, + size_int (cnt), NULL_TREE, NULL_TREE); + gimplify_assign (r, x, ilist); + continue; + } + if (TREE_CODE (orig_var) == INDIRECT_REF || TREE_CODE (orig_var) == ADDR_EXPR) orig_var = TREE_OPERAND (orig_var, 0); @@ -3737,7 +4124,64 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist, gcc_assert (TREE_CODE (type) == ARRAY_TYPE); tree v = TYPE_MAX_VALUE (TYPE_DOMAIN (type)); const char *name = get_name (orig_var); - if (TREE_CONSTANT (v)) + if (pass == 3) + { + tree xv = create_tmp_var (ptr_type_node); + if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION) + { + unsigned cnt = task_reduction_cnt - 1; + if (!task_reduction_needs_orig_p) + cnt += (task_reduction_cntorig_full + - task_reduction_cntorig); + else + cnt = task_reduction_cntorig - 1; + x = build4 (ARRAY_REF, ptr_type_node, tskred_avar, + size_int (cnt), NULL_TREE, NULL_TREE); + + gimple *g = gimple_build_assign (xv, x); + gimple_seq_add_stmt (ilist, g); + } + else + { + unsigned int idx = *ctx->task_reduction_map->get (c); + tree off; + if (ctx->task_reductions[1 + idx]) + off = fold_convert (sizetype, + ctx->task_reductions[1 + idx]); + else + off = task_reduction_read (ilist, tskred_temp, sizetype, + 7 + 3 * idx + 1); + gimple *g = gimple_build_assign (xv, POINTER_PLUS_EXPR, + tskred_base, off); + gimple_seq_add_stmt (ilist, g); + } + x = fold_convert (build_pointer_type (boolean_type_node), + xv); + if (TREE_CONSTANT (v)) + x = fold_build2 (POINTER_PLUS_EXPR, TREE_TYPE (x), x, + TYPE_SIZE_UNIT (type)); + else + { + tree t = maybe_lookup_decl (v, ctx); + if (t) + v = t; + else + v = maybe_lookup_decl_in_outer_ctx (v, ctx); + gimplify_expr (&v, ilist, NULL, is_gimple_val, + fb_rvalue); + t = fold_build2_loc (clause_loc, PLUS_EXPR, + TREE_TYPE (v), v, + build_int_cst (TREE_TYPE (v), 1)); + t = fold_build2_loc (clause_loc, MULT_EXPR, + TREE_TYPE (v), t, + TYPE_SIZE_UNIT (TREE_TYPE (type))); + x = fold_build2 (POINTER_PLUS_EXPR, TREE_TYPE (x), x, t); + } + cond = create_tmp_var (TREE_TYPE (x)); + gimplify_assign (cond, x, ilist); + x = xv; + } + else if (TREE_CONSTANT (v)) { x = create_tmp_var_raw (type, name); gimple_add_tmp_var (x); @@ -3799,7 +4243,7 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist, tree new_orig_var = lookup_decl (orig_var, ctx); tree t = build_fold_indirect_ref (new_var); DECL_IGNORED_P (new_var) = 0; - TREE_THIS_NOTRAP (t); + TREE_THIS_NOTRAP (t) = 1; SET_DECL_VALUE_EXPR (new_orig_var, t); DECL_HAS_VALUE_EXPR_P (new_orig_var) = 1; } @@ -3824,44 +4268,101 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist, x = fold_convert_loc (clause_loc, TREE_TYPE (new_var), x); gimplify_assign (new_var, x, ilist); } - tree y1 = create_tmp_var (ptype, NULL); + /* GOMP_taskgroup_reduction_register memsets the whole + array to zero. If the initializer is zero, we don't + need to initialize it again, just mark it as ever + used unconditionally, i.e. cond = true. */ + if (cond + && OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) == NULL_TREE + && initializer_zerop (omp_reduction_init (c, + TREE_TYPE (type)))) + { + gimple *g = gimple_build_assign (build_simple_mem_ref (cond), + boolean_true_node); + gimple_seq_add_stmt (ilist, g); + continue; + } + tree end = create_artificial_label (UNKNOWN_LOCATION); + if (cond) + { + gimple *g; + if (!is_parallel_ctx (ctx)) + { + tree condv = create_tmp_var (boolean_type_node); + g = gimple_build_assign (condv, + build_simple_mem_ref (cond)); + gimple_seq_add_stmt (ilist, g); + tree lab1 = create_artificial_label (UNKNOWN_LOCATION); + g = gimple_build_cond (NE_EXPR, condv, + boolean_false_node, end, lab1); + gimple_seq_add_stmt (ilist, g); + gimple_seq_add_stmt (ilist, gimple_build_label (lab1)); + } + g = gimple_build_assign (build_simple_mem_ref (cond), + boolean_true_node); + gimple_seq_add_stmt (ilist, g); + } + + tree y1 = create_tmp_var (ptype); gimplify_assign (y1, y, ilist); tree i2 = NULL_TREE, y2 = NULL_TREE; tree body2 = NULL_TREE, end2 = NULL_TREE; tree y3 = NULL_TREE, y4 = NULL_TREE; - if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) || is_simd) + if (task_reduction_needs_orig_p) { - y2 = create_tmp_var (ptype, NULL); - gimplify_assign (y2, y, ilist); - tree ref = build_outer_var_ref (var, ctx); - /* For ref build_outer_var_ref already performs this. */ - if (TREE_CODE (d) == INDIRECT_REF) - gcc_assert (omp_is_reference (var)); - else if (TREE_CODE (d) == ADDR_EXPR) - ref = build_fold_addr_expr (ref); - else if (omp_is_reference (var)) - ref = build_fold_addr_expr (ref); - ref = fold_convert_loc (clause_loc, ptype, ref); - if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) - && OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c)) + y3 = create_tmp_var (ptype); + tree ref; + if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION) + ref = build4 (ARRAY_REF, ptr_type_node, tskred_avar, + size_int (task_reduction_cnt_full + + task_reduction_cntorig - 1), + NULL_TREE, NULL_TREE); + else { - y3 = create_tmp_var (ptype, NULL); - gimplify_assign (y3, unshare_expr (ref), ilist); + unsigned int idx = *ctx->task_reduction_map->get (c); + ref = task_reduction_read (ilist, tskred_temp, ptype, + 7 + 3 * idx); } - if (is_simd) + gimplify_assign (y3, ref, ilist); + } + else if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) || is_simd) + { + if (pass != 3) { - y4 = create_tmp_var (ptype, NULL); - gimplify_assign (y4, ref, dlist); + y2 = create_tmp_var (ptype); + gimplify_assign (y2, y, ilist); + } + if (is_simd || OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c)) + { + tree ref = build_outer_var_ref (var, ctx); + /* For ref build_outer_var_ref already performs this. */ + if (TREE_CODE (d) == INDIRECT_REF) + gcc_assert (omp_is_reference (var)); + else if (TREE_CODE (d) == ADDR_EXPR) + ref = build_fold_addr_expr (ref); + else if (omp_is_reference (var)) + ref = build_fold_addr_expr (ref); + ref = fold_convert_loc (clause_loc, ptype, ref); + if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) + && OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c)) + { + y3 = create_tmp_var (ptype); + gimplify_assign (y3, unshare_expr (ref), ilist); + } + if (is_simd) + { + y4 = create_tmp_var (ptype); + gimplify_assign (y4, ref, dlist); + } } } - tree i = create_tmp_var (TREE_TYPE (v), NULL); + tree i = create_tmp_var (TREE_TYPE (v)); gimplify_assign (i, build_int_cst (TREE_TYPE (v), 0), ilist); tree body = create_artificial_label (UNKNOWN_LOCATION); - tree end = create_artificial_label (UNKNOWN_LOCATION); gimple_seq_add_stmt (ilist, gimple_build_label (body)); if (y2) { - i2 = create_tmp_var (TREE_TYPE (v), NULL); + i2 = create_tmp_var (TREE_TYPE (v)); gimplify_assign (i2, build_int_cst (TREE_TYPE (v), 0), dlist); body2 = create_artificial_label (UNKNOWN_LOCATION); end2 = create_artificial_label (UNKNOWN_LOCATION); @@ -3904,14 +4405,17 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist, } DECL_HAS_VALUE_EXPR_P (placeholder) = 0; DECL_HAS_VALUE_EXPR_P (decl_placeholder) = 0; - x = lang_hooks.decls.omp_clause_dtor - (c, build_simple_mem_ref (y2)); - if (x) + if (y2) { - gimple_seq tseq = NULL; - dtor = x; - gimplify_stmt (&dtor, &tseq); - gimple_seq_add_seq (dlist, tseq); + x = lang_hooks.decls.omp_clause_dtor + (c, build_simple_mem_ref (y2)); + if (x) + { + gimple_seq tseq = NULL; + dtor = x; + gimplify_stmt (&dtor, &tseq); + gimple_seq_add_seq (dlist, tseq); + } } } else @@ -3970,6 +4474,78 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist, } continue; } + else if (pass == 2) + { + if (is_global_var (maybe_lookup_decl_in_outer_ctx (var, ctx))) + x = var; + else + { + bool by_ref = use_pointer_for_field (var, ctx); + x = build_receiver_ref (var, by_ref, ctx); + } + if (!omp_is_reference (var)) + x = build_fold_addr_expr (x); + x = fold_convert (ptr_type_node, x); + unsigned cnt = task_reduction_cnt - 1; + if (!task_reduction_needs_orig_p) + cnt += task_reduction_cntorig_full - task_reduction_cntorig; + else + cnt = task_reduction_cntorig - 1; + tree r = build4 (ARRAY_REF, ptr_type_node, tskred_avar, + size_int (cnt), NULL_TREE, NULL_TREE); + gimplify_assign (r, x, ilist); + continue; + } + else if (pass == 3) + { + tree type = TREE_TYPE (new_var); + if (!omp_is_reference (var)) + type = build_pointer_type (type); + if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION) + { + unsigned cnt = task_reduction_cnt - 1; + if (!task_reduction_needs_orig_p) + cnt += (task_reduction_cntorig_full + - task_reduction_cntorig); + else + cnt = task_reduction_cntorig - 1; + x = build4 (ARRAY_REF, ptr_type_node, tskred_avar, + size_int (cnt), NULL_TREE, NULL_TREE); + } + else + { + unsigned int idx = *ctx->task_reduction_map->get (c); + tree off; + if (ctx->task_reductions[1 + idx]) + off = fold_convert (sizetype, + ctx->task_reductions[1 + idx]); + else + off = task_reduction_read (ilist, tskred_temp, sizetype, + 7 + 3 * idx + 1); + x = fold_build2 (POINTER_PLUS_EXPR, ptr_type_node, + tskred_base, off); + } + x = fold_convert (type, x); + tree t; + if (omp_is_reference (var)) + { + gimplify_assign (new_var, x, ilist); + t = new_var; + new_var = build_simple_mem_ref (new_var); + } + else + { + t = create_tmp_var (type); + gimplify_assign (t, x, ilist); + SET_DECL_VALUE_EXPR (new_var, build_simple_mem_ref (t)); + DECL_HAS_VALUE_EXPR_P (new_var) = 1; + } + t = fold_convert (build_pointer_type (boolean_type_node), t); + t = fold_build2 (POINTER_PLUS_EXPR, TREE_TYPE (t), t, + TYPE_SIZE_UNIT (TREE_TYPE (type))); + cond = create_tmp_var (TREE_TYPE (t)); + gimplify_assign (cond, t, ilist); + } else if (is_variable_sized (var)) { /* For variable sized types, we need to allocate the @@ -4003,7 +4579,9 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist, gimplify_assign (ptr, x, ilist); } } - else if (omp_is_reference (var)) + else if (omp_is_reference (var) + && (c_kind != OMP_CLAUSE_FIRSTPRIVATE + || !OMP_CLAUSE_FIRSTPRIVATE_NO_REFERENCE (c))) { /* For references that are being privatized for Fortran, allocate new backing storage for the new pointer @@ -4053,7 +4631,8 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist, new_var = build_simple_mem_ref_loc (clause_loc, new_var); } - else if (c_kind == OMP_CLAUSE_REDUCTION + else if ((c_kind == OMP_CLAUSE_REDUCTION + || c_kind == OMP_CLAUSE_IN_REDUCTION) && OMP_CLAUSE_REDUCTION_PLACEHOLDER (c)) { if (pass == 0) @@ -4065,8 +4644,10 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist, switch (OMP_CLAUSE_CODE (c)) { case OMP_CLAUSE_SHARED: - /* Ignore shared directives in teams construct. */ - if (gimple_code (ctx->stmt) == GIMPLE_OMP_TEAMS) + /* Ignore shared directives in teams construct inside + target construct. */ + if (gimple_code (ctx->stmt) == GIMPLE_OMP_TEAMS + && !is_host_teams_ctx (ctx)) continue; /* Shared global vars are just accessed directly. */ if (is_global_var (new_var)) @@ -4170,7 +4751,9 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist, case OMP_CLAUSE_FIRSTPRIVATE: if (is_task_ctx (ctx)) { - if (omp_is_reference (var) || is_variable_sized (var)) + if ((omp_is_reference (var) + && !OMP_CLAUSE_FIRSTPRIVATE_NO_REFERENCE (c)) + || is_variable_sized (var)) goto do_dtor; else if (is_global_var (maybe_lookup_decl_in_outer_ctx (var, ctx)) @@ -4182,6 +4765,18 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist, goto do_dtor; } } + if (OMP_CLAUSE_FIRSTPRIVATE_NO_REFERENCE (c) + && omp_is_reference (var)) + { + x = build_outer_var_ref (var, ctx); + gcc_assert (TREE_CODE (x) == MEM_REF + && integer_zerop (TREE_OPERAND (x, 1))); + x = TREE_OPERAND (x, 0); + x = lang_hooks.decls.omp_clause_copy_ctor + (c, unshare_expr (new_var), x); + gimplify_and_add (x, ilist); + goto do_dtor; + } do_firstprivate: x = build_outer_var_ref (var, ctx); if (is_simd) @@ -4273,6 +4868,7 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist, goto do_dtor; case OMP_CLAUSE__LOOPTEMP_: + case OMP_CLAUSE__REDUCTEMP_: gcc_assert (is_taskreg_ctx (ctx)); x = build_outer_var_ref (var, ctx); x = build2 (MODIFY_EXPR, TREE_TYPE (new_var), new_var, x); @@ -4288,6 +4884,7 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist, break; case OMP_CLAUSE_REDUCTION: + case OMP_CLAUSE_IN_REDUCTION: /* OpenACC reductions are initialized using the GOACC_REDUCTION internal function. */ if (is_gimple_omp_oacc (ctx->stmt)) @@ -4296,12 +4893,40 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist, { tree placeholder = OMP_CLAUSE_REDUCTION_PLACEHOLDER (c); gimple *tseq; - x = build_outer_var_ref (var, ctx); + tree ptype = TREE_TYPE (placeholder); + if (cond) + { + x = error_mark_node; + if (OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c) + && !task_reduction_needs_orig_p) + x = var; + else if (OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c)) + { + tree pptype = build_pointer_type (ptype); + if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION) + x = build4 (ARRAY_REF, ptr_type_node, tskred_avar, + size_int (task_reduction_cnt_full + + task_reduction_cntorig - 1), + NULL_TREE, NULL_TREE); + else + { + unsigned int idx + = *ctx->task_reduction_map->get (c); + x = task_reduction_read (ilist, tskred_temp, + pptype, 7 + 3 * idx); + } + x = fold_convert (pptype, x); + x = build_simple_mem_ref (x); + } + } + else + { + x = build_outer_var_ref (var, ctx); - if (omp_is_reference (var) - && !useless_type_conversion_p (TREE_TYPE (placeholder), - TREE_TYPE (x))) - x = build_fold_addr_expr_loc (clause_loc, x); + if (omp_is_reference (var) + && !useless_type_conversion_p (ptype, TREE_TYPE (x))) + x = build_fold_addr_expr_loc (clause_loc, x); + } SET_DECL_VALUE_EXPR (placeholder, x); DECL_HAS_VALUE_EXPR_P (placeholder) = 1; tree new_vard = new_var; @@ -4365,9 +4990,35 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist, initialization now. */ else if (omp_is_reference (var) && is_simd) handle_simd_reference (clause_loc, new_vard, ilist); + + tree lab2 = NULL_TREE; + if (cond) + { + gimple *g; + if (!is_parallel_ctx (ctx)) + { + tree condv = create_tmp_var (boolean_type_node); + tree m = build_simple_mem_ref (cond); + g = gimple_build_assign (condv, m); + gimple_seq_add_stmt (ilist, g); + tree lab1 + = create_artificial_label (UNKNOWN_LOCATION); + lab2 = create_artificial_label (UNKNOWN_LOCATION); + g = gimple_build_cond (NE_EXPR, condv, + boolean_false_node, + lab2, lab1); + gimple_seq_add_stmt (ilist, g); + gimple_seq_add_stmt (ilist, + gimple_build_label (lab1)); + } + g = gimple_build_assign (build_simple_mem_ref (cond), + boolean_true_node); + gimple_seq_add_stmt (ilist, g); + } x = lang_hooks.decls.omp_clause_default_ctor (c, unshare_expr (new_var), - build_outer_var_ref (var, ctx)); + cond ? NULL_TREE + : build_outer_var_ref (var, ctx)); if (x) gimplify_and_add (x, ilist); if (OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c)) @@ -4385,6 +5036,12 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist, OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c) = NULL; } DECL_HAS_VALUE_EXPR_P (placeholder) = 0; + if (cond) + { + if (lab2) + gimple_seq_add_stmt (ilist, gimple_build_label (lab2)); + break; + } goto do_dtor; } else @@ -4393,6 +5050,49 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist, gcc_assert (TREE_CODE (TREE_TYPE (new_var)) != ARRAY_TYPE); enum tree_code code = OMP_CLAUSE_REDUCTION_CODE (c); + if (cond) + { + gimple *g; + tree lab2 = NULL_TREE; + /* GOMP_taskgroup_reduction_register memsets the whole + array to zero. If the initializer is zero, we don't + need to initialize it again, just mark it as ever + used unconditionally, i.e. cond = true. */ + if (initializer_zerop (x)) + { + g = gimple_build_assign (build_simple_mem_ref (cond), + boolean_true_node); + gimple_seq_add_stmt (ilist, g); + break; + } + + /* Otherwise, emit + if (!cond) { cond = true; new_var = x; } */ + if (!is_parallel_ctx (ctx)) + { + tree condv = create_tmp_var (boolean_type_node); + tree m = build_simple_mem_ref (cond); + g = gimple_build_assign (condv, m); + gimple_seq_add_stmt (ilist, g); + tree lab1 + = create_artificial_label (UNKNOWN_LOCATION); + lab2 = create_artificial_label (UNKNOWN_LOCATION); + g = gimple_build_cond (NE_EXPR, condv, + boolean_false_node, + lab2, lab1); + gimple_seq_add_stmt (ilist, g); + gimple_seq_add_stmt (ilist, + gimple_build_label (lab1)); + } + g = gimple_build_assign (build_simple_mem_ref (cond), + boolean_true_node); + gimple_seq_add_stmt (ilist, g); + gimplify_assign (new_var, x, ilist); + if (lab2) + gimple_seq_add_stmt (ilist, gimple_build_label (lab2)); + break; + } + /* reduction(-:var) sums up the partial results, so it acts identically to reduction(+:var). */ if (code == MINUS_EXPR) @@ -4456,6 +5156,12 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist, } } } + if (tskred_avar) + { + tree clobber = build_constructor (TREE_TYPE (tskred_avar), NULL); + TREE_THIS_VOLATILE (clobber) = 1; + gimple_seq_add_stmt (ilist, gimple_build_assign (tskred_avar, clobber)); + } if (known_eq (sctx.max_vf, 1U)) sctx.is_simt = false; @@ -4587,8 +5293,9 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist, { /* Don't add any barrier for #pragma omp simd or #pragma omp distribute. */ - if (gimple_code (ctx->stmt) != GIMPLE_OMP_FOR - || gimple_omp_for_kind (ctx->stmt) == GF_OMP_FOR_KIND_FOR) + if (!is_task_ctx (ctx) + && (gimple_code (ctx->stmt) != GIMPLE_OMP_FOR + || gimple_omp_for_kind (ctx->stmt) == GF_OMP_FOR_KIND_FOR)) gimple_seq_add_stmt (ilist, omp_build_barrier (NULL_TREE)); } @@ -5078,7 +5785,8 @@ lower_reduction_clauses (tree clauses, gimple_seq *stmt_seqp, omp_context *ctx) /* First see if there is exactly one reduction clause. Use OMP_ATOMIC update in that case, otherwise use a lock. */ for (c = clauses; c && count < 2; c = OMP_CLAUSE_CHAIN (c)) - if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION) + if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION + && !OMP_CLAUSE_REDUCTION_TASK (c)) { if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) || TREE_CODE (OMP_CLAUSE_DECL (c)) == MEM_REF) @@ -5099,7 +5807,8 @@ lower_reduction_clauses (tree clauses, gimple_seq *stmt_seqp, omp_context *ctx) enum tree_code code; location_t clause_loc = OMP_CLAUSE_LOCATION (c); - if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION) + if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION + || OMP_CLAUSE_REDUCTION_TASK (c)) continue; enum omp_clause_code ccode = OMP_CLAUSE_REDUCTION; @@ -5150,6 +5859,7 @@ lower_reduction_clauses (tree clauses, gimple_seq *stmt_seqp, omp_context *ctx) ref = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (addr)), addr); x = fold_build2_loc (clause_loc, code, TREE_TYPE (ref), ref, new_var); x = build2 (OMP_ATOMIC, void_type_node, addr, x); + OMP_ATOMIC_MEMORY_ORDER (x) = OMP_MEMORY_ORDER_RELAXED; gimplify_and_add (x, stmt_seqp); return; } @@ -5158,7 +5868,7 @@ lower_reduction_clauses (tree clauses, gimple_seq *stmt_seqp, omp_context *ctx) tree d = OMP_CLAUSE_DECL (c); tree type = TREE_TYPE (d); tree v = TYPE_MAX_VALUE (TYPE_DOMAIN (type)); - tree i = create_tmp_var (TREE_TYPE (v), NULL); + tree i = create_tmp_var (TREE_TYPE (v)); tree ptype = build_pointer_type (TREE_TYPE (type)); tree bias = TREE_OPERAND (d, 1); d = TREE_OPERAND (d, 0); @@ -5222,10 +5932,10 @@ lower_reduction_clauses (tree clauses, gimple_seq *stmt_seqp, omp_context *ctx) } new_var = fold_convert_loc (clause_loc, ptype, new_var); ref = fold_convert_loc (clause_loc, ptype, ref); - tree m = create_tmp_var (ptype, NULL); + tree m = create_tmp_var (ptype); gimplify_assign (m, new_var, stmt_seqp); new_var = m; - m = create_tmp_var (ptype, NULL); + m = create_tmp_var (ptype); gimplify_assign (m, ref, stmt_seqp); ref = m; gimplify_assign (i, build_int_cst (TREE_TYPE (v), 0), stmt_seqp); @@ -5387,7 +6097,12 @@ lower_send_clauses (tree clauses, gimple_seq *ilist, gimple_seq *olist, case OMP_CLAUSE_FIRSTPRIVATE: case OMP_CLAUSE_COPYIN: case OMP_CLAUSE_LASTPRIVATE: + case OMP_CLAUSE_IN_REDUCTION: + case OMP_CLAUSE__REDUCTEMP_: + break; case OMP_CLAUSE_REDUCTION: + if (is_task_ctx (ctx) || OMP_CLAUSE_REDUCTION_TASK (c)) + continue; break; case OMP_CLAUSE_SHARED: if (OMP_CLAUSE_SHARED_FIRSTPRIVATE (c)) @@ -5405,7 +6120,8 @@ lower_send_clauses (tree clauses, gimple_seq *ilist, gimple_seq *olist, } val = OMP_CLAUSE_DECL (c); - if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION + if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION + || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION) && TREE_CODE (val) == MEM_REF) { val = TREE_OPERAND (val, 0); @@ -5429,7 +6145,13 @@ lower_send_clauses (tree clauses, gimple_seq *ilist, gimple_seq *olist, var = lookup_decl_in_outer_ctx (val, ctx_for_o); if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_COPYIN - && is_global_var (var)) + && is_global_var (var) + && (val == OMP_CLAUSE_DECL (c) + || !is_task_ctx (ctx) + || (TREE_CODE (TREE_TYPE (val)) != POINTER_TYPE + && (TREE_CODE (TREE_TYPE (val)) != REFERENCE_TYPE + || (TREE_CODE (TREE_TYPE (TREE_TYPE (val))) + != POINTER_TYPE))))) continue; t = omp_member_access_dummy_var (var); @@ -5457,7 +6179,8 @@ lower_send_clauses (tree clauses, gimple_seq *ilist, gimple_seq *olist, continue; } - if ((OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION + if (((OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION + && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION) || val == OMP_CLAUSE_DECL (c)) && is_variable_sized (val)) continue; @@ -5476,6 +6199,7 @@ lower_send_clauses (tree clauses, gimple_seq *ilist, gimple_seq *olist, case OMP_CLAUSE_PRIVATE: case OMP_CLAUSE_COPYIN: case OMP_CLAUSE__LOOPTEMP_: + case OMP_CLAUSE__REDUCTEMP_: do_in = true; break; @@ -5495,9 +6219,15 @@ lower_send_clauses (tree clauses, gimple_seq *ilist, gimple_seq *olist, break; case OMP_CLAUSE_REDUCTION: + case OMP_CLAUSE_IN_REDUCTION: do_in = true; if (val == OMP_CLAUSE_DECL (c)) - do_out = !(by_ref || omp_is_reference (val)); + { + if (is_task_ctx (ctx)) + by_ref = use_pointer_for_field (val, ctx); + else + do_out = !(by_ref || omp_is_reference (val)); + } else by_ref = TREE_CODE (TREE_TYPE (val)) == ARRAY_TYPE; break; @@ -5802,30 +6532,55 @@ maybe_catch_exception (gimple_seq body) cancellation in the implicit barrier. */ static void -maybe_add_implicit_barrier_cancel (omp_context *ctx, gimple_seq *body) +maybe_add_implicit_barrier_cancel (omp_context *ctx, gimple *omp_return, + gimple_seq *body) { - gimple *omp_return = gimple_seq_last_stmt (*body); gcc_assert (gimple_code (omp_return) == GIMPLE_OMP_RETURN); if (gimple_omp_return_nowait_p (omp_return)) return; - if (ctx->outer - && gimple_code (ctx->outer->stmt) == GIMPLE_OMP_PARALLEL - && ctx->outer->cancellable) - { - tree fndecl = builtin_decl_explicit (BUILT_IN_GOMP_CANCEL); - tree c_bool_type = TREE_TYPE (TREE_TYPE (fndecl)); - tree lhs = create_tmp_var (c_bool_type); - gimple_omp_return_set_lhs (omp_return, lhs); - tree fallthru_label = create_artificial_label (UNKNOWN_LOCATION); - gimple *g = gimple_build_cond (NE_EXPR, lhs, - fold_convert (c_bool_type, - boolean_false_node), - ctx->outer->cancel_label, fallthru_label); - gimple_seq_add_stmt (body, g); - gimple_seq_add_stmt (body, gimple_build_label (fallthru_label)); + for (omp_context *outer = ctx->outer; outer; outer = outer->outer) + if (gimple_code (outer->stmt) == GIMPLE_OMP_PARALLEL + && outer->cancellable) + { + tree fndecl = builtin_decl_explicit (BUILT_IN_GOMP_CANCEL); + tree c_bool_type = TREE_TYPE (TREE_TYPE (fndecl)); + tree lhs = create_tmp_var (c_bool_type); + gimple_omp_return_set_lhs (omp_return, lhs); + tree fallthru_label = create_artificial_label (UNKNOWN_LOCATION); + gimple *g = gimple_build_cond (NE_EXPR, lhs, + fold_convert (c_bool_type, + boolean_false_node), + outer->cancel_label, fallthru_label); + gimple_seq_add_stmt (body, g); + gimple_seq_add_stmt (body, gimple_build_label (fallthru_label)); + } + else if (gimple_code (outer->stmt) != GIMPLE_OMP_TASKGROUP) + return; +} + +/* Find the first task_reduction or reduction clause or return NULL + if there are none. */ + +static inline tree +omp_task_reductions_find_first (tree clauses, enum tree_code code, + enum omp_clause_code ccode) +{ + while (1) + { + clauses = omp_find_clause (clauses, ccode); + if (clauses == NULL_TREE) + return NULL_TREE; + if (ccode != OMP_CLAUSE_REDUCTION + || code == OMP_TASKLOOP + || OMP_CLAUSE_REDUCTION_TASK (clauses)) + return clauses; + clauses = OMP_CLAUSE_CHAIN (clauses); } } +static void lower_omp_task_reductions (omp_context *, enum tree_code, tree, + gimple_seq *, gimple_seq *); + /* Lower the OpenMP sections directive in the current statement in GSI_P. CTX is the enclosing OMP context for the current statement. */ @@ -5837,7 +6592,7 @@ lower_omp_sections (gimple_stmt_iterator *gsi_p, omp_context *ctx) gomp_sections *stmt; gimple *t; gbind *new_stmt, *bind; - gimple_seq ilist, dlist, olist, new_body; + gimple_seq ilist, dlist, olist, tred_dlist = NULL, new_body; stmt = as_a <gomp_sections *> (gsi_stmt (*gsi_p)); @@ -5845,6 +6600,27 @@ lower_omp_sections (gimple_stmt_iterator *gsi_p, omp_context *ctx) dlist = NULL; ilist = NULL; + + tree rclauses + = omp_task_reductions_find_first (gimple_omp_sections_clauses (stmt), + OMP_SECTIONS, OMP_CLAUSE_REDUCTION); + tree rtmp = NULL_TREE; + if (rclauses) + { + tree type = build_pointer_type (pointer_sized_int_node); + tree temp = create_tmp_var (type); + tree c = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE__REDUCTEMP_); + OMP_CLAUSE_DECL (c) = temp; + OMP_CLAUSE_CHAIN (c) = gimple_omp_sections_clauses (stmt); + gimple_omp_sections_set_clauses (stmt, c); + lower_omp_task_reductions (ctx, OMP_SECTIONS, + gimple_omp_sections_clauses (stmt), + &ilist, &tred_dlist); + rclauses = c; + rtmp = make_ssa_name (type); + gimple_seq_add_stmt (&ilist, gimple_build_assign (rtmp, temp)); + } + lower_rec_input_clauses (gimple_omp_sections_clauses (stmt), &ilist, &dlist, ctx, NULL); @@ -5916,7 +6692,11 @@ lower_omp_sections (gimple_stmt_iterator *gsi_p, omp_context *ctx) OMP_CLAUSE_NOWAIT) != NULL_TREE; t = gimple_build_omp_return (nowait); gimple_seq_add_stmt (&new_body, t); - maybe_add_implicit_barrier_cancel (ctx, &new_body); + gimple_seq_add_seq (&new_body, tred_dlist); + maybe_add_implicit_barrier_cancel (ctx, t, &new_body); + + if (rclauses) + OMP_CLAUSE_DECL (rclauses) = rtmp; gimple_bind_set_body (new_stmt, new_body); } @@ -6078,7 +6858,7 @@ lower_omp_single (gimple_stmt_iterator *gsi_p, omp_context *ctx) OMP_CLAUSE_NOWAIT) != NULL_TREE; gimple *g = gimple_build_omp_return (nowait); gimple_seq_add_stmt (&bind_body_tail, g); - maybe_add_implicit_barrier_cancel (ctx, &bind_body_tail); + maybe_add_implicit_barrier_cancel (ctx, g, &bind_body_tail); if (ctx->record_type) { gimple_stmt_iterator gsi = gsi_start (bind_body_tail); @@ -6140,6 +6920,604 @@ lower_omp_master (gimple_stmt_iterator *gsi_p, omp_context *ctx) BLOCK_VARS (block) = ctx->block_vars; } +/* Helper function for lower_omp_task_reductions. For a specific PASS + find out the current clause it should be processed, or return false + if all have been processed already. */ + +static inline bool +omp_task_reduction_iterate (int pass, enum tree_code code, + enum omp_clause_code ccode, tree *c, tree *decl, + tree *type, tree *next) +{ + for (; *c; *c = omp_find_clause (OMP_CLAUSE_CHAIN (*c), ccode)) + { + if (ccode == OMP_CLAUSE_REDUCTION + && code != OMP_TASKLOOP + && !OMP_CLAUSE_REDUCTION_TASK (*c)) + continue; + *decl = OMP_CLAUSE_DECL (*c); + *type = TREE_TYPE (*decl); + if (TREE_CODE (*decl) == MEM_REF) + { + if (pass != 1) + continue; + } + else + { + if (omp_is_reference (*decl)) + *type = TREE_TYPE (*type); + if (pass != (!TREE_CONSTANT (TYPE_SIZE_UNIT (*type)))) + continue; + } + *next = omp_find_clause (OMP_CLAUSE_CHAIN (*c), ccode); + return true; + } + *decl = NULL_TREE; + *type = NULL_TREE; + *next = NULL_TREE; + return false; +} + +/* Lower task_reduction and reduction clauses (the latter unless CODE is + OMP_TASKGROUP only with task modifier). Register mapping of those in + START sequence and reducing them and unregister them in the END sequence. */ + +static void +lower_omp_task_reductions (omp_context *ctx, enum tree_code code, tree clauses, + gimple_seq *start, gimple_seq *end) +{ + enum omp_clause_code ccode + = (code == OMP_TASKGROUP + ? OMP_CLAUSE_TASK_REDUCTION : OMP_CLAUSE_REDUCTION); + tree cancellable = NULL_TREE; + clauses = omp_task_reductions_find_first (clauses, code, ccode); + if (clauses == NULL_TREE) + return; + if (code == OMP_FOR || code == OMP_SECTIONS) + { + for (omp_context *outer = ctx->outer; outer; outer = outer->outer) + if (gimple_code (outer->stmt) == GIMPLE_OMP_PARALLEL + && outer->cancellable) + { + cancellable = error_mark_node; + break; + } + else if (gimple_code (outer->stmt) != GIMPLE_OMP_TASKGROUP) + break; + } + tree record_type = lang_hooks.types.make_type (RECORD_TYPE); + tree *last = &TYPE_FIELDS (record_type); + unsigned cnt = 0; + if (cancellable) + { + tree field = build_decl (UNKNOWN_LOCATION, FIELD_DECL, NULL_TREE, + ptr_type_node); + tree ifield = build_decl (UNKNOWN_LOCATION, FIELD_DECL, NULL_TREE, + integer_type_node); + *last = field; + DECL_CHAIN (field) = ifield; + last = &DECL_CHAIN (ifield); + } + for (int pass = 0; pass < 2; pass++) + { + tree decl, type, next; + for (tree c = clauses; + omp_task_reduction_iterate (pass, code, ccode, + &c, &decl, &type, &next); c = next) + { + ++cnt; + tree new_type = type; + if (ctx->outer) + new_type = remap_type (type, &ctx->outer->cb); + tree field + = build_decl (OMP_CLAUSE_LOCATION (c), FIELD_DECL, + DECL_P (decl) ? DECL_NAME (decl) : NULL_TREE, + new_type); + if (DECL_P (decl) && type == TREE_TYPE (decl)) + { + SET_DECL_ALIGN (field, DECL_ALIGN (decl)); + DECL_USER_ALIGN (field) = DECL_USER_ALIGN (decl); + TREE_THIS_VOLATILE (field) = TREE_THIS_VOLATILE (decl); + } + else + SET_DECL_ALIGN (field, TYPE_ALIGN (type)); + DECL_CONTEXT (field) = record_type; + *last = field; + last = &DECL_CHAIN (field); + tree bfield + = build_decl (OMP_CLAUSE_LOCATION (c), FIELD_DECL, NULL_TREE, + boolean_type_node); + DECL_CONTEXT (bfield) = record_type; + *last = bfield; + last = &DECL_CHAIN (bfield); + } + } + *last = NULL_TREE; + layout_type (record_type); + + /* Build up an array which registers with the runtime all the reductions + and deregisters them at the end. Format documented in libgomp/task.c. */ + tree atype = build_array_type_nelts (pointer_sized_int_node, 7 + cnt * 3); + tree avar = create_tmp_var_raw (atype); + gimple_add_tmp_var (avar); + TREE_ADDRESSABLE (avar) = 1; + tree r = build4 (ARRAY_REF, pointer_sized_int_node, avar, size_zero_node, + NULL_TREE, NULL_TREE); + tree t = build_int_cst (pointer_sized_int_node, cnt); + gimple_seq_add_stmt (start, gimple_build_assign (r, t)); + gimple_seq seq = NULL; + tree sz = fold_convert (pointer_sized_int_node, + TYPE_SIZE_UNIT (record_type)); + int cachesz = 64; + sz = fold_build2 (PLUS_EXPR, pointer_sized_int_node, sz, + build_int_cst (pointer_sized_int_node, cachesz - 1)); + sz = fold_build2 (BIT_AND_EXPR, pointer_sized_int_node, sz, + build_int_cst (pointer_sized_int_node, ~(cachesz - 1))); + ctx->task_reductions.create (1 + cnt); + ctx->task_reduction_map = new hash_map<tree, unsigned>; + ctx->task_reductions.quick_push (TREE_CODE (sz) == INTEGER_CST + ? sz : NULL_TREE); + sz = force_gimple_operand (sz, &seq, true, NULL_TREE); + gimple_seq_add_seq (start, seq); + r = build4 (ARRAY_REF, pointer_sized_int_node, avar, size_one_node, + NULL_TREE, NULL_TREE); + gimple_seq_add_stmt (start, gimple_build_assign (r, sz)); + r = build4 (ARRAY_REF, pointer_sized_int_node, avar, size_int (2), + NULL_TREE, NULL_TREE); + t = build_int_cst (pointer_sized_int_node, + MAX (TYPE_ALIGN_UNIT (record_type), (unsigned) cachesz)); + gimple_seq_add_stmt (start, gimple_build_assign (r, t)); + r = build4 (ARRAY_REF, pointer_sized_int_node, avar, size_int (3), + NULL_TREE, NULL_TREE); + t = build_int_cst (pointer_sized_int_node, -1); + gimple_seq_add_stmt (start, gimple_build_assign (r, t)); + r = build4 (ARRAY_REF, pointer_sized_int_node, avar, size_int (4), + NULL_TREE, NULL_TREE); + t = build_int_cst (pointer_sized_int_node, 0); + gimple_seq_add_stmt (start, gimple_build_assign (r, t)); + + /* In end, build a loop that iterates from 0 to < omp_get_num_threads () + and for each task reduction checks a bool right after the private variable + within that thread's chunk; if the bool is clear, it hasn't been + initialized and thus isn't going to be reduced nor destructed, otherwise + reduce and destruct it. */ + tree idx = create_tmp_var (size_type_node); + gimple_seq_add_stmt (end, gimple_build_assign (idx, size_zero_node)); + tree num_thr_sz = create_tmp_var (size_type_node); + tree lab1 = create_artificial_label (UNKNOWN_LOCATION); + tree lab2 = create_artificial_label (UNKNOWN_LOCATION); + tree lab3 = NULL_TREE; + gimple *g; + if (code == OMP_FOR || code == OMP_SECTIONS) + { + /* For worksharing constructs, only perform it in the master thread, + with the exception of cancelled implicit barriers - then only handle + the current thread. */ + tree lab4 = create_artificial_label (UNKNOWN_LOCATION); + t = builtin_decl_explicit (BUILT_IN_OMP_GET_THREAD_NUM); + tree thr_num = create_tmp_var (integer_type_node); + g = gimple_build_call (t, 0); + gimple_call_set_lhs (g, thr_num); + gimple_seq_add_stmt (end, g); + if (cancellable) + { + tree c; + tree lab5 = create_artificial_label (UNKNOWN_LOCATION); + tree lab6 = create_artificial_label (UNKNOWN_LOCATION); + lab3 = create_artificial_label (UNKNOWN_LOCATION); + if (code == OMP_FOR) + c = gimple_omp_for_clauses (ctx->stmt); + else if (code == OMP_SECTIONS) + c = gimple_omp_sections_clauses (ctx->stmt); + c = OMP_CLAUSE_DECL (omp_find_clause (c, OMP_CLAUSE__REDUCTEMP_)); + cancellable = c; + g = gimple_build_cond (NE_EXPR, c, build_zero_cst (TREE_TYPE (c)), + lab5, lab6); + gimple_seq_add_stmt (end, g); + gimple_seq_add_stmt (end, gimple_build_label (lab5)); + g = gimple_build_assign (idx, NOP_EXPR, thr_num); + gimple_seq_add_stmt (end, g); + g = gimple_build_assign (num_thr_sz, PLUS_EXPR, idx, + build_one_cst (TREE_TYPE (idx))); + gimple_seq_add_stmt (end, g); + gimple_seq_add_stmt (end, gimple_build_goto (lab3)); + gimple_seq_add_stmt (end, gimple_build_label (lab6)); + } + g = gimple_build_cond (NE_EXPR, thr_num, integer_zero_node, lab2, lab4); + gimple_seq_add_stmt (end, g); + gimple_seq_add_stmt (end, gimple_build_label (lab4)); + } + if (code != OMP_PARALLEL) + { + t = builtin_decl_explicit (BUILT_IN_OMP_GET_NUM_THREADS); + tree num_thr = create_tmp_var (integer_type_node); + g = gimple_build_call (t, 0); + gimple_call_set_lhs (g, num_thr); + gimple_seq_add_stmt (end, g); + g = gimple_build_assign (num_thr_sz, NOP_EXPR, num_thr); + gimple_seq_add_stmt (end, g); + if (cancellable) + gimple_seq_add_stmt (end, gimple_build_label (lab3)); + } + else + { + tree c = omp_find_clause (gimple_omp_parallel_clauses (ctx->stmt), + OMP_CLAUSE__REDUCTEMP_); + t = fold_convert (pointer_sized_int_node, OMP_CLAUSE_DECL (c)); + t = fold_convert (size_type_node, t); + gimplify_assign (num_thr_sz, t, end); + } + t = build4 (ARRAY_REF, pointer_sized_int_node, avar, size_int (2), + NULL_TREE, NULL_TREE); + tree data = create_tmp_var (pointer_sized_int_node); + gimple_seq_add_stmt (end, gimple_build_assign (data, t)); + gimple_seq_add_stmt (end, gimple_build_label (lab1)); + tree ptr; + if (TREE_CODE (TYPE_SIZE_UNIT (record_type)) == INTEGER_CST) + ptr = create_tmp_var (build_pointer_type (record_type)); + else + ptr = create_tmp_var (ptr_type_node); + gimple_seq_add_stmt (end, gimple_build_assign (ptr, NOP_EXPR, data)); + + tree field = TYPE_FIELDS (record_type); + cnt = 0; + if (cancellable) + field = DECL_CHAIN (DECL_CHAIN (field)); + for (int pass = 0; pass < 2; pass++) + { + tree decl, type, next; + for (tree c = clauses; + omp_task_reduction_iterate (pass, code, ccode, + &c, &decl, &type, &next); c = next) + { + tree var = decl, ref; + if (TREE_CODE (decl) == MEM_REF) + { + var = TREE_OPERAND (var, 0); + if (TREE_CODE (var) == POINTER_PLUS_EXPR) + var = TREE_OPERAND (var, 0); + tree v = var; + if (TREE_CODE (var) == ADDR_EXPR) + var = TREE_OPERAND (var, 0); + else if (TREE_CODE (var) == INDIRECT_REF) + var = TREE_OPERAND (var, 0); + tree orig_var = var; + if (is_variable_sized (var)) + { + gcc_assert (DECL_HAS_VALUE_EXPR_P (var)); + var = DECL_VALUE_EXPR (var); + gcc_assert (TREE_CODE (var) == INDIRECT_REF); + var = TREE_OPERAND (var, 0); + gcc_assert (DECL_P (var)); + } + t = ref = maybe_lookup_decl_in_outer_ctx (var, ctx); + if (orig_var != var) + gcc_assert (TREE_CODE (v) == ADDR_EXPR); + else if (TREE_CODE (v) == ADDR_EXPR) + t = build_fold_addr_expr (t); + else if (TREE_CODE (v) == INDIRECT_REF) + t = build_fold_indirect_ref (t); + if (TREE_CODE (TREE_OPERAND (decl, 0)) == POINTER_PLUS_EXPR) + { + tree b = TREE_OPERAND (TREE_OPERAND (decl, 0), 1); + b = maybe_lookup_decl_in_outer_ctx (b, ctx); + t = fold_build2 (POINTER_PLUS_EXPR, TREE_TYPE (t), t, b); + } + if (!integer_zerop (TREE_OPERAND (decl, 1))) + t = fold_build2 (POINTER_PLUS_EXPR, TREE_TYPE (t), t, + fold_convert (size_type_node, + TREE_OPERAND (decl, 1))); + } + else + { + t = ref = maybe_lookup_decl_in_outer_ctx (var, ctx); + if (!omp_is_reference (decl)) + t = build_fold_addr_expr (t); + } + t = fold_convert (pointer_sized_int_node, t); + seq = NULL; + t = force_gimple_operand (t, &seq, true, NULL_TREE); + gimple_seq_add_seq (start, seq); + r = build4 (ARRAY_REF, pointer_sized_int_node, avar, + size_int (7 + cnt * 3), NULL_TREE, NULL_TREE); + gimple_seq_add_stmt (start, gimple_build_assign (r, t)); + t = unshare_expr (byte_position (field)); + t = fold_convert (pointer_sized_int_node, t); + ctx->task_reduction_map->put (c, cnt); + ctx->task_reductions.quick_push (TREE_CODE (t) == INTEGER_CST + ? t : NULL_TREE); + seq = NULL; + t = force_gimple_operand (t, &seq, true, NULL_TREE); + gimple_seq_add_seq (start, seq); + r = build4 (ARRAY_REF, pointer_sized_int_node, avar, + size_int (7 + cnt * 3 + 1), NULL_TREE, NULL_TREE); + gimple_seq_add_stmt (start, gimple_build_assign (r, t)); + + tree bfield = DECL_CHAIN (field); + tree cond; + if (code == OMP_PARALLEL || code == OMP_FOR || code == OMP_SECTIONS) + /* In parallel or worksharing all threads unconditionally + initialize all their task reduction private variables. */ + cond = boolean_true_node; + else if (TREE_TYPE (ptr) == ptr_type_node) + { + cond = build2 (POINTER_PLUS_EXPR, ptr_type_node, ptr, + unshare_expr (byte_position (bfield))); + seq = NULL; + cond = force_gimple_operand (cond, &seq, true, NULL_TREE); + gimple_seq_add_seq (end, seq); + tree pbool = build_pointer_type (TREE_TYPE (bfield)); + cond = build2 (MEM_REF, TREE_TYPE (bfield), cond, + build_int_cst (pbool, 0)); + } + else + cond = build3 (COMPONENT_REF, TREE_TYPE (bfield), + build_simple_mem_ref (ptr), bfield, NULL_TREE); + tree lab3 = create_artificial_label (UNKNOWN_LOCATION); + tree lab4 = create_artificial_label (UNKNOWN_LOCATION); + tree condv = create_tmp_var (boolean_type_node); + gimple_seq_add_stmt (end, gimple_build_assign (condv, cond)); + g = gimple_build_cond (NE_EXPR, condv, boolean_false_node, + lab3, lab4); + gimple_seq_add_stmt (end, g); + gimple_seq_add_stmt (end, gimple_build_label (lab3)); + if (cancellable && OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) == NULL_TREE) + { + /* If this reduction doesn't need destruction and parallel + has been cancelled, there is nothing to do for this + reduction, so jump around the merge operation. */ + tree lab5 = create_artificial_label (UNKNOWN_LOCATION); + g = gimple_build_cond (NE_EXPR, cancellable, + build_zero_cst (TREE_TYPE (cancellable)), + lab4, lab5); + gimple_seq_add_stmt (end, g); + gimple_seq_add_stmt (end, gimple_build_label (lab5)); + } + + tree new_var; + if (TREE_TYPE (ptr) == ptr_type_node) + { + new_var = build2 (POINTER_PLUS_EXPR, ptr_type_node, ptr, + unshare_expr (byte_position (field))); + seq = NULL; + new_var = force_gimple_operand (new_var, &seq, true, NULL_TREE); + gimple_seq_add_seq (end, seq); + tree pbool = build_pointer_type (TREE_TYPE (field)); + new_var = build2 (MEM_REF, TREE_TYPE (field), new_var, + build_int_cst (pbool, 0)); + } + else + new_var = build3 (COMPONENT_REF, TREE_TYPE (field), + build_simple_mem_ref (ptr), field, NULL_TREE); + + enum tree_code rcode = OMP_CLAUSE_REDUCTION_CODE (c); + if (TREE_CODE (decl) != MEM_REF && omp_is_reference (decl)) + ref = build_simple_mem_ref (ref); + /* reduction(-:var) sums up the partial results, so it acts + identically to reduction(+:var). */ + if (rcode == MINUS_EXPR) + rcode = PLUS_EXPR; + if (TREE_CODE (decl) == MEM_REF) + { + tree type = TREE_TYPE (new_var); + tree v = TYPE_MAX_VALUE (TYPE_DOMAIN (type)); + tree i = create_tmp_var (TREE_TYPE (v)); + tree ptype = build_pointer_type (TREE_TYPE (type)); + if (DECL_P (v)) + { + v = maybe_lookup_decl_in_outer_ctx (v, ctx); + tree vv = create_tmp_var (TREE_TYPE (v)); + gimplify_assign (vv, v, start); + v = vv; + } + ref = build4 (ARRAY_REF, pointer_sized_int_node, avar, + size_int (7 + cnt * 3), NULL_TREE, NULL_TREE); + new_var = build_fold_addr_expr (new_var); + new_var = fold_convert (ptype, new_var); + ref = fold_convert (ptype, ref); + tree m = create_tmp_var (ptype); + gimplify_assign (m, new_var, end); + new_var = m; + m = create_tmp_var (ptype); + gimplify_assign (m, ref, end); + ref = m; + gimplify_assign (i, build_int_cst (TREE_TYPE (v), 0), end); + tree body = create_artificial_label (UNKNOWN_LOCATION); + tree endl = create_artificial_label (UNKNOWN_LOCATION); + gimple_seq_add_stmt (end, gimple_build_label (body)); + tree priv = build_simple_mem_ref (new_var); + tree out = build_simple_mem_ref (ref); + if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c)) + { + tree placeholder = OMP_CLAUSE_REDUCTION_PLACEHOLDER (c); + tree decl_placeholder + = OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c); + tree lab6 = NULL_TREE; + if (cancellable) + { + /* If this reduction needs destruction and parallel + has been cancelled, jump around the merge operation + to the destruction. */ + tree lab5 = create_artificial_label (UNKNOWN_LOCATION); + lab6 = create_artificial_label (UNKNOWN_LOCATION); + tree zero = build_zero_cst (TREE_TYPE (cancellable)); + g = gimple_build_cond (NE_EXPR, cancellable, zero, + lab6, lab5); + gimple_seq_add_stmt (end, g); + gimple_seq_add_stmt (end, gimple_build_label (lab5)); + } + SET_DECL_VALUE_EXPR (placeholder, out); + DECL_HAS_VALUE_EXPR_P (placeholder) = 1; + SET_DECL_VALUE_EXPR (decl_placeholder, priv); + DECL_HAS_VALUE_EXPR_P (decl_placeholder) = 1; + lower_omp (&OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c), ctx); + gimple_seq_add_seq (end, + OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c)); + OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c) = NULL; + if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION) + { + OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL; + OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c) = NULL; + } + if (cancellable) + gimple_seq_add_stmt (end, gimple_build_label (lab6)); + tree x = lang_hooks.decls.omp_clause_dtor (c, priv); + if (x) + { + gimple_seq tseq = NULL; + gimplify_stmt (&x, &tseq); + gimple_seq_add_seq (end, tseq); + } + } + else + { + tree x = build2 (rcode, TREE_TYPE (out), out, priv); + out = unshare_expr (out); + gimplify_assign (out, x, end); + } + gimple *g + = gimple_build_assign (new_var, POINTER_PLUS_EXPR, new_var, + TYPE_SIZE_UNIT (TREE_TYPE (type))); + gimple_seq_add_stmt (end, g); + g = gimple_build_assign (ref, POINTER_PLUS_EXPR, ref, + TYPE_SIZE_UNIT (TREE_TYPE (type))); + gimple_seq_add_stmt (end, g); + g = gimple_build_assign (i, PLUS_EXPR, i, + build_int_cst (TREE_TYPE (i), 1)); + gimple_seq_add_stmt (end, g); + g = gimple_build_cond (LE_EXPR, i, v, body, endl); + gimple_seq_add_stmt (end, g); + gimple_seq_add_stmt (end, gimple_build_label (endl)); + } + else if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c)) + { + tree placeholder = OMP_CLAUSE_REDUCTION_PLACEHOLDER (c); + tree oldv = NULL_TREE; + tree lab6 = NULL_TREE; + if (cancellable) + { + /* If this reduction needs destruction and parallel + has been cancelled, jump around the merge operation + to the destruction. */ + tree lab5 = create_artificial_label (UNKNOWN_LOCATION); + lab6 = create_artificial_label (UNKNOWN_LOCATION); + tree zero = build_zero_cst (TREE_TYPE (cancellable)); + g = gimple_build_cond (NE_EXPR, cancellable, zero, + lab6, lab5); + gimple_seq_add_stmt (end, g); + gimple_seq_add_stmt (end, gimple_build_label (lab5)); + } + if (omp_is_reference (decl) + && !useless_type_conversion_p (TREE_TYPE (placeholder), + TREE_TYPE (ref))) + ref = build_fold_addr_expr_loc (OMP_CLAUSE_LOCATION (c), ref); + ref = build_fold_addr_expr_loc (OMP_CLAUSE_LOCATION (c), ref); + tree refv = create_tmp_var (TREE_TYPE (ref)); + gimplify_assign (refv, ref, end); + ref = build_simple_mem_ref_loc (OMP_CLAUSE_LOCATION (c), refv); + SET_DECL_VALUE_EXPR (placeholder, ref); + DECL_HAS_VALUE_EXPR_P (placeholder) = 1; + tree d = maybe_lookup_decl (decl, ctx); + gcc_assert (d); + if (DECL_HAS_VALUE_EXPR_P (d)) + oldv = DECL_VALUE_EXPR (d); + if (omp_is_reference (var)) + { + tree v = fold_convert (TREE_TYPE (d), + build_fold_addr_expr (new_var)); + SET_DECL_VALUE_EXPR (d, v); + } + else + SET_DECL_VALUE_EXPR (d, new_var); + DECL_HAS_VALUE_EXPR_P (d) = 1; + lower_omp (&OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c), ctx); + if (oldv) + SET_DECL_VALUE_EXPR (d, oldv); + else + { + SET_DECL_VALUE_EXPR (d, NULL_TREE); + DECL_HAS_VALUE_EXPR_P (d) = 0; + } + gimple_seq_add_seq (end, OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c)); + OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c) = NULL; + if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION) + OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL; + if (cancellable) + gimple_seq_add_stmt (end, gimple_build_label (lab6)); + tree x = lang_hooks.decls.omp_clause_dtor (c, new_var); + if (x) + { + gimple_seq tseq = NULL; + gimplify_stmt (&x, &tseq); + gimple_seq_add_seq (end, tseq); + } + } + else + { + tree x = build2 (rcode, TREE_TYPE (ref), ref, new_var); + ref = unshare_expr (ref); + gimplify_assign (ref, x, end); + } + gimple_seq_add_stmt (end, gimple_build_label (lab4)); + ++cnt; + field = DECL_CHAIN (bfield); + } + } + + if (code == OMP_TASKGROUP) + { + t = builtin_decl_explicit (BUILT_IN_GOMP_TASKGROUP_REDUCTION_REGISTER); + g = gimple_build_call (t, 1, build_fold_addr_expr (avar)); + gimple_seq_add_stmt (start, g); + } + else + { + tree c; + if (code == OMP_FOR) + c = gimple_omp_for_clauses (ctx->stmt); + else if (code == OMP_SECTIONS) + c = gimple_omp_sections_clauses (ctx->stmt); + else + c = gimple_omp_taskreg_clauses (ctx->stmt); + c = omp_find_clause (c, OMP_CLAUSE__REDUCTEMP_); + t = fold_convert (TREE_TYPE (OMP_CLAUSE_DECL (c)), + build_fold_addr_expr (avar)); + gimplify_assign (OMP_CLAUSE_DECL (c), t, start); + } + + gimple_seq_add_stmt (end, gimple_build_assign (data, PLUS_EXPR, data, sz)); + gimple_seq_add_stmt (end, gimple_build_assign (idx, PLUS_EXPR, idx, + size_one_node)); + g = gimple_build_cond (NE_EXPR, idx, num_thr_sz, lab1, lab2); + gimple_seq_add_stmt (end, g); + gimple_seq_add_stmt (end, gimple_build_label (lab2)); + if (code == OMP_FOR || code == OMP_SECTIONS) + { + enum built_in_function bfn + = BUILT_IN_GOMP_WORKSHARE_TASK_REDUCTION_UNREGISTER; + t = builtin_decl_explicit (bfn); + tree c_bool_type = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (t))); + tree arg; + if (cancellable) + { + arg = create_tmp_var (c_bool_type); + gimple_seq_add_stmt (end, gimple_build_assign (arg, NOP_EXPR, + cancellable)); + } + else + arg = build_int_cst (c_bool_type, 0); + g = gimple_build_call (t, 1, arg); + } + else + { + t = builtin_decl_explicit (BUILT_IN_GOMP_TASKGROUP_REDUCTION_UNREGISTER); + g = gimple_build_call (t, 1, build_fold_addr_expr (avar)); + } + gimple_seq_add_stmt (end, g); + t = build_constructor (atype, NULL); + TREE_THIS_VOLATILE (t) = 1; + gimple_seq_add_stmt (end, gimple_build_assign (avar, t)); +} /* Expand code for an OpenMP taskgroup directive. */ @@ -6149,21 +7527,31 @@ lower_omp_taskgroup (gimple_stmt_iterator *gsi_p, omp_context *ctx) gimple *stmt = gsi_stmt (*gsi_p); gcall *x; gbind *bind; + gimple_seq dseq = NULL; tree block = make_node (BLOCK); bind = gimple_build_bind (NULL, NULL, block); gsi_replace (gsi_p, bind, true); gimple_bind_add_stmt (bind, stmt); + push_gimplify_context (); + x = gimple_build_call (builtin_decl_explicit (BUILT_IN_GOMP_TASKGROUP_START), 0); gimple_bind_add_stmt (bind, x); + lower_omp_task_reductions (ctx, OMP_TASKGROUP, + gimple_omp_taskgroup_clauses (stmt), + gimple_bind_body_ptr (bind), &dseq); + lower_omp (gimple_omp_body_ptr (stmt), ctx); gimple_bind_add_seq (bind, gimple_omp_body (stmt)); gimple_omp_set_body (stmt, NULL); gimple_bind_add_stmt (bind, gimple_build_omp_return (true)); + gimple_bind_add_seq (bind, dseq); + + pop_gimplify_context (bind); gimple_bind_append_vars (bind, ctx->block_vars); BLOCK_VARS (block) = ctx->block_vars; @@ -6752,7 +8140,8 @@ lower_omp_for (gimple_stmt_iterator *gsi_p, omp_context *ctx) struct omp_for_data fd, *fdp = NULL; gomp_for *stmt = as_a <gomp_for *> (gsi_stmt (*gsi_p)); gbind *new_stmt; - gimple_seq omp_for_body, body, dlist; + gimple_seq omp_for_body, body, dlist, tred_ilist = NULL, tred_dlist = NULL; + gimple_seq cnt_list = NULL; gimple_seq oacc_head = NULL, oacc_tail = NULL; size_t i; @@ -6845,9 +8234,30 @@ lower_omp_for (gimple_stmt_iterator *gsi_p, omp_context *ctx) /* The pre-body and input clauses go before the lowered GIMPLE_OMP_FOR. */ dlist = NULL; body = NULL; + tree rclauses + = omp_task_reductions_find_first (gimple_omp_for_clauses (stmt), OMP_FOR, + OMP_CLAUSE_REDUCTION); + tree rtmp = NULL_TREE; + if (rclauses) + { + tree type = build_pointer_type (pointer_sized_int_node); + tree temp = create_tmp_var (type); + tree c = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE__REDUCTEMP_); + OMP_CLAUSE_DECL (c) = temp; + OMP_CLAUSE_CHAIN (c) = gimple_omp_for_clauses (stmt); + gimple_omp_for_set_clauses (stmt, c); + lower_omp_task_reductions (ctx, OMP_FOR, + gimple_omp_for_clauses (stmt), + &tred_ilist, &tred_dlist); + rclauses = c; + rtmp = make_ssa_name (type); + gimple_seq_add_stmt (&body, gimple_build_assign (rtmp, temp)); + } + lower_rec_input_clauses (gimple_omp_for_clauses (stmt), &body, &dlist, ctx, fdp); - gimple_seq_add_seq (&body, gimple_omp_for_pre_body (stmt)); + gimple_seq_add_seq (rclauses ? &tred_ilist : &body, + gimple_omp_for_pre_body (stmt)); lower_omp (gimple_omp_body_ptr (stmt), ctx); @@ -6862,20 +8272,24 @@ lower_omp_for (gimple_stmt_iterator *gsi_p, omp_context *ctx) { rhs_p = gimple_omp_for_initial_ptr (stmt, i); if (!is_gimple_min_invariant (*rhs_p)) - *rhs_p = get_formal_tmp_var (*rhs_p, &body); + *rhs_p = get_formal_tmp_var (*rhs_p, &cnt_list); else if (TREE_CODE (*rhs_p) == ADDR_EXPR) recompute_tree_invariant_for_addr_expr (*rhs_p); rhs_p = gimple_omp_for_final_ptr (stmt, i); if (!is_gimple_min_invariant (*rhs_p)) - *rhs_p = get_formal_tmp_var (*rhs_p, &body); + *rhs_p = get_formal_tmp_var (*rhs_p, &cnt_list); else if (TREE_CODE (*rhs_p) == ADDR_EXPR) recompute_tree_invariant_for_addr_expr (*rhs_p); rhs_p = &TREE_OPERAND (gimple_omp_for_incr (stmt, i), 1); if (!is_gimple_min_invariant (*rhs_p)) - *rhs_p = get_formal_tmp_var (*rhs_p, &body); + *rhs_p = get_formal_tmp_var (*rhs_p, &cnt_list); } + if (rclauses) + gimple_seq_add_seq (&tred_ilist, cnt_list); + else + gimple_seq_add_seq (&body, cnt_list); /* Once lowered, extract the bounds and clauses. */ omp_extract_for_data (stmt, &fd, NULL); @@ -6922,13 +8336,26 @@ lower_omp_for (gimple_stmt_iterator *gsi_p, omp_context *ctx) gimple_seq_add_seq (&body, dlist); + if (rclauses) + { + gimple_seq_add_seq (&tred_ilist, body); + body = tred_ilist; + } + body = maybe_catch_exception (body); if (!phony_loop) { /* Region exit marker goes at the end of the loop body. */ - gimple_seq_add_stmt (&body, gimple_build_omp_return (fd.have_nowait)); - maybe_add_implicit_barrier_cancel (ctx, &body); + gimple *g = gimple_build_omp_return (fd.have_nowait); + gimple_seq_add_stmt (&body, g); + + gimple_seq_add_seq (&body, tred_dlist); + + maybe_add_implicit_barrier_cancel (ctx, g, &body); + + if (rclauses) + OMP_CLAUSE_DECL (rclauses) = rtmp; } /* Add OpenACC joining and reduction markers just after the loop. */ @@ -7153,6 +8580,40 @@ create_task_copyfn (gomp_task *task_stmt, omp_context *ctx) t = build2 (MODIFY_EXPR, TREE_TYPE (dst), dst, src); append_to_statement_list (t, &list); break; + case OMP_CLAUSE_REDUCTION: + case OMP_CLAUSE_IN_REDUCTION: + decl = OMP_CLAUSE_DECL (c); + if (TREE_CODE (decl) == MEM_REF) + { + decl = TREE_OPERAND (decl, 0); + if (TREE_CODE (decl) == POINTER_PLUS_EXPR) + decl = TREE_OPERAND (decl, 0); + if (TREE_CODE (decl) == INDIRECT_REF + || TREE_CODE (decl) == ADDR_EXPR) + decl = TREE_OPERAND (decl, 0); + } + key = (splay_tree_key) decl; + n = splay_tree_lookup (ctx->field_map, key); + if (n == NULL) + break; + f = (tree) n->value; + if (tcctx.cb.decl_map) + f = *tcctx.cb.decl_map->get (f); + n = splay_tree_lookup (ctx->sfield_map, key); + sf = (tree) n->value; + if (tcctx.cb.decl_map) + sf = *tcctx.cb.decl_map->get (sf); + src = build_simple_mem_ref_loc (loc, sarg); + src = omp_build_component_ref (src, sf); + if (decl != OMP_CLAUSE_DECL (c) + && TREE_CODE (TREE_TYPE (decl)) == REFERENCE_TYPE + && TREE_CODE (TREE_TYPE (TREE_TYPE (decl))) == POINTER_TYPE) + src = build_simple_mem_ref_loc (loc, src); + dst = build_simple_mem_ref_loc (loc, arg); + dst = omp_build_component_ref (dst, f); + t = build2 (MODIFY_EXPR, TREE_TYPE (dst), dst, src); + append_to_statement_list (t, &list); + break; case OMP_CLAUSE__LOOPTEMP_: /* Fields for first two _looptemp_ clauses are initialized by GOMP_taskloop*, the rest are handled like firstprivate. */ @@ -7162,6 +8623,7 @@ create_task_copyfn (gomp_task *task_stmt, omp_context *ctx) break; } /* FALLTHRU */ + case OMP_CLAUSE__REDUCTEMP_: case OMP_CLAUSE_FIRSTPRIVATE: decl = OMP_CLAUSE_DECL (c); if (is_variable_sized (decl)) @@ -7187,7 +8649,7 @@ create_task_copyfn (gomp_task *task_stmt, omp_context *ctx) src = decl; dst = build_simple_mem_ref_loc (loc, arg); dst = omp_build_component_ref (dst, f); - if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE__LOOPTEMP_) + if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_FIRSTPRIVATE) t = build2 (MODIFY_EXPR, TREE_TYPE (dst), dst, src); else t = lang_hooks.decls.omp_clause_copy_ctor (c, dst, src); @@ -7279,7 +8741,7 @@ lower_depend_clauses (tree *pclauses, gimple_seq *iseq, gimple_seq *oseq) { tree c, clauses; gimple *g; - size_t n_in = 0, n_out = 0, idx = 2, i; + size_t cnt[4] = { 0, 0, 0, 0 }, idx = 2, i; clauses = omp_find_clause (*pclauses, OMP_CLAUSE_DEPEND); gcc_assert (clauses); @@ -7287,12 +8749,21 @@ lower_depend_clauses (tree *pclauses, gimple_seq *iseq, gimple_seq *oseq) if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND) switch (OMP_CLAUSE_DEPEND_KIND (c)) { + case OMP_CLAUSE_DEPEND_LAST: + /* Lowering already done at gimplification. */ + return; case OMP_CLAUSE_DEPEND_IN: - n_in++; + cnt[2]++; break; case OMP_CLAUSE_DEPEND_OUT: case OMP_CLAUSE_DEPEND_INOUT: - n_out++; + cnt[0]++; + break; + case OMP_CLAUSE_DEPEND_MUTEXINOUTSET: + cnt[1]++; + break; + case OMP_CLAUSE_DEPEND_DEPOBJ: + cnt[3]++; break; case OMP_CLAUSE_DEPEND_SOURCE: case OMP_CLAUSE_DEPEND_SINK: @@ -7300,25 +8771,61 @@ lower_depend_clauses (tree *pclauses, gimple_seq *iseq, gimple_seq *oseq) default: gcc_unreachable (); } - tree type = build_array_type_nelts (ptr_type_node, n_in + n_out + 2); + if (cnt[1] || cnt[3]) + idx = 5; + size_t total = cnt[0] + cnt[1] + cnt[2] + cnt[3]; + tree type = build_array_type_nelts (ptr_type_node, total + idx); tree array = create_tmp_var (type); TREE_ADDRESSABLE (array) = 1; tree r = build4 (ARRAY_REF, ptr_type_node, array, size_int (0), NULL_TREE, NULL_TREE); - g = gimple_build_assign (r, build_int_cst (ptr_type_node, n_in + n_out)); - gimple_seq_add_stmt (iseq, g); - r = build4 (ARRAY_REF, ptr_type_node, array, size_int (1), NULL_TREE, - NULL_TREE); - g = gimple_build_assign (r, build_int_cst (ptr_type_node, n_out)); + if (idx == 5) + { + g = gimple_build_assign (r, build_int_cst (ptr_type_node, 0)); + gimple_seq_add_stmt (iseq, g); + r = build4 (ARRAY_REF, ptr_type_node, array, size_int (1), NULL_TREE, + NULL_TREE); + } + g = gimple_build_assign (r, build_int_cst (ptr_type_node, total)); gimple_seq_add_stmt (iseq, g); - for (i = 0; i < 2; i++) + for (i = 0; i < (idx == 5 ? 3 : 1); i++) + { + r = build4 (ARRAY_REF, ptr_type_node, array, + size_int (i + 1 + (idx == 5)), NULL_TREE, NULL_TREE); + g = gimple_build_assign (r, build_int_cst (ptr_type_node, cnt[i])); + gimple_seq_add_stmt (iseq, g); + } + for (i = 0; i < 4; i++) { - if ((i ? n_in : n_out) == 0) + if (cnt[i] == 0) continue; for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c)) - if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND - && ((OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_IN) ^ i)) + if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND) + continue; + else { + switch (OMP_CLAUSE_DEPEND_KIND (c)) + { + case OMP_CLAUSE_DEPEND_IN: + if (i != 2) + continue; + break; + case OMP_CLAUSE_DEPEND_OUT: + case OMP_CLAUSE_DEPEND_INOUT: + if (i != 0) + continue; + break; + case OMP_CLAUSE_DEPEND_MUTEXINOUTSET: + if (i != 1) + continue; + break; + case OMP_CLAUSE_DEPEND_DEPOBJ: + if (i != 3) + continue; + break; + default: + gcc_unreachable (); + } tree t = OMP_CLAUSE_DECL (c); t = fold_convert (ptr_type_node, t); gimplify_expr (&t, iseq, NULL, is_gimple_val, fb_rvalue); @@ -7329,6 +8836,7 @@ lower_depend_clauses (tree *pclauses, gimple_seq *iseq, gimple_seq *oseq) } } c = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE_DEPEND); + OMP_CLAUSE_DEPEND_KIND (c) = OMP_CLAUSE_DEPEND_LAST; OMP_CLAUSE_DECL (c) = build_fold_addr_expr (array); OMP_CLAUSE_CHAIN (c) = *pclauses; *pclauses = c; @@ -7348,13 +8856,22 @@ lower_omp_taskreg (gimple_stmt_iterator *gsi_p, omp_context *ctx) tree child_fn, t; gimple *stmt = gsi_stmt (*gsi_p); gbind *par_bind, *bind, *dep_bind = NULL; - gimple_seq par_body, olist, ilist, par_olist, par_rlist, par_ilist, new_body; + gimple_seq par_body; location_t loc = gimple_location (stmt); clauses = gimple_omp_taskreg_clauses (stmt); - par_bind - = as_a <gbind *> (gimple_seq_first_stmt (gimple_omp_body (stmt))); - par_body = gimple_bind_body (par_bind); + if (gimple_code (stmt) == GIMPLE_OMP_TASK + && gimple_omp_task_taskwait_p (stmt)) + { + par_bind = NULL; + par_body = NULL; + } + else + { + par_bind + = as_a <gbind *> (gimple_seq_first_stmt (gimple_omp_body (stmt))); + par_body = gimple_bind_body (par_bind); + } child_fn = ctx->cb.dst_fn; if (gimple_code (stmt) == GIMPLE_OMP_PARALLEL && !gimple_omp_parallel_combined_p (stmt)) @@ -7380,14 +8897,49 @@ lower_omp_taskreg (gimple_stmt_iterator *gsi_p, omp_context *ctx) &dep_ilist, &dep_olist); } + if (gimple_code (stmt) == GIMPLE_OMP_TASK + && gimple_omp_task_taskwait_p (stmt)) + { + if (dep_bind) + { + gsi_replace (gsi_p, dep_bind, true); + gimple_bind_add_seq (dep_bind, dep_ilist); + gimple_bind_add_stmt (dep_bind, stmt); + gimple_bind_add_seq (dep_bind, dep_olist); + pop_gimplify_context (dep_bind); + } + return; + } + if (ctx->srecord_type) create_task_copyfn (as_a <gomp_task *> (stmt), ctx); + gimple_seq tskred_ilist = NULL; + gimple_seq tskred_olist = NULL; + if ((is_task_ctx (ctx) + && gimple_omp_task_taskloop_p (ctx->stmt) + && omp_find_clause (gimple_omp_task_clauses (ctx->stmt), + OMP_CLAUSE_REDUCTION)) + || (is_parallel_ctx (ctx) + && omp_find_clause (gimple_omp_parallel_clauses (stmt), + OMP_CLAUSE__REDUCTEMP_))) + { + if (dep_bind == NULL) + { + push_gimplify_context (); + dep_bind = gimple_build_bind (NULL, NULL, make_node (BLOCK)); + } + lower_omp_task_reductions (ctx, is_task_ctx (ctx) ? OMP_TASKLOOP + : OMP_PARALLEL, + gimple_omp_taskreg_clauses (ctx->stmt), + &tskred_ilist, &tskred_olist); + } + push_gimplify_context (); - par_olist = NULL; - par_ilist = NULL; - par_rlist = NULL; + gimple_seq par_olist = NULL; + gimple_seq par_ilist = NULL; + gimple_seq par_rlist = NULL; bool phony_construct = gimple_code (stmt) == GIMPLE_OMP_PARALLEL && gimple_omp_parallel_grid_phony (as_a <gomp_parallel *> (stmt)); if (phony_construct && ctx->record_type) @@ -7417,8 +8969,8 @@ lower_omp_taskreg (gimple_stmt_iterator *gsi_p, omp_context *ctx) gimple_omp_taskreg_set_data_arg (stmt, ctx->sender_decl); } - olist = NULL; - ilist = NULL; + gimple_seq olist = NULL; + gimple_seq ilist = NULL; lower_send_clauses (clauses, &ilist, &olist, ctx); lower_send_shared_vars (&ilist, &olist, ctx); @@ -7433,7 +8985,7 @@ lower_omp_taskreg (gimple_stmt_iterator *gsi_p, omp_context *ctx) /* Once all the expansions are done, sequence all the different fragments inside gimple_omp_body. */ - new_body = NULL; + gimple_seq new_body = NULL; if (ctx->record_type) { @@ -7461,7 +9013,10 @@ lower_omp_taskreg (gimple_stmt_iterator *gsi_p, omp_context *ctx) gimple_omp_set_body (stmt, new_body); } - bind = gimple_build_bind (NULL, NULL, gimple_bind_block (par_bind)); + if (dep_bind && gimple_bind_block (par_bind) == NULL_TREE) + bind = gimple_build_bind (NULL, NULL, make_node (BLOCK)); + else + bind = gimple_build_bind (NULL, NULL, gimple_bind_block (par_bind)); gsi_replace (gsi_p, dep_bind ? dep_bind : bind, true); gimple_bind_add_seq (bind, ilist); if (!phony_construct) @@ -7475,7 +9030,9 @@ lower_omp_taskreg (gimple_stmt_iterator *gsi_p, omp_context *ctx) if (dep_bind) { gimple_bind_add_seq (dep_bind, dep_ilist); + gimple_bind_add_seq (dep_bind, tskred_ilist); gimple_bind_add_stmt (dep_bind, bind); + gimple_bind_add_seq (dep_bind, tskred_olist); gimple_bind_add_seq (dep_bind, dep_olist); pop_gimplify_context (dep_bind); } @@ -8830,7 +10387,10 @@ lower_omp_1 (gimple_stmt_iterator *gsi_p, omp_context *ctx) case GIMPLE_OMP_TEAMS: ctx = maybe_lookup_ctx (stmt); gcc_assert (ctx); - lower_omp_teams (gsi_p, ctx); + if (gimple_omp_teams_host (as_a <gomp_teams *> (stmt))) + lower_omp_taskreg (gsi_p, ctx); + else + lower_omp_teams (gsi_p, ctx); break; case GIMPLE_OMP_GRID_BODY: ctx = maybe_lookup_ctx (stmt); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 5d24473..c227dc9 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,114 @@ +2018-11-08 Jakub Jelinek <jakub@redhat.com> + + * c-c++-common/gomp/atomic-17.c: New test. + * c-c++-common/gomp/atomic-18.c: New test. + * c-c++-common/gomp/atomic-19.c: New test. + * c-c++-common/gomp/atomic-20.c: New test. + * c-c++-common/gomp/atomic-21.c: New test. + * c-c++-common/gomp/atomic-22.c: New test. + * c-c++-common/gomp/clauses-1.c (r2): New variable. + (foo): Add ntm argument and test if and nontemporal clauses on + constructs with simd. + (bar): Put taskloop simd inside of taskgroup with task_reduction, + use in_reduction clause instead of reduction. Add another + taskloop simd without nogroup clause, but with reduction clause and + a new in_reduction. Add ntm and i3 arguments. Test if and + nontemporal clauses on constructs with simd. Change if clauses on + some constructs from specific to the particular constituents to one + without a modifier. Add new tests for combined host teams and for + new parallel master and {,parallel }master taskloop{, simd} combined + constructs. + (baz): New function with host teams tests. + * gcc.dg/gomp/combined-1.c: Moved to ... + * c-c++-common/gomp/combined-1.c: ... here. Adjust expected library + call. + * c-c++-common/gomp/combined-2.c: New test. + * c-c++-common/gomp/combined-3.c: New test. + * c-c++-common/gomp/critical-1.c: New test. + * c-c++-common/gomp/critical-2.c: New test. + * c-c++-common/gomp/default-1.c: New test. + * c-c++-common/gomp/defaultmap-1.c: New test. + * c-c++-common/gomp/defaultmap-2.c: New test. + * c-c++-common/gomp/defaultmap-3.c: New test. + * c-c++-common/gomp/depend-5.c: New test. + * c-c++-common/gomp/depend-6.c: New test. + * c-c++-common/gomp/depend-iterator-1.c: New test. + * c-c++-common/gomp/depend-iterator-2.c: New test. + * c-c++-common/gomp/depobj-1.c: New test. + * c-c++-common/gomp/flush-1.c: New test. + * c-c++-common/gomp/flush-2.c: New test. + * c-c++-common/gomp/for-1.c: New test. + * c-c++-common/gomp/for-2.c: New test. + * c-c++-common/gomp/for-3.c: New test. + * c-c++-common/gomp/for-4.c: New test. + * c-c++-common/gomp/for-5.c: New test. + * c-c++-common/gomp/for-6.c: New test. + * c-c++-common/gomp/for-7.c: New test. + * c-c++-common/gomp/if-1.c (foo): Add some further tests. + * c-c++-common/gomp/if-2.c (foo): Likewise. Expect slightly different + diagnostics wording in one case. + * c-c++-common/gomp/if-3.c: New test. + * c-c++-common/gomp/master-combined-1.c: New test. + * c-c++-common/gomp/master-combined-2.c: New test. + * c-c++-common/gomp/nontemporal-1.c: New test. + * c-c++-common/gomp/nontemporal-2.c: New test. + * c-c++-common/gomp/reduction-task-1.c: New test. + * c-c++-common/gomp/reduction-task-2.c: New test. + * c-c++-common/gomp/requires-1.c: New test. + * c-c++-common/gomp/requires-2.c: New test. + * c-c++-common/gomp/requires-3.c: New test. + * c-c++-common/gomp/requires-4.c: New test. + * c-c++-common/gomp/schedule-modifiers-1.c (bar): Don't expect + diagnostics for nonmonotonic modifier with static, runtime or auto + schedule kinds. + * c-c++-common/gomp/simd7.c: New test. + * c-c++-common/gomp/target-data-1.c: New test. + * c-c++-common/gomp/taskloop-reduction-1.c: New test. + * c-c++-common/gomp/taskwait-depend-1.c: New test. + * c-c++-common/gomp/teams-1.c: New test. + * c-c++-common/gomp/teams-2.c: New test. + * gcc.dg/gomp/appendix-a/a.24.1.c: Update from OpenMP examples. Add + shared(c) clause. + * gcc.dg/gomp/atomic-5.c (f1): Add another expected error. + * gcc.dg/gomp/clause-1.c: Adjust expected diagnostics for const + qualified vars without mutable member no longer being predeterined + shared. + * gcc.dg/gomp/sharing-1.c: Likewise. + * g++.dg/gomp/clause-3.C: Likewise. + * g++.dg/gomp/member-2.C: Likewise. + * g++.dg/gomp/predetermined-1.C: Likewise. + * g++.dg/gomp/private-1.C: Likewise. + * g++.dg/gomp/sharing-1.C: Likewise. + * g++.dg/gomp/sharing-2.C: Likewise. Add a few tests with aggregate + const static data member without mutable elements. + * gcc.dg/gomp/for-4.c: Expected nonmonotonic functions in the dumps. + * gcc.dg/gomp/for-5.c: Likewise. + * gcc.dg/gomp/for-6.c: Change expected library call. + * gcc.dg/gomp/pr39495-2.c (foo): Don't expect errors on !=. + * gcc.dg/gomp/reduction-2.c: New test. + * gcc.dg/gomp/simd-1.c: New test. + * gcc.dg/gomp/teams-1.c: Adjust expected diagnostic lines. + * g++.dg/gomp/atomic-18.C: New test. + * g++.dg/gomp/atomic-19.C: New test. + * g++.dg/gomp/atomic-5.C (f1): Adjust expected lines of read-only + variable messages. Add another expected error. + * g++.dg/gomp/critical-3.C: New test. + * g++.dg/gomp/depend-iterator-1.C: New test. + * g++.dg/gomp/depend-iterator-2.C: New test. + * g++.dg/gomp/depobj-1.C: New test. + * g++.dg/gomp/doacross-1.C: New test. + * g++.dg/gomp/for-21.C: New test. + * g++.dg/gomp/for-4.C: Expected nonmonotonic functions in the dumps. + * g++.dg/gomp/for-5.C: Likewise. + * g++.dg/gomp/for-6.C: Change expected library call. + * g++.dg/gomp/loop-4.C: New test. + * g++.dg/gomp/pr33372-1.C: Adjust location of the expected + diagnostics. + * g++.dg/gomp/pr33372-3.C: Likewise. + * g++.dg/gomp/pr39495-2.C (foo): Don't expect errors on !=. + * g++.dg/gomp/simd-2.C: New test. + * g++.dg/gomp/tpl-atomic-2.C: Adjust expected diagnostic lines. + 2018-11-08 Uros Bizjak <ubizjak@gmail.com> * gcc.dg/pr87874.c (em): Declare uint64_max as diff --git a/gcc/testsuite/c-c++-common/gomp/atomic-17.c b/gcc/testsuite/c-c++-common/gomp/atomic-17.c new file mode 100644 index 0000000..d313b29 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/atomic-17.c @@ -0,0 +1,29 @@ +int i, v; +float f; + +void +foo () +{ + #pragma omp atomic release, hint (0), update + i = i + 1; + #pragma omp atomic hint(0)seq_cst + i = i + 1; + #pragma omp atomic relaxed,update,hint (0) + i = i + 1; + #pragma omp atomic release + i = i + 1; + #pragma omp atomic relaxed + i = i + 1; + #pragma omp atomic acq_rel capture + v = i = i + 1; + #pragma omp atomic capture,acq_rel , hint (1) + v = i = i + 1; + #pragma omp atomic hint(0),acquire capture + v = i = i + 1; + #pragma omp atomic read acquire + v = i; + #pragma omp atomic release,write + i = v; + #pragma omp atomic hint(1),update,release + f = f + 2.0; +} diff --git a/gcc/testsuite/c-c++-common/gomp/atomic-18.c b/gcc/testsuite/c-c++-common/gomp/atomic-18.c new file mode 100644 index 0000000..95fbcd1 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/atomic-18.c @@ -0,0 +1,35 @@ +int i, v; +float f; + +void +foo (int j) +{ + #pragma omp atomic update,update /* { dg-error "too many atomic clauses" } */ + i = i + 1; + #pragma omp atomic seq_cst release /* { dg-error "too many memory order clauses" } */ + i = i + 1; + #pragma omp atomic read,release /* { dg-error "incompatible with 'acq_rel' or 'release' clauses" } */ + v = i; + #pragma omp atomic acq_rel read /* { dg-error "incompatible with 'acq_rel' or 'release' clauses" } */ + v = i; + #pragma omp atomic write acq_rel /* { dg-error "incompatible with 'acq_rel' or 'acquire' clauses" } */ + i = v; + #pragma omp atomic acquire , write /* { dg-error "incompatible with 'acq_rel' or 'acquire' clauses" } */ + i = v; + #pragma omp atomic update ,acquire /* { dg-error "incompatible with 'acq_rel' or 'acquire' clauses" } */ + i = i + 1; + #pragma omp atomic acq_rel update /* { dg-error "incompatible with 'acq_rel' or 'acquire' clauses" } */ + i = i + 1; + #pragma omp atomic acq_rel,hint(0) /* { dg-error "incompatible with 'acq_rel' or 'acquire' clauses" } */ + i = i + 1; + #pragma omp atomic acquire /* { dg-error "incompatible with 'acq_rel' or 'acquire' clauses" } */ + i = i + 1; + #pragma omp atomic capture hint (0) capture /* { dg-error "too many atomic clauses" } */ + v = i = i + 1; + #pragma omp atomic hint(j + 2) /* { dg-error "constant integer expression" } */ + i = i + 1; + #pragma omp atomic hint(f) /* { dg-error "integ" } */ + i = i + 1; + #pragma omp atomic foobar /* { dg-error "expected 'read', 'write', 'update', 'capture', 'seq_cst', 'acq_rel', 'release', 'relaxed' or 'hint' clause" } */ + i = i + 1; /* { dg-error "expected end of line before" "" { target *-*-* } .-1 } */ +} diff --git a/gcc/testsuite/c-c++-common/gomp/atomic-19.c b/gcc/testsuite/c-c++-common/gomp/atomic-19.c new file mode 100644 index 0000000..b15761e --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/atomic-19.c @@ -0,0 +1,27 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-fdump-tree-original" } */ +/* { dg-final { scan-tree-dump-times "omp atomic release" 1 "original" } } */ +/* { dg-final { scan-tree-dump-times "omp atomic relaxed" 3 "original" } } */ +/* { dg-final { scan-tree-dump-times "omp atomic read relaxed" 1 "original" } } */ +/* { dg-final { scan-tree-dump-times "omp atomic capture relaxed" 1 "original" } } */ + +int i, j, k, l, m, n; + +void +foo () +{ + int v; + #pragma omp atomic release + i = i + 1; + #pragma omp requires atomic_default_mem_order (relaxed) + #pragma omp atomic + j = j + 1; + #pragma omp atomic update + k = k + 1; + #pragma omp atomic read + v = l; + #pragma omp atomic write + m = v; + #pragma omp atomic capture + v = n = n + 1; +} diff --git a/gcc/testsuite/c-c++-common/gomp/atomic-20.c b/gcc/testsuite/c-c++-common/gomp/atomic-20.c new file mode 100644 index 0000000..3343d5e --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/atomic-20.c @@ -0,0 +1,27 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-fdump-tree-original" } */ +/* { dg-final { scan-tree-dump-times "omp atomic release" 1 "original" } } */ +/* { dg-final { scan-tree-dump-times "omp atomic seq_cst" 3 "original" } } */ +/* { dg-final { scan-tree-dump-times "omp atomic read seq_cst" 1 "original" } } */ +/* { dg-final { scan-tree-dump-times "omp atomic capture seq_cst" 1 "original" } } */ + +int i, j, k, l, m, n; + +void +foo () +{ + int v; + #pragma omp atomic release + i = i + 1; + #pragma omp requires atomic_default_mem_order (seq_cst) + #pragma omp atomic + j = j + 1; + #pragma omp atomic update + k = k + 1; + #pragma omp atomic read + v = l; + #pragma omp atomic write + m = v; + #pragma omp atomic capture + v = n = n + 1; +} diff --git a/gcc/testsuite/c-c++-common/gomp/atomic-21.c b/gcc/testsuite/c-c++-common/gomp/atomic-21.c new file mode 100644 index 0000000..8fa97b1 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/atomic-21.c @@ -0,0 +1,26 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-fdump-tree-original" } */ +/* { dg-final { scan-tree-dump-times "omp atomic release" 4 "original" } } */ +/* { dg-final { scan-tree-dump-times "omp atomic read acquire" 1 "original" } } */ +/* { dg-final { scan-tree-dump-times "omp atomic capture acq_rel" 1 "original" } } */ + +int i, j, k, l, m, n; + +void +foo () +{ + int v; + #pragma omp atomic release + i = i + 1; + #pragma omp requires atomic_default_mem_order (acq_rel) + #pragma omp atomic + j = j + 1; + #pragma omp atomic update + k = k + 1; + #pragma omp atomic read + v = l; + #pragma omp atomic write + m = v; + #pragma omp atomic capture + v = n = n + 1; +} diff --git a/gcc/testsuite/c-c++-common/gomp/atomic-22.c b/gcc/testsuite/c-c++-common/gomp/atomic-22.c new file mode 100644 index 0000000..57b0dcb --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/atomic-22.c @@ -0,0 +1,12 @@ +int i, j; + +void +foo () +{ + int v; + #pragma omp atomic release + i = i + 1; + #pragma omp atomic read + v = j; + #pragma omp requires atomic_default_mem_order (acq_rel) /* { dg-error "'atomic_default_mem_order' clause used lexically after first 'atomic' construct without memory order clause" } */ +} diff --git a/gcc/testsuite/c-c++-common/gomp/clauses-1.c b/gcc/testsuite/c-c++-common/gomp/clauses-1.c index fe90c24..652270c 100644 --- a/gcc/testsuite/c-c++-common/gomp/clauses-1.c +++ b/gcc/testsuite/c-c++-common/gomp/clauses-1.c @@ -5,11 +5,11 @@ int t; #pragma omp threadprivate (t) #pragma omp declare target -int f, l, ll, r; +int f, l, ll, r, r2; void foo (int d, int m, int i1, int i2, int p, int *idp, int s, - int nte, int tl, int nth, int g, int nta, int fi, int pp, int *q) + int nte, int tl, int nth, int g, int nta, int fi, int pp, int *q, int ntm) { #pragma omp distribute parallel for \ private (p) firstprivate (f) collapse(1) dist_schedule(static, 16) \ @@ -19,26 +19,50 @@ foo (int d, int m, int i1, int i2, int p, int *idp, int s, ll++; #pragma omp distribute parallel for simd \ private (p) firstprivate (f) collapse(1) dist_schedule(static, 16) \ - if (parallel: i2) default(shared) shared(s) reduction(+:r) num_threads (nth) proc_bind(spread) \ - lastprivate (l) schedule(static, 4) \ + if (parallel: i2) if(simd: i1) default(shared) shared(s) reduction(+:r) num_threads (nth) proc_bind(spread) \ + lastprivate (l) schedule(static, 4) nontemporal(ntm) \ safelen(8) simdlen(4) aligned(q: 32) for (int i = 0; i < 64; i++) ll++; #pragma omp distribute simd \ private (p) firstprivate (f) collapse(1) dist_schedule(static, 16) \ - safelen(8) simdlen(4) aligned(q: 32) reduction(+:r) + safelen(8) simdlen(4) aligned(q: 32) reduction(+:r) if(i1) nontemporal(ntm) for (int i = 0; i < 64; i++) ll++; } #pragma omp end declare target void -bar (int d, int m, int i1, int i2, int p, int *idp, int s, - int nte, int tl, int nth, int g, int nta, int fi, int pp, int *q, int *dd) +baz (int d, int m, int i1, int i2, int p, int *idp, int s, + int nte, int tl, int nth, int g, int nta, int fi, int pp, int *q, int ntm) +{ + #pragma omp distribute parallel for \ + private (p) firstprivate (f) collapse(1) dist_schedule(static, 16) \ + if (parallel: i2) default(shared) shared(s) reduction(+:r) num_threads (nth) proc_bind(spread) \ + lastprivate (l) schedule(static, 4) copyin(t) + for (int i = 0; i < 64; i++) + ll++; + #pragma omp distribute parallel for simd \ + private (p) firstprivate (f) collapse(1) dist_schedule(static, 16) \ + if (parallel: i2) if(simd: i1) default(shared) shared(s) reduction(+:r) num_threads (nth) proc_bind(spread) \ + lastprivate (l) schedule(static, 4) nontemporal(ntm) \ + safelen(8) simdlen(4) aligned(q: 32) copyin(t) + for (int i = 0; i < 64; i++) + ll++; + #pragma omp distribute simd \ + private (p) firstprivate (f) collapse(1) dist_schedule(static, 16) \ + safelen(8) simdlen(4) aligned(q: 32) reduction(+:r) if(i1) nontemporal(ntm) + for (int i = 0; i < 64; i++) + ll++; +} + +void +bar (int d, int m, int i1, int i2, int i3, int p, int *idp, int s, + int nte, int tl, int nth, int g, int nta, int fi, int pp, int *q, int *dd, int ntm) { #pragma omp for simd \ private (p) firstprivate (f) lastprivate (l) linear (ll:1) reduction(+:r) schedule(static, 4) collapse(1) nowait \ - safelen(8) simdlen(4) aligned(q: 32) + safelen(8) simdlen(4) aligned(q: 32) nontemporal(ntm) if(i1) for (int i = 0; i < 64; i++) ll++; #pragma omp parallel for \ @@ -47,9 +71,9 @@ bar (int d, int m, int i1, int i2, int p, int *idp, int s, for (int i = 0; i < 64; i++) ll++; #pragma omp parallel for simd \ - private (p) firstprivate (f) if (parallel: i2) default(shared) shared(s) copyin(t) reduction(+:r) num_threads (nth) proc_bind(spread) \ + private (p) firstprivate (f) if (i2) default(shared) shared(s) copyin(t) reduction(+:r) num_threads (nth) proc_bind(spread) \ lastprivate (l) linear (ll:1) schedule(static, 4) collapse(1) \ - safelen(8) simdlen(4) aligned(q: 32) + safelen(8) simdlen(4) aligned(q: 32) nontemporal(ntm) for (int i = 0; i < 64; i++) ll++; #pragma omp parallel sections \ @@ -76,7 +100,7 @@ bar (int d, int m, int i1, int i2, int p, int *idp, int s, device(d) map (tofrom: m) if (target: i1) private (p) firstprivate (f) defaultmap(tofrom: scalar) is_device_ptr (idp) \ if (parallel: i2) default(shared) shared(s) reduction(+:r) num_threads (nth) proc_bind(spread) \ lastprivate (l) linear (ll:1) schedule(static, 4) collapse(1) \ - safelen(8) simdlen(4) aligned(q: 32) nowait depend(inout: dd[0]) + safelen(8) simdlen(4) aligned(q: 32) nowait depend(inout: dd[0]) nontemporal(ntm) if (simd: i3) for (int i = 0; i < 64; i++) ll++; #pragma omp target teams \ @@ -103,31 +127,38 @@ bar (int d, int m, int i1, int i2, int p, int *idp, int s, collapse(1) dist_schedule(static, 16) \ if (parallel: i2) num_threads (nth) proc_bind(spread) \ lastprivate (l) schedule(static, 4) \ - safelen(8) simdlen(4) aligned(q: 32) nowait depend(inout: dd[0]) + safelen(8) simdlen(4) aligned(q: 32) nowait depend(inout: dd[0]) nontemporal(ntm) if (simd: i3) for (int i = 0; i < 64; i++) ll++; #pragma omp target teams distribute simd \ - device(d) map (tofrom: m) if (target: i1) private (p) firstprivate (f) defaultmap(tofrom: scalar) is_device_ptr (idp) \ + device(d) map (tofrom: m) if (i1) private (p) firstprivate (f) defaultmap(tofrom: scalar) is_device_ptr (idp) \ shared(s) default(shared) reduction(+:r) num_teams(nte) thread_limit(tl) \ collapse(1) dist_schedule(static, 16) \ - safelen(8) simdlen(4) aligned(q: 32) nowait depend(inout: dd[0]) + safelen(8) simdlen(4) aligned(q: 32) nowait depend(inout: dd[0]) nontemporal(ntm) for (int i = 0; i < 64; i++) ll++; #pragma omp target simd \ device(d) map (tofrom: m) if (target: i1) private (p) firstprivate (f) defaultmap(tofrom: scalar) is_device_ptr (idp) \ safelen(8) simdlen(4) lastprivate (l) linear(ll: 1) aligned(q: 32) reduction(+:r) \ - nowait depend(inout: dd[0]) + nowait depend(inout: dd[0]) nontemporal(ntm) if(simd:i3) + for (int i = 0; i < 64; i++) + ll++; + #pragma omp taskgroup task_reduction(+:r2) + #pragma omp taskloop simd \ + private (p) firstprivate (f) lastprivate (l) shared (s) default(shared) grainsize (g) collapse(1) untied if(taskloop: i1) if(simd: i2) final(fi) mergeable priority (pp) \ + safelen(8) simdlen(4) linear(ll: 1) aligned(q: 32) reduction(default, +:r) in_reduction(+:r2) nontemporal(ntm) for (int i = 0; i < 64; i++) ll++; + #pragma omp taskgroup task_reduction(+:r) #pragma omp taskloop simd \ - private (p) firstprivate (f) lastprivate (l) shared (s) default(shared) grainsize (g) collapse(1) untied if(taskloop: i1) final(fi) mergeable nogroup priority (pp) \ - safelen(8) simdlen(4) linear(ll: 1) aligned(q: 32) reduction(+:r) + private (p) firstprivate (f) lastprivate (l) shared (s) default(shared) grainsize (g) collapse(1) untied if(i1) final(fi) mergeable nogroup priority (pp) \ + safelen(8) simdlen(4) linear(ll: 1) aligned(q: 32) in_reduction(+:r) nontemporal(ntm) for (int i = 0; i < 64; i++) ll++; #pragma omp taskwait #pragma omp taskloop simd \ private (p) firstprivate (f) lastprivate (l) shared (s) default(shared) num_tasks (nta) collapse(1) if(taskloop: i1) final(fi) priority (pp) \ - safelen(8) simdlen(4) linear(ll: 1) aligned(q: 32) reduction(+:r) + safelen(8) simdlen(4) linear(ll: 1) aligned(q: 32) reduction(+:r) if (simd: i3) nontemporal(ntm) for (int i = 0; i < 64; i++) ll++; #pragma omp target nowait depend(inout: dd[0]) @@ -150,14 +181,83 @@ bar (int d, int m, int i1, int i2, int p, int *idp, int s, collapse(1) dist_schedule(static, 16) \ if (parallel: i2) num_threads (nth) proc_bind(spread) \ lastprivate (l) schedule(static, 4) \ - safelen(8) simdlen(4) aligned(q: 32) + safelen(8) simdlen(4) aligned(q: 32) if (simd: i3) nontemporal(ntm) for (int i = 0; i < 64; i++) ll++; #pragma omp target #pragma omp teams distribute simd \ private(p) firstprivate (f) shared(s) default(shared) reduction(+:r) num_teams(nte) thread_limit(tl) \ collapse(1) dist_schedule(static, 16) \ - safelen(8) simdlen(4) aligned(q: 32) + safelen(8) simdlen(4) aligned(q: 32) if(i3) nontemporal(ntm) + for (int i = 0; i < 64; i++) + ll++; + #pragma omp teams distribute parallel for \ + private(p) firstprivate (f) shared(s) default(shared) reduction(+:r) num_teams(nte) thread_limit(tl) \ + collapse(1) dist_schedule(static, 16) \ + if (parallel: i2) num_threads (nth) proc_bind(spread) \ + lastprivate (l) schedule(static, 4) copyin(t) + for (int i = 0; i < 64; i++) + ll++; + #pragma omp teams distribute parallel for simd \ + private(p) firstprivate (f) shared(s) default(shared) reduction(+:r) num_teams(nte) thread_limit(tl) \ + collapse(1) dist_schedule(static, 16) \ + if (parallel: i2) num_threads (nth) proc_bind(spread) \ + lastprivate (l) schedule(static, 4) \ + safelen(8) simdlen(4) aligned(q: 32) if (simd: i3) nontemporal(ntm) copyin(t) + for (int i = 0; i < 64; i++) + ll++; + #pragma omp teams distribute simd \ + private(p) firstprivate (f) shared(s) default(shared) reduction(+:r) num_teams(nte) thread_limit(tl) \ + collapse(1) dist_schedule(static, 16) \ + safelen(8) simdlen(4) aligned(q: 32) if(i3) nontemporal(ntm) + for (int i = 0; i < 64; i++) + ll++; + #pragma omp parallel master \ + private (p) firstprivate (f) if (parallel: i2) default(shared) shared(s) reduction(+:r) \ + num_threads (nth) proc_bind(spread) copyin(t) + ; + #pragma omp taskgroup task_reduction (+:r2) + #pragma omp master taskloop \ + private (p) firstprivate (f) lastprivate (l) shared (s) default(shared) grainsize (g) collapse(1) untied if(taskloop: i1) final(fi) mergeable priority (pp) \ + reduction(default, +:r) in_reduction(+:r2) + for (int i = 0; i < 64; i++) + ll++; + #pragma omp taskgroup task_reduction (+:r2) + #pragma omp master taskloop simd \ + private (p) firstprivate (f) lastprivate (l) shared (s) default(shared) grainsize (g) collapse(1) untied if(taskloop: i1) if(simd: i2) final(fi) mergeable priority (pp) \ + safelen(8) simdlen(4) linear(ll: 1) aligned(q: 32) reduction(default, +:r) in_reduction(+:r2) nontemporal(ntm) + for (int i = 0; i < 64; i++) + ll++; + #pragma omp parallel master taskloop \ + private (p) firstprivate (f) lastprivate (l) shared (s) default(shared) grainsize (g) collapse(1) untied if(taskloop: i1) final(fi) mergeable priority (pp) \ + reduction(default, +:r) if (parallel: i2) num_threads (nth) proc_bind(spread) copyin(t) + for (int i = 0; i < 64; i++) + ll++; + #pragma omp parallel master taskloop simd \ + private (p) firstprivate (f) lastprivate (l) shared (s) default(shared) grainsize (g) collapse(1) untied if(taskloop: i1) if(simd: i2) final(fi) mergeable priority (pp) \ + safelen(8) simdlen(4) linear(ll: 1) aligned(q: 32) reduction(default, +:r) nontemporal(ntm) if (parallel: i2) num_threads (nth) proc_bind(spread) copyin(t) + for (int i = 0; i < 64; i++) + ll++; + #pragma omp taskgroup task_reduction (+:r2) + #pragma omp master taskloop \ + private (p) firstprivate (f) lastprivate (l) shared (s) default(shared) num_tasks (nta) collapse(1) untied if(i1) final(fi) mergeable priority (pp) \ + reduction(default, +:r) in_reduction(+:r2) + for (int i = 0; i < 64; i++) + ll++; + #pragma omp taskgroup task_reduction (+:r2) + #pragma omp master taskloop simd \ + private (p) firstprivate (f) lastprivate (l) shared (s) default(shared) num_tasks (nta) collapse(1) untied if(i1) final(fi) mergeable priority (pp) \ + safelen(8) simdlen(4) linear(ll: 1) aligned(q: 32) reduction(default, +:r) in_reduction(+:r2) nontemporal(ntm) + for (int i = 0; i < 64; i++) + ll++; + #pragma omp parallel master taskloop \ + private (p) firstprivate (f) lastprivate (l) shared (s) default(shared) num_tasks (nta) collapse(1) untied if(i1) final(fi) mergeable priority (pp) \ + reduction(default, +:r) num_threads (nth) proc_bind(spread) copyin(t) + for (int i = 0; i < 64; i++) + ll++; + #pragma omp parallel master taskloop simd \ + private (p) firstprivate (f) lastprivate (l) shared (s) default(shared) num_tasks (nta) collapse(1) untied if(i1) final(fi) mergeable priority (pp) \ + safelen(8) simdlen(4) linear(ll: 1) aligned(q: 32) reduction(default, +:r) nontemporal(ntm) num_threads (nth) proc_bind(spread) copyin(t) for (int i = 0; i < 64; i++) ll++; } diff --git a/gcc/testsuite/c-c++-common/gomp/combined-1.c b/gcc/testsuite/c-c++-common/gomp/combined-1.c new file mode 100644 index 0000000..4d62844c --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/combined-1.c @@ -0,0 +1,23 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -fopenmp -fdump-tree-optimized" } */ + +int a[10]; +void foo (void) +{ + int i; +#pragma omp parallel for schedule(runtime) + for (i = 0; i < 10; i++) + a[i] = i; +#pragma omp parallel +#pragma omp for schedule(runtime) + for (i = 0; i < 10; i++) + a[i] = 10 - i; +#pragma omp parallel + { +#pragma omp for schedule(runtime) + for (i = 0; i < 10; i++) + a[i] = i; + } +} + +/* { dg-final { scan-tree-dump-times "GOMP_parallel_loop_maybe_nonmonotonic_runtime" 3 "optimized" } } */ diff --git a/gcc/testsuite/c-c++-common/gomp/combined-2.c b/gcc/testsuite/c-c++-common/gomp/combined-2.c new file mode 100644 index 0000000..82bc4df --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/combined-2.c @@ -0,0 +1,23 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -fopenmp -fdump-tree-optimized" } */ + +int a[10]; +void foo (void) +{ + int i; +#pragma omp parallel for schedule(monotonic:runtime) + for (i = 0; i < 10; i++) + a[i] = i; +#pragma omp parallel +#pragma omp for schedule(monotonic :runtime) + for (i = 0; i < 10; i++) + a[i] = 10 - i; +#pragma omp parallel + { +#pragma omp for schedule(monotonic: runtime) + for (i = 0; i < 10; i++) + a[i] = i; + } +} + +/* { dg-final { scan-tree-dump-times "GOMP_parallel_loop_runtime" 3 "optimized" } } */ diff --git a/gcc/testsuite/c-c++-common/gomp/combined-3.c b/gcc/testsuite/c-c++-common/gomp/combined-3.c new file mode 100644 index 0000000..33c9884 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/combined-3.c @@ -0,0 +1,23 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -fopenmp -fdump-tree-optimized" } */ + +int a[10]; +void foo (void) +{ + int i; +#pragma omp parallel for schedule(nonmonotonic:runtime) + for (i = 0; i < 10; i++) + a[i] = i; +#pragma omp parallel +#pragma omp for schedule(nonmonotonic :runtime) + for (i = 0; i < 10; i++) + a[i] = 10 - i; +#pragma omp parallel + { +#pragma omp for schedule(nonmonotonic: runtime) + for (i = 0; i < 10; i++) + a[i] = i; + } +} + +/* { dg-final { scan-tree-dump-times "GOMP_parallel_loop_nonmonotonic_runtime" 3 "optimized" } } */ diff --git a/gcc/testsuite/c-c++-common/gomp/critical-1.c b/gcc/testsuite/c-c++-common/gomp/critical-1.c new file mode 100644 index 0000000..8d607e4 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/critical-1.c @@ -0,0 +1,14 @@ +int i; + +void +foo (void) +{ + #pragma omp critical + i = i + 1; + #pragma omp critical (foo) + i = i + 1; + #pragma omp critical (foo) hint (0) + i = i + 1; + #pragma omp critical (foo),hint(1) + i = i + 1; +} diff --git a/gcc/testsuite/c-c++-common/gomp/critical-2.c b/gcc/testsuite/c-c++-common/gomp/critical-2.c new file mode 100644 index 0000000..f501cc1 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/critical-2.c @@ -0,0 +1,10 @@ +int i; + +void +foo (int j) +{ + #pragma omp critical (foo) hint (j + 1) /* { dg-error "constant integer expression" } */ + i = i + 1; + #pragma omp critical (foo),hint(j) /* { dg-error "constant integer expression" } */ + i = i + 1; +} diff --git a/gcc/testsuite/c-c++-common/gomp/default-1.c b/gcc/testsuite/c-c++-common/gomp/default-1.c new file mode 100644 index 0000000..6525483 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/default-1.c @@ -0,0 +1,22 @@ +void +foo (void) +{ + int x = 0, i; + #pragma omp task default(none) /* { dg-error "enclosing 'task'" } */ + { + x++; /* { dg-error "'x' not specified in enclosing 'task'" } */ + } + #pragma omp taskloop default(none) /* { dg-error "enclosing 'taskloop'" } */ + for (i = 0; i < 64; i++) + { + x++; /* { dg-error "'x' not specified in enclosing 'taskloop'" } */ + } + #pragma omp teams default(none) /* { dg-error "enclosing 'teams'" } */ + { + x++; /* { dg-error "'x' not specified in enclosing 'teams'" } */ + } + #pragma omp parallel default(none) /* { dg-error "enclosing 'parallel'" } */ + { + x++; /* { dg-error "'x' not specified in enclosing 'parallel'" } */ + } +} diff --git a/gcc/testsuite/c-c++-common/gomp/defaultmap-1.c b/gcc/testsuite/c-c++-common/gomp/defaultmap-1.c new file mode 100644 index 0000000..80a111c --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/defaultmap-1.c @@ -0,0 +1,30 @@ +void +foo (void) +{ + #pragma omp target defaultmap(alloc) defaultmap(alloc) /* { dg-error "too many 'defaultmap' clauses with unspecified category" } */ + ; + #pragma omp target defaultmap(to) defaultmap(from) /* { dg-error "too many 'defaultmap' clauses with unspecified category" } */ + ; + #pragma omp target defaultmap(tofrom) defaultmap(firstprivate:scalar) /* { dg-error "too many 'defaultmap' clauses with 'scalar' category" } */ + ; + #pragma omp target defaultmap(none:aggregate) defaultmap(alloc:scalar) defaultmap(none:scalar) /* { dg-error "too many 'defaultmap' clauses with 'scalar' category" } */ + ; + #pragma omp target defaultmap(none : pointer) defaultmap ( none ) /* { dg-error "too many 'defaultmap' clauses with 'pointer' category" } */ + ; + #pragma omp target defaultmap() /* { dg-error "expected" } */ + ; + #pragma omp target defaultmap(for) /* { dg-error "expected" } */ + ; + #pragma omp target defaultmap(blah) /* { dg-error "expected" } */ + ; + #pragma omp target defaultmap(tofrom:) /* { dg-error "expected" } */ + ; + #pragma omp target defaultmap(tofrom scalar) /* { dg-error "expected" } */ + ; + #pragma omp target defaultmap(tofrom,scalar) /* { dg-error "expected" } */ + ; + #pragma omp target defaultmap(default ;) /* { dg-error "expected" } */ + ; + #pragma omp target defaultmap(default : qux) /* { dg-error "expected" } */ + ; +} diff --git a/gcc/testsuite/c-c++-common/gomp/defaultmap-2.c b/gcc/testsuite/c-c++-common/gomp/defaultmap-2.c new file mode 100644 index 0000000..75dca23 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/defaultmap-2.c @@ -0,0 +1,131 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-fdump-tree-gimple" } */ + +struct S { int s; }; +void foo (char *); +void bar (int, char *, struct S, int *); +#pragma omp declare target to (bar) +#define N 16 + +void +f1 (int sc1, struct S ag1, int *pt1) +{ + char ar1[N]; + foo (ar1); + #pragma omp target + bar (sc1, ar1, ag1, pt1); +/* { dg-final { scan-tree-dump "firstprivate\\(sc1\\)" "gimple" } } */ +/* { dg-final { scan-tree-dump "map\\(tofrom:ar1" "gimple" } } */ +/* { dg-final { scan-tree-dump "map\\(tofrom:ag1" "gimple" } } */ +/* { dg-final { scan-tree-dump "map\\(firstprivate:pt1 .pointer assign" "gimple" } } */ +} + +void +f2 (int sc2, struct S ag2, int *pt2) +{ + char ar2[N]; + foo (ar2); + #pragma omp target firstprivate (sc2, ar2, ag2, pt2) defaultmap (none) + bar (sc2, ar2, ag2, pt2); +/* { dg-final { scan-tree-dump "firstprivate\\(sc2\\)" "gimple" } } */ +/* { dg-final { scan-tree-dump "firstprivate\\(ar2\\)" "gimple" } } */ +/* { dg-final { scan-tree-dump "firstprivate\\(ag2\\)" "gimple" } } */ +/* { dg-final { scan-tree-dump "firstprivate\\(pt2\\)" "gimple" } } */ +} + +void +f3 (int sc3, struct S ag3, int *pt3) +{ + char ar3[N]; + foo (ar3); + #pragma omp target defaultmap(none:scalar) defaultmap(none:aggregate) \ + map (sc3, ar3, ag3, pt3) defaultmap(none:pointer) + bar (sc3, ar3, ag3, pt3); +/* { dg-final { scan-tree-dump "map\\(tofrom:sc3" "gimple" } } */ +/* { dg-final { scan-tree-dump "map\\(tofrom:ar3" "gimple" } } */ +/* { dg-final { scan-tree-dump "map\\(tofrom:ag3" "gimple" } } */ +/* { dg-final { scan-tree-dump "map\\(tofrom:pt3" "gimple" } } */ +} + +void +f4 (int sc4, struct S ag4, int *pt4) +{ + char ar4[N]; + foo (ar4); + #pragma omp target defaultmap(tofrom:scalar) + bar (sc4, ar4, ag4, pt4); +/* { dg-final { scan-tree-dump "map\\(tofrom:sc4" "gimple" } } */ +/* { dg-final { scan-tree-dump "map\\(tofrom:ar4" "gimple" } } */ +/* { dg-final { scan-tree-dump "map\\(tofrom:ag4" "gimple" } } */ +/* { dg-final { scan-tree-dump "map\\(firstprivate:pt4 .pointer assign" "gimple" } } */ +} + +void +f5 (int sc5, struct S ag5, int *pt5) +{ + char ar5[N]; + foo (ar5); + #pragma omp target defaultmap(to) + bar (sc5, ar5, ag5, pt5); +/* { dg-final { scan-tree-dump "map\\(to:sc5" "gimple" } } */ +/* { dg-final { scan-tree-dump "map\\(to:ar5" "gimple" } } */ +/* { dg-final { scan-tree-dump "map\\(to:ag5" "gimple" } } */ +/* { dg-final { scan-tree-dump "map\\(to:pt5" "gimple" } } */ +} + +void +f6 (int sc6, struct S ag6, int *pt6) +{ + char ar6[N]; + foo (ar6); + #pragma omp target defaultmap(firstprivate) + bar (sc6, ar6, ag6, pt6); +/* { dg-final { scan-tree-dump "firstprivate\\(sc6\\)" "gimple" } } */ +/* { dg-final { scan-tree-dump "firstprivate\\(ar6\\)" "gimple" } } */ +/* { dg-final { scan-tree-dump "firstprivate\\(ag6\\)" "gimple" } } */ +/* { dg-final { scan-tree-dump "firstprivate\\(pt6\\)" "gimple" } } */ +} + +void +f7 (int sc7, struct S ag7, int *pt7) +{ + char ar7[N]; + foo (ar7); + #pragma omp target defaultmap(alloc: scalar) defaultmap(from: aggregate) defaultmap(default: pointer) + { + int *q = &sc7; + *q = 6; + ag7.s = 5; + int i; + for (i = 0; i < N; ++i) + ar7[i] = 7; + bar (sc7, ar7, ag7, pt7); + } +/* { dg-final { scan-tree-dump "map\\(alloc:sc7" "gimple" } } */ +/* { dg-final { scan-tree-dump "map\\(from:ar7" "gimple" } } */ +/* { dg-final { scan-tree-dump "map\\(from:ag7" "gimple" } } */ +/* { dg-final { scan-tree-dump "map\\(firstprivate:pt7 .pointer assign" "gimple" } } */ +} + +void +f8 (int sc8, struct S ag8, int *pt8) +{ + char ar8[N]; + foo (ar8); + #pragma omp target defaultmap(firstprivate:aggregate) defaultmap(none:scalar) \ + defaultmap(tofrom:pointer) map(to: sc8) + bar (sc8, ar8, ag8, pt8); +/* { dg-final { scan-tree-dump "map\\(to:sc8" "gimple" } } */ +/* { dg-final { scan-tree-dump "firstprivate\\(ar8\\)" "gimple" } } */ +/* { dg-final { scan-tree-dump "firstprivate\\(ag8\\)" "gimple" } } */ +/* { dg-final { scan-tree-dump "map\\(tofrom:pt8" "gimple" } } */ +} + +void +f9 (int sc9, struct S ag9) +{ + char ar9[sc9 + 2]; + foo (ar9); + #pragma omp target defaultmap(none) map(to: ar9, ag9) firstprivate (sc9) + bar (sc9, ar9, ag9, &sc9); +} diff --git a/gcc/testsuite/c-c++-common/gomp/defaultmap-3.c b/gcc/testsuite/c-c++-common/gomp/defaultmap-3.c new file mode 100644 index 0000000..2f5b303 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/defaultmap-3.c @@ -0,0 +1,34 @@ +/* { dg-do compile } */ + +struct S { int s; }; +void foo (char *); +void bar (int, char *, struct S, int *); +#pragma omp declare target to (bar) +#define N 16 + +void +f1 (int sc1, struct S ag1, int *pt1) +{ + char ar1[N]; + foo (ar1); + #pragma omp target defaultmap(default:scalar) defaultmap(to:aggregate) defaultmap(none:pointer) /* { dg-error "enclosing 'target'" } */ + bar (sc1, ar1, ag1, pt1); /* { dg-error "'pt1' not specified in enclosing 'target'" } */ +} + +void +f2 (int sc2, struct S ag2, int *pt2) +{ + char ar2[N]; + foo (ar2); + #pragma omp target defaultmap(none:scalar) defaultmap(from:aggregate) defaultmap(default:pointer) /* { dg-error "enclosing 'target'" } */ + bar (sc2, ar2, ag2, pt2); /* { dg-error "'sc2' not specified in enclosing 'target'" } */ +} + +void +f3 (int sc3, struct S ag3, int *pt3) +{ + char ar3[N]; + foo (ar3); + #pragma omp target defaultmap(firstprivate:scalar) defaultmap(none:aggregate) defaultmap(to:pointer) /* { dg-error "enclosing 'target'" } */ + bar (sc3, ar3, ag3, pt3); /* { dg-error "'ar3' not specified in enclosing 'target'" } */ +} /* { dg-error "'ag3' not specified in enclosing 'target'" "" { target *-*-* } .-1 } */ diff --git a/gcc/testsuite/c-c++-common/gomp/depend-5.c b/gcc/testsuite/c-c++-common/gomp/depend-5.c new file mode 100644 index 0000000..993987f --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/depend-5.c @@ -0,0 +1,48 @@ +/* { dg-do compile } */ +/* { dg-options "-fopenmp" } */ + +struct T { int c[3]; }; +struct S { int a; struct T *b; struct T g; }; +struct S d[10]; +struct S *e[10]; +struct S *f; +struct S h; + +void +foo (void) +{ + #pragma omp task depend(inout: d) + ; + #pragma omp task depend(out: d[2]) + ; + #pragma omp task depend(in: d[:]) + ; + #pragma omp task depend(in: d[2:2]) + ; + #pragma omp task depend(in: d[:2]) + ; + #pragma omp task depend(inout: d[1].b->c[2]) + ; + #pragma omp task depend(out: d[0].a) + ; + #pragma omp task depend(in: e[3]->a) + ; + #pragma omp task depend(inout: e[2]->b->c) + ; + #pragma omp task depend(in: e[1]->b->c[2]) + ; + #pragma omp task depend(out: (*f).a) + ; + #pragma omp task depend(inout: f->b->c[0]) + ; + #pragma omp task depend(in: f) + ; + #pragma omp task depend(out: *f) + ; + #pragma omp task depend(inout: f[0]) + ; + #pragma omp task depend(in: f[0].a) + ; + #pragma omp task depend(inout: h.g.c[2]) + ; +} diff --git a/gcc/testsuite/c-c++-common/gomp/depend-6.c b/gcc/testsuite/c-c++-common/gomp/depend-6.c new file mode 100644 index 0000000..4684653 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/depend-6.c @@ -0,0 +1,36 @@ +/* { dg-do compile } */ +/* { dg-options "-fopenmp" } */ + +struct T { int c[3]; }; +struct S { int a; struct T *b; struct T g; }; +struct U { int a : 5; }; +struct S d[10]; +struct S *e[10]; +struct S *f; +struct S h; +struct U i; + +void +foo (void) +{ + #pragma omp task depend(in: d[:2].b->c[2]) /* { dg-error "expected" } */ + ; + #pragma omp task depend(inout: d[1:].b->c[2]) /* { dg-error "expected" } */ + ; + #pragma omp task depend(out: d[0:1].a) /* { dg-error "expected" } */ + ; + #pragma omp task depend(in: e[3:2]->a) /* { dg-error "expected" } */ + ; + #pragma omp task depend(inout: e[2:2]->b->c) /* { dg-error "expected" } */ + ; + #pragma omp task depend(in: e[1]->b->c[2:1]) /* { dg-error "expected" } */ + ; + #pragma omp task depend(out: f + 0) /* { dg-error "not lvalue expression" } */ + ; + #pragma omp task depend(inout: f[0:1].a) /* { dg-error "expected" } */ + ; + #pragma omp task depend(inout: h.g.c[2:1]) /* { dg-error "expected" } */ + ; + #pragma omp task depend(in: i.a) /* { dg-error "bit-field '\[^\n\r]*' in 'depend' clause" } */ + ; +} diff --git a/gcc/testsuite/c-c++-common/gomp/depend-iterator-1.c b/gcc/testsuite/c-c++-common/gomp/depend-iterator-1.c new file mode 100644 index 0000000..4fb01c1 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/depend-iterator-1.c @@ -0,0 +1,75 @@ +int arr[64], arr2[64]; +struct S { int a[4]; } k; +short arr4[4]; +volatile int v; +#define TEST_EQ(x,y) ({ int o[x == y ? 1 : -1]; 0; }) + +void +foo (unsigned char i, signed char j) +{ + #pragma omp task depend (iterator (j=6:2:-2) , out : \ + arr[TEST_EQ (sizeof (j), sizeof (int)), \ + TEST_EQ (sizeof (i), sizeof (unsigned char)), \ + TEST_EQ (sizeof (k), sizeof (struct S)), j], \ + arr2[TEST_EQ (((__typeof (j)) -1) < 0, 1), \ + TEST_EQ (((__typeof (i)) -1) < 0, 0), \ + TEST_EQ (((__typeof (k.a[0])) -1) < 0, 1), j]) \ + depend(out: arr[0]) \ + depend (iterator (long long i=__LONG_LONG_MAX__ - 4:__LONG_LONG_MAX__ - 2:2, \ + unsigned short j=~0U-16:~0U-8:3, \ + short *k=&arr4[1]:&arr4[2]:1) , in : \ + arr[TEST_EQ (sizeof (i), sizeof (long long)), \ + TEST_EQ (sizeof (j), sizeof (unsigned short)), \ + TEST_EQ (sizeof (k), sizeof (short *)), \ + TEST_EQ (sizeof (*k), sizeof (short)), i - __LONG_LONG_MAX__ + 4], \ + arr2[TEST_EQ (((__typeof (i)) -1) < 0, 1), \ + TEST_EQ (((__typeof (j)) -1) < 0, 0), \ + TEST_EQ (((__typeof (*k)) -1) < 0, 1), j - (~0U-16)], \ + arr2[k - &arr4[0]]) \ + depend(in : k) + v++; +} + +void +bar (unsigned char i, signed char j) +{ + int m = j; + int n = j + 2; + #pragma omp task depend (iterator (j=6:2:m) , out : \ + arr[TEST_EQ (sizeof (j), sizeof (int)), \ + TEST_EQ (sizeof (i), sizeof (unsigned char)), \ + TEST_EQ (sizeof (k), sizeof (struct S)), j], \ + arr2[TEST_EQ (((__typeof (j)) -1) < 0, 1), \ + TEST_EQ (((__typeof (i)) -1) < 0, 0), \ + TEST_EQ (((__typeof (k.a[0])) -1) < 0, 1), j]) \ + depend(out: arr[0]) \ + depend (iterator (long long i=__LONG_LONG_MAX__ - 4 - n:__LONG_LONG_MAX__ - 2:2, \ + unsigned short j=~0U-16:~0U-8-n:3, \ + short *k=&arr4[1]:&arr4[n + 2]:1) , in : \ + arr[TEST_EQ (sizeof (i), sizeof (long long)), \ + TEST_EQ (sizeof (j), sizeof (unsigned short)), \ + TEST_EQ (sizeof (k), sizeof (short *)), \ + TEST_EQ (sizeof (*k), sizeof (short)), i - __LONG_LONG_MAX__ + 4], \ + arr2[TEST_EQ (((__typeof (i)) -1) < 0, 1), \ + TEST_EQ (((__typeof (j)) -1) < 0, 0), \ + TEST_EQ (((__typeof (*k)) -1) < 0, 1), j - (~0U-16)], \ + arr2[k - &arr4[0]:10]) \ + depend(in : k) + v++; +} + +void +baz (void) +{ + #pragma omp parallel + #pragma omp master + { + #pragma omp task depend(iterator(unsigned long int k = 0 : 2) , inout : \ + arr[TEST_EQ (sizeof (k), sizeof (unsigned long)), \ + TEST_EQ (((__typeof (k)) -1) < 0, 0), k]) \ + depend(iterator(signed char s = -3 : -12 : -1) , out : \ + arr[TEST_EQ (sizeof (s), sizeof (signed char)), \ + TEST_EQ (((__typeof (s)) -1) < 0, 1), s + 12]) + v++; + } +} diff --git a/gcc/testsuite/c-c++-common/gomp/depend-iterator-2.c b/gcc/testsuite/c-c++-common/gomp/depend-iterator-2.c new file mode 100644 index 0000000..1275282 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/depend-iterator-2.c @@ -0,0 +1,97 @@ +int a, b[64]; +struct S { int c; } *d, *e; +struct T; +struct T *f, *g; +int *h; + +void +f1 (void) +{ + #pragma omp task depend (iterator , in : a) /* { dg-error "expected" } */ + ; + #pragma omp task depend (iterator (for = 0 : 2) , in : a) /* { dg-error "expected" } */ + ; + #pragma omp task depend (iterator (5 = 0 : 2) , in : a) /* { dg-error "expected" } */ + ; + #pragma omp task depend (iterator (i : 0 : 2) , in : a) /* { dg-error "expected '='|name a type|expected" } */ + ; + #pragma omp task depend (iterator (i = 0, 1 : 2) , in : a) /* { dg-error "expected" } */ + ; + #pragma omp task depend (iterator (i = (0, 1) : 2) , in : a) + ; + #pragma omp task depend (iterator (i = 0 : 1 : 2 : 3) , in : a) /* { dg-error "expected '.'" } */ + ; + #pragma omp task depend (iterator (i = 0 : 2, 3) , in : a) /* { dg-error "expected" } */ + ; + #pragma omp task depend (iterator (i = 0 : 10 : 2, 3) , in : a) /* { dg-error "expected" } */ + ; + #pragma omp task depend (iterator (i = 0:1), iterator (j = 0:1) , in : a) /* { dg-error "invalid depend kind" } */ + ; + #pragma omp task depend (iterator (i = 0:32) , in : b[i*2:2]) + ; + #pragma omp task depend (iterator (struct S i = 0:1), in : a) /* { dg-error "iterator 'i' has neither integral nor pointer type" } */ + ; + #pragma omp task depend (iterator (void i = 0:1) , in : a) /* { dg-error "iterator 'i' has neither integral nor pointer type" } */ + ; + #pragma omp task depend (iterator (float f = 0.2:0.4) , in : a) /* { dg-error "iterator 'f' has neither integral nor pointer type" } */ + ; + #pragma omp task depend (iterator (struct S *p = d:e:2) , in : a) + ; + #pragma omp task depend (iterator (struct T *p = f:g) , in : a) /* { dg-error "invalid use of" } */ + ; + #pragma omp task depend (iterator (int i = 0:4, \ + struct U { int (*p)[i + 2]; } *p = 0:2) , in : a) /* { dg-error "type of iterator 'p' refers to outer iterator 'i'" "" { target c } } */ + ; /* { dg-error "types may not be defined in iterator type|not an integer constant" "" { target c++ } .-1 } */ + #pragma omp task depend (iterator (i = 0:4, j = i:16) , in : a) /* { dg-error "begin expression refers to outer iterator 'i'" } */ + ; + #pragma omp task depend (iterator (i = 0:4, j = 2:i:1) , in : a) /* { dg-error "end expression refers to outer iterator 'i'" } */ + ; + #pragma omp task depend (iterator (i = 0:4, j = 2:8:i) , in : a) /* { dg-error "step expression refers to outer iterator 'i'" } */ + ; + #pragma omp task depend (iterator (i = *d:2) , in : a) /* { dg-error "aggregate value used where an integer was expected" "" { target c } } */ + ; /* { dg-error "invalid cast from type 'S' to type 'int'" "" { target c++ } .-1 } */ + #pragma omp task depend (iterator (i = 2:*d:2) , in : a) /* { dg-error "aggregate value used where an integer was expected" "" { target c } } */ + ; /* { dg-error "invalid cast from type 'S' to type 'int'" "" { target c++ } .-1 } */ + #pragma omp task depend (iterator (i = 2:4:*d) , in : a) /* { dg-error "iterator step with non-integral type" } */ + ; + #pragma omp task depend (iterator (i = 1.25:2.5:3) , in : a) + ; + #pragma omp task depend (iterator (i = 1:2:3.5) , in : a) /* { dg-error "iterator step with non-integral type" } */ + ; + #pragma omp task depend (iterator (int *p = 23 : h) , in : a) + ; + #pragma omp task depend (iterator (short i=1:3:0) , in : a) /* { dg-error "iterator 'i' has zero step" } */ + ; + #pragma omp task depend (iterator (i = 1 : 3 : 3 - 3) , in : a) /* { dg-error "iterator 'i' has zero step" } */ + ; + #pragma omp task depend (iterator (int *p = &b[6]:&b[9]:4 - 4) , in : a) /* { dg-error "iterator 'p' has zero step" } */ + ; + #pragma omp task depend (iterator (const int i = 0 : 2) , in : a) /* { dg-error "const qualified" } */ + ; + #pragma omp task depend (iterator (const long long unsigned i = 0 : 2) , in : a) /* { dg-error "const qualified" } */ + ; +#if !defined (__cplusplus) && __STDC_VERSION__ >= 201112L + #pragma omp task depend (iterator (_Atomic unsigned i = 0 : 2) , in : a) /* { dg-error "_Atomic" "" { target c } } */ + ; +#endif +} + +void +f2 (void) +{ + int i, j; + #pragma omp for ordered(2) + for (i = 0; i < 64; i++) + for (j = 0; j < 64; j++) + { + #pragma omp ordered depend (iterator (k=0:1) , sink: i - 1, j - 1) /* { dg-error "'iterator' modifier incompatible with 'sink'" } */ + #pragma omp ordered depend (iterator (int l = 0:2:3) , source) /* { dg-error "'iterator' modifier incompatible with 'source'" } */ + } +} + +void +f3 (void) +{ + #pragma omp task depend (iterator (i = 0:1), iterator (j = 0:1) , in : a) /* { dg-error "invalid depend kind" } */ + ; +} diff --git a/gcc/testsuite/c-c++-common/gomp/depobj-1.c b/gcc/testsuite/c-c++-common/gomp/depobj-1.c new file mode 100644 index 0000000..688371b --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/depobj-1.c @@ -0,0 +1,63 @@ +typedef struct __attribute__((__aligned__ (sizeof (void *)))) omp_depend_t { + char __omp_depend_t__[2 * sizeof (void *)]; +} omp_depend_t; + +omp_depend_t bar (void); +extern const omp_depend_t cdepobj; +extern omp_depend_t depobj; +extern omp_depend_t depobja[4]; +extern omp_depend_t *pdepobj; +int a, b, i, j; + +void +f1 (void) +{ + #pragma omp depobj(depobj) depend(in : a) + #pragma omp depobj(depobj) update(inout) + #pragma omp task depend (depobj: depobj) + ; + #pragma omp depobj(depobj) destroy + #pragma omp task depend (iterator (i=1:3) , depobj: *(depobja + i)) + ; + #pragma omp depobj(pdepobj[0]) depend(mutexinoutset:a) + #pragma omp depobj(*pdepobj) destroy +} + +void +f2 (void) +{ + omp_depend_t depobjb[4]; + #pragma omp depobj /* { dg-error "expected" } */ + #pragma omp depobj destroy /* { dg-error "expected" } */ + #pragma omp depobj (depobj) /* { dg-error "expected 'depend', 'destroy' or 'update' clause" } */ + #pragma omp depobj (depobj) foobar /* { dg-error "expected 'depend', 'destroy' or 'update' clause" } */ + #pragma omp depobj(bar ()) update(inout) /* { dg-error "'depobj' expression is not lvalue expression" } */ + #pragma omp depobj (cdepobj) update(in) /* { dg-error "'const' qualified 'depobj' expression" } */ + #pragma omp depobj (depobjb) depend(in: a) /* { dg-error "type of 'depobj' expression is not 'omp_depend_t'" } */ + #pragma omp depobj (pdepobj) depend(in: a) /* { dg-error "type of 'depobj' expression is not 'omp_depend_t'" } */ + #pragma omp depobj (a) destroy /* { dg-error "type of 'depobj' expression is not 'omp_depend_t'" } */ + #pragma omp depobj (depobj) depend(depobj:a) /* { dg-error "does not have 'omp_depend_t' type in 'depend' clause with 'depobj' dependence type" } */ + #pragma omp depobj (depobj) depend(depobj:*depobjb) /* { dg-error "'depobj' dependence type specified in 'depend' clause on 'depobj' construct" } */ + #pragma omp depobj (depobj) update(foobar) /* { dg-error "expected 'in', 'out', 'inout' or 'mutexinoutset'" } */ + #pragma omp depobj (depobj) depend(in: *depobja) /* { dg-error "should not have 'omp_depend_t' type in 'depend' clause with dependence type" } */ + #pragma omp depobj (depobj) depend(in: a) depend(in: b) /* { dg-error "expected" } */ + #pragma omp depobj (depobj) depend(in: a) update(out) /* { dg-error "expected" } */ + #pragma omp depobj (depobj) depend(in: a, b) /* { dg-error "more than one locator in 'depend' clause on 'depobj' construct" } */ + #pragma omp depobj (depobj) depend(source) /* { dg-error "'depend\\(source\\)' is only allowed in 'omp ordered'" } */ + #pragma omp depobj (depobj) depend(sink: i + 1, j - 1) /* { dg-error "'depend\\(sink\\)' is only allowed in 'omp ordered'" } */ + #pragma omp depobj (depobj) depend(iterator (i = 0:2) , in : a) /* { dg-error "'iterator' modifier may not be specified on 'depobj' construct" } */ + if (0) + #pragma omp depobj (depobj) destroy /* { dg-error "'#pragma omp depobj' may only be used in compound statements" } */ + ; +} + +void +f3 (void) +{ + #pragma omp task depend (depobj: depobja[1:2]) /* { dg-error "'depend' clause with 'depobj' dependence type on array section" } */ + ; + #pragma omp task depend (depobj: a) /* { dg-error "'a' does not have 'omp_depend_t' type in 'depend' clause with 'depobj' dependence type" } */ + ; + #pragma omp task depend (in: depobj) /* { dg-error "'depobj' should not have 'omp_depend_t' type in 'depend' clause with dependence type" } */ + ; +} diff --git a/gcc/testsuite/c-c++-common/gomp/flush-1.c b/gcc/testsuite/c-c++-common/gomp/flush-1.c new file mode 100644 index 0000000..7c3e529 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/flush-1.c @@ -0,0 +1,39 @@ +/* { dg-additional-options "-fdump-tree-gimple" } */ +/* { dg-final { scan-tree-dump "foo \\(4\\);\[\n\r]* __atomic_thread_fence \\(4\\);\[\n\r]* foo \\(4\\);" "gimple" } } */ +/* { dg-final { scan-tree-dump "foo \\(3\\);\[\n\r]* __atomic_thread_fence \\(3\\);\[\n\r]* foo \\(3\\);" "gimple" } } */ +/* { dg-final { scan-tree-dump "foo \\(2\\);\[\n\r]* __atomic_thread_fence \\(2\\);\[\n\r]* foo \\(2\\);" "gimple" } } */ +/* { dg-final { scan-tree-dump "foo \\(5\\);\[\n\r]* __sync_synchronize \\(\\);\[\n\r]* foo \\(5\\);" "gimple" } } */ + +void foo (int); + +void +f1 (void) +{ + foo (4); + #pragma omp flush acq_rel + foo (4); +} + +void +f2 (void) +{ + foo (3); + #pragma omp flush release + foo (3); +} + +void +f3 (void) +{ + foo (2); + #pragma omp flush acquire + foo (2); +} + +void +f4 (void) +{ + foo (5); + #pragma omp flush + foo (5); +} diff --git a/gcc/testsuite/c-c++-common/gomp/flush-2.c b/gcc/testsuite/c-c++-common/gomp/flush-2.c new file mode 100644 index 0000000..00baa8a --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/flush-2.c @@ -0,0 +1,17 @@ +int a, b; + +void +foo (void) +{ + #pragma omp flush + #pragma omp flush (a, b) + #pragma omp flush acquire + #pragma omp flush release + #pragma omp flush acq_rel + #pragma omp flush relaxed /* { dg-error "expected 'acq_rel', 'release' or 'acquire'" } */ + #pragma omp flush seq_cst /* { dg-error "expected 'acq_rel', 'release' or 'acquire'" } */ + #pragma omp flush foobar /* { dg-error "expected 'acq_rel', 'release' or 'acquire'" } */ + #pragma omp flush acquire (a, b) /* { dg-error "'flush' list specified together with memory order clause" } */ + #pragma omp flush release (a, b) /* { dg-error "'flush' list specified together with memory order clause" } */ + #pragma omp flush acq_rel (a, b) /* { dg-error "'flush' list specified together with memory order clause" } */ +} diff --git a/gcc/testsuite/c-c++-common/gomp/for-1.c b/gcc/testsuite/c-c++-common/gomp/for-1.c new file mode 100644 index 0000000..a0e498b --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/for-1.c @@ -0,0 +1,60 @@ +void bar (int); + +int a[256]; + +void +foo (void) +{ + int i; + #pragma omp for + for (i = 0; i != 64; i++) + bar (i); + #pragma omp for + for (i = 128; i != 64; i--) + bar (i); + #pragma omp for + for (i = 0; i != 64; i = i + 1) + bar (i); + #pragma omp for + for (i = 128; i != 64; i = i - 1) + bar (i); + #pragma omp for + for (i = 0; i != 64; i = 1 + i) + bar (i); + #pragma omp for + for (i = 128; i != 64; i = -1 + i) + bar (i); + #pragma omp for + for (i = 0; i != 64; i += 1) + bar (i); + #pragma omp for + for (i = 128; i != 64; i -= 1) + bar (i); + #pragma omp single + { + #pragma omp simd + for (i = 0; i != 64; i++) + a[i] = a[i] + 1; + #pragma omp simd + for (i = 128; i != 64; i--) + a[i] = a[i] + 1; + #pragma omp simd + for (i = 0; i != 64; i = i + 1) + a[i] = a[i] + 1; + #pragma omp simd + for (i = 128; i != 64; i = i - 1) + a[i] = a[i] + 1; + #pragma omp simd + for (i = 0; i != 64; i = 1 + i) + a[i] = a[i] + 1; + #pragma omp simd + for (i = 128; i != 64; i = -1 + i) + a[i] = a[i] + 1; + #pragma omp simd + for (i = 0; i != 64; i += 1) + a[i] = a[i] + 1; + #pragma omp simd + for (i = 128; i != 64; i -= 1) + a[i] = a[i] + 1; + } +} diff --git a/gcc/testsuite/c-c++-common/gomp/for-2.c b/gcc/testsuite/c-c++-common/gomp/for-2.c new file mode 100644 index 0000000..98dfe21 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/for-2.c @@ -0,0 +1,31 @@ +void bar (short *); + +void +foo (short *q, short *r, short *s) +{ + short *p; + #pragma omp for + for (p = q; p != r; p++) + bar (p); + #pragma omp for + for (p = s; p != r; p--) + bar (p); + #pragma omp for + for (p = q; p != r; p = p + 1) + bar (p); + #pragma omp for + for (p = s; p != r; p = p - 1) + bar (p); + #pragma omp for + for (p = q; p != r; p = 1 + p) + bar (p); + #pragma omp for + for (p = s; p != r; p = -1 + p) + bar (p); + #pragma omp for + for (p = q; p != r; p += 1) + bar (p); + #pragma omp for + for (p = s; p != r; p -= 1) + bar (p); +} diff --git a/gcc/testsuite/c-c++-common/gomp/for-3.c b/gcc/testsuite/c-c++-common/gomp/for-3.c new file mode 100644 index 0000000..c3c57e4 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/for-3.c @@ -0,0 +1,48 @@ +void bar (int); + +int a[256]; + +void +foo (int j) +{ + int i; + #pragma omp for + for (i = 0; i != 64; i = i + 4) /* { dg-error "increment is not constant 1 or -1" } */ + bar (i); + #pragma omp for + for (i = 128; i != 64; i = i - 4) /* { dg-error "increment is not constant 1 or -1" } */ + bar (i); + #pragma omp for + for (i = 0; i != 64; i = j + i) /* { dg-error "increment is not constant 1 or -1" } */ + bar (i); + #pragma omp for + for (i = 128; i != 64; i = -16 + i) /* { dg-error "increment is not constant 1 or -1" } */ + bar (i); + #pragma omp for + for (i = 0; i != 64; i += j) /* { dg-error "increment is not constant 1 or -1" } */ + bar (i); + #pragma omp for + for (i = 128; i != 64; i -= 8) /* { dg-error "increment is not constant 1 or -1" } */ + bar (i); + #pragma omp single + { + #pragma omp simd + for (i = 0; i != 64; i = i + 16) /* { dg-error "increment is not constant 1 or -1" } */ + a[i] = a[i] + 1; + #pragma omp simd + for (i = 128; i != 64; i = i - 2) /* { dg-error "increment is not constant 1 or -1" } */ + a[i] = a[i] + 1; + #pragma omp simd + for (i = 0; i != 64; i = j + i) /* { dg-error "increment is not constant 1 or -1" } */ + a[i] = a[i] + 1; + #pragma omp simd + for (i = 128; i != 64; i = -j + i) /* { dg-error "increment is not constant 1 or -1" } */ + a[i] = a[i] + 1; + #pragma omp simd + for (i = 0; i != 64; i += 8) /* { dg-error "increment is not constant 1 or -1" } */ + a[i] = a[i] + 1; + #pragma omp simd + for (i = 128; i != 64; i -= j) /* { dg-error "increment is not constant 1 or -1" } */ + a[i] = a[i] + 1; + } +} diff --git a/gcc/testsuite/c-c++-common/gomp/for-4.c b/gcc/testsuite/c-c++-common/gomp/for-4.c new file mode 100644 index 0000000..53d5260 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/for-4.c @@ -0,0 +1,25 @@ +void bar (short *); + +void +foo (short *q, short *r, short *s, long t) +{ + short *p; + #pragma omp for + for (p = q; p != r; p = p + 5) /* { dg-error "increment is not constant 1 or -1" } */ + bar (p); + #pragma omp for + for (p = s; p != r; p = p - 2) /* { dg-error "increment is not constant 1 or -1" } */ + bar (p); + #pragma omp for + for (p = q; p != r; p = t + p) /* { dg-error "increment is not constant 1 or -1" } */ + bar (p); + #pragma omp for + for (p = s; p != r; p = -t + p) /* { dg-error "increment is not constant 1 or -1" } */ + bar (p); + #pragma omp for + for (p = q; p != r; p += t) /* { dg-error "increment is not constant 1 or -1" } */ + bar (p); + #pragma omp for + for (p = s; p != r; p -= 7) /* { dg-error "increment is not constant 1 or -1" } */ + bar (p); +} diff --git a/gcc/testsuite/c-c++-common/gomp/for-5.c b/gcc/testsuite/c-c++-common/gomp/for-5.c new file mode 100644 index 0000000..6a1d1db --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/for-5.c @@ -0,0 +1,50 @@ +// { dg-options "-fopenmp" } + +void bar (void *); + +__attribute__((noinline, noclone)) void +foo (void *qx, void *rx, void *sx, int n) +{ + unsigned short (*q)[n], (*r)[n], (*s)[n], (*p)[n]; + q = (typeof (q)) qx; + r = (typeof (r)) rx; + s = (typeof (s)) sx; + int t = 1; + int o = -1; + #pragma omp for + for (p = q; p != r; p += t) /* { dg-error "increment is not constant 1 or -1" } */ + bar (p); + #pragma omp for + for (p = s; p != r; p += o) /* { dg-error "increment is not constant 1 or -1" } */ + bar (p); + #pragma omp for + for (p = q; p != r; p = p + t) /* { dg-error "increment is not constant 1 or -1" } */ + bar (p); + #pragma omp for + for (p = s; p != r; p = p + o) /* { dg-error "increment is not constant 1 or -1" } */ + bar (p); + #pragma omp for + for (p = q; p != r; p = t + p) /* { dg-error "increment is not constant 1 or -1" } */ + bar (p); + #pragma omp for + for (p = s; p != r; p = o + p) /* { dg-error "increment is not constant 1 or -1" } */ + bar (p); + #pragma omp for + for (p = q; p != r; p += 2) /* { dg-error "increment is not constant 1 or -1" } */ + bar (p); + #pragma omp for + for (p = s; p != r; p -= 2) /* { dg-error "increment is not constant 1 or -1" } */ + bar (p); + #pragma omp for + for (p = q; p != r; p = p + 3) /* { dg-error "increment is not constant 1 or -1" } */ + bar (p); + #pragma omp for + for (p = s; p != r; p = p - 3) /* { dg-error "increment is not constant 1 or -1" } */ + bar (p); + #pragma omp for + for (p = q; p != r; p = 4 + p) /* { dg-error "increment is not constant 1 or -1" } */ + bar (p); + #pragma omp for + for (p = s; p != r; p = -5 + p) /* { dg-error "increment is not constant 1 or -1" } */ + bar (p); +} diff --git a/gcc/testsuite/c-c++-common/gomp/for-6.c b/gcc/testsuite/c-c++-common/gomp/for-6.c new file mode 100644 index 0000000..274e189 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/for-6.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-fopenmp -fdump-tree-ompexp" } */ + +extern void bar(int); + +void foo (int n) +{ + int i; + + #pragma omp for schedule(monotonic:runtime) + for (i = 0; i < n; ++i) + bar(i); +} + +/* { dg-final { scan-tree-dump-times "GOMP_loop_runtime_start" 1 "ompexp" } } */ +/* { dg-final { scan-tree-dump-times "GOMP_loop_runtime_next" 1 "ompexp" } } */ diff --git a/gcc/testsuite/c-c++-common/gomp/for-7.c b/gcc/testsuite/c-c++-common/gomp/for-7.c new file mode 100644 index 0000000..5cd0a91 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/for-7.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-fopenmp -fdump-tree-ompexp" } */ + +extern void bar(int); + +void foo (int n) +{ + int i; + + #pragma omp for schedule(nonmonotonic:runtime) + for (i = 0; i < n; ++i) + bar(i); +} + +/* { dg-final { scan-tree-dump-times "GOMP_loop_nonmonotonic_runtime_start" 1 "ompexp" } } */ +/* { dg-final { scan-tree-dump-times "GOMP_loop_nonmonotonic_runtime_next" 1 "ompexp" } } */ diff --git a/gcc/testsuite/c-c++-common/gomp/if-1.c b/gcc/testsuite/c-c++-common/gomp/if-1.c index 3a9b538..1ae39e6 100644 --- a/gcc/testsuite/c-c++-common/gomp/if-1.c +++ b/gcc/testsuite/c-c++-common/gomp/if-1.c @@ -14,6 +14,12 @@ foo (int a, int b, int *p, int *q) #pragma omp parallel for simd if (parallel : a) for (i = 0; i < 16; i++) ; + #pragma omp parallel for simd if (simd : a) + for (i = 0; i < 16; i++) + ; + #pragma omp parallel for simd if (simd : a) if (parallel:b) + for (i = 0; i < 16; i++) + ; #pragma omp task if (a) ; #pragma omp task if (task: a) @@ -24,16 +30,37 @@ foo (int a, int b, int *p, int *q) #pragma omp taskloop if (taskloop : a) for (i = 0; i < 16; i++) ; + #pragma omp taskloop simd if (a) + for (i = 0; i < 16; i++) + ; + #pragma omp taskloop simd if (taskloop : a) + for (i = 0; i < 16; i++) + ; + #pragma omp taskloop simd if (simd : a) + for (i = 0; i < 16; i++) + ; + #pragma omp taskloop simd if (taskloop:b) if (simd : a) + for (i = 0; i < 16; i++) + ; #pragma omp target if (a) ; #pragma omp target if (target: a) ; + #pragma omp target simd if (a) + for (i = 0; i < 16; i++) + ; + #pragma omp target simd if (simd : a) if (target: b) + for (i = 0; i < 16; i++) + ; #pragma omp target teams distribute parallel for simd if (a) for (i = 0; i < 16; i++) ; #pragma omp target teams distribute parallel for simd if (parallel : a) if (target: b) for (i = 0; i < 16; i++) ; + #pragma omp target teams distribute parallel for simd if (simd : a) if (target: b) + for (i = 0; i < 16; i++) + ; #pragma omp target data if (a) map (p[0:2]) ; #pragma omp target data if (target data: a) map (p[0:2]) @@ -44,4 +71,47 @@ foo (int a, int b, int *p, int *q) #pragma omp target exit data if (target exit data: a) map (from: p[0:2]) #pragma omp target update if (a) to (q[0:3]) #pragma omp target update if (target update:a) to (q[0:3]) + #pragma omp parallel + { + #pragma omp cancel parallel if (a) + } + #pragma omp parallel + { + #pragma omp cancel parallel if (cancel:a) + } + #pragma omp for + for (i = 0; i < 16; i++) + { + #pragma omp cancel for if (a) + } + #pragma omp for + for (i = 0; i < 16; i++) + { + #pragma omp cancel for if (cancel: a) + } + #pragma omp sections + { + #pragma omp section + { + #pragma omp cancel sections if (a) + } + } + #pragma omp sections + { + #pragma omp section + { + #pragma omp cancel sections if (cancel: a) + } + } + #pragma omp taskgroup + { + #pragma omp task + { + #pragma omp cancel taskgroup if (a) + } + #pragma omp task + { + #pragma omp cancel taskgroup if (cancel: a) + } + } } diff --git a/gcc/testsuite/c-c++-common/gomp/if-2.c b/gcc/testsuite/c-c++-common/gomp/if-2.c index f1f417e..0e9daf2 100644 --- a/gcc/testsuite/c-c++-common/gomp/if-2.c +++ b/gcc/testsuite/c-c++-common/gomp/if-2.c @@ -18,6 +18,8 @@ foo (int a, int b, int *p, int *q, int task) ; #pragma omp parallel if (target update:a) /* { dg-error "expected .parallel. .if. clause modifier rather than .target update." } */ ; + #pragma omp parallel if (cancel:a) /* { dg-error "expected .parallel. .if. clause modifier rather than .cancel." } */ + ; #pragma omp parallel for simd if (target update: a) /* { dg-error "expected .parallel. .if. clause modifier rather than .target update." } */ for (i = 0; i < 16; i++) ; @@ -27,12 +29,15 @@ foo (int a, int b, int *p, int *q, int task) ; #pragma omp task if (parallel: a) /* { dg-error "expected .task. .if. clause modifier rather than .parallel." } */ ; + #pragma omp simd if (cancel: a) /* { dg-error "expected .simd. .if. clause modifier rather than .cancel." } */ + for (i = 0; i < 16; i++) + ; #pragma omp taskloop if (task : a) /* { dg-error "expected .taskloop. .if. clause modifier rather than .task." } */ for (i = 0; i < 16; i++) ; #pragma omp target if (taskloop: a) /* { dg-error "expected .target. .if. clause modifier rather than .taskloop." } */ ; - #pragma omp target teams distribute parallel for simd if (target exit data : a) /* { dg-error "expected .parallel. or .target. .if. clause modifier" } */ + #pragma omp target teams distribute parallel for simd if (target exit data : a) /* { dg-error "expected .target. .if. clause modifier" } */ for (i = 0; i < 16; i++) ; #pragma omp target data if (target: a) map (p[0:2]) /* { dg-error "expected .target data. .if. clause modifier rather than .target." } */ @@ -40,4 +45,9 @@ foo (int a, int b, int *p, int *q, int task) #pragma omp target enter data if (target data: a) map (to: p[0:2]) /* { dg-error "expected .target enter data. .if. clause modifier rather than .target data." } */ #pragma omp target exit data if (target enter data: a) map (from: p[0:2]) /* { dg-error "expected .target exit data. .if. clause modifier rather than .target enter data." } */ #pragma omp target update if (target exit data:a) to (q[0:3]) /* { dg-error "expected .target update. .if. clause modifier rather than .target exit data." } */ + #pragma omp for + for (i = 0; i < 16; i++) + { + #pragma omp cancel for if (target exit data:a) /* { dg-error "expected .cancel. .if. clause modifier" } */ + } } diff --git a/gcc/testsuite/c-c++-common/gomp/if-3.c b/gcc/testsuite/c-c++-common/gomp/if-3.c new file mode 100644 index 0000000..12c342b --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/if-3.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-O2" } */ + +#define N 1024 + +void +foo (int *x, int *y, int *z, int a) +{ + int i; + #pragma omp simd if (simd: a > 2) aligned (x, y, z : 16) + for (i = 0; i < N; i++) + x[i] = y[i] + z[i]; +} diff --git a/gcc/testsuite/c-c++-common/gomp/master-combined-1.c b/gcc/testsuite/c-c++-common/gomp/master-combined-1.c new file mode 100644 index 0000000..b11f5db --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/master-combined-1.c @@ -0,0 +1,32 @@ +void bar (int *); + +void +foo (int *a) +{ + int i, j, k, u = 0, v = 0, w = 0, x = 0, y = 0, z = 0; + #pragma omp parallel master default(none) private (k) + bar (&k); + #pragma omp parallel default(none) firstprivate(a) shared(x, y, z) + { + #pragma omp master taskloop reduction (+:x) default(none) firstprivate(a) + for (i = 0; i < 64; i++) + x += a[i]; + #pragma omp master taskloop simd reduction (+:y) default(none) firstprivate(a) private (i) + for (i = 0; i < 64; i++) + y += a[i]; + #pragma omp master taskloop simd collapse(2) reduction (+:z) default(none) firstprivate(a) private (i, j) + for (j = 0; j < 1; j++) + for (i = 0; i < 64; ++i) + z += a[i]; + } + #pragma omp parallel master taskloop reduction (+:u) default(none) firstprivate(a) + for (i = 0; i < 64; i++) + u += a[i]; + #pragma omp parallel master taskloop simd reduction (+:v) default(none) firstprivate(a) + for (i = 0; i < 64; i++) + v += a[i]; + #pragma omp parallel master taskloop simd collapse(2) reduction (+:w) default(none) firstprivate(a) + for (j = 0; j < 1; j++) + for (i = 0; i < 64; ++i) + w += a[i]; +} diff --git a/gcc/testsuite/c-c++-common/gomp/master-combined-2.c b/gcc/testsuite/c-c++-common/gomp/master-combined-2.c new file mode 100644 index 0000000..4f7b574 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/master-combined-2.c @@ -0,0 +1,13 @@ +void +foo (int *a) +{ + int i, r = 0, s = 0; + #pragma omp taskgroup task_reduction(+:r) + #pragma omp parallel master taskloop in_reduction(+:r) /* { dg-error "'in_reduction' is not valid for '#pragma omp parallel master taskloop'" } */ + for (i = 0; i < 64; i++) + r += a[i]; + #pragma omp taskgroup task_reduction(+:s) + #pragma omp parallel master taskloop simd in_reduction(+:s) /* { dg-error "'in_reduction' is not valid for '#pragma omp parallel master taskloop simd'" } */ + for (i = 0; i < 64; i++) + s += a[i]; +} diff --git a/gcc/testsuite/c-c++-common/gomp/nontemporal-1.c b/gcc/testsuite/c-c++-common/gomp/nontemporal-1.c new file mode 100644 index 0000000..7f1f182 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/nontemporal-1.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-O2" } */ + +#define N 1024 +int a[N], b[N], c[N], d[N]; + +void +foo (void) +{ + int i; + #pragma omp simd nontemporal (a, b) + for (i = 0; i < N; ++i) + a[i] = b[i] + c[i]; + #pragma omp simd nontemporal (d) + for (i = 0; i < N; ++i) + d[i] = 2 * c[i]; +} diff --git a/gcc/testsuite/c-c++-common/gomp/nontemporal-2.c b/gcc/testsuite/c-c++-common/gomp/nontemporal-2.c new file mode 100644 index 0000000..950a87d --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/nontemporal-2.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ + +#define N 1024 +extern int a[N], b[N], c[N], d[N]; + +void +foo (void) +{ + int i; + #pragma omp simd nontemporal (a, b) aligned (a, b, c) + for (i = 0; i < N; ++i) + a[i] = b[i] + c[i]; + #pragma omp simd nontemporal (d) nontemporal (d) /* { dg-error "'d' appears more than once in 'nontemporal' clauses" } */ + for (i = 0; i < N; ++i) + d[i] = 2 * c[i]; + #pragma omp simd nontemporal (a, b, b) /* { dg-error "'b' appears more than once in 'nontemporal' clauses" } */ + for (i = 0; i < N; ++i) + a[i] += b[i] + c[i]; +} diff --git a/gcc/testsuite/c-c++-common/gomp/reduction-task-1.c b/gcc/testsuite/c-c++-common/gomp/reduction-task-1.c new file mode 100644 index 0000000..3c509d6 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/reduction-task-1.c @@ -0,0 +1,86 @@ +int v; +extern void foo (int); + +void +bar (void) +{ + int i; + #pragma omp for reduction (task, +: v) + for (i = 0; i < 64; i++) + foo (i); + #pragma omp sections reduction (task, +: v) + { + foo (-2); + #pragma omp section + foo (-3); + } + #pragma omp parallel reduction (task, +: v) + foo (-1); + #pragma omp parallel for reduction (task, +: v) + for (i = 0; i < 64; i++) + foo (i); + #pragma omp parallel sections reduction (task, +: v) + { + foo (-2); + #pragma omp section + foo (-3); + } + #pragma omp teams distribute parallel for reduction (task, +: v) + for (i = 0; i < 64; i++) + foo (i); + #pragma omp for reduction (default, +: v) + for (i = 0; i < 64; i++) + foo (i); + #pragma omp sections reduction (default, +: v) + { + foo (-2); + #pragma omp section + foo (-3); + } + #pragma omp parallel reduction (default, +: v) + foo (-1); + #pragma omp parallel for reduction (default, +: v) + for (i = 0; i < 64; i++) + foo (i); + #pragma omp parallel sections reduction (default, +: v) + { + foo (-2); + #pragma omp section + foo (-3); + } + #pragma omp teams distribute parallel for reduction (default, +: v) + for (i = 0; i < 64; i++) + foo (i); + #pragma omp for reduction (default, +: v) nowait + for (i = 0; i < 64; i++) + foo (i); + #pragma omp sections nowait reduction (default, +: v) + { + foo (-2); + #pragma omp section + foo (-3); + } + #pragma omp simd reduction (default, +: v) + for (i = 0; i < 64; i++) + v++; + #pragma omp for simd reduction (default, +: v) + for (i = 0; i < 64; i++) + v++; + #pragma omp parallel for simd reduction (default, +: v) + for (i = 0; i < 64; i++) + v++; + #pragma omp teams distribute parallel for simd reduction (default, +: v) + for (i = 0; i < 64; i++) + v++; + #pragma omp taskloop reduction (default, +: v) + for (i = 0; i < 64; i++) + foo (i); + #pragma omp taskloop simd reduction (default, +: v) + for (i = 0; i < 64; i++) + v++; + #pragma omp teams reduction (default, +: v) + foo (i); + #pragma omp teams distribute reduction (default, +: v) + for (i = 0; i < 64; i++) + foo (i); +} diff --git a/gcc/testsuite/c-c++-common/gomp/reduction-task-2.c b/gcc/testsuite/c-c++-common/gomp/reduction-task-2.c new file mode 100644 index 0000000..1e262d3 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/reduction-task-2.c @@ -0,0 +1,40 @@ +int v; +extern void foo (int); + +void +bar (void) +{ + int i; + #pragma omp for reduction (task, +: v) nowait /* { dg-error "'task' reduction modifier on a construct with a 'nowait' clause" } */ + for (i = 0; i < 64; i++) + foo (i); + #pragma omp sections nowait reduction (task, +: v) /* { dg-error "'task' reduction modifier on a construct with a 'nowait' clause" } */ + { + foo (-2); + #pragma omp section + foo (-3); + } + #pragma omp simd reduction (task, +: v) /* { dg-error "invalid 'task' reduction modifier on construct other than 'parallel', 'for' or 'sections'" } */ + for (i = 0; i < 64; i++) + v++; + #pragma omp for simd reduction (task, +: v) /* { dg-error "invalid 'task' reduction modifier on construct combined with 'simd'" } */ + for (i = 0; i < 64; i++) + v++; + #pragma omp parallel for simd reduction (task, +: v) /* { dg-error "invalid 'task' reduction modifier on construct combined with 'simd'" } */ + for (i = 0; i < 64; i++) + v++; + #pragma omp teams distribute parallel for simd reduction (task, +: v) /* { dg-error "invalid 'task' reduction modifier on construct combined with 'simd'" } */ + for (i = 0; i < 64; i++) + v++; + #pragma omp taskloop reduction (task, +: v) /* { dg-error "invalid 'task' reduction modifier on construct other than 'parallel', 'for' or 'sections'" } */ + for (i = 0; i < 64; i++) + foo (i); + #pragma omp taskloop simd reduction (task, +: v) /* { dg-error "invalid 'task' reduction modifier on construct combined with 'simd'" } */ + for (i = 0; i < 64; i++) + v++; + #pragma omp teams reduction (task, +: v) /* { dg-error "invalid 'task' reduction modifier on construct other than 'parallel', 'for' or 'sections'" } */ + foo (i); + #pragma omp teams distribute reduction (task, +: v) /* { dg-error "invalid 'task' reduction modifier on construct not combined with 'parallel', 'for' or 'sections'" } */ + for (i = 0; i < 64; i++) + foo (i); +} diff --git a/gcc/testsuite/c-c++-common/gomp/requires-1.c b/gcc/testsuite/c-c++-common/gomp/requires-1.c new file mode 100644 index 0000000..7be6c38 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/requires-1.c @@ -0,0 +1,15 @@ +#pragma omp requires unified_address +#pragma omp requires unified_shared_memory +#pragma omp requires unified_shared_memory unified_address +#pragma omp requires dynamic_allocators,reverse_offload + +int i; + +void +foo () +{ + if (0) + #pragma omp requires unified_shared_memory unified_address + i++; + #pragma omp requries atomic_default_mem_order(seq_cst) +} diff --git a/gcc/testsuite/c-c++-common/gomp/requires-2.c b/gcc/testsuite/c-c++-common/gomp/requires-2.c new file mode 100644 index 0000000..d242a32 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/requires-2.c @@ -0,0 +1,18 @@ +#pragma omp requires /* { dg-error "requires at least one clause" } */ +#pragma omp requires unified_shared_memory,unified_shared_memory /* { dg-error "too many 'unified_shared_memory' clauses" } */ +#pragma omp requires unified_address unified_address /* { dg-error "too many 'unified_address' clauses" } */ +#pragma omp requires reverse_offload reverse_offload /* { dg-error "too many 'reverse_offload' clauses" } */ +#pragma omp requires foobarbaz /* { dg-error "expected 'unified_address', 'unified_shared_memory', 'dynamic_allocators', 'reverse_offload' or 'atomic_default_mem_order' clause" } */ + +int i; + +void +foo () +{ + #pragma omp requires dynamic_allocators , dynamic_allocators /* { dg-error "too many 'dynamic_allocators' clauses" } */ + if (0) + #pragma omp requires atomic_default_mem_order(seq_cst) atomic_default_mem_order(seq_cst) /* { dg-error "too many 'atomic_default_mem_order' clauses" } */ + i++; +} + +#pragma omp requires atomic_default_mem_order (seq_cst) /* { dg-error "more than one 'atomic_default_mem_order' clause in a single compilation unit" } */ diff --git a/gcc/testsuite/c-c++-common/gomp/requires-3.c b/gcc/testsuite/c-c++-common/gomp/requires-3.c new file mode 100644 index 0000000..e5a6cbb --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/requires-3.c @@ -0,0 +1,3 @@ +#pragma omp requires atomic_default_mem_order(acquire) /* { dg-error "expected 'seq_cst', 'relaxed' or 'acq_rel'" } */ +#pragma omp requires atomic_default_mem_order(release) /* { dg-error "expected 'seq_cst', 'relaxed' or 'acq_rel'" } */ +#pragma omp requires atomic_default_mem_order(foobar) /* { dg-error "expected 'seq_cst', 'relaxed' or 'acq_rel'" } */ diff --git a/gcc/testsuite/c-c++-common/gomp/requires-4.c b/gcc/testsuite/c-c++-common/gomp/requires-4.c new file mode 100644 index 0000000..a3497b1 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/requires-4.c @@ -0,0 +1,11 @@ +#pragma omp requires unified_shared_memory,unified_address,reverse_offload +void +foo (void) +{ + #pragma omp target + ; + #pragma omp requires unified_shared_memory /* { dg-error "'unified_shared_memory' clause used lexically after first target construct or offloading API" } */ +} + +#pragma omp requires unified_address /* { dg-error "'unified_address' clause used lexically after first target construct or offloading API" } */ +#pragma omp requires reverse_offload /* { dg-error "'reverse_offload' clause used lexically after first target construct or offloading API" } */ diff --git a/gcc/testsuite/c-c++-common/gomp/schedule-modifiers-1.c b/gcc/testsuite/c-c++-common/gomp/schedule-modifiers-1.c index 33ca3a6..82ab257 100644 --- a/gcc/testsuite/c-c++-common/gomp/schedule-modifiers-1.c +++ b/gcc/testsuite/c-c++-common/gomp/schedule-modifiers-1.c @@ -68,18 +68,26 @@ void bar (void) { int i; - #pragma omp for schedule (nonmonotonic: static, 2) /* { dg-error ".nonmonotonic. modifier specified for .static. schedule kind" } */ + #pragma omp for schedule (nonmonotonic: static, 2) for (i = 0; i < 64; i++) ; - #pragma omp for schedule (nonmonotonic : static) /* { dg-error ".nonmonotonic. modifier specified for .static. schedule kind" } */ + #pragma omp for schedule (nonmonotonic : static) for (i = 0; i < 64; i++) ; - #pragma omp for schedule (nonmonotonic : runtime) /* { dg-error ".nonmonotonic. modifier specified for .runtime. schedule kind" } */ + #pragma omp for schedule (nonmonotonic : runtime) for (i = 0; i < 64; i++) ; - #pragma omp for schedule (nonmonotonic : auto) /* { dg-error ".nonmonotonic. modifier specified for .auto. schedule kind" } */ + #pragma omp for schedule (nonmonotonic : auto) for (i = 0; i < 64; i++) ; + #pragma omp for schedule (nonmonotonic : static) ordered /* { dg-error ".nonmonotonic. schedule modifier specified together with .ordered. clause" } */ + for (i = 0; i < 64; i++) + #pragma omp ordered + ; + #pragma omp for ordered schedule (nonmonotonic: static, 4) /* { dg-error ".nonmonotonic. schedule modifier specified together with .ordered. clause" } */ + for (i = 0; i < 64; i++) + #pragma omp ordered + ; #pragma omp for schedule (nonmonotonic : dynamic) ordered /* { dg-error ".nonmonotonic. schedule modifier specified together with .ordered. clause" } */ for (i = 0; i < 64; i++) #pragma omp ordered @@ -100,6 +108,12 @@ bar (void) #pragma omp ordered depend(source) #pragma omp ordered depend(sink: i - 1) } + #pragma omp for schedule(nonmonotonic : runtime) ordered(1) /* { dg-error ".nonmonotonic. schedule modifier specified together with .ordered. clause" } */ + for (i = 0; i < 64; i++) + { + #pragma omp ordered depend(source) + #pragma omp ordered depend(sink: i - 1) + } #pragma omp for schedule (nonmonotonic , monotonic : dynamic) /* { dg-error "both .monotonic. and .nonmonotonic. modifiers specified" } */ for (i = 0; i < 64; i++) ; diff --git a/gcc/testsuite/c-c++-common/gomp/simd7.c b/gcc/testsuite/c-c++-common/gomp/simd7.c new file mode 100644 index 0000000..83d53251 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/simd7.c @@ -0,0 +1,21 @@ +int a[64]; + +#pragma omp declare simd linear(x) +int +bar (int x, int y) +{ + int v; + #pragma omp atomic capture + v = a[x] += y; + return v; +} + +void +foo (void) +{ + int i; + #pragma omp simd + for (i = 0; i < 64; i++) + #pragma omp atomic + a[i] += 1; +} diff --git a/gcc/testsuite/c-c++-common/gomp/target-data-1.c b/gcc/testsuite/c-c++-common/gomp/target-data-1.c new file mode 100644 index 0000000..0d4975b --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/target-data-1.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ + +void +foo (void) +{ + int a[4] = { 1, 2, 3, 4 }; + #pragma omp target data map(to:a) + #pragma omp target data use_device_ptr(a) + #pragma omp target is_device_ptr(a) + { + a[0]++; + } + #pragma omp target data /* { dg-error "must contain at least one" } */ + a[0]++; + #pragma omp target data map(to:a) + #pragma omp target data use_device_ptr(a) use_device_ptr(a) /* { dg-error "appears more than once in data clauses" } */ + a[0]++; +} diff --git a/gcc/testsuite/c-c++-common/gomp/taskloop-reduction-1.c b/gcc/testsuite/c-c++-common/gomp/taskloop-reduction-1.c new file mode 100644 index 0000000..0df073f --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/taskloop-reduction-1.c @@ -0,0 +1,10 @@ +int +foo (int *a) +{ + int x = 0; + #pragma omp taskloop reduction (+:x) nogroup /* { dg-error "'nogroup' clause must not be used together with 'reduction' clause" } */ + for (int i = 0; i < 64; i++) + x += a[i]; + #pragma omp taskwait + return x; +} diff --git a/gcc/testsuite/c-c++-common/gomp/taskwait-depend-1.c b/gcc/testsuite/c-c++-common/gomp/taskwait-depend-1.c new file mode 100644 index 0000000..1fcce74 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/taskwait-depend-1.c @@ -0,0 +1,11 @@ +void +foo (int *p) +{ + #pragma omp taskwait depend(iterator(i = 0:16) , in : p[i]) depend(out : p[32]) +} + +void +bar (int *p) +{ + #pragma omp taskwait depend(mutexinoutset : p[0]) /* { dg-error "'mutexinoutset' kind in 'depend' clause on a 'taskwait' construct" } */ +} diff --git a/gcc/testsuite/c-c++-common/gomp/teams-1.c b/gcc/testsuite/c-c++-common/gomp/teams-1.c new file mode 100644 index 0000000..0ef3bb9 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/teams-1.c @@ -0,0 +1,64 @@ +#ifdef __cplusplus +extern "C" { +#endif + +int omp_get_num_teams (void); +int omp_get_team_num (void); + +#ifdef __cplusplus +} +#endif + +void bar (int *, int *, int *, int, int, int, int); + +void +foo (void) +{ + int a = 1, b = 2, c = 3, d = 4, e = 5, f = 6; + #pragma omp teams num_teams (4) shared (b) firstprivate (c, d) private (e, f) + { + f = 7; + bar (&a, &c, &e, b, d, f, 0); + } + bar (&a, (int *) 0, (int *) 0, b, 0, 0, 1); +} + +void +baz (void) +{ + #pragma omp teams + { + #pragma omp distribute + for (int i = 0; i < 64; i++) + ; + #pragma omp distribute simd + for (int i = 0; i < 64; i++) + ; + #pragma omp distribute parallel for + for (int i = 0; i < 64; i++) + ; + #pragma omp distribute parallel for + for (int i = 0; i < 64; i++) + ; + #pragma omp distribute parallel for simd + for (int i = 0; i < 64; i++) + ; + #pragma omp parallel + ; + #pragma omp parallel for + for (int i = 0; i < 64; i++) + ; + #pragma omp parallel for simd + for (int i = 0; i < 64; i++) + ; + int a, b; + #pragma omp parallel sections + { + a = 5; + #pragma omp section + b = 6; + } + int c = omp_get_num_teams (); + int d = omp_get_team_num (); + } +} diff --git a/gcc/testsuite/c-c++-common/gomp/teams-2.c b/gcc/testsuite/c-c++-common/gomp/teams-2.c new file mode 100644 index 0000000..011c284 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/teams-2.c @@ -0,0 +1,119 @@ +void +foo (void) +{ + int i; + + #pragma omp parallel + { + #pragma omp teams /* { dg-error "'teams' construct must be closely nested inside of 'target' construct or not nested in any OpenMP construct" } */ + ; + } + #pragma omp teams + { + #pragma omp teams /* { dg-error "only 'distribute' or 'parallel' regions are allowed to be strictly nested inside 'teams' region" } */ + ; + } + #pragma omp target + { + #pragma omp parallel + { + #pragma omp teams /* { dg-error "'teams' construct must be closely nested inside of 'target' construct or not nested in any OpenMP construct" } */ + ; + } + } + #pragma omp for + for (i = 0; i < 4; i++) + if (i == 0) + { + #pragma omp teams /* { dg-error "'teams' construct must be closely nested inside of 'target' construct or not nested in any OpenMP construct" } */ + ; + } + #pragma omp single + #pragma omp teams /* { dg-error "'teams' construct must be closely nested inside of 'target' construct or not nested in any OpenMP construct" } */ + ; + #pragma omp master + { + #pragma omp teams /* { dg-error "'teams' construct must be closely nested inside of 'target' construct or not nested in any OpenMP construct" } */ + ; + } + #pragma omp critical + #pragma omp teams /* { dg-error "'teams' construct must be closely nested inside of 'target' construct or not nested in any OpenMP construct" } */ + ; + #pragma omp sections + { + #pragma omp teams /* { dg-error "'teams' construct must be closely nested inside of 'target' construct or not nested in any OpenMP construct" } */ + ; + #pragma omp section + { + #pragma omp teams /* { dg-error "'teams' construct must be closely nested inside of 'target' construct or not nested in any OpenMP construct" } */ + ; + } + } + #pragma omp target data map (to: i) + { + #pragma omp teams /* { dg-error "'teams' construct must be closely nested inside of 'target' construct or not nested in any OpenMP construct" } */ + ; + } + #pragma omp task + { + #pragma omp teams /* { dg-error "'teams' construct must be closely nested inside of 'target' construct or not nested in any OpenMP construct" } */ + ; + } + #pragma omp taskgroup + { + #pragma omp teams /* { dg-error "'teams' construct must be closely nested inside of 'target' construct or not nested in any OpenMP construct" } */ + ; + } +} + +void +bar (void) +{ + #pragma omp teams + { + int x, y, v = 4; + #pragma omp target /* { dg-error "only 'distribute' or 'parallel' regions are allowed to be strictly nested inside 'teams' region" } */ + ; + #pragma omp target data map (to: v) /* { dg-error "only 'distribute' or 'parallel' regions are allowed to be strictly nested inside 'teams' region" } */ + ; + #pragma omp for /* { dg-error "only 'distribute' or 'parallel' regions are allowed to be strictly nested inside 'teams' region" } */ + for (int i = 0; i < 64; ++i) + ; + #pragma omp simd /* { dg-error "only 'distribute' or 'parallel' regions are allowed to be strictly nested inside 'teams' region" } */ + for (int i = 0; i < 64; ++i) + ; + #pragma omp for simd /* { dg-error "only 'distribute' or 'parallel' regions are allowed to be strictly nested inside 'teams' region" } */ + for (int i = 0; i < 64; ++i) + ; + #pragma omp single /* { dg-error "only 'distribute' or 'parallel' regions are allowed to be strictly nested inside 'teams' region" } */ + ; + #pragma omp master /* { dg-error "only 'distribute' or 'parallel' regions are allowed to be strictly nested inside 'teams' region" } */ + ; + #pragma omp sections /* { dg-error "only 'distribute' or 'parallel' regions are allowed to be strictly nested inside 'teams' region" } */ + { + x = 1; + #pragma omp section + y = 2; + } + #pragma omp critical /* { dg-error "only 'distribute' or 'parallel' regions are allowed to be strictly nested inside 'teams' region" } */ + ; + #pragma omp target enter data map (to: v) /* { dg-error "only 'distribute' or 'parallel' regions are allowed to be strictly nested inside 'teams' region" } */ + #pragma omp target exit data map (from: v) /* { dg-error "only 'distribute' or 'parallel' regions are allowed to be strictly nested inside 'teams' region" } */ + #pragma omp cancel parallel /* { dg-error "only 'distribute' or 'parallel' regions are allowed to be strictly nested inside 'teams' region" } */ + #pragma omp cancellation point parallel /* { dg-error "only 'distribute' or 'parallel' regions are allowed to be strictly nested inside 'teams' region" } */ + #pragma omp barrier /* { dg-error "only 'distribute' or 'parallel' regions are allowed to be strictly nested inside 'teams' region" } */ + #pragma omp ordered /* { dg-error "only 'distribute' or 'parallel' regions are allowed to be strictly nested inside 'teams' region" } */ + ; + #pragma omp task /* { dg-error "only 'distribute' or 'parallel' regions are allowed to be strictly nested inside 'teams' region" } */ + ; + #pragma omp taskloop /* { dg-error "only 'distribute' or 'parallel' regions are allowed to be strictly nested inside 'teams' region" } */ + for (int i = 0; i < 64; ++i) + ; + #pragma omp atomic /* { dg-error "only 'distribute' or 'parallel' regions are allowed to be strictly nested inside 'teams' region" } */ + v++; + #pragma omp taskgroup /* { dg-error "only 'distribute' or 'parallel' regions are allowed to be strictly nested inside 'teams' region" } */ + ; + #pragma omp taskwait /* { dg-error "only 'distribute' or 'parallel' regions are allowed to be strictly nested inside 'teams' region" } */ + #pragma omp taskyield /* { dg-error "only 'distribute' or 'parallel' regions are allowed to be strictly nested inside 'teams' region" } */ + } +} diff --git a/gcc/testsuite/g++.dg/gomp/atomic-18.C b/gcc/testsuite/g++.dg/gomp/atomic-18.C new file mode 100644 index 0000000..c93e732 --- /dev/null +++ b/gcc/testsuite/g++.dg/gomp/atomic-18.C @@ -0,0 +1,50 @@ +// { dg-do compile } +// { dg-additional-options "-fdump-tree-original" } +// { dg-final { scan-tree-dump-times "omp atomic release" 5 "original" } } +// { dg-final { scan-tree-dump-times "omp atomic seq_cst" 1 "original" } } +// { dg-final { scan-tree-dump-times "omp atomic relaxed" 2 "original" } } +// { dg-final { scan-tree-dump-times "omp atomic capture acq_rel" 3 "original" } } +// { dg-final { scan-tree-dump-times "omp atomic capture acquire" 1 "original" } } +// { dg-final { scan-tree-dump-times "omp atomic read acquire" 1 "original" } } + +int i, v; +float f; + +template <int N, int M, typename T> +void +foo (T *p) +{ + #pragma omp atomic release, hint (N), update + i = i + 1; + #pragma omp atomic hint(0)seq_cst + i = i + 1; + #pragma omp atomic relaxed,update,hint (N) + i = i + 1; + #pragma omp atomic release + i = i + 1; + #pragma omp atomic relaxed + i = i + 1; + #pragma omp atomic acq_rel capture + v = i = i + 1; + #pragma omp atomic capture,acq_rel , hint (M) + v = i = i + 1; + #pragma omp atomic hint(N),acquire capture + v = i = i + 1; + #pragma omp atomic read acquire + v = i; + #pragma omp atomic release,write + i = v; + #pragma omp atomic hint(1),update,release + f = f + 2.0; + #pragma omp requires atomic_default_mem_order (acq_rel) + #pragma omp atomic hint (M - 1) update + *p += 1; + #pragma omp atomic capture, hint (M) + v = *p = *p + 1; +} + +void +bar () +{ + foo <0, 1, int> (&i); +} diff --git a/gcc/testsuite/g++.dg/gomp/atomic-19.C b/gcc/testsuite/g++.dg/gomp/atomic-19.C new file mode 100644 index 0000000..93f6613 --- /dev/null +++ b/gcc/testsuite/g++.dg/gomp/atomic-19.C @@ -0,0 +1,17 @@ +int i; + +template <int N, typename T> +void +foo (T x) +{ + #pragma omp atomic hint (x) // { dg-error "must be integral" } + i = i + 1; + #pragma omp atomic hint (N + i) // { dg-error "constant integer expression" } + i = i + 1; +} + +void +bar () +{ + foo <0, float> (1.0f); +} diff --git a/gcc/testsuite/g++.dg/gomp/atomic-5.C b/gcc/testsuite/g++.dg/gomp/atomic-5.C index b277ebf..78f6344 100644 --- a/gcc/testsuite/g++.dg/gomp/atomic-5.C +++ b/gcc/testsuite/g++.dg/gomp/atomic-5.C @@ -12,18 +12,18 @@ void f1(void) x = x + 1; #pragma omp atomic x = 1; /* { dg-error "invalid form" } */ - #pragma omp atomic + #pragma omp atomic /* { dg-error "read-only variable" } */ ++y; /* { dg-error "read-only variable" } */ - #pragma omp atomic + #pragma omp atomic /* { dg-error "read-only variable" } */ y--; /* { dg-error "read-only variable" } */ - #pragma omp atomic - y += 1; /* { dg-error "read-only variable" } */ + #pragma omp atomic /* { dg-error "read-only variable" } */ + y += 1; #pragma omp atomic bar(); /* { dg-error "invalid operator" } */ #pragma omp atomic bar() += 1; /* { dg-error "lvalue required" } */ #pragma omp atomic a /* { dg-error "expected end of line" } */ - x++; + x++; /* { dg-error "expected 'read', 'write', 'update', 'capture', 'seq_cst', 'acq_rel', 'release', 'relaxed' or 'hint' clause" "" { target *-*-* } .-1 } */ #pragma omp atomic ; /* { dg-error "expected primary-expression" } */ #pragma omp atomic diff --git a/gcc/testsuite/g++.dg/gomp/clause-3.C b/gcc/testsuite/g++.dg/gomp/clause-3.C index 54f7957..e0edc87 100644 --- a/gcc/testsuite/g++.dg/gomp/clause-3.C +++ b/gcc/testsuite/g++.dg/gomp/clause-3.C @@ -86,18 +86,18 @@ foo (int x) #pragma omp p for linear (t) // { dg-error "predetermined 'threadprivate'" } for (i = 0; i < 10; i++) ; -#pragma omp p shared (c) // { dg-error "predetermined 'shared'" } +#pragma omp p shared (c) ; -#pragma omp p private (c) // { dg-error "predetermined 'shared'" } +#pragma omp p private (c) // { dg-error "may appear only in 'shared' or 'firstprivate' clauses" } ; #pragma omp p firstprivate (c) ; -#pragma omp p for lastprivate (c) // { dg-error "predetermined 'shared'" } +#pragma omp p for lastprivate (c) // { dg-error "may appear only in 'shared' or 'firstprivate' clauses" } for (i = 0; i < 10; i++) ; -#pragma omp p reduction (*:c) // { dg-error "predetermined 'shared'" } +#pragma omp p reduction (*:c) // { dg-error "may appear only in 'shared' or 'firstprivate' clauses" } ; -#pragma omp p for linear (c:2) // { dg-error "predetermined 'shared'" } +#pragma omp p for linear (c:2) // { dg-error "may appear only in 'shared' or 'firstprivate' clauses" } for (i = 0; i < 10; i++) ; } diff --git a/gcc/testsuite/g++.dg/gomp/critical-3.C b/gcc/testsuite/g++.dg/gomp/critical-3.C new file mode 100644 index 0000000..b8dc496 --- /dev/null +++ b/gcc/testsuite/g++.dg/gomp/critical-3.C @@ -0,0 +1,33 @@ +int i; + +template <int N> +void +foo (void) +{ + #pragma omp critical (foo), hint (N + 1) + i++; +} + +template <int N> +void +bar (void) +{ + #pragma omp critical (bar), hint (N + i) // { dg-error "constant integer expression" } + i++; +} + +template <typename T> +void +baz (T x) +{ + #pragma omp critical (baz) hint (x) // { dg-error "expression must be integral" } + i++; +} + +void +test () +{ + foo <0> (); + bar <0> (); + baz (0.0); +} diff --git a/gcc/testsuite/g++.dg/gomp/depend-iterator-1.C b/gcc/testsuite/g++.dg/gomp/depend-iterator-1.C new file mode 100644 index 0000000..6f4aa97 --- /dev/null +++ b/gcc/testsuite/g++.dg/gomp/depend-iterator-1.C @@ -0,0 +1,86 @@ +int arr[64], arr2[64]; +struct S { int a[4]; } k; +short arr4[4]; +volatile int v; +#define TEST_EQ(x,y) ({ int o[x == y ? 1 : -1]; 0; }) + +template <typename T, typename U, typename V, typename W, int N> +void +foo (unsigned char i, signed char j) +{ + #pragma omp task depend (iterator (T j=6:N:-2) , out : \ + arr[TEST_EQ (sizeof (j), sizeof (int)), \ + TEST_EQ (sizeof (i), sizeof (unsigned char)), \ + TEST_EQ (sizeof (k), sizeof (struct S)), j], \ + arr2[TEST_EQ (((__typeof (j)) -1) < 0, 1), \ + TEST_EQ (((__typeof (i)) -1) < 0, 0), \ + TEST_EQ (((__typeof (k.a[0])) -1) < 0, 1), j]) \ + depend(out: arr[0]) \ + depend (iterator (U i=__LONG_LONG_MAX__ - 4:__LONG_LONG_MAX__ - N:N, \ + V j=~0U-16:~0U-8:3, \ + W *k=&arr4[1]:&arr4[2]:1) , in : \ + arr[TEST_EQ (sizeof (i), sizeof (long long)), \ + TEST_EQ (sizeof (j), sizeof (unsigned short)), \ + TEST_EQ (sizeof (k), sizeof (short *)), \ + TEST_EQ (sizeof (*k), sizeof (short)), i - __LONG_LONG_MAX__ + 4], \ + arr2[TEST_EQ (((__typeof (i)) -1) < 0, 1), \ + TEST_EQ (((__typeof (j)) -1) < 0, 0), \ + TEST_EQ (((__typeof (*k)) -1) < 0, 1), j - (~0U-16)], \ + arr2[k - &arr4[0]]) \ + depend(in : k) + v++; +} + +template <typename U, typename W, int N> +void +bar (unsigned char i, signed char j) +{ + int m = j; + int n = j + 2; + #pragma omp task depend (iterator (j=N:2:m) , out : \ + arr[TEST_EQ (sizeof (j), sizeof (int)), \ + TEST_EQ (sizeof (i), sizeof (unsigned char)), \ + TEST_EQ (sizeof (k), sizeof (struct S)), j], \ + arr2[TEST_EQ (((__typeof (j)) -1) < 0, 1), \ + TEST_EQ (((__typeof (i)) -1) < 0, 0), \ + TEST_EQ (((__typeof (k.a[0])) -1) < 0, 1), j]) \ + depend(out: arr[0]) \ + depend (iterator (U i=__LONG_LONG_MAX__ - 4 - n:__LONG_LONG_MAX__ - 2:2, \ + unsigned short j=~0U-16:~0U-8-n:3, \ + W k=&arr4[N-5]:&arr4[n + 2]:1) , in : \ + arr[TEST_EQ (sizeof (i), sizeof (long long)), \ + TEST_EQ (sizeof (j), sizeof (unsigned short)), \ + TEST_EQ (sizeof (k), sizeof (short *)), \ + TEST_EQ (sizeof (*k), sizeof (short)), i - __LONG_LONG_MAX__ + 4], \ + arr2[TEST_EQ (((__typeof (i)) -1) < 0, 1), \ + TEST_EQ (((__typeof (j)) -1) < 0, 0), \ + TEST_EQ (((__typeof (*k)) -1) < 0, 1), j - (~0U-16)], \ + arr2[k - &arr4[0]:10]) \ + depend(in : k) + v++; +} + +template <typename T, typename U, int N> +void +baz (void) +{ + #pragma omp parallel + #pragma omp master + { + #pragma omp task depend(iterator(T k = N : 2) , inout : \ + arr[TEST_EQ (sizeof (k), sizeof (unsigned long)), \ + TEST_EQ (((__typeof (k)) -1) < N, 0), k]) \ + depend(iterator(U s = -3 : -12 : -1 + N) , out : \ + arr[TEST_EQ (sizeof (s), sizeof (signed char)), \ + TEST_EQ (((__typeof (s)) -1) < 0, 1), s + 12]) + v++; + } +} + +void +test (void) +{ + foo <int, long long, unsigned short, short, 2> (0, 0); + bar <long long, short *, 6> (0, -2); + baz <unsigned long int, signed char, 0> (); +} diff --git a/gcc/testsuite/g++.dg/gomp/depend-iterator-2.C b/gcc/testsuite/g++.dg/gomp/depend-iterator-2.C new file mode 100644 index 0000000..a0119eb --- /dev/null +++ b/gcc/testsuite/g++.dg/gomp/depend-iterator-2.C @@ -0,0 +1,121 @@ +int a, b[64]; +struct S { int c; } *d, *e; +struct T; +struct T *f, *g; +int *h; + +template <typename U, typename V, typename W, W N> +void +f1 () +{ + #pragma omp task depend (iterator , in : a) // { dg-error "expected" } + ; + #pragma omp task depend (iterator (for = 0 : 2) , in : a) // { dg-error "expected" } + ; + #pragma omp task depend (iterator (5 = 0 : 2) , in : a) // { dg-error "expected" } + ; + #pragma omp task depend (iterator (i : N : 2) , in : a) // { dg-error "expected '='|name a type|expected" } + ; + #pragma omp task depend (iterator (i = 0, 1 : 2) , in : a) // { dg-error "expected" } + ; + #pragma omp task depend (iterator (i = (0, 1) : 2) , in : a) + ; + #pragma omp task depend (iterator (i = 0 : 1 : 2 : 3) , in : a) // { dg-error "expected '.'" } + ; + #pragma omp task depend (iterator (i = 0 : 2, 3) , in : a) // { dg-error "expected" } + ; + #pragma omp task depend (iterator (i = N : 10 : 2, 3) , in : a) // { dg-error "expected" } + ; + #pragma omp task depend (iterator (i = 0:1), iterator (j = 0:1) , in : a) // { dg-error "invalid depend kind" } + ; + #pragma omp task depend (iterator (i = N:32) , in : b[i*2:2]) + ; + #pragma omp task depend (iterator (void i = 0:1) , in : a) // { dg-error "iterator 'i' has neither integral nor pointer type" } + ; + #pragma omp task depend (iterator (U *p = d:e:2) , in : a) + ; + #pragma omp task depend (iterator (W i = N:4, \ + struct U2 { W *p; } *p = 0:2) , in : a) // { dg-error "types may not be defined in iterator type" } + ; + #pragma omp task depend (iterator (i = 0:4, j = i:16) , in : a) // { dg-error "begin expression refers to outer iterator 'i'" } + ; + #pragma omp task depend (iterator (i = N:4, j = 2:i:1) , in : a) // { dg-error "end expression refers to outer iterator 'i'" } + ; + #pragma omp task depend (iterator (i = 0:4, j = 2:8:i) , in : a) // { dg-error "step expression refers to outer iterator 'i'" } + ; + #pragma omp task depend (iterator (i = 1.25:2.5:3) , in : a) + ; + #pragma omp task depend (iterator (i = 1:2:3.5) , in : a) // { dg-error "iterator step with non-integral type" } + ; + #pragma omp task depend (iterator (W *p = 23 : h) , in : a) + ; + #pragma omp task depend (iterator (const int i = N : 2) , in : a) // { dg-error "const qualified" } + ; + #pragma omp task depend (iterator (const long long unsigned i = 0 : 2) , in : a) // { dg-error "const qualified" } + ; +} + +template <typename W, int N> +void +f2 () +{ + int i, j; + #pragma omp for ordered(2) + for (i = 0; i < 64; i++) + for (j = 0; j < 64; j++) + { + #pragma omp ordered depend (iterator (k=0:N) , sink: i - 1, j - 1) // { dg-error "'iterator' modifier incompatible with 'sink'" } + #pragma omp ordered depend (iterator (W l = 0:2:3) , source) // { dg-error "'iterator' modifier incompatible with 'source'" } + } +} + +template <typename U, typename V, typename W, W N, typename X, typename Y> +void +f3 () +{ + #pragma omp task depend (iterator (U i = 0:1), in : a) // { dg-error "iterator 'i' has neither integral nor pointer type" } + ; + #pragma omp task depend (iterator (V f = 0.2:0.4) , in : a) // { dg-error "iterator 'f' has neither integral nor pointer type" } + ; + #pragma omp task depend (iterator (struct T *p = f:g) , in : a) // { dg-error "invalid use of" } + ; + #pragma omp task depend (iterator (i = *d:2) , in : a) // { dg-error "invalid cast from type 'S' to type 'int'" } + ; + #pragma omp task depend (iterator (i = 2:*d:2) , in : a) // { dg-error "invalid cast from type 'S' to type 'int'" } + ; + #pragma omp task depend (iterator (i = 2:4:*d) , in : a) // { dg-error "iterator step with non-integral type" } + ; + #pragma omp task depend (iterator (i = 1.25:2.5:3) , in : a) + ; + #pragma omp task depend (iterator (i = 1:2:3.5) , in : a) // { dg-error "iterator step with non-integral type" } + ; + #pragma omp task depend (iterator (W *p = 23 : h) , in : a) + ; + #pragma omp task depend (iterator (short i=1:3:N) , in : a) // { dg-error "iterator 'i' has zero step" } + ; + #pragma omp task depend (iterator (i = 1 : 3 : N + 3 - 3) , in : a) // { dg-error "iterator 'i' has zero step" } + ; + #pragma omp task depend (iterator (int *p = &b[6]:&b[9]:4 - 4) , in : a) // { dg-error "iterator 'p' has zero step" } + ; + #pragma omp task depend (iterator (X i = N : 2) , in : a) // { dg-error "const qualified" } + ; + #pragma omp task depend (iterator (Y i = 0 : 2) , in : a) // { dg-error "const qualified" } + ; +} + +template <int N> +void +f4 () +{ + #pragma omp task depend (iterator (i = 0:1), iterator (j = 0:1) , in : a) // { dg-error "invalid depend kind" } + ; +} + +void +f5 () +{ + f1 <struct S, float, int, 0> (); + f2 <int, 1> (); + f3 <struct S, float, int, 0, const int, const long long unsigned> (); + f4 <0> (); +} diff --git a/gcc/testsuite/g++.dg/gomp/depobj-1.C b/gcc/testsuite/g++.dg/gomp/depobj-1.C new file mode 100644 index 0000000..6004f1e --- /dev/null +++ b/gcc/testsuite/g++.dg/gomp/depobj-1.C @@ -0,0 +1,118 @@ +typedef struct __attribute__((__aligned__ (sizeof (void *)))) omp_depend_t { + char __omp_depend_t__[2 * sizeof (void *)]; +} omp_depend_t; + +omp_depend_t bar (void); +extern const omp_depend_t cdepobj; +extern omp_depend_t depobj, depobj4; +extern omp_depend_t depobja[4]; +extern omp_depend_t *pdepobj; +int a, b, i, j; + +template <int N> +void +f1 (bool x) +{ + #pragma omp depobj(x ? depobj : depobj4) depend(in : x ? a : b) + #pragma omp depobj(x ? depobj : depobj4) update(inout) + #pragma omp task depend (depobj:depobj) + ; + #pragma omp depobj(depobj) destroy + #pragma omp task depend (iterator (i=1:3) , depobj: *(depobja + i)) + ; + #pragma omp depobj(pdepobj[0]) depend(mutexinoutset:a) + #pragma omp depobj(*pdepobj) destroy +} + +template <typename T, typename T2> +void +f2 (T &depobj2, T2 depobj3, T *pdepobj) +{ + T depobj1; + T depobja[4]; + #pragma omp depobj(depobj1) depend(in : --a) + #pragma omp depobj(depobj1) update(inout) + #pragma omp task depend (depobj: depobj1) + ; + #pragma omp depobj(depobj1) destroy + #pragma omp depobj(depobj2) depend(in : a) + #pragma omp depobj(depobj2) update(inout) + #pragma omp task depend (depobj :depobj2) + ; + #pragma omp depobj(depobj2) destroy + #pragma omp depobj(depobj3) depend(in : a) + #pragma omp depobj(depobj3) update(inout) + #pragma omp task depend (depobj : depobj3) + ; + #pragma omp depobj(depobj3) destroy + for (int q = 1; q < 3; q++) + { + #pragma omp depobj(depobja[q]) depend (in:a) + } + #pragma omp task depend (iterator (i=1:3) , depobj : *(depobja + i)) + ; + for (int q = 1; q < 3; q++) + { + #pragma omp depobj(depobja[q]) destroy + } + #pragma omp depobj(pdepobj[0]) depend(mutexinoutset:a) + #pragma omp depobj(*pdepobj) destroy +} + +void +f3 (bool x) +{ + omp_depend_t depobjx, depobjy; + f1 <0> (x); + f2 <omp_depend_t, omp_depend_t &> (depobjx, depobjy, pdepobj); +} + +template <int N> +void +f4 (void) +{ + omp_depend_t depobjb[4]; + #pragma omp depobj // { dg-error "expected" } + #pragma omp depobj destroy // { dg-error "expected" } + #pragma omp depobj (depobj) // { dg-error "expected 'depend', 'destroy' or 'update' clause" } + #pragma omp depobj (depobj) foobar // { dg-error "expected 'depend', 'destroy' or 'update' clause" } + #pragma omp depobj(bar ()) update(inout) // { dg-error "'depobj' expression is not lvalue expression" } + #pragma omp depobj (cdepobj) update(in) // { dg-error "'const' qualified 'depobj' expression" } + #pragma omp depobj (depobjb) depend(in: a) // { dg-error "type of 'depobj' expression is not 'omp_depend_t'" } + #pragma omp depobj (pdepobj) depend(in: a) // { dg-error "type of 'depobj' expression is not 'omp_depend_t'" } + #pragma omp depobj (a) destroy // { dg-error "type of 'depobj' expression is not 'omp_depend_t'" } + #pragma omp depobj (depobj) depend(depobj:a) // { dg-error "does not have 'omp_depend_t' type in 'depend' clause with 'depobj' dependence type" } + #pragma omp depobj (depobj) depend(depobj:*depobjb) // { dg-error "'depobj' dependence type specified in 'depend' clause on 'depobj' construct" } + #pragma omp depobj (depobj) update(foobar) // { dg-error "expected 'in', 'out', 'inout' or 'mutexinoutset'" } + #pragma omp depobj (depobj) depend(in: *depobja) // { dg-error "should not have 'omp_depend_t' type in 'depend' clause with dependence type" } + #pragma omp depobj (depobj) depend(in: a) depend(in: b) // { dg-error "expected" } + #pragma omp depobj (depobj) depend(in: a) update(out) // { dg-error "expected" } + #pragma omp depobj (depobj) depend(in: a, b) // { dg-error "more than one locator in 'depend' clause on 'depobj' construct" } + #pragma omp depobj (depobj) depend(source) // { dg-error "'depend\\(source\\)' is only allowed in 'omp ordered'" } + #pragma omp depobj (depobj) depend(sink: i + 1, j - 1) // { dg-error "'depend\\(sink\\)' is only allowed in 'omp ordered'" } + #pragma omp depobj (depobj) depend(iterator (i = 0:2) , in : a) // { dg-error "'iterator' modifier may not be specified on 'depobj' construct" } + if (0) + #pragma omp depobj (depobj) destroy // { dg-error "'#pragma omp depobj' may only be used in compound statements" } + ; +} + +template <int N> +void +f5 (void) +{ + #pragma omp task depend (depobj:depobja[1:2]) // { dg-error "'depend' clause with 'depobj' dependence type on array section" } + ; + #pragma omp task depend (depobj : a) // { dg-error "'a' does not have 'omp_depend_t' type in 'depend' clause with 'depobj' dependence type" } + ; + #pragma omp task depend (in: depobj) // { dg-error "'depobj' should not have 'omp_depend_t' type in 'depend' clause with dependence type" } + ; +} + +void +f6 (omp_depend_t &x) +{ + f4 <0> (); + f5 <0> (); + #pragma omp depobj (x) depend(in: a) + #pragma omp depobj (depobj) depend(in: x) // { dg-error "should not have 'omp_depend_t' type in 'depend' clause with dependence type" } +} diff --git a/gcc/testsuite/g++.dg/gomp/doacross-1.C b/gcc/testsuite/g++.dg/gomp/doacross-1.C new file mode 100644 index 0000000..9381b3a --- /dev/null +++ b/gcc/testsuite/g++.dg/gomp/doacross-1.C @@ -0,0 +1,21 @@ +// { dg-do compile { target c++11 } } +// { dg-options "-fopenmp" } + +int a[42]; + +void +foo () +{ + #pragma omp for ordered (1) // { dg-error "'ordered' clause with parameter on range-based 'for' loop" } + for (auto x : a) + ; +} + +void +bar () +{ + #pragma omp for ordered (2) // { dg-error "'ordered' clause with parameter on range-based 'for' loop" } + for (int i = 0; i < 1; i++) + for (auto x : a) + ; +} diff --git a/gcc/testsuite/g++.dg/gomp/for-21.C b/gcc/testsuite/g++.dg/gomp/for-21.C new file mode 100644 index 0000000..774f888 --- /dev/null +++ b/gcc/testsuite/g++.dg/gomp/for-21.C @@ -0,0 +1,104 @@ +// { dg-do compile { target c++17 } } + +void +f1 (int a[10][10]) +{ + #pragma omp for collapse (2) + for (int i = 0; i < 10; ++i) + for (auto j : a[i]) // { dg-error "initializer expression refers to iteration variable 'i'" } + ; +} + +void +f2 (int (&a)[10]) +{ + #pragma omp for collapse (2) + for (auto i : a) + for (int j = i * 2; j < i * 4; j++) // { dg-error "initializer expression refers to iteration variable 'i'" } + ; +} + +struct S { int a, b, c; }; + +void +f3 (S (&a)[10]) +{ + #pragma omp for collapse (2) + for (auto [i, j, k] : a) // { dg-error "use of 'i' before deduction of 'auto'" "" { target *-*-* } .+1 } + for (int l = i; l < j; l += k) // { dg-error "use of 'j' before deduction of 'auto'" } + ; // { dg-error "use of 'k' before deduction of 'auto'" "" { target *-*-* } .-1 } +} + +template <int N> +void +f4 (int a[10][10]) +{ + #pragma omp for collapse (2) + for (int i = 0; i < 10; ++i) // { dg-error "initializer expression refers to iteration variable 'i'" } + for (auto j : a[i]) + ; +} + +template <int N> +void +f5 (int (&a)[10]) +{ + #pragma omp for collapse (2) + for (auto i : a) + for (int j = i * 2; j < i * 4; j++) // { dg-error "initializer expression refers to iteration variable 'i'" } + ; +} + +template <int N> +void +f6 (S (&a)[10]) +{ + #pragma omp for collapse (2) + for (auto [i, j, k] : a) // { dg-error "use of 'i' before deduction of 'auto'" "" { target *-*-* } .-1 } + for (int l = i; l < j; l += k) // { dg-error "use of 'j' before deduction of 'auto'" } + ; // { dg-error "use of 'k' before deduction of 'auto'" "" { target *-*-* } .-3 } +} + +template <typename T> +void +f7 (T a[10][10]) +{ + #pragma omp for collapse (2) + for (T i = 0; i < 10; ++i) + for (auto j : a[i]) // { dg-error "initializer expression refers to iteration variable 'i'" } + ; +} + +template <typename T> +void +f8 (T (&a)[10]) +{ + #pragma omp for collapse (2) + for (auto i : a) + for (T j = i * 2; j < i * 4; j++) // { dg-error "initializer expression refers to iteration variable 'i'" } + ; +} + +template <typename T, typename U> +void +f9 (U (&a)[10]) +{ + #pragma omp for collapse (2) + for (auto [i, j, k] : a) // { dg-error "use of 'i' before deduction of 'auto'" "" { target *-*-* } .-1 } + for (T l = i; l < j; l += k) // { dg-error "use of 'j' before deduction of 'auto'" } + ; // { dg-error "use of 'k' before deduction of 'auto'" "" { target *-*-* } .-3 } +} + +void +test () +{ + int a[10][10] {}; + int b[10] {}; + S c[10] {}; + f4 <0> (a); + f5 <0> (b); + f6 <0> (c); + f7 (a); + f8 (b); + f9 <int, S> (c); +} diff --git a/gcc/testsuite/g++.dg/gomp/for-4.C b/gcc/testsuite/g++.dg/gomp/for-4.C index 989d4b2..d3351f5 100644 --- a/gcc/testsuite/g++.dg/gomp/for-4.C +++ b/gcc/testsuite/g++.dg/gomp/for-4.C @@ -12,5 +12,5 @@ void foo (int n) bar(i); } -/* { dg-final { scan-tree-dump-times "GOMP_loop_dynamic_start" 1 "ompexp" } } */ -/* { dg-final { scan-tree-dump-times "GOMP_loop_dynamic_next" 1 "ompexp" } } */ +/* { dg-final { scan-tree-dump-times "GOMP_loop_nonmonotonic_dynamic_start" 1 "ompexp" } } */ +/* { dg-final { scan-tree-dump-times "GOMP_loop_nonmonotonic_dynamic_next" 1 "ompexp" } } */ diff --git a/gcc/testsuite/g++.dg/gomp/for-5.C b/gcc/testsuite/g++.dg/gomp/for-5.C index fca2697..3bc8d51 100644 --- a/gcc/testsuite/g++.dg/gomp/for-5.C +++ b/gcc/testsuite/g++.dg/gomp/for-5.C @@ -12,5 +12,5 @@ void foo (int n) bar(i); } -/* { dg-final { scan-tree-dump-times "GOMP_loop_guided_start" 1 "ompexp" } } */ -/* { dg-final { scan-tree-dump-times "GOMP_loop_guided_next" 1 "ompexp" } } */ +/* { dg-final { scan-tree-dump-times "GOMP_loop_nonmonotonic_guided_start" 1 "ompexp" } } */ +/* { dg-final { scan-tree-dump-times "GOMP_loop_nonmonotonic_guided_next" 1 "ompexp" } } */ diff --git a/gcc/testsuite/g++.dg/gomp/for-6.C b/gcc/testsuite/g++.dg/gomp/for-6.C index 9f9db41..9762be6 100644 --- a/gcc/testsuite/g++.dg/gomp/for-6.C +++ b/gcc/testsuite/g++.dg/gomp/for-6.C @@ -12,5 +12,5 @@ void foo (int n) bar(i); } -/* { dg-final { scan-tree-dump-times "GOMP_loop_runtime_start" 1 "ompexp" } } */ -/* { dg-final { scan-tree-dump-times "GOMP_loop_runtime_next" 1 "ompexp" } } */ +/* { dg-final { scan-tree-dump-times "GOMP_loop_maybe_nonmonotonic_runtime_start" 1 "ompexp" } } */ +/* { dg-final { scan-tree-dump-times "GOMP_loop_maybe_nonmonotonic_runtime_next" 1 "ompexp" } } */ diff --git a/gcc/testsuite/g++.dg/gomp/loop-4.C b/gcc/testsuite/g++.dg/gomp/loop-4.C new file mode 100644 index 0000000..cd85dbd --- /dev/null +++ b/gcc/testsuite/g++.dg/gomp/loop-4.C @@ -0,0 +1,227 @@ +typedef __PTRDIFF_TYPE__ ptrdiff_t; + +template <typename T> +class I +{ +public: + typedef ptrdiff_t difference_type; + I (); + ~I (); + I (T *); + I (const I &); + T &operator * (); + T *operator -> (); + T &operator [] (const difference_type &) const; + I &operator = (const I &); + I &operator ++ (); + I operator ++ (int); + I &operator -- (); + I operator -- (int); + I &operator += (const difference_type &); + I &operator -= (const difference_type &); + I operator + (const difference_type &) const; + I operator - (const difference_type &) const; + template <typename S> friend bool operator == (I<S> &, I<S> &); + template <typename S> friend bool operator == (const I<S> &, const I<S> &); + template <typename S> friend bool operator < (I<S> &, I<S> &); + template <typename S> friend bool operator < (const I<S> &, const I<S> &); + template <typename S> friend bool operator <= (I<S> &, I<S> &); + template <typename S> friend bool operator <= (const I<S> &, const I<S> &); + template <typename S> friend bool operator > (I<S> &, I<S> &); + template <typename S> friend bool operator > (const I<S> &, const I<S> &); + template <typename S> friend bool operator >= (I<S> &, I<S> &); + template <typename S> friend bool operator >= (const I<S> &, const I<S> &); + template <typename S> friend typename I<S>::difference_type operator - (I<S> &, I<S> &); + template <typename S> friend typename I<S>::difference_type operator - (const I<S> &, const I<S> &); + template <typename S> friend I<S> operator + (typename I<S>::difference_type , const I<S> &); +private: + T *p; +}; + +template <typename T> bool operator == (I<T> &, I<T> &); +template <typename T> bool operator == (const I<T> &, const I<T> &); +template <typename T> bool operator != (I<T> &, I<T> &); +template <typename T> bool operator != (const I<T> &, const I<T> &); +template <typename T> bool operator < (I<T> &, I<T> &); +template <typename T> bool operator < (const I<T> &, const I<T> &); +template <typename T> bool operator <= (I<T> &, I<T> &); +template <typename T> bool operator <= (const I<T> &, const I<T> &); +template <typename T> bool operator > (I<T> &, I<T> &); +template <typename T> bool operator > (const I<T> &, const I<T> &); +template <typename T> bool operator >= (I<T> &, I<T> &); +template <typename T> bool operator >= (const I<T> &, const I<T> &); +template <typename T> typename I<T>::difference_type operator - (I<T> &, I<T> &); +template <typename T> typename I<T>::difference_type operator - (const I<T> &, const I<T> &); +template <typename T> I<T> operator + (typename I<T>::difference_type, const I<T> &); + +ptrdiff_t foo (I<int> &); +I<int> &bar (I<int> &); +I<int> &baz (I<int> *); + +void +f0 () +{ + int i; + const int j = 1; + const int k = -1; + const int m = 2; + const int n = -7; + int o = 1; + int p = -1; + #pragma omp for + for (i = 0; i != 64; i += j) + ; + #pragma omp for + for (i = 64; i != 0; i -= j) + ; + #pragma omp for + for (i = 0; i != 64; i -= k) + ; + #pragma omp for + for (i = 64; i != 0; i += k) + ; + #pragma omp for + for (i = 0; i != 64; i += m) // { dg-error "increment is not constant 1 or -1 for != condition" } + ; + #pragma omp for + for (i = 64; i != 0; i -= m) // { dg-error "increment is not constant 1 or -1 for != condition" } + ; + #pragma omp for + for (i = 0; i != 64; i -= n) // { dg-error "increment is not constant 1 or -1 for != condition" } + ; + #pragma omp for + for (i = 64; i != 0; i += n) // { dg-error "increment is not constant 1 or -1 for != condition" } + ; + #pragma omp for + for (i = 0; i != 64; i += o) // { dg-error "increment is not constant 1 or -1 for != condition" } + ; + #pragma omp for + for (i = 64; i != 0; i -= o) // { dg-error "increment is not constant 1 or -1 for != condition" } + ; + #pragma omp for + for (i = 0; i != 64; i -= p) // { dg-error "increment is not constant 1 or -1 for != condition" } + ; + #pragma omp for + for (i = 64; i != 0; i += p) // { dg-error "increment is not constant 1 or -1 for != condition" } + ; +} + +void +f1 (I<int> &x, I<int> &y, I<int> &u, I<int> &v) +{ + I<int> i, j; + const int k = 1; + const int l = -1; + const int m = 2; + const int n = -7; + int o = 1; + int p = -1; + #pragma omp for + for (i = x; i != y; i++) + ; + #pragma omp for + for (i = x; y != i; ++i) + ; + #pragma omp for + for (i = x; i != y; i = i + 1) + ; + #pragma omp for + for (i = x; i != y; i = 1 + i) + ; + #pragma omp for + for (i = y; i != x; i--) + ; + #pragma omp for + for (i = y; x != i; --i) + ; + #pragma omp for + for (i = y; i != x; i = i - 1) + ; + #pragma omp for + for (i = y; i != x; i = -1 + i) + ; + #pragma omp for + for (i = x; i != y; i = i + k) + ; + #pragma omp for + for (i = x; i != y; i = k + i) + ; + #pragma omp for + for (i = y; i != x; i = i - k) + ; + #pragma omp for + for (i = y; i != x; i = -k + i) + ; + #pragma omp for + for (i = x; i != y; i = i - l) + ; + #pragma omp for + for (i = x; i != y; i = -l + i) + ; + #pragma omp for + for (i = y; i != x; i = i + l) + ; + #pragma omp for + for (i = y; i != x; i = l + i) + ; + #pragma omp for + for (i = x; i != y; i = i + 2) // { dg-error "increment is not constant 1 or -1 for != condition" } + ; + #pragma omp for + for (i = x; i != y; i = 7 + i) // { dg-error "increment is not constant 1 or -1 for != condition" } + ; + #pragma omp for + for (i = y; i != x; i = i - 2) // { dg-error "increment is not constant 1 or -1 for != condition" } + ; + #pragma omp for + for (i = y; i != x; i = -7 + i) // { dg-error "increment is not constant 1 or -1 for != condition" } + ; + #pragma omp for + for (i = x; i != y; i = i + m) // { dg-error "increment is not constant 1 or -1 for != condition" } + ; + #pragma omp for + for (i = x; i != y; i = m + i) // { dg-error "increment is not constant 1 or -1 for != condition" } + ; + #pragma omp for + for (i = y; i != x; i = i - m) // { dg-error "increment is not constant 1 or -1 for != condition" } + ; + #pragma omp for + for (i = y; i != x; i = -m + i) // { dg-error "increment is not constant 1 or -1 for != condition" } + ; + #pragma omp for + for (i = x; i != y; i = i - n) // { dg-error "increment is not constant 1 or -1 for != condition" } + ; + #pragma omp for + for (i = x; i != y; i = -n + i) // { dg-error "increment is not constant 1 or -1 for != condition" } + ; + #pragma omp for + for (i = y; i != x; i = i + n) // { dg-error "increment is not constant 1 or -1 for != condition" } + ; + #pragma omp for + for (i = y; i != x; i = n + i) // { dg-error "increment is not constant 1 or -1 for != condition" } + ; + #pragma omp for + for (i = x; i != y; i = i + o) // { dg-error "increment is not constant 1 or -1 for != condition" } + ; + #pragma omp for + for (i = x; i != y; i = o + i) // { dg-error "increment is not constant 1 or -1 for != condition" } + ; + #pragma omp for + for (i = y; i != x; i = i - o) // { dg-error "increment is not constant 1 or -1 for != condition" } + ; + #pragma omp for + for (i = y; i != x; i = -o + i) // { dg-error "increment is not constant 1 or -1 for != condition" } + ; + #pragma omp for + for (i = x; i != y; i = i - p) // { dg-error "increment is not constant 1 or -1 for != condition" } + ; + #pragma omp for + for (i = x; i != y; i = -p + i) // { dg-error "increment is not constant 1 or -1 for != condition" } + ; + #pragma omp for + for (i = y; i != x; i = i + p) // { dg-error "increment is not constant 1 or -1 for != condition" } + ; + #pragma omp for + for (i = y; i != x; i = p + i) // { dg-error "increment is not constant 1 or -1 for != condition" } + ; +} diff --git a/gcc/testsuite/g++.dg/gomp/member-2.C b/gcc/testsuite/g++.dg/gomp/member-2.C index c51fa20..77fc6c3 100644 --- a/gcc/testsuite/g++.dg/gomp/member-2.C +++ b/gcc/testsuite/g++.dg/gomp/member-2.C @@ -60,17 +60,17 @@ B::m1 () int B::m2 () { - #pragma omp parallel private (h) // { dg-error "is predetermined .shared. for .private." } + #pragma omp parallel private (h) // { dg-error "may appear only in .shared. or .firstprivate. clauses" } ; #pragma omp parallel firstprivate (h) ; - #pragma omp parallel for lastprivate (h) // { dg-error "is predetermined .shared. for .lastprivate." } + #pragma omp parallel for lastprivate (h) // { dg-error "may appear only in .shared. or .firstprivate. clauses" } for (int i = 0; i < 10; i++) ; - #pragma omp simd linear (h : 1) // { dg-error "is predetermined .shared. for .linear." } + #pragma omp simd linear (h : 1) // { dg-error "may appear only in .shared. or .firstprivate. clauses" } for (int i = 0; i < 10; i++) ; - #pragma omp parallel for reduction (+:h) // { dg-error "is predetermined .shared. for .reduction." } + #pragma omp parallel for reduction (+:h) // { dg-error "may appear only in .shared. or .firstprivate. clauses" } for (int i = 0; i < 10; i++) ; #pragma omp parallel for reduction (+:g) // { dg-error "has const type for .reduction." } @@ -88,7 +88,7 @@ B::m2 () ; #pragma omp parallel shared (g) ; - #pragma omp parallel shared (h) // { dg-error "is predetermined .shared. for .shared." } + #pragma omp parallel shared (h) ; return 0; } @@ -118,30 +118,30 @@ B::m3 () const int B::m4 () const { - #pragma omp parallel private (a) // { dg-error "is predetermined .shared. for .private." } + #pragma omp parallel private (a) // { dg-error "may appear only in .shared. or .firstprivate. clauses" } ; #pragma omp parallel firstprivate (a) ; - #pragma omp parallel for lastprivate (a) // { dg-error "is predetermined .shared. for .lastprivate." } + #pragma omp parallel for lastprivate (a) // { dg-error "may appear only in .shared. or .firstprivate. clauses" } for (int i = 0; i < 10; i++) ; - #pragma omp simd linear (a : 1) // { dg-error "is predetermined .shared. for .linear." } + #pragma omp simd linear (a : 1) // { dg-error "may appear only in .shared. or .firstprivate. clauses" } for (int i = 0; i < 10; i++) ; - #pragma omp parallel for reduction (+:a) // { dg-error "is predetermined .shared. for .reduction." } + #pragma omp parallel for reduction (+:a) // { dg-error "may appear only in .shared. or .firstprivate. clauses" } for (int i = 0; i < 10; i++) ; - #pragma omp parallel private (h) // { dg-error "is predetermined .shared. for .private." } + #pragma omp parallel private (h) // { dg-error "may appear only in .shared. or .firstprivate. clauses" } ; #pragma omp parallel firstprivate (h) ; - #pragma omp parallel for lastprivate (h) // { dg-error "is predetermined .shared. for .lastprivate." } + #pragma omp parallel for lastprivate (h) // { dg-error "may appear only in .shared. or .firstprivate. clauses" } for (int i = 0; i < 10; i++) ; - #pragma omp simd linear (h : 1) // { dg-error "is predetermined .shared. for .linear." } + #pragma omp simd linear (h : 1) // { dg-error "may appear only in .shared. or .firstprivate. clauses" } for (int i = 0; i < 10; i++) ; - #pragma omp parallel for reduction (+:h) // { dg-error "is predetermined .shared. for .reduction." } + #pragma omp parallel for reduction (+:h) // { dg-error "may appear only in .shared. or .firstprivate. clauses" } for (int i = 0; i < 10; i++) ; #pragma omp parallel for reduction (+:e) // { dg-error "has const type for .reduction." } @@ -150,7 +150,7 @@ B::m4 () const #pragma omp parallel for reduction (+:g) // { dg-error "has const type for .reduction." } for (int i = 0; i < 10; i++) ; - #pragma omp parallel shared (a) // { dg-error "is predetermined .shared. for .shared." } + #pragma omp parallel shared (a) ; #pragma omp parallel shared (b) ; @@ -162,7 +162,7 @@ B::m4 () const ; #pragma omp parallel shared (g) ; - #pragma omp parallel shared (h) // { dg-error "is predetermined .shared. for .shared." } + #pragma omp parallel shared (h) ; return 0; } diff --git a/gcc/testsuite/g++.dg/gomp/pr33372-1.C b/gcc/testsuite/g++.dg/gomp/pr33372-1.C index e9da259..8bb18cc 100644 --- a/gcc/testsuite/g++.dg/gomp/pr33372-1.C +++ b/gcc/testsuite/g++.dg/gomp/pr33372-1.C @@ -8,8 +8,8 @@ void f () extern T n (); #pragma omp parallel num_threads(n) // { dg-error "'num_threads' expression must be integral" } ; -#pragma omp parallel for schedule(static, n) - for (int i = 0; i < 10; i++) // { dg-error "chunk size expression must be integral" } +#pragma omp parallel for schedule(static, n) // { dg-error "chunk size expression must be integral" } + for (int i = 0; i < 10; i++) ; } diff --git a/gcc/testsuite/g++.dg/gomp/pr33372-3.C b/gcc/testsuite/g++.dg/gomp/pr33372-3.C index f0a1910..47a3dfa 100644 --- a/gcc/testsuite/g++.dg/gomp/pr33372-3.C +++ b/gcc/testsuite/g++.dg/gomp/pr33372-3.C @@ -8,8 +8,8 @@ void f () T n = 6; #pragma omp parallel num_threads(n) // { dg-error "'num_threads' expression must be integral" } ; -#pragma omp parallel for schedule(static, n) - for (int i = 0; i < 10; i++) // { dg-error "chunk size expression must be integral" } +#pragma omp parallel for schedule(static, n) // { dg-error "chunk size expression must be integral" } + for (int i = 0; i < 10; i++) ; } diff --git a/gcc/testsuite/g++.dg/gomp/pr39495-2.C b/gcc/testsuite/g++.dg/gomp/pr39495-2.C index f8b0f23..8b31ce8 100644 --- a/gcc/testsuite/g++.dg/gomp/pr39495-2.C +++ b/gcc/testsuite/g++.dg/gomp/pr39495-2.C @@ -13,25 +13,25 @@ foo (void) unsigned int u; #pragma omp for - for (i = INT_MIN + 6; i != INT_MIN; i--) // { dg-error "invalid controlling predicate" } + for (i = INT_MIN + 6; i != INT_MIN; i--) ; #pragma omp for for (i = INT_MIN + 6; i == INT_MIN; i--) // { dg-error "invalid controlling predicate" } ; #pragma omp for - for (i = INT_MAX - 6; i != INT_MAX; i++) // { dg-error "invalid controlling predicate" } + for (i = INT_MAX - 6; i != INT_MAX; i++) ; #pragma omp for for (i = INT_MAX - 6; i == INT_MAX; i++) // { dg-error "invalid controlling predicate" } ; #pragma omp for - for (u = 6; u != 0; u--) // { dg-error "invalid controlling predicate" } + for (u = 6; u != 0; u--) ; #pragma omp for for (u = 6; u == 0; u--) // { dg-error "invalid controlling predicate" } ; #pragma omp for - for (u = UINT_MAX - 6; u != UINT_MAX; u++) // { dg-error "invalid controlling predicate" } + for (u = UINT_MAX - 6; u != UINT_MAX; u++) ; #pragma omp for for (u = UINT_MAX - 6; u == UINT_MAX; u++) // { dg-error "invalid controlling predicate" } diff --git a/gcc/testsuite/g++.dg/gomp/predetermined-1.C b/gcc/testsuite/g++.dg/gomp/predetermined-1.C index 495c09e..084f04e 100644 --- a/gcc/testsuite/g++.dg/gomp/predetermined-1.C +++ b/gcc/testsuite/g++.dg/gomp/predetermined-1.C @@ -15,18 +15,18 @@ const A foo (const A d, const C e) const A f; const B b = { 4 }; A g; - #pragma omp parallel default (none) - bar (&a); - #pragma omp parallel default (none) - bar (&b); + #pragma omp parallel default (none) // { dg-error "enclosing 'parallel'" } + bar (&a); // { dg-error "not specified" } + #pragma omp parallel default (none) // { dg-error "enclosing 'parallel'" } + bar (&b); // { dg-error "not specified" } #pragma omp parallel default (none) // { dg-error "enclosing 'parallel'" } bar (&c); // { dg-error "not specified" } - #pragma omp parallel default (none) - bar (&d); + #pragma omp parallel default (none) // { dg-error "enclosing 'parallel'" } + bar (&d); // { dg-error "not specified" } #pragma omp parallel default (none) // { dg-error "enclosing 'parallel'" } bar (&e); // { dg-error "not specified" } - #pragma omp parallel default (none) - bar (&f); + #pragma omp parallel default (none) // { dg-error "enclosing 'parallel'" } + bar (&f); // { dg-error "not specified" } #pragma omp parallel default (none) // { dg-error "enclosing 'parallel'" } bar (&g); // { dg-error "not specified" } return f; diff --git a/gcc/testsuite/g++.dg/gomp/private-1.C b/gcc/testsuite/g++.dg/gomp/private-1.C index 09f15e3..1c24aeb 100644 --- a/gcc/testsuite/g++.dg/gomp/private-1.C +++ b/gcc/testsuite/g++.dg/gomp/private-1.C @@ -15,17 +15,17 @@ const A foo (const A d, const C e) const A f; const B b = { 4 }; A g; - #pragma omp parallel private (a) // { dg-error "predetermined" } + #pragma omp parallel private (a) // { dg-error "may appear only in 'shared' or 'firstprivate' clauses" } bar (&a); - #pragma omp parallel private (b) // { dg-error "predetermined" } + #pragma omp parallel private (b) // { dg-error "may appear only in 'shared' or 'firstprivate' clauses" } bar (&b); #pragma omp parallel private (c) bar (&c); - #pragma omp parallel private (d) // { dg-error "predetermined" } + #pragma omp parallel private (d) // { dg-error "may appear only in 'shared' or 'firstprivate' clauses" } bar (&d); #pragma omp parallel private (e) bar (&e); - #pragma omp parallel private (f) // { dg-error "predetermined" } + #pragma omp parallel private (f) // { dg-error "may appear only in 'shared' or 'firstprivate' clauses" } bar (&f); #pragma omp parallel private (g) bar (&g); diff --git a/gcc/testsuite/g++.dg/gomp/sharing-1.C b/gcc/testsuite/g++.dg/gomp/sharing-1.C index 9dca5d9..ac6908b 100644 --- a/gcc/testsuite/g++.dg/gomp/sharing-1.C +++ b/gcc/testsuite/g++.dg/gomp/sharing-1.C @@ -61,7 +61,7 @@ main (void) thrglobalvar++; /* Predetermined - threadprivate. */ thrlocvar++; /* Predetermined - threadprivate. */ foo (i); /* Predetermined - private (omp for loop variable). */ - foo (constvar.x); /* Predetermined - shared (const qualified type). */ + foo (constvar.x); /* { dg-error "not specified in" } */ foo (T::t.i); /* Predetermined - shared (static data member). */ foo (*p); /* *p predetermined - shared (heap allocated */ (*p)++; /* storage). */ diff --git a/gcc/testsuite/g++.dg/gomp/sharing-2.C b/gcc/testsuite/g++.dg/gomp/sharing-2.C index 6145b92..23e9133 100644 --- a/gcc/testsuite/g++.dg/gomp/sharing-2.C +++ b/gcc/testsuite/g++.dg/gomp/sharing-2.C @@ -5,15 +5,21 @@ struct T int i; mutable int j; }; +struct U +{ + int i, j; +}; struct S { const static int d = 1; const static T e; + const static U f; void foo (int, T); }; const int S::d; const T S::e = { 2, 3 }; +const U S::f = { 4, 5 }; void bar (const int &); @@ -28,15 +34,19 @@ S::foo (const int x, const T y) bar (y.i); #pragma omp parallel firstprivate (e) // { dg-error "is predetermined" } bar (e.i); - #pragma omp parallel shared (x) // { dg-error "is predetermined" } + #pragma omp parallel firstprivate (f) + bar (f.i); + #pragma omp parallel shared (x) bar (x); #pragma omp parallel shared (d) // { dg-error "is predetermined" } bar (d); #pragma omp parallel shared (e) // { dg-error "is predetermined" } bar (e.i); + #pragma omp parallel shared (f) // { dg-error "is predetermined" } + bar (f.i); #pragma omp parallel shared (y) bar (y.i); - #pragma omp parallel private (x) // { dg-error "is predetermined" } + #pragma omp parallel private (x) // { dg-error "may appear only in 'shared' or 'firstprivate' clauses" } bar (x); #pragma omp parallel private (d) // { dg-error "is predetermined" } bar (d); @@ -44,4 +54,6 @@ S::foo (const int x, const T y) bar (y.i); #pragma omp parallel private (e) // { dg-error "is predetermined" } bar (e.i); + #pragma omp parallel private (f) // { dg-error "is predetermined" } + bar (f.i); } diff --git a/gcc/testsuite/g++.dg/gomp/simd-2.C b/gcc/testsuite/g++.dg/gomp/simd-2.C new file mode 100644 index 0000000..3903814 --- /dev/null +++ b/gcc/testsuite/g++.dg/gomp/simd-2.C @@ -0,0 +1,21 @@ +int a[32], b[32]; + +void +foo (void) +{ + int i, j; + #pragma omp simd linear(i, j) collapse(2) // { dg-error "iteration variable 'i' should not be linear" } + for (i = 0; i < 32; ++i) // { dg-error "iteration variable 'j' should not be linear" "" { target *-*-* } .-1 } + for (j = 0; j < 32; ++j) + a[i] += b[j]; +} + +void +bar (void) +{ + static int i, j; + #pragma omp for simd linear(i, j) collapse(2) // { dg-error "iteration variable 'i' should not be linear" "" { target *-*-* } .+1 } + for (i = 0; i < 32; ++i) // { dg-error "iteration variable 'j' should not be linear" } + for (j = 0; j < 32; ++j) + a[i] += b[j]; +} diff --git a/gcc/testsuite/g++.dg/gomp/tpl-atomic-2.C b/gcc/testsuite/g++.dg/gomp/tpl-atomic-2.C index c27f201..627c6c6 100644 --- a/gcc/testsuite/g++.dg/gomp/tpl-atomic-2.C +++ b/gcc/testsuite/g++.dg/gomp/tpl-atomic-2.C @@ -6,21 +6,21 @@ struct S { int x; } s; // even when the templates are never instantiated. template<typename T> void f1() { - #pragma omp atomic - s += 1; // { dg-error "invalid" } + #pragma omp atomic // { dg-error "invalid" } + s += 1; } template<typename T> void f2(float *f) { - #pragma omp atomic - *f |= 1; // { dg-error "invalid|evaluation" } + #pragma omp atomic // { dg-error "invalid" } + *f |= 1; // { dg-error "evaluation" } } // Here the rhs is dependent, but not type dependent. template<typename T> void f3(float *f) { - #pragma omp atomic - *f |= sizeof (T); // { dg-error "invalid|evaluation" } + #pragma omp atomic // { dg-error "invalid" } + *f |= sizeof (T); // { dg-error "evaluation" } } // And the converse, no error here because we're never fed a T. @@ -35,6 +35,6 @@ template<typename T> void f4(T *t) // of the semantic analysis concurrent with that. template<typename T> void f5(float *f) { - #pragma omp atomic - *f |= (T)sizeof(T); // { dg-error "invalid|evaluation" "" { xfail *-*-* } } + #pragma omp atomic // { dg-error "invalid" "" { xfail *-*-* } } + *f |= (T)sizeof(T); // { dg-error "evaluation" "" { xfail *-*-* } } } diff --git a/gcc/testsuite/gcc.dg/gomp/appendix-a/a.24.1.c b/gcc/testsuite/gcc.dg/gomp/appendix-a/a.24.1.c index e0f0eca..099f03f 100644 --- a/gcc/testsuite/gcc.dg/gomp/appendix-a/a.24.1.c +++ b/gcc/testsuite/gcc.dg/gomp/appendix-a/a.24.1.c @@ -10,14 +10,15 @@ a24 (int a) const int c = 1; int i = 0; int l = 0; -#pragma omp parallel default(none) private(a) shared(z) /* { dg-line omp_parallel } */ +#pragma omp parallel default(none) private(a) shared(z, c) /* { dg-line omp_parallel } */ { int j = omp_get_num_threads (); - /* O.K. - j is declared within parallel region */ - /* O.K. - a is listed in private clause */ - /* - z is listed in shared clause */ + /* O.K. - j is declared within parallel region */ + a = z[j]; /* O.K. - a is listed in private clause */ + /* - z is listed in shared clause */ x = c; /* O.K. - x is threadprivate */ - /* - c has const-qualified type */ + /* - c has const-qualified type and + is listed in shared clause */ z[i] = y; /* { dg-error "'i' not specified" "" { target *-*-* } .-1 } */ /* { dg-error "enclosing 'parallel'" "" { target *-*-* } omp_parallel } */ diff --git a/gcc/testsuite/gcc.dg/gomp/atomic-5.c b/gcc/testsuite/gcc.dg/gomp/atomic-5.c index 68ead29..70cfb35 100644 --- a/gcc/testsuite/gcc.dg/gomp/atomic-5.c +++ b/gcc/testsuite/gcc.dg/gomp/atomic-5.c @@ -27,7 +27,7 @@ void f1(void) #pragma omp atomic bar() += 1; /* { dg-error "lvalue required" } */ #pragma omp atomic a /* { dg-error "expected end of line" } */ - x++; + x++; /* { dg-error "expected 'read', 'write', 'update', 'capture', 'seq_cst', 'acq_rel', 'release', 'relaxed' or 'hint' clause" "" { target *-*-* } .-1 } */ #pragma omp atomic ; /* { dg-error "expected expression" } */ #pragma omp atomic diff --git a/gcc/testsuite/gcc.dg/gomp/clause-1.c b/gcc/testsuite/gcc.dg/gomp/clause-1.c index c2d1fc6..9d34b041 100644 --- a/gcc/testsuite/gcc.dg/gomp/clause-1.c +++ b/gcc/testsuite/gcc.dg/gomp/clause-1.c @@ -86,18 +86,18 @@ foo (int x) #pragma omp p for linear (t) /* { dg-error "predetermined 'threadprivate" } */ for (i = 0; i < 10; i++) ; -#pragma omp p shared (c) /* { dg-error "predetermined 'shared'" } */ +#pragma omp p shared (c) ; -#pragma omp p private (c) /* { dg-error "predetermined 'shared'" } */ +#pragma omp p private (c) /* { dg-error "'const' qualified 'c' may appear only in 'shared' or 'firstprivate' clauses" } */ ; #pragma omp p firstprivate (c) ; -#pragma omp p for lastprivate (c) /* { dg-error "predetermined 'shared'" } */ +#pragma omp p for lastprivate (c) /* { dg-error "'const' qualified 'c' may appear only in 'shared' or 'firstprivate' clauses" } */ for (i = 0; i < 10; i++) ; -#pragma omp p reduction (*:c) /* { dg-error "predetermined 'shared'" } */ +#pragma omp p reduction (*:c) /* { dg-error "'const' qualified 'c' may appear only in 'shared' or 'firstprivate' clauses" } */ ; -#pragma omp p for linear (c) /* { dg-error "predetermined 'shared'" } */ +#pragma omp p for linear (c) /* { dg-error "'const' qualified 'c' may appear only in 'shared' or 'firstprivate' clauses" } */ for (i = 0; i < 10; i++) ; } diff --git a/gcc/testsuite/gcc.dg/gomp/combined-1.c b/gcc/testsuite/gcc.dg/gomp/combined-1.c index 0c0848c..e69de29 100644 --- a/gcc/testsuite/gcc.dg/gomp/combined-1.c +++ b/gcc/testsuite/gcc.dg/gomp/combined-1.c @@ -1,23 +0,0 @@ -/* { dg-do compile } */ -/* { dg-options "-O1 -fopenmp -fdump-tree-optimized" } */ - -int a[10]; -int foo (void) -{ - int i; -#pragma omp parallel for schedule(runtime) - for (i = 0; i < 10; i++) - a[i] = i; -#pragma omp parallel -#pragma omp for schedule(runtime) - for (i = 0; i < 10; i++) - a[i] = 10 - i; -#pragma omp parallel - { -#pragma omp for schedule(runtime) - for (i = 0; i < 10; i++) - a[i] = i; - } -} - -/* { dg-final { scan-tree-dump-times "GOMP_parallel_loop_runtime" 3 "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/gomp/for-4.c b/gcc/testsuite/gcc.dg/gomp/for-4.c index 989d4b2..d3351f5 100644 --- a/gcc/testsuite/gcc.dg/gomp/for-4.c +++ b/gcc/testsuite/gcc.dg/gomp/for-4.c @@ -12,5 +12,5 @@ void foo (int n) bar(i); } -/* { dg-final { scan-tree-dump-times "GOMP_loop_dynamic_start" 1 "ompexp" } } */ -/* { dg-final { scan-tree-dump-times "GOMP_loop_dynamic_next" 1 "ompexp" } } */ +/* { dg-final { scan-tree-dump-times "GOMP_loop_nonmonotonic_dynamic_start" 1 "ompexp" } } */ +/* { dg-final { scan-tree-dump-times "GOMP_loop_nonmonotonic_dynamic_next" 1 "ompexp" } } */ diff --git a/gcc/testsuite/gcc.dg/gomp/for-5.c b/gcc/testsuite/gcc.dg/gomp/for-5.c index fca2697..3bc8d51 100644 --- a/gcc/testsuite/gcc.dg/gomp/for-5.c +++ b/gcc/testsuite/gcc.dg/gomp/for-5.c @@ -12,5 +12,5 @@ void foo (int n) bar(i); } -/* { dg-final { scan-tree-dump-times "GOMP_loop_guided_start" 1 "ompexp" } } */ -/* { dg-final { scan-tree-dump-times "GOMP_loop_guided_next" 1 "ompexp" } } */ +/* { dg-final { scan-tree-dump-times "GOMP_loop_nonmonotonic_guided_start" 1 "ompexp" } } */ +/* { dg-final { scan-tree-dump-times "GOMP_loop_nonmonotonic_guided_next" 1 "ompexp" } } */ diff --git a/gcc/testsuite/gcc.dg/gomp/for-6.c b/gcc/testsuite/gcc.dg/gomp/for-6.c index 9f9db41..9762be6 100644 --- a/gcc/testsuite/gcc.dg/gomp/for-6.c +++ b/gcc/testsuite/gcc.dg/gomp/for-6.c @@ -12,5 +12,5 @@ void foo (int n) bar(i); } -/* { dg-final { scan-tree-dump-times "GOMP_loop_runtime_start" 1 "ompexp" } } */ -/* { dg-final { scan-tree-dump-times "GOMP_loop_runtime_next" 1 "ompexp" } } */ +/* { dg-final { scan-tree-dump-times "GOMP_loop_maybe_nonmonotonic_runtime_start" 1 "ompexp" } } */ +/* { dg-final { scan-tree-dump-times "GOMP_loop_maybe_nonmonotonic_runtime_next" 1 "ompexp" } } */ diff --git a/gcc/testsuite/gcc.dg/gomp/pr39495-2.c b/gcc/testsuite/gcc.dg/gomp/pr39495-2.c index a276c24..c0b05cb 100644 --- a/gcc/testsuite/gcc.dg/gomp/pr39495-2.c +++ b/gcc/testsuite/gcc.dg/gomp/pr39495-2.c @@ -13,25 +13,25 @@ foo (void) unsigned int u; #pragma omp for - for (i = INT_MIN + 6; i != INT_MIN; i--) /* { dg-error "invalid controlling predicate" } */ + for (i = INT_MIN + 6; i != INT_MIN; i--) ; #pragma omp for for (i = INT_MIN + 6; i == INT_MIN; i--) /* { dg-error "invalid controlling predicate" } */ ; #pragma omp for - for (i = INT_MAX - 6; i != INT_MAX; i++) /* { dg-error "invalid controlling predicate" } */ + for (i = INT_MAX - 6; i != INT_MAX; i++) ; #pragma omp for for (i = INT_MAX - 6; i == INT_MAX; i++) /* { dg-error "invalid controlling predicate" } */ ; #pragma omp for - for (u = 6; u != 0; u--) /* { dg-error "invalid controlling predicate" } */ + for (u = 6; u != 0; u--) ; #pragma omp for for (u = 6; u == 0; u--) /* { dg-error "invalid controlling predicate" } */ ; #pragma omp for - for (u = UINT_MAX - 6; u != UINT_MAX; u++) /* { dg-error "invalid controlling predicate" } */ + for (u = UINT_MAX - 6; u != UINT_MAX; u++) ; #pragma omp for for (u = UINT_MAX - 6; u == UINT_MAX; u++) /* { dg-error "invalid controlling predicate" } */ diff --git a/gcc/testsuite/gcc.dg/gomp/reduction-2.c b/gcc/testsuite/gcc.dg/gomp/reduction-2.c new file mode 100644 index 0000000..f8ac8b6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/gomp/reduction-2.c @@ -0,0 +1,30 @@ +/* { dg-do compile } */ +/* { dg-options "-fopenmp" } */ + +struct S {}; +void foo (void *, void *); +void bar (void *, void *); +void baz (void *); +#pragma omp declare reduction(+:struct S:foo (&omp_out, &omp_in))initializer(bar(&omp_priv, &omp_orig)) + +void +test1 (void) +{ + struct S s; + int i; + #pragma omp parallel reduction(+:s) + baz (&s); + #pragma omp parallel reduction(task, +:s) /* { dg-error "zero sized type 'struct S' in 'reduction' clause" } */ + baz (&s); + #pragma omp taskloop reduction(+:s) /* { dg-error "zero sized type 'struct S' in 'reduction' clause" } */ + for (i = 0; i < 1; i++) + baz (&s); + #pragma omp taskloop simd reduction(+:s) /* { dg-error "zero sized type 'struct S' in 'reduction' clause" } */ + for (i = 0; i < 1; i++) + baz (&s); + #pragma omp taskgroup task_reduction(+:s) /* { dg-error "zero sized type 'struct S' in 'task_reduction' clause" } */ + { + #pragma omp task in_reduction(+:s) /* { dg-error "zero sized type 'struct S' in 'in_reduction' clause" } */ + baz (&s); + } +} diff --git a/gcc/testsuite/gcc.dg/gomp/sharing-1.c b/gcc/testsuite/gcc.dg/gomp/sharing-1.c index 0e2b60f..79abb64 100644 --- a/gcc/testsuite/gcc.dg/gomp/sharing-1.c +++ b/gcc/testsuite/gcc.dg/gomp/sharing-1.c @@ -44,7 +44,7 @@ main (void) thrglobalvar++; /* Predetermined - threadprivate. */ thrlocvar++; /* Predetermined - threadprivate. */ foo (i); /* Predetermined - private (omp for loop variable). */ - foo (constvar); /* Predetermined - shared (const qualified type). */ + foo (constvar); /* { dg-error "not specified in" } */ foo (*p); /* *p predetermined - shared (heap allocated */ (*p)++; /* storage). */ bar (p); /* Explicitly determined - private. */ diff --git a/gcc/testsuite/gcc.dg/gomp/simd-1.c b/gcc/testsuite/gcc.dg/gomp/simd-1.c new file mode 100644 index 0000000..00aa159 --- /dev/null +++ b/gcc/testsuite/gcc.dg/gomp/simd-1.c @@ -0,0 +1,21 @@ +int a[32], b[32]; + +void +foo (void) +{ + int i, j; + #pragma omp simd linear(i, j) collapse(2) /* { dg-error "iteration variable 'i' should not be linear" } */ + for (i = 0; i < 32; ++i) /* { dg-error "iteration variable 'j' should not be linear" "" { target *-*-* } .-1 } */ + for (j = 0; j < 32; ++j) + a[i] += b[j]; +} + +void +bar (void) +{ + static int i, j; + #pragma omp for simd linear(i, j) collapse(2) /* { dg-error "iteration variable 'i' should not be linear" } */ + for (i = 0; i < 32; ++i) /* { dg-error "iteration variable 'j' should not be linear" "" { target *-*-* } .-1 } */ + for (j = 0; j < 32; ++j) + a[i] += b[j]; +} diff --git a/gcc/testsuite/gcc.dg/gomp/teams-1.c b/gcc/testsuite/gcc.dg/gomp/teams-1.c index a537047..db7f50b 100644 --- a/gcc/testsuite/gcc.dg/gomp/teams-1.c +++ b/gcc/testsuite/gcc.dg/gomp/teams-1.c @@ -23,8 +23,8 @@ foo (int x) switch (x) // { dg-error "invalid entry to OpenMP structured block" } { - #pragma omp target teams - { case 0:; } // { dg-warning "statement will never be executed" } + #pragma omp target teams // { dg-warning "statement will never be executed" } + { case 0:; } } } diff --git a/gcc/tree-core.h b/gcc/tree-core.h index 7df5c40..cec95e7 100644 --- a/gcc/tree-core.h +++ b/gcc/tree-core.h @@ -258,6 +258,12 @@ enum omp_clause_code { reductions. */ OMP_CLAUSE_REDUCTION, + /* OpenMP clause: task_reduction (operator:variable_list). */ + OMP_CLAUSE_TASK_REDUCTION, + + /* OpenMP clause: in_reduction (operator:variable_list). */ + OMP_CLAUSE_IN_REDUCTION, + /* OpenMP clause: copyin (variable_list). */ OMP_CLAUSE_COPYIN, @@ -273,6 +279,9 @@ enum omp_clause_code { /* OpenMP clause: depend ({in,out,inout}:variable-list). */ OMP_CLAUSE_DEPEND, + /* OpenMP clause: nontemporal (variable-list). */ + OMP_CLAUSE_NONTEMPORAL, + /* OpenMP clause: uniform (argument-list). */ OMP_CLAUSE_UNIFORM, @@ -331,6 +340,9 @@ enum omp_clause_code { /* Internal clause: temporary for combined loops expansion. */ OMP_CLAUSE__LOOPTEMP_, + /* Internal clause: temporary for task reductions. */ + OMP_CLAUSE__REDUCTEMP_, + /* OpenACC/OpenMP clause: if (scalar-expression). */ OMP_CLAUSE_IF, @@ -493,6 +505,36 @@ enum omp_clause_default_kind { OMP_CLAUSE_DEFAULT_LAST }; +enum omp_clause_defaultmap_kind { + OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED, + OMP_CLAUSE_DEFAULTMAP_CATEGORY_SCALAR, + OMP_CLAUSE_DEFAULTMAP_CATEGORY_AGGREGATE, + OMP_CLAUSE_DEFAULTMAP_CATEGORY_ALLOCATABLE, + OMP_CLAUSE_DEFAULTMAP_CATEGORY_POINTER, + OMP_CLAUSE_DEFAULTMAP_CATEGORY_MASK = 7, + OMP_CLAUSE_DEFAULTMAP_ALLOC = 1 * (OMP_CLAUSE_DEFAULTMAP_CATEGORY_MASK + 1), + OMP_CLAUSE_DEFAULTMAP_TO = 2 * (OMP_CLAUSE_DEFAULTMAP_CATEGORY_MASK + 1), + OMP_CLAUSE_DEFAULTMAP_FROM = 3 * (OMP_CLAUSE_DEFAULTMAP_CATEGORY_MASK + 1), + OMP_CLAUSE_DEFAULTMAP_TOFROM = 4 * (OMP_CLAUSE_DEFAULTMAP_CATEGORY_MASK + 1), + OMP_CLAUSE_DEFAULTMAP_FIRSTPRIVATE + = 5 * (OMP_CLAUSE_DEFAULTMAP_CATEGORY_MASK + 1), + OMP_CLAUSE_DEFAULTMAP_NONE = 6 * (OMP_CLAUSE_DEFAULTMAP_CATEGORY_MASK + 1), + OMP_CLAUSE_DEFAULTMAP_DEFAULT + = 7 * (OMP_CLAUSE_DEFAULTMAP_CATEGORY_MASK + 1), + OMP_CLAUSE_DEFAULTMAP_MASK = 7 * (OMP_CLAUSE_DEFAULTMAP_CATEGORY_MASK + 1) +}; + +/* memory-order-clause on OpenMP atomic/flush constructs or + argument of atomic_default_mem_order clause. */ +enum omp_memory_order { + OMP_MEMORY_ORDER_UNSPECIFIED, + OMP_MEMORY_ORDER_RELAXED, + OMP_MEMORY_ORDER_ACQUIRE, + OMP_MEMORY_ORDER_RELEASE, + OMP_MEMORY_ORDER_ACQ_REL, + OMP_MEMORY_ORDER_SEQ_CST +}; + /* There is a TYPE_QUAL value for each type qualifier. They can be combined by bitwise-or to form the complete set of qualifiers for a type. */ @@ -983,6 +1025,9 @@ struct GTY(()) tree_base { /* Internal function code. */ enum internal_fn ifn; + /* OMP_ATOMIC* memory order. */ + enum omp_memory_order omp_atomic_memory_order; + /* The following two fields are used for MEM_REF and TARGET_MEM_REF expression trees and specify known data non-dependences. For two memory references in a function they are known to not @@ -1095,7 +1140,7 @@ struct GTY(()) tree_base { OMP_CLAUSE_MAP OMP_CLAUSE_REDUCTION_OMP_ORIG_REF in - OMP_CLAUSE_REDUCTION + OMP_CLAUSE_{,TASK_,IN_}REDUCTION TRANSACTION_EXPR_RELAXED in TRANSACTION_EXPR @@ -1123,9 +1168,6 @@ struct GTY(()) tree_base { OMP_PARALLEL_COMBINED in OMP_PARALLEL - OMP_ATOMIC_SEQ_CST in - OMP_ATOMIC* - OMP_CLAUSE_PRIVATE_OUTER_REF in OMP_CLAUSE_PRIVATE @@ -1373,8 +1415,10 @@ enum omp_clause_depend_kind OMP_CLAUSE_DEPEND_IN, OMP_CLAUSE_DEPEND_OUT, OMP_CLAUSE_DEPEND_INOUT, + OMP_CLAUSE_DEPEND_MUTEXINOUTSET, OMP_CLAUSE_DEPEND_SOURCE, OMP_CLAUSE_DEPEND_SINK, + OMP_CLAUSE_DEPEND_DEPOBJ, OMP_CLAUSE_DEPEND_LAST }; @@ -1463,6 +1507,7 @@ struct GTY(()) tree_omp_clause { enum tree_code reduction_code; enum omp_clause_linear_kind linear_kind; enum tree_code if_modifier; + enum omp_clause_defaultmap_kind defaultmap_kind; /* The dimension a OMP_CLAUSE__GRIDDIM_ clause of a gridified target construct describes. */ unsigned int dimension; diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index 5ce319a..5aa782b 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -1515,7 +1515,8 @@ remap_gimple_stmt (gimple *stmt, copy_body_data *id) case GIMPLE_OMP_TASKGROUP: s1 = remap_gimple_seq (gimple_omp_body (stmt), id); - copy = gimple_build_omp_taskgroup (s1); + copy = gimple_build_omp_taskgroup + (s1, gimple_omp_taskgroup_clauses (stmt)); break; case GIMPLE_OMP_ORDERED: diff --git a/gcc/tree-nested.c b/gcc/tree-nested.c index 4579b4c..c964b7a 100644 --- a/gcc/tree-nested.c +++ b/gcc/tree-nested.c @@ -1314,6 +1314,8 @@ convert_nonlocal_omp_clauses (tree *pclauses, struct walk_stmt_info *wi) convert_nonlocal_reference_op (&OMP_CLAUSE_ALIGNED_ALIGNMENT (clause), &dummy, wi); } + /* FALLTHRU */ + case OMP_CLAUSE_NONTEMPORAL: /* Like do_decl_clause, but don't add any suppression. */ decl = OMP_CLAUSE_DECL (clause); if (VAR_P (decl) @@ -1322,8 +1324,7 @@ convert_nonlocal_omp_clauses (tree *pclauses, struct walk_stmt_info *wi) if (decl_function_context (decl) != info->context) { OMP_CLAUSE_DECL (clause) = get_nonlocal_debug_decl (info, decl); - if (OMP_CLAUSE_CODE (clause) != OMP_CLAUSE_PRIVATE) - need_chain = true; + need_chain = true; } break; @@ -1365,6 +1366,7 @@ convert_nonlocal_omp_clauses (tree *pclauses, struct walk_stmt_info *wi) /* The following clauses are only added during OMP lowering; nested function decomposition happens before that. */ case OMP_CLAUSE__LOOPTEMP_: + case OMP_CLAUSE__REDUCTEMP_: case OMP_CLAUSE__SIMDUID_: case OMP_CLAUSE__GRIDDIM_: /* Anything else. */ @@ -2000,6 +2002,8 @@ convert_local_omp_clauses (tree *pclauses, struct walk_stmt_info *wi) convert_local_reference_op (&OMP_CLAUSE_ALIGNED_ALIGNMENT (clause), &dummy, wi); } + /* FALLTHRU */ + case OMP_CLAUSE_NONTEMPORAL: /* Like do_decl_clause, but don't add any suppression. */ decl = OMP_CLAUSE_DECL (clause); if (VAR_P (decl) @@ -2056,6 +2060,7 @@ convert_local_omp_clauses (tree *pclauses, struct walk_stmt_info *wi) /* The following clauses are only added during OMP lowering; nested function decomposition happens before that. */ case OMP_CLAUSE__LOOPTEMP_: + case OMP_CLAUSE__REDUCTEMP_: case OMP_CLAUSE__SIMDUID_: case OMP_CLAUSE__GRIDDIM_: /* Anything else. */ diff --git a/gcc/tree-parloops.c b/gcc/tree-parloops.c index 5935cf4..94824a0 100644 --- a/gcc/tree-parloops.c +++ b/gcc/tree-parloops.c @@ -1130,7 +1130,8 @@ create_call_for_reduction_1 (reduction_info **slot, struct clsn_data *clsn_data) tmp_load = create_tmp_var (TREE_TYPE (TREE_TYPE (addr))); tmp_load = make_ssa_name (tmp_load); - load = gimple_build_omp_atomic_load (tmp_load, addr); + load = gimple_build_omp_atomic_load (tmp_load, addr, + OMP_MEMORY_ORDER_RELAXED); SSA_NAME_DEF_STMT (tmp_load) = load; gsi = gsi_start_bb (new_bb); gsi_insert_after (&gsi, load, GSI_NEW_STMT); @@ -1146,7 +1147,9 @@ create_call_for_reduction_1 (reduction_info **slot, struct clsn_data *clsn_data) name = force_gimple_operand_gsi (&gsi, x, true, NULL_TREE, true, GSI_CONTINUE_LINKING); - gsi_insert_after (&gsi, gimple_build_omp_atomic_store (name), GSI_NEW_STMT); + gimple *store = gimple_build_omp_atomic_store (name, + OMP_MEMORY_ORDER_RELAXED); + gsi_insert_after (&gsi, store, GSI_NEW_STMT); return 1; } diff --git a/gcc/tree-pretty-print.c b/gcc/tree-pretty-print.c index 81414d1..99eca4a 100644 --- a/gcc/tree-pretty-print.c +++ b/gcc/tree-pretty-print.c @@ -392,6 +392,31 @@ dump_array_domain (pretty_printer *pp, tree domain, int spc, dump_flags_t flags) } +/* Dump OpenMP iterators ITER. */ + +static void +dump_omp_iterators (pretty_printer *pp, tree iter, int spc, dump_flags_t flags) +{ + pp_string (pp, "iterator("); + for (tree it = iter; it; it = TREE_CHAIN (it)) + { + if (it != iter) + pp_string (pp, ", "); + dump_generic_node (pp, TREE_TYPE (TREE_VEC_ELT (it, 0)), spc, flags, + false); + pp_space (pp); + dump_generic_node (pp, TREE_VEC_ELT (it, 0), spc, flags, false); + pp_equal (pp); + dump_generic_node (pp, TREE_VEC_ELT (it, 1), spc, flags, false); + pp_colon (pp); + dump_generic_node (pp, TREE_VEC_ELT (it, 2), spc, flags, false); + pp_colon (pp); + dump_generic_node (pp, TREE_VEC_ELT (it, 3), spc, flags, false); + } + pp_right_paren (pp); +} + + /* Dump OpenMP clause CLAUSE. PP, CLAUSE, SPC and FLAGS are as in dump_generic_node. */ @@ -413,7 +438,13 @@ dump_omp_clause (pretty_printer *pp, tree clause, int spc, dump_flags_t flags) goto print_remap; case OMP_CLAUSE_LASTPRIVATE: name = "lastprivate"; - goto print_remap; + if (!OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (clause)) + goto print_remap; + pp_string (pp, "lastprivate(conditional:"); + dump_generic_node (pp, OMP_CLAUSE_DECL (clause), + spc, flags, false); + pp_right_paren (pp); + break; case OMP_CLAUSE_COPYIN: name = "copyin"; goto print_remap; @@ -432,12 +463,18 @@ dump_omp_clause (pretty_printer *pp, tree clause, int spc, dump_flags_t flags) case OMP_CLAUSE__LOOPTEMP_: name = "_looptemp_"; goto print_remap; + case OMP_CLAUSE__REDUCTEMP_: + name = "_reductemp_"; + goto print_remap; case OMP_CLAUSE_TO_DECLARE: name = "to"; goto print_remap; case OMP_CLAUSE_LINK: name = "link"; goto print_remap; + case OMP_CLAUSE_NONTEMPORAL: + name = "nontemporal"; + goto print_remap; print_remap: pp_string (pp, name); pp_left_paren (pp); @@ -446,8 +483,20 @@ dump_omp_clause (pretty_printer *pp, tree clause, int spc, dump_flags_t flags) pp_right_paren (pp); break; + case OMP_CLAUSE_TASK_REDUCTION: + case OMP_CLAUSE_IN_REDUCTION: + pp_string (pp, OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_IN_REDUCTION + ? "in_" : "task_"); + /* FALLTHRU */ case OMP_CLAUSE_REDUCTION: pp_string (pp, "reduction("); + if (OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_REDUCTION) + { + if (OMP_CLAUSE_REDUCTION_TASK (clause)) + pp_string (pp, "task,"); + else if (OMP_CLAUSE_REDUCTION_INSCAN (clause)) + pp_string (pp, "inscan,"); + } if (OMP_CLAUSE_REDUCTION_CODE (clause) != ERROR_MARK) { pp_string (pp, @@ -464,7 +513,9 @@ dump_omp_clause (pretty_printer *pp, tree clause, int spc, dump_flags_t flags) switch (OMP_CLAUSE_IF_MODIFIER (clause)) { case ERROR_MARK: break; + case VOID_CST: pp_string (pp, "cancel:"); break; case OMP_PARALLEL: pp_string (pp, "parallel:"); break; + case OMP_SIMD: pp_string (pp, "simd:"); break; case OMP_TASK: pp_string (pp, "task:"); break; case OMP_TASKLOOP: pp_string (pp, "taskloop:"); break; case OMP_TARGET_DATA: pp_string (pp, "target data:"); break; @@ -643,18 +694,27 @@ dump_omp_clause (pretty_printer *pp, tree clause, int spc, dump_flags_t flags) pp_string (pp, "depend("); switch (OMP_CLAUSE_DEPEND_KIND (clause)) { + case OMP_CLAUSE_DEPEND_DEPOBJ: + name = "depobj"; + break; case OMP_CLAUSE_DEPEND_IN: - pp_string (pp, "in"); + name = "in"; break; case OMP_CLAUSE_DEPEND_OUT: - pp_string (pp, "out"); + name = "out"; break; case OMP_CLAUSE_DEPEND_INOUT: - pp_string (pp, "inout"); + name = "inout"; + break; + case OMP_CLAUSE_DEPEND_MUTEXINOUTSET: + name = "mutexinoutset"; break; case OMP_CLAUSE_DEPEND_SOURCE: pp_string (pp, "source)"); return; + case OMP_CLAUSE_DEPEND_LAST: + name = "__internal__"; + break; case OMP_CLAUSE_DEPEND_SINK: pp_string (pp, "sink:"); for (tree t = OMP_CLAUSE_DECL (clause); t; t = TREE_CHAIN (t)) @@ -680,10 +740,21 @@ dump_omp_clause (pretty_printer *pp, tree clause, int spc, dump_flags_t flags) default: gcc_unreachable (); } - pp_colon (pp); - dump_generic_node (pp, OMP_CLAUSE_DECL (clause), - spc, flags, false); - pp_right_paren (pp); + { + tree t = OMP_CLAUSE_DECL (clause); + if (TREE_CODE (t) == TREE_LIST + && TREE_PURPOSE (t) + && TREE_CODE (TREE_PURPOSE (t)) == TREE_VEC) + { + dump_omp_iterators (pp, TREE_PURPOSE (t), spc, flags); + pp_colon (pp); + t = TREE_VALUE (t); + } + pp_string (pp, name); + pp_colon (pp); + dump_generic_node (pp, t, spc, flags, false); + pp_right_paren (pp); + } break; case OMP_CLAUSE_MAP: @@ -900,7 +971,53 @@ dump_omp_clause (pretty_printer *pp, tree clause, int spc, dump_flags_t flags) break; case OMP_CLAUSE_DEFAULTMAP: - pp_string (pp, "defaultmap(tofrom:scalar)"); + pp_string (pp, "defaultmap("); + switch (OMP_CLAUSE_DEFAULTMAP_BEHAVIOR (clause)) + { + case OMP_CLAUSE_DEFAULTMAP_ALLOC: + pp_string (pp, "alloc"); + break; + case OMP_CLAUSE_DEFAULTMAP_TO: + pp_string (pp, "to"); + break; + case OMP_CLAUSE_DEFAULTMAP_FROM: + pp_string (pp, "from"); + break; + case OMP_CLAUSE_DEFAULTMAP_TOFROM: + pp_string (pp, "tofrom"); + break; + case OMP_CLAUSE_DEFAULTMAP_FIRSTPRIVATE: + pp_string (pp, "firstprivate"); + break; + case OMP_CLAUSE_DEFAULTMAP_NONE: + pp_string (pp, "none"); + break; + case OMP_CLAUSE_DEFAULTMAP_DEFAULT: + pp_string (pp, "default"); + break; + default: + gcc_unreachable (); + } + switch (OMP_CLAUSE_DEFAULTMAP_CATEGORY (clause)) + { + case OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED: + break; + case OMP_CLAUSE_DEFAULTMAP_CATEGORY_SCALAR: + pp_string (pp, ":scalar"); + break; + case OMP_CLAUSE_DEFAULTMAP_CATEGORY_AGGREGATE: + pp_string (pp, ":aggregate"); + break; + case OMP_CLAUSE_DEFAULTMAP_CATEGORY_ALLOCATABLE: + pp_string (pp, ":allocatable"); + break; + case OMP_CLAUSE_DEFAULTMAP_CATEGORY_POINTER: + pp_string (pp, ":pointer"); + break; + default: + gcc_unreachable (); + } + pp_right_paren (pp); break; case OMP_CLAUSE__SIMDUID_: @@ -1218,6 +1335,34 @@ dump_block_node (pretty_printer *pp, tree block, int spc, dump_flags_t flags) } } +/* Dump #pragma omp atomic memory order clause. */ + +void +dump_omp_atomic_memory_order (pretty_printer *pp, enum omp_memory_order mo) +{ + switch (mo) + { + case OMP_MEMORY_ORDER_RELAXED: + pp_string (pp, " relaxed"); + break; + case OMP_MEMORY_ORDER_SEQ_CST: + pp_string (pp, " seq_cst"); + break; + case OMP_MEMORY_ORDER_ACQ_REL: + pp_string (pp, " acq_rel"); + break; + case OMP_MEMORY_ORDER_ACQUIRE: + pp_string (pp, " acquire"); + break; + case OMP_MEMORY_ORDER_RELEASE: + pp_string (pp, " release"); + break; + case OMP_MEMORY_ORDER_UNSPECIFIED: + break; + default: + gcc_unreachable (); + } +} /* Dump the node NODE on the pretty_printer PP, SPC spaces of indent. FLAGS specifies details to show in the dump (see TDF_* in @@ -2991,7 +3136,8 @@ dump_generic_node (pretty_printer *pp, tree node, int spc, dump_flags_t flags, break; case OMP_TASK: - pp_string (pp, "#pragma omp task"); + pp_string (pp, OMP_TASK_BODY (node) ? "#pragma omp task" + : "#pragma omp taskwait"); dump_omp_clauses (pp, OMP_TASK_CLAUSES (node), spc, flags); goto dump_omp_body; @@ -3122,6 +3268,7 @@ dump_generic_node (pretty_printer *pp, tree node, int spc, dump_flags_t flags, case OMP_TASKGROUP: pp_string (pp, "#pragma omp taskgroup"); + dump_omp_clauses (pp, OMP_TASKGROUP_CLAUSES (node), spc, flags); goto dump_omp_body; case OMP_ORDERED: @@ -3144,8 +3291,7 @@ dump_generic_node (pretty_printer *pp, tree node, int spc, dump_flags_t flags, case OMP_ATOMIC: pp_string (pp, "#pragma omp atomic"); - if (OMP_ATOMIC_SEQ_CST (node)) - pp_string (pp, " seq_cst"); + dump_omp_atomic_memory_order (pp, OMP_ATOMIC_MEMORY_ORDER (node)); newline_and_indent (pp, spc + 2); dump_generic_node (pp, TREE_OPERAND (node, 0), spc, flags, false); pp_space (pp); @@ -3156,8 +3302,7 @@ dump_generic_node (pretty_printer *pp, tree node, int spc, dump_flags_t flags, case OMP_ATOMIC_READ: pp_string (pp, "#pragma omp atomic read"); - if (OMP_ATOMIC_SEQ_CST (node)) - pp_string (pp, " seq_cst"); + dump_omp_atomic_memory_order (pp, OMP_ATOMIC_MEMORY_ORDER (node)); newline_and_indent (pp, spc + 2); dump_generic_node (pp, TREE_OPERAND (node, 0), spc, flags, false); pp_space (pp); @@ -3166,8 +3311,7 @@ dump_generic_node (pretty_printer *pp, tree node, int spc, dump_flags_t flags, case OMP_ATOMIC_CAPTURE_OLD: case OMP_ATOMIC_CAPTURE_NEW: pp_string (pp, "#pragma omp atomic capture"); - if (OMP_ATOMIC_SEQ_CST (node)) - pp_string (pp, " seq_cst"); + dump_omp_atomic_memory_order (pp, OMP_ATOMIC_MEMORY_ORDER (node)); newline_and_indent (pp, spc + 2); dump_generic_node (pp, TREE_OPERAND (node, 0), spc, flags, false); pp_space (pp); diff --git a/gcc/tree-pretty-print.h b/gcc/tree-pretty-print.h index 4de0e09..ea4ebee 100644 --- a/gcc/tree-pretty-print.h +++ b/gcc/tree-pretty-print.h @@ -40,6 +40,8 @@ extern void print_generic_stmt_indented (FILE *, tree, dump_flags_t, int); extern void print_generic_expr (FILE *, tree, dump_flags_t = TDF_NONE); extern char *print_generic_expr_to_str (tree); extern void dump_omp_clauses (pretty_printer *, tree, int, dump_flags_t); +extern void dump_omp_atomic_memory_order (pretty_printer *, + enum omp_memory_order); extern int dump_generic_node (pretty_printer *, tree, int, dump_flags_t, bool); extern void print_declaration (pretty_printer *, tree, int, dump_flags_t); extern int op_code_prio (enum tree_code); diff --git a/gcc/tree-streamer-in.c b/gcc/tree-streamer-in.c index a1e67d6..811d673 100644 --- a/gcc/tree-streamer-in.c +++ b/gcc/tree-streamer-in.c @@ -447,6 +447,8 @@ unpack_ts_omp_clause_value_fields (struct data_in *data_in, OMP_CLAUSE_PROC_BIND_LAST); break; case OMP_CLAUSE_REDUCTION: + case OMP_CLAUSE_TASK_REDUCTION: + case OMP_CLAUSE_IN_REDUCTION: OMP_CLAUSE_REDUCTION_CODE (expr) = bp_unpack_enum (bp, tree_code, MAX_TREE_CODES); break; diff --git a/gcc/tree-streamer-out.c b/gcc/tree-streamer-out.c index 55abd3c..ac798a3 100644 --- a/gcc/tree-streamer-out.c +++ b/gcc/tree-streamer-out.c @@ -395,6 +395,8 @@ pack_ts_omp_clause_value_fields (struct output_block *ob, OMP_CLAUSE_PROC_BIND_KIND (expr)); break; case OMP_CLAUSE_REDUCTION: + case OMP_CLAUSE_TASK_REDUCTION: + case OMP_CLAUSE_IN_REDUCTION: bp_pack_enum (bp, tree_code, MAX_TREE_CODES, OMP_CLAUSE_REDUCTION_CODE (expr)); break; @@ -836,12 +838,18 @@ write_ts_omp_clause_tree_pointers (struct output_block *ob, tree expr, int i; for (i = 0; i < omp_clause_num_ops[OMP_CLAUSE_CODE (expr)]; i++) stream_write_tree (ob, OMP_CLAUSE_OPERAND (expr, i), ref_p); - if (OMP_CLAUSE_CODE (expr) == OMP_CLAUSE_REDUCTION) + switch (OMP_CLAUSE_CODE (expr)) { + case OMP_CLAUSE_REDUCTION: + case OMP_CLAUSE_TASK_REDUCTION: + case OMP_CLAUSE_IN_REDUCTION: /* We don't stream these right now, handle it if streaming of them is needed. */ gcc_assert (OMP_CLAUSE_REDUCTION_GIMPLE_INIT (expr) == NULL); gcc_assert (OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (expr) == NULL); + break; + default: + break; } stream_write_tree (ob, OMP_CLAUSE_CHAIN (expr), ref_p); } @@ -282,11 +282,14 @@ unsigned const char omp_clause_num_ops[] = 1, /* OMP_CLAUSE_FIRSTPRIVATE */ 2, /* OMP_CLAUSE_LASTPRIVATE */ 5, /* OMP_CLAUSE_REDUCTION */ + 5, /* OMP_CLAUSE_TASK_REDUCTION */ + 5, /* OMP_CLAUSE_IN_REDUCTION */ 1, /* OMP_CLAUSE_COPYIN */ 1, /* OMP_CLAUSE_COPYPRIVATE */ 3, /* OMP_CLAUSE_LINEAR */ 2, /* OMP_CLAUSE_ALIGNED */ 1, /* OMP_CLAUSE_DEPEND */ + 1, /* OMP_CLAUSE_NONTEMPORAL */ 1, /* OMP_CLAUSE_UNIFORM */ 1, /* OMP_CLAUSE_TO_DECLARE */ 1, /* OMP_CLAUSE_LINK */ @@ -302,6 +305,7 @@ unsigned const char omp_clause_num_ops[] = 0, /* OMP_CLAUSE_AUTO */ 0, /* OMP_CLAUSE_SEQ */ 1, /* OMP_CLAUSE__LOOPTEMP_ */ + 1, /* OMP_CLAUSE__REDUCTEMP_ */ 1, /* OMP_CLAUSE_IF */ 1, /* OMP_CLAUSE_NUM_THREADS */ 1, /* OMP_CLAUSE_SCHEDULE */ @@ -355,11 +359,14 @@ const char * const omp_clause_code_name[] = "firstprivate", "lastprivate", "reduction", + "task_reduction", + "in_reduction", "copyin", "copyprivate", "linear", "aligned", "depend", + "nontemporal", "uniform", "to", "link", @@ -375,6 +382,7 @@ const char * const omp_clause_code_name[] = "auto", "seq", "_looptemp_", + "_reductemp_", "if", "num_threads", "schedule", @@ -11886,6 +11894,7 @@ walk_tree_1 (tree *tp, walk_tree_fn func, void *data, case OMP_CLAUSE_SCHEDULE: case OMP_CLAUSE_UNIFORM: case OMP_CLAUSE_DEPEND: + case OMP_CLAUSE_NONTEMPORAL: case OMP_CLAUSE_NUM_TEAMS: case OMP_CLAUSE_THREAD_LIMIT: case OMP_CLAUSE_DEVICE: @@ -11902,6 +11911,7 @@ walk_tree_1 (tree *tp, walk_tree_fn func, void *data, case OMP_CLAUSE_USE_DEVICE_PTR: case OMP_CLAUSE_IS_DEVICE_PTR: case OMP_CLAUSE__LOOPTEMP_: + case OMP_CLAUSE__REDUCTEMP_: case OMP_CLAUSE__SIMDUID_: WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp, 0)); /* FALLTHRU */ @@ -11959,6 +11969,8 @@ walk_tree_1 (tree *tp, walk_tree_fn func, void *data, WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp)); case OMP_CLAUSE_REDUCTION: + case OMP_CLAUSE_TASK_REDUCTION: + case OMP_CLAUSE_IN_REDUCTION: { int i; for (i = 0; i < 5; i++) diff --git a/gcc/tree.def b/gcc/tree.def index 78b499a..b75204de 100644 --- a/gcc/tree.def +++ b/gcc/tree.def @@ -1186,6 +1186,11 @@ DEFTREECODE (OMP_CRITICAL, "omp_critical", tcc_statement, 3) Operand 1: OMP_SINGLE_CLAUSES: List of clauses. */ DEFTREECODE (OMP_SINGLE, "omp_single", tcc_statement, 2) +/* OpenMP - #pragma omp taskgroup + Operand 0: OMP_TASKGROUP_BODY: Taskgroup body. + Operand 1: OMP_SINGLE_CLAUSES: List of clauses. */ +DEFTREECODE (OMP_TASKGROUP, "omp_taskgroup", tcc_statement, 2) + /* OpenMP - #pragma omp section Operand 0: OMP_SECTION_BODY: Section body. */ DEFTREECODE (OMP_SECTION, "omp_section", tcc_statement, 1) @@ -1194,10 +1199,6 @@ DEFTREECODE (OMP_SECTION, "omp_section", tcc_statement, 1) Operand 0: OMP_MASTER_BODY: Master section body. */ DEFTREECODE (OMP_MASTER, "omp_master", tcc_statement, 1) -/* OpenMP - #pragma omp taskgroup - Operand 0: OMP_TASKGROUP_BODY: Taskgroup body. */ -DEFTREECODE (OMP_TASKGROUP, "omp_taskgroup", tcc_statement, 1) - /* OpenACC - #pragma acc cache (variable1 ... variableN) Operand 0: OACC_CACHE_CLAUSES: List of variables (transformed into OMP_CLAUSE__CACHE_ clauses). */ @@ -1306,9 +1306,9 @@ extern tree maybe_wrap_with_location (tree, location_t); /* Generic accessors for OMP nodes that keep the body as operand 0, and clauses as operand 1. */ #define OMP_BODY(NODE) \ - TREE_OPERAND (TREE_RANGE_CHECK (NODE, OACC_PARALLEL, OMP_TASKGROUP), 0) + TREE_OPERAND (TREE_RANGE_CHECK (NODE, OACC_PARALLEL, OMP_MASTER), 0) #define OMP_CLAUSES(NODE) \ - TREE_OPERAND (TREE_RANGE_CHECK (NODE, OACC_PARALLEL, OMP_SINGLE), 1) + TREE_OPERAND (TREE_RANGE_CHECK (NODE, OACC_PARALLEL, OMP_TASKGROUP), 1) /* Generic accessors for OMP nodes that keep clauses as operand 0. */ #define OMP_STANDALONE_CLAUSES(NODE) \ @@ -1369,6 +1369,8 @@ extern tree maybe_wrap_with_location (tree, location_t); #define OMP_MASTER_BODY(NODE) TREE_OPERAND (OMP_MASTER_CHECK (NODE), 0) #define OMP_TASKGROUP_BODY(NODE) TREE_OPERAND (OMP_TASKGROUP_CHECK (NODE), 0) +#define OMP_TASKGROUP_CLAUSES(NODE) \ + TREE_OPERAND (OMP_TASKGROUP_CHECK (NODE), 1) #define OMP_ORDERED_BODY(NODE) TREE_OPERAND (OMP_ORDERED_CHECK (NODE), 0) #define OMP_ORDERED_CLAUSES(NODE) TREE_OPERAND (OMP_ORDERED_CHECK (NODE), 1) @@ -1406,7 +1408,7 @@ extern tree maybe_wrap_with_location (tree, location_t); #define OMP_CLAUSE_DECL(NODE) \ OMP_CLAUSE_OPERAND (OMP_CLAUSE_RANGE_CHECK (OMP_CLAUSE_CHECK (NODE), \ OMP_CLAUSE_PRIVATE, \ - OMP_CLAUSE__LOOPTEMP_), 0) + OMP_CLAUSE__REDUCTEMP_), 0) #define OMP_CLAUSE_HAS_LOCATION(NODE) \ (LOCATION_LOCUS ((OMP_CLAUSE_CHECK (NODE))->omp_clause.locus) \ != UNKNOWN_LOCATION) @@ -1432,11 +1434,10 @@ extern tree maybe_wrap_with_location (tree, location_t); #define OMP_TARGET_COMBINED(NODE) \ (OMP_TARGET_CHECK (NODE)->base.private_flag) -/* True if OMP_ATOMIC* is supposed to be sequentially consistent - as opposed to relaxed. */ -#define OMP_ATOMIC_SEQ_CST(NODE) \ +/* Memory order for OMP_ATOMIC*. */ +#define OMP_ATOMIC_MEMORY_ORDER(NODE) \ (TREE_RANGE_CHECK (NODE, OMP_ATOMIC, \ - OMP_ATOMIC_CAPTURE_NEW)->base.private_flag) + OMP_ATOMIC_CAPTURE_NEW)->base.u.omp_atomic_memory_order) /* True on a PRIVATE clause if its decl is kept around for debugging information only and its DECL_VALUE_EXPR is supposed to point @@ -1459,6 +1460,11 @@ extern tree maybe_wrap_with_location (tree, location_t); #define OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT(NODE) \ (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_FIRSTPRIVATE)->base.public_flag) +/* True on a FIRSTPRIVATE clause if only the reference and not what it refers + to should be firstprivatized. */ +#define OMP_CLAUSE_FIRSTPRIVATE_NO_REFERENCE(NODE) \ + TREE_PRIVATE (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_FIRSTPRIVATE)) + /* True on a LASTPRIVATE clause if a FIRSTPRIVATE clause for the same decl is present in the chain. */ #define OMP_CLAUSE_LASTPRIVATE_FIRSTPRIVATE(NODE) \ @@ -1476,6 +1482,10 @@ extern tree maybe_wrap_with_location (tree, location_t); #define OMP_CLAUSE_LASTPRIVATE_TASKLOOP_IV(NODE) \ TREE_PROTECTED (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_LASTPRIVATE)) +/* True if a LASTPRIVATE clause has CONDITIONAL: modifier. */ +#define OMP_CLAUSE_LASTPRIVATE_CONDITIONAL(NODE) \ + TREE_PRIVATE (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_LASTPRIVATE)) + /* True on a SHARED clause if a FIRSTPRIVATE clause for the same decl is present in the chain (this can happen only for taskloop with FIRSTPRIVATE/LASTPRIVATE on it originally. */ @@ -1579,24 +1589,38 @@ extern tree maybe_wrap_with_location (tree, location_t); OMP_CLAUSE_OPERAND (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_ORDERED), 0) #define OMP_CLAUSE_REDUCTION_CODE(NODE) \ - (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_REDUCTION)->omp_clause.subcode.reduction_code) + (OMP_CLAUSE_RANGE_CHECK (NODE, OMP_CLAUSE_REDUCTION, \ + OMP_CLAUSE_IN_REDUCTION)->omp_clause.subcode.reduction_code) #define OMP_CLAUSE_REDUCTION_INIT(NODE) \ - OMP_CLAUSE_OPERAND (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_REDUCTION), 1) + OMP_CLAUSE_OPERAND (OMP_CLAUSE_RANGE_CHECK (NODE, OMP_CLAUSE_REDUCTION, \ + OMP_CLAUSE_IN_REDUCTION), 1) #define OMP_CLAUSE_REDUCTION_MERGE(NODE) \ - OMP_CLAUSE_OPERAND (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_REDUCTION), 2) + OMP_CLAUSE_OPERAND (OMP_CLAUSE_RANGE_CHECK (NODE, OMP_CLAUSE_REDUCTION, \ + OMP_CLAUSE_IN_REDUCTION), 2) #define OMP_CLAUSE_REDUCTION_GIMPLE_INIT(NODE) \ (OMP_CLAUSE_CHECK (NODE))->omp_clause.gimple_reduction_init #define OMP_CLAUSE_REDUCTION_GIMPLE_MERGE(NODE) \ (OMP_CLAUSE_CHECK (NODE))->omp_clause.gimple_reduction_merge #define OMP_CLAUSE_REDUCTION_PLACEHOLDER(NODE) \ - OMP_CLAUSE_OPERAND (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_REDUCTION), 3) + OMP_CLAUSE_OPERAND (OMP_CLAUSE_RANGE_CHECK (NODE, OMP_CLAUSE_REDUCTION, \ + OMP_CLAUSE_IN_REDUCTION), 3) #define OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER(NODE) \ - OMP_CLAUSE_OPERAND (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_REDUCTION), 4) + OMP_CLAUSE_OPERAND (OMP_CLAUSE_RANGE_CHECK (NODE, OMP_CLAUSE_REDUCTION, \ + OMP_CLAUSE_IN_REDUCTION), 4) /* True if a REDUCTION clause may reference the original list item (omp_orig) in its OMP_CLAUSE_REDUCTION_{,GIMPLE_}INIT. */ #define OMP_CLAUSE_REDUCTION_OMP_ORIG_REF(NODE) \ - (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_REDUCTION)->base.public_flag) + (OMP_CLAUSE_RANGE_CHECK (NODE, OMP_CLAUSE_REDUCTION, \ + OMP_CLAUSE_IN_REDUCTION)->base.public_flag) + +/* True if a REDUCTION clause has task reduction-modifier. */ +#define OMP_CLAUSE_REDUCTION_TASK(NODE) \ + TREE_PROTECTED (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_REDUCTION)) + +/* True if a REDUCTION clause has inscan reduction-modifier. */ +#define OMP_CLAUSE_REDUCTION_INSCAN(NODE) \ + TREE_PRIVATE (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_REDUCTION)) /* True if a LINEAR clause doesn't need copy in. True for iterator vars which are always initialized inside of the loop construct, false otherwise. */ @@ -1665,6 +1689,18 @@ extern tree maybe_wrap_with_location (tree, location_t); #define OMP_CLAUSE_DEFAULT_KIND(NODE) \ (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_DEFAULT)->omp_clause.subcode.default_kind) +#define OMP_CLAUSE_DEFAULTMAP_KIND(NODE) \ + (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_DEFAULTMAP)->omp_clause.subcode.defaultmap_kind) +#define OMP_CLAUSE_DEFAULTMAP_CATEGORY(NODE) \ + ((enum omp_clause_defaultmap_kind) \ + (OMP_CLAUSE_DEFAULTMAP_KIND (NODE) & OMP_CLAUSE_DEFAULTMAP_CATEGORY_MASK)) +#define OMP_CLAUSE_DEFAULTMAP_BEHAVIOR(NODE) \ + ((enum omp_clause_defaultmap_kind) \ + (OMP_CLAUSE_DEFAULTMAP_KIND (NODE) & OMP_CLAUSE_DEFAULTMAP_MASK)) +#define OMP_CLAUSE_DEFAULTMAP_SET_KIND(NODE, BEHAVIOR, CATEGORY) \ + (OMP_CLAUSE_DEFAULTMAP_KIND (NODE) \ + = (enum omp_clause_defaultmap_kind) (CATEGORY | BEHAVIOR)) + #define OMP_CLAUSE_TILE_LIST(NODE) \ OMP_CLAUSE_OPERAND (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_TILE), 0) #define OMP_CLAUSE_TILE_ITERVAR(NODE) \ |