diff options
author | Aniket Lal <lalaniket8@gmail.com> | 2025-05-07 15:42:23 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-05-07 15:42:23 +0530 |
commit | c3ce5684a8b408220eed983d065edba0e6ed5016 (patch) | |
tree | 77a95f0b22a5e8bcb9458810cf8231946c81a9fb /clang/lib/CodeGen/CodeGenModule.cpp | |
parent | 62385b848757f2dc35070eadb2ccd921508497dc (diff) | |
download | llvm-c3ce5684a8b408220eed983d065edba0e6ed5016.zip llvm-c3ce5684a8b408220eed983d065edba0e6ed5016.tar.gz llvm-c3ce5684a8b408220eed983d065edba0e6ed5016.tar.bz2 |
[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 <anikelal@amd.com>
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
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<MinSizeAttr>(); + + if (D->hasAttr<OpenCLKernelAttr>()) { + if (GD.getKernelReferenceKind() == KernelReferenceKind::Stub && + !D->hasAttr<NoInlineAttr>() && + !Fn->hasFnAttribute(llvm::Attribute::NoInline) && + !D->hasAttr<OptimizeNoneAttr>() && + !Fn->hasFnAttribute(llvm::Attribute::OptimizeNone) && + !ShouldAddOptNone) { + Fn->addFnAttr(llvm::Attribute::AlwaysInline); + } + } + SetLLVMFunctionAttributesForDefinition(D, Fn); if (const ConstructorAttr *CA = D->getAttr<ConstructorAttr>()) |