1 // RUN: %clang_cc1 -verify -fopenmp -triple x86_64-apple-darwin10.6.0 -emit-llvm -o - %s | FileCheck %s
2 // RUN: %clang_cc1 -fopenmp -triple x86_64-apple-darwin10.6.0 -x c++ -std=c++11 -emit-pch -o %t %s
3 // RUN: %clang_cc1 -fopenmp -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 -triple x86_64-unknown-linux-gnu -emit-llvm -o - %s | FileCheck %s
5 // RUN: %clang_cc1 -fopenmp -fnoopenmp-use-tls -triple x86_64-unknown-linux-gnu -x c++ -std=c++11 -emit-pch -o %t %s
6 // RUN: %clang_cc1 -fopenmp -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 -triple x86_64-apple-darwin10.6.0 -emit-llvm -o - %s | FileCheck --check-prefix SIMD-ONLY0 %s
9 // RUN: %clang_cc1 -fopenmp-simd -triple x86_64-apple-darwin10.6.0 -x c++ -std=c++11 -emit-pch -o %t %s
10 // RUN: %clang_cc1 -fopenmp-simd -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 -triple x86_64-unknown-linux-gnu -emit-llvm -o - %s | FileCheck --check-prefix SIMD-ONLY0 %s
12 // RUN: %clang_cc1 -fopenmp-simd -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 -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 typedef void **omp_allocator_handle_t;
21 extern const omp_allocator_handle_t omp_default_mem_alloc;
22 extern const omp_allocator_handle_t omp_large_cap_mem_alloc;
23 extern const omp_allocator_handle_t omp_const_mem_alloc;
24 extern const omp_allocator_handle_t omp_high_bw_mem_alloc;
25 extern const omp_allocator_handle_t omp_low_lat_mem_alloc;
26 extern const omp_allocator_handle_t omp_cgroup_mem_alloc;
27 extern const omp_allocator_handle_t omp_pteam_mem_alloc;
28 extern const omp_allocator_handle_t omp_thread_mem_alloc;
29 
30 struct St{
31  int a;
32 };
33 
34 struct St1{
35  int a;
36  static int b;
37 #pragma omp allocate(b) allocator(omp_default_mem_alloc)
38 } d;
39 
40 int a, b, c;
41 #pragma omp allocate(a) allocator(omp_large_cap_mem_alloc)
42 #pragma omp allocate(b) allocator(omp_const_mem_alloc)
43 #pragma omp allocate(d, c) allocator(omp_high_bw_mem_alloc)
44 
45 template <class T>
46 struct ST {
47   static T m;
48   #pragma omp allocate(m) allocator(omp_low_lat_mem_alloc)
49 };
50 
51 template <class T> T foo() {
52   T v;
53   #pragma omp allocate(v) allocator(omp_cgroup_mem_alloc)
54   v = ST<T>::m;
55   return v;
56 }
57 
58 namespace ns{
59   int a;
60 }
61 #pragma omp allocate(ns::a) allocator(omp_pteam_mem_alloc)
62 
63 // CHECK-NOT:  call {{.+}} {{__kmpc_alloc|__kmpc_free}}
64 
65 // CHECK-LABEL: @main
66 int main () {
67   static int a;
68 #pragma omp allocate(a) allocator(omp_thread_mem_alloc)
69   a=2;
70   // CHECK-NOT:  {{__kmpc_alloc|__kmpc_free}}
71   // CHECK:      alloca double,
72   // CHECK-NOT:  {{__kmpc_alloc|__kmpc_free}}
73   double b = 3;
74 #pragma omp allocate(b)
75   return (foo<int>());
76 }
77 
78 // CHECK: define {{.*}}i32 @{{.+}}foo{{.+}}()
79 // CHECK:      [[GTID:%.+]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @{{.+}})
80 // CHECK-NEXT: [[OMP_CGROUP_MEM_ALLOC:%.+]] = load i8**, i8*** @omp_cgroup_mem_alloc,
81 // CHECK-NEXT: [[V_VOID_ADDR:%.+]] = call i8* @__kmpc_alloc(i32 [[GTID]], i64 4, i8** [[OMP_CGROUP_MEM_ALLOC]])
82 // CHECK-NEXT: [[V_ADDR:%.+]] = bitcast i8* [[V_VOID_ADDR]] to i32*
83 // CHECK-NOT:  {{__kmpc_alloc|__kmpc_free}}
84 // CHECK:      store i32 %{{.+}}, i32* [[V_ADDR]],
85 // CHECK-NEXT: [[V_VAL:%.+]] = load i32, i32* [[V_ADDR]],
86 // CHECK-NEXT: call void @__kmpc_free(i32 [[GTID]], i8* [[V_VOID_ADDR]], i8** [[OMP_CGROUP_MEM_ALLOC]])
87 // CHECK-NOT:  {{__kmpc_alloc|__kmpc_free}}
88 // CHECK:      ret i32 [[V_VAL]]
89 
90 // CHECK-NOT:  call {{.+}} {{__kmpc_alloc|__kmpc_free}}
91 extern template int ST<int>::m;
92 #endif
93