Преглед изворни кода

[CUDA][HIP] Do not emit type info when compiling for device

CUDA/HIP does not support RTTI on device side, therefore there
is no point of emitting type info when compiling for device.

Emitting type info for device not only clutters the IR with useless
global variables, but also causes undefined symbol at linking
since vtable for cxxabiv1::class_type_info has external linkage.

Differential Revision: https://reviews.llvm.org/D47694


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@334021 91177308-0d34-0410-b5e6-96231b3b80d8
Yaxun Liu пре 7 година
родитељ
комит
571a2502f2
2 измењених фајлова са 10 додато и 3 уклоњено
  1. 1 1
      lib/CodeGen/CodeGenModule.cpp
  2. 9 2
      test/CodeGenCUDA/device-vtable.cu

+ 1 - 1
lib/CodeGen/CodeGenModule.cpp

@@ -4900,7 +4900,7 @@ llvm::Constant *CodeGenModule::GetAddrOfRTTIDescriptor(QualType Ty,
   // Return a bogus pointer if RTTI is disabled, unless it's for EH.
   // Return a bogus pointer if RTTI is disabled, unless it's for EH.
   // FIXME: should we even be calling this method if RTTI is disabled
   // FIXME: should we even be calling this method if RTTI is disabled
   // and it's not for EH?
   // and it's not for EH?
-  if (!ForEH && !getLangOpts().RTTI)
+  if ((!ForEH && !getLangOpts().RTTI) || getLangOpts().CUDAIsDevice)
     return llvm::Constant::getNullValue(Int8PtrTy);
     return llvm::Constant::getNullValue(Int8PtrTy);
 
 
   if (ForEH && Ty->isObjCObjectPointerType() &&
   if (ForEH && Ty->isObjCObjectPointerType() &&

+ 9 - 2
test/CodeGenCUDA/device-vtable.cu

@@ -19,7 +19,9 @@ struct H  {
 //CHECK-HOST: @_ZTV1H =
 //CHECK-HOST: @_ZTV1H =
 //CHECK-HOST-SAME: @_ZN1H6methodEv
 //CHECK-HOST-SAME: @_ZN1H6methodEv
 //CHECK-DEVICE-NOT: @_ZTV1H =
 //CHECK-DEVICE-NOT: @_ZTV1H =
-
+//CHECK-DEVICE-NOT: @_ZTVN10__cxxabiv117__class_type_infoE
+//CHECK-DEVICE-NOT: @_ZTS1H
+//CHECK-DEVICE-NOT: @_ZTI1H
 struct D  {
 struct D  {
    __device__ virtual void method();
    __device__ virtual void method();
 };
 };
@@ -27,7 +29,9 @@ struct D  {
 //CHECK-DEVICE: @_ZTV1D
 //CHECK-DEVICE: @_ZTV1D
 //CHECK-DEVICE-SAME: @_ZN1D6methodEv
 //CHECK-DEVICE-SAME: @_ZN1D6methodEv
 //CHECK-HOST-NOT: @_ZTV1D
 //CHECK-HOST-NOT: @_ZTV1D
-
+//CHECK-DEVICE-NOT: @_ZTVN10__cxxabiv117__class_type_infoE
+//CHECK-DEVICE-NOT: @_ZTS1D
+//CHECK-DEVICE-NOT: @_ZTI1D
 // This is the case with mixed host and device virtual methods.  It's
 // 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
 // impossible to emit a valid vtable in that case because only host or
 // only device methods would be available during host or device
 // only device methods would be available during host or device
@@ -45,6 +49,9 @@ struct HD  {
 // CHECK-HOST-NOT: @_ZN2HD8d_methodEv
 // CHECK-HOST-NOT: @_ZN2HD8d_methodEv
 // CHECK-HOST-SAME: null
 // CHECK-HOST-SAME: null
 // CHECK-BOTH-SAME: ]
 // CHECK-BOTH-SAME: ]
+// CHECK-DEVICE-NOT: @_ZTVN10__cxxabiv117__class_type_infoE
+// CHECK-DEVICE-NOT: @_ZTS2HD
+// CHECK-DEVICE-NOT: @_ZTI2HD
 
 
 void H::method() {}
 void H::method() {}
 //CHECK-HOST: define void @_ZN1H6methodEv
 //CHECK-HOST: define void @_ZN1H6methodEv