Re: [Patch] OpenMP: Add iterator support to Fortran's depend; add affinity clause
@Joseph: I CC'ed you in case you have comments regarding c-parser.c's c_parser_check_balanced_raw_token_sequence (comment update) and c_parser_check_tight_balanced_raw_token_sequence (new); the latter is essentially cp_parser_skip_balanced_tokens with slight adaptions. On 27.05.21 10:22, Jakub Jelinek via Gcc-patches wrote: One important thing I've missed. Unlike depend clause where dependence-type : is required, in affinity clause the aff-modifier is optional. Now handled for C, C++ and Fortran. What happens with this block ns: + char name[GFC_MAX_SYMBOL_LEN + 1]; + while (true) +{ + locus old_loc = gfc_current_locus; + if (gfc_match_type_spec (&ts) == MATCH_YES + && gfc_match (" :: ") == MATCH_YES) +{ + if (ts.type != BT_INTEGER) +{ + gfc_error ("Expected INTEGER type at %L", &old_loc); In the error handling? Well, in the old code nothing – until the parent namespace (gfc_current_ns) is beeing freed. Otherwise, it is walked at several places but not ns->symtree but only ns->code or ns->entry or ... As it now can be used in a non-error case, I decided to free it inside openmp.c instead of leaving it there for later cleanup. Tobias - Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank Thürauf OpenMP: Add iterator support to Fortran's depend; add affinity clause gcc/c-family/ChangeLog: * c-pragma.h (enum pragma_omp_clause): Add PRAGMA_OMP_CLAUSE_AFFINITY. gcc/c/ChangeLog: * c-parser.c (c_parser_check_balanced_raw_token_sequence): Update description. (c_parser_check_tight_balanced_raw_token_sequence, c_parser_omp_clause_affinity): New. (c_parser_omp_clause_name, c_parser_omp_variable_list, c_parser_omp_all_clauses, OMP_TASK_CLAUSE_MASK): Handle affinity clause. * c-typeck.c (handle_omp_array_sections_1, handle_omp_array_sections, c_finish_omp_clauses): Likewise. gcc/cp/ChangeLog: * parser.c (cp_parser_omp_clause_affinity): New. (cp_parser_omp_clause_name, cp_parser_omp_var_list_no_open, cp_parser_omp_all_clauses, OMP_TASK_CLAUSE_MASK): Handle affinity clause. * semantics.c (handle_omp_array_sections_1, handle_omp_array_sections, finish_omp_clauses): Likewise. gcc/fortran/ChangeLog: * dump-parse-tree.c (show_iterator): New. (show_omp_namelist): Handle iterators. (show_omp_clauses): Handle affinity. * gfortran.h (gfc_free_omp_namelist): New union with 'udr' and new 'ns'. * match.c (gfc_free_omp_namelist): Add are to choose union element. * openmp.c (gfc_free_omp_clauses, gfc_match_omp_detach): Update call to gfc_free_omp_namelist. (gfc_match_omp_variable_list): Likewise; permit preceeding whitespace. (enum omp_mask1): (gfc_match_iterator): New. (gfc_match_omp_clause_reduction): (gfc_match_omp_clauses): (gfc_match_omp_flush): (gfc_match_omp_taskwait): Match depend clause. (resolve_omp_clauses): Handle affinity; update for udr/union change. (gfc_resolve_omp_directive): Resolve clauses of taskwait. * st.c (gfc_free_statement): Update gfc_free_omp_namelist call. * trans-openmp.c (gfc_trans_omp_array_reduction_or_udr): Likewise (handle_iterator): New. (gfc_trans_omp_clauses): Handle iterators for depend/affinity clause. (gfc_trans_omp_taskwait): Handle depend clause. (gfc_trans_omp_directive): Update call. gcc/ChangeLog: * (gimplify_scan_omp_clauses): Ignore affinity clause. * tree-core.h (enum omp_clause_code): Add OMP_CLAUSE_AFFINITY. * tree-pretty-print.c (dump_omp_clause): Handle OMP_CLAUSE_AFFINITY. * tree.c (omp_clause_num_ops, omp_clause_code_name): Add clause. (walk_tree_1): Handle OMP_CLAUSE_AFFINITY. libgomp/ChangeLog: * testsuite/libgomp.fortran/depend-iterator-2.f90: New test. gcc/testsuite/ChangeLog: * c-c++-common/gomp/affinity-1.c: New test. * c-c++-common/gomp/affinity-2.c: New test. * c-c++-common/gomp/affinity-3.c: New test. * c-c++-common/gomp/affinity-4.c: New test. * c-c++-common/gomp/affinity-5.c: New test. * c-c++-common/gomp/affinity-6.c: New test. * c-c++-common/gomp/affinity-7.c: New test. * gfortran.dg/gomp/affinity-clause-1.f90: New test. * gfortran.dg/gomp/affinity-clause-2.f90: New test. * gfortran.dg/gomp/affinity-clause-3.f90: New test. * gfortran.dg/gomp/affinity-clause-4.f90: New test. * gfortran.dg/gomp/affinity-clause-5.f90: New test. * gfortran.dg/gomp/affinity-clause-6.f90: New test. * gfortran.dg/gomp/depend-iterator-1.f90: New test. * gfortran.dg/gomp/depend-iterator-2.f90: New test. * gfortran.dg/gomp/depend-iterator-3.f90: New test. * gfortran.dg/gomp/taskwait.f90: New test. gcc/c-family/c-pragma.h| 1 + gcc/c/c-parser.c | 124 - gcc/c/c-typeck.c | 52 ++-- gcc/cp/parser.c| 84 +- gcc/cp/semantics.c | 53 ++-- gcc/fortran/dump-parse-tree.c
Re: [Patch] OpenMP: Add iterator support to Fortran's depend; add affinity clause
On Thu, May 27, 2021 at 08:30:33PM +0200, Tobias Burnus wrote: > + if (c_parser_next_token_is (parser, CPP_NAME)) > +{ > + const char *p = IDENTIFIER_POINTER (c_parser_peek_token > (parser)->value); > + bool parse_iter = (strcmp ("iterator", p) == 0); > + if (parse_iter) I'd add here && c_parser_peek_2nd_token (parser)->type == CPP_OPEN_PAREN > + if (parse_iter) And similarly here && cp_lexer_nth_token_is (parser->lexer, 2, CPP_OPEN_PAREN) Otherwise LGTM, but please give Joseph some time to comment on the new function. Jakub
Re: [Patch] OpenMP: Add iterator support to Fortran's depend; add affinity clause
On Thu, 27 May 2021, Tobias Burnus wrote: > @Joseph: I CC'ed you in case you have comments regarding > c-parser.c's c_parser_check_balanced_raw_token_sequence (comment update) > and c_parser_check_tight_balanced_raw_token_sequence (new); the latter > is essentially cp_parser_skip_balanced_tokens with slight adaptions. I don't understand why the name says either "tight" or "balanced". As far as I can see, c_parser_check_tight_balanced_raw_token_sequence isn't checking for balanced token sequences (in the sense defined in C2x) at all and would accept e.g. }]{[ as being balanced. Is that really what's supposed to be accepted there? If it is, the comment on the function definition needs to explain the exact definition of what token sequences are accepted. -- Joseph S. Myers jos...@codesourcery.com
Re: [Patch] OpenMP: Add iterator support to Fortran's depend; add affinity clause
On Thu, May 27, 2021 at 07:58:03PM +, Joseph Myers wrote: > On Thu, 27 May 2021, Tobias Burnus wrote: > > > @Joseph: I CC'ed you in case you have comments regarding > > c-parser.c's c_parser_check_balanced_raw_token_sequence (comment update) > > and c_parser_check_tight_balanced_raw_token_sequence (new); the latter > > is essentially cp_parser_skip_balanced_tokens with slight adaptions. > > I don't understand why the name says either "tight" or "balanced". As far > as I can see, c_parser_check_tight_balanced_raw_token_sequence isn't > checking for balanced token sequences (in the sense defined in C2x) at all > and would accept e.g. }]{[ as being balanced. Is that really what's > supposed to be accepted there? If it is, the comment on the function > definition needs to explain the exact definition of what token sequences > are accepted. Not }]{[ but {[}], true. I guess what Tobias posted comes from the C++ FE cp_parser_skip_balanced_tokens which is apparently my fault. The C++ grammar is: balanced-token-seq: balanced-token balanced-token-seq balanced-token balanced-token: ( balanced-token-seq opt ) [ balanced-token-seq opt ] { balanced-token-seq opt } any token other than a parenthesis, a bracket, or a brace so I bet we need something like the C c_parser_check_balanced_raw_token_sequence instead in the C++ FE too. For the particular OpenMP use case, I think it really doesn't matter which one we use, if the opening and closing parens kinds/counts would match but they wouldn't be balanced, it would be invalid in any case and we'd reported it during parsing of the iterators. Jakub
[PATCH] PR fortran/99839 - [9/10/11/12 Regression] ICE in inline_matmul_assign, at fortran/frontend-passes.c:4234
Dear Fortranners, frontend optimization tries to inline matmul, but then it also needs to take care of the assignment to the result array. If that one is not of canonical type, we currently get an ICE. The straightforward solution is to simply punt in those cases and avoid inlining. Regtested on x86_64-pc-linux-gnu. OK for mainline? Backport to affected branches? Thanks, Harald Fortran - ICE in inline_matmul_assign Restrict inlining of matmul to those cases where assignment to the result array does not need special treatment. gcc/fortran/ChangeLog: PR fortran/99839 * frontend-passes.c (inline_matmul_assign): Do not inline matmul if the assignment to the resulting array if it is not of canonical type (real/integer/complex/logical). gcc/testsuite/ChangeLog: PR fortran/99839 * gfortran.dg/inline_matmul_25.f90: New test. diff --git a/gcc/fortran/frontend-passes.c b/gcc/fortran/frontend-passes.c index ffe2db4881d..8aa4cf0eca7 100644 --- a/gcc/fortran/frontend-passes.c +++ b/gcc/fortran/frontend-passes.c @@ -4193,6 +4193,19 @@ inline_matmul_assign (gfc_code **c, int *walk_subtrees, if (m_case == none) return 0; + /* We only handle assignment to numeric or logical variables. */ + switch(expr1->ts.type) +{ +case BT_INTEGER: +case BT_LOGICAL: +case BT_REAL: +case BT_COMPLEX: + break; + +default: + return 0; +} + ns = insert_block (); /* Assign the type of the zero expression for initializing the resulting diff --git a/gcc/testsuite/gfortran.dg/inline_matmul_25.f90 b/gcc/testsuite/gfortran.dg/inline_matmul_25.f90 new file mode 100644 index 000..df8ad06c123 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/inline_matmul_25.f90 @@ -0,0 +1,9 @@ +! { dg-do compile } +! { dg-options "-ffrontend-optimize" } +! PR fortran/99839 - ICE in inline_matmul_assign + +program p + real :: x(3, 3) = 1.0 + class(*), allocatable :: z(:, :) + z = matmul(x, x) +end
Re: [Patch] OpenMP: Add iterator support to Fortran's depend; add affinity clause
On 27.05.21 21:58, Joseph Myers wrote: On Thu, 27 May 2021, Tobias Burnus wrote: @Joseph: I CC'ed you in case you have comments regarding c-parser.c's c_parser_check_balanced_raw_token_sequence Pilot error on my side – doing three things in parallel (fixing a patch, updating docs + attending a spec conference) does not work well. Unsurprisingly, when properly used, calling c_parser_check_balanced_raw_token_sequence does work. Hence, I removed my balanced function & only the OpenMP specific omp_affinity function remains. (Updated version attached.) As far as I can see, ... isn't checking for balanced token sequences (in the sense defined in C2x) at all and would accept e.g. }]{[ as being balanced. It looks as if one should/could update the gcc/cp/ function to use the same algorithm as the gcc/c/ one – as the latter has also this issue. But that's a separate issue and completely independent of this patch. Thanks, Tobias - Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank Thürauf OpenMP: Add iterator support to Fortran's depend; add affinity clause gcc/c-family/ChangeLog: * c-pragma.h (enum pragma_omp_clause): Add PRAGMA_OMP_CLAUSE_AFFINITY. gcc/c/ChangeLog: * c-parser.c (c_parser_omp_clause_affinity): New. (c_parser_omp_clause_name, c_parser_omp_variable_list, c_parser_omp_all_clauses, OMP_TASK_CLAUSE_MASK): Handle affinity clause. * c-typeck.c (handle_omp_array_sections_1, handle_omp_array_sections, c_finish_omp_clauses): Likewise. gcc/cp/ChangeLog: * parser.c (cp_parser_omp_clause_affinity): New. (cp_parser_omp_clause_name, cp_parser_omp_var_list_no_open, cp_parser_omp_all_clauses, OMP_TASK_CLAUSE_MASK): Handle affinity clause. * semantics.c (handle_omp_array_sections_1, handle_omp_array_sections, finish_omp_clauses): Likewise. gcc/fortran/ChangeLog: * dump-parse-tree.c (show_iterator): New. (show_omp_namelist): Handle iterators. (show_omp_clauses): Handle affinity. * gfortran.h (gfc_free_omp_namelist): New union with 'udr' and new 'ns'. * match.c (gfc_free_omp_namelist): Add are to choose union element. * openmp.c (gfc_free_omp_clauses, gfc_match_omp_detach): Update call to gfc_free_omp_namelist. (gfc_match_omp_variable_list): Likewise; permit preceeding whitespace. (enum omp_mask1): (gfc_match_iterator): New. (gfc_match_omp_clause_reduction): (gfc_match_omp_clauses): (gfc_match_omp_flush): (gfc_match_omp_taskwait): Match depend clause. (resolve_omp_clauses): Handle affinity; update for udr/union change. (gfc_resolve_omp_directive): Resolve clauses of taskwait. * st.c (gfc_free_statement): Update gfc_free_omp_namelist call. * trans-openmp.c (gfc_trans_omp_array_reduction_or_udr): Likewise (handle_iterator): New. (gfc_trans_omp_clauses): Handle iterators for depend/affinity clause. (gfc_trans_omp_taskwait): Handle depend clause. (gfc_trans_omp_directive): Update call. gcc/ChangeLog: * (gimplify_scan_omp_clauses): Ignore affinity clause. * tree-core.h (enum omp_clause_code): Add OMP_CLAUSE_AFFINITY. * tree-pretty-print.c (dump_omp_clause): Handle OMP_CLAUSE_AFFINITY. * tree.c (omp_clause_num_ops, omp_clause_code_name): Add clause. (walk_tree_1): Handle OMP_CLAUSE_AFFINITY. libgomp/ChangeLog: * testsuite/libgomp.fortran/depend-iterator-2.f90: New test. gcc/testsuite/ChangeLog: * c-c++-common/gomp/affinity-1.c: New test. * c-c++-common/gomp/affinity-2.c: New test. * c-c++-common/gomp/affinity-3.c: New test. * c-c++-common/gomp/affinity-4.c: New test. * c-c++-common/gomp/affinity-5.c: New test. * c-c++-common/gomp/affinity-6.c: New test. * c-c++-common/gomp/affinity-7.c: New test. * gfortran.dg/gomp/affinity-clause-1.f90: New test. * gfortran.dg/gomp/affinity-clause-2.f90: New test. * gfortran.dg/gomp/affinity-clause-3.f90: New test. * gfortran.dg/gomp/affinity-clause-4.f90: New test. * gfortran.dg/gomp/affinity-clause-5.f90: New test. * gfortran.dg/gomp/affinity-clause-6.f90: New test. * gfortran.dg/gomp/depend-iterator-1.f90: New test. * gfortran.dg/gomp/depend-iterator-2.f90: New test. * gfortran.dg/gomp/depend-iterator-3.f90: New test. * gfortran.dg/gomp/taskwait.f90: New test. gcc/c-family/c-pragma.h| 1 + gcc/c/c-parser.c | 81 +- gcc/c/c-typeck.c | 52 ++-- gcc/cp/parser.c| 86 +- gcc/cp/semantics.c | 53 ++-- gcc/fortran/dump-parse-tree.c | 51 +++- gcc/fortran/gfortran.h | 9 +- gcc/fortran/match.c| 18 +- gcc/fortran/openmp.c | 307 ++--- gcc/fortran/st.c | 2 +- gcc/fortran/trans-openmp.c | 198 ++--- gcc/gimplify.c