teams_distribute_parallel_for_simd_collapse_codegen.cpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. template <typename T, int X, long long Y>
  13. struct SS{
  14. T a[X][Y];
  15. // CK1: define {{.*}}i32 @{{.+}}foo{{.+}}(
  16. int foo(void) {
  17. // CK1: call i32 @__tgt_target_teams(
  18. // CK1: call void @[[OFFL1:.+]](
  19. #pragma omp target
  20. #pragma omp teams distribute parallel for simd collapse(2)
  21. for(int i = 0; i < X; i++) {
  22. for(int j = 0; j < Y; j++) {
  23. a[i][j] = (T)0;
  24. }
  25. }
  26. // CK1: define internal void @[[OFFL1]](
  27. // CK1: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 1, {{.+}} @[[OUTL1:.+]] to {{.+}},
  28. // CK1: ret void
  29. // CK1: define internal void @[[OUTL1]]({{.+}})
  30. // discard loop variables not needed here
  31. // CK1: [[OMP_UB:%.omp.comb.ub]] = alloca i32,
  32. // CK1: store i32 56087, i32* [[OMP_UB]],
  33. // CK1: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, i32 92, {{.+}}, {{.+}}, i32* [[OMP_UB]],
  34. // CK1: call void {{.*}} @__kmpc_fork_call({{.+}}, {{.+}}, {{.+}} @[[PAR_OUTL1:.+]] to
  35. // CK1: call void @__kmpc_for_static_fini(
  36. // CK1: ret void
  37. // CK1: define internal void @[[PAR_OUTL1]]({{.+}})
  38. // CK1: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, i32 34, {{.+}}, {{.+}},
  39. // CK1: call void @__kmpc_for_static_fini(
  40. // CK1: ret void
  41. return a[0][0];
  42. }
  43. };
  44. int teams_template_struct(void) {
  45. SS<int, 123, 456> V;
  46. return V.foo();
  47. }
  48. // CK4: !{!"llvm.loop.vectorize.enable", i1 true}
  49. #endif // CK1
  50. // Test host codegen.
  51. // 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
  52. // 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
  53. // 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
  54. // 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
  55. // 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
  56. // 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
  57. #ifdef CK2
  58. template <typename T, int n, int m>
  59. int tmain(T argc) {
  60. T a[n][m];
  61. #pragma omp target
  62. #pragma omp teams distribute parallel for simd collapse(2)
  63. for(int i = 0; i < n; i++) {
  64. for(int j = 0; j < m; j++) {
  65. a[i][j] = (T)0;
  66. }
  67. }
  68. return 0;
  69. }
  70. int main (int argc, char **argv) {
  71. int n = 100;
  72. int m = 2;
  73. int a[n][m];
  74. #pragma omp target
  75. #pragma omp teams distribute parallel for simd collapse(2)
  76. for(int i = 0; i < n; i++) {
  77. for(int j = 0; j < m; j++) {
  78. a[i][j] = 0;
  79. }
  80. }
  81. return tmain<int, 10, 2>(argc);
  82. }
  83. // CK2: define {{.*}}i32 @{{[^,]+}}(i{{.+}}{{.+}} %[[ARGC:.+]], {{.+}})
  84. // CK2: call i32 @__tgt_target_teams(
  85. // CK2: call void @[[OFFL1:.+]]({{.+}})
  86. // CK2: {{%.+}} = call{{.*}} i32 @[[TMAIN:.+]]({{.+}})
  87. // CK2: ret
  88. // CK2: define {{.*}}void @[[OFFL1]]({{.+}})
  89. // CK2: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 5, {{.+}} @[[OUTL1:.+]] to {{.+}},
  90. // CK2: ret void
  91. // CK2: define internal void @[[OUTL1]]({{.+}})
  92. // CK2: [[OMP_UB:%.omp.comb.ub]] = alloca i64,
  93. // CK2: store i64 {{.+}}, i64* [[OMP_UB]],
  94. // CK2: call void @__kmpc_for_static_init_8({{.+}}, {{.+}}, i32 92, {{.+}}, {{.+}}, i64* [[OMP_UB]],
  95. // CK2: call void {{.*}} @__kmpc_fork_call({{.+}}, {{.+}}, {{.+}} @[[PAR_OUTL1:.+]] to
  96. // CK2: call void @__kmpc_for_static_fini(
  97. // CK2: ret void
  98. // CK2: define internal void @[[PAR_OUTL1]]({{.+}})
  99. // CK2: call void @__kmpc_for_static_init_{{[4|8]}}({{.+}}, {{.+}}, i32 34, {{.+}}, {{.+}},
  100. // CK2: call void @__kmpc_for_static_fini(
  101. // CK2: ret void
  102. // CK2: define {{.*}}i32 @[[TMAIN]]({{.+}})
  103. // CK2: call i32 @__tgt_target_teams(
  104. // CK2: call void @[[OFFLT1:.+]]({{.+}})
  105. // CK2: ret
  106. // CK2-NEXT: }
  107. // CK2: define {{.*}}void @[[OFFLT1]]({{.+}})
  108. // CK2: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 1, {{.+}} @[[OUTLT1:.+]] to {{.+}},
  109. // CK2: ret void
  110. // CK2: define internal void @[[OUTLT1]]({{.+}})
  111. // discard loop variables not needed here
  112. // CK2: [[OMP_UB:%.omp.comb.ub]] = alloca i32,
  113. // CK2: store i32 {{.+}}, i32* [[OMP_UB]],
  114. // CK2: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, i32 92, {{.+}}, {{.+}}, i32* [[OMP_UB]],
  115. // CK2: call void {{.*}} @__kmpc_fork_call({{.+}}, {{.+}}, {{.+}} @[[TPAR_OUTL1:.+]] to
  116. // CK2: call void @__kmpc_for_static_fini(
  117. // CK2: ret void
  118. // CK2: define internal void @[[TPAR_OUTL1]]({{.+}})
  119. // CK2: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, i32 34, {{.+}}, {{.+}},
  120. // CK2: call void @__kmpc_for_static_fini(
  121. // CK2: ret void
  122. // CK4: !{!"llvm.loop.vectorize.enable", i1 true}
  123. #endif // CK2
  124. #endif // #ifndef HEADER