[clang] [HLSL] Appropriately set function attribute optnone (PR #125937)

Chris B via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 11 08:10:19 PST 2025


================
@@ -345,6 +345,14 @@ void clang::CodeGen::CGHLSLRuntime::setHLSLEntryAttributes(
                 WaveSizeAttr->getPreferred());
     Fn->addFnAttr(WaveSizeKindStr, WaveSizeStr);
   }
+  // HLSL entry functions are materialized for module functions with
+  // HLSLShaderAttr attribute. SetLLVMFunctionAttributesForDefinition called
+  // later in the compiler-flow for such module functions is not aware of and
+  // hence not able to set attributes of the newly materialized entry functions.
+  // So, set attributes of entry function here, as appropriate.
+  if (CGM.getCodeGenOpts().OptimizationLevel == 0) {
+    Fn->addFnAttr(llvm::Attribute::OptimizeNone);
+  }
----------------
llvm-beanz wrote:

nit: https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements
```suggestion
  if (CGM.getCodeGenOpts().OptimizationLevel == 0)
    Fn->addFnAttr(llvm::Attribute::OptimizeNone);
```

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


More information about the cfe-commits mailing list