Hi Thomas,

On 08/07/2026 11:10, Thomas Schwinge wrote:
Hi Paul-Antoine!

On 2026-07-07T18:12:58+0200, Paul-Antoine Arras <[email protected]> wrote:
On 07/07/2026 09:19, Thomas Schwinge wrote:
On 2026-07-02T15:22:34+0200, Paul-Antoine Arras <[email protected]> wrote:
Add parameter to GOMP_{loop,distribute}_static_worksharing{,_start} carrying the
total number of loop iterations. niter is unused for now, pending OMPT
implementation.

I had run the testsuite on amdgcn and fixed the
loop-counter-variable-type issue, but it seems to have gotten lost in a
rebase or something :sigh:

Yeah, I've had that happen, too.  ;-)

Anyway, thanks for the fixup patch -- I re-ran the testsuite with it and
it now works.

The attached patch has it squashed in, the trailer added and the
ChangeLog updated.

Thanks!  OK to push with the following items addressed.

--- gcc/omp-expand.cc
+++ gcc/omp-expand.cc

@@ -5236,31 +5200,69 @@ expand_omp_for_static_nochunk (struct omp_region 
*region,

        gcc_assert (innerc);
        n2 = OMP_CLAUSE_DECL (innerc);
      }
-  n1 = force_gimple_operand_gsi (&gsi, fold_convert (type, n1),
-                                true, NULL_TREE, true, GSI_SAME_STMT);
-  n2 = force_gimple_operand_gsi (&gsi, fold_convert (itype, n2),
-                                true, NULL_TREE, true, GSI_SAME_STMT);
-  step = force_gimple_operand_gsi (&gsi, fold_convert (itype, step),
-                                  true, NULL_TREE, true, GSI_SAME_STMT);
+  n1 = force_gimple_operand_gsi (&gsi, fold_convert (type, n1), true, 
NULL_TREE,
+                                true, GSI_SAME_STMT);
+  n2 = force_gimple_operand_gsi (&gsi, fold_convert (itype, n2), true,
+                                NULL_TREE, true, GSI_SAME_STMT);
+  step = force_gimple_operand_gsi (&gsi, fold_convert (itype, step), true,
+                                  NULL_TREE, true, GSI_SAME_STMT);
t = build_int_cst (itype, (fd->loop.cond_code == LT_EXPR ? -1 : 1));
    t = fold_build2 (PLUS_EXPR, itype, step, t);

(Might drop this reformatting, too?)

I went through the whole diff on this file, removing all spurious reformatting -- hope I didn't miss any!

--- libgomp/libgomp_g.h
+++ libgomp/libgomp_g.h

