For the `omp master' and `omp masked filter(x)' constructs, the compiler lowers
the filter check by emitting omp_get_thread_num() == filter. Because
omp_get_thread_num is a public OpenMP API function, OMPT cannot distinguish this
internal check from a user-level thread-number query.
Introduce GOMP_has_masked_thread_num(int tid), a new libgomp entry point that
encapsulates the thread id check, and update lower_omp_master to call it instead
of building the comparison inline.
gcc/ChangeLog:
* builtin-types.def (BT_FN_BOOL_UINT): New function type.
* omp-builtins.def (BUILT_IN_GOMP_HAS_MASKED_THREAD_NUM): New builtin.
* omp-low.cc (lower_omp_master): Call it.
gcc/fortran/ChangeLog:
* types.def (BT_FN_BOOL_UINT): New function type.
libgomp/ChangeLog:
* libgomp.map (GOMP_6.0.2): New symbol version. Export
GOMP_has_masked_thread_num.
* parallel.c (GOMP_has_masked_thread_num): New function.
gcc/testsuite/ChangeLog:
* c-c++-common/gomp/masked-1.c: Add scan directives verifying that
GOMP_has_masked_thread_num is emitted and omp_get_thread_num is not.
* g++.dg/gomp/master-3.C: Update scan-tree-dump-times to look for
GOMP_has_masked_thread_num instead of omp_get_thread_num.
* gcc.dg/gomp/master-3.c: Likewise.
* gfortran.dg/gomp/masked-1.f90: Add scan directive for
GOMP_has_masked_thread_num.
---
gcc/omp-builtins.def | 3 +++
gcc/omp-low.cc | 5 ++---
gcc/testsuite/c-c++-common/gomp/masked-1.c | 6 ++++++
gcc/testsuite/g++.dg/gomp/master-3.C | 2 +-
gcc/testsuite/gcc.dg/gomp/master-3.c | 2 +-
gcc/testsuite/gfortran.dg/gomp/masked-1.f90 | 6 +++++-
libgomp/libgomp.map | 5 +++++
libgomp/parallel.c | 9 +++++++++
8 files changed, 32 insertions(+), 6 deletions(-)
diff --git a/gcc/omp-builtins.def b/gcc/omp-builtins.def
index f5b16c5d29e..c7ddea9880a 100644
--- a/gcc/omp-builtins.def
+++ b/gcc/omp-builtins.def
@@ -496,3 +496,6 @@ DEF_GOMP_BUILTIN (BUILT_IN_GOMP_WARNING, "GOMP_warning",
BT_FN_VOID_CONST_PTR_SIZE, ATTR_NOTHROW_LEAF_LIST)
DEF_GOMP_BUILTIN (BUILT_IN_GOMP_ERROR, "GOMP_error",
BT_FN_VOID_CONST_PTR_SIZE,
ATTR_COLD_NORETURN_NOTHROW_LEAF_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_HAS_MASKED_THREAD_NUM,
+ "GOMP_has_masked_thread_num", BT_FN_BOOL_INT,
+ ATTR_CONST_NOTHROW_LEAF_LIST)
diff --git a/gcc/omp-low.cc b/gcc/omp-low.cc
index e8716d9fa37..030bc8d9fc3 100644
--- a/gcc/omp-low.cc
+++ b/gcc/omp-low.cc
@@ -9059,9 +9059,8 @@ lower_omp_master (gimple_stmt_iterator *gsi_p,
omp_context *ctx)
gsi_replace (gsi_p, bind, true);
gimple_bind_add_stmt (bind, stmt);
- bfn_decl = builtin_decl_explicit (BUILT_IN_OMP_GET_THREAD_NUM);
- x = build_call_expr_loc (loc, bfn_decl, 0);
- x = build2 (EQ_EXPR, boolean_type_node, x, filter);
+ bfn_decl = builtin_decl_explicit (BUILT_IN_GOMP_HAS_MASKED_THREAD_NUM);
+ x = build_call_expr_loc (loc, bfn_decl, 1, filter);
x = build3 (COND_EXPR, void_type_node, x, NULL, build_and_jump (&lab));
tseq = NULL;
gimplify_and_add (x, &tseq);
diff --git a/gcc/testsuite/c-c++-common/gomp/masked-1.c
b/gcc/testsuite/c-c++-common/gomp/masked-1.c
index 36c2e492892..8de87b551e3 100644
--- a/gcc/testsuite/c-c++-common/gomp/masked-1.c
+++ b/gcc/testsuite/c-c++-common/gomp/masked-1.c
@@ -1,3 +1,6 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-fdump-tree-omplower" } */
+
void bar (void);
void
@@ -21,3 +24,6 @@ foo (int x, int *a)
#pragma omp masked filter (x)
;
}
+
+/* { dg-final { scan-tree-dump "GOMP_has_masked_thread_num" "omplower" } } */
+/* { dg-final { scan-tree-dump-not "omp_get_thread_num" "omplower" } } */
diff --git a/gcc/testsuite/g++.dg/gomp/master-3.C
b/gcc/testsuite/g++.dg/gomp/master-3.C
index c396128afdb..3d27b936d64 100644
--- a/gcc/testsuite/g++.dg/gomp/master-3.C
+++ b/gcc/testsuite/g++.dg/gomp/master-3.C
@@ -9,4 +9,4 @@ void foo (void)
bar(0);
}
-/* { dg-final { scan-tree-dump-times "omp_get_thread_num" 1 "omplower" } } */
+/* { dg-final { scan-tree-dump-times "GOMP_has_masked_thread_num" 1 "omplower"
} } */
diff --git a/gcc/testsuite/gcc.dg/gomp/master-3.c
b/gcc/testsuite/gcc.dg/gomp/master-3.c
index 5c0544dfa3c..0d5836748ce 100644
--- a/gcc/testsuite/gcc.dg/gomp/master-3.c
+++ b/gcc/testsuite/gcc.dg/gomp/master-3.c
@@ -9,4 +9,4 @@ void foo (void)
bar(0);
}
-/* { dg-final { scan-tree-dump-times "omp_get_thread_num" 1 "ompexp" } } */
+/* { dg-final { scan-tree-dump-times "GOMP_has_masked_thread_num" 1 "ompexp" }
} */
diff --git a/gcc/testsuite/gfortran.dg/gomp/masked-1.f90
b/gcc/testsuite/gfortran.dg/gomp/masked-1.f90
index 1bd61760ced..2b2526ac712 100644
--- a/gcc/testsuite/gfortran.dg/gomp/masked-1.f90
+++ b/gcc/testsuite/gfortran.dg/gomp/masked-1.f90
@@ -1,4 +1,6 @@
-! { dg-additional-options "-ffree-line-length-none" }
+! { dg-do compile }
+! { dg-additional-options "-ffree-line-length-none -fdump-tree-omplower" }
+
subroutine foo (x, a)
implicit none
integer, value :: x
@@ -92,3 +94,5 @@ subroutine foobar (d, f, fi, p, s, g, i1, i2, l, ll, nth,
ntm, pp, q, r, r2)
end do
!$omp end parallel masked taskloop simd
end subroutine
+
+! { dg-final { scan-tree-dump "GOMP_has_masked_thread_num" "omplower" } }
diff --git a/libgomp/libgomp.map b/libgomp/libgomp.map
index 06db9040e96..241fd45c4da 100644
--- a/libgomp/libgomp.map
+++ b/libgomp/libgomp.map
@@ -466,6 +466,11 @@ GOMP_6.0.1 {
omp_target_memset_async;
} GOMP_6.0;
+GOMP_6.0.2 {
+ global:
+ GOMP_has_masked_thread_num;
+} GOMP_6.0.1;
+
OACC_2.0 {
global:
acc_get_num_devices;
diff --git a/libgomp/parallel.c b/libgomp/parallel.c
index 754745227e0..d45ea61ddaa 100644
--- a/libgomp/parallel.c
+++ b/libgomp/parallel.c
@@ -270,6 +270,15 @@ GOMP_cancel (int which, bool do_cancel)
gomp_team_barrier_cancel (team);
return true;
}
+
+/* Return true if the current thread number equals TID.
+ Used to implement the masked construct's filter clause. */
+
+bool
+GOMP_has_masked_thread_num (int tid)
+{
+ return tid == gomp_thread ()->ts.team_id;
+}
/* The public OpenMP API for thread and team related inquiries. */
--
2.53.0