]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
openmp: Add OMPT entry points for worksharing-loop, single, and masked constructs
authorPaul-Antoine Arras <parras@baylibre.com>
Tue, 30 Jun 2026 09:06:44 +0000 (11:06 +0200)
committerThomas Schwinge <tschwinge@baylibre.com>
Thu, 9 Jul 2026 22:06:31 +0000 (00:06 +0200)
Add two new compiler flags, -fopenmp-ompt and -fopenmp-ompt-detailed, that
cause the compiler to emit OMPT-aware runtime entry points around OpenMP
worksharing constructs.  With -fopenmp-ompt, the _start and _end variants
are called instead of the plain worksharing functions; with
-fopenmp-ompt-detailed, a _dispatch stub is additionally called after the
chunk bounds are computed.  New stubs are added to libgomp as placeholders
for future OMPT callback invocations.

gcc/ChangeLog:

* common.opt (fopenmp-ompt): New option.
(fopenmp-ompt-detailed): New option.
* common.opt.urls: Regenerate.
* doc/invoke.texi (Option Summary): Add -fopenmp-ompt and
-fopenmp-ompt-detailed.
(OpenMP and OpenACC Options): Document -fopenmp-ompt and
-fopenmp-ompt-detailed.
* omp-builtins.def (BUILT_IN_GOMP_SINGLE_START_WITH_END): New builtin.
(BUILT_IN_GOMP_SINGLE_END): New builtin.
(BUILT_IN_GOMP_MASKED_END): New builtin.
(BUILT_IN_GOMP_LOOP_STATIC_WORKSHARING_START): New builtin.
(BUILT_IN_GOMP_LOOP_STATIC_WORKSHARING_END): New builtin.
(BUILT_IN_GOMP_LOOP_STATIC_WORKSHARING_DISPATCH): New builtin.
(BUILT_IN_GOMP_DISTRIBUTE_STATIC_WORKSHARING_START): New builtin.
(BUILT_IN_GOMP_DISTRIBUTE_STATIC_WORKSHARING_END): New builtin.
(BUILT_IN_GOMP_DISTRIBUTE_STATIC_WORKSHARING_DISPATCH): New builtin.
* omp-expand.cc (expand_omp_for_static_nochunk): With -fopenmp-ompt,
emit _start and _end variants instead of the plain worksharing call;
with -fopenmp-ompt-detailed, also emit _dispatch.
(expand_omp_for_static_chunk): Likewise.
* omp-low.cc (lower_omp_single_simple): With -fopenmp-ompt, use
GOMP_single_start_with_end instead of GOMP_single_start.
(lower_omp_single): With -fopenmp-ompt, emit GOMP_single_end.
(lower_omp_master): With -fopenmp-ompt, emit GOMP_masked_end.
* opts.cc (finish_options): Diagnose -fopenmp-ompt and
-fopenmp-ompt-detailed used without -fopenmp.

libgomp/ChangeLog:

* config/gcn/teams.c (GOMP_distribute_static_worksharing_start,
GOMP_distribute_static_worksharing_dispatch,
GOMP_distribute_static_worksharing_end): New functions.
* config/nvptx/teams.c (GOMP_distribute_static_worksharing_start,
GOMP_distribute_static_worksharing_dispatch,
GOMP_distribute_static_worksharing_end): Likewise.
* libgomp.map (GOMP_6.0.2): Export new entry points.
* libgomp_g.h: Add prototypes for GOMP_loop_static_worksharing,
GOMP_loop_static_worksharing_start, GOMP_loop_static_worksharing_dispatch,
GOMP_loop_static_worksharing_end, GOMP_has_masked_thread_num,
GOMP_masked_end, GOMP_single_start_with_end, GOMP_single_end,
GOMP_distribute_static_worksharing_start,
GOMP_distribute_static_worksharing_dispatch, and
GOMP_distribute_static_worksharing_end.
* loop.c (GOMP_loop_static_worksharing): Move here from parallel.c.
(GOMP_loop_static_worksharing_start): New function.
(GOMP_loop_static_worksharing_dispatch): New stub.
(GOMP_loop_static_worksharing_end): New stub.
(GOMP_has_masked_thread_num): Move here from parallel.c.
(GOMP_masked_end): New stub.
* parallel.c (GOMP_loop_static_worksharing): Move to loop.c.
(GOMP_has_masked_thread_num): Move to loop.c.
* single.c (GOMP_single_start_with_end): New function.
(GOMP_single_end): New stub.
(GOMP_single_copy_start): Fix trailing whitespace.
* teams.c (GOMP_distribute_static_worksharing_start): New function.
(GOMP_distribute_static_worksharing_dispatch): New stub.
(GOMP_distribute_static_worksharing_end): New stub.
* testsuite/libgomp.c-c++-common/for-static-1.c: New test.
* testsuite/libgomp.c-c++-common/for-static-2.c: New test.
* testsuite/libgomp.c-c++-common/for-static-3.c: New test.
* testsuite/libgomp.c-c++-common/for-static.h: New test.

gcc/testsuite/ChangeLog:

