llvm-project/clang/lib/Parse
Johannes Doerfert befb4be3a8 [OpenMP] `omp begin/end declare variant` - part 2, sema ("+CG")
This is the second part loosely extracted from 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].
The sema handling makes code generation obsolete as we generate "the
right" calls that can just be handled as usual. This handling also
applies to the existing, albeit problematic, `omp declare variant
support`. As a consequence a lot of unneeded code generation and
complexity is removed.

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:

If we have seen a `#pragma omp begin declare variant match(<SELECTOR>)`
but not the corresponding `end declare variant`, and we find a function
definition we will:
  1) Create a function declaration for the definition we were about to generate.
  2) Create a function definition but with a mangled name (according to
     `<SELECTOR>`).
  3) Annotate the declaration with the `OMPDeclareVariantAttr`, the same
     one used already for `omp declare variant`, using and the mangled
     function definition as specialization for the context defined by
     `<SELECTOR>`.

When a call is created we inspect it. If the target has an
`OMPDeclareVariantAttr` attribute we try to specialize the call. To this
end, all variants are checked, the best applicable one is picked and a
new call to the specialization is created. The new call is used instead
of the original one to the base function. To keep the AST printing and
tooling possible we utilize the PseudoObjectExpr. The original call is
the syntactic expression, the specialized call is the semantic
expression.

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

Reviewers: kiranchandramohan, ABataev, RaviNarayanaswamy, gtbercea, grokos, sdmitriev, JonChesterfield, hfinkel, fghanim, aaron.ballman

Subscribers: bollu, guansong, openmp-commits, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D75779
2020-03-27 02:30:58 -05:00
..
CMakeLists.txt [OpenMP][NFCI] Introduce llvm/IR/OpenMPConstants.h 2019-12-10 00:10:09 -06:00
ParseAST.cpp [Support] Add TimeTraceScope constructor without detail arg 2019-12-11 14:32:21 +00:00
ParseCXXInlineMethods.cpp [Concepts] Placeholder constraints and abbreviated templates 2020-01-23 19:39:43 +02:00
ParseDecl.cpp Clean up and simplify after collision of c48442c and 19fccc5, which 2020-03-20 14:53:09 -07:00
ParseDeclCXX.cpp PR45267: Don't reject pure-specifiers with escaped newlines in their '0' token. 2020-03-20 18:44:55 -07:00
ParseExpr.cpp [AST] Build recovery expressions for nonexistent member exprs. 2020-03-26 08:50:33 +01:00
ParseExprCXX.cpp PR45142: 'template ~X<T>' is ill-formed; reject it rather than crashing. 2020-03-23 15:07:06 -07:00
ParseInit.cpp [clang][CodeComplete] Support for designated initializers 2020-01-28 16:34:15 +01:00
ParseObjc.cpp Prune TargetInfo.h include from ParsedAttr.h, NFC 2020-03-11 20:47:11 -07:00
ParseOpenMP.cpp [OpenMP] `omp begin/end declare variant` - part 2, sema ("+CG") 2020-03-27 02:30:58 -05:00
ParsePragma.cpp Fix docs and comments for max_tokens_total pragma 2020-02-07 11:37:14 +01:00
ParseStmt.cpp [FPEnv] Extended FPOptions with new attributes 2020-01-26 21:03:53 +07:00
ParseStmtAsm.cpp [Parser] Avoid spurious 'missing template' error in presence of typos. 2020-03-19 16:15:27 +01:00
ParseTemplate.cpp [Parser] Avoid spurious 'missing template' error in presence of typos. 2020-03-19 16:15:27 +01:00
ParseTentative.cpp [SYCL] Implement __builtin_unique_stable_name. 2020-03-25 07:01:50 -07:00
Parser.cpp [Parser] Avoid spurious 'missing template' error in presence of typos. 2020-03-19 16:15:27 +01:00