[clang] [Clang][OpenCL][AMDGPU] OpenCL Kernel stubs should be assigned alwaysinline attribute (PR #137769)

Aniket Lal via cfe-commits cfe-commits at lists.llvm.org
Fri May 2 02:45:45 PDT 2025


================
@@ -6174,6 +6174,19 @@ void CodeGenModule::EmitGlobalFunctionDefinition(GlobalDecl GD,
   CodeGenFunction(*this).GenerateCode(GD, Fn, FI);
 
   setNonAliasAttributes(GD, Fn);
+
+  bool ShouldAddOptNone = !CodeGenOpts.DisableO0ImplyOptNone &&
+                          (CodeGenOpts.OptimizationLevel == 0) &&
+                          !D->hasAttr<MinSizeAttr>();
----------------
lalaniket8 wrote:

I am following the logic for `ShouldAddOptNone` used later in `SetLLVMFunctionAttributesForDefinition(D, Fn);`  here https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/CodeGenModule.cpp#L2552 to decide if optnone and noinline attribute should be added. 

If we don't do the same check we end up adding alwaysinline to the stub in cases where `ShouldAddOptNone` would be true. This prevents adding of optnone and noinline later in https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/CodeGenModule.cpp#L2552

https://github.com/llvm/llvm-project/pull/137769


More information about the cfe-commits mailing list