[all-commits] [llvm/llvm-project] df729e: [OpenMP] Overhaul `declare target` handling

Johannes Doerfert via All-commits all-commits at lists.llvm.org
Thu May 6 00:11:02 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: df729e2b82b3cfc602a2295b95b7fa55ab423e88
      https://github.com/llvm/llvm-project/commit/df729e2b82b3cfc602a2295b95b7fa55ab423e88
  Author: Johannes Doerfert <johannes at jdoerfert.de>
  Date:   2021-05-06 (Thu, 06 May 2021)

  Changed paths:
    M clang/include/clang/Basic/Attr.td
    M clang/include/clang/Basic/DiagnosticParseKinds.td
    M clang/include/clang/Basic/DiagnosticSemaKinds.td
    M clang/include/clang/Parse/Parser.h
    M clang/include/clang/Sema/Sema.h
    M clang/lib/AST/AttrImpl.cpp
    M clang/lib/CodeGen/CGDecl.cpp
    M clang/lib/CodeGen/CGOpenMPRuntime.cpp
    M clang/lib/CodeGen/CodeGenModule.cpp
    M clang/lib/CodeGen/CodeGenModule.h
    M clang/lib/Parse/ParseOpenMP.cpp
    M clang/lib/Sema/SemaDecl.cpp
    M clang/lib/Sema/SemaOpenMP.cpp
    M clang/test/Headers/nvptx_device_math_complex.c
    M clang/test/OpenMP/declare_target_codegen_globalization.cpp
    R clang/test/OpenMP/declare_target_device_only_compilation.cpp
    M clang/test/OpenMP/declare_target_messages.cpp
    A clang/test/OpenMP/declare_target_only_one_side_compilation.cpp
    M clang/test/OpenMP/for_firstprivate_codegen.cpp
    M clang/test/OpenMP/irbuilder_for_iterator.cpp
    M clang/test/OpenMP/irbuilder_for_rangefor.cpp
    M clang/test/OpenMP/irbuilder_for_unsigned.c
    M clang/test/OpenMP/irbuilder_nested_openmp_parallel_empty.c
    M clang/test/OpenMP/irbuilder_nested_parallel_for.c
    M clang/test/OpenMP/nvptx_declare_target_var_ctor_dtor_codegen.cpp
    M clang/test/OpenMP/nvptx_declare_variant_name_mangling.cpp
    M clang/test/OpenMP/nvptx_multi_target_parallel_codegen.cpp
    M clang/test/OpenMP/nvptx_nested_parallel_codegen.cpp
    M clang/test/OpenMP/nvptx_target_codegen.cpp
    M clang/test/OpenMP/parallel_for_codegen.cpp
    M clang/test/OpenMP/parallel_master_taskloop_codegen.cpp
    M clang/test/OpenMP/parallel_master_taskloop_simd_codegen.cpp
    M clang/test/OpenMP/remarks_parallel_in_multiple_target_state_machines.c
    M clang/test/OpenMP/remarks_parallel_in_target_state_machine.c
    M clang/test/OpenMP/sections_firstprivate_codegen.cpp
    M clang/test/OpenMP/single_codegen.cpp
    M clang/test/OpenMP/single_firstprivate_codegen.cpp
    M clang/test/OpenMP/task_codegen.cpp
    M clang/test/OpenMP/taskgroup_codegen.cpp
    M clang/test/OpenMP/threadprivate_codegen.cpp
    M clang/test/OpenMP/tile_codegen.cpp
    M clang/test/utils/update_cc_test_checks/Inputs/generated-funcs.c.generated.expected
    M clang/test/utils/update_cc_test_checks/Inputs/generated-funcs.c.no-generated.expected
    M llvm/include/llvm/Frontend/OpenMP/OMP.td

  Log Message:
  -----------
  [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




More information about the All-commits mailing list