]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
openmp: Add OMPT variants of GOMP_scope_start
authorPaul-Antoine Arras <parras@baylibre.com>
Mon, 20 Jul 2026 09:48:59 +0000 (11:48 +0200)
committerPaul-Antoine Arras <parras@baylibre.com>
Mon, 20 Jul 2026 14:08:03 +0000 (16:08 +0200)
GOMP_scope_start is emitted only for task reductions without -fopenmp-ompt
(unchanged). With -fopenmp-ompt, both GOMP_scope_start_with_end and
GOMP_scope_end are emitted, whether a task reduction is specified or not.

gcc/ChangeLog:

* omp-builtins.def (BUILT_IN_GOMP_SCOPE_START_WITH_END): New
builtin.
(BUILT_IN_GOMP_SCOPE_END): Likewise.
* omp-low.cc (lower_omp_scope): Emit calls to
GOMP_scope_start_with_end and GOMP_scope_end when -fopenmp-ompt.

libgomp/ChangeLog:

* libgomp.map: Add GOMP_scope_start_with_end and GOMP_scope_end.
* libgomp_g.h (GOMP_scope_start_with_end): Declare.
(GOMP_scope_end): Likewise.
* scope.c (GOMP_scope_start_with_end): New function.
(GOMP_scope_end): New stub.

gcc/testsuite/ChangeLog:

* c-c++-common/gomp/scope-7.c: New test.
* c-c++-common/gomp/scope-8.c: New test.

gcc/omp-builtins.def
gcc/omp-low.cc
gcc/testsuite/c-c++-common/gomp/scope-7.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/scope-8.c [new file with mode: 0644]
libgomp/libgomp.map
libgomp/libgomp_g.h
libgomp/scope.c

index 29b3b72c2cdf819e8389c5414df29d70ed002909..6b5e231eb0a842f3e228da6dbe004ab214f7bc0f 100644 (file)
@@ -456,6 +456,10 @@ DEF_GOMP_BUILTIN (BUILT_IN_GOMP_SINGLE_COPY_END, "GOMP_single_copy_end",
                  BT_FN_VOID_PTR, ATTR_NOTHROW_LEAF_LIST)
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_SCOPE_START, "GOMP_scope_start",
                  BT_FN_VOID_PTR, ATTR_NOTHROW_LEAF_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_SCOPE_START_WITH_END, "GOMP_scope_start_with_end",
+                 BT_FN_VOID_PTR, ATTR_NOTHROW_LEAF_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_SCOPE_END, "GOMP_scope_end",
+                 BT_FN_VOID, ATTR_NOTHROW_LEAF_LIST)
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_OFFLOAD_REGISTER, "GOMP_offload_register_ver",
                  BT_FN_VOID_UINT_PTR_INT_PTR, ATTR_NOTHROW_LIST)
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_OFFLOAD_UNREGISTER,
index d87b6b6b29242bce63c6c406a5a3bfe7e16a3061..19ec304dc8111b9ff6c83950d933105834d2042f 100644 (file)
@@ -9035,10 +9035,18 @@ lower_omp_scope (gimple_stmt_iterator *gsi_p, omp_context *ctx)
                                 gimple_omp_scope_clauses (scope_stmt),
                                 &bind_body, &tred_dlist);
       rclauses = c;
-      tree fndecl = builtin_decl_explicit (BUILT_IN_GOMP_SCOPE_START);
+      tree fndecl = builtin_decl_explicit (
+       flag_openmp_ompt ? BUILT_IN_GOMP_SCOPE_START_WITH_END
+                        : BUILT_IN_GOMP_SCOPE_START);
       gimple *stmt = gimple_build_call (fndecl, 1, temp);
       gimple_seq_add_stmt (&bind_body, stmt);
     }
+  else if (flag_openmp_ompt)
+    {
+      tree fndecl = builtin_decl_explicit (BUILT_IN_GOMP_SCOPE_START_WITH_END);
+      gimple *stmt = gimple_build_call (fndecl, 1, null_pointer_node);
+      gimple_seq_add_stmt (&bind_body, stmt);
+    }
 
   lower_rec_input_clauses (gimple_omp_scope_clauses (scope_stmt),
                           &bind_body, &dlist, ctx, NULL);
@@ -9068,6 +9076,13 @@ lower_omp_scope (gimple_stmt_iterator *gsi_p, omp_context *ctx)
 
   bind_body = maybe_catch_exception (bind_body);
 
