https://gcc.gnu.org/g:91e02f44be983014dc081137f6015e29017ecf99

commit r17-2484-g91e02f44be983014dc081137f6015e29017ecf99
Author: Paul-Antoine Arras <[email protected]>
Date:   Thu Jul 16 15:06:16 2026 +0200

    openmp: Add OMPT variant of GOMP_has_masked_thread_num
    
    Add GOMP_has_masked_thread_num_with_end, which is semantically identical but
    meant for -fopenmp-ompt.
    
    gcc/ChangeLog:
    
            * omp-builtins.def (BUILT_IN_GOMP_HAS_MASKED_THREAD_NUM_WITH_END):
            New builtin.
            * omp-low.cc (lower_omp_master): Use it when -fopenmp-ompt.
    
    libgomp/ChangeLog:
    
            * libgomp.map: Add GOMP_has_masked_thread_num_with_end.
            * libgomp.texi: Document it.
            * libgomp_g.h (GOMP_has_masked_thread_num_with_end): Declare.
            * parallel.c (GOMP_has_masked_thread_num_with_end): New function.
    
    gcc/testsuite/ChangeLog:
    
            * c-c++-common/gomp/masked-1.c: Check new builtin is not emitted.
            * c-c++-common/gomp/masked-3.c: Check new builtin is emitted with
            -fopenmp-ompt.

Diff:
---
 gcc/omp-builtins.def                       | 3 +++
 gcc/omp-low.cc                             | 4 +++-
 gcc/testsuite/c-c++-common/gomp/masked-1.c | 1 +
 gcc/testsuite/c-c++-common/gomp/masked-3.c | 4 +++-
 libgomp/libgomp.map                        | 1 +
 libgomp/libgomp.texi                       | 4 +++-
 libgomp/libgomp_g.h                        | 1 +
 libgomp/parallel.c                         | 8 ++++++++
 8 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/gcc/omp-builtins.def b/gcc/omp-builtins.def
index 121bdcb61a33..29b3b72c2cdf 100644
--- a/gcc/omp-builtins.def
+++ b/gcc/omp-builtins.def
@@ -508,6 +508,9 @@ DEF_GOMP_BUILTIN (BUILT_IN_GOMP_ERROR, "GOMP_error",
 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_HAS_MASKED_THREAD_NUM_WITH_END,
+                 "GOMP_has_masked_thread_num_with_end", BT_FN_BOOL_INT,
+                 ATTR_CONST_NOTHROW_LEAF_LIST)
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_MASKED_END, "GOMP_masked_end", BT_FN_VOID,
                  ATTR_NOTHROW_LEAF_LIST)
 /* TODO review these function attributes once OMPT implementation done  */
diff --git a/gcc/omp-low.cc b/gcc/omp-low.cc
index 4bab2c56a23d..d87b6b6b2924 100644
--- a/gcc/omp-low.cc
+++ b/gcc/omp-low.cc
@@ -9146,7 +9146,9 @@ 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_GOMP_HAS_MASKED_THREAD_NUM);
+  bfn_decl = builtin_decl_explicit (
+    flag_openmp_ompt ? BUILT_IN_GOMP_HAS_MASKED_THREAD_NUM_WITH_END
+                    : 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;
diff --git a/gcc/testsuite/c-c++-common/gomp/masked-1.c 
b/gcc/testsuite/c-c++-common/gomp/masked-1.c
index 28d2735d96e3..92d005dbb9ba 100644
--- a/gcc/testsuite/c-c++-common/gomp/masked-1.c
+++ b/gcc/testsuite/c-c++-common/gomp/masked-1.c
@@ -26,5 +26,6 @@ foo (int x, int *a)
 }
 
 /* { dg-final { scan-tree-dump "GOMP_has_masked_thread_num" "omplower" } } */
+/* { dg-final { scan-tree-dump-not "GOMP_has_masked_thread_num_with_end" 
"omplower" } } */
 /* { dg-final { scan-tree-dump-not "GOMP_masked_end" "omplower" } } */
 /* { dg-final { scan-tree-dump-not "omp_get_thread_num" "omplower" } } */
