Debian Codegraph @

clang/test/CodeGenSYCL/sycl-external-attr.cpp

raw
1 // RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -disable-llvm-passes -emit-llvm %s -o - | FileCheck %s
2
3 // This test code generation when sycl_external attribute is used
4
5 // Function defined and not used - symbols emitted
6 [[clang::sycl_external]] int square(int x) { return x*x; }
7 // CHECK: define dso_local spir_func noundef i32 @_Z6squarei
8
9 // Function defined and used - symbols emitted
10 [[clang::sycl_external]] int squareUsed(int x) { return x*x; }
11 // CHECK: define dso_local spir_func noundef i32 @_Z10squareUsedi
12
13 // FIXME: Constexpr function defined and not used - symbols emitted
14 [[clang::sycl_external]] constexpr int squareInlined(int x) { return x*x; }
15 // CHECK: define linkonce_odr spir_func noundef i32 @_Z13squareInlinedi
16
17 // Function declared but not defined or used - no symbols emitted
18 [[clang::sycl_external]] int declOnly();
19 // CHECK-NOT: define {{.*}} i32 @_Z8declOnlyv
20 // CHECK-NOT: declare {{.*}} i32 @_Z8declOnlyv
21
22 // Function declared and used in host but not defined - no symbols emitted
23 [[clang::sycl_external]] void declUsedInHost(int y);
24
25 // Function declared and used in device but not defined - emit external reference
26 [[clang::sycl_external]] void declUsedInDevice(int y);
27 // CHECK: define dso_local spir_func void @_Z9deviceUsev
28 [[clang::sycl_external]] void deviceUse() { declUsedInDevice(3); }
29 // CHECK: declare spir_func void @_Z16declUsedInDevicei
30
31 // Function declared with the attribute and later defined - definition emitted
32 [[clang::sycl_external]] int func1(int arg);
33 int func1(int arg) { return arg; }
34 // CHECK: define dso_local spir_func noundef i32 @_Z5func1i
35
36 class A {
37 // Unused defaulted special member functions - no symbols emitted
38 [[clang::sycl_external]] A& operator=(A& a) = default;
39 };
40
41 class B {
42 [[clang::sycl_external]] virtual void BFunc1WithAttr() { int i = 1; }
43 // CHECK: define linkonce_odr spir_func void @_ZN1B14BFunc1WithAttrEv
44 virtual void BFunc2NoAttr() { int i = 2; }
45 };
46
47 class C {
48 // Special member function defined - definition emitted
49 [[clang::sycl_external]] ~C() {}
50 // CHECK: define linkonce_odr spir_func void @_ZN1CD1Ev
51 };
52
53 // Function reachable from an unused function - definition emitted
54 int ret1() { return 1; }
55 [[clang::sycl_external]] int withAttr() { return ret1(); }
56 // CHECK: define dso_local spir_func noundef i32 @_Z8withAttrv
57 // CHECK: define dso_local spir_func noundef i32 @_Z4ret1v
58
59 template <typename T>
60 [[clang::sycl_external]] void tFunc1(T arg) {}
61 // Explicit specialization defined - symbols emitted
62 template<>
63 [[clang::sycl_external]] void tFunc1<int>(int arg) {}
64 // CHECK: define dso_local spir_func void @_Z6tFunc1IiEvT_
65
66 template <typename T>
67 [[clang::sycl_external]] void tFunc2(T arg) {}
68 template void tFunc2<int>(int arg);
69 // CHECK: define weak_odr spir_func void @_Z6tFunc2IiEvT_
70 template<> void tFunc2<char>(char arg) {}
71 // CHECK: define dso_local spir_func void @_Z6tFunc2IcEvT_
72 template<> [[clang::sycl_external]] void tFunc2<long>(long arg) {}
73 // CHECK: define dso_local spir_func void @_Z6tFunc2IlEvT_
74
75 // Functions defined without the sycl_external attribute that are used
76 // in host code, but not in device code are not emitted.
77 int squareNoAttr(int x) { return x*x; }
78 // CHECK-NOT: define {{.*}} i32 @_Z12squareNoAttri
79
80 int main() {
81 declUsedInHost(4);
82 int i = squareUsed(5);
83 int j = squareNoAttr(6);
84 return 0;
85 }