Changes

Summary

  1. [OpenMP] Make sure classes work on the device as they do on the host (details)
  2. [OpenMP] Ensure the DefaultMapperId has a location (details)
  3. [OpenMP] Overhaul `declare target` handling (details)
Commit 5d8d994dfbe38fe86b1d883daa9fd8e47cdc1376 by johannes
[OpenMP] Make sure classes work on the device as they do on the host

We do provide `operator delete(void*)` in `<new>` but it should be
available by default. This is mostly boilerplate to test it and the
unconditional include of `<new>` in the header we always in include
on the device.

Reviewed By: JonChesterfield

Differential Revision: https://reviews.llvm.org/D100620
The file was modifiedclang/test/Headers/Inputs/include/stdlib.h
The file was addedclang/test/Headers/target_include_new.cpp
The file was modifiedclang/lib/Headers/openmp_wrappers/__clang_openmp_device_functions.h
The file was modifiedclang/lib/Headers/openmp_wrappers/new
The file was addedclang/test/Headers/Inputs/include/new
Commit 3f14596700093bce436ae27178c307e842398b65 by johannes
[OpenMP] Ensure the DefaultMapperId has a location

A user reported an assertion (below) but without a reproducer. I failed to
create a test myself but from the assertion one can derive the problem.
I set the DefaultMapperId location now to make sure this doesn't cause
trouble.

```
clang-13: .../DeclTemplate.h:1940:
void clang::ClassTemplateSpecializationDecl::setPointOfInstantiation(clang::SourceLocation):
Assertion `Loc.isValid() && "point of instantiation must be valid!"' failed.
```

Reviewed By: JonChesterfield

Differential Revision: https://reviews.llvm.org/D100621
The file was modifiedclang/lib/Sema/SemaOpenMP.cpp
Commit df729e2b82b3cfc602a2295b95b7fa55ab423e88 by johannes
[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
The file was modifiedclang/lib/CodeGen/CodeGenModule.cpp
The file was modifiedclang/lib/CodeGen/CodeGenModule.h
The file was modifiedclang/test/OpenMP/irbuilder_nested_parallel_for.c
The file was modifiedclang/test/OpenMP/for_firstprivate_codegen.cpp
The file was modifiedclang/test/OpenMP/nvptx_declare_variant_name_mangling.cpp
The file was modifiedclang/test/utils/update_cc_test_checks/Inputs/generated-funcs.c.no-generated.expected
The file was modifiedclang/include/clang/Basic/DiagnosticSemaKinds.td
The file was modifiedclang/test/OpenMP/sections_firstprivate_codegen.cpp
The file was modifiedclang/test/OpenMP/irbuilder_for_iterator.cpp
The file was modifiedclang/lib/AST/AttrImpl.cpp
The file was modifiedclang/test/Headers/nvptx_device_math_complex.c
The file was modifiedclang/test/OpenMP/task_codegen.cpp
The file was modifiedclang/test/OpenMP/tile_codegen.cpp
The file was modifiedclang/lib/Parse/ParseOpenMP.cpp
The file was modifiedclang/test/OpenMP/irbuilder_for_unsigned.c
The file was modifiedclang/test/OpenMP/irbuilder_for_rangefor.cpp
The file was modifiedclang/test/OpenMP/irbuilder_nested_openmp_parallel_empty.c
The file was modifiedclang/test/OpenMP/declare_target_messages.cpp
The file was modifiedclang/test/OpenMP/remarks_parallel_in_multiple_target_state_machines.c
The file was modifiedclang/lib/CodeGen/CGDecl.cpp
The file was modifiedclang/test/OpenMP/nvptx_declare_target_var_ctor_dtor_codegen.cpp
The file was modifiedclang/include/clang/Sema/Sema.h
The file was modifiedclang/test/OpenMP/nvptx_multi_target_parallel_codegen.cpp
The file was modifiedclang/test/OpenMP/parallel_for_codegen.cpp
The file was addedclang/test/OpenMP/declare_target_only_one_side_compilation.cpp
The file was modifiedclang/include/clang/Basic/Attr.td
The file was modifiedclang/test/OpenMP/parallel_master_taskloop_codegen.cpp
The file was modifiedclang/test/OpenMP/taskgroup_codegen.cpp
The file was removedclang/test/OpenMP/declare_target_device_only_compilation.cpp
The file was modifiedclang/test/OpenMP/remarks_parallel_in_target_state_machine.c
The file was modifiedclang/include/clang/Basic/DiagnosticParseKinds.td
The file was modifiedclang/test/OpenMP/single_firstprivate_codegen.cpp
The file was modifiedllvm/include/llvm/Frontend/OpenMP/OMP.td
The file was modifiedclang/lib/Sema/SemaDecl.cpp
The file was modifiedclang/test/OpenMP/parallel_master_taskloop_simd_codegen.cpp
The file was modifiedclang/test/OpenMP/single_codegen.cpp
The file was modifiedclang/test/OpenMP/nvptx_nested_parallel_codegen.cpp
The file was modifiedclang/test/OpenMP/nvptx_target_codegen.cpp
The file was modifiedclang/test/OpenMP/threadprivate_codegen.cpp
The file was modifiedclang/test/OpenMP/declare_target_codegen_globalization.cpp
The file was modifiedclang/lib/CodeGen/CGOpenMPRuntime.cpp
The file was modifiedclang/test/utils/update_cc_test_checks/Inputs/generated-funcs.c.generated.expected
The file was modifiedclang/lib/Sema/SemaOpenMP.cpp
The file was modifiedclang/include/clang/Parse/Parser.h