[clang] [HLSL] set alwaysinline on HLSL functions (PR #106588)

Greg Roth via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 3 07:28:56 PDT 2024


================
@@ -414,9 +414,20 @@ void CGHLSLRuntime::emitEntryFunction(const FunctionDecl *FD,
 
 void CGHLSLRuntime::setHLSLFunctionAttributes(const FunctionDecl *FD,
                                               llvm::Function *Fn) {
-  if (FD->isInExportDeclContext()) {
-    const StringRef ExportAttrKindStr = "hlsl.export";
-    Fn->addFnAttr(ExportAttrKindStr);
+  if (FD) { // "explicit" functions with declarations
+    if (FD->isInExportDeclContext()) {
+      const StringRef ExportAttrKindStr = "hlsl.export";
+      Fn->addFnAttr(ExportAttrKindStr);
+    }
+    // Respect noinline if the explicit functions use it
+    // otherwise default to alwaysinline
+    if (!Fn->hasFnAttribute(Attribute::NoInline))
+      Fn->addFnAttr(llvm::Attribute::AlwaysInline);
+  } else { // "implicit" autogenerated functions with no declaration
+    // Implicit functions might get marked as noinline by default
+    // but we override that for HLSL
+    Fn->removeFnAttr(Attribute::NoInline);
----------------
pow2clk wrote:

It is applied here: https://github.com/llvm/llvm-project/blob/df159d3cf8e681f8d225bd0b4ed0cbd97b16c588/clang/lib/CodeGen/CodeGenModule.cpp#L2477-L2479
on functions not explicitly created by the user, but generated to construct or destruct global/static local variables as well as the global functions that call each of these at the top and bottom of the entry function.


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


More information about the cfe-commits mailing list