@@ -144,6 +144,14 @@ 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 (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_end (void);

That patch hunk can't apply on top of the
v2 "openmp: Add OMPT entry points for worksharing-loop, single, and masked 
constructs".

The updated patch attached should now apply cleanly.

+
+extern bool GOMP_has_masked_thread_num (int);
+extern void GOMP_masked_end (void);
+

Those two stay in the 'parallel.c' section:

  /* loop_ull.c */
extern bool GOMP_loop_ull_static_start (bool, unsigned long long,
@@ -297,8 +305,6 @@ extern unsigned GOMP_parallel_reductions (void (*) (void 
*), void *, unsigned,
                                          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);

... if that's where their implementation remains.

Yes, that's where they belong.

/* task.c */ @@ -379,7 +385,10 @@ 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 (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_end (void);
/* allocator.c */


Grüße
  Thomas


--
PA
From 7ef2a3fe946f9efb918b3a17562380cd57b9e89b Mon Sep 17 00:00:00 2001
From: Paul-Antoine Arras <[email protected]>
Date: Wed, 1 Jul 2026 18:51:07 +0200
Subject: [PATCH v3 2/2] openmp: Pass iteration count to static worksharing
 builtins for OMPT

Add parameter to GOMP_{loop,distribute}_static_worksharing{,_start} carrying the
total number of loop iterations. niter is unused for now, pending OMPT
implementation.

The call in omp-expand.cc is moved after the iteration count computation
so that the iteration count is available to pass as the argument.

gcc/ChangeLog:

	* builtin-types.def (BT_FN_COMPLEX_INT): Remove.
	(BT_FN_COMPLEX_INT_ULONGLONG): New.
	* omp-builtins.def (BUILT_IN_GOMP_LOOP_STATIC_WORKSHARING): Use
	BT_FN_COMPLEX_INT_ULONGLONG.
	(BUILT_IN_GOMP_LOOP_STATIC_WORKSHARING_START): Likewise.
	(BUILT_IN_GOMP_DISTRIBUTE_STATIC_WORKSHARING): Likewise.
	(BUILT_IN_GOMP_DISTRIBUTE_STATIC_WORKSHARING_START): Likewise.
	* omp-expand.cc (expand_omp_for_static_nochunk): Move worksharing
	builtin call after iteration count computation; pass n as niter.
	(expand_omp_for_static_chunk): Likewise.

gcc/fortran/ChangeLog:

	* types.def (BT_FN_COMPLEX_INT): Remove.
	(BT_FN_COMPLEX_INT_ULONGLONG): New.

libgomp/ChangeLog:

	* config/gcn/teams.c (GOMP_distribute_static_worksharing): Add
	long niter parameter (unused).
	(GOMP_distribute_static_worksharing_start): Likewise.
	* config/nvptx/teams.c (GOMP_distribute_static_worksharing):
	Likewise.
	(GOMP_distribute_static_worksharing_start): Likewise.
	* libgomp.texi: Update function signatures; fix real/imaginary
	description; document niter parameter.
	* libgomp_g.h (GOMP_loop_static_worksharing): Update prototype.
	(GOMP_distribute_static_worksharing): Likewise.
	* loop.c (GOMP_loop_static_worksharing): Add long niter parameter
	(unused).
	(GOMP_loop_static_worksharing_start): Likewise.
	* teams.c (GOMP_distribute_static_worksharing): Likewise.
	(GOMP_distribute_static_worksharing_start): Likewise.
	* testsuite/libgomp.c-c++-common/for-static-1.c: Update scan
	pattern to match niter argument.
	* testsuite/libgomp.c-c++-common/for-static-2.c: Likewise.
	* testsuite/libgomp.c-c++-common/for-static-3.c: Likewise.

gcc/testsuite/ChangeLog:

	* c-c++-common/gomp/for-static-1.c: Update scan pattern to match
	niter argument.
	* c-c++-common/gomp/for-static-2.c: Likewise.
	* c-c++-common/gomp/for-static-3.c: Likewise.

Co-authored-by: Thomas Schwinge <[email protected]>
---
 gcc/builtin-types.def                         |   2 +-
 gcc/fortran/types.def                         |   2 +-
 gcc/omp-builtins.def                          |  13 +-
 gcc/omp-expand.cc                             | 150 +++++++++---------
 .../c-c++-common/gomp/for-static-1.c          |   7 +-
 .../c-c++-common/gomp/for-static-2.c          |  12 +-
 .../c-c++-common/gomp/for-static-3.c          |  18 ++-
 libgomp/config/gcn/teams.c                    |   9 +-
 libgomp/config/nvptx/teams.c                  |   9 +-
 libgomp/libgomp.texi                          |   9 +-
 libgomp/libgomp_g.h                           |  10 +-
 libgomp/loop.c                                |   9 +-
 libgomp/teams.c                               |   9 +-
 .../libgomp.c-c++-common/for-static-1.c       |   2 +-
 .../libgomp.c-c++-common/for-static-2.c       |   4 +-
 .../libgomp.c-c++-common/for-static-3.c       |   6 +-
 16 files changed, 155 insertions(+), 116 deletions(-)

diff --git a/gcc/builtin-types.def b/gcc/builtin-types.def
index 55ed6f0cae1..d11e6e736a2 100644
--- a/gcc/builtin-types.def
+++ b/gcc/builtin-types.def
@@ -236,7 +236,6 @@ DEF_FUNCTION_TYPE_0 (BT_FN_CONST_STRING, BT_CONST_STRING)
 DEF_FUNCTION_TYPE_0 (BT_FN_PID, BT_PID)
 DEF_FUNCTION_TYPE_0 (BT_FN_INT, BT_INT)
 DEF_FUNCTION_TYPE_0 (BT_FN_UINT, BT_UINT)
-DEF_FUNCTION_TYPE_0 (BT_FN_COMPLEX_INT, BT_COMPLEX_INT)
 DEF_FUNCTION_TYPE_0 (BT_FN_ULONG, BT_ULONG)
 DEF_FUNCTION_TYPE_0 (BT_FN_ULONGLONG, BT_ULONGLONG)
 DEF_FUNCTION_TYPE_0 (BT_FN_FLOAT, BT_FLOAT)
@@ -429,6 +428,7 @@ DEF_FUNCTION_TYPE_1 (BT_FN_UINT16_UINT32, BT_UINT16, BT_UINT32)
 DEF_FUNCTION_TYPE_1 (BT_FN_UINT32_UINT16, BT_UINT32, BT_UINT16)
 DEF_FUNCTION_TYPE_1 (BT_FN_INT_FENV_T_PTR, BT_INT, BT_FENV_T_PTR)
 DEF_FUNCTION_TYPE_1 (BT_FN_INT_CONST_FENV_T_PTR, BT_INT, BT_CONST_FENV_T_PTR)
+DEF_FUNCTION_TYPE_1 (BT_FN_COMPLEX_INT_ULONGLONG, BT_COMPLEX_INT, BT_ULONGLONG)
 
 DEF_POINTER_TYPE (BT_PTR_FN_VOID_PTR, BT_FN_VOID_PTR)
 
diff --git a/gcc/fortran/types.def b/gcc/fortran/types.def
index 6f98e3e48ff..b694e689360 100644
--- a/gcc/fortran/types.def
+++ b/gcc/fortran/types.def
@@ -77,7 +77,6 @@ DEF_POINTER_TYPE (BT_PTR_PTR, BT_PTR)
 DEF_FUNCTION_TYPE_0 (BT_FN_BOOL, BT_BOOL)
 DEF_FUNCTION_TYPE_0 (BT_FN_PTR, BT_PTR)
 DEF_FUNCTION_TYPE_0 (BT_FN_INT, BT_INT)
-DEF_FUNCTION_TYPE_0 (BT_FN_COMPLEX_INT, BT_COMPLEX_INT)
 DEF_FUNCTION_TYPE_0 (BT_FN_UINT, BT_UINT)
 DEF_FUNCTION_TYPE_0 (BT_FN_VOID, BT_VOID)
 DEF_FUNCTION_TYPE_0 (BT_FN_ULONGLONG, BT_ULONGLONG)
@@ -91,6 +90,7 @@ DEF_FUNCTION_TYPE_1 (BT_FN_PTR_PTR, BT_PTR, BT_PTR)
 DEF_FUNCTION_TYPE_1 (BT_FN_VOID_INT, BT_VOID, BT_INT)
 DEF_FUNCTION_TYPE_1 (BT_FN_VOID_BOOL, BT_VOID, BT_BOOL)
 DEF_FUNCTION_TYPE_1 (BT_FN_BOOL_INT, BT_BOOL, BT_INT)
+DEF_FUNCTION_TYPE_1 (BT_FN_COMPLEX_INT_ULONGLONG, BT_COMPLEX_INT, BT_ULONGLONG)
 
 DEF_POINTER_TYPE (BT_PTR_FN_VOID_PTR, BT_FN_VOID_PTR)
 
diff --git a/gcc/omp-builtins.def b/gcc/omp-builtins.def
index 465aeebefdb..3b0d5572043 100644
--- a/gcc/omp-builtins.def
+++ b/gcc/omp-builtins.def
@@ -510,11 +510,14 @@ DEF_GOMP_BUILTIN (BUILT_IN_GOMP_HAS_MASKED_THREAD_NUM,
 		  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  */
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_STATIC_WORKSHARING,
-		  "GOMP_loop_static_worksharing", BT_FN_COMPLEX_INT,
+		  "GOMP_loop_static_worksharing",
+		  BT_FN_COMPLEX_INT_ULONGLONG,
 		  ATTR_CONST_NOTHROW_LEAF_LIST)
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_STATIC_WORKSHARING_START,
-		  "GOMP_loop_static_worksharing_start", BT_FN_COMPLEX_INT,
+		  "GOMP_loop_static_worksharing_start",
+		  BT_FN_COMPLEX_INT_ULONGLONG,
 		  ATTR_CONST_NOTHROW_LEAF_LIST)
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_STATIC_WORKSHARING_END,
 		  "GOMP_loop_static_worksharing_end", BT_FN_VOID,
@@ -523,10 +526,12 @@ 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,
+		  "GOMP_distribute_static_worksharing",
+		  BT_FN_COMPLEX_INT_ULONGLONG,
 		  ATTR_CONST_NOTHROW_LEAF_LIST)
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_DISTRIBUTE_STATIC_WORKSHARING_START,
-		  "GOMP_distribute_static_worksharing_start", BT_FN_COMPLEX_INT,
+		  "GOMP_distribute_static_worksharing_start",
+		  BT_FN_COMPLEX_INT_ULONGLONG,
 		  ATTR_CONST_NOTHROW_LEAF_LIST)
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_DISTRIBUTE_STATIC_WORKSHARING_END,
 		  "GOMP_distribute_static_worksharing_end", BT_FN_VOID,
