https://gcc.gnu.org/g:ccf32d2937db034528658477ecb13de793096c6f

commit r17-2473-gccf32d2937db034528658477ecb13de793096c6f
Author: Paul-Antoine Arras <[email protected]>
Date:   Wed Jul 15 20:41:45 2026 +0200

    openmp: Pass loop parameters to static worksharing dispatch builtins for 
OMPT
    
    The GOMP_*_static_worksharing_dispatch builtins took no arguments and the
    OMPT dispatch callback was missing information about the loop. Pass the 
loop's
    iteration count, start, step, chunk size, and the thread's starting
    iteration instead.
    
    gcc/ChangeLog:
    
            * builtin-types.def 
(BT_FN_VOID_ULONGLONG_ULONGLONG_ULONGLONG_ULONGLONG_ULONGLONG): New.
            * omp-builtins.def 
(BUILT_IN_GOMP_LOOP_STATIC_WORKSHARING_DISPATCH): Use
            BT_FN_VOID_ULONGLONG_ULONGLONG_ULONGLONG_ULONGLONG_ULONGLONG.
            (BUILT_IN_GOMP_DISTRIBUTE_STATIC_WORKSHARING_DISPATCH): Likewise.
            * omp-expand.cc (expand_omp_for_static_nochunk): Pass niter, start,
            incr, chunk size, and istart to the dispatch call.
            (expand_omp_for_static_chunk): Likewise.
    
    gcc/fortran/ChangeLog:
    
            * types.def 
(BT_FN_VOID_ULONGLONG_ULONGLONG_ULONGLONG_ULONGLONG_ULONGLONG): New.
    
    libgomp/ChangeLog:
    
            * config/gcn/teams.c (GOMP_distribute_static_worksharing_dispatch): 
Add
            niter, start, incr, chunk_size, and istart parameters (unused).
            * config/nvptx/teams.c 
(GOMP_distribute_static_worksharing_dispatch):
            Likewise.
            * libgomp_g.h (GOMP_loop_static_worksharing_dispatch): Update 
prototype.
            (GOMP_distribute_static_worksharing_dispatch): Likewise.
            * loop.c (GOMP_loop_static_worksharing_dispatch): Add niter, start,
            incr, chunk_size, and istart parameters (unused).
            * teams.c (GOMP_distribute_static_worksharing_dispatch): Likewise.
            * testsuite/libgomp.c-c++-common/for-static-3.c: Update scan pattern
            to match new arguments.
    
    gcc/testsuite/ChangeLog:
    
            * c-c++-common/gomp/for-static-3.c: Update scan pattern to match new
            arguments.

Diff:
---
 gcc/builtin-types.def                              |  2 ++
 gcc/fortran/types.def                              |  2 ++
 gcc/omp-builtins.def                               |  6 ++++--
 gcc/omp-expand.cc                                  | 23 ++++++++++++++++++----
 gcc/testsuite/c-c++-common/gomp/for-static-3.c     |  6 ++++--
 libgomp/config/gcn/teams.c                         | 13 ++++++++++--
 libgomp/config/nvptx/teams.c                       | 13 ++++++++++--
 libgomp/libgomp_g.h                                | 12 +++++++++--
 libgomp/loop.c                                     | 13 ++++++++++--
 libgomp/teams.c                                    | 13 ++++++++++--
 .../testsuite/libgomp.c-c++-common/for-static-3.c  |  3 ++-
 11 files changed, 87 insertions(+), 19 deletions(-)

