llvm-project/clang/lib
Johannes Doerfert df729e2b82 [OpenMP] Overhaul `declare target` handling
This patch fixes various issues with our prior `declare target` handling
and extends it to support `omp begin declare target` as well.

This started with PR49649 in mind, trying to provide a way for users to
avoid the "ref" global use introduced for globals with internal linkage.
From there it went down the rabbit hole, e.g., all variables, even
`nohost` ones, were emitted into the device code so it was impossible to
determine if "ref" was needed late in the game (based on the name only).
To make it really useful, `begin declare target` was needed as it can
carry the `device_type`. Not emitting variables eagerly had a ripple
effect. Finally, the precedence of the (explicit) declare target list
items needed to be taken into account, that meant we cannot just look
for any declare target attribute to make a decision. This caused the
handling of functions to require fixup as well.

I tried to clean up things while I was at it, e.g., we should not "parse
declarations and defintions" as part of OpenMP parsing, this will always
break at some point. Instead, we keep track what region we are in and
act on definitions and declarations instead, this is what we do for
declare variant and other begin/end directives already.

Highlights:
  - new diagnosis for restrictions specificed in the standard,
  - delayed emission of globals not mentioned in an explicit
    list of a declare target,
  - omission of `nohost` globals on the host and `host` globals on the
    device,
  - no explicit parsing of declarations in-between `omp [begin] declare
    variant` and the corresponding end anymore, regular parsing instead,
  - precedence for explicit mentions in `declare target` lists over
    implicit mentions in the declaration-definition-seq, and
  - `omp allocate` declarations will now replace an earlier emitted
    global, if necessary.

---

Notes:

The patch is larger than I hoped but it turns out that most changes do
on their own lead to "inconsistent states", which seem less desirable
overall.

After working through this I feel the standard should remove the
explicit declare target forms as the delayed emission is horrible.
That said, while we delay things anyway, it seems to me we check too
often for the current status even though that is often not sufficient to
act upon. There seems to be a lot of duplication that can probably be
trimmed down. Eagerly emitting some things seems pretty weak as an
argument to keep so much logic around.

---

Reviewed By: ABataev

Differential Revision: https://reviews.llvm.org/D101030
2021-05-06 02:10:41 -05:00
..
APINotes [clang][APINotes] Fix -Wunused-function warning (NFC) 2021-04-01 09:52:43 +08:00
ARCMigrate [SystemZ][z/OS] Set files in FileRemapper.cpp are text 2021-04-19 07:59:42 -04:00
AST [OpenMP] Overhaul `declare target` handling 2021-05-06 02:10:41 -05:00
ASTMatchers [ASTMatchers] Add `cxxBaseSpecifier` matcher (non-top-level) 2021-04-09 00:05:36 +01:00
Analysis Thread safety analysis: Fix false negative on break 2021-05-03 14:03:17 +02:00
Basic [OpenCL] Add clang extension for non-portable kernel parameters. 2021-05-05 14:58:23 +01:00
CodeGen [OpenMP] Overhaul `declare target` handling 2021-05-06 02:10:41 -05:00
CrossTU [analyzer][CTU] API for CTU macro expansions 2021-02-22 11:12:22 +01:00
DirectoryWatcher Revert "ADT: Migrate users of AlignedCharArrayUnion to std::aligned_union_t, NFC" 2020-12-14 17:04:06 -08:00
Driver [Clang] remove text extension from diag::err_drv_invalid_value_with_suggestion 2021-05-05 11:01:43 -07:00
Edit [Matrix] Implement C-style explicit type conversions for matrix types. 2021-04-10 11:48:41 +01:00
Format [Format] Don't sort includes if DisableFormat is true 2021-05-04 19:04:12 +01:00
Frontend [clang] Add -fc++-abi= flag for specifying which C++ ABI to use 2021-05-04 10:52:13 -07:00
FrontendTool
Headers [OpenMP] Make sure classes work on the device as they do on the host 2021-05-06 02:10:30 -05:00
Index [index] Improve macro indexing support 2021-04-06 09:12:14 -07:00
IndexSerialization [index-while-building] Fix build with -DBUILD_SHARED_LIBS=True 2020-08-20 15:12:56 +01:00
Lex [C++2b] Support size_t literals 2021-03-31 13:36:23 +00:00
Parse [OpenMP] Overhaul `declare target` handling 2021-05-06 02:10:41 -05:00
Rewrite [clang] DeltaTree::AddDelta - fix "initialization is never read" clang-tidy warning. NFCI. 2021-03-02 15:01:34 +00:00
Sema [OpenMP] Overhaul `declare target` handling 2021-05-06 02:10:41 -05:00
Serialization [clang] Spell correct variable 2021-05-03 05:33:47 -07:00
StaticAnalyzer [analyzer] Fix assertion in SVals.h 2021-04-30 11:00:43 -05:00
Testing
Tooling Support: Stop using F_{None,Text,Append} compatibility synonyms, NFC 2021-04-30 11:00:03 -07:00
CMakeLists.txt APINotes: add APINotesYAMLCompiler 2020-11-05 18:55:13 +00:00