diff --git a/gcc/omp-expand.cc b/gcc/omp-expand.cc
index ad380b27d06..388f84eddff 100644
--- a/gcc/omp-expand.cc
+++ b/gcc/omp-expand.cc
@@ -5190,42 +5190,6 @@ expand_omp_for_static_nochunk (struct omp_region *region,
 	  release_ssa_name (gimple_assign_lhs (g));
 	}
     }
-  /* Fetch the thread/team id and the number of threads/teams in a single
-     call to GOMP_loop_static_worksharing or GOMP_distribute_static_worksharing.
-     The helper returns both values packed into one complex int, with
-     the id as the imaginary part and the count as the real part.  Returning
-     (rather than writing through pointers) keeps both values as plain SSA
-     names, which lets later passes - notably IPA-CP propagating constants
-     into the outlined kernel - reason about them.  */
-  tree decl;
-  switch (gimple_omp_for_kind (fd->for_stmt))
-    {
-    case GF_OMP_FOR_KIND_FOR:
-      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 (
-	flag_openmp_ompt ? BUILT_IN_GOMP_DISTRIBUTE_STATIC_WORKSHARING_START
-			 : BUILT_IN_GOMP_DISTRIBUTE_STATIC_WORKSHARING);
-      break;
-    default:
-      gcc_unreachable ();
-    }
-  {
-    tree packed = build_call_expr (decl, 0);
-    packed = force_gimple_operand_gsi (&gsi, packed, true, NULL_TREE,
-				       true, GSI_SAME_STMT);
-    threadid = fold_build1 (IMAGPART_EXPR, integer_type_node, packed);
-    threadid = fold_convert (itype, threadid);
-    threadid = force_gimple_operand_gsi (&gsi, threadid, true, NULL_TREE,
-					 true, GSI_SAME_STMT);
-    nthreads = fold_build1 (REALPART_EXPR, integer_type_node, packed);
-    nthreads = fold_convert (itype, nthreads);
-    nthreads = force_gimple_operand_gsi (&gsi, nthreads, true, NULL_TREE,
-					 true, GSI_SAME_STMT);
-  }
 
   n1 = fd->loop.n1;
   n2 = fd->loop.n2;