diff --git a/gcc/testsuite/c-c++-common/gomp/masked-3.c 
b/gcc/testsuite/c-c++-common/gomp/masked-3.c
index adea59fdb69e..cb2209284c3c 100644
--- a/gcc/testsuite/c-c++-common/gomp/masked-3.c
+++ b/gcc/testsuite/c-c++-common/gomp/masked-3.c
@@ -1,6 +1,8 @@
 /* { dg-do compile } */
 /* { dg-additional-options "-fopenmp-ompt -fdump-tree-omplower" } */
 
+/* Check that OMPT variants of libgomp calls are emitted.  */
+
 void bar (void);
 
 void
@@ -10,6 +12,6 @@ foo (void)
   bar ();
 }
 
-/* { dg-final { scan-tree-dump-times "GOMP_has_masked_thread_num" 1 "omplower" 
} } */
+/* { dg-final { scan-tree-dump-times "GOMP_has_masked_thread_num_with_end" 1 
"omplower" } } */
 /* { dg-final { scan-tree-dump-times "GOMP_masked_end" 1 "omplower" } } */
 /* { dg-final { scan-tree-dump-not "omp_get_thread_num" "omplower" } } */
diff --git a/libgomp/libgomp.map b/libgomp/libgomp.map
index 3f465cc14916..81bad4d23296 100644
--- a/libgomp/libgomp.map
+++ b/libgomp/libgomp.map
@@ -485,6 +485,7 @@ GOMP_6.0.1 {
 GOMP_6.0.2 {
   global:
        GOMP_has_masked_thread_num;
+       GOMP_has_masked_thread_num_with_end;
        GOMP_masked_end;
        GOMP_loop_static_worksharing;
        GOMP_loop_static_worksharing_start;
diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi
index 687ae1a7cbca..1e6bb80e0ced 100644
--- a/libgomp/libgomp.texi
+++ b/libgomp/libgomp.texi
@@ -8070,7 +8070,9 @@ if (GOMP_has_masked_thread_num(thread_num))
 
 @code{GOMP_has_masked_thread_num} encapsulates the following check, so that 
OMPT
 can distinguish the compiler-generated code from user-level thread-number
-queries:
+queries; with @option{-fopenmp-ompt}, a paired call to
+@code{GOMP_has_masked_thread_num_with_end} and @code{GOMP_masked_end} is
+generated instead.
 
 @smallexample
 omp_get_thread_num() == @var{thread_num}
diff --git a/libgomp/libgomp_g.h b/libgomp/libgomp_g.h
index 1ea8123056e2..be3e349a4170 100644
--- a/libgomp/libgomp_g.h
+++ b/libgomp/libgomp_g.h
@@ -307,6 +307,7 @@ extern unsigned GOMP_parallel_reductions (void (*) (void 
*), void *, unsigned,
 extern bool GOMP_cancel (int, bool);
 extern bool GOMP_cancellation_point (int);
 extern bool GOMP_has_masked_thread_num (int);
+extern bool GOMP_has_masked_thread_num_with_end (int);
 extern void GOMP_masked_end (void);
 
 /* task.c */
diff --git a/libgomp/parallel.c b/libgomp/parallel.c
index bb522b39ecb1..286798ff9027 100644
--- a/libgomp/parallel.c
+++ b/libgomp/parallel.c
@@ -280,6 +280,14 @@ GOMP_has_masked_thread_num (int tid)
   return tid == gomp_thread ()->ts.team_id;
 }
 
+/* OMPT variant enabled by -fopenmp-ompt.  */
+
+bool
+GOMP_has_masked_thread_num_with_end (int tid)
+{
+  return tid == gomp_thread ()->ts.team_id;
+}
+
 /* Stub for OMPT callback enabled by -fopenmp-ompt.  */
 
 void

Reply via email to