blob: 01542ca4044a86484dec6e933974f21e8351b3a6 [file] [log] [blame]
Alexey Bataevc5687252019-03-21 19:35:27 +00001// 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 Bataev8c5555c2019-05-21 15:11:58 +00002// 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 Bataevc5687252019-03-21 19:35:27 +00003// expected-no-diagnostics
4
5#ifndef HEADER
6#define HEADER
7
8#pragma omp declare target
9typedef void **omp_allocator_handle_t;
Alexey Bataev80263942020-04-30 13:32:22 -040010extern const omp_allocator_handle_t omp_null_allocator;
Alexey Bataevc5687252019-03-21 19:35:27 +000011extern const omp_allocator_handle_t omp_default_mem_alloc;
12extern const omp_allocator_handle_t omp_large_cap_mem_alloc;
13extern const omp_allocator_handle_t omp_const_mem_alloc;
14extern const omp_allocator_handle_t omp_high_bw_mem_alloc;
15extern const omp_allocator_handle_t omp_low_lat_mem_alloc;
16extern const omp_allocator_handle_t omp_cgroup_mem_alloc;
17extern const omp_allocator_handle_t omp_pteam_mem_alloc;
18extern const omp_allocator_handle_t omp_thread_mem_alloc;
19
20// CHECK-DAG: @{{.+}}St1{{.+}}b{{.+}} = external global i32,
Alexey Bataevbbc328c2019-11-21 11:30:43 -050021// 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 Bataevc5687252019-03-21 19:35:27 +000026// CHECK-DAG: @{{.+}}main{{.+}}a{{.*}} = internal global i32 0,
27// CHECK-DAG: @{{.+}}ST{{.+}}m{{.+}} = external global i32,
Alexey Bataev1db9bfe2019-04-08 16:53:57 +000028// CHECK-DAG: @bar_c = internal global i32 0,
29// CHECK-DAG: @bar_b = internal addrspace(3) global double 0.000000e+00,
Alexey Bataevc5687252019-03-21 19:35:27 +000030struct St{
31 int a;
32};
33
34struct St1{
35 int a;
36 static int b;
37#pragma omp allocate(b) allocator(omp_default_mem_alloc)
38} d;
39
40int 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
45template <class T>
46struct ST {
47 static T m;
48 #pragma omp allocate(m) allocator(omp_low_lat_mem_alloc)
49};
50
51template <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
58namespace ns{
59 int a;
60}
61#pragma omp allocate(ns::a) allocator(omp_pteam_mem_alloc)
62
Alexey Bataev084b0c2f02019-03-21 20:36:16 +000063// CHECK-LABEL: @main
Alexey Bataevc5687252019-03-21 19:35:27 +000064int main () {
Alexey Bataev084b0c2f02019-03-21 20:36:16 +000065 // CHECK: alloca double,
Alexey Bataevc5687252019-03-21 19:35:27 +000066 static int a;
67#pragma omp allocate(a) allocator(omp_thread_mem_alloc)
68 a=2;
69 double b = 3;
Alexey Bataev1db9bfe2019-04-08 16:53:57 +000070 float c;
Alexey Bataev2213dd62019-03-22 14:41:39 +000071#pragma omp allocate(b) allocator(omp_default_mem_alloc)
Alexey Bataev1db9bfe2019-04-08 16:53:57 +000072#pragma omp allocate(c) allocator(omp_cgroup_mem_alloc)
Alexey Bataevc5687252019-03-21 19:35:27 +000073 return (foo<int>());
74}
75
Alexey Bataev084b0c2f02019-03-21 20:36:16 +000076// CHECK: define {{.*}}i32 @{{.+}}foo{{.+}}()
Alexey Bataev1db9bfe2019-04-08 16:53:57 +000077// CHECK-NOT: alloca i32,
Alexey Bataev084b0c2f02019-03-21 20:36:16 +000078
Alexey Bataevc5687252019-03-21 19:35:27 +000079extern template int ST<int>::m;
Alexey Bataev1db9bfe2019-04-08 16:53:57 +000080
81void baz(float &);
82
Alexey Bataevbbc328c2019-11-21 11:30:43 -050083// CHECK: define{{ hidden | }}void @{{.+}}bar{{.+}}()
Alexey Bataev1db9bfe2019-04-08 16:53:57 +000084void 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 Bataev9dc327d2020-07-13 12:56:18 -0400104// CHECK: store double {{.+}}, double* addrspacecast (double addrspace(3)* @bar_b to double*),
Alexey Bataev1db9bfe2019-04-08 16:53:57 +0000105}
106
Alexey Bataevc5687252019-03-21 19:35:27 +0000107#pragma omp end declare target
108#endif