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.
- 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.
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
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.