* c-c++-common/gomp/masked-1.c: Add scan-tree-dump-not check that
GOMP_masked_end is not emitted without -fopenmp-ompt.
* c-c++-common/gomp/for-8.c: Remove; superseded by for-static-*.c.
* c-c++-common/gomp/for-static-1.c: New test; checks that the plain
worksharing builtins are emitted without -fopenmp-ompt.
* c-c++-common/gomp/for-static-2.c: New test; checks that _start and
_end variants are emitted with -fopenmp-ompt.
* c-c++-common/gomp/for-static-3.c: New test; checks that _dispatch is
also emitted with -fopenmp-ompt-detailed.
* c-c++-common/gomp/for-static.h: New shared test header.
* c-c++-common/gomp/masked-3.c: New test for GOMP_masked_end emission
with -fopenmp-ompt.
* c-c++-common/gomp/openmp-ompt-1.c: New test; checks that
-fopenmp-ompt without -fopenmp is diagnosed.
* c-c++-common/gomp/openmp-ompt-2.c: New test; checks that
-fopenmp-ompt-detailed without -fopenmp is diagnosed.
* c-c++-common/gomp/single2.c: New test for GOMP_single_start_with_end
and GOMP_single_end emission with -fopenmp-ompt.

29 files changed:
gcc/common.opt
gcc/common.opt.urls
gcc/doc/invoke.texi
gcc/omp-builtins.def
gcc/omp-expand.cc
gcc/omp-low.cc
gcc/opts.cc
gcc/testsuite/c-c++-common/gomp/for-8.c [deleted file]
gcc/testsuite/c-c++-common/gomp/for-static-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/for-static-2.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/for-static-3.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/for-static.h [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/masked-1.c
gcc/testsuite/c-c++-common/gomp/masked-3.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/openmp-ompt-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/openmp-ompt-2.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/single2.c [new file with mode: 0644]
libgomp/config/gcn/teams.c
libgomp/config/nvptx/teams.c
libgomp/libgomp.map
libgomp/libgomp_g.h
libgomp/loop.c
libgomp/parallel.c
libgomp/single.c
libgomp/teams.c
libgomp/testsuite/libgomp.c-c++-common/for-static-1.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/for-static-2.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/for-static-3.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/for-static.h [new file with mode: 0644]

index 0055578ccf60a2794caa30c5701824842bc6898e..ecebc186af774318a69902fb8bf91b3de2fb89e3 100644 (file)
@@ -2503,6 +2503,14 @@ fomit-frame-pointer
 Common Var(flag_omit_frame_pointer) Optimization
 When possible do not generate stack frames.
 
+fopenmp-ompt
+Common Var(flag_openmp_ompt) EnabledBy(fopenmp-ompt-detailed)
+Emit additional calls into libgomp, enabling OMPT callbacks before and after some OpenMP worksharing constructs.
+
+fopenmp-ompt-detailed
+Common Var(flag_openmp_ompt_detailed)
+Like -fopenmp-ompt, and emit additional calls into libgomp, enabling OMPT dispatch callbacks.
+
 fopenmp-target-simd-clone
 Common Alias(fopenmp-target-simd-clone=,any,none)
 
index 490146dde8c0ca4900fe75aade871024d8e01640..567a8dfc2d6a63c6ad1b5a25b6abe43be66b85e1 100644 (file)
@@ -1336,6 +1336,12 @@ UrlSuffix(gcc/OpenMP-and-OpenACC-Options.html#index-foffload-options)
 fomit-frame-pointer
 UrlSuffix(gcc/Optimize-Options.html#index-fno-omit-frame-pointer)
 
+fopenmp-ompt
+UrlSuffix(gcc/OpenMP-and-OpenACC-Options.html#index-fno-openmp-ompt)
+
+fopenmp-ompt-detailed
+UrlSuffix(gcc/OpenMP-and-OpenACC-Options.html#index-fno-openmp-ompt-detailed)
+
 fopenmp-target-simd-clone
 UrlSuffix(gcc/OpenMP-and-OpenACC-Options.html#index-fno-openmp-target-simd-clone)
 
index 606d666cd51b23446c691a367a871cdbefa1a6f9..354ceb76f5388b212a08d98b1d15c5f09a7ac707 100644 (file)
@@ -323,7 +323,8 @@ Objective-C and Objective-C++ Dialects}.
 @xref{OpenMP and OpenACC Options,,Options Controlling OpenMP and OpenACC}.
 @gccoptlist{-foffload=@var{arg}  -foffload-options=@var{arg}
 -fopenacc  -fopenacc-dim=@var{geom}
--fopenmp  -fopenmp-simd  -fopenmp-target-simd-clone@r{[}=@var{device-type}@r{]}}
+-fopenmp  -fopenmp-simd  -fopenmp-ompt  -fopenmp-ompt-detailed
+-fopenmp-target-simd-clone@r{[}=@var{device-type}@r{]}}
 
 @item Diagnostic Message Formatting Options
 @xref{Diagnostic Message Formatting Options,,Options to Control Diagnostic Messages Formatting}.
@@ -5601,6 +5602,24 @@ Fortran.  In fixed source form Fortran, the sentinels can also start with
 @option{-fopenmp} is additionally specified, the @code{loop} region binds
 to the current task region, independent of the specified @code{bind} clause.
 
+@opindex fopenmp-ompt
+@opindex fno-openmp-ompt
+@cindex OpenMP OMPT
+@item -fopenmp-ompt
+Emit additional calls into libgomp, enabling OMPT callbacks around some OpenMP
+worksharing constructs (namely statically scheduled @code{for} and
+@code{distribute}, @code{single}, @code{masked} and @code{master}), so that an
+OMPT tool can observe their start and end.  Requires @option{-fopenmp}.
+
+@opindex fopenmp-ompt-detailed
+@opindex fno-openmp-ompt-detailed
+@cindex OpenMP OMPT
+@item -fopenmp-ompt-detailed
+Like @option{-fopenmp-ompt}, and additionally emit calls into libgomp, enabling
+OMPT dispatch callbacks that get called at the beginning of each workshare chunk
+for statically scheduled @code{for} and @code{distribute}.  Requires
+@option{-fopenmp}.
+
 @opindex fopenmp-target-simd-clone
 @opindex fno-openmp-target-simd-clone
 @cindex OpenMP target SIMD clone
index d7440a42761bd923a3d6c2f4bd2acff2cca6b2f8..465aeebefdb74aa5e3ef7a0ce1bd59caddf34b19 100644 (file)
@@ -445,6 +445,11 @@ DEF_GOMP_BUILTIN (BUILT_IN_GOMP_SECTIONS_END_NOWAIT,
                  BT_FN_VOID, ATTR_NOTHROW_LEAF_LIST)
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_SINGLE_START, "GOMP_single_start",
                  BT_FN_BOOL, ATTR_NOTHROW_LEAF_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_SINGLE_START_WITH_END,
+                 "GOMP_single_start_with_end", BT_FN_BOOL,
+                 ATTR_NOTHROW_LEAF_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_SINGLE_END, "GOMP_single_end", BT_FN_VOID,
+                 ATTR_NOTHROW_LEAF_LIST)
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_SINGLE_COPY_START, "GOMP_single_copy_start",
                  BT_FN_PTR, ATTR_NOTHROW_LEAF_LIST)
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_SINGLE_COPY_END, "GOMP_single_copy_end",
@@ -503,9 +508,29 @@ 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_MASKED_END, "GOMP_masked_end", BT_FN_VOID,
+                 ATTR_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_LOOP_STATIC_WORKSHARING_START,
+                 "GOMP_loop_static_worksharing_start", BT_FN_COMPLEX_INT,
+                 ATTR_CONST_NOTHROW_LEAF_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_STATIC_WORKSHARING_END,
+                 "GOMP_loop_static_worksharing_end", BT_FN_VOID,
+                 ATTR_NOTHROW_LEAF_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_STATIC_WORKSHARING_DISPATCH,
+                 "GOMP_loop_static_worksharing_dispatch", BT_FN_VOID,
+                 ATTR_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)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_DISTRIBUTE_STATIC_WORKSHARING_START,
+                 "GOMP_distribute_static_worksharing_start", BT_FN_COMPLEX_INT,
+                 ATTR_CONST_NOTHROW_LEAF_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_DISTRIBUTE_STATIC_WORKSHARING_END,
+                 "GOMP_distribute_static_worksharing_end", BT_FN_VOID,
+                 ATTR_NOTHROW_LEAF_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_DISTRIBUTE_STATIC_WORKSHARING_DISPATCH,
+                 "GOMP_distribute_static_worksharing_dispatch", BT_FN_VOID,
+                 ATTR_NOTHROW_LEAF_LIST)
index 3d799d2803295dada49c4e871a76590eff2db7b8..ad380b27d06270d5649086fcea5b5138553ee791 100644 (file)
@@ -5201,10 +5201,14 @@ expand_omp_for_static_nochunk (struct omp_region *region,
   switch (gimple_omp_for_kind (fd->for_stmt))
     {
     case GF_OMP_FOR_KIND_FOR:
-      decl = builtin_decl_explicit (BUILT_IN_GOMP_LOOP_STATIC_WORKSHARING);
+      decl = builtin_decl_explicit (
+       flag_openmp_ompt ? BUILT_IN_GOMP_LOOP_STATIC_WORKSHARING_START
+                        : BUILT_IN_GOMP_LOOP_STATIC_WORKSHARING);
       break;
     case GF_OMP_FOR_KIND_DISTRIBUTE:
-      decl = builtin_decl_explicit (BUILT_IN_GOMP_DISTRIBUTE_STATIC_WORKSHARING);
+      decl = builtin_decl_explicit (
+       flag_openmp_ompt ? BUILT_IN_GOMP_DISTRIBUTE_STATIC_WORKSHARING_START
+                        : BUILT_IN_GOMP_DISTRIBUTE_STATIC_WORKSHARING);
       break;
     default:
       gcc_unreachable ();
@@ -5576,8 +5580,53 @@ expand_omp_for_static_nochunk (struct omp_region *region,
                                                   cont_bb, body_bb);
     }
 
-  /* Replace the GIMPLE_OMP_RETURN with a barrier, or nothing.  */
+  if (flag_openmp_ompt_detailed)
+    {
+      /* Insert call to GOMP_*_static_worksharing_dispatch at the end of
+        seq_start_bb.  */
+      gsi = gsi_last_nondebug_bb (seq_start_bb);
+      tree decl;
+      switch (gimple_omp_for_kind (fd->for_stmt))
+       {
+       case GF_OMP_FOR_KIND_FOR:
+         decl = builtin_decl_explicit (
+           BUILT_IN_GOMP_LOOP_STATIC_WORKSHARING_DISPATCH);
+         break;
+       case GF_OMP_FOR_KIND_DISTRIBUTE:
+         decl = builtin_decl_explicit (
+           BUILT_IN_GOMP_DISTRIBUTE_STATIC_WORKSHARING_DISPATCH);
+         break;
+       default:
+         gcc_unreachable ();
+       }
+      gcall *g = gimple_build_call (decl, 0);
+      gsi_insert_before (&gsi, g, GSI_SAME_STMT);
+    }
+
   gsi = gsi_last_nondebug_bb (exit_bb);
+  if (flag_openmp_ompt)
+    {
+      /* Insert call to GOMP_*_static_worksharing_end at the end of exit_bb.
+       */
+      tree decl;
+      switch (gimple_omp_for_kind (fd->for_stmt))
+       {
+       case GF_OMP_FOR_KIND_FOR:
+         decl
+           = builtin_decl_explicit (BUILT_IN_GOMP_LOOP_STATIC_WORKSHARING_END);
+         break;
+       case GF_OMP_FOR_KIND_DISTRIBUTE:
+         decl = builtin_decl_explicit (
+           BUILT_IN_GOMP_DISTRIBUTE_STATIC_WORKSHARING_END);
+         break;
+       default:
+         gcc_unreachable ();
+       }
+      gcall *g = gimple_build_call (decl, 0);
+      gsi_insert_after (&gsi, g, GSI_SAME_STMT);
+    }
+
+  /* Replace the GIMPLE_OMP_RETURN with a barrier, or nothing.  */
   if (!gimple_omp_return_nowait_p (gsi_stmt (gsi)))
     {
       t = gimple_omp_return_lhs (gsi_stmt (gsi));
@@ -5646,6 +5695,7 @@ expand_omp_for_static_nochunk (struct omp_region *region,
       exit3_bb = split_block (exit2_bb, g)->dest;
       gsi = gsi_after_labels (exit3_bb);
     }
+
   gsi_remove (&gsi, true);
 
   /* Connect all the blocks.  */
@@ -5969,10 +6019,14 @@ expand_omp_for_static_chunk (struct omp_region *region,
   switch (gimple_omp_for_kind (fd->for_stmt))
     {
     case GF_OMP_FOR_KIND_FOR:
-      decl = builtin_decl_explicit (BUILT_IN_GOMP_LOOP_STATIC_WORKSHARING);
+      decl = builtin_decl_explicit (
+       flag_openmp_ompt ? BUILT_IN_GOMP_LOOP_STATIC_WORKSHARING_START
+                        : BUILT_IN_GOMP_LOOP_STATIC_WORKSHARING);
       break;
     case GF_OMP_FOR_KIND_DISTRIBUTE:
-      decl = builtin_decl_explicit (BUILT_IN_GOMP_DISTRIBUTE_STATIC_WORKSHARING);
+      decl = builtin_decl_explicit (
+       flag_openmp_ompt ? BUILT_IN_GOMP_DISTRIBUTE_STATIC_WORKSHARING_START
+                        : BUILT_IN_GOMP_DISTRIBUTE_STATIC_WORKSHARING);
       break;
     default:
       gcc_unreachable ();
@@ -6303,8 +6357,30 @@ expand_omp_for_static_chunk (struct omp_region *region,
       gsi_insert_after (&gsi, assign_stmt, GSI_CONTINUE_LINKING);
     }
 
-  /* Replace the GIMPLE_OMP_RETURN with a barrier, or nothing.  */
   gsi = gsi_last_nondebug_bb (exit_bb);
+  if (flag_openmp_ompt)
+    {
+      /* Insert call to GOMP_*_static_worksharing_end at the end of exit_bb.
+       */
+      tree decl;
+      switch (gimple_omp_for_kind (fd->for_stmt))
+       {
+       case GF_OMP_FOR_KIND_FOR:
+         decl
+           = builtin_decl_explicit (BUILT_IN_GOMP_LOOP_STATIC_WORKSHARING_END);
+         break;
+       case GF_OMP_FOR_KIND_DISTRIBUTE:
+         decl = builtin_decl_explicit (
+           BUILT_IN_GOMP_DISTRIBUTE_STATIC_WORKSHARING_END);
+         break;
+       default:
+         gcc_unreachable ();
+       }
+      gcall *g = gimple_build_call (decl, 0);
+      gsi_insert_after (&gsi, g, GSI_SAME_STMT);
+    }
+
+  /* Replace the GIMPLE_OMP_RETURN with a barrier, or nothing.  */
   if (!gimple_omp_return_nowait_p (gsi_stmt (gsi)))
     {
       t = gimple_omp_return_lhs (gsi_stmt (gsi));
@@ -6340,6 +6416,29 @@ expand_omp_for_static_chunk (struct omp_region *region,
     }
   gsi_remove (&gsi, true);
 
+  if (flag_openmp_ompt_detailed)
+    {
+      /* Insert call to GOMP_*_static_worksharing_dispatch at the end of
+        seq_start_bb.  */
+      gsi = gsi_last_nondebug_bb (seq_start_bb);
+      tree decl;
+      switch (gimple_omp_for_kind (fd->for_stmt))
+       {
+       case GF_OMP_FOR_KIND_FOR:
+         decl = builtin_decl_explicit (
+           BUILT_IN_GOMP_LOOP_STATIC_WORKSHARING_DISPATCH);
+         break;
+       case GF_OMP_FOR_KIND_DISTRIBUTE:
+         decl = builtin_decl_explicit (
+           BUILT_IN_GOMP_DISTRIBUTE_STATIC_WORKSHARING_DISPATCH);
+         break;
+       default:
+         gcc_unreachable ();
+       }
+      gcall *g = gimple_build_call (decl, 0);
+      gsi_insert_before (&gsi, g, GSI_SAME_STMT);
+    }
+
   /* Connect the new blocks.  */
   find_edge (iter_part_bb, seq_start_bb)->flags = EDGE_TRUE_VALUE;
   find_edge (iter_part_bb, fin_bb)->flags = EDGE_FALSE_VALUE;
index ad5b2225d2798a1f21257c900ba7ca1d0a41c4cc..c578e8ece49a9fa5c519a47d78f233386f6d4c7a 100644 (file)
@@ -8825,7 +8825,9 @@ lower_omp_single_simple (gomp_single *single_stmt, gimple_seq *pre_p)
   gimple *call, *cond;
   tree lhs, decl;
 
-  decl = builtin_decl_explicit (BUILT_IN_GOMP_SINGLE_START);
+  decl = builtin_decl_explicit (flag_openmp_ompt
+                                 ? BUILT_IN_GOMP_SINGLE_START_WITH_END
+                                 : BUILT_IN_GOMP_SINGLE_START);
   lhs = create_tmp_var (TREE_TYPE (TREE_TYPE (decl)));
   call = gimple_build_call (decl, 0);
   gimple_call_set_lhs (call, lhs);
@@ -8962,6 +8964,15 @@ lower_omp_single (gimple_stmt_iterator *gsi_p, omp_context *ctx)
   gimple *g = gimple_build_omp_return (nowait);
   gimple_seq_add_stmt (&bind_body_tail, g);
   maybe_add_implicit_barrier_cancel (ctx, g, &bind_body_tail);
+
+  if (flag_openmp_ompt && !ctx->record_type)
+    {
+      /* Insert call to GOMP_single_end.  */
+      tree decl = builtin_decl_explicit (BUILT_IN_GOMP_SINGLE_END);
+      gimple *stmt = gimple_build_call (decl, 0);
+      gimple_seq_add_stmt (&bind_body_tail, stmt);
+    }
+
   if (ctx->record_type)
     {
       gimple_stmt_iterator gsi = gsi_start (bind_body_tail);
@@ -9138,6 +9149,14 @@ lower_omp_master (gimple_stmt_iterator *gsi_p, omp_context *ctx)
   gimple_bind_add_seq (bind, gimple_omp_body (stmt));
   gimple_omp_set_body (stmt, NULL);
 
+  if (flag_openmp_ompt)
+    {
+      /* Insert call to GOMP_masked_end at the end of the body.  */
+      tree decl = builtin_decl_explicit (BUILT_IN_GOMP_MASKED_END);
+      gcall *g = gimple_build_call (decl, 0);
+      gimple_bind_add_stmt (bind, g);
+    }
+
   gimple_bind_add_stmt (bind, gimple_build_label (lab));
 
   gimple_bind_add_stmt (bind, gimple_build_omp_return (true));
index 5522f41f90698e17fc189590b7dbb808f9e0cd95..0d96fb6d78e577b01ce809de4aa39d484c02829b 100644 (file)
@@ -1537,6 +1537,12 @@ finish_options (struct gcc_options *opts, struct gcc_options *opts_set,
                    " %<-fstrict-flex-arrays%> is not present");
       }
 
+  if ((opts->x_flag_openmp_ompt || opts->x_flag_openmp_ompt_detailed)
+      && !opts->x_flag_openmp)
+    error_at (
+      loc,
+      "%<-fopenmp-ompt%> and %<-fopenmp-ompt-detailed%> require %<-fopenmp%>");
+
   diagnose_options (opts, opts_set, loc);
 }
 
diff --git a/gcc/testsuite/c-c++-common/gomp/for-8.c b/gcc/testsuite/c-c++-common/gomp/for-8.c
deleted file mode 100644 (file)
index a894aaa..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/* { 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" } } */
diff --git a/gcc/testsuite/c-c++-common/gomp/for-static-1.c b/gcc/testsuite/c-c++-common/gomp/for-static-1.c
new file mode 100644 (file)
index 0000000..50d4e17
--- /dev/null
@@ -0,0 +1,17 @@
+/* { 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.  */
+
+#include "for-static.h"
+
+/* { dg-final { scan-tree-dump-times "GOMP_loop_static_worksharing \\(" 2 "ompexp" } } */
+/* { dg-final { scan-tree-dump-times "GOMP_distribute_static_worksharing \\(" 2 "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" } } */
diff --git a/gcc/testsuite/c-c++-common/gomp/for-static-2.c b/gcc/testsuite/c-c++-common/gomp/for-static-2.c
new file mode 100644 (file)
index 0000000..c3d25b9
--- /dev/null
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-fopenmp-ompt -fdump-tree-ompexp" } */
+
+/* Check that, with -fopenmp-ompt, the _start and _end variants are called.  */
+
+#include "for-static.h"
+
+/* { dg-final { scan-tree-dump-times "GOMP_loop_static_worksharing_start \\(" 2 "ompexp" } } */
+/* { dg-final { scan-tree-dump-times "GOMP_loop_static_worksharing_end \\(" 2 "ompexp" } } */
+/* { dg-final { scan-tree-dump-times "GOMP_distribute_static_worksharing_start \\(" 2 "ompexp" } } */
+/* { dg-final { scan-tree-dump-times "GOMP_distribute_static_worksharing_end \\(" 2 "ompexp" } } */
+/* { dg-final { scan-tree-dump-not "GOMP_loop_static_worksharing \\(" "ompexp" } } */
+/* { dg-final { scan-tree-dump-not "GOMP_loop_static_worksharing_dispatch" "ompexp" } } */
+/* { dg-final { scan-tree-dump-not "GOMP_distribute_static_worksharing \\(" "ompexp" } } */
+/* { dg-final { scan-tree-dump-not "GOMP_distribute_static_worksharing_dispatch" "ompexp" } } */
diff --git a/gcc/testsuite/c-c++-common/gomp/for-static-3.c b/gcc/testsuite/c-c++-common/gomp/for-static-3.c
new file mode 100644 (file)
index 0000000..6fd1da6
--- /dev/null
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-fopenmp-ompt-detailed -fdump-tree-ompexp" } */
+
+/* Check that, with -fopenmp-ompt-detailed, _dispatch builtins are called along
+   with the _start and _end variants.  */
+
+#include "for-static.h"
+
+/* { dg-final { scan-tree-dump-times "GOMP_loop_static_worksharing_start \\(" 2 "ompexp" } } */
+/* { dg-final { scan-tree-dump-times "GOMP_loop_static_worksharing_dispatch \\(" 2 "ompexp" } } */
+/* { dg-final { scan-tree-dump-times "GOMP_loop_static_worksharing_end \\(" 2 "ompexp" } } */
+/* { dg-final { scan-tree-dump-times "GOMP_distribute_static_worksharing_start \\(" 2 "ompexp" } } */
+/* { dg-final { scan-tree-dump-times "GOMP_distribute_static_worksharing_dispatch \\(" 2 "ompexp" } } */
+/* { dg-final { scan-tree-dump-times "GOMP_distribute_static_worksharing_end \\(" 2 "ompexp" } } */
diff --git a/gcc/testsuite/c-c++-common/gomp/for-static.h b/gcc/testsuite/c-c++-common/gomp/for-static.h
new file mode 100644 (file)
index 0000000..6504c75
--- /dev/null
@@ -0,0 +1,51 @@
+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);
+}
index 8de87b551e30212b5f0eaf3cd8cc915331dc51a9..28d2735d96e3de153bb8085b56b562940a4cedde 100644 (file)
@@ -26,4 +26,5 @@ foo (int x, int *a)
 }
 
 /* { dg-final { scan-tree-dump "GOMP_has_masked_thread_num" "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
new file mode 100644 (file)
index 0000000..adea59f
--- /dev/null
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-fopenmp-ompt -fdump-tree-omplower" } */
+
+void bar (void);
+
+void
+foo (void)
+{
+  #pragma omp masked
+  bar ();
+}
+
+/* { dg-final { scan-tree-dump-times "GOMP_has_masked_thread_num" 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/gcc/testsuite/c-c++-common/gomp/openmp-ompt-1.c b/gcc/testsuite/c-c++-common/gomp/openmp-ompt-1.c
new file mode 100644 (file)
index 0000000..0a45c2b
--- /dev/null
@@ -0,0 +1,4 @@
+/* { dg-do compile } */
+/* { dg-options "-fopenmp-ompt" } */
+
+/* { dg-error ".-fopenmp-ompt. and .-fopenmp-ompt-detailed. require .-fopenmp." "" { target *-*-* } 0 } */
diff --git a/gcc/testsuite/c-c++-common/gomp/openmp-ompt-2.c b/gcc/testsuite/c-c++-common/gomp/openmp-ompt-2.c
new file mode 100644 (file)
index 0000000..f93f692
--- /dev/null
@@ -0,0 +1,4 @@
+/* { dg-do compile } */
+/* { dg-options "-fopenmp-ompt-detailed" } */
+
+/* { dg-error ".-fopenmp-ompt. and .-fopenmp-ompt-detailed. require .-fopenmp." "" { target *-*-* } 0 } */
diff --git a/gcc/testsuite/c-c++-common/gomp/single2.c b/gcc/testsuite/c-c++-common/gomp/single2.c
new file mode 100644 (file)
index 0000000..215f036
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-fopenmp-ompt -fdump-tree-ompexp" } */
+
+void
+foo (void)
+{
+  #pragma omp single
+    ;
+}
+
+/* { dg-final { scan-tree-dump-times "GOMP_single_start_with_end" 1 "ompexp" } } */
+/* { dg-final { scan-tree-dump-times "GOMP_single_end" 1 "ompexp" } } */
+/* { dg-final { scan-tree-dump-not "GOMP_single_start \\(" "ompexp" } } */
index 5aa8b15502aa56ede257ade6294d6079a76de9e3..99f807ac87661e1ab21ad7d075817f178aa4d0cb 100644 (file)
@@ -50,6 +50,29 @@ GOMP_distribute_static_worksharing (void)
   return nteams + tid * 1I;
 }
 
