This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by yaxunl on Jun 3 2018, 4:41 PM.

Details

Summary

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.

Diff Detail

Event Timeline

yaxunl created this revision.Jun 3 2018, 4:41 PM

Why not just have the driver disable RTTI in the frontend invocation?

yaxunl added a comment.Jun 3 2018, 8:15 PM

Why not just have the driver disable RTTI in the frontend invocation?

CUDA/HIP uses single source for device and host. The host code may depend on RTTI,
e.g., an application may include some boost headers which will fail if RTTI is disabled,
therefore RTTI cannot be disabled when compiling device code.

Why not just have the driver disable RTTI in the frontend invocation?

CUDA/HIP uses single source for device and host. The host code may depend on RTTI,
e.g., an application may include some boost headers which will fail if RTTI is disabled,
therefore RTTI cannot be disabled when compiling device code.

It's a single source file, yes, but behind the scenes you do a separate invocation of the compiler to re-parse that file for device code-generation, right?

yaxunl added a comment.Jun 4 2018, 9:18 AM

Why not just have the driver disable RTTI in the frontend invocation?

CUDA/HIP uses single source for device and host. The host code may depend on RTTI,
e.g., an application may include some boost headers which will fail if RTTI is disabled,
therefore RTTI cannot be disabled when compiling device code.

It's a single source file, yes, but behind the scenes you do a separate invocation of the compiler to re-parse that file for device code-generation, right?

That's true. However, when compiling for device, the source file is still the original source code which are for both host and device. When compiling
for device, the compiler still needs to parse the source code for host, and there is no way to disable RTTI only for the device code.

Oh, I see, because you're worried that the host code might contain dynamic_cast or similar features which would complain if RTTI were disabled.

getLangOpts().CUDAIsDevice implies getLangOpts().CUDA, so I think you can just check the former. Otherwise LGTM.

yaxunl updated this revision to Diff 149892.Jun 4 2018, 6:53 PM

Revised by John's comments.

rjmccall accepted this revision.Jun 4 2018, 8:53 PM

Thanks, LGTM.

This revision is now accepted and ready to land.Jun 4 2018, 8:53 PM
This revision was automatically updated to reflect the committed changes.