[Openmp-commits] [openmp] 0b2e935 - [NFCI][OpenMP][OMPT] Move `for_static_init` work callbacks into macro (#217259)

via Openmp-commits openmp-commits at lists.llvm.org
Thu Aug 20 11:18:36 PDT 2026


Author: Jan André Reuter
Date: 2026-08-20T20:18:30+02:00
New Revision: 0b2e935b198a58439a42c2fda15819bcfea93b16

URL: https://github.com/llvm/llvm-project/commit/0b2e935b198a58439a42c2fda15819bcfea93b16
DIFF: https://github.com/llvm/llvm-project/commit/0b2e935b198a58439a42c2fda15819bcfea93b16.diff

LOG: [NFCI][OpenMP][OMPT] Move `for_static_init` work callbacks into macro (#217259)

`__kmp_for_static_init` uses a very similar pattern for dispatching the
work callback to an attached tool throughout the function. Hence, avoid
the duplication by moving the pattern into a macro, taking the number of
loop iterations as an argument. Without OMPT, this macro is a no-op.

Signed-off-by: Jan André Reuter <jan at zyten.de>

Added: 
    

Modified: 
    openmp/runtime/src/kmp_sched.cpp

Removed: 
    


################################################################################
diff  --git a/openmp/runtime/src/kmp_sched.cpp b/openmp/runtime/src/kmp_sched.cpp
index 2b1bb6f595f9a..7b6b54d274a6f 100644
--- a/openmp/runtime/src/kmp_sched.cpp
+++ b/openmp/runtime/src/kmp_sched.cpp
@@ -128,6 +128,14 @@ static void __kmp_for_static_init(ident_t *loc, kmp_int32 global_tid,
       KMP_DEBUG_ASSERT(ompt_work_type);
     }
   }
+#define OMPT_LOOP_BEGIN(count)                                                 \
+  if (ompt_enabled.ompt_callback_work) {                                       \
+    ompt_callbacks.ompt_callback(ompt_callback_work)(                          \
+        ompt_work_type, ompt_scope_begin, &(team_info->parallel_data),         \
+        &(task_info->task_data), count, codeptr);                              \
+  }
+#else
+#define OMPT_LOOP_BEGIN(count) // no-op
 #endif
 
   KMP_DEBUG_ASSERT(plastiter && plower && pupper && pstride);
@@ -181,13 +189,7 @@ static void __kmp_for_static_init(ident_t *loc, kmp_int32 global_tid,
 #endif
     KE_TRACE(10, ("__kmpc_for_static_init: T#%d return\n", global_tid));
 
-#if OMPT_SUPPORT && OMPT_OPTIONAL
-    if (ompt_enabled.ompt_callback_work) {
-      ompt_callbacks.ompt_callback(ompt_callback_work)(
-          ompt_work_type, ompt_scope_begin, &(team_info->parallel_data),
-          &(task_info->task_data), 0, codeptr);
-    }
-#endif
+    OMPT_LOOP_BEGIN(0);
     KMP_STATS_LOOP_END(OMP_loop_static_iterations);
     return;
   }
@@ -235,13 +237,7 @@ static void __kmp_for_static_init(ident_t *loc, kmp_int32 global_tid,
 #endif
     KE_TRACE(10, ("__kmpc_for_static_init: T#%d return\n", global_tid));
 
-#if OMPT_SUPPORT && OMPT_OPTIONAL
-    if (ompt_enabled.ompt_callback_work) {
-      ompt_callbacks.ompt_callback(ompt_callback_work)(
-          ompt_work_type, ompt_scope_begin, &(team_info->parallel_data),
-          &(task_info->task_data), *pstride, codeptr);
-    }
-#endif
+    OMPT_LOOP_BEGIN(*pstride);
     KMP_STATS_LOOP_END(OMP_loop_static_iterations);
     return;
   }
@@ -265,13 +261,7 @@ static void __kmp_for_static_init(ident_t *loc, kmp_int32 global_tid,
 #endif
     KE_TRACE(10, ("__kmpc_for_static_init: T#%d return\n", global_tid));
 
-#if OMPT_SUPPORT && OMPT_OPTIONAL
-    if (ompt_enabled.ompt_callback_work) {
-      ompt_callbacks.ompt_callback(ompt_callback_work)(
-          ompt_work_type, ompt_scope_begin, &(team_info->parallel_data),
-          &(task_info->task_data), *pstride, codeptr);
-    }
-#endif
+    OMPT_LOOP_BEGIN(*pstride);
     KMP_STATS_LOOP_END(OMP_loop_static_iterations);
     return;
   }
@@ -445,12 +435,8 @@ static void __kmp_for_static_init(ident_t *loc, kmp_int32 global_tid,
 #endif
   KE_TRACE(10, ("__kmpc_for_static_init: T#%d return\n", global_tid));
 
+  OMPT_LOOP_BEGIN(trip_count);
 #if OMPT_SUPPORT && OMPT_OPTIONAL
-  if (ompt_enabled.ompt_callback_work) {
-    ompt_callbacks.ompt_callback(ompt_callback_work)(
-        ompt_work_type, ompt_scope_begin, &(team_info->parallel_data),
-        &(task_info->task_data), trip_count, codeptr);
-  }
   if (ompt_enabled.ompt_callback_dispatch) {
     ompt_dispatch_t dispatch_type;
     ompt_data_t instance = ompt_data_none;


        


More information about the Openmp-commits mailing list