diff --git a/gcc/builtin-types.def b/gcc/builtin-types.def
index d11e6e736a2b..4725668643d7 100644
--- a/gcc/builtin-types.def
+++ b/gcc/builtin-types.def
@@ -945,6 +945,8 @@ DEF_FUNCTION_TYPE_5 
(BT_FN_BOOL_UINT_LONGPTR_LONG_LONGPTR_LONGPTR,
 DEF_FUNCTION_TYPE_5 (BT_FN_BOOL_UINT_ULLPTR_ULL_ULLPTR_ULLPTR,
                     BT_BOOL, BT_UINT, BT_PTR_ULONGLONG, BT_ULONGLONG,
                     BT_PTR_ULONGLONG, BT_PTR_ULONGLONG)
+DEF_FUNCTION_TYPE_5 
(BT_FN_VOID_ULONGLONG_ULONGLONG_ULONGLONG_ULONGLONG_ULONGLONG,
+                    BT_VOID, BT_ULONGLONG, BT_ULONGLONG, BT_ULONGLONG, 
BT_ULONGLONG, BT_ULONGLONG)
 
 DEF_FUNCTION_TYPE_6 (BT_FN_INT_STRING_SIZE_INT_SIZE_CONST_STRING_VALIST_ARG,
                     BT_INT, BT_STRING, BT_SIZE, BT_INT, BT_SIZE,
diff --git a/gcc/fortran/types.def b/gcc/fortran/types.def
index b694e6893600..30c1050d87d4 100644
--- a/gcc/fortran/types.def
+++ b/gcc/fortran/types.def
@@ -198,6 +198,8 @@ DEF_FUNCTION_TYPE_5 
(BT_FN_BOOL_UINT_LONGPTR_LONG_LONGPTR_LONGPTR,
 DEF_FUNCTION_TYPE_5 (BT_FN_BOOL_UINT_ULLPTR_ULL_ULLPTR_ULLPTR,
                     BT_BOOL, BT_UINT, BT_PTR_ULONGLONG, BT_ULONGLONG,
                     BT_PTR_ULONGLONG, BT_PTR_ULONGLONG)
+DEF_FUNCTION_TYPE_5 
(BT_FN_VOID_ULONGLONG_ULONGLONG_ULONGLONG_ULONGLONG_ULONGLONG,
+                    BT_VOID, BT_ULONGLONG, BT_ULONGLONG, BT_ULONGLONG, 
BT_ULONGLONG, BT_ULONGLONG)
 
 DEF_FUNCTION_TYPE_6 (BT_FN_BOOL_LONG_LONG_LONG_LONG_LONGPTR_LONGPTR,
                      BT_BOOL, BT_LONG, BT_LONG, BT_LONG, BT_LONG,
diff --git a/gcc/omp-builtins.def b/gcc/omp-builtins.def
index 3b0d5572043a..121bdcb61a33 100644
--- a/gcc/omp-builtins.def
+++ b/gcc/omp-builtins.def
@@ -523,7 +523,8 @@ 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,
+                 "GOMP_loop_static_worksharing_dispatch",
+                 BT_FN_VOID_ULONGLONG_ULONGLONG_ULONGLONG_ULONGLONG_ULONGLONG,
                  ATTR_NOTHROW_LEAF_LIST)
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_DISTRIBUTE_STATIC_WORKSHARING,
                  "GOMP_distribute_static_worksharing",
@@ -537,5 +538,6 @@ 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,
+                 "GOMP_distribute_static_worksharing_dispatch",
+                 BT_FN_VOID_ULONGLONG_ULONGLONG_ULONGLONG_ULONGLONG_ULONGLONG,
                  ATTR_NOTHROW_LEAF_LIST)
diff --git a/gcc/omp-expand.cc b/gcc/omp-expand.cc
index ca4d5d0db9e5..cf992eab835f 100644
--- a/gcc/omp-expand.cc
+++ b/gcc/omp-expand.cc
@@ -5602,8 +5602,15 @@ expand_omp_for_static_nochunk (struct omp_region *region,
        default:
          gcc_unreachable ();
        }
-      gcall *g = gimple_build_call (decl, 0);
-      gsi_insert_before (&gsi, g, GSI_SAME_STMT);
+      tree n_ull = fold_convert (long_long_unsigned_type_node, n);
+      tree n1_ull = fold_convert (long_long_unsigned_type_node, n1);
+      tree step_ull = fold_convert (long_long_unsigned_type_node, step);
+      tree chunk_size_ull = build_int_cst (long_long_unsigned_type_node, 0);
+      tree v_ull = fold_convert (long_long_unsigned_type_node, fd->loop.v);
+      tree call = build_call_expr (decl, 5, n_ull, n1_ull, step_ull,
+                                  chunk_size_ull, v_ull);
+      force_gimple_operand_gsi (&gsi, call, true, NULL_TREE, true,
+                               GSI_SAME_STMT);
     }
 
   gsi = gsi_last_nondebug_bb (exit_bb);
@@ -6441,8 +6448,16 @@ expand_omp_for_static_chunk (struct omp_region *region,
        default:
          gcc_unreachable ();
        }
-      gcall *g = gimple_build_call (decl, 0);
-      gsi_insert_before (&gsi, g, GSI_SAME_STMT);
+      tree n_ull = fold_convert (long_long_unsigned_type_node, n);
+      tree n1_ull = fold_convert (long_long_unsigned_type_node, n1);
+      tree step_ull = fold_convert (long_long_unsigned_type_node, step);
+      tree chunk_size_ull
+       = fold_convert (long_long_unsigned_type_node, chunk_size);
+      tree v_ull = fold_convert (long_long_unsigned_type_node, fd->loop.v);
+      tree call = build_call_expr (decl, 5, n_ull, n1_ull, step_ull,
+                                  chunk_size_ull, v_ull);
+      force_gimple_operand_gsi (&gsi, call, true, NULL_TREE, true,
+                               GSI_SAME_STMT);
     }
 
   /* Connect the new blocks.  */
