On Fri, Jun 06, 2025 at 04:51:33PM +0200, Tobias Burnus wrote: > Most builtins in omp-builtins.def is marked as LEAF. At a glance, > that's surprising but looking at the functions, it turns out > that most of them just call 'gomp_thread ()' which is a simple > inline function such that no function call remains.
leaf attribute doesn't mark functions which don't call other functions, whether they call other functions or not is an implementation detail. Quoting docs: "Calls to external functions with this attribute must return to the current compilation unit only by return or by exception handling. In particular, a leaf function is not allowed to invoke callback functions passed to it from the current compilation unit, directly call functions exported by the unit, or @code{longjmp} into the unit. Leaf functions might still call functions from other compilation units and thus they are not necessarily leaf in the sense that they contain no function calls at all." So, leaf shouldn't be present on functions which have callbacks, or which can modify global variables a TU cares about etc. And sometimes leaf shouldn't be used on a function that does something difficult to describe and without leaf attribute the optimizers will treat it properly. E.g. for omp_is_initial_device, we mainly need to care that void foo () { int a = omp_is_initial_device (); #pragma omp target { int b = omp_is_initial_device (); use (a, b); } int c = omp_is_initial_device (); use (a, c); } we don't try to CSE/VN the call from outside of the target region with the call from inside of it; it is fine to CSE/VN the two calls outside of it. I think this ought to work fine, because omp expansion is done pretty soon. It is ok if GENERIC folding CSEs stuff in the same expression for it or fold_stmt again on the same stmt, but things wouldn't work well if some forwprop/fre/pre etc. were done before the omp expansion, we'd perhaps need to privatize some extra variables etc. and the builtin should have different results between those. So, what side-effect visible to the current TU does omp_get_mapped_ptr have? And what omp_get_interop_int? Jakub