mirror of
https://github.com/KhronosGroup/SPIRV-Tools
synced 2024-11-27 22:00:07 +00:00
c2b2b57885
The front-end language compiler would simply emit DebugDeclare for
a variable when it is declared, which is effective through the variable's
scope. Since DebugDeclare only maps an OpVariable to a local variable,
the information can be removed when an optimization pass uses the
loaded value of the variable. DebugValue can be used to specify the
value of a variable. For each value update or phi instruction of a variable,
we can add DebugValue to help debugger inspect the variable at any
point of the program execution.
For example,
float a = 3;
... (complicated cfg) ...
foo(a); // <-- variable inspection: debugger can find DebugValue of `float a` in the nearest dominant
For the code with complicated CFG e.g., for-loop, if-statement, we
need help of ssa-rewrite to analyze the effective value of each variable
in each basic block.
If the value update of the variable happens only once and it dominates
all its uses, local-single-store-elim pass conducts the same value update
with ssa-rewrite and we have to let it add DebugValue for the value assignment.
One main issue is that we have to add DebugValue only when the value
update of a variable is visible to DebugDeclare. For example,
```
{ // scope1
%stack = OpVariable %ptr_int %int_3
{ // scope2
DebugDeclare %foo %stack <-- local variable "foo" in high-level language source code is declared as OpVariable "%stack"
// add DebugValue "foo = 3"
...
Store %stack %int_7 <-- foo = 7, add DebugValue "foo = 7"
...
// debugger can inspect the value of "foo"
}
Store %stack %int_11 <-- out of "scope2" i.e., scope of "foo". DO NOT add DebugValue "foo = 11"
}
```
However, the initalization of a variable is an exception.
For example, an argument passing of an inlined function must be done out of
the function's scope, but we must add a DebugValue for it.
```
// in HLSL
bar(float arg) { ... }
...
float foo = 3;
bar(foo);
// in SPIR-V
%arg = OpVariable
OpStore %arg %foo <-- Argument passing. Out of "float arg" scope, but we must add DebugValue for "float arg"
... body of function bar(float arg) ...
```
This PR handles the except case in local-single-store-elim pass. It adds
DebugValue for a store that is considered as an initialization.
The same exception handling code for ssa-rewrite is done by this commit:
|
||
---|---|---|
.. | ||
fuzz | ||
link | ||
opt | ||
reduce | ||
util | ||
val | ||
assembly_grammar.cpp | ||
assembly_grammar.h | ||
binary.cpp | ||
binary.h | ||
cfa.h | ||
CMakeLists.txt | ||
diagnostic.cpp | ||
diagnostic.h | ||
disassemble.cpp | ||
disassemble.h | ||
enum_set.h | ||
enum_string_mapping.cpp | ||
enum_string_mapping.h | ||
ext_inst.cpp | ||
ext_inst.h | ||
extensions.cpp | ||
extensions.h | ||
instruction.h | ||
latest_version_glsl_std_450_header.h | ||
latest_version_opencl_std_header.h | ||
latest_version_spirv_header.h | ||
libspirv.cpp | ||
macro.h | ||
name_mapper.cpp | ||
name_mapper.h | ||
opcode.cpp | ||
opcode.h | ||
operand.cpp | ||
operand.h | ||
parsed_operand.cpp | ||
parsed_operand.h | ||
pch_source.cpp | ||
pch_source.h | ||
print.cpp | ||
print.h | ||
software_version.cpp | ||
spirv_constant.h | ||
spirv_definition.h | ||
spirv_endian.cpp | ||
spirv_endian.h | ||
spirv_fuzzer_options.cpp | ||
spirv_fuzzer_options.h | ||
spirv_optimizer_options.cpp | ||
spirv_optimizer_options.h | ||
spirv_reducer_options.cpp | ||
spirv_reducer_options.h | ||
spirv_target_env.cpp | ||
spirv_target_env.h | ||
spirv_validator_options.cpp | ||
spirv_validator_options.h | ||
table.cpp | ||
table.h | ||
text_handler.cpp | ||
text_handler.h | ||
text.cpp | ||
text.h |