[all-commits] [llvm/llvm-project] de59f5: [OpenMP] Support OpenMP 5.1 attributes

Aaron Ballman via All-commits all-commits at lists.llvm.org
Mon Jul 12 03:54:07 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: de59f564400de1b0fe30ae07f3c800562a025e27
      https://github.com/llvm/llvm-project/commit/de59f564400de1b0fe30ae07f3c800562a025e27
  Author: Aaron Ballman <aaron at aaronballman.com>
  Date:   2021-07-12 (Mon, 12 Jul 2021)

  Changed paths:
    M clang/docs/OpenMPSupport.rst
    M clang/include/clang/Basic/DiagnosticGroups.td
    M clang/include/clang/Basic/DiagnosticParseKinds.td
    M clang/include/clang/Basic/TokenKinds.def
    M clang/include/clang/Parse/Parser.h
    M clang/lib/Basic/Attributes.cpp
    M clang/lib/Parse/ParseCXXInlineMethods.cpp
    M clang/lib/Parse/ParseDecl.cpp
    M clang/lib/Parse/ParseDeclCXX.cpp
    M clang/lib/Parse/ParseOpenMP.cpp
    M clang/lib/Parse/ParseStmt.cpp
    M clang/lib/Parse/Parser.cpp
    A clang/test/OpenMP/allocate_codegen_attr.cpp
    A clang/test/OpenMP/assumes_messages_attr.c
    A clang/test/OpenMP/critical_codegen_attr.cpp
    A clang/test/OpenMP/masked_messages_attr.cpp
    A clang/test/OpenMP/openmp_attribute.cpp
    A clang/test/OpenMP/openmp_attribute_compat.cpp
    A clang/test/OpenMP/openmp_attribute_parsing.cpp
    A clang/test/OpenMP/target_map_names_attr.cpp
    A clang/test/OpenMP/taskloop_reduction_messages_attr.cpp
    A clang/test/OpenMP/teams_distribute_parallel_for_simd_num_teams_messages_attr.cpp
    A clang/test/OpenMP/unroll_codegen_unroll_for_attr.cpp

  Log Message:
  -----------
  [OpenMP] Support OpenMP 5.1 attributes

OpenMP 5.1 added support for writing OpenMP directives using [[]]
syntax in addition to using #pragma and this introduces support for the
new syntax.

In OpenMP, the attributes take one of two forms:
[[omp::directive(...)]] or [[omp::sequence(...)]]. A directive
attribute contains an OpenMP directive clause that is identical to the
analogous #pragma syntax. A sequence attribute can contain either
sequence or directive arguments and is used to ensure that the
attributes are processed sequentially for situations where the order of
the attributes matter (remember:
https://eel.is/c++draft/dcl.attr.grammar#4.sentence-4).

The approach taken here is somewhat novel and deserves mention. We
could refactor much of the OpenMP parsing logic to work for either
pragma annotation tokens or for attribute clauses. It would be a fair
amount of effort to share the logic for both, but it's certainly
doable. However, the semantic attribute system is not designed to
handle the arbitrarily complex arguments that OpenMP directives
contain. Adding support to thread the novel parsed information until we
can produce a semantic attribute would be considerably more effort.
What's more, existing OpenMP constructs are not (often) represented as
semantic attributes. So doing this through Attr.td would be a massive
undertaking that would likely only benefit OpenMP and comes with
additional risks. Rather than walk down that path, I am taking
advantage of the fact that the syntax of the directives within the
directive clause is identical to that of the #pragma form. Once the
parser recognizes that we're processing an OpenMP attribute, it caches
all of the directive argument tokens and then replays them as though
the user wrote a pragma. This reuses the same OpenMP parsing and
semantic logic directly, but does come with a risk if the OpenMP
committee decides to purposefully diverge their pragma and attribute
syntaxes. So, despite this being a novel approach that does token
replay, I think it's actually a better approach than trying to do this
through the declarative syntax in Attr.td.




More information about the All-commits mailing list