================
@@ -345,6 +345,9 @@ void clang::CodeGen::CGHLSLRuntime::setHLSLEntryAttributes(
                 WaveSizeAttr->getPreferred());
     Fn->addFnAttr(WaveSizeKindStr, WaveSizeStr);
   }
+  if (CGM.getCodeGenOpts().OptimizationLevel == 0) {
+    Fn->addFnAttr(llvm::Attribute::OptimizeNone);
+  }
   Fn->addFnAttr(llvm::Attribute::NoInline);
----------------
bharadwajy wrote:

> Given that these already have "noinline", I'm surprised that the logic in 
> "SetLLVMFunctionAttributesForDefinition" doesn't already put optnone on these 
> functions. Is something undoing this later?

The entry function that is created and whose attribute is set to `noinline` in 
this function is different from that `SetLLVMFunctionAttributesForDefinition()` 
looks at.

`GenerateCode(GlobalFnDecl, MangledFn, ...)` calls `StartFunction(GlobalFnDecl, 
ResTy, MangledFn, ...)` which in turn calls `emitEntryFunction(FnDecl, 
MangledFn)`. `emitEntryFunction(FnDecl, MangledFn, ...)` constructs a new entry 
function `EntryFn`, sets linkage of `MangledFn` to be `internal` to arrange it 
to be inlined in `EntryFn` etc., and calls `setHLSLEntryAttributes(FnDecl, 
EntryFn)` to set attributes of `EntryFn`.

`SetLLVMFunctionAttributesForDefinition(...)` sets attributes of `MangledFn`. 
So the logic in that function checks attributes for `MangledFn` and not for the 
created `EntryFn`.

Hence setting optnone attribute in `setHLSLEntryAttributes(FnDecl, EntryFn)` of 
`EntryFn` at the time of its set up seemed appropriate - if optimizations are 
disabled.


https://github.com/llvm/llvm-project/pull/125937
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to