spirv-opt: Add support to prevent functions from being inlined if they have DontInline flag (#3858)
This commit add support for optimizer to not inline functions with DontInline control flag, so that the [noinline] attribute in HLSL will be useful in DXC SPIR-V generation.
This is part of work of github.com/microsoft/DirectXShaderCompiler/issues/3158
diff --git a/source/opt/inline_pass.cpp b/source/opt/inline_pass.cpp
index 6021a7c..eaf29aa 100644
--- a/source/opt/inline_pass.cpp
+++ b/source/opt/inline_pass.cpp
@@ -727,6 +727,12 @@
bool InlinePass::IsInlinableFunction(Function* func) {
// We can only inline a function if it has blocks.
if (func->cbegin() == func->cend()) return false;
+
+ // Do not inline functions with DontInline flag.
+ if (func->control_mask() & SpvFunctionControlDontInlineMask) {
+ return false;
+ }
+
// Do not inline functions with returns in loops. Currently early return
// functions are inlined by wrapping them in a one trip loop and implementing
// the returns as a branch to the loop's merge block. However, this can only