aboutsummaryrefslogtreecommitdiff
path: root/gcc
AgeCommit message (Collapse)AuthorFilesLines
2023-05-17c++: Don't try to initialize zero width bitfields in zero initialization ↵Jakub Jelinek2-6/+26
[PR109868] My GCC 12 change to avoid removing zero-sized bitfields as they are important for ABI and are needed for layout compatibility traits apparently causes zero sized bitfields to be initialized in the IL, which at least in 13+ results in ICEs in the ranger which is upset about zero precision types. I think we could even avoid initializing other unnamed bitfields, but unfortunately !CONSTRUCTOR_NO_CLEARING doesn't mean in the middle-end clearing of padding bits and until we have some new flag that represents the request to clear padding bits, I think it is better to keep zeroing non-zero sized unnamed bitfields. In addition to skipping those fields, I have changed the logic how UNION_TYPEs are handled, the current code was a little bit weird in that e.g. if first non-static data member had error_mark_node type, we'd happily zero initialize the second non-static data member, etc. 2023-05-17 Jakub Jelinek <jakub@redhat.com> PR c++/109868 * init.cc (build_zero_init_1): Don't initialize zero-width bitfields. For unions only initialize the first FIELD_DECL. * g++.dg/init/pr109868.C: New test. (cherry picked from commit 78327cf06e6b65fc9c614622c98f6a3f3bfb7784)
2023-05-17Daily bump.GCC Administrator4-1/+51
2023-05-16c++: -Wdangling-reference not suppressed in template [PR109774]Marek Polacek2-3/+26
In check_return_expr, we suppress the -Wdangling-reference warning when we're sure it would be a false positive. It wasn't working in a template, though, because the suppress_warning call was never reached. PR c++/109774 gcc/cp/ChangeLog: * typeck.cc (check_return_expr): In a template, return only after suppressing -Wdangling-reference. gcc/testsuite/ChangeLog: * g++.dg/warn/Wdangling-reference13.C: New test. (cherry picked from commit f25d2de17663a0132f9fe090dee39d3b1132067b)
2023-05-16amdgcn, openmp: Auto-detect USM mode and set HSA_XNACKAndrew Stubbs4-2/+78
The AMD GCN runtime must be set to the correct mode for Unified Shared Memory to work, but this is not always clear at compile and link time due to the split nature of the offload compilation pipeline. This patch sets a new attribute on OpenMP offload functions to ensure that the information is passed all the way to the backend. The backend then places a marker in the assembler code for mkoffload to find. Finally mkoffload places a constructor function into the final program to ensure that the HSA_XNACK environment variable passes the correct mode to the GPU. The HSA_XNACK variable must be set before the HSA runtime is even loaded, so it makes more sense to have this set within the constructor than at some point later within libgomp or the GCN plugin. gcc/ChangeLog: * config/gcn/gcn.c (unified_shared_memory_enabled): New variable. (gcn_init_cumulative_args): Handle attribute "omp unified memory". (gcn_hsa_declare_function_name): Emit "MKOFFLOAD OPTIONS: USM+". * config/gcn/mkoffload.c (TEST_XNACK_OFF): New macro. (process_asm): Detect "MKOFFLOAD OPTIONS: USM+". Emit configure_xnack constructor, as required. * omp-low.c (create_omp_child_function): Add attribute "omp unified memory".
2023-05-16amdgcn: Support XNACK modeAndrew Stubbs8-86/+171
The XNACK feature allows memory load instructions to restart safely following a page-miss interrupt. This is useful for shared-memory devices, like APUs, and to implement OpenMP Unified Shared Memory. To support the feature we must be able to set the appropriate meta-data and set the load instructions to early-clobber. When the port supports scheduling of s_waitcnt instructions there will be further requirements. gcc/ChangeLog: * config/gcn/gcn-hsa.h (XNACKOPT): New macro. (ASM_SPEC): Use XNACKOPT. * config/gcn/gcn-opts.h (enum sram_ecc_type): Rename to ... (enum hsaco_attr_type): ... this, and generalize the names. (TARGET_XNACK): New macro. * config/gcn/gcn-valu.md (gather<mode>_insn_1offset<exec>): Add xnack compatible alternatives. (gather<mode>_insn_2offsets<exec>): Likewise. * config/gcn/gcn.c (gcn_option_override): Permit -mxnack for devices other than Fiji. (gcn_expand_epilogue): Remove early-clobber problems. (output_file_start): Emit xnack attributes. (gcn_hsa_declare_function_name): Obey -mxnack setting. * config/gcn/gcn.md (xnack): New attribute. (enabled): Rework to include "xnack" attribute. (*movbi): Add xnack compatible alternatives. (*mov<mode>_insn): Likewise. (*mov<mode>_insn): Likewise. (*mov<mode>_insn): Likewise. (*movti_insn): Likewise. * config/gcn/gcn.opt (-mxnack): Add the "on/off/any" syntax. (sram_ecc_type): Rename to ... (hsaco_attr_type: ... this.) * config/gcn/mkoffload.c (SET_XNACK_ANY): New macro. (TEST_XNACK): Delete. (TEST_XNACK_ANY): New macro. (TEST_XNACK_ON): New macro. (main): Support the new -mxnack=on/off/any syntax.
2023-05-16Fix gfortran.dg/gomp/num-teams-2.f90Tobias Burnus2-6/+10
OG11 contrary to mainline issues an error for resolve_positive_int_expr (-> OG11 commit a14b3f29681da1d2465e15f98b8cf8d5c64a2c3c). Update testcase accordingly. gcc/testsuite/ * gfortran.dg/gomp/num-teams-2.f90: Use dg-error not dg-warning.
2023-05-16Fix ICE in nested-function-1.c testcaseKwok Cheung Yeung1-1/+9
The ICE occurs during Gimple verification after the ompexp stage because one of the arguments to the generated builtin call is of a Gimple reg type, but isn't a Gimple value (because it is marked addressable). This appears to be fallout from the commit "OpenACC 'kernels' decomposition: Mark variables used in synthesized data clauses as addressable [PR100280]". The launch dimensions have been added to the arguments of a builtin call by oacc_set_fn_attrib, but one of the dimensions has been marked addressable. Fixed by forcing the added arguments to be re-gimplified. 2022-05-13 Kwok Cheung Yeung <kcy@codesourcery.com> gcc/ * omp-expand.cc (expand_omp_target): Gimplify launch dimensions used in function call.
2023-05-16Fix ICE in kernels-decompose-pr100280-1.c testcaseKwok Cheung Yeung2-0/+7
Check that there is a DECL_INITIAL associated with prev_stmt before using it. 2022-04-15 Kwok Cheung Yeung <kcy@codesourcery.com> gcc/c-family/ * c-omp.cc (check_and_annotate_for_loop): Check that the DECL_INITIAL is non-NULL before using.
2023-05-16Fix ICE when cache-3-1.c testcase is runKwok Cheung Yeung4-2/+14
A change that was present in the OG11 version of 'openmp: in_reduction clause support on target construct' but not in the mainline version resulted in non-contiguous arrays being accepted in cache clauses, only to ICE later. 2022-03-17 Kwok Cheung Yeung <kcy@codesourcery.com> gcc/c/ * c-typeck.cc (handle_omp_array_sections_1): Add check to ensure that clause is a map. gcc/cp/ * semantics.cc (handle_omp_array_sections_1): Add check to ensure that clause is a map.
2023-05-16openmp: Implement uses_allocators clauseChung-Lin Tang33-15/+1758
This is a merge of: https://gcc.gnu.org/pipermail/gcc-patches/2022-June/596412.html For user defined allocator handles, this allows target regions to assign memory space and traits to allocators, and automatically calls omp_init/destroy_allocator() in the beginning/end of the target region. For pre-defined allocators (i.e. omp_..._mem_alloc names), this is a no-op, such clauses are not created. Asides from the front-end portions, the target region transforms are done in gimplify_omp_workshare. This patch also includes added changes to enforce the "allocate allocator must be also in a uses_allocator clause". This is done during gimplify_scan_omp_clauses. gcc/c-family/ChangeLog: * c-omp.cc (c_omp_split_clauses): Add OMP_CLAUSE_USES_ALLOCATORS case. * c-pragma.h (enum pragma_omp_clause): Add PRAGMA_OMP_CLAUSE_USES_ALLOCATORS. gcc/c/ChangeLog: * c-parser.cc (c_parser_omp_clause_name): Add case for uses_allocators clause. (c_parser_omp_clause_uses_allocators): New function. (c_parser_omp_all_clauses): Add PRAGMA_OMP_CLAUSE_USES_ALLOCATORS case. (OMP_TARGET_CLAUSE_MASK): Add PRAGMA_OMP_CLAUSE_USES_ALLOCATORS to mask. * c-typeck.cc (c_finish_omp_clauses): Add case handling for OMP_CLAUSE_USES_ALLOCATORS. gcc/cp/ChangeLog: * parser.cc (cp_parser_omp_clause_name): Add case for uses_allocators clause. (cp_parser_omp_clause_uses_allocators): New function. (cp_parser_omp_all_clauses): Add PRAGMA_OMP_CLAUSE_USES_ALLOCATORS case. (OMP_TARGET_CLAUSE_MASK): Add PRAGMA_OMP_CLAUSE_USES_ALLOCATORS to mask. * semantics.cc (finish_omp_clauses): Add case handling for OMP_CLAUSE_USES_ALLOCATORS. fortran/ChangeLog: * gfortran.h (struct gfc_omp_namelist): Add memspace_sym, traits_sym fields. (OMP_LIST_USES_ALLOCATORS): New list enum. * openmp.cc (enum omp_mask2): Add OMP_CLAUSE_USES_ALLOCATORS. (gfc_match_omp_clause_uses_allocators): New function. (gfc_match_omp_clauses): Add case to handle OMP_CLAUSE_USES_ALLOCATORS. (OMP_TARGET_CLAUSES): Add OMP_CLAUSE_USES_ALLOCATORS. (resolve_omp_clauses): Add "USES_ALLOCATORS" to clause_names[]. * dump-parse-tree.cc (show_omp_namelist): Handle OMP_LIST_USES_ALLOCATORS. (show_omp_clauses): Likewise. * trans-array.cc (gfc_conv_array_initializer): Adjust array index to always be a created tree expression instead of NULL_TREE when zero. * trans-openmp.cc (gfc_trans_omp_clauses): For ALLOCATE clause, handle using gfc_trans_omp_variable for EXPR_VARIABLE exprs. Add handling of OMP_LIST_USES_ALLOCATORS case. * types.def (BT_FN_VOID_PTRMODE): Define. (BT_FN_PTRMODE_PTRMODE_INT_PTR): Define. gcc/ChangeLog: * builtin-types.def (BT_FN_VOID_PTRMODE): Define. (BT_FN_PTRMODE_PTRMODE_INT_PTR): Define. * omp-builtins.def (BUILT_IN_OMP_INIT_ALLOCATOR): Define. (BUILT_IN_OMP_DESTROY_ALLOCATOR): Define. * tree-core.h (enum omp_clause_code): Add OMP_CLAUSE_USES_ALLOCATORS. * tree-pretty-print.cc (dump_omp_clause): Handle OMP_CLAUSE_USES_ALLOCATORS. * tree.h (OMP_CLAUSE_USES_ALLOCATORS_ALLOCATOR): New macro. (OMP_CLAUSE_USES_ALLOCATORS_MEMSPACE): New macro. (OMP_CLAUSE_USES_ALLOCATORS_TRAITS): New macro. * tree.cc (omp_clause_num_ops): Add OMP_CLAUSE_USES_ALLOCATORS. (omp_clause_code_name): Add "uses_allocators". (walk_tree_1): Add OMP_CLAUSE_USES_ALLOCATORS case. * gimplify.cc (gimplify_scan_omp_clauses): Add checking of OpenMP target region allocate clauses, to require a uses_allocators clause to exist for allocators. (gimplify_omp_workshare): Add handling of OMP_CLAUSE_USES_ALLOCATORS for OpenMP target regions; create calls of omp_init/destroy_allocator around target region body. * omp-low.cc (lower_private_allocate): Adjust receiving of allocator. (lower_rec_input_clauses): Likewise. (create_task_copyfn): Add dereference for allocator if needed. * system.h (startswith): New function. gcc/testsuite/ChangeLog: * c-c++-common/gomp/uses_allocators-1.c: New test. * c-c++-common/gomp/uses_allocators-2.c: New test. * c-c++-common/gomp/uses_allocators-3.c: New test. * gfortran.dg/gomp/allocate-1.f90: Adjust testcase. * gfortran.dg/gomp/uses_allocators-1.f90: New test. * gfortran.dg/gomp/uses_allocators-2.f90: New test. * gfortran.dg/gomp/uses_allocators-3.f90: New test.
2023-05-16Fortran: Fix proc pointer as elemental arg handlingTobias Burnus4-0/+16
The vtab's _callback function calls the elemental 'cb' cb (var(:)%comp, comp_types_vtable._callback); which gets called in a scalarization loop as 'var' might be a nonscalar. Without the patch, that got translated as: D.1234 = &comp_types_vtable._callback ... cb (&(*D.4060)[S.3 + D.4071], &D.1234); where 'D.1234' is function_type. With the patch, it remains a pointer; i.e. D.1234 = comp... and 'cb (..., D.1234)', avoiding ME ICE. Note: Fortran (F2018, C15100) requires that dummy arguments are dummy data objects, which rules out dummy procs/proc-pointer dummies, which is enforced in resolve_fl_procedure. Thus, this change only affects the internally generated code. gcc/fortran/ChangeLog: * trans-array.cc (gfc_scalar_elemental_arg_saved_as_reference): Return true for attr.proc_pointer expressions. gcc/testsuite/ChangeLog: * gfortran.dg/finalize_38b.f90: Compile with -Ofast.
2023-05-16Fortran: Fix finalization resolution with deep copy (cont)Tobias Burnus6-13/+192
gcc/fortran/ChangeLog: * resolve.cc (gfc_resolve_finalizers): Remove gfc_resolve_finalizers calls, use gfc_is_finalizable. (resolve_fl_derived): Resolve derived-type components first. gcc/testsuite/ChangeLog: * gfortran.dg/abstract_type_6.f03: Remove dg-error as now hidden by other errors; copy to ... * gfortran.dg/abstract_type_6a.f03: ... here; remove some error to diagnose the error. * gfortran.dg/finalize_39a.f90: New test.
2023-05-16Fortran: Fix finalization resolution with deep copyTobias Burnus4-3/+151
Follow-up patch to "Fortran/OpenMP: Support mapping of DT with allocatable components" https://gcc.gnu.org/pipermail/gcc-patches/2022-March/591144.html gcc/fortran/ChangeLog: * resolve.cc (gfc_resolve_finalizers): Also resolve allocatable comps. gcc/testsuite/ChangeLog: * gfortran.dg/finalize_38b.f90: New test.
2023-05-16openmp: -foffload-memory=pinnedAndrew Stubbs5-0/+107
Implement the -foffload-memory=pinned option such that libgomp is instructed to enable fully-pinned memory at start-up. The option is intended to provide a performance boost to certain offload programs without modifying the code. This feature only works on Linux, at present, and simply calls mlockall to enable always-on memory pinning. It requires that the ulimit feature is set high enough to accommodate all the program's memory usage. In this mode the ompx_pinned_memory_alloc feature is disabled as it is not needed and may conflict. gcc/ChangeLog: * omp-builtins.def (BUILT_IN_GOMP_ENABLE_PINNED_MODE): New. * omp-low.cc (omp_enable_pinned_mode): New function. (execute_lower_omp): Call omp_enable_pinned_mode. libgomp/ChangeLog: * config/linux/allocator.c (always_pinned_mode): New variable. (GOMP_enable_pinned_mode): New function. (linux_memspace_alloc): Disable pinning when always_pinned_mode set. (linux_memspace_calloc): Likewise. (linux_memspace_free): Likewise. (linux_memspace_realloc): Likewise. * libgomp.map: Add GOMP_enable_pinned_mode. * testsuite/libgomp.c/alloc-pinned-7.c: New test. gcc/testsuite/ChangeLog: * c-c++-common/gomp/alloc-pinned-1.c: New test.
2023-05-16openmp: Use libgomp memory allocation functions with unified shared memory.Hafiz Abid Qadeer12-0/+413
This patches changes calls to malloc/free/calloc/realloc and operator new to memory allocation functions in libgomp with allocator=ompx_unified_shared_mem_alloc. This helps existing code to benefit from the unified shared memory. The libgomp does the correct thing with all the mapping constructs and there is no memory copies if the pointer is pointing to unified shared memory. We only replace replacable new operator and not the class member or placement new. gcc/ChangeLog: * omp-low.cc (usm_transform): New function. (make_pass_usm_transform): Likewise. (class pass_usm_transform): New. * passes.def: Add pass_usm_transform. * tree-pass.h (make_pass_usm_transform): New declaration. gcc/testsuite/ChangeLog: * c-c++-common/gomp/usm-2.c: New test. * c-c++-common/gomp/usm-3.c: New test. * g++.dg/gomp/usm-1.C: New test. * g++.dg/gomp/usm-2.C: New test. * g++.dg/gomp/usm-3.C: New test. * gfortran.dg/gomp/usm-2.f90: New test. * gfortran.dg/gomp/usm-3.f90: New test. libgomp/ChangeLog: * testsuite/libgomp.c/usm-6.c: New test. * testsuite/libgomp.c++/usm-1.C: Likewise. co-authored-by: Andrew Stubbs <ams@codesourcery.com>
2023-05-16openmp: allow requires unified_shared_memoryAndrew Stubbs11-4/+94
This is the front-end portion of the Unified Shared Memory implementation. It removes the "sorry, unimplemented message" in C, C++, and Fortran, and sets flag_offload_memory, but is otherwise inactive, for now. It also checks that -foffload-memory isn't set to an incompatible mode. gcc/c/ChangeLog: * c-parser.cc (c_parser_omp_requires): Allow "requires unified_share_memory" and "unified_address". gcc/cp/ChangeLog: * parser.cc (cp_parser_omp_requires): Allow "requires unified_share_memory" and "unified_address". gcc/fortran/ChangeLog: * openmp.cc (gfc_match_omp_requires): Allow "requires unified_share_memory" and "unified_address". gcc/testsuite/ChangeLog: * c-c++-common/gomp/usm-1.c: New test. * c-c++-common/gomp/usm-4.c: New test. * gfortran.dg/gomp/usm-1.f90: New test. * gfortran.dg/gomp/usm-4.f90: New test.
2023-05-16openmp: Add -foffload-memoryAndrew Stubbs4-1/+44
Add a new option. It's inactive until I add some follow-up patches. gcc/ChangeLog: * common.opt: Add -foffload-memory and its enum values. * coretypes.h (enum offload_memory): New. * doc/invoke.texi: Document -foffload-memory.
2023-05-16Lower allocate directive (OpenMP 5.0).Hafiz Abid Qadeer6-0/+190
This patch looks for malloc/free calls that were generated by allocate statement that is associated with allocate directive and replaces them with GOMP_alloc and GOMP_free. gcc/ChangeLog: * omp-low.cc (scan_sharing_clauses): Handle OMP_CLAUSE_ALLOCATOR. (scan_omp_allocate): New. (scan_omp_1_stmt): Call it. (lower_omp_allocate): New function. (lower_omp_1): Call it. gcc/testsuite/ChangeLog: * gfortran.dg/gomp/allocate-6.f90: Add tests. * gfortran.dg/gomp/allocate-7.f90: New test. * gfortran.dg/gomp/allocate-8.f90: New test. libgomp/ChangeLog: * testsuite/libgomp.fortran/allocate-2.f90: New test.
2023-05-16Gimplify allocate directive (OpenMP 5.0).Hafiz Abid Qadeer10-3/+198
gcc/ChangeLog: * doc/gimple.texi: Describe GIMPLE_OMP_ALLOCATE. * gimple-pretty-print.cc (dump_gimple_omp_allocate): New function. (pp_gimple_stmt_1): Call it. * gimple.cc (gimple_build_omp_allocate): New function. * gimple.def (GIMPLE_OMP_ALLOCATE): New node. * gimple.h (enum gf_mask): Add GF_OMP_ALLOCATE_KIND_MASK, GF_OMP_ALLOCATE_KIND_ALLOCATE and GF_OMP_ALLOCATE_KIND_FREE. (struct gomp_allocate): New. (is_a_helper <gomp_allocate *>::test): New. (is_a_helper <const gomp_allocate *>::test): New. (gimple_build_omp_allocate): Declare. (gimple_omp_allocate_set_clauses): New. (gimple_omp_allocate_set_kind): Likewise. (gimple_omp_allocate_clauses): Likewise. (gimple_omp_allocate_kind): Likewise. (CASE_GIMPLE_OMP): Add GIMPLE_OMP_ALLOCATE. * gimplify.cc (gimplify_omp_allocate): New. (gimplify_expr): Call it. * gsstruct.def (GSS_OMP_ALLOCATE): Define. gcc/testsuite/ChangeLog: * gfortran.dg/gomp/allocate-6.f90: Add tests.
2023-05-16Handle cleanup of omp allocated variables (OpenMP 5.0).Hafiz Abid Qadeer11-1/+97
Currently we are only handling omp allocate directive that is associated with an allocate statement. This statement results in malloc and free calls. The malloc calls are easy to get to as they are in the same block as allocate directive. But the free calls come in a separate cleanup block. To help any later passes finding them, an allocate directive is generated in the cleanup block with kind=free. The normal allocate directive is given kind=allocate. gcc/fortran/ChangeLog: * gfortran.h (struct access_ref): Declare new members omp_allocated and omp_allocated_end. * openmp.cc (gfc_match_omp_allocate): Set new_st.resolved_sym to NULL. (prepare_omp_allocated_var_list_for_cleanup): New function. (gfc_resolve_omp_allocate): Call it. * trans-decl.cc (gfc_trans_deferred_vars): Process omp_allocated. * trans-openmp.cc (gfc_trans_omp_allocate): Set kind for the stmt generated for allocate directive. gcc/ChangeLog: * tree-core.h (struct tree_base): Add comments. * tree-pretty-print.cc (dump_generic_node): Handle allocate directive kind. * tree.h (OMP_ALLOCATE_KIND_ALLOCATE): New define. (OMP_ALLOCATE_KIND_FREE): Likewise. gcc/testsuite/ChangeLog: * gfortran.dg/gomp/allocate-6.f90: Test kind of allocate directive.
2023-05-16Translate allocate directive (OpenMP 5.0).Hafiz Abid Qadeer10-0/+174
gcc/fortran/ChangeLog: * trans-openmp.cc (gfc_trans_omp_clauses): Handle OMP_LIST_ALLOCATOR. (gfc_trans_omp_allocate): New function. (gfc_trans_omp_directive): Handle EXEC_OMP_ALLOCATE. gcc/ChangeLog: * tree-pretty-print.cc (dump_omp_clause): Handle OMP_CLAUSE_ALLOCATOR. (dump_generic_node): Handle OMP_ALLOCATE. * tree.def (OMP_ALLOCATE): New. * tree.h (OMP_ALLOCATE_CLAUSES): Likewise. (OMP_ALLOCATE_DECL): Likewise. (OMP_ALLOCATE_ALLOCATOR): Likewise. * tree.cc (omp_clause_num_ops): Add entry for OMP_CLAUSE_ALLOCATOR. gcc/testsuite/ChangeLog: * gfortran.dg/gomp/allocate-6.f90: New test.
2023-05-16Add parsing support for allocate directive (OpenMP 5.0)Hafiz Abid Qadeer11-6/+425
Currently we only make use of this directive when it is associated with an allocate statement. gcc/fortran/ChangeLog: * dump-parse-tree.cc (show_omp_node): Handle EXEC_OMP_ALLOCATE. (show_code_node): Likewise. * gfortran.h (enum gfc_statement): Add ST_OMP_ALLOCATE. (OMP_LIST_ALLOCATOR): New enum value. (enum gfc_exec_op): Add EXEC_OMP_ALLOCATE. * match.h (gfc_match_omp_allocate): New function. * openmp.cc (enum omp_mask1): Add OMP_CLAUSE_ALLOCATOR. (OMP_ALLOCATE_CLAUSES): New define. (gfc_match_omp_allocate): New function. (resolve_omp_clauses): Add ALLOCATOR in clause_names. (omp_code_to_statement): Handle EXEC_OMP_ALLOCATE. (EMPTY_VAR_LIST): New define. (check_allocate_directive_restrictions): New function. (gfc_resolve_omp_allocate): Likewise. (gfc_resolve_omp_directive): Handle EXEC_OMP_ALLOCATE. * parse.cc (decode_omp_directive): Handle ST_OMP_ALLOCATE. (next_statement): Likewise. (gfc_ascii_statement): Likewise. * resolve.cc (gfc_resolve_code): Handle EXEC_OMP_ALLOCATE. * st.cc (gfc_free_statement): Likewise. * trans.cc (trans_code): Likewise
2023-05-16Fortran/OpenMP: Support mapping of DT with allocatable componentsTobias Burnus24-136/+2527
gcc/fortran/ChangeLog: * class.cc (finalization_scalarizer): Mark syms as artificial. (generate_callback_wrapper): New. (gfc_find_derived_vtab): Call it, add _callback comp. * f95-lang.cc (LANG_HOOKS_OMP_DEEP_MAPPING, LANG_HOOKS_OMP_DEEP_MAPPING_P, LANG_HOOKS_OMP_DEEP_MAPPING_CNT): Redeinfe * gfortran.h (gfc_import_iso_c_binding_module, GFC_CLASS_CALLBACK_DEFAULT_FLAG, GFC_CLASS_CALLBACK_VTABLE_FLAG, GFC_CLASS_CB_ALLOCATABLE, GFC_CLASS_CB_POINTER, GFC_CLASS_CB_PROC_POINTER, GFC_CLASS_CB_VTABLE, GFC_CLASS_CB_VPTR): New. * match.cc (select_type_set_tmp): Propagate allocatable property. * module.cc (MOD_VERSION): Bump due to vtab change. (import_iso_c_binding_module): New import_all arg. (gfc_import_iso_c_binding_module): New. (gfc_use_module): Update call. * openmp.cc (resolve_omp_clauses): Accept DT with alloc comps. * resolve.cc (gfc_resolve_formal_arglist, gfc_resolve_intrinsic, resolve_fl_procedure, resolve_types): Permit some violations for internal code. * trans-array.cc (gfc_conv_descriptor_stride_get, gfc_tree_array_size, gfc_full_array_size): Update for GFC_TYPE_ARRAY_AKIND change. (gfc_conv_expr_descriptor): Likewise; permit calling with tree code. * trans-expr.cc (VTABLE_CALLBACK_FIELD): Add. (VTAB_GET_FIELD_GEN): Use it. (VTABLE_DEALLOCATE_FIELD): Undef at the end. (gfc_conv_expr_reference): Fixes; avoid unneccessary temp var. * trans-intrinsic.cc (gfc_conv_intrinsic_sizeof, gfc_conv_associated): Fix class and comp-ref handling. (conv_isocbinding_function): Remove buggy code. * trans-openmp.cc (gfc_has_alloc_comps): Add ptr_ok arg. (gfc_omp_private_outer_ref, gfc_walk_alloc_comps, gfc_omp_clause_default_ctor, gfc_omp_clause_copy_ctor, gfc_omp_clause_assign_op, gfc_omp_clause_dtor, (gfc_omp_finish_clause): Update call. (GFC_MAP_TOKEN_DATA, GFC_MAP_TOKEN_SIZES, GFC_MAP_TOKEN_KINDS, GFC_MAP_TOKEN_DATA_OFFSET, GFC_MAP_TOKEN_OFFSET, GFC_MAP_TOKEN_FLAGS, GFC_MAP_TOKEN_DETACH): Define. (gfc_omp_get_token_data, gfc_omp_get_token_sizes, gfc_omp_get_token_kinds, gfc_omp_get_token_offset_data, gfc_omp_get_token_offset, gfc_omp_get_token_flags, gfc_omp_get_token_detach, gfc_omp_get_map_token_type, gfc_omp_get_cb_type, gfc_omp_gen_deep_map_fn, gfc_omp_deep_mapping_map, gfc_omp_deep_mapping_item, gfc_omp_deep_mapping_comps, gfc_omp_gen_simple_loop, gfc_omp_get_array_size, gfc_omp_elmental_loop, gfc_omp_deep_map_kind_p, gfc_omp_deep_mapping_int_p, gfc_omp_deep_mapping_p, gfc_omp_deep_mapping_do), gfc_omp_deep_mapping_cnt, gfc_omp_deep_mapping): New. (gfc_trans_omp_array_section): Save clause decl to survive gimplifying. (gfc_trans_omp_clauses): Likewise; fixes. * trans-types.cc (gfc_build_array_type, gfc_get_derived_type, gfc_get_array_descr_info): Update array kind to distinguish different assumed-rank arrays. * trans.h (gfc_class_vtab_callback_get, gfc_omp_deep_mapping_p, gfc_omp_deep_mapping_cnt, gfc_omp_deep_mapping): New prototypes. (enum gfc_array_kind): Additional GFC_ARRAY_ASSUMED_RANK_* entries. gcc/ChangeLog: * langhooks-def.h (lhd_omp_deep_mapping_p, lhd_omp_deep_mapping_cnt, lhd_omp_deep_mapping): New. (LANG_HOOKS_OMP_DEEP_MAPPING_P, LANG_HOOKS_OMP_DEEP_MAPPING_CNT, LANG_HOOKS_OMP_DEEP_MAPPING): Define. (LANG_HOOKS_DECLS): Use it. * langhooks.cc (lhd_omp_deep_mapping_p, lhd_omp_deep_mapping_cnt, lhd_omp_deep_mapping): New stubs. * langhooks.h (struct lang_hooks_for_decls): Add new hooks * omp-expand.cc (expand_omp_target): Handle dynamic-size addr/sizes/kinds arrays. * omp-low.cc (build_sender_ref, fixup_child_record_type, scan_sharing_clauses, lower_omp_target): Update to handle new hooks and dynamic-size addr/sizes/kinds arrays. libgomp/ChangeLog: * testsuite/libgomp.fortran/allocatable-comp.f90: New test. * testsuite/libgomp.fortran/map-alloc-comp-3.f90: New test. * testsuite/libgomp.fortran/map-alloc-comp-4.f90: New test. * testsuite/libgomp.fortran/map-alloc-comp-5.f90: New test. * testsuite/libgomp.fortran/map-alloc-comp-6.f90: New test. * testsuite/libgomp.fortran/map-alloc-comp-7.f90: New test. gcc/testsuite/ChangeLog: * gfortran.dg/c_loc_test_22.f90: Update scan-tree. * gfortran.dg/finalize_21.f90: Likewise. * gfortran.dg/gomp/map-alloc-comp-1.f90: Remove sorry dg-error.
2023-05-16openmp: Handle C/C++ array reference base-pointers in array sectionsChung-Lin Tang6-3/+69
In cases where a program constructs its own deep-copying for arrays-of-pointers, e.g: #pragma omp target enter data map(to:level->vectors[:N]) for (i = 0; i < N; i++) #pragma omp target enter data map(to:level->vectors[i][:N]) We need to treat the part of the array reference before the array section as a base-pointer (here 'level->vectors[i]'), providing pointer-attachment behavior. This patch adds this inside handle_omp_array_sections(), tracing the whole sequence of array dimensions, creating a whole base-pointer reference iteratively using build_array_ref(). The conditions are that each of the "absorbed" dimensions must be length==1, and the final reference must be of pointer-type (so that pointer attachment makes sense). Merged from: https://gcc.gnu.org/pipermail/gcc-patches/2022-February/590658.html 2022-02-24 Chung-Lin Tang <cltang@codesourcery.com> gcc/c/ChangeLog: * c-typeck.cc (handle_omp_array_sections): Add handling for creating array-reference base-pointer attachment clause. gcc/cp/ChangeLog: * semantics.cc (handle_omp_array_sections): Add handling for creating array-reference base-pointer attachment clause. gcc/testsuite/ChangeLog: * c-c++-common/gomp/target-enter-data-1.c: Adjust testcase. libgomp/ChangeLog: * testsuite/libgomp.c-c++-common/ptr-attach-2.c: New test.
2023-05-16openmp: Improve handling of nested OpenMP metadirectives in C and C++Kwok Cheung Yeung6-42/+78
This patch fixes a misparsing issue when encountering code like: #pragma omp metadirective when {<selector_set>={...}: A) #pragma omp metadirective when (<selector_set>={...}: B) When called for the first metadirective, analyze_metadirective_body would stop just before the colon in the second metadirective because it naively assumes that the '}' marks the end of a code block. The assertion for clauses to end parsing at the same point is now disabled if a parse error has occurred during the parsing of the clause, since some tokens may not be consumed if a parse error cuts parsing short. 2022-02-18 Kwok Cheung Yeung <kcy@codesourcery.com> gcc/c/ * c-parser.cc (c_parser_omp_construct): Move handling of PRAGMA_OMP_METADIRECTIVE from here... (c_parser_pragma): ...to here. (analyze_metadirective_body): Check that the bracket nesting level is also zero before stopping the adding of tokens on encountering a close brace. (c_parser_omp_metadirective): Modify function signature and update. Do not assert on remaining tokens if there has been a parse error. gcc/cp/ * parser.cc (cp_parser_omp_construct): Move handling of PRAGMA_OMP_METADIRECTIVE from here... (cp_parser_pragma): ...to here. (analyze_metadirective_body): Check that the bracket nesting level is also zero before stopping the adding of tokens on encountering a close brace. (cp_parser_omp_metadirective): Modify function signature and update. Do not assert on remaining tokens if there has been a parse error. gcc/testsuite/ * c-c++-common/gomp/metadirective-1.c (f): Add test for improperly nested metadirectives.
2023-05-16openmp: Eliminate non-matching metadirective variants early in Fortran front-endKwok Cheung Yeung7-14/+93
This patch checks during parsing if a metadirective selector is both resolvable and non-matching - if so, it is removed from further consideration. This is both more efficient, and avoids spurious syntax errors caused by considering combinations of selectors that lead to invalid combinations of OpenMP directives, when that combination would never arise in the first place. This exposes another bug - when metadirectives that are not of the begin-end variety are nested, we might have to drill up through multiple layers of the state stack to reach the state for the next statement. This is now fixed. 2022-02-11 Kwok Cheung Yeung <kcy@codesourcery.com> gcc/fortran/ * decl.cc (gfc_match_end): Search for first previous state that is not COMP_OMP_METADIRECTIVE. * gfortran.h (gfc_skip_omp_metadirective_clause): Add prototype. * openmp.cc (match_omp_metadirective): Skip clause if result of gfc_skip_omp_metadirective_clause is true. * trans-openmp.cc (gfc_trans_omp_set_selector): Add argument and disable expression conversion if false. (gfc_skip_omp_metadirective_clause): New. gcc/testsuite/ * gfortran.dg/gomp/metadirective-8.f90: New.
2023-05-16openmp: Add warning when functions containing metadirectives with ↵Kwok Cheung Yeung8-2/+77
'construct={target}' called directly void f(void) { #pragma omp metadirective \ when (construct={target}: A) \ default (B) ... } ... { #pragma omp target f(); // Target call f(); // Local call } With the OpenMP 5.0/5.1 specifications, we would expect A to be selected in the metadirective when the target call is made, but B when f is called directly outside of a target context. However, since GCC does not have separate copies of f for local and target calls, and the construct selector is static, it must be resolved one way or the other at compile-time (currently in the favour of selecting A), which may be unexpected behaviour. This patch attempts to detect the above situation, and will emit a warning if found. 2022-01-28 Kwok Cheung Yeung <kcy@codesourcery.com> gcc/ * gimplify.cc (gimplify_omp_metadirective): Mark offloadable functions containing metadirectives with 'construct={target}' in the selector. * omp-general.cc (omp_has_target_constructor_p): New. * omp-general.h (omp_has_target_constructor_p): New prototype. * omp-low.cc (lower_omp_1): Emit warning if marked functions called outside of a target context. gcc/testsuite/ * c-c++-common/gomp/metadirective-4.c (main): Add expected warning. * gfortran.dg/gomp/metadirective-4.f90 (test): Likewise. libgomp/ * testsuite/libgomp.c-c++-common/metadirective-2.c (main): Add expected warning. * testsuite/libgomp.fortran/metadirective-2.f90 (test): Likewise.
2023-05-16openmp: Add support for 'target_device' context selector setKwok Cheung Yeung14-16/+260
2022-01-25 Kwok Cheung Yeung <kcy@codesourcery.com> gcc/ * builtin-types.def (BT_FN_BOOL_INT_CONST_PTR_CONST_PTR_CONST_PTR): New type. * omp-builtins.def (BUILT_IN_GOMP_EVALUATE_TARGET_DEVICE): New builtin. * omp-general.cc (omp_context_selector_matches): Handle 'target_device' selector set. (omp_dynamic_cond): Generate expression tree for 'target_device' selector set. (omp_context_compute_score): Handle selectors in 'target_device' set. gcc/c/ * c-parser.cc (omp_target_device_selectors): New. (c_parser_omp_context_selector): Accept 'target_device' selector set. Treat 'device_num' selector as expression. (c_parser_omp_context_selector_specification): Handle 'target_device' selector set. gcc/cp/ * parser.cc (omp_target_device_selectors): New. (cp_parser_omp_context_selector): Accept 'target_device' selector set. Treat 'device_num' selector as expression. (cp_parser_omp_context_selector_specification): Handle 'target_device' selector set. gcc/fortran/ * openmp.cc (omp_target_device_selectors): New. (gfc_match_omp_context_selector): Accept 'target_device' selector set. Treat 'device_num' selector as expression. (gfc_match_omp_context_selector_specification): Handle 'target_device' selector set. * types.def (BT_FN_BOOL_INT_CONST_PTR_CONST_PTR_CONST_PTR): New type. gcc/testsuite/ * c-c++-common/gomp/metadirective-7.c: New. * gfortran.dg/gomp/metadirective-7.f90: New. libgomp/ * Makefile.am (libgomp_la_SOURCES): Add selector.c. * Makefile.am: Regenerate. * config/gcn/selector.c: New. * config/linux/selector.c: New. * config/linux/x86/selector.c: New. * config/nvptx/selector.c: New. * libgomp-plugin.h (GOMP_OFFLOAD_evaluate_device): New. * libgomp.h (struct gomp_device_descr): Add evaluate_device_func field. * libgomp.map (GOMP_5.1): Add GOMP_evaluate_target_device. * libgomp_g.h (GOMP_evaluate_current_device): New. (GOMP_evaluate_target_device): New. * oacc-host.c (host_evaluate_device): New. (host_openacc_exec): Initialize evaluate_device_func field to host_evaluate_device. * plugin/plugin-gcn.c (GOMP_OFFLOAD_evaluate_device): New. * plugin/plugin-nvptx.c (struct ptx_device): Add compute_major and compute_minor fields. (nvptx_open_device): Read compute capability information from device. (CHECK_ISA): New macro. (GOMP_OFFLOAD_evaluate_device): New. * selector.c: New. * target.c (GOMP_evaluate_target_device): New. (gomp_load_plugin_for_device): Load evaulate_device plugin function. * testsuite/libgomp.c-c++-common/metadirective-5.c: New testcase. * testsuite/libgomp.fortran/metadirective-5.f90: New testcase.
2023-05-16openmp: Add testcases for metadirectivesKwok Cheung Yeung14-0/+497
2022-01-25 Kwok Cheung Yeung <kcy@codesourcery.com> gcc/testsuite/ * c-c++-common/gomp/metadirective-1.c: New. * c-c++-common/gomp/metadirective-2.c: New. * c-c++-common/gomp/metadirective-3.c: New. * c-c++-common/gomp/metadirective-4.c: New. * c-c++-common/gomp/metadirective-5.c: New. * c-c++-common/gomp/metadirective-6.c: New. * gcc.dg/gomp/metadirective-1.c: New. * gfortran.dg/gomp/metadirective-1.f90: New. * gfortran.dg/gomp/metadirective-2.f90: New. * gfortran.dg/gomp/metadirective-3.f90: New. * gfortran.dg/gomp/metadirective-4.f90: New. * gfortran.dg/gomp/metadirective-5.f90: New. * gfortran.dg/gomp/metadirective-6.f90: New. libgomp/ * testsuite/libgomp.c-c++-common/metadirective-1.c: New. * testsuite/libgomp.c-c++-common/metadirective-2.c: New. * testsuite/libgomp.c-c++-common/metadirective-3.c: New. * testsuite/libgomp.c-c++-common/metadirective-4.c: New. * testsuite/libgomp.fortran/metadirective-1.f90: New. * testsuite/libgomp.fortran/metadirective-2.f90: New. * testsuite/libgomp.fortran/metadirective-3.f90: New. * testsuite/libgomp.fortran/metadirective-4.f90: New.
2023-05-16openmp, fortran: Add Fortran support for parsing metadirectivesKwok Cheung Yeung18-322/+831
This adds support for parsing OpenMP metadirectives in the Fortran front end. 2022-01-25 Kwok Cheung Yeung <kcy@codesourcery.com> gcc/ * omp-general.cc (omp_check_context_selector): Revert string length check. (omp_context_name_list_prop): Likewise. gcc/fortran/ * decl.cc (gfc_match_end): Handle COMP_OMP_METADIRECTIVE and COMP_OMP_BEGIN_METADIRECTIVE. * dump-parse-tree.cc (show_omp_node): Handle EXEC_OMP_METADIRECTIVE. (show_code_node): Handle EXEC_OMP_METADIRECTIVE. * gfortran.h (enum gfc_statement): Add ST_OMP_METADIRECTIVE, ST_OMP_BEGIN_METADIRECTIVE and ST_OMP_END_METADIRECTIVE. (struct gfc_omp_metadirective_clause): New structure. (gfc_get_omp_metadirective_clause): New macro. (struct gfc_st_label): Add omp_region field. (enum gfc_exec_op): Add EXEC_OMP_METADIRECTIVE. (struct gfc_code): Add omp_metadirective_clauses field. (gfc_free_omp_metadirective_clauses): New prototype. (match_omp_directive): New prototype. (is_omp_declarative_stmt): New prototype. * io.cc (format_asterisk): Initialize omp_region field. * match.h (gfc_match_omp_begin_metadirective): New prototype. (gfc_match_omp_metadirective): New prototype. * openmp.cc (gfc_match_omp_eos): Match ')' in context selectors. (gfc_free_omp_metadirective_clauses): New. (gfc_match_omp_clauses): Remove context_selector argument. Rely on gfc_match_omp_eos to match end of clauses. (match_omp): Remove extra argument to gfc_match_omp_clauses. (gfc_match_omp_context_selector): Remove extra argument to gfc_match_omp_clauses. Set gfc_matching_omp_context_selector before call to gfc_match_omp_clauses and reset after. (gfc_match_omp_context_selector_specification): Modify to take a gfc_omp_set_selector** argument. (gfc_match_omp_declare_variant): Pass set_selectors to gfc_match_omp_context_selector_specification. (match_omp_metadirective): New. (gfc_match_omp_begin_metadirective): New. (gfc_match_omp_metadirective): New. (resolve_omp_metadirective): New. (gfc_resolve_omp_directive): Handle EXEC_OMP_METADIRECTIVE. * parse.cc (gfc_matching_omp_context_selector): New variable. (gfc_in_metadirective_body): New variable. (gfc_omp_region_count): New variable. (decode_omp_directive): Match 'begin metadirective', 'end metadirective' and 'metadirective'. (match_omp_directive): New. (case_omp_structured_block): New. (case_omp_do): New. (gfc_ascii_statement): Handle metadirective statements. (gfc_omp_end_stmt): New. (parse_omp_do): Delegate to gfc_omp_end_stmt. (parse_omp_structured_block): Delegate to gfc_omp_end_stmt. Handle ST_OMP_END_METADIRECTIVE. (parse_omp_metadirective_body): New. (parse_executable): Delegate to case_omp_structured_block and case_omp_do. Return after one statement if compiling regular metadirective. Handle metadirective statements. (gfc_parse_file): Reset gfc_omp_region_count, gfc_in_metadirective_body and gfc_matching_omp_context_selector. (is_omp_declarative_stmt): New. * parse.h (enum gfc_compile_state): Add COMP_OMP_METADIRECTIVE and COMP_OMP_BEGIN_METADIRECTIVE. (gfc_omp_end_stmt): New prototype. (gfc_matching_omp_context_selector): New declaration. (gfc_in_metadirective_body): New declaration. (gfc_omp_region_count): New declaration. (is_omp_declarative_stmt): New. * resolve.cc (gfc_resolve_code): Handle EXEC_OMP_METADIRECTIVE. * st.cc (gfc_free_statement): Handle EXEC_OMP_METADIRECTIVE. * symbol.cc (compare_st_labels): Take omp_region into account. (gfc_get_st_labels): Incorporate omp_region into label. * trans-decl.cc (gfc_get_label_decl): Add omp_region into translated label name. * trans-openmp.cc (gfc_trans_omp_directive): Handle EXEC_OMP_METADIRECTIVE. (gfc_trans_omp_set_selector): Hoist code from... (gfc_trans_omp_declare_variant): ...here. (gfc_trans_omp_metadirective): New. * trans-stmt.h (gfc_trans_omp_metadirective): New prototype. * trans.cc (trans_code): Handle EXEC_OMP_METADIRECTIVE.
2023-05-16openmp: Add C++ support for parsing metadirectivesKwok Cheung Yeung2-9/+423
This adds support for parsing OpenMP metadirectives in the C++ front end. 2022-01-25 Kwok Cheung Yeung <kcy@codesourcery.com> gcc/cp/ * parser.cc (cp_parser_skip_to_end_of_block_or_statement): Handle parentheses. (cp_parser_omp_context_selector): Add extra argument. Allow non-constant expressions. (cp_parser_omp_context_selector_specification): Add extra argument and propagate to cp_parser_omp_context_selector. (analyze_metadirective_body): New. (cp_parser_omp_metadirective): New. (cp_parser_omp_construct): Handle PRAGMA_OMP_METADIRECTIVE. (cp_parser_pragma): Handle PRAGMA_OMP_METADIRECTIVE.
2023-05-16openmp: Add support for streaming metadirectives and resolving them after LTOKwok Cheung Yeung7-0/+220
This patch adds support for streaming metadirective Gimple statements during LTO, and adds a metadirective expansion pass that runs after LTO. This is required for metadirectives with selectors that can only be resolved from within the accel compiler. 2022-01-25 Kwok Cheung Yeung <kcy@codesourcery.com> gcc/ * Makefile.in (OBJS): Add omp-expand-metadirective.o. * gimple-streamer-in.cc (input_gimple_stmt): Add case for GIMPLE_OMP_METADIRECTIVE. Handle metadirective labels. * gimple-streamer-out.cc (output_gimple_stmt): Likewise. * omp-expand-metadirective.cc: New. * passes.def: Add pass_omp_expand_metadirective. * tree-pass.h (make_pass_omp_expand_metadirective): New prototype.
2023-05-16openmp: Add support for resolving metadirectives during parsing and ↵Kwok Cheung Yeung6-10/+372
Gimplification This adds support for resolving metadirectives according to the OpenMP 5.1 specification. The variants are sorted by score, then gathered into a list of dynamic replacement candidates. The metadirective is then expanded into a sequence of 'if..else' statements to test the dynamic selector and execute the variant if the selector is satisfied. If any of the selectors in the list are unresolvable, GCC will give up on resolving the metadirective and try again later. 2022-01-25 Kwok Cheung Yeung <kcy@codesourcery.com> gcc/ * gimplify.cc (expand_omp_metadirective): New. * omp-general.cc: Include tree-pretty-print.h. (DELAY_METADIRECTIVES_AFTER_LTO): New macro. (omp_context_selector_matches): Delay resolution of selectors. Allow non-constant expressions. (omp_dynamic_cond): New. (omp_dynamic_selector_p): New. (sort_variant): New. (omp_get_dynamic_candidates): New. (omp_resolve_metadirective): New. (omp_resolve_metadirective): New. * omp-general.h (struct omp_metadirective_variant): New. (omp_resolve_metadirective): New prototype. gcc/c-family/ * c-omp.cc (c_omp_expand_metadirective_r): New. (c_omp_expand_metadirective): New.
2023-05-16openmp: Add middle-end support for metadirectivesKwok Cheung Yeung15-1/+631
This adds a new Gimple statement type GIMPLE_OMP_METADIRECTIVE, which represents the metadirective in Gimple. In high Gimple, the statement contains the body of the directive variants, whereas in low Gimple, it only contains labels to the bodies. This patch adds support for converting metadirectives from tree to Gimple form, and handling of the Gimple form (Gimple lowering, OpenMP lowering and expansion, inlining, SSA handling etc). Metadirectives should be resolved before they reach the back-end, otherwise the compiler will crash as GCC does not know how to convert metadirective Gimple statements to RTX. 2022-01-25 Kwok Cheung Yeung <kcy@codesourcery.com> gcc/ * gimple-low.cc (lower_omp_metadirective): New. (lower_stmt): Handle GIMPLE_OMP_METADIRECTIVE. * gimple-pretty-print.cc (dump_gimple_omp_metadirective): New. (pp_gimple_stmt_1): Handle GIMPLE_OMP_METADIRECTIVE. * gimple-walk.cc (walk_gimple_op): Handle GIMPLE_OMP_METADIRECTIVE. (walk_gimple_stmt): Likewise. * gimple.cc (gimple_alloc_omp_metadirective): New. (gimple_build_omp_metadirective): New. (gimple_build_omp_metadirective_variant): New. * gimple.def (GIMPLE_OMP_METADIRECTIVE): New. (GIMPLE_OMP_METADIRECTIVE_VARIANT): New. * gimple.h (gomp_metadirective_variant): New. (gomp_metadirective): New. (is_a_helper <gomp_metadirective *>::test): New. (is_a_helper <gomp_metadirective_variant *>::test): New. (is_a_helper <const gomp_metadirective *>::test): New. (is_a_helper <const gomp_metadirective_variant *>::test): New. (gimple_alloc_omp_metadirective): New prototype. (gimple_build_omp_metadirective): New prototype. (gimple_build_omp_metadirective_variant): New prototype. (gimple_has_substatements): Add GIMPLE_OMP_METADIRECTIVE case. (gimple_has_ops): Add GIMPLE_OMP_METADIRECTIVE. (gimple_omp_metadirective_label): New. (gimple_omp_metadirective_set_label): New. (gimple_omp_metadirective_variants): New. (gimple_omp_metadirective_set_variants): New. (CASE_GIMPLE_OMP): Add GIMPLE_OMP_METADIRECTIVE. * gimplify.cc (is_gimple_stmt): Add OMP_METADIRECTIVE. (expand_omp_metadirective): New. (gimplify_omp_metadirective): New. (gimplify_expr): Add case for OMP_METADIRECTIVE. * gsstruct.def (GSS_OMP_METADIRECTIVE): New. (GSS_OMP_METADIRECTIVE_VARIANT): New. * omp-expand.cc (build_omp_regions_1): Handle GIMPLE_OMP_METADIRECTIVE. (omp_make_gimple_edges): Likewise. * omp-low.cc (struct omp_context): Add next_clone field. (new_omp_context): Initialize next_clone field. (clone_omp_context): New. (delete_omp_context): Delete clone contexts. (scan_omp_metadirective): New. (scan_omp_1_stmt): Handle GIMPLE_OMP_METADIRECTIVE. (lower_omp_metadirective): New. (lower_omp_1): Handle GIMPLE_OMP_METADIRECTIVE. * tree-cfg.cc (cleanup_dead_labels): Handle GIMPLE_OMP_METADIRECTIVE. (gimple_redirect_edge_and_branch): Likewise. * tree-inline.cc (remap_gimple_stmt): Handle GIMPLE_OMP_METADIRECTIVE. (estimate_num_insns): Likewise. * tree-pretty-print.cc (dump_generic_node): Handle OMP_METADIRECTIVE. * tree-ssa-operands.cc (parse_ssa_operands): Handle GIMPLE_OMP_METADIRECTIVE.
2023-05-16openmp: Add C support for parsing metadirectivesKwok Cheung Yeung13-15/+503
This patch implements parsing for the OpenMP metadirective introduced in OpenMP 5.0. Metadirectives are parsed into an OMP_METADIRECTIVE node, with the variant clauses forming a chain accessible via OMP_METADIRECTIVE_CLAUSES. Each clause contains the context selector and tree for the variant. User conditions in the selector are now permitted to be non-constant when used in metadirectives as specified in OpenMP 5.1. 2021-01-25 Kwok Cheung Yeung <kcy@codesourcery.com> gcc/ * omp-general.cc (omp_context_selector_matches): Add extra argument. (omp_resolve_metadirective): New stub function. * omp-general.h (struct omp_metadirective_variant): New. (omp_context_selector_matches): Add extra argument. (omp_resolve_metadirective): New prototype. * tree.def (OMP_METADIRECTIVE): New. * tree.h (OMP_METADIRECTIVE_CLAUSES): New macro. gcc/c/ * c-parser.cc (c_parser_skip_to_end_of_block_or_statement): Handle parentheses in statement. (c_parser_omp_metadirective): New prototype. (c_parser_omp_context_selector): Add extra argument. Allow non-constant expressions. (c_parser_omp_context_selector_specification): Add extra argument and propagate it to c_parser_omp_context_selector. (analyze_metadirective_body): New. (c_parser_omp_metadirective): New. (c_parser_omp_construct): Handle PRAGMA_OMP_METADIRECTIVE. gcc/c-family/ * c-common.h (enum c_omp_directive_kind): Add C_OMP_DIR_META. (c_omp_expand_metadirective): New prototype. * c-gimplify.cc (genericize_omp_metadirective_stmt): New. (c_genericize_control_stmt): Handle OMP_METADIRECTIVE tree nodes. * c-omp.cc (omp_directives): Classify metadirectives as C_OMP_DIR_META. (c_omp_expand_metadirective): New stub function. * c-pragma.cc (omp_pragmas): Add entry for metadirective. * c-pragma.h (enum pragma_kind): Add PRAGMA_OMP_METADIRECTIVE.
2023-05-16RISCV: Inline subword atomic opsPatrick O'Neill13-2/+1840
RISC-V has no support for subword atomic operations; code currently generates libatomic library calls. This patch changes the default behavior to inline subword atomic calls (using the same logic as the existing library call). Behavior can be specified using the -minline-atomics and -mno-inline-atomics command line flags. gcc/libgcc/config/riscv/atomic.c has the same logic implemented in asm. This will need to stay for backwards compatibility and the -mno-inline-atomics flag. 2023-05-03 Patrick O'Neill <patrick@rivosinc.com> gcc/ChangeLog: PR target/104338 * config/riscv/riscv-protos.h: Add helper function stubs. * config/riscv/riscv.cc: Add helper functions for subword masking. * config/riscv/riscv.opt: Add command-line flags -minline-atomics and -mno-inline-atomics. * config/riscv/sync.md: Add masking logic and inline asm for fetch_and_op, fetch_and_nand, CAS, and exchange ops. * doc/invoke.texi: Add blurb regarding new command-line flags -minline-atomics and -mno-inline-atomics. libgcc/ChangeLog: PR target/104338 * config/riscv/atomic.c: Add reference to duplicate logic. gcc/testsuite/ChangeLog: PR target/104338 * gcc.target/riscv/inline-atomics-1.c: New test. * gcc.target/riscv/inline-atomics-2.c: New test. * gcc.target/riscv/inline-atomics-3.c: New test. * gcc.target/riscv/inline-atomics-4.c: New test. * gcc.target/riscv/inline-atomics-5.c: New test. * gcc.target/riscv/inline-atomics-6.c: New test. * gcc.target/riscv/inline-atomics-7.c: New test. * gcc.target/riscv/inline-atomics-8.c: New test. Signed-off-by: Patrick O'Neill <patrick@rivosinc.com> Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
2023-05-16LTO: Fix writing of toplevel asm with offloading [PR109816]Tobias Burnus1-1/+1
When offloading was enabled, top-level 'asm' were added to the offloading section, confusing assemblers which did not support the syntax. Additionally, with offloading and -flto, the top-level assembler code did not end up in the host files. As r14-321-g9a41d2cdbcd added top-level 'asm' to one libstdc++ header file, the issue became more apparent, causing fails with nvptx for some C++ testcases. PR libstdc++/109816 gcc/ChangeLog: * lto-cgraph.cc (output_symtab): Guard lto_output_toplevel_asms by '!lto_stream_offload_p'. libgomp/ChangeLog: * testsuite/libgomp.c++/target-map-class-1.C: New test. * testsuite/libgomp.c++/target-map-class-2.C: New test. (cherry picked from commit a835f046cdf017b9e8ad5576df4f10daaf8420d0)
2023-05-16Daily bump.GCC Administrator2-1/+9
2023-05-15Fix gcc.dg/vect/pr108950.cRichard Biener1-1/+1
The following puts the dg-require-effective-target properly after the dg-do. * gcc.dg/vect/pr108950.c: Re-order dg-require-effective-target and dg-do. (cherry picked from commit 66e268eb063de32b232f6f006048e6f7bae6268f)
2023-05-15Daily bump.GCC Administrator1-1/+1
2023-05-14Daily bump.GCC Administrator1-1/+1
2023-05-13Daily bump.GCC Administrator3-1/+112
2023-05-12openacc: Adjust test expectations to new "kernels" handlingFrederik Harwath53-687/+886
Adjust tests to changed expectations with the new Graphite-based "kernels" handling. libgomp/ChangeLog: * testsuite/libgomp.oacc-c-c++-common/kernels-decompose-1.c: Adjust. * testsuite/libgomp.oacc-c-c++-common/parallel-dims.c: Adjust. * testsuite/libgomp.oacc-c-c++-common/pr84955-1.c: Adjust. * testsuite/libgomp.oacc-c-c++-common/pr85381-2.c: Adjust. * testsuite/libgomp.oacc-c-c++-common/pr85381-3.c: Adjust. * testsuite/libgomp.oacc-c-c++-common/pr85381-4.c: Adjust. * testsuite/libgomp.oacc-c-c++-common/pr85486-2.c: Adjust. * testsuite/libgomp.oacc-c-c++-common/pr85486-3.c: Adjust. * testsuite/libgomp.oacc-c-c++-common/pr85486.c: Adjust. * testsuite/libgomp.oacc-c-c++-common/vector-length-128-1.c: Adjust. * testsuite/libgomp.oacc-c-c++-common/vector-length-128-2.c: Adjust. * testsuite/libgomp.oacc-c-c++-common/vector-length-128-3.c: Adjust. * testsuite/libgomp.oacc-c-c++-common/vector-length-128-4.c: Adjust. * testsuite/libgomp.oacc-c-c++-common/vector-length-128-5.c: Adjust. * testsuite/libgomp.oacc-c-c++-common/vector-length-128-6.c: Adjust. * testsuite/libgomp.oacc-c-c++-common/vector-length-128-7.c: Adjust. * testsuite/libgomp.oacc-fortran/kernels-acc-loop-reduction-2.f90: Adjust. * testsuite/libgomp.oacc-fortran/pr94358-1.f90: Adjust. * testsuite/libgomp.oacc-fortran/parallel-loop-auto-reduction-2.f90: Removed. gcc/testsuite/ChangeLog: * c-c++-common/goacc/acc-icf.c: Adjust. * c-c++-common/goacc/cache-3-1.c: Adjust. * c-c++-common/goacc/classify-kernels-unparallelized-graphite.c: Adjust. * c-c++-common/goacc/classify-kernels.c: Adjust. * c-c++-common/goacc/classify-serial.c: Adjust. * c-c++-common/goacc/if-clause-2.c: Adjust. * c-c++-common/goacc/kernels-decompose-1.c: Adjust. * c-c++-common/goacc/kernels-decompose-2.c: Adjust. * c-c++-common/goacc/kernels-decompose-ice-1.c: Adjust. * c-c++-common/goacc/kernels-decompose-ice-2.c: Adjust. * c-c++-common/goacc/kernels-loop-3-acc-loop.c: Adjust. * c-c++-common/goacc/kernels-loop-3.c: Adjust. * c-c++-common/goacc/loop-2-kernels.c: Adjust. * c-c++-common/goacc/nested-reductions-2-parallel.c: Adjust. * c-c++-common/goacc/note-parallelism-1-kernels-loop-auto.c: Adjust. * c-c++-common/goacc/note-parallelism-1-kernels-loop-independent_seq.c: Adjust. * c-c++-common/goacc/note-parallelism-1-kernels-loops.c: Adjust. * c-c++-common/goacc/note-parallelism-1-kernels-straight-line.c: Adjust. * c-c++-common/goacc/note-parallelism-combined-kernels-loop-auto.c: Adjust. * c-c++-common/goacc/note-parallelism-combined-kernels-loop-independent_seq.c: Adjust. * c-c++-common/goacc/note-parallelism-kernels-conditional-loop-independent_seq.c: Adjust. * c-c++-common/goacc/note-parallelism-kernels-loop-auto.c: Adjust. * c-c++-common/goacc/note-parallelism-kernels-loop-independent_seq.c: Adjust. * c-c++-common/goacc/note-parallelism-kernels-loops.c: Adjust. * c-c++-common/goacc/routine-1.c: Adjust. * c-c++-common/goacc/routine-level-of-parallelism-2.c: Adjust. * c-c++-common/goacc/routine-nohost-1.c: Adjust. * c-c++-common/goacc/uninit-copy-clause.c: Adjust. * gcc.dg/goacc/loop-processing-1.c: Adjust. * gcc.dg/goacc/nested-function-1.c: Adjust. * gfortran.dg/goacc/classify-kernels-unparallelized.f95: Adjust. * gfortran.dg/goacc/classify-kernels.f95: Adjust. * gfortran.dg/goacc/classify-parallel.f95: Adjust. * gfortran.dg/goacc/classify-routine.f95: Adjust. * gfortran.dg/goacc/classify-serial.f95: Adjust. * gfortran.dg/goacc/common-block-3.f90: Adjust. * gfortran.dg/goacc/gang-static.f95: Adjust. * gfortran.dg/goacc/kernels-decompose-1.f95: Adjust. * gfortran.dg/goacc/kernels-decompose-2.f95: Adjust. * gfortran.dg/goacc/kernels-loop-2.f95: Adjust. * gfortran.dg/goacc/kernels-loop-data-2.f95: Adjust. * gfortran.dg/goacc/kernels-loop-inner.f95: Adjust. * gfortran.dg/goacc/kernels-loop.f95: Adjust. * gfortran.dg/goacc/kernels-tree.f95: Adjust. * gfortran.dg/goacc/loop-2-kernels.f95: Adjust. * gfortran.dg/goacc/loop-auto-transfer-2.f90: Adjust. * gfortran.dg/goacc/loop-auto-transfer-3.f90: Adjust. * gfortran.dg/goacc/loop-auto-transfer-4.f90: Adjust. * gfortran.dg/goacc/nested-function-1.f90: Adjust. * gfortran.dg/goacc/nested-reductions-2-parallel.f90: Adjust. * gfortran.dg/goacc/private-explicit-kernels-1.f95: Adjust. * gfortran.dg/goacc/private-predetermined-kernels-1.f95: Adjust. * gfortran.dg/goacc/routine-module-mod-1.f90: Adjust. * gfortran.dg/goacc/uninit-copy-clause.f95: Adjust. * c-c++-common/goacc/note-parallelism-1-kernels-conditional-loop-independent_seq.c: Removed.
2023-05-12graphite: Accept loops without data referencesFrederik Harwath2-12/+5
It seems that the check that rejects loops without data references is only included to avoid handling non-profitable loops. Including those loops in Graphite's analysis enables more consistent diagnostic messages in OpenACC "kernels" code and does not introduce any testsuite regressions. If executing Graphite on loops without data references leads to noticeable compile time slow-downs for non-OpenACC users of Graphite, the check can be re-introduced but restricted to non-OpenACC functions. gcc/ChangeLog: * graphite-scop-detection.cc (scop_detection::harmful_loop_in_region): Remove check for loops without data references.
2023-05-12graphite: Adjust scop loop-nest choiceFrederik Harwath4-6/+27
The find_common_loop function is used in Graphite to obtain a common super-loop of all loops inside a SCoP. The function is applied to the loop of the destination block of the edge that leads into the SESE region and the loop of the source block of the edge that exits the region. The exit block is usually introduced by the canonicalization of the loop structure that Graphite does to support its code generation. If it is empty, it may happen that it belongs to the outer fake loop. This way, build_alias_set may end up analysing data-references with respect to this loop although there may exist a proper super-loop of the SCoP loops. This does not seem to be correct in general and it leads to problems with runtime alias check creation which fails if executed on a loop without niter information. gcc/ChangeLog: * graphite-scop-detection.cc (scop_context_loop): New function. (build_alias_set): Use scop_context_loop instead of find_common_loop. * graphite-isl-ast-to-gimple.cc (graphite_regenerate_ast_isl): Likewise. * graphite.h (scop_context_loop): New declaration.
2023-05-12graphite: Tune parameters for OpenACC useFrederik Harwath6-6/+115
The default values of some parameters that restrict Graphite's resource usage are too low for many OpenACC codes. Furthermore, exceeding the limits does not alwas lead to user-visible diagnostic messages. This commit increases the parameter values on OpenACC functions. The values were chosen to allow for the analysis of all "kernels" regions in the SPEC ACCEL v1.3 benchmark suite. Warnings about exceeded Graphite-related limits are added to the -fopt-info-missed output. Those warnings are phrased in a uniform way that intentionally refers to the "data-dependence analysis" of "OpenACC loops" instead of "a failure in Graphite" to make them easier to understand for users. gcc/ChangeLog: * graphite-optimize-isl.cc (optimize_isl): Adjust param_max_isl_operations value for OpenACC functions and add special warnings if value gets exceeded. * graphite-scop-detection.cc (build_scops): Likewise for param_graphite_max_arrays_per_scop. gcc/testsuite/ChangeLog: * gcc.dg/goacc/graphite-parameter-1.c: New test. * gcc.dg/goacc/graphite-parameter-2.c: New test.
2023-05-12openacc: Disable pass_pre on outlined functions analyzed by GraphiteFrederik Harwath2-0/+22
The additional dependences introduced by partial redundancy elimination proper and by the code hoisting step of the pass very often cause Graphite to fail on OpenACC functions. On the other hand, the pass can also enable the analysis of OpenACC loops (cf. e.g. the loop-auto-transfer-4.f90 testcase), for instance, because full redundancy elimination removes definitions that would otherwise prevent the creation of runtime alias checks outside of the SCoP. This commit disables the actual partial redundancy elimination step as well as the code hoisting step of pass_pre on OpenACC functions that might be handled by Graphite. gcc/ChangeLog: * tree-ssa-pre.cc (insert): Skip any insertions in OpenACC functions that might be processed by Graphite.
2023-05-12openacc: Handle internal function calls in pass_limFrederik Harwath5-14/+71
The loop invariant motion pass correctly refuses to move statements out of a loop if any other statement in the loop is unanalyzable. The pass does not know how to handle the OpenACC internal function calls which was not necessary until recently when the OpenACC device lowering pass was moved to a later position in the pass pipeline. This commit changes pass_lim to ignore the OpenACC internal function calls which do not contain any memory references. The hoisting enabled by this change can be useful for the data-dependence analysis in Graphite; for instance, in the outlined functions for OpenACC regions, all invariant accesses to the ".omp_data_i" struct should be hoisted out of the OpenACC loop. This is particularly important for variables that were scalars in the original loop and which have been turned into accesses to the struct by the outlining process. Not hoisting those can prevent scalar evolution analysis which is crucial for Graphite. Since any hoisting that introduces intermediate names - and hence, "fake" dependences - inside the analyzed nest can be harmful to data-dependence analysis, a flag to restrict the hoisting in OpenACC functions is added to the pass. The pass instance that executes before Graphite now runs with this flag set to true and the pass instance after Graphite runs unrestricted. A more precise way of selecting the statements for which hoisting should be enabled is left for a future improvement. gcc/ChangeLog: * passes.def: Set restrict_oacc_hoisting to true for the early pass_lim instance. * tree-ssa-loop-im.cc (movement_possibility_1): Add restrict_oacc_hoisting flag to function; restrict movement if set. (movement_possibility): Add restrict_oacc_hoisting parameter. Forward to movement_possibility_1. (compute_invariantness): Add restrict_oacc_hoisting flag and pass it on. (gather_mem_refs_stmt): Skip IFN_GOACC_LOOP and IFN_UNIQUE calls. (loop_invariant_motion_in_fun): Add restrict_oacc_hoisting flag and pass it on. (pass_lim::execute): Pass on new flags. * tree-ssa-loop-manip.h (loop_invariant_motion_in_fun): Adjust declaration. * gimple-loop-interchange.cc (pass_linterchange::execute): Adjust call to loop_invariant_motion_in_fun. gcc/ * tree-ssa-loop-im.cc (movement_possibility): Add restrict_oacc_hoisting parameter. Forward new parameter to movement_possibility_1.
2023-05-12openacc: Warn about "independent" "kernels" loops with data-dependencesFrederik Harwath3-0/+60
This commit concerns loops in OpenACC "kernels" region that have been marked up with an explicit "independent" clause by the user, but for which Graphite found data dependences. A discussion on the private internal OpenACC mailing list suggested that warning the user about the dependences woud be a more acceptable solution than reverting the user's decision. This behavior is implemented by the present commit. gcc/ChangeLog: * common.opt: Add flag Wopenacc-false-independent. * omp-offload.cc (oacc_loop_warn_if_false_independent): New function. (oacc_loop_fixed_partitions): Call from here.
2023-05-12openacc: Add runtime alias checking for OpenACC kernelsAndrew Stubbs5-209/+391
This commit adds the code generation for the runtime alias checks for OpenACC loops that have been analyzed by Graphite. The runtime alias check condition gets generated in Graphite. It is evaluated by the code generated for the IFN_GOACC_LOOP internal function calls. If aliasing is detected at runtime, the execution dimensions get adjusted to execute the affected loops sequentially. gcc/ChangeLog: * graphite-isl-ast-to-gimple.cc: Include internal-fn.h. (graphite_oacc_analyze_scop): Implement runtime alias checks. * omp-expand.cc (expand_oacc_for): Add an additional "noalias" parameter to GOACC_LOOP internal calls, and initialise it to integer_one_node. * omp-offload.cc (oacc_xform_loop): Integrate the runtime alias check into the GOACC_LOOP expansion. libgomp/ChangeLog: * testsuite/libgomp.oacc-c-c++-common/runtime-alias-check-1.c: New test. * testsuite/libgomp.oacc-c-c++-common/runtime-alias-check-2.c: New test.