diff --git a/gcc/testsuite/c-c++-common/gomp/for-static-3.c 
b/gcc/testsuite/c-c++-common/gomp/for-static-3.c
index 8e45223c3538..950edab0779c 100644
--- a/gcc/testsuite/c-c++-common/gomp/for-static-3.c
+++ b/gcc/testsuite/c-c++-common/gomp/for-static-3.c
@@ -8,11 +8,13 @@
 
 /* { dg-final { scan-tree-dump-not "GOMP_loop_static_worksharing \\(" "ompexp" 
} } */
 /* { 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_dispatch 
\\(\[^,\]+, \[^,\]+, \[^,\]+, 0, \[^)\]+\\)" 1 "ompexp" } } */
+/* { dg-final { scan-tree-dump-times "GOMP_loop_static_worksharing_dispatch 
\\(\[^,\]+, \[^,\]+, \[^,\]+, 4, \[^)\]+\\)" 1 "ompexp" } } */
 /* { dg-final { scan-tree-dump-times "GOMP_loop_static_worksharing_end \\(\\)" 
2 "ompexp" } } */
 /* { dg-final { scan-tree-dump-not "GOMP_distribute_static_worksharing \\(" 
"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_dispatch \\(\[^,\]+, \[^,\]+, \[^,\]+, 0, 
\[^)\]+\\)" 1 "ompexp" } } */
+/* { dg-final { scan-tree-dump-times 
"GOMP_distribute_static_worksharing_dispatch \\(\[^,\]+, \[^,\]+, \[^,\]+, 4, 
\[^)\]+\\)" 1 "ompexp" } } */
 /* { dg-final { scan-tree-dump-times "GOMP_distribute_static_worksharing_end 
\\(\\)" 2 "ompexp" } } */
 /* { dg-final { scan-tree-dump-not "omp_get_num_threads" "ompexp" } } */
 /* { dg-final { scan-tree-dump-not "omp_get_thread_num" "ompexp" } } */
diff --git a/libgomp/config/gcn/teams.c b/libgomp/config/gcn/teams.c
index 4354131f9b76..7000e99fb32b 100644
--- a/libgomp/config/gcn/teams.c
+++ b/libgomp/config/gcn/teams.c
@@ -64,10 +64,19 @@ GOMP_distribute_static_worksharing_start (unsigned long 
long niter
   return nteams + tid * 1I;
 }
 
