diff options
| author | Artem Belevich <tra@google.com> | 2015-12-17 18:12:36 +0000 |
|---|---|---|
| committer | Artem Belevich <tra@google.com> | 2015-12-17 18:12:36 +0000 |
| commit | 9b9294674b879d260b61b9176bc88a02d00265ac (patch) | |
| tree | a2cfad9265c4c029413047290540cb7a316add40 /clang/test/CodeGenCUDA/device-vtable.cu | |
| parent | 8b524597efcef4ff37f667195516e468be66da6f (diff) | |
| download | bcm5719-llvm-9b9294674b879d260b61b9176bc88a02d00265ac.tar.gz bcm5719-llvm-9b9294674b879d260b61b9176bc88a02d00265ac.zip | |
[CUDA] Make vtable construction aware of host/device side of CUDA compilation.
C++ emits vtables for classes that have key function present in the
current TU. While we compile CUDA the fact that key function was found
in this TU does not mean that we are going to generate code for it. E.g.
vtable for a class with host-only methods should not (and can not) be
generated on device side, because we'll never generate code for them
during device-side compilation.
This patch adds an extra CUDA-specific check during key method computation
and filters out potential key methods that are not suitable for this side
of CUDA compilation.
When we codegen vtable, entries for unsuitable methods are set to null.
Differential Revision: http://reviews.llvm.org/D15309
llvm-svn: 255911
Diffstat (limited to 'clang/test/CodeGenCUDA/device-vtable.cu')
| -rw-r--r-- | clang/test/CodeGenCUDA/device-vtable.cu | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/clang/test/CodeGenCUDA/device-vtable.cu b/clang/test/CodeGenCUDA/device-vtable.cu new file mode 100644 index 00000000000..9730e404caa --- /dev/null +++ b/clang/test/CodeGenCUDA/device-vtable.cu @@ -0,0 +1,61 @@ +// REQUIRES: x86-registered-target +// REQUIRES: nvptx-registered-target + +// Make sure we don't emit vtables for classes with methods that have +// inappropriate target attributes. Currently it's mostly needed in +// order to avoid emitting vtables for host-only classes on device +// side where we can't codegen them. + +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -o - %s \ +// RUN: | FileCheck %s -check-prefix=CHECK-HOST -check-prefix=CHECK-BOTH +// RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fcuda-is-device -emit-llvm -o - %s \ +// RUN: | FileCheck %s -check-prefix=CHECK-DEVICE -check-prefix=CHECK-BOTH + +#include "Inputs/cuda.h" + +struct H { + virtual void method(); +}; +//CHECK-HOST: @_ZTV1H = +//CHECK-HOST-SAME: @_ZN1H6methodEv +//CHECK-DEVICE-NOT: @_ZTV1H = + +struct D { + __device__ virtual void method(); +}; + +//CHECK-DEVICE: @_ZTV1D +//CHECK-DEVICE-SAME: @_ZN1D6methodEv +//CHECK-HOST-NOT: @_ZTV1D + +// This is the case with mixed host and device virtual methods. It's +// impossible to emit a valid vtable in that case because only host or +// only device methods would be available during host or device +// compilation. At the moment Clang (and NVCC) emit NULL pointers for +// unavailable methods, +struct HD { + virtual void h_method(); + __device__ virtual void d_method(); +}; +// CHECK-BOTH: @_ZTV2HD +// CHECK-DEVICE-NOT: @_ZN2HD8h_methodEv +// CHECK-DEVICE-SAME: null +// CHECK-DEVICE-SAME: @_ZN2HD8d_methodEv +// CHECK-HOST-SAME: @_ZN2HD8h_methodEv +// CHECK-HOST-NOT: @_ZN2HD8d_methodEv +// CHECK-HOST-SAME: null +// CHECK-BOTH-SAME: ] + +void H::method() {} +//CHECK-HOST: define void @_ZN1H6methodEv + +void __device__ D::method() {} +//CHECK-DEVICE: define void @_ZN1D6methodEv + +void __device__ HD::d_method() {} +// CHECK-DEVICE: define void @_ZN2HD8d_methodEv +// CHECK-HOST-NOT: define void @_ZN2HD8d_methodEv +void HD::h_method() {} +// CHECK-HOST: define void @_ZN2HD8h_methodEv +// CHECK-DEVICE-NOT: define void @_ZN2HD8h_methodEv + |