@@ -5261,6 +5225,45 @@ expand_omp_for_static_nochunk (struct omp_region *region,
   t = fold_convert (itype, t);
   n = force_gimple_operand_gsi (&gsi, t, true, NULL_TREE, true, GSI_SAME_STMT);
 
+  {
+    /* Fetch the thread/team id and the number of threads/teams in a single
+       call to GOMP_loop_static_worksharing or
+       GOMP_distribute_static_worksharing. The helper returns both values packed
+       into one complex int, with the id as the imaginary part and the count as
+       the real part.  Returning (rather than writing through pointers) keeps
+       both values as plain SSA names, which lets later passes - notably IPA-CP
+       propagating constants into the outlined kernel - reason about them.
+       Also pass the total number of iterations for OMPT.  */
+    tree decl;
+    switch (gimple_omp_for_kind (fd->for_stmt))
+      {
+      case GF_OMP_FOR_KIND_FOR:
+	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 (
+	  flag_openmp_ompt ? BUILT_IN_GOMP_DISTRIBUTE_STATIC_WORKSHARING_START
+			   : BUILT_IN_GOMP_DISTRIBUTE_STATIC_WORKSHARING);
+	break;
+      default:
+	gcc_unreachable ();
+      }
+    tree n_ull = fold_convert (long_long_unsigned_type_node, n);
+    tree packed = build_call_expr (decl, 1, n_ull);
+    packed = force_gimple_operand_gsi (&gsi, packed, true, NULL_TREE,
+				       true, GSI_SAME_STMT);
+    threadid = fold_build1 (IMAGPART_EXPR, integer_type_node, packed);
+    threadid = fold_convert (itype, threadid);
+    threadid = force_gimple_operand_gsi (&gsi, threadid, true, NULL_TREE,
+					 true, GSI_SAME_STMT);
+    nthreads = fold_build1 (REALPART_EXPR, integer_type_node, packed);
+    nthreads = fold_convert (itype, nthreads);
+    nthreads = force_gimple_operand_gsi (&gsi, nthreads, true, NULL_TREE,
+					 true, GSI_SAME_STMT);
+  }
+
   q = create_tmp_reg (itype, "q");
   t = fold_build2 (TRUNC_DIV_EXPR, itype, n, nthreads);
   t = force_gimple_operand_gsi (&gsi, t, false, NULL_TREE, true, GSI_SAME_STMT);
@@ -6008,42 +6011,6 @@ expand_omp_for_static_chunk (struct omp_region *region,
 	  release_ssa_name (gimple_assign_lhs (g));
 	}
     }