-/* Stub for OMPT callback enabled by -fopenmp-ompt-detailed.  */
+/* Stub for OMPT callback enabled by -fopenmp-ompt-detailed. NITER is the total
+   number of iterations. START is the starting iteration index. INCR is the
+   increment of the loop (or step). CHUNK_SIZE is the specific chunk size
+   requested in the schedule clause, or 0 if not specified. ISTART is the
+   iteration index of the logical chunk start.  */
 
 void
-GOMP_distribute_static_worksharing_dispatch (void)
+GOMP_distribute_static_worksharing_dispatch (
+  unsigned long long niter __attribute__ ((unused)),
+  unsigned long long start __attribute__ ((unused)),
+  unsigned long long incr __attribute__ ((unused)),
+  unsigned long long chunk_size __attribute__ ((unused)),
+  unsigned long long istart __attribute__ ((unused)))
 {}
 
 /* Stub for OMPT callback enabled by -fopenmp-ompt.  */
diff --git a/libgomp/config/nvptx/teams.c b/libgomp/config/nvptx/teams.c
index e04f8bbbdb14..7793a745bb11 100644
--- a/libgomp/config/nvptx/teams.c
+++ b/libgomp/config/nvptx/teams.c
@@ -65,10 +65,19 @@ GOMP_distribute_static_worksharing_start (unsigned long 
long niter
   return nteams + tid * 1I;
 }
 
-/* Stub for OMPT callback enabled by -fopenmp-ompt-detailed.  */
+/* Stub for OMPT callback enabled by -fopenmp-ompt-detailed. NITER is the total
+   number of iterations. START is the starting iteration index. INCR is the
+   increment of the loop (or step). CHUNK_SIZE is the specific chunk size
+   requested in the schedule clause, or 0 if not specified. ISTART is the
+   iteration index of the logical chunk start.  */
 
 void
-GOMP_distribute_static_worksharing_dispatch (void)
+GOMP_distribute_static_worksharing_dispatch (
+  unsigned long long niter __attribute__ ((unused)),
+  unsigned long long start __attribute__ ((unused)),
+  unsigned long long incr __attribute__ ((unused)),
+  unsigned long long chunk_size __attribute__ ((unused)),
+  unsigned long long istart __attribute__ ((unused)))
 {}
 
 /* Stub for OMPT callback enabled by -fopenmp-ompt.  */
diff --git a/libgomp/libgomp_g.h b/libgomp/libgomp_g.h
index 27d0db8c93bb..1ea8123056e2 100644
--- a/libgomp/libgomp_g.h
+++ b/libgomp/libgomp_g.h
@@ -146,7 +146,11 @@ extern bool GOMP_loop_end_cancel (void);
 
 extern _Complex int GOMP_loop_static_worksharing (unsigned long long);
 extern _Complex int GOMP_loop_static_worksharing_start (unsigned long long);
-extern void GOMP_loop_static_worksharing_dispatch (void);
+extern void GOMP_loop_static_worksharing_dispatch (unsigned long long,
+                                                  unsigned long long,
+                                                  unsigned long long,
+                                                  unsigned long long,
+                                                  unsigned long long);
 extern void GOMP_loop_static_worksharing_end (void);
 
 /* loop_ull.c */
@@ -388,7 +392,11 @@ extern void GOMP_teams_reg (void (*) (void *), void *, 
unsigned, unsigned,
                            unsigned);
 extern _Complex int GOMP_distribute_static_worksharing (unsigned long long);
 extern _Complex int GOMP_distribute_static_worksharing_start (unsigned long 
long);
-extern void GOMP_distribute_static_worksharing_dispatch (void);
+extern void GOMP_distribute_static_worksharing_dispatch (unsigned long long,
+                                                        unsigned long long,
+                                                        unsigned long long,
+                                                        unsigned long long,
+                                                        unsigned long long);
 extern void GOMP_distribute_static_worksharing_end (void);
 
 /* allocator.c */
