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

Matt Arsenault via cfe-commits cfe-commits at lists.llvm.org
Thu May 1 09:25:06 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>();
+
+  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);
----------------
arsenm wrote:

There are fewer test changes than I expect for this. Do we have tests with explicit optnone or noinline placed on kernels? 

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


More information about the cfe-commits mailing list