llvm-project/clang/test/OpenMP/begin_declare_variant_using...

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

62 lines
1.7 KiB
C++
Raw Normal View History

[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-02-26 06:04:06 +08:00
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fopenmp -verify %s
namespace BEFORE_AND_1 {
void before_and_1();
}
namespace AFTER_AND_2 {
void after_and_2(); // expected-note {{'AFTER_AND_2::after_and_2' declared here}} expected-note {{'AFTER_AND_2::after_and_2' declared here}}
}
namespace ONLY_1 {
void only_1(); // expected-note {{'ONLY_1::only_1' declared here}}
}
namespace BEFORE_1_AND_2 {
void before_1_and_2();
}
using BEFORE_1_AND_2::before_1_and_2;
using BEFORE_AND_1::before_and_1;
void test_before() {
before_and_1();
after_and_2(); // expected-error {{use of undeclared identifier 'after_and_2'; did you mean 'AFTER_AND_2::after_and_2'?}}
only_1(); // expected-error {{use of undeclared identifier 'only_1'; did you mean 'ONLY_1::only_1'?}}
before_1_and_2();
}
#pragma omp begin declare variant match(implementation = {vendor(llvm)})
using BEFORE_1_AND_2::before_1_and_2;
using BEFORE_AND_1::before_and_1;
using ONLY_1::only_1;
void test_1() {
before_and_1();
after_and_2(); // expected-error {{use of undeclared identifier 'after_and_2'; did you mean 'AFTER_AND_2::after_and_2'?}}
only_1();
before_1_and_2();
}
#pragma omp end declare variant
#pragma omp begin declare variant match(implementation = {vendor(llvm)})
using AFTER_AND_2::after_and_2;
using BEFORE_1_AND_2::before_1_and_2;
void test_2() {
before_and_1();
after_and_2();
only_1();
before_1_and_2();
}
#pragma omp end declare variant
void test_after() {
before_and_1();
after_and_2();
only_1();
before_1_and_2();
}
using AFTER_AND_2::after_and_2;
// Make sure:
// - we do not see the ast nodes for the gpu kind
// - we do not choke on the text in the kind(fpga) guarded scopes
// - we pick the right cbefore_1_and_2ees