blob: 1d330bdf6a49d8561972542747b10c721342c2ed [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
Stephen Lin43622612013-08-15 06:47:53 +00009// CHECK-LABEL: define void @device_function
Justin Holewinski36837432013-03-30 14:38:24 +000010extern "C"
Peter Collingbourne5bad4af2011-10-06 16:49:54 +000011__device__ void device_function() {}
12
Stephen Lin43622612013-08-15 06:47:53 +000013// CHECK-LABEL: define void @global_function
Justin Holewinski36837432013-03-30 14:38:24 +000014extern "C"
Peter Collingbourne5bad4af2011-10-06 16:49:54 +000015__global__ void global_function() {
Justin Holewinski36837432013-03-30 14:38:24 +000016 // CHECK: call void @device_function
Peter Collingbourne5bad4af2011-10-06 16:49:54 +000017 device_function();
18}
Justin Holewinski36837432013-03-30 14:38:24 +000019
Artem Belevichc3fa25d2015-09-22 17:22:51 +000020// Make sure host-instantiated kernels are preserved on device side.
21template <typename T> __global__ void templated_kernel(T param) {}
Justin Lebar27ee1302016-06-30 18:41:33 +000022// CHECK-DAG: define void @_Z16templated_kernelIiEvT_(
Artem Belevichca2b9512016-05-02 20:30:03 +000023
24namespace {
25__global__ void anonymous_ns_kernel() {}
Justin Lebar27ee1302016-06-30 18:41:33 +000026// CHECK-DAG: define void @_ZN12_GLOBAL__N_119anonymous_ns_kernelEv(
Artem Belevichca2b9512016-05-02 20:30:03 +000027}
28
29void host_function() {
30 templated_kernel<<<0, 0>>>(0);
31 anonymous_ns_kernel<<<0,0>>>();
32}
Artem Belevichc3fa25d2015-09-22 17:22:51 +000033
Duncan P. N. Exon Smithb3a66692014-12-15 19:10:08 +000034// CHECK: !{{[0-9]+}} = !{void ()* @global_function, !"kernel", i32 1}
Artem Belevichc3fa25d2015-09-22 17:22:51 +000035// CHECK: !{{[0-9]+}} = !{void (i32)* @_Z16templated_kernelIiEvT_, !"kernel", i32 1}