]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
openmp: Add OMPT variant of GOMP_has_masked_thread_num
authorPaul-Antoine Arras <parras@baylibre.com>
Thu, 16 Jul 2026 13:06:16 +0000 (15:06 +0200)
committerPaul-Antoine Arras <parras@baylibre.com>
Fri, 17 Jul 2026 10:42:47 +0000 (12:42 +0200)
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.

gcc/omp-builtins.def
gcc/omp-low.cc
gcc/testsuite/c-c++-common/gomp/masked-1.c
gcc/testsuite/c-c++-common/gomp/masked-3.c
libgomp/libgomp.map
libgomp/libgomp.texi
libgomp/libgomp_g.h
libgomp/parallel.c

index 121bdcb61a3396bdf02571171afaed3ae9ce7070..29b3b72c2cdf819e8389c5414df29d70ed002909 100644 (file)
@@ -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  */
index 4bab2c56a23d5cfeea52dc5830541b5280005e55..d87b6b6b29242bce63c6c406a5a3bfe7e16a3061 100644 (file)
@@ -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;
index 28d2735d96e3de153bb8085b56b562940a4cedde..92d005dbb9ba966c4df1820317e117c0fa9d5bca 100644 (file)
@@ -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" } } */
index adea59fdb69efe141b9e9f85e5abf878ee99ecee..cb2209284c3c820e1f4741c4cdd93b83389cdd3c 100644 (file)
@@ -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" } } */
index 3f465cc14916086794bd3da1eb7b1ea069d2ad86..81bad4d232962006b68c5d33eb1c53a82a7f5d0c 100644 (file)
@@ -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;
index 687ae1a7cbca151ece9366102cfe8429a027b57d..1e6bb80e0cedd5fd84120a0def0575814814311f 100644 (file)
@@ -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}
index 1ea8123056e2d03fe2e78f822825346c642ae01a..be3e349a4170d978557c142cf4489d78b1bcccc3 100644 (file)
@@ -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 */
index bb522b39ecb1abd0bb9035e842865f38c4903703..286798ff90276b33c066d1a9bfac534fde6de072 100644 (file)
@@ -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