https://github.com/shader-slang/slang
Revision 14fab67c5edd8eb697ffb10dbcc0467678521eef authored by Theresa Foley on 14 January 2023, 23:31:31 UTC, committed by GitHub on 14 January 2023, 23:31:31 UTC
* Fixes for crash when inlining at global scope

Recent changes to the way inlining is implemented in the Slang compiler
have broken certain scenarios involving `static const` declarations.
The basic problem is that the initial-value expression for a `static const`
gets lowered into IR code at the global scope of a module, and if
that code includes `call`s to stdlib operations marked `forceInlineEarly`,
then we end up trying to apply inlining to code at module scope.
The current inlining operation assumes that all `call`s are in basic
blocks, and that the correct way to do inlining involves splitting
those blocks.

This change adds logic to detect when the callee at a call site to
be inlined consists of a single basic block ending in a `return`,
and in that case it invokes specialized inlining logic that doesn't
split basic blocks and doesn't need to care if the original `call`
is in a basic block.

Thus we are able to inline calls to single-basic-block `forceInlineEarly`
functions called as part of the initialization for global-scope
`static const` variables.

This logic does *not* solve the problem of calls to multi-block
`forceInlineEarly` functions from the global scope. Such calls cannot
really be inlined.

A secondary problem that arises when inlining such calls is that the
callee might include local temporaries (`var` instructions) that are
read and written (`load`s and `store`s), and none of those instructions
should be allowed at the global scope.

In the case of the functions being inlined here, the `load`/`store`
operations are superfluous, and should be cleaned up by our SSA pass.
The only reason that they seem to *not* be getting cleaned up in the
case that was been triggering crashes is that the callee is a generic.

The current logic for the SSA pass was skipping the bodies of generic
functions, so they would not be cleaned up. This change enables the SSA
pass to apply to the bodies of generic functions, and also ensures that
SSA cleanups are applied *before* any `forceInlineEarly` functions get
inlined.

* fixup: liveness test outputs
1 parent 4adc64f
History
Tip revision: 14fab67c5edd8eb697ffb10dbcc0467678521eef authored by Theresa Foley on 14 January 2023, 23:31:31 UTC
Fixes for crash when inlining at global scope (#2593)
Tip revision: 14fab67
File Mode Size
.github
build
deps
docs
examples
external
extras
prelude
source
tests
tools
.editorconfig -rw-r--r-- 984 bytes
.gitattributes -rw-r--r-- 95 bytes
.gitignore -rw-r--r-- 1.4 KB
.gitmodules -rw-r--r-- 951 bytes
CODE_OF_CONDUCT.md -rw-r--r-- 3.1 KB
LICENSE -rw-r--r-- 1.1 KB
README.md -rw-r--r-- 6.1 KB
github_build.sh -rw-r--r-- 1.1 KB
github_macos_build.sh -rw-r--r-- 1.2 KB
github_test.sh -rw-r--r-- 968 bytes
make-slang-tag-version.bat -rw-r--r-- 210 bytes
premake.bat -rw-r--r-- 120 bytes
premake5.lua -rw-r--r-- 56.1 KB
slang-com-helper.h -rw-r--r-- 4.9 KB
slang-com-ptr.h -rw-r--r-- 5.0 KB
slang-gfx.h -rw-r--r-- 86.4 KB
slang-tag-version.h -rw-r--r-- 36 bytes
slang.h -rw-r--r-- 191.0 KB
slang.sln -rw-r--r-- 41.1 KB
test.bat -rw-r--r-- 1.4 KB

README.md

back to top