1 // Test target codegen - host bc file has to be created first.
2 // RUN: %clang_cc1 -DCK1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fomptargets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc
3 // RUN: %clang_cc1 -DCK1 -verify -fopenmp -x c++ -triple nvptx64-unknown-unknown -fomptargets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fomp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s --check-prefix CK1 --check-prefix CK1-64
4 // RUN: %clang_cc1 -DCK1 -verify -fopenmp -x c++ -triple i386-unknown-unknown -fomptargets=nvptx-nvidia-cuda -emit-llvm-bc %s -o %t-x86-host.bc
5 // RUN: %clang_cc1 -DCK1 -verify -fopenmp -x c++ -triple nvptx-unknown-unknown -fomptargets=nvptx-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fomp-host-ir-file-path %t-x86-host.bc -o - | FileCheck %s --check-prefix CK1 --check-prefix CK1-32
6 // expected-no-diagnostics
7 #ifndef HEADER
8 #define HEADER
9 
10 #ifdef CK1
11 
12 template <typename T>
13 int tmain(T argc) {
14 #pragma omp target
15 #pragma omp teams
16   argc = 0;
17   return 0;
18 }
19 
20 
21 int main (int argc, char **argv) {
22 #pragma omp target
23 #pragma omp teams
24   {
25   argc = 0;
26   }
27   return tmain(argv);
28 }
29 
30 // only nvptx side: do not outline teams region and do not call fork_teams
31 // CK1:  define {{.*}}void @{{[^,]+}}(i{{[0-9]+}} [[ARGC:%.+]])
32 // CK1:  {{.+}} = alloca i{{[0-9]+}}*,
33 // CK1:  {{.+}} = alloca i{{[0-9]+}}*,
34 // CK1:  [[ARGCADDR_PTR:%.+]] = alloca i{{[0-9]+}}*,
35 // CK1:  [[ARGCADDR:%.+]] = alloca i{{[0-9]+}},
36 // CK1:  store {{.+}} 0, {{.+}},
37 // CK1:  store i{{[0-9]+}} [[ARGC]], i{{[0-9]+}}* [[ARGCADDR]],
38 // CK1-64:  [[CONV:%.+]] = bitcast i{{[0-9]+}}* [[ARGCADDR]] to i{{[0-9]+}}*
39 // CK1-64:  store i{{[0-9]+}}* [[CONV]], i{{[0-9]+}}** [[ARGCADDR_PTR]],
40 // CK1-32:  store i{{[0-9]+}}* [[ARGCADDR]], i{{[0-9]+}}** [[ARGCADDR_PTR]],
41 // CK1:  [[ARGCADDR_PTR_REF:%.+]] = load i{{[0-9]+}}*, i{{[0-9]+}}** [[ARGCADDR_PTR]],
42 // CK1:  store i{{[0-9]+}} 0, i{{[0-9]+}}* [[ARGCADDR_PTR_REF]],
43 // CK1-NOT: call {{.*}}void (%ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_teams(
44 // CK1:  ret void
45 // CK1-NEXT: }
46 
47 // target region in template
48 // CK1: define {{.*}}void @{{[^,]+}}(i{{.+}}***{{.+}} [[ARGC:%.+]])
49 // CK1: [[ARGCADDR_PTR:%.+]] = alloca i{{.+}}***,
50 // CK1: [[ARGCADDR:%.+]] = alloca i{{.+}}***,
51 // CK1: store i{{.+}}*** [[ARGC]], i{{.+}}**** [[ARGCADDR]]
52 // CK1: [[ARGCADDR_REF:%.+]] = load i{{.+}}***, i{{.+}}**** [[ARGCADDR]],
53 // CK1: store i8*** [[ARGCADDR_REF]], i8**** [[ARGCADDR_PTR]],
54 // CK1: [[ARGCADDR_PTR_REF:%.+]] = load i{{.+}}***, i{{.+}}**** [[ARGCADDR_PTR]],
55 // CK1: store i{{[0-9]+}}** null, i{{[0-9]+}}*** [[ARGCADDR_PTR_REF]],
56 // CK1-NOT: call {{.*}}void (%ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_teams(
57 // CK1:  ret void
58 // CK1-NEXT: }
59 
60 
61 #endif // CK1
62 
63 // Test target codegen - host bc file has to be created first.
64 // RUN: %clang_cc1 -DCK2 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fomptargets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc
65 // RUN: %clang_cc1 -DCK2 -verify -fopenmp -x c++ -triple nvptx64-unknown-unknown -fomptargets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fomp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s --check-prefix CK2 --check-prefix CK2-64
66 // RUN: %clang_cc1 -DCK2 -verify -fopenmp -x c++ -triple i386-unknown-unknown -fomptargets=nvptx-nvidia-cuda -emit-llvm-bc %s -o %t-x86-host.bc
67 // RUN: %clang_cc1 -DCK2 -verify -fopenmp -x c++ -triple nvptx-unknown-unknown -fomptargets=nvptx-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fomp-host-ir-file-path %t-x86-host.bc -o - | FileCheck %s --check-prefix CK2 --check-prefix CK2-32
68 // expected-no-diagnostics
69 #ifdef CK2
70 
71 template <typename T>
72 int tmain(T argc) {
73   int a = 10;
74   int b = 5;
75 #pragma omp target
76 #pragma omp teams num_teams(a) thread_limit(b)
77   {
78   argc = 0;
79   }
80   return 0;
81 }
82 
83 int main (int argc, char **argv) {
84   int a = 20;
85   int b = 5;
86 #pragma omp target
87 #pragma omp teams num_teams(a) thread_limit(b)
88   {
89   argc = 0;
90   }
91   return tmain(argv);
92 }
93 
94 // CK2: define {{.*}}void @{{[^,]+}}(i{{[0-9]+}} [[A_IN:%.+]], i{{[0-9]+}} [[B_IN:%.+]], i{{[0-9]+}} [[ARGC_IN:.+]])
95 // CK2: {{.}} = alloca i{{[0-9]+}}*,
96 // CK2: {{.}} = alloca i{{[0-9]+}}*,
97 // CK2: [[ARGCADDR_PTR:%.+]] = alloca i{{[0-9]+}}*,
98 // CK2: [[AADDR:%.+]] = alloca i{{[0-9]+}},
99 // CK2: [[BADDR:%.+]] = alloca i{{[0-9]+}},
100 // CK2: [[ARGCADDR:%.+]] = alloca i{{[0-9]+}},
101 // CK2-NOT:  {{%.+}} = call i32 @__kmpc_global_thread_num(
102 // CK2: store i{{[0-9]+}} [[A_IN]], i{{[0-9]+}}* [[AADDR]],
103 // CK2: store i{{[0-9]+}} [[B_IN]], i{{[0-9]+}}* [[BADDR]],
104 // CK2: store i{{[0-9]+}} [[ARGC_IN]], i{{[0-9]+}}* [[ARGCADDR]],
105 // CK2-64: [[ACONV:%.+]] = bitcast i64* [[AADDR]] to i32*
106 // CK2-64: [[BCONV:%.+]] = bitcast i64* [[BADDR]] to i32*
107 // CK2-64: [[CONV:%.+]] = bitcast i64* [[ARGCADDR]] to i32*
108 // CK2-64:  store i{{[0-9]+}}* [[CONV]], i{{[0-9]+}}** [[ARGCADDR_PTR]],
109 // CK2-32:  store i{{[0-9]+}}* [[ARGCADDR]], i{{[0-9]+}}** [[ARGCADDR_PTR]],
110 // CK2:  [[ARGCADDR_PTR_REF:%.+]] = load i{{[0-9]+}}*, i{{[0-9]+}}** [[ARGCADDR_PTR]],
111 // CK2: store i{{[0-9]+}} 0, i{{[0-9]+}}* [[ARGCADDR_PTR_REF]],
112 // CK2-NOT:  {{.+}} = call i32 @__kmpc_push_num_teams(
113 // CK2-NOT:  call void (%ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_teams(
114 // CK2: ret
115 
116 // CK2: define {{.*}}void @{{[^,]+}}(i{{[0-9]+}}*{{.+}} [[A_IN:%.+]], i{{[0-9]+}}*{{.+}} [[BP:%.+]], i{{[0-9]+}}***{{.+}}  [[ARGC:%.+]])
117 // CK2: [[ARGCADDR_PTR:%.+]] = alloca i{{[0-9]+}}***,
118 // CK2: [[AADDR:%.+]] = alloca i{{[0-9]+}}*,
119 // CK2: [[BADDR:%.+]] = alloca i{{[0-9]+}}*,
120 // CK2: [[ARGCADDR:%.+]] = alloca i{{[0-9]+}}***,
121 // CK2-NOT: {{%.+}} = call i32 @__kmpc_global_thread_num(
122 // CK2: store i{{[0-9]+}}* [[A_IN]], i{{[0-9]+}}** [[AADDR]],
123 // CK2: store i{{[0-9]+}}* [[B_IN]], i{{[0-9]+}}** [[BADDR]],
124 // CK2: store i{{[0-9]+}}*** [[ARGC]], i{{[0-9]+}}**** [[ARGCADDR]],
125 // CK2: [[A_ADDR_VAL:%.+]] = load i32*, i32** [[AADDR]]
126 // CK2: [[B_ADDR_VAL:%.+]] = load i32*, i32** [[BADDR]]
127 // CK2: [[ARGC_ADDR_VAL:%.+]] = load i{{[0-9]+}}***, i{{[0-9]+}}**** [[ARGCADDR]]
128 // CK2: store i{{[0-9]+}}*** [[ARGC_ADDR_VAL]], i{{[0-9]+}}**** [[ARGCADDR_PTR]],
129 // CK2: [[ARGCADDR_PTR_REF:%.+]] = load i{{[0-9]+}}***, i{{[0-9]+}}**** [[ARGCADDR_PTR]],
130 // CK2: store i{{[0-9]+}}** null, i{{[0-9]+}}*** [[ARGCADDR_PTR_REF]],
131 // CK2-NOT: {{.+}} = call i32 @__kmpc_push_num_teams(
132 // CK2-NOT: call void (%ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_teams(
133 // CK2:  ret void
134 
135 #endif // CK2
136 #endif
137