Ignore acc loop directive in kernels region --- gcc/gimplify.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/gcc/gimplify.c b/gcc/gimplify.c index 7be6bd7..cec0627 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -8364,6 +8364,82 @@ find_combined_omp_for (tree *tp, int *walk_subtrees, void *) return NULL_TREE; } +/* Gimplify the loops with index I and higher in omp_for FOR_STMT as a + sequential loop, and append the resulting gimple statements to PRE_P. */ + +static void +gimplify_omp_for_seq (tree for_stmt, gimple_seq *pre_p, unsigned int i) +{ + gcc_assert (OMP_FOR_ORIG_DECLS (for_stmt) == NULL_TREE); + unsigned int len = TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)); + gcc_assert (i < len); + + /* Gimplify OMP_FOR[i] as: + + if (i == 0) + OMP_FOR_PRE_BODY; + OMP_FOR_INIT[i]; + goto ; + : + if (i == len - 1) + OMP_FOR_BODY; + else + OMP_FOR[i+1]; + OMP_FOR_INCR[i]; + : + if (OMP_FOR_COND[i]) + goto ; + else + goto ; + : + */ + + tree loop_entry_label = create_artificial_label (UNKNOWN_LOCATION); + tree fall_thru_label = create_artificial_label (UNKNOWN_LOCATION); + tree loop_exit_label = create_artificial_label (UNKNOWN_LOCATION); + + /* if (i = 0) OMP_FOR_PRE_BODY. */ + if (i == 0) + gimplify_and_add (OMP_FOR_PRE_BODY (for_stmt), pre_p); + + /* OMP_FOR_INIT[i]. */ + tree init = TREE_VEC_ELT (OMP_FOR_INIT (for_stmt), i); + gimplify_stmt (&init, pre_p); + + /* goto . */ + gimplify_seq_add_stmt (pre_p, gimple_build_goto (loop_entry_label)); + + /* . */ + gimplify_seq_add_stmt (pre_p, gimple_build_label (fall_thru_label)); + + /* if (i == len - 1) OMP_FOR_BODY + else OMP_FOR[i+1]. */ + if (i == len - 1) + gimplify_and_return_first (OMP_FOR_BODY (for_stmt), pre_p); + else + gimplify_omp_for_seq (for_stmt, pre_p, i + 1); + + /* OMP_FOR_INCR[i]. */ + tree incr = TREE_VEC_ELT (OMP_FOR_INCR (for_stmt), i); + gimplify_stmt (&incr, pre_p); + + /* . */ + gimplify_seq_add_stmt (pre_p, gimple_build_label (loop_entry_label)); + + /* if (OMP_FOR_COND[i]) goto + else goto . */ + tree cond = TREE_VEC_ELT (OMP_FOR_COND (for_stmt), i); + tree var = TREE_OPERAND (cond, 0); + tree final_val = TREE_OPERAND (cond, 1); + gimplify_expr (&final_val, pre_p, NULL, is_gimple_val, fb_rvalue); + gimple *gimple_cond = gimple_build_cond (TREE_CODE (cond), var, final_val, + fall_thru_label, loop_exit_label); + gimplify_seq_add_stmt (pre_p, gimple_cond); + + /* . */ + gimplify_seq_add_stmt (pre_p, gimple_build_label (loop_exit_label)); +} + /* Gimplify the gross structure of an OMP_FOR statement. */ static enum gimplify_status @@ -8403,6 +8479,15 @@ gimplify_omp_for (tree *expr_p, gimple_seq *pre_p) gcc_unreachable (); } + if (ort == ORT_ACC + && gimplify_omp_ctxp != NULL + && gimplify_omp_ctxp->region_type == ORT_ACC_KERNELS) + { + /* For now, ignore loop directive in kernels region. */ + gimplify_omp_for_seq (for_stmt, pre_p, 0); + return GS_ALL_DONE; + } + /* Set OMP_CLAUSE_LINEAR_NO_COPYIN flag on explicit linear clause for the IV. */ if (ort == ORT_SIMD && TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)) == 1)