[llvm] [DirectX] Set Shader Flag DisableOptimizations. (PR #123136)

Justin Bogner via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 27 10:30:34 PST 2025


bogner wrote:

> I am not aware of module-level metadata `dx.disable_optimizations` being documented anywhere nor of other module-level metadata presently in use - such as `dx.valver`, `dx.shaderModel`. Created [an issue](#124310) to add documentation.
>
> Currently, presence of command-line option `-Od` is denoted by [adding a module metadata](https://github.com/llvm/llvm-project/blob/7842374103b26933d71a8fe354cd4d8715d55b1c/clang/lib/CodeGen/CGHLSLRuntime.cpp#L189) `dx.disable_optimizations`. I do not know of the context of the design choice, but it seems to be a reasonable choice to capture the module-wide property of optimizations being disabled. Relying on an attribute of a specific function(s) (such as entry) appears to involve additional bookkeeping or traversals and an awkward way to denote a module-wide property.

There's a very big difference between `dx.disable_optimizations` and metadata like `dx.valver` and `dx.shaderModel` - the latter are part of DXIL and we're required to generate them to match dxc/fxc output. `dx.disable_optimizations` is unique to the upstream llvm implementation (it was added in f712c0131f3b without any specific mention of why it was needed). My concern here is mostly that the `dx.disable_optimizations` metadata is redundant with information that's already available in more standard ways and the story around keeping it consistent within the module isn't clear. It also isn't clear to me how this will interact with linking - what if part of the module is built with optimizations disabled and part with them enabled? Reconciling global metadata in this case sounds like a nightmare, whereas the `optnone` attribute that is already present on functions will already do the right thing.

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


More information about the llvm-commits mailing list