Skip to content

Commit 518b08c

Browse files
authored
[OpenMP] Fix issue of indirect function call in __kmpc_fork_call_if (#65436)
The outlined function is typically invoked by using `__kmp_invoke_microtask`, which is written in asm. D138495 introduces a new interface function for parallel region for OpenMPIRBuilder, where the outlined function is called via the function pointer. For some reason, it works perfectly well on x86 and x86-64 system, but doesn't work on Apple Silicon. The 3rd argument in the callee is always `nullptr`, even if it is not in caller. It appears `x2` always contains `0x0`. This patch adopts the typical method to invoke the function pointer. It works on my M2 Ultra Mac. Fix #63194.
1 parent 08ad327 commit 518b08c

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

openmp/runtime/src/kmp_csupport.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,6 @@ Perform a fork only if the condition is true.
343343
void __kmpc_fork_call_if(ident_t *loc, kmp_int32 argc, kmpc_micro microtask,
344344
kmp_int32 cond, void *args) {
345345
int gtid = __kmp_entry_gtid();
346-
int zero = 0;
347346
if (cond) {
348347
if (args)
349348
__kmpc_fork_call(loc, argc, microtask, args);
@@ -352,10 +351,29 @@ void __kmpc_fork_call_if(ident_t *loc, kmp_int32 argc, kmpc_micro microtask,
352351
} else {
353352
__kmpc_serialized_parallel(loc, gtid);
354353

354+
#ifdef OMPT_SUPPORT
355+
void *exit_frame_ptr;
356+
#endif
357+
355358
if (args)
356-
microtask(&gtid, &zero, args);
359+
__kmp_invoke_microtask(VOLATILE_CAST(microtask_t) microtask, gtid,
360+
/*npr=*/0,
361+
/*argc=*/1, &args
362+
#ifdef OMPT_SUPPORT
363+
,
364+
&exit_frame_ptr
365+
#endif
366+
);
357367
else
358-
microtask(&gtid, &zero);
368+
__kmp_invoke_microtask(VOLATILE_CAST(microtask_t) microtask, gtid,
369+
/*npr=*/0,
370+
/*argc=*/0,
371+
/*args=*/nullptr
372+
#ifdef OMPT_SUPPORT
373+
,
374+
&exit_frame_ptr
375+
#endif
376+
);
359377

360378
__kmpc_end_serialized_parallel(loc, gtid);
361379
}

0 commit comments

Comments
 (0)