1 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=51 -triple x86_64-apple-darwin10.6.0 -emit-llvm -o - %s | FileCheck %s
2 // RUN: %clang_cc1 -fopenmp -fopenmp-version=51 -triple x86_64-apple-darwin10.6.0 -x c++ -std=c++11 -emit-pch -o %t %s
3 // RUN: %clang_cc1 -fopenmp -fopenmp-version=51 -triple x86_64-apple-darwin10.6.0 -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
4 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=51 -triple x86_64-unknown-linux-gnu -emit-llvm -o - %s | FileCheck %s
5 // RUN: %clang_cc1 -fopenmp -fopenmp-version=51 -fnoopenmp-use-tls -triple x86_64-unknown-linux-gnu -x c++ -std=c++11 -emit-pch -o %t %s
6 // RUN: %clang_cc1 -fopenmp -fopenmp-version=51 -fnoopenmp-use-tls -triple x86_64-unknown-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
7 
8 // RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=51 -triple x86_64-apple-darwin10.6.0 -emit-llvm -o - %s | FileCheck --check-prefix SIMD-ONLY0 %s
9 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=51 -triple x86_64-apple-darwin10.6.0 -x c++ -std=c++11 -emit-pch -o %t %s
10 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=51 -triple x86_64-apple-darwin10.6.0 -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
11 // RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=51 -triple x86_64-unknown-linux-gnu -emit-llvm -o - %s | FileCheck --check-prefix SIMD-ONLY0 %s
12 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=51 -fnoopenmp-use-tls -triple x86_64-unknown-linux-gnu -x c++ -std=c++11 -emit-pch -o %t %s
13 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=51 -fnoopenmp-use-tls -triple x86_64-unknown-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
14 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
15 // expected-no-diagnostics
16 
17 #ifndef HEADER
18 #define HEADER
19 
20 enum omp_allocator_handle_t {
21   omp_null_allocator = 0,
22   omp_default_mem_alloc = 1,
23   omp_large_cap_mem_alloc = 2,
24   omp_const_mem_alloc = 3,
25   omp_high_bw_mem_alloc = 4,
26   omp_low_lat_mem_alloc = 5,
27   omp_cgroup_mem_alloc = 6,
28   omp_pteam_mem_alloc = 7,
29   omp_thread_mem_alloc = 8,
30   KMP_ALLOCATOR_MAX_HANDLE = __UINTPTR_MAX__
31 };
32 
33 struct St{
34  int a;
35 };
36 
37 struct St1{
38  int a;
39  static int b;
40  [[omp::directive(allocate(b) allocator(omp_default_mem_alloc))]];
41 } d;
42 
43 int a, b, c;
44 [[omp::directive(allocate(a) allocator(omp_large_cap_mem_alloc)),
45        directive(allocate(b) allocator(omp_const_mem_alloc)),
46        directive(allocate(d, c) allocator(omp_high_bw_mem_alloc))]];
47 
48 template <class T>
49 struct ST {
50   static T m;
51   [[omp::directive(allocate(m) allocator(omp_low_lat_mem_alloc))]];
52 };
53 
foo()54 template <class T> T foo() {
55   T v;
56   [[omp::directive(allocate(v) allocator(omp_cgroup_mem_alloc))]];
57   v = ST<T>::m;
58   return v;
59 }
60 
61 namespace ns{
62   int a;
63 }
64 [[omp::directive(allocate(ns::a) allocator(omp_pteam_mem_alloc))]];
65 
66 // CHECK-NOT:  call {{.+}} {{__kmpc_alloc|__kmpc_free}}
67 
68 // CHECK-LABEL: @main
main()69 int main () {
70   static int a;
71   [[omp::directive(allocate(a) allocator(omp_thread_mem_alloc))]];
72   a=2;
73   // CHECK-NOT:  {{__kmpc_alloc|__kmpc_free}}
74   // CHECK:      alloca double,
75   // CHECK-NOT:  {{__kmpc_alloc|__kmpc_free}}
76   double b = 3;
77   [[omp::directive(allocate(b))]];
78   return (foo<int>());
79 }
80 
81 // CHECK: define {{.*}}i32 @{{.+}}foo{{.+}}()
82 // CHECK:      [[GTID:%.+]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @{{.+}})
83 // CHECK-NEXT: [[V_VOID_ADDR:%.+]] = call i8* @__kmpc_alloc(i32 [[GTID]], i64 4, i8* inttoptr (i64 6 to i8*))
84 // CHECK-NEXT: [[V_ADDR:%.+]] = bitcast i8* [[V_VOID_ADDR]] to i32*
85 // CHECK-NOT:  {{__kmpc_alloc|__kmpc_free}}
86 // CHECK:      store i32 %{{.+}}, i32* [[V_ADDR]],
87 // CHECK-NEXT: [[V_VAL:%.+]] = load i32, i32* [[V_ADDR]],
88 // CHECK-NEXT: [[V_VOID_ADDR:%.+]] = bitcast i32* [[V_ADDR]] to i8*
89 // CHECK-NEXT: call void @__kmpc_free(i32 [[GTID]], i8* [[V_VOID_ADDR]], i8* inttoptr (i64 6 to i8*))
90 // CHECK-NOT:  {{__kmpc_alloc|__kmpc_free}}
91 // CHECK:      ret i32 [[V_VAL]]
92 
93 // CHECK-NOT:  call {{.+}} {{__kmpc_alloc|__kmpc_free}}
94 extern template int ST<int>::m;
95 
96 // CHECK: define{{.*}} void @{{.+}}bar{{.+}}(i32 %{{.+}}, float* {{.+}})
bar(int a,float & z)97 void bar(int a, float &z) {
98 // CHECK: [[A_VOID_PTR:%.+]] = call i8* @__kmpc_alloc(i32 [[GTID:%.+]], i64 4, i8* inttoptr (i64 1 to i8*))
99 // CHECK: [[A_ADDR:%.+]] = bitcast i8* [[A_VOID_PTR]] to i32*
100 // CHECK: store i32 %{{.+}}, i32* [[A_ADDR]],
101 // CHECK: [[Z_VOID_PTR:%.+]] = call i8* @__kmpc_alloc(i32 [[GTID]], i64 8, i8* inttoptr (i64 1 to i8*))
102 // CHECK: [[Z_ADDR:%.+]] = bitcast i8* [[Z_VOID_PTR]] to float**
103 // CHECK: store float* %{{.+}}, float** [[Z_ADDR]],
104 [[omp::directive(allocate(a,z) allocator(omp_default_mem_alloc))]];
105 // CHECK-NEXT: [[Z_VOID_PTR:%.+]] = bitcast float** [[Z_ADDR]] to i8*
106 // CHECK: call void @__kmpc_free(i32 [[GTID]], i8* [[Z_VOID_PTR]], i8* inttoptr (i64 1 to i8*))
107 // CHECK-NEXT: [[A_VOID_PTR:%.+]] = bitcast i32* [[A_ADDR]] to i8*
108 // CHECK: call void @__kmpc_free(i32 [[GTID]], i8* [[A_VOID_PTR]], i8* inttoptr (i64 1 to i8*))
109 // CHECK: ret void
110 }
111 #endif
112 
113