blob: 1214845a42011681d0a5cb5e6f06457df27ba3a4 [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;
10extern const omp_allocator_handle_t omp_default_mem_alloc;
11extern const omp_allocator_handle_t omp_large_cap_mem_alloc;
12extern const omp_allocator_handle_t omp_const_mem_alloc;
13extern const omp_allocator_handle_t omp_high_bw_mem_alloc;
14extern const omp_allocator_handle_t omp_low_lat_mem_alloc;
15extern const omp_allocator_handle_t omp_cgroup_mem_alloc;
16extern const omp_allocator_handle_t omp_pteam_mem_alloc;
17extern const omp_allocator_handle_t omp_thread_mem_alloc;
18
19// CHECK-DAG: @{{.+}}St1{{.+}}b{{.+}} = external global i32,
20// CHECK-DAG: @a = global i32 0,
21// CHECK-DAG: @b = addrspace(4) global i32 0,
22// CHECK-DAG: @c = global i32 0,
23// CHECK-DAG: @d = global %struct.St1 zeroinitializer,
24// CHECK-DAG: @{{.+}}ns{{.+}}a{{.+}} = addrspace(3) global i32 0,
25// CHECK-DAG: @{{.+}}main{{.+}}a{{.*}} = internal global i32 0,
26// CHECK-DAG: @{{.+}}ST{{.+}}m{{.+}} = external global i32,
Alexey Bataev1db9bfe2019-04-08 16:53:57 +000027// CHECK-DAG: @bar_c = internal global i32 0,
28// CHECK-DAG: @bar_b = internal addrspace(3) global double 0.000000e+00,
Alexey Bataevc5687252019-03-21 19:35:27 +000029struct St{
30 int a;
31};
32
33struct St1{
34 int a;
35 static int b;
36#pragma omp allocate(b) allocator(omp_default_mem_alloc)
37} d;
38
39int a, b, c;
40#pragma omp allocate(a) allocator(omp_large_cap_mem_alloc)
41#pragma omp allocate(b) allocator(omp_const_mem_alloc)
42#pragma omp allocate(d, c) allocator(omp_high_bw_mem_alloc)
43
44template <class T>
45struct ST {
46 static T m;
47 #pragma omp allocate(m) allocator(omp_low_lat_mem_alloc)
48};
49
50template <class T> T foo() {
51 T v;
52 #pragma omp allocate(v) allocator(omp_cgroup_mem_alloc)
53 v = ST<T>::m;
54 return v;
55}
56
57namespace ns{
58 int a;
59}
60#pragma omp allocate(ns::a) allocator(omp_pteam_mem_alloc)
61
Alexey Bataev084b0c2f02019-03-21 20:36:16 +000062// CHECK-LABEL: @main
Alexey Bataevc5687252019-03-21 19:35:27 +000063int main () {
Alexey Bataev084b0c2f02019-03-21 20:36:16 +000064 // CHECK: alloca double,
Alexey Bataevc5687252019-03-21 19:35:27 +000065 static int a;
66#pragma omp allocate(a) allocator(omp_thread_mem_alloc)
67 a=2;
68 double b = 3;
Alexey Bataev1db9bfe2019-04-08 16:53:57 +000069 float c;
Alexey Bataev2213dd62019-03-22 14:41:39 +000070#pragma omp allocate(b) allocator(omp_default_mem_alloc)
Alexey Bataev1db9bfe2019-04-08 16:53:57 +000071#pragma omp allocate(c) allocator(omp_cgroup_mem_alloc)
Alexey Bataevc5687252019-03-21 19:35:27 +000072 return (foo<int>());
73}
74
Alexey Bataev084b0c2f02019-03-21 20:36:16 +000075// CHECK: define {{.*}}i32 @{{.+}}foo{{.+}}()
Alexey Bataev1db9bfe2019-04-08 16:53:57 +000076// CHECK-NOT: alloca i32,
Alexey Bataev084b0c2f02019-03-21 20:36:16 +000077
Alexey Bataevc5687252019-03-21 19:35:27 +000078extern template int ST<int>::m;
Alexey Bataev1db9bfe2019-04-08 16:53:57 +000079
80void baz(float &);
81
82// CHECK: define void @{{.+}}bar{{.+}}()
83void bar() {
84 // CHECK: alloca float,
85 float bar_a;
86 // CHECK: alloca double,
87 double bar_b;
88 int bar_c;
89#pragma omp allocate(bar_c) allocator(omp_cgroup_mem_alloc)
90 // CHECK: call void [[OUTLINED:@.+]](i32* %{{.+}}, i32* %{{.+}})
91#pragma omp parallel private(bar_a, bar_b) allocate(omp_thread_mem_alloc \
92 : bar_a) allocate(omp_pteam_mem_alloc \
93 : bar_b)
94 {
95 bar_b = bar_a;
96 baz(bar_a);
97 }
98// CHECK: define internal void [[OUTLINED]](i32* noalias %{{.+}}, i32* noalias %{{.+}})
99// CHECK-NOT: alloca double,
100// CHECK: alloca float,
101// CHECK-NOT: alloca double,
102// CHECK: load float, float* %
103// CHECK: store double {{.+}}, double addrspace(3)* @bar_b,
104}
105
Alexey Bataevc5687252019-03-21 19:35:27 +0000106#pragma omp end declare target
107#endif