-  /* Fetch the thread/team id and the number of threads/teams in a single
-     call to GOMP_loop_static_worksharing or GOMP_distribute_static_worksharing.
-     The helper returns both values packed into one complex int, with
-     the id as the imaginary part and the count as the real part.  Returning
-     (rather than writing through pointers) keeps both values as plain SSA
-     names, which lets later passes - notably IPA-CP propagating constants
-     into the outlined kernel - reason about them.  */
-  tree decl;
-  switch (gimple_omp_for_kind (fd->for_stmt))
-    {
-    case GF_OMP_FOR_KIND_FOR:
-      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 (
-	flag_openmp_ompt ? BUILT_IN_GOMP_DISTRIBUTE_STATIC_WORKSHARING_START
-			 : BUILT_IN_GOMP_DISTRIBUTE_STATIC_WORKSHARING);
-      break;
-    default:
-      gcc_unreachable ();
-    }
-  {
-    tree packed = build_call_expr (decl, 0);
-    packed = force_gimple_operand_gsi (&gsi, packed, true, NULL_TREE,
-				       true, GSI_SAME_STMT);
-    threadid = fold_build1 (IMAGPART_EXPR, integer_type_node, packed);
-    threadid = fold_convert (itype, threadid);
-    threadid = force_gimple_operand_gsi (&gsi, threadid, true, NULL_TREE,
-					 true, GSI_SAME_STMT);
-    nthreads = fold_build1 (REALPART_EXPR, integer_type_node, packed);
-    nthreads = fold_convert (itype, nthreads);
-    nthreads = force_gimple_operand_gsi (&gsi, nthreads, true, NULL_TREE,
-					 true, GSI_SAME_STMT);
-  }
 
   n1 = fd->loop.n1;
   n2 = fd->loop.n2;