+/* OMPT variant enabled by -fopenmp-ompt.  */
+
+_Complex int
+GOMP_distribute_static_worksharing_start (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;
+}
+
+/* Stub for OMPT callback enabled by -fopenmp-ompt-detailed.  */
+
+void
+GOMP_distribute_static_worksharing_dispatch (void)
+{}
+
+/* Stub for OMPT callback enabled by -fopenmp-ompt.  */
+
+void
+GOMP_distribute_static_worksharing_end (void)
+{}
+
 int
 omp_get_num_teams (void)
 {
index 9763f6f41084dac1d23990e465c2c963fab68732..3e6ea2872766312a272babe3335edf3f11c9d637 100644 (file)
@@ -52,6 +52,27 @@ GOMP_distribute_static_worksharing (void)
   return nteams + tid * 1I;
 }
 
+/* OMPT variant enabled by -fopenmp-ompt.  */
+
+_Complex int
+GOMP_distribute_static_worksharing_start (void)
+{
+  unsigned tid = __gomp_team_num;
+  unsigned nteams = gomp_num_teams_var + 1;
+  return nteams + tid * 1I;
+}
+
+/* Stub for OMPT callback enabled by -fopenmp-ompt-detailed.  */
+
+void
+GOMP_distribute_static_worksharing_dispatch (void)
+{}
+
+/* Stub for OMPT callback enabled by -fopenmp-ompt.  */
+
+void
+GOMP_distribute_static_worksharing_end (void)
+{}
 int
 omp_get_num_teams (void)
 {
index e2985347bf778651cf1deedbcdb824c87614a525..3f465cc14916086794bd3da1eb7b1ea069d2ad86 100644 (file)
@@ -485,12 +485,21 @@ GOMP_6.0.1 {
 GOMP_6.0.2 {
   global:
        GOMP_has_masked_thread_num;
+       GOMP_masked_end;
        GOMP_loop_static_worksharing;
+       GOMP_loop_static_worksharing_start;
+       GOMP_loop_static_worksharing_dispatch;
+       GOMP_loop_static_worksharing_end;
        GOMP_distribute_static_worksharing;
+       GOMP_distribute_static_worksharing_start;
+       GOMP_distribute_static_worksharing_dispatch;
+       GOMP_distribute_static_worksharing_end;
        GOMP_barrier_ext;
        GOMP_barrier_cancel_ext;
        GOMP_reduction_start;
        GOMP_reduction_end;
+       GOMP_single_start_with_end;
+       GOMP_single_end;
 } GOMP_6.0.1;
 
 OACC_2.0 {
index a3097d5b0936f187be2ba87f719ac426c0b6ef63..4a3565684cc955febfbbc76b0ffc10ef567bf283 100644 (file)
@@ -144,6 +144,11 @@ extern void GOMP_loop_end (void);
 extern void GOMP_loop_end_nowait (void);
 extern bool GOMP_loop_end_cancel (void);
 
+extern __complex__ int GOMP_loop_static_worksharing (void);
+extern __complex__ int GOMP_loop_static_worksharing_start (void);
+extern void GOMP_loop_static_worksharing_dispatch (void);
+extern void GOMP_loop_static_worksharing_end (void);
+
 /* loop_ull.c */
 
 extern bool GOMP_loop_ull_static_start (bool, unsigned long long,
@@ -298,7 +303,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 __complex__ int GOMP_loop_static_worksharing (void);
+extern void GOMP_masked_end (void);
 
 /* task.c */
 
@@ -339,6 +344,8 @@ extern bool GOMP_sections_end_cancel (void);
 /* single.c */
 
 extern bool GOMP_single_start (void);
+extern bool GOMP_single_start_with_end (void);
+extern void GOMP_single_end (void);
 extern void *GOMP_single_copy_start (void);
 extern void GOMP_single_copy_end (void *);
 
@@ -380,6 +387,9 @@ extern void *GOMP_target_map_indirect_ptr (void *);
 extern void GOMP_teams_reg (void (*) (void *), void *, unsigned, unsigned,
                            unsigned);
 extern __complex__ int GOMP_distribute_static_worksharing (void);
+extern __complex__ int GOMP_distribute_static_worksharing_start (void);
+extern void GOMP_distribute_static_worksharing_dispatch (void);
+extern void GOMP_distribute_static_worksharing_end (void);
 
 /* allocator.c */
 
index e3fbeb1c4de9868a3afedf28c3c85b965f66e5b0..f286ce6b6db58f76ec3af2f94ddfe303caa11334 100644 (file)
@@ -1186,3 +1186,38 @@ GOMP_loop_ordered_guided_next (long *istart, long *iend)
   return gomp_loop_ordered_guided_next (istart, iend);
 }
 #endif
+
+/* 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;
+}
+
+/* OMPT variant enabled by -fopenmp-ompt.  */
+
+_Complex int
+GOMP_loop_static_worksharing_start (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;
+}
+
+/* Stub for OMPT callback enabled by -fopenmp-ompt-detailed.  */
+
+void
+GOMP_loop_static_worksharing_dispatch (void)
+{}
+
+/* Stub for OMPT callback enabled by -fopenmp-ompt.  */
+
+void
+GOMP_loop_static_worksharing_end (void)
+{}
index 92472ecb4f0e56785ff07ecf62669b5a2d660269..bb522b39ecb1abd0bb9035e842865f38c4903703 100644 (file)
@@ -271,18 +271,6 @@ GOMP_cancel (int which, bool do_cancel)
   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.  */
 
@@ -291,6 +279,12 @@ GOMP_has_masked_thread_num (int tid)
 {
   return tid == gomp_thread ()->ts.team_id;
 }
+
+/* Stub for OMPT callback enabled by -fopenmp-ompt.  */
+
+void
+GOMP_masked_end (void)
+{}
 \f
 /* The public OpenMP API for thread and team related inquiries.  */
 
index 65126000ea9af69b2e8ab1dd0b288d7ff01976bf..00a84e1c9c1c8cd7b5008d8b2845839e7baee4ae 100644 (file)
@@ -55,6 +55,37 @@ GOMP_single_start (void)
 #endif
 }
 
+/* OMPT variant enabled by -fopenmp-ompt.  */
+
+bool
+GOMP_single_start_with_end (void)
+{
+#ifdef HAVE_SYNC_BUILTINS
+  struct gomp_thread *thr = gomp_thread ();
+  struct gomp_team *team = thr->ts.team;
+  unsigned long single_count;
+
+  if (__builtin_expect (team == NULL, 0))
+    return true;
+
+  single_count = thr->ts.single_count++;
+  return __sync_bool_compare_and_swap (&team->single_count, single_count,
+                                      single_count + 1L);
+#else
+  bool ret = gomp_work_share_start (0);
+  if (ret)
+    gomp_work_share_init_done ();
+  gomp_work_share_end_nowait ();
+  return ret;
+#endif
+}
+
+/* Stub for OMPT callback enabled by -fopenmp-ompt.  */
+
+void
+GOMP_single_end (void)
+{}
+
 /* This routine is called when first encountering a SINGLE construct that
    does have a COPYPRIVATE clause.  Returns NULL if this is the thread
    that should execute the clause; otherwise the return value is pointer
@@ -69,7 +100,7 @@ GOMP_single_copy_start (void)
   void *ret;
 
   first = gomp_work_share_start (0);
-  
+
   if (first)
     {
       gomp_work_share_init_done ();
index 7038623b2dfb4160ed973827dcd702275167a438..f501123d6479d5eb99b935706d76dd1c58fa4de0 100644 (file)
@@ -70,6 +70,29 @@ GOMP_distribute_static_worksharing (void)
   return nteams + tid * 1I;
 }
 
+/* OMPT variant enabled by -fopenmp-ompt.  */
+
+_Complex int
+GOMP_distribute_static_worksharing_start (void)
+{
+  struct gomp_thread *thr = gomp_thread ();
+  unsigned tid = thr->team_num;
+  unsigned nteams = thr->num_teams + 1;
+  return nteams + tid * 1I;
+}
+
+/* Stub for OMPT callback enabled by -fopenmp-ompt-detailed.  */
+
+void
+GOMP_distribute_static_worksharing_dispatch (void)
+{}
+
+/* Stub for OMPT callback enabled by -fopenmp-ompt.  */
+
+void
+GOMP_distribute_static_worksharing_end (void)
+{}
+
 int
 omp_get_num_teams (void)
 {
diff --git a/libgomp/testsuite/libgomp.c-c++-common/for-static-1.c b/libgomp/testsuite/libgomp.c-c++-common/for-static-1.c
new file mode 100644 (file)
index 0000000..b304c8c
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-do link { target offload_target_any } } */
+/* { dg-additional-options "-O0 -foffload=-fdump-tree-optimized" } */
+
+/* Check that the static distribute expanders fetch the team id and count
+   through a single GOMP_distribute_static_worksharing call rather than separate
+   omp_get_team_num and omp_get_num_teams calls, and that this function exists
+   on the target side.  */
+
+#include "for-static.h"
+
+/* { dg-final { scan-offload-tree-dump-times "GOMP_distribute_static_worksharing \\(" 2 "optimized" } } */
+/* { dg-final { scan-offload-tree-dump-not "omp_get_num_teams" "optimized" } } */
+/* { dg-final { scan-offload-tree-dump-not "omp_get_team_num" "optimized" } } */
diff --git a/libgomp/testsuite/libgomp.c-c++-common/for-static-2.c b/libgomp/testsuite/libgomp.c-c++-common/for-static-2.c
new file mode 100644 (file)
index 0000000..83e577a
--- /dev/null
@@ -0,0 +1,11 @@
+/* { dg-do link { target offload_target_any } } */
+/* { dg-additional-options "-O0 -foffload=-fdump-tree-optimized -fopenmp-ompt" } */
+
+/* Check that, with -fopenmp-ompt, the _start and _end variants are called.  */
+
+#include "for-static.h"
+
+/* { dg-final { scan-offload-tree-dump-times "GOMP_distribute_static_worksharing_start \\(" 2 "optimized" } } */
+/* { dg-final { scan-offload-tree-dump-times "GOMP_distribute_static_worksharing_end \\(" 2 "optimized" } } */
+/* { dg-final { scan-offload-tree-dump-not "GOMP_distribute_static_worksharing \\(" "optimized" } } */
+/* { dg-final { scan-offload-tree-dump-not "GOMP_distribute_static_worksharing_dispatch" "optimized" } } */
diff --git a/libgomp/testsuite/libgomp.c-c++-common/for-static-3.c b/libgomp/testsuite/libgomp.c-c++-common/for-static-3.c
new file mode 100644 (file)
index 0000000..e7b904e
--- /dev/null
@@ -0,0 +1,11 @@
+/* { dg-do link { target offload_target_any } } */
+/* { dg-additional-options "-O0 -foffload=-fdump-tree-optimized -fopenmp-ompt-detailed" } */
+
+/* Check that, with -fopenmp-ompt-detailed, _dispatch builtins are called along
+   with the _start and _end variants.  */
+
+#include "for-static.h"
+
+/* { dg-final { scan-offload-tree-dump-times "GOMP_distribute_static_worksharing_start \\(" 2 "optimized" } } */
+/* { dg-final { scan-offload-tree-dump-times "GOMP_distribute_static_worksharing_dispatch \\(" 2 "optimized" } } */
+/* { dg-final { scan-offload-tree-dump-times "GOMP_distribute_static_worksharing_end \\(" 2 "optimized" } } */
diff --git a/libgomp/testsuite/libgomp.c-c++-common/for-static.h b/libgomp/testsuite/libgomp.c-c++-common/for-static.h
new file mode 100644 (file)
index 0000000..a6c0e05
--- /dev/null
@@ -0,0 +1,37 @@
+void bar (int a)
+{}
+
+/* Distribute without a chunk size goes through
+   expand_omp_for_static_nochunk.  */
+
+void
+f3 (int n)
+{
+  int i;
+#pragma omp target
+#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 target
+#pragma omp teams
+#pragma omp distribute dist_schedule(static, 4)
+  for (i = 0; i < n; ++i)
+    bar (i);
+}
+
+int main (void)
+{
+  f3(0);
+  f4(1);
+  return 0;
+}