aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2020-08-13 09:06:05 +0200
committerJakub Jelinek <jakub@redhat.com>2020-08-13 09:06:05 +0200
commit2e47c8c6eac405ceb599bf5e31ac3717c22a008c (patch)
tree6b548e09bcebf00f74983be40030d2acc78db3ac /gcc
parent7123217afb33d4a2860f552ad778a819cc8dea5e (diff)
downloadgcc-2e47c8c6eac405ceb599bf5e31ac3717c22a008c.zip
gcc-2e47c8c6eac405ceb599bf5e31ac3717c22a008c.tar.gz
gcc-2e47c8c6eac405ceb599bf5e31ac3717c22a008c.tar.bz2
openmp: Add support for non-rectangular loops in taskloop construct
2020-08-13 Jakub Jelinek <jakub@redhat.com> * gimplify.c (gimplify_omp_taskloop_expr): New function. (gimplify_omp_for): Use it. For OMP_FOR_NON_RECTANGULAR loops adjust in outer taskloop the var-outer decls. * omp-expand.c (expand_omp_taskloop_for_inner): Handle non-rectangular loops. (expand_omp_for): Don't reject non-rectangular taskloop. * omp-general.c (omp_extract_for_data): Don't assert that non-rectangular loops have static schedule, instead treat loop->m1 or loop->m2 as if loop->n1 or loop->n2 is non-constant. * testsuite/libgomp.c/loop-22.c (main): Add some further tests. * testsuite/libgomp.c/loop-23.c (main): Likewise. * testsuite/libgomp.c/loop-24.c: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/gimplify.c145
-rw-r--r--gcc/omp-expand.c20
-rw-r--r--gcc/omp-general.c12
3 files changed, 103 insertions, 74 deletions
diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index 6a5349c..23d0e25 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -10996,6 +10996,37 @@ gimplify_omp_task (tree *expr_p, gimple_seq *pre_p)
*expr_p = NULL_TREE;
}
+/* Helper function for gimplify_omp_for. If *TP is not a gimple constant,
+ force it into a temporary initialized in PRE_P and add firstprivate clause
+ to ORIG_FOR_STMT. */
+
+static void
+gimplify_omp_taskloop_expr (tree type, tree *tp, gimple_seq *pre_p,
+ tree orig_for_stmt)
+{
+ if (*tp == NULL || is_gimple_constant (*tp))
+ return;
+
+ *tp = get_initialized_tmp_var (*tp, pre_p, NULL, false);
+ /* Reference to pointer conversion is considered useless,
+ but is significant for firstprivate clause. Force it
+ here. */
+ if (type
+ && TREE_CODE (type) == POINTER_TYPE
+ && TREE_CODE (TREE_TYPE (*tp)) == REFERENCE_TYPE)
+ {
+ tree v = create_tmp_var (TYPE_MAIN_VARIANT (type));
+ tree m = build2 (INIT_EXPR, TREE_TYPE (v), v, *tp);
+ gimplify_and_add (m, pre_p);
+ *tp = v;
+ }
+
+ tree c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE);
+ OMP_CLAUSE_DECL (c) = *tp;
+ OMP_CLAUSE_CHAIN (c) = OMP_FOR_CLAUSES (orig_for_stmt);
+ OMP_FOR_CLAUSES (orig_for_stmt) = c;
+}
+
/* Gimplify the gross structure of an OMP_FOR statement. */
static enum gimplify_status
@@ -11298,65 +11329,34 @@ gimplify_omp_for (tree *expr_p, gimple_seq *pre_p)
for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)); i++)
{
t = TREE_VEC_ELT (OMP_FOR_INIT (for_stmt), i);
- if (!is_gimple_constant (TREE_OPERAND (t, 1)))
- {
+ gimple_seq *for_pre_p = (gimple_seq_empty_p (for_pre_body)
+ ? pre_p : &for_pre_body);
tree type = TREE_TYPE (TREE_OPERAND (t, 0));
- TREE_OPERAND (t, 1)
- = get_initialized_tmp_var (TREE_OPERAND (t, 1),
- gimple_seq_empty_p (for_pre_body)
- ? pre_p : &for_pre_body, NULL,
- false);
- /* Reference to pointer conversion is considered useless,
- but is significant for firstprivate clause. Force it
- here. */
- if (TREE_CODE (type) == POINTER_TYPE
- && (TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 1)))
- == REFERENCE_TYPE))
- {
- tree v = create_tmp_var (TYPE_MAIN_VARIANT (type));
- tree m = build2 (INIT_EXPR, TREE_TYPE (v), v,
- TREE_OPERAND (t, 1));
- gimplify_and_add (m, gimple_seq_empty_p (for_pre_body)
- ? pre_p : &for_pre_body);
- TREE_OPERAND (t, 1) = v;
- }
- tree c = build_omp_clause (input_location,
- OMP_CLAUSE_FIRSTPRIVATE);
- OMP_CLAUSE_DECL (c) = TREE_OPERAND (t, 1);
- OMP_CLAUSE_CHAIN (c) = OMP_FOR_CLAUSES (orig_for_stmt);
- OMP_FOR_CLAUSES (orig_for_stmt) = c;
+ if (TREE_CODE (TREE_OPERAND (t, 1)) == TREE_VEC)
+ {
+ tree v = TREE_OPERAND (t, 1);
+ gimplify_omp_taskloop_expr (type, &TREE_VEC_ELT (v, 1),
+ for_pre_p, orig_for_stmt);
+ gimplify_omp_taskloop_expr (type, &TREE_VEC_ELT (v, 2),
+ for_pre_p, orig_for_stmt);
}
+ else
+ gimplify_omp_taskloop_expr (type, &TREE_OPERAND (t, 1), for_pre_p,
+ orig_for_stmt);
/* Handle OMP_FOR_COND. */
t = TREE_VEC_ELT (OMP_FOR_COND (for_stmt), i);
- if (!is_gimple_constant (TREE_OPERAND (t, 1)))
+ if (TREE_CODE (TREE_OPERAND (t, 1)) == TREE_VEC)
{
- tree type = TREE_TYPE (TREE_OPERAND (t, 0));
- TREE_OPERAND (t, 1)
- = get_initialized_tmp_var (TREE_OPERAND (t, 1),
- gimple_seq_empty_p (for_pre_body)
- ? pre_p : &for_pre_body, NULL,
- false);
- /* Reference to pointer conversion is considered useless,
- but is significant for firstprivate clause. Force it
- here. */
- if (TREE_CODE (type) == POINTER_TYPE
- && (TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 1)))
- == REFERENCE_TYPE))
- {
- tree v = create_tmp_var (TYPE_MAIN_VARIANT (type));
- tree m = build2 (INIT_EXPR, TREE_TYPE (v), v,
- TREE_OPERAND (t, 1));
- gimplify_and_add (m, gimple_seq_empty_p (for_pre_body)
- ? pre_p : &for_pre_body);
- TREE_OPERAND (t, 1) = v;
- }
- tree c = build_omp_clause (input_location,
- OMP_CLAUSE_FIRSTPRIVATE);
- OMP_CLAUSE_DECL (c) = TREE_OPERAND (t, 1);
- OMP_CLAUSE_CHAIN (c) = OMP_FOR_CLAUSES (orig_for_stmt);
- OMP_FOR_CLAUSES (orig_for_stmt) = c;
+ tree v = TREE_OPERAND (t, 1);
+ gimplify_omp_taskloop_expr (type, &TREE_VEC_ELT (v, 1),
+ for_pre_p, orig_for_stmt);
+ gimplify_omp_taskloop_expr (type, &TREE_VEC_ELT (v, 2),
+ for_pre_p, orig_for_stmt);
}
+ else
+ gimplify_omp_taskloop_expr (type, &TREE_OPERAND (t, 1), for_pre_p,
+ orig_for_stmt);
/* Handle OMP_FOR_INCR. */
t = TREE_VEC_ELT (OMP_FOR_INCR (for_stmt), i);
@@ -11368,17 +11368,8 @@ gimplify_omp_for (tree *expr_p, gimple_seq *pre_p)
if (TREE_CODE (t) == PLUS_EXPR && *tp == decl)
tp = &TREE_OPERAND (t, 0);
- if (!is_gimple_constant (*tp))
- {
- gimple_seq *seq = gimple_seq_empty_p (for_pre_body)
- ? pre_p : &for_pre_body;
- *tp = get_initialized_tmp_var (*tp, seq, NULL, false);
- tree c = build_omp_clause (input_location,
- OMP_CLAUSE_FIRSTPRIVATE);
- OMP_CLAUSE_DECL (c) = *tp;
- OMP_CLAUSE_CHAIN (c) = OMP_FOR_CLAUSES (orig_for_stmt);
- OMP_FOR_CLAUSES (orig_for_stmt) = c;
- }
+ gimplify_omp_taskloop_expr (NULL_TREE, tp, for_pre_p,
+ orig_for_stmt);
}
}
@@ -12220,6 +12211,34 @@ gimplify_omp_for (tree *expr_p, gimple_seq *pre_p)
OMP_CLAUSE_DECL (t) = v;
OMP_CLAUSE_CHAIN (t) = gimple_omp_for_clauses (gforo);
gimple_omp_for_set_clauses (gforo, t);
+ if (OMP_FOR_NON_RECTANGULAR (for_stmt))
+ {
+ tree *p1 = NULL, *p2 = NULL;
+ t = gimple_omp_for_initial (gforo, i);
+ if (TREE_CODE (t) == TREE_VEC)
+ p1 = &TREE_VEC_ELT (t, 0);
+ t = gimple_omp_for_final (gforo, i);
+ if (TREE_CODE (t) == TREE_VEC)
+ {
+ if (p1)
+ p2 = &TREE_VEC_ELT (t, 0);
+ else
+ p1 = &TREE_VEC_ELT (t, 0);
+ }
+ if (p1)
+ {
+ int j;
+ for (j = 0; j < i; j++)
+ if (*p1 == gimple_omp_for_index (gfor, j))
+ {
+ *p1 = gimple_omp_for_index (gforo, j);
+ if (p2)
+ *p2 = *p1;
+ break;
+ }
+ gcc_assert (j < i);
+ }
+ }
}
gimplify_seq_add_stmt (pre_p, gforo);
}
diff --git a/gcc/omp-expand.c b/gcc/omp-expand.c
index eb37b38..8f1286e 100644
--- a/gcc/omp-expand.c
+++ b/gcc/omp-expand.c
@@ -6917,8 +6917,20 @@ expand_omp_taskloop_for_inner (struct omp_region *region,
assign_stmt = gimple_build_assign (fd->loop.v, NOP_EXPR, e);
gsi_insert_after (&gsi, assign_stmt, GSI_CONTINUE_LINKING);
}
+
+ tree *nonrect_bounds = NULL;
if (fd->collapse > 1)
- expand_omp_for_init_vars (fd, &gsi, counts, NULL, inner_stmt, startvar);
+ {
+ if (fd->non_rect)
+ {
+ nonrect_bounds = XALLOCAVEC (tree, fd->last_nonrect + 1);
+ memset (nonrect_bounds, 0, sizeof (tree) * (fd->last_nonrect + 1));
+ }
+ gcc_assert (gsi_bb (gsi) == entry_bb);
+ expand_omp_for_init_vars (fd, &gsi, counts, nonrect_bounds, inner_stmt,
+ startvar);
+ entry_bb = gsi_bb (gsi);
+ }
if (!broken_loop)
{
@@ -6953,7 +6965,8 @@ expand_omp_taskloop_for_inner (struct omp_region *region,
gsi_remove (&gsi, true);
if (fd->collapse > 1 && !gimple_omp_for_combined_p (fd->for_stmt))
- collapse_bb = extract_omp_for_update_vars (fd, NULL, cont_bb, body_bb);
+ collapse_bb = extract_omp_for_update_vars (fd, nonrect_bounds,
+ cont_bb, body_bb);
}
/* Remove the GIMPLE_OMP_FOR statement. */
@@ -7643,9 +7656,6 @@ expand_omp_for (struct omp_region *region, gimple *inner_stmt)
}
else if (gimple_omp_for_kind (fd.for_stmt) == GF_OMP_FOR_KIND_TASKLOOP)
{
- if (fd.non_rect)
- sorry_at (gimple_location (fd.for_stmt),
- "non-rectangular %<taskloop%> not supported yet");
if (gimple_omp_for_combined_into_p (fd.for_stmt))
expand_omp_taskloop_for_inner (region, &fd, inner_stmt);
else
diff --git a/gcc/omp-general.c b/gcc/omp-general.c
index 6e6d3e1..8e2665a 100644
--- a/gcc/omp-general.c
+++ b/gcc/omp-general.c
@@ -444,10 +444,6 @@ omp_extract_for_data (gomp_for *for_stmt, struct omp_for_data *fd,
= build_nonstandard_integer_type
(TYPE_PRECISION (TREE_TYPE (loop->v)), 1);
}
- else if (loop->m1 || loop->m2)
- /* Non-rectangular loops should use static schedule and no
- ordered clause. */
- gcc_unreachable ();
else if (iter_type != long_long_unsigned_type_node)
{
if (POINTER_TYPE_P (TREE_TYPE (loop->v)))
@@ -463,7 +459,9 @@ omp_extract_for_data (gomp_for *for_stmt, struct omp_for_data *fd,
loop->n2, loop->step);
else
n = loop->n1;
- if (TREE_CODE (n) != INTEGER_CST
+ if (loop->m1
+ || loop->m2
+ || TREE_CODE (n) != INTEGER_CST
|| tree_int_cst_lt (TYPE_MAX_VALUE (iter_type), n))
iter_type = long_long_unsigned_type_node;
}
@@ -484,7 +482,9 @@ omp_extract_for_data (gomp_for *for_stmt, struct omp_for_data *fd,
loop->n2, loop->step);
n2 = loop->n1;
}
- if (TREE_CODE (n1) != INTEGER_CST
+ if (loop->m1
+ || loop->m2
+ || TREE_CODE (n1) != INTEGER_CST
|| TREE_CODE (n2) != INTEGER_CST
|| !tree_int_cst_lt (TYPE_MIN_VALUE (iter_type), n1)
|| !tree_int_cst_lt (n2, TYPE_MAX_VALUE (iter_type)))