llvm-project/clang/lib/Sema
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
..
AnalysisBasedWarnings.cpp Revert "[clang] detect switch fallthrough marked by a comment (PR43465)" 2020-03-02 22:33:25 +01:00
CMakeLists.txt [Sema] Split availability processing into SemaAvailability.cpp 2020-01-24 17:35:39 -08:00
CodeCompleteConsumer.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CoroutineStmtBuilder.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
DeclSpec.cpp Avoid SourceManager.h include in RawCommentList.h, add missing incs 2020-02-27 13:49:40 -08:00
DelayedDiagnostic.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
IdentifierResolver.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
JumpDiagnostics.cpp [CodeGen] Emit destructor calls to destruct compound literals 2020-03-10 14:08:28 -07:00
MultiplexExternalSemaSource.cpp recommit 1b978ddba0 [CUDA][HIP][OpenMP] Emit deferred diagnostics by a post-parsing AST travese 2020-03-23 12:09:07 -04:00
OpenCLBuiltins.td [OpenCL] Add pipe and kernel enqueuing builtins 2020-03-17 13:15:32 +00:00
ParsedAttr.cpp Add ParsedAttrInfo::handleDeclAttribute 2020-03-23 13:23:11 +00:00
Scope.cpp Un-revert "[coroutines][PR40978] Emit error for co_yield within catch block" 2019-03-25 00:53:10 +00:00
ScopeInfo.cpp PR42104: Support instantiations of lambdas that implicitly capture 2019-06-04 17:17:20 +00:00
Sema.cpp recommit 1b978ddba0 [CUDA][HIP][OpenMP] Emit deferred diagnostics by a post-parsing AST travese 2020-03-23 12:09:07 -04:00
SemaAccess.cpp [c++20] Delete defaulted comparison functions if they would invoke an 2019-12-10 19:28:30 -08:00
SemaAttr.cpp Make llvm::StringRef to std::string conversions explicit. 2020-01-28 23:25:25 +01:00
SemaAvailability.cpp Prune TargetInfo.h include from ParsedAttr.h, NFC 2020-03-11 20:47:11 -07:00
SemaCUDA.cpp recommit 1b978ddba0 [CUDA][HIP][OpenMP] Emit deferred diagnostics by a post-parsing AST travese 2020-03-23 12:09:07 -04:00
SemaCXXScopeSpec.cpp [Clang] Migrate llvm::make_unique to std::make_unique 2019-08-14 23:04:18 +00:00
SemaCast.cpp [Sema][SVE] Allow casting SVE types to themselves in C 2020-03-25 10:52:43 +00:00
SemaChecking.cpp [clang] Fix crash during template sema checking 2020-03-21 12:42:06 +01:00
SemaCodeComplete.cpp [Sema][CodeComplete] Handle symlinks for include code completion 2020-02-19 11:45:58 -05:00
SemaConcept.cpp [Concepts] Add missing CXXThisScope to function template constraint substitution 2020-02-05 01:10:35 +02:00
SemaConsumer.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
SemaCoroutine.cpp Fix "pointer is null" static analyzer warnings. NFCI. 2020-01-09 12:05:48 +00:00
SemaDecl.cpp [OpenMP] `omp begin/end declare variant` - part 2, sema ("+CG") 2020-03-27 02:30:58 -05:00
SemaDeclAttr.cpp [cuda][hip] Add CUDA builtin surface/texture reference support. 2020-03-26 14:44:52 -04:00
SemaDeclCXX.cpp [cuda][hip] Add CUDA builtin surface/texture reference support. 2020-03-26 14:44:52 -04:00
SemaDeclObjC.cpp [objc_direct] also go through implementations when looking for clashes 2020-03-23 20:49:09 -07:00
SemaExceptionSpec.cpp [AST] Add RecoveryExpr to retain expressions on semantic errors 2020-03-24 09:20:37 +01:00
SemaExpr.cpp [OpenMP] `omp begin/end declare variant` - part 2, sema ("+CG") 2020-03-27 02:30:58 -05:00
SemaExprCXX.cpp [CodeGen] Emit destructor calls to destruct non-trivial C struct objects 2020-03-20 18:34:22 -07:00
SemaExprMember.cpp Resolve exception specifications after marking the corresponding 2019-12-15 22:02:30 -08:00
SemaExprObjC.cpp [objc_direct] Small updates to help with adoption. 2020-02-16 16:32:41 -08:00
SemaFixItUtils.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
SemaInit.cpp [clang] Add support for consteval constructors 2020-03-20 11:33:54 +01:00
SemaLambda.cpp [Sema][SVE] Don't allow fields to have sizeless type 2020-03-13 19:22:23 +00:00
SemaLookup.cpp Fix handling of destructor names that name typedefs. 2020-02-10 02:21:01 -08:00
SemaModule.cpp [DeclCXX] Remove unknown external linkage specifications 2019-11-21 15:23:05 +02:00
SemaObjCProperty.cpp [NFC] Remove trailing space 2020-02-18 10:49:13 +08:00
SemaOpenMP.cpp [OpenMP] `omp begin/end declare variant` - part 2, sema ("+CG") 2020-03-27 02:30:58 -05:00
SemaOverload.cpp [c++20] Further extend the set of comparisons broken by C++20 that we 2020-03-20 14:22:48 -07:00
SemaPseudoObject.cpp [OpenMP] `omp begin/end declare variant` - part 2, sema ("+CG") 2020-03-27 02:30:58 -05:00
SemaStmt.cpp [OpenMP] `omp begin/end declare variant` - part 2, sema ("+CG") 2020-03-27 02:30:58 -05:00
SemaStmtAsm.cpp Support output constraints on "asm goto" 2020-02-24 18:51:29 -08:00
SemaStmtAttr.cpp [NFCI]Create CommonAttributeInfo Type as base type of *Attr and ParsedAttr. 2019-09-13 17:39:31 +00:00
SemaTemplate.cpp [clang] Fix crash on visiting null nestedNameSpecifier. 2020-03-18 09:15:02 +01:00
SemaTemplateDeduction.cpp PR44890: Inherit explicitly-specified template arguments into base class 2020-02-15 02:16:21 -08:00
SemaTemplateInstantiate.cpp [SYCL] Implement __builtin_unique_stable_name. 2020-03-25 07:01:50 -07:00
SemaTemplateInstantiateDecl.cpp [OpenMP][NFC] Minimize memory usage and copying of `OMPTraitInfo`s 2020-03-23 14:23:46 -05:00
SemaTemplateVariadic.cpp [NFC] Remove trailing space 2020-02-18 10:49:13 +08:00
SemaType.cpp [ARM][CMSE] Implement CMSE attributes 2020-03-24 10:21:26 +00:00
TreeTransform.h [AST] Add RecoveryExpr to retain expressions on semantic errors 2020-03-24 09:20:37 +01:00
TypeLocBuilder.cpp [NFC] avoid AlignedCharArray in clang 2019-07-29 23:12:48 +00:00
TypeLocBuilder.h [NFC] avoid AlignedCharArray in clang 2019-07-29 23:12:48 +00:00
UsedDeclVisitor.h recommit 1b978ddba0 [CUDA][HIP][OpenMP] Emit deferred diagnostics by a post-parsing AST travese 2020-03-23 12:09:07 -04:00