This is an archive of the discontinued LLVM Phabricator instance.

[OpenMP] Do not always emit unused extern variables
ClosedPublic

Authored by jhuber6 on Jul 26 2023, 2:07 PM.

Details

Summary

Currently, the precense of the OpenMP target declare metadata requires
that we always codegen a global declaration. This is undesirable in the
case that we could defer or omit this declaration as is common with
unused extern variables. This is important as it allows us, in the
runtime, to rely on static linking semantics to omit unused symbols so
they are not included when the user links it in.

This patch changes the check for always emitting these variables.
Because of this we also need to extend this logic to the generation of
the offloading entries. This has the result of derring the offload entry
generation to the canonical definitoin. So we are effectively assuming
whoever owns the storage for this variable will perform that operation.
This makes an exception for link attributes as those require their own
special handling.

Let me know if this is sound in the implementation, I do not have the
largest view of the standards here.

Fixes: https://github.com/llvm/llvm-project/issues/64133

Diff Detail

Event Timeline

jhuber6 created this revision.Jul 26 2023, 2:07 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 26 2023, 2:07 PM
jhuber6 requested review of this revision.Jul 26 2023, 2:07 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 26 2023, 2:07 PM
jhuber6 updated this revision to Diff 545168.Jul 28 2023, 7:56 AM

Add OpenMP runtime test

I think this is reasonable.

clang/test/OpenMP/declare_target_codegen.cpp
264

Since ccc is used here, it is not supposed to be removed right?

jhuber6 added inline comments.Jul 28 2023, 8:17 AM
clang/test/OpenMP/declare_target_codegen.cpp
264

This is the declare target metadta, which this patch no longer emits for external storage variables. Since we assume that whoever defined ccc will handle it.

tianshilei1992 accepted this revision.Jul 28 2023, 8:20 AM
This revision is now accepted and ready to land.Jul 28 2023, 8:20 AM
This revision was landed with ongoing or failed builds.Jul 28 2023, 9:52 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJul 28 2023, 9:52 AM