diff --git a/libgomp/loop.c b/libgomp/loop.c
index f4d962667741..01ba0a3c9003 100644
--- a/libgomp/loop.c
+++ b/libgomp/loop.c
@@ -1213,10 +1213,19 @@ GOMP_loop_static_worksharing_start (unsigned long long 
niter
   return nthreads + tid * 1I;
 }
 
-/* Stub for OMPT callback enabled by -fopenmp-ompt-detailed.  */
+/* Stub for OMPT callback enabled by -fopenmp-ompt-detailed. NITER is the total
+   number of iterations. START is the starting iteration index. INCR is the
+   increment of the loop (or step). CHUNK_SIZE is the specific chunk size
+   requested in the schedule clause, or 0 if not specified. ISTART is the
+   iteration index of the logical chunk start.  */
 
 void
-GOMP_loop_static_worksharing_dispatch (void)
+GOMP_loop_static_worksharing_dispatch (
+  unsigned long long niter __attribute__ ((unused)),
+  unsigned long long start __attribute__ ((unused)),
+  unsigned long long incr __attribute__ ((unused)),
+  unsigned long long chunk_size __attribute__ ((unused)),
+  unsigned long long istart __attribute__ ((unused)))
 {}
 
 /* Stub for OMPT callback enabled by -fopenmp-ompt.  */
diff --git a/libgomp/teams.c b/libgomp/teams.c
index 71c40ef5b466..e95f52056c7a 100644
--- a/libgomp/teams.c
+++ b/libgomp/teams.c
@@ -84,10 +84,19 @@ GOMP_distribute_static_worksharing_start (unsigned long long
   return nteams + tid * 1I;
 }
 
-/* Stub for OMPT callback enabled by -fopenmp-ompt-detailed.  */
+/* Stub for OMPT callback enabled by -fopenmp-ompt-detailed. NITER is the total
+   number of iterations. START is the starting iteration index. INCR is the
+   increment of the loop (or step). CHUNK_SIZE is the specific chunk size
+   requested in the schedule clause, or 0 if not specified. ISTART is the
+   iteration index of the logical chunk start.  */
 
 void
-GOMP_distribute_static_worksharing_dispatch (void)
+GOMP_distribute_static_worksharing_dispatch (
+  unsigned long long niter __attribute__ ((unused)),
+  unsigned long long start __attribute__ ((unused)),
+  unsigned long long incr __attribute__ ((unused)),
+  unsigned long long chunk_size __attribute__ ((unused)),
+  unsigned long long istart __attribute__ ((unused)))
 {}
 
 /* Stub for OMPT callback enabled by -fopenmp-ompt.  */
diff --git a/libgomp/testsuite/libgomp.c-c++-common/for-static-3.c 
b/libgomp/testsuite/libgomp.c-c++-common/for-static-3.c
index d783b2c7c6b7..77954743843e 100644
--- a/libgomp/testsuite/libgomp.c-c++-common/for-static-3.c
+++ b/libgomp/testsuite/libgomp.c-c++-common/for-static-3.c
@@ -7,5 +7,6 @@
 #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_dispatch \\(\[^,\]+, \[^,\]+, \[^,\]+, 0, 
\[^)\]+\\)" 1 "optimized" } } */
+/* { dg-final { scan-offload-tree-dump-times 
"GOMP_distribute_static_worksharing_dispatch \\(\[^,\]+, \[^,\]+, \[^,\]+, 4, 
\[^)\]+\\)" 1 "optimized" } } */
 /* { dg-final { scan-offload-tree-dump-times 
"GOMP_distribute_static_worksharing_end \\(\\)" 2 "optimized" } } */

Reply via email to