Artem Belevich | c3fa25d | 2015-09-22 17:22:51 +0000 | [diff] [blame] | 1 | // Make sure that __global__ functions are emitted along with correct |
| 2 | // annotations and are added to @llvm.used to prevent their elimination. |
| 3 | // REQUIRES: nvptx-registered-target |
| 4 | // |
Justin Holewinski | 83e9668 | 2012-05-24 17:43:12 +0000 | [diff] [blame] | 5 | // RUN: %clang_cc1 %s -triple nvptx-unknown-unknown -fcuda-is-device -emit-llvm -o - | FileCheck %s |
Peter Collingbourne | 5bad4af | 2011-10-06 16:49:54 +0000 | [diff] [blame] | 6 | |
Eli Bendersky | 3468d9d | 2014-04-28 22:21:28 +0000 | [diff] [blame] | 7 | #include "Inputs/cuda.h" |
Peter Collingbourne | 5bad4af | 2011-10-06 16:49:54 +0000 | [diff] [blame] | 8 | |
Stephen Lin | 4362261 | 2013-08-15 06:47:53 +0000 | [diff] [blame] | 9 | // CHECK-LABEL: define void @device_function |
Justin Holewinski | 3683743 | 2013-03-30 14:38:24 +0000 | [diff] [blame] | 10 | extern "C" |
Peter Collingbourne | 5bad4af | 2011-10-06 16:49:54 +0000 | [diff] [blame] | 11 | __device__ void device_function() {} |
| 12 | |
Stephen Lin | 4362261 | 2013-08-15 06:47:53 +0000 | [diff] [blame] | 13 | // CHECK-LABEL: define void @global_function |
Justin Holewinski | 3683743 | 2013-03-30 14:38:24 +0000 | [diff] [blame] | 14 | extern "C" |
Peter Collingbourne | 5bad4af | 2011-10-06 16:49:54 +0000 | [diff] [blame] | 15 | __global__ void global_function() { |
Justin Holewinski | 3683743 | 2013-03-30 14:38:24 +0000 | [diff] [blame] | 16 | // CHECK: call void @device_function |
Peter Collingbourne | 5bad4af | 2011-10-06 16:49:54 +0000 | [diff] [blame] | 17 | device_function(); |
| 18 | } |
Justin Holewinski | 3683743 | 2013-03-30 14:38:24 +0000 | [diff] [blame] | 19 | |
Artem Belevich | c3fa25d | 2015-09-22 17:22:51 +0000 | [diff] [blame] | 20 | // Make sure host-instantiated kernels are preserved on device side. |
| 21 | template <typename T> __global__ void templated_kernel(T param) {} |
Justin Lebar | 27ee130 | 2016-06-30 18:41:33 +0000 | [diff] [blame] | 22 | // CHECK-DAG: define void @_Z16templated_kernelIiEvT_( |
Artem Belevich | ca2b951 | 2016-05-02 20:30:03 +0000 | [diff] [blame] | 23 | |
| 24 | namespace { |
| 25 | __global__ void anonymous_ns_kernel() {} |
Justin Lebar | 27ee130 | 2016-06-30 18:41:33 +0000 | [diff] [blame] | 26 | // CHECK-DAG: define void @_ZN12_GLOBAL__N_119anonymous_ns_kernelEv( |
Artem Belevich | ca2b951 | 2016-05-02 20:30:03 +0000 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | void host_function() { |
| 30 | templated_kernel<<<0, 0>>>(0); |
| 31 | anonymous_ns_kernel<<<0,0>>>(); |
| 32 | } |
Artem Belevich | c3fa25d | 2015-09-22 17:22:51 +0000 | [diff] [blame] | 33 | |
Duncan P. N. Exon Smith | b3a6669 | 2014-12-15 19:10:08 +0000 | [diff] [blame] | 34 | // CHECK: !{{[0-9]+}} = !{void ()* @global_function, !"kernel", i32 1} |
Artem Belevich | c3fa25d | 2015-09-22 17:22:51 +0000 | [diff] [blame] | 35 | // CHECK: !{{[0-9]+}} = !{void (i32)* @_Z16templated_kernelIiEvT_, !"kernel", i32 1} |