From c3ce5684a8b408220eed983d065edba0e6ed5016 Mon Sep 17 00:00:00 2001 From: Aniket Lal Date: Wed, 7 May 2025 15:42:23 +0530 Subject: [Clang][OpenCL][AMDGPU] OpenCL Kernel stubs should be assigned alwaysinline attribute (#137769) OpenCL Kernels body is emitted as stubs and the kernel is emitted as call to respective stub. (https://github.com/llvm/llvm-project/pull/115821). The stub function should be alwaysinlined, since call to stub can cause performance drop. Co-authored-by: anikelal --- clang/lib/CodeGen/CodeGenModule.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'clang/lib/CodeGen/CodeGenModule.cpp') diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index b36e078..c278176 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -6172,6 +6172,22 @@ void CodeGenModule::EmitGlobalFunctionDefinition(GlobalDecl GD, CodeGenFunction(*this).GenerateCode(GD, Fn, FI); setNonAliasAttributes(GD, Fn); + + bool ShouldAddOptNone = !CodeGenOpts.DisableO0ImplyOptNone && + (CodeGenOpts.OptimizationLevel == 0) && + !D->hasAttr(); + + if (D->hasAttr()) { + if (GD.getKernelReferenceKind() == KernelReferenceKind::Stub && + !D->hasAttr() && + !Fn->hasFnAttribute(llvm::Attribute::NoInline) && + !D->hasAttr() && + !Fn->hasFnAttribute(llvm::Attribute::OptimizeNone) && + !ShouldAddOptNone) { + Fn->addFnAttr(llvm::Attribute::AlwaysInline); + } + } + SetLLVMFunctionAttributesForDefinition(D, Fn); if (const ConstructorAttr *CA = D->getAttr()) -- cgit v1.1