DEF_PRIMITIVE_TYPE (BT_BOOL, boolean_type_node)
DEF_PRIMITIVE_TYPE (BT_INT, integer_type_node)
DEF_PRIMITIVE_TYPE (BT_UINT, unsigned_type_node)
+DEF_PRIMITIVE_TYPE (BT_COMPLEX_INT, complex_integer_type_node)
DEF_PRIMITIVE_TYPE (BT_LONG, long_integer_type_node)
DEF_PRIMITIVE_TYPE (BT_ULONG, long_unsigned_type_node)
DEF_PRIMITIVE_TYPE (BT_LONGLONG, long_long_integer_type_node)
DEF_FUNCTION_TYPE_0 (BT_FN_PID, BT_PID)
DEF_FUNCTION_TYPE_0 (BT_FN_INT, BT_INT)
DEF_FUNCTION_TYPE_0 (BT_FN_UINT, BT_UINT)
+DEF_FUNCTION_TYPE_0 (BT_FN_COMPLEX_INT, BT_COMPLEX_INT)
DEF_FUNCTION_TYPE_0 (BT_FN_ULONG, BT_ULONG)
+DEF_FUNCTION_TYPE_0 (BT_FN_ULONGLONG, BT_ULONGLONG)
DEF_FUNCTION_TYPE_0 (BT_FN_FLOAT, BT_FLOAT)
DEF_FUNCTION_TYPE_0 (BT_FN_DOUBLE, BT_DOUBLE)
/* For "long double" we use LONGDOUBLE (not LONG_DOUBLE) to
DEF_PRIMITIVE_TYPE (BT_VOID, void_type_node)
DEF_PRIMITIVE_TYPE (BT_BOOL, boolean_type_node)
DEF_PRIMITIVE_TYPE (BT_INT, integer_type_node)
+DEF_PRIMITIVE_TYPE (BT_COMPLEX_INT, complex_integer_type_node)
DEF_PRIMITIVE_TYPE (BT_UINT, unsigned_type_node)
DEF_PRIMITIVE_TYPE (BT_LONG, long_integer_type_node)
DEF_PRIMITIVE_TYPE (BT_ULONGLONG, long_long_unsigned_type_node)
DEF_FUNCTION_TYPE_0 (BT_FN_BOOL, BT_BOOL)
DEF_FUNCTION_TYPE_0 (BT_FN_PTR, BT_PTR)
DEF_FUNCTION_TYPE_0 (BT_FN_INT, BT_INT)
+DEF_FUNCTION_TYPE_0 (BT_FN_COMPLEX_INT, BT_COMPLEX_INT)
DEF_FUNCTION_TYPE_0 (BT_FN_UINT, BT_UINT)
DEF_FUNCTION_TYPE_0 (BT_FN_VOID, BT_VOID)
+DEF_FUNCTION_TYPE_0 (BT_FN_ULONGLONG, BT_ULONGLONG)
DEF_FUNCTION_TYPE_1 (BT_FN_VOID_PTR, BT_VOID, BT_PTR)
DEF_FUNCTION_TYPE_1 (BT_FN_VOID_PTRPTR, BT_VOID, BT_PTR_PTR)
DEF_GOMP_BUILTIN (BUILT_IN_GOMP_HAS_MASKED_THREAD_NUM,
"GOMP_has_masked_thread_num", BT_FN_BOOL_INT,
ATTR_CONST_NOTHROW_LEAF_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_STATIC_WORKSHARING,
+ "GOMP_loop_static_worksharing", BT_FN_COMPLEX_INT,
+ ATTR_CONST_NOTHROW_LEAF_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_DISTRIBUTE_STATIC_WORKSHARING,
+ "GOMP_distribute_static_worksharing", BT_FN_COMPLEX_INT,
+ ATTR_CONST_NOTHROW_LEAF_LIST)
release_ssa_name (gimple_assign_lhs (g));
}
}
+ /* Fetch the thread/team id and the number of threads/teams in a single
+ call to GOMP_loop_static_worksharing or GOMP_distribute_static_worksharing.
+ The helper returns both values packed into one complex int, with
+ the id as the imaginary part and the count as the real part. Returning
+ (rather than writing through pointers) keeps both values as plain SSA
+ names, which lets later passes - notably IPA-CP propagating constants
+ into the outlined kernel - reason about them. */
+ tree decl;
switch (gimple_omp_for_kind (fd->for_stmt))
{
case GF_OMP_FOR_KIND_FOR:
- nthreads = builtin_decl_explicit (BUILT_IN_OMP_GET_NUM_THREADS);
- threadid = builtin_decl_explicit (BUILT_IN_OMP_GET_THREAD_NUM);
+ decl = builtin_decl_explicit (BUILT_IN_GOMP_LOOP_STATIC_WORKSHARING);
break;
case GF_OMP_FOR_KIND_DISTRIBUTE:
- nthreads = builtin_decl_explicit (BUILT_IN_OMP_GET_NUM_TEAMS);
- threadid = builtin_decl_explicit (BUILT_IN_OMP_GET_TEAM_NUM);
+ decl = builtin_decl_explicit (BUILT_IN_GOMP_DISTRIBUTE_STATIC_WORKSHARING);
break;
default:
gcc_unreachable ();
}
- nthreads = build_call_expr (nthreads, 0);
- nthreads = fold_convert (itype, nthreads);
- nthreads = force_gimple_operand_gsi (&gsi, nthreads, true, NULL_TREE,
- true, GSI_SAME_STMT);
- threadid = build_call_expr (threadid, 0);
- threadid = fold_convert (itype, threadid);
- threadid = force_gimple_operand_gsi (&gsi, threadid, true, NULL_TREE,
+ {
+ tree packed = build_call_expr (decl, 0);
+ packed = force_gimple_operand_gsi (&gsi, packed, true, NULL_TREE,
true, GSI_SAME_STMT);
+ threadid = fold_build1 (IMAGPART_EXPR, integer_type_node, packed);
+ threadid = fold_convert (itype, threadid);
+ threadid = force_gimple_operand_gsi (&gsi, threadid, true, NULL_TREE,
+ true, GSI_SAME_STMT);
+ nthreads = fold_build1 (REALPART_EXPR, integer_type_node, packed);
+ nthreads = fold_convert (itype, nthreads);
+ nthreads = force_gimple_operand_gsi (&gsi, nthreads, true, NULL_TREE,
+ true, GSI_SAME_STMT);
+ }
n1 = fd->loop.n1;
n2 = fd->loop.n2;
release_ssa_name (gimple_assign_lhs (g));
}
}
+ /* Fetch the thread/team id and the number of threads/teams in a single
+ call to GOMP_loop_static_worksharing or GOMP_distribute_static_worksharing.
+ The helper returns both values packed into one complex int, with
+ the id as the imaginary part and the count as the real part. Returning
+ (rather than writing through pointers) keeps both values as plain SSA
+ names, which lets later passes - notably IPA-CP propagating constants
+ into the outlined kernel - reason about them. */
+ tree decl;
switch (gimple_omp_for_kind (fd->for_stmt))
{
case GF_OMP_FOR_KIND_FOR:
- nthreads = builtin_decl_explicit (BUILT_IN_OMP_GET_NUM_THREADS);
- threadid = builtin_decl_explicit (BUILT_IN_OMP_GET_THREAD_NUM);
+ decl = builtin_decl_explicit (BUILT_IN_GOMP_LOOP_STATIC_WORKSHARING);
break;
case GF_OMP_FOR_KIND_DISTRIBUTE:
- nthreads = builtin_decl_explicit (BUILT_IN_OMP_GET_NUM_TEAMS);
- threadid = builtin_decl_explicit (BUILT_IN_OMP_GET_TEAM_NUM);
+ decl = builtin_decl_explicit (BUILT_IN_GOMP_DISTRIBUTE_STATIC_WORKSHARING);
break;
default:
gcc_unreachable ();
}
- nthreads = build_call_expr (nthreads, 0);
- nthreads = fold_convert (itype, nthreads);
- nthreads = force_gimple_operand_gsi (&gsi, nthreads, true, NULL_TREE,
- true, GSI_SAME_STMT);
- threadid = build_call_expr (threadid, 0);
- threadid = fold_convert (itype, threadid);
- threadid = force_gimple_operand_gsi (&gsi, threadid, true, NULL_TREE,
+ {
+ tree packed = build_call_expr (decl, 0);
+ packed = force_gimple_operand_gsi (&gsi, packed, true, NULL_TREE,
true, GSI_SAME_STMT);
+ threadid = fold_build1 (IMAGPART_EXPR, integer_type_node, packed);
+ threadid = fold_convert (itype, threadid);
+ threadid = force_gimple_operand_gsi (&gsi, threadid, true, NULL_TREE,
+ true, GSI_SAME_STMT);
+ nthreads = fold_build1 (REALPART_EXPR, integer_type_node, packed);
+ nthreads = fold_convert (itype, nthreads);
+ nthreads = force_gimple_operand_gsi (&gsi, nthreads, true, NULL_TREE,
+ true, GSI_SAME_STMT);
+ }
n1 = fd->loop.n1;
n2 = fd->loop.n2;
--- /dev/null
+/* { dg-do compile } */
+/* { dg-additional-options "-fdump-tree-ompexp" } */
+
+/* Check that the static loop and distribute expanders fetch the thread/team
+ id and count through a single GOMP_loop_static_worksharing /
+ GOMP_distribute_static_worksharing call rather than separate
+ omp_get_thread_num/omp_get_num_threads or omp_get_team_num/omp_get_num_teams
+ calls. */
+
+void bar (int);
+
+/* Static schedule without a chunk size goes through
+ expand_omp_for_static_nochunk. */
+
+void
+f1 (int n)
+{
+ int i;
+ #pragma omp for schedule(static)
+ for (i = 0; i < n; ++i)
+ bar (i);
+}
+
+/* Static schedule with a chunk size goes through
+ expand_omp_for_static_chunk. */
+
+void
+f2 (int n)
+{
+ int i;
+ #pragma omp for schedule(static, 4)
+ for (i = 0; i < n; ++i)
+ bar (i);
+}
+
+/* Distribute without a chunk size goes through
+ expand_omp_for_static_nochunk. */
+
+void
+f3 (int n)
+{
+ int i;
+#pragma omp teams
+#pragma omp distribute
+ for (i = 0; i < n; ++i)
+ bar (i);
+}
+
+/* Distribute with a chunk size goes through
+ expand_omp_for_static_chunk. */
+
+void
+f4 (int n)
+{
+ int i;
+#pragma omp teams
+#pragma omp distribute dist_schedule(static, 4)
+ for (i = 0; i < n; ++i)
+ bar (i);
+}
+
+/* { dg-final { scan-tree-dump "GOMP_loop_static_worksharing" "ompexp" } } */
+/* { dg-final { scan-tree-dump "GOMP_distribute_static_worksharing" "ompexp" } } */
+/* { dg-final { scan-tree-dump-not "omp_get_num_threads" "ompexp" } } */
+/* { dg-final { scan-tree-dump-not "omp_get_thread_num" "ompexp" } } */
+/* { dg-final { scan-tree-dump-not "omp_get_num_teams" "ompexp" } } */
+/* { dg-final { scan-tree-dump-not "omp_get_team_num" "ompexp" } } */
(void) thread_limit;
}
+/* For a distribute construct with static schedule, return the team ID and
+ number of teams packed into a single complexvalue. */
+
+_Complex int
+GOMP_distribute_static_worksharing (void)
+{
+ int __lds *gomp_team_num = (int __lds *) GOMP_TEAM_NUM;
+ unsigned tid = *gomp_team_num;
+ unsigned nteams = gomp_num_teams_var + 1;
+ return nteams + tid * 1I;
+}
+
int
omp_get_num_teams (void)
{
(void) thread_limit;
}
+/* For a distribute construct with static schedule, return the team ID and
+ number of teams packed into a single complexvalue. */
+
+_Complex int
+GOMP_distribute_static_worksharing (void)
+{
+ unsigned tid = __gomp_team_num;
+ unsigned nteams = gomp_num_teams_var + 1;
+ return nteams + tid * 1I;
+}
+
int
omp_get_num_teams (void)
{
GOMP_6.0.2 {
global:
GOMP_has_masked_thread_num;
+ GOMP_loop_static_worksharing;
+ GOMP_distribute_static_worksharing;
} GOMP_6.0.1;
OACC_2.0 {
extern bool GOMP_cancel (int, bool);
extern bool GOMP_cancellation_point (int);
extern bool GOMP_has_masked_thread_num (int);
+extern __complex__ int GOMP_loop_static_worksharing (void);
/* task.c */
extern void GOMP_teams_reg (void (*) (void *), void *, unsigned, unsigned,
unsigned);
+extern __complex__ int GOMP_distribute_static_worksharing (void);
/* allocator.c */
return true;
}
+/* For a worksharing-loop construct with static schedule, return the thread ID
+ and number of threads packed into a single complex value. */
+
+_Complex int
+GOMP_loop_static_worksharing (void)
+{
+ struct gomp_team *team = gomp_thread ()->ts.team;
+ unsigned tid = gomp_thread ()->ts.team_id;
+ unsigned nthreads = team ? team->nthreads : 1;
+ return nthreads + tid * 1I;
+}
+
/* Return true if the current thread number equals TID.
Used to implement the masked construct's filter clause. */
}
}
+/* For a distribute construct with static schedule, return the team ID and
+ number of teams packed into a single complex value. */
+
+_Complex int
+GOMP_distribute_static_worksharing (void)
+{
+ struct gomp_thread *thr = gomp_thread ();
+ unsigned tid = thr->team_num;
+ unsigned nteams = thr->num_teams + 1;
+ return nteams + tid * 1I;
+}
+
int
omp_get_num_teams (void)
{