teams_distribute_parallel_for_simd_codegen.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. // expected-no-diagnostics
  2. #ifndef HEADER
  3. #define HEADER
  4. // Test host codegen.
  5. // RUN: %clang_cc1 -DCK1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CK1 --check-prefix CK1-64
  6. // RUN: %clang_cc1 -DCK1 -fopenmp -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -o %t %s
  7. // RUN: %clang_cc1 -DCK1 -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CK1 --check-prefix CK1-64
  8. // RUN: %clang_cc1 -DCK1 -verify -fopenmp -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CK1 --check-prefix CK1-32
  9. // RUN: %clang_cc1 -DCK1 -fopenmp -x c++ -std=c++11 -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-pch -o %t %s
  10. // RUN: %clang_cc1 -DCK1 -fopenmp -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CK1 --check-prefix CK1-32
  11. #ifdef CK1
  12. int a[100];
  13. // CK1: define {{.*}}i32 @{{.+}}teams_argument_globali(
  14. int teams_argument_global(int n){
  15. int te = n / 128;
  16. int th = 128;
  17. // discard n_addr
  18. // CK1: alloca i32,
  19. // CK1: [[TE:%.+]] = alloca i32,
  20. // CK1: [[TH:%.+]] = alloca i32,
  21. // CK1: [[TE_CAST:%.+]] = alloca i{{32|64}},
  22. // CK1: [[TH_CAST:%.+]] = alloca i{{32|64}},
  23. // CK1: [[TE_PAR:%.+]] = load{{.+}}, {{.+}} [[TE_CAST]],
  24. // CK1: [[TH_PAR:%.+]] = load{{.+}}, {{.+}} [[TH_CAST]],
  25. // CK1: call i32 @__tgt_target_teams(i64 -1, i8* @{{[^,]+}}, i32 4, i8** %{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* {{.+}}@{{[^,]+}}, i32 0, i32 0), i64* {{.+}}@{{[^,]+}}, i32 0, i32 0)
  26. // CK1: call void @[[OFFL1:.+]](i{{32|64}} [[TE_PAR]], i{{32|64}} [[TH_PAR]],
  27. #pragma omp target
  28. #pragma omp teams distribute parallel for simd num_teams(te), thread_limit(th) simdlen(64)
  29. for(int i = 0; i < n; i++) {
  30. a[i] = 0;
  31. }
  32. int i;
  33. // CK1: call i32 @__tgt_target_teams(i64 -1, i8* @{{[^,]+}}, i32 3, i8** %{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* {{.+}}@{{[^,]+}}, i32 0, i32 0), i64* {{.+}}@{{[^,]+}}, i32 0, i32 0)
  34. // CK1: call void @[[OFFL2:.+]](
  35. #pragma omp target
  36. {{{
  37. #pragma omp teams distribute parallel for simd safelen(4) aligned(a) linear(i)
  38. for(i = 0; i < n; i++) {
  39. a[i] = 0;
  40. }
  41. }}}
  42. // outlined target regions
  43. // CK1: define internal void @[[OFFL1]](i{{32|64}} [[TE_ARG:%.+]], i{{32|64}} [[TH_ARG:%.+]], i{{32|64}} {{.+}}, {{.+}})
  44. // CK1: [[TE_ADDR:%.+]] = alloca i{{32|64}},
  45. // CK1: [[TH_ADDR:%.+]] = alloca i{{32|64}},
  46. // CK1: store{{.+}} [[TE_ARG]], {{.+}} [[TE_ADDR]],
  47. // CK1: store{{.+}} [[TH_ARG]], {{.+}} [[TH_ADDR]],
  48. // CK1-64: [[TE_CONV:%.+]] = bitcast{{.+}} [[TE_ADDR]] to
  49. // CK1-64: [[TH_CONV:%.+]] = bitcast{{.+}} [[TH_ADDR]] to
  50. // CK1-64: [[TE_VAL:%.+]] = load i32, i32* [[TE_CONV]],
  51. // CK1-64: [[TH_VAL:%.+]] = load i32, i32* [[TH_CONV]],
  52. // CK1-32: [[TE_VAL:%.+]] = load i32, i32* [[TE_ADDR]],
  53. // CK1-32: [[TH_VAL:%.+]] = load i32, i32* [[TH_ADDR]],
  54. // CK1: {{%.+}} = call i32 @__kmpc_push_num_teams({{.+}}, {{.+}}, i32 [[TE_VAL]], i32 [[TH_VAL]])
  55. // CK1: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 2, {{.+}} @[[OUTL1:.+]] to {{.+}}, {{.+}}, {{.+}})
  56. // CK1: ret void
  57. // CK1: define internal void @[[OUTL1]]({{.+}})
  58. // CK1: call void @__kmpc_for_static_init_4(
  59. // CK1: call void {{.+}} @__kmpc_fork_call(
  60. // CK1: call void @__kmpc_for_static_fini(
  61. // CK1: ret void
  62. // CK1: define internal void @[[OFFL2]]({{.+}}, {{.+}})
  63. // CK1: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 3, {{.+}} @[[OUTL2:.+]] to {{.+}}, {{.+}}, {{.+}})
  64. // CK1: ret void
  65. // CK1: define internal void @[[OUTL2]]({{.+}})
  66. // CK1: call void @__kmpc_for_static_init_4(
  67. // CK1: call void {{.+}} @__kmpc_fork_call(
  68. // CK1: call void @__kmpc_for_static_fini(
  69. // CK1: ret void
  70. return a[0];
  71. }
  72. // CK1-DAG: !{!"llvm.loop.vectorize.enable", i1 true}
  73. // CK1-DAG: !{!"llvm.loop.vectorize.width", i32 4}
  74. // CK1-DAG: !{!"llvm.loop.vectorize.width", i32 64}
  75. #endif // CK1
  76. // Test host codegen.
  77. // RUN: %clang_cc1 -DCK2 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CK2 --check-prefix CK2-64
  78. // RUN: %clang_cc1 -DCK2 -fopenmp -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -o %t %s
  79. // RUN: %clang_cc1 -DCK2 -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CK2 --check-prefix CK2-64
  80. // RUN: %clang_cc1 -DCK2 -verify -fopenmp -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CK2 --check-prefix CK2-32
  81. // RUN: %clang_cc1 -DCK2 -fopenmp -x c++ -std=c++11 -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-pch -o %t %s
  82. // RUN: %clang_cc1 -DCK2 -fopenmp -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CK2 --check-prefix CK2-32
  83. #ifdef CK2
  84. // CK2: define {{.*}}i32 @{{.+}}teams_local_argv(
  85. int teams_local_arg(void) {
  86. int n = 100;
  87. int a[n], i;
  88. // CK2: call i32 @__tgt_target_teams(i64 -1, i8* @{{[^,]+}}, i32 4, i8** %{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* {{.+}}, i64* {{.+}}@{{[^,]+}}, i32 0, i32 0)
  89. // CK2: call void @[[OFFL1:.+]](
  90. #pragma omp target
  91. #pragma omp teams distribute parallel for simd safelen(4) aligned(a) linear(i)
  92. for(i = 0; i < n; i++) {
  93. a[i] = 0;
  94. }
  95. // outlined target region
  96. // CK2: define internal void @[[OFFL1]]({{.+}}, {{.+}})
  97. // CK2: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 4, {{.+}} @[[OUTL1:.+]] to {{.+}}, {{.+}}, {{.+}})
  98. // CK2: ret void
  99. // CK2: define internal void @[[OUTL1]]({{.+}})
  100. // CK2: call void @__kmpc_for_static_init_4(
  101. // CK2: call void {{.+}} @__kmpc_fork_call(
  102. // CK2: call void @__kmpc_for_static_fini(
  103. // CK2: ret void
  104. return a[0];
  105. }
  106. // CK2-DAG: !{!"llvm.loop.vectorize.enable", i1 true}
  107. // CK2-DAG: !{!"llvm.loop.vectorize.width", i32 4}
  108. #endif // CK2
  109. // Test host codegen.
  110. // RUN: %clang_cc1 -DCK3 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CK3 --check-prefix CK3-64
  111. // RUN: %clang_cc1 -DCK3 -fopenmp -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -o %t %s
  112. // RUN: %clang_cc1 -DCK3 -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CK3 --check-prefix CK3-64
  113. // RUN: %clang_cc1 -DCK3 -verify -fopenmp -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CK3 --check-prefix CK3-32
  114. // RUN: %clang_cc1 -DCK3 -fopenmp -x c++ -std=c++11 -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-pch -o %t %s
  115. // RUN: %clang_cc1 -DCK3 -fopenmp -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CK3 --check-prefix CK3-32
  116. #ifdef CK3
  117. // CK3: [[SSI:%.+]] = type { [{{.+}} x i32], float }
  118. template <typename T, int X, long long Y>
  119. struct SS{
  120. T a[X];
  121. float b;
  122. // CK3: define {{.*}}i32 @{{.+}}foo{{.+}}(
  123. int foo(void) {
  124. int i;
  125. // CK3: call i32 @__tgt_target_teams(i64 -1, i8* @{{[^,]+}}, i32 2, i8** %{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* {{.+}}@{{[^,]+}}, i32 0, i32 0), i64* {{.+}}@{{[^,]+}}, i32 0, i32 0)
  126. // CK3: call void @[[OFFL1:.+]]([[SSI]]* %{{.+}})
  127. #pragma omp target
  128. #pragma omp teams distribute parallel for simd safelen(4) aligned(a) linear(i)
  129. for(i = 0; i < X; i++) {
  130. a[i] = (T)0;
  131. }
  132. // outlined target region
  133. // CK3: define internal void @[[OFFL1]]([[SSI]]* {{.+}})
  134. // CK3: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 2, {{.+}} @[[OUTL1:.+]] to {{.+}}, {{.+}}, {{.+}})
  135. // CK3: ret void
  136. // CK3: define internal void @[[OUTL1]]({{.+}})
  137. // CK3: call void @__kmpc_for_static_init_4(
  138. // CK3: call void {{.+}} @__kmpc_fork_call(
  139. // CK3: call void @__kmpc_for_static_fini(
  140. // CK3: ret void
  141. return a[0];
  142. }
  143. };
  144. int teams_template_struct(void) {
  145. SS<int, 123, 456> V;
  146. return V.foo();
  147. }
  148. // CK3-DAG: !{!"llvm.loop.vectorize.enable", i1 true}
  149. // CK3-DAG: !{!"llvm.loop.vectorize.width", i32 4}
  150. #endif // CK3
  151. // Test host codegen.
  152. // RUN: %clang_cc1 -DCK4 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CK4 --check-prefix CK4-64
  153. // RUN: %clang_cc1 -DCK4 -fopenmp -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -o %t %s
  154. // RUN: %clang_cc1 -DCK4 -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CK4 --check-prefix CK4-64
  155. // RUN: %clang_cc1 -DCK4 -verify -fopenmp -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CK4 --check-prefix CK4-32
  156. // RUN: %clang_cc1 -DCK4 -fopenmp -x c++ -std=c++11 -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-pch -o %t %s
  157. // RUN: %clang_cc1 -DCK4 -fopenmp -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CK4 --check-prefix CK4-32
  158. #ifdef CK4
  159. template <typename T, int n>
  160. int tmain(T argc) {
  161. T a[n];
  162. int te = n/128;
  163. int th = 128;
  164. #pragma omp target
  165. #pragma omp teams distribute parallel for simd num_teams(te) thread_limit(th) simdlen(64)
  166. for(int i = 0; i < n; i++) {
  167. a[i] = (T)0;
  168. }
  169. return 0;
  170. }
  171. int main (int argc, char **argv) {
  172. int n = 100;
  173. int a[n], i;
  174. #pragma omp target
  175. #pragma omp teams distribute parallel for simd safelen(4) aligned(a) linear(i)
  176. for(i = 0; i < n; i++) {
  177. a[i] = 0;
  178. }
  179. return tmain<int, 10>(argc);
  180. }
  181. // CK4: define {{.*}}i32 @{{[^,]+}}(i{{.+}}{{.+}} %[[ARGC:.+]], {{.+}})
  182. // CK4: call i32 @__tgt_target_teams(i64 -1, i8* @{{[^,]+}}, i32 4, i8** %{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* {{.+}}, i64* {{.+}}@{{[^,]+}}, i32 0, i32 0)
  183. // CK4: call void @[[OFFL1:.+]]({{.+}})
  184. // CK4: {{%.+}} = call{{.*}} i32 @[[TMAIN:.+]]({{.+}})
  185. // CK4: ret
  186. // CK4: define {{.*}}void @[[OFFL1]]({{.+}})
  187. // CK4: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 4, {{.+}} @[[OUTL1:.+]] to {{.+}}, {{.+}}, {{.+}})
  188. // CK4: ret void
  189. // CK4: define internal void @[[OUTL1]]({{.+}})
  190. // CK4: call void @__kmpc_for_static_init_4(
  191. // CK4: call void {{.+}} @__kmpc_fork_call(
  192. // CK4: call void @__kmpc_for_static_fini(
  193. // CK4: ret void
  194. // CK4: define {{.*}}i32 @[[TMAIN]]({{.+}})
  195. // CK4: call i32 @__tgt_target_teams(i64 -1, i8* @{{[^,]+}}, i32 3, i8** %{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* {{.+}}@{{[^,]+}}, i32 0, i32 0), i64* {{.+}}@{{[^,]+}}, i32 0, i32 0)
  196. // CK4: call void @[[OFFLT:.+]]({{.+}})
  197. // CK4: ret
  198. // CK4-NEXT: }
  199. // CK4: define {{.*}}void @[[OFFLT]](i{{32|64}} [[TE_ARG:%.+]], i{{32|64}} [[TH_ARG:%.+]], {{.+}})
  200. // CK4: [[TE_ADDR:%.+]] = alloca i{{32|64}},
  201. // CK4: [[TH_ADDR:%.+]] = alloca i{{32|64}},
  202. // CK4: store{{.+}} [[TE_ARG]], {{.+}} [[TE_ADDR]],
  203. // CK4: store{{.+}} [[TH_ARG]], {{.+}} [[TH_ADDR]],
  204. // CK4-64: [[TE_CONV:%.+]] = bitcast{{.+}} [[TE_ADDR]] to
  205. // CK4-64: [[TH_CONV:%.+]] = bitcast{{.+}} [[TH_ADDR]] to
  206. // CK4-64: [[TE_VAL:%.+]] = load i32, i32* [[TE_CONV]],
  207. // CK4-64: [[TH_VAL:%.+]] = load i32, i32* [[TH_CONV]],
  208. // CK4-32: [[TE_VAL:%.+]] = load i32, i32* [[TE_ADDR]],
  209. // CK4-32: [[TH_VAL:%.+]] = load i32, i32* [[TH_ADDR]],
  210. // CK4: {{%.+}} = call i32 @__kmpc_push_num_teams({{.+}}, {{.+}}, i32 [[TE_VAL]], i32 [[TH_VAL]])
  211. // CK4: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 1, {{.+}} @[[OUTLT:.+]] to {{.+}}, {{.+}}, {{.+}})
  212. // CK4: ret void
  213. // CK4: define internal void @[[OUTLT]]({{.+}})
  214. // CK4: call void @__kmpc_for_static_init_4(
  215. // CK4: call void {{.+}} @__kmpc_fork_call(
  216. // CK4: call void @__kmpc_for_static_fini(
  217. // CK4: ret void
  218. // CK4-DAG: !{!"llvm.loop.vectorize.enable", i1 true}
  219. // CK4-DAG: !{!"llvm.loop.vectorize.width", i32 4}
  220. // CK4-DAG: !{!"llvm.loop.vectorize.width", i32 64}
  221. #endif // CK4
  222. #endif