From 5cf2a37f1255700d4da9d5f45e82bdfff09aee8c Mon Sep 17 00:00:00 2001 From: "Yaxun (Sam) Liu" Date: Mon, 8 Feb 2021 12:29:29 -0500 Subject: [HIP] Emit kernel symbol Currently clang uses stub function to launch kernel. This is inconvenient to interop with C++ programs since the stub function has different name as kernel, which is required by ROCm debugger. This patch emits a variable symbol which has the same name as the kernel and uses it to register and launch the kernel. This allows C++ program to launch a kernel by using the original kernel name. Reviewed by: Artem Belevich Differential Revision: https://reviews.llvm.org/D86376 --- clang/lib/CodeGen/CodeGenModule.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'clang/lib/CodeGen/CodeGenModule.cpp') diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 0d499a564039..750439dd6844 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -3571,9 +3571,19 @@ llvm::Constant *CodeGenModule::GetAddrOfFunction(GlobalDecl GD, } StringRef MangledName = getMangledName(GD); - return GetOrCreateLLVMFunction(MangledName, Ty, GD, ForVTable, DontDefer, - /*IsThunk=*/false, llvm::AttributeList(), - IsForDefinition); + auto *F = GetOrCreateLLVMFunction(MangledName, Ty, GD, ForVTable, DontDefer, + /*IsThunk=*/false, llvm::AttributeList(), + IsForDefinition); + // Returns kernel handle for HIP kernel stub function. + if (LangOpts.CUDA && !LangOpts.CUDAIsDevice && + cast(GD.getDecl())->hasAttr()) { + auto *Handle = getCUDARuntime().getKernelHandle( + cast(F->stripPointerCasts()), GD); + if (IsForDefinition) + return F; + return llvm::ConstantExpr::getBitCast(Handle, Ty->getPointerTo()); + } + return F; } static const FunctionDecl * -- cgit v1.2.3