blob: 3a8722a342d101c81f22916c06a9e4aa22311f49 [file] [log] [blame]
Artem Belevichc3fa25d2015-09-22 17:22:51 +00001// 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 Holewinski83e96682012-05-24 17:43:12 +00005// RUN: %clang_cc1 %s -triple nvptx-unknown-unknown -fcuda-is-device -emit-llvm -o - | FileCheck %s
Peter Collingbourne5bad4af2011-10-06 16:49:54 +00006
Eli Bendersky3468d9d2014-04-28 22:21:28 +00007#include "Inputs/cuda.h"
Peter Collingbourne5bad4af2011-10-06 16:49:54 +00008
Artem Belevichc3fa25d2015-09-22 17:22:51 +00009// Make sure that all __global__ functions are added to @llvm.used
10// CHECK: @llvm.used = appending global
11// CHECK-SAME: @global_function
12// CHECK-SAME: @_Z16templated_kernelIiEvT_
13
Stephen Lin43622612013-08-15 06:47:53 +000014// CHECK-LABEL: define void @device_function
Justin Holewinski36837432013-03-30 14:38:24 +000015extern "C"
Peter Collingbourne5bad4af2011-10-06 16:49:54 +000016__device__ void device_function() {}
17
Stephen Lin43622612013-08-15 06:47:53 +000018// CHECK-LABEL: define void @global_function
Justin Holewinski36837432013-03-30 14:38:24 +000019extern "C"
Peter Collingbourne5bad4af2011-10-06 16:49:54 +000020__global__ void global_function() {
Justin Holewinski36837432013-03-30 14:38:24 +000021 // CHECK: call void @device_function
Peter Collingbourne5bad4af2011-10-06 16:49:54 +000022 device_function();
23}
Justin Holewinski36837432013-03-30 14:38:24 +000024
Artem Belevichc3fa25d2015-09-22 17:22:51 +000025// Make sure host-instantiated kernels are preserved on device side.
26template <typename T> __global__ void templated_kernel(T param) {}
27// CHECK-LABEL: define linkonce_odr void @_Z16templated_kernelIiEvT_
28void host_function() { templated_kernel<<<0,0>>>(0); }
29
Duncan P. N. Exon Smithb3a66692014-12-15 19:10:08 +000030// CHECK: !{{[0-9]+}} = !{void ()* @global_function, !"kernel", i32 1}
Artem Belevichc3fa25d2015-09-22 17:22:51 +000031// CHECK: !{{[0-9]+}} = !{void (i32)* @_Z16templated_kernelIiEvT_, !"kernel", i32 1}