Alexey Bataev | c568725 | 2019-03-21 19:35:27 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -verify -fopenmp -triple x86_64-apple-darwin10.6.0 -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc -o %t-host.bc %s |
Alexey Bataev | 8c5555c | 2019-05-21 15:11:58 +0000 | [diff] [blame] | 2 | // RUN: %clang_cc1 -verify -fopenmp -triple nvptx64-nvidia-cuda -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-host.bc -o - -disable-llvm-optzns | FileCheck %s |
Alexey Bataev | c568725 | 2019-03-21 19:35:27 +0000 | [diff] [blame] | 3 | // expected-no-diagnostics |
| 4 | |
| 5 | #ifndef HEADER |
| 6 | #define HEADER |
| 7 | |
| 8 | #pragma omp declare target |
| 9 | typedef void **omp_allocator_handle_t; |
Alexey Bataev | 8026394 | 2020-04-30 13:32:22 -0400 | [diff] [blame] | 10 | extern const omp_allocator_handle_t omp_null_allocator; |
Alexey Bataev | c568725 | 2019-03-21 19:35:27 +0000 | [diff] [blame] | 11 | extern const omp_allocator_handle_t omp_default_mem_alloc; |
| 12 | extern const omp_allocator_handle_t omp_large_cap_mem_alloc; |
| 13 | extern const omp_allocator_handle_t omp_const_mem_alloc; |
| 14 | extern const omp_allocator_handle_t omp_high_bw_mem_alloc; |
| 15 | extern const omp_allocator_handle_t omp_low_lat_mem_alloc; |
| 16 | extern const omp_allocator_handle_t omp_cgroup_mem_alloc; |
| 17 | extern const omp_allocator_handle_t omp_pteam_mem_alloc; |
| 18 | extern const omp_allocator_handle_t omp_thread_mem_alloc; |
| 19 | |
| 20 | // CHECK-DAG: @{{.+}}St1{{.+}}b{{.+}} = external global i32, |
Alexey Bataev | bbc328c | 2019-11-21 11:30:43 -0500 | [diff] [blame] | 21 | // CHECK-DAG: @a ={{ hidden | }}global i32 0, |
| 22 | // CHECK-DAG: @b ={{ hidden | }}addrspace(4) global i32 0, |
| 23 | // CHECK-DAG: @c ={{ hidden | }}global i32 0, |
| 24 | // CHECK-DAG: @d ={{ hidden | }}global %struct.St1 zeroinitializer, |
| 25 | // CHECK-DAG: @{{.+}}ns{{.+}}a{{.+}} ={{ hidden | }}addrspace(3) global i32 0, |
Alexey Bataev | c568725 | 2019-03-21 19:35:27 +0000 | [diff] [blame] | 26 | // CHECK-DAG: @{{.+}}main{{.+}}a{{.*}} = internal global i32 0, |
| 27 | // CHECK-DAG: @{{.+}}ST{{.+}}m{{.+}} = external global i32, |
Alexey Bataev | 1db9bfe | 2019-04-08 16:53:57 +0000 | [diff] [blame] | 28 | // CHECK-DAG: @bar_c = internal global i32 0, |
| 29 | // CHECK-DAG: @bar_b = internal addrspace(3) global double 0.000000e+00, |
Alexey Bataev | c568725 | 2019-03-21 19:35:27 +0000 | [diff] [blame] | 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 | |
Alexey Bataev | 084b0c2f0 | 2019-03-21 20:36:16 +0000 | [diff] [blame] | 63 | // CHECK-LABEL: @main |
Alexey Bataev | c568725 | 2019-03-21 19:35:27 +0000 | [diff] [blame] | 64 | int main () { |
Alexey Bataev | 084b0c2f0 | 2019-03-21 20:36:16 +0000 | [diff] [blame] | 65 | // CHECK: alloca double, |
Alexey Bataev | c568725 | 2019-03-21 19:35:27 +0000 | [diff] [blame] | 66 | static int a; |
| 67 | #pragma omp allocate(a) allocator(omp_thread_mem_alloc) |
| 68 | a=2; |
| 69 | double b = 3; |
Alexey Bataev | 1db9bfe | 2019-04-08 16:53:57 +0000 | [diff] [blame] | 70 | float c; |
Alexey Bataev | 2213dd6 | 2019-03-22 14:41:39 +0000 | [diff] [blame] | 71 | #pragma omp allocate(b) allocator(omp_default_mem_alloc) |
Alexey Bataev | 1db9bfe | 2019-04-08 16:53:57 +0000 | [diff] [blame] | 72 | #pragma omp allocate(c) allocator(omp_cgroup_mem_alloc) |
Alexey Bataev | c568725 | 2019-03-21 19:35:27 +0000 | [diff] [blame] | 73 | return (foo<int>()); |
| 74 | } |
| 75 | |
Alexey Bataev | 084b0c2f0 | 2019-03-21 20:36:16 +0000 | [diff] [blame] | 76 | // CHECK: define {{.*}}i32 @{{.+}}foo{{.+}}() |
Alexey Bataev | 1db9bfe | 2019-04-08 16:53:57 +0000 | [diff] [blame] | 77 | // CHECK-NOT: alloca i32, |
Alexey Bataev | 084b0c2f0 | 2019-03-21 20:36:16 +0000 | [diff] [blame] | 78 | |
Alexey Bataev | c568725 | 2019-03-21 19:35:27 +0000 | [diff] [blame] | 79 | extern template int ST<int>::m; |
Alexey Bataev | 1db9bfe | 2019-04-08 16:53:57 +0000 | [diff] [blame] | 80 | |
| 81 | void baz(float &); |
| 82 | |
Alexey Bataev | bbc328c | 2019-11-21 11:30:43 -0500 | [diff] [blame] | 83 | // CHECK: define{{ hidden | }}void @{{.+}}bar{{.+}}() |
Alexey Bataev | 1db9bfe | 2019-04-08 16:53:57 +0000 | [diff] [blame] | 84 | void bar() { |
| 85 | // CHECK: alloca float, |
| 86 | float bar_a; |
| 87 | // CHECK: alloca double, |
| 88 | double bar_b; |
| 89 | int bar_c; |
| 90 | #pragma omp allocate(bar_c) allocator(omp_cgroup_mem_alloc) |
| 91 | // CHECK: call void [[OUTLINED:@.+]](i32* %{{.+}}, i32* %{{.+}}) |
| 92 | #pragma omp parallel private(bar_a, bar_b) allocate(omp_thread_mem_alloc \ |
| 93 | : bar_a) allocate(omp_pteam_mem_alloc \ |
| 94 | : bar_b) |
| 95 | { |
| 96 | bar_b = bar_a; |
| 97 | baz(bar_a); |
| 98 | } |
| 99 | // CHECK: define internal void [[OUTLINED]](i32* noalias %{{.+}}, i32* noalias %{{.+}}) |
| 100 | // CHECK-NOT: alloca double, |
| 101 | // CHECK: alloca float, |
| 102 | // CHECK-NOT: alloca double, |
| 103 | // CHECK: load float, float* % |
Alexey Bataev | 9dc327d | 2020-07-13 12:56:18 -0400 | [diff] [blame^] | 104 | // CHECK: store double {{.+}}, double* addrspacecast (double addrspace(3)* @bar_b to double*), |
Alexey Bataev | 1db9bfe | 2019-04-08 16:53:57 +0000 | [diff] [blame] | 105 | } |
| 106 | |
Alexey Bataev | c568725 | 2019-03-21 19:35:27 +0000 | [diff] [blame] | 107 | #pragma omp end declare target |
| 108 | #endif |