+  if (flag_openmp_ompt)
+    {
+      tree fndecl = builtin_decl_explicit (BUILT_IN_GOMP_SCOPE_END);
+      gcall *g = gimple_build_call (fndecl, 0);
+      gimple_seq_add_stmt (&bind_body_tail, g);
+    }
+
   bool nowait = omp_find_clause (gimple_omp_scope_clauses (scope_stmt),
                                 OMP_CLAUSE_NOWAIT) != NULL_TREE;
   gimple *g = gimple_build_omp_return (nowait);
diff --git a/gcc/testsuite/c-c++-common/gomp/scope-7.c b/gcc/testsuite/c-c++-common/gomp/scope-7.c
new file mode 100644 (file)
index 0000000..9db2fd1
--- /dev/null
@@ -0,0 +1,26 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-fopenmp-ompt -fdump-tree-omplower" } */
+
+/* Check that OMPT variants of libgomp calls are emitted for the scope
+   construct, both with and without a task reduction clause.  */
+
+int x;
+
+void
+f1 (void)
+{
+  #pragma omp scope
+  ;
+}
+
+void
+f2 (void)
+{
+#pragma omp scope reduction(task, + : x)
+  ;
+}
+
+/* { dg-final { scan-tree-dump-times "GOMP_scope_start_with_end \\(0B\\)" 1 "omplower" } } */
+/* { dg-final { scan-tree-dump-times "GOMP_scope_start_with_end \\(D\.\[0-9\]+\\)" 1 "omplower" } } */
+/* { dg-final { scan-tree-dump-times "GOMP_scope_end" 2 "omplower" } } */
+/* { dg-final { scan-tree-dump-not "GOMP_scope_start \\(" "omplower" } } */
diff --git a/gcc/testsuite/c-c++-common/gomp/scope-8.c b/gcc/testsuite/c-c++-common/gomp/scope-8.c
new file mode 100644 (file)
index 0000000..2a36b1a
--- /dev/null
@@ -0,0 +1,25 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-fdump-tree-omplower" } */
+
+/* Check that a single, non-OMPT variant of libgomp call is emitted for the
+   scope construct, only with a task reduction clause.  */
+
+int x;
+
+void
+f1 (void)
+{
+  #pragma omp scope
+  ;
+}
+
+void
+f2 (void)
+{
+  #pragma omp scope reduction(task, +:x)
+  ;
+}
+
+/* { dg-final { scan-tree-dump-times "GOMP_scope_start \\(" 1 "omplower" } } */
+/* { dg-final { scan-tree-dump-not "GOMP_scope_start_with_end" "omplower" } } */
+/* { dg-final { scan-tree-dump-not "GOMP_scope_end" "omplower" } } */
index 81bad4d232962006b68c5d33eb1c53a82a7f5d0c..8a59d4965b3934cfe6add47350888204a6a93599 100644 (file)
@@ -501,6 +501,8 @@ GOMP_6.0.2 {
        GOMP_reduction_end;
        GOMP_single_start_with_end;
        GOMP_single_end;
+       GOMP_scope_start_with_end;
+       GOMP_scope_end;
 } GOMP_6.0.1;
 
 OACC_2.0 {
index be3e349a4170d978557c142cf4489d78b1bcccc3..bc0589672d4389f1a9b90ed26648f49fa6e0677c 100644 (file)
@@ -357,6 +357,8 @@ extern void GOMP_single_copy_end (void *);
 /* scope.c */
 
 extern void GOMP_scope_start (uintptr_t *);
+extern void GOMP_scope_start_with_end (uintptr_t *);
+extern void GOMP_scope_end (void);
 
 /* target.c */
 
index df52e472e147b612497bce06eb7b5680d4afe805..00a8701d9f1dd9e4a70444367e76012ca06fb8ad 100644 (file)
@@ -60,3 +60,35 @@ GOMP_scope_start (uintptr_t *reductions)
                                              first_reductions);
     }
 }
+
+/* OMPT variant enabled by -fopenmp-ompt. Called at the beginning of every scope
+   construct even without reduction.  */
+
+void
+GOMP_scope_start_with_end (uintptr_t *reductions)
+{
+  if (!reductions)
+    return;
+
+  struct gomp_thread *thr = gomp_thread ();
+
+  gomp_workshare_taskgroup_start ();
+  if (gomp_work_share_start (0))
+    {
+      GOMP_taskgroup_reduction_register (reductions);
+      thr->task->taskgroup->workshare = true;
+      thr->ts.work_share->task_reductions = reductions;
+      gomp_work_share_init_done ();
+    }
+  else
+    {
+      uintptr_t *first_reductions = thr->ts.work_share->task_reductions;
+      gomp_workshare_task_reduction_register (reductions, first_reductions);
+    }
+}
+
+/* Stub for OMPT callback enabled by -fopenmp-ompt.  */
+
+void
+GOMP_scope_end (void)
+{}