llvm-project/clang/lib
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
..
ARCMigrate Avoid SourceManager.h include in RawCommentList.h, add missing incs 2020-02-27 13:49:40 -08:00
AST [OpenMP] `omp begin/end declare variant` - part 2, sema ("+CG") 2020-03-27 02:30:58 -05:00
ASTMatchers [clang] Prune 'IsOMPStructuredBlock' Stmt bit 2020-03-12 14:48:57 +03:00
Analysis [[Clang CallGraph]] CallGraph should still record calls to decls. 2020-03-20 08:55:23 -07:00
Basic [OpenMP] `omp begin/end declare variant` - part 1, parsing 2020-03-27 02:30:58 -05:00
CodeGen [OpenMP] `omp begin/end declare variant` - part 2, sema ("+CG") 2020-03-27 02:30:58 -05:00
CrossTU [clang] Replace SmallStr.str().str() with std::string conversion operator. 2020-01-29 21:27:46 -08:00
DirectoryWatcher Add missing newlines at EOF; NFC 2020-02-12 15:57:25 +00:00
Driver Make PS4 use -fno-use-init-array only as the ABI does not support .init_array. 2020-03-26 15:45:40 -07:00
Edit [C++2a] Add __builtin_bit_cast, used to implement std::bit_cast 2019-07-02 18:28:13 +00:00
Format [clang-format] No space inserted between commas in C# 2020-03-23 17:17:27 +00:00
Frontend Revert "[AST] Build recovery expressions by default for C++." 2020-03-26 16:25:32 +01:00
FrontendTool Reland "[analyzer][NFC] Tie CheckerRegistry to CheckerManager, allow CheckerManager to be constructed for non-analysis purposes" 2020-03-26 16:12:38 +01:00
Headers [cuda][hip] Add CUDA builtin surface/texture reference support. 2020-03-26 14:44:52 -04:00
Index Avoid including FileManager.h from SourceManager.h 2020-03-11 13:53:12 -07:00
Lex [CodeComplete] Don't replace the rest of line in #include completion. 2020-03-26 11:03:04 +01:00
Parse [OpenMP] `omp begin/end declare variant` - part 2, sema ("+CG") 2020-03-27 02:30:58 -05:00
Rewrite [Rewrite][NFC] Add FIXMEs and tests for RemoveLineIfEmpty bug 2019-08-15 21:17:48 +00:00
Sema [OpenMP] `omp begin/end declare variant` - part 2, sema ("+CG") 2020-03-27 02:30:58 -05:00
Serialization [ARM][CMSE] Implement CMSE attributes 2020-03-24 10:21:26 +00:00
StaticAnalyzer [analyzer] Add the Preprocessor to CheckerManager 2020-03-26 17:29:52 +01:00
Tooling Fix unused variable warning 2020-03-24 11:51:49 +00:00
CMakeLists.txt Reland [clang] DirectoryWatcher 2019-07-12 20:34:10 +00:00