1 // RUN: %clang_cc1 -no-opaque-pointers %s --std=c++11 -triple nvptx-unknown-unknown -fcuda-is-device \
2 // RUN: -emit-llvm -o - | FileCheck %s --check-prefixes=COMMON,DEVICE
3 // RUN: %clang_cc1 -no-opaque-pointers %s --std=c++11 -triple nvptx-unknown-unknown \
4 // RUN: -emit-llvm -o - | FileCheck %s --check-prefixes=COMMON,HOST
5 // RUN: %clang_cc1 -no-opaque-pointers %s --std=c++17 -triple nvptx-unknown-unknown -fcuda-is-device \
6 // RUN: -emit-llvm -o - | FileCheck %s --check-prefixes=COMMON,DEVICE
7 // RUN: %clang_cc1 -no-opaque-pointers %s --std=c++17 -triple nvptx-unknown-unknown \
8 // RUN: -emit-llvm -o - | FileCheck %s --check-prefixes=COMMON,HOST
10 #include "Inputs/cuda.h"
11 extern "C" __host__ void host_fn();
12 extern "C" __device__ void dev_fn();
13 extern "C" __host__ __device__ void hd_fn();
15 // Destructors are handled a bit differently, compared to regular functions.
16 // Make sure we do trigger kernel generation on the GPU side even if it's only
17 // referenced by the destructor.
18 template<typename T> __global__ void f(T) {}
19 template<typename T> struct A {
20 ~A() { f<<<1, 1>>>(T()); }
25 // HOST-LABEL: define linkonce_odr void @_ZN1AIiED1Ev
26 // search further down for the deice-side checks for @_Z1fIiEvT_
29 __host__ void operator delete(void *) { host_fn(); };
30 __device__ void operator delete(void *) { dev_fn(); };
34 __host__ void operator delete(void *) { host_fn(); };
35 __device__ void operator delete(void *, __SIZE_TYPE__) { dev_fn(); };
39 __host__ void operator delete(void *, __SIZE_TYPE__) { host_fn(); };
40 __device__ void operator delete(void *) { dev_fn(); };
44 __host__ void operator delete(void *, __SIZE_TYPE__) { host_fn(); };
45 __device__ void operator delete(void *, __SIZE_TYPE__) { dev_fn(); };
49 __host__ void operator delete(void *) { host_fn(); };
50 __device__ void operator delete(void *) { dev_fn(); };
51 __device__ void operator delete(void *, __SIZE_TYPE__) { dev_fn(); };
55 __host__ void operator delete(void *) { host_fn(); };
56 __host__ void operator delete(void *, __SIZE_TYPE__) { host_fn(); };
57 __device__ void operator delete(void *) { dev_fn(); };
61 __host__ void operator delete(void *) { host_fn(); };
62 __host__ void operator delete(void *, __SIZE_TYPE__) { host_fn(); };
63 __device__ void operator delete(void *, __SIZE_TYPE__) { dev_fn(); };
67 __host__ void operator delete(void *) { host_fn(); };
68 __host__ void operator delete(void *, __SIZE_TYPE__) { host_fn(); };
69 __device__ void operator delete(void *) { dev_fn(); };
70 __device__ void operator delete(void *, __SIZE_TYPE__) { dev_fn(); };
75 __host__ __device__ void test_hd(void *p) {
80 // Make sure we call the right variant of usual deallocator.
81 __host__ __device__ void tests_hd(void *t) {
82 // COMMON-LABEL: define linkonce_odr void @_Z7test_hdI4H1D1EvPv
83 // COMMON: call void @_ZN4H1D1dlEPv
85 // COMMON-LABEL: define linkonce_odr void @_Z7test_hdI4H1D2EvPv
86 // DEVICE: call void @_ZN4H1D2dlEPvj(i8* noundef {{.*}}, i32 noundef 1)
87 // HOST: call void @_ZN4H1D2dlEPv(i8* noundef {{.*}})
89 // COMMON-LABEL: define linkonce_odr void @_Z7test_hdI4H2D1EvPv
90 // DEVICE: call void @_ZN4H2D1dlEPv(i8* {{.*}})
91 // HOST: call void @_ZN4H2D1dlEPvj(i8* noundef %3, i32 noundef 1)
93 // COMMON-LABEL: define linkonce_odr void @_Z7test_hdI4H2D2EvPv
94 // COMMON: call void @_ZN4H2D2dlEPvj(i8* noundef {{.*}}, i32 noundef 1)
96 // COMMON-LABEL: define linkonce_odr void @_Z7test_hdI6H1D1D2EvPv
97 // COMMON: call void @_ZN6H1D1D2dlEPv(i8* noundef %3)
99 // COMMON-LABEL: define linkonce_odr void @_Z7test_hdI6H1H2D1EvPv
100 // COMMON: call void @_ZN6H1H2D1dlEPv(i8* {{.*}})
102 // COMMON-LABEL: define linkonce_odr void @_Z7test_hdI6H1H2D2EvPv
103 // DEVICE: call void @_ZN6H1H2D2dlEPvj(i8* noundef {{.*}}, i32 noundef 1)
104 // HOST: call void @_ZN6H1H2D2dlEPv(i8* noundef {{.*}})
106 // COMMON-LABEL: define linkonce_odr void @_Z7test_hdI8H1H2D1D2EvPv
107 // COMMON: call void @_ZN8H1H2D1D2dlEPv(i8* {{.*}})
108 test_hd<H1H2D1D2>(t);
111 // Make sure that we've generated the kernel used by A::~A.
112 // DEVICE-LABEL: define void @_Z1fIiEvT_
114 // Make sure we've picked deallocator for the correct side of compilation.
116 // COMMON-LABEL: define linkonce_odr void @_ZN4H1D1dlEPv(i8* noundef %0)
117 // DEVICE: call void @dev_fn()
118 // HOST: call void @host_fn()
120 // DEVICE-LABEL: define linkonce_odr void @_ZN4H1D2dlEPvj(i8* noundef %0, i32 noundef %1)
121 // DEVICE: call void @dev_fn()
122 // HOST-LABEL: define linkonce_odr void @_ZN4H1D2dlEPv(i8* noundef %0)
123 // HOST: call void @host_fn()
125 // DEVICE-LABEL: define linkonce_odr void @_ZN4H2D1dlEPv(i8* noundef %0)
126 // DEVICE: call void @dev_fn()
127 // HOST-LABEL: define linkonce_odr void @_ZN4H2D1dlEPvj(i8* noundef %0, i32 noundef %1)
128 // HOST: call void @host_fn()
130 // COMMON-LABEL: define linkonce_odr void @_ZN4H2D2dlEPvj(i8* noundef %0, i32 noundef %1)
131 // DEVICE: call void @dev_fn()
132 // HOST: call void @host_fn()
134 // COMMON-LABEL: define linkonce_odr void @_ZN6H1D1D2dlEPv(i8* noundef %0)
135 // DEVICE: call void @dev_fn()
136 // HOST: call void @host_fn()
138 // COMMON-LABEL: define linkonce_odr void @_ZN6H1H2D1dlEPv(i8* noundef %0)
139 // DEVICE: call void @dev_fn()
140 // HOST: call void @host_fn()
142 // DEVICE-LABEL: define linkonce_odr void @_ZN6H1H2D2dlEPvj(i8* noundef %0, i32 noundef %1)
143 // DEVICE: call void @dev_fn()
144 // HOST-LABEL: define linkonce_odr void @_ZN6H1H2D2dlEPv(i8* noundef %0)
145 // HOST: call void @host_fn()
147 // COMMON-LABEL: define linkonce_odr void @_ZN8H1H2D1D2dlEPv(i8* noundef %0)
148 // DEVICE: call void @dev_fn()
149 // HOST: call void @host_fn()
151 // DEVICE: !0 = !{void (i32)* @_Z1fIiEvT_, !"kernel", i32 1}