[CUDA][HIP] Fix host used external kernel in archive
authorYaxun (Sam) Liu <yaxun.liu@amd.com>
Sat, 9 Apr 2022 03:56:07 +0000 (23:56 -0400)
committerYaxun (Sam) Liu <yaxun.liu@amd.com>
Wed, 13 Apr 2022 14:47:16 +0000 (10:47 -0400)
commit0424b5115cffad73a0f6e68affed603a7ed9a692
treeb56c890234e87faa29bb8c859f855bcd9376def6
parent8c74169990c0b179fa9a0c82f8d6ca35889b9ec4
[CUDA][HIP] Fix host used external kernel in archive

For -fgpu-rdc, a host function may call an external kernel
which is defined in an archive of bitcode. Since this external
kernel is only referenced in host function, the device
bitcode does not contain reference to this external
kernel, then the linker will not try to resolve this external
kernel in the archive.

To fix this issue, host-used external kernels and device
variables are tracked. A global array containing pointers
to these external kernels and variables is emitted which
serves as an artificial references to the external kernels
and variables used by host.

Reviewed by: Artem Belevich

Differential Revision: https://reviews.llvm.org/D123441
clang/include/clang/AST/ASTContext.h
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/Sema/SemaCUDA.cpp
clang/lib/Sema/SemaExpr.cpp
clang/test/CodeGenCUDA/host-used-extern.cu [new file with mode: 0644]