From f80cb8228e4847577a6fdde806f0f352225620d0 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 16 Jun 2020 16:31:13 +0200 Subject: openmp: Initial part of OpenMP 5.0 non-rectangular loop support OpenMP 5.0 adds support for non-rectangular loop collapses, e.g. triangular and more complex. This patch deals just with the diagnostics so that they aren't rejected immediately as before. As the spec generally requires as before that the iteration variable initializer and bound in the comparison as invariant vs. the outermost loop, and just add some exceptional forms that can violate that, we need to avoid folding the expressions until we can detect them and in order to avoid folding it later on, I chose to use a TREE_VEC in those expressions to hold the var_outer * expr1 + expr2 triplet, the patch adds pretty-printing of that, gimplification etc. and just sorry_at during omp expansion for now. The next step will be to implement the different cases of that one by one. 2020-06-16 Jakub Jelinek gcc/ * tree.h (OMP_FOR_NON_RECTANGULAR): Define. * gimplify.c (gimplify_omp_for): Diagnose schedule, ordered or dist_schedule clause on non-rectangular loops. Handle gimplification of non-rectangular lb/b expressions. When changing iteration variable, adjust also non-rectangular lb/b expressions referencing that. * omp-general.h (struct omp_for_data_loop): Add m1, m2 and outer members. (struct omp_for_data): Add non_rect member. * omp-general.c (omp_extract_for_data): Handle non-rectangular loops. Fill in non_rect, m1, m2 and outer. * omp-low.c (lower_omp_for): Handle non-rectangular lb/b expressions. * omp-expand.c (expand_omp_for): Emit sorry_at for unsupported non-rectangular loop cases and assert for cases that can't be non-rectangular. * tree-pretty-print.c (dump_mem_ref): Formatting fix. (dump_omp_loop_non_rect_expr): New function. (dump_generic_node): Handle non-rectangular OpenMP loops. * tree-pretty-print.h (dump_omp_loop_non_rect_expr): Declare. * gimple-pretty-print.c (dump_gimple_omp_for): Handle non-rectangular OpenMP loops. gcc/c-family/ * c-common.h (c_omp_check_loop_iv_exprs): Add an int argument. * c-omp.c (struct c_omp_check_loop_iv_data): Add maybe_nonrect and idx members. (c_omp_is_loop_iterator): New function. (c_omp_check_loop_iv_r): Use it. Add support for silent scanning if outer loop iterator is present. Perform duplicate checking through hash_set in the function rather than expecting caller to do that. Pass NULL instead of d->ppset to walk_tree_1. (c_omp_check_nonrect_loop_iv): New function. (c_omp_check_loop_iv): Use it. Fill in new members, allow non-rectangular loop forms, diagnose multiple associated loops with the same iterator. Pass NULL instead of &pset to walk_tree_1. (c_omp_check_loop_iv_exprs): Likewise. gcc/c/ * c-parser.c (c_parser_expr_no_commas): Save, clear and restore c_in_omp_for. (c_parser_omp_for_loop): Set c_in_omp_for around some calls to avoid premature c_fully_fold. Defer explicit c_fully_fold calls to after c_finish_omp_for. * c-tree.h (c_in_omp_for): Declare. * c-typeck.c (c_in_omp_for): Define. (build_modify_expr): Avoid c_fully_fold if c_in_omp_for. (digest_init): Likewise. (build_binary_op): Likewise. gcc/cp/ * semantics.c (handle_omp_for_class_iterator): Adjust c_omp_check_loop_iv_exprs caller. (finish_omp_for): Likewise. Don't call fold_build_cleanup_point_expr before calling c_finish_omp_for and c_omp_check_loop_iv, move it after those calls. * pt.c (tsubst_omp_for_iterator): Handle non-rectangular loops. gcc/testsuite/ * c-c++-common/gomp/loop-6.c: New test. * gcc.dg/gomp/loop-1.c: Don't expect diagnostics on valid non-rectangular loops. * gcc.dg/gomp/loop-2.c: New test. * g++.dg/gomp/loop-1.C: Don't expect diagnostics on valid non-rectangular loops. * g++.dg/gomp/loop-2.C: Likewise. * g++.dg/gomp/loop-5.C: New test. * g++.dg/gomp/loop-6.C: New test. --- gcc/gimplify.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 78 insertions(+), 4 deletions(-) (limited to 'gcc/gimplify.c') diff --git a/gcc/gimplify.c b/gcc/gimplify.c index 9851edfc4db..dd101197869 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -11182,7 +11182,26 @@ gimplify_omp_for (tree *expr_p, gimple_seq *pre_p) switch (TREE_CODE (for_stmt)) { case OMP_FOR: + if (OMP_FOR_NON_RECTANGULAR (inner_for_stmt ? inner_for_stmt : for_stmt)) + { + if (omp_find_clause (OMP_FOR_CLAUSES (for_stmt), + OMP_CLAUSE_SCHEDULE)) + error_at (EXPR_LOCATION (for_stmt), + "%qs clause may not appear on non-rectangular %qs", + "schedule", "for"); + if (omp_find_clause (OMP_FOR_CLAUSES (for_stmt), OMP_CLAUSE_ORDERED)) + error_at (EXPR_LOCATION (for_stmt), + "%qs clause may not appear on non-rectangular %qs", + "ordered", "for"); + } + break; case OMP_DISTRIBUTE: + if (OMP_FOR_NON_RECTANGULAR (inner_for_stmt ? inner_for_stmt : for_stmt) + && omp_find_clause (OMP_FOR_CLAUSES (for_stmt), + OMP_CLAUSE_DIST_SCHEDULE)) + error_at (EXPR_LOCATION (for_stmt), + "%qs clause may not appear on non-rectangular %qs", + "dist_schedule", "distribute"); break; case OACC_LOOP: ort = ORT_ACC; @@ -11757,8 +11776,18 @@ gimplify_omp_for (tree *expr_p, gimple_seq *pre_p) else var = decl; - tret = gimplify_expr (&TREE_OPERAND (t, 1), &for_pre_body, NULL, - is_gimple_val, fb_rvalue, false); + if (TREE_CODE (TREE_OPERAND (t, 1)) == TREE_VEC) + { + tree lb = TREE_OPERAND (t, 1); + tret = gimplify_expr (&TREE_VEC_ELT (lb, 1), &for_pre_body, NULL, + is_gimple_val, fb_rvalue, false); + ret = MIN (ret, tret); + tret = gimplify_expr (&TREE_VEC_ELT (lb, 2), &for_pre_body, NULL, + is_gimple_val, fb_rvalue, false); + } + else + tret = gimplify_expr (&TREE_OPERAND (t, 1), &for_pre_body, NULL, + is_gimple_val, fb_rvalue, false); ret = MIN (ret, tret); if (ret == GS_ERROR) return ret; @@ -11768,8 +11797,18 @@ gimplify_omp_for (tree *expr_p, gimple_seq *pre_p) gcc_assert (COMPARISON_CLASS_P (t)); gcc_assert (TREE_OPERAND (t, 0) == decl); - tret = gimplify_expr (&TREE_OPERAND (t, 1), &for_pre_body, NULL, - is_gimple_val, fb_rvalue, false); + if (TREE_CODE (TREE_OPERAND (t, 1)) == TREE_VEC) + { + tree ub = TREE_OPERAND (t, 1); + tret = gimplify_expr (&TREE_VEC_ELT (ub, 1), &for_pre_body, NULL, + is_gimple_val, fb_rvalue, false); + ret = MIN (ret, tret); + tret = gimplify_expr (&TREE_VEC_ELT (ub, 2), &for_pre_body, NULL, + is_gimple_val, fb_rvalue, false); + } + else + tret = gimplify_expr (&TREE_OPERAND (t, 1), &for_pre_body, NULL, + is_gimple_val, fb_rvalue, false); ret = MIN (ret, tret); /* Handle OMP_FOR_INCR. */ @@ -11911,6 +11950,20 @@ gimplify_omp_for (tree *expr_p, gimple_seq *pre_p) pop_gimplify_context (bind); } } + if (OMP_FOR_NON_RECTANGULAR (for_stmt) && var != decl) + for (int j = i + 1; j < TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)); j++) + { + t = TREE_VEC_ELT (OMP_FOR_INIT (for_stmt), j); + gcc_assert (TREE_CODE (t) == MODIFY_EXPR); + if (TREE_CODE (TREE_OPERAND (t, 1)) == TREE_VEC + && TREE_VEC_ELT (TREE_OPERAND (t, 1), 0) == decl) + TREE_VEC_ELT (TREE_OPERAND (t, 1), 0) = var; + t = TREE_VEC_ELT (OMP_FOR_COND (for_stmt), j); + gcc_assert (COMPARISON_CLASS_P (t)); + if (TREE_CODE (TREE_OPERAND (t, 1)) == TREE_VEC + && TREE_VEC_ELT (TREE_OPERAND (t, 1), 0) == decl) + TREE_VEC_ELT (TREE_OPERAND (t, 1), 0) = var; + } } BITMAP_FREE (has_decl_expr); @@ -11955,6 +12008,27 @@ gimplify_omp_for (tree *expr_p, gimple_seq *pre_p) t = TREE_VEC_ELT (OMP_FOR_INCR (for_stmt), i); TREE_OPERAND (t, 1) = copy_node (TREE_OPERAND (t, 1)); TREE_OPERAND (TREE_OPERAND (t, 1), 0) = var; + if (OMP_FOR_NON_RECTANGULAR (for_stmt)) + for (int j = i + 1; + j < TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)); j++) + { + t = TREE_VEC_ELT (OMP_FOR_INIT (for_stmt), j); + gcc_assert (TREE_CODE (t) == MODIFY_EXPR); + if (TREE_CODE (TREE_OPERAND (t, 1)) == TREE_VEC + && TREE_VEC_ELT (TREE_OPERAND (t, 1), 0) == decl) + { + TREE_OPERAND (t, 1) = copy_node (TREE_OPERAND (t, 1)); + TREE_VEC_ELT (TREE_OPERAND (t, 1), 0) = var; + } + t = TREE_VEC_ELT (OMP_FOR_COND (for_stmt), j); + gcc_assert (COMPARISON_CLASS_P (t)); + if (TREE_CODE (TREE_OPERAND (t, 1)) == TREE_VEC + && TREE_VEC_ELT (TREE_OPERAND (t, 1), 0) == decl) + { + TREE_OPERAND (t, 1) = copy_node (TREE_OPERAND (t, 1)); + TREE_VEC_ELT (TREE_OPERAND (t, 1), 0) = var; + } + } } gimplify_adjust_omp_clauses (pre_p, for_body, -- cgit v1.2.1