@@ -6086,6 +6053,45 @@ expand_omp_for_static_chunk (struct omp_region *region,
   n = force_gimple_operand_gsi (&gsi, t, true, NULL_TREE,
 				true, GSI_SAME_STMT);
 
+  {
+    /* Fetch the thread/team id and the number of threads/teams in a single
+       call to GOMP_loop_static_worksharing or
+       GOMP_distribute_static_worksharing. The helper returns both values packed
+       into one complex int, with the id as the imaginary part and the count as
+       the real part.  Returning (rather than writing through pointers) keeps
+       both values as plain SSA names, which lets later passes - notably IPA-CP
+       propagating constants into the outlined kernel - reason about them.
+       Also pass the total number of iterations for OMPT.  */
+    tree decl;
+    switch (gimple_omp_for_kind (fd->for_stmt))
+      {
+      case GF_OMP_FOR_KIND_FOR:
+	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 (
+	  flag_openmp_ompt ? BUILT_IN_GOMP_DISTRIBUTE_STATIC_WORKSHARING_START
+			   : BUILT_IN_GOMP_DISTRIBUTE_STATIC_WORKSHARING);
+	break;
+      default:
+	gcc_unreachable ();
+      }
+    tree n_ull = fold_convert (long_long_unsigned_type_node, n);
+    tree packed = build_call_expr (decl, 1, n_ull);
+    packed = force_gimple_operand_gsi (&gsi, packed, true, NULL_TREE, true,
+				       GSI_SAME_STMT);
+    threadid = fold_build1 (IMAGPART_EXPR, integer_type_node, packed);
+    threadid = fold_convert (itype, threadid);
+    threadid = force_gimple_operand_gsi (&gsi, threadid, true, NULL_TREE, true,
+					 GSI_SAME_STMT);
+    nthreads = fold_build1 (REALPART_EXPR, integer_type_node, packed);
+    nthreads = fold_convert (itype, nthreads);
+    nthreads = force_gimple_operand_gsi (&gsi, nthreads, true, NULL_TREE, true,
+					 GSI_SAME_STMT);
+  }
+
   trip_var = create_tmp_reg (itype, ".trip");
   if (gimple_in_ssa_p (cfun))
     {
diff --git a/gcc/testsuite/c-c++-common/gomp/for-static-1.c b/gcc/testsuite/c-c++-common/gomp/for-static-1.c
index 50d4e176f3d..09e533c931d 100644
--- a/gcc/testsuite/c-c++-common/gomp/for-static-1.c
+++ b/gcc/testsuite/c-c++-common/gomp/for-static-1.c
@@ -9,8 +9,11 @@
 
 #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-times "GOMP_loop_static_worksharing \\(\[^\\)\]" 2 "ompexp" } } */
+/* { dg-final { scan-tree-dump-not "GOMP_loop_static_worksharing_start" "ompexp" } } */
+/* { dg-final { scan-tree-dump-not "GOMP_loop_static_worksharing_dispatch" "ompexp" } } */
+/* { dg-final { scan-tree-dump-not "GOMP_loop_static_worksharing_end" "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" } } */
diff --git a/gcc/testsuite/c-c++-common/gomp/for-static-2.c b/gcc/testsuite/c-c++-common/gomp/for-static-2.c
index c3d25b97bed..d99f59d7471 100644
--- a/gcc/testsuite/c-c++-common/gomp/for-static-2.c
+++ b/gcc/testsuite/c-c++-common/gomp/for-static-2.c
@@ -5,11 +5,15 @@
 
 #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-times "GOMP_loop_static_worksharing_start \\(\[^\\)\]" 2 "ompexp" } } */
 /* { dg-final { scan-tree-dump-not "GOMP_loop_static_worksharing_dispatch" "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-not "GOMP_distribute_static_worksharing_dispatch" "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" } } */
+/* { 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-3.c b/gcc/testsuite/c-c++-common/gomp/for-static-3.c
index 6fd1da6c407..8e45223c353 100644
--- a/gcc/testsuite/c-c++-common/gomp/for-static-3.c
+++ b/gcc/testsuite/c-c++-common/gomp/for-static-3.c
@@ -6,9 +6,15 @@
 
 #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" } } */
+/* { 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_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_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" } } */
+/* { 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/libgomp/config/gcn/teams.c b/libgomp/config/gcn/teams.c
index 99f807ac876..4354131f9b7 100644
--- a/libgomp/config/gcn/teams.c
+++ b/libgomp/config/gcn/teams.c
@@ -39,10 +39,12 @@ GOMP_teams_reg (void (*fn) (void *), void *data, unsigned int num_teams,
 }
 
 /* For a distribute construct with static schedule, return the team ID and
-   number of teams packed into a single complexvalue.  */
+   number of teams packed into a single complex value. NITER is the total
+   number of iterations.  */
 
 _Complex int
-GOMP_distribute_static_worksharing (void)
+GOMP_distribute_static_worksharing (unsigned long long niter
+				    __attribute__ ((unused)))
 {
   int __lds *gomp_team_num = (int __lds *) GOMP_TEAM_NUM;
   unsigned tid = *gomp_team_num;
@@ -53,7 +55,8 @@ GOMP_distribute_static_worksharing (void)
 /* OMPT variant enabled by -fopenmp-ompt.  */
 
 _Complex int
-GOMP_distribute_static_worksharing_start (void)
+GOMP_distribute_static_worksharing_start (unsigned long long niter
+					  __attribute__ ((unused)))
 {
   int __lds *gomp_team_num = (int __lds *) GOMP_TEAM_NUM;
   unsigned tid = *gomp_team_num;
diff --git a/libgomp/config/nvptx/teams.c b/libgomp/config/nvptx/teams.c
index 3e6ea287276..e04f8bbbdb1 100644
--- a/libgomp/config/nvptx/teams.c
+++ b/libgomp/config/nvptx/teams.c
@@ -42,10 +42,12 @@ GOMP_teams_reg (void (*fn) (void *), void *data, unsigned int num_teams,
 }
 
 /* For a distribute construct with static schedule, return the team ID and
-   number of teams packed into a single complexvalue.  */
+   number of teams packed into a single complex value. NITER is the total
+   number of iterations.  */
 
 _Complex int
-GOMP_distribute_static_worksharing (void)
+GOMP_distribute_static_worksharing (unsigned long long niter
+				    __attribute__ ((unused)))
 {
   unsigned tid = __gomp_team_num;
   unsigned nteams = gomp_num_teams_var + 1;
@@ -55,7 +57,8 @@ GOMP_distribute_static_worksharing (void)
 /* OMPT variant enabled by -fopenmp-ompt.  */
 
 _Complex int
-GOMP_distribute_static_worksharing_start (void)
+GOMP_distribute_static_worksharing_start (unsigned long long niter
+					  __attribute__ ((unused)))
 {
   unsigned tid = __gomp_team_num;
   unsigned nteams = gomp_num_teams_var + 1;
diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi
index 83b90e6dc53..5d29da0984d 100644
--- a/libgomp/libgomp.texi
+++ b/libgomp/libgomp.texi
@@ -8318,17 +8318,18 @@ but since its supposed to remain unchanged, we can also not if we like.
 For @code{schedule(static)} without @code{ordered}, the compiler uses:
 
 @smallexample
-  _Complex int GOMP_loop_static_worksharing (void)
+  _Complex int GOMP_loop_static_worksharing (unsigned long long)
 @end smallexample
 
-which returns the thread id in the real part and the thread count in the imaginary
-part as a single value, avoiding separate @code{omp_get_thread_num} /
+which returns the thread id in the imaginary part and the thread count in the
+real part as a single value, avoiding separate @code{omp_get_thread_num} /
 @code{omp_get_num_threads} calls that OMPT cannot distinguish from user queries.
+For OMPT, the total number of loop iterations is passed as argument.
 
 Similarly, for @code{distribute} constructs:
 
 @smallexample
-  _Complex int GOMP_distribute_static_worksharing (void)
+  _Complex int GOMP_distribute_static_worksharing (unsigned long long)
 @end smallexample
 
 returns the team id and team count.
diff --git a/libgomp/libgomp_g.h b/libgomp/libgomp_g.h
index 4a3565684cc..8cbbf50df0b 100644
--- a/libgomp/libgomp_g.h
+++ b/libgomp/libgomp_g.h
@@ -144,8 +144,8 @@ 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 _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_end (void);
 
@@ -386,8 +386,10 @@ 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 _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_end (void);
 extern void GOMP_distribute_static_worksharing_dispatch (void);
 extern void GOMP_distribute_static_worksharing_end (void);
 
diff --git a/libgomp/loop.c b/libgomp/loop.c
index f286ce6b6db..f4d96266774 100644
--- a/libgomp/loop.c
+++ b/libgomp/loop.c
@@ -1188,10 +1188,12 @@ GOMP_loop_ordered_guided_next (long *istart, long *iend)
 #endif
 
 /* For a worksharing-loop construct with static schedule, return the thread ID
-   and number of threads packed into a single complex value.  */
+   and number of threads packed into a single complex value. NITER is the total
+   number of iterations.  */
 
 _Complex int
-GOMP_loop_static_worksharing (void)
+GOMP_loop_static_worksharing (unsigned long long niter
+			      __attribute__ ((unused)))
 {
   struct gomp_team *team = gomp_thread ()->ts.team;
   unsigned tid = gomp_thread ()->ts.team_id;
@@ -1202,7 +1204,8 @@ GOMP_loop_static_worksharing (void)
 /* OMPT variant enabled by -fopenmp-ompt.  */
 
 _Complex int
-GOMP_loop_static_worksharing_start (void)
+GOMP_loop_static_worksharing_start (unsigned long long niter
+				    __attribute__ ((unused)))
 {
   struct gomp_team *team = gomp_thread ()->ts.team;
   unsigned tid = gomp_thread ()->ts.team_id;
diff --git a/libgomp/teams.c b/libgomp/teams.c
index f501123d647..71c40ef5b46 100644
--- a/libgomp/teams.c
+++ b/libgomp/teams.c
@@ -59,10 +59,12 @@ GOMP_teams_reg (void (*fn) (void *), void *data, unsigned int num_teams,
 }
 
 /* For a distribute construct with static schedule, return the team ID and
-   number of teams packed into a single complex value.  */
+   number of teams packed into a single complex value. NITER is the total
+   number of iterations.  */
 
 _Complex int
-GOMP_distribute_static_worksharing (void)
+GOMP_distribute_static_worksharing (unsigned long long
+				    niter __attribute__ ((unused)))
 {
   struct gomp_thread *thr = gomp_thread ();
   unsigned tid = thr->team_num;
@@ -73,7 +75,8 @@ GOMP_distribute_static_worksharing (void)
 /* OMPT variant enabled by -fopenmp-ompt.  */
 
 _Complex int
-GOMP_distribute_static_worksharing_start (void)
+GOMP_distribute_static_worksharing_start (unsigned long long
+					  niter __attribute__ ((unused)))
 {
   struct gomp_thread *thr = gomp_thread ();
   unsigned tid = thr->team_num;
diff --git a/libgomp/testsuite/libgomp.c-c++-common/for-static-1.c b/libgomp/testsuite/libgomp.c-c++-common/for-static-1.c
index b304c8c10ec..2eb63e3d1ad 100644
--- a/libgomp/testsuite/libgomp.c-c++-common/for-static-1.c
+++ b/libgomp/testsuite/libgomp.c-c++-common/for-static-1.c
@@ -8,6 +8,6 @@
 
 #include "for-static.h"
 
-/* { dg-final { scan-offload-tree-dump-times "GOMP_distribute_static_worksharing \\(" 2 "optimized" } } */
+/* { 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
index 83e577a3298..ff756a38489 100644
--- a/libgomp/testsuite/libgomp.c-c++-common/for-static-2.c
+++ b/libgomp/testsuite/libgomp.c-c++-common/for-static-2.c
@@ -5,7 +5,7 @@
 
 #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-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
index e7b904eedc3..d783b2c7c6b 100644
--- a/libgomp/testsuite/libgomp.c-c++-common/for-static-3.c
+++ b/libgomp/testsuite/libgomp.c-c++-common/for-static-3.c
@@ -6,6 +6,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_end \\(" 2 "optimized" } } */
+/* { 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" } } */
-- 
2.53.0

Reply via email to