This is an archive of the discontinued LLVM Phabricator instance.

[OpenMP] Define omp_is_initial_device() variants in omp.h
ClosedPublic

Authored by hbae on Mar 26 2021, 3:34 PM.

Details

Summary

omp_is_initial_device() is marked as a built-in function in the current
compiler, and user code guarded by this call may be optimized away,
resulting in undesired behavior in some cases. This patch provides a
possible fix for such cases by defining the routine as a variant
function. Full fix also requires removal of the routine from the
built-in function list in the compiler.

Diff Detail

Event Timeline

hbae created this revision.Mar 26 2021, 3:34 PM
hbae requested review of this revision.Mar 26 2021, 3:34 PM

Cool, can we get rid of the clang builtin while we are at it?

openmp/runtime/src/include/omp.h.var
479

Do we want them to be static? I would have expected odr linkage instead.

hbae updated this revision to Diff 335034.Apr 2 2021, 3:11 PM

Removed omp_is_initial_device() from clang built-ins.
Added a new test under openmp/libomptarget.

Herald added a project: Restricted Project. · View Herald TranscriptApr 2 2021, 3:11 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
hbae added inline comments.Apr 2 2021, 3:13 PM
openmp/runtime/src/include/omp.h.var
479

Current clang fails to link two files that include omp.h, so I think we need static here.

jdoerfert accepted this revision.Apr 2 2021, 10:24 PM

LG, thanks

openmp/runtime/src/include/omp.h.var
479

I would expect this to cause "unused function" warnings if you include omp.h.
That said, given that clang might be the only impl. so far for begin/end declare variant and it doesn't warn, we can go ahead.

This revision is now accepted and ready to land.Apr 2 2021, 10:24 PM

Nice, thanks! I think the function in the devicertl is dead with this change, maybe remove that too?

openmp/runtime/src/include/omp.h.var
479

'inline' is right for c++. Inline plus instantiation in library code right for c. Can we hit linkonce_odr from a clang attribute?

hbae updated this revision to Diff 335347.Apr 5 2021, 3:43 PM

Added inline after static to avoid unused function warning.
Added a RUN line to the test to catch unused function warning.

JonChesterfield accepted this revision.Apr 6 2021, 12:31 PM

LGTM, thanks!

This revision was automatically updated to reflect the committed changes.
clang/lib/AST/ExprConstant.cpp