From 3b9ebe92011b033523217a9b9a2f03f4c8c37aab Mon Sep 17 00:00:00 2001 From: Nick Sarnie Date: Thu, 5 Jun 2025 10:15:38 -0400 Subject: [clang] Simplify device kernel attributes (#137882) We have multiple different attributes in clang representing device kernels for specific targets/languages. Refactor them into one attribute with different spellings to make it more easily scalable for new languages/targets. --------- Signed-off-by: Sarnie, Nick --- clang/lib/CodeGen/CodeGenModule.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'clang/lib/CodeGen/CodeGenModule.cpp') diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 468fc6e..84166dd 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -1913,7 +1913,9 @@ static std::string getMangledNameImpl(CodeGenModule &CGM, GlobalDecl GD, } else if (FD && FD->hasAttr() && GD.getKernelReferenceKind() == KernelReferenceKind::Stub) { Out << "__device_stub__" << II->getName(); - } else if (FD && FD->hasAttr() && + } else if (FD && + DeviceKernelAttr::isOpenCLSpelling( + FD->getAttr()) && GD.getKernelReferenceKind() == KernelReferenceKind::Stub) { Out << "__clang_ocl_kern_imp_" << II->getName(); } else { @@ -3930,7 +3932,8 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) { // Ignore declarations, they will be emitted on their first use. if (const auto *FD = dyn_cast(Global)) { - if (FD->hasAttr() && FD->doesThisDeclarationHaveABody()) + if (DeviceKernelAttr::isOpenCLSpelling(FD->getAttr()) && + FD->doesThisDeclarationHaveABody()) addDeferredDeclToEmit(GlobalDecl(FD, KernelReferenceKind::Stub)); // Update deferred annotations with the latest declaration if the function @@ -4895,7 +4898,7 @@ CodeGenModule::GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty, bool ForVTable, if (!Ty) { const auto *FD = cast(GD.getDecl()); Ty = getTypes().ConvertType(FD->getType()); - if (FD->hasAttr() && + if (DeviceKernelAttr::isOpenCLSpelling(FD->getAttr()) && GD.getKernelReferenceKind() == KernelReferenceKind::Stub) { const CGFunctionInfo &FI = getTypes().arrangeGlobalDeclaration(GD); Ty = getTypes().GetFunctionType(FI); @@ -6195,7 +6198,7 @@ void CodeGenModule::EmitGlobalFunctionDefinition(GlobalDecl GD, (CodeGenOpts.OptimizationLevel == 0) && !D->hasAttr(); - if (D->hasAttr()) { + if (DeviceKernelAttr::isOpenCLSpelling(D->getAttr())) { if (GD.getKernelReferenceKind() == KernelReferenceKind::Stub && !D->hasAttr() && !Fn->hasFnAttribute(llvm::Attribute::NoInline) && -- cgit v1.1