[Openmp-commits] [PATCH] D75779: [OpenMP] `omp begin/end declare variant` - part 2, semantic analysis

Johannes Doerfert via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Fri Mar 6 15:29:45 PST 2020


jdoerfert created this revision.
jdoerfert added reviewers: kiranchandramohan, ABataev, RaviNarayanaswamy, gtbercea, grokos, sdmitriev, JonChesterfield, hfinkel, fghanim, aaron.ballman.
Herald added subscribers: guansong, bollu.
Herald added a project: clang.
jdoerfert added parent revisions: D75210: [Attr] Allow ParsedAttr to be constructor for any Attribute, D74941: [OpenMP] `omp begin/end declare variant` - part 1, parsing.

This is the second part loosely extracted from D71179 <https://reviews.llvm.org/D71179> and cleaned up.

This patch provides semantic analysis support for `omp begin/end declare
variant`, mostly as defined in OpenMP technical report 8 (TR8) [0].
Differences will be addressed as we finalize OpenMP 5.1, hopefully via
improved wording in the standard (as this is the first real
implementation).

A major purpose of this patch is to provide proper `math.h`/`cmath`
support for OpenMP target offloading. See PR42061, PR42798, PR42799. The
current code was developed with this feature in mind, see [1].

The logic is as follows:
A `#pragma omp begin declare variant match(<SELECTOR>)` is translated
into

  a `namespace __omp_declare_variant_scope {`, and
  a `#pragma clang attribute push (OMPMultiVersionDeclareVariantAttr(<SELECTOR>, apply_to=function(is_definition))`

The `#pragma omp end declare variant` will close the namespace and pop
the attribute. When the OMPMultiVersionDeclareVariantAttr is applied to
a function definition it is also renamed. Additionally, we create a
declaration outside of the namespace with the original name of the
definition and an OMPMultiVersionDeclareBaseAttr attribute which spreads
to all redeclarations as well. If a call to a function with the BaseAttr
is encountered we select the best matching function variant and replace
the callee if we found one. The logic uses namespaces, renaming, and
attributes to make sure the program is not affected by the variants
except if we replace a call to a base with a call to the specialization.

[0] https://www.openmp.org/wp-content/uploads/openmp-TR8.pdf
[1] https://reviews.llvm.org/D61399#change-496lQkg0mhRN


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75779

Files:
  clang/include/clang/AST/Decl.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Decl.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Parse/ParsePragma.cpp
  clang/lib/Sema/SemaAttr.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaLookup.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/test/AST/ast-dump-openmp-begin-declare-variant.c
  clang/test/AST/ast-dump-openmp-begin-declare-variant_1.c
  clang/test/AST/ast-dump-openmp-begin-declare-variant_2.c
  clang/test/AST/ast-dump-openmp-begin-declare-variant_3.c
  clang/test/AST/ast-dump-openmp-begin-declare-variant_4.c
  clang/test/AST/ast-dump-openmp-begin-declare-variant_5.c
  clang/test/AST/ast-dump-openmp-begin-declare-variant_6.c
  clang/test/AST/ast-dump-openmp-begin-declare-variant_7.c
  clang/test/AST/ast-dump-openmp-begin-declare-variant_8.c
  clang/test/AST/ast-dump-openmp-begin-declare-variant_9.c
  clang/test/AST/ast-dump-openmp-begin-declare-variant_addr_1.c
  clang/test/AST/ast-dump-openmp-begin-declare-variant_decl_1.c
  clang/test/OpenMP/begin-declare-variant_elided_range_withouth_end.c
  clang/test/OpenMP/begin-declare-variant_using_messages.cpp
  clang/test/OpenMP/declare_variant_begin_messages.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75779.248846.patch
Type: text/x-patch
Size: 119403 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20200306/0b4d27b5/attachment-0001.bin>


More information about the Openmp-commits mailing list