1*2cedaee6SMike Rice // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 \
2*2cedaee6SMike Rice // RUN: -fsyntax-only -verify %s
3*2cedaee6SMike Rice
4*2cedaee6SMike Rice // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 \
5*2cedaee6SMike Rice // RUN: -ast-print %s | FileCheck %s
6*2cedaee6SMike Rice
7*2cedaee6SMike Rice // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 \
8*2cedaee6SMike Rice // RUN: -emit-pch -o %t %s
9*2cedaee6SMike Rice
10*2cedaee6SMike Rice // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 \
11*2cedaee6SMike Rice // RUN: -include-pch %t -ast-print %s | FileCheck %s
12*2cedaee6SMike Rice
13*2cedaee6SMike Rice // expected-no-diagnostics
14*2cedaee6SMike Rice
15*2cedaee6SMike Rice #ifndef HEADER
16*2cedaee6SMike Rice #define HEADER
17*2cedaee6SMike Rice
18*2cedaee6SMike Rice typedef void **omp_allocator_handle_t;
19*2cedaee6SMike Rice extern const omp_allocator_handle_t omp_null_allocator;
20*2cedaee6SMike Rice extern const omp_allocator_handle_t omp_default_mem_alloc;
21*2cedaee6SMike Rice extern const omp_allocator_handle_t omp_large_cap_mem_alloc;
22*2cedaee6SMike Rice extern const omp_allocator_handle_t omp_const_mem_alloc;
23*2cedaee6SMike Rice extern const omp_allocator_handle_t omp_high_bw_mem_alloc;
24*2cedaee6SMike Rice extern const omp_allocator_handle_t omp_low_lat_mem_alloc;
25*2cedaee6SMike Rice extern const omp_allocator_handle_t omp_cgroup_mem_alloc;
26*2cedaee6SMike Rice extern const omp_allocator_handle_t omp_pteam_mem_alloc;
27*2cedaee6SMike Rice extern const omp_allocator_handle_t omp_thread_mem_alloc;
28*2cedaee6SMike Rice
29*2cedaee6SMike Rice //CHECK: template <typename T, int C> void templ_foo(T t) {
30*2cedaee6SMike Rice //CHECK: T j, z;
31*2cedaee6SMike Rice //CHECK: #pragma omp parallel loop collapse(C) reduction(+: z) lastprivate(j) bind(thread)
32*2cedaee6SMike Rice //CHECK: for (T i = 0; i < t; ++i)
33*2cedaee6SMike Rice //CHECK: for (j = 0; j < t; ++j)
34*2cedaee6SMike Rice //CHECK: z += i + j;
35*2cedaee6SMike Rice //CHECK: }
36*2cedaee6SMike Rice
37*2cedaee6SMike Rice //CHECK: template<> void templ_foo<int, 2>(int t) {
38*2cedaee6SMike Rice //CHECK: int j, z;
39*2cedaee6SMike Rice //CHECK: #pragma omp parallel loop collapse(2) reduction(+: z) lastprivate(j) bind(thread)
40*2cedaee6SMike Rice //CHECK: for (int i = 0; i < t; ++i)
41*2cedaee6SMike Rice //CHECK: for (j = 0; j < t; ++j)
42*2cedaee6SMike Rice //CHECK: z += i + j;
43*2cedaee6SMike Rice //CHECK: }
44*2cedaee6SMike Rice template <typename T, int C>
templ_foo(T t)45*2cedaee6SMike Rice void templ_foo(T t) {
46*2cedaee6SMike Rice
47*2cedaee6SMike Rice T j,z;
48*2cedaee6SMike Rice #pragma omp parallel loop collapse(C) reduction(+:z) lastprivate(j) bind(thread)
49*2cedaee6SMike Rice for (T i = 0; i<t; ++i)
50*2cedaee6SMike Rice for (j = 0; j<t; ++j)
51*2cedaee6SMike Rice z += i+j;
52*2cedaee6SMike Rice }
53*2cedaee6SMike Rice
54*2cedaee6SMike Rice
55*2cedaee6SMike Rice //CHECK: void test() {
test()56*2cedaee6SMike Rice void test() {
57*2cedaee6SMike Rice constexpr int N = 100;
58*2cedaee6SMike Rice float MTX[N][N];
59*2cedaee6SMike Rice int aaa[1000];
60*2cedaee6SMike Rice
61*2cedaee6SMike Rice //CHECK: #pragma omp target teams distribute parallel for map(tofrom: MTX)
62*2cedaee6SMike Rice //CHECK: #pragma omp parallel loop
63*2cedaee6SMike Rice #pragma omp target teams distribute parallel for map(MTX)
64*2cedaee6SMike Rice for (auto i = 0; i < N; ++i) {
65*2cedaee6SMike Rice #pragma omp parallel loop
66*2cedaee6SMike Rice for (auto j = 0; j < N; ++j) {
67*2cedaee6SMike Rice MTX[i][j] = 0;
68*2cedaee6SMike Rice }
69*2cedaee6SMike Rice }
70*2cedaee6SMike Rice
71*2cedaee6SMike Rice //CHECK: #pragma omp target teams
72*2cedaee6SMike Rice //CHECK: #pragma omp parallel loop
73*2cedaee6SMike Rice #pragma omp target teams
74*2cedaee6SMike Rice for (int i=0; i<1000; ++i) {
75*2cedaee6SMike Rice #pragma omp parallel loop
76*2cedaee6SMike Rice for (int j=0; j<100; j++) {
77*2cedaee6SMike Rice aaa[i] += i + j;
78*2cedaee6SMike Rice }
79*2cedaee6SMike Rice }
80*2cedaee6SMike Rice
81*2cedaee6SMike Rice int j, z, z1, z2 = 1, z3 = 2;
82*2cedaee6SMike Rice //CHECK: #pragma omp parallel loop collapse(2) private(z) lastprivate(j) order(concurrent) firstprivate(z2) num_threads(4) if(1) allocate(omp_default_mem_alloc: z2) shared(z3) reduction(+: z1) bind(parallel) proc_bind(primary)
83*2cedaee6SMike Rice #pragma omp parallel loop collapse(2) private(z) lastprivate(j) \
84*2cedaee6SMike Rice order(concurrent) firstprivate(z2) num_threads(4) if(1) \
85*2cedaee6SMike Rice allocate(omp_default_mem_alloc:z2) shared(z3) \
86*2cedaee6SMike Rice reduction(+:z1) bind(parallel) proc_bind(primary)
87*2cedaee6SMike Rice for (auto i = 0; i < N; ++i) {
88*2cedaee6SMike Rice for (j = 0; j < N; ++j) {
89*2cedaee6SMike Rice z = i+j;
90*2cedaee6SMike Rice MTX[i][j] = z;
91*2cedaee6SMike Rice z1 += z;
92*2cedaee6SMike Rice }
93*2cedaee6SMike Rice }
94*2cedaee6SMike Rice
95*2cedaee6SMike Rice //CHECK: #pragma omp target teams
96*2cedaee6SMike Rice //CHECK: #pragma omp parallel loop bind(teams)
97*2cedaee6SMike Rice #pragma omp target teams
98*2cedaee6SMike Rice #pragma omp parallel loop bind(teams)
99*2cedaee6SMike Rice for (auto i = 0; i < N; ++i) { }
100*2cedaee6SMike Rice
101*2cedaee6SMike Rice //CHECK: #pragma omp target
102*2cedaee6SMike Rice //CHECK: #pragma omp teams
103*2cedaee6SMike Rice //CHECK: #pragma omp parallel loop bind(teams)
104*2cedaee6SMike Rice #pragma omp target
105*2cedaee6SMike Rice #pragma omp teams
106*2cedaee6SMike Rice #pragma omp parallel loop bind(teams)
107*2cedaee6SMike Rice for (auto i = 0; i < N; ++i) { }
108*2cedaee6SMike Rice }
109*2cedaee6SMike Rice
110*2cedaee6SMike Rice //CHECK: void nobindingfunc() {
nobindingfunc()111*2cedaee6SMike Rice void nobindingfunc()
112*2cedaee6SMike Rice {
113*2cedaee6SMike Rice //CHECK: #pragma omp parallel loop
114*2cedaee6SMike Rice #pragma omp parallel loop
115*2cedaee6SMike Rice for (int i=0; i<10; ++i) { }
116*2cedaee6SMike Rice }
117*2cedaee6SMike Rice
bar()118*2cedaee6SMike Rice void bar()
119*2cedaee6SMike Rice {
120*2cedaee6SMike Rice templ_foo<int,2>(8);
121*2cedaee6SMike Rice }
122*2cedaee6SMike Rice
123*2cedaee6SMike Rice #endif // HEADER
124