tree x;
x = builtin_decl_explicit (BUILT_IN_GOMP_BARRIER);
- x = build_call_expr_loc (loc, x, 0);
+ x = build_call_expr_loc (loc, x, 1,
+ build_int_cst (integer_type_node,
+ GOMP_BARRIER_EXPLICIT));
add_stmt (x);
}
{
tree fn = builtin_decl_explicit (BUILT_IN_GOMP_BARRIER);
releasing_vec vec;
+ vec->quick_push (build_int_cst (integer_type_node, GOMP_BARRIER_EXPLICIT));
tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
finish_expr_stmt (stmt);
}
gfc_trans_omp_barrier (void)
{
tree decl = builtin_decl_explicit (BUILT_IN_GOMP_BARRIER);
- return build_call_expr_loc (input_location, decl, 0);
+ return build_call_expr_loc (input_location, decl, 1,
+ build_int_cst (integer_type_node,
+ GOMP_BARRIER_EXPLICIT));
}
static tree
BT_FN_VOID, ATTR_NOTHROW_LEAF_LIST)
DEF_GOMP_BUILTIN (BUILT_IN_GOMP_ATOMIC_END, "GOMP_atomic_end",
BT_FN_VOID, ATTR_NOTHROW_LEAF_LIST)
-DEF_GOMP_BUILTIN (BUILT_IN_GOMP_BARRIER, "GOMP_barrier",
- BT_FN_VOID, ATTR_NOTHROW_LEAF_LIST)
-DEF_GOMP_BUILTIN (BUILT_IN_GOMP_BARRIER_CANCEL, "GOMP_barrier_cancel",
- BT_FN_BOOL, ATTR_NOTHROW_LEAF_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_BARRIER, "GOMP_barrier_ext", BT_FN_VOID_INT,
+ ATTR_NOTHROW_LEAF_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_BARRIER_CANCEL, "GOMP_barrier_cancel_ext",
+ BT_FN_BOOL_INT, ATTR_NOTHROW_LEAF_LIST)
DEF_GOMP_BUILTIN (BUILT_IN_GOMP_TASKWAIT, "GOMP_taskwait",
BT_FN_VOID, ATTR_NOTHROW_LEAF_LIST)
DEF_GOMP_BUILTIN (BUILT_IN_GOMP_TASKWAIT_DEPEND, "GOMP_taskwait_depend",
gsi_insert_after (&gsi, g, GSI_SAME_STMT);
}
else
- gsi_insert_after (&gsi, omp_build_barrier (t), GSI_SAME_STMT);
+ gsi_insert_after (&gsi,
+ omp_build_barrier (t,
+ GOMP_BARRIER_IMPLICIT_WORKSHARE),
+ GSI_SAME_STMT);
}
else if ((fd->have_pointer_condtemp || fd->have_scantemp)
&& !fd->have_nonctrl_scantemp)
gsi_insert_after (&gsi, g, GSI_SAME_STMT);
}
else
- gsi_insert_after (&gsi, omp_build_barrier (t), GSI_SAME_STMT);
+ gsi_insert_after (&gsi,
+ omp_build_barrier (t,
+ GOMP_BARRIER_IMPLICIT_WORKSHARE),
+ GSI_SAME_STMT);
}
else if (fd->have_pointer_condtemp)
{
if (!gimple_omp_return_nowait_p (gsi_stmt (si)))
{
tree t = gimple_omp_return_lhs (gsi_stmt (si));
- gsi_insert_after (&si, omp_build_barrier (t), GSI_SAME_STMT);
+ gsi_insert_after (&si,
+ omp_build_barrier (t, GOMP_BARRIER_IMPLICIT_WORKSHARE),
+ GSI_SAME_STMT);
}
gsi_remove (&si, true);
single_succ_edge (exit_bb)->flags = EDGE_FALLTHRU;
/* Build a call to GOMP_barrier. */
gimple *
-omp_build_barrier (tree lhs)
+omp_build_barrier (tree lhs, int kind)
{
tree fndecl = builtin_decl_explicit (lhs ? BUILT_IN_GOMP_BARRIER_CANCEL
: BUILT_IN_GOMP_BARRIER);
- gcall *g = gimple_build_call (fndecl, 0);
+ gcall *g = gimple_build_call (fndecl, 1,
+ build_int_cst (integer_type_node, kind));
if (lhs)
gimple_call_set_lhs (g, lhs);
return g;
extern tree omp_get_for_step_from_incr (location_t loc, tree incr);
extern void omp_extract_for_data (gomp_for *for_stmt, struct omp_for_data *fd,
struct omp_for_data_loop *loops);
-extern gimple *omp_build_barrier (tree lhs);
+extern gimple *omp_build_barrier (tree lhs, int kind);
extern tree find_combined_omp_for (tree *, int *, void *);
extern poly_uint64 omp_max_vf (bool);
extern int omp_max_simt_vf (void);
if (!is_task_ctx (ctx)
&& (gimple_code (ctx->stmt) != GIMPLE_OMP_FOR
|| gimple_omp_for_kind (ctx->stmt) == GF_OMP_FOR_KIND_FOR))
- gimple_seq_add_stmt (ilist, omp_build_barrier (NULL_TREE));
+ {
+ int barrier_kind;
+ switch (gimple_code (ctx->stmt))
+ {
+ case GIMPLE_OMP_SECTIONS:
+ case GIMPLE_OMP_SCOPE:
+ case GIMPLE_OMP_FOR:
+ barrier_kind = GOMP_BARRIER_IMPLICIT_WORKSHARE;
+ break;
+ case GIMPLE_OMP_PARALLEL:
+ case GIMPLE_OMP_TEAMS:
+ barrier_kind = GOMP_BARRIER_IMPLICIT_PARALLEL;
+ break;
+ default:
+ gcc_unreachable ();
+ }
+ gimple_seq_add_stmt (ilist,
+ omp_build_barrier (NULL_TREE, barrier_kind));
+ }
}
/* If max_vf is non-zero, then we can use only a vectorization factor
g = gimple_build_label (lab1);
gimple_seq_add_stmt (body_p, g);
- g = omp_build_barrier (NULL);
+ g = omp_build_barrier (NULL, GOMP_BARRIER_IMPLICIT_WORKSHARE);
gimple_seq_add_stmt (body_p, g);
tree down = create_tmp_var (unsigned_type_node);
g = gimple_build_label (lab12);
gimple_seq_add_stmt (body_p, g);
- g = omp_build_barrier (NULL);
+ g = omp_build_barrier (NULL, GOMP_BARRIER_IMPLICIT_WORKSHARE);
gimple_seq_add_stmt (body_p, g);
g = gimple_build_cond (NE_EXPR, k, build_zero_cst (unsigned_type_node),
--- /dev/null
+/* { dg-do compile } */
+/* { dg-additional-options "-fdump-tree-ompexp" } */
+
+/* Check that implicit barriers are emitted with the correct kind. */
+
+void body (void);
+void bar (int);
+void foo (int);
+
+/* OMP for construct with static schedule (with and without chunk) -> workshare
+ barrier. */
+void wfor (int n) {
+ int i;
+ #pragma omp for schedule(static)
+ for (i = 0; i < n; i++) bar (i);
+ #pragma omp for schedule(static, 4)
+ for (i = 0; i < n; i++) bar (i);
+}
+
+/* OMP for construct with inscan reduction -> workshare barrier. */
+int r;
+void wfor_scan (int n)
+{
+ int i;
+ #pragma omp for reduction(inscan, + : r) private(i)
+ for (i = 0; i < n; i = i + 1)
+ {
+ {
+ bar (r);
+ }
+ #pragma omp scan inclusive(r)
+ {
+ foo (r);
+ }
+ }
+}
+
+/* OMP sections construct with firstprivate and lastprivate clauses -> workshare
+ barrier. */
+int a;
+int wsections (void) {
+ #pragma omp sections firstprivate(a) lastprivate(a)
+ { foo (a); }
+ return a;
+}
+
+/* parallel with a copyin variable passed by reference (an aggregate, so
+ use_pointer_for_field is true) -> copyin_by_ref -> parallel barrier. */
+int tp[64];
+#pragma omp threadprivate (tp)
+void pcopyin (void) {
+ #pragma omp parallel copyin(tp)
+ body ();
+}
+
+/* UDR whose initializer references omp_orig, used on a (non-task) parallel
+ construct -> reduction_omp_orig_ref -> parallel barrier. */
+struct S { int s; };
+void combine (struct S *out, struct S *in);
+struct S init_from_orig (struct S *orig);
+void use (struct S *);
+
+#pragma omp declare reduction (+: struct S: combine (&omp_out, &omp_in)) \
+ initializer (omp_priv = init_from_orig (&omp_orig))
+
+void preduction_orig (struct S s) {
+ #pragma omp parallel reduction (+: s)
+ use (&s);
+}
+
+/* Same omp_orig UDR on a teams construct -> parallel barrier. */
+void treduction_orig (struct S s) {
+ #pragma omp teams reduction (+: s)
+ use (&s);
+}
+
+/* Same omp_orig UDR on a scope construct -> workshare barrier. */
+struct S gs;
+void sreduction_orig (void) {
+ #pragma omp parallel
+ #pragma omp scope reduction (+: gs)
+ use (&gs);
+}
+
+/* OMP single construct (without nowait) -> workshare barrier. */
+void wsingle (void) {
+ #pragma omp single
+ body ();
+}
+
+/* OMP scope construct (without nowait) -> workshare barrier. */
+void wscope (void) {
+ #pragma omp scope
+ body ();
+}
+
+/* GOMP_BARRIER_IMPLICIT_PARALLEL (0): pcopyin, preduction_orig,
+ treduction_orig. */
+/* { dg-final { scan-tree-dump-times "GOMP_barrier_ext \\(0\\)" 3 "ompexp" } } */
+/* GOMP_BARRIER_IMPLICIT_WORKSHARE (1): wfor (x2), wfor_scan (x2), wsections,
+ sreduction_orig, wsingle, wscope. */
+/* { dg-final { scan-tree-dump-times "GOMP_barrier_ext \\(1\\)" 8 "ompexp" } } */
}
}
-/* { dg-final { scan-tree-dump-times "GOMP_barrier" 2 "gimple" } } */
+/* { dg-final { scan-tree-dump-times "GOMP_barrier_ext \\(2\\)" 2 "gimple" } } */
f2<0> (true);
}
-// { dg-final { scan-tree-dump-times "GOMP_barrier" 2 "gimple" } }
+// { dg-final { scan-tree-dump-times "GOMP_barrier_ext" 2 "gimple" } }
}
}
-/* { dg-final { scan-tree-dump-times "GOMP_barrier" 2 "gimple" } } */
+/* { dg-final { scan-tree-dump-times "GOMP_barrier_ext \\(2\\)" 2 "gimple" } } */
--- /dev/null
+! { dg-do compile }
+! { dg-additional-options "-fdump-tree-omplower" }
+
+! A lastprivate allocatable (without a corresponding firstprivate) needs an
+! outer-variable reference (gfc_omp_private_outer_ref is true), which makes
+! lower_rec_input_clauses emit the implicit barrier. The barrier kind
+! depends on the construct the clause ends up on:
+! - combined "parallel do" -> GOMP_BARRIER_IMPLICIT_PARALLEL (0)
+! - "do" enclosed in a "parallel" -> GOMP_BARRIER_IMPLICIT_WORKSHARE (1)
+
+subroutine parallel_case
+ integer, allocatable :: a(:)
+ integer :: i
+ !$omp parallel do lastprivate(a)
+ do i = 1, 1
+ a = [i]
+ end do
+end subroutine parallel_case
+
+subroutine workshare_case
+ integer, allocatable :: a(:)
+ integer :: i
+ !$omp parallel
+ !$omp do lastprivate(a)
+ do i = 1, 1
+ a = [i]
+ end do
+ !$omp end do
+ !$omp end parallel
+end subroutine workshare_case
+
+! { dg-final { scan-tree-dump-times "GOMP_barrier_ext \\(0\\)" 1 "omplower" } }
+! { dg-final { scan-tree-dump-times "GOMP_barrier_ext \\(1\\)" 1 "omplower" } }
/* Identifiers of device-specific target arguments. */
#define GOMP_TARGET_ARG_HSA_KERNEL_ATTRIBUTES (1 << 8)
+/* GOMP_barrier{,_cancel}_ext argument.
+ TODO turn this into an enum? */
+#define GOMP_BARRIER_IMPLICIT_PARALLEL 0
+#define GOMP_BARRIER_IMPLICIT_WORKSHARE 1
+#define GOMP_BARRIER_EXPLICIT 2
+
#endif
#include "libgomp.h"
+/* GOMP_barrier is no longer called by new code; it is only kept for
+ backward compatibility. New code uses GOMP_barrier_ext. */
void
GOMP_barrier (void)
gomp_team_barrier_wait (&team->barrier);
}
+void
+GOMP_barrier_ext (int kind __attribute__ ((unused)))
+{
+ struct gomp_thread *thr = gomp_thread ();
+ struct gomp_team *team = thr->ts.team;
+
+ /* It is legal to have orphaned barriers. */
+ if (team == NULL)
+ return;
+
+ gomp_team_barrier_wait (&team->barrier);
+}
+
+/* GOMP_barrier_cancel is no longer called by new code; it is only kept for
+ backward compatibility. New code uses GOMP_barrier_cancel_ext. */
+
bool
GOMP_barrier_cancel (void)
{
never have an orphaned cancellable barrier. */
return gomp_team_barrier_wait_cancel (&team->barrier);
}
+
+bool
+GOMP_barrier_cancel_ext (int kind __attribute__ ((unused)))
+{
+ struct gomp_thread *thr = gomp_thread ();
+ struct gomp_team *team = thr->ts.team;
+
+ /* The compiler transforms to barrier_cancel when it sees that the
+ barrier is within a construct that can cancel. Thus we should
+ never have an orphaned cancellable barrier. */
+ return gomp_team_barrier_wait_cancel (&team->barrier);
+}
GOMP_has_masked_thread_num;
GOMP_loop_static_worksharing;
GOMP_distribute_static_worksharing;
+ GOMP_barrier_ext;
+ GOMP_barrier_cancel_ext;
} GOMP_6.0.1;
OACC_2.0 {
/* barrier.c */
extern void GOMP_barrier (void);
+extern void GOMP_barrier_ext (int);
extern bool GOMP_barrier_cancel (void);
+extern bool GOMP_barrier_cancel_ext (int);
/* critical.c */
#include <unistd.h>
#include <assert.h>
#include "libgomp_g.h"
-
+#include <gomp-constants.h>
struct timeval stamps[3][3];
if (iam == 0)
usleep (10);
- GOMP_barrier ();
+ GOMP_barrier_ext (GOMP_BARRIER_EXPLICIT);
if (iam == 0)
{
usleep (10);
}
- GOMP_barrier ();
-
+ GOMP_barrier_ext (GOMP_BARRIER_EXPLICIT);
+
gettimeofday (&stamps[iam][2], NULL);
}