brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.3 KiB · 2c22e65 Raw
86 lines · cpp
1// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -disable-llvm-passes -emit-llvm %s -o - | FileCheck %s2 3// This test code generation when sycl_external attribute is used4 5// Function defined and not used - symbols emitted6[[clang::sycl_external]] int square(int x) { return x*x; }7// CHECK: define dso_local spir_func noundef i32 @_Z6squarei8 9// Function defined and used - symbols emitted10[[clang::sycl_external]] int squareUsed(int x) { return x*x; }11// CHECK: define dso_local spir_func noundef i32 @_Z10squareUsedi12 13// FIXME: Constexpr function defined and not used - symbols emitted14[[clang::sycl_external]] constexpr int squareInlined(int x) { return x*x; }15// CHECK: define linkonce_odr spir_func noundef i32 @_Z13squareInlinedi16 17// Function declared but not defined or used - no symbols emitted18[[clang::sycl_external]] int declOnly();19// CHECK-NOT: define {{.*}} i32 @_Z8declOnlyv20// CHECK-NOT: declare {{.*}} i32 @_Z8declOnlyv21 22// Function declared and used in host but not defined - no symbols emitted23[[clang::sycl_external]] void declUsedInHost(int y);24 25// Function declared and used in device but not defined - emit external reference26[[clang::sycl_external]] void declUsedInDevice(int y);27// CHECK: define dso_local spir_func void @_Z9deviceUsev28[[clang::sycl_external]] void deviceUse() { declUsedInDevice(3); }29// CHECK: declare spir_func void @_Z16declUsedInDevicei30 31// Function declared with the attribute and later defined - definition emitted32[[clang::sycl_external]] int func1(int arg);33int func1(int arg) { return arg; }34// CHECK: define dso_local spir_func noundef i32 @_Z5func1i35 36class A {37// Unused defaulted special member functions - no symbols emitted38  [[clang::sycl_external]] A& operator=(A& a) = default;39};40 41class B {42  [[clang::sycl_external]] virtual void BFunc1WithAttr() { int i = 1; }43// CHECK: define linkonce_odr spir_func void @_ZN1B14BFunc1WithAttrEv44  virtual void BFunc2NoAttr() { int i = 2; }45};46 47class C {48// Special member function defined - definition emitted49  [[clang::sycl_external]] ~C() {}50// CHECK: define linkonce_odr spir_func void @_ZN1CD1Ev51};52 53// Function reachable from an unused function - definition emitted54int ret1() { return 1; }55[[clang::sycl_external]] int withAttr() { return ret1(); }56// CHECK: define dso_local spir_func noundef i32 @_Z8withAttrv57// CHECK: define dso_local spir_func noundef i32 @_Z4ret1v58 59template <typename T>60[[clang::sycl_external]] void tFunc1(T arg) {}61// Explicit specialization defined - symbols emitted62template<>63[[clang::sycl_external]] void tFunc1<int>(int arg) {}64// CHECK: define dso_local spir_func void @_Z6tFunc1IiEvT_65 66template <typename T>67[[clang::sycl_external]] void tFunc2(T arg) {}68template void tFunc2<int>(int arg);69// CHECK: define weak_odr spir_func void @_Z6tFunc2IiEvT_70template<> void tFunc2<char>(char arg) {}71// CHECK: define dso_local spir_func void @_Z6tFunc2IcEvT_72template<> [[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 used76// in host code, but not in device code are not emitted.77int squareNoAttr(int x) { return x*x; }78// CHECK-NOT: define {{.*}} i32 @_Z12squareNoAttri79 80int main() {81  declUsedInHost(4);82  int i = squareUsed(5);83  int j = squareNoAttr(6);84  return 0;85}86