166 lines · cpp
1// RUN: %clang_cc1 -verify -fopenmp -ast-print %s -Wno-openmp-mapping | FileCheck %s2// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -emit-pch -o %t %s -Wno-openmp-mapping3// RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -verify %s -ast-print -Wno-openmp-mapping | FileCheck %s4 5// RUN: %clang_cc1 -verify -fopenmp-simd -ast-print %s -Wno-openmp-mapping | FileCheck %s6// RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -emit-pch -o %t %s -Wno-openmp-mapping7// RUN: %clang_cc1 -fopenmp-simd -std=c++11 -include-pch %t -verify %s -ast-print -Wno-openmp-mapping | FileCheck %s8// expected-no-diagnostics9 10#ifndef HEADER11#define HEADER12 13typedef void **omp_allocator_handle_t;14extern const omp_allocator_handle_t omp_null_allocator;15extern const omp_allocator_handle_t omp_default_mem_alloc;16extern const omp_allocator_handle_t omp_large_cap_mem_alloc;17extern const omp_allocator_handle_t omp_const_mem_alloc;18extern const omp_allocator_handle_t omp_high_bw_mem_alloc;19extern const omp_allocator_handle_t omp_low_lat_mem_alloc;20extern const omp_allocator_handle_t omp_cgroup_mem_alloc;21extern const omp_allocator_handle_t omp_pteam_mem_alloc;22extern const omp_allocator_handle_t omp_thread_mem_alloc;23 24void foo() {}25 26struct S {27 S(): a(0) {}28 S(int v) : a(v) {}29 int a;30 typedef int type;31};32 33template <typename T>34class S7 : public T {35protected:36 T a;37 S7() : a(0) {}38 39public:40 S7(typename T::type v) : a(v) {41#pragma omp target teams distribute private(a) private(this->a) private(T::a)42 for (int k = 0; k < a.a; ++k)43 ++this->a.a;44 }45 S7 &operator=(S7 &s) {46#pragma omp target teams distribute private(a) private(this->a)47 for (int k = 0; k < s.a.a; ++k)48 ++s.a.a;49 return *this;50 }51 52 void foo() {53 int b, argv, d, c, e, f;54#pragma omp target teams distribute default(none), private(b) firstprivate(argv) shared(d) reduction(+:c) reduction(max:e) num_teams(f) thread_limit(d) allocate(omp_low_lat_mem_alloc:b) uses_allocators(omp_low_lat_mem_alloc)55 for (int k = 0; k < a.a; ++k)56 ++a.a;57 }58};59// CHECK: #pragma omp target teams distribute private(this->a) private(this->a) private(T::a)60// CHECK: #pragma omp target teams distribute private(this->a) private(this->a)61// CHECK: #pragma omp target teams distribute default(none) private(b) firstprivate(argv) shared(d) reduction(+: c) reduction(max: e) num_teams(f) thread_limit(d) allocate(omp_low_lat_mem_alloc: b) uses_allocators(omp_low_lat_mem_alloc)62// CHECK: #pragma omp target teams distribute private(this->a) private(this->a) private(this->S::a)63 64class S8 : public S7<S> {65 S8() {}66 67public:68 S8(int v) : S7<S>(v){69#pragma omp target teams distribute private(a) private(this->a) private(S7<S>::a)70 for (int k = 0; k < a.a; ++k)71 ++this->a.a;72 }73 S8 &operator=(S8 &s) {74#pragma omp target teams distribute private(a) private(this->a)75 for (int k = 0; k < s.a.a; ++k)76 ++s.a.a;77 return *this;78 }79 80 void bar() {81 int b, argv, d, c, e, f;82#pragma omp target teams distribute allocate(argv) default(none), private(b) firstprivate(argv) shared(d) reduction(+:c) reduction(max:e) num_teams(f) thread_limit(d) allocate(e)83 for (int k = 0; k < a.a; ++k)84 ++a.a;85 }86};87// CHECK: #pragma omp target teams distribute private(this->a) private(this->a) private(this->S7<S>::a)88// CHECK: #pragma omp target teams distribute private(this->a) private(this->a)89// CHECK: #pragma omp target teams distribute allocate(argv) default(none) private(b) firstprivate(argv) shared(d) reduction(+: c) reduction(max: e) num_teams(f) thread_limit(d) allocate(e)90 91template <class T, int N>92T tmain(T argc) {93 T b = argc, c, d, e, f, g;94 static T a;95// CHECK: static T a;96#pragma omp target teams distribute97 for (int i=0; i < 2; ++i)98 a = 2;99// CHECK: #pragma omp target teams distribute{{$}}100// CHECK-NEXT: for (int i = 0; i < 2; ++i)101// CHECK-NEXT: a = 2;102#pragma omp target teams distribute private(argc, b), firstprivate(c, d), collapse(2)103 for (int i = 0; i < 10; ++i)104 for (int j = 0; j < 10; ++j)105 foo();106// CHECK: #pragma omp target teams distribute private(argc,b) firstprivate(c,d) collapse(2)107// CHECK-NEXT: for (int i = 0; i < 10; ++i)108// CHECK-NEXT: for (int j = 0; j < 10; ++j)109// CHECK-NEXT: foo();110 for (int i = 0; i < 10; ++i)111 foo();112// CHECK: for (int i = 0; i < 10; ++i)113// CHECK-NEXT: foo();114#pragma omp target teams distribute115 for (int i = 0; i < 10; ++i)116 foo();117// CHECK: #pragma omp target teams distribute118// CHECK-NEXT: for (int i = 0; i < 10; ++i)119// CHECK-NEXT: foo(); 120#pragma omp target teams distribute default(none), private(b) firstprivate(argc) shared(d) reduction(+:c) reduction(max:e) num_teams(f) thread_limit(d)121 for (int k = 0; k < 10; ++k)122 e += d + argc;123// CHECK: #pragma omp target teams distribute default(none) private(b) firstprivate(argc) shared(d) reduction(+: c) reduction(max: e) num_teams(f) thread_limit(d)124// CHECK-NEXT: for (int k = 0; k < 10; ++k)125// CHECK-NEXT: e += d + argc;126 return T();127}128 129int main (int argc, char **argv) {130 int b = argc, c, d, e, f, g;131 static int a;132// CHECK: static int a;133#pragma omp target teams distribute134 for (int i=0; i < 2; ++i)135 a = 2;136// CHECK: #pragma omp target teams distribute137// CHECK-NEXT: for (int i = 0; i < 2; ++i)138// CHECK-NEXT: a = 2;139#pragma omp target teams distribute private(argc,b),firstprivate(argv, c), collapse(2)140 for (int i = 0; i < 10; ++i)141 for (int j = 0; j < 10; ++j)142 foo();143// CHECK: #pragma omp target teams distribute private(argc,b) firstprivate(argv,c) collapse(2)144// CHECK-NEXT: for (int i = 0; i < 10; ++i)145// CHECK-NEXT: for (int j = 0; j < 10; ++j)146// CHECK-NEXT: foo();147 for (int i = 0; i < 10; ++i)148 foo();149// CHECK: for (int i = 0; i < 10; ++i)150// CHECK-NEXT: foo();151#pragma omp target teams distribute152 for (int i = 0; i < 10; ++i)foo();153// CHECK: #pragma omp target teams distribute154// CHECK-NEXT: for (int i = 0; i < 10; ++i)155// CHECK-NEXT: foo();156#pragma omp target teams distribute default(none), private(b) firstprivate(argc) shared(d) reduction(+:c) reduction(max:e) num_teams(f) thread_limit(d)157 for (int k = 0; k < 10; ++k)158 e += d + argc;159// CHECK: #pragma omp target teams distribute default(none) private(b) firstprivate(argc) shared(d) reduction(+: c) reduction(max: e) num_teams(f) thread_limit(d)160// CHECK-NEXT: for (int k = 0; k < 10; ++k)161// CHECK-NEXT: e += d + argc;162 return (0);163}164 165#endif166