1 // RUN: %clang_cc1 -no-opaque-pointers -verify -fopenmp -fopenmp-version=51 -triple x86_64-apple-darwin10.6.0 -emit-llvm -o - %s | FileCheck %s
2 // RUN: %clang_cc1 -no-opaque-pointers -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 -no-opaque-pointers -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 -no-opaque-pointers -verify -fopenmp -fopenmp-version=51 -triple x86_64-unknown-linux-gnu -emit-llvm -o - %s | FileCheck %s
5 // RUN: %clang_cc1 -no-opaque-pointers -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 -no-opaque-pointers -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 -no-opaque-pointers -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 -no-opaque-pointers -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 -no-opaque-pointers -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 -no-opaque-pointers -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 -no-opaque-pointers -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 -no-opaque-pointers -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 
main()68 int main() {
69   static int a;
70   [[omp::directive(allocate(a) allocator(omp_thread_mem_alloc))]];
71   a = 2;
72   double b = 3;
73   [[omp::directive(allocate(b))]];
74   return (foo<int>());
75 }
76 
77 // CHECK-LABEL: define {{[^@]+}}@main
78 // CHECK-SAME: () #[[ATTR0:[0-9]+]] {
79 // CHECK-NEXT:  entry:
80 // CHECK-NEXT:    [[RETVAL:%.*]] = alloca i32, align 4
81 // CHECK-NEXT:    [[TMP0:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB1:[0-9]+]])
82 // CHECK-NEXT:    store i32 0, i32* [[RETVAL]], align 4
83 // CHECK-NEXT:    store i32 2, i32* @_ZZ4mainE1a, align 4
84 // CHECK-NEXT:    [[DOTB__VOID_ADDR:%.*]] = call i8* @__kmpc_alloc(i32 [[TMP0]], i64 8, i8* null)
85 // CHECK-NEXT:    [[DOTB__ADDR:%.*]] = bitcast i8* [[DOTB__VOID_ADDR]] to double*
86 // CHECK-NEXT:    store double 3.000000e+00, double* [[DOTB__ADDR]], align 8
87 // CHECK-NEXT:    [[CALL:%.*]] = call noundef i32 @_Z3fooIiET_v()
88 // CHECK-NEXT:    store i32 [[CALL]], i32* [[RETVAL]], align 4
89 // CHECK-NEXT:    [[TMP1:%.*]] = bitcast double* [[DOTB__ADDR]] to i8*
90 // CHECK-NEXT:    call void @__kmpc_free(i32 [[TMP0]], i8* [[TMP1]], i8* null)
91 // CHECK-NEXT:    [[TMP2:%.*]] = load i32, i32* [[RETVAL]], align 4
92 // CHECK-NEXT:    ret i32 [[TMP2]]
93 
94 // CHECK: define {{.*}}i32 @{{.+}}foo{{.+}}()
95 // CHECK:      [[GTID:%.+]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @{{.+}})
96 // CHECK-NEXT: [[V_VOID_ADDR:%.+]] = call i8* @__kmpc_alloc(i32 [[GTID]], i64 4, i8* inttoptr (i64 6 to i8*))
97 // CHECK-NEXT: [[V_ADDR:%.+]] = bitcast i8* [[V_VOID_ADDR]] to i32*
98 // CHECK-NOT:  {{__kmpc_alloc|__kmpc_free}}
99 // CHECK:      store i32 %{{.+}}, i32* [[V_ADDR]],
100 // CHECK-NEXT: [[V_VAL:%.+]] = load i32, i32* [[V_ADDR]],
101 // CHECK-NEXT: [[V_VOID_ADDR:%.+]] = bitcast i32* [[V_ADDR]] to i8*
102 // CHECK-NEXT: call void @__kmpc_free(i32 [[GTID]], i8* [[V_VOID_ADDR]], i8* inttoptr (i64 6 to i8*))
103 // CHECK-NOT:  {{__kmpc_alloc|__kmpc_free}}
104 // CHECK:      ret i32 [[V_VAL]]
105 
106 // CHECK-NOT:  call {{.+}} {{__kmpc_alloc|__kmpc_free}}
107 extern template int ST<int>::m;
108 
109 // CHECK: define{{.*}} void @{{.+}}bar{{.+}}(i32 noundef %{{.+}}, float* noundef {{.+}})
bar(int a,float & z)110 void bar(int a, float &z) {
111   // CHECK: [[A_VOID_PTR:%.+]] = call i8* @__kmpc_alloc(i32 [[GTID:%.+]], i64 4, i8* inttoptr (i64 1 to i8*))
112   // CHECK: [[A_ADDR:%.+]] = bitcast i8* [[A_VOID_PTR]] to i32*
113   // CHECK: store i32 %{{.+}}, i32* [[A_ADDR]],
114   // CHECK: [[Z_VOID_PTR:%.+]] = call i8* @__kmpc_alloc(i32 [[GTID]], i64 8, i8* inttoptr (i64 1 to i8*))
115   // CHECK: [[Z_ADDR:%.+]] = bitcast i8* [[Z_VOID_PTR]] to float**
116   // CHECK: store float* %{{.+}}, float** [[Z_ADDR]],
117   [[omp::directive(allocate(a, z) allocator(omp_default_mem_alloc))]];
118   // CHECK-NEXT: [[Z_VOID_PTR:%.+]] = bitcast float** [[Z_ADDR]] to i8*
119   // CHECK: call void @__kmpc_free(i32 [[GTID]], i8* [[Z_VOID_PTR]], i8* inttoptr (i64 1 to i8*))
120   // CHECK-NEXT: [[A_VOID_PTR:%.+]] = bitcast i32* [[A_ADDR]] to i8*
121   // CHECK: call void @__kmpc_free(i32 [[GTID]], i8* [[A_VOID_PTR]], i8* inttoptr (i64 1 to i8*))
122   // CHECK: ret void
123 }
124 #endif
125